//////////////////////////////////////////////////////////////////////////// // // SLIC for Ages of Man. // // By Dale // // Version 0.1 26-Aug-2002 // //////////////////////////////////////////////////////////////////////////// int_t AOM_NumPlayers; int_t AOM_MaxPlayers; int_t AOM_ColonisationPolicy[]; location_t AOM_ColSite; HandleEvent(BeginTurn) 'AOM_setupsomethings' pre { int_t count; if(g.player == 1) { AOM_NumPlayers = preference("NumPlayers"); AOM_MaxPlayers = preference("MaxPlayers"); if(AOM_MaxPlayers < (AOM_NumPlayers + 3)) { AOM_MaxPlayers = AOM_NumPlayers + 3; } for(count = 0; count <= AOM_MaxPlayers; count = count + 1) { AOM_ColonisationPolicy[count] = 4; } } DisableTrigger('AOM_setupsomethings'); } /////////////// // Colonisation /////////////// int_f AOM_ColSiteScore(location_t siteLoc) { location_t tmpLoc; location_t seaCheck; int_t score; int_t terrainType; 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 + 100; } if(terrainType == 1 || terrainType == 4) { score = score + 200; } 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 + 100; } if(TileHasImprovement(tmpLoc, 0)) { score = score + 150; } if(TileHasImprovement(tmpLoc, 9)) { score = score + 200; } if(HasGood(tmpLoc) >= 0) { score = score + 100; } if(HasRiver(tmpLoc)) { score = score + 50; } 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 + 100; } } cityCount = Cities(g.player); for(counter = 0; counter < cityCount; counter = counter + 1) { GetCityByIndex(g.player, counter, cityCheck); if(Distance(cityCheck.location, tmpLoc) < 4) { 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(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 highScoreLoc; city_t tmpCity; tmpCity = startCity; int_t count; 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 < 3; 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; } } 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(count = 0; count < 4; 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(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(count = 0; count < 4; 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; } } } 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; } } } if(borderDirection != 2 ) { // borderDirection = 0 or 1; south side of city tmpLoc = tmpCity.location; for(count = 0; count < 3; 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; } } 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(count = 0; count < 4; 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(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(count = 0; count < 4; 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; } } } 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; } } } 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 = player; player[0] = g.player; colNum = AOM_ColonisationPolicy[tmpPlayer]; if(!(IsHumanPlayer(tmpPlayer))) { if(HasAdvance(tmpPlayer, ID_ADVANCE_VIRTUAL_DEMOCRACY) || HasAdvance(tmpPlayer, ID_ADVANCE_ECOTOPIA)) { if(Cities(tmpPlayer) >= 62) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(HasAdvance(tmpPlayer, ID_ADVANCE_CORPORATE_REPUBLIC) || HasAdvance(tmpPlayer, ID_ADVANCE_TECHNOCRACY)) { if(Cities(tmpPlayer) >= 47) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(HasAdvance(tmpPlayer, ID_ADVANCE_COMMUNISM) || HasAdvance(tmpPlayer, ID_ADVANCE_DEMOCRACY) || HasAdvance(tmpPlayer, ID_ADVANCE_FASCISM) || HasAdvance(tmpPlayer, ID_ADVANCE_BUREAUCRACY)) { if(Cities(tmpPlayer) >= 37) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } elseif(HasAdvance(tmpPlayer, ID_ADVANCE_MONARCHY) || HasAdvance(tmpPlayer, ID_ADVANCE_THEOLOGY)) { if(Cities(tmpPlayer) >= 22) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } else { if(Cities(tmpPlayer) >= 12) { AOM_ColonisationPolicy[tmpPlayer] = 0; return STOP; } } } 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. } }