CvPlayer::AddIncomingUnit(PlayerTypes, CvUnit *)
- Defined in
- CvPlayer.cpp, line 19668
- Class
- CvPlayer
- Hook name
CivHooks::CvPlayer_AddIncomingUnit- Changed in
- 0.5.0 (added hand-placed hook UnitReplaced)
Hand-placed hooks inside
A replacement for this function that does not call original stops these hooks from running.
Hooks
static bool BeforeCvPlayer_AddIncomingUnit(CvPlayer* self, PlayerTypes eFromPlayer, CvUnit* pUnit);static void AfterCvPlayer_AddIncomingUnit(CvPlayer* self, PlayerTypes eFromPlayer, CvUnit* pUnit);static void ReplaceCvPlayer_AddIncomingUnit(void (*original)(CvPlayer*, PlayerTypes, CvUnit*), CvPlayer* self, PlayerTypes eFromPlayer, CvUnit* pUnit);CivRegisterBefore<CivHooks::CvPlayer_AddIncomingUnit>(host, &BeforeCvPlayer_AddIncomingUnit);CivRegisterAfter<CivHooks::CvPlayer_AddIncomingUnit>(host, &AfterCvPlayer_AddIncomingUnit);CivRegisterReplace<CivHooks::CvPlayer_AddIncomingUnit>(host, &ReplaceCvPlayer_AddIncomingUnit);
Code
19667/// Someone sent us a present!19668void CvPlayer::AddIncomingUnit(PlayerTypes eFromPlayer, CvUnit* pUnit)19669{19670 UnitTypes eUnitType = pUnit->getUnitType();1967119672 // Gift to a minor civ for friendship19673 if(isMinorCiv() && eFromPlayer < MAX_MAJOR_CIVS)19674 {19675 CvAssertMsg(GetIncomingUnitType(eFromPlayer) == NO_UNIT, "Adding incoming unit when one is already on its way. Please send Anton your save file and version.");19676 CvAssertMsg(GetIncomingUnitCountdown(eFromPlayer) == -1, "Adding incoming unit when one is already on its way. Please send Anton your save file and version.");19677 if(GetIncomingUnitCountdown(eFromPlayer) == -1)19678 {19679 SetIncomingUnitCountdown(eFromPlayer, GC.getMINOR_UNIT_GIFT_TRAVEL_TURNS());19680 SetIncomingUnitType(eFromPlayer, eUnitType);19681 }1968219683 // Get rid of the old unit19684 pUnit->kill(true);19685 }19686 // Gift from minor civ to this major civ (ex. Austria UA, but NOT Militaristic unit spawning, that is handled elsewhere)19687 else if(!isMinorCiv() && GET_PLAYER(eFromPlayer).isMinorCiv())19688 {19689 int iX = pUnit->getX();19690 int iY = pUnit->getY();19691 UnitTypes eType = pUnit->getUnitType();19692#if defined(CIV_HOST_API)19693 const int iCivHostOldID = pUnit->GetID();19694#endif1969519696 // Get rid of the old unit19697 pUnit->kill(true);1969819699 // Add the new unit in its place19700 if(eType != NO_UNIT)19701 {19702 CvUnit* pNewUnit = initUnit(eType, iX, iY);19703#if defined(CIV_HOST_API)19704 if (pNewUnit)19705 CivHandUnitReplaced(eFromPlayer, iCivHostOldID, pNewUnit);hand-placed hook: UnitReplaced19706#endif19707 CvAssert(pNewUnit);19708 if (pNewUnit)19709#if defined(MOD_BUGFIX_MOVE_AFTER_PURCHASE)19710 {19711 if (!pUnit->getUnitInfo().CanMoveAfterPurchase())19712 {19713#endif19714 pNewUnit->finishMoves();19715#if defined(MOD_BUGFIX_MOVE_AFTER_PURCHASE)19716 }19717 }19718#endif19719 }19720 }19721 else19722 {19723 CvAssertMsg(false, "Unexpected case for adding an incoming unit for this player. Please send Anton your save file and version.");19724 }19725}
Calls
CivHandUnitReplaced- CvGlobals::getMINOR_UNIT_GIFT_TRAVEL_TURNS()
- CvPlayer::GetIncomingUnitCountdown(PlayerTypes) const
- CvPlayer::initUnit(UnitTypes, int, int, UnitAITypes, DirectionTypes, bool, bool, int, int)
- CvPlayer::isMinorCiv() const
- CvPlayer::SetIncomingUnitCountdown(PlayerTypes, int)
- CvPlayer::SetIncomingUnitType(PlayerTypes, UnitTypes)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvUnit::finishMoves()
- CvUnit::GetID() const
- CvUnit::getUnitInfo() const
- CvUnit::getUnitType() const
- CvUnit::getX() const
- CvUnit::getY() const
- CvUnit::kill(bool, PlayerTypes)
- CvUnitEntry::CanMoveAfterPurchase() const