Class: Unit

Catastrophe. Unit

A unit in the game.

new Catastrophe.Unit()

Initializes a Unit with basic logic as provided by the Creer code generator. Never use this directly. It is for internal Joueur use.

Extends

Members

boolean acted

Whether this Unit has performed its action this turn.

number energy

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

number food

The amount of food this Unit is holding.

string gameObjectName

Inherited From:
Catastrophe.GameObject#gameObjectName
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.

string id

Inherited From:
Catastrophe.GameObject#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.
The Job this Unit was recruited to do.

Array.<string> logs

Inherited From:
Catastrophe.GameObject#logs
Any strings logged will be stored here. Intended for debugging.

number materials

The amount of materials this Unit is holding.

Catastrophe.Tile movementTarget

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.

number moves

How many moves this Unit has left this turn.
The Player that owns and can control this Unit, or null if the Unit is neutral.

Array.<Catastrophe.Unit> squad

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

boolean starving

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

number turnsToDie

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

Methods

boolean attack(tile)

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.
Name Type Description
tile Catastrophe.Tile The Tile to attack.
Returns: boolean
True if successfully attacked, false otherwise.

boolean changeJob(job)

Changes this Unit's Job. Must be at max energy (100) to change Jobs.
Name Type Description
job string The name of the Job to change to.
Returns: boolean
True if successfully changed Jobs, false otherwise.

boolean construct(tile, type)

Constructs a Structure on an adjacent Tile.
Name Type Description
tile Catastrophe.Tile The Tile to construct the Structure on. It must have enough materials on it for a Structure to be constructed.
type string The type of Structure to construct on that Tile.
Returns: boolean
True if successfully constructed a structure, false otherwise.

boolean convert(tile)

Converts an adjacent Unit to your side.
Name Type Description
tile Catastrophe.Tile The Tile with the Unit to convert.
Returns: boolean
True if successfully converted, false otherwise.

boolean deconstruct(tile)

Removes materials from an adjacent Tile's Structure. You cannot deconstruct friendly structures (see `Unit.attack`).
Name Type Description
tile Catastrophe.Tile The Tile to deconstruct. It must have a Structure on it.
Returns: boolean
True if successfully deconstructed, false otherwise.

boolean drop(tile, resource, amount)

Drops some of the given resource on or adjacent to the Unit's Tile. Does not count as an action.
Name Type Description
tile Catastrophe.Tile The Tile to drop materials/food on.
resource string The type of resource to drop ('materials' or 'food').
amount number optional The amount of the resource to drop. Amounts <= 0 will drop as much as possible.
Returns: boolean
True if successfully dropped the resource, false otherwise.

boolean harvest(tile)

Harvests the food on an adjacent Tile.
Name Type Description
tile Catastrophe.Tile The Tile you want to harvest.
Returns: boolean
True if successfully harvested, false otherwise.

log(message)

Inherited From:
Catastrophe.GameObject#log
Adds a message to this GameObject's logs. Intended for your own debugging purposes, as strings stored here are saved in the gamelog.
Name Type Description
message string A string to add to this GameObject's log. Intended for debugging.

boolean move(tile)

Moves this Unit from its current Tile to an adjacent Tile.
Name Type Description
tile Catastrophe.Tile The Tile this Unit should move to.
Returns: boolean
True if it moved, false otherwise.

boolean pickup(tile, resource, amount)

Picks up some materials or food on or adjacent to the Unit's Tile. Does not count as an action.
Name Type Description
tile Catastrophe.Tile The Tile to pickup materials/food from.
resource string The type of resource to pickup ('materials' or 'food').
amount number optional The amount of the resource to pickup. Amounts <= 0 will pickup as much as possible.
Returns: boolean
True if successfully picked up a resource, false otherwise.

boolean rest()

Regenerates energy. Must be in range of a friendly shelter to rest. Costs an action. Units cannot move after resting.
Returns: boolean
True if successfully rested, false otherwise.

string toString()

Inherited From:
BaseGameObject#toString
toString override for easier debugging
Returns: string
readable string in the format `GameObjectName #id`