Get the side or faction of a unit

Get the side or faction of a unit

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
Zigaroula
Posts: 10
Joined: 10 Mar 2016, 17:46

Get the side or faction of a unit

Post by Zigaroula »

Hello everyone,

I am trying to develop a level editor that should work with most games created through SpringRTS engine. For this, I would like to sort the different units of the mod by faction/side. I got them all using UnitDefs, but there does not seem to be a field where I can get the side of a unit.

I saw that it is possible to get the side of an instance of a unit using Spring.GetTeamInfo along with Spring.GetUnitTeam, but this is only related to the team as chosen in the lobby and not to the unit itself.

So, here's my question : is there a way to get the side of a unit ?

For instance, in Kernel Panic 4.1, this piece of information is stored in the .fbi files located in the units folder (which is different for BA 7.50), but it does not seem accessible by a widget, and as I already said, I need to do something that can be used with most Spring mods.

Thanks in advance for your answers.
gajop
Moderator
Posts: 3047
Joined: 05 Aug 2009, 20:42

Re: Get the side or faction of a unit

Post by gajop »

Probably not possible trivially anymore since Spring.GetUnitLineage was removed. Specific games might have ways of differentiating between sides but it's not guaranteed. Note also that not all games have sides (e.g. ZK and afaik EVO have 1 side).

PS: Not sure if you are aware, but Scened exists and is an ingame level editor. There's also ZK Mission Editor that runs outside of Spring.
8611z
Posts: 169
Joined: 08 Jul 2015, 20:20

Re: Get the side or faction of a unit

Post by 8611z »

Hello. On https://springrts.com/wiki/Gamedev:UnitDefs is no way for the files in units\ folder to set the side of a unit. So there is no way to read it either.
There is no methode that always works.
What works with some mods:
a) The side might be contained in the unit names: UnitDefs[unitDefID].name -> "core_light_laser_tower"
Sadly there tend to be handful of units per mod where this does not work.
b) Begin with the starting unit of a mod (for example the Commander) and walk through its buildoptions. If the buildoption contains a factory or builder, walk through those buildoptions too. Each unit you encounter belongs to the same faction as the first unit.
This fails for units which are not built via 'normal' way.
User avatar
Silentwings
Moderator
Posts: 3696
Joined: 25 Oct 2008, 00:23

Re: Get the side or faction of a unit

Post by Silentwings »

One thing you can do, is look at the starting units of the game, construct the whole tree of what is buildable from them, and infer faction based on this. For many games (including BA) that will work reliably.

Apart from that, you have to rely on the game to provide the information in customParams, which unfortunately most games don't do.
User avatar
Jools
XTA Developer
Posts: 2814
Joined: 23 Feb 2009, 16:29

Re: Get the side or faction of a unit

Post by Jools »

In XTA, all commanders have a param called "side" in customparams. You could try to guess it from the name otherwise, or maybe even from the unitdefnumber, but I don't think those methods are foolproof. (For example, if the 4th character is a _, then the unit is usually core, but it doesn't really work). But those things have been used around before.
Zigaroula
Posts: 10
Joined: 10 Mar 2016, 17:46

Re: Get the side or faction of a unit

Post by Zigaroula »

Thank you all for those quick answers.

Unfortunately, I think I'll have to go through the whole construction tree starting from the starting units of each faction. This was one of my first ideas, but I hoped there was another way around.

I'll also look for Scened, this may be interesting.
Post Reply

Return to “Lua Scripts”