Hooks
static bool BeforeCvTeam_DoNowAtWarOrPeace(CvTeam* self, TeamTypes eTeam, bool bWar);static void AfterCvTeam_DoNowAtWarOrPeace(CvTeam* self, TeamTypes eTeam, bool bWar);static void ReplaceCvTeam_DoNowAtWarOrPeace(void (*original)(CvTeam*, TeamTypes, bool), CvTeam* self, TeamTypes eTeam, bool bWar);CivRegisterBefore<CivHooks::CvTeam_DoNowAtWarOrPeace>(host, &BeforeCvTeam_DoNowAtWarOrPeace);CivRegisterAfter<CivHooks::CvTeam_DoNowAtWarOrPeace>(host, &AfterCvTeam_DoNowAtWarOrPeace);CivRegisterReplace<CivHooks::CvTeam_DoNowAtWarOrPeace>(host, &ReplaceCvTeam_DoNowAtWarOrPeace);
Code
1451void CvTeam::DoNowAtWarOrPeace(TeamTypes eTeam, bool bWar)1452{1453 // Major is at war with a minor1454 if(isMinorCiv())1455 {1456 PlayerTypes eMinor;1457 for(int iMinorCivLoop = MAX_MAJOR_CIVS; iMinorCivLoop < MAX_CIV_PLAYERS; iMinorCivLoop++)1458 {1459 eMinor = (PlayerTypes) iMinorCivLoop;14601461 if(GET_PLAYER(eMinor).getTeam() == GetID())1462 {1463 if(GET_PLAYER(eMinor).isAlive())1464 {1465 if(bWar)1466 GET_PLAYER(eMinor).GetMinorCivAI()->DoNowAtWarWithTeam(eTeam);1467 else1468 GET_PLAYER(eMinor).GetMinorCivAI()->DoNowPeaceWithTeam(eTeam);1469 }1470 }1471 }1472 }14731474 if(bWar)1475 {1476 PlayerTypes eMinor;1477 PlayerTypes ePlayer;14781479 // Loop through players on this team1480 for(int iPlayerCivLoop = 0; iPlayerCivLoop < MAX_MAJOR_CIVS; iPlayerCivLoop++)1481 {1482 ePlayer = (PlayerTypes) iPlayerCivLoop;14831484 if(!GET_PLAYER(ePlayer).isAlive())1485 continue;14861487 if(GET_PLAYER(ePlayer).getTeam() != GetID())1488 continue;14891490 GET_PLAYER(ePlayer).SetDangerPlotsDirty();1491 GET_PLAYER(ePlayer).UpdateReligion();14921493 // ******************************1494 // Our minor civ allies declare war on eTeam1495 // ******************************14961497 FStaticVector<PlayerTypes, MAX_CIV_PLAYERS, true, c_eCiv5GameplayDLL, 0> veMinorAllies;1498 for(int iMinorCivLoop = MAX_MAJOR_CIVS; iMinorCivLoop < MAX_CIV_PLAYERS; iMinorCivLoop++)1499 {1500 eMinor = (PlayerTypes) iMinorCivLoop;15011502 // Must be alive1503 if(!GET_PLAYER(eMinor).isAlive())1504 continue;15051506 if(GET_PLAYER(eMinor).GetMinorCivAI()->IsAllies(ePlayer))1507 {1508 // Don't declare war on self! (just in case)1509 if(GET_PLAYER(eMinor).getTeam() != eTeam)1510 {1511 // Match war state1512#if defined(MOD_EVENTS_WAR_AND_PEACE)1513 GET_TEAM(GET_PLAYER(eMinor).getTeam()).DoDeclareWar(eMinor, false, eTeam, /*bDefensivePact*/ false, /*bMinorAllyPact*/ true);1514#else1515 GET_TEAM(GET_PLAYER(eMinor).getTeam()).DoDeclareWar(eTeam, /*bDefensivePact*/ false, /*bMinorAllyPact*/ true);1516#endif15171518 // Add to vector for notification sent out1519 veMinorAllies.push_back(eMinor);1520 }1521 }1522 }15231524 // Notifications about minor allies that join the war against a major civ1525 if(!veMinorAllies.empty())1526 {1527 if(!GET_TEAM(eTeam).isMinorCiv())1528 {1529 Localization::String strTemp;15301531 // Notification for us...allies got our back!1532 Localization::String strOurAlliesSummary = Localization::Lookup("TXT_KEY_MISC_YOUR_MINOR_ALLIES_DECLARED_WAR_SUMMARY");1533 strTemp = Localization::Lookup("TXT_KEY_MISC_YOUR_MINOR_ALLIES_DECLARED_WAR");1534 strTemp << GET_TEAM(eTeam).getName().GetCString();1535 CvString strOurAlliesMessage = strTemp.toUTF8();15361537 // Notification for players on the other team1538 Localization::String strTheirEnemiesSummary = Localization::Lookup("TXT_KEY_MISC_MINOR_ALLIES_DECLARED_WAR_ON_YOU_SUMMARY");1539 strTemp = Localization::Lookup("TXT_KEY_MISC_MINOR_ALLIES_DECLARED_WAR_ON_YOU");1540 strTemp << getName().GetCString();1541 CvString strTheirEnemiesMessage = strTemp.toUTF8();15421543 for(uint iMinorCivLoop = 0; iMinorCivLoop < veMinorAllies.size(); iMinorCivLoop++)1544 {1545 eMinor = veMinorAllies[iMinorCivLoop];1546 strTemp = Localization::Lookup(GET_TEAM(GET_PLAYER(eMinor).getTeam()).getName().GetCString());1547 strOurAlliesMessage = strOurAlliesMessage + "[NEWLINE]" + strTemp.toUTF8();1548 strTheirEnemiesMessage = strTheirEnemiesMessage + "[NEWLINE]" + strTemp.toUTF8();1549 }15501551 GET_PLAYER(ePlayer).GetNotifications()->Add(NOTIFICATION_WAR, strOurAlliesMessage, strOurAlliesSummary.toUTF8(), -1, -1, veMinorAllies.front(), eTeam);15521553 for(int iOtherPlayerCivLoop = 0; iOtherPlayerCivLoop < MAX_MAJOR_CIVS; iOtherPlayerCivLoop++)1554 {1555 PlayerTypes eOtherPlayer = (PlayerTypes) iOtherPlayerCivLoop;15561557 if(!GET_PLAYER(eOtherPlayer).isAlive())1558 continue;15591560 if(GET_PLAYER(eOtherPlayer).getTeam() != eTeam)1561 continue;15621563 GET_PLAYER(eOtherPlayer).GetNotifications()->Add(NOTIFICATION_WAR_ACTIVE_PLAYER, strTheirEnemiesMessage, strTheirEnemiesSummary.toUTF8(), -1, -1, veMinorAllies.front());1564 }15651566 }1567 }1568 }1569 }1570}