//--------- Begin of function FirmCamp::assign_unit ---------// // void FirmCamp::assign_unit(int unitRecno) { Unit* unitPtr = unit_array[unitRecno]; //------- if this is a construction worker -------// if( unitPtr->skill.skill_id == SKILL_CONSTRUCTION ) { set_builder(unitRecno); return; } //-------- assign the unit ----------// int rankId = unit_array[unitRecno]->rank_id; if( rankId == RANK_GENERAL || rankId==RANK_KING ) { assign_overseer(unitRecno); } else { assign_worker(unitRecno); } }
//--------- Begin of function FirmBase::assign_unit ---------// // void FirmBase::assign_unit(int unitRecno) { Unit* unitPtr = unit_array[unitRecno]; //### begin alex 18/9 ###// /*//------ only assign units of the right race ------// if( unitPtr->race_id != race_id ) return;*/ //#### end alex 18/9 ####// //------- if this is a construction worker -------// if( unitPtr->skill.skill_id == SKILL_CONSTRUCTION ) { set_builder(unitRecno); return; } //### begin alex 18/9 ###// //------ only assign units of the right race ------// if( unitPtr->race_id != race_id ) return; //#### end alex 18/9 ####// //-------- assign the unit ----------// int rankId = unit_array[unitRecno]->rank_id; if( rankId == RANK_GENERAL || rankId==RANK_KING ) { assign_overseer(unitRecno); } else { assign_worker(unitRecno); } }
//--------- 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 FirmBase::detect_info ---------// // void FirmBase::detect_info() { if( detect_basic_info() ) return; if( !should_show_info() ) return; //------ detect the overseer button -----// int rc = mouse.any_click(INFO_X1+6, INFO_Y1+58, INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, LEFT_BUTTON) ? 1 : mouse.any_click(INFO_X1+6, INFO_Y1+58, INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, RIGHT_BUTTON) ? 2 : 0; if( rc==1 ) // display this overseer's info { selected_worker_id = 0; disp_base_info(INFO_Y1+54, INFO_UPDATE); disp_worker_list(INFO_Y1+104, INFO_UPDATE); disp_worker_info(INFO_Y1+168, INFO_UPDATE); } //--------- detect soldier info ---------// if( detect_worker_list() ) { disp_base_info(INFO_Y1+54, INFO_UPDATE); disp_worker_list(INFO_Y1+104, INFO_UPDATE); disp_worker_info(INFO_Y1+168, INFO_UPDATE); } //---------- detect spy button ----------// detect_spy_button(); if( !own_firm() ) return; //------ detect the overseer button -----// if( rc==2 ) { if(remote.is_enable()) { // packet structure : <firm recno> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short)); shortPtr[0] = firm_recno; } else { assign_overseer(0); // the overseer quits the camp } } //----------- detect invoke -----------// if( button_invoke.detect() ) { if(remote.is_enable()) { // ##### begin Gilbert 14/10 #######// // packet structure : <firm recno> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_BASE_INVOKE_GOD, sizeof(short)); shortPtr[0] = firm_recno; // ##### end Gilbert 14/10 #######// } else { invoke_god(); } } //----------- detect reward -----------// if( button_reward.detect() ) { reward(selected_worker_id, COMMAND_PLAYER); // ##### begin Gilbert 26/9 ########// se_ctrl.immediate_sound("TURN_ON"); // ##### end Gilbert 26/9 ########// } }
//--------- Begin of function FirmCamp::detect_soldier_list ---------// // // <int> selecteSpyMenu 0=main menu; 1=selecting spy // when selectSpyMenu is 0, return 1 if left click on a unit, return 2 if right click on a unit // when selectSpyMenu is 1, return spy_recno of the clicked spy, 0 if no own spy is clicked // int FirmCamp::detect_soldier_list(int selectSpyMenu) { int dispY1 = disp_soldier_list_y1; // display in ascending order to select the overseer first for( int i = 0; i <= soldier_count; ++i ) { // display soldier i int row = i/SOLDIER_PER_ROW; int x = INFO_X1 + 18 + (i % SOLDIER_PER_ROW) * SOLDIER_X_SPACING; int y = INFO_Y1 + 50 + row * SOLDIER_Y_SPACING; int yHp = INFO_Y1 + 7 + row * SOLDIER_Y_SPACING; int windowX1 = INFO_X1 + 16; int windowX2 = INFO_X1 + 220; int windowY1 = INFO_Y1 + 5 + row * 84; // 5,89 int windowY2 = windowY1 + 80 - 1 ; int unitId; int hp; int maxHp; // ##### begin Gilbert 21/9 ######// int combatLevel; int skillLevel; int loyalty; // ##### end Gilbert 21/9 ######// int ownSpy; if( i==0 ) { if( !overseer_recno ) continue; // overseer Unit *overseer = unit_array[overseer_recno]; unitId = overseer->unit_id; hp = (int) overseer->hit_points; maxHp = overseer->max_hit_points(); combatLevel = (int) overseer->combat_level(); skillLevel = (int) overseer->skill_level(); if( overseer->rank_id != RANK_GENERAL ) loyalty = overseer->loyalty; else loyalty = -1; // king or other(?) ownSpy = overseer->is_own_spy() ? overseer->spy_recno : 0; } else { // soldier Soldier *soldierPtr = &soldier_array[i-1]; unitId = soldierPtr->unit_id; hp = soldierPtr->hit_points; maxHp = soldierPtr->max_hit_points(); combatLevel = (int) soldierPtr->combat_level(); skillLevel = (int) soldierPtr->skill_level(); if( soldierPtr->race_id ) loyalty = soldierPtr->loyalty; else loyalty = -1; ownSpy = soldierPtr->is_own_spy() ? soldierPtr->spy_recno : 0; } if( selectSpyMenu && !ownSpy ) continue; int rc = info.draw_unit_icon( x+SOLDIER_X_SPACING/2, y, unitId, nation_recno, windowX1, windowY1, windowX2, windowY2, 24 ); // detect left button (8) and right button(16) if( !rc ) continue; if( selectSpyMenu == 0 ) { // -------- main menu ---------// if( rc & 8 ) { // ----- left click select soldier/overseer -------// selected_soldier_id = i; return 1; } else if( rc & 16 && is_own() ) { // ------ right click mobilize solidier/overseer ------// if( i == 0 ) { if(remote.is_enable()) { // packet structure : <firm recno> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short)); shortPtr[0] = firm_recno; } else { assign_overseer(0); // the overseer quits the camp } } else { // #### begin Gilbert 26/1 #####// if( !soldier_array[i-1].is_under_training() ) mobilize_soldier(i, COMMAND_PLAYER); else cancel_train_soldier(i, COMMAND_PLAYER); // #### end Gilbert 26/1 #####// } return 2; } } else if( selectSpyMenu == 1 ) { if( rc & 8 && ownSpy ) { selected_soldier_id = i; return ownSpy; } } } return 0; /* if( !should_show_info() ) return 0; if( is_own() ) { //------ detect the overseer button -----// int rc = mouse.single_click(INFO_X1+6, INFO_Y1+58, INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, 2 ); if( rc==1 ) { selected_soldier_id = 0; return 1; } else if( rc==2 && is_own() ) { if(remote.is_enable()) { // packet structure : <firm recno> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short)); shortPtr[0] = firm_recno; } else { assign_overseer(0); // the overseer quits the camp } return 1; } } //------- detect buttons on hiring firm soldiers -------// int i, x, y; for( i=0 ; i<soldier_count ; i++ ) { x = INFO_X1+6+i%4*50; y = pop_disp_y1+1+i/4*29; switch( mouse.single_click(x, y, x+27, y+23, 2) ) { case 1: // left button to select soldier selected_soldier_id = i+1; return 1; case 2: if( is_own() ) // only if this is our own firm { //--- if the town where the unit lives belongs to the nation of this firm ---// mobilize_soldier(i+1, COMMAND_PLAYER); return 1; } break; } } return 0; */ }
//--------- 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 ); }
//--------- Begin of function FirmCamp::detect_info ---------// // void FirmCamp::detect_info() { if( detect_basic_info() ) return; if( !should_show_info() ) return; //------ detect the overseer button -----// int rc = mouse.single_click(INFO_X1+6, INFO_Y1+58, INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, 2 ); if( rc==1 ) // display this overseer's info { selected_worker_id = 0; disp_camp_info(INFO_Y1+54, INFO_UPDATE); disp_worker_list(INFO_Y1+104, INFO_UPDATE); disp_worker_info(INFO_Y1+168, INFO_UPDATE); } //--------- detect soldier info ---------// if( detect_worker_list() ) { disp_camp_info(INFO_Y1+54, INFO_UPDATE); disp_worker_list(INFO_Y1+104, INFO_UPDATE); disp_worker_info(INFO_Y1+168, INFO_UPDATE); } //---------- detect spy button ----------// detect_spy_button(); if( !own_firm() ) return; //------ detect the overseer button -----// if( rc==2 ) { if(remote.is_enable()) { // packet structure : <firm recno> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short)); shortPtr[0] = firm_recno; } else { assign_overseer(0); // the overseer quits the camp } } //----------- detect patrol -----------// if( button_patrol.detect() ) { if(remote.is_enable()) { // packet structure : <firm recno> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_CAMP_PATROL, sizeof(short)); shortPtr[0] = firm_recno; } else { patrol(); } } //----------- detect reward -----------// if( button_reward.detect() ) { reward(selected_worker_id, COMMAND_PLAYER); // ##### begin Gilbert 25/9 ######// se_ctrl.immediate_sound("TURN_ON"); // ##### end Gilbert 25/9 ######// } //----- detect defense mode button -------// if( button_defense.detect() ) { // ##### begin Gilbert 25/9 ######// se_ctrl.immediate_sound( !defense_flag?(char*)"TURN_ON":(char*)"TURN_OFF"); // ##### end Gilbert 25/9 ######// if( !remote.is_enable() ) { // update RemoteMsg::toggle_camp_patrol() defense_flag = !defense_flag; } else { // packet structure : <firm recno> <defense_flag> short *shortPtr=(short *)remote.new_send_queue_msg(MSG_F_CAMP_TOGGLE_PATROL, 2*sizeof(short)); shortPtr[0] = firm_recno; shortPtr[1] = !defense_flag; } button_defense.update_bitmap( defense_flag ? (char*)"DEFENSE1" : (char*)"DEFENSE0" ); } }