Simplified advantage calculator.
This commit is contained in:
parent
352009dbbb
commit
600e368f8c
1 changed files with 11 additions and 44 deletions
|
@ -55,45 +55,14 @@
|
|||
[lua]
|
||||
code=<<
|
||||
local function all_sides()
|
||||
local function f(s)
|
||||
local i = s.i
|
||||
s.i = i + 1
|
||||
return i
|
||||
local function f(s, i)
|
||||
i = i + 1
|
||||
local t = wesnoth.get_side(i)
|
||||
return t and i, t
|
||||
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;
|
||||
return f, nil, 0
|
||||
end
|
||||
|
||||
local income_factor = 5
|
||||
local levelup_factor = 5
|
||||
|
||||
|
@ -102,15 +71,13 @@
|
|||
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
|
||||
for side, team in all_sides() do
|
||||
local income = team.total_income * income_factor
|
||||
local units = total_cost(side)
|
||||
local units = 0
|
||||
-- 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
|
||||
for i, unit in ipairs( wesnoth.get_units { side = side } ) do
|
||||
units = units + unit.__cfg.cost
|
||||
end
|
||||
-- Up to here
|
||||
local total = units + team.gold + income
|
||||
if total > total_score then
|
||||
|
|
Loading…
Add table
Reference in a new issue