CvUnit::createCaptureUnit(const CvUnitCaptureDefinition &)
- Defined in
- CvUnit.cpp, line 1919
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_createCaptureUnit- 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 BeforeCvUnit_createCaptureUnit(const CvUnitCaptureDefinition& kCaptureDef, CvUnit*& result);static void AfterCvUnit_createCaptureUnit(const CvUnitCaptureDefinition& kCaptureDef, CvUnit*& result);static CvUnit* ReplaceCvUnit_createCaptureUnit(CvUnit* (*original)(const CvUnitCaptureDefinition&), const CvUnitCaptureDefinition& kCaptureDef);CivRegisterBefore<CivHooks::CvUnit_createCaptureUnit>(host, &BeforeCvUnit_createCaptureUnit);CivRegisterAfter<CivHooks::CvUnit_createCaptureUnit>(host, &AfterCvUnit_createCaptureUnit);CivRegisterReplace<CivHooks::CvUnit_createCaptureUnit>(host, &ReplaceCvUnit_createCaptureUnit);
Code
1919/* static */ CvUnit* CvUnit::createCaptureUnit(const CvUnitCaptureDefinition& kCaptureDef)1920{1921 CvUnit* pkCapturedUnit = NULL;19221923 if(kCaptureDef.eCapturingPlayer != NO_PLAYER && kCaptureDef.eCaptureUnitType != NO_UNIT)1924 {1925 CvPlot* pkPlot = GC.getMap().plot(kCaptureDef.iX , kCaptureDef.iY);1926 if(pkPlot)1927 {1928 CvPlayerAI& kCapturingPlayer = GET_PLAYER(kCaptureDef.eCapturingPlayer);1929 if(kCapturingPlayer.isHuman() || kCapturingPlayer.AI_captureUnit(kCaptureDef.eCaptureUnitType, pkPlot) || 0 == GC.getAI_CAN_DISBAND_UNITS())1930 {1931 pkCapturedUnit = kCapturingPlayer.initUnit(kCaptureDef.eCaptureUnitType, kCaptureDef.iX, kCaptureDef.iY);19321933 if(pkCapturedUnit != NULL)1934 {1935 pkCapturedUnit->GetReligionData()->SetReligion(kCaptureDef.eReligion);1936 pkCapturedUnit->GetReligionData()->SetReligiousStrength(kCaptureDef.iReligiousStrength);1937 pkCapturedUnit->GetReligionData()->SetSpreadsLeft(kCaptureDef.iSpreadsLeft);19381939 pkCapturedUnit->SetOriginalOwner(kCaptureDef.eOriginalOwner);19401941#if defined(MOD_API_EXTENSIONS)1942 pkCapturedUnit->setScenarioData(kCaptureDef.iScenarioData);1943 1944 // If we have a great person, use their details1945 if (pkCapturedUnit->IsGreatPerson())1946 {1947 pkCapturedUnit->setName(kCaptureDef.sName);1948#if defined(MOD_GLOBAL_NO_LOST_GREATWORKS)1949 if (MOD_GLOBAL_NO_LOST_GREATWORKS && pkCapturedUnit->HasUnusedGreatWork())1950 {1951 CUSTOMLOG("Renaming a Great Writer, Artist or Musician who didn't create their Great Work (%s)", pkCapturedUnit->getGreatName().c_str());1952 GC.getGame().removeGreatPersonBornName(pkCapturedUnit->getGreatName());1953 }19541955 pkCapturedUnit->setGreatName(kCaptureDef.sGreatName);1956#endif1957 pkCapturedUnit->SetGreatWork(kCaptureDef.eGreatWork);1958 pkCapturedUnit->SetTourismBlastStrength(kCaptureDef.iTourismBlastStrength);1959 }1960#endif19611962 if(GC.getLogging() && GC.getAILogging())1963 {1964 CvString szMsg;1965 szMsg.Format("Captured: %s, Enemy was: %s", GC.getUnitInfo(kCaptureDef.eOldType)->GetDescription(), kCapturingPlayer.getCivilizationShortDescription());1966 GET_PLAYER(kCaptureDef.eOldPlayer).GetTacticalAI()->LogTacticalMessage(szMsg, true /*bSkipLogDominanceZone*/);1967 }19681969 if(kCaptureDef.bEmbarked)1970 {1971 auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(pkCapturedUnit));1972 gDLL->GameplayUnitEmbark(pDllUnit.get(), true);1973 pkCapturedUnit->setEmbarked(true);1974 if (!pkCapturedUnit->jumpToNearestValidPlot())1975 {1976 pkCapturedUnit->kill(true);1977 pkCapturedUnit = NULL;1978 }1979 }19801981 bool bDisbanded = false;1982 if (pkCapturedUnit != NULL)1983 {1984 pkCapturedUnit->finishMoves();19851986 // Minor civs can't capture settlers, ever!1987 if(!bDisbanded && GET_PLAYER(pkCapturedUnit->getOwner()).isMinorCiv() && (pkCapturedUnit->isFound() || pkCapturedUnit->IsFoundAbroad()))1988 {1989 bDisbanded = true;1990 pkCapturedUnit->kill(false);1991 pkCapturedUnit = NULL;1992 }1993 }19941995#if defined(CIV_HOST_API)1996 int iCivHostOldOwner = NO_PLAYER;1997 int iCivHostOldID = -1;1998 if(pkCapturedUnit != NULL && CivHostTakeCapturedFrom(&iCivHostOldOwner, &iCivHostOldID))1999 CivHandUnitReplaced(iCivHostOldOwner, iCivHostOldID, pkCapturedUnit);hand-placed hook: UnitReplaced2000#endif2001 // Captured civilian who could be returned?2002 if(!kCaptureDef.bAsIs)2003 {2004 bool bShowingHumanPopup = true;2005 bool bShowingActivePlayerPopup = true;20062007 // Only active player gets the choice2008 if(GC.getGame().getActivePlayer() != kCaptureDef.eCapturingPlayer)2009 {2010 bShowingActivePlayerPopup = false;2011 }20122013 // Original owner is dead!2014 if(!GET_PLAYER(kCaptureDef.eOriginalOwner).isAlive())2015 bShowingHumanPopup = false;20162017 // If original owner2018 else if(kCaptureDef.eOriginalOwner == kCaptureDef.eCapturingPlayer)2019 bShowingHumanPopup = false;20202021 // Players at war2022 else if(GET_TEAM(GET_PLAYER(kCaptureDef.eOriginalOwner).getTeam()).isAtWar(kCapturingPlayer.getTeam()))2023 bShowingHumanPopup = false;20242025 // Players haven't met2026 else if(!GET_TEAM(GET_PLAYER(kCaptureDef.eOriginalOwner).getTeam()).isHasMet(kCapturingPlayer.getTeam()))2027 bShowingHumanPopup = false;20282029 // Show the popup2030 if(bShowingHumanPopup && bShowingActivePlayerPopup && pkCapturedUnit)2031 {2032 CvPopupInfo kPopupInfo(BUTTONPOPUP_RETURN_CIVILIAN, kCaptureDef.eCapturingPlayer, kCaptureDef.eOriginalOwner, pkCapturedUnit->GetID());2033 DLLUI->AddPopup(kPopupInfo);2034 // We are adding a popup that the player must make a choice in, make sure they are not in the end-turn phase.2035 if (kCapturingPlayer.isLocalPlayer())2036 CancelActivePlayerEndTurn();2037 }20382039 // Take it automatically!2040 else if(!bShowingHumanPopup && !bDisbanded && pkCapturedUnit != NULL && !pkCapturedUnit->isBarbarian()) // Don't process if the AI decided to disband the unit, or the barbs captured something2041 {2042 // If the unit originally belonged to us, we've already done what we needed to do2043 if(kCaptureDef.eCapturingPlayer != kCaptureDef.eOriginalOwner)2044 kCapturingPlayer.DoCivilianReturnLogic(false, kCaptureDef.eOriginalOwner, pkCapturedUnit->GetID());2045 }2046 // if Venice2047 else if (kCapturingPlayer.GetPlayerTraits()->IsNoAnnexing())2048 {2049 // If the unit originally belonged to us, we've already done what we needed to do2050 if(kCaptureDef.eCapturingPlayer != kCaptureDef.eOriginalOwner)2051 kCapturingPlayer.DoCivilianReturnLogic(false, kCaptureDef.eOriginalOwner, pkCapturedUnit->GetID());2052 }2053 }2054 else2055 {2056 // restore combat units at some percentage of their original health2057 if (pkCapturedUnit != NULL)2058 {2059 int iCapturedHealth = (pkCapturedUnit->GetMaxHitPoints() * GC.getCOMBAT_CAPTURE_HEALTH()) / 100;2060 pkCapturedUnit->setDamage(iCapturedHealth);2061 }2062 }20632064 if(kCaptureDef.eCapturingPlayer == GC.getGame().getActivePlayer())2065 {2066 CvString strBuffer;2067 if(kCaptureDef.eOriginalOwner == kCaptureDef.eCapturingPlayer){2068 //player recaptured a friendly unit2069 strBuffer = GetLocalizedText("TXT_KEY_MISC_YOU_RECAPTURED_UNIT", GC.getUnitInfo(kCaptureDef.eCaptureUnitType)->GetTextKey());2070 }2071 else{2072 strBuffer = GetLocalizedText("TXT_KEY_MISC_YOU_CAPTURED_UNIT", GC.getUnitInfo(kCaptureDef.eCaptureUnitType)->GetTextKey());2073 }2074 DLLUI->AddUnitMessage(0, IDInfo(kCaptureDef.eCapturingPlayer, pkCapturedUnit->GetID()), kCaptureDef.eCapturingPlayer, true, GC.getEVENT_MESSAGE_TIME(), strBuffer/*, "AS2D_UNITCAPTURE", MESSAGE_TYPE_INFO, GC.getUnitInfo(eCaptureUnitType)->GetButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), pPlot->getX(), pPlot->getY()*/);2075 MILITARYLOG(kCaptureDef.eCapturingPlayer, strBuffer.c_str(), pkPlot, kCaptureDef.eOldPlayer);2076 }2077 }2078 }2079 }2080 }20812082 return pkCapturedUnit;2083}
Calls
- CancelActivePlayerEndTurn()
CivHandUnitReplacedCivHostTakeCapturedFrom- CustomMods::isAPI_PLAYER_LOGS()
- CustomMods::isGLOBAL_NO_LOST_GREATWORKS()
- CvBaseInfo::GetDescription() const
- CvBaseInfo::GetTextKey() const
- CvDllUnit::CvDllUnit(CvUnit *)
- CvGame::getActivePlayer() const
- CvGame::removeGreatPersonBornName(const CvString &)
- CvGlobals::getAI_CAN_DISBAND_UNITS()
- CvGlobals::getAILogging()
- CvGlobals::getCOMBAT_CAPTURE_HEALTH()
- CvGlobals::getDLLIFace()
- CvGlobals::GetEngineUserInterface()
- CvGlobals::getEVENT_MESSAGE_TIME()
- CvGlobals::getGame()
- CvGlobals::getLogging()
- CvGlobals::getMap()
- CvGlobals::getUnitInfo(UnitTypes)
- CvMap::plot(int, int) const
- CvPlayer::AddMilitaryEvent(const char *, CvPlot *, PlayerTypes, int, int, int, int)
- CvPlayer::DoCivilianReturnLogic(bool, PlayerTypes, int)
- CvPlayer::getCivilizationShortDescription() const
- CvPlayer::GetPlayerTraits() const
- CvPlayer::GetTacticalAI() const
- CvPlayer::getTeam() const
- CvPlayer::initUnit(UnitTypes, int, int, UnitAITypes, DirectionTypes, bool, bool, int, int)
- CvPlayer::isAlive() const
- CvPlayer::isHuman() const
- CvPlayer::isLocalPlayer() const
- CvPlayer::isMinorCiv() const
- CvPlayerAI::AI_captureUnit(UnitTypes, CvPlot *)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlayerTraits::IsNoAnnexing() const
CvPopupInfo::CvPopupInfoCvString::CvStringCvString::CvStringCvString::FormatCvString::formatCvString::operator const char *CvString::operator=- CvTacticalAI::LogTacticalMessage(CvString &, bool)
- CvTeam::getTeam(TeamTypes)
- CvTeam::isAtWar(TeamTypes) const
- CvTeam::isHasMet(TeamTypes) const
- CvUnit::finishMoves()
- CvUnit::getGreatName() const
- CvUnit::GetID() const
- CvUnit::GetMaxHitPoints() const
- CvUnit::getOwner() const
- CvUnit::GetReligionData() const
- CvUnit::HasUnusedGreatWork() const
- CvUnit::isBarbarian() const
- CvUnit::isFound() const
- CvUnit::IsFoundAbroad() const
- CvUnit::IsGreatPerson() const
- CvUnit::jumpToNearestValidPlot()
- CvUnit::kill(bool, PlayerTypes)
- CvUnit::setDamage(int, PlayerTypes, int, float, const CvString *)
- CvUnit::setEmbarked(bool)
- CvUnit::setGreatName(CvString)
- CvUnit::SetGreatWork(GreatWorkType)
CvUnit::setName- CvUnit::SetOriginalOwner(PlayerTypes)
- CvUnit::setScenarioData(int)
- CvUnit::SetTourismBlastStrength(int)
- CvUnitReligion::SetReligion(ReligionTypes)
- CvUnitReligion::SetReligiousStrength(int)
- CvUnitReligion::SetSpreadsLeft(int)
FILogFile::MsgFILogFileMgr::GetInstanceFILogFileMgr::GetLogGetLocalizedTextICvEngineUtility1::GameplayUnitEmbarkICvUserInterface1::AddPopupICvUserInterface1::AddUnitMessageIDInfo::IDInfostd::auto_ptr::auto_ptrstd::auto_ptr::getstd::basic_string::c_str