Created
September 5, 2025 13:10
-
-
Save bukowa/3bfa2b452d3bb1529f531eb6447d6307 to your computer and use it in GitHub Desktop.
script1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- clear the console output for a nice view | |
consul.console.clear() | |
-- shortcut for writing into consul console | |
function wr(x) | |
consul.console.write(x) | |
end | |
wr("how many alliances in battle?") | |
wr(bm:alliances():count()) | |
for i = 1, bm:alliances():count() do | |
local alliance = bm:alliances():item(i) | |
wr("alliance " .. i .. " has " .. alliance:armies():count() .. " armies") | |
for j = 1, alliance:armies():count() do | |
local army = alliance:armies():item(j) | |
wr(" army " .. j .. " has " .. army:units():count() .. " units") | |
-- create controller | |
local uc = army:create_unit_controller() | |
local unit_types = {} | |
for k = 1, army:units():count() do | |
local unit = army:units():item(k) | |
-- add each unit to the controller | |
uc:add_units(unit) | |
-- gather info for printing | |
local utype = unit:type() | |
local uname = unit:name() | |
local men_alive = unit:number_of_men_alive() | |
local men_start = unit:initial_number_of_men() | |
table.insert(unit_types, utype .. " (" .. uname .. ", " .. men_alive .. "/" .. men_start .. ")") | |
end | |
wr(" units: " .. table.concat(unit_types, ", ")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment