Hooks
static bool BeforeCvUnit_buyCityState(CvUnit* self, bool& result);static void AfterCvUnit_buyCityState(CvUnit* self, bool& result);static bool ReplaceCvUnit_buyCityState(bool (*original)(CvUnit*), CvUnit* self);CivRegisterBefore<CivHooks::CvUnit_buyCityState>(host, &BeforeCvUnit_buyCityState);CivRegisterAfter<CivHooks::CvUnit_buyCityState>(host, &AfterCvUnit_buyCityState);CivRegisterReplace<CivHooks::CvUnit_buyCityState>(host, &ReplaceCvUnit_buyCityState);
Code
9509bool CvUnit::buyCityState()9510{9511 VALIDATE_OBJECT9512 CvPlot* pPlot = plot();95139514 if (!canBuyCityState(pPlot))9515 {9516 return false;9517 }95189519 // Improve relations with the Minor9520 PlayerTypes eMinor = pPlot->getOwner();9521 CvAssertMsg(eMinor != NO_PLAYER, "Trying to buy a city state and not in city state territory. This is bad. Please send slewis this with your last 5 autosaves and what changelist # you're playing.");95229523 if (eMinor != NO_PLAYER)9524 {9525 CvCity* pMinorCapital = GET_PLAYER(eMinor).getCapitalCity();9526 if (pMinorCapital)9527 {9528 pMinorCapital = NULL; // we shouldn't use this pointer because DoAcquire invalidates it9529 int iNumUnits, iCapitalX, iCapitalY;9530#if defined(MOD_GLOBAL_VENICE_KEEPS_RESOURCES)9531 // CvUnit::buyCityState() is only ever called via CvTypes::getMISSION_BUY_CITY_STATE(), so this MUST be a "Merchant of Venice" type unit9532 GET_PLAYER(eMinor).GetMinorCivAI()->DoAcquire(getOwner(), iNumUnits, iCapitalX, iCapitalY, MOD_GLOBAL_VENICE_KEEPS_RESOURCES);9533#else9534 GET_PLAYER(eMinor).GetMinorCivAI()->DoAcquire(getOwner(), iNumUnits, iCapitalX, iCapitalY);9535#endif9536 pMinorCapital = GC.getMap().plot(iCapitalX, iCapitalY)->getPlotCity();9537 if (pMinorCapital)9538 {9539 // reduce the resistence to 0 turns because we bought it fairly9540 pMinorCapital->ChangeResistanceTurns(-pMinorCapital->GetResistanceTurns());9541 }95429543 }9544 }95459546 if (getOwner() == GC.getGame().getActivePlayer())9547 {9548 DLLUI->AddUnitMessage(0, GetIDInfo(), getOwner(), true, GC.getEVENT_MESSAGE_TIME(), GetLocalizedText("TXT_KEY_VENETIAN_MERCHANT_BOUGHT_CITY_STATE"));9549 }95509551 if (pPlot->isActiveVisible(false))9552 {9553 auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(this));9554 gDLL->GameplayUnitActivate(pDllUnit.get());9555 }95569557 if (IsGreatPerson())9558 {9559 CvPlayer& kPlayer = GET_PLAYER(getOwner());9560#if defined(MOD_EVENTS_GREAT_PEOPLE)9561 kPlayer.DoGreatPersonExpended(getUnitType(), this);9562#else9563 kPlayer.DoGreatPersonExpended(getUnitType());9564#endif9565 }95669567 kill(true);95689569 return true;9570}