The wl.bases module contains Base functions on which the classes of wl.game and wl.editor are based. You will not need to create any of the functions in this module directly, but you might use their functionality via the child classes.

Module Classes


class wl.bases.EditorGameBase

Common functionality between Editor and Game.


(RO) The Map the game is played on.


(RO) An array with the defined players. The players are either of type wl.game.Player or wl.editor.Player.

In game, there might be less players then defined in wl.map.Map.player_slots because some slots might not be taken. Also note that for the same reason you cannot index this array with wl.bases.PlayerBase.number, but the players are ordered with increasing number in this array.

The editor always creates all players that are defined by the map.


immovable_name – the name of the immovable

Returns the ImmovableDescription for the named object.

(RO) The Immovable_description.


immovable_name – the name of the immovable

Returns whether the descriptions know about an ImmovableDescription for the named object.

(RO) true if the named immovable exists, false otherwise.


building_name – the name of the building

Returns the description for the given building.

(RO) The Building_description.


ship_name – the name of the ship

Returns the description for the given ship.

(RO) The Ship_description.


tribe_name – the name of the tribe

Returns the tribe description of the given tribe. Loads the tribe if it hasn’t been loaded yet.

(RO) The Tribe_description.


ware_name – the name of the ware

Returns the ware description for the given ware.

(RO) The Ware_description.


worker_name – the name of the worker

Returs the worker desciption for the given worker.

(RO) The Worker_description.


resource_name – the name of the resource

Returns the resource description for the given resource.

(RO) The Resource_description.


terrain_name – the name of the terrain

Returns a given terrain description for the given terrain.

(RO) The Terrain_description.

save_campaign_data(campaign_name, scenario_name, data)
  • campaign_name – the name of the current campaign, e.g. “empiretut” or “frisians”

  • scenario_name – the name of the current scenario, e.g. “emp04” or “fri03”

  • data – a table of key-value pairs to save

Saves information that can be read by other scenarios.

If an array is used, the data will be saved in the correct order. Arrays may not contain nil values. If the table is not an array, all keys have to be strings. Tables may contain subtables of any depth. Cyclic dependencies will cause Widelands to crash. Only tables/arrays, strings, integer numbers and booleans may be used as values.

read_campaign_data(campaign_name, scenario_name)
  • campaign_name – the name of the campaign, e.g. “empiretut” or “frisians”

  • scenario_name – the name of the scenario that saved the data, e.g. “emp04” or “fri03”

Reads information that was saved by another scenario. The data is returned as a table of key-value pairs. The table is not guaranteed to be in any particular order, unless it is an array, in which case it will be returned in the same order as it was saved. This function returns nil if the file cannot be opened for reading.


text – the text to display

Change the progress message on the loading screen. May be used from the init.lua files for tribe/world loading only.


class wl.bases.PlayerBase

The Base class for the Player objects in Editor and Game


(RO) The number of this Player.


(RO) The name of the tribe of this player.

place_flag(field[, force])

Builds a flag on a given field if it is legal to do so. If not, reports an error

  • field (wl.map.Field) – where the flag should be created

  • force (boolean) –

    If this is true then the map is created with pure force:

    • if there is an immovable on this field, it will be removed

    • if there are flags too close by to this field, they will be ripped

    • if the player does not own the territory, it is conquered for him.


wl.map.Flag object created or nil.

place_road(roadtype, f1, dir1, dir2, ...[, force=false])

Start a road or waterway at the given field, then walk the directions given. Places a flag at the last field.

If the last argument to this function is true the road will be created by force: all immovables in the way are removed and land is conquered.

  • roadtype (string) – ‘normal’, ‘busy’, or ‘waterway’

  • f1 (wl.map.Field) – fields to connect with this road

  • dirs (string) – direction, can be either (“r”, “l”, “br”, “bl”, “tr”, “tl”) or (“e”, “w”, “ne”, “nw”, “se”, “sw”).


the road created

place_building(name, field[, cs = false, force = false])

Immediately creates a building on the given field. The building starts out completely empty. If cs is set, the building is not created directly, instead a constructionsite for this building is placed.

If the force argument is set, the building is forced into existence: the same action is taken as for place_flag() when force is true. Additionally, all buildings that are too close to the new one are ripped.


a subclass of wl.map.Building


Places a ship for the player’s tribe, which will be owned by the player.


field (wl.map.Field) – where the ship should be placed.


The new ship that was created.

conquer(f[, radius=1])

Conquer this area around the given field if it does not belong to the player already. This will conquer the fields no matter who owns it at the moment.

  • f (wl.map.Field) – center field for conquering

  • radius (integer) – radius to conquer around. Default value makes this call conquer 7 fields




Returns the number of workers of this type in the players stock. This does not implement everything that HasWorkers offers.


name (string.) – name of the worker to get


the number of workers


Returns the number of wares of this type in the players stock. This does not implement everything that HasWorkers offers.


name (string.) – name of the worker to get


the number of wares