-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
1205 lines (1072 loc) · 32.2 KB
/
main.c
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
/*
Copyright (C) 2005 Michael K. McCarty & Fritz Bronner
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//****************************************************************
//*Interplay's BUZZ ALDRIN's RACE into SPACE *
//* *
//*Formerly -=> LiftOff : Race to the Moon :: IBM version MCGA *
//*Copyright 1991 by Strategic Visions, Inc. *
//*Designed by Fritz Bronner *
//*Programmed by Michael K McCarty *
//* *
//****************************************************************
#include <Buzz_inc.h>
#include <options.h>
#include <utils.h>
#include <logging.h>
#include <externs.h>
#include <ctype.h>
#ifdef CONFIG_MACOSX
// SDL.h needs to be included here to replace the original main() with
// what it needs for the Mac
#include <SDL.h>
#endif
int cdROM,hDISK;
char Name[20];
struct Players *Data;
int x,y,mousebuttons,key,oldx,oldy;
unsigned char LOAD,QUIT,HARD1,UNIT1,BUTLOAD,FADE,AL_CALL,XMAS;
char plr[NUM_PLAYERS],IDT[5],IKEY[5],df,IDLE[2];
char *buffer;
GXHEADER vhptr,vhptr2;
char * oldpal,pNeg[NUM_PLAYERS][MAX_MISSIONS];
long xMODE;
HTIMER server;
char Option=-1,MAIL=-1;
int SEG=15,FadeVal,fOFF=-1;
extern struct mStr Mis;
extern struct Prest_Upd MP[3];
struct cdtable *cdt;
long PalOff;
ui16 LetHand;
char BIG, /**< 1 for fullscreen mission playback, 0 otherwise */
manOnMoon=0, dayOnMoon=20;
char *S_Name[] = {
"LAUNCH",
"ORBITAL INS. BURN",
"HARDWARE POWER-ON",
"REENTRY",
"RECOVERY/LANDING",
"EARTH ORBITAL ACTIVITIES",
"EARTH DE-ORBIT BURN",
"ORBITAL EVA",
"DOCKING",
"TRANS-LUNAR INJECTION",
"TRANS-EARTH INJECTION",
"LUNAR ORBITAL INS. BURN",
"LUNAR ORBITAL ACTIVITIES",
"EARTH MID-COURSE ACT.",
"LUNAR MID-COURSE ACT.",
"LUNAR EVA",
"LEM ACTIVITIES",
"LUNAR DE-ORBIT BURN",
"LUNAR LANDING",
"LUNAR LIFTOFF",
"PHOTO RECONNAISSANCE",
"PLANET ORBIT BURN",
"PLANETARY ACTIVITIES",
"EARTH RENDEZVOUS",
"LUNAR RENDEZVOUS",
"TRANS-PLANETARY INJ.",
"LEM THRUST TEST",
"DURATION",
"JOINT DURATION",
"REENTRY CORRIDOR",
"MID-COURSE CORR. BURN",
"MID-COURSE CORR. BURN",
"EARTH ORBITAL INS. BURN"
};
#define BSOUND 1
#define HOST 0
#define SLAVE 1
#define MODEM_ERROR 4
extern struct order Order[6];
extern struct ManPool *Men;
char AI[2]={0,0};
#ifdef DEAD_CODE
static char BUZZ_DIR[32];
void Plop(char plr,char mode);
#endif
LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT)
int main(int argc, char *argv[])
{
int i;
FILE *fin;
const char * see_readme = "look for further instructions in the README file";
char AName[6][22]={"NEW GAME","OLD GAME","MODEM","PLAY BY MAIL","CREDITS","EXIT TO DOS"};
char ex;
argc = setup_options(argc, argv);
/* hacking... */
log_setThreshold(&_LOGV(LOG_ROOT_CAT), maxx(0, LP_NOTICE-(int)options.want_debug));
fin = open_gamedat("USA_PORT.DAT");
if (fin == NULL)
{
CRITICAL1("can't find game data files");
NOTICE1("set environment variable BARIS_DATA or edit config file");
NOTICE2("%s", see_readme);
exit(EXIT_FAILURE);
}
fclose(fin);
if (create_save_dir() != 0)
{
CRITICAL3("can't create save directory `%s': %s",
options.dir_savegame, strerror(errno));
NOTICE1("set environment variable BARIS_SAVE to a writable directory");
NOTICE2("%s", see_readme);
exit(EXIT_FAILURE);
}
av_setup();
strcpy(IDT,"i000\0"); strcpy(IKEY,"k000\0");
LOAD=QUIT=0;
xMODE=0;
xMODE|=xMODE_NOCOPRO;
Data = xmalloc(sizeof (struct Players) + 1);
buffer = xmalloc(BUFFER_SIZE);
DEBUG3("main buffer %p (%d)", buffer, BUFFER_SIZE);
memset(buffer,0x00,BUFFER_SIZE);
OpenEmUp(); // OPEN SCREEN AND SETUP GOODIES
if (options.want_intro)
Introd();
ex=0;
while(ex==0) {
MakeRecords();
fin=sOpen("RAST.DAT","rb",0);
i=fread(buffer,1,BUFFER_SIZE,fin);
fclose(fin);
DEBUG2("reading Players: size = %d", (int)sizeof (struct Players));
RLED(buffer,(char *)Data,i);
SwapGameDat(); // Take care of endian read
if (Data->Checksum!=(sizeof (struct Players))) {
/* XXX: too drastic */
CRITICAL1("wrong version of data file");
exit(EXIT_FAILURE);
}
gxClearDisplay(0,0);
PortPal(0);
key=0;strcpy(IDT,"i000\0");strcpy(IKEY,"i000\0");
df=1;
tommy:
music_start(M_LIFTOFF);
i=99;
while (i == 99)
{
i=MChoice(6,(char *)AName);
if (i==98) goto tommy;
IDLE[0]=IDLE[1]=0;
if (i==99) {Introd();PortPal(0);}
}
switch(i) {
case 1: // New Game
LOAD=QUIT=0,BUTLOAD=0;
HARD1=UNIT1=1;
MAIL=-1;Option=-1;
strcpy(IDT,"i013");
Prefs(0); // GET INITIAL PREFS FROM PLAYER
plr[0]=Data->Def.Plr1; // SET GLOBAL PLAYER VALUES
plr[1]=Data->Def.Plr2;
Data->plr[0]=Data->Def.Plr1; // SET STRUCTURE PLAYER VALUES
Data->plr[1]=Data->Def.Plr2;
if (plr[0]==2 || plr[0]==3) AI[0]=1;
else AI[0]=0;
if (plr[1]==2 || plr[1]==3) AI[1]=1;
else AI[1]=0;
InitData(); // PICK EVENT CARDS N STUFF
MainLoop(); // PLAY GAME
gxClearDisplay(0,0);
break;
case 2: // Play Old Game
LOAD=QUIT=BUTLOAD=0;
HARD1=UNIT1=1;
MAIL=-1;Option=-1;
FileAccess(1);
if (LOAD==1)
{
if (Option==-1 && MAIL==-1) MainLoop(); //Regular game
else { //Modem game
WARNING1("can't do modem games");
break;
}
}
else if (!QUIT) FadeOut(2,pal,10,0,0);
QUIT=0;
gxClearDisplay(0,0);
break;
case 3:
break;
case 4:
break;
case 5:
df=0;
Credits();
df=1;
break;
case 6:
//KillMusic();
ex=1;
FadeOut(2,pal,10,0,0);
break;
}
}
CloseEmUp(0,0); // Normal Exit
exit(EXIT_SUCCESS);
}
/** utility fn for AI to see if it should scrub the mission
*
* Rules are:
* - always do unmanned missions
* - Safety must be within 15 of R&D-Safety
*
* \param plr Playerdata
* \param launchIdx ID of the launch
*/
int CheckIfMissionGo(char plr,char launchIdx)
{
char idx,mcode;
struct MissionType *pMission;
Equipment *E = NULL; /* Pointer to Equipment we're looking at */
// Grab the Mission Code from the current Launch Index
mcode=Data->P[plr].Mission[launchIdx].MissionCode;
pMission=&Data->P[plr].Mission[launchIdx];
// Always a go for Unmanned missions
/** \todo introduce mission attribute "manned vs. unmanned" */
if (mcode==1 || mcode==3 || mcode==5 || (mcode>=7 && mcode<=13) || mcode==15)
return 1;
// Spin through mission hardware checking safety
for (idx = Mission_Capsule; idx <= Mission_PrimaryBooster; idx++) {
switch(idx) {
case Mission_Capsule:
E=&Data->P[plr].Manned[pMission->Hard[idx]];
E->MisSaf=E->Safety;
break;
case Mission_Kicker:
E=&Data->P[plr].Misc[pMission->Hard[idx]];
E->MisSaf=E->Safety;
break;
case Mission_LM:
E=&Data->P[plr].Manned[pMission->Hard[idx]];
E->MisSaf=E->Safety;
break;
case Mission_PrimaryBooster:
E=&Data->P[plr].Manned[pMission->Hard[idx%4]]; // YYY No idea why this is using this value
// YYY Safety check for this is never reached
if (idx>Mission_PrimaryBooster) // implies
E->MisSaf = (int) RocketBoosterSafety(E->Safety, Data->P[plr].Manned[pMission->Hard[Mission_PrimaryBooster]].Safety);
break;
}
if (E && idx != Mission_Probe_DM && pMission->Hard[idx]>=0)
{
// If mission Safety is not within 15 points of the MaxRD then NO Go
if (E->MisSaf < (E->MaxRD-15))
return 0;
}
}
return 1;
}
void InitData(void)
{
int i,j;
SetEvents(); // RESET EVENT CARDS
Data->Count=0; // SET EVENT COUNTER TO ZERO
for(j=0;j<NUM_PLAYERS;j++)
for(i=0;i<5;i++)
Data->P[j].PresRev[i]=8;
return;
}
void MainLoop(void)
{
int i,j,t1,t2,t3,prest,sign,kik;
if (LOAD!=1) {
Data->P[0].Cash=Data->P[0].Budget; // INCREMENT BY BUDGET
Data->P[1].Cash=Data->P[1].Budget;
}
restart: // ON A LOAD PROG JUMPS TO HERE
LOAD=0; // CLEAR LOAD FLAG
while (Data->Year < 78) // WHILE THE YEAR IS NOT 1977
{
EndOfTurnSave((char *) Data, sizeof ( struct Players));
Data->P[0].RDMods=0; // CLEAR ALL TURN RD MODS
Data->P[1].RDMods=0;
Data->P[0].BudgetHistory[Data->Year-53]=Data->P[0].Budget; // RECORD BUDGET
Data->P[1].BudgetHistory[Data->Year-53]=Data->P[1].Budget;
Data->P[0].BudgetHistoryF[Data->Year-53]= // MAKE ESTIMATE OF BUDGETS
(Data->P[0].Budget*(random(40)+80))/100;
Data->P[1].BudgetHistoryF[Data->Year-53]=
(Data->P[1].Budget*(random(40)+80))/100;
for(t1=0;t1<NUM_PLAYERS;t1++) // Move Expenditures down one
{
for(t2=4;t2>=0;t2--)
for(t3=0;t3<4;t3++)
Data->P[t1].Spend[t2][t3]=Data->P[t1].Spend[t2-1][t3];
for(t3=0;t3<4;t3++)
Data->P[t1].Spend[0][t3]=0;
};
if(Data->Season==0) CalcPresRev();
for (i=0;i<NUM_PLAYERS;i++) {
xMODE&= ~xMODE_CLOUDS; // reset clouds for spaceport
if (Data->Season==1) {
IntelPhase(plr[i]-2*AI[i],0);
}
// computer vs. human
if ((IDLE[0]>12 || IDLE[1]>12) || ((AI[i] && plr[other(i)]<NUM_PLAYERS && ((Data->Def.Lev1!=0 && other(i)==0) || (Data->Def.Lev2!=0 && other(i)==1)))))
{
if (IDLE[0]>12 || IDLE[1]>12 || Data->P[abs(i-1)].PresRev[0]>=16)
{
strncpy(IDT,"i136",4);
Data->P[abs(i-1)].PresRev[0]=0x7F;
strncpy(IDT,"i000",4);
if (IDLE[0]>12 || IDLE[1]>12) SpecialEnd();
else {
Review(abs(i-1));
FakeWin(plr[i]-2);
}
FadeOut(2,pal,10,0,0);
QUIT=1;
return;
}
};
if (!AI[i]) {
NextTurn(plr[i]);
VerifySF(plr[i]);
News(plr[i]); // EVENT FOR PLAYER
if ((Data->P[plr[i] % NUM_PLAYERS].Mission[0].MissionCode>6 ||
Data->P[plr[i] % NUM_PLAYERS].Mission[1].MissionCode>6 ||
Data->P[plr[i] % NUM_PLAYERS].Mission[2].MissionCode>6) &&
(NOCOPRO && !PUSSY ))
xMODE &= ~xMODE_NOCOPRO;
VerifyCrews(plr[i]);
VerifySF(plr[i]);
strncpy(IDT,"i000",4);strncpy(IKEY,"k000",4);
FixPrograms(plr[i]);
//soften sound
// SetVoiceVolume(80); // 80% seems good MWR
Master(plr[i]); // PLAY TURN
//restore sound
// SetVoiceVolume(115);
gxClearDisplay(0,0);
IDLE[plr[i]]++;
if (LOAD==1) goto restart; // TEST FOR LOAD
} else {
AI_Begin(plr[i]-2); // Turns off Mouse for AI
GetMouse();
VerifySF(plr[i]-2);
AIEvent(plr[i]-2);VerifySF(plr[i]-2);
AIMaster(plr[i]-2);
AI_Done(); // Fade Out AI Thinking Screen and Restores Mouse
};
Data->Count++;
if (QUIT) return;
};
DockingKludge(); // fixup for both sides
// Do Missions Here
kik=OrderMissions();
for (i = 0; i < kik; i++)
if (Data->P[Order[i].plr].Mission[Order[i].loc].MissionCode != 0)
{
if (AI[Order[i].plr] == 1)
{
if (!CheckIfMissionGo(Order[i].plr, Order[i].loc))
ClrMiss(Order[i].plr, Order[i].loc);
}
if (Data->P[Order[i].plr].Mission[Order[i].loc].MissionCode != 0)
{
if (!AI[Order[i].plr])
IDLE[0] = IDLE[1] = 0;
if (!(Data->P[Order[i].plr].Mission[Order[i].loc].part == 1
|| Data->P[Order[i].plr].Mission[Order[i].loc].Hard[4] ==
0))
{
prest = Launch(Order[i].plr, Order[i].loc);
// check for prestige firsts
if (AI[Order[i].plr] == 1 && Data->Prestige[22].Place == -1) // supposed to be 1
for (j = 0; j < 28; j++)
{
if (j != 4 && j != 5 && j != 6)
if (Data->Prestige[j].Place == Order[i].plr
&& Data->PD[Order[i].plr][j] != 1)
{
PlayFirst(Order[i].plr, j);
}
}
if (Data->Prestige[22].Place != -1)
{
UpdateRecords(1);
NewEnd(Data->Prestige[22].Place, Order[i].loc);
FadeOut(2, pal, 10, 0, 0);
return;
}
if (!AI[Order[i].plr] && prest != -20) // -20 means scrubbed
MisRev(Order[i].plr, prest);
}
}
}; //for(i=0...
Update(); /* Moves Future launches to Missions + More */
// Update M array to speed AI code
for (j=0;j<NUM_PLAYERS;j++) {
for (i=0;i<Data->P[j].PastMis;i++) {
if (Data->P[j].History[i].result>=100)
Data->P[j].M[Data->P[j].History[i].MissionCode]=1;
}
}
if (Data->Year==77 && Data->Season==1 && Data->Prestige[22].Place==-1)
{ // nobody wins .....
SpecialEnd();
FadeOut(2,pal,10,0,0);
return;
}
Data->P[0].Budget+=Data->P[0].Prestige;
Data->P[1].Budget+=Data->P[1].Prestige;
if (Data->P[0].Budget>180) Data->P[0].Budget=180;
if (Data->P[1].Budget>180) Data->P[1].Budget=180;
// move prestige history down one;
for(t3=0;t3<2;t3++) // t3 is the index to the real and random hists
{
for(t1=0;t1<NUM_PLAYERS;t1++) // t1 is the player index
{
for(t2=4;t2>0;t2--) // t2 is the time index
Data->P[t1].PrestHist[t2][t3]=Data->P[t1].PrestHist[t2-1][t3];
sign = (Data->P[t1].Prestige < 0) ? -1 : 1;
Data->P[t1].PrestHist[0][t3] = (t3 == 0) ? Data->P[t1].Prestige
: (Data->P[t1].Prestige*4)/5+sign*random(Data->P[t1].Prestige*2/5)+1;
if(t3==0) Data->P[t1].tempPrestige[Data->Season] += Data->P[t1].Prestige;
}
};
Data->P[0].Prestige=Data->P[1].Prestige=0;
if (Data->Season == 1)
{
for (i = 0; i < NUM_PLAYERS; i++)
{
int p = plr[i] % NUM_PLAYERS;
int pi = plr[i] - 2*AI[i];
assert(0 <= pi && pi <= NUM_PLAYERS);
Data->P[p].Cash += Data->P[pi].Budget;
if (Data->P[p].Cash > 999)
Data->P[pi].Cash = 900;
}
Data->Season = 0;
Data->Year++;
}
else
Data->Season++;
};
FadeOut(2,pal,10,0,0);
Museum(0);
Museum(1);
return;
}
void DockingKludge(void)
{
int j;
for (j=0;j<NUM_PLAYERS;j++) {
Data->P[j].Misc[4].MSF=
maxx( maxx(Data->P[j].Probe[0].Safety,Data->P[j].Probe[1].Safety),
Data->P[j].Probe[2].Safety);
}
return;
}
/** Reset Crews on a particular Mission
*/
void FreePadMen(char plr,struct MissionType *XMis)
{
int i,c;
if (XMis->PCrew>0) { // Remove Primary Crew
for (i=0;i<Data->P[plr].Gcnt[XMis->Prog][XMis->PCrew-1];i++) {
c=Data->P[plr].Crew[XMis->Prog][XMis->PCrew-1][i]-1;
Data->P[plr].Pool[c].Prime=0;
}
}
if (XMis->BCrew>0) { // Remove Backup Crew
for (i=0;i<Data->P[plr].Gcnt[XMis->Prog][XMis->BCrew-1];i++) {
c=Data->P[plr].Crew[XMis->Prog][XMis->BCrew-1][i]-1;
Data->P[plr].Pool[c].Prime=0;
}
}
return;
}
/** Destroy Pad and Reset any Crews affected
*
* \param cost amount of MB to pay for repairs
* \param pad number of the launch facility destroyed
* \param plr Player data
* \param mode 0 if future mission, 1 is current mission
*/
void DestroyPad(char plr,char pad,int cost,char mode)
{
struct MissionType *BMis=NULL,*AMis=NULL;
Data->P[plr].LaunchFacility[pad]=cost; // Destroys pad
AMis=(mode==0) ? &Data->P[plr].Future[pad] : &Data->P[plr].Mission[pad];
if (AMis->Joint==1) {
if (AMis->part==0) BMis=&AMis[1];
if (AMis->part==1) BMis=&AMis[-1];
}
if (AMis!=NULL) {
if (AMis->Men!=0) FreePadMen(plr,AMis);
memset(AMis,0x00,sizeof (struct MissionType));
}
if (BMis!=NULL) {
if (BMis->Men!=0) FreePadMen(plr,BMis);
memset(BMis,0x00,sizeof (struct MissionType));
}
return;
}
void GV(GXHEADER *obj,int w,int h)
{
gxCreateVirtual(gxCMM,obj,gxVGA_13,w,h);
}
void DV(GXHEADER *obj)
{
gxDestroyVirtual(obj);
return;
}
void
GetMouse (void)
{
av_block ();
GetMouse_fast ();
}
/* get mouse of keyboard input, non-blocking */
void GetMouse_fast(void)
{
mousebuttons=0;
oldx=x;oldy=y;
gr_maybe_sync ();
av_step ();
if (XMAS!=0) {
if (grGetMouseButtons()) {
mousebuttons=1;
grGetMousePressedPos(&x,&y);
} else {
mousebuttons=0;
grGetMouseCurPos (&x, &y);
}
}
while (bioskey(1)) {
key=bioskey(0);
if((key&0x00ff)>0) key=toupper(key & 0xff);
mousebuttons=0;
//grSetMousePos(319,199);
}
if (mousebuttons>0) key=0;
if (key>>8==15) CloseEmUp(0,0);
else if (XMAS && AL_CALL==0 && (key>>8==0x3B)) {
if (mousebuttons!=1) Help(IDT);
}
else if (AL_CALL==0 && ((key>>8)==0x3C)) Help(IKEY);
else if (AL_CALL==0 && ((key>>8)==0x3D)) Help("i123");
}
void WaitForMouseUp(void)
{
// Wait for mouse and key to be up
while (mousebuttons)
GetMouse();
}
void WaitForKeyOrMouseDown(void)
{
// Wait for mouse and key to be up
while (mousebuttons==0 && key==0)
GetMouse();
}
void PauseMouse(void)
{
/* wait until mouse button is released */
while(1) {
GetMouse(); /* blocks briefly */
if (mousebuttons==0) break;
}
GetMouse ();
}
/** Print string at specific position
*
* The function will print a string at a certain position.
* If both the x and y coordinate are zero (0) the position is "current position".
* The area will be marked as "needs update" to the graphics handler.
*
* \note Will not print anything if length of string exceeds 100 characters
*
* \param x x-coordinate of the start of the string
* \param y y-coordinate of the start of the string
* \param s pointer to char-array (string) to print
*
*/
void PrintAt(int x,int y,char *s)
{
short i;
if (x!=0 && y!=0) grMoveTo(x,y);
if (strlen(s) > 100) return;
for(i=0;i<(int)strlen(s);i++)
DispChr(s[i]);
av_need_update_xy(x, y-7, x+i*7, y);
return;
}
void PrintAtKey(int x,int y,char *s,char val)
{
PrintAt(x, y, s);
grMoveTo(x,y);grSetColor(9);
DispChr(s[val]);
return;
}
#ifdef DEAD_CODE
void DrawLED(int x,int y,char st)
{
int i,j;
unsigned char Dots[2][5][5] ={
{{0,9,9,10,0},{9,8,9,9,10},{9,9,9,9,10},{10,9,9,9,10},{0,10,10,10,0}}, // Red
{{0,15,15,16,0},{15,14,15,15,16},{15,15,15,15,16},{16,15,15,15,16},{0,16,16,16,0}}}; // Grn
for (i=0;i<5;i++) for (j=0;j<5;j++) if (Dots[st][i][j]!=0)
grPutPixel(x+i,y+j,Dots[st][i][j]);
return;
}
#endif
void DispBig(int x,int y,char *txt,char mode,char te)
{
int i,k,l,px;
struct LET {char width,img[15][21];} letter;
int c;
int x0 = x;
y--;
if(mode)EMPTY_BODY;
for (i=0;i<(int)strlen(txt);i++) {
if (txt[i]==0x20) {x+=6;i++;};
c=toupper(txt[i] & 0xff);
if (c>=0x30 && c<=0x39) px=c-32;
else px=c-33;
if (c=='-') px++;
memcpy(&letter,letter_dat + (sizeof letter*px),sizeof letter); // copy letter over
for (k=0;k<15;k++)
for (l=0;l<letter.width;l++) {
if (letter.img[k][l]!=0x03) {
if ((letter.img[k][l]==0x01 || letter.img[k][l]==0x02) && i==te)
grPutPixel(x+l,y+k,letter.img[k][l]+7);
else grPutPixel(x+l,y+k,letter.img[k][l]);
}
}
x+=letter.width-1;
};
av_need_update_xy(x0, y, x, y+15);
}
void DispNum(int xx,int yy,int num)
{
short n0,n1,n2,n3,t;
if (xx!=0 && yy!=0) grMoveTo(xx,yy);
t=num;
num=abs(t);
if (t<0) PrintAt(0,0,"-");
n0=num/1000;
n1=num/100-n0*10;
n2=num/10-n0*100-n1*10;
n3=num-n0*1000-n1*100-n2*10;
if (n0!=0) {
DispChr(n0+0x30);
DispChr(n1+0x30);
DispChr(n2+0x30);
DispChr(n3+0x30);
};
if (n0==0 && n1!=0) {
DispChr(n1+0x30);
DispChr(n2+0x30);
DispChr(n3+0x30);
};
if (n0==0 && n1==0 && n2!=0) {
DispChr(n2+0x30);
DispChr(n3+0x30);
};
if (n0==0 && n1==0 && n2==0)
DispChr(n3+0x30);
return;
}
void DispMB(int x,int y,int val)
{
DispNum(x,y,val);
PrintAt(0,0," MB");
return;
}
#ifdef DEAD_CODE
// Place a glimmer on a box
void Gl(int x1,int x2,int y,char t)
{
int i,nx;
char Glim[13]={31,30,29,28,27,1,1,1,27,28,29,30,31};
if ((x2-x1)<30) return;
nx=(x2-x1)/2;
if (t==0) nx=nx-(nx/3);
else nx=nx+(nx/3);
for (i=0;i<13;i++) grPutPixel(x1+nx+i,y,Glim[i]);
return;
}
#endif
void ShBox(int x1,int y1,int x2,int y2)
{
RectFill(x1,y1,x2,y2,3);
OutBox(x1,y1,x2,y2);
return;
}
void UPArrow(int x1,int y1)
{
grSetColor(4);grDrawLine(x1,y1,x1,25+y1);grDrawLine(3+x1,11+y1,5+x1,11+y1);
grSetColor(2);grDrawLine(1+x1,y1,6+x1,11+y1);grDrawLine(3+x1,12+y1,3+x1,25+y1);
return;
}
void RTArrow(int x1,int y1)
{
grSetColor(4);grDrawLine(x1,y1,x1+31,y1);grDrawLine(x1+20,y1+3,x1+20,y1+5);
grSetColor(2);grDrawLine(x1,y1+3,x1+19,y1+3);grDrawLine(x1+31,y1+1,x1+20,y1+6);
return;
}
void LTArrow(int x1,int y1)
{
grSetColor(4);grDrawLine(x1,y1,x1+31,y1);grDrawLine(x1+11,y1+3,x1+11,y1+5);
grSetColor(2);grDrawLine(x1,y1+1,x1+11,y1+6);grDrawLine(x1+12,y1+3,x1+31,y1+3);
return;
}
void DNArrow(int x1,int y1)
{
grSetColor(4);grDrawLine(x1,y1,x1,25+y1);grDrawLine(3+x1,14+y1,5+x1,14+y1);
grSetColor(2);grDrawLine(3+x1,y1,3+x1,13+y1);grDrawLine(6+x1,14+y1,1+x1,25+y1);
return;
}
void InBox(int x1,int y1,int x2,int y2)
{
grSetColor(2); grMoveTo(x1,y2); grLineTo(x2,y2); grLineTo(x2,y1);
grSetColor(4); grLineTo(x1,y1); grLineTo(x1,y2);
av_need_update_xy(x1, y1, x2, y2);
}
void OutBox(int x1,int y1,int x2,int y2)
{
grSetColor(4); grMoveTo(x1,y2); grLineTo(x2,y2); grLineTo(x2,y1);
grSetColor(2); grMoveTo(x2-1,y1); grLineTo(x1,y1); grLineTo(x1,y2-1);
av_need_update_xy(x1, y1, x2, y2);
}
void IOBox(int x1, int y1, int x2, int y2)
{
InBox(x1,y1,x2,y2);
grSetColor(0);Box(x1+1,y1+1,x2-1,y2-1);
OutBox(x1+2,y1+2,x2-2,y2-2);
}
/** draw a rectangle
*
* \param x1
* \param y1
* \param x2
* \param y2
* \param col Color code of the rectangle
*
*/
void RectFill(int x1,int y1,int x2,int y2,char col)
{
grSetBkColor(col);
grClearArea(x1,y1,x2,y2);
return;
}
void Box(int x1,int y1,int x2,int y2)
{
grDrawRect(x1,y1,x2,y2,grOUTLINE);
return;
}
void GradRect(int x1,int y1,int x2,int y2,char plr)
{
//register int i,j,val;
//val=3*plr+6;
RectFill(x1,y1,x2,y2,7+3*plr);
//for (j=x1;j<=x2;j+=4)
// for (i=y1;i<=y2;i+=4)
// screen[j+320*i]=val;
return;
}
void FlagSm(char plr,int xm,int ym)
{
int i;
if (plr==0) {
RectFill(xm,ym,xm+25,ym+14,1);
grSetColor(8);
for (i=0;i<15;i++) {
grMoveTo(xm,ym+i);
grLineTo(xm+25,ym+i);
i++;
};
RectFill(xm,ym,xm+12,ym+7,5);
xm++;
for (i=0;i<11;i++) {
grPutPixel(xm+i,ym+1,2);
grPutPixel(xm+i,ym+3,2);
grPutPixel(xm+i,ym+5,2);
i++;
};
for (i=1;i<10;i++) {
grPutPixel(xm+i,ym+2,2);
grPutPixel(xm+i,ym+4,2);
grPutPixel(xm+i,ym+6,2);
i++;
};
} else {
RectFill(xm,ym,xm+25,ym+14,8);
grSetColor(11); grMoveTo(xm+2,ym+6); grLineTo(xm+4,ym+6); grLineTo(xm+4,ym+5);
grLineTo(xm+5,ym+5); grLineTo(xm+5,ym+3);
grPutPixel(xm+3,ym+4,11);grPutPixel(xm+4,ym+2,11);grPutPixel(xm+5,ym+1,11);
grPutPixel(xm+6,ym+2,11);
}
return;
}
void Flag(int x,int y,char plr)
{
int i,j;
if (plr==0) {
for (i=0;i<7;i++) RectFill(x,y+i*6,x+69,y+2+i*6,8);
for (i=0;i<6;i++) RectFill(x,y+3+i*6,x+69,y+5+i*6,1);
RectFill(x,y,x+33,y+20,6);
RectFill(x,y,x+32,y+20,5);
for (j=0;j<5;j++) for (i=0;i<8;i++) PP(x+2+i*4,y+2+4*j,2);
for (j=0;j<4;j++) for (i=0;i<7;i++) PP(x+4+i*4,y+4+4*j,2);
} else {
RectFill(x,y,x+69,38+y,8);
PP(10+x,2+y,11);
PP(8+x,3+y,11); PP(9+x,3+y,11);PP(11+x,3+y,11); PP(12+x,3+y,11);
PP(9+x,5+y,11); PP(11+x,5+y,11);
PP(12+x,6+y,11);
PP(10+x,7+y,11);PP(13+x,7+y,11);
PP(9+x,8+y,11);PP(10+x,8+y,11);PP(11+x,8+y,11);PP(14+x,8+y,11);
PP(8+x,9+y,11);PP(9+x,9+y,11);PP(10+x,9+y,11);PP(14+x,9+y,11);PP(15+x,9+y,11);
PP(7+x,10+y,11);PP(8+x,10+y,11);PP(9+x,10+y,11);PP(10+x,10+y,11);PP(14+x,10+y,11);PP(15+x,10+y,11);
PP(11+x,11+y,11);PP(14+x,11+y,11);
PP(12+x,12+y,11);PP(13+x,12+y,11);PP(14+x,12+y,11);
PP(7+x,13+y,11);PP(8+x,13+y,11);PP(12+x,13+y,11);PP(13+x,13+y,11);
PP(6+x,14+y,11);PP(9+x,14+y,11);PP(10+x,14+y,11);PP(11+x,14+y,11);
PP(12+x,14+y,11);PP(13+x,14+y,11);PP(14+x,15+y,11);
PP(9+x,4+y,12);PP(10+x,4+y,12);PP(11+x,4+y,12);
PP(14+x,7+y,12); PP(8+x,11+y,12); PP(10+x,11+y,12); PP(15+x,11+y,12);
PP(11+x,12+y,12); PP(14+x,13+y,12); PP(7+x,14+y,12); PP(5+x,15+y,12);
PP(15+x,15+y,12);
};
return;
}
/** Prints a character at current position of graphics handler.
*
* \note The function converts all characters to upper case before printing.
*
* \param chr Character to be printed
*/
void DispChr(char chr)
{
switch(toupper(chr))
{
case 'A': LR(0,-3);LR(1,-1);LR(2,0);LR(1,1);LR(0,3);LR(-1,-1);
LR(-2,0);MR(5,1);break;
case 'B': LR(0,-4);LR(3,0);LR(1,1);LR(-1,1);LR(1,1);
LR(-1,1);LR(-2,0);MR(0,-2);LR(1,0);MR(4,2);
break;
case 'C': MR(4,-4);LR(-3,0);LR(-1,1);LR(0,2);LR(1,1);LR(3,0);MR(2,0);
break;
case 'D': LR(0,-4);LR(3,0);LR(1,1);LR(0,2);LR(-1,1);LR(-2,0);MR(5,0);
break;
case 'E': LR(0,-4);LR(4,0);MR(0,4);LR(-3,0);MR(0,-2);LR(1,0);MR(4,2);
break;
case 'F': LR(0,-4);LR(4,0);MR(-2,2);LR(-1,0);MR(5,2);break;
case 'G': MR(4,-4);LR(-3,0);LR(-1,1);LR(0,2);LR(1,1);LR(3,0);
LR(0,-2);LR(-1,0);MR(3,2);break;
case 'H': LR(0,-4);MR(1,2);LR(2,0);MR(1,-2);LR(0,4);MR(2,0);
break;
case 'I': LR(2,0);LR(-1,-1);LR(0,-2);LR(-1,-1);LR(2,0);MR(2,4);break;
case 'J': MR(0,-1);LR(1,1);LR(2,0);LR(1,-1);LR(0,-3);MR(2,4);break;
case 'K': LR(0,-4);MR(4,0);LR(-2,2);LR(-1,0);MR(1,0);LR(2,2);MR(2,0);
break;
case 'L': MR(0,-4);LR(0,4);LR(4,0);
MR(2,0);break;
case 'M': LR(0,-4);LR(2,2);LR(2,-2);LR(0,4);MR(2,0);break;