//--------- Begin of function Firm::disp_spy_button --------// // void Firm::disp_spy_button(int x, int y, int refreshFlag) { if( !own_firm() ) // if not own firm, there is not other button other than the spy button, so always display it left-aligned x = INFO_X1; // if own firm, the x passed will be space position on the interface already, taking into account of the other buttons on interface //-------------------------------------// if( player_spy_count > 0 ) { //------------ spy menu -----------// if( refreshFlag == INFO_REPAINT ) button_spy_menu.paint( x, y, 'A', "SPYMENU" ); x += BUTTON_ACTION_WIDTH; //---------- bribe button -----------// if( nation_recno != nation_array.player_recno ) // only display the bribe button for non-player owned towns { int canBribe=0; if( selected_worker_id ) canBribe = can_spy_bribe(selected_worker_id, nation_array.player_recno ); else if( overseer_recno ) canBribe = can_spy_bribe(0, nation_array.player_recno ); //-------- display the bribe button -------// if( refreshFlag == INFO_REPAINT ) button_bribe.paint( x, y, 'A', "SELBRIBE" ); if( canBribe ) button_bribe.enable(); else button_bribe.disable(); x += BUTTON_ACTION_WIDTH; } } //--------- capture button ----------// int canCapture = can_worker_capture(nation_array.player_recno); if( canCapture ) { if( !button_capture.enable_flag || refreshFlag==INFO_REPAINT ) button_capture.paint( x, y, 'A', "CAPTURE" ); } else { if( refreshFlag==INFO_REPAINT ) button_capture.reset(); else if( button_capture.enable_flag ) button_capture.hide(); } }
//--------- Begin of function Firm::validate_cur_bribe ---------// // // Whether the current bribe action is still valid. // int Firm::validate_cur_bribe() { if( spy_array.is_deleted(action_spy_recno) || spy_array[action_spy_recno]->true_nation_recno != nation_array.player_recno ) { return 0; } return can_spy_bribe( selected_worker_id, spy_array[action_spy_recno]->true_nation_recno ); }
//--------- Begin of function Firm::spy_bribe ---------// // // The money the spy offers to bribe the unit. // // <int> bribeAmount - the amount offered // <short> birberSpyRecno - spy recno of the briber // <short> workerId - if 0, then bribe the overseer, // if >0, then bribe a worker. // // return: <int> >0 - bribing succeeded, return the spy recno of the bribed unit (as it has been turned into a spy) // 0 - bribing failed // int Firm::spy_bribe(int bribeAmount, short briberSpyRecno, short workerId) { if( !can_spy_bribe(workerId, spy_array[briberSpyRecno]->true_nation_recno) ) // this can happen in multiplayer as there is a one frame delay when the message is sent and when it is processed return 0; //---------------------------------------// int succeedChance = spy_bribe_succeed_chance(bribeAmount, briberSpyRecno, workerId); Spy* spyPtr = spy_array[briberSpyRecno]; nation_array[spyPtr->true_nation_recno]->add_expense( EXPENSE_BRIBE, (float) bribeAmount, 0 ); //------ if the bribe succeeds ------// if( succeedChance > 0 && misc.random(100) < succeedChance ) { int spyRecno = spy_array.add_spy(); // add a new Spy record Spy* newSpy = spy_array[spyRecno]; newSpy->spy_skill = 10; newSpy->action_mode = SPY_IDLE; newSpy->spy_loyalty = MIN( 100, MAX(30,succeedChance) ); // within the 30-100 range newSpy->true_nation_recno = spyPtr->true_nation_recno; newSpy->cloaked_nation_recno = spyPtr->cloaked_nation_recno; if( workerId ) { Worker* workerPtr = worker_array+workerId-1; workerPtr->spy_recno = spyRecno; newSpy->race_id = workerPtr->race_id; newSpy->name_id = workerPtr->name_id; err_when( newSpy->race_id < 1 || newSpy->race_id > MAX_RACE ); if( !newSpy->name_id ) // if this worker does not have a name, give him one now as a spy must reserve a name (see below on use_name_id() for reasons) newSpy->name_id = race_res[newSpy->race_id]->get_new_name_id(); } else if( overseer_recno ) { Unit* unitPtr = unit_array[overseer_recno]; unitPtr->spy_recno = spyRecno; newSpy->race_id = unitPtr->race_id; newSpy->name_id = unitPtr->name_id; err_when( newSpy->race_id < 1 || newSpy->race_id > MAX_RACE ); } else err_here(); newSpy->set_place( SPY_FIRM, firm_recno ); //-- Spy always registers its name twice as his name will be freed up in deinit(). Keep an additional right because when a spy is assigned to a town, the normal program will free up the name id., so we have to keep an additional copy race_res[newSpy->race_id]->use_name_id(newSpy->name_id); bribe_result = BRIBE_SUCCEED; if( firm_recno == firm_array.selected_recno ) info.disp(); return newSpy->spy_recno; } else //------- if the bribe fails --------// { spyPtr->get_killed(0); // the spy gets killed when the action failed. // 0 - don't display new message for the spy being killed, so we already display the msg on the interface bribe_result = BRIBE_FAIL; if( firm_recno == firm_array.selected_recno ) info.disp(); return 0; } }