Currently Online

Latest Posts

Topic: How can I iterate over all conquered player buildings, his tribe not know?

MarkMcWire
Avatar
Joined: 2017-02-08, 21:06
Posts: 294
Ranking
Tribe Member
Location: Eisenach, Germany
Posted at: 2021-07-30, 18:07

How can I iterate (in Lua) over all buildings from a player, his tribe not know.

Problem is, this code:

    for i, tbuilding in ipairs(player.tribe.buildings) do
       for j, building in ipairs(player:get_buildings(tbuilding.name)) do


don't work, if I search buildings that a player conquered in the game but are not part of his tribe.

I wouldn't iterate over all immovable object on map, because this takes a long time.

My widelands project: https://github.com/widelands/wl_addons_server/tree/master/addons/europeans_tribe.wad

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2016
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2021-07-30, 22:59

you may have a look at data/scripting/win_conditions/win_condition_functions.lua I used p.allowed_buildings there for this purpose.


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2098
Ranking
One Elder of Players
Location: Germany
Posted at: 2021-07-30, 23:52

Since only military buildings get conquered you may create a list of all military buildings of all players. And then compare the buildings owner.

For gathering military buildings names i've done similar in my auto_soldiers addon: https://github.com/widelands/wl_addons_server/blob/master/addons/auto_soldiers_cs.wad/init.lua#L188


Top Quote