# Workers¶

Workers are created in a warehouse or recruited by a building. Most workers will work in buildings, while special worker types will act as carriers or soldiers.

Widelands knows about the following worker types:

## Common Worker Properties¶

Workers are defined with Lua functions called new_<worker_type>_type{table}. The contents of table depend on the type of worker that you are defining. The common properties shared by all workers are:

name: A string containing the internal name of this worker.

descname: The translatable display name. Use pgettext to fetch the string.

helptext_script: The full path to the helptexts.lua script for this worker.

icon: The full path to the menu icon for this worker.

vision_range

The size of the radius that the worker sees.

buildcost

Optional. A table with the wares and workers used by warehouses to create this worker, containing warename - amount pairs, e.g.:

buildcost = { atlanteans_carrier = 1, hammer = 1 }

default_target_quantity:

Optional. An int defining the default target quantity for the worker’s tribe’s economy. Use this if the worker is produced by a production site rather than the warehouses. For example, default_target_quantity = 10

Note

This parameter has been shifted to tribes initialization in the current development version.**

experience

Optional. The amount of experience that the worker needs to gather in order to be transformend into a higher worker type. If becomes is defined, this needs to be set as well.

becomes

Optional. The name of the higher worker type that this worker will transform to after gaining enough experience. If experience is defined, this needs to be set as well.

animation_directory

Mandatory. The location of the animation png files.

animations:

A table containing all animations for this worker. Workers have an “idle” animation. They also have directional animations called “walk” and “walkload” which are defined with the help of add_walking_animations(), plus additional Animations used in their worker programs. The “idle” and “walk” animations are mandatory.

programs:

Optional. If the worker leaves the building to do his work, the Worker Programs that define which type of space or resource the worker has to find on the map in order to do his work, and what that work is, including any animations and sounds played.

ware_hotspot

Optional. The x, y coordinates for adjusting the placement of the ware being carried. The default value is {0, 15}. Increase x to shift the ware to the left and y to shift it upwards. For example:

ware_hotspot = { -2, 13 },

aihints

Optional. A list of hints for the AI. Can contain the following optional entries:

preciousness: How precious this worker is to each tribe. For example, { atlanteans = 0, empire = 1 }. You can use this for workers that are recruited.

Note

This parameter has been shifted to tribes initialization in the current development version.

For making the UI texts translateable, we also need to push/pop the correct textdomain.

Example:

push_textdomain("tribes")

dirname = path.dirname (__file__)

tribes:new_worker_type {
name = "frisians_baker",
-- TRANSLATORS: This is a worker name used in lists of workers
descname = pgettext("frisians_worker", "Baker"),
vision_range = 2,

buildcost = {
frisians_carrier = 1,
},

experience = 13,
becomes = "frisians_baker_master",

ware_hotspot = {0, 20},

spritesheets = {
walk = {
directory = dirname,
basename = "walk",
fps = 15,
frames = 10,
columns = 5,
rows = 2,
directional = true,
hotspot = {11, 23}
},
directory = dirname,
fps = 15,
frames = 10,
columns = 5,
rows = 2,
directional = true,
hotspot = {10, 26}
},
},
animations = {
idle = {
directory = dirname,
basename = "idle",
hotspot = {8, 23}
},
},
}

pop_textdomain()


## Help Texts¶

Each worker has a helptexts.lua script, which is located in the same directory as its init.lua script. The function in this file returns a text that is used for the worker by the Tribal Encyclopedia.

worker_helptext()

Returns a localized string with the helptext for this worker type. It needs to be fetched by pgettext, using <tribename>_worker as the message context. Example:

function worker_helptext()
-- TRANSLATORS: Helptext for a worker: Armorsmith
return pgettext("atlanteans_worker", "Produces armor for the soldiers.")
end