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