//--------- Begin of function FirmCamp::patrol ---------// // // patrolType = 0 when sortie all // 1 when sortie no leader // 2 when sortie no injury // void FirmCamp::patrol(short patrolType) { err_when( 1+MAX_SOLDIER != MAX_TEAM_MEMBER); err_when( !overseer_recno && !soldier_count ); err_when( is_ai && ai_capture_town_recno ); // ai_capture_town_recno is set after patrol() is called if( nation_recno == nation_array.player_recno ) power.reset_selection(); //------------------------------------------------------------// // If the commander in this camp has units under his lead // outside and he is now going to lead a new team, then // the old team members should be reset. //------------------------------------------------------------// if( overseer_recno ) unit_array[overseer_recno]->team_info->reset(); //------------------------------------------------------------// // mobilize the overseer first, then the soldiers //------------------------------------------------------------// short overseerRecno = overseer_recno; if ((patrolType == 0) || (patrolType == 2 && overseerRecno && unit_array[overseerRecno]->hit_points >= unit_array[overseerRecno]->max_hit_points() - 25)) assign_overseer(0); else // must reset if no leader can be patrol overseerRecno = 0; if( patrol_all_soldier(overseerRecno, patrolType) && overseerRecno ) { Unit* unitPtr = unit_array[overseerRecno]; err_when(unitPtr->rank_id!=RANK_GENERAL && unitPtr->rank_id!=RANK_KING); if( nation_recno == nation_array.player_recno ) unitPtr->select(true); } //---------------------------------------------------// if( overseerRecno && !overseer_recno ) // has overseer and the overseer is mobilized { Unit* overseerUnit = unit_array[overseerRecno]; if(overseerUnit->is_own() ) { se_res.sound( overseerUnit->cur_x_loc(), overseerUnit->cur_y_loc(), 1, 'S', overseerUnit->sprite_id, "SEL"); } err_when( patrol_unit_count > MAX_SOLDIER ); //--- add the overseer into the patrol_unit_array[] of this camp ---// patrol_unit_array[patrol_unit_count++] = overseerRecno; err_when( patrol_unit_count > MAX_SOLDIER+1 ); //------- set the team_info of the overseer -------// err_when( !overseerUnit->team_info ); for( int i=0 ; i<patrol_unit_count ; i++ ) { overseerUnit->team_info->member_unit_array[i] = patrol_unit_array[i]; if( patrol_unit_array[i] != overseerRecno ) // don't set the overseer himself unit_array[ patrol_unit_array[i] ]->leader_unit_recno = overseerRecno; } overseerUnit->team_info->member_count = patrol_unit_count; } //-------- display info --------// if( nation_recno == nation_array.player_recno ) // for player's camp, patrol() can only be called when the player presses the button. info.disp(); err_when( patrol_unit_count < 0 ); err_when( patrol_unit_count > MAX_SOLDIER+1 ); }
//--------- Begin of function FirmCamp::patrol ---------// // void FirmCamp::patrol() { err_when( !overseer_recno && !worker_count ); err_when( firm_ai && ai_capture_town_recno ); // ai_capture_town_recno is set after patrol() is called if( nation_recno == nation_array.player_recno ) power.reset_selection(); //------------------------------------------------------------// // If the commander in this camp has units under his lead // outside and he is now going to lead a new team, then // the old team members should be reset. //------------------------------------------------------------// if(overseer_recno) { TeamInfo* teamInfo = unit_array[overseer_recno]->team_info; if( worker_count>0 && teamInfo->member_count>0 ) { int unitRecno; for( int i=0 ; i<teamInfo->member_count ; i++ ) { unitRecno = teamInfo->member_unit_array[i]; if( unit_array.is_deleted(unitRecno) ) continue; unit_array[unitRecno]->leader_unit_recno = 0; } } } //------------------------------------------------------------// // mobilize workers first, then the overseer. //------------------------------------------------------------// short overseerRecno = overseer_recno; if(patrol_all_soldier() && overseer_recno) { Unit* unitPtr = unit_array[overseer_recno]; err_when(unitPtr->rank_id!=RANK_GENERAL && unitPtr->rank_id!=RANK_KING); unitPtr->team_id = unit_array.cur_team_id-1; // set it to the same team as the soldiers which are defined in mobilize_all_worker() if( nation_recno == nation_array.player_recno ) { unitPtr->selected_flag = 1; unit_array.selected_recno = overseer_recno; unit_array.selected_count++; } } assign_overseer(0); //---------------------------------------------------// if(overseerRecno && !overseer_recno) // has overseer and the overseer is mobilized { Unit* overseerUnit = unit_array[overseerRecno]; if(overseerUnit->is_own() ) { se_res.sound( overseerUnit->cur_x_loc(), overseerUnit->cur_y_loc(), 1, 'S', overseerUnit->sprite_id, "SEL"); } err_when( patrol_unit_count > MAX_WORKER ); //--- add the overseer into the patrol_unit_array[] of this camp ---// patrol_unit_array[patrol_unit_count++] = overseerRecno; err_when( patrol_unit_count > 9 ); //------- set the team_info of the overseer -------// err_when( !overseerUnit->team_info ); for( int i=0 ; i<patrol_unit_count ; i++ ) overseerUnit->team_info->member_unit_array[i] = patrol_unit_array[i]; overseerUnit->team_info->member_count = patrol_unit_count; } //-------- display info --------// if( nation_recno == nation_array.player_recno ) // for player's camp, patrol() can only be called when the player presses the button. info.disp(); err_when( patrol_unit_count < 0 ); err_when( patrol_unit_count > 9 ); }