//----- Begin of function Nation::think_eliminate_enemy_unit -----// // // This function is called to eliminate remaining enemy firms // when all enemy towns have been destroyed. // int Nation::think_eliminate_enemy_unit(int enemyNationRecno) { Unit *unitPtr; int hasWar; for( int i=unit_array.size() ; i>0 ; i-- ) { if( unit_array.is_deleted(i) ) continue; unitPtr = unit_array[i]; if( unitPtr->nation_recno != enemyNationRecno ) continue; if( !unitPtr->is_visible() || unitPtr->mobile_type != UNIT_LAND ) // only deal with land units now continue; //--- only attack if we have any base town in the enemy unit's region ---// if( base_town_count_in_region(unitPtr->region_id()) == 0 ) continue; //----- take into account of the mobile units around this town -----// int mobileCombatLevel = mobile_defense_combat_level(unitPtr->next_x_loc(), unitPtr->next_y_loc(), unitPtr->nation_recno, 1, hasWar); if( mobileCombatLevel == -1 ) // do not attack this town because a battle is already going on continue; return ai_attack_target(unitPtr->next_x_loc(), unitPtr->next_y_loc(), mobileCombatLevel + (int) unitPtr->unit_power()); } return 0; }
//----- Begin of function Nation::think_eliminate_enemy_firm -----// // // This function is called to eliminate remaining enemy firms // when all enemy towns have been destroyed. // int Nation::think_eliminate_enemy_firm(int enemyNationRecno) { //---- look for enemy firms to attack ----// int hasWar; Firm *firmPtr; for( int i=firm_array.size() ; i>0 ; i-- ) { if( firm_array.is_deleted(i) ) continue; firmPtr = firm_array[i]; if( firmPtr->nation_recno != enemyNationRecno ) continue; //--- only attack if we have any base town in the enemy firm's region ---// if( base_town_count_in_region(firmPtr->region_id)==0 ) continue; //----- take into account of the mobile units around this town -----// int mobileCombatLevel = mobile_defense_combat_level(firmPtr->center_x, firmPtr->center_y, firmPtr->nation_recno, 1, hasWar); if( mobileCombatLevel == -1 ) // do not attack this town because a battle is already going on continue; //---- calculate the combat level of this target firm ----// int firmCombatLevel; if( firmPtr->firm_id == FIRM_CAMP ) // other civilian firms firmCombatLevel = ((FirmCamp*)firmPtr)->total_combat_level(); else firmCombatLevel = firmPtr->worker_count * 10; // civilian firms have very low combat level return ai_attack_target(firmPtr->loc_x1, firmPtr->loc_y1, mobileCombatLevel + firmCombatLevel); } return 0; }
//----- Begin of function Nation::think_eliminate_enemy_town -----// // // This function is called to eliminate remaining enemy firms // when all enemy towns have been destroyed. // int Nation::think_eliminate_enemy_town(int enemyNationRecno) { //---- look for enemy firms to attack ----// int hasWar; Town *townPtr; for( int i=town_array.size() ; i>0 ; i-- ) { if( town_array.is_deleted(i) ) continue; townPtr = town_array[i]; if( townPtr->nation_recno != enemyNationRecno ) continue; //--- only attack if we have any base town in the enemy town's region ---// if( base_town_count_in_region(townPtr->region_id)==0 ) continue; //----- take into account of the mobile units around this town -----// int mobileCombatLevel = mobile_defense_combat_level(townPtr->center_x, townPtr->center_y, townPtr->nation_recno, 1, hasWar); if( mobileCombatLevel == -1 ) // do not attack this town because a battle is already going on continue; //---- calculate the combat level of this target town ----// int townCombatLevel = townPtr->protection_available(); return ai_attack_target(townPtr->loc_x1, townPtr->loc_y1, mobileCombatLevel + townCombatLevel); } return 0; }
//--------- Begin of function Nation::think_destroy_raw_site_guard --------// // int Nation::think_destroy_raw_site_guard() { Site* sitePtr; Location* locPtr; Unit* unitPtr; for( int i=site_array.size() ; i>0 ; i-- ) { if( site_array.is_deleted(i) ) continue; sitePtr = site_array[i]; //--- if there is already a mine built on this raw site ---// if( sitePtr->has_mine ) continue; //----- if there is a unit standing on this site -----// locPtr = world.get_loc( sitePtr->map_x_loc, sitePtr->map_y_loc ); if( !locPtr->unit_recno(UNIT_LAND) ) continue; unitPtr = unit_array[ locPtr->unit_recno(UNIT_LAND) ]; if( unitPtr->cur_action != SPRITE_IDLE ) // only attack if this unit is idle continue; if( unitPtr->nation_recno == nation_recno ) // don't attack our own units continue; //------ check if we have a presence in this region ----// if( is_human() && base_town_count_in_region(sitePtr->region_id) == 0 ) continue; //------ check the relationship with this unit ------// // // If we are friendly with this nation, don't attack it. // //---------------------------------------------------// if( get_relation_status(unitPtr->nation_recno) >= RELATION_FRIENDLY ) continue; //--------- attack the enemy unit ---------// int hasWar; int enemyCombatLevel = mobile_defense_combat_level( sitePtr->map_x_loc, sitePtr->map_y_loc, unitPtr->nation_recno, 1, hasWar ); if( enemyCombatLevel == - 1 ) // a war is going on here, don't attack this target continue; if( ai_attack_target(sitePtr->map_x_loc, sitePtr->map_y_loc, enemyCombatLevel, 0, 0, 0, 0, 1) ) // 1-use all camps return 1; } return 0; }