Ejemplo n.º 1
0
def compile_dialog_states(processor, dialog_file):
  global start_states
  global end_states
  unique_state_list = ["start", "party_encounter", "prisoner_liberated", "enemy_defeated", "party_relieved",
      "event_triggered", "close_window", "trade", "exchange_members", "trade_prisoners", "buy_mercenaries",
      "view_char", "training", "member_chat", "prisoner_chat"]
  unique_state_usages = [1 for i in unique_state_list]
  unique_states = dict((k, i) for i, k in enumerate(unique_state_list))
  last_index = len(unique_state_list)
  for entry in module_dialogs.dialogs:
    end_state = entry[5]
    index = unique_states.setdefault(end_state, last_index)
    if index == last_index:
      last_index += 1
      unique_state_list.append(end_state)
      unique_state_usages.append(0)
    end_states.append(index)
  for entry in module_dialogs.dialogs:
    start_state = entry[2]
    try:
      index = unique_states[start_state]
      unique_state_usages[index] += 1
      start_states.append(index)
    except KeyError:
      pc.ERROR("starting dialog state '%s' has no matching ending state" % start_state)
  for state, usages in zip(unique_state_list, unique_state_usages):
    if not usages:
      pc.ERROR("ending dialog state '%s' is not used" % state)
  with open(module_info.export_path("dialog_states.txt"), "wb") as state_file:
    state_file.write("".join("%s\r\n" % e for e in unique_state_list))
 def load_ids(self, tag, data, opmask):
     if not tag in self.tag_map:
         self.tag_map[tag] = {}
     id_map = self.tag_map[tag]
     for i, entry in enumerate(data):
         try:
             name = entry[0]
         except TypeError:
             pc.ERROR(
                 "'%s' entry number %d, '%s': has no valid identifier field"
                 % (tag, i, entry))
         pc.assert_valid_identifier(name, entry=entry, tag=tag)
         if name in id_map:
             pc.ERROR("duplicate identifier '%s_%s'" % (tag, name))
         id_map[name] = opmask | i
 def get_id(self, name):
     try:
         id_uses = self.variables[name]
         id_uses[1] += 1
         return self.opmask | id_uses[0]
     except KeyError:
         pc.ERROR("local variable '%s' used uninitialized" % name)
def process_entry(processor, txt_file, entry, index):
    spawn_records = entry[4]
    output_list = [
        "mst_%s %s %d  %d\r\n%s \r\n\r\n%d " %
        (entry[0], entry[0], entry[1], entry[2], pc.replace_spaces(
            entry[3]), po.block_len(spawn_records))
    ]
    for spawn_record in spawn_records:
        item_override_len = po.block_len(spawn_record[5])
        if item_override_len > 8:
            pc.ERROR("the maximum number of spawn item overrides is 8")
        output_list.append("%d %d %d %d %d %d  " % (spawn_record[0:5] +
                                                    (item_override_len, )))
        output_list.extend("%d " % processor.process_id(item, "itm")
                           for item in spawn_record[5])
        output_list.append("\r\n")
    output_list.append("%d\r\n" % po.block_len(entry[5]))
    txt_file.write("".join(output_list))
    for i, trigger in enumerate(entry[5]):
        txt_file.write("%f %f %f " % trigger[0:3])
        if trigger[0] < 0.0:
            name = "%s: %s" % (entry[0], get_trigger_name(trigger[0]))
        else:
            name = "%s: trigger #%d" % (entry[0], i)
        txt_file.write("".join(
            processor.process_block(trigger[3], name + " conditions")))
        txt_file.write("".join(
            processor.process_block(trigger[4], name + " consequences")))
        txt_file.write("\r\n")
    txt_file.write("\r\n\r\n")
 def process_id(self, param, tag=None):
     if isinstance(param, str):
         tag_name = param.partition("_")
         if tag and tag_name[0] != tag:
             pc.ERROR("identifier '%s_%s' is the wrong type: %s required" %
                      (tag_name[0], tag_name[2], tag))
         param = self.identifier_map.get_id(tag_name[0],
                                            tag_name[2],
                                            opmask=False)
     return param
 def add_id(self, name, uses=0):
     id_uses = self.variables.setdefault(name, [self.number, 0])
     if id_uses[0] == self.number:
         self.number += 1
     if uses > 0:
         id_uses[1] += uses
     if self.limit is not None and self.number >= self.limit:
         pc.ERROR(
             "new local variable '%s' exceeds the maximum count of %d per operations block"
             % (name, self.limit))
     return self.opmask | id_uses[0]
def process_entry(processor, txt_file, entry, index):
    icon_flags = 0 if not entry[2] else ((entry[2][1] if po.block_len(entry[2]) > 1 else 0) | processor.process_id(entry[2][0], "icon"))
    txt_file.write("pt_%s %s %d %d %d %d " % (entry[0], pc.replace_spaces(entry[1]), icon_flags, entry[3],
        processor.process_id(entry[4], "fac"), entry[5]))
    member_count = po.block_len(entry[6])
    if member_count > 6:
      raise pc.ERROR("party templates can only have a maximum of 6 members")
    members_list = ["%d %d %d %d " % (processor.process_id(troop[0], "trp"), troop[1], troop[2], troop[3] if len(troop) > 3 else 0) for troop in entry[6]]
    members_list.extend("-1 " for i in xrange(6 - member_count))
    members_list.append("\r\n")
    txt_file.write("".join(members_list))
 def process_block(self, block, name, check_can_fail=False):
     self.local_variables = LocalVariables()
     self.current_block_result = [None]
     self.current_statement_count = 0
     self.current_indent = 0
     self.current_block_name = name
     self.current_block_check_can_fail = check_can_fail
     try:
         self.process_statements(block)
     except pc.ModuleSystemError as e:
         if not e.entry:
             e.entry = name
         raise
     self.local_variables.warn_unused(name)
     if self.current_indent != 0:
         if self.current_indent > 0:
             missing = "missing"
         else:
             missing = "extra"
             self.current_indent *= -1
         pc.ERROR("%d %s try_end" % (self.current_indent, missing),
                  entry=name)
     self.current_block_result[0] = " %d " % self.current_statement_count
     return self.current_block_result
def block_len(block):
    if not isinstance(block, (list, tuple)):
        pc.ERROR("%s %s found where list was expected" %
                 (repr(block), type(block)))
    return len(block)
 def get_id(self, tag, name, opmask=False):
     try:
         id_no = self.tag_map[tag][name]
         return id_no if opmask else id_no & remove_opmask
     except KeyError:
         pc.ERROR("identifier '%s_%s' not found" % (tag, name))
Ejemplo n.º 11
0
def check_count(processor, txt_file):
    if len(module_skins.skins) > 16:
        raise pc.ERROR("the maximum number of skins is 16")