//------ Begin of function Nation::ai_build_camp_town_next_to ------// // // Build a new camp and settle a new town next to the given location. // // <int> xLoc1, yLoc1, xLoc2, yLoc2 - the location that the new camp // and town should be built next to. // int Nation::ai_build_camp_town_next_to(int xLoc1, int yLoc1, int xLoc2, int yLoc2) { //---- first see if we already have a camp in the region ---// int regionId = world.get_region_id(xLoc1, yLoc1); // ##### patch begin Gilbert 16/3 #######// //#ifdef AMPLUS if( region_array[regionId]->region_stat_id == 0) return 0; //#endif // ##### patch end Gilbert 16/3 #######// if( region_array.get_region_stat(regionId)->camp_nation_count_array[nation_recno-1] == 0 ) { //--- if we don't have one yet, build one next to the destination ---// if( !world.locate_space( xLoc1, yLoc1, xLoc2, yLoc2, 3, 3, UNIT_LAND, regionId, 1 ) ) // 1-locating the space for building { return 0; } if( !world.can_build_firm( xLoc1, yLoc1, FIRM_CAMP ) ) return 0; return ai_patrol_to_region(xLoc1, yLoc1, SEA_ACTION_BUILD_CAMP); } else //-- if there's already a camp there, then set people there to settle --// { FirmCamp* firmCamp; for( int i=0 ; i<ai_camp_count ; i++ ) { firmCamp = (FirmCamp*) firm_array[ ai_camp_array[i] ]; if( firmCamp->region_id != regionId ) continue; xLoc1 = firmCamp->loc_x1; yLoc1 = firmCamp->loc_y1; xLoc2 = firmCamp->loc_x2; yLoc2 = firmCamp->loc_y2; if( world.locate_space( xLoc1, yLoc1, xLoc2, yLoc2, STD_TOWN_LOC_WIDTH, STD_TOWN_LOC_HEIGHT, UNIT_LAND, regionId, 1 ) ) // 1-locating the space for building { if( world.can_build_town( xLoc1, yLoc1 ) ) return ai_settle_to_region(xLoc1, yLoc1, SEA_ACTION_SETTLE); } } } return 0; }
//------ Begin of function Nation::think_move_people_between_region ------// // // Thing about moving units between regions // int Nation::think_move_people_between_region() { //----- find the region with the least population -----// int joblessPop, maxJoblessPop=0, minJoblessPop=0x1000; int maxRegionId=0, minRegionId=0; RegionStat* regionStat = region_array.region_stat_array; int i; for( i=0 ; i<region_array.region_stat_count ; i++, regionStat++ ) { //--- only move to regions in which we have camps ---// if( regionStat->camp_nation_count_array[nation_recno-1] == 0 ) continue; joblessPop = regionStat->nation_jobless_population_array[nation_recno-1]; if( joblessPop > maxJoblessPop ) { maxJoblessPop = joblessPop; maxRegionId = regionStat->region_id; } if( joblessPop < minJoblessPop ) { minJoblessPop = joblessPop; minRegionId = regionStat->region_id; } } if( !maxRegionId || !minRegionId || maxRegionId==minRegionId ) return 0; //----- only move if the difference is big enough ------// if( pref_use_marine < 90 ) // if > 90, it will ignore all these and move anyway { if( maxJoblessPop - minJoblessPop < 150 - pref_use_marine ) // 100 to 150 (pref_use_marine is always >= 50, if it is < 50, marine functions are not called at all return 0; } else { if( maxJoblessPop < 20 ) // don't move if we only have a few jobless people return 0; } //------------ see if we have any towns in the region -----------// int destRegionId = minRegionId; Town* townPtr; for( i=ai_town_count-1 ; i>=0 ; i-- ) { townPtr = town_array[ai_town_array[i]]; if( townPtr->region_id == destRegionId ) { //--- if there is one, must move the people to it ---// return ai_settle_to_region(townPtr->center_x, townPtr->center_y, SEA_ACTION_NONE); } } //----- if we don't have any towns in the region, settle one ----// int xLoc=0, yLoc=0; if(world.locate_space_random(xLoc, yLoc, MAX_WORLD_X_LOC-1, MAX_WORLD_Y_LOC-1, STD_TOWN_LOC_WIDTH, STD_TOWN_LOC_HEIGHT, MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC, destRegionId, 1)) { return ai_settle_to_region(xLoc, yLoc, SEA_ACTION_SETTLE); } return 0; }