Proof-of-concept 'ending advantage' calculator.
This commit is contained in:
parent
34301174dd
commit
1fdedb9c2b
1 changed files with 87 additions and 0 deletions
|
@ -49,6 +49,92 @@
|
|||
[/event]
|
||||
#enddef
|
||||
|
||||
#define TURNS_OVER_ADVANTAGE
|
||||
[event]
|
||||
name=time over
|
||||
[lua]
|
||||
code=<<
|
||||
local function all_sides()
|
||||
local function f(s)
|
||||
local i = s.i
|
||||
s.i = i + 1
|
||||
return i
|
||||
end
|
||||
return f, { i = 1 }
|
||||
end
|
||||
local function total_cost(s)
|
||||
wesnoth.fire("store_unit", {
|
||||
{ "filter", {
|
||||
side = s,
|
||||
} },
|
||||
variable = "side_units",
|
||||
kill = "no",
|
||||
});
|
||||
wesnoth.fire("set_variable", { name = "total", value = "0", } );
|
||||
wesnoth.fire("set_variable", { name = "index", value = "0", } );
|
||||
wesnoth.fire("while", {
|
||||
{ "variable", {
|
||||
name = "index",
|
||||
less_than = "$side_units.length",
|
||||
} },
|
||||
{ "do", {
|
||||
{ "set_variable", {
|
||||
name = "total",
|
||||
add = "$side_units[$index].cost",
|
||||
} },
|
||||
{ "set_variable", {
|
||||
name = "index",
|
||||
add = "1",
|
||||
} },
|
||||
} },
|
||||
});
|
||||
wesnoth.fire("clear_variable", { name = "index", } );
|
||||
wesnoth.fire("clear_variable", { name = "side_units", } );
|
||||
local retval = wesnoth.get_variable("total");
|
||||
wesnoth.fire("clear_variable", { name = "total", } );
|
||||
return retval;
|
||||
end
|
||||
local income_factor = 5
|
||||
local levelup_factor = 5
|
||||
|
||||
local side_num = -1
|
||||
local income_score = -1
|
||||
local unit_score = -1
|
||||
local gold_score = -1
|
||||
local total_score = -1
|
||||
for side in all_sides() do
|
||||
local team = wesnoth.get_side(side)
|
||||
if team == nil then break end
|
||||
local income = team.total_income * income_factor
|
||||
local units = total_cost(side)
|
||||
-- Calc the total unit-score here
|
||||
--for i, unit in ipairs( wesnoth.get_units( { side = side } ) ) do
|
||||
-- units = units + 20 -- This is a random magic number that represents the unit's cost (badly)
|
||||
--end
|
||||
-- Up to here
|
||||
local total = units + team.gold + income
|
||||
if total > total_score then
|
||||
side_num = side
|
||||
income_score = income
|
||||
unit_score = units
|
||||
gold_score = team.gold
|
||||
total_score = total
|
||||
end
|
||||
end
|
||||
wesnoth.fire("message", { message =
|
||||
string.format("Side %d has the advantage with:\nIncome score %d\nUnit score %d\nGold %d\n\nGrand total %d",
|
||||
side_num,
|
||||
income_score,
|
||||
unit_score,
|
||||
gold_score,
|
||||
total_score),
|
||||
speaker = "narrator",
|
||||
image = "wesnoth-icon.png" })
|
||||
>>
|
||||
[/lua]
|
||||
[/event]
|
||||
#enddef
|
||||
|
||||
[era]
|
||||
id=era_default
|
||||
name= _ "Default"
|
||||
|
@ -62,6 +148,7 @@
|
|||
{multiplayer/factions/drakes-default.cfg}
|
||||
|
||||
{QUICK_4MP_LEADERS}
|
||||
{TURNS_OVER_ADVANTAGE}
|
||||
[/era]
|
||||
|
||||
[era]
|
||||
|
|
Loading…
Add table
Reference in a new issue