Difference between revisions of "LuaWML/Sides"

From The Battle for Wesnoth Wiki
(wesnoth.set_village_owner)
(Cleaning up documentation for 1.10)
Line 9: Line 9:
  
 
Teams are proxy tables with the following fields:
 
Teams are proxy tables with the following fields:
* '''side''': the side number {{DevFeature1.9}}
+
* '''side''': the side number
 
* '''gold''', '''village_gold''', '''base_income''': integers (read/write)
 
* '''gold''', '''village_gold''', '''base_income''': integers (read/write)
 
* '''total_income''': integer (read only)
 
* '''total_income''': integer (read only)
Line 15: Line 15:
 
* '''objectives_changed''': boolean (read/write)
 
* '''objectives_changed''': boolean (read/write)
 
* '''team_name''': string (read/write)
 
* '''team_name''': string (read/write)
* '''controller''': string (read/write) {{DevFeature1.9}}
+
* '''controller''': string (read/write)
 
''note: In networked multiplayer, the controller attribute is ambiguous. Be very careful or you have OOS errors.''
 
''note: In networked multiplayer, the controller attribute is ambiguous. Be very careful or you have OOS errors.''
* '''fog''': boolean (read) {{DevFeature1.9}}
+
* '''fog''': boolean (read)
* '''shroud''': boolean (read) {{DevFeature1.9}}
+
* '''shroud''': boolean (read)
* '''hidden''': boolean (read) {{DevFeature1.9}}
+
* '''hidden''': boolean (read)
* '''name''': string (read) {{DevFeature1.9}}
+
* '''name''': string (read)
* '''color''': string (read) {{DevFeature1.9}}
+
* '''color''': string (read)
 
* '''__cfg''': WML table (dump)
 
* '''__cfg''': WML table (dump)
  
Line 27: Line 27:
  
 
==== wesnoth.sides ====
 
==== wesnoth.sides ====
 
{{DevFeature1.9}}
 
  
 
This is not a function but a table indexed by side numbers. Its elements are the proxy tables returned by [[#wesnoth.get_side]].
 
This is not a function but a table indexed by side numbers. Its elements are the proxy tables returned by [[#wesnoth.get_side]].
Line 37: Line 35:
  
 
==== wesnoth.get_sides ====
 
==== wesnoth.get_sides ====
 
{{DevFeature1.9}}
 
  
 
Returns a table array containing proxy tables for these sides matching the passed [[StandardSideFilter]].
 
Returns a table array containing proxy tables for these sides matching the passed [[StandardSideFilter]].
Line 56: Line 52:
  
 
Gives ownership of the village at the given location to the given side (or remove ownership if none). Ownership is also removed if nil or 0 is passed for the third parameter, but no capture events are fired in this case.
 
Gives ownership of the village at the given location to the given side (or remove ownership if none). Ownership is also removed if nil or 0 is passed for the third parameter, but no capture events are fired in this case.
{{DevFeature1.9}}: An optional 4th parameter (boolean true|false, default: false) can be passed determining whether to fire any capture events. Previously, capture events were forcefully fired.
+
An optional 4th parameter (boolean true|false, default: false) can be passed determining whether to fire any capture events.
  
 
  wesnoth.set_village_owner(12, 15, 1)
 
  wesnoth.set_village_owner(12, 15, 1)
  
 
==== wesnoth.is_enemy ====
 
==== wesnoth.is_enemy ====
 
{{DevFeature1.9}}
 
  
 
Returns true if side A is enemy of side B, false otherwise.
 
Returns true if side A is enemy of side B, false otherwise.
Line 69: Line 63:
  
 
==== wesnoth.match_side ====
 
==== wesnoth.match_side ====
{{DevFeature1.9}}
 
  
 
Matches a side against a given [[StandardSideFilter]].
 
Matches a side against a given [[StandardSideFilter]].
Line 76: Line 69:
  
 
==== wesnoth.get_starting_location ====
 
==== wesnoth.get_starting_location ====
{{DevFeature1.9}}
 
  
 
  local loc = wesnoth.get_starting_location(1)
 
  local loc = wesnoth.get_starting_location(1)

Revision as of 16:09, 29 January 2012

This page describes the LuaWML functions and helpers for handling sides and villages.

wesnoth.get_side

Returns the team with given number.

local team = wesnoth.get_side(1)
team.gold = team.gold + 50

Teams are proxy tables with the following fields:

  • side: the side number
  • gold, village_gold, base_income: integers (read/write)
  • total_income: integer (read only)
  • objectives, user_team_name: translatable strings (read/write)
  • objectives_changed: boolean (read/write)
  • team_name: string (read/write)
  • controller: string (read/write)

note: In networked multiplayer, the controller attribute is ambiguous. Be very careful or you have OOS errors.

  • fog: boolean (read)
  • shroud: boolean (read)
  • hidden: boolean (read)
  • name: string (read)
  • color: string (read)
  • __cfg: WML table (dump)

The metatable of these proxy tables appears as "side".

wesnoth.sides

This is not a function but a table indexed by side numbers. Its elements are the proxy tables returned by #wesnoth.get_side.

local team = wesnoth.sides[1]
team.gold = team.gold + 50
wesnoth.message(string.format("%d sides", #wesnoth.sides))

wesnoth.get_sides

Returns a table array containing proxy tables for these sides matching the passed StandardSideFilter.

--set gold to 0 for all sides with a leader
local sides = wesnoth.get_sides({ {"has_unit", { canrecruit = true }} })
for i,v in ipairs(sides) do
    v.gold = 0
end

wesnoth.get_village_owner

Returns the side that owns the village at the given location.

local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1

wesnoth.set_village_owner

Gives ownership of the village at the given location to the given side (or remove ownership if none). Ownership is also removed if nil or 0 is passed for the third parameter, but no capture events are fired in this case. An optional 4th parameter (boolean true|false, default: false) can be passed determining whether to fire any capture events.

wesnoth.set_village_owner(12, 15, 1)

wesnoth.is_enemy

Returns true if side A is enemy of side B, false otherwise.

local enemy_flag = wesnoth.is_enemy(1, 3)

wesnoth.match_side

Matches a side against a given StandardSideFilter.

wesnoth.message(tostring(wesnoth.match_side(1, {{"has_unit", { type = "Troll" }}})))

wesnoth.get_starting_location

local loc = wesnoth.get_starting_location(1)
wesnoth.message(string.format("side 1 starts at (%u, %u)", loc[1], loc[2]))

helper.all_teams

Returns an iterator over teams that can be used in a for-in loop.

for team in helper.all_teams() do team.gold = 200 end