Skip to content

Unit Tasks

Tasks define what actions a unit can perform - combat, gathering, building, healing, and more.

Overview

Each task is an entry in the unit's task list with properties like:

  • Action Type - What the task does (combat, gather, build, etc.)
  • Target Class - What unit class can be targeted
  • Work Values - Parameters for the task behavior
  • Work Range - How far the task can operate

Adding Tasks

The add_task property provides a fluent API with named methods:

python
unit_manager = workspace.unit_manager
unit = unit_manager.get(4)

# Add combat task
unit.add_task.combat(class_id=0)

# Add garrison task
unit.add_task.garrison(class_id=11)

# Add resource generation
unit.add_task.resource_generation(
    amount_received=0.7,
    type_resource_received=0,
)

# Add aura effect
unit.add_task.aura(
    attribute_id=0,
    max_increase=10,
    radius=4.0,
)

Using Raw Parameters

For full control, use create_task():

python
unit.create_task(
    action_type=7,      # Combat
    class_id=0,         # Target archers
    work_range=8.0,
    work_value_1=1.0,
)

TaskBuilder Methods Reference

Basic Actions

MethodAction TypeDescription
none()0No action
move_to()1Move to location
follow()2Follow unit
garrison(class_id)3Garrison into building
explore()4Auto-explore map
gather(resource_in, resource_out)5Gather resources
graze()6Graze (animals)
combat(class_id)7Attack enemies
shoot()8Ranged attack
attack()9Melee attack
fly()10Fly movement
scare_hunt()11Scare prey
unload_boat()12Unload transport
guard()13Guard unit
siege_tower_ability()14Siege tower
escape()20Escape
make()21Make

Production Actions

MethodAction TypeDescription
build()101Construct buildings
make_unit()102Train units
make_technology()103Research tech
convert(work_value_1, work_value_2)104Convert enemies
heal(work_value_1, work_range)105Heal allies
repair()106Repair buildings
auto_convert(capture_text_id)107Auto-convert
discovery_artifact()108Discover artifact
hunt(resource_in, resource_out)110Hunt animals
trade(unit_id)111Trade with market

Advanced Actions

MethodAction TypeDescription
generate_wonder_victory()120Wonder victory
deselect_when_tasked_farm()121Farm deselect
loot_gather()122Loot gathering
housing()123Housing
pack()124Pack up
unpack_and_attack()125Unpack and attack
off_map_trade()131Off-map trade
pickup_unit(transform_unit_id)132Pick up unit
speed_charge(work_value_1, work_value_2)133Speed charge
transform_unit()134Transform
kidnap_unit()135Kidnap
deposit_unit(transform_unit_id)136Deposit unit
shear()149Shear sheep
regeneration()150Regeneration

DE-Era Actions

MethodAction TypeDescription
resource_generation(...)151Passive resource income
movement_damage()152Damage while moving
moveable_drop_site()153Mobile drop site
pillage(...)154Loot/pillage
aura(...)155Area buff effect
additional_spawn(...)156Spawn extra units
stingers(...)157Stinger effects
hp_transformation(...)158Transform at HP threshold

Detailed Method Examples

combat(class_id=-1, **kwargs)

Makes the unit attack enemies.

ParameterTypeDefaultDescription
class_idint-1Target class (-1 = all)
python
# Attack all units
unit.add_task.combat()

# Attack only infantry
unit.add_task.combat(class_id=1)

garrison(class_id=-1, **kwargs)

Makes the unit able to garrison.

ParameterTypeDefaultDescription
class_idint-1Building class to garrison in
python
unit.add_task.garrison(class_id=11)  # Garrison in buildings

gather(resource_in=-1, resource_out=-1, **kwargs)

Makes the unit gather resources.

ParameterTypeDefaultDescription
resource_inint-1Resource type gathered
resource_outint-1Resource type returned
python
# Gather food
unit.add_task.gather(resource_in=0, resource_out=0)

heal(work_value_1=0.0, work_range=0.0, **kwargs)

Makes the unit heal allies.

ParameterTypeDefaultDescription
work_value_1float0.0Heal amount per tick
work_rangefloat0.0Heal range
python
unit.add_task.heal(work_value_1=1.0, work_range=4.0)

resource_generation(...)

Passive resource generation (Feitoria-style).

ParameterTypeDefaultDescription
amount_receivedfloat0.0Amount per tick
type_resource_receivedint-1Resource type (0=food, etc.)
productivity_resourceint-1Multiplier resource
target_unit_idint-1Target unit filter
target_class_idint-1Target class filter
python
# Generate 0.7 food per tick
unit.add_task.resource_generation(
    amount_received=0.7,
    type_resource_received=0,
)

# Generate all resources (Feitoria)
unit.add_task.resource_generation(amount_received=0.5, type_resource_received=0)
unit.add_task.resource_generation(amount_received=0.5, type_resource_received=1)
unit.add_task.resource_generation(amount_received=0.5, type_resource_received=2)
unit.add_task.resource_generation(amount_received=0.5, type_resource_received=3)

aura(...)

Area buff effect (like Centurion aura).

ParameterTypeDefaultDescription
attribute_idfloat0.0Attribute to buff
max_increasefloat0.0Maximum bonus
required_unitsfloat0.0Units needed
radiusfloat0.0Effect radius
affected_playersint0Diplomacy filter
proceeding_graphicint-1Visual effect
icon_idint0Icon
tooltip_shortint-1Short tooltip string ID
tooltip_longint-1Long tooltip string ID
flagsint0Behavior flags
python
# +10 attack aura in 4 tile radius
unit.add_task.aura(
    attribute_id=9,      # Attack
    max_increase=10,
    radius=4.0,
    affected_players=1,  # Allies
)

Managing Tasks

Get All Tasks

python
tasks = unit.get_tasks_list()
for task in tasks:
    print(f"Task {task.action_type}")

Get Single Task

python
task = unit.get_task(0)  # First task
print(f"Action: {task.action_type}")

Remove Task

python
unit.remove_task(0)  # Remove first task

TaskHandle Properties

PropertyTypeDescription
action_typeintTask action type
class_idintTarget class
unit_idintTarget unit ID
terrain_idintTarget terrain
resource_inintInput resource
resource_outintOutput resource
work_value_1floatWork parameter 1
work_value_2floatWork parameter 2
work_rangefloatWork range
enabledintTask enabled (0/1)
proceeding_graphicintVisual effect graphic
carry_checkintCarry check flag
search_wait_timefloatWait time between searches
combat_levelintCombat level/priority
unused_flagintAlias for combat_level (Genie Editor naming)
python
task = unit.get_task(0)
task.work_range = 8.0
task.enabled = 1
task.combat_level = 1  # Set combat priority

TasksManager Methods

Access tasks via unit.tasks:

remove_by_action_type(action_type)

Remove all tasks matching an action type.

ParameterTypeDescription
action_typeintAction type to remove

Returns: int - Number of tasks removed

python
# Remove all combat tasks
removed = unit.tasks.remove_by_action_type(7)
print(f"Removed {removed} combat tasks")

Released under the MIT License.