123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928 |
- /*
- * Seven Kingdoms: Ancient Adversaries
- *
- * Copyright 1997,1998 Enlight Software Ltd.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- //Filename : OREMOTEM.CPP
- //Description : Object RemoteMsg
- #include <ALL.h>
- #include <OFONT.h>
- #include <ONEWS.h>
- #include <OSYS.h>
- #include <ONATION.h>
- #include <OUNIT.h>
- #include <OGAME.h>
- #include <OREMOTE.h>
- #include <OFIRM.h>
- #include <OFIRMALL.h>
- #include <OTOWN.h>
- #include <OLOG.h>
- #include <OUNITALL.h>
- #include <OSPY.h>
- #include <OTALKRES.h>
- #include <OLONGLOG.h>
- #include <OCRC_STO.h>
- // ##### patch begin Gilbert 20/1 #######//
- #include <OBOX.h>
- // ##### patch end Gilbert 20/1 #######//
- //---------------- Define variable type ---------------//
- typedef void (RemoteMsg::*MsgProcessFP)();
- //----------- Define function pointers array -----------//
- static MsgProcessFP msg_process_function_array[] =
- {
- &RemoteMsg::queue_header,
- &RemoteMsg::queue_trailer,
- &RemoteMsg::new_nation,
- &RemoteMsg::update_game_setting,
- &RemoteMsg::start_game,
- &RemoteMsg::next_frame,
- &RemoteMsg::request_resend,
- &RemoteMsg::tell_send_time,
- &RemoteMsg::set_speed,
- &RemoteMsg::tell_random_seed,
- &RemoteMsg::request_save_game,
- &RemoteMsg::player_quit,
- &RemoteMsg::unit_stop,
- &RemoteMsg::unit_move,
- &RemoteMsg::unit_set_force_move,
- &RemoteMsg::unit_attack,
- &RemoteMsg::unit_assign,
- &RemoteMsg::unit_change_nation,
- &RemoteMsg::unit_build_firm,
- &RemoteMsg::unit_burn,
- &RemoteMsg::units_settle,
- &RemoteMsg::unit_set_guard,
- &RemoteMsg::unit_set_rank,
- &RemoteMsg::unit_dismount,
- &RemoteMsg::unit_reward,
- &RemoteMsg::units_transform,
- &RemoteMsg::unit_resign,
- &RemoteMsg::units_assign_to_ship,
- &RemoteMsg::units_ship_to_beach,
- &RemoteMsg::unit_succeed_king,
- &RemoteMsg::units_return_camp,
- &RemoteMsg::caravan_change_goods,
- &RemoteMsg::caravan_set_stop,
- &RemoteMsg::caravan_del_stop,
- &RemoteMsg::caravan_selected,
- &RemoteMsg::ship_unload_unit,
- &RemoteMsg::ship_unload_all_units,
- &RemoteMsg::ship_change_goods,
- &RemoteMsg::ship_set_stop,
- &RemoteMsg::ship_del_stop,
- &RemoteMsg::ship_change_mode,
- &RemoteMsg::ship_selected,
- &RemoteMsg::god_cast,
- &RemoteMsg::change_spy_nation,
- &RemoteMsg::notify_cloaked_nation,
- &RemoteMsg::unit_change_aggressive_mode,
- &RemoteMsg::spy_change_notify_flag,
- //#### trevor 15/10 ######//
- &RemoteMsg::spy_assassinate,
- //#### trevor 15/10 ######//
- &RemoteMsg::unit_add_way_point,
- &RemoteMsg::firm_sell,
- &RemoteMsg::firm_cancel,
- &RemoteMsg::firm_destruct,
- &RemoteMsg::firm_set_repair,
- &RemoteMsg::firm_train_level,
- &RemoteMsg::mobilize_worker,
- &RemoteMsg::mobilize_overseer,
- &RemoteMsg::mobilize_builder,
- &RemoteMsg::firm_toggle_link_firm,
- &RemoteMsg::firm_toggle_link_town,
- &RemoteMsg::firm_pull_town_people,
- &RemoteMsg::firm_set_worker_home,
- &RemoteMsg::firm_bribe,
- &RemoteMsg::firm_capture,
- &RemoteMsg::firm_reward,
- &RemoteMsg::camp_patrol,
- &RemoteMsg::toggle_camp_patrol,
- &RemoteMsg::inn_hire,
- &RemoteMsg::market_scrap,
- &RemoteMsg::market_hire_caravan,
- &RemoteMsg::research_start,
- &RemoteMsg::build_weapon,
- &RemoteMsg::cancel_weapon,
- &RemoteMsg::skip_build_weapon,
- &RemoteMsg::build_ship,
- &RemoteMsg::sail_ship,
- &RemoteMsg::skip_build_ship,
- &RemoteMsg::factory_change_product,
- &RemoteMsg::base_mobilize_prayer,
- &RemoteMsg::invoke_god,
- &RemoteMsg::town_recruit,
- &RemoteMsg::town_skip_recruit,
- &RemoteMsg::town_migrate,
- &RemoteMsg::town_collect_tax,
- &RemoteMsg::town_reward,
- &RemoteMsg::town_toggle_link_firm,
- &RemoteMsg::town_toggle_link_town,
- &RemoteMsg::town_auto_tax,
- &RemoteMsg::town_auto_grant,
- &RemoteMsg::town_grant_independent,
- &RemoteMsg::wall_build,
- &RemoteMsg::wall_destruct,
- &RemoteMsg::spy_cycle_action,
- &RemoteMsg::spy_leave_town,
- &RemoteMsg::spy_leave_firm,
- &RemoteMsg::spy_capture_firm,
- &RemoteMsg::spy_drop_identity,
- &RemoteMsg::spy_reward,
- &RemoteMsg::spy_exposed,
- &RemoteMsg::send_talk_msg,
- &RemoteMsg::reply_talk_msg,
- &RemoteMsg::nation_contact,
- &RemoteMsg::nation_set_should_attack,
- &RemoteMsg::chat,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- &RemoteMsg::compare_remote_object,
- };
- //---------- Declare static functions ----------//
- static void validate_selected_unit_array(short* selectedUnitArray, short& selectedCount);
- static short validate_firm(short firmRecno, unsigned flags = 0);
- static short validate_town(short townRecno, unsigned flags = 0);
- //------ Begin of function RemoteMsg::process_msg -----//
- //
- void RemoteMsg::process_msg()
- {
- if( id==0 )
- return;
- err_when( id<FIRST_REMOTE_MSG_ID || id>LAST_REMOTE_MSG_ID );
- MsgProcessFP msgProcessFP = msg_process_function_array[id-FIRST_REMOTE_MSG_ID];
- (this->*msgProcessFP)(); // call the corrsponding function to return the news process_msg
- }
- //------- End of function RemoteMsg::process_msg -----//
- //-------- Begin of function RemoteMsg::queue_header ---------//
- //
- // Nothing here, it shouldn't be called at all.
- //
- void RemoteMsg::queue_header()
- {
- }
- //--------- End of function RemoteMsg::queue_header ---------//
- //-------- Begin of function RemoteMsg::queue_trailer ---------//
- //
- // Nothing here
- //
- void RemoteMsg::queue_trailer()
- {
- #ifdef DEBUG
- long_log->printf("Queue trailer of nation %d\n", *(short *)data_buf);
- #endif
- }
- //--------- End of function RemoteMsg::queue_trailer ---------//
- //-------- Begin of function RemoteMsg::new_nation ---------//
- //
- // Create a remote player.
- //
- // Sent from a client to the host when the client start a new nation.
- //
- // Client --> MSG_NEW_NATION --> Host
- //
- // Sent from the host to a newly joined client to update it with all
- // existing nations.
- //
- // Host --> UPDATE_GAME_SETTING --> Client
- //
- // structure of data_buf:
- //
- // <Nation> - Nation object of the newly joined nation
- //
- void RemoteMsg::new_nation()
- {
- //-------- create a new nation now --------//
- if( !remote.is_host ) // ignore this message if this is not the host
- return;
- Nation* nationPtr = (Nation*)(this->data_buf);
- int nationRecno = nation_array.new_nation( NATION_REMOTE, nationPtr->race_id, nationPtr->color_scheme_id, nationPtr->player_id );
- game.mp_broadcast_setting();
- }
- //--------- End of function RemoteMsg::new_nation ---------//
- //-------- Begin of function RemoteMsg::update_game_setting ---------//
- //
- // Sent from the host to clients, update the client with the latest
- // game settings.
- //
- // Host --> UPDATE_GAME_SETTING --> Client
- //
- // structure of data_buf:
- //
- // <long> - random seed
- // <short> - The number of nations joined
- // <Nation..> - An array of nation objects
- //
- void RemoteMsg::update_game_setting()
- {
- //------- get parameters -----------//
- char* dataPtr = data_buf;
- //------- set random seed -----------//
- m.set_random_seed(*(long*)dataPtr);
- dataPtr += sizeof(long);
- //------- update nation_array -----------//
- int nationCount = *(short*)dataPtr;
- dataPtr += sizeof(short);
- char nationType;
- int i, ownCount=0;
- nation_array.deinit(); // deinit() first and then recreate it as follows
- for( i=0 ; i<nationCount ; i++ )
- {
- short nationRecno = *(short *)dataPtr;
- dataPtr += sizeof(short);
- DWORD dpPlayerId = *(DWORD *)dataPtr;
- dataPtr += sizeof(DWORD);
- short colorSchemeId = *(short *)dataPtr;
- dataPtr += sizeof(short);
- short raceId = *(short *)dataPtr;
- dataPtr += sizeof(short);
- // int NationType;
- if( dpPlayerId == remote.self_player_id() ) // if this nation is the player's nation
- {
- nationType = NATION_OWN;
- ownCount++;
- }
- else
- nationType = NATION_REMOTE;
- if(nationRecno != nation_array.new_nation( nationType, raceId, colorSchemeId, dpPlayerId ))
- {
- // nation recno should match across all players
- err.run("Error in transmitting nation data");
- }
- }
- err_when( ownCount>1 );
- }
- //--------- End of function RemoteMsg::update_game_setting ---------//
- //-------- Begin of function RemoteMsg::start_game ---------//
- //
- // The host sends MSG_START_GAME to the clients to notify them
- // to start the game.
- //
- void RemoteMsg::start_game()
- {
- game.started_flag = 1;
- }
- //--------- End of function RemoteMsg::start_game ---------//
- //-------- Begin of function RemoteMsg::next_frame ---------//
- //
- // Notify the others that we are ready to proceed to the next
- // frame.
- //
- // structure of data_buf:
- //
- // <short> - nation recno of the message queue
- //
- void RemoteMsg::next_frame()
- {
- short nationRecno = *((short*)data_buf);
- if( !nation_array.is_deleted(nationRecno) )
- {
- nation_array[nationRecno]->next_frame_ready=1;
- }
- }
- //--------- End of function RemoteMsg::next_frame ---------//
- //-------- Begin of function RemoteMsg::request_resend ---------//
- //
- // Request a specific player to resend its packets.
- //
- // structure of data_buf:
- //
- // <DWORD> - player id.
- // <DWORD> - frame count of the message queue
- //
- void RemoteMsg::request_resend()
- {
- DWORD *dwordPtr = (DWORD*) data_buf;
- err_when( dwordPtr[0] == (~nation_array)->player_id ); // sent to itself
- remote.send_backup_now(dwordPtr[0], dwordPtr[1]);
- }
- //--------- End of function RemoteMsg::request_resend ---------//
- //-------- Begin of function RemoteMsg::tell_send_time ---------//
- //
- // Display the delivery time of the packet
- //
- void RemoteMsg::tell_send_time()
- {
- String str;
- unsigned long sendTime = *((unsigned long*)data_buf);
- str = "Packet Delivery Time: ";
- str += m.get_time() - sendTime;
- str += " ms ";
- str += m.get_time();
- font_san.disp( ZOOM_X1, 4, str, ZOOM_X1+249);
- }
- //--------- End of function RemoteMsg::tell_send_time ---------//
- //-------- Begin of function RemoteMsg::set_speed ---------//
- //
- // Order the selected units to stop.
- //
- // structure of data_buf:
- //
- // <short> - the game speed setting.
- //
- void RemoteMsg::set_speed()
- {
- err_when( id != MSG_SET_SPEED);
- short* shortPtr = (short*) data_buf;
- sys.set_speed(shortPtr[0], COMMAND_REMOTE); // 1-remote call
- }
- //--------- End of function RemoteMsg::set_speed ---------//
- //-------- Begin of function RemoteMsg::tell_random_seed ---------//
- //
- // structure of data_buf:
- //
- // <short> - nation recno
- // <long> - random seed
- //
- void RemoteMsg::tell_random_seed()
- {
- // ######## patch begin Gilbert 20/1 #########//
- char *p = data_buf;
- short nationRecno = *(short *)p;
- p += sizeof(short);
- long remoteSeed = *(long *)p;
- #if defined(DEBUG) && defined(ENABLE_LOG)
- String logLine("remote random seed ");
- logLine += nationRecno;
- logLine += ",";
- logLine += remoteSeed;
-
- LOG_MSG(logLine);
- #endif
- // it assume random seed of each nation come in sequence
- // if may fails when connection lost
- static long lastRemoteSeed = -1;
- static short lastNation = 0x7fff;
- if( nationRecno <= lastNation)
- {
- // assume the smallest human nation
- lastRemoteSeed = remoteSeed;
- }
- else
- {
- if( lastRemoteSeed != remoteSeed )
- {
- #ifdef DEBUG
- // delete long_log;
- // long_log = NULL;
- #endif
- LOG_DUMP;
- if( (remote.sync_test_level & 1) && (remote.sync_test_level >= 0) )
- {
- remote.sync_test_level = ~remote.sync_test_level; // signal error encountered
- if( sys.debug_session )
- err.run( "Multiplayer Random Seed Sync Error." );
- else
- box.msg( "Multiplayer Random Seed Sync Error." );
- }
- }
- }
- lastNation = nationRecno;
- // ######## patch end Gilbert 20/1 #########//
- }
- //-------- End of function RemoteMsg::tell_random_seed ---------//
- //-------- Begin of function RemoteMsg::request_save_game ---------//
- void RemoteMsg::request_save_game()
- {
- err_when( id != MSG_REQUEST_SAVE );
- // message struct : <DWORD> frame when the game should save
- #ifdef DEBUG
- long_log->printf("Request save on %d\n", *(DWORD*)data_buf);
- #endif
- sys.mp_request_save( *(DWORD*)data_buf);
- }
- //-------- End of function RemoteMsg::request_save_game ---------//
- //-------- Begin of function RemoteMsg::unit_stop ---------//
- //
- // Order the selected units to stop.
- //
- // structure of data_buf:
- //
- // <short> - no. of selected unit.
- // <char..> - selected unit recno array
- //
- void RemoteMsg::unit_stop()
- {
- err_when( id != MSG_UNIT_STOP);
- short* shortPtr = (short*) data_buf;
- validate_selected_unit_array(shortPtr+1, shortPtr[0]);
- if(shortPtr[0] > 0)
- {
- #ifdef DEBUG
- long_log->printf("stop units : ");
- for(int i = 0; i < shortPtr[0]; ++i)
- {
- long_log->printf("%d,", shortPtr[1+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- #endif
- unit_array.stop( shortPtr+1, shortPtr[0], COMMAND_REMOTE ); // 1-remote action
- }
- }
- //--------- End of function RemoteMsg::unit_stop ---------//
- //-------- Begin of function RemoteMsg::unit_move ---------//
- //
- // Order the selected units to move to the specified location.
- //
- // structure of data_buf:
- //
- // <short> - destXLoc
- // <short> - destYLoc
- // <short> - no. of selected unit.
- // <char..> - selected unit recno array
- //
- void RemoteMsg::unit_move()
- {
- err_when( id != MSG_UNIT_MOVE);
- short* shortPtr = (short*) data_buf;
- validate_selected_unit_array(shortPtr+4, shortPtr[2]);
- if( shortPtr[2] > 0)
- {
- #ifdef DEBUG
- long_log->printf("move to (%d,%d), units : ", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[2]; ++i)
- {
- long_log->printf("%d,", shortPtr[4+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.move_to( shortPtr[0], shortPtr[1], shortPtr[3], shortPtr+4, shortPtr[2], COMMAND_REMOTE ); // 1-remote action
- }
- }
- //--------- End of function RemoteMsg::unit_move ---------//
- //--------- Begin of function RemoteMsg::unit_set_force_move ---------//
- void RemoteMsg::unit_set_force_move()
- {
- err_when(id != MSG_UNIT_SET_FORCE_MOVE);
- // packet structure : <unit count> <unit recno>...
- short* shortPtr = (short*) data_buf;
- validate_selected_unit_array(shortPtr+1, shortPtr[0]);
- if( shortPtr[0] > 0)
- {
- int i;
- #ifdef DEBUG
- long_log->printf("set force move to , units : ");
- for(i = 0; i < shortPtr[0]; ++i)
- {
- long_log->printf("%d,", shortPtr[1+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- for( i = 0; i < shortPtr[0]; ++i )
- {
- unit_array[shortPtr[1+i]]->force_move_flag = 1;
- }
- }
- }
- //--------- End of function RemoteMsg::unit_set_force_move ---------//
- //-------- Begin of function RemoteMsg::unit_attack ---------//
- //
- // Order the selected units to attack at the specified location.
- //
- // structure of data_buf:
- //
- // <short> - targetXLoc
- // <short> - targetYLoc
- // <short> - unitRecno
- // <short> - no. of selected unit.
- // <short> - divided;
- // <short..> - selected unit recno array
- //
- void RemoteMsg::unit_attack()
- {
- err_when( id != MSG_UNIT_ATTACK);
- short* shortPtr = (short*) data_buf;
- // ###### patch begin Gilbert 5/8 ###########//
- validate_selected_unit_array(shortPtr+5, shortPtr[3]);
- if( shortPtr[3] > 0)
- {
- #ifdef DEBUG
- long_log->printf("attack (%d,%d), units : ", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[3]; ++i)
- {
- long_log->printf("%d,", shortPtr[5+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- int passCount = unit_array.divide_attack_by_nation(remote.nation_processing, shortPtr+5, shortPtr[3]);
- if( passCount > 0 )
- unit_array.attack( shortPtr[0], shortPtr[1], shortPtr[4], shortPtr+5, passCount, COMMAND_REMOTE, shortPtr[2] ); // 1-remote action
- }
- // ###### patch end Gilbert 5/8 ###########//
- }
- //--------- End of function RemoteMsg::unit_attack ---------//
- //-------- Begin of function RemoteMsg::unit_assign ---------//
- //
- // Order the selected units to move to the specified location.
- //
- // structure of data_buf:
- //
- // <short> - destXLoc
- // <short> - destYLoc
- // <short> - no. of selected unit.
- // <char..> - selected unit recno array
- //
- void RemoteMsg::unit_assign()
- {
- err_when( id != MSG_UNIT_ASSIGN);
- short* shortPtr = (short*) data_buf;
- validate_selected_unit_array(shortPtr+4, shortPtr[2]);
- if( shortPtr[2] > 0)
- {
- #ifdef DEBUG
- long_log->printf("assign to (%d,%d), units : ", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[2]; ++i)
- {
- long_log->printf("%d,", shortPtr[4+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.assign( shortPtr[0], shortPtr[1], shortPtr[3], COMMAND_REMOTE, shortPtr+4, shortPtr[2]);
- }
- }
- //--------- End of function RemoteMsg::unit_assign ---------//
- //-------- Begin of function RemoteMsg::unit_change_nation ---------//
- //
- // Order the selected units to move to the specified location.
- //
- // structure of data_buf:
- //
- // <short> - newNationRecno
- // <short> - no. of selected unit.
- // <char..> - selected unit recno array
- //
- void RemoteMsg::unit_change_nation()
- {
- /*
- short* shortPtr = (short*) data_buf;
- short* selectedUnitArray = shortPtr+2;
- int selectedCount = shortPtr[1];
- validate_selected_unit_array(selectedUnitArray, selectedCount);
- unit_array.change_nation( shortPtr[0], selectedUnitArray, selectedCount, COMMAND_REMOTE ); // 1-remote action
- */
- }
- //--------- End of function RemoteMsg::unit_change_nation ---------//
- //------ Begin of static function validate_selected_unit_array ------//
- //
- // Validate all units in selectedUnitArray, remove deleted units from
- // selectedUnitArray.
- //
- static void validate_selected_unit_array(short* selectedUnitArray, short& selectedUnitCount)
- {
- for( int i=0 ; i<selectedUnitCount ; i++ )
- {
- Unit* unitPtr;
- if( unit_array.is_deleted(selectedUnitArray[i]) ||
- !(unitPtr = unit_array[selectedUnitArray[i]]) ||
- !unitPtr->is_visible() || !unitPtr->is_nation(remote.nation_processing) )
- {
- memmove( selectedUnitArray+i, selectedUnitArray+i+1, sizeof(short) * (selectedUnitCount-i-1) );
- selectedUnitCount--;
- i--; // stay with the current recno as the records have been moved. The recno in the current position is actually the next record.
- }
- }
- }
- //------- End of static function validate_selected_unit_array -------//
- //------ Begin of static function validate_firm ------//
- //
- // return the firmRecno if the firm is controllable by the remote player
- //
- // bit 0 - skip firm's nation checking
- //
- static short validate_firm(short firmRecno, unsigned flags)
- {
- err_when( !(flags & 1) && remote.nation_processing == 0);
- Firm* firmPtr;
- if( firmRecno && !firm_array.is_deleted(firmRecno)
- && (firmPtr = firm_array[firmRecno])
- && ((flags & 1) || firmPtr->nation_recno == remote.nation_processing) )
- return firmRecno;
- else
- return 0;
- }
- //------ End of static function validate_firm ------//
- //------ Begin of static function validate_town ------//
- //
- // return the townRecno if the town is controllable by the remote player
- //
- // bit 0 - skip town's nation checking
- //
- static short validate_town(short townRecno, unsigned flags)
- {
- Town* townPtr;
- err_when( !(flags & 1) && remote.nation_processing == 0);
- if( townRecno && !town_array.is_deleted(townRecno)
- && (townPtr = town_array[townRecno])
- && ((flags & 1) || townPtr->nation_recno == remote.nation_processing) )
- return townRecno;
- else
- return 0;
- }
- //------ End of static function validate_firm ------//
- // ------- Begin of function RemoteMsg::unit_build ---------//
- void RemoteMsg::unit_build_firm()
- {
- err_when( id != MSG_UNIT_BUILD_FIRM);
- // packet structure : <unit recno> <xLoc> <yLoc> <firmId>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 )
- {
- #ifdef DEBUG
- long_log->printf("unit %d build firm %d at (%d,%d)\n", shortPtr[0], shortPtr[3], shortPtr[1], shortPtr[2]);
- #endif
- unit_array[*shortPtr]->build_firm( shortPtr[1], shortPtr[2],
- shortPtr[3], COMMAND_REMOTE );
- }
- }
- // ------- End of function RemoteMsg::unit_build_firm ---------//
- // ------- Begin of function RemoteMsg::unit_burn ---------//
- void RemoteMsg::unit_burn()
- {
- err_when( id != MSG_UNIT_BURN);
- // packet structure : <unit recno> <xLoc> <yLoc>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 )
- {
- #ifdef DEBUG
- long_log->printf("unit %d burn at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- unit_array[*shortPtr]->burn(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::unit_burn ---------//
- // ------- Begin of function RemoteMsg::units_settle ---------//
- void RemoteMsg::units_settle()
- {
- err_when( id != MSG_UNITS_SETTLE);
- // packet structure : <xLoc> <yLoc> <no. of units> <divided> <unit recno ...>
- short *shortPtr = (short *)data_buf;
- validate_selected_unit_array(shortPtr+4, shortPtr[2]);
- if( shortPtr[2] > 0)
- {
- #ifdef DEBUG
- long_log->printf("settle at (%d,%d), units : ", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[2]; ++i)
- {
- long_log->printf("%d,", shortPtr[4+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.settle(shortPtr[0], shortPtr[1], shortPtr[3], COMMAND_REMOTE, shortPtr+4, shortPtr[2]);
- }
- }
- // ------- End of function RemoteMsg::units_settle ---------//
- // ------- Begin of function RemoteMsg::unit_set_guard ---------//
- //
- // **BUGHERE, this function is no longer needed.
- //
- void RemoteMsg::unit_set_guard()
- {
- /*
- err_when( id != MSG_UNIT_SET_GUARD);
- // packet structure : <unit recno> <new guard mode 0/1>
- short *shortPtr = (short *)data_buf;
- unit_array[*shortPtr]->guard_mode = (char) shortPtr[1];
- */
- }
- // ------- End of function RemoteMsg::unit_set_guard ---------//
- // ------- Begin of function RemoteMsg::unit_set_rank ---------//
- void RemoteMsg::unit_set_rank()
- {
- err_when( id != MSG_UNIT_SET_RANK);
- // packet structure : <unit recno> <new rank>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- // ignore <new rank> parameter
- // unit_array[*shortPtr]->set_rank(shortPtr[1]);
- if( unitCount > 0)
- {
- #ifdef DEBUG
- long_log->printf("unit %d promote/demote to %d\n", shortPtr[0], shortPtr[1]);
- #endif
- switch(unit_array[*shortPtr]->rank_id)
- {
- case RANK_SOLDIER:
- unit_array[*shortPtr]->set_rank(RANK_GENERAL);
- break;
- case RANK_GENERAL:
- unit_array[*shortPtr]->set_rank(RANK_SOLDIER);
- break;
- }
- }
- }
- // ------- End of function RemoteMsg::unit_set_rank ---------//
- // ------- Begin of function RemoteMsg::unit_dismount ---------//
- void RemoteMsg::unit_dismount()
- {
- err_when( id != MSG_UNIT_DISMOUNT);
- // packet structure : <unit recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 )
- {
- #ifdef DEBUG
- long_log->printf("unit %d dismount\n", shortPtr[0]);
- #endif
- UnitVehicle *uv = (UnitVehicle *) unit_array[*shortPtr];
- uv->dismount();
- }
- }
- // ------- End of function RemoteMsg::unit_dismount ---------//
- // ------- Begin of function RemoteMsg::unit_reward ---------//
- void RemoteMsg::unit_reward()
- {
- //###### begin trevor 9/6 #######//
- err_when( id != MSG_UNIT_REWARD);
- // packet structure : <unit recno> <rewarding nation recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 )
- {
- #ifdef DEBUG
- long_log->printf("nation %d rewards unit %d\n", shortPtr[1], shortPtr[0]);
- #endif
- unit_array[*shortPtr]->reward(shortPtr[1]);
- }
- //###### end trevor 9/6 #######//
- }
- // ------- End of function RemoteMsg::unit_reward ---------//
- // ------- Begin of function RemoteMsg::units_transform ------//
- void RemoteMsg::units_transform()
- {
- err_when( id != MSG_UNITS_TRANSFORM );
- // packet structure <this recno> <no. of units> <unit recno> ...
- short *shortPtr = (short *)data_buf;
- validate_selected_unit_array(shortPtr+2, shortPtr[1]);
- if( unit_array.is_deleted(*shortPtr) )
- {
- // if <this recno> is dead, use the first unit in
- // the unit group
- if( shortPtr[1] >= 1)
- {
- *shortPtr = shortPtr[2];
- unit_array[*shortPtr]->group_transform(COMMAND_REMOTE,
- shortPtr +2, shortPtr[1]);
- }
- }
- else
- {
- unit_array[*shortPtr]->group_transform(COMMAND_REMOTE,
- shortPtr +2, shortPtr[1]);
- }
- }
- // ------- End of function RemoteMsg::units_transform ------//
- // ------- Begin of function RemoteMsg::unit_resign ---------//
- void RemoteMsg::unit_resign()
- {
- err_when( id != MSG_UNIT_RESIGN);
- // packet structure : <unit recno> <nation recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 && unit_array[*shortPtr]->is_nation(shortPtr[1])
- && unit_array[*shortPtr]->can_resign() )
- {
- #ifdef DEBUG
- long_log->printf("nation %d resigns unit %d\n", shortPtr[1], shortPtr[0]);
- #endif
- unit_array[*shortPtr]->resign(COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::unit_resign ---------//
- // ------- Begin of function RemoteMsg::units_assign_to_ship ---------//
- void RemoteMsg::units_assign_to_ship()
- {
- err_when( id != MSG_UNITS_ASSIGN_TO_SHIP);
- // ##### patch begin Gilbert 5/8 ######//
- // packet structure : <xLoc> <yLoc> <ship recno> <no. of units> <divided> <unit recno ...>
- short *shortPtr = (short *)data_buf;
- validate_selected_unit_array(shortPtr+5, shortPtr[3]);
- if( shortPtr[3] > 0)
- {
- #ifdef DEBUG
- long_log->printf("assign to ship at (%d,%d), units : ", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[3]; ++i)
- {
- long_log->printf("%d,", shortPtr[5+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.assign_to_ship(shortPtr[0], shortPtr[1], shortPtr[4], shortPtr+5, shortPtr[3], COMMAND_REMOTE, shortPtr[2]);
- }
- // ##### patch end Gilbert 5/8 ######//
- }
- // ------- End of function RemoteMsg::units_assign_to_ship ---------//
- // ------- Begin of function RemoteMsg::units_ship_to_beach ---------//
- void RemoteMsg::units_ship_to_beach()
- {
- err_when( id != MSG_UNITS_SHIP_TO_BEACH);
- // packet structure : <xLoc> <yLoc> <no. of units> <divided> <unit recno ...>
- short *shortPtr = (short *)data_buf;
- validate_selected_unit_array(shortPtr+4, shortPtr[2]);
- if( shortPtr[2] > 0)
- {
- #ifdef DEBUG
- long_log->printf("move ships to beach at (%d,%d), units : ", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[2]; ++i)
- {
- long_log->printf("%d,", shortPtr[4+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.ship_to_beach(shortPtr[0], shortPtr[1], shortPtr[3], shortPtr+4, shortPtr[2], COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::units_assign_to_ship ---------//
- // ------- Begin of function RemoteMsg::unit_succeed_king ------//
- void RemoteMsg::unit_succeed_king()
- {
- err_when( id != MSG_UNIT_SUCCEED_KING);
- // packet structure : <unit recno> <nation recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 && !nation_array.is_deleted(shortPtr[1]) &&
- unit_array[*shortPtr]->nation_recno == shortPtr[1] )
- {
- #ifdef DEBUG
- long_log->printf("unit %d succeed nation %d\n", shortPtr[0], shortPtr[1]);
- #endif
- nation_array[shortPtr[1]]->succeed_king(*shortPtr);
- if(unit_array.selected_recno == *shortPtr)
- info.disp();
- }
- }
- // ------- End of function RemoteMsg::unit_succeed_king ------//
- // ------- Begin of function RemoteMsg::units_return_camp ------//
- void RemoteMsg::units_return_camp()
- {
- err_when( id != MSG_UNITS_RETURN_CAMP );
- // packet structure : <no. of units> <unit recno ...>
- short *shortPtr = (short *)data_buf;
- validate_selected_unit_array(shortPtr+1, *shortPtr);
- if( *shortPtr > 0)
- {
- #ifdef DEBUG
- long_log->printf("return to camp, units : ");
- for(int i = 0; i < *shortPtr; ++i)
- {
- long_log->printf("%d,", shortPtr[1+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.return_camp(COMMAND_REMOTE, shortPtr+1, *shortPtr);
- }
- }
- // ------- Begin of function RemoteMsg::caravan_change_goods ------//
- void RemoteMsg::caravan_change_goods()
- {
- err_when( id != MSG_U_CARA_CHANGE_GOODS );
- // packet structure <unit recno> <stop id> <new pick_up_type>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitCaravan *caravanPtr;
- if( unitPtr->unit_id != UNIT_CARAVAN)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("caravan %d change goods row %d, %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- caravanPtr = (UnitCaravan *)unitPtr;
- // caravanPtr->stop_array[shortPtr[1]].pick_up_type = (char) shortPtr[2];
- caravanPtr->set_stop_pick_up(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- //if( unit_array.selected_recno == *shortPtr )
- // info.disp();
- }
- }
- }
- // ------- End of function RemoteMsg::caravan_change_goods ------//
- // ------- Begin of function RemoteMsg::caravan_set_stop ------//
- void RemoteMsg::caravan_set_stop()
- {
- err_when( id != MSG_U_CARA_SET_STOP );
- // packet structure <unit recno> <stop id> <stop x> <stop y>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitCaravan *caravanPtr;
- if( unitPtr->unit_id != UNIT_CARAVAN)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("caravan %d set stop %d at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2], shortPtr[3]);
- #endif
- caravanPtr = (UnitCaravan *)unitPtr;
- caravanPtr->set_stop(shortPtr[1], shortPtr[2], shortPtr[3], COMMAND_REMOTE);
- // if( unit_array.selected_recno == *shortPtr )
- // info.disp();
- }
- }
- }
- // ------- End of function RemoteMsg::caravan_set_stop ------//
- // ------- Begin of function RemoteMsg::caravan_del_stop ------//
- void RemoteMsg::caravan_del_stop()
- {
- err_when( id != MSG_U_CARA_DEL_STOP );
- // packet structure <unit recno> <stop id>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitCaravan *caravanPtr;
- if( unitPtr->unit_id != UNIT_CARAVAN)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("caravan %d delete stop %d, %d\n", shortPtr[0], shortPtr[1]);
- #endif
- caravanPtr = (UnitCaravan *)unitPtr;
- caravanPtr->del_stop(shortPtr[1], COMMAND_REMOTE);
- //if( unit_array.selected_recno == *shortPtr )
- // info.disp();
- }
- }
- }
- // ------- End of function RemoteMsg::caravan_del_stop ------//
- // ------- Begin of function RemoteMsg::ship_unload_unit ---------//
- void RemoteMsg::ship_unload_unit()
- {
- err_when( id != MSG_U_SHIP_UNLOAD_UNIT );
- // packet structure <unit recno> <unitSeqId>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- if( unitPtr->sprite_info->sprite_type == 'U'
- && unitPtr->sprite_info->sprite_sub_type == 'M')
- {
- UnitMarine *shipPtr = (UnitMarine *)unitPtr;
- if( shortPtr[1] <= shipPtr->unit_count )
- {
- // check if the unit is a ship
- #ifdef DEBUG
- long_log->printf("ship %d unload unit %d\n", shortPtr[0], shortPtr[1]);
- #endif
- shipPtr->unload_unit(shortPtr[1], COMMAND_REMOTE);
- if( unit_array.selected_recno == *shortPtr )
- info.disp();
- }
- }
- else
- {
- err_here();
- }
- }
- }
- // ------- End of function RemoteMsg::ship_unload_unit ---------//
- // ----- Begin of function RemoteMsg::ship_unload_all_units ----- //
- void RemoteMsg::ship_unload_all_units()
- {
- err_when( id != MSG_U_SHIP_UNLOAD_ALL_UNITS );
- // packet structure <unit recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- if( unitPtr->sprite_info->sprite_type == 'U'
- && unitPtr->sprite_info->sprite_sub_type == 'M')
- {
- // check if the unit is a ship
- #ifdef DEBUG
- long_log->printf("ship %d unload all units\n", shortPtr[0]);
- #endif
- UnitMarine *shipPtr = (UnitMarine *)unitPtr;
- shipPtr->unload_all_units(COMMAND_REMOTE);
- if( unit_array.selected_recno == *shortPtr )
- info.disp();
- }
- else
- {
- err_here();
- }
- }
- }
- // ----- End of function RemoteMsg::ship_unload_all_units ----- //
- // ------- Begin of function RemoteMsg::ship_change_goods ------//
- void RemoteMsg::ship_change_goods()
- {
- err_when( id != MSG_U_SHIP_CHANGE_GOODS );
- // packet structure <unit recno> <stop id> <new pick_up_type>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitMarine *shipPtr;
- if( unitPtr->sprite_info->sprite_sub_type != 'M')
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("ship %d change goods, row %d, %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- shipPtr = (UnitMarine *)unitPtr;
- // shipPtr->stop_array[shortPtr[1]].pick_up_type = (char) shortPtr[2];
- shipPtr->set_stop_pick_up(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- // if( unit_array.selected_recno == *shortPtr )
- // info.disp();
- }
- }
- }
- // ------- End of function RemoteMsg::ship_change_goods ------//
- // ------- Begin of function RemoteMsg::ship_set_stop ------//
- void RemoteMsg::ship_set_stop()
- {
- err_when( id != MSG_U_SHIP_SET_STOP );
- // packet structure <unit recno> <stop id> <stop x> <stop y>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitMarine *shipPtr;
- if( unitPtr->sprite_info->sprite_sub_type != 'M')
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("ship %d set stop %d at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2], shortPtr[3]);
- #endif
- shipPtr = (UnitMarine *)unitPtr;
- shipPtr->set_stop(shortPtr[1], shortPtr[2], shortPtr[3], COMMAND_REMOTE);
- }
- }
- }
- // ------- End of function RemoteMsg::ship_set_stop ------//
- // ------- Begin of function RemoteMsg::ship_del_stop ------//
- void RemoteMsg::ship_del_stop()
- {
- err_when( id != MSG_U_SHIP_DEL_STOP );
- // packet structure <unit recno> <stop id>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitMarine *shipPtr;
- if( unitPtr->sprite_info->sprite_sub_type != 'M')
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("ship %d delete stop %d\n", shortPtr[0], shortPtr[1]);
- #endif
- shipPtr = (UnitMarine *)unitPtr;
- shipPtr->del_stop(shortPtr[1], COMMAND_REMOTE);
- }
- }
- }
- // ------- End of function RemoteMsg::ship_del_stop ------//
- // ------- Begin of function RemoteMsg::ship_change_mode ------//
- void RemoteMsg::ship_change_mode()
- {
- err_when( id != MSG_U_SHIP_CHANGE_MODE );
- // packet structure <unit recno> <new mode>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- UnitMarine *shipPtr;
- if( unitPtr->sprite_info->sprite_sub_type != 'M')
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("ship %d changes mode %d\n", shortPtr[0], shortPtr[1]);
- #endif
- shipPtr = (UnitMarine *)unitPtr;
- shipPtr->auto_mode = (char) shortPtr[1];
- if(*shortPtr==unit_array.selected_recno)
- info.disp();
- }
- }
- }
- // ------- End of function RemoteMsg::ship_change_mode ------//
- // ------- Begin of function RemoteMsg::change_spy_nation ------//
- void RemoteMsg::change_spy_nation()
- {
- err_when( id != MSG_UNIT_SPY_NATION );
- // packet structure <unit recno> <new nation recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- #ifdef DEBUG
- long_log->printf("unit %d changes nation %d\n", shortPtr[0], shortPtr[1]);
- #endif
- unit_array[*shortPtr]->spy_change_nation(shortPtr[1], COMMAND_REMOTE);
- if( unit_array.selected_recno == *shortPtr ||
- unit_array[*shortPtr]->selected_flag)
- info.disp();
- }
- }
- // ------- End of function RemoteMsg::change_spy_nation ------//
- // ------- Begin of function RemoteMsg::notify_cloaked_nation ------//
- void RemoteMsg::notify_cloaked_nation()
- {
- err_when( id != MSG_UNIT_SPY_NOTIFY_CLOAKED_NATION );
- // packet structure <unit recno> <new nation recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0)
- {
- if( !unit_array[*shortPtr]->spy_recno )
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("unit %d notify cloaked nation %d\n", shortPtr[0], shortPtr[1]);
- #endif
- spy_array[unit_array[*shortPtr]->spy_recno]->notify_cloaked_nation_flag
- = (char) shortPtr[1];
- }
- if( unit_array.selected_recno == *shortPtr ||
- unit_array[*shortPtr]->selected_flag)
- info.disp();
- }
- }
- // ------- End of function RemoteMsg::notify_cloaked_nation ------//
- //------ Begin of function RemoteMsg::unit_change_aggressive_mode -----//
- //
- void RemoteMsg::unit_change_aggressive_mode()
- {
- err_when( id != MSG_UNIT_CHANGE_AGGRESSIVE_MODE);
- // packet structure : <unit recno> <new aggressive mode 0/1>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount > 0 )
- {
- #ifdef DEBUG
- long_log->printf("unit %d %s aggressive mode\n", shortPtr[0], shortPtr[1] ? "set" : "clear");
- #endif
- unit_array[*shortPtr]->aggressive_mode = (char) shortPtr[1];
- }
- }
- //------- End of function RemoteMsg::unit_change_aggressive_mode ------//
- //------ Begin of function RemoteMsg::spy_change_notify_flag -----//
- //
- void RemoteMsg::spy_change_notify_flag()
- {
- err_when( id != MSG_SPY_CHANGE_NOTIFY_FLAG) ;
- // packet structure : <spy recno> <new notify flag 0/1>
- short *shortPtr = (short *)data_buf;
- spy_array[*shortPtr]->notify_cloaked_nation_flag = (char) shortPtr[1];
- }
- //------- End of function RemoteMsg::spy_change_notify_flag ------//
- //########## begin trevor 15/10 #############//
- //------ Begin of function RemoteMsg::spy_assassinate -----//
- //
- void RemoteMsg::spy_assassinate()
- {
- err_when( id != MSG_SPY_ASSASSINATE );
- // packet structure : <spy recno> <assassinate target unit recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d assassinate unit %d", shortPtr[0], shortPtr[1]);
- #endif
- spy_array[*shortPtr]->assassinate( shortPtr[1], COMMAND_REMOTE );
- }
- }
- //------- End of function RemoteMsg::spy_assassinate ------//
- //########## end trevor 15/10 #############//
- // ------- Begin of function RemoteMsg::firm_sell ---------//
- void RemoteMsg::firm_sell()
- {
- err_when( id != MSG_FIRM_SELL);
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("sell firm %d\n", shortPtr[0]);
- #endif
- firm_array[*shortPtr]->sell_firm(COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::firm_sell ---------//
- // ------- Begin of function RemoteMsg::firm_cancel ---------//
- void RemoteMsg::firm_cancel()
- {
- err_when( id != MSG_FIRM_CANCEL);
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("firm %d cancel construction\n", shortPtr[0]);
- #endif
- firm_array[*shortPtr]->cancel_construction(COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::firm_cancel ---------//
- // ------- Begin of function RemoteMsg::firm_destruct ---------//
- void RemoteMsg::firm_destruct()
- {
- err_when( id != MSG_FIRM_DESTRUCT);
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("destruct firm %d\n", shortPtr[0]);
- #endif
- firm_array[*shortPtr]->destruct_firm(COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::firm_destruct ---------//
- // ------- Begin of function RemoteMsg::firm_set_repair ---------//
- void RemoteMsg::firm_set_repair()
- {
- //##### begin trevor 19/6 ######//
- /*
- err_when( id != MSG_FIRM_SET_REPAIR);
- // packet structure : <firm recno> <new setting>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- firm_array[*shortPtr]->is_repairing = (char)shortPtr[1];
- */
- //##### end trevor 19/6 ######//
- }
- // ------- End of function RemoteMsg::firm_set_repair ---------//
- // ------- Begin of function RemoteMsg::firm_train_level ---------//
- void RemoteMsg::firm_train_level()
- {
- /* //**BUGHERE, no more training in game
- err_when( id != MSG_FIRM_TRAIN_LEVEL);
- // packet structure : <firm recno> <new train level>
- short *shortPtr = (short *)data_buf;
- if( !firm_array.is_deleted(*shortPtr) )
- firm_array[*shortPtr]->train_level = (char)shortPtr[1];
- */
- }
- // ------- End of function RemoteMsg::firm_train_level ---------//
- // ------- Begin of function RemoteMsg::mobilize_worker ---------//
- void RemoteMsg::mobilize_worker()
- {
- err_when( id != MSG_FIRM_MOBL_WORKER);
- // packet structure : <firm recno> <workerId>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) && shortPtr[1] <= firm_array[*shortPtr]->worker_count)
- {
- #ifdef DEBUG
- long_log->printf("firm %d mobilize worker %d\n", shortPtr[0], shortPtr[1]);
- #endif
- firm_array[*shortPtr]->mobilize_worker(shortPtr[1],COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::mobilize_worker ---------//
- // ------- Begin of function RemoteMsg::mobilize_overseer ---------//
- void RemoteMsg::mobilize_overseer()
- {
- err_when( id != MSG_FIRM_MOBL_OVERSEER);
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) && firm_array[*shortPtr]->overseer_recno )
- {
- #ifdef DEBUG
- long_log->printf("firm %d mobilize overseer\n", shortPtr[0]);
- #endif
- firm_array[*shortPtr]->assign_overseer(0);
- }
- }
- // ------- End of function RemoteMsg::mobilize_overseer ---------//
- // ------- Begin of function RemoteMsg::mobilize_builder ---------//
- void RemoteMsg::mobilize_builder()
- {
- err_when( id != MSG_FIRM_MOBL_BUILDER);
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) && firm_array[*shortPtr]->builder_recno )
- {
- #ifdef DEBUG
- long_log->printf("firm %d mobilize builder\n", shortPtr[0]);
- #endif
- firm_array[*shortPtr]->set_builder(0);
- }
- }
- // ------- End of function RemoteMsg::mobilize_builder ---------//
- // ------ Begin of function RemoteMsg::firm_toggle_link_firm ----//
- void RemoteMsg::firm_toggle_link_firm()
- {
- err_when( id != MSG_FIRM_TOGGLE_LINK_FIRM);
- // packet structure : <firm recno> <link Id> <toggle Flag>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- // ###### begin Gilbert 10/11 #######//
- Firm *firmPtr = firm_array[*shortPtr];
- short linkedFirmRecno = 0;
- if( shortPtr[1] <= firmPtr->linked_firm_count
- && (linkedFirmRecno = firmPtr->linked_firm_array[shortPtr[1]-1])
- && validate_firm(linkedFirmRecno, 1) )
- {
- #ifdef DEBUG
- long_log->printf("firm %d %s firm link %d\n", shortPtr[0],
- shortPtr[2] ? "set":"clear", shortPtr[1]);
- #endif
- firm_array[*shortPtr]->toggle_firm_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- }
- // ###### end Gilbert 10/11 #######//
- }
- }
- // ------ End of function RemoteMsg::firm_toggle_link_firm ----//
- // ------ Begin of function RemoteMsg::firm_toggle_link_town ----//
- void RemoteMsg::firm_toggle_link_town()
- {
- err_when( id != MSG_FIRM_TOGGLE_LINK_TOWN);
- // packet structure : <firm recno> <link Id> <toggle Flag>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- // ###### begin Gilbert 10/11 ########//
- Firm *firmPtr = firm_array[*shortPtr];
- short linkedTownRecno = 0;
- if( shortPtr[1] <= firmPtr->linked_town_count
- && (linkedTownRecno = firmPtr->linked_town_array[shortPtr[1]-1])
- && validate_town(linkedTownRecno, 1) )
- {
- #ifdef DEBUG
- long_log->printf("firm %d %s town link %d\n", shortPtr[0],
- shortPtr[2] ? "set":"clear", shortPtr[1]);
- #endif
- firmPtr->toggle_town_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- // update town loyalty if the firm is FIRM_CAMP
- if( firmPtr->firm_id == FIRM_CAMP )
- {
- Town *townPtr = town_array[linkedTownRecno];
- if( townPtr->nation_recno )
- townPtr->update_target_loyalty();
- else
- townPtr->update_target_resistance();
- townPtr->update_camp_link();
- }
- }
- // ###### end Gilbert 10/11 ########//
- }
- }
- // ------ End of function RemoteMsg::firm_toggle_link_town ----//
- // ------ Begin of function RemoteMsg::firm_pull_town_people ----//
- void RemoteMsg::firm_pull_town_people()
- {
- err_when( id != MSG_FIRM_PULL_TOWN_PEOPLE);
- // packet structure : <firm recno> <town recno> <race Id or 0> <force Pull>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) && validate_town(shortPtr[1]) )
- {
- #ifdef DEBUG
- long_log->printf("firm %d %s pull race %d from town %d\n", shortPtr[0],
- shortPtr[3] ? "forcely" : "", shortPtr[2], shortPtr[1]);
- #endif
- firm_array[*shortPtr]->pull_town_people(shortPtr[1], COMMAND_REMOTE, shortPtr[2], shortPtr[3]);
- }
- }
- // ------ End of function RemoteMsg::firm_pull_town_people ----//
- // ------ Begin of function RemoteMsg::firm_set_worker_home ----//
- void RemoteMsg::firm_set_worker_home()
- {
- err_when( id != MSG_FIRM_SET_WORKER_HOME);
- // packet structure : <firm recno> <town recno> <workerId>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) && validate_town(shortPtr[1]) )
- {
- #ifdef DEBUG
- long_log->printf("firm %d workder %d migrate to town %d\n", shortPtr[0], shortPtr[2], shortPtr[1]);
- #endif
- firm_array[*shortPtr]->set_worker_home_town(shortPtr[1], COMMAND_REMOTE, shortPtr[2]);
- }
- }
- // ------ End of function RemoteMsg::firm_set_worker_home ----//
- // ------ Begin of function RemoteMsg::firm_bribe ----//
- void RemoteMsg::firm_bribe()
- {
- err_when( id != MSG_FIRM_BRIBE);
- // packet structure <firm recno> <spy recno> <bribe target : worker (0=overseer)> <amount>
- short *shortPtr = (short *)data_buf;
- // ###### begin Gilbert 10/11 #######//
- Firm *firmPtr;
- if( validate_firm(*shortPtr, 1) && !spy_array.is_deleted(shortPtr[1])
- && (firmPtr = firm_array[*shortPtr])
- && (shortPtr[2] == 0 && firmPtr->overseer_recno ||
- shortPtr[2] >= 1 && shortPtr[2] <= firm_array[*shortPtr]->worker_count) )
- // ###### end Gilbert 10/11 #######//
- {
- #ifdef DEBUG
- long_log->printf("firm %d, spy %d briber worker %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- firm_array[*shortPtr]->spy_bribe(shortPtr[3], shortPtr[1], shortPtr[2]);
- }
- }
- // ------ End of function RemoteMsg::firm_bribe ----//
- // ------ Begin of function RemoteMsg::firm_capture ----//
- void RemoteMsg::firm_capture()
- {
- err_when( id != MSG_FIRM_CAPTURE);
- // packet structure <firm recno> <nation recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr, 1) )
- {
- #ifdef DEBUG
- long_log->printf("firm %d, capture by nation %d\n", shortPtr[0], shortPtr[1]);
- #endif
- firm_array[*shortPtr]->capture_firm(shortPtr[1]);
- }
- }
- // ------ End of function RemoteMsg::firm_capture ----//
- // ------- Begin of function RemoteMsg::camp_patrol ---------//
- void RemoteMsg::camp_patrol()
- {
- err_when( id != MSG_F_CAMP_PATROL);
- if( validate_firm(*(short *)data_buf) )
- {
- FirmCamp *camp = firm_array[*(short *)data_buf]->cast_to_FirmCamp();
- if(camp)
- {
- if(camp->overseer_recno || camp->worker_count > 0)
- {
- #ifdef DEBUG
- long_log->printf("camp %d patrols\n", *(short *)data_buf);
- #endif
- camp->patrol();
- }
- }
- else
- {
- err_here();
- }
- }
- }
- // ------- End of function RemoteMsg::camp_patrol ---------//
- // ------- Begin of function RemoteMsg::toggle_camp_patrol ---------//
- void RemoteMsg::toggle_camp_patrol()
- {
- err_when( id != MSG_F_CAMP_TOGGLE_PATROL);
- // packet structure <firm recno> <defense_flag>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmCamp *camp = firm_array[*shortPtr]->cast_to_FirmCamp();
- if(camp)
- {
- #ifdef DEBUG
- long_log->printf("camp %d %s patrol flag\n", shortPtr[0],
- shortPtr[1] ? "set":"clear");
- #endif
- camp->defense_flag = char(shortPtr[1]);
- if( firm_array.selected_recno == *shortPtr)
- info.disp();
- }
- else
- {
- err_here();
- }
- }
- }
- // ------- End of function RemoteMsg::toggle_camp_patrol ---------//
- // ------- Begin of function RemoteMsg::firm_reward ---------//
- void RemoteMsg::firm_reward()
- {
- err_when( id != MSG_FIRM_REWARD);
- // packet structure : <firm recno> <worker id>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- Firm *firmPtr = firm_array[*shortPtr];
- // ##### begin Gilbert 10/11 ########//
- if( shortPtr[1] == 0 && firmPtr->overseer_recno ||
- shortPtr[1] >= 1 && shortPtr[1] <= firmPtr->worker_count )
- {
- #ifdef DEBUG
- long_log->printf("firm %d reward worker %d\n", shortPtr[0], shortPtr[1]);
- #endif
- firmPtr->reward(shortPtr[1], COMMAND_REMOTE);
- }
- // ##### end Gilbert 10/11 ########//
- }
- }
- // ------- End of function RemoteMsg::firm_reward ---------//
- // ------- Begin of function RemoteMsg::inn_hire ---------//
- void RemoteMsg::inn_hire()
- {
- err_when( id != MSG_F_INN_HIRE);
- // packet structure : <firm recno>, <hire Id> <nation no>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmInn *inn = firm_array[*shortPtr]->cast_to_FirmInn();
- if(inn)
- {
- #ifdef DEBUG
- long_log->printf("inn %d hire %d, by nation %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- inn->hire(shortPtr[1]);
- if( shortPtr[2] == nation_array.player_recno)
- {
- inn->put_info(INFO_REPAINT);
- }
- }
- else
- {
- err_here();
- }
- }
- }
- // ------- End of function RemoteMsg::inn_hire ---------//
- // ------- Begin of function RemoteMsg::market_scrap ---------//
- void RemoteMsg::market_scrap()
- {
- err_when( id != MSG_F_MARKET_SCRAP );
- // packet structure : <firm recno> <cell no 0-3>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmMarket *firmMarket = firm_array[*shortPtr]->cast_to_FirmMarket();
- if(!firmMarket)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("market %d scrap good row %d\n", shortPtr[0], shortPtr[1]);
- #endif
- MarketGoods* marketGoods = firmMarket->market_goods_array + shortPtr[1];
- err_when(marketGoods->raw_id && marketGoods->product_raw_id);
- if(marketGoods->raw_id)
- {
- firmMarket->market_raw_array[marketGoods->raw_id-1] = NULL;
- marketGoods->raw_id = 0;
- }
- else if(marketGoods->product_raw_id)
- {
- firmMarket->market_product_array[marketGoods->product_raw_id-1] = NULL;
- marketGoods->product_raw_id = 0;
- }
- marketGoods->stock_qty = (float) 0;
- if( firm_array.selected_recno == *shortPtr )
- info.disp();
- }
- }
- }
- // ------- End of function RemoteMsg::market_scrap ---------//
- // ------- Begin of function RemoteMsg::market_hire_caravan ---------//
- void RemoteMsg::market_hire_caravan()
- {
- err_when( id != MSG_F_MARKET_HIRE_CARA );
- // packet structure : <town recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmMarket *market = firm_array[*shortPtr]->cast_to_FirmMarket();
- if(!market)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("market %d hire caravan\n", shortPtr[0]);
- #endif
- market->hire_caravan(COMMAND_REMOTE);
- }
- }
- }
- // ------- End of function RemoteMsg::market_hire_caravan ---------//
- // ------- Begin of function RemoteMsg::research_start ---------//
- void RemoteMsg::research_start()
- {
- err_when( id != MSG_F_RESEARCH_START );
- // packet structure : <firm recno> <tech Id>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmResearch *research = firm_array[*shortPtr]->cast_to_FirmResearch();
- if(!research)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("tower of science %d start research tech %d\n", shortPtr[0], shortPtr[1]);
- #endif
- research->start_research(shortPtr[1], COMMAND_REMOTE);
- }
- }
- }
- // ------- End of function RemoteMsg::research_start ---------//
- // ------- Begin of function RemoteMsg::build_weapon ---------//
- void RemoteMsg::build_weapon()
- {
- err_when( id != MSG_F_WAR_BUILD_WEAPON );
- // packet structure : <firm recno> <unit Id>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmWar *warFactory = firm_array[*shortPtr]->cast_to_FirmWar();
- if(!warFactory)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("war factory %d start building unit id %d\n", shortPtr[0], shortPtr[1]);
- #endif
- warFactory->add_queue(shortPtr[1]);
- }
- }
- }
- // ------- End of function RemoteMsg::build_weapon ---------//
- // ------- Begin of function RemoteMsg::cancel_weapon ---------//
- void RemoteMsg::cancel_weapon()
- {
- err_when( id != MSG_F_WAR_CANCEL_WEAPON );
- // packet structure : <firm recno> <unit Id>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmWar *warFactory = firm_array[*shortPtr]->cast_to_FirmWar();
- if(!warFactory)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("war factory %d cancel building unit id %d\n", shortPtr[0], shortPtr[1]);
- #endif
- warFactory->remove_queue(shortPtr[1]);
- }
- }
- }
- // ------- End of function RemoteMsg::cancel_weapon ---------//
- // ------- Begin of function RemoteMsg::skip_build_weapon ---------//
- void RemoteMsg::skip_build_weapon()
- {
- err_when( id != MSG_F_WAR_SKIP_WEAPON );
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmWar *warFactory = firm_array[*shortPtr]->cast_to_FirmWar();
- if(!warFactory)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("war factory %d skip weapon building\n", shortPtr[0]);
- #endif
- warFactory->cancel_build_unit();
- }
- }
- }
- // ------- End of function RemoteMsg::skip_build_weapon ---------//
- // ------- Begin of function RemoteMsg::build_ship ---------//
- void RemoteMsg::build_ship()
- {
- err_when( id != MSG_F_HARBOR_BUILD_SHIP );
- // packet structure : <firm recno> <unit Id>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmHarbor *harbor = firm_array[*shortPtr]->cast_to_FirmHarbor();
- if(!harbor)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("harbor %d start building unit id %d\n", shortPtr[0], shortPtr[1]);
- #endif
- // harbor->build_ship(shortPtr[1], COMMAND_REMOTE);
- if( shortPtr[1] > 0)
- harbor->add_queue(shortPtr[1]);
- else if( shortPtr[1] < 0)
- harbor->remove_queue(-shortPtr[1]);
- else
- {
- err_here();
- }
- }
- }
- }
- // ------- End of function RemoteMsg::build_ship ---------//
- // ------- Begin of function RemoteMsg::sail_ship ---------//
- void RemoteMsg::sail_ship()
- {
- err_when( id != MSG_F_HARBOR_SAIL_SHIP );
- // packet structure : <firm recno> <browse Recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmHarbor *harbor = firm_array[*shortPtr]->cast_to_FirmHarbor();
- if(!harbor)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("ship %d depart from harbor %d\n", shortPtr[1], shortPtr[0]);
- #endif
- harbor->sail_ship(shortPtr[1], COMMAND_REMOTE);
- }
- }
- }
- // ------- End of function RemoteMsg::sail_ship --------//
- // ------- Begin of function RemoteMsg::skip_build_ship ---------//
- void RemoteMsg::skip_build_ship()
- {
- err_when( id != MSG_F_HARBOR_SKIP_SHIP );
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmHarbor *harbor = firm_array[*shortPtr]->cast_to_FirmHarbor();
- if(!harbor)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("harbr %d skip ship building\n", shortPtr[0]);
- #endif
- harbor->cancel_build_unit();
- }
- }
- }
- // ------- End of function RemoteMsg::skip_build_ship ---------//
- // ------- Begin of function RemoteMsg::factory_change_product ---------//
- void RemoteMsg::factory_change_product()
- {
- #define DEFAULT_FACTORY_MAX_STOCK_QTY 500
- #define DEFAULT_FACTORY_MAX_RAW_STOCK_QTY 500
- err_when( id != MSG_F_FACTORY_CHG_PROD );
- // packet structure : <firm recno> <product id>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmFactory *factory = firm_array[*shortPtr]->cast_to_FirmFactory();
- if(!factory)
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("factory %d change product to %d\n", shortPtr[0], shortPtr[1]);
- #endif
- factory->product_raw_id = shortPtr[1];
- factory->stock_qty = (float) 0;
- factory->max_stock_qty = (float) DEFAULT_FACTORY_MAX_STOCK_QTY;
- factory->raw_stock_qty = (float) 0;
- factory->max_raw_stock_qty = (float) DEFAULT_FACTORY_MAX_RAW_STOCK_QTY;
- }
- }
- }
- // ------- End of function RemoteMsg::factory_change_product --------//
- void RemoteMsg::base_mobilize_prayer()
- {
- err_when( id != MSG_F_BASE_MOBL_PRAYER);
- err_here();
- /*
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmBase *base = firm_array[*shortPtr]->cast_to_FirmBase();
- if( !base )
- {
- err_here();
- }
- else
- {
- #ifdef DEBUG
- long_log->printf("seat of power %d mobilize prayer\n", shortPtr[0]);
- #endif
- base->resign_prayer();
- }
- }
- */
- }
- void RemoteMsg::invoke_god()
- {
- err_when( id != MSG_F_BASE_INVOKE_GOD);
- // packet structure : <firm recno>
- short *shortPtr = (short *)data_buf;
- if( validate_firm(*shortPtr) )
- {
- FirmBase *base = firm_array[*shortPtr]->cast_to_FirmBase();
- if( !base )
- {
- err_here();
- }
- else
- {
- // ##### begin Gilbert 10/11 ########//
- if( base->can_invoke() )
- {
- #ifdef DEBUG
- long_log->printf("seat of power %d invoke god\n", shortPtr[0]);
- #endif
- base->invoke_god();
- }
- // ##### end Gilbert 10/11 ########//
- }
- }
- }
- // ------- Begin of function RemoteMsg::town_recruit ---------//
- void RemoteMsg::town_recruit()
- {
- err_when( id != MSG_TOWN_RECRUIT);
- // packet structure : <town recno> <skill id> <race id>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d train skill %d of race %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- if( shortPtr[2] > 0 )
- {
- if( shortPtr[1] == -1 ) // recruit unskilled unit
- town_array[*shortPtr]->recruit(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- else // add train worker skill
- town_array[*shortPtr]->add_queue((char) shortPtr[1], (char) shortPtr[2]);
- }
- else if( shortPtr[2] == -1)
- {
- // remove train worker skill
- town_array[*shortPtr]->remove_queue((char) shortPtr[1]);
- }
- else
- {
- err_here();
- }
- if( town_array.selected_recno == *shortPtr )
- info.update();
- }
- }
- // ------- End of function RemoteMsg::town_recruit ---------//
- // ------- Begin of function RemoteMsg::town_skip_recruit ---------//
- void RemoteMsg::town_skip_recruit()
- {
- err_when( id != MSG_TOWN_SKIP_RECRUIT);
- // packet structure : <town recno>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d skip unit training\n", shortPtr[0]);
- #endif
- town_array[*shortPtr]->cancel_train_unit();
- if( town_array.selected_recno == *shortPtr )
- info.disp();
- }
- }
- // ------- End of function RemoteMsg::town_skip_recruit ---------//
- // ------- Begin of function RemoteMsg::town_migrate ---------//
- void RemoteMsg::town_migrate()
- {
- err_when( id != MSG_TOWN_MIGRATE);
- // packet structure : <town recno> <dest town recno> <race id>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) && validate_town(shortPtr[1]) )
- {
- #ifdef DEBUG
- long_log->printf("town %d race %d migrate to town %d\n", shortPtr[0], shortPtr[2], shortPtr[1]);
- #endif
- town_array[*shortPtr]->migrate_to(shortPtr[1], COMMAND_REMOTE, shortPtr[2]);
- }
- }
- // ------- End of function RemoteMsg::town_migrate ---------//
- // ------- Begin of function RemoteMsg::town_collect_tax ---------//
- void RemoteMsg::town_collect_tax()
- {
- //### begin trevor 6/8 ####//
- err_when( id != MSG_TOWN_COLLECT_TAX );
- // packet structure : <town recno>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d collect tax\n", shortPtr[0]);
- #endif
- town_array[*shortPtr]->collect_tax(COMMAND_REMOTE);
- }
- //### end trevor 6/8 ####//
- }
- // ------- End of function RemoteMsg::town_collect_tax ---------//
- // ------- Begin of function RemoteMsg::town_reward ---------//
- void RemoteMsg::town_reward()
- {
- //### begin trevor 6/8 ####//
- err_when( id != MSG_TOWN_REWARD );
- // packet structure : <town recno>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d reward\n", shortPtr[0]);
- #endif
- town_array[*shortPtr]->reward(COMMAND_REMOTE);
- }
- //### end trevor 6/8 ####//
- }
- // ------- End of function RemoteMsg::town_reward ---------//
- // ------ Begin of function RemoteMsg::town_toggle_link_firm ----//
- void RemoteMsg::town_toggle_link_firm()
- {
- err_when( id != MSG_TOWN_TOGGLE_LINK_FIRM);
- // packet structure : <town recno> <link Id> <toggle Flag>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d %s firm link %d\n", shortPtr[0],
- shortPtr[2] ? "set" : "clear", shortPtr[1]);
- #endif
- Town *townPtr = town_array[*shortPtr];
- // ####### begin Gilbert 10/11 #######//
- short linkedFirmRecno = 0;
- if( shortPtr[1] <= townPtr->linked_firm_count
- && (linkedFirmRecno = townPtr->linked_firm_array[shortPtr[1]-1])
- && validate_firm(linkedFirmRecno, 1) )
- {
- townPtr->toggle_firm_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- // update loyalty if the linked firm is FIRM_BASE
- if( firm_array[linkedFirmRecno]->firm_id == FIRM_CAMP )
- {
- if(townPtr->nation_recno)
- townPtr->update_target_loyalty();
- else
- townPtr->update_target_resistance();
- townPtr->update_camp_link();
- }
- }
- // ####### end Gilbert 10/11 #######//
- }
- }
- // ------ End of function RemoteMsg::town_toggle_link_firm ----//
- // ------ Begin of function RemoteMsg::town_toggle_link_town ----//
- void RemoteMsg::town_toggle_link_town()
- {
- err_when( id != MSG_TOWN_TOGGLE_LINK_TOWN);
- // packet structure : <town recno> <link Id> <toggle Flag>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr) )
- {
- // ###### begin Gilbert 10/11 #######//
- Town *townPtr = town_array[*shortPtr];
- short linkedTownRecno = 0;
- if( shortPtr[1] <= townPtr->linked_town_count
- && (linkedTownRecno = townPtr->linked_town_array[shortPtr[1]-1])
- && validate_town(linkedTownRecno, 1) )
- {
- #ifdef DEBUG
- long_log->printf("town %d %s town link %d\n", shortPtr[0],
- shortPtr[2] ? "set" : "clear", shortPtr[1]);
- #endif
- town_array[*shortPtr]->toggle_town_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
- }
- // ###### end Gilbert 10/11 #######//
- }
- }
- // ------ End of function RemoteMsg::town_toggle_link_town ----//
- // ------ Begin of function RemoteMsg::town_auto_tax -------//
- void RemoteMsg::town_auto_tax()
- {
- err_when( id != MSG_TOWN_AUTO_TAX );
- // packet structure : <town recno> <loyalty level>
- // or <-nation recno> <loyalty level>
- short *shortPtr = (short *)data_buf;
- if( *shortPtr > 0)
- {
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d auto collect tax at loyal %d\n", shortPtr[0], shortPtr[1]);
- #endif
- town_array[*shortPtr]->set_auto_collect_tax_loyalty(shortPtr[1]);
- if( town_array.selected_recno == *shortPtr )
- info.disp();
- }
- }
- else
- {
- short nationRecno = -*shortPtr;
- err_when( !nationRecno );
- #ifdef DEBUG
- long_log->printf("nation %d auto collect tax at loyal %d\n", nationRecno, shortPtr[1]);
- #endif
- if( !nation_array.is_deleted(nationRecno) )
- {
- nation_array[nationRecno]->set_auto_collect_tax_loyalty(shortPtr[1]);
- for( int townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
- {
- Town *townPtr;
- if( !town_array.is_deleted(townRecno) && (townPtr = town_array[townRecno]) &&
- townPtr->nation_recno == nationRecno )
- {
- townPtr->set_auto_collect_tax_loyalty(shortPtr[1]);
- if( town_array.selected_recno == townRecno )
- info.disp();
- }
- }
- }
- }
- }
- // ------ End of function RemoteMsg::town_auto_tax -------//
- // ------ Begin of function RemoteMsg::town_auto_grant -------//
- void RemoteMsg::town_auto_grant()
- {
- err_when( id != MSG_TOWN_AUTO_GRANT );
- // packet structure : <town recno> <loyalty level>
- // or <-nation recno> <loyalty level>
- short *shortPtr = (short *)data_buf;
- if( *shortPtr > 0 )
- {
- if( validate_town(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("town %d auto grant at loyal %d\n", shortPtr[0], shortPtr[1]);
- #endif
- town_array[*shortPtr]->set_auto_grant_loyalty(shortPtr[1]);
- if( town_array.selected_recno == *shortPtr )
- info.disp();
- }
- }
- else
- {
- short nationRecno = -*shortPtr;
- err_when( !nationRecno );
- #ifdef DEBUG
- long_log->printf("nation %d auto grant at loyal %d\n", nationRecno, shortPtr[1]);
- #endif
- if( !nation_array.is_deleted(nationRecno) )
- {
- nation_array[nationRecno]->set_auto_grant_loyalty(shortPtr[1]);
- for( int townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
- {
- Town *townPtr;
- if( !town_array.is_deleted(townRecno) && (townPtr = town_array[townRecno]) &&
- townPtr->nation_recno == nationRecno )
- {
- townPtr->set_auto_grant_loyalty(shortPtr[1]);
- if( town_array.selected_recno == townRecno )
- info.disp();
- }
- }
- }
- }
- }
- // ------ End of function RemoteMsg::town_auto_grant -------//
- // ------ Begin of function RemoteMsg::town_grant_independent -------//
- void RemoteMsg::town_grant_independent()
- {
- err_when( id != MSG_TOWN_GRANT_INDEPENDENT );
- // packet structure : <town recno> <nation recno>
- short *shortPtr = (short *)data_buf;
- if( validate_town(*shortPtr, 1) && !nation_array.is_deleted(shortPtr[1]) )
- {
- town_array[*shortPtr]->grant_to_non_own_town(shortPtr[1], COMMAND_REMOTE);
- }
- }
- // ------ Begin of function RemoteMsg::town_grant_independent -------//
- // ------- Begin of function RemoteMsg::wall_build---------//
- void RemoteMsg::wall_build()
- {
- err_when( id != MSG_WALL_BUILD);
- // packet structure : <nation recno> <xLoc> <yLoc>
- short *shortPtr = (short *)data_buf;
- if( !nation_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("nation %d build wall at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- world.build_wall_tile( shortPtr[1], shortPtr[2], shortPtr[0], COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::wall_build---------//
- // ------- Begin of function RemoteMsg::wall_destruct ---------//
- void RemoteMsg::wall_destruct()
- {
- err_when( id != MSG_WALL_DESTRUCT);
- // packet structure : <nation recno> <xLoc> <yLoc>
- short *shortPtr = (short *)data_buf;
- if( !nation_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("nation %d destruct wall at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2]);
- #endif
- world.destruct_wall_tile( shortPtr[1], shortPtr[2], shortPtr[0], COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::wall_build---------//
- // ------- Begin of function RemoteMsg::spy_cycle_action -------//
- void RemoteMsg::spy_cycle_action()
- {
- err_when( id != MSG_SPY_CYCLE_ACTION);
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d change action\n", shortPtr[0]);
- #endif
- spy_array[*shortPtr]->set_next_action_mode();
- }
- }
- // ------- End of function RemoteMsg::spy_cycle_action -------//
- // ------- Begin of function RemoteMsg::spy_leave_town -------//
- void RemoteMsg::spy_leave_town()
- {
- err_when( id != MSG_SPY_LEAVE_TOWN);
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d leave town\n", shortPtr[0]);
- #endif
- //##### trevor 10/10 #####//
- if( spy_array[*shortPtr]->spy_place == SPY_TOWN )
- {
- spy_array[*shortPtr]->mobilize_town_spy();
- spy_array[*shortPtr]->notify_cloaked_nation_flag = 0;
- }
- //##### trevor 10/10 #####//
- }
- }
- // ------- End of function RemoteMsg::spy_leave_town -------//
- // ------- Begin of function RemoteMsg::spy_leave_firm -------//
- void RemoteMsg::spy_leave_firm()
- {
- err_when( id != MSG_SPY_LEAVE_FIRM);
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d leave firm\n", shortPtr[0]);
- #endif
- //##### trevor 10/10 #####//
- if( spy_array[*shortPtr]->spy_place == SPY_FIRM )
- {
- spy_array[*shortPtr]->mobilize_firm_spy();
- spy_array[*shortPtr]->notify_cloaked_nation_flag = 0;
- }
- //##### trevor 10/10 #####//
- }
- }
- // ------- End of function RemoteMsg::spy_leave_firm -------//
- // ------- Begin of function RemoteMsg::spy_capture_firm -------//
- void RemoteMsg::spy_capture_firm()
- {
- err_when( id != MSG_SPY_CAPTURE_FIRM);
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d capture firm\n", shortPtr[0]);
- #endif
- spy_array[*shortPtr]->capture_firm();
- }
- }
- // ------- End of function RemoteMsg::capture_firm -------//
- // ------- Begin of function RemoteMsg::spy_drop_identity ------//
- void RemoteMsg::spy_drop_identity()
- {
- err_when( id != MSG_SPY_DROP_IDENTITY );
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d drop identity\n", shortPtr[0]);
- #endif
- spy_array[*shortPtr]->drop_spy_identity();
- }
- }
- // ------- End of function RemoteMsg::spy_drop_identity ------//
- // ------- Begin of function RemoteMsg::spy_reward ------//
- void RemoteMsg::spy_reward()
- {
- err_when( id != MSG_SPY_REWARD );
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d reward\n", shortPtr[0]);
- #endif
- spy_array[*shortPtr]->reward(COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::spy_reward ------//
- // ------- Begin of function RemoteMsg::spy_set_exposed ------//
- void RemoteMsg::spy_exposed()
- {
- err_when( id != MSG_SPY_EXPOSED );
- // packet structure : <spy recno>
- short *shortPtr = (short *)data_buf;
- if( !spy_array.is_deleted(*shortPtr) )
- {
- #ifdef DEBUG
- long_log->printf("spy %d set exposed\n", shortPtr[0]);
- #endif
- spy_array[*shortPtr]->set_exposed(COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::spy_set_exposed ------//
- // ------- Begin of function RemoteMsg::send_talk_msg -------//
- void RemoteMsg::send_talk_msg()
- {
- err_when( id != MSG_SEND_TALK_MSG);
- // packet structure : <talkMsg>
- #ifdef DEBUG
- TalkMsg *talkMsg = (TalkMsg *)data_buf;
- long_log->printf("talk message from %d to %d, id %d, para1=%d, para2=%d\n",
- talkMsg->from_nation_recno, talkMsg->to_nation_recno,
- talkMsg->talk_id, talkMsg->talk_para1, talkMsg->talk_para2);
- #endif
- talk_res.send_talk_msg( (TalkMsg *)data_buf, COMMAND_REMOTE);
- }
- // ------- End of function RemoteMsg::send_talk_msg -------//
- // ------- Begin of function RemoteMsg::reply_talk_msg -------//
- void RemoteMsg::reply_talk_msg()
- {
- err_when( id != MSG_REPLY_TALK_MSG);
- // packet structure : <talkRecno:int> <reply type:char> <padding:char>
- //####### begin trevor 28/8 ########//
-
- int talkMsgRecno = *(int*)data_buf;
- if( !talk_res.is_talk_msg_deleted(talkMsgRecno) )
- {
- #ifdef DEBUG
- long_log->printf("reply talk message %d, %d\n", talkMsgRecno, data_buf[sizeof(int)]);
- #endif
- talk_res.reply_talk_msg( talkMsgRecno, data_buf[sizeof(int)], COMMAND_REMOTE);
- }
- //####### end trevor 28/8 ########//
- }
- // ------- End of function RemoteMsg::reply_talk_msg -------//
- // ------- Begin of function RemoteMsg::nation_contact -------//
- void RemoteMsg::nation_contact()
- {
- err_when( id != MSG_NATION_CONTACT);
- // packet structure : <player nation> <explored nation>
- short *shortPtr = (short *)data_buf;
- err_when( *shortPtr != remote.nation_processing );
- if( !nation_array.is_deleted(*shortPtr) && !nation_array.is_deleted(shortPtr[1]) )
- {
- //####### begin trevor 30/8 #######//
- #ifdef DEBUG
- long_log->printf("nation %d discover nation %d\n", shortPtr[0], shortPtr[1]);
- #endif
- nation_array[shortPtr[0]]->establish_contact(shortPtr[1]);
- //####### end trevor 30/8 #######//
- }
- }
- // ------- End of function RemoteMsg::nation_contact -------//
- // ------- Begin of function RemoteMsg::nation_set_should_attack -------//
- void RemoteMsg::nation_set_should_attack()
- {
- err_when( id != MSG_NATION_SET_SHOULD_ATTACK );
- // packet structure : <player nation> <target nation> <new value>
- short *shortPtr = (short *)data_buf;
- err_when( *shortPtr != remote.nation_processing );
- if( !nation_array.is_deleted(*shortPtr) && !nation_array.is_deleted(shortPtr[1]) )
- {
- #ifdef DEBUG
- long_log->printf("nation %d %s instruct attack nation %d\n", shortPtr[0],
- shortPtr[2] ? "set":"clear", shortPtr[1]);
- #endif
- nation_array[shortPtr[0]]->set_relation_should_attack(shortPtr[1], (char)shortPtr[2], COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::nation_set_should_attack -------//
- // ------- Begin of function RemoteMsg::caravan_selected -------//
- void RemoteMsg::caravan_selected()
- {
- err_when( id != MSG_U_CARA_SELECTED );
- // packet structure : <sprite_recno>
- short *shortPtr = (short *)data_buf;
-
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if( unitCount <= 0)
- return;
-
- #ifdef DEBUG
- Unit *unitPtr = unit_array[*shortPtr];
- err_when( unitPtr->unit_id != UNIT_CARAVAN);
- #endif
- //------ help to check syn. for multiplayer ------//
- #ifdef DEBUG
- m.random(100);
- #endif
- unit_array.mp_add_selected_caravan(*shortPtr);
- }
- // ------- End of function RemoteMsg::caravan_selected -------//
- // ------- Begin of function RemoteMsg::ship_selected -------//
- void RemoteMsg::ship_selected()
- {
- err_when( id != MSG_U_SHIP_SELECTED );
- // packet structure : <sprite_recno>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if(unitCount <= 0)
- return;
- #ifdef DEBUG
- Unit *unitPtr = unit_array[*shortPtr];
- err_when(unit_res[unitPtr->unit_id]->unit_class != UNIT_CLASS_SHIP || unitPtr->unit_id==UNIT_TRANSPORT);
- #endif
- //------ help to check syn. for multiplayer ------//
- #ifdef DEBUG
- m.random(100);
- #endif
- unit_array.mp_add_selected_ship(*shortPtr);
- }
- // ------- End of function RemoteMsg::ship_selected -------//
- //##### begin trevor 30/9 #######//
- //------- Begin of function RemoteMsg::chat -------//
- //
- // Packet structure : <to nation recno> <from nation recno> <char[CHAT_STR_LEN+1]>
- //
- void RemoteMsg::chat()
- {
- short *shortPtr = (short *)data_buf;
- int toNationRecno = shortPtr[0];
- int fromNationRecno = shortPtr[1];
- #ifdef DEBUG
- long_log->printf("nation %d send chat message to %d\n",
- shortPtr[1], shortPtr[0]);
- #endif
- if( toNationRecno == nation_array.player_recno ||
- (toNationRecno == 0 && fromNationRecno != nation_array.player_recno) ||
- (toNationRecno == -1 && !nation_array.is_deleted(fromNationRecno) &&
- nation_array[fromNationRecno]->is_allied_with_player) )
- {
- news_array.chat_msg( fromNationRecno, (char*)(shortPtr+2) );
- }
- }
- //------- End of function RemoteMsg::chat -------//
- //##### end trevor 30/9 #######//
- //------- Begin of function RemoteMsg::compare_remote_object -------//
- void RemoteMsg::compare_remote_object()
- {
- err_when( id < MSG_COMPARE_NATION || id > MSG_COMPARE_TALK );
- // ###### patch begin Gilbert 20/1 #######//
- if( (remote.sync_test_level & 2) && (remote.sync_test_level >= 0)
- && crc_store.compare_remote(id, data_buf) )
- {
- remote.sync_test_level = ~remote.sync_test_level; // signal error encountered
- if( sys.debug_session )
- err.run( "Multiplayer Random Seed Sync Error." );
- else
- box.msg( "Multiplayer Random Seed Sync Error." );
- }
- // ###### patch end Gilbert 20/1 #######//
- }
- //------- End of function RemoteMsg::compare_remote_object -------//
- //------- Begin of function RemoteMsg::unit_add_way_point -------//
- void RemoteMsg::unit_add_way_point()
- {
- //### begin alex 16/10 ###//
- err_when( id != MSG_UNIT_ADD_WAY_POINT);
- short* shortPtr = (short*) data_buf;
- validate_selected_unit_array(shortPtr+3, shortPtr[2]);
- if( shortPtr[2] > 0)
- {
- #ifdef DEBUG
- long_log->printf("add way point at (%d,%d)\n", shortPtr[0], shortPtr[1]);
- for(int i = 0; i < shortPtr[2]; ++i)
- {
- long_log->printf("%d,", shortPtr[3+i]);
- if( i % 20 == 19)
- long_log->printf("\n");
- }
- long_log->printf("\n");
- #endif
- unit_array.add_way_point(shortPtr[0], shortPtr[1], shortPtr+3, shortPtr[2], COMMAND_REMOTE); // 1-remote action
- }
- //#### end alex 16/10 ####//
- }
- //------- End of function RemoteMsg::unit_add_way_point -------//
- // ------- Begin of function RemoteMsg::god_cast -------//
- void RemoteMsg::god_cast()
- {
- err_when( id != MSG_U_GOD_CAST );
- // packet structure : <unit recno> <loc x> <loc y> <power type>
- short *shortPtr = (short *)data_buf;
- short unitCount =1;
- validate_selected_unit_array(shortPtr, unitCount);
- if(unitCount > 0)
- {
- Unit *unitPtr = unit_array[*shortPtr];
- err_when(unit_res[unitPtr->unit_id]->unit_class != UNIT_CLASS_GOD);
- #ifdef DEBUG
- long_log->printf("god %d cast power %d at(%d,%d)\n", shortPtr[0], shortPtr[3],
- shortPtr[1], shortPtr[2]);
- #endif
- unitPtr->go_cast_power(shortPtr[1], shortPtr[2], (char) shortPtr[3], COMMAND_REMOTE);
- }
- }
- // ------- End of function RemoteMsg::god_cast -------//
- // ------- Begin of function RemoteMsg::player_quit ---------//
- void RemoteMsg::player_quit()
- {
- // to let other player know a player quit voluntarily, not by error condition
- err_when( id != MSG_PLAYER_QUIT );
- // packet structure : <nation recno> <retire flag>
- short *shortPtr = (short *)data_buf;
- if( shortPtr[1])
- news_array.multi_retire(*shortPtr);
- else
- news_array.multi_quit_game(*shortPtr);
- }
- // ------- End of function RemoteMsg::player_quit ---------//
|