// 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