dont make 4mp leader quick in campaigns by default

making 4mp leader automaticly quick is unexpected for a campaigns
designer. And the intention is make it easier to port sp campaigns to
mp.
To do this i ported the quick4 mp leader code to lua.

I also moved the lua code from eras.cfg to a new file eras.lua, this
makes is easier for an editor to detect lua syntax highlichting
automaticly.
This commit is contained in:
gfgtdf 2015-06-16 01:57:44 +02:00
parent 219bb24b30
commit 634d29020f
2 changed files with 101 additions and 129 deletions

View file

@ -16,64 +16,12 @@
[event]
name=prestart
[store_unit]
[filter]
canrecruit=yes
[filter_wml]
max_moves=4
[/filter_wml]
[/filter]
kill=yes
variable=leaders_to_make_quick
[/store_unit]
{FOREACH leaders_to_make_quick i}
[if]
# The variable check is done here instead of in the [store_unit]
# so that all boolean values work
[variable]
name=leaders_to_make_quick[$i].variables.dont_make_me_quick
boolean_equals=yes
[/variable]
[then]
[unstore_unit]
variable=leaders_to_make_quick[$i]
[/unstore_unit]
[/then]
[else]
[set_variables]
name=temp
[literal]
{TRAIT_QUICK}
[/literal]
[/set_variables]
[set_variables]
name=leaders_to_make_quick[$i].modifications.trait
mode=append
[insert_tag]
name=literal
variable=temp.trait
[/insert_tag]
[/set_variables]
{CLEAR_VARIABLE leaders_to_make_quick[$i].max_moves,leaders_to_make_quick[$i].moves,leaders_to_make_quick[$i].max_hitpoints,leaders_to_make_quick[$i].hitpoints}
[unstore_unit]
variable=leaders_to_make_quick[$i]
[/unstore_unit]
[/else]
[/if]
{NEXT i}
{CLEAR_VARIABLE leaders_to_make_quick,temp}
[lua]
code = << wesnoth.require("multiplayer/eras.lua").quick_4mp_leaders(...) >>
[args]
{TRAIT_QUICK}
[/args]
[/lua]
[/event]
#enddef
@ -81,77 +29,7 @@
[event]
name=time over
[lua]
# wmllint: markcheck off
code=<<
local show_turns_over_advantage = wesnoth.get_variable("show_turns_over_advantage")
if show_turns_over_advantage == nil then
show_turns_over_advantage = wesnoth.game_config.mp_settings and (wesnoth.game_config.mp_settings.mp_campaign == "")
end
if not show_turns_over_advantage then
return
end
local _ = wesnoth.textdomain "wesnoth-multiplayer"
local function all_sides()
local function f(s, i)
i = i + 1
local t = wesnoth.sides[i]
return t and i, t
end
return f, nil, 0
end
local income_factor = 5
local side_num = -1
local total_score = -1
local side_comparison = ""
for side, team in all_sides() do
repeat -- ugly hack to convert 'break' into 'continue'
if team.__cfg.hidden then
break
end
local r, g, b = 255, 255, 255
if team.__cfg.color == 1 then r, g, b = 255, 0, 0
elseif team.__cfg.color == 2 then r, g, b = 0, 0, 255
elseif team.__cfg.color == 3 then r, g, b = 0, 255, 0
elseif team.__cfg.color == 4 then r, g, b = 155, 48, 255
elseif team.__cfg.color == 5 then r, g, b = 0, 0, 0
elseif team.__cfg.color == 6 then r, g, b = 165, 42, 42
elseif team.__cfg.color == 7 then r, g, b = 255, 165, 0
elseif team.__cfg.color == 8 then r, g, b = 255, 255, 255
elseif team.__cfg.color == 9 then r, g, b = 0, 128, 128 end
if # wesnoth.get_units( { side = side } ) == 0 then
side_comparison = side_comparison ..
string.format( tostring( _ "<span strikethrough='true' foreground='#%02x%02x%02x'>Side %d</span>") .. "\n",
r, g, b, side)
break
end
local income = team.total_income * income_factor
local units = 0
-- Calc the total unit-score here
for i, unit in ipairs( wesnoth.get_units { side = side } ) do
if not unit.__cfg.canrecruit then
wesnoth.fire("unit_worth", { id = unit.id })
units = units + wesnoth.get_variable("unit_worth")
end
end
-- Up to here
local total = units + team.gold + income
side_comparison = side_comparison ..
string.format( tostring( _ "<span foreground='#%02x%02x%02x'>Side %d</span>: Income score = %d Unit score = %d Gold = %d") .. "\n" .. tostring( _ "Grand total: <b>%d</b>") .. "\n",
r, g, b, side, income, units, team.gold, total)
if total > total_score then
color = string.format("#%02x%02x%02x", r, g, b)
side_num = side
total_score = total
end
until true -- end ugly hack
end
side_comparison = side_comparison ..
string.format( "\n" .. tostring( _ "<span foreground='%s'>Side %d</span> has the advantage."), color, side_num)
wesnoth.fire("message", { message = side_comparison, speaker = "narrator", image = "wesnoth-icon.png"})
>>
# wmllint: markcheck on
code = << wesnoth.require("multiplayer/eras.lua").turns_over_advantage() >>
[/lua]
[/event]
#enddef

