CyUnit.convert()... eh?

Baldyr

"Hit It"
Joined
Dec 5, 2009
Messages
5,530
Location
Sweden
I'm trying to figure out what exactly CyUnit.convert() does. :confused: I guess it clones some attributes from one CyUnit instance to another, but which ones and how does it work? And what's the point of it all? (I would probably use it to "flip" units so that they appear to change owners. So create new units for the new owner, clone the units of the old owner, and finally kill off those units.)

I've tried searching the forums but the discussions on this topic only serve to confuse me further. So what about just a simple to-the-point explanation on the use of this particular method?

Oh, and also: What does CyUnit.setXY() do? (What are all those parameters supposed to do?) Can I use it to "teleport" a unit from one tile to another, or is it just some stuff to do with 3D models and the like?
 
Oh, and also: What does CyUnit.setXY() do? (What are all those parameters supposed to do?) Can I use it to "teleport" a unit from one tile to another

:yup:
But i think it's deactivated in PythonCallbackDefines.xml.
 
It is? :eek:
 
When you're trying to figure out exactly what some of these functions do, you should open up the SDK sources, and look in there. For CyUnit::convert(), I'd look at CvUnit::Convert() and see what the code actually does. I've done this quite a few times, no sense in guessing when the source code is available. Plus I think C++ is easier to read ;)
 
Ok, I'll do that then. But C++ makes much less sense to me than some people like to think. :p

I might end up posting the function here and ask you guys to explain it to me...
 
Alright, then. If I'm reading the code correctly, the convert() function clones the following unit attributes:
  • promotions
  • creation game turn
  • current damage level
  • moves left
  • level and XP
  • name
  • leader unit type (whatever that means)
  • something about being a transport/cargo
And lastly the kill() function is called (?) but only one (out of two) arguments are passed. What's up with that? Is the unit disbanded?
 
It's been a while since I messed with this and my SDK is heavily modified but if I remember correctly it works like this. Say you want to convert an Axeman to a Swordsman. First create the Swordsman than call Axeman.convert(Swordsman). The stuff that you listed is cloned to the Swordsman and then the Axeman is killed. The second variable passed to the kill function is a player ID and defaults to NO_PLAYER. This is used to indicate who killed the unit. Since the unit is being converted the default value is used.
 
Ok, so its used for changing unit types, then? But what about flipping a unit? Meaning that ownership reverts from one CyPlayer instance to another?

Or is there perhaps another method for changing owners?

Regarding the kill() function and its Python counterpart the kill() method: Does the -1 value work here also? (I suppose there is no default value here, so the value can't be omitted altogether.)
 
Any python functions that call a function in the SDK must always have the exact number of passed variables.
 
Any python functions that call a function in the SDK must always have the exact number of passed variables.
Yeah, I've noticed. But what about using the -1 value for the second argument? (I've grown accustomed to always using a valid PlayerType, but I'm not even sure what its good for.)
 
Yeah, I've noticed. But what about using the -1 value for the second argument? (I've grown accustomed to always using a valid PlayerType, but I'm not even sure what its good for.)

The only differences if you send -1 are that the python event 'unitKilled' is not called, unit kills statistics are not updated and you don't get the 'General what's-his-name was killed in battle' message.
 
Aha! :D
 
The same convert function will convert units between players. When you create the second unit, pass the second player; then convert, and all the other properties are copied to the new unit. I have used this in Dune Wars to represent a special ability of Fremen to steal units from other players. In this case, it happens as a possible combat result; if a Fremen defeats a steal-able unit in combat, there is an X% chance that the unit is converted to a (damaged) Fremen unit.
 
xienwolf, I think I found it. You're referring to CyUnit.doCommand(), right? But gifting only works as long as the unit is on a plot owned by the new owner, right?

davidlallen, thank you for confirming this. I've yet to test this myself.
 
Top Bottom