//////////////////////////////////////////////////////////////////////////// // // SLIC for Ages of Man. // // By Dale // // Version 0.1 26-Aug-2002 // //////////////////////////////////////////////////////////////////////////// //////////////////////////// // #includes for other SLICs //////////////////////////// #include "AOM_NewDiplomod.slc" #include "AOM_others_slics.slc" /////////////////// // Global Variables /////////////////// int_t AOM_NumPlayers; int_t AOM_MaxPlayers; int_t AOM_ColonisationPolicy[]; location_t AOM_ColSite; int_t AOM_GovtUnits[]; int_t AOM_WhatGovtAmI[]; int_t AOM_FirstUnitIndex; /////////////////////////////// // AOM SetupSomethings at start /////////////////////////////// HandleEvent(BeginTurn) 'AOM_SetupSomethings' pre { int_t count; if(g.player == 1) { AOM_FirstUnitIndex = 55; AOM_GovtUnits[0] = UnitDB(UNIT_ANARCHY); AOM_GovtUnits[1] = UnitDB(UNIT_TYRANNY); AOM_GovtUnits[2] = UnitDB(UNIT_DYNASTY); AOM_GovtUnits[3] = UnitDB(UNIT_NOMARCHY); AOM_GovtUnits[4] = UnitDB(UNIT_CITYSTATE); AOM_GovtUnits[5] = UnitDB(UNIT_OLIGARCHY); AOM_GovtUnits[6] = UnitDB(UNIT_REPUBLIC); AOM_GovtUnits[7] = UnitDB(UNIT_TRIBUNALEMPIRE); AOM_GovtUnits[8] = UnitDB(UNIT_EMPERORSHIP); AOM_GovtUnits[9] = UnitDB(UNIT_DARKAGES); AOM_GovtUnits[10] = UnitDB(UNIT_THEOCRACY); AOM_GovtUnits[11] = UnitDB(UNIT_MONARCHY); AOM_GovtUnits[12] = UnitDB(UNIT_CALIPHATE); AOM_GovtUnits[13] = UnitDB(UNIT_MERCANTILISM); AOM_NumPlayers = preference("NumPlayers"); AOM_MaxPlayers = preference("MaxPlayers"); if(AOM_MaxPlayers < (AOM_NumPlayers + 3)) { AOM_MaxPlayers = AOM_NumPlayers + 3; // Add 3 players to handle revolts } for(count = 0; count <= AOM_MaxPlayers; count = count + 1) { AOM_ColonisationPolicy[count] = 4; // Default all to Fast-Coastal gov policy AOM_WhatGovtAmI[count] = 0; // Default everyone to anarchy! } } DisableTrigger('AOM_SetupSomethings'); } ////////////////////// // AOM mod_* Functions ////////////////////// int_f mod_CanCityBuildBuilding(city_t theCity, int_t theBuilding) { city_t tmpCity; city_t tmpCity2; int_t tmpBuilding; tmpBuilding = theBuilding; tmpCity = theCity; if (tmpBuilding == BuildingDB(IMPROVE_GOV_POLICY) && IsHumanPlayer(g.player)) { // We only want Humans to build this in their first city GetCityByIndex(g.player, 0, tmpCity2); if(tmpCity == tmpCity2) { return 1; } else { return 0; } } return 1; } /////////////// // Colonisation /////////////// int_f AOM_ColSiteScore(location_t siteLoc) { location_t tmpLoc; location_t seaCheck; int_t score; int_t terrainType; int_t count; int_t counter; int_t cityCount; unit_t tmpUnit; city_t cityCheck; score = 0; tmpLoc = siteLoc; terrainType = TerrainType(tmpLoc); if(terrainType == 0 || terrainType == 9) { score = score + 250; } if(terrainType == 1 || terrainType == 4) { score = score + 500; } if(terrainType == 3 || terrainType == 5 || terrainType == 10 || terrainType == 11 || terrainType == 12 || terrainType == 13 || terrainType == 14 || terrainType == 15 || terrainType == 16 || terrainType == 17 || terrainType == 18 || terrainType == 21 || terrainType == 22 || terrainType == 23 || terrainType == 24) { score = score - 50000; } if(TileHasImprovement(tmpLoc, 6) || TileHasImprovement(tmpLoc, 8)) { score = score + 250; } if(TileHasImprovement(tmpLoc, 0)) { score = score + 300; } if(TileHasImprovement(tmpLoc, 9)) { score = score + 350; } if(HasGood(tmpLoc) >= 0) { score = score + 500; } if(HasRiver(tmpLoc)) { score = score + 500; } if(IsFortress(g.player, tmpLoc)) { score = score + 100; } if(g.player == CellOwner(tmpLoc)) { score = score + 50; } if(GetUnitsAtLocation(tmpLoc) > 0) { GetUnitFromCell(tmpLoc, 0, tmpUnit); if(g.player == tmpUnit.owner) { score = score + 200; } else { score = score - 50000; } } for(count = 0; count < AOM_MaxPlayers; count = count + 1) { if(IsPlayerAlive(count)) { cityCount = Cities(count); for(counter = 0; counter < cityCount; counter = counter + 1) { GetCityByIndex(count, counter, cityCheck); if(Distance(cityCheck.location, tmpLoc) < 5) { score = score - 50000; } } } } for(counter = 0; counter < 8; counter = counter + 1) { if(GetNeighbor(tmpLoc, counter, seaCheck)) { if(TerrainType(seaCheck) == 10 || TerrainType(seaCheck) == 11 || TerrainType(seaCheck) == 12 || TerrainType(seaCheck) == 13 || TerrainType(seaCheck) == 14 || TerrainType(seaCheck) == 15 || TerrainType(seaCheck) == 16 || TerrainType(seaCheck) == 23 || TerrainType(seaCheck) == 24) { score = score + 100; if(AOM_ColonisationPolicy[g.player] > 3) { // If coastal policy, then double score score = score * 2; } } } if(GetUnitsAtLocation(seaCheck) > 0) { GetUnitFromCell(seaCheck, 0, tmpUnit); if(g.player == tmpUnit.owner) { score = score + 200; } else { score = score - 50000; } } } if(score < 0) { score = 0; // Score check. Any zero's get eliminated. } return score; } int_f AOM_FindColSite(city_t startCity) { location_t tmpLoc; location_t tmpLoc2; location_t highScoreLoc; city_t tmpCity; tmpCity = startCity; int_t count; int_t count2; int_t borderDirection; int_t locScore; int_t highLocScore; int_t randNum; locScore = 0; highLocScore = 0; borderDirection = 0; // 1 = near north map edge, 2 = near south border edge, 0 = near neither tmpLoc = tmpCity.location; highScoreLoc = tmpLoc; for(count = 0; count < 6; count = count + 1) { // Check if near north border if(!(GetNeighbor(tmpLoc, 0, tmpLoc))) { borderDirection = 1; } } tmpLoc = tmpCity.location; for(count = 0; count < 6; count = count + 1) { // Check if near south border if(!(GetNeighbor(tmpLoc, 7, tmpLoc))) { borderDirection = 2; } } tmpLoc = tmpCity.location; if(borderDirection != 1 ) { // borderDirection = 0 or 2; north side of city for(count = 0; count < 4; count = count + 1) { if(!(GetNeighbor(tmpLoc, 2, tmpLoc))) { return 0; } } if(!(GetNeighbor(tmpLoc, 1, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } if(!(GetNeighbor(tmpLoc, 0, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } for(count = 0; count < 6; count = count + 1) { if(!(GetNeighbor(tmpLoc, 3, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } for(count = 0; count < 3; count = count + 1) { if(!(GetNeighbor(tmpLoc, 5, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } for(count = 0; count < 6; count = count + 1) { if(!(GetNeighbor(tmpLoc, 6, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } if(!(GetNeighbor(tmpLoc, 7, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } if(borderDirection != 2 ) { // borderDirection = 0 or 1; south side of city tmpLoc = tmpCity.location; for(count = 0; count < 4; count = count + 1) { if(!(GetNeighbor(tmpLoc, 2, tmpLoc))) { return 0; } } if(!(GetNeighbor(tmpLoc, 4, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } if(!(GetNeighbor(tmpLoc, 7, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } for(count = 0; count < 6; count = count + 1) { if(!(GetNeighbor(tmpLoc, 6, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } for(count = 0; count < 3; count = count + 1) { if(!(GetNeighbor(tmpLoc, 5, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } for(count = 0; count < 6; count = count + 1) { if(!(GetNeighbor(tmpLoc, 3, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } if(!(GetNeighbor(tmpLoc, 0, tmpLoc))) { return 0; } locScore = AOM_ColSiteScore(tmpLoc); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc; } } for(count2 = 0; count2 < 8; count2 = count2 + 1) { if(GetNeighbor(tmpLoc, count2, tmpLoc2)) { locScore = AOM_ColSiteScore(tmpLoc2); if(locScore > highLocScore) { highLocScore = locScore; highScoreLoc = tmpLoc2; } if(locScore == highLocScore) { randNum = random(1); if(randNum < 1) { highLocScore = locScore; highScoreLoc = tmpLoc2; } } } } } if(highScoreLoc == tmpCity.location || highLocScore == 0) { return 0; } else { AOM_ColSite = highScoreLoc; return 1; } } HandleEvent(MakePop) 'AOM_GrabPop' pre { city_t tmpCity; city_t newCity; int_t tmpPlayer; int_t colNum; int_t randNum; int_t tmpNum; location_t tmpLoc; tmpCity = city[0]; tmpPlayer = g.player; colNum = AOM_ColonisationPolicy[tmpPlayer]; if(!(IsHumanPlayer(tmpPlayer))) { if(AOM_WhatGovtAmI[tmpPlayer] > 9 && AOM_WhatGovtAmI[tmpPlayer] < 14) { if(Cities(tmpPlayer) >= 52) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(AOM_WhatGovtAmI[tmpPlayer] == 9) { if(Cities(tmpPlayer) >= 42) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(AOM_WhatGovtAmI[tmpPlayer] == 7 || AOM_WhatGovtAmI[tmpPlayer] == 8) { if(Cities(tmpPlayer) >= 52) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(AOM_WhatGovtAmI[tmpPlayer] == 6) { if(Cities(tmpPlayer) >= 42) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(AOM_WhatGovtAmI[tmpPlayer] == 4 || AOM_WhatGovtAmI[tmpPlayer] == 5) { if(Cities(tmpPlayer) >= 32) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(AOM_WhatGovtAmI[tmpPlayer] == 2 || AOM_WhatGovtAmI[tmpPlayer] == 3) { if(Cities(tmpPlayer) >= 22) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(AOM_WhatGovtAmI[tmpPlayer] == 0 || AOM_WhatGovtAmI[tmpPlayer] == 1) { if(Cities(tmpPlayer) >= 12) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } else { AOM_ColonisationPolicy[tmpPlayer] = 4; } } if((tmpCity.population >= 1) && (g.year >= 1) && (colNum > 0)) { if(colNum < 4) { tmpNum = colNum * 3; randNum = random(tmpNum); if(randNum < 1) { if(AOM_FindColSite(tmpCity)) { CreateCity(g.player, AOM_ColSite, 0); return STOP; } } } else { tmpNum = (colNum - 3); tmpNum = tmpNum * 3; randNum = random(tmpNum); if(randNum < 1) { if(AOM_FindColSite(tmpCity)) { CreateCity(g.player, AOM_ColSite, 0); return STOP; } } } } } //HandleEvent(BeginTurn) 'AOM_CheckColPolicy' pre { // int_t tmpPlayer; // tmpPlayer = g.player; // if(!(IsHumanPlayer(tmpPlayer))) { // AOM_ColonisationPolicy[tmpPlayer] = 4; // Reset AI's colonisation policy. May use it later. // } //} ////////////////////// // Government Policies ////////////////////// AlertBox 'AOMMSG_Col_Land' { Title(ID_GOV_LAND_TITLE); Text(ID_GOV_LAND); Show(); Button(ID_COL_FAST) { Kill(); AOM_ColonisationPolicy[g.player] = 1; } Button(ID_COL_NORM) { Kill(); AOM_ColonisationPolicy[g.player] = 2; } Button(ID_COL_SLOW) { Kill(); AOM_ColonisationPolicy[g.player] = 3; } } AlertBox 'AOMMSG_Col_Coast' { Title(ID_GOV_COAST_TITLE); Text(ID_GOV_COAST); Show(); Button(ID_COL_FAST) { Kill(); AOM_ColonisationPolicy[g.player] = 4; } Button(ID_COL_NORM) { Kill(); AOM_ColonisationPolicy[g.player] = 5; } Button(ID_COL_SLOW) { Kill(); AOM_ColonisationPolicy[g.player] = 6; } } MessageBox 'AOMMSG_Gov_Policy' { Title(ID_GOV_POLICY_TITLE); Text(ID_GOV_POLICY); MessageType("CIVILIZATION"); Show(); Button(ID_COL_COAST) { Kill(); Message(g.player, 'AOMMSG_Col_Coast'); } Button(ID_COL_LAND) { Kill(); Message(g.player, 'AOMMSG_Col_Land'); } Button(ID_COL_STOP) { Kill(); AOM_ColonisationPolicy[g.player] = 0; } } HandleEvent(BeginTurn) 'AOM_KillGovPolicy' pre { city_t tmpCity; int_t thePlayer; thePlayer = g.player; if(Cities(thePlayer) > 0) { GetCityByIndex(thePlayer, 0, tmpCity); if(CityIsValid(tmpCity)) { if(CityHasBuilding(tmpCity, "IMPROVE_GOV_POLICY")) { DestroyBuilding(tmpCity, BuildingDB(IMPROVE_GOV_POLICY)); } } } } HandleEvent(CreateBuilding) 'AOM_GovPolicy' pre { int_t theBuilding; int_t thePlayer; thePlayer = g.player; theBuilding = value[0]; if(theBuilding == BuildingDB(IMPROVE_GOV_POLICY)) { Message(thePlayer, 'AOMMSG_Gov_Policy'); } } ////////////////// // What Govt Am I? ////////////////// HandleEvent(BeginTurn) 'CheckMyGovernment' pre { int_t tmpPlayer; int_t tmpUnit; int_t counter; int_t index; city_t tmpCity; tmpPlayer = g.player; if(IsPlayerAlive(tmpPlayer) && Cities(tmpPlayer) > 0) { GetCityByIndex(tmpPlayer, 0, tmpCity); if(CityIsValid(tmpCity)) { for(counter = 0; counter < AOM_GovtUnits.#; counter = counter + 1) { index = counter + AOM_FirstUnitIndex; tmpUnit = AOM_GovtUnits[counter]; if(IsUnitAtHead(tmpCity) == index) { Event:ZeroProduction(tmpCity); } if(IsUnitInBuildList(tmpCity, index)) { AOM_WhatGovtAmI[tmpPlayer] = counter; KillUnitFromBuildList(tmpCity, index); } } } } } HandleEvent(EndTurn) 'DeleteCheckUnitsEndTurnCheat' pre { int_t count; int_t tmpUnit; int_t tmpPlayer; city_t tmpCity; tmpPlayer = g.player; if(Cities(tmpPlayer) > 0) { GetCityByIndex(g.player, 0, tmpCity); if(CityIsValid(tmpCity)) { for(count = 0; count < AOM_GovtUnits.#; count = count + 1) { tmpUnit = count + AOM_FirstUnitIndex; Event:BuildUnit(tmpCity, tmpUnit); } } } }