Detecting that a unit has changed army

Interesting mapping tools and mapping help.

Moderator: Morax

Detecting that a unit has changed army

Postby EntropyWins » 21 Aug 2018, 16:34

I have some map lua code where I have a `unit` object and I would like to tell if it has changed army.

What I have so far is `if unit.originalBuilder == nil then`. This works to distinguish player created unit from those that changed army, though has some false positives. Units created by the map will also not have an originalBuilder and the same goes for those created via the cheating menu. The same is presumably true for captured units. Is there a more sure way to tell if a unit has changed army?

The reason I'm asking is because of /viewtopic.php?f=53&t=16598. If there is a way to detect unit creation, then I don't need to bother with detecting if a unit has changed army or not.

My unit creation event thing is using entity ids to keep track of which units are new. The problem I'm running into is that the game changes the entity id when a unit changes army, which happens because the game creates a new unit object and just copies over a bunch of stuff. So I need to be able to tell if I'm dealing with such a copied object or not
Last edited by EntropyWins on 21 Aug 2018, 17:28, edited 2 times in total.
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins

Re: Detecting that a unit has been gifted

Postby FlyingThunder » 21 Aug 2018, 16:42

Hey, i cant help you im 99% sure that @Kyryl(Etherr) might be able to help you - maybe ask him on discord or slack :)?
[Hex5] to all: A smoking crater is all thats going to be left of you
FlyingThunder
Crusader
 
Posts: 44
Joined: 26 Mar 2014, 22:27
Location: Yes
Has liked: 14 times
Been liked: 4 times
FAF User Name: FlyingThunder

Re: Detecting that a unit has changed army

Postby Uveso » 21 Aug 2018, 18:08

originalBuilder will be set if the original builder gives his unit to another player.
It's used in case the player died and we need to give the units back to the original owner. (unitshareconditions)

So this is a helper variable because there is no other way to see who build the unit first.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: Detecting that a unit has changed army

Postby EntropyWins » 21 Aug 2018, 20:07

Thanks for explaining. That matches my findings. Using this flag does not work for owner changes via another mechanism such as via capture, and it does not work for owner changes of units created by the map or the cheat menu, since those never set originalBuilder.

Edit: wait, actually what you wrote is not correct. Units that have been gifted DO NOT have the originalBuilder field set, while those that have not been gifted do have it set. (Unless one of the things I wrote above is the case.) That does leave the question of how the unit is given back to the original owner. Could you point to the code that does that?
EntropyWins
Avatar-of-War
 
Posts: 113
Joined: 02 Oct 2016, 20:26
Has liked: 18 times
Been liked: 4 times
FAF User Name: EntropyWins

Re: Detecting that a unit has changed army

Postby Uveso » 21 Aug 2018, 23:25

This function is used to transfer units ownership:
https://github.com/FAForever/fa/blob/775b4b00ec0474dc112537c9938c081e0810cb3c/lua/SimUtils.lua#L59

BTW, the owner is stored inside "unit.oldowner" not in "unit.originalBuilder"
The variable "originalBuilder" is just the builder (engineer, ACU etc) that is building the unit and will be set on Fn "OnStartBeingBuilt" from unit.lua.

And this function returns units to its original owner at playerdead:
https://github.com/FAForever/fa/blob/28 ... n.lua#L605
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso


Return to Mapping

Who is online

Users browsing this forum: No registered users and 1 guest