Make the multiplayer faction accessible via Lua and simplified Hornshark
Island
This commit is contained in:
parent
68e5e7d7dc
commit
a8f625fc8a
9 changed files with 41 additions and 63 deletions
|
@ -170,10 +170,12 @@ Version 1.13.4+dev:
|
|||
* abilities - list of the IDs of all abilities
|
||||
* Additional fields in table returned by wesnoth.get_terrain_info:
|
||||
* icon, editor_image, light
|
||||
* Additional fields in unit type proxu:
|
||||
* Additional fields in unit type proxy:
|
||||
* race, id, alignment
|
||||
* attacks, which returns the same thing as unit.attacks
|
||||
* abilities, same as unit.abilities
|
||||
* Additional field in side proxy:
|
||||
* faction (read-only), faction_name (read-only)
|
||||
* LuaAI:
|
||||
* The table returned by check_*() now has a "result" field which
|
||||
gives a description of the action's result; similar to "status"
|
||||
|
@ -205,6 +207,8 @@ Version 1.13.4+dev:
|
|||
should return a table with keys "own" and "enemy", each of which may
|
||||
be either a unit filter table or a function which takes a unit as a
|
||||
parameter and returns true or false.
|
||||
* Multiplayer:
|
||||
* Hornshark Island: simplified multiplayer faction determination
|
||||
* Wesnoth formula engine:
|
||||
* Formulas in unit filters can now access nearly all unit attributes
|
||||
The following attributes were renamed (old names still work, for now):
|
||||
|
|
|
@ -1269,6 +1269,9 @@
|
|||
[entry]
|
||||
name = "Maximilian Lupke (malumalu)"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Marius Spix (spixi)"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Michael Flowers (MJ)"
|
||||
[/entry]
|
||||
|
|
|
@ -65,18 +65,6 @@
|
|||
[event]
|
||||
name=prestart
|
||||
|
||||
[set_variables]
|
||||
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={./2p_Hornshark_Island_lua}
|
||||
[/lua]
|
||||
|
@ -93,7 +81,7 @@
|
|||
[switch]
|
||||
variable=p1_faction
|
||||
[case]
|
||||
value=$factions.multiplayer_side[0].id
|
||||
value=Drakes
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
|
@ -149,7 +137,7 @@
|
|||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=$factions.multiplayer_side[1].id
|
||||
value=Knalgan Alliance
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
|
@ -214,7 +202,7 @@
|
|||
[/case]
|
||||
|
||||
[case]
|
||||
value=$factions.multiplayer_side[2].id
|
||||
value=Loyalists
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
|
@ -289,7 +277,7 @@
|
|||
[/case]
|
||||
|
||||
[case]
|
||||
value=$factions.multiplayer_side[3].id
|
||||
value=Northerners
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
|
@ -343,7 +331,7 @@
|
|||
[/case]
|
||||
|
||||
[case]
|
||||
value=$factions.multiplayer_side[4].id
|
||||
value=Rebels
|
||||
|
||||
[unit]
|
||||
side=1
|
||||
|
@ -400,7 +388,7 @@
|
|||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=$factions.multiplayer_side[5].id
|
||||
value=Undead
|
||||
|
||||
[unit]
|
||||
x,y=23,3
|
||||
|
@ -553,7 +541,7 @@
|
|||
[switch]
|
||||
variable=p2_faction
|
||||
[case]
|
||||
value=$factions.multiplayer_side[0].id
|
||||
value=Drakes
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
|
@ -609,7 +597,7 @@
|
|||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=$factions.multiplayer_side[1].id
|
||||
value=Knalgan Alliance
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
|
@ -674,7 +662,7 @@
|
|||
[/case]
|
||||
|
||||
[case]
|
||||
value=$factions.multiplayer_side[2].id
|
||||
value=Loyalists
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
|
@ -749,7 +737,7 @@
|
|||
[/case]
|
||||
|
||||
[case]
|
||||
value=$factions.multiplayer_side[3].id
|
||||
value=Northerners
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
|
@ -803,7 +791,7 @@
|
|||
[/case]
|
||||
|
||||
[case]
|
||||
value=$factions.multiplayer_side[4].id
|
||||
value=Rebels
|
||||
|
||||
[unit]
|
||||
side=2
|
||||
|
@ -860,7 +848,7 @@
|
|||
[/unit]
|
||||
[/case]
|
||||
[case]
|
||||
value=$factions.multiplayer_side[5].id
|
||||
value=Undead
|
||||
|
||||
[unit]
|
||||
x,y=6,20
|
||||
|
|
|
@ -1,40 +1,8 @@
|
|||
<<
|
||||
local factions = wesnoth.get_variable("factions")
|
||||
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]
|
||||
|
||||
if actual then
|
||||
for searched in string.gmatch(multiplayer_side.leader, "[^%s,][^,]*") do
|
||||
if searched == actual.type then return true end
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
if recruits_match() and leader_matches() then
|
||||
wesnoth.set_variable("p" .. tostring(side_number) .. "_faction", multiplayer_side.id)
|
||||
return
|
||||
end
|
||||
end
|
||||
local function detect_factions()
|
||||
for i, side in ipairs(wesnoth.get_sides({})) do
|
||||
wesnoth.set_variable("p" .. tostring(i) .. "_faction", side.faction)
|
||||
end
|
||||
detect_faction(1)
|
||||
detect_faction(2)
|
||||
end
|
||||
detect_factions()
|
||||
>>
|
||||
|
|
|
@ -218,6 +218,8 @@ CALLABLE_WRAPPER_INPUT(hidden)
|
|||
CALLABLE_WRAPPER_INPUT(flag)
|
||||
CALLABLE_WRAPPER_INPUT(flag_icon)
|
||||
CALLABLE_WRAPPER_INPUT(team_name)
|
||||
CALLABLE_WRAPPER_INPUT(faction)
|
||||
CALLABLE_WRAPPER_INPUT(faction_name)
|
||||
CALLABLE_WRAPPER_INPUT(color)
|
||||
CALLABLE_WRAPPER_INPUT(share_vision)
|
||||
CALLABLE_WRAPPER_INPUT(carryover_bonus)
|
||||
|
|
|
@ -988,6 +988,7 @@ config side_engine::new_config() const
|
|||
// Merge the faction data to res.
|
||||
config faction = flg_.current_faction();
|
||||
res["faction_name"] = faction["name"];
|
||||
res["faction"] = faction["id"];
|
||||
faction.remove_attributes("id", "name", "image", "gender", "type");
|
||||
res.append(faction);
|
||||
}
|
||||
|
|
|
@ -68,6 +68,8 @@ static int impl_side_get(lua_State *L)
|
|||
return_string_attrib("flag_icon", t.flag_icon());
|
||||
return_tstring_attrib("user_team_name", t.user_team_name());
|
||||
return_string_attrib("team_name", t.team_name());
|
||||
return_string_attrib("faction", t.faction());
|
||||
return_tstring_attrib("faction_name", t.faction_name());
|
||||
return_string_attrib("color", t.color());
|
||||
return_cstring_attrib("controller", t.controller().to_string().c_str());
|
||||
return_string_attrib("defeat_condition", t.defeat_condition().to_string());
|
||||
|
@ -108,7 +110,7 @@ static int impl_side_set(lua_State *L)
|
|||
// Find the corresponding attribute.
|
||||
modify_int_attrib("gold", t.set_gold(value));
|
||||
modify_tstring_attrib("objectives", t.set_objectives(value, true));
|
||||
//maybe add a setterf for save_id too?
|
||||
//maybe add a setter for save_id too?
|
||||
modify_int_attrib("village_gold", t.set_village_gold(value));
|
||||
modify_int_attrib("village_support", t.set_village_support(value));
|
||||
modify_int_attrib("recall_cost", t.set_recall_cost(value));
|
||||
|
|
|
@ -83,6 +83,8 @@ team::team_info::team_info() :
|
|||
team_name(),
|
||||
user_team_name(),
|
||||
side_name(),
|
||||
faction(),
|
||||
faction_name(),
|
||||
save_id(),
|
||||
current_player(),
|
||||
countdown_time(),
|
||||
|
@ -122,6 +124,8 @@ void team::team_info::read(const config &cfg)
|
|||
team_name = cfg["team_name"].str();
|
||||
user_team_name = cfg["user_team_name"];
|
||||
side_name = cfg["side_name"];
|
||||
faction = cfg["faction"].str();
|
||||
faction_name = cfg["faction_name"];
|
||||
save_id = cfg["save_id"].str();
|
||||
current_player = cfg["current_player"].str();
|
||||
countdown_time = cfg["countdown_time"].str();
|
||||
|
@ -239,6 +243,8 @@ void team::team_info::write(config& cfg) const
|
|||
cfg["team_name"] = team_name;
|
||||
cfg["user_team_name"] = user_team_name;
|
||||
cfg["side_name"] = side_name;
|
||||
cfg["faction"] = faction;
|
||||
cfg["faction_name"] = faction_name;
|
||||
cfg["save_id"] = save_id;
|
||||
cfg["current_player"] = current_player;
|
||||
cfg["flag"] = flag;
|
||||
|
|
|
@ -117,6 +117,8 @@ private:
|
|||
std::string team_name;
|
||||
t_string user_team_name;
|
||||
t_string side_name;
|
||||
std::string faction;
|
||||
t_string faction_name;
|
||||
std::string save_id;
|
||||
// 'id' of the current player (not necessarily unique)
|
||||
std::string current_player;
|
||||
|
@ -303,6 +305,8 @@ public:
|
|||
void set_flag_icon(const std::string& flag_icon) { info_.flag_icon = flag_icon; }
|
||||
|
||||
const std::string& side_name() const { return info_.side_name.empty() ? info_.current_player : info_.side_name.str(); }
|
||||
const std::string& faction() const { return info_.faction; }
|
||||
const t_string& faction_name() const { return info_.faction_name; }
|
||||
//Returns true if the hex is shrouded/fogged for this side, or
|
||||
//any other ally with shared vision.
|
||||
bool shrouded(const map_location& loc) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue