Unit

class games.catastrophe.unit.Unit

Bases: games.catastrophe.game_object.GameObject

The class representing the Unit in the Catastrophe game.

A unit in the game.

property acted

Whether this Unit has performed its action this turn.

Type

bool

attack(tile: games.catastrophe.tile.Tile) → bool

Attacks an adjacent Tile. Costs an action for each Unit in this Unit’s squad. Units in the squad without an action don’t participate in combat. Units in combat cannot move afterwards. Attacking structures will not give materials.

Parameters

tile (games.catastrophe.tile.Tile) – The Tile to attack.

Returns

True if successfully attacked, False otherwise.

Return type

bool

change_job(job: str) → bool

Changes this Unit’s Job. Must be at max energy (100) to change Jobs.

Parameters

job ('soldier', 'gatherer', 'builder', or 'missionary') – The name of the Job to change to.

Returns

True if successfully changed Jobs, False otherwise.

Return type

bool

construct(tile: games.catastrophe.tile.Tile, type: str) → bool

Constructs a Structure on an adjacent Tile.

Parameters
  • tile (games.catastrophe.tile.Tile) – The Tile to construct the Structure on. It must have enough materials on it for a Structure to be constructed.

  • type ('neutral', 'shelter', 'monument', 'wall', or 'road') – The type of Structure to construct on that Tile.

Returns

True if successfully constructed a structure, False otherwise.

Return type

bool

convert(tile: games.catastrophe.tile.Tile) → bool

Converts an adjacent Unit to your side.

Parameters

tile (games.catastrophe.tile.Tile) – The Tile with the Unit to convert.

Returns

True if successfully converted, False otherwise.

Return type

bool

deconstruct(tile: games.catastrophe.tile.Tile) → bool

Removes materials from an adjacent Tile’s Structure. You cannot deconstruct friendly structures (see Unit.attack).

Parameters

tile (games.catastrophe.tile.Tile) – The Tile to deconstruct. It must have a Structure on it.

Returns

True if successfully deconstructed, False otherwise.

Return type

bool

drop(tile: games.catastrophe.tile.Tile, resource: str, amount: int = 0) → bool

Drops some of the given resource on or adjacent to the Unit’s Tile. Does not count as an action.

Parameters
  • tile (games.catastrophe.tile.Tile) – The Tile to drop materials/food on.

  • resource ('materials' or 'food') – The type of resource to drop (‘materials’ or ‘food’).

  • amount (int) – The amount of the resource to drop. Amounts <= 0 will drop as much as possible.

Returns

True if successfully dropped the resource, False otherwise.

Return type

bool

property energy

The amount of energy this Unit has (from 0.0 to 100.0).

Type

float

property food

The amount of food this Unit is holding.

Type

int

property game_object_name

String representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data.

Type

str

harvest(tile: games.catastrophe.tile.Tile) → bool

Harvests the food on an adjacent Tile.

Parameters

tile (games.catastrophe.tile.Tile) – The Tile you want to harvest.

Returns

True if successfully harvested, False otherwise.

Return type

bool

property id

A unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set.

Type

str

property job

The Job this Unit was recruited to do.

Type

games.catastrophe.job.Job

log(message: str) → None

Adds a message to this GameObject’s logs. Intended for your own debugging purposes, as strings stored here are saved in the gamelog.

Parameters

message (str) – A string to add to this GameObject’s log. Intended for debugging.

property logs

Any strings logged will be stored here. Intended for debugging.

Type

list[str]

property materials

The amount of materials this Unit is holding.

Type

int

move(tile: games.catastrophe.tile.Tile) → bool

Moves this Unit from its current Tile to an adjacent Tile.

Parameters

tile (games.catastrophe.tile.Tile) – The Tile this Unit should move to.

Returns

True if it moved, False otherwise.

Return type

bool

property movement_target

The tile this Unit is moving to. This only applies to neutral fresh humans spawned on the road. Otherwise, the tile this Unit is on.

Type

games.catastrophe.tile.Tile or None

property moves

How many moves this Unit has left this turn.

Type

int

property owner

The Player that owns and can control this Unit, or None if the Unit is neutral.

Type

games.catastrophe.player.Player or None

pickup(tile: games.catastrophe.tile.Tile, resource: str, amount: int = 0) → bool

Picks up some materials or food on or adjacent to the Unit’s Tile. Does not count as an action.

Parameters
  • tile (games.catastrophe.tile.Tile) – The Tile to pickup materials/food from.

  • resource ('materials' or 'food') – The type of resource to pickup (‘materials’ or ‘food’).

  • amount (int) – The amount of the resource to pickup. Amounts <= 0 will pickup as much as possible.

Returns

True if successfully picked up a resource, False otherwise.

Return type

bool

rest() → bool

Regenerates energy. Must be in range of a friendly shelter to rest. Costs an action. Units cannot move after resting.

Returns

True if successfully rested, False otherwise.

Return type

bool

property squad

The Units in the same squad as this Unit. Units in the same squad attack and defend together.

Type

list[games.catastrophe.unit.Unit]

property starving

Whether this Unit is starving. Starving Units regenerate energy at half the rate they normally would while resting.

Type

bool

property tile

The Tile this Unit is on.

Type

games.catastrophe.tile.Tile or None

property turns_to_die

The number of turns before this Unit dies. This only applies to neutral fresh humans created from combat. Otherwise, 0.

Type

int