Can we now assume all clients in MP have the same units loaded?

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
Luther
Posts: 128
Joined: July 28th, 2007, 5:19 pm
Location: USA

Can we now assume all clients in MP have the same units loaded?

Post by Luther »

I have an add-on called Random Units that randomly chooses recruits from all available unit types. In 1.14, the only way to do this without OOS is to include the unit WML in a custom [randomUnits_loadUnitTypes] tag and get the unit type ids from the resulting cfg. I was able to include units from both core and Era of Myths this way. You can see that code here.

In 1.15, EoM is not uploaded yet, so I tried adding Era of Magic instead. I found that EoMa unit types aren't actually loaded unless I create a game with that era. It seems that unit types are now loaded on a per scenario basis. It looks like the entire era gets loaded, not just the factions in that game. Does this now mean that all clients in a scenario have exactly the same units loaded? Would it now be MP-safe to put the keys from wesnoth.unit_types into an array, sort it, and pick unit types out of that?
bil
Posts: 7
Joined: July 21st, 2021, 9:01 am

Re: Can we now assume all clients in MP have the same units loaded?

Post by bil »

gfgtdf seems to have done it in the PYR_No_Preperation_Turn addon. Here's part of his script, in the lua/unit_selection.lua file.

Code: Select all

function unit_selection.get_unit_types(side)
	local pool_type = tostring(V.pyr_npt_unit_pool_type or "recruitable")
	if pool_type == "recruitable" then
		return unit_selection.get_unit_types_current_era()
	elseif pool_type == "advanceable" then
		return unit_selection.get_unit_types_current_era_and_advancemts()
	elseif pool_type == "all" then
		return unit_selection.get_unit_types_all()
	elseif pool_type == "original" then
		return unit_selection.get_unit_types_original(side)
In one playtest in mp, it feels like it does what you are asking.
Last edited by Pentarctagon on July 28th, 2021, 3:45 pm, edited 1 time in total.
Reason: [c]->[code]
Luther
Posts: 128
Joined: July 28th, 2007, 5:19 pm
Location: USA

Re: Can we now assume all clients in MP have the same units loaded?

Post by Luther »

That looks like it's a good find, but I'm down a huge rabbit hole trying to investigate it. For one thing, we're using two different Wesnoth versions, so nothing you find is guaranteed to work in 1.15. Currently, `wesnoth.game_config.mp_settings.mp_eras` is nil, so the method in that add-on isn't possible.
User avatar
Pentarctagon
Project Manager
Posts: 5496
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Can we now assume all clients in MP have the same units loaded?

Post by Pentarctagon »

I'd guess that it's essentially an effect of add-ons that aren't being used not being available during a game. So it would probably work most of the time, but there are also edge cases where it wouldn't work, for example if hosts had different versions of the add-ons being used.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2337
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Can we now assume all clients in MP have the same units loaded?

Post by Lord-Knightmare »

an effect of add-ons that aren't being used not being available during a game
The solutions to this were making the scenarios/modifications only allow the specific eras, or having some [resource] and [load_resource] tags to load in the units for that modification. Normally, it's the responsibility of UMC era authors to provide the [resource] file for their add-ons. An example can be seen in Ageless Era in 1.15.15.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Celtic_Minstrel
Developer
Posts: 2158
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Can we now assume all clients in MP have the same units loaded?

Post by Celtic_Minstrel »

I think the safe and generic way to do this would be to use wesnoth.sync.evaluate_multiple. With that you could get the list of possible unit types from all clients and take the intersection to produce a list guaranteed to not cause out-of-sync. I'm not sure whether it's necessary to do this, mind you. There are probably edge cases where it would make a difference.

I don't have time right now to write out (mostly-)working code that does the above, but if you can't figure it out yourself, perhaps I can do it later.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Luther
Posts: 128
Joined: July 28th, 2007, 5:19 pm
Location: USA

Re: Can we now assume all clients in MP have the same units loaded?

Post by Luther »

It seems to me that if different clients have different unit type lists, they could have any amount of other conflicting data, such as unit type stats. I don't see any way to ever protect against that, except by asking everyone to update their add-ons.
User avatar
Pentarctagon
Project Manager
Posts: 5496
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Can we now assume all clients in MP have the same units loaded?

Post by Pentarctagon »

The way to do that is either by having an addon_min_version set explicitly, or for 1.16 #5004 should be fixed so that mismatched versions aren't able to play with each other by default.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
Post Reply