forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign.cpp
4785 lines (4295 loc) · 143 KB
/
design.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 design.c
*
* Functions for design screen.
*
*/
#include <string.h>
#include "lib/framework/frame.h"
#include "lib/framework/strres.h"
#include "lib/widget/widget.h"
#include "objects.h"
#include "loop.h"
#include "map.h"
/* Includes direct access to render library */
#include "lib/ivis_opengl/ivisdef.h"
#include "lib/ivis_opengl/bitimage.h"
#include "lib/ivis_opengl/pieblitfunc.h"
// FIXME Direct iVis implementation include!
#include "lib/ivis_opengl/piematrix.h"//matrix code
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/screen.h"
#include "lib/ivis_opengl/piemode.h"
#include "display3d.h"
#include "edit3d.h"
#include "structure.h"
#include "research.h"
#include "function.h"
#include "lib/gamelib/gtime.h"
#include "hci.h"
#include "stats.h"
#include "game.h"
#include "power.h"
#include "lib/sound/audio.h"
#include "lib/widget/widgint.h"
#include "lib/widget/bar.h"
#include "lib/widget/form.h"
#include "lib/widget/label.h"
#include "lib/widget/button.h"
#include "lib/widget/editbox.h"
#include "lib/widget/slider.h"
#include "order.h"
#include "projectile.h"
#include "intimage.h"
#include "intdisplay.h"
#include "design.h"
#include "component.h"
#include "lib/script/script.h"
#include "scripttabs.h"
#include "main.h"
#include "objects.h"
#include "display.h"
#include "console.h"
#include "cmddroid.h"
#include "scriptextern.h"
#include "mission.h"
#include "template.h"
#include "multiplay.h"
#include "multistat.h"
#define FLASH_BUTTONS // Enable flashing body part buttons.
#define MAX_TABS 4
#define TAB_USEMAJOR 0
#define TAB_USEMINOR 1
//how many buttons can be put on the system component form
#define DES_BUTSPERFORM 8
#define MAX_DESIGN_COMPONENTS 40 // Max number of stats the design screen can cope with.
#define MAX_SYSTEM_COMPONENTS 128
/***************************************************************************************/
/* Max values for the design bar graphs */
#define DBAR_TEMPLATEMAXPOINTS 8400 //maximum body points for a template
#define DBAR_TEMPLATEMAXPOWER 1000 //maximum power points for a template
/* The maximum number of characters on the component buttons */
#define DES_COMPBUTMAXCHAR 5
/* Which type of system is displayed on the design screen */
enum DES_SYSMODE
{
IDES_SENSOR, // The sensor clickable is displayed
IDES_ECM, // The ECM clickable is displayed
IDES_CONSTRUCT, // The Constructor clickable is displayed
IDES_REPAIR, // The Repair clickable is displayed
IDES_WEAPON, // The Weapon clickable is displayed
IDES_COMMAND, // The command droid clickable is displayed
IDES_NOSYSTEM, // No system clickable has been displayed
};
static DES_SYSMODE desSysMode;
/* The major component tabs on the design screen */
#define IDES_MAINTAB 0
#define IDES_EXTRATAB 1
#define IDES_EXTRATAB2 2
/* Which component type is being selected on the design screen */
//added IDES_TURRET_A,IDES_TURRET_B,changing the name of IDES_TURRET might break exist codes
enum DES_COMPMODE
{
IDES_SYSTEM, // The main system for the droid (sensor, ECM, constructor)
IDES_TURRET, // The weapon for the droid
IDES_BODY, // The droid body
IDES_PROPULSION, // The propulsion system
IDES_NOCOMPONENT, // No system has been selected
IDES_TURRET_A, // The 2nd turret
IDES_TURRET_B, // The 3rd turret
};
static DES_COMPMODE desCompMode;
/* Which type of propulsion is being selected */
enum DES_PROPMODE
{
IDES_GROUND, // Ground propulsion (wheeled, tracked, etc).
IDES_AIR, // Air propulsion
IDES_NOPROPULSION, // No propulsion has been selected
};
static DES_PROPMODE desPropMode;
#define STRING_BUFFER_SIZE (32 * MAX_STR_LENGTH)
char StringBuffer[STRING_BUFFER_SIZE];
/* Design screen positions */
#define DESIGN_Y (59 + D_H) //the top left y value for all forms on the design screen
#define DES_NUMMAJORTABS 8
#define DES_TABTHICKNESS 0
#define DES_MAJORSIZE 40
#define DES_MINORSIZE 11
#define DES_TABBUTGAP 2
#define DES_TABBUTWIDTH 60
#define DES_TABBUTHEIGHT 46
#define DES_TITLEY 10
#define DES_TITLEHEIGHT 20
#define DES_NAMELABELX 10
#define DES_NAMELABELWIDTH 100
#define DES_TAB_LEFTOFFSET OBJ_TABOFFSET
#define DES_TAB_RIGHTOFFSET OBJ_TABOFFSET
#define DES_TAB_SYSOFFSET 0
#define DES_TAB_SYSWIDTH 12
#define DES_TAB_SYSHEIGHT 19
#define DES_TAB_WIDTH OBJ_TABWIDTH
#define DES_TAB_HEIGHT OBJ_TABHEIGHT
#define DES_TAB_SYSHORZOFFSET OBJ_TABOFFSET
#define DES_TAB_SYSGAP 4
#define DES_LEFTFORMX RET_X
#define DES_LEFTFORMY DESIGN_Y
#define DES_LEFTFORMWIDTH RET_FORMWIDTH
#define DES_LEFTFORMHEIGHT 258
#define DES_LEFTFORMBUTX 2
#define DES_LEFTFORMBUTY 2
#define DES_CENTERFORMWIDTH 315
#define DES_CENTERFORMHEIGHT 262
#define DES_CENTERFORMX POW_X
#define DES_CENTERFORMY DESIGN_Y
#define DES_3DVIEWX 8
#define DES_3DVIEWY 25
#define DES_3DVIEWWIDTH 236
#define DES_3DVIEWHEIGHT 192
#define DES_STATSFORMX POW_X
#define DES_STATSFORMY (DES_CENTERFORMY + DES_CENTERFORMHEIGHT + 3)
#define DES_STATSFORMWIDTH DES_CENTERFORMWIDTH
#define DES_STATSFORMHEIGHT 100
#define DES_PARTFORMX DES_3DVIEWX + DES_3DVIEWWIDTH + 2
#define DES_PARTFORMY DES_3DVIEWY
#define DES_PARTFORMHEIGHT DES_3DVIEWHEIGHT
#define DES_POWERFORMX DES_3DVIEWX
#define DES_POWERFORMY (DES_3DVIEWY + DES_3DVIEWHEIGHT + 2)
#define DES_POWERFORMWIDTH (DES_CENTERFORMWIDTH - 2*DES_POWERFORMX)
#define DES_POWERFORMHEIGHT 40
#define DES_RIGHTFORMX RADTLX
#define DES_RIGHTFORMY DESIGN_Y
#define DES_RIGHTFORMWIDTH (RET_FORMWIDTH + 20)
#define DES_RIGHTFORMHEIGHT DES_LEFTFORMHEIGHT
#define DES_RIGHTFORMBUTX 2
#define DES_RIGHTFORMBUTY 2
#define DES_BARFORMX 6
#define DES_BARFORMY 6
#define DES_BARFORMWIDTH 300
#define DES_BARFORMHEIGHT 85
#define DES_NAMEBOXX DES_3DVIEWX
#define DES_NAMEBOXY 6
#define DES_NAMEBOXWIDTH DES_CENTERFORMWIDTH - 2*DES_NAMEBOXX
#define DES_NAMEBOXHEIGHT 14
/* The central boxes on the design screen */
#define DES_COMPBUTWIDTH 150
#define DES_COMPBUTHEIGHT 85
#define DES_MAINBUTWIDTH 36
#define DES_MAINBUTHEIGHT 24
#define DES_ICONX 5
#define DES_ICONY 22//28
#define DES_ICONWIDTH 76
#define DES_ICONHEIGHT 53
#define DES_POWERX 1
#define DES_POWERY 6
#define DES_POWERSEPARATIONX 4
#define DES_POWERSEPARATIONY 2
#define DES_PARTSEPARATIONX 6
#define DES_PARTSEPARATIONY 6
/* Positions of stuff on the clickable boxes (Design screen) */
#define DES_CLICKLABELHEIGHT 14
#define DES_CLICKBARX 154
#define DES_CLICKBARY 7
#define DES_CLICKBARWIDTH 140
#define DES_CLICKBARHEIGHT 11
#define DES_CLICKGAP 9
#define DES_CLICKBARNAMEX 126
#define DES_CLICKBARNAMEWIDTH 20
#define DES_CLICKBARNAMEHEIGHT 19
#define DES_CLICKBARMAJORRED 255 //0xcc
#define DES_CLICKBARMAJORGREEN 235 //0
#define DES_CLICKBARMAJORBLUE 19 //0
#define DES_CLICKBARMINORRED 0x55
#define DES_CLICKBARMINORGREEN 0
#define DES_CLICKBARMINORBLUE 0
#define DES_WEAPONBUTTON_X 26
#define DES_SYSTEMBUTTON_X 68
#define DES_SYSTEMBUTTON_Y 10
// Stat bar y positions.
#define DES_STATBAR_Y1 (DES_CLICKBARY)
#define DES_STATBAR_Y2 (DES_CLICKBARY+DES_CLICKBARHEIGHT + DES_CLICKGAP)
#define DES_STATBAR_Y3 (DES_CLICKBARY+(DES_CLICKBARHEIGHT + DES_CLICKGAP)*2)
#define DES_STATBAR_Y4 (DES_CLICKBARY+(DES_CLICKBARHEIGHT + DES_CLICKGAP)*3)
/* the widget screen */
extern W_SCREEN *psWScreen;
/* default droid design template */
DROID_TEMPLATE sDefaultDesignTemplate;
static void desSetupDesignTemplates();
static void intDisplayTemplateButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void setDesignPauseState();
static void resetDesignPauseState();
static bool intAddTemplateButtons(UDWORD formID, UDWORD formWidth, UDWORD formHeight,
UDWORD butWidth, UDWORD butHeight, UDWORD gap, DROID_TEMPLATE *psSelected);
static void intDisplayDesignForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours);
/* Set the current mode of the design screen, and display the appropriate component lists */
static void intSetDesignMode(DES_COMPMODE newCompMode);
/* Set all the design bar graphs from a design template */
static void intSetDesignStats(DROID_TEMPLATE *psTemplate);
/* Set up the system clickable form of the design screen given a set of stats */
static bool intSetSystemForm(COMPONENT_STATS *psStats);
/* Set up the propulsion clickable form of the design screen given a set of stats */
static bool intSetPropulsionForm(PROPULSION_STATS *psStats);
/* Add the component tab form to the design screen */
static bool intAddComponentForm(UDWORD numButtons);
/* Add the template tab form to the design screen */
static bool intAddTemplateForm(DROID_TEMPLATE *psSelected);
/* Add the Major system tab form to the design screen */
// count the number of available components
static UDWORD intNumAvailable(UBYTE *aAvailable, UDWORD numEntries,
COMPONENT_STATS *asStats, UDWORD size);
/* Add the system buttons (weapons, command droid, etc) to the design screen */
static bool intAddSystemButtons(DES_COMPMODE mode);
/* Add the component buttons to the main tab of the system or component form */
static bool intAddComponentButtons(COMPONENT_STATS *psStats, UDWORD size,
UBYTE *aAvailable, UDWORD numEntries,
UDWORD compID,UDWORD WhichTab);
/* Add the component buttons to the main tab of the component form */
static bool intAddExtraSystemButtons(UDWORD sensorIndex, UDWORD ecmIndex,
UDWORD constIndex, UDWORD repairIndex, UDWORD brainIndex);
/* Set the bar graphs for the system clickable */
static void intSetSystemStats(COMPONENT_STATS *psStats);
/* Set the shadow bar graphs for the system clickable */
static void intSetSystemShadowStats(COMPONENT_STATS *psStats);
/* Set the bar graphs for the sensor stats */
static void intSetSensorStats(SENSOR_STATS *psStats);
/* Set the shadow bar graphs for the sensor stats */
static void intSetSensorShadowStats(SENSOR_STATS *psStats);
/* Set the bar graphs for the ECM stats */
static void intSetECMStats(ECM_STATS *psStats);
/* Set the shadow bar graphs for the ECM stats */
static void intSetECMShadowStats(ECM_STATS *psStats);
/* Set the bar graphs for the Repair stats */
static void intSetRepairStats(REPAIR_STATS *psStats);
/* Set the shadow bar graphs for the Repair stats */
static void intSetRepairShadowStats(REPAIR_STATS *psStats);
/* Set the bar graphs for the Constructor stats */
static void intSetConstructStats(CONSTRUCT_STATS *psStats);
/* Set the shadow bar graphs for the Constructor stats */
static void intSetConstructShadowStats(CONSTRUCT_STATS *psStats);
/* Set the bar graphs for the Weapon stats */
static void intSetWeaponStats(WEAPON_STATS *psStats);
/* Set the shadow bar graphs for the weapon stats */
static void intSetWeaponShadowStats(WEAPON_STATS *psStats);
/* Set the bar graphs for the Body stats */
static void intSetBodyStats(BODY_STATS *psStats);
/* Set the shadow bar graphs for the Body stats */
static void intSetBodyShadowStats(BODY_STATS *psStats);
/* Set the bar graphs for the Propulsion stats */
static void intSetPropulsionStats(PROPULSION_STATS *psStats);
/* Set the shadow bar graphs for the Propulsion stats */
static void intSetPropulsionShadowStats(PROPULSION_STATS *psStats);
/* Sets the Design Power Bar for a given Template */
static void intSetDesignPower(DROID_TEMPLATE *psTemplate);
/* Sets the Power shadow Bar for the current Template with new stat*/
static void intSetTemplatePowerShadowStats(COMPONENT_STATS *psStats);
/* Sets the Body Points Bar for a given Template */
static void intSetBodyPoints(DROID_TEMPLATE *psTemplate);
/* Sets the Body Points shadow Bar for the current Template with new stat*/
static void intSetTemplateBodyShadowStats(COMPONENT_STATS *psStats);
/* set flashing flag for button */
static void intSetButtonFlash( UDWORD id, bool bFlash );
/*Function to set the shadow bars for all the stats when the mouse is over
the Template buttons*/
static void runTemplateShadowStats(UDWORD id);
static bool intCheckValidWeaponForProp(void);
static bool checkTemplateIsVtol(DROID_TEMPLATE *psTemplate);
/* save the current Template if valid. Return true if stored */
static bool saveTemplate();
static void desCreateDefaultTemplate( void );
/**
* Updates the status of the stored template toggle button.
*
* @param isStored If the template is stored or not.
*/
static void updateStoreButton(bool isStored);
/* The current name of the design */
static char aCurrName[WIDG_MAXSTR];
/* Store a list of component stats pointers for the design screen */
extern UDWORD maxComponent;
extern UDWORD numComponent;
extern COMPONENT_STATS **apsComponentList;
extern UDWORD maxExtraSys;
extern UDWORD numExtraSys;
extern COMPONENT_STATS **apsExtraSysList;
/* The button id of the component that is in the design */
static UDWORD desCompID;
static UDWORD droidTemplID;
/* The current design being edited on the design screen */
DROID_TEMPLATE sCurrDesign;
static void intDisplayStatForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void intDisplayViewForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void intDisplayComponentButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
extern bool bRender3DOnly;
/* Add the design widgets to the widget screen */
static bool _intAddDesign( bool bShowCentreScreen )
{
W_FORMINIT sFormInit;
W_LABINIT sLabInit;
W_EDBINIT sEdInit;
W_BUTINIT sButInit;
W_BARINIT sBarInit;
desSetupDesignTemplates();
//set which states are to be paused while design screen is up
setDesignPauseState();
if((GetGameMode() == GS_NORMAL) && !bMultiPlayer)
{ // Only do this in main game.
bool radOnScreen = radarOnScreen;
bRender3DOnly = true;
radarOnScreen = false;
// Just display the 3d, no interface
displayWorld();
// Upload the current display back buffer into system memory.
pie_UploadDisplayBuffer();
radarOnScreen = radOnScreen;
bRender3DOnly = false;
}
/* Add the main design form */
sFormInit.formID = 0;
sFormInit.id = IDDES_FORM;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = (SWORD)DES_CENTERFORMX; //0;
sFormInit.y = (SWORD)DES_CENTERFORMY; //0;
sFormInit.width = DES_CENTERFORMWIDTH; //DISP_WIDTH-1;
sFormInit.height = DES_CENTERFORMHEIGHT; //DES_BASEHEIGHT;
sFormInit.pDisplay = intDisplayPlainForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* add the edit name box */
sEdInit.formID = IDDES_FORM;
sEdInit.id = IDDES_NAMEBOX;
sEdInit.x = DES_NAMEBOXX;
sEdInit.y = DES_NAMEBOXY;
sEdInit.width = DES_NAMEBOXWIDTH;
sEdInit.height = DES_NAMEBOXHEIGHT;
sEdInit.pText = _("New Vehicle");
sEdInit.pBoxDisplay = intDisplayEditBox;
if (!widgAddEditBox(psWScreen, &sEdInit))
{
return false;
}
CurrentStatsTemplate = NULL;
/* Initialise the current design */
sCurrDesign = sDefaultDesignTemplate;
sCurrDesign.pName = NULL;
sCurrDesign.stored = false;
sstrcpy(aCurrName, _("New Vehicle"));
sstrcpy(sCurrDesign.aName, aCurrName);
/* Add the design templates form */
if (!intAddTemplateForm(NULL)) // Was psCurrTemplate instead of NULL, but psCurrTemplate was always NULL. Deleted psCurrTemplate, but leaving this here, in case intAddTemplateForm(NULL) does something useful.
{
return false;
}
/* Add the 3D View form */
sFormInit.formID = IDDES_FORM;
sFormInit.id = IDDES_3DVIEW;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = DES_3DVIEWX;
sFormInit.y = DES_3DVIEWY;
sFormInit.width = DES_3DVIEWWIDTH;
sFormInit.height = DES_3DVIEWHEIGHT;
sFormInit.pDisplay = intDisplayViewForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the part button form */
sFormInit.formID = IDDES_FORM;
sFormInit.id = IDDES_PARTFORM;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = DES_PARTFORMX;
sFormInit.y = DES_PARTFORMY;
sFormInit.width = (UWORD)(iV_GetImageWidth(IntImages, IMAGE_DES_TURRET) +
2*DES_PARTSEPARATIONX);
sFormInit.height = DES_PARTFORMHEIGHT;
sFormInit.pDisplay = intDisplayDesignForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
// add the body part button
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_BODYBUTTON;
sButInit.x = DES_PARTSEPARATIONX;
sButInit.y = DES_PARTSEPARATIONY;
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_BODY);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_BODY);
sButInit.pTip = _("Vehicle Body");
#ifdef FLASH_BUTTONS
sButInit.pDisplay = intDisplayButtonFlash;
#else
sButInit.pDisplay = intDisplayButtonHilight;
#endif
sButInit.UserData = PACKDWORD_TRI(1, IMAGE_DES_BODYH, IMAGE_DES_BODY);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
// add the propulsion part button
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_PROPBUTTON;
sButInit.x = DES_PARTSEPARATIONX;
sButInit.y = (UWORD)(iV_GetImageHeight(IntImages, IMAGE_DES_PROPULSION) +
2 * DES_PARTSEPARATIONY);
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_PROPULSION);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_PROPULSION);
sButInit.pTip = _("Vehicle Propulsion");
#ifdef FLASH_BUTTONS
sButInit.pDisplay = intDisplayButtonFlash;
#else
sButInit.pDisplay = intDisplayButtonHilight;
#endif
sButInit.UserData = PACKDWORD_TRI(1, IMAGE_DES_PROPULSIONH, IMAGE_DES_PROPULSION);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
// add the turret part button
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_SYSTEMBUTTON;
sButInit.x = DES_PARTSEPARATIONX;
sButInit.y = (UWORD)(iV_GetImageHeight(IntImages, IMAGE_DES_PROPULSION) +
iV_GetImageHeight(IntImages, IMAGE_DES_BODY) +
3*DES_PARTSEPARATIONY);
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_TURRET);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_TURRET);
sButInit.pTip = _("Vehicle Turret");
#ifdef FLASH_BUTTONS
sButInit.pDisplay = intDisplayButtonFlash;
#else
sButInit.pDisplay = intDisplayButtonHilight;
#endif
sButInit.UserData = PACKDWORD_TRI(1, IMAGE_DES_TURRETH, IMAGE_DES_TURRET);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
// add the turret_a button
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_WPABUTTON;
sButInit.x = DES_PARTSEPARATIONX;
// use BODY height for now
sButInit.y = (UWORD)(iV_GetImageHeight(IntImages, IMAGE_DES_PROPULSION) +
iV_GetImageHeight(IntImages, IMAGE_DES_BODY) +
iV_GetImageHeight(IntImages, IMAGE_DES_BODY) +
4*DES_PARTSEPARATIONY);
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_TURRET);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_TURRET);
sButInit.pTip = _("Vehicle Turret");
#ifdef FLASH_BUTTONS
sButInit.pDisplay = intDisplayButtonFlash;
#else
sButInit.pDisplay = intDisplayButtonHilight;
#endif
sButInit.UserData = PACKDWORD_TRI(1, IMAGE_DES_TURRETH, IMAGE_DES_TURRET);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
// add the turret_b button
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_WPBBUTTON;
sButInit.x = DES_PARTSEPARATIONX;
//use body height for now
sButInit.y = (UWORD)(iV_GetImageHeight(IntImages, IMAGE_DES_PROPULSION) +
iV_GetImageHeight(IntImages, IMAGE_DES_BODY) +
iV_GetImageHeight(IntImages, IMAGE_DES_BODY) +
iV_GetImageHeight(IntImages, IMAGE_DES_BODY) +
5*DES_PARTSEPARATIONY);
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_TURRET);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_TURRET);
sButInit.pTip = _("Vehicle Turret");
#ifdef FLASH_BUTTONS
sButInit.pDisplay = intDisplayButtonFlash;
#else
sButInit.pDisplay = intDisplayButtonHilight;
#endif
sButInit.UserData = PACKDWORD_TRI(1, IMAGE_DES_TURRETH, IMAGE_DES_TURRET);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
/* add the delete button */
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_BIN;
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_BIN);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_BIN);
sButInit.x = DES_PARTSEPARATIONX;
sButInit.y = (UWORD)(DES_PARTFORMHEIGHT - sButInit.height - DES_PARTSEPARATIONY);
sButInit.pTip = _("Delete Design");
sButInit.pDisplay = intDisplayButtonHilight;
sButInit.UserData = PACKDWORD_TRI(0,IMAGE_DES_BINH, IMAGE_DES_BIN);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
// Add the store template button
sButInit.formID = IDDES_PARTFORM;
sButInit.id = IDDES_STOREBUTTON;
sButInit.style = WBUT_PLAIN;
sButInit.width = iV_GetImageWidth(IntImages, IMAGE_DES_SAVE);
sButInit.height = iV_GetImageHeight(IntImages, IMAGE_DES_SAVE);
sButInit.x = DES_PARTSEPARATIONX;
sButInit.y = DES_PARTFORMHEIGHT - 2*sButInit.height - 2*DES_PARTSEPARATIONY;
sButInit.pTip = _("Store Template");
sButInit.FontID = font_regular;
sButInit.pDisplay = intDisplayButtonHilight;
sButInit.UserData = PACKDWORD_TRI(0, IMAGE_DES_SAVEH, IMAGE_DES_SAVE);
if (!widgAddButton(psWScreen, &sButInit))
{
return false;
}
/* add central stats form */
sFormInit.formID = 0;
sFormInit.id = IDDES_STATSFORM;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = (SWORD)DES_STATSFORMX;
sFormInit.y = (SWORD)DES_STATSFORMY;
sFormInit.width = DES_STATSFORMWIDTH;
sFormInit.height = DES_STATSFORMHEIGHT;
sFormInit.pDisplay = intDisplayPlainForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the body form */
sFormInit.formID = IDDES_STATSFORM;
sFormInit.id = IDDES_BODYFORM;
sFormInit.style = WFORM_CLICKABLE | WFORM_NOCLICKMOVE;
sFormInit.width = DES_BARFORMWIDTH;
sFormInit.height = DES_BARFORMHEIGHT;
sFormInit.x = DES_BARFORMX;
sFormInit.y = DES_BARFORMY;
sFormInit.pDisplay = intDisplayStatForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the graphs for the Body */
sBarInit.formID = IDDES_BODYFORM;
sBarInit.id = IDDES_BODYARMOUR_K;
sBarInit.x = DES_CLICKBARX;
sBarInit.y = DES_STATBAR_Y1; //DES_CLICKBARY;
sBarInit.width = DES_CLICKBARWIDTH;
sBarInit.height = DES_CLICKBARHEIGHT;
sBarInit.size = 50;
sBarInit.sCol.byte.r = DES_CLICKBARMAJORRED;
sBarInit.sCol.byte.g = DES_CLICKBARMAJORGREEN;
sBarInit.sCol.byte.b = DES_CLICKBARMAJORBLUE;
sBarInit.sMinorCol.byte.r = DES_CLICKBARMINORRED;
sBarInit.sMinorCol.byte.g = DES_CLICKBARMINORGREEN;
sBarInit.sMinorCol.byte.b = DES_CLICKBARMINORBLUE;
sBarInit.pDisplay = intDisplayStatsBar;
sBarInit.pTip = _("Kinetic Armour");
sBarInit.iRange = getMaxBodyArmour();
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return true;
}
sBarInit.id = IDDES_BODYARMOUR_H;
sBarInit.y = DES_STATBAR_Y2; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.pTip = _("Thermal Armour");
sBarInit.iRange = getMaxBodyArmour();
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return true;
}
//body points added AB 3/9/97
//sBarInit.id = IDDES_BODYPOINTS;
//sBarInit.y += DES_CLICKBARHEIGHT + DES_CLICKGAP;
//if (!widgAddBarGraph(psWScreen, &sBarInit))
//{
// return true;
//}
sBarInit.id = IDDES_BODYPOWER;
sBarInit.y = DES_STATBAR_Y3; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.pTip = _("Engine Output");
sBarInit.iRange = (UWORD)getMaxBodyPower();//DBAR_BODYMAXPOWER;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return true;
}
sBarInit.id = IDDES_BODYWEIGHT;
sBarInit.y = DES_STATBAR_Y4; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit.pTip = _("Weight");
sBarInit.iRange = (UWORD)getMaxComponentWeight();//DBAR_MAXWEIGHT;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return true;
}
/* Add the labels for the Body */
sLabInit.formID = IDDES_BODYFORM;
sLabInit.id = IDDES_BODYARMOURKLAB;
sLabInit.x = DES_CLICKBARNAMEX;
sLabInit.y = DES_CLICKBARY - DES_CLICKBARHEIGHT/3;
sLabInit.width = DES_CLICKBARNAMEWIDTH;
sLabInit.height = DES_CLICKBARHEIGHT;
sLabInit.pTip = _("Kinetic Armour");
sLabInit.pDisplay = intDisplayImage;
//just to confuse things even more - the graphics were named incorrectly!
sLabInit.UserData = IMAGE_DES_ARMOUR_EXPLOSIVE;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return true;
}
sLabInit.id = IDDES_BODYARMOURHLAB;
sLabInit.y += DES_CLICKBARHEIGHT + DES_CLICKGAP;
sLabInit.pTip = _("Thermal Armour");
sLabInit.pDisplay = intDisplayImage;
sLabInit.UserData = IMAGE_DES_ARMOUR_KINETIC;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return true;
}
//body points added AB 3/9/97
//sLabInit.id = IDDES_BODYPOINTSLAB;
//sLabInit.y += DES_CLICKBARHEIGHT + DES_CLICKGAP;
//sLabInit.pText = "Body Points";
//sLabInit.pTip = sLabInit.pText;
//sLabInit.pDisplay = intDisplayImage;
//sLabInit.pUserData = (void*)IMAGE_DES_BODYPOINTS;
//if (!widgAddLabel(psWScreen, &sLabInit))
//{
// return true;
//}
sLabInit.id = IDDES_BODYPOWERLAB;
sLabInit.y += DES_CLICKBARHEIGHT + DES_CLICKGAP;
sLabInit.pTip = _("Engine Output");
sLabInit.pDisplay = intDisplayImage;
sLabInit.UserData = IMAGE_DES_POWER;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return true;
}
sLabInit.id = IDDES_BODYWEIGHTLAB;
sLabInit.y += DES_CLICKBARHEIGHT + DES_CLICKGAP;
sLabInit.pTip = _("Weight");
sLabInit.pDisplay = intDisplayImage;
sLabInit.UserData = IMAGE_DES_WEIGHT;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return true;
}
/* add power/points bar subform */
sFormInit = W_FORMINIT();
sFormInit.formID = IDDES_FORM;
sFormInit.id = IDDES_POWERFORM;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = DES_POWERFORMX;
sFormInit.y = DES_POWERFORMY;
sFormInit.width = DES_POWERFORMWIDTH;
sFormInit.height = DES_POWERFORMHEIGHT;
sFormInit.pDisplay = intDisplayDesignForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Set the text colour for the form */
widgSetColour(psWScreen, IDDES_POWERFORM, WCOL_TEXT, WZCOL_DESIGN_POWER_FORM_BACKGROUND);
/* Add the design template power bar and label*/
sLabInit.formID = IDDES_POWERFORM;
sLabInit.id = IDDES_TEMPPOWERLAB;
sLabInit.x = DES_POWERX;
sLabInit.y = DES_POWERY;
sLabInit.pTip = _("Total Power Required");
sLabInit.pDisplay = intDisplayImage;
sLabInit.UserData = IMAGE_DES_POWER;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return true;
}
sBarInit = W_BARINIT();
sBarInit.formID = IDDES_POWERFORM;
sBarInit.id = IDDES_POWERBAR;
sBarInit.x = (SWORD)(DES_POWERX + DES_POWERSEPARATIONX +
iV_GetImageWidth(IntImages,IMAGE_DES_BODYPOINTS));
sBarInit.y = DES_POWERY;
sBarInit.width = (SWORD)(DES_POWERFORMWIDTH - 15 -
iV_GetImageWidth(IntImages,IMAGE_DES_BODYPOINTS));
sBarInit.height = iV_GetImageHeight(IntImages,IMAGE_DES_POWERBACK);
sBarInit.pDisplay = intDisplayDesignPowerBar;//intDisplayStatsBar;
sBarInit.pTip = _("Total Power Required");
sBarInit.iRange = DBAR_TEMPLATEMAXPOWER;//WBAR_SCALE;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
/* Add the design template body points bar and label*/
sLabInit.formID = IDDES_POWERFORM;
sLabInit.id = IDDES_TEMPBODYLAB;
sLabInit.x = DES_POWERX;
sLabInit.y = (SWORD)(DES_POWERY + DES_POWERSEPARATIONY +
iV_GetImageHeight(IntImages,IMAGE_DES_BODYPOINTS));
sLabInit.pTip = _("Total Body Points");
sLabInit.pDisplay = intDisplayImage;
sLabInit.UserData = IMAGE_DES_BODYPOINTS;
if (!widgAddLabel(psWScreen, &sLabInit))
{
return true;
}
sBarInit = W_BARINIT();
sBarInit.formID = IDDES_POWERFORM;
sBarInit.id = IDDES_BODYPOINTS;
sBarInit.x = (SWORD)(DES_POWERX + DES_POWERSEPARATIONX +
iV_GetImageWidth(IntImages,IMAGE_DES_BODYPOINTS));
sBarInit.y = (SWORD)(DES_POWERY + DES_POWERSEPARATIONY + 4 +
iV_GetImageHeight(IntImages,IMAGE_DES_BODYPOINTS));
sBarInit.width = (SWORD)(DES_POWERFORMWIDTH - 15 -
iV_GetImageWidth(IntImages,IMAGE_DES_BODYPOINTS));
sBarInit.height = iV_GetImageHeight(IntImages,IMAGE_DES_POWERBACK);
sBarInit.pDisplay = intDisplayDesignPowerBar;//intDisplayStatsBar;
sBarInit.pTip = _("Total Body Points");
sBarInit.iRange = DBAR_TEMPLATEMAXPOINTS;//(UWORD)getMaxBodyPoints();//DBAR_BODYMAXPOINTS;
if (!widgAddBarGraph(psWScreen, &sBarInit))
{
return false;
}
/* Add the variable bits of the design screen and set the bar graphs */
desCompMode = IDES_NOCOMPONENT;
desSysMode = IDES_NOSYSTEM;
desPropMode = IDES_NOPROPULSION;
intSetDesignStats(&sCurrDesign);
intSetBodyPoints(&sCurrDesign);
intSetDesignPower(&sCurrDesign);
intSetDesignMode(IDES_BODY);
/* hide design and component forms until required */
if ( bShowCentreScreen == false )
{
widgHide( psWScreen, IDDES_FORM );
}
widgHide( psWScreen, IDDES_STATSFORM );
widgHide( psWScreen, IDDES_RIGHTBASE );
return true;
}
/* set up droid templates before going into design screen */
void desSetupDesignTemplates(void)
{
/* init template list */
apsTemplateList.clear();
apsTemplateList.push_back(&sDefaultDesignTemplate);
for (std::list<DROID_TEMPLATE>::iterator i = localTemplates.begin(); i != localTemplates.end(); ++i)
{
DROID_TEMPLATE *psTempl = &*i; // &* changes iterators into pointers.
/* add template to list if not a transporter,
* cyborg, person or command droid,
*/
if (psTempl->droidType != DROID_TRANSPORTER &&
psTempl->droidType != DROID_SUPERTRANSPORTER &&
psTempl->droidType != DROID_CYBORG &&
psTempl->droidType != DROID_CYBORG_SUPER &&
psTempl->droidType != DROID_CYBORG_CONSTRUCT &&
psTempl->droidType != DROID_CYBORG_REPAIR &&
psTempl->droidType != DROID_PERSON &&
researchedTemplate(psTempl, selectedPlayer))
{
apsTemplateList.push_back(psTempl);
}
}
}
/* Add the design template form */
static bool _intAddTemplateForm(DROID_TEMPLATE *psSelected)
{
UDWORD numButtons, butPerForm;
UDWORD i;
/* Count the number of minor tabs needed for the template form */
numButtons = apsTemplateList.size();
/* Calculate how many buttons will go on a single form */
butPerForm = ((DES_LEFTFORMWIDTH - DES_TABTHICKNESS - DES_TABBUTGAP) /
(DES_TABBUTWIDTH + DES_TABBUTGAP)) *
((DES_LEFTFORMHEIGHT - DES_TABTHICKNESS - DES_TABBUTGAP) /
(DES_TABBUTHEIGHT + DES_TABBUTGAP));
/* add a form to place the tabbed form on */
W_FORMINIT sFormInit;
sFormInit.formID = 0;
sFormInit.id = IDDES_TEMPLBASE;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = (SWORD)RET_X;
sFormInit.y = (SWORD)DESIGN_Y;
sFormInit.width = RET_FORMWIDTH;
sFormInit.height = DES_LEFTFORMHEIGHT + 4;
sFormInit.pDisplay = intDisplayPlainForm;
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Add the design templates form */
sFormInit = W_FORMINIT();
sFormInit.formID = IDDES_TEMPLBASE; //IDDES_FORM;
sFormInit.id = IDDES_TEMPLFORM;
sFormInit.style = WFORM_TABBED;
sFormInit.x = 2;//DES_LEFTFORMX; //DES_TEMPLX;
sFormInit.y = 2;//DES_LEFTFORMY; //DES_TEMPLY;
sFormInit.width = DES_LEFTFORMWIDTH; //DES_TEMPLWIDTH;
sFormInit.height = DES_LEFTFORMHEIGHT; //DES_TEMPLHEIGHT;
sFormInit.numMajor = numForms(numButtons, butPerForm);
sFormInit.majorPos = WFORM_TABTOP;
sFormInit.minorPos = WFORM_TABNONE;
sFormInit.majorSize = DES_TAB_WIDTH;
sFormInit.majorOffset = DES_TAB_LEFTOFFSET;
sFormInit.tabVertOffset = (DES_TAB_HEIGHT/2); //(DES_TAB_HEIGHT/2)+2;
sFormInit.tabMajorThickness = DES_TAB_HEIGHT;
sFormInit.pUserData = &StandardTab;
sFormInit.pTabDisplay = intDisplayTab;
if (sFormInit.numMajor > MAX_TAB_STD_SHOWN)
{
// we do NOT want more than this amount of tabs on design screen.
// 40 templates should be more than enough.
sFormInit.numMajor = MAX_TAB_STD_SHOWN;
// If we were to change this in future then :
//Just switching from normal sized tabs to smaller ones to fit more in form.
// sFormInit.pUserData = &SmallTab;
// sFormInit.majorSize /= 2;
// Change MAX_TAB_STD_SHOWN to ..SMALL_SHOWN, this will give us 80 templates max.
}
for (i=0; i< sFormInit.numMajor; i++)
{
sFormInit.aNumMinors[i] = 1;
}
if (!widgAddForm(psWScreen, &sFormInit))
{
return false;
}
/* Put the buttons on it */
if (!intAddTemplateButtons(IDDES_TEMPLFORM, DES_LEFTFORMWIDTH - DES_TABTHICKNESS,
DES_LEFTFORMHEIGHT - DES_TABTHICKNESS,
DES_TABBUTWIDTH, DES_TABBUTHEIGHT, DES_TABBUTGAP,
psSelected ))
{
return false;
}
return true;
}
/* Add the droid template buttons to a form */
static bool intAddTemplateButtons(UDWORD formID, UDWORD formWidth, UDWORD formHeight,
UDWORD butWidth, UDWORD butHeight, UDWORD gap, DROID_TEMPLATE *psSelected)
{
DROID_TEMPLATE *psTempl = NULL;
char aButText[DES_COMPBUTMAXCHAR + 1];
SDWORD BufferID;
char TempString[256];
int BufferPos = 0;
ClearStatBuffers();