OREMOTEM.cpp 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OREMOTEM.CPP
  21. //Description : Object RemoteMsg
  22. #include <ALL.h>
  23. #include <OFONT.h>
  24. #include <ONEWS.h>
  25. #include <OSYS.h>
  26. #include <ONATION.h>
  27. #include <OUNIT.h>
  28. #include <OGAME.h>
  29. #include <OREMOTE.h>
  30. #include <OFIRM.h>
  31. #include <OFIRMALL.h>
  32. #include <OTOWN.h>
  33. #include <OLOG.h>
  34. #include <OUNITALL.h>
  35. #include <OSPY.h>
  36. #include <OTALKRES.h>
  37. #include <OLONGLOG.h>
  38. #include <OCRC_STO.h>
  39. // ##### patch begin Gilbert 20/1 #######//
  40. #include <OBOX.h>
  41. // ##### patch end Gilbert 20/1 #######//
  42. //---------------- Define variable type ---------------//
  43. typedef void (RemoteMsg::*MsgProcessFP)();
  44. //----------- Define function pointers array -----------//
  45. static MsgProcessFP msg_process_function_array[] =
  46. {
  47. &RemoteMsg::queue_header,
  48. &RemoteMsg::queue_trailer,
  49. &RemoteMsg::new_nation,
  50. &RemoteMsg::update_game_setting,
  51. &RemoteMsg::start_game,
  52. &RemoteMsg::next_frame,
  53. &RemoteMsg::request_resend,
  54. &RemoteMsg::tell_send_time,
  55. &RemoteMsg::set_speed,
  56. &RemoteMsg::tell_random_seed,
  57. &RemoteMsg::request_save_game,
  58. &RemoteMsg::player_quit,
  59. &RemoteMsg::unit_stop,
  60. &RemoteMsg::unit_move,
  61. &RemoteMsg::unit_set_force_move,
  62. &RemoteMsg::unit_attack,
  63. &RemoteMsg::unit_assign,
  64. &RemoteMsg::unit_change_nation,
  65. &RemoteMsg::unit_build_firm,
  66. &RemoteMsg::unit_burn,
  67. &RemoteMsg::units_settle,
  68. &RemoteMsg::unit_set_guard,
  69. &RemoteMsg::unit_set_rank,
  70. &RemoteMsg::unit_dismount,
  71. &RemoteMsg::unit_reward,
  72. &RemoteMsg::units_transform,
  73. &RemoteMsg::unit_resign,
  74. &RemoteMsg::units_assign_to_ship,
  75. &RemoteMsg::units_ship_to_beach,
  76. &RemoteMsg::unit_succeed_king,
  77. &RemoteMsg::units_return_camp,
  78. &RemoteMsg::caravan_change_goods,
  79. &RemoteMsg::caravan_set_stop,
  80. &RemoteMsg::caravan_del_stop,
  81. &RemoteMsg::caravan_selected,
  82. &RemoteMsg::ship_unload_unit,
  83. &RemoteMsg::ship_unload_all_units,
  84. &RemoteMsg::ship_change_goods,
  85. &RemoteMsg::ship_set_stop,
  86. &RemoteMsg::ship_del_stop,
  87. &RemoteMsg::ship_change_mode,
  88. &RemoteMsg::ship_selected,
  89. &RemoteMsg::god_cast,
  90. &RemoteMsg::change_spy_nation,
  91. &RemoteMsg::notify_cloaked_nation,
  92. &RemoteMsg::unit_change_aggressive_mode,
  93. &RemoteMsg::spy_change_notify_flag,
  94. //#### trevor 15/10 ######//
  95. &RemoteMsg::spy_assassinate,
  96. //#### trevor 15/10 ######//
  97. &RemoteMsg::unit_add_way_point,
  98. &RemoteMsg::firm_sell,
  99. &RemoteMsg::firm_cancel,
  100. &RemoteMsg::firm_destruct,
  101. &RemoteMsg::firm_set_repair,
  102. &RemoteMsg::firm_train_level,
  103. &RemoteMsg::mobilize_worker,
  104. &RemoteMsg::mobilize_overseer,
  105. &RemoteMsg::mobilize_builder,
  106. &RemoteMsg::firm_toggle_link_firm,
  107. &RemoteMsg::firm_toggle_link_town,
  108. &RemoteMsg::firm_pull_town_people,
  109. &RemoteMsg::firm_set_worker_home,
  110. &RemoteMsg::firm_bribe,
  111. &RemoteMsg::firm_capture,
  112. &RemoteMsg::firm_reward,
  113. &RemoteMsg::camp_patrol,
  114. &RemoteMsg::toggle_camp_patrol,
  115. &RemoteMsg::inn_hire,
  116. &RemoteMsg::market_scrap,
  117. &RemoteMsg::market_hire_caravan,
  118. &RemoteMsg::research_start,
  119. &RemoteMsg::build_weapon,
  120. &RemoteMsg::cancel_weapon,
  121. &RemoteMsg::skip_build_weapon,
  122. &RemoteMsg::build_ship,
  123. &RemoteMsg::sail_ship,
  124. &RemoteMsg::skip_build_ship,
  125. &RemoteMsg::factory_change_product,
  126. &RemoteMsg::base_mobilize_prayer,
  127. &RemoteMsg::invoke_god,
  128. &RemoteMsg::town_recruit,
  129. &RemoteMsg::town_skip_recruit,
  130. &RemoteMsg::town_migrate,
  131. &RemoteMsg::town_collect_tax,
  132. &RemoteMsg::town_reward,
  133. &RemoteMsg::town_toggle_link_firm,
  134. &RemoteMsg::town_toggle_link_town,
  135. &RemoteMsg::town_auto_tax,
  136. &RemoteMsg::town_auto_grant,
  137. &RemoteMsg::town_grant_independent,
  138. &RemoteMsg::wall_build,
  139. &RemoteMsg::wall_destruct,
  140. &RemoteMsg::spy_cycle_action,
  141. &RemoteMsg::spy_leave_town,
  142. &RemoteMsg::spy_leave_firm,
  143. &RemoteMsg::spy_capture_firm,
  144. &RemoteMsg::spy_drop_identity,
  145. &RemoteMsg::spy_reward,
  146. &RemoteMsg::spy_exposed,
  147. &RemoteMsg::send_talk_msg,
  148. &RemoteMsg::reply_talk_msg,
  149. &RemoteMsg::nation_contact,
  150. &RemoteMsg::nation_set_should_attack,
  151. &RemoteMsg::chat,
  152. &RemoteMsg::compare_remote_object,
  153. &RemoteMsg::compare_remote_object,
  154. &RemoteMsg::compare_remote_object,
  155. &RemoteMsg::compare_remote_object,
  156. &RemoteMsg::compare_remote_object,
  157. &RemoteMsg::compare_remote_object,
  158. &RemoteMsg::compare_remote_object,
  159. &RemoteMsg::compare_remote_object,
  160. };
  161. //---------- Declare static functions ----------//
  162. static void validate_selected_unit_array(short* selectedUnitArray, short& selectedCount);
  163. static short validate_firm(short firmRecno, unsigned flags = 0);
  164. static short validate_town(short townRecno, unsigned flags = 0);
  165. //------ Begin of function RemoteMsg::process_msg -----//
  166. //
  167. void RemoteMsg::process_msg()
  168. {
  169. if( id==0 )
  170. return;
  171. err_when( id<FIRST_REMOTE_MSG_ID || id>LAST_REMOTE_MSG_ID );
  172. MsgProcessFP msgProcessFP = msg_process_function_array[id-FIRST_REMOTE_MSG_ID];
  173. (this->*msgProcessFP)(); // call the corrsponding function to return the news process_msg
  174. }
  175. //------- End of function RemoteMsg::process_msg -----//
  176. //-------- Begin of function RemoteMsg::queue_header ---------//
  177. //
  178. // Nothing here, it shouldn't be called at all.
  179. //
  180. void RemoteMsg::queue_header()
  181. {
  182. }
  183. //--------- End of function RemoteMsg::queue_header ---------//
  184. //-------- Begin of function RemoteMsg::queue_trailer ---------//
  185. //
  186. // Nothing here
  187. //
  188. void RemoteMsg::queue_trailer()
  189. {
  190. #ifdef DEBUG
  191. long_log->printf("Queue trailer of nation %d\n", *(short *)data_buf);
  192. #endif
  193. }
  194. //--------- End of function RemoteMsg::queue_trailer ---------//
  195. //-------- Begin of function RemoteMsg::new_nation ---------//
  196. //
  197. // Create a remote player.
  198. //
  199. // Sent from a client to the host when the client start a new nation.
  200. //
  201. // Client --> MSG_NEW_NATION --> Host
  202. //
  203. // Sent from the host to a newly joined client to update it with all
  204. // existing nations.
  205. //
  206. // Host --> UPDATE_GAME_SETTING --> Client
  207. //
  208. // structure of data_buf:
  209. //
  210. // <Nation> - Nation object of the newly joined nation
  211. //
  212. void RemoteMsg::new_nation()
  213. {
  214. //-------- create a new nation now --------//
  215. if( !remote.is_host ) // ignore this message if this is not the host
  216. return;
  217. Nation* nationPtr = (Nation*)(this->data_buf);
  218. int nationRecno = nation_array.new_nation( NATION_REMOTE, nationPtr->race_id, nationPtr->color_scheme_id, nationPtr->player_id );
  219. game.mp_broadcast_setting();
  220. }
  221. //--------- End of function RemoteMsg::new_nation ---------//
  222. //-------- Begin of function RemoteMsg::update_game_setting ---------//
  223. //
  224. // Sent from the host to clients, update the client with the latest
  225. // game settings.
  226. //
  227. // Host --> UPDATE_GAME_SETTING --> Client
  228. //
  229. // structure of data_buf:
  230. //
  231. // <long> - random seed
  232. // <short> - The number of nations joined
  233. // <Nation..> - An array of nation objects
  234. //
  235. void RemoteMsg::update_game_setting()
  236. {
  237. //------- get parameters -----------//
  238. char* dataPtr = data_buf;
  239. //------- set random seed -----------//
  240. m.set_random_seed(*(long*)dataPtr);
  241. dataPtr += sizeof(long);
  242. //------- update nation_array -----------//
  243. int nationCount = *(short*)dataPtr;
  244. dataPtr += sizeof(short);
  245. char nationType;
  246. int i, ownCount=0;
  247. nation_array.deinit(); // deinit() first and then recreate it as follows
  248. for( i=0 ; i<nationCount ; i++ )
  249. {
  250. short nationRecno = *(short *)dataPtr;
  251. dataPtr += sizeof(short);
  252. DWORD dpPlayerId = *(DWORD *)dataPtr;
  253. dataPtr += sizeof(DWORD);
  254. short colorSchemeId = *(short *)dataPtr;
  255. dataPtr += sizeof(short);
  256. short raceId = *(short *)dataPtr;
  257. dataPtr += sizeof(short);
  258. // int NationType;
  259. if( dpPlayerId == remote.self_player_id() ) // if this nation is the player's nation
  260. {
  261. nationType = NATION_OWN;
  262. ownCount++;
  263. }
  264. else
  265. nationType = NATION_REMOTE;
  266. if(nationRecno != nation_array.new_nation( nationType, raceId, colorSchemeId, dpPlayerId ))
  267. {
  268. // nation recno should match across all players
  269. err.run("Error in transmitting nation data");
  270. }
  271. }
  272. err_when( ownCount>1 );
  273. }
  274. //--------- End of function RemoteMsg::update_game_setting ---------//
  275. //-------- Begin of function RemoteMsg::start_game ---------//
  276. //
  277. // The host sends MSG_START_GAME to the clients to notify them
  278. // to start the game.
  279. //
  280. void RemoteMsg::start_game()
  281. {
  282. game.started_flag = 1;
  283. }
  284. //--------- End of function RemoteMsg::start_game ---------//
  285. //-------- Begin of function RemoteMsg::next_frame ---------//
  286. //
  287. // Notify the others that we are ready to proceed to the next
  288. // frame.
  289. //
  290. // structure of data_buf:
  291. //
  292. // <short> - nation recno of the message queue
  293. //
  294. void RemoteMsg::next_frame()
  295. {
  296. short nationRecno = *((short*)data_buf);
  297. if( !nation_array.is_deleted(nationRecno) )
  298. {
  299. nation_array[nationRecno]->next_frame_ready=1;
  300. }
  301. }
  302. //--------- End of function RemoteMsg::next_frame ---------//
  303. //-------- Begin of function RemoteMsg::request_resend ---------//
  304. //
  305. // Request a specific player to resend its packets.
  306. //
  307. // structure of data_buf:
  308. //
  309. // <DWORD> - player id.
  310. // <DWORD> - frame count of the message queue
  311. //
  312. void RemoteMsg::request_resend()
  313. {
  314. DWORD *dwordPtr = (DWORD*) data_buf;
  315. err_when( dwordPtr[0] == (~nation_array)->player_id ); // sent to itself
  316. remote.send_backup_now(dwordPtr[0], dwordPtr[1]);
  317. }
  318. //--------- End of function RemoteMsg::request_resend ---------//
  319. //-------- Begin of function RemoteMsg::tell_send_time ---------//
  320. //
  321. // Display the delivery time of the packet
  322. //
  323. void RemoteMsg::tell_send_time()
  324. {
  325. String str;
  326. unsigned long sendTime = *((unsigned long*)data_buf);
  327. str = "Packet Delivery Time: ";
  328. str += m.get_time() - sendTime;
  329. str += " ms ";
  330. str += m.get_time();
  331. font_san.disp( ZOOM_X1, 4, str, ZOOM_X1+249);
  332. }
  333. //--------- End of function RemoteMsg::tell_send_time ---------//
  334. //-------- Begin of function RemoteMsg::set_speed ---------//
  335. //
  336. // Order the selected units to stop.
  337. //
  338. // structure of data_buf:
  339. //
  340. // <short> - the game speed setting.
  341. //
  342. void RemoteMsg::set_speed()
  343. {
  344. err_when( id != MSG_SET_SPEED);
  345. short* shortPtr = (short*) data_buf;
  346. sys.set_speed(shortPtr[0], COMMAND_REMOTE); // 1-remote call
  347. }
  348. //--------- End of function RemoteMsg::set_speed ---------//
  349. //-------- Begin of function RemoteMsg::tell_random_seed ---------//
  350. //
  351. // structure of data_buf:
  352. //
  353. // <short> - nation recno
  354. // <long> - random seed
  355. //
  356. void RemoteMsg::tell_random_seed()
  357. {
  358. // ######## patch begin Gilbert 20/1 #########//
  359. char *p = data_buf;
  360. short nationRecno = *(short *)p;
  361. p += sizeof(short);
  362. long remoteSeed = *(long *)p;
  363. #if defined(DEBUG) && defined(ENABLE_LOG)
  364. String logLine("remote random seed ");
  365. logLine += nationRecno;
  366. logLine += ",";
  367. logLine += remoteSeed;
  368. LOG_MSG(logLine);
  369. #endif
  370. // it assume random seed of each nation come in sequence
  371. // if may fails when connection lost
  372. static long lastRemoteSeed = -1;
  373. static short lastNation = 0x7fff;
  374. if( nationRecno <= lastNation)
  375. {
  376. // assume the smallest human nation
  377. lastRemoteSeed = remoteSeed;
  378. }
  379. else
  380. {
  381. if( lastRemoteSeed != remoteSeed )
  382. {
  383. #ifdef DEBUG
  384. // delete long_log;
  385. // long_log = NULL;
  386. #endif
  387. LOG_DUMP;
  388. if( (remote.sync_test_level & 1) && (remote.sync_test_level >= 0) )
  389. {
  390. remote.sync_test_level = ~remote.sync_test_level; // signal error encountered
  391. if( sys.debug_session )
  392. err.run( "Multiplayer Random Seed Sync Error." );
  393. else
  394. box.msg( "Multiplayer Random Seed Sync Error." );
  395. }
  396. }
  397. }
  398. lastNation = nationRecno;
  399. // ######## patch end Gilbert 20/1 #########//
  400. }
  401. //-------- End of function RemoteMsg::tell_random_seed ---------//
  402. //-------- Begin of function RemoteMsg::request_save_game ---------//
  403. void RemoteMsg::request_save_game()
  404. {
  405. err_when( id != MSG_REQUEST_SAVE );
  406. // message struct : <DWORD> frame when the game should save
  407. #ifdef DEBUG
  408. long_log->printf("Request save on %d\n", *(DWORD*)data_buf);
  409. #endif
  410. sys.mp_request_save( *(DWORD*)data_buf);
  411. }
  412. //-------- End of function RemoteMsg::request_save_game ---------//
  413. //-------- Begin of function RemoteMsg::unit_stop ---------//
  414. //
  415. // Order the selected units to stop.
  416. //
  417. // structure of data_buf:
  418. //
  419. // <short> - no. of selected unit.
  420. // <char..> - selected unit recno array
  421. //
  422. void RemoteMsg::unit_stop()
  423. {
  424. err_when( id != MSG_UNIT_STOP);
  425. short* shortPtr = (short*) data_buf;
  426. validate_selected_unit_array(shortPtr+1, shortPtr[0]);
  427. if(shortPtr[0] > 0)
  428. {
  429. #ifdef DEBUG
  430. long_log->printf("stop units : ");
  431. for(int i = 0; i < shortPtr[0]; ++i)
  432. {
  433. long_log->printf("%d,", shortPtr[1+i]);
  434. if( i % 20 == 19)
  435. long_log->printf("\n");
  436. }
  437. #endif
  438. unit_array.stop( shortPtr+1, shortPtr[0], COMMAND_REMOTE ); // 1-remote action
  439. }
  440. }
  441. //--------- End of function RemoteMsg::unit_stop ---------//
  442. //-------- Begin of function RemoteMsg::unit_move ---------//
  443. //
  444. // Order the selected units to move to the specified location.
  445. //
  446. // structure of data_buf:
  447. //
  448. // <short> - destXLoc
  449. // <short> - destYLoc
  450. // <short> - no. of selected unit.
  451. // <char..> - selected unit recno array
  452. //
  453. void RemoteMsg::unit_move()
  454. {
  455. err_when( id != MSG_UNIT_MOVE);
  456. short* shortPtr = (short*) data_buf;
  457. validate_selected_unit_array(shortPtr+4, shortPtr[2]);
  458. if( shortPtr[2] > 0)
  459. {
  460. #ifdef DEBUG
  461. long_log->printf("move to (%d,%d), units : ", shortPtr[0], shortPtr[1]);
  462. for(int i = 0; i < shortPtr[2]; ++i)
  463. {
  464. long_log->printf("%d,", shortPtr[4+i]);
  465. if( i % 20 == 19)
  466. long_log->printf("\n");
  467. }
  468. long_log->printf("\n");
  469. #endif
  470. unit_array.move_to( shortPtr[0], shortPtr[1], shortPtr[3], shortPtr+4, shortPtr[2], COMMAND_REMOTE ); // 1-remote action
  471. }
  472. }
  473. //--------- End of function RemoteMsg::unit_move ---------//
  474. //--------- Begin of function RemoteMsg::unit_set_force_move ---------//
  475. void RemoteMsg::unit_set_force_move()
  476. {
  477. err_when(id != MSG_UNIT_SET_FORCE_MOVE);
  478. // packet structure : <unit count> <unit recno>...
  479. short* shortPtr = (short*) data_buf;
  480. validate_selected_unit_array(shortPtr+1, shortPtr[0]);
  481. if( shortPtr[0] > 0)
  482. {
  483. int i;
  484. #ifdef DEBUG
  485. long_log->printf("set force move to , units : ");
  486. for(i = 0; i < shortPtr[0]; ++i)
  487. {
  488. long_log->printf("%d,", shortPtr[1+i]);
  489. if( i % 20 == 19)
  490. long_log->printf("\n");
  491. }
  492. long_log->printf("\n");
  493. #endif
  494. for( i = 0; i < shortPtr[0]; ++i )
  495. {
  496. unit_array[shortPtr[1+i]]->force_move_flag = 1;
  497. }
  498. }
  499. }
  500. //--------- End of function RemoteMsg::unit_set_force_move ---------//
  501. //-------- Begin of function RemoteMsg::unit_attack ---------//
  502. //
  503. // Order the selected units to attack at the specified location.
  504. //
  505. // structure of data_buf:
  506. //
  507. // <short> - targetXLoc
  508. // <short> - targetYLoc
  509. // <short> - unitRecno
  510. // <short> - no. of selected unit.
  511. // <short> - divided;
  512. // <short..> - selected unit recno array
  513. //
  514. void RemoteMsg::unit_attack()
  515. {
  516. err_when( id != MSG_UNIT_ATTACK);
  517. short* shortPtr = (short*) data_buf;
  518. // ###### patch begin Gilbert 5/8 ###########//
  519. validate_selected_unit_array(shortPtr+5, shortPtr[3]);
  520. if( shortPtr[3] > 0)
  521. {
  522. #ifdef DEBUG
  523. long_log->printf("attack (%d,%d), units : ", shortPtr[0], shortPtr[1]);
  524. for(int i = 0; i < shortPtr[3]; ++i)
  525. {
  526. long_log->printf("%d,", shortPtr[5+i]);
  527. if( i % 20 == 19)
  528. long_log->printf("\n");
  529. }
  530. long_log->printf("\n");
  531. #endif
  532. int passCount = unit_array.divide_attack_by_nation(remote.nation_processing, shortPtr+5, shortPtr[3]);
  533. if( passCount > 0 )
  534. unit_array.attack( shortPtr[0], shortPtr[1], shortPtr[4], shortPtr+5, passCount, COMMAND_REMOTE, shortPtr[2] ); // 1-remote action
  535. }
  536. // ###### patch end Gilbert 5/8 ###########//
  537. }
  538. //--------- End of function RemoteMsg::unit_attack ---------//
  539. //-------- Begin of function RemoteMsg::unit_assign ---------//
  540. //
  541. // Order the selected units to move to the specified location.
  542. //
  543. // structure of data_buf:
  544. //
  545. // <short> - destXLoc
  546. // <short> - destYLoc
  547. // <short> - no. of selected unit.
  548. // <char..> - selected unit recno array
  549. //
  550. void RemoteMsg::unit_assign()
  551. {
  552. err_when( id != MSG_UNIT_ASSIGN);
  553. short* shortPtr = (short*) data_buf;
  554. validate_selected_unit_array(shortPtr+4, shortPtr[2]);
  555. if( shortPtr[2] > 0)
  556. {
  557. #ifdef DEBUG
  558. long_log->printf("assign to (%d,%d), units : ", shortPtr[0], shortPtr[1]);
  559. for(int i = 0; i < shortPtr[2]; ++i)
  560. {
  561. long_log->printf("%d,", shortPtr[4+i]);
  562. if( i % 20 == 19)
  563. long_log->printf("\n");
  564. }
  565. long_log->printf("\n");
  566. #endif
  567. unit_array.assign( shortPtr[0], shortPtr[1], shortPtr[3], COMMAND_REMOTE, shortPtr+4, shortPtr[2]);
  568. }
  569. }
  570. //--------- End of function RemoteMsg::unit_assign ---------//
  571. //-------- Begin of function RemoteMsg::unit_change_nation ---------//
  572. //
  573. // Order the selected units to move to the specified location.
  574. //
  575. // structure of data_buf:
  576. //
  577. // <short> - newNationRecno
  578. // <short> - no. of selected unit.
  579. // <char..> - selected unit recno array
  580. //
  581. void RemoteMsg::unit_change_nation()
  582. {
  583. /*
  584. short* shortPtr = (short*) data_buf;
  585. short* selectedUnitArray = shortPtr+2;
  586. int selectedCount = shortPtr[1];
  587. validate_selected_unit_array(selectedUnitArray, selectedCount);
  588. unit_array.change_nation( shortPtr[0], selectedUnitArray, selectedCount, COMMAND_REMOTE ); // 1-remote action
  589. */
  590. }
  591. //--------- End of function RemoteMsg::unit_change_nation ---------//
  592. //------ Begin of static function validate_selected_unit_array ------//
  593. //
  594. // Validate all units in selectedUnitArray, remove deleted units from
  595. // selectedUnitArray.
  596. //
  597. static void validate_selected_unit_array(short* selectedUnitArray, short& selectedUnitCount)
  598. {
  599. for( int i=0 ; i<selectedUnitCount ; i++ )
  600. {
  601. Unit* unitPtr;
  602. if( unit_array.is_deleted(selectedUnitArray[i]) ||
  603. !(unitPtr = unit_array[selectedUnitArray[i]]) ||
  604. !unitPtr->is_visible() || !unitPtr->is_nation(remote.nation_processing) )
  605. {
  606. memmove( selectedUnitArray+i, selectedUnitArray+i+1, sizeof(short) * (selectedUnitCount-i-1) );
  607. selectedUnitCount--;
  608. i--; // stay with the current recno as the records have been moved. The recno in the current position is actually the next record.
  609. }
  610. }
  611. }
  612. //------- End of static function validate_selected_unit_array -------//
  613. //------ Begin of static function validate_firm ------//
  614. //
  615. // return the firmRecno if the firm is controllable by the remote player
  616. //
  617. // bit 0 - skip firm's nation checking
  618. //
  619. static short validate_firm(short firmRecno, unsigned flags)
  620. {
  621. err_when( !(flags & 1) && remote.nation_processing == 0);
  622. Firm* firmPtr;
  623. if( firmRecno && !firm_array.is_deleted(firmRecno)
  624. && (firmPtr = firm_array[firmRecno])
  625. && ((flags & 1) || firmPtr->nation_recno == remote.nation_processing) )
  626. return firmRecno;
  627. else
  628. return 0;
  629. }
  630. //------ End of static function validate_firm ------//
  631. //------ Begin of static function validate_town ------//
  632. //
  633. // return the townRecno if the town is controllable by the remote player
  634. //
  635. // bit 0 - skip town's nation checking
  636. //
  637. static short validate_town(short townRecno, unsigned flags)
  638. {
  639. Town* townPtr;
  640. err_when( !(flags & 1) && remote.nation_processing == 0);
  641. if( townRecno && !town_array.is_deleted(townRecno)
  642. && (townPtr = town_array[townRecno])
  643. && ((flags & 1) || townPtr->nation_recno == remote.nation_processing) )
  644. return townRecno;
  645. else
  646. return 0;
  647. }
  648. //------ End of static function validate_firm ------//
  649. // ------- Begin of function RemoteMsg::unit_build ---------//
  650. void RemoteMsg::unit_build_firm()
  651. {
  652. err_when( id != MSG_UNIT_BUILD_FIRM);
  653. // packet structure : <unit recno> <xLoc> <yLoc> <firmId>
  654. short *shortPtr = (short *)data_buf;
  655. short unitCount =1;
  656. validate_selected_unit_array(shortPtr, unitCount);
  657. if( unitCount > 0 )
  658. {
  659. #ifdef DEBUG
  660. long_log->printf("unit %d build firm %d at (%d,%d)\n", shortPtr[0], shortPtr[3], shortPtr[1], shortPtr[2]);
  661. #endif
  662. unit_array[*shortPtr]->build_firm( shortPtr[1], shortPtr[2],
  663. shortPtr[3], COMMAND_REMOTE );
  664. }
  665. }
  666. // ------- End of function RemoteMsg::unit_build_firm ---------//
  667. // ------- Begin of function RemoteMsg::unit_burn ---------//
  668. void RemoteMsg::unit_burn()
  669. {
  670. err_when( id != MSG_UNIT_BURN);
  671. // packet structure : <unit recno> <xLoc> <yLoc>
  672. short *shortPtr = (short *)data_buf;
  673. short unitCount =1;
  674. validate_selected_unit_array(shortPtr, unitCount);
  675. if( unitCount > 0 )
  676. {
  677. #ifdef DEBUG
  678. long_log->printf("unit %d burn at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  679. #endif
  680. unit_array[*shortPtr]->burn(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  681. }
  682. }
  683. // ------- End of function RemoteMsg::unit_burn ---------//
  684. // ------- Begin of function RemoteMsg::units_settle ---------//
  685. void RemoteMsg::units_settle()
  686. {
  687. err_when( id != MSG_UNITS_SETTLE);
  688. // packet structure : <xLoc> <yLoc> <no. of units> <divided> <unit recno ...>
  689. short *shortPtr = (short *)data_buf;
  690. validate_selected_unit_array(shortPtr+4, shortPtr[2]);
  691. if( shortPtr[2] > 0)
  692. {
  693. #ifdef DEBUG
  694. long_log->printf("settle at (%d,%d), units : ", shortPtr[0], shortPtr[1]);
  695. for(int i = 0; i < shortPtr[2]; ++i)
  696. {
  697. long_log->printf("%d,", shortPtr[4+i]);
  698. if( i % 20 == 19)
  699. long_log->printf("\n");
  700. }
  701. long_log->printf("\n");
  702. #endif
  703. unit_array.settle(shortPtr[0], shortPtr[1], shortPtr[3], COMMAND_REMOTE, shortPtr+4, shortPtr[2]);
  704. }
  705. }
  706. // ------- End of function RemoteMsg::units_settle ---------//
  707. // ------- Begin of function RemoteMsg::unit_set_guard ---------//
  708. //
  709. // **BUGHERE, this function is no longer needed.
  710. //
  711. void RemoteMsg::unit_set_guard()
  712. {
  713. /*
  714. err_when( id != MSG_UNIT_SET_GUARD);
  715. // packet structure : <unit recno> <new guard mode 0/1>
  716. short *shortPtr = (short *)data_buf;
  717. unit_array[*shortPtr]->guard_mode = (char) shortPtr[1];
  718. */
  719. }
  720. // ------- End of function RemoteMsg::unit_set_guard ---------//
  721. // ------- Begin of function RemoteMsg::unit_set_rank ---------//
  722. void RemoteMsg::unit_set_rank()
  723. {
  724. err_when( id != MSG_UNIT_SET_RANK);
  725. // packet structure : <unit recno> <new rank>
  726. short *shortPtr = (short *)data_buf;
  727. short unitCount =1;
  728. validate_selected_unit_array(shortPtr, unitCount);
  729. // ignore <new rank> parameter
  730. // unit_array[*shortPtr]->set_rank(shortPtr[1]);
  731. if( unitCount > 0)
  732. {
  733. #ifdef DEBUG
  734. long_log->printf("unit %d promote/demote to %d\n", shortPtr[0], shortPtr[1]);
  735. #endif
  736. switch(unit_array[*shortPtr]->rank_id)
  737. {
  738. case RANK_SOLDIER:
  739. unit_array[*shortPtr]->set_rank(RANK_GENERAL);
  740. break;
  741. case RANK_GENERAL:
  742. unit_array[*shortPtr]->set_rank(RANK_SOLDIER);
  743. break;
  744. }
  745. }
  746. }
  747. // ------- End of function RemoteMsg::unit_set_rank ---------//
  748. // ------- Begin of function RemoteMsg::unit_dismount ---------//
  749. void RemoteMsg::unit_dismount()
  750. {
  751. err_when( id != MSG_UNIT_DISMOUNT);
  752. // packet structure : <unit recno>
  753. short *shortPtr = (short *)data_buf;
  754. short unitCount =1;
  755. validate_selected_unit_array(shortPtr, unitCount);
  756. if( unitCount > 0 )
  757. {
  758. #ifdef DEBUG
  759. long_log->printf("unit %d dismount\n", shortPtr[0]);
  760. #endif
  761. UnitVehicle *uv = (UnitVehicle *) unit_array[*shortPtr];
  762. uv->dismount();
  763. }
  764. }
  765. // ------- End of function RemoteMsg::unit_dismount ---------//
  766. // ------- Begin of function RemoteMsg::unit_reward ---------//
  767. void RemoteMsg::unit_reward()
  768. {
  769. //###### begin trevor 9/6 #######//
  770. err_when( id != MSG_UNIT_REWARD);
  771. // packet structure : <unit recno> <rewarding nation recno>
  772. short *shortPtr = (short *)data_buf;
  773. short unitCount =1;
  774. validate_selected_unit_array(shortPtr, unitCount);
  775. if( unitCount > 0 )
  776. {
  777. #ifdef DEBUG
  778. long_log->printf("nation %d rewards unit %d\n", shortPtr[1], shortPtr[0]);
  779. #endif
  780. unit_array[*shortPtr]->reward(shortPtr[1]);
  781. }
  782. //###### end trevor 9/6 #######//
  783. }
  784. // ------- End of function RemoteMsg::unit_reward ---------//
  785. // ------- Begin of function RemoteMsg::units_transform ------//
  786. void RemoteMsg::units_transform()
  787. {
  788. err_when( id != MSG_UNITS_TRANSFORM );
  789. // packet structure <this recno> <no. of units> <unit recno> ...
  790. short *shortPtr = (short *)data_buf;
  791. validate_selected_unit_array(shortPtr+2, shortPtr[1]);
  792. if( unit_array.is_deleted(*shortPtr) )
  793. {
  794. // if <this recno> is dead, use the first unit in
  795. // the unit group
  796. if( shortPtr[1] >= 1)
  797. {
  798. *shortPtr = shortPtr[2];
  799. unit_array[*shortPtr]->group_transform(COMMAND_REMOTE,
  800. shortPtr +2, shortPtr[1]);
  801. }
  802. }
  803. else
  804. {
  805. unit_array[*shortPtr]->group_transform(COMMAND_REMOTE,
  806. shortPtr +2, shortPtr[1]);
  807. }
  808. }
  809. // ------- End of function RemoteMsg::units_transform ------//
  810. // ------- Begin of function RemoteMsg::unit_resign ---------//
  811. void RemoteMsg::unit_resign()
  812. {
  813. err_when( id != MSG_UNIT_RESIGN);
  814. // packet structure : <unit recno> <nation recno>
  815. short *shortPtr = (short *)data_buf;
  816. short unitCount =1;
  817. validate_selected_unit_array(shortPtr, unitCount);
  818. if( unitCount > 0 && unit_array[*shortPtr]->is_nation(shortPtr[1])
  819. && unit_array[*shortPtr]->can_resign() )
  820. {
  821. #ifdef DEBUG
  822. long_log->printf("nation %d resigns unit %d\n", shortPtr[1], shortPtr[0]);
  823. #endif
  824. unit_array[*shortPtr]->resign(COMMAND_REMOTE);
  825. }
  826. }
  827. // ------- End of function RemoteMsg::unit_resign ---------//
  828. // ------- Begin of function RemoteMsg::units_assign_to_ship ---------//
  829. void RemoteMsg::units_assign_to_ship()
  830. {
  831. err_when( id != MSG_UNITS_ASSIGN_TO_SHIP);
  832. // ##### patch begin Gilbert 5/8 ######//
  833. // packet structure : <xLoc> <yLoc> <ship recno> <no. of units> <divided> <unit recno ...>
  834. short *shortPtr = (short *)data_buf;
  835. validate_selected_unit_array(shortPtr+5, shortPtr[3]);
  836. if( shortPtr[3] > 0)
  837. {
  838. #ifdef DEBUG
  839. long_log->printf("assign to ship at (%d,%d), units : ", shortPtr[0], shortPtr[1]);
  840. for(int i = 0; i < shortPtr[3]; ++i)
  841. {
  842. long_log->printf("%d,", shortPtr[5+i]);
  843. if( i % 20 == 19)
  844. long_log->printf("\n");
  845. }
  846. long_log->printf("\n");
  847. #endif
  848. unit_array.assign_to_ship(shortPtr[0], shortPtr[1], shortPtr[4], shortPtr+5, shortPtr[3], COMMAND_REMOTE, shortPtr[2]);
  849. }
  850. // ##### patch end Gilbert 5/8 ######//
  851. }
  852. // ------- End of function RemoteMsg::units_assign_to_ship ---------//
  853. // ------- Begin of function RemoteMsg::units_ship_to_beach ---------//
  854. void RemoteMsg::units_ship_to_beach()
  855. {
  856. err_when( id != MSG_UNITS_SHIP_TO_BEACH);
  857. // packet structure : <xLoc> <yLoc> <no. of units> <divided> <unit recno ...>
  858. short *shortPtr = (short *)data_buf;
  859. validate_selected_unit_array(shortPtr+4, shortPtr[2]);
  860. if( shortPtr[2] > 0)
  861. {
  862. #ifdef DEBUG
  863. long_log->printf("move ships to beach at (%d,%d), units : ", shortPtr[0], shortPtr[1]);
  864. for(int i = 0; i < shortPtr[2]; ++i)
  865. {
  866. long_log->printf("%d,", shortPtr[4+i]);
  867. if( i % 20 == 19)
  868. long_log->printf("\n");
  869. }
  870. long_log->printf("\n");
  871. #endif
  872. unit_array.ship_to_beach(shortPtr[0], shortPtr[1], shortPtr[3], shortPtr+4, shortPtr[2], COMMAND_REMOTE);
  873. }
  874. }
  875. // ------- End of function RemoteMsg::units_assign_to_ship ---------//
  876. // ------- Begin of function RemoteMsg::unit_succeed_king ------//
  877. void RemoteMsg::unit_succeed_king()
  878. {
  879. err_when( id != MSG_UNIT_SUCCEED_KING);
  880. // packet structure : <unit recno> <nation recno>
  881. short *shortPtr = (short *)data_buf;
  882. short unitCount =1;
  883. validate_selected_unit_array(shortPtr, unitCount);
  884. if( unitCount > 0 && !nation_array.is_deleted(shortPtr[1]) &&
  885. unit_array[*shortPtr]->nation_recno == shortPtr[1] )
  886. {
  887. #ifdef DEBUG
  888. long_log->printf("unit %d succeed nation %d\n", shortPtr[0], shortPtr[1]);
  889. #endif
  890. nation_array[shortPtr[1]]->succeed_king(*shortPtr);
  891. if(unit_array.selected_recno == *shortPtr)
  892. info.disp();
  893. }
  894. }
  895. // ------- End of function RemoteMsg::unit_succeed_king ------//
  896. // ------- Begin of function RemoteMsg::units_return_camp ------//
  897. void RemoteMsg::units_return_camp()
  898. {
  899. err_when( id != MSG_UNITS_RETURN_CAMP );
  900. // packet structure : <no. of units> <unit recno ...>
  901. short *shortPtr = (short *)data_buf;
  902. validate_selected_unit_array(shortPtr+1, *shortPtr);
  903. if( *shortPtr > 0)
  904. {
  905. #ifdef DEBUG
  906. long_log->printf("return to camp, units : ");
  907. for(int i = 0; i < *shortPtr; ++i)
  908. {
  909. long_log->printf("%d,", shortPtr[1+i]);
  910. if( i % 20 == 19)
  911. long_log->printf("\n");
  912. }
  913. long_log->printf("\n");
  914. #endif
  915. unit_array.return_camp(COMMAND_REMOTE, shortPtr+1, *shortPtr);
  916. }
  917. }
  918. // ------- Begin of function RemoteMsg::caravan_change_goods ------//
  919. void RemoteMsg::caravan_change_goods()
  920. {
  921. err_when( id != MSG_U_CARA_CHANGE_GOODS );
  922. // packet structure <unit recno> <stop id> <new pick_up_type>
  923. short *shortPtr = (short *)data_buf;
  924. short unitCount =1;
  925. validate_selected_unit_array(shortPtr, unitCount);
  926. if( unitCount > 0)
  927. {
  928. Unit *unitPtr = unit_array[*shortPtr];
  929. UnitCaravan *caravanPtr;
  930. if( unitPtr->unit_id != UNIT_CARAVAN)
  931. {
  932. err_here();
  933. }
  934. else
  935. {
  936. #ifdef DEBUG
  937. long_log->printf("caravan %d change goods row %d, %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  938. #endif
  939. caravanPtr = (UnitCaravan *)unitPtr;
  940. // caravanPtr->stop_array[shortPtr[1]].pick_up_type = (char) shortPtr[2];
  941. caravanPtr->set_stop_pick_up(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  942. //if( unit_array.selected_recno == *shortPtr )
  943. // info.disp();
  944. }
  945. }
  946. }
  947. // ------- End of function RemoteMsg::caravan_change_goods ------//
  948. // ------- Begin of function RemoteMsg::caravan_set_stop ------//
  949. void RemoteMsg::caravan_set_stop()
  950. {
  951. err_when( id != MSG_U_CARA_SET_STOP );
  952. // packet structure <unit recno> <stop id> <stop x> <stop y>
  953. short *shortPtr = (short *)data_buf;
  954. short unitCount =1;
  955. validate_selected_unit_array(shortPtr, unitCount);
  956. if( unitCount > 0)
  957. {
  958. Unit *unitPtr = unit_array[*shortPtr];
  959. UnitCaravan *caravanPtr;
  960. if( unitPtr->unit_id != UNIT_CARAVAN)
  961. {
  962. err_here();
  963. }
  964. else
  965. {
  966. #ifdef DEBUG
  967. long_log->printf("caravan %d set stop %d at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2], shortPtr[3]);
  968. #endif
  969. caravanPtr = (UnitCaravan *)unitPtr;
  970. caravanPtr->set_stop(shortPtr[1], shortPtr[2], shortPtr[3], COMMAND_REMOTE);
  971. // if( unit_array.selected_recno == *shortPtr )
  972. // info.disp();
  973. }
  974. }
  975. }
  976. // ------- End of function RemoteMsg::caravan_set_stop ------//
  977. // ------- Begin of function RemoteMsg::caravan_del_stop ------//
  978. void RemoteMsg::caravan_del_stop()
  979. {
  980. err_when( id != MSG_U_CARA_DEL_STOP );
  981. // packet structure <unit recno> <stop id>
  982. short *shortPtr = (short *)data_buf;
  983. short unitCount =1;
  984. validate_selected_unit_array(shortPtr, unitCount);
  985. if( unitCount > 0)
  986. {
  987. Unit *unitPtr = unit_array[*shortPtr];
  988. UnitCaravan *caravanPtr;
  989. if( unitPtr->unit_id != UNIT_CARAVAN)
  990. {
  991. err_here();
  992. }
  993. else
  994. {
  995. #ifdef DEBUG
  996. long_log->printf("caravan %d delete stop %d, %d\n", shortPtr[0], shortPtr[1]);
  997. #endif
  998. caravanPtr = (UnitCaravan *)unitPtr;
  999. caravanPtr->del_stop(shortPtr[1], COMMAND_REMOTE);
  1000. //if( unit_array.selected_recno == *shortPtr )
  1001. // info.disp();
  1002. }
  1003. }
  1004. }
  1005. // ------- End of function RemoteMsg::caravan_del_stop ------//
  1006. // ------- Begin of function RemoteMsg::ship_unload_unit ---------//
  1007. void RemoteMsg::ship_unload_unit()
  1008. {
  1009. err_when( id != MSG_U_SHIP_UNLOAD_UNIT );
  1010. // packet structure <unit recno> <unitSeqId>
  1011. short *shortPtr = (short *)data_buf;
  1012. short unitCount =1;
  1013. validate_selected_unit_array(shortPtr, unitCount);
  1014. if( unitCount > 0)
  1015. {
  1016. Unit *unitPtr = unit_array[*shortPtr];
  1017. if( unitPtr->sprite_info->sprite_type == 'U'
  1018. && unitPtr->sprite_info->sprite_sub_type == 'M')
  1019. {
  1020. UnitMarine *shipPtr = (UnitMarine *)unitPtr;
  1021. if( shortPtr[1] <= shipPtr->unit_count )
  1022. {
  1023. // check if the unit is a ship
  1024. #ifdef DEBUG
  1025. long_log->printf("ship %d unload unit %d\n", shortPtr[0], shortPtr[1]);
  1026. #endif
  1027. shipPtr->unload_unit(shortPtr[1], COMMAND_REMOTE);
  1028. if( unit_array.selected_recno == *shortPtr )
  1029. info.disp();
  1030. }
  1031. }
  1032. else
  1033. {
  1034. err_here();
  1035. }
  1036. }
  1037. }
  1038. // ------- End of function RemoteMsg::ship_unload_unit ---------//
  1039. // ----- Begin of function RemoteMsg::ship_unload_all_units ----- //
  1040. void RemoteMsg::ship_unload_all_units()
  1041. {
  1042. err_when( id != MSG_U_SHIP_UNLOAD_ALL_UNITS );
  1043. // packet structure <unit recno>
  1044. short *shortPtr = (short *)data_buf;
  1045. short unitCount =1;
  1046. validate_selected_unit_array(shortPtr, unitCount);
  1047. if( unitCount > 0)
  1048. {
  1049. Unit *unitPtr = unit_array[*shortPtr];
  1050. if( unitPtr->sprite_info->sprite_type == 'U'
  1051. && unitPtr->sprite_info->sprite_sub_type == 'M')
  1052. {
  1053. // check if the unit is a ship
  1054. #ifdef DEBUG
  1055. long_log->printf("ship %d unload all units\n", shortPtr[0]);
  1056. #endif
  1057. UnitMarine *shipPtr = (UnitMarine *)unitPtr;
  1058. shipPtr->unload_all_units(COMMAND_REMOTE);
  1059. if( unit_array.selected_recno == *shortPtr )
  1060. info.disp();
  1061. }
  1062. else
  1063. {
  1064. err_here();
  1065. }
  1066. }
  1067. }
  1068. // ----- End of function RemoteMsg::ship_unload_all_units ----- //
  1069. // ------- Begin of function RemoteMsg::ship_change_goods ------//
  1070. void RemoteMsg::ship_change_goods()
  1071. {
  1072. err_when( id != MSG_U_SHIP_CHANGE_GOODS );
  1073. // packet structure <unit recno> <stop id> <new pick_up_type>
  1074. short *shortPtr = (short *)data_buf;
  1075. short unitCount =1;
  1076. validate_selected_unit_array(shortPtr, unitCount);
  1077. if( unitCount > 0)
  1078. {
  1079. Unit *unitPtr = unit_array[*shortPtr];
  1080. UnitMarine *shipPtr;
  1081. if( unitPtr->sprite_info->sprite_sub_type != 'M')
  1082. {
  1083. err_here();
  1084. }
  1085. else
  1086. {
  1087. #ifdef DEBUG
  1088. long_log->printf("ship %d change goods, row %d, %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  1089. #endif
  1090. shipPtr = (UnitMarine *)unitPtr;
  1091. // shipPtr->stop_array[shortPtr[1]].pick_up_type = (char) shortPtr[2];
  1092. shipPtr->set_stop_pick_up(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  1093. // if( unit_array.selected_recno == *shortPtr )
  1094. // info.disp();
  1095. }
  1096. }
  1097. }
  1098. // ------- End of function RemoteMsg::ship_change_goods ------//
  1099. // ------- Begin of function RemoteMsg::ship_set_stop ------//
  1100. void RemoteMsg::ship_set_stop()
  1101. {
  1102. err_when( id != MSG_U_SHIP_SET_STOP );
  1103. // packet structure <unit recno> <stop id> <stop x> <stop y>
  1104. short *shortPtr = (short *)data_buf;
  1105. short unitCount =1;
  1106. validate_selected_unit_array(shortPtr, unitCount);
  1107. if( unitCount > 0)
  1108. {
  1109. Unit *unitPtr = unit_array[*shortPtr];
  1110. UnitMarine *shipPtr;
  1111. if( unitPtr->sprite_info->sprite_sub_type != 'M')
  1112. {
  1113. err_here();
  1114. }
  1115. else
  1116. {
  1117. #ifdef DEBUG
  1118. long_log->printf("ship %d set stop %d at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2], shortPtr[3]);
  1119. #endif
  1120. shipPtr = (UnitMarine *)unitPtr;
  1121. shipPtr->set_stop(shortPtr[1], shortPtr[2], shortPtr[3], COMMAND_REMOTE);
  1122. }
  1123. }
  1124. }
  1125. // ------- End of function RemoteMsg::ship_set_stop ------//
  1126. // ------- Begin of function RemoteMsg::ship_del_stop ------//
  1127. void RemoteMsg::ship_del_stop()
  1128. {
  1129. err_when( id != MSG_U_SHIP_DEL_STOP );
  1130. // packet structure <unit recno> <stop id>
  1131. short *shortPtr = (short *)data_buf;
  1132. short unitCount =1;
  1133. validate_selected_unit_array(shortPtr, unitCount);
  1134. if( unitCount > 0)
  1135. {
  1136. Unit *unitPtr = unit_array[*shortPtr];
  1137. UnitMarine *shipPtr;
  1138. if( unitPtr->sprite_info->sprite_sub_type != 'M')
  1139. {
  1140. err_here();
  1141. }
  1142. else
  1143. {
  1144. #ifdef DEBUG
  1145. long_log->printf("ship %d delete stop %d\n", shortPtr[0], shortPtr[1]);
  1146. #endif
  1147. shipPtr = (UnitMarine *)unitPtr;
  1148. shipPtr->del_stop(shortPtr[1], COMMAND_REMOTE);
  1149. }
  1150. }
  1151. }
  1152. // ------- End of function RemoteMsg::ship_del_stop ------//
  1153. // ------- Begin of function RemoteMsg::ship_change_mode ------//
  1154. void RemoteMsg::ship_change_mode()
  1155. {
  1156. err_when( id != MSG_U_SHIP_CHANGE_MODE );
  1157. // packet structure <unit recno> <new mode>
  1158. short *shortPtr = (short *)data_buf;
  1159. short unitCount =1;
  1160. validate_selected_unit_array(shortPtr, unitCount);
  1161. if( unitCount > 0)
  1162. {
  1163. Unit *unitPtr = unit_array[*shortPtr];
  1164. UnitMarine *shipPtr;
  1165. if( unitPtr->sprite_info->sprite_sub_type != 'M')
  1166. {
  1167. err_here();
  1168. }
  1169. else
  1170. {
  1171. #ifdef DEBUG
  1172. long_log->printf("ship %d changes mode %d\n", shortPtr[0], shortPtr[1]);
  1173. #endif
  1174. shipPtr = (UnitMarine *)unitPtr;
  1175. shipPtr->auto_mode = (char) shortPtr[1];
  1176. if(*shortPtr==unit_array.selected_recno)
  1177. info.disp();
  1178. }
  1179. }
  1180. }
  1181. // ------- End of function RemoteMsg::ship_change_mode ------//
  1182. // ------- Begin of function RemoteMsg::change_spy_nation ------//
  1183. void RemoteMsg::change_spy_nation()
  1184. {
  1185. err_when( id != MSG_UNIT_SPY_NATION );
  1186. // packet structure <unit recno> <new nation recno>
  1187. short *shortPtr = (short *)data_buf;
  1188. short unitCount =1;
  1189. validate_selected_unit_array(shortPtr, unitCount);
  1190. if( unitCount > 0)
  1191. {
  1192. #ifdef DEBUG
  1193. long_log->printf("unit %d changes nation %d\n", shortPtr[0], shortPtr[1]);
  1194. #endif
  1195. unit_array[*shortPtr]->spy_change_nation(shortPtr[1], COMMAND_REMOTE);
  1196. if( unit_array.selected_recno == *shortPtr ||
  1197. unit_array[*shortPtr]->selected_flag)
  1198. info.disp();
  1199. }
  1200. }
  1201. // ------- End of function RemoteMsg::change_spy_nation ------//
  1202. // ------- Begin of function RemoteMsg::notify_cloaked_nation ------//
  1203. void RemoteMsg::notify_cloaked_nation()
  1204. {
  1205. err_when( id != MSG_UNIT_SPY_NOTIFY_CLOAKED_NATION );
  1206. // packet structure <unit recno> <new nation recno>
  1207. short *shortPtr = (short *)data_buf;
  1208. short unitCount =1;
  1209. validate_selected_unit_array(shortPtr, unitCount);
  1210. if( unitCount > 0)
  1211. {
  1212. if( !unit_array[*shortPtr]->spy_recno )
  1213. {
  1214. err_here();
  1215. }
  1216. else
  1217. {
  1218. #ifdef DEBUG
  1219. long_log->printf("unit %d notify cloaked nation %d\n", shortPtr[0], shortPtr[1]);
  1220. #endif
  1221. spy_array[unit_array[*shortPtr]->spy_recno]->notify_cloaked_nation_flag
  1222. = (char) shortPtr[1];
  1223. }
  1224. if( unit_array.selected_recno == *shortPtr ||
  1225. unit_array[*shortPtr]->selected_flag)
  1226. info.disp();
  1227. }
  1228. }
  1229. // ------- End of function RemoteMsg::notify_cloaked_nation ------//
  1230. //------ Begin of function RemoteMsg::unit_change_aggressive_mode -----//
  1231. //
  1232. void RemoteMsg::unit_change_aggressive_mode()
  1233. {
  1234. err_when( id != MSG_UNIT_CHANGE_AGGRESSIVE_MODE);
  1235. // packet structure : <unit recno> <new aggressive mode 0/1>
  1236. short *shortPtr = (short *)data_buf;
  1237. short unitCount =1;
  1238. validate_selected_unit_array(shortPtr, unitCount);
  1239. if( unitCount > 0 )
  1240. {
  1241. #ifdef DEBUG
  1242. long_log->printf("unit %d %s aggressive mode\n", shortPtr[0], shortPtr[1] ? "set" : "clear");
  1243. #endif
  1244. unit_array[*shortPtr]->aggressive_mode = (char) shortPtr[1];
  1245. }
  1246. }
  1247. //------- End of function RemoteMsg::unit_change_aggressive_mode ------//
  1248. //------ Begin of function RemoteMsg::spy_change_notify_flag -----//
  1249. //
  1250. void RemoteMsg::spy_change_notify_flag()
  1251. {
  1252. err_when( id != MSG_SPY_CHANGE_NOTIFY_FLAG) ;
  1253. // packet structure : <spy recno> <new notify flag 0/1>
  1254. short *shortPtr = (short *)data_buf;
  1255. spy_array[*shortPtr]->notify_cloaked_nation_flag = (char) shortPtr[1];
  1256. }
  1257. //------- End of function RemoteMsg::spy_change_notify_flag ------//
  1258. //########## begin trevor 15/10 #############//
  1259. //------ Begin of function RemoteMsg::spy_assassinate -----//
  1260. //
  1261. void RemoteMsg::spy_assassinate()
  1262. {
  1263. err_when( id != MSG_SPY_ASSASSINATE );
  1264. // packet structure : <spy recno> <assassinate target unit recno>
  1265. short *shortPtr = (short *)data_buf;
  1266. if( !spy_array.is_deleted(*shortPtr) )
  1267. {
  1268. #ifdef DEBUG
  1269. long_log->printf("spy %d assassinate unit %d", shortPtr[0], shortPtr[1]);
  1270. #endif
  1271. spy_array[*shortPtr]->assassinate( shortPtr[1], COMMAND_REMOTE );
  1272. }
  1273. }
  1274. //------- End of function RemoteMsg::spy_assassinate ------//
  1275. //########## end trevor 15/10 #############//
  1276. // ------- Begin of function RemoteMsg::firm_sell ---------//
  1277. void RemoteMsg::firm_sell()
  1278. {
  1279. err_when( id != MSG_FIRM_SELL);
  1280. // packet structure : <firm recno>
  1281. short *shortPtr = (short *)data_buf;
  1282. if( validate_firm(*shortPtr) )
  1283. {
  1284. #ifdef DEBUG
  1285. long_log->printf("sell firm %d\n", shortPtr[0]);
  1286. #endif
  1287. firm_array[*shortPtr]->sell_firm(COMMAND_REMOTE);
  1288. }
  1289. }
  1290. // ------- End of function RemoteMsg::firm_sell ---------//
  1291. // ------- Begin of function RemoteMsg::firm_cancel ---------//
  1292. void RemoteMsg::firm_cancel()
  1293. {
  1294. err_when( id != MSG_FIRM_CANCEL);
  1295. short *shortPtr = (short *)data_buf;
  1296. if( validate_firm(*shortPtr) )
  1297. {
  1298. #ifdef DEBUG
  1299. long_log->printf("firm %d cancel construction\n", shortPtr[0]);
  1300. #endif
  1301. firm_array[*shortPtr]->cancel_construction(COMMAND_REMOTE);
  1302. }
  1303. }
  1304. // ------- End of function RemoteMsg::firm_cancel ---------//
  1305. // ------- Begin of function RemoteMsg::firm_destruct ---------//
  1306. void RemoteMsg::firm_destruct()
  1307. {
  1308. err_when( id != MSG_FIRM_DESTRUCT);
  1309. // packet structure : <firm recno>
  1310. short *shortPtr = (short *)data_buf;
  1311. if( validate_firm(*shortPtr) )
  1312. {
  1313. #ifdef DEBUG
  1314. long_log->printf("destruct firm %d\n", shortPtr[0]);
  1315. #endif
  1316. firm_array[*shortPtr]->destruct_firm(COMMAND_REMOTE);
  1317. }
  1318. }
  1319. // ------- End of function RemoteMsg::firm_destruct ---------//
  1320. // ------- Begin of function RemoteMsg::firm_set_repair ---------//
  1321. void RemoteMsg::firm_set_repair()
  1322. {
  1323. //##### begin trevor 19/6 ######//
  1324. /*
  1325. err_when( id != MSG_FIRM_SET_REPAIR);
  1326. // packet structure : <firm recno> <new setting>
  1327. short *shortPtr = (short *)data_buf;
  1328. if( validate_firm(*shortPtr) )
  1329. firm_array[*shortPtr]->is_repairing = (char)shortPtr[1];
  1330. */
  1331. //##### end trevor 19/6 ######//
  1332. }
  1333. // ------- End of function RemoteMsg::firm_set_repair ---------//
  1334. // ------- Begin of function RemoteMsg::firm_train_level ---------//
  1335. void RemoteMsg::firm_train_level()
  1336. {
  1337. /* //**BUGHERE, no more training in game
  1338. err_when( id != MSG_FIRM_TRAIN_LEVEL);
  1339. // packet structure : <firm recno> <new train level>
  1340. short *shortPtr = (short *)data_buf;
  1341. if( !firm_array.is_deleted(*shortPtr) )
  1342. firm_array[*shortPtr]->train_level = (char)shortPtr[1];
  1343. */
  1344. }
  1345. // ------- End of function RemoteMsg::firm_train_level ---------//
  1346. // ------- Begin of function RemoteMsg::mobilize_worker ---------//
  1347. void RemoteMsg::mobilize_worker()
  1348. {
  1349. err_when( id != MSG_FIRM_MOBL_WORKER);
  1350. // packet structure : <firm recno> <workerId>
  1351. short *shortPtr = (short *)data_buf;
  1352. if( validate_firm(*shortPtr) && shortPtr[1] <= firm_array[*shortPtr]->worker_count)
  1353. {
  1354. #ifdef DEBUG
  1355. long_log->printf("firm %d mobilize worker %d\n", shortPtr[0], shortPtr[1]);
  1356. #endif
  1357. firm_array[*shortPtr]->mobilize_worker(shortPtr[1],COMMAND_REMOTE);
  1358. }
  1359. }
  1360. // ------- End of function RemoteMsg::mobilize_worker ---------//
  1361. // ------- Begin of function RemoteMsg::mobilize_overseer ---------//
  1362. void RemoteMsg::mobilize_overseer()
  1363. {
  1364. err_when( id != MSG_FIRM_MOBL_OVERSEER);
  1365. // packet structure : <firm recno>
  1366. short *shortPtr = (short *)data_buf;
  1367. if( validate_firm(*shortPtr) && firm_array[*shortPtr]->overseer_recno )
  1368. {
  1369. #ifdef DEBUG
  1370. long_log->printf("firm %d mobilize overseer\n", shortPtr[0]);
  1371. #endif
  1372. firm_array[*shortPtr]->assign_overseer(0);
  1373. }
  1374. }
  1375. // ------- End of function RemoteMsg::mobilize_overseer ---------//
  1376. // ------- Begin of function RemoteMsg::mobilize_builder ---------//
  1377. void RemoteMsg::mobilize_builder()
  1378. {
  1379. err_when( id != MSG_FIRM_MOBL_BUILDER);
  1380. // packet structure : <firm recno>
  1381. short *shortPtr = (short *)data_buf;
  1382. if( validate_firm(*shortPtr) && firm_array[*shortPtr]->builder_recno )
  1383. {
  1384. #ifdef DEBUG
  1385. long_log->printf("firm %d mobilize builder\n", shortPtr[0]);
  1386. #endif
  1387. firm_array[*shortPtr]->set_builder(0);
  1388. }
  1389. }
  1390. // ------- End of function RemoteMsg::mobilize_builder ---------//
  1391. // ------ Begin of function RemoteMsg::firm_toggle_link_firm ----//
  1392. void RemoteMsg::firm_toggle_link_firm()
  1393. {
  1394. err_when( id != MSG_FIRM_TOGGLE_LINK_FIRM);
  1395. // packet structure : <firm recno> <link Id> <toggle Flag>
  1396. short *shortPtr = (short *)data_buf;
  1397. if( validate_firm(*shortPtr) )
  1398. {
  1399. // ###### begin Gilbert 10/11 #######//
  1400. Firm *firmPtr = firm_array[*shortPtr];
  1401. short linkedFirmRecno = 0;
  1402. if( shortPtr[1] <= firmPtr->linked_firm_count
  1403. && (linkedFirmRecno = firmPtr->linked_firm_array[shortPtr[1]-1])
  1404. && validate_firm(linkedFirmRecno, 1) )
  1405. {
  1406. #ifdef DEBUG
  1407. long_log->printf("firm %d %s firm link %d\n", shortPtr[0],
  1408. shortPtr[2] ? "set":"clear", shortPtr[1]);
  1409. #endif
  1410. firm_array[*shortPtr]->toggle_firm_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  1411. }
  1412. // ###### end Gilbert 10/11 #######//
  1413. }
  1414. }
  1415. // ------ End of function RemoteMsg::firm_toggle_link_firm ----//
  1416. // ------ Begin of function RemoteMsg::firm_toggle_link_town ----//
  1417. void RemoteMsg::firm_toggle_link_town()
  1418. {
  1419. err_when( id != MSG_FIRM_TOGGLE_LINK_TOWN);
  1420. // packet structure : <firm recno> <link Id> <toggle Flag>
  1421. short *shortPtr = (short *)data_buf;
  1422. if( validate_firm(*shortPtr) )
  1423. {
  1424. // ###### begin Gilbert 10/11 ########//
  1425. Firm *firmPtr = firm_array[*shortPtr];
  1426. short linkedTownRecno = 0;
  1427. if( shortPtr[1] <= firmPtr->linked_town_count
  1428. && (linkedTownRecno = firmPtr->linked_town_array[shortPtr[1]-1])
  1429. && validate_town(linkedTownRecno, 1) )
  1430. {
  1431. #ifdef DEBUG
  1432. long_log->printf("firm %d %s town link %d\n", shortPtr[0],
  1433. shortPtr[2] ? "set":"clear", shortPtr[1]);
  1434. #endif
  1435. firmPtr->toggle_town_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  1436. // update town loyalty if the firm is FIRM_CAMP
  1437. if( firmPtr->firm_id == FIRM_CAMP )
  1438. {
  1439. Town *townPtr = town_array[linkedTownRecno];
  1440. if( townPtr->nation_recno )
  1441. townPtr->update_target_loyalty();
  1442. else
  1443. townPtr->update_target_resistance();
  1444. townPtr->update_camp_link();
  1445. }
  1446. }
  1447. // ###### end Gilbert 10/11 ########//
  1448. }
  1449. }
  1450. // ------ End of function RemoteMsg::firm_toggle_link_town ----//
  1451. // ------ Begin of function RemoteMsg::firm_pull_town_people ----//
  1452. void RemoteMsg::firm_pull_town_people()
  1453. {
  1454. err_when( id != MSG_FIRM_PULL_TOWN_PEOPLE);
  1455. // packet structure : <firm recno> <town recno> <race Id or 0> <force Pull>
  1456. short *shortPtr = (short *)data_buf;
  1457. if( validate_firm(*shortPtr) && validate_town(shortPtr[1]) )
  1458. {
  1459. #ifdef DEBUG
  1460. long_log->printf("firm %d %s pull race %d from town %d\n", shortPtr[0],
  1461. shortPtr[3] ? "forcely" : "", shortPtr[2], shortPtr[1]);
  1462. #endif
  1463. firm_array[*shortPtr]->pull_town_people(shortPtr[1], COMMAND_REMOTE, shortPtr[2], shortPtr[3]);
  1464. }
  1465. }
  1466. // ------ End of function RemoteMsg::firm_pull_town_people ----//
  1467. // ------ Begin of function RemoteMsg::firm_set_worker_home ----//
  1468. void RemoteMsg::firm_set_worker_home()
  1469. {
  1470. err_when( id != MSG_FIRM_SET_WORKER_HOME);
  1471. // packet structure : <firm recno> <town recno> <workerId>
  1472. short *shortPtr = (short *)data_buf;
  1473. if( validate_firm(*shortPtr) && validate_town(shortPtr[1]) )
  1474. {
  1475. #ifdef DEBUG
  1476. long_log->printf("firm %d workder %d migrate to town %d\n", shortPtr[0], shortPtr[2], shortPtr[1]);
  1477. #endif
  1478. firm_array[*shortPtr]->set_worker_home_town(shortPtr[1], COMMAND_REMOTE, shortPtr[2]);
  1479. }
  1480. }
  1481. // ------ End of function RemoteMsg::firm_set_worker_home ----//
  1482. // ------ Begin of function RemoteMsg::firm_bribe ----//
  1483. void RemoteMsg::firm_bribe()
  1484. {
  1485. err_when( id != MSG_FIRM_BRIBE);
  1486. // packet structure <firm recno> <spy recno> <bribe target : worker (0=overseer)> <amount>
  1487. short *shortPtr = (short *)data_buf;
  1488. // ###### begin Gilbert 10/11 #######//
  1489. Firm *firmPtr;
  1490. if( validate_firm(*shortPtr, 1) && !spy_array.is_deleted(shortPtr[1])
  1491. && (firmPtr = firm_array[*shortPtr])
  1492. && (shortPtr[2] == 0 && firmPtr->overseer_recno ||
  1493. shortPtr[2] >= 1 && shortPtr[2] <= firm_array[*shortPtr]->worker_count) )
  1494. // ###### end Gilbert 10/11 #######//
  1495. {
  1496. #ifdef DEBUG
  1497. long_log->printf("firm %d, spy %d briber worker %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  1498. #endif
  1499. firm_array[*shortPtr]->spy_bribe(shortPtr[3], shortPtr[1], shortPtr[2]);
  1500. }
  1501. }
  1502. // ------ End of function RemoteMsg::firm_bribe ----//
  1503. // ------ Begin of function RemoteMsg::firm_capture ----//
  1504. void RemoteMsg::firm_capture()
  1505. {
  1506. err_when( id != MSG_FIRM_CAPTURE);
  1507. // packet structure <firm recno> <nation recno>
  1508. short *shortPtr = (short *)data_buf;
  1509. if( validate_firm(*shortPtr, 1) )
  1510. {
  1511. #ifdef DEBUG
  1512. long_log->printf("firm %d, capture by nation %d\n", shortPtr[0], shortPtr[1]);
  1513. #endif
  1514. firm_array[*shortPtr]->capture_firm(shortPtr[1]);
  1515. }
  1516. }
  1517. // ------ End of function RemoteMsg::firm_capture ----//
  1518. // ------- Begin of function RemoteMsg::camp_patrol ---------//
  1519. void RemoteMsg::camp_patrol()
  1520. {
  1521. err_when( id != MSG_F_CAMP_PATROL);
  1522. if( validate_firm(*(short *)data_buf) )
  1523. {
  1524. FirmCamp *camp = firm_array[*(short *)data_buf]->cast_to_FirmCamp();
  1525. if(camp)
  1526. {
  1527. if(camp->overseer_recno || camp->worker_count > 0)
  1528. {
  1529. #ifdef DEBUG
  1530. long_log->printf("camp %d patrols\n", *(short *)data_buf);
  1531. #endif
  1532. camp->patrol();
  1533. }
  1534. }
  1535. else
  1536. {
  1537. err_here();
  1538. }
  1539. }
  1540. }
  1541. // ------- End of function RemoteMsg::camp_patrol ---------//
  1542. // ------- Begin of function RemoteMsg::toggle_camp_patrol ---------//
  1543. void RemoteMsg::toggle_camp_patrol()
  1544. {
  1545. err_when( id != MSG_F_CAMP_TOGGLE_PATROL);
  1546. // packet structure <firm recno> <defense_flag>
  1547. short *shortPtr = (short *)data_buf;
  1548. if( validate_firm(*shortPtr) )
  1549. {
  1550. FirmCamp *camp = firm_array[*shortPtr]->cast_to_FirmCamp();
  1551. if(camp)
  1552. {
  1553. #ifdef DEBUG
  1554. long_log->printf("camp %d %s patrol flag\n", shortPtr[0],
  1555. shortPtr[1] ? "set":"clear");
  1556. #endif
  1557. camp->defense_flag = char(shortPtr[1]);
  1558. if( firm_array.selected_recno == *shortPtr)
  1559. info.disp();
  1560. }
  1561. else
  1562. {
  1563. err_here();
  1564. }
  1565. }
  1566. }
  1567. // ------- End of function RemoteMsg::toggle_camp_patrol ---------//
  1568. // ------- Begin of function RemoteMsg::firm_reward ---------//
  1569. void RemoteMsg::firm_reward()
  1570. {
  1571. err_when( id != MSG_FIRM_REWARD);
  1572. // packet structure : <firm recno> <worker id>
  1573. short *shortPtr = (short *)data_buf;
  1574. if( validate_firm(*shortPtr) )
  1575. {
  1576. Firm *firmPtr = firm_array[*shortPtr];
  1577. // ##### begin Gilbert 10/11 ########//
  1578. if( shortPtr[1] == 0 && firmPtr->overseer_recno ||
  1579. shortPtr[1] >= 1 && shortPtr[1] <= firmPtr->worker_count )
  1580. {
  1581. #ifdef DEBUG
  1582. long_log->printf("firm %d reward worker %d\n", shortPtr[0], shortPtr[1]);
  1583. #endif
  1584. firmPtr->reward(shortPtr[1], COMMAND_REMOTE);
  1585. }
  1586. // ##### end Gilbert 10/11 ########//
  1587. }
  1588. }
  1589. // ------- End of function RemoteMsg::firm_reward ---------//
  1590. // ------- Begin of function RemoteMsg::inn_hire ---------//
  1591. void RemoteMsg::inn_hire()
  1592. {
  1593. err_when( id != MSG_F_INN_HIRE);
  1594. // packet structure : <firm recno>, <hire Id> <nation no>
  1595. short *shortPtr = (short *)data_buf;
  1596. if( validate_firm(*shortPtr) )
  1597. {
  1598. FirmInn *inn = firm_array[*shortPtr]->cast_to_FirmInn();
  1599. if(inn)
  1600. {
  1601. #ifdef DEBUG
  1602. long_log->printf("inn %d hire %d, by nation %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  1603. #endif
  1604. inn->hire(shortPtr[1]);
  1605. if( shortPtr[2] == nation_array.player_recno)
  1606. {
  1607. inn->put_info(INFO_REPAINT);
  1608. }
  1609. }
  1610. else
  1611. {
  1612. err_here();
  1613. }
  1614. }
  1615. }
  1616. // ------- End of function RemoteMsg::inn_hire ---------//
  1617. // ------- Begin of function RemoteMsg::market_scrap ---------//
  1618. void RemoteMsg::market_scrap()
  1619. {
  1620. err_when( id != MSG_F_MARKET_SCRAP );
  1621. // packet structure : <firm recno> <cell no 0-3>
  1622. short *shortPtr = (short *)data_buf;
  1623. if( validate_firm(*shortPtr) )
  1624. {
  1625. FirmMarket *firmMarket = firm_array[*shortPtr]->cast_to_FirmMarket();
  1626. if(!firmMarket)
  1627. {
  1628. err_here();
  1629. }
  1630. else
  1631. {
  1632. #ifdef DEBUG
  1633. long_log->printf("market %d scrap good row %d\n", shortPtr[0], shortPtr[1]);
  1634. #endif
  1635. MarketGoods* marketGoods = firmMarket->market_goods_array + shortPtr[1];
  1636. err_when(marketGoods->raw_id && marketGoods->product_raw_id);
  1637. if(marketGoods->raw_id)
  1638. {
  1639. firmMarket->market_raw_array[marketGoods->raw_id-1] = NULL;
  1640. marketGoods->raw_id = 0;
  1641. }
  1642. else if(marketGoods->product_raw_id)
  1643. {
  1644. firmMarket->market_product_array[marketGoods->product_raw_id-1] = NULL;
  1645. marketGoods->product_raw_id = 0;
  1646. }
  1647. marketGoods->stock_qty = (float) 0;
  1648. if( firm_array.selected_recno == *shortPtr )
  1649. info.disp();
  1650. }
  1651. }
  1652. }
  1653. // ------- End of function RemoteMsg::market_scrap ---------//
  1654. // ------- Begin of function RemoteMsg::market_hire_caravan ---------//
  1655. void RemoteMsg::market_hire_caravan()
  1656. {
  1657. err_when( id != MSG_F_MARKET_HIRE_CARA );
  1658. // packet structure : <town recno>
  1659. short *shortPtr = (short *)data_buf;
  1660. if( validate_firm(*shortPtr) )
  1661. {
  1662. FirmMarket *market = firm_array[*shortPtr]->cast_to_FirmMarket();
  1663. if(!market)
  1664. {
  1665. err_here();
  1666. }
  1667. else
  1668. {
  1669. #ifdef DEBUG
  1670. long_log->printf("market %d hire caravan\n", shortPtr[0]);
  1671. #endif
  1672. market->hire_caravan(COMMAND_REMOTE);
  1673. }
  1674. }
  1675. }
  1676. // ------- End of function RemoteMsg::market_hire_caravan ---------//
  1677. // ------- Begin of function RemoteMsg::research_start ---------//
  1678. void RemoteMsg::research_start()
  1679. {
  1680. err_when( id != MSG_F_RESEARCH_START );
  1681. // packet structure : <firm recno> <tech Id>
  1682. short *shortPtr = (short *)data_buf;
  1683. if( validate_firm(*shortPtr) )
  1684. {
  1685. FirmResearch *research = firm_array[*shortPtr]->cast_to_FirmResearch();
  1686. if(!research)
  1687. {
  1688. err_here();
  1689. }
  1690. else
  1691. {
  1692. #ifdef DEBUG
  1693. long_log->printf("tower of science %d start research tech %d\n", shortPtr[0], shortPtr[1]);
  1694. #endif
  1695. research->start_research(shortPtr[1], COMMAND_REMOTE);
  1696. }
  1697. }
  1698. }
  1699. // ------- End of function RemoteMsg::research_start ---------//
  1700. // ------- Begin of function RemoteMsg::build_weapon ---------//
  1701. void RemoteMsg::build_weapon()
  1702. {
  1703. err_when( id != MSG_F_WAR_BUILD_WEAPON );
  1704. // packet structure : <firm recno> <unit Id>
  1705. short *shortPtr = (short *)data_buf;
  1706. if( validate_firm(*shortPtr) )
  1707. {
  1708. FirmWar *warFactory = firm_array[*shortPtr]->cast_to_FirmWar();
  1709. if(!warFactory)
  1710. {
  1711. err_here();
  1712. }
  1713. else
  1714. {
  1715. #ifdef DEBUG
  1716. long_log->printf("war factory %d start building unit id %d\n", shortPtr[0], shortPtr[1]);
  1717. #endif
  1718. warFactory->add_queue(shortPtr[1]);
  1719. }
  1720. }
  1721. }
  1722. // ------- End of function RemoteMsg::build_weapon ---------//
  1723. // ------- Begin of function RemoteMsg::cancel_weapon ---------//
  1724. void RemoteMsg::cancel_weapon()
  1725. {
  1726. err_when( id != MSG_F_WAR_CANCEL_WEAPON );
  1727. // packet structure : <firm recno> <unit Id>
  1728. short *shortPtr = (short *)data_buf;
  1729. if( validate_firm(*shortPtr) )
  1730. {
  1731. FirmWar *warFactory = firm_array[*shortPtr]->cast_to_FirmWar();
  1732. if(!warFactory)
  1733. {
  1734. err_here();
  1735. }
  1736. else
  1737. {
  1738. #ifdef DEBUG
  1739. long_log->printf("war factory %d cancel building unit id %d\n", shortPtr[0], shortPtr[1]);
  1740. #endif
  1741. warFactory->remove_queue(shortPtr[1]);
  1742. }
  1743. }
  1744. }
  1745. // ------- End of function RemoteMsg::cancel_weapon ---------//
  1746. // ------- Begin of function RemoteMsg::skip_build_weapon ---------//
  1747. void RemoteMsg::skip_build_weapon()
  1748. {
  1749. err_when( id != MSG_F_WAR_SKIP_WEAPON );
  1750. // packet structure : <firm recno>
  1751. short *shortPtr = (short *)data_buf;
  1752. if( validate_firm(*shortPtr) )
  1753. {
  1754. FirmWar *warFactory = firm_array[*shortPtr]->cast_to_FirmWar();
  1755. if(!warFactory)
  1756. {
  1757. err_here();
  1758. }
  1759. else
  1760. {
  1761. #ifdef DEBUG
  1762. long_log->printf("war factory %d skip weapon building\n", shortPtr[0]);
  1763. #endif
  1764. warFactory->cancel_build_unit();
  1765. }
  1766. }
  1767. }
  1768. // ------- End of function RemoteMsg::skip_build_weapon ---------//
  1769. // ------- Begin of function RemoteMsg::build_ship ---------//
  1770. void RemoteMsg::build_ship()
  1771. {
  1772. err_when( id != MSG_F_HARBOR_BUILD_SHIP );
  1773. // packet structure : <firm recno> <unit Id>
  1774. short *shortPtr = (short *)data_buf;
  1775. if( validate_firm(*shortPtr) )
  1776. {
  1777. FirmHarbor *harbor = firm_array[*shortPtr]->cast_to_FirmHarbor();
  1778. if(!harbor)
  1779. {
  1780. err_here();
  1781. }
  1782. else
  1783. {
  1784. #ifdef DEBUG
  1785. long_log->printf("harbor %d start building unit id %d\n", shortPtr[0], shortPtr[1]);
  1786. #endif
  1787. // harbor->build_ship(shortPtr[1], COMMAND_REMOTE);
  1788. if( shortPtr[1] > 0)
  1789. harbor->add_queue(shortPtr[1]);
  1790. else if( shortPtr[1] < 0)
  1791. harbor->remove_queue(-shortPtr[1]);
  1792. else
  1793. {
  1794. err_here();
  1795. }
  1796. }
  1797. }
  1798. }
  1799. // ------- End of function RemoteMsg::build_ship ---------//
  1800. // ------- Begin of function RemoteMsg::sail_ship ---------//
  1801. void RemoteMsg::sail_ship()
  1802. {
  1803. err_when( id != MSG_F_HARBOR_SAIL_SHIP );
  1804. // packet structure : <firm recno> <browse Recno>
  1805. short *shortPtr = (short *)data_buf;
  1806. if( validate_firm(*shortPtr) )
  1807. {
  1808. FirmHarbor *harbor = firm_array[*shortPtr]->cast_to_FirmHarbor();
  1809. if(!harbor)
  1810. {
  1811. err_here();
  1812. }
  1813. else
  1814. {
  1815. #ifdef DEBUG
  1816. long_log->printf("ship %d depart from harbor %d\n", shortPtr[1], shortPtr[0]);
  1817. #endif
  1818. harbor->sail_ship(shortPtr[1], COMMAND_REMOTE);
  1819. }
  1820. }
  1821. }
  1822. // ------- End of function RemoteMsg::sail_ship --------//
  1823. // ------- Begin of function RemoteMsg::skip_build_ship ---------//
  1824. void RemoteMsg::skip_build_ship()
  1825. {
  1826. err_when( id != MSG_F_HARBOR_SKIP_SHIP );
  1827. // packet structure : <firm recno>
  1828. short *shortPtr = (short *)data_buf;
  1829. if( validate_firm(*shortPtr) )
  1830. {
  1831. FirmHarbor *harbor = firm_array[*shortPtr]->cast_to_FirmHarbor();
  1832. if(!harbor)
  1833. {
  1834. err_here();
  1835. }
  1836. else
  1837. {
  1838. #ifdef DEBUG
  1839. long_log->printf("harbr %d skip ship building\n", shortPtr[0]);
  1840. #endif
  1841. harbor->cancel_build_unit();
  1842. }
  1843. }
  1844. }
  1845. // ------- End of function RemoteMsg::skip_build_ship ---------//
  1846. // ------- Begin of function RemoteMsg::factory_change_product ---------//
  1847. void RemoteMsg::factory_change_product()
  1848. {
  1849. #define DEFAULT_FACTORY_MAX_STOCK_QTY 500
  1850. #define DEFAULT_FACTORY_MAX_RAW_STOCK_QTY 500
  1851. err_when( id != MSG_F_FACTORY_CHG_PROD );
  1852. // packet structure : <firm recno> <product id>
  1853. short *shortPtr = (short *)data_buf;
  1854. if( validate_firm(*shortPtr) )
  1855. {
  1856. FirmFactory *factory = firm_array[*shortPtr]->cast_to_FirmFactory();
  1857. if(!factory)
  1858. {
  1859. err_here();
  1860. }
  1861. else
  1862. {
  1863. #ifdef DEBUG
  1864. long_log->printf("factory %d change product to %d\n", shortPtr[0], shortPtr[1]);
  1865. #endif
  1866. factory->product_raw_id = shortPtr[1];
  1867. factory->stock_qty = (float) 0;
  1868. factory->max_stock_qty = (float) DEFAULT_FACTORY_MAX_STOCK_QTY;
  1869. factory->raw_stock_qty = (float) 0;
  1870. factory->max_raw_stock_qty = (float) DEFAULT_FACTORY_MAX_RAW_STOCK_QTY;
  1871. }
  1872. }
  1873. }
  1874. // ------- End of function RemoteMsg::factory_change_product --------//
  1875. void RemoteMsg::base_mobilize_prayer()
  1876. {
  1877. err_when( id != MSG_F_BASE_MOBL_PRAYER);
  1878. err_here();
  1879. /*
  1880. // packet structure : <firm recno>
  1881. short *shortPtr = (short *)data_buf;
  1882. if( validate_firm(*shortPtr) )
  1883. {
  1884. FirmBase *base = firm_array[*shortPtr]->cast_to_FirmBase();
  1885. if( !base )
  1886. {
  1887. err_here();
  1888. }
  1889. else
  1890. {
  1891. #ifdef DEBUG
  1892. long_log->printf("seat of power %d mobilize prayer\n", shortPtr[0]);
  1893. #endif
  1894. base->resign_prayer();
  1895. }
  1896. }
  1897. */
  1898. }
  1899. void RemoteMsg::invoke_god()
  1900. {
  1901. err_when( id != MSG_F_BASE_INVOKE_GOD);
  1902. // packet structure : <firm recno>
  1903. short *shortPtr = (short *)data_buf;
  1904. if( validate_firm(*shortPtr) )
  1905. {
  1906. FirmBase *base = firm_array[*shortPtr]->cast_to_FirmBase();
  1907. if( !base )
  1908. {
  1909. err_here();
  1910. }
  1911. else
  1912. {
  1913. // ##### begin Gilbert 10/11 ########//
  1914. if( base->can_invoke() )
  1915. {
  1916. #ifdef DEBUG
  1917. long_log->printf("seat of power %d invoke god\n", shortPtr[0]);
  1918. #endif
  1919. base->invoke_god();
  1920. }
  1921. // ##### end Gilbert 10/11 ########//
  1922. }
  1923. }
  1924. }
  1925. // ------- Begin of function RemoteMsg::town_recruit ---------//
  1926. void RemoteMsg::town_recruit()
  1927. {
  1928. err_when( id != MSG_TOWN_RECRUIT);
  1929. // packet structure : <town recno> <skill id> <race id>
  1930. short *shortPtr = (short *)data_buf;
  1931. if( validate_town(*shortPtr) )
  1932. {
  1933. #ifdef DEBUG
  1934. long_log->printf("town %d train skill %d of race %d\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  1935. #endif
  1936. if( shortPtr[2] > 0 )
  1937. {
  1938. if( shortPtr[1] == -1 ) // recruit unskilled unit
  1939. town_array[*shortPtr]->recruit(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  1940. else // add train worker skill
  1941. town_array[*shortPtr]->add_queue((char) shortPtr[1], (char) shortPtr[2]);
  1942. }
  1943. else if( shortPtr[2] == -1)
  1944. {
  1945. // remove train worker skill
  1946. town_array[*shortPtr]->remove_queue((char) shortPtr[1]);
  1947. }
  1948. else
  1949. {
  1950. err_here();
  1951. }
  1952. if( town_array.selected_recno == *shortPtr )
  1953. info.update();
  1954. }
  1955. }
  1956. // ------- End of function RemoteMsg::town_recruit ---------//
  1957. // ------- Begin of function RemoteMsg::town_skip_recruit ---------//
  1958. void RemoteMsg::town_skip_recruit()
  1959. {
  1960. err_when( id != MSG_TOWN_SKIP_RECRUIT);
  1961. // packet structure : <town recno>
  1962. short *shortPtr = (short *)data_buf;
  1963. if( validate_town(*shortPtr) )
  1964. {
  1965. #ifdef DEBUG
  1966. long_log->printf("town %d skip unit training\n", shortPtr[0]);
  1967. #endif
  1968. town_array[*shortPtr]->cancel_train_unit();
  1969. if( town_array.selected_recno == *shortPtr )
  1970. info.disp();
  1971. }
  1972. }
  1973. // ------- End of function RemoteMsg::town_skip_recruit ---------//
  1974. // ------- Begin of function RemoteMsg::town_migrate ---------//
  1975. void RemoteMsg::town_migrate()
  1976. {
  1977. err_when( id != MSG_TOWN_MIGRATE);
  1978. // packet structure : <town recno> <dest town recno> <race id>
  1979. short *shortPtr = (short *)data_buf;
  1980. if( validate_town(*shortPtr) && validate_town(shortPtr[1]) )
  1981. {
  1982. #ifdef DEBUG
  1983. long_log->printf("town %d race %d migrate to town %d\n", shortPtr[0], shortPtr[2], shortPtr[1]);
  1984. #endif
  1985. town_array[*shortPtr]->migrate_to(shortPtr[1], COMMAND_REMOTE, shortPtr[2]);
  1986. }
  1987. }
  1988. // ------- End of function RemoteMsg::town_migrate ---------//
  1989. // ------- Begin of function RemoteMsg::town_collect_tax ---------//
  1990. void RemoteMsg::town_collect_tax()
  1991. {
  1992. //### begin trevor 6/8 ####//
  1993. err_when( id != MSG_TOWN_COLLECT_TAX );
  1994. // packet structure : <town recno>
  1995. short *shortPtr = (short *)data_buf;
  1996. if( validate_town(*shortPtr) )
  1997. {
  1998. #ifdef DEBUG
  1999. long_log->printf("town %d collect tax\n", shortPtr[0]);
  2000. #endif
  2001. town_array[*shortPtr]->collect_tax(COMMAND_REMOTE);
  2002. }
  2003. //### end trevor 6/8 ####//
  2004. }
  2005. // ------- End of function RemoteMsg::town_collect_tax ---------//
  2006. // ------- Begin of function RemoteMsg::town_reward ---------//
  2007. void RemoteMsg::town_reward()
  2008. {
  2009. //### begin trevor 6/8 ####//
  2010. err_when( id != MSG_TOWN_REWARD );
  2011. // packet structure : <town recno>
  2012. short *shortPtr = (short *)data_buf;
  2013. if( validate_town(*shortPtr) )
  2014. {
  2015. #ifdef DEBUG
  2016. long_log->printf("town %d reward\n", shortPtr[0]);
  2017. #endif
  2018. town_array[*shortPtr]->reward(COMMAND_REMOTE);
  2019. }
  2020. //### end trevor 6/8 ####//
  2021. }
  2022. // ------- End of function RemoteMsg::town_reward ---------//
  2023. // ------ Begin of function RemoteMsg::town_toggle_link_firm ----//
  2024. void RemoteMsg::town_toggle_link_firm()
  2025. {
  2026. err_when( id != MSG_TOWN_TOGGLE_LINK_FIRM);
  2027. // packet structure : <town recno> <link Id> <toggle Flag>
  2028. short *shortPtr = (short *)data_buf;
  2029. if( validate_town(*shortPtr) )
  2030. {
  2031. #ifdef DEBUG
  2032. long_log->printf("town %d %s firm link %d\n", shortPtr[0],
  2033. shortPtr[2] ? "set" : "clear", shortPtr[1]);
  2034. #endif
  2035. Town *townPtr = town_array[*shortPtr];
  2036. // ####### begin Gilbert 10/11 #######//
  2037. short linkedFirmRecno = 0;
  2038. if( shortPtr[1] <= townPtr->linked_firm_count
  2039. && (linkedFirmRecno = townPtr->linked_firm_array[shortPtr[1]-1])
  2040. && validate_firm(linkedFirmRecno, 1) )
  2041. {
  2042. townPtr->toggle_firm_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  2043. // update loyalty if the linked firm is FIRM_BASE
  2044. if( firm_array[linkedFirmRecno]->firm_id == FIRM_CAMP )
  2045. {
  2046. if(townPtr->nation_recno)
  2047. townPtr->update_target_loyalty();
  2048. else
  2049. townPtr->update_target_resistance();
  2050. townPtr->update_camp_link();
  2051. }
  2052. }
  2053. // ####### end Gilbert 10/11 #######//
  2054. }
  2055. }
  2056. // ------ End of function RemoteMsg::town_toggle_link_firm ----//
  2057. // ------ Begin of function RemoteMsg::town_toggle_link_town ----//
  2058. void RemoteMsg::town_toggle_link_town()
  2059. {
  2060. err_when( id != MSG_TOWN_TOGGLE_LINK_TOWN);
  2061. // packet structure : <town recno> <link Id> <toggle Flag>
  2062. short *shortPtr = (short *)data_buf;
  2063. if( validate_town(*shortPtr) )
  2064. {
  2065. // ###### begin Gilbert 10/11 #######//
  2066. Town *townPtr = town_array[*shortPtr];
  2067. short linkedTownRecno = 0;
  2068. if( shortPtr[1] <= townPtr->linked_town_count
  2069. && (linkedTownRecno = townPtr->linked_town_array[shortPtr[1]-1])
  2070. && validate_town(linkedTownRecno, 1) )
  2071. {
  2072. #ifdef DEBUG
  2073. long_log->printf("town %d %s town link %d\n", shortPtr[0],
  2074. shortPtr[2] ? "set" : "clear", shortPtr[1]);
  2075. #endif
  2076. town_array[*shortPtr]->toggle_town_link(shortPtr[1], shortPtr[2], COMMAND_REMOTE);
  2077. }
  2078. // ###### end Gilbert 10/11 #######//
  2079. }
  2080. }
  2081. // ------ End of function RemoteMsg::town_toggle_link_town ----//
  2082. // ------ Begin of function RemoteMsg::town_auto_tax -------//
  2083. void RemoteMsg::town_auto_tax()
  2084. {
  2085. err_when( id != MSG_TOWN_AUTO_TAX );
  2086. // packet structure : <town recno> <loyalty level>
  2087. // or <-nation recno> <loyalty level>
  2088. short *shortPtr = (short *)data_buf;
  2089. if( *shortPtr > 0)
  2090. {
  2091. if( validate_town(*shortPtr) )
  2092. {
  2093. #ifdef DEBUG
  2094. long_log->printf("town %d auto collect tax at loyal %d\n", shortPtr[0], shortPtr[1]);
  2095. #endif
  2096. town_array[*shortPtr]->set_auto_collect_tax_loyalty(shortPtr[1]);
  2097. if( town_array.selected_recno == *shortPtr )
  2098. info.disp();
  2099. }
  2100. }
  2101. else
  2102. {
  2103. short nationRecno = -*shortPtr;
  2104. err_when( !nationRecno );
  2105. #ifdef DEBUG
  2106. long_log->printf("nation %d auto collect tax at loyal %d\n", nationRecno, shortPtr[1]);
  2107. #endif
  2108. if( !nation_array.is_deleted(nationRecno) )
  2109. {
  2110. nation_array[nationRecno]->set_auto_collect_tax_loyalty(shortPtr[1]);
  2111. for( int townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
  2112. {
  2113. Town *townPtr;
  2114. if( !town_array.is_deleted(townRecno) && (townPtr = town_array[townRecno]) &&
  2115. townPtr->nation_recno == nationRecno )
  2116. {
  2117. townPtr->set_auto_collect_tax_loyalty(shortPtr[1]);
  2118. if( town_array.selected_recno == townRecno )
  2119. info.disp();
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. // ------ End of function RemoteMsg::town_auto_tax -------//
  2126. // ------ Begin of function RemoteMsg::town_auto_grant -------//
  2127. void RemoteMsg::town_auto_grant()
  2128. {
  2129. err_when( id != MSG_TOWN_AUTO_GRANT );
  2130. // packet structure : <town recno> <loyalty level>
  2131. // or <-nation recno> <loyalty level>
  2132. short *shortPtr = (short *)data_buf;
  2133. if( *shortPtr > 0 )
  2134. {
  2135. if( validate_town(*shortPtr) )
  2136. {
  2137. #ifdef DEBUG
  2138. long_log->printf("town %d auto grant at loyal %d\n", shortPtr[0], shortPtr[1]);
  2139. #endif
  2140. town_array[*shortPtr]->set_auto_grant_loyalty(shortPtr[1]);
  2141. if( town_array.selected_recno == *shortPtr )
  2142. info.disp();
  2143. }
  2144. }
  2145. else
  2146. {
  2147. short nationRecno = -*shortPtr;
  2148. err_when( !nationRecno );
  2149. #ifdef DEBUG
  2150. long_log->printf("nation %d auto grant at loyal %d\n", nationRecno, shortPtr[1]);
  2151. #endif
  2152. if( !nation_array.is_deleted(nationRecno) )
  2153. {
  2154. nation_array[nationRecno]->set_auto_grant_loyalty(shortPtr[1]);
  2155. for( int townRecno=town_array.size() ; townRecno>0 ; townRecno-- )
  2156. {
  2157. Town *townPtr;
  2158. if( !town_array.is_deleted(townRecno) && (townPtr = town_array[townRecno]) &&
  2159. townPtr->nation_recno == nationRecno )
  2160. {
  2161. townPtr->set_auto_grant_loyalty(shortPtr[1]);
  2162. if( town_array.selected_recno == townRecno )
  2163. info.disp();
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. // ------ End of function RemoteMsg::town_auto_grant -------//
  2170. // ------ Begin of function RemoteMsg::town_grant_independent -------//
  2171. void RemoteMsg::town_grant_independent()
  2172. {
  2173. err_when( id != MSG_TOWN_GRANT_INDEPENDENT );
  2174. // packet structure : <town recno> <nation recno>
  2175. short *shortPtr = (short *)data_buf;
  2176. if( validate_town(*shortPtr, 1) && !nation_array.is_deleted(shortPtr[1]) )
  2177. {
  2178. town_array[*shortPtr]->grant_to_non_own_town(shortPtr[1], COMMAND_REMOTE);
  2179. }
  2180. }
  2181. // ------ Begin of function RemoteMsg::town_grant_independent -------//
  2182. // ------- Begin of function RemoteMsg::wall_build---------//
  2183. void RemoteMsg::wall_build()
  2184. {
  2185. err_when( id != MSG_WALL_BUILD);
  2186. // packet structure : <nation recno> <xLoc> <yLoc>
  2187. short *shortPtr = (short *)data_buf;
  2188. if( !nation_array.is_deleted(*shortPtr) )
  2189. {
  2190. #ifdef DEBUG
  2191. long_log->printf("nation %d build wall at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  2192. #endif
  2193. world.build_wall_tile( shortPtr[1], shortPtr[2], shortPtr[0], COMMAND_REMOTE);
  2194. }
  2195. }
  2196. // ------- End of function RemoteMsg::wall_build---------//
  2197. // ------- Begin of function RemoteMsg::wall_destruct ---------//
  2198. void RemoteMsg::wall_destruct()
  2199. {
  2200. err_when( id != MSG_WALL_DESTRUCT);
  2201. // packet structure : <nation recno> <xLoc> <yLoc>
  2202. short *shortPtr = (short *)data_buf;
  2203. if( !nation_array.is_deleted(*shortPtr) )
  2204. {
  2205. #ifdef DEBUG
  2206. long_log->printf("nation %d destruct wall at (%d,%d)\n", shortPtr[0], shortPtr[1], shortPtr[2]);
  2207. #endif
  2208. world.destruct_wall_tile( shortPtr[1], shortPtr[2], shortPtr[0], COMMAND_REMOTE);
  2209. }
  2210. }
  2211. // ------- End of function RemoteMsg::wall_build---------//
  2212. // ------- Begin of function RemoteMsg::spy_cycle_action -------//
  2213. void RemoteMsg::spy_cycle_action()
  2214. {
  2215. err_when( id != MSG_SPY_CYCLE_ACTION);
  2216. // packet structure : <spy recno>
  2217. short *shortPtr = (short *)data_buf;
  2218. if( !spy_array.is_deleted(*shortPtr) )
  2219. {
  2220. #ifdef DEBUG
  2221. long_log->printf("spy %d change action\n", shortPtr[0]);
  2222. #endif
  2223. spy_array[*shortPtr]->set_next_action_mode();
  2224. }
  2225. }
  2226. // ------- End of function RemoteMsg::spy_cycle_action -------//
  2227. // ------- Begin of function RemoteMsg::spy_leave_town -------//
  2228. void RemoteMsg::spy_leave_town()
  2229. {
  2230. err_when( id != MSG_SPY_LEAVE_TOWN);
  2231. // packet structure : <spy recno>
  2232. short *shortPtr = (short *)data_buf;
  2233. if( !spy_array.is_deleted(*shortPtr) )
  2234. {
  2235. #ifdef DEBUG
  2236. long_log->printf("spy %d leave town\n", shortPtr[0]);
  2237. #endif
  2238. //##### trevor 10/10 #####//
  2239. if( spy_array[*shortPtr]->spy_place == SPY_TOWN )
  2240. {
  2241. spy_array[*shortPtr]->mobilize_town_spy();
  2242. spy_array[*shortPtr]->notify_cloaked_nation_flag = 0;
  2243. }
  2244. //##### trevor 10/10 #####//
  2245. }
  2246. }
  2247. // ------- End of function RemoteMsg::spy_leave_town -------//
  2248. // ------- Begin of function RemoteMsg::spy_leave_firm -------//
  2249. void RemoteMsg::spy_leave_firm()
  2250. {
  2251. err_when( id != MSG_SPY_LEAVE_FIRM);
  2252. // packet structure : <spy recno>
  2253. short *shortPtr = (short *)data_buf;
  2254. if( !spy_array.is_deleted(*shortPtr) )
  2255. {
  2256. #ifdef DEBUG
  2257. long_log->printf("spy %d leave firm\n", shortPtr[0]);
  2258. #endif
  2259. //##### trevor 10/10 #####//
  2260. if( spy_array[*shortPtr]->spy_place == SPY_FIRM )
  2261. {
  2262. spy_array[*shortPtr]->mobilize_firm_spy();
  2263. spy_array[*shortPtr]->notify_cloaked_nation_flag = 0;
  2264. }
  2265. //##### trevor 10/10 #####//
  2266. }
  2267. }
  2268. // ------- End of function RemoteMsg::spy_leave_firm -------//
  2269. // ------- Begin of function RemoteMsg::spy_capture_firm -------//
  2270. void RemoteMsg::spy_capture_firm()
  2271. {
  2272. err_when( id != MSG_SPY_CAPTURE_FIRM);
  2273. // packet structure : <spy recno>
  2274. short *shortPtr = (short *)data_buf;
  2275. if( !spy_array.is_deleted(*shortPtr) )
  2276. {
  2277. #ifdef DEBUG
  2278. long_log->printf("spy %d capture firm\n", shortPtr[0]);
  2279. #endif
  2280. spy_array[*shortPtr]->capture_firm();
  2281. }
  2282. }
  2283. // ------- End of function RemoteMsg::capture_firm -------//
  2284. // ------- Begin of function RemoteMsg::spy_drop_identity ------//
  2285. void RemoteMsg::spy_drop_identity()
  2286. {
  2287. err_when( id != MSG_SPY_DROP_IDENTITY );
  2288. // packet structure : <spy recno>
  2289. short *shortPtr = (short *)data_buf;
  2290. if( !spy_array.is_deleted(*shortPtr) )
  2291. {
  2292. #ifdef DEBUG
  2293. long_log->printf("spy %d drop identity\n", shortPtr[0]);
  2294. #endif
  2295. spy_array[*shortPtr]->drop_spy_identity();
  2296. }
  2297. }
  2298. // ------- End of function RemoteMsg::spy_drop_identity ------//
  2299. // ------- Begin of function RemoteMsg::spy_reward ------//
  2300. void RemoteMsg::spy_reward()
  2301. {
  2302. err_when( id != MSG_SPY_REWARD );
  2303. // packet structure : <spy recno>
  2304. short *shortPtr = (short *)data_buf;
  2305. if( !spy_array.is_deleted(*shortPtr) )
  2306. {
  2307. #ifdef DEBUG
  2308. long_log->printf("spy %d reward\n", shortPtr[0]);
  2309. #endif
  2310. spy_array[*shortPtr]->reward(COMMAND_REMOTE);
  2311. }
  2312. }
  2313. // ------- End of function RemoteMsg::spy_reward ------//
  2314. // ------- Begin of function RemoteMsg::spy_set_exposed ------//
  2315. void RemoteMsg::spy_exposed()
  2316. {
  2317. err_when( id != MSG_SPY_EXPOSED );
  2318. // packet structure : <spy recno>
  2319. short *shortPtr = (short *)data_buf;
  2320. if( !spy_array.is_deleted(*shortPtr) )
  2321. {
  2322. #ifdef DEBUG
  2323. long_log->printf("spy %d set exposed\n", shortPtr[0]);
  2324. #endif
  2325. spy_array[*shortPtr]->set_exposed(COMMAND_REMOTE);
  2326. }
  2327. }
  2328. // ------- End of function RemoteMsg::spy_set_exposed ------//
  2329. // ------- Begin of function RemoteMsg::send_talk_msg -------//
  2330. void RemoteMsg::send_talk_msg()
  2331. {
  2332. err_when( id != MSG_SEND_TALK_MSG);
  2333. // packet structure : <talkMsg>
  2334. #ifdef DEBUG
  2335. TalkMsg *talkMsg = (TalkMsg *)data_buf;
  2336. long_log->printf("talk message from %d to %d, id %d, para1=%d, para2=%d\n",
  2337. talkMsg->from_nation_recno, talkMsg->to_nation_recno,
  2338. talkMsg->talk_id, talkMsg->talk_para1, talkMsg->talk_para2);
  2339. #endif
  2340. talk_res.send_talk_msg( (TalkMsg *)data_buf, COMMAND_REMOTE);
  2341. }
  2342. // ------- End of function RemoteMsg::send_talk_msg -------//
  2343. // ------- Begin of function RemoteMsg::reply_talk_msg -------//
  2344. void RemoteMsg::reply_talk_msg()
  2345. {
  2346. err_when( id != MSG_REPLY_TALK_MSG);
  2347. // packet structure : <talkRecno:int> <reply type:char> <padding:char>
  2348. //####### begin trevor 28/8 ########//
  2349. int talkMsgRecno = *(int*)data_buf;
  2350. if( !talk_res.is_talk_msg_deleted(talkMsgRecno) )
  2351. {
  2352. #ifdef DEBUG
  2353. long_log->printf("reply talk message %d, %d\n", talkMsgRecno, data_buf[sizeof(int)]);
  2354. #endif
  2355. talk_res.reply_talk_msg( talkMsgRecno, data_buf[sizeof(int)], COMMAND_REMOTE);
  2356. }
  2357. //####### end trevor 28/8 ########//
  2358. }
  2359. // ------- End of function RemoteMsg::reply_talk_msg -------//
  2360. // ------- Begin of function RemoteMsg::nation_contact -------//
  2361. void RemoteMsg::nation_contact()
  2362. {
  2363. err_when( id != MSG_NATION_CONTACT);
  2364. // packet structure : <player nation> <explored nation>
  2365. short *shortPtr = (short *)data_buf;
  2366. err_when( *shortPtr != remote.nation_processing );
  2367. if( !nation_array.is_deleted(*shortPtr) && !nation_array.is_deleted(shortPtr[1]) )
  2368. {
  2369. //####### begin trevor 30/8 #######//
  2370. #ifdef DEBUG
  2371. long_log->printf("nation %d discover nation %d\n", shortPtr[0], shortPtr[1]);
  2372. #endif
  2373. nation_array[shortPtr[0]]->establish_contact(shortPtr[1]);
  2374. //####### end trevor 30/8 #######//
  2375. }
  2376. }
  2377. // ------- End of function RemoteMsg::nation_contact -------//
  2378. // ------- Begin of function RemoteMsg::nation_set_should_attack -------//
  2379. void RemoteMsg::nation_set_should_attack()
  2380. {
  2381. err_when( id != MSG_NATION_SET_SHOULD_ATTACK );
  2382. // packet structure : <player nation> <target nation> <new value>
  2383. short *shortPtr = (short *)data_buf;
  2384. err_when( *shortPtr != remote.nation_processing );
  2385. if( !nation_array.is_deleted(*shortPtr) && !nation_array.is_deleted(shortPtr[1]) )
  2386. {
  2387. #ifdef DEBUG
  2388. long_log->printf("nation %d %s instruct attack nation %d\n", shortPtr[0],
  2389. shortPtr[2] ? "set":"clear", shortPtr[1]);
  2390. #endif
  2391. nation_array[shortPtr[0]]->set_relation_should_attack(shortPtr[1], (char)shortPtr[2], COMMAND_REMOTE);
  2392. }
  2393. }
  2394. // ------- End of function RemoteMsg::nation_set_should_attack -------//
  2395. // ------- Begin of function RemoteMsg::caravan_selected -------//
  2396. void RemoteMsg::caravan_selected()
  2397. {
  2398. err_when( id != MSG_U_CARA_SELECTED );
  2399. // packet structure : <sprite_recno>
  2400. short *shortPtr = (short *)data_buf;
  2401. short unitCount =1;
  2402. validate_selected_unit_array(shortPtr, unitCount);
  2403. if( unitCount <= 0)
  2404. return;
  2405. #ifdef DEBUG
  2406. Unit *unitPtr = unit_array[*shortPtr];
  2407. err_when( unitPtr->unit_id != UNIT_CARAVAN);
  2408. #endif
  2409. //------ help to check syn. for multiplayer ------//
  2410. #ifdef DEBUG
  2411. m.random(100);
  2412. #endif
  2413. unit_array.mp_add_selected_caravan(*shortPtr);
  2414. }
  2415. // ------- End of function RemoteMsg::caravan_selected -------//
  2416. // ------- Begin of function RemoteMsg::ship_selected -------//
  2417. void RemoteMsg::ship_selected()
  2418. {
  2419. err_when( id != MSG_U_SHIP_SELECTED );
  2420. // packet structure : <sprite_recno>
  2421. short *shortPtr = (short *)data_buf;
  2422. short unitCount =1;
  2423. validate_selected_unit_array(shortPtr, unitCount);
  2424. if(unitCount <= 0)
  2425. return;
  2426. #ifdef DEBUG
  2427. Unit *unitPtr = unit_array[*shortPtr];
  2428. err_when(unit_res[unitPtr->unit_id]->unit_class != UNIT_CLASS_SHIP || unitPtr->unit_id==UNIT_TRANSPORT);
  2429. #endif
  2430. //------ help to check syn. for multiplayer ------//
  2431. #ifdef DEBUG
  2432. m.random(100);
  2433. #endif
  2434. unit_array.mp_add_selected_ship(*shortPtr);
  2435. }
  2436. // ------- End of function RemoteMsg::ship_selected -------//
  2437. //##### begin trevor 30/9 #######//
  2438. //------- Begin of function RemoteMsg::chat -------//
  2439. //
  2440. // Packet structure : <to nation recno> <from nation recno> <char[CHAT_STR_LEN+1]>
  2441. //
  2442. void RemoteMsg::chat()
  2443. {
  2444. short *shortPtr = (short *)data_buf;
  2445. int toNationRecno = shortPtr[0];
  2446. int fromNationRecno = shortPtr[1];
  2447. #ifdef DEBUG
  2448. long_log->printf("nation %d send chat message to %d\n",
  2449. shortPtr[1], shortPtr[0]);
  2450. #endif
  2451. if( toNationRecno == nation_array.player_recno ||
  2452. (toNationRecno == 0 && fromNationRecno != nation_array.player_recno) ||
  2453. (toNationRecno == -1 && !nation_array.is_deleted(fromNationRecno) &&
  2454. nation_array[fromNationRecno]->is_allied_with_player) )
  2455. {
  2456. news_array.chat_msg( fromNationRecno, (char*)(shortPtr+2) );
  2457. }
  2458. }
  2459. //------- End of function RemoteMsg::chat -------//
  2460. //##### end trevor 30/9 #######//
  2461. //------- Begin of function RemoteMsg::compare_remote_object -------//
  2462. void RemoteMsg::compare_remote_object()
  2463. {
  2464. err_when( id < MSG_COMPARE_NATION || id > MSG_COMPARE_TALK );
  2465. // ###### patch begin Gilbert 20/1 #######//
  2466. if( (remote.sync_test_level & 2) && (remote.sync_test_level >= 0)
  2467. && crc_store.compare_remote(id, data_buf) )
  2468. {
  2469. remote.sync_test_level = ~remote.sync_test_level; // signal error encountered
  2470. if( sys.debug_session )
  2471. err.run( "Multiplayer Random Seed Sync Error." );
  2472. else
  2473. box.msg( "Multiplayer Random Seed Sync Error." );
  2474. }
  2475. // ###### patch end Gilbert 20/1 #######//
  2476. }
  2477. //------- End of function RemoteMsg::compare_remote_object -------//
  2478. //------- Begin of function RemoteMsg::unit_add_way_point -------//
  2479. void RemoteMsg::unit_add_way_point()
  2480. {
  2481. //### begin alex 16/10 ###//
  2482. err_when( id != MSG_UNIT_ADD_WAY_POINT);
  2483. short* shortPtr = (short*) data_buf;
  2484. validate_selected_unit_array(shortPtr+3, shortPtr[2]);
  2485. if( shortPtr[2] > 0)
  2486. {
  2487. #ifdef DEBUG
  2488. long_log->printf("add way point at (%d,%d)\n", shortPtr[0], shortPtr[1]);
  2489. for(int i = 0; i < shortPtr[2]; ++i)
  2490. {
  2491. long_log->printf("%d,", shortPtr[3+i]);
  2492. if( i % 20 == 19)
  2493. long_log->printf("\n");
  2494. }
  2495. long_log->printf("\n");
  2496. #endif
  2497. unit_array.add_way_point(shortPtr[0], shortPtr[1], shortPtr+3, shortPtr[2], COMMAND_REMOTE); // 1-remote action
  2498. }
  2499. //#### end alex 16/10 ####//
  2500. }
  2501. //------- End of function RemoteMsg::unit_add_way_point -------//
  2502. // ------- Begin of function RemoteMsg::god_cast -------//
  2503. void RemoteMsg::god_cast()
  2504. {
  2505. err_when( id != MSG_U_GOD_CAST );
  2506. // packet structure : <unit recno> <loc x> <loc y> <power type>
  2507. short *shortPtr = (short *)data_buf;
  2508. short unitCount =1;
  2509. validate_selected_unit_array(shortPtr, unitCount);
  2510. if(unitCount > 0)
  2511. {
  2512. Unit *unitPtr = unit_array[*shortPtr];
  2513. err_when(unit_res[unitPtr->unit_id]->unit_class != UNIT_CLASS_GOD);
  2514. #ifdef DEBUG
  2515. long_log->printf("god %d cast power %d at(%d,%d)\n", shortPtr[0], shortPtr[3],
  2516. shortPtr[1], shortPtr[2]);
  2517. #endif
  2518. unitPtr->go_cast_power(shortPtr[1], shortPtr[2], (char) shortPtr[3], COMMAND_REMOTE);
  2519. }
  2520. }
  2521. // ------- End of function RemoteMsg::god_cast -------//
  2522. // ------- Begin of function RemoteMsg::player_quit ---------//
  2523. void RemoteMsg::player_quit()
  2524. {
  2525. // to let other player know a player quit voluntarily, not by error condition
  2526. err_when( id != MSG_PLAYER_QUIT );
  2527. // packet structure : <nation recno> <retire flag>
  2528. short *shortPtr = (short *)data_buf;
  2529. if( shortPtr[1])
  2530. news_array.multi_retire(*shortPtr);
  2531. else
  2532. news_array.multi_quit_game(*shortPtr);
  2533. }
  2534. // ------- End of function RemoteMsg::player_quit ---------//