Hooks
static bool BeforeCvMinorCivAI_DoTeamDeclaredWarOnMe(CvMinorCivAI* self, TeamTypes eEnemyTeam);static void AfterCvMinorCivAI_DoTeamDeclaredWarOnMe(CvMinorCivAI* self, TeamTypes eEnemyTeam);static void ReplaceCvMinorCivAI_DoTeamDeclaredWarOnMe(void (*original)(CvMinorCivAI*, TeamTypes), CvMinorCivAI* self, TeamTypes eEnemyTeam);CivRegisterBefore<CivHooks::CvMinorCivAI_DoTeamDeclaredWarOnMe>(host, &BeforeCvMinorCivAI_DoTeamDeclaredWarOnMe);CivRegisterAfter<CivHooks::CvMinorCivAI_DoTeamDeclaredWarOnMe>(host, &AfterCvMinorCivAI_DoTeamDeclaredWarOnMe);CivRegisterReplace<CivHooks::CvMinorCivAI_DoTeamDeclaredWarOnMe>(host, &ReplaceCvMinorCivAI_DoTeamDeclaredWarOnMe);
Code
10327/// eTeam declared war on us10328void CvMinorCivAI::DoTeamDeclaredWarOnMe(TeamTypes eEnemyTeam)10329{10330 CvTeam* pEnemyTeam = &GET_TEAM(eEnemyTeam);10331 CivsList veMinorsNowWary;10332 int iRand;1033310334 // Since eEnemyTeam was the aggressor, drop the base influence to the minimum10335 for(int iEnemyMajorLoop = 0; iEnemyMajorLoop < MAX_MAJOR_CIVS; iEnemyMajorLoop++)10336 {10337 PlayerTypes eEnemyMajorLoop = (PlayerTypes) iEnemyMajorLoop;10338 if(!GET_PLAYER(eEnemyMajorLoop).isAlive())10339 continue;10340 if(GET_PLAYER(eEnemyMajorLoop).getTeam() != eEnemyTeam)10341 continue; 1034210343 //antonjs: consider: forcibly revoke PtP here instead, and have negative INF / broken PtP fallout10344 10345 SetFriendshipWithMajor(eEnemyMajorLoop, GC.getMINOR_FRIENDSHIP_AT_WAR());10346 }1034710348 //antonjs: todo: xml, rename xml to indicate it is for WaryOf, not Permanent War10349 // Minor Civ Warmonger10350 if(pEnemyTeam->IsMinorCivWarmonger())10351 {10352 if(!IsWaryOfTeam(eEnemyTeam))10353 {10354 SetWaryOfTeam(eEnemyTeam, true);10355 veMinorsNowWary.push_back(GetPlayer()->GetID());10356 }10357 if(ENABLE_PERMANENT_WAR)10358 SetPermanentWar(eEnemyTeam, true);10359 }10360 // Minor Civ Aggressor - chance of permanent war10361 else if(pEnemyTeam->IsMinorCivAggressor())10362 {10363 iRand = GC.getGame().getJonRandNum(100, "MINOR CIV AI: Become Wary Of aggressor roll.");1036410365 if(iRand < /*50*/ GC.getPERMANENT_WAR_AGGRESSOR_CHANCE())10366 {10367 if(!IsWaryOfTeam(eEnemyTeam))10368 {10369 SetWaryOfTeam(eEnemyTeam, true);10370 veMinorsNowWary.push_back(GetPlayer()->GetID());10371 }10372 if(ENABLE_PERMANENT_WAR)10373 SetPermanentWar(eEnemyTeam, true);10374 }10375 }1037610377 // See if other minors will declare war10378 if(pEnemyTeam->IsMinorCivAggressor())10379 {10380 int iChance;1038110382 PlayerProximityTypes eProximity;1038310384 int iAttackingMajorPlayer;10385 PlayerTypes eAttackingMajorPlayer;10386 bool bAttackerIsAlly;1038710388 CvPlayer* pOtherMinorCiv;10389 PlayerTypes eOtherMinorCiv;10390 for(int iMinorCivLoop = MAX_MAJOR_CIVS; iMinorCivLoop < MAX_CIV_PLAYERS; iMinorCivLoop++)10391 {10392 eOtherMinorCiv = (PlayerTypes) iMinorCivLoop;10393 pOtherMinorCiv = &GET_PLAYER((eOtherMinorCiv));1039410395 iChance = 0;1039610397 // Must be alive10398 if(!pOtherMinorCiv->isAlive())10399 continue;1040010401 // Must be a different minor10402 if(eOtherMinorCiv == GetPlayer()->GetID())10403 continue;1040410405 // Ignore minors that want THIS minor dead10406 if(pOtherMinorCiv->GetMinorCivAI()->IsWantsMinorDead(GetPlayer()->GetID()))10407 continue;1040810409 bAttackerIsAlly = false;1041010411 // Ignore minors that are allied to the attacker10412 for(iAttackingMajorPlayer = 0; iAttackingMajorPlayer < MAX_MAJOR_CIVS; iAttackingMajorPlayer++)10413 {10414 eAttackingMajorPlayer = (PlayerTypes) iAttackingMajorPlayer;1041510416 // Not on this team10417 if(GET_PLAYER(eAttackingMajorPlayer).getTeam() != eEnemyTeam)10418 continue;1041910420 // Not alive10421 if(!GET_PLAYER(eAttackingMajorPlayer).isAlive())10422 continue;1042310424 if(pOtherMinorCiv->GetMinorCivAI()->GetAlly() == eAttackingMajorPlayer)10425 {10426 bAttackerIsAlly = true;10427 break;10428 }10429 }1043010431 if(bAttackerIsAlly)10432 continue;1043310434 // Closer to the minor the more likely war is10435 eProximity = pOtherMinorCiv->GetProximityToPlayer(GetPlayer()->GetID());1043610437 // Warmonger10438 if(pEnemyTeam->IsMinorCivWarmonger())10439 {10440 if(eProximity == PLAYER_PROXIMITY_DISTANT)10441 iChance += /*25*/ GC.getPERMANENT_WAR_OTHER_WARMONGER_CHANCE_DISTANT();10442 else if(eProximity == PLAYER_PROXIMITY_FAR)10443 iChance += /*50*/ GC.getPERMANENT_WAR_OTHER_WARMONGER_CHANCE_FAR();10444 else if(eProximity == PLAYER_PROXIMITY_CLOSE)10445 iChance += /*75*/ GC.getPERMANENT_WAR_OTHER_WARMONGER_CHANCE_CLOSE();10446 else if(eProximity == PLAYER_PROXIMITY_NEIGHBORS)10447 iChance += /*100*/ GC.getPERMANENT_WAR_OTHER_WARMONGER_CHANCE_NEIGHBORS();10448 }10449 // Aggressor10450 else10451 {10452 if(eProximity == PLAYER_PROXIMITY_DISTANT)10453 iChance += /*0*/ GC.getPERMANENT_WAR_OTHER_CHANCE_DISTANT();10454 else if(eProximity == PLAYER_PROXIMITY_FAR)10455 iChance += /*0*/ GC.getPERMANENT_WAR_OTHER_CHANCE_FAR();10456 else if(eProximity == PLAYER_PROXIMITY_CLOSE)10457 iChance += /*20*/ GC.getPERMANENT_WAR_OTHER_CHANCE_CLOSE();10458 else if(eProximity == PLAYER_PROXIMITY_NEIGHBORS)10459 iChance += /*50*/ GC.getPERMANENT_WAR_OTHER_CHANCE_NEIGHBORS();10460 }1046110462 // If the minor is already at war, then there's a chance of it turning into permanent war10463 if(GET_TEAM(pOtherMinorCiv->getTeam()).isAtWar(eEnemyTeam))10464 iChance += /*50*/ GC.getPERMANENT_WAR_OTHER_AT_WAR();1046510466 iRand = GC.getGame().getJonRandNum(100, "MINOR CIV AI: Third party minor to become Wary Of aggressor roll.");10467 if(iRand < iChance)10468 {10469 if(!pOtherMinorCiv->GetMinorCivAI()->IsWaryOfTeam(eEnemyTeam))10470 {10471 pOtherMinorCiv->GetMinorCivAI()->SetWaryOfTeam(eEnemyTeam, true);10472 veMinorsNowWary.push_back(eOtherMinorCiv);10473 }10474 if(ENABLE_PERMANENT_WAR)10475 pOtherMinorCiv->GetMinorCivAI()->SetPermanentWar(eEnemyTeam, true);10476 }10477 }10478 }1047910480 if(veMinorsNowWary.size() > 0)10481 {10482 int iMinimumFriendshipMod = 20; //antonjs: todo: xml10483 Localization::String strTemp;1048410485 strTemp = Localization::Lookup("TXT_KEY_NOTIFICATION_MINORS_NOW_WARY");10486 CvString strSummary = strTemp.toUTF8();10487 strTemp = Localization::Lookup("TXT_KEY_NOTIFICATION_MINORS_NOW_WARY_TT");10488 strTemp << iMinimumFriendshipMod;10489 CvString strMessage = strTemp.toUTF8();1049010491 for(int iEnemyMajorLoop = 0; iEnemyMajorLoop < MAX_MAJOR_CIVS; iEnemyMajorLoop++)10492 {10493 PlayerTypes eEnemyMajorLoop = (PlayerTypes) iEnemyMajorLoop;10494 if(!GET_PLAYER(eEnemyMajorLoop).isAlive())10495 continue;10496 if(GET_PLAYER(eEnemyMajorLoop).getTeam() != eEnemyTeam)10497 continue;1049810499 strMessage = strMessage + GetNamesListAsString(veMinorsNowWary);10500 AddNotification(strMessage, strSummary, eEnemyMajorLoop);10501 }10502 }1050310504 GC.GetEngineUserInterface()->setDirty(GameData_DIRTY_BIT, true);10505}