def read(self, s): s = preprocess(s) d = self._dict for line in s.split("\n"): words = line.split() if not words: continue if words[0] == "clear": d.clear() elif words[0] == "def": name = words[1] if name not in d: d[name] = {} elif words[0] in self.string_properties: d[name][words[0]] = words[1] elif words[0] in self.int_properties: d[name][words[0]] = int(words[1]) elif words[0] in self.precision_properties: d[name][words[0]] = to_int(words[1]) elif words[0] in self.int_list_properties: d[name][words[0]] = [int(x) for x in words[1:]] elif words[0] in self.precision_list_properties: d[name][words[0]] = [to_int(x) for x in words[1:]] else: if words[0] == "effect" and words[1] == "bonus" and words[2] in self.precision_properties: words[3] = to_int(words[3]) if len(words) > 4: # apparently this case doesn't happen at the moment words[4] = to_int(words[4]) d[name][words[0]] = words[1:]
def _read_ai_to_dict(s, d): s = preprocess(s) name = None for line in s.split("\n"): words = line.split() if not words: continue if words[0] == "def": name = words[1] d[name] = [] elif name is not None: d[name] += [line] else: warning("'def <AI_name>' is missing (check ai.txt)")
def read(self, s): s = preprocess(s) d = self._dict name = "(the name is missing)" for line in s.split("\n"): try: words = line.split() if not words: continue if words[0] == "clear": d.clear() elif words[0] == "def": name = words[1] if name not in d: d[name] = {} elif words[0] in self.string_properties: d[name][words[0]] = words[1] elif words[0] in self.int_properties: d[name][words[0]] = int(words[1]) elif words[0] in self.precision_properties: if words[0] == "effect_range" and len(words) >= 2: if words[1] == "square": words[1] = "6" info( "effect_range of %s will be 6 (instead of 'square')", name) elif words[1] == "nearby": words[1] = "12" info( "effect_range of %s will be 12 (instead of 'nearby')", name) elif words[1] == "anywhere": words[1] = "2147483" # sys.maxint / 1000 (32 bits) if len(words) >= 2 and words[1] == "inf": words[1] = "2147483" # sys.maxint / 1000 (32 bits) d[name][words[0]] = to_int(words[1]) elif words[0] in self.int_list_properties: d[name][words[0]] = [int(x) for x in words[1:]] elif words[0] in self.precision_list_properties: d[name][words[0]] = [to_int(x) for x in words[1:]] else: if words[0] == "effect" and words[1] == "bonus" and words[ 2] in self.precision_properties: words[3] = to_int(words[3]) if len( words ) > 4: # apparently this case doesn't happen at the moment words[4] = to_int(words[4]) d[name][words[0]] = words[1:] except: warning("error in definition of %s: %s", name, line)
def read(self, s): s = preprocess(s) d = self._dict name = "(the name is missing)" for line in s.split("\n"): try: words = line.split() if not words: continue if words[0] == "clear": d.clear() elif words[0] == "def": name = words[1] if name not in d: d[name] = {} elif words[0] in self.string_properties: d[name][words[0]] = words[1] elif words[0] in self.int_properties: d[name][words[0]] = int(words[1]) elif words[0] in self.precision_properties: if words[0] == "effect_range" and len(words) >= 2: if words[1] == "square": words[1] = "6" info("effect_range of %s will be 6 (instead of 'square')", name) elif words[1] == "nearby": words[1] = "12" info("effect_range of %s will be 12 (instead of 'nearby')", name) elif words[1] == "anywhere": words[1] = "2147483" # sys.maxint / 1000 (32 bits) if len(words) >= 2 and words[1] == "inf": words[1] = "2147483" # sys.maxint / 1000 (32 bits) d[name][words[0]] = to_int(words[1]) elif words[0] in self.int_list_properties: d[name][words[0]] = [int(x) for x in words[1:]] elif words[0] in self.precision_list_properties: d[name][words[0]] = [to_int(x) for x in words[1:]] else: if words[0] == "effect" and words[1] == "bonus" and words[2] in self.precision_properties: words[3] = to_int(words[3]) if len(words) > 4: # apparently this case doesn't happen at the moment words[4] = to_int(words[4]) d[name][words[0]] = words[1:] except: warning("error in definition of %s: %s", name, line)