beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
224 stars 102 forks source link

Add a system to allow selection of non-owned units #567

Open GoogleFrog opened 1 year ago

GoogleFrog commented 1 year ago

A lot of RTS engines allow the selection of enemy and allied units. Usually this just gives the player an expanded tooltip for the unit, but it can also be used for game mechanics. For example, a bounty system for a FFA mode would be cleanest to implement by selecting enemies and clicking buttons on the UI to configure how much bounty you want to pay. Selecting some allied units could also be good for team games.

LuaUI can probably hack enemy selection in at the moment, but it would be fragile and involve essentially reimplementing the concept of selection. Engine support would be more robust. Selecting enemies prettymuch already works when spectating, or with /godmode enabled. The engine would be good for:

Responsibility for legal selection shouldn't be left up to luaUI, as it is user-space rather than game mechanics-space.

Setting a selection filter could look something like this: Spring.SetUnitSelectable(unitID, playerID, canSelect, visionMask, canCommand, canSeeCommands)

The vision mask and command visibility toggle should be luaRules-side because there is potential for widgets to hack information out of selecting unseen enemies. Once a unit is allowed to be selected, further filtering can happen in luaUI with widget:SelectionChanged. Eg the engine will allow mixed selections of allied and enemy units, but games can implement selection filtering in luaUI.

Spectators could even use this system of commanding "enemy" units. Eg, some meme tournament could let spectators have a subtle effect on units to support their favorite player. This could be done with luarules messages, but why do that when commands already exist.

sprunk commented 1 year ago

Some commentary:

GoogleFrog commented 1 year ago

I wrote down the idea that led to this feature request: https://zero-k.info/Forum/Thread/36119?postID=256736

GoogleFrog commented 7 months ago

perhaps there's room for gadget:AllowUnitSelect(unitID, playerID) that works the same way AllowUnitCommand does ... gadget:AllowUnitRead

I think it would be better to let luarules set some fairly powerful filters, rather than use callins. LuaUI might want to rapidly read or mess with what is selected. Going through luarules each time that happens seems like a lot of overhead, and I can't imagine a scenario when it would be required over filtering. Remember, fancy stuff like selection filtering shouldn't be in luarules, that can be done in luaUI once luarules determines what is even legal.

icexuick commented 7 months ago

Would be handy for selecting a group/army of an ally and ask to get/give/sell the selected allied units.

Might be a bad idea, but we're recently exploring a "unit market" widget where you can select your own units and offer them for 'sale'. Allies can then decide to buy units, and will transfer them if the buyer has enough resources.

Other way around, asking to buy, could be interesting here.