-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhangercontrol.bmx
2748 lines (2442 loc) · 76.7 KB
/
hangercontrol.bmx
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
'a component to add to the ships. can be a gun, armour, engines, etc.
Global componentList:TList = New TList'a list of global component archtypes
Type Component
Field name$
Field desc$ 'a short description of the component
Field x,y 'when placed into a ship, at this position of the ship's configuration
Field shape[5,5] '5x5 grid of what squares this component takes up: 0=empty|1=filled|2=attachment point
Field rgb[3] 'the color of this component
Field rot '0 = 0d | 1 = 90d | 2 = 180d | 3 = 270d
Field class$ 'what color the item should be, and when it consumes power: "gun"|"engine"|"misc"
Field unique = False 'TRUE/FALSE, whether this component is a unique or if it's stock (NOW DEFUNCT)
Field cost = 200 'point cost to unlock this component
Field mass# 'how much mass this component adds
Field armourBonus # 'how much armour to add
Field juiceBonus# 'max juice stockpile bonus
Field engineBonus # 'adds to the engine rating, which (along with mass) sets maxspeed and thrust.
Field thrustBonus# 'adds to the ship's thrust
Field pointBonus 'ability point bonus
Field damageBonus # '% damage added to all guns
Field burstBonus 'number of shots in a burst
Field recycleBonus# 'alters time between shots. usually negative.
Field shotspeedBonus# 'alters the speed of shots
Field fortify# 'damage resistance arc this component proffers
Field fortify_range# = 90
Field fortify_offset# 'offset the arc from center
Field fortify_ramming = False'if it only reduces collision damage
Field gunList:TList = New TList
Field preq[4] 'the type and number of power squares this component needs to work. 0="energy" | 1="munitions" | 2=unused | 3="any"
Field alt = False 'whether weapons will be tied to the alternate button
Field plugged = True 'whether or not it's on its requisite power tile
Field accepts_addons = True 'can we stick addons on this component?
Field addon = False 'is THIS component an addon? (addons are always powered, generally have a single attachment tile, add to parent bonuses)
Field addonList:TList = New TList 'list of addon components attached to this. cleared every loop, they have to re-add themselves constantly
Field locked = False 'TRUE/FALSE whether the player can modify the location of this component (used mostly for engines)
Field unlockable = True'can the player obtain this component?
Field special = False'VIP-only?
'makes self a copy of the provided component (if no component is provided, search compList for the provided name
Method copyComp(_comp:Component,_name$="")
If _comp = Null
For Local c:Component = EachIn componentList
If c.name = _name Then _comp = c
Next
EndIf
'component properties
class = _comp.class
name = _comp.name
desc = _comp.desc
addon = _comp.addon
accepts_addons = _comp.accepts_addons
rgb[0] = _comp.rgb[0]
rgb[1] = _comp.rgb[1]
rgb[2] = _comp.rgb[2]
x = 0
y = 0
rot = 0
locked = _comp.locked
For Local xp = 0 To 4
For Local yp = 0 To 4
shape[xp,yp] = _comp.shape[xp,yp]
Next
Next
'ship modification stats
cost = _comp.cost
armourBonus = _comp.armourBonus
juiceBonus = _comp.juiceBonus
engineBonus = _comp.engineBonus
thrustBonus = _comp.thrustBonus
pointBonus = _comp.pointBonus
damageBonus = _comp.damageBonus
burstBonus = _comp.burstBonus
recycleBonus = _comp.recycleBonus
shotspeedBonus = _comp.shotspeedBonus
fortify = _comp.fortify
fortify_offset = _comp.fortify_offset
fortify_range = _comp.fortify_range
fortify_ramming = _comp.fortify_ramming
preq[0] = _comp.preq[0]
preq[1] = _comp.preq[1]
preq[2] = _comp.preq[2]
preq[3] = _comp.preq[3]
For Local g:Gun = EachIn _comp.gunList
gunList.addLast(new_gun(g.name))
Next
alt = _comp.alt
EndMethod
Method loadSelf(cFile:TStream)
'get the name of the next component
Local compName$ = ReadLine(cFile)
'see if it's a stock component or a unique
If Right(compName,7) = "_unique" Then unique = True
'get the stats for the stock component
For Local c:Component = EachIn componentList
If c.name = compName
copyComp(c)
EndIf
Next
'read how it's configured on the ship, exactly
x = ReadByte(cFile)
y = ReadByte(cFile)
rot = ReadInt(cFile)
plugged = ReadByte(cFile)
locked = ReadByte(cFile)
EndMethod
Method saveSelf(cFile:TStream)
'write the name of the component
Local compName$ = name
WriteLine(cFile, compName)
'read how it's configured on the ship, exactly
WriteByte(cFile, x)
WriteByte(cFile, y)
WriteInt(cFile, rot)
WriteByte(cFile, plugged)
WriteByte(cFile, locked)
EndMethod
'sets shape to one of a whole bunch of presets
Method setShape(_id)
'clear previous shape
For Local xp = 0 To 4
For Local yp = 0 To 4
shape[xp,yp] = 0
Next
Next
'set the new shape
Select _id
Case 0 '1x1
shape[0,0]=1
Case 1 '2x1
shape[0,0]=1
shape[1,0]=1
Case 2 '2x2 corner
shape[0,0]=1
shape[1,0]=1
shape[0,1]=1
Case 3 '2x2
shape[0,0]=1
shape[1,0]=1
shape[0,1]=1
shape[1,1]=1
Case 4 '3x1
shape[0,0]=1
shape[1,0]=1
shape[2,0]=1
Case 5 '3x2, L-shape
shape[0,0]=1
shape[1,0]=1
shape[0,1]=1
shape[2,0]=1
Case 6 '3x2, missing a corner
shape[0,0]=1
shape[1,0]=1
shape[0,1]=1
shape[1,1]=1
shape[2,0]=1
Case 7 '3x2, T-shape
shape[0,0]=1
shape[1,0]=1
shape[2,0]=1
shape[1,1]=1
Case 8 '3x2
shape[0,0]=1
shape[1,0]=1
shape[0,1]=1
shape[1,1]=1
shape[2,0]=1
shape[2,1]=1
Case 9 '3x3, corner
shape[0,0]=1
shape[1,0]=1
shape[2,0]=1
shape[0,1]=1
shape[0,2]=1
Case 10 '3x3, missing a corner
shape[0,0]=1
shape[1,0]=1
shape[0,1]=1
shape[1,1]=1
shape[2,0]=1
shape[2,1]=1
Case 12 '3x3, plus-shape
shape[1,0]=1
shape[0,1]=1
shape[1,1]=1
shape[2,1]=1
shape[1,2]=1
Case 12 '3x3
shape[0,0]=1
shape[1,0]=1
shape[2,0]=1
shape[0,1]=1
shape[1,1]=1
shape[2,1]=1
shape[0,2]=1
shape[1,2]=1
shape[2,2]=1
EndSelect
EndMethod
EndType
'makes a new component, copies one from the archtype, and returns it
Function new_comp:Component(_name$)
Local c:Component = New Component
c.copyComp(Null,_name)
If c.class = "engine" Then c.locked = True
Return c
EndFunction
'rotates & returns a set of two points around a 0,0 by some amount
Function rotAdjust[](_cx,_cy,_rot)
Local adjust[2]
'adjust for rotation
adjust[0] = ((_rot-2) Mod 2)*_cy - ((_rot-1) Mod 2)*_cx
adjust[1] = -((_rot-2) Mod 2)*_cx - ((_rot-1) Mod 2)*_cy
Return adjust
EndFunction
Global psquareMap:TMap = CreateMap()
MapInsert(psquareMap, "2", "energy")'power tiles of -1 are energy-type
MapInsert(psquareMap, "3", "munition")'power tiles of -2 are munition-type
MapInsert(psquareMap, "4", "unused")'unused - reserved for later expansion
MapInsert(psquareMap, "5", "omni")'power tiles of -3 are omni-type
Global preqMap:TMap = CreateMap()
MapInsert(preqMap, "0", "energy")'preq[0] is number of energy-requiring tiles
MapInsert(preqMap, "1", "munition")'preq[0] is number of munition-requiring tiles
MapInsert(preqMap, "2", "unused")'unused
MapInsert(preqMap, "3", "any")'preq[0] is number of ADDITIONAL power tiles of any type
'list of components currently installed on the ship
Global cshapedim = 11 'the X-by-X grid for ships that you can drop components onto
Global cshaperatio = 6 'how many pixels x pixels in the gfx that make up a placeable tile
Global selshipscale = 7
Global csize = cshaperatio*selshipscale 'size of the component squares
Global loadout$[16,3]'because we can't convert from 'string array' to 'string array' and I'm sick of this shit
Global loadoutB:Button[16]'loadout mouseover-detecting buttons
For Local i = 0 To 15
loadoutB[i] = New button
Next
Global configSList:SList 'FUCK IT TWO TEARS IN A BUCKET
Function hanger()
FlushKeys()
FlushMouse()
FlushJoy()
Local barbuttonhet = 50 'height of fleet/component buttons above list
Local barwid = 220 'the fleet/component list bar
Local infoboxhet = 250 'height of the ship/component information box below the list
'set up the (main) buttons and whatnot
'ships button
Local shipB:Button = New Button
'shipB.text = "Ships"
shipB.skipdraw = True
shipB.x = 6
shipB.y = 10
shipB.wid = 94
shipB.het = 28
shipB.toggle = 2
shipB.tab = True
'components button
Local compB:Button = New Button
'compB.text = "Components"
compB.skipdraw = True
compB.x = 106
compB.y = 10
compB.wid = 120
compB.het = 28
compB.toggle = 1
shipB.tab = True
'"return to ships" button
Local returnB:Button = New button
returnB.text = "Ship List"
returnB.x = 228
returnB.y = 2
returnB.wid = 108
returnB.het = 30
'how-to button
Local helpB:Button = New button
helpB.text = "How-To"
helpB.wid = 108
helpB.het = 30
helpB.x = SWIDTH - ImageWidth(hanger_infoaddon_gfx) + 50 - helpB.wid
helpB.y = 2
helpB.toggle = 1
'unlock components
Local unlockB:Button = New button
unlockB.text = "Unlock Components"
unlockB.wid = 218
unlockB.het = 30
unlockB.x = ((returnB.x + returnB.wid) + helpB.x) / 2 - (unlockB.wid/2)
unlockB.y = 2
unlockB.toggle = 1
'and the close button for it
Local closeB:Button = New Button
closeB.text = "Close"
closeB.text_scale = 2
closeB.wid = 256
closeB.het = 60
closeB.x = SWIDTH/2 - closeB.wid/2
closeB.y = SHEIGHT/2 + ImageHeight(hangerhelp_gfx)/2
'mission select button
Local systB:Button = New Button
systB.text = "Back"
systB.wid = 152
systB.het = 30
systB.x = SWIDTH - systB.wid - 8
systB.y = SHEIGHT - 52
'test drive button
Local testB:Button = New Button
testB.text = "Test Drive"
testB.wid = 152
testB.het = 30
testB.x = SWIDTH - testB.wid - 8
testB.y = systB.y - 2 - testB.het
'color scheme buttons
Local cschemeBList:TList = New TList
Local colornum = 8
If Not pilot.VIP Then colornum = 4'agh, it hurts to cut off functionality for some people
For Local scheme = 0 To colornum
Local cb:Button = New Button
cb.wid = 30
cb.het = 30
cb.x = SWIDTH - 176 - (cb.wid+8)*(scheme+1)
cb.y = SHEIGHT - cb.het - 8
cb.RGB = colorScheme(scheme,2)'dark shade for buttons
cschemeBList.addlast(cb)
Next
'new configuration button
Local newconfigB:Button = New Button
newconfigB.text = "New Config"
newconfigB.wid = 10'we reinitialize this constantly, below, so no worries
newconfigB.het = 30
newconfigB.textbox = True
newconfigB.allow_underscores = False'can't name configs with underscores
newconfigB.toggle = 1
'list of configurations that are available for this ship
configSList = New SList
configSList.init(0, 0, 10, 10, True, 30)'we reinitialize this constantly, below, so no worries
configSList.skipscrollbar = True
'strip components button
Local stripB:Button = New Button
stripB.text = "Clear"
stripB.wid = 154
stripB.het = 30
'revert config button
'Local revertB:Button = New Button
'revertB.text = "Revert"
'revertB.wid = 76
'revertB.het = 30
'save config button
'local saveB:Button = New Button
'saveB.text = "Save Changes"
'saveB.wid = 118
'saveB.het = 30
'saveB.x = SWIDTH - saveB.wid - 2
'list of actual ships to modify
Local modshipList:TList = New TList
'corresponding scrolling list of buttons for each ship- will be in same order as above!
Local shipSList:SList = New SList
shipSList.init(6, 10+ImageHeight(hanger_tabs_gfx)+4, ImageWidth(hanger_tabs_gfx)-12, SHEIGHT-(10+ImageHeight(hanger_tabs_gfx)+16)-4, False)
'grab ships from the pilot's fleetlist
For Local s:Ship = EachIn pilot.fleetList
modshipList.addLast(s)
Local sb:Button = shipSList.add_button(s.name,0,0,s.gfx[0],25,10 + ImageHeight(s.gfx[0])/2)
sb.text_y = -18
sb.text_x = 20
sb.toggle = 1'they're toggle buttons!
sb.tab = True'also, can't unselect it
Next
'make a slave button to automatically switch over to component customization, only the selected ship has this as a child
Local customizeB:Button = New Button
customizeB.text = "Customize"
customizeB.text_scale = 2
customizeB.wid = 256
customizeB.het = 60
customizeB.x = SWIDTH/2 - customizeB.wid/2
customizeB.y = SHEIGHT/2 + (cshapedim/2)*csize
'list of actual components to add
Local modcompList:TList = New TList
'corresponding scrolling list of buttons for the components
Local compSList:SList = New SList
compSList.init(shipSList.x, shipSList.y, shipSList.wid, shipSList.het, shipSList.barside, 50)
'grab components from the pilot's complist
For Local c:Component = EachIn pilot.compList
modcompList.addLast(c)
Local nb:Button = compSList.add_button(c.name)
nb.text_centered = False
nb.text_x = 45
nb.text_y = (-nb.het/2) + 15
Next
'make a list of components available to unlock
Local unlock_compList:TList = New TList
Local unlock_compSList:SList = New SList
unlock_compSList.init(compSList.x, compSList.y, compSList.wid, compSList.het, compSList.barside, compSList.entryhet)
For Local c:Component = EachIn componentList
'if we haven't already unlocked it
If Not pilot.alreadyhave_component(c.name)
'if this component is available to unlock
If c.unlockable And (Not c.special Or pilot.VIP)
unlock_compList.addLast(c)
Local nb:Button = unlock_compSList.add_button(c.name)
nb.text_centered = False
nb.text_x = 45
nb.text_y = (-nb.het/2) + 15
EndIf
EndIf
Next
'------------------------------------------------------------------------------------------------------------------------------------
'------------------------------------------------------------------MAIN HANGER LOOP--------------------------------------------------
'------------------------------------------------------------------------------------------------------------------------------------
'sidebar dimensions
Local statwid = ImageWidth(hanger_infoaddon_gfx)
Local stathet = 144
Local texthet = TextHeight("BOBCAT")
Local addonwid = 178
Local addonhet = 86
Local buttonspace = 2 + stripB.het + 2 + ImageHeight(boxseparator_gfx) + 2
Local staty = 10
Local addony = staty+ImageHeight(hanger_infoaddon_gfx)+stathet-4
'amount of scrap to display
'Local dispscrap = pilot.scrap
'the current color of ship on display
Local hangercolor = -1
'has there been a change to a configuration?
'Local changes = False
'should we hide the current components?
Local hidecomps = False
'selected ship to modify
Local selship:Ship, old_selship:Ship'(old used to detect changes, resets some important stuff when that happens)
Local selship_gfx:TImage
'selected component to add
Local selcomp:Component
'mouse button state information
Local m,mc,mc2,mr,old_m
Local m_dc, dc_delay = 100, dc_timer=dc_delay'double click timer
oldTime = MilliSecs()
timePass = 22'just so no tricky stuff at the initial loop
Repeat
WaitTimer(frameTimer)
Cls
SetColor 255,255,255
updateTime()
updateCursor()
'mousedown information
old_m = m
m = MouseDown(1) Or (joyDetected And JoyDown(JOY_FIREPRIMARY))
'mouseclick information
If (old_m <> m) And (m = True) Then mc = True Else mc = False
mc2 = MouseHit(2) Or (joyDetected And JoyHit(JOY_FIRESECONDARY))
'mouserelease information
If (old_m <> m) And (m = False) Then mr = True Else mr = False
'double clicks
If dc_timer > 0
dc_timer:- frameTime
If mc Then m_dc = True
EndIf
If mc Then dc_timer = dc_delay
'draw the background
SetRotation 0
SetScale 1,1
SetAlpha 1
SetColor 16,16,35
If unlockB.toggle = 2 Then SetColor 60,20,0
TileImage grid_gfx
'change the amount of scrap displayed to match reality
'If dispscrap > pilot.scrap
' SetColor 255,120,120
'ElseIf dispscrap < pilot.scrap
' SetColor 120,120,255
'Else
' SetColor 255,255,255
'EndIf
'change scrap counter by a percentage
'dispscrap = constrain(dispscrap - Float(dispscrap - pilot.scrap)*frameTime/1000.0, pilot.scrap, dispscrap)
'current amount of scrap available
'SetScale 2,2
'SetRotation 0
'DrawText dispscrap+" scp.", ImageWidth(hanger_tabs_gfx) + 15 ,15
'exitbox box
SetScale 1,1
SetColor 255,255,255
SetAlpha 1
SetRotation 0
drawBorderedRect(testB.x-8,testB.y-8,SWIDTH-testB.wid-16,testB.het*2+18)
SetColor 255,255,255
DrawImage hanger_exitbox_gfx,testB.x-8,testB.y-30,0
DrawImage hanger_exitbox_gfx,systB.x-8,systB.y+systB.het+6,1
'TEST DRIVE BUTTON
testB.update(m)
testB.draw()
If testB.pressed = 2 And selship <> Null
selship.save_config()
p1 = selship
p1.reset()
new_game("testdrive")
EndIf
'MISSION SELECT BUTTON
systB.update(m)
systB.draw()
'save changes button
'If changes Then saveB.active = True Else saveB.active = False'only can save changes if there's been changes
'saveB.y = testB.y-32-saveB.het
'saveB.update(m)
'saveB.draw()
'If saveB.pressed = 2
' selship.save_config()
' changes = False
'EndIf
'box for list of installed components, LOADOUT
SetRotation 0
SetScale 1,1
SetAlpha 1
SetColor 255,255,255
addony = staty+ImageHeight(hanger_infoaddon_gfx)*2+stathet-4 'y of capping (middle) gfx
'default to displaying the components in configuration
hidecomps = False
'-------------------------------------------------------------------------------------------- CURRENT SHIP -------------------------
If selship <> Null
'DRAW THE SHIP BIG in the center of the screen
SetColor 255,255,255
SetAlpha 1
If selship_gfx <> Null Then DrawImage selship_gfx,SWIDTH/2-1,SHEIGHT/2
'draw the ship color schemes
If (Lower(selship.config) <> "default" Or Lower(pilot.name) = "wik")'only if we can customize this ship
Local cscheme = 0
For Local schemeB:Button = EachIn cschemeBList
schemeB.update(m)
schemeB.draw()
'if mouse-near the buttons, hide the current components
If cursory >= schemeB.y And (Abs(cursorx - schemeB.x) < 30 Or Abs(cursorx - (schemeB.x + schemeB.wid)) < 30)
hidecomps = True
EndIf
'if press button to change current color scheme
If schemeB.pressed = 2 And selship.color <> cscheme
'changes = True
selship.scheme = cscheme
'actually recolor the thing
selship.recalc()
EndIf
cscheme:+1
Next
EndIf
'figure out where to start drawing the topleft corner of component grid
Local ox = SWIDTH/2 - (cshapedim/2)*csize - csize/2
Local oy = SHEIGHT/2 - (cshapedim/2)*csize - csize/2
'if we're currently editing components
If compB.toggle = 2
'draw the component grid
SetScale 1,1
'draw the grid
Local MOptile[3]'0:the type of ptile | 1,2:x,y position of ptile
If Not hidecomps
For Local y = 0 To cshapedim-1
For Local x = 0 To cshapedim-1
'if this square is not unavailable
If selship.cshape[x,y] <> 0
SetAlpha 1
Local tx = x*csize
Local ty = y*csize
'draw a border
SetColor 64,64,64
DrawRect ox+tx-2,oy+ty-2,csize+2,csize+2
'is it a power tile color?
Local rgb[3]
rgb = getTileColor(String(MapValueForKey(psquareMap, String(Abs(selship.cshape[x,y])))))
'dark colored border
SetColor 32,32,32
DrawRect ox+tx,oy+ty,csize-2,csize-2
'normal tiles are just plain/with a 1px border
If Abs(selship.cshape[x,y]) = 1
'dark colored border
SetColor rgb[0],rgb[1],rgb[2]
DrawRect ox+tx+4,oy+ty+4,csize-8,csize-8
'lighter center
SetColor rgb[0]*2,rgb[1]*2,rgb[2]*2
DrawRect ox+tx+4,oy+ty+4,csize-10,csize-10
'power tiles are made of concentric circles
Else
'lighter center box
SetColor 64,64,64
DrawRect ox+tx+2,oy+ty+2,csize-6,csize-6
'concentric circles
SetColor 32,32,32
DrawOval ox+tx+1,oy+ty+1,csize-4,csize-4
SetColor rgb[0],rgb[1],rgb[2]
DrawOval ox+tx+3,oy+ty+3,csize-8,csize-8
SetColor rgb[0]*2,rgb[1]*2,rgb[2]*2
DrawOval ox+tx+7,oy+ty+7,csize-16,csize-16
SetColor rgb[0],rgb[1],rgb[2]
DrawOval ox+tx+13,oy+ty+13,csize-28,csize-28
'mouseover?
If cursorx > ox+tx And cursorx < ox+tx+csize And cursory > oy+ty And cursory < oy+ty+csize
MOptile[0] = Abs(selship.cshape[x,y])
MOptile[1] = ox+tx
MOptile[2] = oy+ty
EndIf
EndIf
'SetColor 255,255,255
'DrawText x+","+y,ox+x*csize+2,oy+y*csize+2
'DrawText selship.cshape[x,y],ox+x*csize+2,oy+y*csize+2
EndIf
Next
Next
EndIf
'---------------------------------------------------------------------- draw/select current components -------------------
Local MOcomp:Component = Null'the currently mouseover'd component
For Local c:Component = EachIn selship.compList
'is the mouse over this component?
Local mouseover = False
For Local cy = 0 To 4
For Local cx = 0 To 4
'adjust for rotation
Local cr[2]
cr = rotAdjust(cx,cy,c.rot)
'component occupies this space?
If c.shape[cx,cy] = 1
If cursorx >= ox+(c.x+cr[0])*csize And cursorx < ox+(c.x+cr[0])*csize+csize
If cursory >= oy+(c.y+cr[1])*csize And cursory < oy+(c.y+cr[1])*csize+csize
mouseover = True
MOcomp = c
EndIf
EndIf
EndIf
Next
Next
'pick up or delete the component
If mouseover And (Not c.locked Or Lower(pilot.name) = "wik")
'pick it up
If mc
selcomp = c
ListRemove(selship.compList,c)
'recalculate the shape data for the ship
selship.cshape_recalc()
mc = 0'lie! we've "used up" this release, so we don't just replace it
'changes = True'we messed with stuff
'just kill it
ElseIf mc2 And selcomp = Null
ListRemove(selship.compList,c)
'recalculate the shape data for the ship
selship.cshape_recalc()
'changes = True'we messed with stuff
EndIf
EndIf
'draw the component
If Not hidecomps
For Local cy = 0 To 4
For Local cx = 0 To 4
'adjust for rotation
Local cr[2]
cr = rotAdjust(cx,cy,c.rot)
'component occupies this space?
If c.shape[cx,cy] = 1
'draw it (mouseover, plugged components are highlighted)
Local cmod = 42*mouseover
SetColor c.rgb[0]+cmod, c.rgb[1]+cmod, c.rgb[2]+cmod
If Not c.plugged Then SetColor 168+cmod,128+cmod,128+cmod
SetAlpha .8
SetScale 1,1
DrawRect ox+(c.x+cr[0])*csize+2,oy+(c.y+cr[1])*csize+2,csize-6,csize-6
ElseIf c.shape[cx,cy] = 2'this is an attachment tile
SetColor 128,128,64
SetAlpha .7
DrawRect ox+(c.x+cr[0])*csize+8, oy+(c.y+cr[1])*csize+8, csize-16, csize-16
DrawRect ox+(c.x+cr[0])*csize+12, oy+(c.y+cr[1])*csize+12, csize-24, csize-24
EndIf
Next
Next
EndIf
Next
If Not hidecomps
'make a tooltip for the mouseover'd component
If MOcomp <> Null' And selcomp = Null
drawTooltip(MOcomp, ox+(MOcomp.x*csize)+csize/2, oy+(MOcomp.y*csize))
'make a tooltip for the mouseover'd power tile
ElseIf MOptile[0] > 1
Local tipwid = 170
Local tiphet = 30
Local ox = MOptile[1]+csize/2-tipwid/2
Local oy = MOptile[2]-ImageHeight(boxpointer_gfx)-tiphet
drawBorderedRect(ox,oy,tipwid,tiphet)
SetColor 255,255,255
DrawImage boxpointer_gfx, ox + tipwid/2, oy + tiphet
Local tiletext$ = String(MapValueForKey(psquareMap, String(MOptile[0]))) + " power tile"
draw_text(tiletext, ox+(tipwid-TextWidth(tiletext))/2, oy+8)
EndIf
EndIf
EndIf
'-- ATTACHMENT TILES --
For Local c:Component = EachIn selship.compList
ClearList(c.addonList)'clear any components that are added to this one, we'll re-add them in a second
Next
'see if this component is adjecent to any others of the same name, attach components to their parents
For Local c:Component = EachIn selship.compList
For Local cy = 0 To 4
For Local cx = 0 To 4
'if this component has an attactment tile at this space
If c.addon And c.shape[cx,cy] = 2
'overlappers?
For Local a:Component = EachIn selship.compList
'if it's the right class, accepts addons, and is not an addon itself (heaven forbid!)
If c.class = a.class And a.accepts_addons And Not a.addon
For Local ay = 0 To 4
For Local ax = 0 To 4
'if THAT comp is occupying this space
If a.shape[ax,ay] = 1
'adjust for rotation
Local cr[2],ar[2]
cr = rotAdjust(cx,cy,c.rot)
ar = rotAdjust(ax,ay,a.rot)
'see if that component's square is on top of the attachement tile
If (c.x+cr[0]) = (a.x+ar[0]) And (c.y+cr[1]) = (a.y+ar[1])
a.addonList.addLast(c)'attach this component to this other component
EndIf
EndIf
Next
Next
EndIf
Next
EndIf
Next
Next
Next
'for ALL components...
For Local c:Component = EachIn selship.compList
'check to see if it's plugged in to a degree it wishes
c.plugged = False
'engines are always plugged in
If c.class = "engine"
c.plugged = True
'if we don't need no stinking power tiles
ElseIf c.preq[0] = 0 And c.preq[1] = 0 And c.preq[2] = 0 And c.preq[3] = 0
c.plugged = True
'other things have to check for power tiles
Else
'go through all bits of the component to see if any of them are powered
Local omni_count 'after everything else is checked, use omni tiles to fill remaining requirements
Local ptile_count[4] 'number of each type of tile that this component needs
ptile_count[0] = c.preq[0]
ptile_count[1] = c.preq[1]
ptile_count[2] = c.preq[2]
ptile_count[3] = c.preq[3]
For Local cy = 0 To 4
For Local cx = 0 To 4
If c.shape[cx,cy] = 1
'adjust for rotation
Local cr[2]
cr = rotAdjust(cx,cy,c.rot)
'is this square powered?
If isWithin(c.x+cr[0], 0, cshapedim-1) And isWithin(c.y+cr[1], 0, cshapedim-1)
'find the type of power tile at this location
Local ptile$ = String(MapValueForKey(psquareMap, String(Abs(selship.cshape[c.x+cr[0],c.y+cr[1]]))))
Local spent = False'whether we've spent this tile on filling a requirement yet
'if we found a power tile
If ptile <> ""
'try and knock off a specific requirements first
For Local i = 0 To 2
'if we require some number of this type of tile
If ptile_count[i] > 0
If ptile = String(MapValueForKey(preqMap, String(i)))'does this ptile match the requirement?
ptile_count[i]:- 1
spent = True
EndIf
EndIf
Next
'see if we can't just use it for a flexible slot
If Not spent
If ptile_count[3] > 0
ptile_count[3]:- 1
spent = True
EndIf
EndIf
'if all else fails, and this is an omni tile,
'just record that we have one omni in the bank for when the dust settles
If Not spent And ptile = "omni" Then omni_count:+ 1
EndIf
EndIf
EndIf
Next
Next
'check if we fulfilled requirements (also, spend omni tiles on any remaining ptile requirements)
c.plugged = True
For Local i = 0 To 3
'spend remaining omni tiles
If ptile_count[i] > 0 And omni_count > 0
ptile_count[i]:- omni_count
omni_count = -ptile_count[i]
EndIf
'if we still haven't met the quota
If ptile_count[i] > 0 Then c.plugged = False
Next
EndIf
Next
'list of the contained components (second value is quantity of that component) (third value is TRUE/FALSE, whether to draw text red)
tallyComponents(selShip)
'see how many lines of components we got
For Local i = 0 To 15
If loadout[i,0] = ""
addonhet = (i+1)*textHet
Exit
EndIf
Next
'ACTUAL box for loadout
SetColor 255,255,255
SetAlpha 1
addonhet:+ buttonspace'make space for the two below buttons
drawBorderedRect(SWIDTH-addonwid, addony-6, addonwid, addonhet+2)
'clear and revert buttons
stripB.x = SWIDTH - addonwid + 8
stripB.y = addony + 2
stripB.update(m)
stripB.draw()
If stripB.pressed = 2
Local configName$ = selship.config 'preserve the current configuration name
selship.load_config("null") 'but reset components to just the engines.
selship.config = configName 'restore name
EndIf
'If revertB.active And changes = False Then revertB.active = False'can only revert if we're not already there
'revertB.x = SWIDTH - revertB.wid - 8
'revertB.y = addony + 2
'revertB.update(m)
'revertB.draw()
'If revertB.pressed = 2
' changes = False'back to original
' selship.load_config(selship.config)
'EndIf
'draw a divider below them
SetColor 255,255,255
DrawImage boxseparator_gfx, SWIDTH - (addonwid/2), stripB.y + stripB.het + 5, 0
addony:+ buttonspace
'list of installed components
For Local i = 0 To 15
'update the button
loadoutB[i].het = textHet
loadoutB[i].wid = addonwid
loadoutB[i].x = SWIDTH - addonwid
loadoutB[i].y = addony + i*textHet
loadoutB[i].update(m)
If loadout[i,0] <> ""
Local textx = SWIDTH - addonwid + 8
Local texty = addony + i*textHet
'is the mouse over it?
If loadoutB[i].pressed < 5
'draw a highlighted rectangle
SetColor 64,64,128
DrawRect textx-2,texty,addonwid-12,texthet
EndIf
'list the component
If loadout[i,2] = "" Then SetColor 255,255,255 Else SetColor 208,105,100'red if there's power
If loadout[i,1] = "1" Or loadout[i,1] = ""'if there's no quantity
draw_text(loadout[i,0], textx, texty)
Else
draw_text(loadout[i,0] + " x"+loadout[i,1], textx, texty)
EndIf
EndIf
Next
'box for current stats
drawBorderedRect(SWIDTH-statwid, staty+ImageHeight(hanger_infoaddon_gfx)-2, statwid, stathet)
'draw the "current stats' box for the CURRENT SHIP
SetRotation 0
SetScale 1,1
SetAlpha 1
SetColor 255,255,255
'top bar
DrawImage hanger_infoaddon_gfx, SWIDTH-statwid, staty, 0
'middle bar
DrawImage hanger_infoaddon_gfx, SWIDTH-statwid, addony-ImageHeight(hanger_infoaddon_gfx)-buttonspace, 1
'bottom bar
DrawImage hanger_infoaddon_gfx, SWIDTH-statwid, addony-buttonspace+addonhet-6, 2
'draw the CURRENT STATS
draw_stats(selship, SWIDTH-statwid+10, staty+ImageHeight(hanger_infoaddon_gfx)+8)
'CURRENTLY SELECTED COMPONENT
If selcomp <> Null
'draw the component under the mouse
SetScale 1,1
For Local cy = 0 To 4
For Local cx = 0 To 4
'adjust for rotation
Local cr[2]
cr = rotAdjust(cx,cy,selcomp.rot)
If selcomp.shape[cx,cy] = 1
SetAlpha .9
SetColor selcomp.rgb[0],selcomp.rgb[1],selcomp.rgb[2]