forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmission.cpp
3361 lines (2909 loc) · 88.9 KB
/
mission.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
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project
Warzone 2100 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.
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file mission.c
*
* All the stuff relevant to a mission.
*/
#include "mission.h"
#include "lib/framework/frame.h"
#include "lib/framework/wzapp.h"
#include "lib/framework/math_ext.h"
#include "lib/ivis_opengl/bitimage.h"
#include "lib/ivis_opengl/textdraw.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/gamelib/gtime.h"
#include "lib/script/script.h"
#include "lib/sound/audio.h"
#include "lib/sound/audio_id.h"
#include "lib/sound/cdaudio.h"
#include "lib/widget/label.h"
#include "lib/widget/widget.h"
#include "game.h"
#include "challenge.h"
#include "projectile.h"
#include "power.h"
#include "structure.h"
#include "message.h"
#include "research.h"
#include "hci.h"
#include "order.h"
#include "action.h"
#include "display3d.h"
#include "effects.h"
#include "radar.h"
#include "transporter.h"
#include "group.h"
#include "frontend.h" // for displaytextoption.
#include "intdisplay.h"
#include "main.h"
#include "display.h"
#include "loadsave.h"
#include "scripttabs.h"
#include "cmddroid.h"
#include "warcam.h"
#include "wrappers.h"
#include "console.h"
#include "droid.h"
#include "data.h"
#include "multiplay.h"
#include "loop.h"
#include "visibility.h"
#include "mapgrid.h"
#include "cluster.h"
#include "gateway.h"
#include "selection.h"
#include "scores.h"
#include "keymap.h"
#include "texture.h"
#include "warzoneconfig.h"
#include "combat.h"
#include "qtscript.h"
#define IDMISSIONRES_TXT 11004
#define IDMISSIONRES_LOAD 11005
#define IDMISSIONRES_CONTINUE 11008
#define IDMISSIONRES_BACKFORM 11013
#define IDMISSIONRES_TITLE 11014
/* Mission timer label position */
#define TIMER_LABELX 15
#define TIMER_LABELY 0
/* Transporter Timer form position */
#define TRAN_FORM_X STAT_X
#define TRAN_FORM_Y TIMER_Y
#define TRAN_FORM_WIDTH 75
#define TRAN_FORM_HEIGHT 25
/* Transporter Timer position */
#define TRAN_TIMER_X 4
#define TRAN_TIMER_Y TIMER_LABELY
#define TRAN_TIMER_WIDTH 25
#define MISSION_1_X 5 // pos of text options in box.
#define MISSION_1_Y 15
#define MISSION_2_X 5
#define MISSION_2_Y 35
#define MISSION_3_X 5
#define MISSION_3_Y 55
#define MISSION_TEXT_W MISSIONRES_W-10
#define MISSION_TEXT_H 16
// These are used for mission countdown
#define TEN_MINUTES (10 * 60 * GAME_TICKS_PER_SEC)
#define FIVE_MINUTES (5 * 60 * GAME_TICKS_PER_SEC)
#define FOUR_MINUTES (4 * 60 * GAME_TICKS_PER_SEC)
#define THREE_MINUTES (3 * 60 * GAME_TICKS_PER_SEC)
#define TWO_MINUTES (2 * 60 * GAME_TICKS_PER_SEC)
#define ONE_MINUTE (1 * 60 * GAME_TICKS_PER_SEC)
#define NOT_PLAYED_ONE 0x01
#define NOT_PLAYED_TWO 0x02
#define NOT_PLAYED_THREE 0x04
#define NOT_PLAYED_FIVE 0x08
#define NOT_PLAYED_TEN 0x10
#define NOT_PLAYED_ACTIVATED 0x20
MISSION mission;
bool offWorldKeepLists;
// Set by scrFlyInTransporter. True if were currenly tracking the transporter.
bool bTrackingTransporter = false;
/*lists of droids that are held seperate over several missions. There should
only be selectedPlayer's droids but have possibility for MAX_PLAYERS -
also saves writing out list functions to cater for just one player*/
DROID *apsLimboDroids[MAX_PLAYERS];
//Where the Transporter lands for player 0 (sLandingZone[0]), and the rest are
//a list of areas that cannot be built on, used for landing the enemy transporters
static LANDING_ZONE sLandingZone[MAX_NOGO_AREAS];
//flag to indicate when the droids in a Transporter are flown to safety and not the next mission
static bool bDroidsToSafety;
/* mission result holder */
static bool g_bMissionResult;
// return positions for vtols
Vector2i asVTOLReturnPos[MAX_PLAYERS];
static UBYTE missionCountDown;
//flag to indicate whether the coded mission countdown is played
static UBYTE bPlayCountDown;
//FUNCTIONS**************
static void addLandingLights( UDWORD x, UDWORD y);
static bool startMissionOffClear(char *pGame);
static bool startMissionOffKeep(char *pGame);
static bool startMissionCampaignStart(char *pGame);
static bool startMissionCampaignChange(char *pGame);
static bool startMissionCampaignExpand(char *pGame);
static bool startMissionCampaignExpandLimbo(char *pGame);
static bool startMissionBetween(void);
static void endMissionCamChange(void);
static void endMissionOffClear(void);
static void endMissionOffKeep(void);
static void endMissionOffKeepLimbo(void);
static void endMissionExpandLimbo(void);
static void saveMissionData(void);
static void restoreMissionData(void);
static void saveCampaignData(void);
static void missionResetDroids(void);
static void saveMissionLimboData(void);
static void restoreMissionLimboData(void);
static void processMissionLimbo(void);
static void intUpdateMissionTimer(WIDGET *psWidget, W_CONTEXT *psContext);
static bool intAddMissionTimer(void);
static void intUpdateTransporterTimer(WIDGET *psWidget, W_CONTEXT *psContext);
static void adjustMissionPower(void);
static void saveMissionPower(void);
static UDWORD getHomeLandingX(void);
static UDWORD getHomeLandingY(void);
static void fillTimeDisplay(char *psText, UDWORD time, bool bHours);
static void processPreviousCampDroids(void);
static bool intAddTransporterTimer(void);
static void clearCampaignUnits(void);
static void emptyTransporters(bool bOffWorld);
bool MissionResUp = false;
bool ClosingMissionRes = false;
static SDWORD g_iReinforceTime = 0;
/* Which campaign are we dealing with? */
static UDWORD camNumber = 1;
//returns true if on an off world mission
bool missionIsOffworld(void)
{
return ((mission.type == LDS_MKEEP)
|| (mission.type == LDS_MCLEAR)
|| (mission.type == LDS_MKEEP_LIMBO)
);
}
//returns true if the correct type of mission for reinforcements
bool missionForReInforcements(void)
{
if (mission.type == LDS_CAMSTART || missionIsOffworld() || mission.type == LDS_CAMCHANGE)
{
return true;
}
else
{
return false;
}
}
//returns true if the correct type of mission and a reinforcement time has been set
bool missionCanReEnforce(void)
{
if (mission.ETA >= 0)
{
if (missionForReInforcements())
{
return true;
}
}
return false;
}
//returns true if the mission is a Limbo Expand mission
bool missionLimboExpand(void)
{
return (mission.type == LDS_EXPAND_LIMBO);
}
// mission initialisation game code
void initMission(void)
{
debug(LOG_SAVE, "*** Init Mission ***");
mission.type = LDS_NONE;
for (int inc = 0; inc < MAX_PLAYERS; inc++)
{
mission.apsStructLists[inc] = NULL;
mission.apsDroidLists[inc] = NULL;
mission.apsFeatureLists[inc] = NULL;
mission.apsFlagPosLists[inc] = NULL;
mission.apsExtractorLists[inc] = NULL;
apsLimboDroids[inc] = NULL;
}
mission.apsSensorList[0] = NULL;
mission.apsOilList[0] = NULL;
offWorldKeepLists = false;
mission.time = -1;
setMissionCountDown();
mission.ETA = -1;
mission.startTime = 0;
mission.psGateways = NULL;
mission.mapHeight = 0;
mission.mapWidth = 0;
for (int i = 0; i < ARRAY_SIZE(mission.psBlockMap); ++i)
{
mission.psBlockMap[i] = NULL;
}
for (int i = 0; i < ARRAY_SIZE(mission.psAuxMap); ++i)
{
mission.psAuxMap[i] = NULL;
}
//init all the landing zones
for (int inc = 0; inc < MAX_NOGO_AREAS; inc++)
{
sLandingZone[inc].x1 = sLandingZone[inc].y1 = sLandingZone[inc].x2 = sLandingZone[inc].y2 = 0;
}
// init the vtol return pos
memset(asVTOLReturnPos, 0, sizeof(Vector2i) * MAX_PLAYERS);
bDroidsToSafety = false;
setPlayCountDown(true);
//start as not cheating!
mission.cheatTime = 0;
}
// reset the vtol landing pos
void resetVTOLLandingPos(void)
{
memset(asVTOLReturnPos, 0, sizeof(Vector2i)*MAX_PLAYERS);
}
//this is called everytime the game is quit
void releaseMission(void)
{
/* mission.apsDroidLists may contain some droids that have been transferred from one campaign to the next */
freeAllMissionDroids();
/* apsLimboDroids may contain some droids that have been saved at the end of one mission and not yet used */
freeAllLimboDroids();
}
//called to shut down when mid-mission on an offWorld map
bool missionShutDown(void)
{
UDWORD inc;
debug(LOG_SAVE, "called, mission is %s", missionIsOffworld() ? "off-world" : "main map");
if (missionIsOffworld())
{
//clear out the audio
audio_StopAll();
freeAllDroids();
freeAllStructs();
freeAllFeatures();
releaseAllProxDisp();
gwShutDown();
for (inc = 0; inc < MAX_PLAYERS; inc++)
{
apsDroidLists[inc] = mission.apsDroidLists[inc];
mission.apsDroidLists[inc] = NULL;
apsStructLists[inc] = mission.apsStructLists[inc];
mission.apsStructLists[inc] = NULL;
apsFeatureLists[inc] = mission.apsFeatureLists[inc];
mission.apsFeatureLists[inc] = NULL;
apsFlagPosLists[inc] = mission.apsFlagPosLists[inc];
mission.apsFlagPosLists[inc] = NULL;
apsExtractorLists[inc] = mission.apsExtractorLists[inc];
mission.apsExtractorLists[inc] = NULL;
}
apsSensorList[0] = mission.apsSensorList[0];
apsOilList[0] = mission.apsOilList[0];
mission.apsSensorList[0] = NULL;
mission.apsOilList[0] = NULL;
psMapTiles = mission.psMapTiles;
mapWidth = mission.mapWidth;
mapHeight = mission.mapHeight;
for (int i = 0; i < ARRAY_SIZE(mission.psBlockMap); ++i)
{
free(psBlockMap[i]);
psBlockMap[i] = mission.psBlockMap[i];
mission.psBlockMap[i] = NULL;
}
for (int i = 0; i < ARRAY_SIZE(mission.psAuxMap); ++i)
{
free(psAuxMap[i]);
psAuxMap[i] = mission.psAuxMap[i];
mission.psAuxMap[i] = NULL;
}
gwSetGateways(mission.psGateways);
}
// sorry if this breaks something - but it looks like it's what should happen - John
mission.type = LDS_NONE;
return true;
}
/*on the PC - sets the countdown played flag*/
void setMissionCountDown(void)
{
SDWORD timeRemaining;
timeRemaining = mission.time - (gameTime - mission.startTime);
if (timeRemaining < 0)
{
timeRemaining = 0;
}
// Need to init the countdown played each time the mission time is changed
missionCountDown = NOT_PLAYED_ONE | NOT_PLAYED_TWO | NOT_PLAYED_THREE | NOT_PLAYED_FIVE | NOT_PLAYED_TEN | NOT_PLAYED_ACTIVATED;
if (timeRemaining < TEN_MINUTES - 1)
{
missionCountDown &= ~NOT_PLAYED_TEN;
}
if (timeRemaining < FIVE_MINUTES - 1)
{
missionCountDown &= ~NOT_PLAYED_FIVE;
}
if (timeRemaining < THREE_MINUTES - 1)
{
missionCountDown &= ~NOT_PLAYED_THREE;
}
if (timeRemaining < TWO_MINUTES - 1)
{
missionCountDown &= ~NOT_PLAYED_TWO;
}
if (timeRemaining < ONE_MINUTE - 1)
{
missionCountDown &= ~NOT_PLAYED_ONE;
}
}
bool startMission(LEVEL_TYPE missionType, char *pGame)
{
bool loaded = true;
debug(LOG_SAVE, "type %d", (int)missionType);
/* Player has (obviously) not failed at the start */
setPlayerHasLost(false);
setPlayerHasWon(false);
/* and win/lose video is obvioulsy not playing */
setScriptWinLoseVideo(PLAY_NONE);
// this inits the flag so that 'reinforcements have arrived' message isn't played for the first transporter load
initFirstTransporterFlag();
if (mission.type != LDS_NONE)
{
/*mission type gets set to none when you have returned from a mission
so don't want to go another mission when already on one! - so ignore*/
debug(LOG_SAVE, "Already on a mission");
return true;
}
// reset the cluster stuff
clustInitialise();
initEffectsSystem();
//load the game file for all types of mission except a Between Mission
if (missionType != LDS_BETWEEN)
{
loadGameInit(pGame);
}
//all proximity messages are removed between missions now
releaseAllProxDisp();
switch (missionType)
{
case LDS_CAMSTART:
{
if (!startMissionCampaignStart(pGame))
{
loaded = false;
}
break;
}
case LDS_MKEEP:
case LDS_MKEEP_LIMBO:
{
if (!startMissionOffKeep(pGame))
{
loaded = false;
}
break;
}
case LDS_BETWEEN:
{
//do anything?
if (!startMissionBetween())
{
loaded = false;
}
break;
}
case LDS_CAMCHANGE:
{
if (!startMissionCampaignChange(pGame))
{
loaded = false;
}
break;
}
case LDS_EXPAND:
{
if (!startMissionCampaignExpand(pGame))
{
loaded = false;
}
break;
}
case LDS_EXPAND_LIMBO:
{
if (!startMissionCampaignExpandLimbo(pGame))
{
loaded = false;
}
break;
}
case LDS_MCLEAR:
{
if (!startMissionOffClear(pGame))
{
loaded = false;
}
break;
}
default:
{
//error!
debug( LOG_ERROR, "Unknown Mission Type" );
loaded = false;
}
}
if (!loaded)
{
debug( LOG_ERROR, "Unable to load mission file" );
return false;
}
mission.type = missionType;
if (missionIsOffworld())
{
//add what power have got from the home base
adjustMissionPower();
}
if (missionCanReEnforce())
{
//add mission timer - if necessary
addMissionTimerInterface();
//add Transporter Timer
addTransporterTimerInterface();
}
scoreInitSystem();
return true;
}
// initialise the mission stuff for a save game
bool startMissionSave(SDWORD missionType)
{
mission.type = missionType;
return true;
}
/*checks the time has been set and then adds the timer if not already on
the display*/
void addMissionTimerInterface(void)
{
//don't add if the timer hasn't been set
if (mission.time < 0 && !challengeActive)
{
return;
}
//check timer is not already on the screen
if (!widgGetFromID(psWScreen, IDTIMER_FORM))
{
intAddMissionTimer();
}
}
/*checks that the timer has been set and that a Transporter exists before
adding the timer button*/
void addTransporterTimerInterface(void)
{
DROID *psTransporter = NULL;
bool bAddInterface = false;
W_CLICKFORM *psForm;
//check if reinforcements are allowed
if (mission.ETA >= 0)
{
//check the player has at least one Transporter back at base
for (DROID *psDroid = mission.apsDroidLists[selectedPlayer]; psDroid != NULL; psDroid = psDroid->psNext)
{
if (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)
{
psTransporter = psDroid;
break;
}
}
if (psTransporter)
{
bAddInterface = true;
//check timer is not already on the screen
if (!widgGetFromID(psWScreen, IDTRANTIMER_BUTTON))
{
intAddTransporterTimer();
}
//set the data for the transporter timer
widgSetUserData(psWScreen, IDTRANTIMER_DISPLAY, (void*)psTransporter);
// lock the button if necessary
if (transporterFlying(psTransporter))
{
// disable the form so can't add any more droids into the transporter
psForm = (W_CLICKFORM*)widgGetFromID(psWScreen,IDTRANTIMER_BUTTON);
if (psForm)
{
formSetClickState(psForm, WBUT_LOCK);
}
}
}
}
// if criteria not met
if (!bAddInterface)
{
// make sure its not there!
intRemoveTransporterTimer();
}
}
#define OFFSCREEN_RADIUS 600
#define OFFSCREEN_HEIGHT 600
#define EDGE_SIZE 1
/* pick nearest map edge to point */
void missionGetNearestCorner( UWORD iX, UWORD iY, UWORD *piOffX, UWORD *piOffY )
{
UDWORD iMidX = (scrollMinX + scrollMaxX)/2,
iMidY = (scrollMinY + scrollMaxY)/2;
if (map_coord(iX) < iMidX)
{
*piOffX = (UWORD) (world_coord(scrollMinX) + (EDGE_SIZE * TILE_UNITS));
}
else
{
*piOffX = (UWORD) (world_coord(scrollMaxX) - (EDGE_SIZE * TILE_UNITS));
}
if (map_coord(iY) < iMidY)
{
*piOffY = (UWORD) (world_coord(scrollMinY) + (EDGE_SIZE * TILE_UNITS));
}
else
{
*piOffY = (UWORD) (world_coord(scrollMaxY) - (EDGE_SIZE * TILE_UNITS));
}
}
/* fly in transporters at start of level */
void missionFlyTransportersIn( SDWORD iPlayer, bool bTrackTransporter )
{
DROID *psTransporter, *psNext;
UWORD iX, iY, iZ;
SDWORD iLandX, iLandY, iDx, iDy;
ASSERT_OR_RETURN(, iPlayer < MAX_PLAYERS, "Flying nonexistent player %d's transporters in", iPlayer);
bTrackingTransporter = bTrackTransporter;
iLandX = getLandingX(iPlayer);
iLandY = getLandingY(iPlayer);
missionGetTransporterEntry( iPlayer, &iX, &iY );
iZ = (UWORD) (map_Height( iX, iY ) + OFFSCREEN_HEIGHT);
psNext = NULL;
//get the droids for the mission
for (psTransporter = mission.apsDroidLists[iPlayer]; psTransporter !=
NULL; psTransporter = psNext)
{
psNext = psTransporter->psNext;
// FIXME: When we convert campaign scripts to use DROID_SUPERTRANSPORTER
if (psTransporter->droidType == DROID_TRANSPORTER)
{
// Check that this transporter actually contains some droids
if (psTransporter->psGroup && psTransporter->psGroup->refCount > 1)
{
// Remove map information from previous map
free(psTransporter->watchedTiles);
psTransporter->watchedTiles = NULL;
psTransporter->numWatchedTiles = 0;
// Remove out of stored list and add to current Droid list
if (droidRemove(psTransporter, mission.apsDroidLists))
{
// Do not want to add it unless managed to remove it from the previous list
addDroid(psTransporter, apsDroidLists);
}
/* set start position */
psTransporter->pos.x = iX;
psTransporter->pos.y = iY;
psTransporter->pos.z = iZ;
/* set start direction */
iDx = iLandX - iX;
iDy = iLandY - iY;
psTransporter->rot.direction = iAtan2(iDx, iDy);
// Camera track requested and it's the selected player.
if ( ( bTrackTransporter == true ) && (iPlayer == (SDWORD)selectedPlayer) )
{
/* deselect all droids */
selDroidDeselect( selectedPlayer );
if ( getWarCamStatus() )
{
camToggleStatus();
}
/* select transporter */
psTransporter->selected = true;
camToggleStatus();
}
//little hack to ensure all Transporters are fully repaired by time enter world
psTransporter->body = psTransporter->originalBody;
/* set fly-in order */
orderDroidLoc(psTransporter, DORDER_TRANSPORTIN,
iLandX, iLandY, ModeImmediate);
audio_PlayObjDynamicTrack( psTransporter, ID_SOUND_BLIMP_FLIGHT,
moveCheckDroidMovingAndVisible );
//only want to fly one transporter in at a time now - AB 14/01/99
break;
}
}
}
}
/* Saves the necessary data when moving from a home base Mission to an OffWorld mission */
static void saveMissionData(void)
{
UDWORD inc;
DROID *psDroid;
STRUCTURE *psStruct, *psStructBeingBuilt;
bool bRepairExists;
debug(LOG_SAVE, "called");
//clear out the audio
audio_StopAll();
//save the mission data
mission.psMapTiles = psMapTiles;
mission.mapWidth = mapWidth;
mission.mapHeight = mapHeight;
for (int i = 0; i < ARRAY_SIZE(mission.psBlockMap); ++i)
{
mission.psBlockMap[i] = psBlockMap[i];
}
for (int i = 0; i < ARRAY_SIZE(mission.psAuxMap); ++i)
{
mission.psAuxMap[i] = psAuxMap[i];
}
mission.scrollMinX = scrollMinX;
mission.scrollMinY = scrollMinY;
mission.scrollMaxX = scrollMaxX;
mission.scrollMaxY = scrollMaxY;
mission.psGateways = gwGetGateways();
gwSetGateways(NULL);
// save the selectedPlayer's LZ
mission.homeLZ_X = getLandingX(selectedPlayer);
mission.homeLZ_Y = getLandingY(selectedPlayer);
bRepairExists = false;
//set any structures currently being built to completed for the selected player
for (psStruct = apsStructLists[selectedPlayer]; psStruct != NULL; psStruct =
psStruct->psNext)
{
if (psStruct->status == SS_BEING_BUILT)
{
//find a droid working on it
for (psDroid = apsDroidLists[selectedPlayer]; psDroid != NULL;
psDroid = psDroid->psNext)
{
if ((psStructBeingBuilt = (STRUCTURE*)orderStateObj(psDroid, DORDER_BUILD))
&& psStructBeingBuilt == psStruct)
{
// just give it all its build points
structureBuild(psStruct, NULL, psStruct->pStructureType->buildPoints);
//don't bother looking for any other droids working on it
break;
}
}
}
//check if have a completed repair facility on home world
if (psStruct->pStructureType->type == REF_REPAIR_FACILITY &&
psStruct->status == SS_BUILT)
{
bRepairExists = true;
}
}
//repair all droids back at home base if have a repair facility
if (bRepairExists)
{
for (psDroid = apsDroidLists[selectedPlayer]; psDroid != NULL;
psDroid = psDroid->psNext)
{
if (droidIsDamaged(psDroid))
{
psDroid->body = psDroid->originalBody;
}
}
}
//clear droid orders for all droids except constructors still building
for (psDroid = apsDroidLists[selectedPlayer]; psDroid != NULL;
psDroid = psDroid->psNext)
{
if ((psStructBeingBuilt = (STRUCTURE*)orderStateObj(psDroid, DORDER_BUILD)))
{
if (psStructBeingBuilt->status == SS_BUILT)
{
orderDroid(psDroid, DORDER_STOP, ModeImmediate);
}
}
else
{
orderDroid(psDroid, DORDER_STOP, ModeImmediate);
}
}
for (inc = 0; inc < MAX_PLAYERS; inc++)
{
mission.apsStructLists[inc] = apsStructLists[inc];
mission.apsDroidLists[inc] = apsDroidLists[inc];
mission.apsFeatureLists[inc] = apsFeatureLists[inc];
mission.apsFlagPosLists[inc] = apsFlagPosLists[inc];
mission.apsExtractorLists[inc] = apsExtractorLists[inc];
}
mission.apsSensorList[0] = apsSensorList[0];
mission.apsOilList[0] = apsOilList[0];
mission.playerX = player.p.x;
mission.playerY = player.p.z;
//save the power settings
saveMissionPower();
//reset before loading in the new game
//resetFactoryNumFlag();
//init before loading in the new game
initFactoryNumFlag();
//clear all the effects from the map
initEffectsSystem();
resizeRadar();
}
/*
This routine frees the memory for the offworld mission map (in the call to mapShutdown)
- so when this routine is called we must still be set to the offworld map data
i.e. We shoudn't have called SwapMissionPointers()
*/
void restoreMissionData(void)
{
UDWORD inc;
BASE_OBJECT *psObj;
debug(LOG_SAVE, "called");
//clear out the audio
audio_StopAll();
//clear all the lists
proj_FreeAllProjectiles();
freeAllDroids();
freeAllStructs();
freeAllFeatures();
gwShutDown();
if (game.type != CAMPAIGN)
{
ASSERT(false, "game type isn't campaign, but we are in a campaign game!");
game.type = CAMPAIGN; // fix the issue, since it is obviously a bug
}
//restore the game pointers
for (inc = 0; inc < MAX_PLAYERS; inc++)
{
apsDroidLists[inc] = mission.apsDroidLists[inc];
mission.apsDroidLists[inc] = NULL;
for(psObj = (BASE_OBJECT *)apsDroidLists[inc]; psObj; psObj=psObj->psNext)
{
psObj->died = false; //make sure the died flag is not set
}
apsStructLists[inc] = mission.apsStructLists[inc];
mission.apsStructLists[inc] = NULL;
apsFeatureLists[inc] = mission.apsFeatureLists[inc];
mission.apsFeatureLists[inc] = NULL;
apsFlagPosLists[inc] = mission.apsFlagPosLists[inc];
mission.apsFlagPosLists[inc] = NULL;
apsExtractorLists[inc] = mission.apsExtractorLists[inc];
mission.apsExtractorLists[inc] = NULL;
}
apsSensorList[0] = mission.apsSensorList[0];
apsOilList[0] = mission.apsOilList[0];
mission.apsSensorList[0] = NULL;
//swap mission data over
psMapTiles = mission.psMapTiles;
mapWidth = mission.mapWidth;
mapHeight = mission.mapHeight;
for (int i = 0; i < ARRAY_SIZE(mission.psBlockMap); ++i)
{
psBlockMap[i] = mission.psBlockMap[i];
mission.psBlockMap[i] = NULL;
}
for (int i = 0; i < ARRAY_SIZE(mission.psAuxMap); ++i)
{
psAuxMap[i] = mission.psAuxMap[i];
mission.psAuxMap[i] = NULL;
}
scrollMinX = mission.scrollMinX;
scrollMinY = mission.scrollMinY;
scrollMaxX = mission.scrollMaxX;
scrollMaxY = mission.scrollMaxY;
gwSetGateways(mission.psGateways);
//and clear the mission pointers
mission.psMapTiles = NULL;
mission.mapWidth = 0;
mission.mapHeight = 0;
mission.scrollMinX = 0;
mission.scrollMinY = 0;
mission.scrollMaxX = 0;
mission.scrollMaxY = 0;
mission.psGateways = NULL;
//reset the current structure lists
setCurrentStructQuantity(false);
initFactoryNumFlag();
resetFactoryNumFlag();
offWorldKeepLists = false;
resizeRadar();
}
/*Saves the necessary data when moving from one mission to a limbo expand Mission*/
void saveMissionLimboData(void)
{
DROID *psDroid, *psNext;
STRUCTURE *psStruct;
debug(LOG_SAVE, "called");
//clear out the audio
audio_StopAll();
// before copy the pointers over check selectedPlayer's mission.droids since
// there might be some from the previous camapign
processPreviousCampDroids();
// move droids properly - does all the clean up code
for (psDroid = apsDroidLists[selectedPlayer]; psDroid != NULL; psDroid = psNext)
{
psNext = psDroid->psNext;
if (droidRemove(psDroid, apsDroidLists))
{
addDroid(psDroid, mission.apsDroidLists);
}
}
apsDroidLists[selectedPlayer] = NULL;
// any selectedPlayer's factories/research need to be put on holdProduction/holdresearch
for (psStruct = apsStructLists[selectedPlayer]; psStruct != NULL; psStruct = psStruct->psNext)
{
if (StructIsFactory(psStruct))
{
holdProduction(psStruct, ModeImmediate);
}
else if (psStruct->pStructureType->type == REF_RESEARCH)
{
holdResearch(psStruct, ModeImmediate);
}
}
}
//this is called via a script function to place the Limbo droids once the mission has started
void placeLimboDroids(void)
{
DROID *psDroid, *psNext;
UDWORD droidX, droidY;
PICKTILE pickRes;