123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- #include <OPOWER.h>
- #include <OGAME.h>
- #include <ODATE.h>
- #include <ONEWS.h>
- #include <OFONT.h>
- #include <OUNIT.h>
- #include <OWORLD.h>
- #include <OBUTTON.h>
- #include <OFIRM.h>
- #include <OTOWN.h>
- #include <ONATION.h>
- #include <ORACERES.h>
- #include <OSYS.h>
- #include <OSPY.h>
- #define SECRET_REPORT_COUNT 7
- static char* secret_report_str_array[] = { "Kingdoms", "Villages", "Economy", "Trade", "Military", "Technology", "Espionage" };
- static char secret_view_mode_array[] = { MODE_NATION, MODE_TOWN, MODE_ECONOMY, MODE_TRADE, MODE_MILITARY, MODE_TECH, MODE_SPY };
- static char secret_view_skill_array[] = { 40, 20, 30, 30, 50, 40, 90 };
- static Button button_secret_report_array[SECRET_REPORT_COUNT];
- static Button button_secret_report_cancel;
- SpyArray::SpyArray() : DynArrayB(sizeof(Spy), 10)
- {
- }
- SpyArray::~SpyArray()
- {
- deinit();
- }
- void SpyArray::init()
- {
- }
- void SpyArray::deinit()
- {
- if( size()==0 )
- return;
-
- zap();
- }
- int SpyArray::add_spy(int unitRecno, int spySkill)
- {
- Spy spy;
- Unit* unitPtr = unit_array[unitRecno];
- memset( &spy, 0, sizeof(spy) );
- spy.spy_place = SPY_MOBILE;
- spy.spy_place_para = unitRecno;
- spy.spy_skill = spySkill;
- spy.spy_loyalty = unitPtr->loyalty;
- spy.race_id = unitPtr->race_id;
- spy.name_id = unitPtr->name_id;
- err_when( unitPtr->race_id < 1 || unitPtr->race_id > MAX_RACE );
- err_when( nation_array.is_deleted(unitPtr->nation_recno) );
- spy.true_nation_recno = unitPtr->nation_recno;
- spy.cloaked_nation_recno = unitPtr->nation_recno;
-
- race_res[spy.race_id]->use_name_id(spy.name_id);
-
- linkin( &spy );
- ((Spy*)get())->spy_recno = recno();
- return recno();
- }
- int SpyArray::add_spy()
- {
- Spy spy;
- memset( &spy, 0, sizeof(spy) );
- linkin( &spy );
- ((Spy*)get())->spy_recno = recno();
- return recno();
- }
- void SpyArray::del_spy(int spyRecno)
- {
- spy_array[spyRecno]->deinit();
- linkout(spyRecno);
- }
- void SpyArray::next_day()
- {
- int spyCount = size();
- Spy* spyPtr;
- for( int i=1 ; i<=spyCount ; i++ )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- spyPtr->next_day();
- if( spy_array.is_deleted(i) )
- continue;
- if( nation_array[spyPtr->true_nation_recno]->is_ai() )
- spyPtr->process_ai();
- }
-
- if( info.game_date%15==0 )
- process_sabotage();
- }
- int SpyArray::find_town_spy(int townRecno, int raceId, int spySeq)
- {
- int spyCount=size(), matchCount=0;
- Spy* spyPtr;
- for( int i=1 ; i<=spyCount ; i++ )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->spy_place==SPY_TOWN &&
- spyPtr->spy_place_para==townRecno &&
- spyPtr->race_id==raceId )
- {
- if( ++matchCount == spySeq )
- return i;
- }
- }
- return 0;
- }
- void SpyArray::process_sabotage()
- {
- Spy* spyPtr;
- Firm* firmPtr;
-
- int i;
- for( i=firm_array.size() ; i>0 ; i-- )
- {
- if( firm_array.is_deleted(i) )
- continue;
- firm_array[i]->sabotage_level = 0;
- }
-
- for( i=spy_array.size() ; i>0 ; i-- )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->action_mode == SPY_SABOTAGE )
- {
- err_when( spyPtr->spy_place != SPY_FIRM );
- firmPtr = firm_array[spyPtr->spy_place_para];
- firmPtr->sabotage_level += spyPtr->spy_skill/5;
- if( firmPtr->sabotage_level > 100 )
- firmPtr->sabotage_level = 100;
- }
- }
- }
- void SpyArray::mobilize_all_spy(int spyPlace, int spyPlacePara, int nationRecno)
- {
- Spy* spyPtr;
- for( int i=size() ; i>0 ; i-- )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->spy_place == spyPlace &&
- spyPtr->spy_place_para == spyPlacePara &&
- spyPtr->true_nation_recno == nationRecno )
- {
- if( spyPtr->spy_place == SPY_TOWN )
- spyPtr->mobilize_town_spy();
- else if( spyPtr->spy_place == SPY_FIRM )
- spyPtr->mobilize_firm_spy();
- }
- }
- }
- void SpyArray::disp_view_secret_menu(int spyRecno, int refreshFlag)
- {
- if( refreshFlag != INFO_REPAINT )
- return;
-
- vga.d3_panel_up( INFO_X1, INFO_Y1, INFO_X2, INFO_Y1+42 );
- font_san.put_paragraph( INFO_X1+7, INFO_Y1+5, INFO_X2-7, INFO_Y2-5,
- "Steal which type of secrets?" );
-
- int y=INFO_Y1+45;
- err_when( spy_array.is_deleted(spyRecno) );
- Spy* spyPtr = spy_array[spyRecno];
- for( int i=0 ; i<SECRET_REPORT_COUNT ; i++ )
- {
- if( spyPtr->spy_skill >= secret_view_skill_array[i] )
- {
- button_secret_report_array[i].paint_text( INFO_X1, y, INFO_X2, y+21, secret_report_str_array[i] );
- y+=23;
- }
- else
- {
- button_secret_report_array[i].reset();
- }
- }
- button_secret_report_cancel.paint_text( INFO_X1, y, INFO_X2, y+22, "Cancel" );
- }
- int SpyArray::detect_view_secret_menu(int spyRecno, int nationRecno)
- {
-
- int rc=0;
- for( int i=0 ; i<SECRET_REPORT_COUNT ; i++ )
- {
- if( button_secret_report_array[i].detect() )
- {
- sys.set_view_mode( secret_view_mode_array[i], nationRecno, spyRecno );
- rc=1;
- break;
- }
- }
-
- if( button_secret_report_cancel.detect() )
- rc = 1;
- return rc;
- }
- void SpyArray::update_firm_spy_count(int firmRecno)
- {
-
- Spy* spyPtr;
- Firm* firmPtr = firm_array[firmRecno];
- firmPtr->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 )
- {
- firmPtr->player_spy_count++;
- }
- }
- }
- void SpyArray::change_cloaked_nation(int spyPlace, int spyPlacePara, int fromNationRecno, int toNationRecno)
- {
- Spy* spyPtr;
- for( int i=spy_array.size() ; i>0 ; i-- )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->cloaked_nation_recno != fromNationRecno )
- continue;
- if( spyPtr->spy_place != spyPlace )
- continue;
-
- if( spyPlace == SPY_FIRM || spyPlace == SPY_TOWN )
- {
- if( spyPtr->spy_place_para != spyPlacePara )
- continue;
- }
- if(spyPlace==spyPtr->spy_place && spyPlacePara==spyPtr->spy_place_para &&
- spyPtr->true_nation_recno==toNationRecno)
- spyPtr->set_action_mode(SPY_IDLE);
-
- if( spyPlace == SPY_FIRM )
- {
- int firmOverseerRecno = firm_array[spyPtr->spy_place_para]->overseer_recno;
- if( firmOverseerRecno && unit_array[firmOverseerRecno]->spy_recno == i )
- {
- unit_array[firmOverseerRecno]->spy_change_nation(toNationRecno, COMMAND_AUTO);
- continue;
- }
- }
- else if( spyPlace == SPY_MOBILE )
- {
- unit_array[spyPtr->spy_place_para]->spy_change_nation(toNationRecno, COMMAND_AUTO);
- continue;
- }
-
- spyPtr->cloaked_nation_recno = toNationRecno;
- }
- }
- int SpyArray::total_spy_skill_level(int spyPlace, int spyPlacePara, int spyNationRecno, int& spyCount)
- {
- int totalSpyLevel=0;
- Spy* spyPtr;
- spyCount = 0;
- for( int i=spy_array.size() ; i>0 ; i-- )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->true_nation_recno != spyNationRecno )
- continue;
- if( spyPtr->spy_place != spyPlace )
- continue;
- if( spyPtr->spy_place_para != spyPlacePara )
- continue;
- spyCount++;
- totalSpyLevel += spyPtr->spy_skill;
- }
- return totalSpyLevel;
- }
- 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;
- totalPop = firmPtr->worker_count + (firmPtr->overseer_recno>0);
- }
- else
- err_here();
-
- int enemySpyCount=0, counterSpySkill=0;
- Spy* spyPtr;
- 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;
- else
- enemySpyCount++;
- }
- }
-
- if( enemySpyCount == totalPop )
- return 0;
- err_when( enemySpyCount > totalPop );
-
- 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 )
- continue;
- if( spyPtr->spy_place == spyPlace &&
- spyPtr->spy_place_para == spyPlacePara &&
- spyPtr->true_nation_recno != nationRecno )
- {
- int escapeChance = 100 + spyPtr->spy_skill - counterSpySkill;
- escapeChance = max( spyPtr->spy_skill/10, escapeChance );
- if( m.random(escapeChance) == 0 )
- {
- spyPtr->get_killed();
- return 1;
- }
- }
- }
- return 0;
- }
- void SpyArray::set_action_mode(int spyPlace, int spyPlacePara, int actionMode)
- {
- int spyCount=size();
- Spy* spyPtr;
- for( int i=1 ; i<=spyCount ; i++ )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->spy_place==spyPlace &&
- spyPtr->spy_place_para==spyPlacePara )
- {
- spyPtr->set_action_mode(actionMode);
- }
- }
- }
- void SpyArray::ai_spy_town_rebel(int townRecno)
- {
- int spyCount=size();
- Spy* spyPtr;
- for( int i=1 ; i<=spyCount ; i++ )
- {
- if( spy_array.is_deleted(i) )
- continue;
- spyPtr = spy_array[i];
- if( spyPtr->spy_place==SPY_TOWN &&
- spyPtr->spy_place_para==townRecno &&
- nation_array[spyPtr->true_nation_recno]->is_ai() )
- {
-
- int unitRecno = spyPtr->mobilize_town_spy();
-
- if( unitRecno )
- spyPtr->think_mobile_spy_new_action();
- }
- }
- }
- int SpyArray::needed_view_secret_skill(int viewMode)
- {
- for( int i=0 ; i<SECRET_REPORT_COUNT ; i++ )
- {
- if( secret_view_mode_array[i] == viewMode )
- return secret_view_skill_array[i];
- }
- return 0;
- }
- #ifdef DEBUG
- Spy* SpyArray::operator[](int recNo)
- {
- Spy* spyPtr = (Spy*) get(recNo);
- if( !spyPtr || spyPtr->spy_recno==0 )
- err.run( "SpyArray[] is deleted" );
- return spyPtr;
- }
- #endif
|