Hooks
static bool BeforeCvPlayerTrade_PlunderTradeRoute(CvPlayerTrade* self, int iTradeConnectionID, CvUnit* pUnit, bool& result);static void AfterCvPlayerTrade_PlunderTradeRoute(CvPlayerTrade* self, int iTradeConnectionID, CvUnit* pUnit, bool& result);static bool ReplaceCvPlayerTrade_PlunderTradeRoute(bool (*original)(CvPlayerTrade*, int, CvUnit*), CvPlayerTrade* self, int iTradeConnectionID, CvUnit* pUnit);CivRegisterBefore<CivHooks::CvPlayerTrade_PlunderTradeRoute>(host, &BeforeCvPlayerTrade_PlunderTradeRoute);CivRegisterAfter<CivHooks::CvPlayerTrade_PlunderTradeRoute>(host, &AfterCvPlayerTrade_PlunderTradeRoute);CivRegisterReplace<CivHooks::CvPlayerTrade_PlunderTradeRoute>(host, &ReplaceCvPlayerTrade_PlunderTradeRoute);
Code
3298#if defined(MOD_API_EXTENSIONS)3299bool CvPlayerTrade::PlunderTradeRoute(int iTradeConnectionID, CvUnit* pUnit)3300#else3301bool CvPlayerTrade::PlunderTradeRoute(int iTradeConnectionID)3302#endif3303{3304 CvGameTrade* pTrade = GC.getGame().GetGameTrade();3305 int iTradeConnectionIndex = pTrade->GetIndexFromID(iTradeConnectionID);33063307 CvAssertMsg(iTradeConnectionIndex >= 0, "iTradeConnectionIndex < 0");3308 if (iTradeConnectionIndex < 0)3309 {3310 return false;3311 }33123313 TradeConnection* pTradeConnection = &(pTrade->m_aTradeConnections[iTradeConnectionIndex]);3314#if defined(MOD_EVENTS_TRADE_ROUTE_PLUNDERED)3315 TradeConnectionType eConnectionType = pTradeConnection->m_eConnectionType;3316#endif3317 DomainTypes eDomain = pTradeConnection->m_eDomain;3318 PlayerTypes eOwningPlayer = pTradeConnection->m_eOriginOwner;3319 PlayerTypes eDestPlayer = pTradeConnection->m_eDestOwner;3320 TeamTypes eOwningTeam = GET_PLAYER(eOwningPlayer).getTeam();3321 TeamTypes eDestTeam = GET_PLAYER(eDestPlayer).getTeam();3322 CvPlot* pPlunderPlot = GC.getMap().plot(pTradeConnection->m_aPlotList[pTradeConnection->m_iTradeUnitLocationIndex].m_iX, pTradeConnection->m_aPlotList[pTradeConnection->m_iTradeUnitLocationIndex].m_iY);3323 int iDomainModifier = GetTradeConnectionDomainValueModifierTimes100(*pTradeConnection, YIELD_GOLD);33243325 // add trade connnection to broken list3326 GET_PLAYER(eOwningPlayer).GetTrade()->AddTradeConnectionWasPlundered(*pTradeConnection);33273328 CvCity* pOriginCity = NULL;3329 CvCity* pDestCity = NULL;3330 CvPlot* pPlot = GC.getMap().plot(pTradeConnection->m_iOriginX, pTradeConnection->m_iOriginY);3331 if (pPlot)3332 {3333 pOriginCity = pPlot->getPlotCity();3334 }3335 pPlot = GC.getMap().plot(pTradeConnection->m_iDestX, pTradeConnection->m_iDestY);3336 if (pPlot)3337 {3338 pDestCity = pPlot->getPlotCity();3339 }3340 CvAssertMsg(pOriginCity, "pOriginCity doesn't exist");3341 CvAssertMsg(pDestCity, "pDestCity doesn't exist");33423343 bool bEmptyResult = pTrade->EmptyTradeRoute(iTradeConnectionIndex);33443345 // if the trade route was not broken3346 if (!bEmptyResult)3347 {3348 return false;3349 }33503351#if defined(MOD_TRADE_ROUTE_SCALING)3352 int iPlunderGoldValue = GD_INT_GET(TRADE_ROUTE_BASE_PLUNDER_GOLD);3353#else3354 int iPlunderGoldValue = 100;3355#endif3356 iPlunderGoldValue *= 100 + iDomainModifier;3357 iPlunderGoldValue /= 100;3358 m_pPlayer->GetTreasury()->ChangeGold(iPlunderGoldValue);33593360 // do the floating popup3361 if (GC.getGame().getActivePlayer() == m_pPlayer->GetID())3362 {3363 char text[256] = {0};3364 sprintf_s(text, "[COLOR_YELLOW]+%d[ENDCOLOR][ICON_GOLD]", iPlunderGoldValue);3365#if defined(SHOW_PLOT_POPUP)3366 SHOW_PLOT_POPUP(pPlunderPlot, m_pPlayer->GetID(), text, 0.0f);3367#else3368 float fDelay = 0.0f;3369 DLLUI->AddPopupText(pPlunderPlot->getX(), pPlunderPlot->getY(), text, fDelay);3370#endif3371 CvString strBuffer;33723373#if defined(MOD_BUGFIX_UNITCLASS_NOT_UNIT)3374 strBuffer = GetLocalizedText("TXT_KEY_MISC_PLUNDERED_GOLD_FROM_IMP", iPlunderGoldValue, GC.getUnitInfo(GetTradeUnit(eDomain, m_pPlayer))->GetDescriptionKey());3375#else3376 if (eDomain == DOMAIN_LAND)3377 {3378 strBuffer = GetLocalizedText("TXT_KEY_MISC_PLUNDERED_GOLD_FROM_IMP", iPlunderGoldValue, "TXT_KEY_UNIT_CARAVAN");3379 }3380 else3381 {3382 strBuffer = GetLocalizedText("TXT_KEY_MISC_PLUNDERED_GOLD_FROM_IMP", iPlunderGoldValue, "TXT_KEY_UNIT_CARGO_SHIP");3383 }3384#endif3385 3386 DLLUI->AddMessage(0, m_pPlayer->GetID(), true, GC.getEVENT_MESSAGE_TIME(), strBuffer);3387 }33883389 // barbarians get a bonus unit out of the deal!3390 if (m_pPlayer->isBarbarian() && pPlot)3391 {3392 int iLoop = 0;3393 for(CvUnit* pLoopUnit = m_pPlayer->firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = m_pPlayer->nextUnit(&iLoop))3394 {3395 if (pLoopUnit->plot() == pPlunderPlot)3396 {3397 CvBarbarians::DoSpawnBarbarianUnit(pPlunderPlot, true, true);3398 break;3399 }3400 }3401 }34023403 // do the notification stuff3404 if (pOriginCity && pDestCity)3405 {3406 // send notification to owner player3407 CvNotifications* pNotifications = GET_PLAYER(eOwningPlayer).GetNotifications();3408 if(pNotifications)3409 {3410 Localization::String strSummary;3411 Localization::String strMessage;34123413 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADER_SUMMARY");3414 if (m_pPlayer->isBarbarian())3415 {3416 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADER_BARBARIAN");3417 strMessage << pOriginCity->getNameKey();3418 strMessage << pDestCity->getNameKey();3419 }3420 else if (GET_TEAM(eOwningTeam).isHasMet(m_pPlayer->getTeam()))3421 {3422 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADER_KNOWN");3423 if(GC.getGame().isGameMultiPlayer() && m_pPlayer->isHuman())3424 {3425 strMessage << m_pPlayer->getNickName();3426 }3427 else3428 {3429 strMessage << m_pPlayer->getNameKey();3430 }3431 strMessage << pOriginCity->getNameKey();3432 strMessage << pDestCity->getNameKey();3433 }3434 else3435 {3436 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADER_UNKNOWN");3437 strMessage << pOriginCity->getNameKey();3438 strMessage << pDestCity->getNameKey();3439 }34403441 pNotifications->Add(NOTIFICATION_TRADE_ROUTE_BROKEN, strMessage.toUTF8(), strSummary.toUTF8(), pPlunderPlot->getX(), pPlunderPlot->getY(), -1);3442 }34433444 if (!GET_PLAYER(eDestPlayer).isMinorCiv() && eOwningPlayer != eDestPlayer && eDestPlayer != m_pPlayer->GetID())3445 {3446 // send notification to destination player3447 pNotifications = GET_PLAYER(eDestPlayer).GetNotifications();3448 if (pNotifications)3449 {3450 Localization::String strSummary;3451 Localization::String strMessage;34523453 strSummary = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADEE_SUMMARY");3454 if (m_pPlayer->isBarbarian())3455 {3456 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADEE_BARBARIANS");3457 if(GC.getGame().isGameMultiPlayer() && GET_PLAYER(eOwningPlayer).isHuman())3458 {3459 strMessage << GET_PLAYER(eOwningPlayer).getNickName();3460 }3461 else3462 {3463 strMessage << GET_PLAYER(eOwningPlayer).getNameKey();3464 }3465 strMessage << pOriginCity->getNameKey();3466 strMessage << pDestCity->getNameKey();3467 }3468 else if (GET_TEAM(eDestTeam).isHasMet(m_pPlayer->getTeam()))3469 {3470 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADEE_KNOWN");3471 if(GC.getGame().isGameMultiPlayer() && m_pPlayer->isHuman())3472 {3473 strMessage << m_pPlayer->getNickName();3474 }3475 else3476 {3477 strMessage << m_pPlayer->getNameKey();3478 }34793480 if(GC.getGame().isGameMultiPlayer() && GET_PLAYER(eOwningPlayer).isHuman())3481 {3482 strMessage << GET_PLAYER(eOwningPlayer).getNickName();3483 }3484 else3485 {3486 strMessage << GET_PLAYER(eOwningPlayer).getNameKey();3487 }34883489 strMessage << pOriginCity->getNameKey();3490 strMessage << pDestCity->getNameKey();3491 }3492 else3493 {3494 strMessage = Localization::Lookup("TXT_KEY_NOTIFICATION_TRADE_UNIT_PLUNDERED_TRADEE_UNKNOWN");34953496 if(GC.getGame().isGameMultiPlayer() && GET_PLAYER(eOwningPlayer).isHuman())3497 {3498 strMessage << GET_PLAYER(eOwningPlayer).getNickName();3499 }3500 else3501 {3502 strMessage << GET_PLAYER(eOwningPlayer).getNameKey();3503 }35043505 strMessage << pOriginCity->getNameKey();3506 strMessage << pDestCity->getNameKey();3507 }35083509 pNotifications->Add(NOTIFICATION_TRADE_ROUTE_BROKEN, strMessage.toUTF8(), strSummary.toUTF8(), -1, -1, -1);3510 }3511 }3512 }35133514#if !defined(NO_ACHIEVEMENTS)3515 if (eDomain == DOMAIN_LAND && m_pPlayer->isHuman() && !GC.getGame().isGameMultiPlayer())3516 {3517 gDLL->UnlockAchievement(ACHIEVEMENT_XP2_28);3518 }3519#endif35203521#if defined(MOD_EVENTS_TRADE_ROUTE_PLUNDERED)3522 if (MOD_EVENTS_TRADE_ROUTE_PLUNDERED) {3523 GAMEEVENTINVOKE_HOOK(GAMEEVENT_PlayerPlunderedTradeRoute, pUnit->getOwner(), pUnit->GetID(), iPlunderGoldValue, pOriginCity->getOwner(), pOriginCity->GetID(), pDestCity->getOwner(), pDestCity->GetID(), eConnectionType, eDomain);3524 }3525#endif35263527 return true;3528}