//---- Begin of function Town::think_independent_unit_join_nation ----// // // Think having independent units joining existing nations. // int Town::think_independent_unit_join_nation() { if( jobless_population==0 ) return 0; independent_unit_join_nation_min_rating -= 2; // make it easier to join nation everytime it's called // -2 each time, adding of 30 after a unit has been recruited and calling it once every 2 months make it a normal rate of joining once a year per town //------ think about which nation to turn towards -----// int i, bestNationRecno=0, curRating, raceId, bestRaceId=0; int bestRating=independent_unit_join_nation_min_rating; Nation *nationPtr; // ###### patch begin Gilbert 16/3 ########// // #ifdef AMPLUS if( region_array[region_id]->region_stat_id == 0) return 0; // #endif // ###### patch end Gilbert 16/3 ########// RegionStat* regionStat = region_array.get_region_stat(region_id); for( i=nation_array.size() ; i>0 ; i-- ) { if( nation_array.is_deleted(i) ) continue; nationPtr = nation_array[i]; if( !nationPtr->race_id ) continue; if( nationPtr->cash <= 0 ) continue; if( info.game_date < nationPtr->last_independent_unit_join_date + 90 ) // don't join too frequently, at most 3 months a unit continue; //--- only join the nation if the nation has town in the town's region ---// if( regionStat->town_nation_count_array[i-1] == 0 ) continue; //----- calculate the rating of the nation -----// curRating = (int) nationPtr->reputation + nationPtr->overall_rating; if( recruitable_race_pop(nationPtr->race_id, 0) > 0 ) // 0-don't count spies { curRating += 30; raceId = nationPtr->race_id; } else raceId = 0; if( curRating > bestRating ) { bestRating = curRating; bestNationRecno = i; bestRaceId = raceId; } } //--------------------------------------------// if( !bestNationRecno ) return 0; if( !bestRaceId ) bestRaceId = pick_random_race(0, 0); // 0-only pick jobless unit, 0-don't pick spy units if( !bestRaceId ) return 0; if( !independent_unit_join_nation(bestRaceId, bestNationRecno) ) return 0; //--- set a new value to independent_unit_join_nation_min_rating ---// independent_unit_join_nation_min_rating = bestRating + 100 + m.random(30); // reset it to a higher rating if( independent_unit_join_nation_min_rating < 100 ) independent_unit_join_nation_min_rating = 100; return 1; }
//------- Begin of function Town::think_split_town -------// // // Split the town into two, migrating some population to the new // town. // int Town::think_split_town() { if( jobless_population==0 ) // cannot move if we don't have any mobilizable unit return 0; //--- split when the population is close to its limit ----// Nation* nationPtr = nation_array[nation_recno]; if( population < 45 + nationPtr->pref_territorial_cohesiveness / 10 ) return 0; //-------- think about which race to move --------// int mostRaceId1, mostRaceId2, raceId=0; get_most_populated_race(mostRaceId1, mostRaceId2); if( mostRaceId2 && jobless_race_pop_array[mostRaceId2-1] > 0 && can_recruit(mostRaceId2) ) raceId = mostRaceId2; else if( mostRaceId1 && jobless_race_pop_array[mostRaceId1-1] > 0 && can_recruit(mostRaceId1) ) raceId = mostRaceId1; else raceId = pick_random_race(0, 1); // 0-recruitable only, 1-also pick spy. if( !raceId ) { //---- if the racial mix favors a split of town -----// // // This is when there are two major races, both of significant // population in the town. This is a good time for us to move // the second major race to a new town. // //---------------------------------------------------// if( mostRaceId2 && jobless_race_pop_array[mostRaceId2] > 0 && race_pop_array[mostRaceId2] >= population/3 && // the race's has at least 1/3 of the town's total population can_recruit(mostRaceId2) ) { raceId = mostRaceId2; } } if( !raceId ) return 0; //---- check if there is already a town of this race with low population linked to this town, then don't split a new one ---// Town* townPtr; for( int i=0 ; i<linked_town_count ; i++ ) { townPtr = town_array[ linked_town_array[i] ]; if( townPtr->nation_recno == nation_recno && townPtr->population < 20 && townPtr->majority_race() == raceId ) { return 0; } } //-------- settle to a new town ---------// return ai_settle_new(raceId); }