mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-05 23:16:17 +00:00
implement better faction detection (bug #19281)
Whenever default era is used the units should be placed for sure now, this was IMHO not guaranteed since the recruits are internally a std::set, so the first entry can change. In case that one or both of the players have another faction than the ones in the default era, none of the players gets the extra units. Support for Khalifate can and should IMHO be added (given a suggested set of units + locations).
This commit is contained in:
parent
fb5bc52c84
commit
478db11354
@ -64,24 +64,77 @@
|
||||
[event]
|
||||
name=prestart
|
||||
|
||||
[store_side]
|
||||
side=1
|
||||
variable=p1
|
||||
[/store_side]
|
||||
|
||||
[set_variables]
|
||||
name=p1_recruits
|
||||
[split]
|
||||
list=$p1.recruit
|
||||
separator=","
|
||||
key=type
|
||||
[/split]
|
||||
name=factions
|
||||
[value]
|
||||
{multiplayer/factions/drakes-default.cfg}
|
||||
{multiplayer/factions/knalgans-default.cfg}
|
||||
{multiplayer/factions/loyalists-default.cfg}
|
||||
{multiplayer/factions/northerners-default.cfg}
|
||||
{multiplayer/factions/rebels-default.cfg}
|
||||
{multiplayer/factions/undead-default.cfg}
|
||||
[/value]
|
||||
[/set_variables]
|
||||
|
||||
[lua]
|
||||
code=<<
|
||||
local factions = wesnoth.get_variable("factions")
|
||||
local dbms = wesnoth.require("~add-ons/Wesnoth_Lua_Pack/debug_utils.lua").dbms
|
||||
local function detect_faction(side_number)
|
||||
local helper = wesnoth.require("lua/helper.lua")
|
||||
for multiplayer_side in helper.child_range(factions, "multiplayer_side") do
|
||||
local function recruits_match()
|
||||
local count = 0
|
||||
for searched in string.gmatch(multiplayer_side.recruit, "[^%s,][^,]*") do
|
||||
count = count + 1
|
||||
local found = false
|
||||
for i, actual in ipairs(wesnoth.sides[side_number].recruit) do
|
||||
if searched == actual then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not found then return false end
|
||||
end
|
||||
return count == #wesnoth.sides[side_number].recruit
|
||||
end
|
||||
local function leader_matches()
|
||||
local actual = wesnoth.get_units({ canrecruit = true, side = side_number })[1]
|
||||
for searched in string.gmatch(multiplayer_side.leader, "[^%s,][^,]*") do
|
||||
if searched == actual.type then return true end
|
||||
end
|
||||
end
|
||||
if recruits_match() and leader_matches() then
|
||||
wesnoth.set_variable("p" .. tostring(side_number) .. "_faction", multiplayer_side.id)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
if detect_faction(1) then wesnoth.set_variable("detection_successful", detect_faction(2))
|
||||
else wesnoth.set_variable("detection_successful", false)
|
||||
end
|
||||
>>
|
||||
[/lua]
|
||||
|
||||
[fire_event]
|
||||
name=place_units
|
||||
[/fire_event]
|
||||
{CLEAR_VARIABLE factions}
|
||||
[/event]
|
||||
|
||||
[event]
|
||||
name=place_units
|
||||
[filter_condition]
|
||||
[variable]
|
||||
name=detection_successful
|
||||
equals=yes
|
||||
[/variable]
|
||||
[/filter_condition]
|
||||
|
||||
[switch]
|
||||
variable=p1_recruits[0].type
|
||||
variable=p1_faction
|
||||
[case]
|
||||
value=Drake Burner
|
||||
value=$factions.multiplayer_side[0].id
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
@ -137,7 +190,7 @@
|
||||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=Dwarvish Fighter
|
||||
value=$factions.multiplayer_side[1].id
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
@ -202,7 +255,7 @@
|
||||
[/case]
|
||||
|
||||
[case]
|
||||
value=Bowman
|
||||
value=$factions.multiplayer_side[2].id
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
@ -277,7 +330,7 @@
|
||||
[/case]
|
||||
|
||||
[case]
|
||||
value=Goblin Spearman
|
||||
value=$factions.multiplayer_side[3].id
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
@ -331,7 +384,7 @@
|
||||
[/case]
|
||||
|
||||
[case]
|
||||
value=Elvish Archer
|
||||
value=$factions.multiplayer_side[4].id
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
@ -388,7 +441,7 @@
|
||||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=Dark Adept
|
||||
value=$factions.multiplayer_side[5].id
|
||||
|
||||
[unit]
|
||||
x,y=23,3
|
||||
@ -468,29 +521,11 @@
|
||||
[/unit]
|
||||
[/case]
|
||||
[/switch]
|
||||
[/event]
|
||||
|
||||
[event]
|
||||
name=prestart
|
||||
|
||||
[store_side]
|
||||
side=2
|
||||
variable=p2
|
||||
[/store_side]
|
||||
|
||||
[set_variables]
|
||||
name=p2_recruits
|
||||
[split]
|
||||
list=$p2.recruit
|
||||
separator=","
|
||||
key=type
|
||||
[/split]
|
||||
[/set_variables]
|
||||
|
||||
[switch]
|
||||
variable=p2_recruits[0].type
|
||||
variable=p2_faction
|
||||
[case]
|
||||
value=Drake Burner
|
||||
value=$factions.multiplayer_side[0].id
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
@ -546,7 +581,7 @@
|
||||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=Dwarvish Fighter
|
||||
value=$factions.multiplayer_side[1].id
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
@ -611,7 +646,7 @@
|
||||
[/case]
|
||||
|
||||
[case]
|
||||
value=Bowman
|
||||
value=$factions.multiplayer_side[2].id
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
@ -686,7 +721,7 @@
|
||||
[/case]
|
||||
|
||||
[case]
|
||||
value=Goblin Spearman
|
||||
value=$factions.multiplayer_side[3].id
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
@ -740,7 +775,7 @@
|
||||
[/case]
|
||||
|
||||
[case]
|
||||
value=Elvish Archer
|
||||
value=$factions.multiplayer_side[4].id
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
@ -797,7 +832,7 @@
|
||||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=Dark Adept
|
||||
value=$factions.multiplayer_side[5].id
|
||||
|
||||
[unit]
|
||||
x,y=6,20
|
||||
|
Loading…
x
Reference in New Issue
Block a user