wl.bases

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

EditorGameBase

class wl.bases.EditorGameBase

Common functionality between Editor and Game.

map

(RO) The Map the game is played on.

players

(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.

get_immovable_description(immovable_name)
Parameters

immovable_name – the name of the immovable

Returns the ImmovableDescription for the named object.

(RO) The Immovable_description.

get_building_description(building_description.name)
Parameters

building_name – the name of the building

Returns the description for the given building.

(RO) The Building_description.

get_tribe_description(tribe_name)
Parameters

tribe_name – the name of the tribe

Returns the tribe description of the given tribe.

(RO) The Tribe_description.

get_ware_description(ware_description.name)
Parameters

ware_name – the name of the ware

Returns the ware description for the given ware.

(RO) The Ware_description.

get_worker_description(worker_description.name)
Parameters

worker_name – the name of the worker

Returs the worker desciption for the given worker.

(RO) The Worker_description.

get_resource_description(resource_name)
Parameters

resource_name – the name of the resource

Returns the resource description for the given resource.

(RO) The Resource_description.

get_terrain_description(terrain_name)
Parameters

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)
Parameters
  • 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)
Parameters
  • 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.

PlayerBase

class wl.bases.PlayerBase

The Base class for the Player objects in Editor and Game

number

(RO) The number of this Player.

tribe_name

(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

Parameters
  • 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.

Returns

wl.map.Flag object created or nil.

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

Start a road 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.

Parameters
  • 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”).

Returns

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.

Returns

a subclass of wl.map.Building

place_ship(field)

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

Parameters

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

Returns

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.

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

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

Returns

nil

get_workers(name)

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

Parameters

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

Returns

the number of wares

get_wares(name)

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

Parameters

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

Returns

the number of wares