Exemplo n.º 1
0
 def __init__(self, param_list, body, pos):
     base_statement.BaseStatement.__init__(self, "switch-block", pos, False,
                                           False)
     if len(param_list) < 4:
         raise generic.ScriptError(
             "Switch-block requires at least 4 parameters, encountered " +
             str(len(param_list)), pos)
     if not isinstance(param_list[1], expression.Identifier):
         raise generic.ScriptError(
             "Switch-block parameter 2 'variable range' must be an identifier.",
             param_list[1].pos)
     if param_list[1].value in var_ranges:
         self.var_range = var_ranges[param_list[1].value]
     else:
         raise generic.ScriptError(
             "Unrecognized value for switch parameter 2 'variable range': '{}'"
             .format(param_list[1].value),
             param_list[1].pos,
         )
     if not isinstance(param_list[2], expression.Identifier):
         raise generic.ScriptError(
             "Switch-block parameter 3 'name' must be an identifier.",
             param_list[2].pos)
     self.initialize(param_list[2],
                     general.parse_feature(param_list[0]).value,
                     len(param_list) - 4)
     self.expr = param_list[-1]
     self.body = body
     self.param_list = param_list[3:-1]
     # register_map is a dict to be duck-compatible with spritelayouts.
     # But because feature_set has only one item for switches, register_map also has at most one item.
     self.register_map = {}
Exemplo n.º 2
0
 def __init__(self, param_list, body, pos):
     base_statement.BaseStatement.__init__(self, "switch-block", pos, False,
                                           False)
     if len(param_list) != 4:
         raise generic.ScriptError(
             "Switch-block requires 4 parameters, encountered " +
             str(len(param_list)), pos)
     if not isinstance(param_list[1], expression.Identifier):
         raise generic.ScriptError(
             "Switch-block parameter 2 'variable range' must be an identifier.",
             param_list[1].pos)
     if param_list[1].value in var_ranges:
         self.var_range = var_ranges[param_list[1].value]
     else:
         raise generic.ScriptError(
             "Unrecognized value for switch parameter 2 'variable range': '{}'"
             .format(param_list[1].value), param_list[1].pos)
     if not isinstance(param_list[2], expression.Identifier):
         raise generic.ScriptError(
             "Switch-block parameter 3 'name' must be an identifier.",
             param_list[2].pos)
     self.initialize(param_list[2],
                     general.parse_feature(param_list[0]).value)
     self.expr = param_list[3]
     self.body = body
Exemplo n.º 3
0
Arquivo: item.py Projeto: spnda/nml
    def __init__(self, params, body, pos):
        base_statement.BaseStatementList.__init__(
            self, "item-block", pos,
            base_statement.BaseStatementList.LIST_TYPE_ITEM, body)

        if not (1 <= len(params) <= 4):
            raise generic.ScriptError(
                "Item block requires between 1 and 4 parameters, found {:d}.".
                format(len(params)), self.pos)
        self.feature = general.parse_feature(params[0])
        if self.feature.value in (0x08, 0x0C, 0x0E):
            raise generic.ScriptError(
                "Defining item blocks for this feature is not allowed.",
                self.pos)
        self.name = params[1] if len(params) >= 2 else None

        self.id = params[2].reduce_constant(
            global_constants.const_list) if len(params) >= 3 else None
        if isinstance(self.id,
                      expression.ConstantNumeric) and self.id.value == -1:
            self.id = None  # id == -1 means default

        if len(params) >= 4:
            if self.feature.value != 0x07:
                raise generic.ScriptError(
                    "item-block parameter 4 'size' may only be set for houses",
                    params[3].pos)
            self.size = params[3].reduce_constant(global_constants.const_list)
            if self.size.value not in action0.house_sizes:
                raise generic.ScriptError(
                    "item-block parameter 4 'size' does not have a valid value",
                    self.size.pos)
        else:
            self.size = None
Exemplo n.º 4
0
 def __init__(self, params, pos):
     base_statement.BaseStatement.__init__(self, "sort-block", pos)
     if len(params) != 2:
         raise generic.ScriptError(
             "Sort-block requires exactly two parameters, got {:d}".format(
                 len(params)), self.pos)
     self.feature = general.parse_feature(params[0])
     self.vehid_list = params[1]
Exemplo n.º 5
0
    def __init__(self, param_list, choices, pos):
        base_statement.BaseStatement.__init__(self, "random_switch-block", pos, False, False)
        if not (3 <= len(param_list) <= 4):
            raise generic.ScriptError(
                "random_switch requires 3 or 4 parameters, encountered {:d}".format(len(param_list)), pos
            )
        # feature
        feature = general.parse_feature(param_list[0]).value

        # type
        self.type = param_list[1]
        # Extract type name and possible argument
        if isinstance(self.type, expression.Identifier):
            self.type_count = None
        elif isinstance(self.type, expression.FunctionCall):
            if len(self.type.params) == 0:
                self.type_count = None
            elif len(self.type.params) == 1:
                self.type_count = action2var.reduce_varaction2_expr(self.type.params[0], feature)
            else:
                raise generic.ScriptError(
                    "Value for random_switch parameter 2 'type' can have only one parameter.", self.type.pos
                )
            self.type = self.type.name
        else:
            raise generic.ScriptError(
                "random_switch parameter 2 'type' should be an identifier, possibly with a parameter.", self.type.pos
            )

        # name
        if not isinstance(param_list[2], expression.Identifier):
            raise generic.ScriptError("random_switch parameter 3 'name' should be an identifier", pos)
        name = param_list[2]

        # triggers
        self.triggers = param_list[3] if len(param_list) == 4 else expression.ConstantNumeric(0)

        # body
        self.choices = []
        self.dependent = []
        self.independent = []
        for choice in choices:
            if isinstance(choice.probability, expression.Identifier):
                if choice.probability.value == "dependent":
                    self.dependent.append(choice.result)
                    continue
                elif choice.probability.value == "independent":
                    self.independent.append(choice.result)
                    continue
            self.choices.append(choice)
        if len(self.choices) == 0:
            raise generic.ScriptError("random_switch requires at least one possible choice", pos)

        self.initialize(name, feature)
        self.random_act2 = None  # Set during action generation to resolve dependent/independent chains
Exemplo n.º 6
0
    def __init__(self, param_list, pos):
        base_statement.BaseStatement.__init__(self, "disable_item()", pos)
        if not (1 <= len(param_list) <= 3):
            raise generic.ScriptError(
                "disable_item() requires between 1 and 3 parameters, encountered {:d}.".format(len(param_list)), pos
            )
        self.feature = general.parse_feature(param_list[0])

        if len(param_list) > 1:
            self.first_id = param_list[1].reduce_constant(global_constants.const_list)
        else:
            self.first_id = None

        if len(param_list) > 2:
            self.last_id = param_list[2].reduce_constant(global_constants.const_list)
            if self.last_id.value < self.first_id.value:
                raise generic.ScriptError("Last id to disable may not be lower than the first id.", pos)
        else:
            self.last_id = None