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.
Get the side or faction of a unit
Moderator: Moderators
Re: Get the side or faction of a unit
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.
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.
Re: Get the side or faction of a unit
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.
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.
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Get the side or faction of a unit
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.
Apart from that, you have to rely on the game to provide the information in customParams, which unfortunately most games don't do.
Re: Get the side or faction of a unit
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.
Re: Get the side or faction of a unit
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.
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.