Skip to content

Extending Requirements

DrInfy edited this page Aug 30, 2021 · 1 revision

You can create custom Requirements easily with RequireCustom using lambda. Step and IfElse will also automatically convert lambda clauses to RequireCustom components. Here is some examples of how they could be used. RequireCustom parameter will always refer to the bot object, but you can also simply choose to not use it.

# if lost 2 or more probes, switch to normal build, otherwise cannon rush
IfElse(lambda ai: ai.lost_units_manager.own_lost_type(UnitTypeId.PROBE) >= 2, normal_build, cannon_rush_build)

# Build 2 ravens when cloak trigger is detected, otherwise skip this step
Step(None, TerranUnit(UnitTypeId.Raven, 2), skip_until=lambda ai: ai.enemy_units_manager.enemy_cloak_trigger)

If the condition is increasingly complex or the condition is used ofter, it's probably better to make the condition a requirement object.

class MineralForGate(RequireBase):
    """ Only allow building gates when having excess minerals. """
    def __init__(self, mineral_requirement: int):
        assert mineral_requirement is not None and isinstance(mineral_requirement, int)
        super().__init__()

        self.mineralRequirement = mineral_requirement

    def check(self) -> bool:
        return self.ai.minerals > self.mineralRequirement - 150 * self.get_ordered_count(UnitTypeId.GATEWAY)
Clone this wiki locally