If there was a UnitCaptured event ...

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,725
Location
Near Portsmouth, UK
... would knowing the capturing unit, the captured unit and if the game core is going to kill the captured unit be enough?

Code:
GameEvents.UnitCaptured.add(function (iByPlayer, iByUnit, iCapturedPlayer, iCapturedUnit, bWillBeKilled)
    local pCapturingUnit = Players[iByPlayer]:GetUnitByID(iByUnit)
    local pCapturedUnit = Players[iCapturedPlayer]:GetUnitByID(iCapturedUnit)

    -- pCapturingUnit captured pCapturedUnit, at this point both units are still alive
    -- both units are currently on the same tile

    if (bWillBeKilled) then
        -- the game core will kill pCapturedUnit just after this function exits
    end
end
 
I can't think of anything else at the moment.
Neither can I, mainly because both units are still alive at the point I can inject the event - so if you do need anything (hit points, script data, unit class, etc, etc, etc) you can just pull the info direct from the units involved

How would it handle a Settler (which is converted to a worker)? I assume "kill" the settler and spawn a worker?

Depends which civ captures it - Barbs capture settlers as settlers.

All captures are actually "kill original unit and spawn a new one". The bWillBeKilled flag applies to things the game core considers not "acquirable", eg Great People, workboats, etc, which upon capture are always killed.
 
Ways to capture a unit

a) Combat unit moves onto civilian unit (workers, settlers, great people, religious units, etc)
b) Combat unit with appropriate promotion defeats unit (eg Prize Ships)
c) By trait
d) By belief (eg Heathen Conversion)

Any others?

Edit: c) only applies to naval units (ie Suliman in vanilla), as the German trait is actually "after killing a barb in a camp, there is a % chance of gaining a unit"
 
Though it really isn't an additional capturing scenario.
-- If there was an onUnitCaptured() event, we could give the unit's gold to the capturing player,
-- but there isn't, so it will just be lost
:mischief:
I wracked my little brain off and on all day trying to think if there was any scenario you had missed, and I can't think of any. Rescued units just fall into an alternative flavor of "a)", I believe: that was the only thing I thought you might have missed, until I thought it through further.
 
Should "capturing" a barb in a camp generate the event? To be consistent with naval units it should, but the problem is that by the time the event would fire the original barb unit is long gone, so the second unit in the parameters would either need to be -1, -1 or refer to the unit just created for the player (ie iCapturedPlayer == iByPlayer) with bWillBeKilled=false

An alternative would be to add a 6th parameter - iReason - that could take values to clarify how the unit was captured.
 
Ways to capture a unit

a) Combat unit moves onto civilian unit (workers, settlers, great people, religious units, etc)
b) Combat unit with appropriate promotion defeats unit (eg Prize Ships)
c) By trait
d) By belief (eg Heathen Conversion)

Any others?

Edit: c) only applies to naval units (ie Suliman in vanilla), as the German trait is actually "after killing a barb in a camp, there is a % chance of gaining a unit"
Suliman's method is actually 'b' since his trait gives prize ships to all his navalmelee units. So I am prabalby misunderstanding what you mean exactly in your edit if 'c' does not apply to Germany.
Should "capturing" a barb in a camp generate the event? To be consistent with naval units it should, but the problem is that by the time the event would fire the original barb unit is long gone, so the second unit in the parameters would either need to be -1, -1 or refer to the unit just created for the player (ie iCapturedPlayer == iByPlayer) with bWillBeKilled=false

An alternative would be to add a 6th parameter - iReason - that could take values to clarify how the unit was captured.
Really depends on how much work it is to add a 6th parameter (iReason) and whether there would be real 'value-return' on the extra time involved. I'm assuming you mean something like:
Code:
-1 = No Data
0 = From Promotion
1 = Civilian Capture
2 = Civilian Rescue
3 = Heathen Conversion
4 = Trait ability (ie, Bismarck)
 
Suliman's method is actually 'b' since his trait gives prize ships to all his navalmelee units.

"ie Suliman in vanilla" (that is, not the new improved G&K/BNW version - the original code is still available in the XML/DLL)
 
Really depends on how much work it is to add a 6th parameter (iReason)

Almost none. The event code has had to be added at 3 possibly 4 points anuway, and it's those places that determine the value in iReason. An extra event call would need to be added for the "pseudo-capture in camp" ... but I now know where that is, having already tracked it down!

(Think I've just "typed" myself into adding it ..."
 
Will be in v69 of my DLL

Code:
GameEvents.UnitCaptured.Add(function(iByPlayer, iByUnit, iCapturedPlayer, iCapturedUnit, bWillBeKilled, iReason)
  -- iReason -->
  --  0=Move - a unit moved onto an enemy unit and captured it
  --  1=Combat - a unit converted as a result of combat (only Prize Ships in the standard game)
  --  2=Trait (barb land) - a unit cleared a camp and 1 (or more) barbs joined up
  --  3=Trait (barb naval) - a naval unit converted a barb
  --  4=Belief (barb) - a missionary converted a barb

  -- Take care with iReason=2 as it's the only one where the captured unit already belongs to the capturing player
end)
 
Back
Top Bottom