94
data/multiplayer/eras.lua Normal file
View file

@ -0,0 +1,94 @@
local helper = wesnoth.require "lua/helper.lua"
local T = helper.set_wml_tag_metatable {}
local res = {}
res.quick_4mp_leaders = function(args)
local make_4mp_leaders_quick = wesnoth.get_variable("make_4mp_leaders_quick")
if make_4mp_leaders_quick == nil then
make_4mp_leaders_quick = wesnoth.game_config.mp_settings and (wesnoth.game_config.mp_settings.mp_campaign == "")
end
if not make_4mp_leaders_quick then
return
end
local tratit_quick = args[1][2]
for i, unit in ipairs(wesnoth.get_units { canrecruit = true, T.filter_wml { max_moves = 4 } }) do
if not unit.variables.dont_make_me_quick then
wesnoth.add_modification(unit, "trait", tratit_quick )
unit.moves = unit.max_moves
unit.hitpoints = unit.max_hitpoints
end
end
end
res.turns_over_advantage = function()
local show_turns_over_advantage = wesnoth.get_variable("show_turns_over_advantage")
if show_turns_over_advantage == nil then
show_turns_over_advantage = wesnoth.game_config.mp_settings and (wesnoth.game_config.mp_settings.mp_campaign == "")
end
if not show_turns_over_advantage then
return
end
local _ = wesnoth.textdomain "wesnoth-multiplayer"
local function all_sides()
local function f(s, i)
i = i + 1
local t = wesnoth.sides[i]
return t and i, t
end
return f, nil, 0
end
local income_factor = 5
local side_num = -1
local total_score = -1
local side_comparison = ""
for side, team in all_sides() do
repeat -- ugly hack to convert 'break' into 'continue'
if team.__cfg.hidden then
break
end
local r, g, b = 255, 255, 255
if team.__cfg.color == 1 then r, g, b = 255, 0, 0
elseif team.__cfg.color == 2 then r, g, b = 0, 0, 255
elseif team.__cfg.color == 3 then r, g, b = 0, 255, 0
elseif team.__cfg.color == 4 then r, g, b = 155, 48, 255
elseif team.__cfg.color == 5 then r, g, b = 0, 0, 0
elseif team.__cfg.color == 6 then r, g, b = 165, 42, 42
elseif team.__cfg.color == 7 then r, g, b = 255, 165, 0
elseif team.__cfg.color == 8 then r, g, b = 255, 255, 255
elseif team.__cfg.color == 9 then r, g, b = 0, 128, 128 end
if # wesnoth.get_units( { side = side } ) == 0 then
side_comparison = side_comparison ..
string.format( tostring( _ "<span strikethrough='true' foreground='#%02x%02x%02x'>Side %d</span>") .. "\n",
r, g, b, side)
break
end
local income = team.total_income * income_factor
local units = 0
-- Calc the total unit-score here
for i, unit in ipairs( wesnoth.get_units { side = side } ) do
if not unit.__cfg.canrecruit then
wesnoth.fire("unit_worth", { id = unit.id })
units = units + wesnoth.get_variable("unit_worth")
end
end
-- Up to here
local total = units + team.gold + income
side_comparison = side_comparison ..
string.format( tostring( _ "<span foreground='#%02x%02x%02x'>Side %d</span>: Income score = %d Unit score = %d Gold = %d") .. "\n" .. tostring( _ "Grand total: <b>%d</b>") .. "\n",
r, g, b, side, income, units, team.gold, total)
if total > total_score then
color = string.format("#%02x%02x%02x", r, g, b)
side_num = side
total_score = total
end
until true -- end ugly hack
end
side_comparison = side_comparison ..
string.format( "\n" .. tostring( _ "<span foreground='%s'>Side %d</span> has the advantage."), color, side_num)
wesnoth.fire("message", { message = side_comparison, speaker = "narrator", image = "wesnoth-icon.png"})
end
return res