OK, using Tony Evans's SwapCity function, I've got this little handler that makes AI civs surrender rather than fighting to the last city:
For one thing, I had to use Martin's technique of creating a Bomber unit to expose the city and then disbanding the unit after the city has been swapped to the human player. (Otherwise, I could only swap cities that the capturing player already knows about.) But it doesn't work as well here as it does in GoodMod. There's no real problem except that there can be 10 or 20 sec lag while the computer executes.
The other thing is the triggering condition "MilitaryRank(player[0])-MilitaryRank(player[1])>25". The MilitaryRank function is, IMO, a bit weird. I think it must take Advances into account as well as existing military units, so that although your armies can have overwhelming military superiority on the ground, your enemy's MilitaryRank may not be that much lower than yours.
So if anybody wants to play with this and try to optimize it, you're welcome to it. Cause I have to get back to Diplomacy.
Code:
// Swaps City to Player. Kills all units first if flag is set to 1. int_f SwapCity (city_t swCity, int_t swPlayer, int_t killUnits) { int_t i; int_t tmpPlayer; int_t numUnits; unit_t tmpUnit; city_t tmpCity; location_t tmpLoc; tmpCity = swCity; if (CityIsValid(tmpCity)) { tmpPlayer = swPlayer; tmpLoc = tmpCity.location; numUnits = GetUnitsAtLocation(tmpLoc); if (killUnits == 1) { for (i = 0; i < numUnits; i = i + 1) { // Kill all units GetUnitFromCell(tmpLoc, i, tmpUnit); Event: DisbandUnit(tmpUnit); } } Event:GiveCity(tmpCity, tmpPlayer); } else { return -1;// Can't swap due to invalid city } } HandleEvent(CaptureCity) 'CivSurrenders' pre { city_t tmpCity; int_t i; int_t numCities; int_t numUnits; unit_t tmpUnit; if ( IsHumanPlayer(player[0]) ){//what about AI? player[1]=city[0].owner; numUnits=player[1].units; TMP_PLAYER=player[1]; TMP_CITY=city[0]; if( MilitaryRank(player[0])-MilitaryRank(player[1])>25) { for (i=0;i< numUnits;i=i+1 ){//first, kill his civilians GetUnitByIndex(TMP_PLAYER,i,tmpUnit); if (tmpUnit.valid && IsCivilian(tmpUnit) ) { Event: DisbandUnit(tmpUnit); } } numCities=PlayerCityCount(TMP_PLAYER); for (i = 0; i < numCities; i = i + 1) {//then take his cities GetCityByIndex(TMP_PLAYER, i, tmpCity); if (tmpCity.location != city[0].location ){ CreateUnit(player[0], UnitDB(UNIT_BOMBER), city[0].location, 1, tmpUnit); SwapCity(tmpCity, player[0].owner, 1); Event: DisbandUnit(tmpUnit); } } } EnableTrigger('SurrenderMessages'); } } HandleEvent(CaptureCity) 'SurrenderMessages' post { player[1]=TMP_PLAYER; city[0]=TMP_CITY; if( MilitaryRank(player[0])-MilitaryRank(player[1])>25 ){ Message(player[0].owner, 'SurrenderMessage'); } elseif( MilitaryRank(player[0])-MilitaryRank(player[1])>20 ){ Message(player[0].owner, 'OverwhelmingSuperiority'); } elseif( MilitaryRank(player[0])-MilitaryRank(player[1])>15 ){ Message(player[0].owner, 'MajorSuperiority'); } elseif (MilitaryRank(player[0])>MilitaryRank(player[1]) ){ Message(player[0].owner, 'MilitarySuperiority'); } DisableTrigger('SurrenderMessages'); } messagebox 'SurrenderMessage' { show(); Text (ID_TheSurrenderMessage) ; } //TheSurrenderMessage "Sire! We've won! With the capture of {city[0].name}, {player[1].civ_name_singular} resistence has //totally collapsed and they have agreed to an unconditional surrender!" messagebox 'OverwhelmingSuperiority' { Text (ID_OverwhelmingSuperiorityM) ; show(); } //OverwhelmingSuperiorityM "With the capture of {city[0].name}, our generals are pleased to report that we have //obtained overwhelming military superiority over the {player[1].civ_name_plural}. Victory is at hand!" messagebox 'MajorSuperiority' { show(); Text (ID_MajorSuperiorityM) ; } //MajorSuperiorityM "Sire, our generals report that the war is going very well. // \n They believe that we are now significantly stronger than the {player[1].civ_name_plural}." messagebox 'MilitarySuperiority' { show(); Text (ID_MilitarySuperiorityM) ; } //MilitarySuperiorityM "Sire, our generals report that the war with the {player[1].civ_name_plural} is going well. //We have gained the upper hand."
The other thing is the triggering condition "MilitaryRank(player[0])-MilitaryRank(player[1])>25". The MilitaryRank function is, IMO, a bit weird. I think it must take Advances into account as well as existing military units, so that although your armies can have overwhelming military superiority on the ground, your enemy's MilitaryRank may not be that much lower than yours.
So if anybody wants to play with this and try to optimize it, you're welcome to it. Cause I have to get back to Diplomacy.
Comment