This repository was archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathCONQUER.CPP
4013 lines (3444 loc) · 134 KB
/
CONQUER.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Command & Conquer(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Header: F:\projects\c&c\vcs\code\conquer.cpv 2.18 16 Oct 1995 16:50:24 JOE_BOSTIC $ */
/***********************************************************************************************
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
***********************************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : CONQUER.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : April 3, 1991 *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* CC_Draw_Shape -- Custom draw shape handler. *
* Call_Back -- Main game maintenance callback routine. *
* Color_Cycle -- Handle the general palette color cycling. *
* Disk_Space_Available -- returns bytes of free disk space *
* Do_Record_Playback -- handles saving/loading map pos & current object *
* Fading_Table_Name -- Builds a theater specific fading table name. *
* Fetch_Techno_Type -- Convert type and ID into TechnoTypeClass pointer. *
* Force_CD_Available -- Ensures that specified CD is available. *
* Get_Radar_Icon -- Builds and alloc a radar icon from a shape file *
* Handle_Team -- Processes team selection command. *
* Handle_View -- Either records or restores the tactical view. *
* KN_To_Facing -- Converts a keyboard input number into a facing value. *
* Keyboard_Process -- Processes the tactical map input codes. *
* Language_Name -- Build filename for current language. *
* Main_Game -- Main game startup routine. *
* Main_Loop -- This is the main game loop (as a single loop). *
* Map_Edit_Loop -- a mini-main loop for map edit mode only *
* Message_Input -- allows inter-player message input processing *
* MixFileHandler -- Handles VQ file access. *
* Name_From_Source -- retrieves the name for the given SourceType *
* Play_Movie -- Plays a VQ movie. *
* Source_From_Name -- Converts ASCII name into SourceType. *
* Sync_Delay -- Forces the game into a 15 FPS rate. *
* Theater_From_Name -- Converts ASCII name into a theater number. *
* Trap_Object -- gets a ptr to object of given type & coord *
* Unselect_All -- Causes all selected objects to become unselected. *
* VQ_Call_Back -- Maintenance callback used for VQ movies. *
* Validate_Error -- prints an error message when an object fails validation *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
#include "tcpip.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <direct.h>
#include <fcntl.h>
#include <io.h>
#include <dos.h>
#include <share.h>
#include <malloc.h>
#include "ccdde.h"
#define SHAPE_TRANS 0x40
void *Get_Shape_Header_Data(void *ptr);
/****************************************
** Function prototypes for this module **
*****************************************/
bool Main_Loop();
void Keyboard_Process(KeyNumType & input);
#ifndef DEMO
static void Message_Input(KeyNumType &input);
#endif
static bool Color_Cycle(void);
bool Map_Edit_Loop(void);
void Trap_Object(void);
#ifdef CHEAT_KEYS
void Heap_Dump_Check( char *string );
void Dump_Heap_Pointers( void );
void Error_In_Heap_Pointers( char *string );
#endif
static void Do_Record_Playback(void);
extern void Register_Game_Start_Time(void);
extern void Register_Game_End_Time(void);
extern void Send_Statistics_Packet(void);
extern "C" {
extern char *__nheapbeg;
}
bool InMainLoop = false;
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#endif
/***********************************************************************************************
* Main_Game -- Main game startup routine. *
* *
* This is the first official routine of the game. It handles game initialization and *
* the main game loop control. *
* *
* Initialization: *
* - Init_Game handles one-time-only inits *
* - Select_Game is responsible for initializations required for each new game played *
* (these may be different depending on whether a multiplayer game is selected, and *
* other parameters) *
* - This routine performs any un-inits required, both for each game played, and one-time *
* *
* INPUT: argc -- Number of command line arguments (including program name itself). *
* *
* argv -- Array of command line argument pointers. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/01/1994 JLB : Created. *
*=============================================================================================*/
extern int TotalLocks;
extern bool Spawn_WChat(bool can_launch);
extern bool SpawnedFromWChat;
void Main_Game(int argc, char *argv[])
{
bool fade = false; // don't fade title screen the first time through
/*
** Perform one-time-only initializations
*/
if (!Init_Game(argc, argv)) {
return;
}
CCDebugString ("C&C95 - Game initialisation complete.\n");
/*
** Game processing loop:
** 1) Select which game to play, or whether to exit (don't fade the palette
** on the first game selection, but fade it in on subsequent calls)
** 2) Invoke either the main-loop routine, or the editor-loop routine,
** until they indicate that the user wants to exit the scenario.
*/
while (Select_Game(fade)) {
ScenarioInit = 0; // Kludge.
// Theme.Queue_Song(THEME_PICK_ANOTHER);
fade = true;
/*
** Make the game screen visible, clear the keyboard buffer of spurious
** values, and then show the mouse. This PRESUMES that Select_Game() has
** told the map to draw itself.
*/
Fade_Palette_To(GamePalette, FADE_PALETTE_MEDIUM, NULL);
Keyboard::Clear();
/*
** Only show the mouse if we're not playing back a recording.
*/
if (PlaybackGame) {
Hide_Mouse();
} else {
Show_Mouse();
}
SpecialDialog = SDLG_NONE;
//Start_Profiler();
if (GameToPlay == GAME_INTERNET){
Register_Game_Start_Time();
GameStatisticsPacketSent = false;
PacketLater = NULL;
ConnectionLost = false;
}else{
DDEServer.Disable();
}
InMainLoop = true;
#ifdef SCENARIO_EDITOR
/*
** Scenario-editor version of main-loop processing
*/
for (;;) {
/*
** Non-scenario-editor-mode: call the game's main loop
*/
if (!Debug_Map) {
TotalLocks=0;
if (Main_Loop()) {
break;
}
if (SpecialDialog != SDLG_NONE) {
//Stop_Profiler();
switch (SpecialDialog) {
case SDLG_SPECIAL:
Map.Help_Text(TXT_NONE);
Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
Special_Dialog();
Map.Revert_Mouse_Shape();
SpecialDialog = SDLG_NONE;
break;
case SDLG_OPTIONS:
Map.Help_Text(TXT_NONE);
Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
Options.Process();
Map.Revert_Mouse_Shape();
SpecialDialog = SDLG_NONE;
break;
case SDLG_SURRENDER:
Map.Help_Text(TXT_NONE);
Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
if (Surrender_Dialog()) {
OutList.Add(EventClass(EventClass::DESTRUCT));
}
SpecialDialog = SDLG_NONE;
Map.Revert_Mouse_Shape();
break;
default:
break;
}
}
} else {
/*
** Scenario-editor-mode: call the editor's main loop
*/
if (Map_Edit_Loop()) {
break;
}
}
}
#else
/*
** Non-editor version of main-loop processing
*/
for (;;) {
/*
** Call the game's main loop
*/
TotalLocks=0;
if (Main_Loop()) {
break;
}
/*
** If the SpecialDialog flag is set, invoke the given special dialog.
** This must be done outside the main loop, since the dialog will call
** Main_Loop(), allowing the game to run in the background.
*/
if (SpecialDialog != SDLG_NONE) {
//Stop_Profiler();
switch (SpecialDialog) {
case SDLG_SPECIAL:
Map.Help_Text(TXT_NONE);
Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
Special_Dialog();
Map.Revert_Mouse_Shape();
SpecialDialog = SDLG_NONE;
break;
case SDLG_OPTIONS:
Map.Help_Text(TXT_NONE);
Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
Options.Process();
Map.Revert_Mouse_Shape();
SpecialDialog = SDLG_NONE;
break;
case SDLG_SURRENDER:
Map.Help_Text(TXT_NONE);
Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
if (Surrender_Dialog()) {
OutList.Add(EventClass(EventClass::DESTRUCT));
}
SpecialDialog = SDLG_NONE;
Map.Revert_Mouse_Shape();
break;
default:
break;
}
}
}
#endif
//Stop_Profiler();
InMainLoop = false;
if (!GameStatisticsPacketSent && PacketLater){
Send_Statistics_Packet();
}
/*
** Scenario is done; fade palette to black
*/
Fade_Palette_To(BlackPalette, FADE_PALETTE_SLOW, NULL);
VisiblePage.Clear();
#ifndef DEMO
/*
** Un-initialize whatever needs it, for each game played.
**
** Shut down either the modem or network; they'll get re-initialized if
** the user selections those options again in Select_Game(). This
** "re-boots" the modem & network code, which I currently feel is safer
** than just letting it hang around.
** (Skip this step if we're in playback mode; the modem or net won't have
** been initialized in that case.)
*/
if ( (RecordGame && !SuperRecord) || PlaybackGame) {
RecordFile.Close();
}
if (!PlaybackGame){
switch (GameToPlay){
case GAME_NULL_MODEM:
case GAME_MODEM:
Modem_Signoff();
break;
case GAME_IPX:
Shutdown_Network();
break;
case GAME_INTERNET:
//Winsock.Close();
break;
}
}
/*
** If we're playing back, the mouse will be hidden; show it.
** Also, set all variables back to normal, to return to the main menu.
*/
if (PlaybackGame) {
Show_Mouse();
GameToPlay = GAME_NORMAL;
PlaybackGame = 0;
}
/*
** If we were spawned from WChat then dont go back to the main menu - just quit
**
** New: If spawned from WChat then maximise WChat and go back to the main menu after all
*/
#ifdef FORCE_WINSOCK
if (Special.IsFromWChat){
Shutdown_Network(); // Clear up the pseudo IPX stuff
Winsock.Close();
Special.IsFromWChat = false;
SpawnedFromWChat = false;
DDEServer.Delete_MPlayer_Game_Info(); //Make sure we dont use the same start packet twice
GameToPlay = GAME_NORMAL; //Have to do this or we will got straight to the multiplayer menu
Spawn_WChat(false); //Will switch back to Wchat. It must be there because its been poking us
//break;
}
#endif //FORCE_WINSOCK
#endif //DEMO
}
#ifdef DEMO
Hide_Mouse();
Fade_Palette_To(BlackPalette, FADE_PALETTE_MEDIUM, NULL);
Load_Title_Screen("DEMOPIC.PCX", &HidPage, Palette);
HidPage.Blit(SeenBuff);
Fade_Palette_To(Palette, FADE_PALETTE_MEDIUM, NULL);
Clear_KeyBuffer();
Get_Key();
Fade_Palette_To(BlackPalette, FADE_PALETTE_MEDIUM, NULL);
// Show_Mouse();
#else
/*
** Free the scenario description buffers
*/
Free_Scenario_Descriptions();
#endif
#ifndef NOMEMCHECK
Uninit_Game();
#endif
}
/***********************************************************************************************
* Keyboard_Process -- Processes the tactical map input codes. *
* *
* This routine is used to process the input codes while the player *
* has the tactical map displayed. It handles all the keys that *
* are appropriate to that mode. *
* *
* INPUT: input -- Input code as returned from Input_Num(). *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/21/1992 JLB : Created. *
* 07/04/1995 JLB : Handles team and map control hotkeys. *
*=============================================================================================*/
extern int DebugColour;
void Keyboard_Process(KeyNumType &input)
{
ObjectClass * obj;
int index;
/*
** Don't do anything if there is not keyboard event.
*/
if (input == KN_NONE) {
return;
}
#ifndef DEMO
/*
** For network & modem, process user input for inter-player messages.
*/
Message_Input(input);
#endif
/*
** Use WWKEY values because KN values have WWKEY_VK_BIT or'd in with them
** and we need WWKEY_VK_BIT to still be set if it is.
*/
KeyNumType plain = input & ~(WWKEY_SHIFT_BIT|WWKEY_ALT_BIT|WWKEY_CTRL_BIT);
#ifdef CHEAT_KEYS
if (Debug_Flag) {
switch (input) {
case (int)KN_M|(int)KN_SHIFT_BIT:
case (int)KN_M|(int)KN_ALT_BIT:
case (int)KN_M|(int)KN_CTRL_BIT:
PlayerPtr->Credits += 10000;
break;
default:
break;
}
}
#endif
#ifdef VIRGIN_CHEAT_KEYS
if (Debug_Playtest && input == (KN_W|KN_ALT_BIT)) {
PlayerPtr->Blockage = false;
PlayerPtr->Flag_To_Win();
}
#endif
//#ifdef CHEAT_KEYS
if (/*Debug_Playtest && */input == (KN_W|KN_ALT_BIT)) {
PlayerPtr->Blockage = false;
PlayerPtr->Flag_To_Win();
}
if (Debug_Flag && input == KN_SLASH) {
if (GameToPlay != GAME_NORMAL) {
SpecialDialog = SDLG_SPECIAL;
input = KN_NONE;
} else {
Special_Dialog();
}
}
//#endif
/*
** If the options key(s) were pressed, then bring up the options screen.
*/
if (input == KN_SPACE || input == KN_ESC) {
Map.Help_Text(TXT_NONE); // Turns off help text.
Queue_Options();
input = KN_NONE;
//DebugColour++;
//DebugColour &=7;
}
/*
** Process prerecorded team selection. This will be an addative select
** if the SHIFT key is held down. It will create the team if the
** CTRL or ALT key is held down.
*/
int action = 0;
if (input & WWKEY_SHIFT_BIT) action = 1;
if (input & WWKEY_ALT_BIT) action = 3;
if (input & WWKEY_CTRL_BIT) action = 2;
switch (KN_To_VK(plain)) {
/*
** Center the map around the currently selected objects. If no
** objects are selected, then fall into the home case.
*/
case VK_HOME:
if (CurrentObject.Count()) {
Map.Center_Map();
Map.Flag_To_Redraw(true);
break;
}
// Fall into next case.
/*
** Center the map about the construction yard or construction vehicle
** if one is present.
*/
case VK_H:
for (index = 0; index < Units.Count(); index++) {
UnitClass * unit = Units.Ptr(index);
if (unit && !unit->IsInLimbo && unit->House == PlayerPtr && *unit == UNIT_MCV) {
Unselect_All();
unit->Select();
break;
}
}
for (index = 0; index < Buildings.Count(); index++) {
BuildingClass * building = Buildings.Ptr(index);
if (building && !building->IsInLimbo && building->House == PlayerPtr && *building == STRUCT_CONST) {
Unselect_All();
building->Select();
break;
}
}
Map.Center_Map();
Map.Flag_To_Redraw(true);
break;
#ifdef CHEAT_KEYS
/*
** Toggle free scrolling mode.
*/
case VK_F:
Options.IsFreeScroll = (Options.IsFreeScroll == false);
break;
#endif
/*
** If the "N" key is pressed, then select the next object.
*/
case VK_N:
if (action) {
obj = Map.Prev_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
} else {
obj = Map.Next_Object(CurrentObject.Count() ? CurrentObject[0] : NULL);
}
if (obj) {
Unselect_All();
obj->Select();
Map.Center_Map();
Map.Flag_To_Redraw(true);
}
break;
/*
** For multiplayer, 'R' pops up the surrender dialog.
*/
case VK_R:
if (/*GameToPlay != GAME_NORMAL &&*/ !PlayerPtr->IsDefeated) {
SpecialDialog = SDLG_SURRENDER;
input = KN_NONE;
}
break;
/*
** Handle making and breaking alliances.
*/
case VK_A:
if (GameToPlay != GAME_NORMAL || Debug_Flag) {
if (CurrentObject.Count() && !PlayerPtr->IsDefeated) {
if (CurrentObject[0]->Owner() != PlayerPtr->Class->House) {
OutList.Add(EventClass(EventClass::ALLY, CurrentObject[0]->Owner()));
}
}
}
break;
/*
** Control the remembered tactical location.
*/
case VK_F7:
case VK_F8:
case VK_F9:
case VK_F10:
if (!Debug_Map) {
Handle_View(KN_To_VK(plain) - VK_F7, action);
}
break;
#if (0)
case VK_F11:
Winsock.Set_Protocol_UDP(FALSE);
break;
case VK_F12:
Winsock.Set_Protocol_UDP(TRUE);
break;
#endif //(0)
/*
** Control the custom team select state.
*/
case VK_1:
case VK_2:
case VK_3:
case VK_4:
case VK_5:
case VK_6:
case VK_7:
case VK_8:
case VK_9:
case VK_0:
Handle_Team(KN_To_VK(plain) - VK_1, action);
break;
/*
** All selected units will go into idle mode.
*/
case VK_S:
if (CurrentObject.Count()) {
for (int index = 0; index < CurrentObject.Count(); index++) {
ObjectClass const * tech = CurrentObject[index];
if (tech && (tech->Can_Player_Move() || (tech->Can_Player_Fire() &&
tech->What_Am_I() != RTTI_BUILDING))) {
OutList.Add(EventClass(EventClass::IDLE, tech->As_Target()));
}
}
}
break;
/*
** All selected units will attempt to scatter.
*/
case VK_X:
if (CurrentObject.Count()) {
for (int index = 0; index < CurrentObject.Count(); index++) {
ObjectClass const * tech = CurrentObject[index];
if (tech && tech->Can_Player_Move()) {
OutList.Add(EventClass(EventClass::SCATTER, tech->As_Target()));
}
}
}
break;
/*
** All selected units will attempt to go into guard area mode.
*/
case VK_G:
if (CurrentObject.Count()) {
for (int index = 0; index < CurrentObject.Count(); index++) {
ObjectClass const * tech = CurrentObject[index];
if (tech && tech->Can_Player_Move() && tech->Can_Player_Fire()) {
OutList.Add(EventClass(tech->As_Target(), MISSION_GUARD_AREA));
}
}
}
break;
default:
break;
}
#ifdef NEVER
FacingType facing = KN_To_Facing(input);
/*
** Scroll the map according to the cursor key pressed.
*/
if (facing != FACING_NONE) {
Map.Scroll_Map(facing);
input = 0;
facing = FACING_NONE;
}
#endif
#ifdef NEVER
/*
** If the <TAB> key is pressed, then select the next object.
*/
if (input == KN_TAB) {
ObjectClass * obj = Map.Next_Object(CurrentObject);
if (obj) {
if (CurrentObject) {
CurrentObject->Unselect();
}
obj->Select();
}
}
#endif
#ifdef CHEAT_KEYS
if (Debug_Flag && input && (input & KN_RLSE_BIT) == 0) {
Debug_Key(input);
}
#endif
}
#ifndef DEMO
/***********************************************************************************************
* Message_Input -- allows inter-player message input processing *
* *
* INPUT: *
* input key value *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* MAX_MESSAGE_LENGTH has increased over the DOS version. COMPAT_MESSAGE_LENGTH reflects * *
* the length of the DOS message and also the length of the message in the packet header. *
* To allow transmission of longer messages I split the message into COMPAT_MESSAGE_LENGTH-4 *
* sized chunks and use the extra space after the zero terminator to specify which segment *
* of the whole message this is and also to supply a crc for the string. *
* This allows message segments to arrive out of order and still be displayed correctly. *
* *
* HISTORY: *
* 05/22/1995 BRR : Created. *
* 03/26/1995 ST : Modified to break up longer messages into multiple packets *
*=============================================================================================*/
static void Message_Input(KeyNumType &input)
{
int rc;
char txt[MAX_MESSAGE_LENGTH+12];
int id;
SerialPacketType *serial_packet;
int i;
int message_length;
int sent_so_far;
unsigned short magic_number;
unsigned short crc;
int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
/*
** Check keyboard input for a request to send a message.
** The 'to' argument for Add_Edit is prefixed to the message buffer; the
** message buffer is big enough for the 'to' field plus MAX_MESSAGE_LENGTH.
** To send the message, calling Get_Edit_Buf retrieves the buffer minus the
** 'to' portion. At the other end, the buffer allocated to display the
** message must be MAX_MESSAGE_LENGTH plus the size of "From: xxx (house)".
*/
if (input >= KN_F1 && input < (KN_F1 + MPlayerMax) &&
Messages.Get_Edit_Buf()==NULL) {
memset (txt, 0, 40);
/*
** For a serial game, send a message on F1 or F4; set 'txt' to the
** "Message:" string & add an editable message to the list.
*/
if (GameToPlay==GAME_NULL_MODEM
|| GameToPlay==GAME_MODEM){
//|| GameToPlay == GAME_INTERNET) {
if (input==KN_F1 || input==(KN_F1 + MPlayerMax - 1)) {
strcpy(txt,Text_String(TXT_MESSAGE)); // "Message:"
Messages.Add_Edit (MPlayerTColors[MPlayerColorIdx],
TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 180*factor);
Map.Flag_To_Redraw(false);
}
} else {
/*
** For a network game:
** F1-F3 = "To <name> (house):" (only allowed if we're not in ObiWan mode)
** F4 = "To All:"
*/
if (GameToPlay == GAME_IPX || GameToPlay == GAME_INTERNET) {
if (input==(KN_F1 + MPlayerMax - 1) && Messages.Get_Edit_Buf()==NULL) {
MessageAddress = IPXAddressClass(); // set to broadcast
strcpy(txt,Text_String(TXT_TO_ALL)); // "To All:"
Messages.Add_Edit(MPlayerTColors[MPlayerColorIdx],
TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 180*factor);
Map.Flag_To_Redraw(false);
} else {
if (Messages.Get_Edit_Buf()==NULL) {
if ((input - KN_F1) < Ipx.Num_Connections() && !MPlayerObiWan) {
id = Ipx.Connection_ID(input - KN_F1);
MessageAddress = (*(Ipx.Connection_Address (id)));
sprintf(txt,Text_String(TXT_TO),Ipx.Connection_Name(id));
Messages.Add_Edit(MPlayerTColors[MPlayerColorIdx],
TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, 180*factor);
Map.Flag_To_Redraw(false);
}
}
}
}
}
}
/*
** Function key input is meaningless beyond this point
*/
if (input >= KN_F1 && input <= KN_F10) return;
if (input >= KN_F11 && input <= KN_F12) return;
/*
** Process message-system input; send the message out if RETURN is hit.
*/
rc = Messages.Input(input);
/*
** If a single character has been added to an edit buffer, update the display.
*/
if (rc == 1) {
Map.Flag_To_Redraw(false);
}
/*
** If backspace was hit, redraw the map. This assumes the map is going to
** completely refresh all cells covered by the messages. Set DisplayClass's
** IsToRedraw to true to tell it to re-compute the cells that it needs to
** redraw.
*/
if (rc==2) {
Map.Flag_To_Redraw(false);
Map.DisplayClass::IsToRedraw = true;
}
/*
** Send a message
*/
if (rc==3) {
/*.....................................................................
Store this message in our LastMessage buffer; the computer may send
us a version of it later.
.....................................................................*/
if (strlen(Messages.Get_Edit_Buf())) {
strcpy(LastMessage,Messages.Get_Edit_Buf());
}
message_length = strlen(Messages.Get_Edit_Buf());
long actual_message_size;
char *the_string;
/*
** Serial game: fill in a SerialPacketType & send it.
** (Note: The size of the SerialPacketType.Command must be the same as
** the EventClass.Type!)
*/
if (GameToPlay==GAME_NULL_MODEM
|| GameToPlay==GAME_MODEM){
//|| GameToPlay==GAME_INTERNET) {
sent_so_far = 0;
magic_number = MESSAGE_HEAD_MAGIC_NUMBER;
crc = (unsigned short) (Calculate_CRC(Messages.Get_Edit_Buf(), message_length) & 0xffff);
while (sent_so_far < message_length){
serial_packet = (SerialPacketType *)NullModem.BuildBuf;
serial_packet->Command = SERIAL_MESSAGE;
strcpy (serial_packet->Name, MPlayerName);
memcpy (serial_packet->Message, Messages.Get_Edit_Buf()+sent_so_far, COMPAT_MESSAGE_LENGTH-5);
/*
** Steve I's stuff for splitting message on word boundries
*/
actual_message_size = COMPAT_MESSAGE_LENGTH - 5;
/* Start at the end of the message and find a space with 10 chars. */
the_string = serial_packet->Message;
while ( (COMPAT_MESSAGE_LENGTH -5) -actual_message_size < 10 &&
the_string[actual_message_size] != ' '){
--actual_message_size;
}
if ( the_string[actual_message_size] == ' ' ){
/* Now delete the extra characters after the space (they musnt print) */
for ( int i=0 ; i< (COMPAT_MESSAGE_LENGTH-5) - actual_message_size; i++ ){
the_string[i + actual_message_size] = 0xff;
}
}else{
actual_message_size = COMPAT_MESSAGE_LENGTH - 5;
}
*(serial_packet->Message + COMPAT_MESSAGE_LENGTH-5) = 0;
/*
** Flag this message segment as either a message head or a message tail.
*/
*((unsigned short*)(serial_packet->Message + COMPAT_MESSAGE_LENGTH-4)) = magic_number;
*((unsigned short*)(serial_packet->Message + COMPAT_MESSAGE_LENGTH-2)) = crc;
serial_packet->ID = MPlayerLocalID;
NullModem.Send_Message(NullModem.BuildBuf, sizeof(SerialPacketType), 1);
magic_number++;
sent_so_far += actual_message_size; //COMPAT_MESSAGE_LENGTH-5;
}
} else {
/*
** Network game: fill in a GlobalPacketType & send it.
*/
if (GameToPlay == GAME_IPX || GameToPlay == GAME_INTERNET) {
sent_so_far = 0;
magic_number = MESSAGE_HEAD_MAGIC_NUMBER;
crc = (unsigned short) (Calculate_CRC(Messages.Get_Edit_Buf(), message_length) & 0xffff);
while (sent_so_far < message_length){
GPacket.Command = NET_MESSAGE;
strcpy (GPacket.Name, MPlayerName);
memcpy (GPacket.Message.Buf, Messages.Get_Edit_Buf()+sent_so_far, COMPAT_MESSAGE_LENGTH-5);
/*
** Steve I's stuff for splitting message on word boundries
*/
actual_message_size = COMPAT_MESSAGE_LENGTH - 5;
/* Start at the end of the message and find a space with 10 chars. */
the_string = GPacket.Message.Buf;
while ( (COMPAT_MESSAGE_LENGTH -5) -actual_message_size < 10 &&
the_string[actual_message_size] != ' '){
--actual_message_size;
}
if ( the_string[actual_message_size] == ' ' ){
/* Now delete the extra characters after the space (they musnt print) */
for ( int i=0 ; i< (COMPAT_MESSAGE_LENGTH-5) - actual_message_size; i++ ){
the_string[i + actual_message_size] = 0xff;
}
}else{
actual_message_size = COMPAT_MESSAGE_LENGTH - 5;
}
*(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-5) = 0;
/*
** Flag this message segment as either a message head or a message tail.
*/
*((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-4)) = magic_number;
*((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-2)) = crc;
GPacket.Message.ID = MPlayerLocalID;
GPacket.Message.NameCRC = Compute_Name_CRC(MPlayerGameName);
/*
** If 'F4' was hit, MessageAddress will be a broadcast address; send
** the message to every player we have a connection with.
*/
if (MessageAddress.Is_Broadcast()) {
for (i = 0; i < Ipx.Num_Connections(); i++) {
Ipx.Send_Global_Message(&GPacket, sizeof(GlobalPacketType), 1,
Ipx.Connection_Address(Ipx.Connection_ID(i)));
Ipx.Service();
}
} else {
/*
** Otherwise, MessageAddress contains the exact address to send to.
** Send to that address only.
*/
Ipx.Send_Global_Message(&GPacket, sizeof(GlobalPacketType), 1,
&MessageAddress);
Ipx.Service();
}
magic_number++;
sent_so_far += actual_message_size; //COMPAT_MESSAGE_LENGTH-5;