// Global Variable city_t THE_NEAREST_CITY; // Function // Finds thePlayer's THE_NEAREST_CITY; beyond or equal to theDistance to theLocation int_f FindTheNearestCity( int_t thePlayer, location_t theLocation, int_t theDistance){ int_t smlDist; int_t tmpDist; int_t i; location_t tmpLocation; city_t tmpCity; smlDist=90000; //initialize to some absurdly large number tmpLocation=theLocation; if (IsPlayerAlive(thePlayer)) { if (PlayerCityCount(thePlayer)> 0) { for(i = 0; i < PlayerCityCount(thePlayer); i = i + 1) { if(GetCityByIndex(thePlayer, i, tmpCity)) { tmpDist=SquaredDistance(tmpLocation, tmpCity.location); if (theDistance <= tmpDist && tmpDist < smlDist) { smlDist = tmpDist; THE_NEAREST_CITY = tmpCity; } } } if (smlDist<90000) { return Distance(tmpLocation, THE_NEAREST_CITY); } else{ return -1;// no such city exists } } } else{ return -1; // no cities at all or not a valid player } } // Handlers HandleEvent(CreateCity)'NewCityTileImprovement' post { //one for new cities location_t theLoc; city_t tmpCity; int_t i; int_t j; int_t CityOK; CityOK=0; if (value[1]==-1) {// if it came from a goody hut if (PlayerCityCount(player[0])==1) {// it was the first city CityOK=1; } elseif (PlayerCityCount(player[0])>0) { for(i=0; i=4) { message(city[0].owner, 'Deforest'); GetNeighbor(city[0].location, 0, firstLoc);//go north of the City for (j=0; j<=7 ; j=j+1) { //directions GetNeighbor(firstLoc, j, theLoc);//look around if ( CellOwner(theLoc)==city[0].owner && HasGood(theLoc)==-1) { if (TerrainType(theLoc)==0 || TerrainType(theLoc)==7 ) { // 0=forest, 7=jungle setPW(city[0].owner, tmpPw); Event:CreateImprovement(city[0].owner,theLoc, 28,0); //change to grassland } } } } GetNeighbor(city[0].location, 2, firstLoc);//go east of the City for (j=0; j<=7 ; j=j+1) { GetNeighbor(firstLoc, j, theLoc); if ( CellOwner(theLoc)==city[0].owner && HasGood(theLoc)==-1) { if (TerrainType(theLoc)==0 || TerrainType(theLoc)==7 ) { // 0=forest, 7=jungle Event:CreateImprovement(city[0].owner,theLoc, 28,0); //change to grassland } } } GetNeighbor(city[0].location, 5, firstLoc);//go west of the City for (j=0; j<=7 ; j=j+1) { //directions GetNeighbor(firstLoc, j, theLoc);//look around if ( CellOwner(theLoc)==city[0].owner && HasGood(theLoc)==-1) { if (TerrainType(theLoc)==0 || TerrainType(theLoc)==7 ) { // 0=forest, 7=jungle Event:CreateImprovement(city[0].owner,theLoc, 28,0); //change to grassland } } } GetNeighbor(city[0].location, 7, firstLoc);//go south of the City for (j=0; j<=7 ; j=j+1) { //directions GetNeighbor(firstLoc, j, theLoc);//look around if ( CellOwner(theLoc)==city[0].owner && HasGood(theLoc)==-1) { if (TerrainType(theLoc)==0 || TerrainType(theLoc)==7 ) { // 0=forest, 7=jungle Event:CreateImprovement(city[0].owner,theLoc, 28,0); //change to grassland } } } } MessageBox 'Deforest' { Show(); MessageClass(601); Text(ID_City_Deforest); Button(ID_EXIT) { Kill(); } Button(ID_NoMoreTheseMessages) { KillClass(g.player, 601);// DisableMessageClass(601) } } ///////////// FROM SCENARIO_STR.TXT EXIT "Exit" NoMoreTheseMessages "Don't Show Me This Again" City_Deforest "Sire, The city of {city[0].name} is bursting at the seams. We have sent squads of workers to scour the surrounding countryside and collect building materials for it's expansion."