forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransporter.cpp
1822 lines (1566 loc) · 49.1 KB
/
transporter.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 transporter.c
*
* Code to deal with loading/unloading, interface and flight of transporters.
*/
#include <string.h>
#include "lib/framework/frame.h"
#include "lib/framework/strres.h"
#include "lib/framework/math_ext.h"
#include "lib/widget/label.h"
#include "lib/widget/widget.h"
#include "lib/ivis_opengl/textdraw.h"
#include "stats.h"
#include "hci.h"
#include "intdisplay.h"
#include "objmem.h"
#include "transporter.h"
#include "group.h"
#include "display3d.h"
#include "mission.h"
#include "objects.h"
#include "display.h"
#include "qtscript.h"
#include "lib/script/script.h"
#include "scripttabs.h"
#include "order.h"
#include "action.h"
#include "lib/gamelib/gtime.h"
#include "console.h"
#include "lib/ivis_opengl/bitimage.h"
#include "warcam.h"
#include "selection.h"
#include "lib/sound/audio.h"
#include "lib/sound/audio_id.h"
// FIXME Direct iVis implementation include!
#include "lib/framework/fixedpoint.h"
#include "lib/ivis_opengl/piematrix.h"
#include "mapgrid.h"
#include "visibility.h"
#include "multiplay.h"
#include "qtscript.h"
//#define IDTRANS_FORM 9000 //The Transporter base form
#define IDTRANS_TABFORM 9001 //The Transporter tabbed form
#define IDTRANS_CLOSE 9002 //The close button icon
//#define IDTRANS_CONTENTFORM 9003 //The Transporter Contents form
#define IDTRANS_CONTABFORM 9004 //The Transporter Contents tabbed form
#define IDTRANS_CONTCLOSE 9005 //The close icon on the Contents form
//#define IDTRANS_DROIDS 9006 //The Droid base form
#define IDTRANS_DROIDTAB 9007 //The Droid tab form
#define IDTRANS_DROIDCLOSE 9008 //The close icon for the Droid form
//#define IDTRANS_LAUNCH 9010 //The Transporter Launch button
#define IDTRANS_START 9100 //The first button on the Transporter tab form
#define IDTRANS_END 9199 //The last button on the Transporter tab form
#define IDTRANS_STATSTART 9200 //The status button for the first Transporter
#define IDTRANS_STATEND 9299 //The status button for the last Transporter
#define IDTRANS_CONTSTART 9300 //The first button on the Transporter contents tab form
#define IDTRANS_CONTEND 9399 //The last button on the Transporter contents tab form
#define IDTRANS_DROIDSTART 9400 //The first button on the Droid tab form
#define IDTRANS_DROIDEND 9499 //The last button on the Droid tab form
#define IDTRANS_REPAIRBARSTART 9600 //The first repair status bar on Droid button
#define IDTRANS_REPAIRBAREND 9699 //The last repair status bar on Droid button
//#define IDTRANS_CAPACITY 9500 //The capacity label
/* Transporter screen positions */
#define TRANS_X OBJ_BACKX
#define TRANS_Y OBJ_BACKY
#define TRANS_WIDTH OBJ_BACKWIDTH
#define TRANS_HEIGHT OBJ_BACKHEIGHT
/*tabbed form screen positions */
#define TRANS_TABX OBJ_TABX
#define TRANS_TABY OBJ_TABY
#define TRANS_TABWIDTH OBJ_WIDTH
#define TRANS_TABHEIGHT OBJ_HEIGHT
/*Transported contents screen positions */
#define TRANSCONT_X STAT_X
#define TRANSCONT_Y STAT_Y
#define TRANSCONT_WIDTH STAT_WIDTH
#define TRANSCONT_HEIGHT STAT_HEIGHT
/*contents tabbed form screen positions */
#define TRANSCONT_TABX STAT_TABFORMX
#define TRANSCONT_TABY STAT_TABFORMY
#define TRANSCONT_TABWIDTH STAT_TABWIDTH
#define TRANSCONT_TABHEIGHT STAT_TABHEIGHT
/*droid form screen positions */
#define TRANSDROID_X RADTLX
#define TRANSDROID_Y STAT_Y
#define TRANSDROID_WIDTH STAT_WIDTH
#define TRANSDROID_HEIGHT STAT_HEIGHT
/*droid Tab form screen positions */
#define TRANSDROID_TABX STAT_TABFORMX
#define TRANSDROID_TABY STAT_TABFORMY
#define TRANSDROID_TABWIDTH STAT_WIDTH
#define TRANSDROID_TABHEIGHT STAT_HEIGHT
//start y position of the available droids buttons
#define AVAIL_STARTY 0
//defines how much space is on the Transporter
#define TRANSPORTER_CAPACITY 10
//They all take up the same amount of space now - AB 30/10/98
//defines how much space each sized droid takes up on the Transporter
#define LIGHT_DROID 1
#define MEDIUM_DROID 2
#define HEAVY_DROID 3
//max that can be available from home
#define MAX_DROIDS 80
/* the widget screen */
extern W_SCREEN *psWScreen;
/* Static variables */
static DROID *psCurrTransporter;
static DROID *g_psCurScriptTransporter = NULL;
static bool onMission;
static UDWORD g_iLaunchTime = 0;
//used for audio message for reinforcements
static bool bFirstTransporter;
//the tab positions of the DroidsAvail window
static UWORD objMajor = 0, objMinor = 0;
/*functions */
static bool intAddTransporterContents(void);
static void setCurrentTransporter(UDWORD id);
static void intRemoveTransContentNoAnim(void);
static bool intAddTransButtonForm(void);
static bool intAddTransContentsForm(void);
static bool intAddDroidsAvailForm(void);
void intRemoveTransContent(void);
static UDWORD transporterSpaceRequired(DROID const *psDroid);
static DROID* transInterfaceDroidList(void);
static void intTransporterAddDroid(UDWORD id);
static void intRemoveTransDroidsAvail(void);
static void intRemoveTransDroidsAvailNoAnim(void);
static bool _intRefreshTransporter(void);
static bool _intAddTransporter(DROID *psSelected, bool offWorld);
static void _intProcessTransporter(UDWORD id);
//initialises Transporter variables
void initTransporters(void)
{
onMission = false;
psCurrTransporter = NULL;
}
// Call to refresh the transporter screen, ie when a droids boards it.
//
bool intRefreshTransporter(void)
{
//printf("intRefreshTransporter\n");
return _intRefreshTransporter();
}
static bool _intRefreshTransporter(void)
{
// Is the transporter screen up?
if( (intMode == INT_TRANSPORTER) &&
(widgGetFromID(psWScreen,IDTRANS_FORM) != NULL))
{
bool Ret;
// Refresh it by re-adding it.
Ret = intAddTransporter(psCurrTransporter,onMission);
intMode = INT_TRANSPORTER;
return Ret;
}
return true;
}
bool intAddTransporter(DROID *psSelected, bool offWorld)
{
return(_intAddTransporter(psSelected,offWorld));
}
/*Add the Transporter Interface*/
static bool _intAddTransporter(DROID *psSelected, bool offWorld)
{
bool Animate = true;
onMission = offWorld;
psCurrTransporter = psSelected;
/*if transporter has died - close the interface - this can only happen in
multiPlayer where the transporter can be killed*/
if (bMultiPlayer)
{
if (psCurrTransporter && isDead((BASE_OBJECT *)psCurrTransporter))
{
intRemoveTransNoAnim();
return true;
}
}
// Add the main Transporter form
// Is the form already up?
if(widgGetFromID(psWScreen,IDTRANS_FORM) != NULL)
{
intRemoveTransNoAnim();
Animate = false;
}
if(intIsRefreshing()) {
Animate = false;
}
W_FORMINIT sFormInit;
sFormInit.formID = 0;
sFormInit.id = IDTRANS_FORM;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = (SWORD)TRANS_X;
sFormInit.y = (SWORD)TRANS_Y;
sFormInit.width = TRANS_WIDTH;
sFormInit.height = TRANS_HEIGHT;
// If the window was closed then do open animation.
if(Animate)
{
sFormInit.pDisplay = intOpenPlainForm;
sFormInit.disableChildren = true;
}
else
{
// otherwise just recreate it.
sFormInit.pDisplay = intDisplayPlainForm;
}
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the close button */
W_BUTINIT sButInit;
sButInit.formID = IDTRANS_FORM;
sButInit.id = IDTRANS_CLOSE;
sButInit.x = TRANS_WIDTH - CLOSE_WIDTH;
sButInit.y = 0;
sButInit.width = CLOSE_WIDTH;
sButInit.height = CLOSE_HEIGHT;
sButInit.pTip = _("Close");
sButInit.pDisplay = intDisplayImageHilight;
sButInit.UserData = PACKDWORD_TRI(0,IMAGE_CLOSEHILIGHT , IMAGE_CLOSE);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
if (!intAddTransButtonForm())
{
return false;
}
// Add the Transporter Contents form (and buttons)
if (!intAddTransporterContents())
{
return false;
}
//if on a mission - add the Droids back at home base form
if (onMission)
{
if (!intAddDroidsAvailForm())
{
return false;
}
}
return true;
}
// Add the main Transporter Contents Interface
bool intAddTransporterContents(void)
{
bool Animate = true;
// Is the form already up?
if(widgGetFromID(psWScreen,IDTRANS_CONTENTFORM) != NULL)
{
intRemoveTransContentNoAnim();
Animate = false;
}
if(intIsRefreshing()) {
Animate = false;
}
W_FORMINIT sFormInit;
sFormInit.formID = 0;
sFormInit.id = IDTRANS_CONTENTFORM;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = (SWORD)TRANSCONT_X;
sFormInit.y = (SWORD)TRANSCONT_Y;
sFormInit.width = TRANSCONT_WIDTH;
sFormInit.height = TRANSCONT_HEIGHT;
// If the window was closed then do open animation.
if(Animate)
{
sFormInit.pDisplay = intOpenPlainForm;
sFormInit.disableChildren = true;
}
else
{
// otherwise just recreate it.
sFormInit.pDisplay = intDisplayPlainForm;
}
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the close button */
W_BUTINIT sButInit;
sButInit.formID = IDTRANS_CONTENTFORM;
sButInit.id = IDTRANS_CONTCLOSE;
sButInit.x = STAT_WIDTH - CLOSE_WIDTH;
sButInit.y = 0;
sButInit.width = CLOSE_WIDTH;
sButInit.height = CLOSE_HEIGHT;
sButInit.pTip = _("Close");
sButInit.pDisplay = intDisplayImageHilight;
sButInit.UserData = PACKDWORD_TRI(0,IMAGE_CLOSEHILIGHT , IMAGE_CLOSE);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
if (bMultiPlayer)
{
//add the capacity label
W_LABINIT sLabInit;
sLabInit.formID = IDTRANS_CONTENTFORM;
sLabInit.id = IDTRANS_CAPACITY;
sLabInit.x = (SWORD)sButInit.x -40;
sLabInit.y = 0;
sLabInit.width = 16;
sLabInit.height = 16;
sLabInit.pText = "00/10";
sLabInit.pCallback = intUpdateTransCapacity;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return false;
}
}
//add the Launch button if on a mission
if (onMission)
{
W_FORMINIT sButFInit;
sButFInit.formID = IDTRANS_CONTENTFORM;
sButFInit.id = IDTRANS_LAUNCH;
sButFInit.style = WFORM_CLICKABLE | WFORM_NOCLICKMOVE;
sButFInit.x = OBJ_STARTX;
sButFInit.y = (UWORD)(STAT_SLDY - 1);
sButFInit.width = iV_GetImageWidth(IntImages,IMAGE_LAUNCHUP);
sButFInit.height = iV_GetImageHeight(IntImages,IMAGE_LAUNCHUP);
sButFInit.pTip = _("Launch Transport");
//sButInit.pText = "Launch";
sButFInit.pDisplay = intDisplayImageHilight;
sButFInit.UserData = PACKDWORD_TRI(0,IMAGE_LAUNCHDOWN,IMAGE_LAUNCHUP);
if (!widgAddForm(psWScreen, &sButFInit))
{
return false;
}
}
if (!intAddTransContentsForm())
{
return false;
}
return true;
}
/*This is used to display the transporter button and capacity when at the home base ONLY*/
bool intAddTransporterLaunch(DROID *psDroid)
{
UDWORD capacity;
DROID *psCurr, *psNext;
if (bMultiPlayer)
{
return true;
}
//do this first so that if the interface is already up it syncs with this transporter
//set up the static transporter
psCurrTransporter = psDroid;
//check the button is not already up
if(widgGetFromID(psWScreen,IDTRANS_LAUNCH) != NULL)
{
return true;
}
W_FORMINIT sButInit; //needs to be a clickable form now
sButInit.formID = 0;
sButInit.id = IDTRANS_LAUNCH;
sButInit.style = WFORM_CLICKABLE | WFORM_NOCLICKMOVE;
sButInit.x = RET_X;
sButInit.y = (SWORD)TIMER_Y;
sButInit.width = (UWORD)(10 + iV_GetImageWidth(IntImages,IMAGE_LAUNCHUP));
sButInit.height = iV_GetImageHeight(IntImages,IMAGE_LAUNCHUP);
sButInit.pTip = _("Launch Transport");
sButInit.pDisplay = intDisplayImageHilight;
sButInit.UserData = PACKDWORD_TRI(0,IMAGE_LAUNCHDOWN,IMAGE_LAUNCHUP);
if (!widgAddForm(psWScreen, &sButInit))
{
return false;
}
//add the capacity label
W_LABINIT sLabInit;
sLabInit.formID = IDTRANS_LAUNCH;
sLabInit.id = IDTRANS_CAPACITY;
sLabInit.x = (SWORD)(sButInit.x + 20);
sLabInit.y = 0;
sLabInit.width = 16;
sLabInit.height = 16;
sLabInit.pText = "00/10";
sLabInit.pCallback = intUpdateTransCapacity;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return false;
}
//when full flash the transporter button
if (psCurrTransporter && psCurrTransporter->psGroup)
{
capacity = TRANSPORTER_CAPACITY;
for (psCurr = psCurrTransporter->psGroup->psList; psCurr != NULL;
psCurr = psNext)
{
psNext = psCurr->psGrpNext;
if (psCurr != psCurrTransporter)
{
capacity -= transporterSpaceRequired(psCurr);
}
}
if (capacity <= 0)
{
flashMissionButton(IDTRANS_LAUNCH);
}
}
return true;
}
/* Remove the Transporter Launch widget from the screen*/
void intRemoveTransporterLaunch(void)
{
if(widgGetFromID(psWScreen,IDTRANS_LAUNCH) != NULL)
{
widgDelete(psWScreen, IDTRANS_LAUNCH);
}
}
/* Add the Transporter Button form */
bool intAddTransButtonForm(void)
{
UDWORD numButtons, i;
SDWORD BufferID;
DROID *psDroid;
/* Add the button form */
W_FORMINIT sFormInit;
sFormInit.formID = IDTRANS_FORM;
sFormInit.id = IDTRANS_TABFORM;
sFormInit.style = WFORM_TABBED;
sFormInit.width = TRANS_TABWIDTH;
sFormInit.height = TRANS_TABHEIGHT;
sFormInit.x = TRANS_TABX;
sFormInit.y = TRANS_TABY;
sFormInit.majorPos = WFORM_TABTOP;
sFormInit.minorPos = WFORM_TABNONE;
sFormInit.majorSize = OBJ_TABWIDTH;
sFormInit.majorOffset = OBJ_TABOFFSET;
sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2);
sFormInit.tabMajorThickness = OBJ_TABHEIGHT;
numButtons = 0;
/*work out the number of buttons */
for(psDroid = transInterfaceDroidList(); psDroid; psDroid = psDroid->psNext)
{
//only interested in Transporter droids
if ((psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER) &&
(psDroid->action != DACTION_TRANSPORTOUT &&
psDroid->action != DACTION_TRANSPORTIN ) )
{
//set the first Transporter to be the current one if not already set
if (psCurrTransporter == NULL)
{
psCurrTransporter = psDroid;
}
numButtons++;
}
}
//set the number of tabs required
sFormInit.numMajor = numForms((OBJ_BUTWIDTH + OBJ_GAP) * numButtons,
OBJ_WIDTH - OBJ_GAP);
sFormInit.pUserData = &StandardTab;
sFormInit.pTabDisplay = intDisplayTab;
if (sFormInit.numMajor > MAX_TAB_STD_SHOWN)
{ // we do NOT use smallTab icons here, so be safe and only display max # of
// standard sized tab icons.
sFormInit.numMajor = MAX_TAB_STD_SHOWN;
}
//set minor tabs to 1
for (i=0; i< sFormInit.numMajor; i++)
{
sFormInit.aNumMinors[i] = 1;
}
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the transporter and status buttons */
W_FORMINIT sBFormInit;
sBFormInit.formID = IDTRANS_TABFORM;
sBFormInit.id = IDTRANS_START;
sBFormInit.majorID = 0;
sBFormInit.minorID = 0;
sBFormInit.style = WFORM_CLICKABLE;
sBFormInit.x = OBJ_STARTX;
sBFormInit.y = OBJ_STARTY;
sBFormInit.width = OBJ_BUTWIDTH;
sBFormInit.height = OBJ_BUTHEIGHT;
W_FORMINIT sBFormInit2 = sBFormInit;
sBFormInit2.id = IDTRANS_STATSTART;
sBFormInit2.y = OBJ_STATSTARTY;
ClearObjectBuffers();
ClearTopicBuffers();
//add each button
for(psDroid = transInterfaceDroidList(); psDroid; psDroid = psDroid->psNext)
{
if ((psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER) &&
(psDroid->action != DACTION_TRANSPORTOUT &&
psDroid->action != DACTION_TRANSPORTIN ) )
{
/* Set the tip and add the button */
sBFormInit.pTip = droidGetName(psDroid);
BufferID = sBFormInit.id-IDTRANS_START;
ASSERT( BufferID < NUM_TOPICBUFFERS,"BufferID > NUM_TOPICBUFFERS" );
ClearTopicButtonBuffer(BufferID);
RENDERBUTTON_INUSE(&TopicBuffers[BufferID]);
TopicBuffers[BufferID].Data = (void*)psDroid;
sBFormInit.pUserData = &TopicBuffers[BufferID];
sBFormInit.pDisplay = intDisplayObjectButton;
if (!widgAddForm(psWScreen, &sBFormInit))
{
return false;
}
/* if the current droid matches psCurrTransporter lock the button */
if (psDroid == psCurrTransporter)
{
widgSetButtonState(psWScreen, sBFormInit.id, WBUT_LOCK);
widgSetTabs(psWScreen, IDTRANS_TABFORM, sBFormInit.majorID, 0);
}
//now do status button
sBFormInit2.pTip = NULL;
BufferID = (sBFormInit2.id-IDTRANS_STATSTART)*2+1;
ASSERT( BufferID < NUM_OBJECTBUFFERS,"BufferID > NUM_OBJECTBUFFERS" );
ClearObjectButtonBuffer(BufferID);
RENDERBUTTON_INUSE(&ObjectBuffers[BufferID]);
sBFormInit2.pUserData = &ObjectBuffers[BufferID];
sBFormInit2.pDisplay = intDisplayStatusButton;
if (!widgAddForm(psWScreen, &sBFormInit2))
{
return false;
}
/* Update the init struct for the next buttons */
sBFormInit.id += 1;
ASSERT( sBFormInit.id < IDTRANS_END,"Too many Transporter buttons" );
sBFormInit.x += OBJ_BUTWIDTH + OBJ_GAP;
if (sBFormInit.x + OBJ_BUTWIDTH + OBJ_GAP > OBJ_WIDTH)
{
sBFormInit.x = OBJ_STARTX;
sBFormInit.majorID += 1;
}
sBFormInit2.id += 1;
ASSERT( sBFormInit2.id < IDTRANS_STATEND,"Too many Transporter status buttons" );
sBFormInit2.x += OBJ_BUTWIDTH + OBJ_GAP;
if (sBFormInit2.x + OBJ_BUTWIDTH + OBJ_GAP > OBJ_WIDTH)
{
sBFormInit2.x = OBJ_STARTX;
sBFormInit2.majorID += 1;
}
}
}
return true;
}
/* Add the Transporter Contents form */
bool intAddTransContentsForm(void)
{
UDWORD i;
SDWORD BufferID;
DROID *psDroid, *psNext;
/* Add the contents form */
W_FORMINIT sFormInit;
sFormInit.formID = IDTRANS_CONTENTFORM;
sFormInit.id = IDTRANS_CONTABFORM;
sFormInit.style = WFORM_TABBED;
sFormInit.width = TRANSCONT_WIDTH;
sFormInit.height = TRANSCONT_HEIGHT;
sFormInit.x = TRANSCONT_TABX;
sFormInit.y = TRANSCONT_TABY;
sFormInit.majorPos = WFORM_TABTOP;
sFormInit.minorPos = WFORM_TABNONE;
sFormInit.majorSize = OBJ_TABWIDTH;
sFormInit.majorOffset = OBJ_TABOFFSET;
sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2);
sFormInit.tabMajorThickness = OBJ_TABHEIGHT;
//set the number of tabs required
//sFormInit.numMajor = numForms((OBJ_BUTWIDTH + OBJ_GAP) * numButtons,
// OBJ_WIDTH - OBJ_GAP);
// TABFIXME: Looks like 10 units is max for this?
sFormInit.numMajor = 1;
//set minor tabs to 1
for (i=0; i< sFormInit.numMajor; i++)
{
sFormInit.aNumMinors[i] = 1;
}
sFormInit.pUserData = &StandardTab;
sFormInit.pTabDisplay = intDisplayTab;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the transporter contents buttons */
W_FORMINIT sBFormInit;
sBFormInit.formID = IDTRANS_CONTABFORM;
sBFormInit.id = IDTRANS_CONTSTART;
sBFormInit.majorID = 0;
sBFormInit.minorID = 0;
sBFormInit.style = WFORM_CLICKABLE;
sBFormInit.x = OBJ_STARTX;
sBFormInit.y = OBJ_STARTY - OBJ_BUTHEIGHT - OBJ_GAP;
sBFormInit.width = OBJ_BUTWIDTH;
sBFormInit.height = OBJ_BUTHEIGHT;
ClearStatBuffers();
//add each button
if (psCurrTransporter != NULL)
{
for (psDroid = psCurrTransporter->psGroup->psList; psDroid != NULL && psDroid !=
psCurrTransporter; psDroid = psNext)
{
psNext = psDroid->psGrpNext;
if (psDroid->selected)
{
continue; // Droid is queued to be ejected from the transport, so don't display it.
}
/* Set the tip and add the button */
sBFormInit.pTip = droidGetName(psDroid);
BufferID = GetStatBuffer();
ASSERT( BufferID >= 0,"Unable to acquire stat buffer." );
RENDERBUTTON_INUSE(&StatBuffers[BufferID]);
StatBuffers[BufferID].Data = (void*)psDroid;
sBFormInit.pUserData = &StatBuffers[BufferID];
sBFormInit.pDisplay = intDisplayTransportButton;
if (!widgAddForm(psWScreen, &sBFormInit))
{
return false;
}
/* Update the init struct for the next button */
sBFormInit.id += 1;
ASSERT( sBFormInit.id < IDTRANS_CONTEND,"Too many Transporter Droid buttons" );
sBFormInit.x += OBJ_BUTWIDTH + OBJ_GAP;
if (sBFormInit.x + OBJ_BUTWIDTH + OBJ_GAP > TRANSCONT_WIDTH)
{
sBFormInit.x = OBJ_STARTX;
sBFormInit.y += OBJ_BUTHEIGHT + OBJ_GAP;
}
if (sBFormInit.y + OBJ_BUTHEIGHT + OBJ_GAP > TRANSCONT_HEIGHT)
{
sBFormInit.y = OBJ_STARTY;
sBFormInit.majorID += 1;
}
}
}
return true;
}
/* Add the Droids back at home form */
bool intAddDroidsAvailForm(void)
{
UDWORD numButtons, i, butPerForm;
SDWORD BufferID;
DROID *psDroid;
bool Animate = true;
// Is the form already up?
if(widgGetFromID(psWScreen,IDTRANS_DROIDS) != NULL)
{
intRemoveTransDroidsAvailNoAnim();
Animate = false;
}
if(intIsRefreshing()) {
Animate = false;
}
/* Add the droids available form */
W_FORMINIT sFormInit;
sFormInit.formID = 0;
sFormInit.id = IDTRANS_DROIDS;
sFormInit.style = WFORM_PLAIN;
sFormInit.width = TRANSDROID_WIDTH;
sFormInit.height = TRANSDROID_HEIGHT;
sFormInit.x = (SWORD)TRANSDROID_X;
sFormInit.y = (SWORD)TRANSDROID_Y;
// If the window was closed then do open animation.
if(Animate)
{
sFormInit.pDisplay = intOpenPlainForm;
sFormInit.disableChildren = true;
}
else
{
// otherwise just recreate it.
sFormInit.pDisplay = intDisplayPlainForm;
}
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the close button */
W_BUTINIT sButInit;
sButInit.formID = IDTRANS_DROIDS;
sButInit.id = IDTRANS_DROIDCLOSE;
sButInit.x = TRANSDROID_WIDTH - CLOSE_WIDTH;
sButInit.y = 0;
sButInit.width = CLOSE_WIDTH;
sButInit.height = CLOSE_HEIGHT;
sButInit.pTip = _("Close");
sButInit.pDisplay = intDisplayImageHilight;
sButInit.UserData = PACKDWORD_TRI(0,IMAGE_CLOSEHILIGHT , IMAGE_CLOSE);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
//now add the tabbed droids available form
sFormInit = W_FORMINIT();
sFormInit.formID = IDTRANS_DROIDS;
sFormInit.id = IDTRANS_DROIDTAB;
sFormInit.style = WFORM_TABBED;
sFormInit.width = TRANSDROID_TABWIDTH;
sFormInit.height = TRANSDROID_TABHEIGHT;
sFormInit.x = TRANSDROID_TABX;
sFormInit.y = TRANSDROID_TABY;
sFormInit.majorPos = WFORM_TABTOP;
sFormInit.minorPos = WFORM_TABNONE;
sFormInit.majorSize = (OBJ_TABWIDTH/2);
sFormInit.majorOffset = OBJ_TABOFFSET;
sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2);
sFormInit.tabMajorThickness = OBJ_TABHEIGHT;
sFormInit.tabMajorGap = OBJ_TABOFFSET;
//calc num buttons
numButtons = 0;
//look through the list of droids that were built before the mission
for (psDroid = mission.apsDroidLists[selectedPlayer]; psDroid; psDroid = psDroid->psNext)
{
//ignore any Transporters!
if (psDroid->droidType != DROID_TRANSPORTER && psDroid->droidType != DROID_SUPERTRANSPORTER)
{
numButtons++;
}
//quit when reached max can cope with
if (numButtons == MAX_DROIDS)
{
break;
}
}
butPerForm = ((TRANSDROID_TABWIDTH - OBJ_GAP) /
(OBJ_BUTWIDTH + OBJ_GAP)) *
((TRANSDROID_TABHEIGHT - OBJ_GAP) /
(OBJ_BUTHEIGHT + OBJ_GAP));
sFormInit.numMajor = numForms(numButtons, butPerForm);
if (sFormInit.numMajor > MAX_TAB_SMALL_SHOWN)
{ // we DO use smallTab icons here, so be safe and only display max # of
// small sized tab icons. No scrolltabs here.
sFormInit.numMajor = MAX_TAB_SMALL_SHOWN;
}
//set minor tabs to 1
for (i=0; i< sFormInit.numMajor; i++)
{
sFormInit.aNumMinors[i] = 1;
}
sFormInit.pUserData = &SmallTab;
sFormInit.pTabDisplay = intDisplayTab;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the droids available buttons */
W_FORMINIT sBFormInit;
sBFormInit.formID = IDTRANS_DROIDTAB;
sBFormInit.id = IDTRANS_DROIDSTART;
sBFormInit.majorID = 0;
sBFormInit.minorID = 0;
sBFormInit.style = WFORM_CLICKABLE;
sBFormInit.x = OBJ_STARTX;
sBFormInit.y = AVAIL_STARTY;
sBFormInit.width = OBJ_BUTWIDTH;
sBFormInit.height = OBJ_BUTHEIGHT;
ClearSystem0Buffers();
/* Add the state of repair bar for each droid*/
W_BARINIT sBarInit;
sBarInit.id = IDTRANS_REPAIRBARSTART;
sBarInit.x = STAT_TIMEBARX;
sBarInit.y = STAT_TIMEBARY;
sBarInit.width = STAT_PROGBARWIDTH;
sBarInit.height = STAT_PROGBARHEIGHT;
sBarInit.size = 50;
sBarInit.sCol = WZCOL_ACTION_PROGRESS_BAR_MAJOR;
sBarInit.sMinorCol = WZCOL_ACTION_PROGRESS_BAR_MINOR;
//add droids built before the mission
for (psDroid = mission.apsDroidLists[selectedPlayer]; psDroid != NULL; psDroid = psDroid->psNext)
{
//stop adding the buttons once MAX_DROIDS has been reached
if (sBFormInit.id == (IDTRANS_DROIDSTART + MAX_DROIDS))
{
break;
}
//don't add Transporter Droids!
if ((psDroid->droidType != DROID_TRANSPORTER && psDroid->droidType != DROID_SUPERTRANSPORTER))
{
/* Set the tip and add the button */
// sBFormInit.pTip = psDroid->pName;
sBFormInit.pTip = droidGetName(psDroid);
BufferID = GetSystem0Buffer();
ASSERT( BufferID >= 0,"Unable to acquire stat buffer." );
RENDERBUTTON_INUSE(&System0Buffers[BufferID]);
System0Buffers[BufferID].Data = (void*)psDroid;
sBFormInit.pUserData = &System0Buffers[BufferID];
sBFormInit.pDisplay = intDisplayTransportButton;
if (!widgAddForm(psWScreen, &sBFormInit))
{
return false;
}
//add bar to indicate stare of repair
sBarInit.size = (UWORD) PERCENT(psDroid->body, psDroid->originalBody);
if(sBarInit.size > 100)
{
sBarInit.size = 100;
}
sBarInit.formID = sBFormInit.id;
//sBarInit.iRange = TBAR_MAX_REPAIR;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
/* Update the init struct for the next button */
sBFormInit.id += 1;
ASSERT( sBFormInit.id < IDTRANS_DROIDEND,"Too many Droids Built buttons" );
sBFormInit.x += OBJ_BUTWIDTH + OBJ_GAP;
if (sBFormInit.x + OBJ_BUTWIDTH + OBJ_GAP > TRANSDROID_TABWIDTH)
{
sBFormInit.x = OBJ_STARTX;
sBFormInit.y += OBJ_BUTHEIGHT + OBJ_GAP;
}
if (sBFormInit.y + OBJ_BUTHEIGHT + OBJ_GAP > TRANSDROID_TABHEIGHT)
{
sBFormInit.y = AVAIL_STARTY;
sBFormInit.majorID += 1;
}
//and bar
sBarInit.id += 1;
}
}
//reset which tab we were on
if (objMajor > (UWORD)(sFormInit.numMajor - 1))
{
//set to last if have lost a tab
widgSetTabs(psWScreen, IDTRANS_DROIDTAB, (UWORD)(sFormInit.numMajor-1), objMinor);
}
else
{
//set to same tab we were on previously
widgSetTabs(psWScreen, IDTRANS_DROIDTAB, objMajor, objMinor);
}
return true;
}
/*calculates how much space is remaining on the transporter - allows droids to take
up different amount depending on their body size - currently all are set to one!*/
UDWORD calcRemainingCapacity(DROID *psTransporter)