//----- Begin of function Town::update_camp_link -----// // // Update the status of links from this town to camps. // void Town::update_camp_link() { //--- enable the link of the town's side to all linked camps ---// Firm* firmPtr; int i; for( i=0 ; i<linked_firm_count ; i++ ) { firmPtr = firm_array[linked_firm_array[i]]; if( !firmPtr->cast_to_FirmCamp() ) continue; //--- don't set it if the town and camp both belong to a human player, the player will set it himself ---// if( firmPtr->nation_recno == nation_recno && nation_recno && !nation_array[nation_recno]->is_ai() ) { continue; } //--------------------------------------------// toggle_firm_link( i+1, 1, COMMAND_AUTO ); } //------- update camp link status -------// has_linked_own_camp = 0; has_linked_enemy_camp = 0; for( i=0 ; i<linked_firm_count ; i++ ) { if( linked_firm_enable_array[i] != LINK_EE ) continue; firmPtr = firm_array[linked_firm_array[i]]; if( !firmPtr->cast_to_FirmCamp() || firmPtr->cast_to_FirmCamp()->overseer_recno == 0 ) { continue; } if( firmPtr->nation_recno == nation_recno ) has_linked_own_camp = 1; else has_linked_enemy_camp = 1; } }
//--------- Begin of function SpyArray::update_firm_spy_count ---------// // // Update the player_spy_count of this firm. This function is called // when the firm change its nation. // // <int> firmRecno - recno of the firm to be updated. // void SpyArray::update_firm_spy_count(int firmRecno) { //---- recalculate Firm::player_spy_count -----// Spy* spyPtr; Firm* firmPtr = firm_array[firmRecno]; if( firmPtr->cast_to_FirmCamp() ) { FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp(); firmCamp->player_spy_count = 0; for( int i=spy_array.size() ; i>0 ; i-- ) { if( spy_array.is_deleted(i) ) continue; spyPtr = spy_array[i]; if( spyPtr->spy_place == SPY_FIRM && spyPtr->spy_place_para == firmRecno && spyPtr->true_nation_recno == nation_array.player_recno ) { firmCamp->player_spy_count++; } } } else if( firmPtr->cast_to_FirmTrain() ) { FirmTrain *firmTrain = firmPtr->cast_to_FirmTrain(); firmTrain->player_spy_count = 0; for( int i=spy_array.size() ; i>0 ; i-- ) { if( spy_array.is_deleted(i) ) continue; spyPtr = spy_array[i]; if( spyPtr->spy_place == SPY_FIRM && spyPtr->spy_place_para == firmRecno && spyPtr->true_nation_recno == nation_array.player_recno ) { firmTrain->player_spy_count++; } } } return; }
//----------- Begin of function Unit::return_camp -----------// // // Order this unit to return to the camp. For ordering many // units to return to a camp, UnitArray::return_camp() should // be called instead. // int Unit::return_camp() { if( !home_camp_firm_recno ) return 0; err_when( firm_array.is_deleted(home_camp_firm_recno) ); Firm* firmPtr = firm_array[home_camp_firm_recno]; if( firmPtr->region_id != region_id() ) return 0; err_when( !firmPtr->cast_to_FirmCamp() && !firmPtr->cast_to_FirmMonsterFortress() ); err_when( firmPtr->nation_recno != nation_recno ); //--------- assign now ---------// // ##### begin Gilbert 2/6 #########// assign(firmPtr->loc_x1, firmPtr->loc_y1, -1, true); // force_move_flag = 1; // ##### end Gilbert 2/6 #########// return cur_action != SPRITE_IDLE; }
//----- Begin of function Town::has_linked_camp -----// // // Return whether there is a camp of the specific nation // linked to this town. // // <int> nationRecno - recno of the nation. // <int> needOverseer - whether only count camps with overseers or not. // int Town::has_linked_camp(int nationRecno, int needOverseer) { Firm* firmPtr; for( int i=0 ; i<linked_firm_count ; i++ ) { firmPtr = firm_array[ linked_firm_array[i] ]; if( firmPtr->cast_to_FirmCamp() && firmPtr->nation_recno == nationRecno ) { if( !needOverseer || firmPtr->cast_to_FirmCamp()->overseer_recno ) return 1; } } return 0; }
//--------- Begin of function Unit::commander_power ---------// // // A commander's power is determined: // // -Population of the towns he controls // -The employment rate of the towns he controls, the higher the // employment rate, the higher his power is // -If there are any other commanders controls the towns at the same time. // -the no. of soldiers led by the commander and their combat levels. // int Unit::commander_power() { //---- if the commander is in a military camp -----// int commanderPower=0; if( unit_mode == UNIT_MODE_OVERSEE ) { Firm* firmPtr = firm_array[unit_mode_para]; if( firmPtr->cast_to_FirmCamp() ) { Town* townPtr; for( int i=firmPtr->linked_town_count-1 ; i>=0 ; i-- ) { if( firmPtr->linked_town_enable_array[i] == LINK_EE ) { townPtr = town_array[firmPtr->linked_town_array[i]]; int linkedCampCount = townPtr->linked_camp_count(true); if( linkedCampCount > 0 ) commanderPower += townPtr->population / linkedCampCount; } } commanderPower += firmPtr->cast_to_FirmCamp()->soldier_count*3; // 0 to 24 } else if( firmPtr->firm_id == FIRM_BASE ) { commanderPower = 60; } } else { commanderPower = team_info->member_count*3; // 0 to 24 } return commanderPower; }
//-------- Begin of function Town::linked_camp_count ------// // // Return the number of linked military camp to this town. // // <bool> hasOverseer - only count the camps with an overseer. // int Town::linked_camp_count(bool hasOverseer) { int i, linkedCount=0; Firm* firmPtr; for( i=0 ; i<linked_firm_count ; i++ ) { if( linked_firm_enable_array[i] == LINK_EE ) { firmPtr = firm_array[linked_firm_array[i]]; if( firmPtr->cast_to_FirmCamp() ) { if( !hasOverseer || firmPtr->cast_to_FirmCamp()->overseer_recno ) { linkedCount++; } } } } return linkedCount; }
// ---------- Begin of function FirmWar::can_set_rally_point ------// // // whether the firm can set rally point // // [int] destBaseObjRecno - destination base obj recno, 0 for setting position // int FirmWar::can_set_rally_point(int destBaseObjRecno) { if( destBaseObjRecno == 0 ) { return 1; } else { if( base_obj_array.is_deleted(destBaseObjRecno) ) return 0; Firm *firmPtr = base_obj_array[destBaseObjRecno]->cast_to_Firm(); if( firmPtr ) { if( firmPtr->cast_to_FirmCamp() ) { return 1; } } } return 0; }
//------- Begin of function Town::setup_link ---------// // void Town::setup_link() { //-----------------------------------------------------------------------------// // check the connected firms location and structure if ai_link_checked is true //-----------------------------------------------------------------------------// if(ai_town) ai_link_checked = 0; //----- build town-to-firm link relationship -------// int firmRecno; Firm* firmPtr; FirmInfo* firmInfo; linked_firm_count = 0; for( firmRecno=firm_array.size() ; firmRecno>0 ; firmRecno-- ) { if( firm_array.is_deleted(firmRecno) ) continue; firmPtr = firm_array[firmRecno]; firmInfo = firm_res[firmPtr->firm_id]; if( !firmInfo->is_linkable_to_town ) continue; //----- only linkable if the firm and the town belong to the same nation or the firm can influence a foreign town, i.e. Camp, Fort and Fryhtan Lair, if( nation_recno==0 ) { //--- independent towns can linked to work firms and markets ---// if( !firmPtr->cast_to_FirmWork() && !firmPtr->cast_to_FirmMarket() && !firmPtr->cast_to_FirmCamp() ) { continue; } } else { //--- nation towns can only linked to own firms or camps -------// if( firmPtr->nation_recno != nation_recno && !firmPtr->cast_to_FirmCamp() ) continue; } //---------- check if the firm is close enough to this firm -------// if( m.points_distance( firmPtr->center_x, firmPtr->center_y, center_x, center_y ) > world.effective_distance(firmPtr->firm_id, 0) ) { continue; } //------ check if both are on the same terrain type ------// if( (world.get_loc(firmPtr->loc_x1, firmPtr->loc_y1)->is_plateau()==1) != (world.get_loc(loc_x1, loc_y1)->is_plateau()==1) ) { continue; } //----- if the firm requires same race -------// if( !firm_res.is_linkable_to_town(firmPtr->firm_id, firmPtr->race_id, race_id) ) continue; //------- determine default link flag -------// int defaultLinkStatus = LINK_EE; if( nation_recno==0 ) // if this is an independent town { if( firmPtr->nation_recno==0 || resistance(firmPtr->nation_recno) > INDEPENDENT_LINK_RESISTANCE ) defaultLinkStatus = LINK_DD; } //-------- add the link now -------// if( linked_firm_count < MAX_LINKED_FIRM_TOWN ) { err_when( linked_firm_count>0 && linked_firm_array[linked_firm_count-1] == firmRecno ); // BUGHERE - check double linking error linked_firm_array[linked_firm_count] = firmRecno; linked_firm_enable_array[linked_firm_count] = defaultLinkStatus; linked_firm_count++; } else { err_here(); } if( firmPtr->linked_town_count < MAX_LINKED_TOWN_TOWN ) { firmPtr->linked_town_array[firmPtr->linked_town_count] = town_recno; firmPtr->linked_town_enable_array[firmPtr->linked_town_count] = defaultLinkStatus; firmPtr->linked_town_count++; if(firmPtr->is_ai) firmPtr->ai_link_checked = 0; } else { err_here(); } } //----- build town-to-town link relationship -------// linked_town_count = 0; int townRecno; Town* townPtr; for( townRecno=town_array.size() ; townRecno>0 ; townRecno-- ) { if( town_array.is_deleted(townRecno) || townRecno==town_recno ) continue; townPtr = town_array[townRecno]; //----- if the firm requires same race -------// if( race_id != townPtr->race_id ) continue; //------ check if the town is close enough to this firm -------// if( m.points_distance( townPtr->center_x, townPtr->center_y, center_x, center_y ) > world.effective_distance(0, 0) ) { continue; } //------ check if both are on the same terrain type ------// if( (world.get_loc(townPtr->loc_x1, townPtr->loc_y1)->is_plateau()==1) != (world.get_loc(loc_x1, loc_y1)->is_plateau()==1) ) { continue; } //-------- link this town -------// if( linked_town_count < MAX_LINKED_TOWN_TOWN ) { linked_town_array[linked_town_count] = townRecno; linked_town_enable_array[linked_town_count] = LINK_EE; linked_town_count++; } else { err_here(); } //-------- link the other town -------// if( townPtr->linked_town_count < MAX_LINKED_TOWN_TOWN ) { townPtr->linked_town_array[townPtr->linked_town_count] = town_recno; townPtr->linked_town_enable_array[townPtr->linked_town_count] = LINK_EE; townPtr->linked_town_count++; if(townPtr->ai_town) townPtr->ai_link_checked = 0; } else { err_here(); } } }
//------- Begin of function NationArray::update_total_human_count ------// // // Update total human count as there are some bugs in calculation of // total human count. This function is used for on-fly correcting // the problem. // void NationArray::update_total_human_count() { int totalHumanCountArray[MAX_NATION]; memset( totalHumanCountArray, 0, sizeof(totalHumanCountArray) ); //------ calculate firm statistic -------// Firm* firmPtr; int i; for( i=firm_array.size() ; i>0 ; i-- ) { if( firm_array.is_deleted(i) ) continue; firmPtr = firm_array[i]; if( firmPtr->nation_recno == 0 || !firmPtr->is_human() ) continue; if( firmPtr->cast_to_FirmCamp() ) { FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp(); for( int j=firmCamp->soldier_count-1 ; j>=0 ; j-- ) { if( firmCamp->soldier_array[j].is_human() ) totalHumanCountArray[firmCamp->nation_recno-1]++; } } if( firmPtr->cast_to_FirmTrain() ) { FirmTrain *firmTrain = firmPtr->cast_to_FirmTrain(); totalHumanCountArray[firmTrain->nation_recno-1] += firmTrain->trainee_count; } } //------ calculate unit statistic -------// Unit* unitPtr; for( i=unit_array.size() ; i>0 ; i-- ) { if( unit_array.is_truly_deleted(i) ) continue; unitPtr = unit_array[i]; if( unitPtr->nation_recno && unitPtr->is_human() && unitPtr->rank_id != RANK_KING ) // does not count kings { if( unitPtr->unit_id == UNIT_WAGON ) totalHumanCountArray[unitPtr->nation_recno-1] += unitPtr->cast_to_UnitWagon()->population; else totalHumanCountArray[unitPtr->nation_recno-1]++; } } //------ update nation statistic ------// for( i=size() ; i>0 ; i-- ) { if( nation_array.is_deleted(i) ) continue; nation_array[i]->total_human_count = totalHumanCountArray[i-1]; } }
//------- Begin of function NationArray::update_military_rating ------// // void NationArray::update_military_rating() { int nationCombatLevelArray[MAX_NATION]; memset( nationCombatLevelArray, 0, sizeof(nationCombatLevelArray) ); //------ calculate firm statistic -------// Firm* firmPtr; int i; for( i=firm_array.size() ; i>0 ; i-- ) { if( firm_array.is_deleted(i) ) continue; firmPtr = firm_array[i]; if( firmPtr->nation_recno == 0 ) continue; if( firmPtr->cast_to_FirmCamp() ) { FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp(); nationCombatLevelArray[firmPtr->nation_recno-1] += firmCamp->total_combat_level() + (firmCamp->overseer_recno>0 + firmCamp->soldier_count) * 20; // 20 is the base military points for a unit, so the nation that has many more units can be reflected in the military rating } // ###### patch begin 9/11 ########// else if( firmPtr->cast_to_FirmTrain() ) { FirmTrain *firmTrain = firmPtr->cast_to_FirmTrain(); nationCombatLevelArray[firmPtr->nation_recno-1] += firmTrain->total_military_combat_level() + firmTrain->total_military_count() * 20; // 20 is the base military points for a unit, so the nation that has many more units can be reflected in the military rating } // ###### patch end 9/11 ########// } //------ calculate unit statistic -------// Unit* unitPtr; for( i=unit_array.size() ; i>0 ; i-- ) { if( unit_array.is_deleted(i) ) continue; unitPtr = unit_array[i]; if( unitPtr->nation_recno == 0 ) continue; //---- if this unit is a ship, increase total_ship_combat_level ----// if( unit_res[unitPtr->unit_id]->unit_class == UNIT_CLASS_SHIP ) { nation_array[unitPtr->nation_recno]->total_ship_combat_level += (int) unitPtr->hit_points; } //----------------------------------// if( unitPtr->unit_mode == UNIT_MODE_OVERSEE ) // firm commanders are counted above with firm_array continue; int addPoints = (int) unitPtr->hit_points; UnitInfo* unitInfo = unit_res[unitPtr->unit_id]; // ##### begin Gilbert 24/3 ########// // if( unitInfo->unit_class == UNIT_CLASS_WEAPON ) // addPoints += (unitInfo->weapon_power + unitPtr->get_weapon_version() - 1) * 30; if( !unitInfo->class_info.has_combat_level ) { addPoints += unitInfo->weapon_power * 30; if( unitInfo->class_info.has_weapon_version ) addPoints += (unitPtr->get_weapon_version() - 1) * 30; } // ##### end Gilbert 24/3 ########// if( unitPtr->leader_unit_recno && !unit_array.is_deleted(unitPtr->leader_unit_recno) ) addPoints += addPoints * unit_array[unitPtr->leader_unit_recno]->skill_level() / 100; nationCombatLevelArray[unitPtr->nation_recno-1] += addPoints + 20; // 20 is the base military points for a unit, so the nation that has many more units can be reflected in the military rating } //------ update nation statistic ------// for( i=size() ; i>0 ; i-- ) { if( nation_array.is_deleted(i) ) continue; nation_array[i]->military_rating = nationCombatLevelArray[i-1]/50; } }
//-------- Begin of function SpyArray::catch_spy ------// // // <int> spyPlace - either SPY_TOWN or SPY_FIRM // <int> spyPlacePara - town_recno or firm_recno // int SpyArray::catch_spy(int spyPlace, int spyPlacePara) { int nationRecno, totalPop; if( spyPlace == SPY_TOWN ) { Town* townPtr = town_array[spyPlacePara]; nationRecno = townPtr->nation_recno; totalPop = townPtr->population; } else if( spyPlace == SPY_FIRM ) { Firm* firmPtr = firm_array[spyPlacePara]; nationRecno = firmPtr->nation_recno; if( firmPtr->cast_to_FirmCamp() ) { FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp(); totalPop = firmCamp->soldier_count + (firmCamp->overseer_recno>0); } else if( firmPtr->cast_to_FirmWork() ) { FirmWork *firmWork = firmPtr->cast_to_FirmWork(); totalPop = firmWork->worker_count; } else if( firmPtr->cast_to_FirmTrain() ) { totalPop = firmPtr->cast_to_FirmTrain()->trainee_count; return 0; // don't catch spy } else if( firmPtr->cast_to_FirmInn() ) { totalPop = firmPtr->cast_to_FirmInn()->inn_unit_count; return 0; // don't catch spy } else if( firmPtr->cast_to_FirmMarket() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmMonsterTrain() ) { totalPop = firmPtr->cast_to_FirmMonsterTrain()->trainee_count; return 0; // don't catch spy } else if( firmPtr->cast_to_FirmMonsterAlchemy() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmLishorr() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmMonsterFortress() ) { FirmMonsterFortress *firmMonsterFortress = firmPtr->cast_to_FirmMonsterFortress(); totalPop = firmMonsterFortress->archer_count + firmMonsterFortress->extra_builder_count; } else if( firmPtr->cast_to_FirmAnimal() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmIncubator() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmMagic() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmOffensive() ) { totalPop = 0; return 0; } else if( firmPtr->cast_to_FirmOffensive2() ) { totalPop = 0; return 0; } else { err_here(); totalPop = 0; } } else err_here(); //--- calculate the total of anti-spy skill in this town ----// int enemySpyCount=0, counterSpySkill=0; Spy* spyPtr; int techLevel = 0; if( nationRecno ) techLevel = tech_res[TECH_COUNTER_SPY]->get_nation_tech_level(nationRecno); int i; for( i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; spyPtr = spy_array[i]; if( spyPtr->spy_place == spyPlace && spyPtr->spy_place_para == spyPlacePara ) { if( spyPtr->true_nation_recno == nationRecno ) counterSpySkill += spyPtr->spy_skill + spyPtr->spy_skill * techLevel / 2; else enemySpyCount++; } } //----- if all citizens are enemy spies ----// if( enemySpyCount == totalPop ) return 0; err_when( enemySpyCount > totalPop ); //-------- try to catch enemy spies now ------// for( i=spy_array.size() ; i>0 ; i-- ) { if( spy_array.is_deleted(i) ) continue; spyPtr = spy_array[i]; if( spyPtr->action_mode == SPY_IDLE ) // it is very hard to get caught in sleep mode continue; if( spyPtr->spy_place == spyPlace && spyPtr->spy_place_para == spyPlacePara && spyPtr->true_nation_recno != nationRecno ) // doesn't get caught in sleep mode { int escapeChance = 100 + spyPtr->spy_skill - counterSpySkill; escapeChance = max( spyPtr->spy_skill/10, escapeChance ); if( m.random(escapeChance) == 0 ) { spyPtr->get_killed(); // only catch one spy per calling return 1; } } } return 0; }
//-------- Begin of function Place::invoke_camp_defense ---------// // // Call out defenders from neighboring camps to help. // void Place::invoke_camp_defense(BaseObj* attackerObj) { if( !attackerObj ) return; //----- if this is an independent town -----// if( !nation_recno ) { //---- if this is a slave town ----// if( cast_to_Town() && cast_to_Town()->is_pay_tribute_to_monster() ) { //---- reckon the net attacking power in the battling area ----// int hasWar; // ref var for returning the result int netAttackerPower = world.net_attacker_power_in_area(center_x, center_y, attackerObj->nation_recno, nation_recno, 0, hasWar, EFFECTIVE_DEFEND_DISTANCE); //-- no need to call for reinforcement if the defense force is more powerful than the attacking force --// if( netAttackerPower <= 0 ) return; //------ call enslaving lair's AI to protect it ------// Town* thisTown = cast_to_Town(); for( int i=0 ; i<thisTown->linked_firm_count ; i++ ) { //--- if this linked firm is a lair enslaving the town ---// if( thisTown->tribute_to_lair( thisTown->linked_firm_array[i], 1 ) ) { FirmLair* firmLair = firm_array[ thisTown->linked_firm_array[i] ]->cast_to_FirmLair(); if( firmLair && firmLair->is_ai ) firmLair->invoke_defense(attackerObj, netAttackerPower); } } } return; } //---- reckon the net attacking power in the battling area ----// int hasWar; // ref var for returning the result int netAttackerPower = world.net_attacker_power_in_area(center_x, center_y, attackerObj->nation_recno, nation_recno, 0, hasWar, EFFECTIVE_DEFEND_DISTANCE); //-- no need to call for reinforcement if the defense force is more powerful than the attacking force --// if( netAttackerPower <= 0 ) return; //--------- call for reinforcement now -------// for( int i=firm_array.size() ; i>0 ; i-- ) { if( firm_array.is_deleted(i) ) continue; Firm* firmPtr = firm_array[i]; //--- look for our camp ----// // ###### begin Gilbert 15/4 #########// // if( !firmPtr->cast_to_FirmCamp() || firmPtr->nation_recno!=nation_recno ) if( !firmPtr->cast_to_FirmCamp() || firmPtr->nation_recno!=nation_recno || nation_recno == 0 ) // ###### end Gilbert 15/4 #########// continue; //--- only if the camp's within the effective defense distance ---// if( misc.points_distance(firmPtr->center_x, firmPtr->center_y, center_x, center_y ) > EFFECTIVE_DEFEND_DISTANCE ) { continue; } //----- ask the camp to send out defenders now ------// int defensePower = firmPtr->cast_to_FirmCamp()->invoke_defense(attackerObj, netAttackerPower); netAttackerPower -= defensePower; if( netAttackerPower <= 0 ) break; } }
//--------- Begin of function Nation::ai_find_unit --------// // // <int> isCivilian - whether the unit is a civilian unit // <int> raceId - the race the selected unit should have // (0 for any races) // <short> destX, destY - location the unit move to // <char&> resultFlag - describle how to find the skilled unit // 0 - for unable to train unit, // 1 - for existing skilled unit // 2 - for unit hired from inn // 3 - for training unit in town (training is required) // // [int] actionId - the action id. of the action which // the unit should do after it has finished training. // // return the unit pointer pointed to the skilled unit // Unit* Nation::ai_find_unit(int isCivilian, int raceId, short destX, short destY, char& resultFlag, int actionId) { //----- try to find an existing unit with the required skill -----// Unit *wantedUnit = NULL; Unit *unitPtr; Firm *firmPtr; short curDist, minDist=0x1000; int destRegionId = world.get_region_id(destX, destY); for(int i=unit_array.size(); i>0; i--) { if(unit_array.is_deleted(i)) continue; unitPtr = unit_array[i]; if( unitPtr->nation_recno!=nation_recno || !unitPtr->race_id ) continue; if( raceId ) { if( unitPtr->race_id != raceId ) continue; } else { if( !unitPtr->is_human() ) continue; } //---- if this unit is on a mission ----// if( unitPtr->home_camp_firm_recno ) continue; if( unitPtr->region_id() != destRegionId ) continue; if( unitPtr->is_civilian() != isCivilian ) continue; if( unitPtr->unit_mode ) // it can be a camp defender. continue; //----- if this is a mobile unit ------// if( unitPtr->is_visible() ) { if( !unitPtr->is_all_stop() ) continue; if( unitPtr->cur_action!=SPRITE_ATTACK && !unitPtr->cur_order.ai_action_id ) { curDist = m.points_distance(unitPtr->next_x_loc(), unitPtr->next_y_loc(), destX, destY); if(curDist < minDist) { wantedUnit = unitPtr; minDist = curDist; } } } //------- if this is an overseer ------// else if( unitPtr->unit_mode==UNIT_MODE_OVERSEE ) { firmPtr = firm_array[unitPtr->unit_mode_para]; if( firmPtr->region_id != destRegionId ) continue; if( firmPtr->cast_to_FirmCamp() ) { //--- if this military camp is going to be closed, use this overseer ---// if( firmPtr->should_close_flag ) { firmPtr->cast_to_FirmCamp()->mobilize_overseer(); wantedUnit = unitPtr; // pick this overseer break; } } } } //---------------------------------------------------// if(wantedUnit) { resultFlag = 1; err_when( wantedUnit->is_civilian() != isCivilian ); } else { //--- if no existing skilled unit found, try to hire one from inns ---// int unitRecno=0; if( !isCivilian ) // if the wanted unit is a military, we can try to hire it from the inn { unitRecno = hire_unit(raceId, isCivilian, false, destX, destY); // this function will try going with hiring units that are better than training your own ones. false-don't hire a spy, just hire a normal military unit if( unitRecno ) { resultFlag = 2; err_when( unit_array[unitRecno]->is_civilian() != isCivilian ); } } if( !unitRecno && isCivilian ) { int recruitTownRecno; unitRecno = recruit_peasant(raceId, destX, destY, recruitTownRecno); if( unitRecno ) { err_when( unit_array[unitRecno]->is_civilian() != isCivilian ); resultFlag = 3; } else resultFlag = 0; } if( unitRecno ) wantedUnit = unit_array[unitRecno]; } return wantedUnit; }