-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
executable file
·2125 lines (1847 loc) · 68.7 KB
/
functions.php
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
<?php
// When debugging, uncomment the following to display errors.
/*
error_reporting(E_ALL);
ini_set('display_errors', 1);
*/
include("calculations.php");
///////////////////////////////////////
/// ///
/// Functions follow. ///
/// ///
///////////////////////////////////////
// Formats output of standard print_r function to make it display on a web page.
function print_r_web($val)
{
echo '<pre>';
print_r($val);
echo '</pre>';
}
// For some values, I want to see the decimals, unless they don't exist.
function number_format_unlimited_precision($number, $decimal = '.')
{
$broken_number = explode($decimal, $number);
if (count($broken_number) == 2) {
return number_format($broken_number[0]) . $decimal . $broken_number[1];
} else {
return number_format($broken_number[0]);
}
}
function categorizeUnitData($categoriesOrder, $userSettings, $dataUnits){
$finalData = array();
$armies = [];
/// For each unit...
for ($i = 0; $i < sizeOf($dataUnits); $i++){
$item = $dataUnits[$i];
/// This chunk of code can be used to skip units lacking an icon, a preview, or basic general information.
/// Useful to avoid displaying debug units.
/// Filter is >necessary<, in fact, because some of these units can cause the script to fail.
/// Added filter to prevent units that don't have a 'faction'.
if (!property_exists($item, 'StrategicIconName') ||
!property_exists($item, 'General') ||
!property_exists($item->General, 'Icon') ||
!property_exists($item->General, 'FactionName')) {
continue;
}
/// Formatting the Faction name to ensure it has good casing : Aeon, Cybran, Seraphim, UEF, Nomads
$faction = formatFaction($item->General->FactionName);
/// Adding the army to the list, given the user said he wanted to see it.
if (!in_array($faction, $armies) && in_array($faction, $userSettings['showArmies'])){
$armies[] = ($faction);
}
$itemCat = $item->Categories;
$tech = getTech($item);
/// Now for the unit categorization...
/// The order in which these Else IF are structured is important. Changing them might allow categorizing Fatboy as "Factory" instead of "Land unit", for example. The unit will be categorized in the first matching category.
//////////////
// CIVILIAN & DEBUG
// Every non-multiplayer-relevant unit should go there
/////////////
if (in_array('OPERATION', $item->Categories) ||
in_array('CIVILIAN', $item->Categories) ||
in_array('INSIGNIFICANTUNIT', $item->Categories) ||
in_array('DEBUG', $item->Categories)){
$finalData['Civilian & Miscellanous'][""][$faction][$item->Id] = $item;
}
///////////////
// COMMANDER & SACU
// SACUs and ACUs go there.
//////////////
else if (in_array ('COMMAND', $itemCat)
|| in_array ('SUBCOMMANDER', $itemCat)){
$finalData['Command'][$tech][$faction][$item->Id] = $item;
}
///////////////
// ENGINEER
// Everything that has the flag Engineer, along with hives and engineering platforms.
//////////////
else if (in_array ('ENGINEER', $itemCat) ||
in_array('PODSTAGINGPLATFORM', $itemCat)){
$finalData['Engineer'][$tech][$faction][$item->Id] = $item;
}
///////////////
// AIRCRAFT
// Everything that flies, including Novax
//////////////
else if (in_array('MOBILE', $itemCat) &&
(in_array ('AIR', $itemCat))){
$finalData['Aircraft'][$tech][$faction][$item->Id] = $item;
}
///////////////
// VEHICLE
// Land vehicles and bots
//////////////
else if (in_array('MOBILE', $itemCat) &&
(in_array ('LAND', $itemCat))){
$finalData['Vehicle'][$tech][$faction][$item->Id] = $item;
}
///////////////
// SHIP
// Stuff that goes under and over water, including Salem
//////////////
else if (in_array('MOBILE', $itemCat) &&
(in_array ('NAVAL', $itemCat))
&& !in_array('MOBILESONAR', $itemCat)){
$finalData['Naval'][$tech][$faction][$item->Id] = $item;
}
///////////////
// SUPPORT
// Wall sections, air staging facilities, everything that does not fit elsewhere
//////////////
else if (in_array ('WALL', $itemCat) ||
in_array ('AIRSTAGINGPLATFORM', $itemCat) ||
in_array ('ORBITALSYSTEM', $itemCat)
){
$finalData['Support'][$tech][$faction][$item->Id] = $item;
}
///////////////
// BUILDING - FACTORY
// Every building that produces units, including Gateways
//////////////
else if (in_array('STRUCTURE', $itemCat) &&
in_array ('FACTORY', $itemCat)){
$finalData['Building - Factory'][$tech][$faction][$item->Id] = $item;
}
///////////////
// BUILDING - ECONOMY
// Mexes, massfabs, pgens, paragons.
//////////////
else if (in_array('STRUCTURE', $itemCat) &&
in_array ('ECONOMIC', $itemCat)){
$finalData['Building - Economy'][$tech][$faction][$item->Id] = $item;
}
///////////////
// BUILDING - WEAPON
// Artillery sites, turrets, ...
//////////////
else if (in_array('STRUCTURE', $itemCat) &&
(in_array('NUKE', $itemCat) ||
in_array ('INDIRECTFIRE', $itemCat) ||
in_array ('DIRECTFIRE', $itemCat))){
$finalData['Building - Weapon'][$tech][$faction][$item->Id] = $item;
}
///////////////
// BUILDING - DEFENSE
// Antimissiles, AA turrets, stealth and shields, ...
//////////////
else if (in_array('STRUCTURE', $itemCat) &&
(in_array ('DEFENSE', $itemCat) ||
in_array('COUNTERINTELLIGENCE', $itemCat) ||
in_array('ANTINAVY', $itemCat) ||
in_array('ANTIAIR', $itemCat))
){
$finalData['Building - Defense'][$tech][$faction][$item->Id] = $item;
}
///////////////
// BUILDING - SENSOR
// Radar and sonar
//////////////
else if ((in_array('STRUCTURE', $itemCat) || in_array('MOBILESONAR', $itemCat)) &&
(in_array ('SORTINTEL', $itemCat) ||
in_array('SONAR', $itemCat))){
$finalData['Building - Sensor'][$tech][$faction][$item->Id] = $item;
}
// Dumping every other unit in the Misc category. Probably debug units or civilian/campaign-related stuff.
else{
$finalData['Civilian & Miscellanous'][""][$faction][$item->Id] = $item;
}
}
$finalData = array_replace($categoriesOrder, $finalData);
/// End of
return array(
"listData"=>$finalData,
"armyList"=>$armies
);
}
function formatFaction($faction){
$faction = ucfirst(strtolower($faction));
if (strtolower($faction) == "uef"){
$faction = strtoupper($faction); // UEF is written all uppercase, unlike the other factions
}
return $faction;
}
/// DISPLAY FUNCTIONS
function displaySettingsMenu($defaultSettings, $userSettings, $dataLoc){
// For each setting
foreach($defaultSettings as $settingName=>$settingValue){
$settingValue = null;
if (array_key_exists($settingName, $userSettings)){
$settingValue = $userSettings[$settingName];
}
// Preview corner has a specific dropdown menu
if ($settingName == "previewCorner"){
$options = ["Top left", "Top right", "Bottom right", "Bottom left", "None"];
$settingValue = '
<select style="width:100%;text-align:center;" name="'.$settingName.'">';
foreach($options as $thisOpt){
$select = '';
if ($thisOpt == $userSettings[$settingName]){
$select = "selected";
}
$settingValue.= '
<option '.$select.' value="'.$thisOpt.'">'.$thisOpt.'</option>';
}
$settingValue .='
</select>';
}
// Lang depends on localization to populate its dropdown menu
else if ($settingName == "lang"){
$options = $dataLoc;
$settingValue = '
<select style="width:100%;text-align:center;" name="'.$settingName.'">';
foreach($options as $locName=>$x){
$select = '';
if (array_key_exists($settingName, $userSettings) && $locName == $userSettings[$settingName]){
$select = "selected";
}
$settingValue.= '
<option '.$select.' value="'.$locName.'">'.$locName.'</option>';
}
$settingValue .='
</select>';
}
// Both checkboxes, displayed the same way
else if ($settingName == "autoExpand" || $settingName == "spookyMode" || $settingName == "experimentalPreview"){
$checked = "";
if ($settingValue){
$checked = "checked";
}
$settingValue = '<input style="width:100%;text-align:center;" name="'.$settingName.'" type="checkbox" '.$checked.' />';
}
// Every other array setting is simply exploded
else if(is_array($settingValue)){
$settingValue = '<input style="width:100%;" type="text" name="'.$settingName.'" value="'.implode(",",$settingValue).'"/>';
}
else{
$settingValue = '<input style="width:100%;text-align:center;" name="'.$settingName.'" type="text" value=\''.($settingValue).'\'/>';
}
echo '
<div class="flexColumns" style="margin:32px;margin-top:8px;margin-bottom:8px;">
<div style="text-align:left;width:50%;margin:8px;">
'.caseFormat($settingName).'
</div>
<div style="text-align:right;width:50%;margin:8px;">
'.$settingValue.'
</div>
</div>';
}
}
function displayUnitlistUnit($thisUnit, $userSettings, $techName, $armyName, $dataLoc, $onCard=false){
/// We will only be displaying this unit if it has an ID
if (property_exists($thisUnit, 'Id')){
$id = $thisUnit->Id;
/// Hover preview displaying
$previewTrigger = "";
if ($userSettings['previewCorner'] != "None"){
$previewTrigger = 'onMouseover="loadHoverInfo(\''.($thisUnit->Id).'\', \''.($userSettings['lang']).'\')"';
}
echo '<div class="unitMainDiv tooltip"
id="'.($thisUnit->Id).'"
onClick="toggleSelect(\''.($thisUnit->Id).'\')"
'.$previewTrigger.'>';
/// Hover preview, "Heavy mode"
if (!$userSettings['experimentalPreview'] && $userSettings['previewCorner'] != "None"){
/// Position of the hover-preview
$position = 'left:0px;bottom:0px;';
switch ($userSettings['previewCorner']){
case "Top left":
$position = 'left:0px;top:0px;';
break;
case "Top right":
$position = 'right:0px;top:0px;';
break;
case "Bottom right":
$position = 'right:0px;bottom:0px;';
break;
}
echo '
<div class="legacyTooltiptext" style="'.$position.'background-color:'.getFactionColor($thisUnit->General->FactionName, "dark").';">
'.getUnitTitle($thisUnit, $dataLoc, $userSettings['lang']).'
</div>';
}
/// "Spooky mode" displaying preview instead of unit names
if ($userSettings['spookyMode']){
$terrain = 'none';
$strategic = 'none';
$description = 'unit';
if (property_exists($thisUnit, 'StrategicIconName')){
$strategic = $thisUnit->StrategicIconName;
}
if (property_exists($thisUnit->General, 'Icon')){
$terrain = $thisUnit->General->Icon;
}
if (property_exists($thisUnit, 'Description')){
$description = ($thisUnit->Description);
$matches = [];
if (preg_match ('/(<loc.*>+)/', $description, $matches)){
$line = $matches[0];
$line = str_replace('<loc ', '', $line);
$line = str_replace('>', '', $line);
$thisLang = $dataLoc[$userSettings['lang']];
if (array_key_exists($line, $thisLang)){
$description = str_replace('"', '', $thisLang[$line]);
}
}
}
/// Custom style for icon hue because of PHP-dynamic faction hue
echo '
<div>
<div class="previewImg">
<img alt="?" class="backgroundIconOverlap" src="res/img/preview_background/'.($terrain).'_up.png">
<img alt="?" class="strategicIcon" style= "width:64px;height:64px;" src="res/img/preview/'.strtoupper($thisUnit->Id).'.png">
<img alt="[x]" class="strategicIconOverlap" src="res/img/strategic/'.($strategic).'_rest.png" style="filter: hue-rotate('.(getFactionColor($armyName, 'hue')).'deg)">
</div>
</div>';
}
/// "Default mode" displaying each unit as a row, with name and strategic icon only
else {
echo '
<div class="unit">';
/// Icon path
$icon = '';
if (property_exists($thisUnit, 'StrategicIconName')){
$icon = ($thisUnit->StrategicIconName).'_rest';
}
/// Custom style for icon hue because of PHP-dynamic faction hue
echo '
<div class="strategicIconDiv">'.
'<img style="filter: hue-rotate('.(getFactionColor($armyName, 'hue')).'deg)" src="res/img/strategic/'.$icon.'.png" alt="[x]">
</div>';
/// Translates name of both unit name an description if possible
$description = "unit";
if (property_exists($thisUnit, 'Description')){
$description = attemptTranslation($thisUnit->Description, $dataLoc, $userSettings['lang']);
}
$description = $techName.($description);
$name = '';
if (property_exists($thisUnit->General, 'UnitName')){
$name = attemptTranslation($thisUnit->General->UnitName, $dataLoc, $userSettings['lang']);
}
/// Slightly different style if we're displayed on a unit comparator card, because the background is darker
$moreStyle = "";
if ($onCard){
$moreStyle = 'style="color:'.getFactionColor($armyName, "bright").';"';
}
/// Displays it all
echo '
<div class="unitName" style="width:100%;">
<span '.$moreStyle.' class="unitHotLink" onclick="seeUnit(\''.$id.'\')">
'.($description).'
</span>
<span class="unitCustomName"
style="color:'.getFactionColor($armyName, ($onCard ? "bright" : "dark") ).'">'.
($name).'
</span>';
if (!$onCard){
/// Uncomment this to add a little "Compare..." text on hover
/*
echo '
<span style="
color:'.getFactionColor($armyName, "bright").';">
Compare...
</span>';
*/
};
echo '
</div>
</div>';
}
echo '
</div>';
}
}
function displayUnitlistArmies($techName, $techLevel, $userSettings, $armies, $dataLoc){
echo '<div class="unitlistArmyRow">';
/// For each army as a column, display one unit per row
foreach($armies as $armyName){
$border = '';
if ($techName != "T1 " && $techName != ""){
$border = 'border-top: 1px dotted grey;';
}
/// Will behave differently if asked to display "Spooky mode", which means preview instead of names for units.
$style = 'classicStyle';
if ($userSettings['spookyMode']){
$style = 'spookyStyle';
}
echo '<div class="'.$style.'"
style="
'.$border.'
background-color:'.getFactionColor($armyName, "bright").'" >';
if (array_key_exists($armyName, $techLevel)){
$thisArmy = $techLevel[$armyName];
}
else{
echo '</div>';
continue;
}
foreach($thisArmy as $thisUnit){
displayUnitlistUnit($thisUnit, $userSettings, $techName, $armyName, $dataLoc);
}
echo '</div>';
}
echo '</div>';
}
function displayUnitlistTechs($catName, $categories, $userSettings, $armies, $dataLoc){
/// The order in which techs will be displayed
$techOrder = ['', 'T1 ', 'T2 ', 'T3 ', 'T4 '];
/// By default, the category will be opened unless it is "Civilian & Miscellanous".
$open = "open";
if ($catName == "Civilian & Miscellanous"){
$open = "";
}
echo '
<details '.$open.'>
<summary class="categoryName">
'.$catName.'
</summary>';
/// Custom flex column - no need for a class
echo '<div style="
display: flex;
justify-content:space-between;
flex-direction: column;" >';
$categories = array_merge(array_flip($techOrder), $categories);
/// For each tech as a row, display one column per army
foreach($categories as $techName => $techLevel){
if (!is_array($techLevel)){
continue;
}
displayUnitlistArmies($techName, $techLevel, $userSettings, $armies, $dataLoc);
}
echo '</div>
</details>';
}
function displayFactionsHeader($armies){
echo '<div class="factionsHeader" >';
foreach($armies as $armyName){
// #
$loadFile = 'res/img/factional/'.strtolower($armyName).'_load.jpg';
if (!file_exists($loadFile)){
$loadFile = 'res/img/factional/default_load.jpg';
}
echo '
<div class="flexColumns title factionSplash" style="
background-image:url(\''.$loadFile.'\');
color:'.getFactionColor($armyName, "bright").';">
<div style="width:40%;">
'.$armyName.'
</div>
<div style="text-align:left;width:60%;">
</div>
</div>';
}
echo '</div>';
}
function displayBuildlist($info, $thisUnit, $userSettings, $dataUnits, $dataLoc){
if (property_exists($thisUnit->Economy, 'BuildableCategory')){
$buildable = [];
/// Checks every unit in the $data to see which ones correspond to the right buildable category
/// and populates the $buildable with them
foreach($dataUnits as $unit){
/// (array) Type cast needed in case BuildableCategory is only a string (for PHP 8)
foreach((array)$thisUnit->Economy->BuildableCategory as $buildableCategory){
$buildableRequirements = explode(' ', $buildableCategory);
$canBuild = true;
foreach((array)$buildableRequirements as $requirement){
if (!in_array($requirement, $unit->Categories) && strtoupper($requirement) != strtoupper($unit->Id)){
$canBuild = false;
}
}
if ($canBuild){
$buildable[] = $unit;
}
}
}
/// Making sure there are no doubles
$buildable = array_unique ($buildable, SORT_REGULAR);
if (sizeOf($buildable) > 0){
$autoOpen = '';
if ($userSettings['autoExpand']){
$autoOpen = 'open';
}
echo '
<details class="sheetSection unitBlueprints" id="blueprintsSection'.($thisUnit->Id).'" '.$autoOpen.'>
<summary onClick="openAllBlueprintsSections(\'blueprintsSection'.($thisUnit->Id).'\')" class="smallTitle" style="color:'.getFactionColor($info['Faction'], 'bright').';">
Blueprints
</summary>';
if ($userSettings['spookyMode']){
echo '<div class="flexWrap">';
}
foreach($buildable as $buildableUnit){
displayUnitlistUnit($buildableUnit, $userSettings, getTech($buildableUnit), formatFaction($buildableUnit->General->FactionName), $dataLoc, true);
}
if ($userSettings['spookyMode']){
echo '</div>';
}
echo '
</details>';
}
}
}
function displayEnhancements($info, $thisUnit, $userSettings, $dataLoc){
if (property_exists($thisUnit, "Enhancements")){
$enhancements = $thisUnit->Enhancements;
$blacklist = ["Slots"]; /// We don't want to get the "Remove " enhancements to display
echo '<div class="sheetSection">
<div class="smallTitle" style="color:'.getFactionColor($info['Faction'], 'bright').';">
Enhancements
</div>
<div class="flexColumn" style="width:100%;color:'.getFactionColor($info['Faction'], 'bright').';">
';
/// For each enhancement...
foreach($enhancements as $thisEnhancement){
if (!in_array($thisEnhancement, $blacklist)
&& property_exists($thisEnhancement, "Slot")
&&!property_exists($thisEnhancement, 'RemoveEnhancements')){
$autoOpen = '';
if ($userSettings['autoExpand']){
$autoOpen = 'open';
}
echo '<details class="weaponList" '.$autoOpen.'>
<summary class="weaponCategory">
<img
alt="X"
src="res/img/enhancements/'.$info['Faction'].'/'.($thisEnhancement->Icon).'_btn_up.png"
class="enhancementImg">
['.($thisEnhancement->Slot).'] '.attemptTranslation($thisEnhancement->Name, $dataLoc, $userSettings['lang']).'
</summary>
<div class="flexRows">
<div class="info" style="font-weight:normal;color:'.getFactionColor($info['Faction'], 'bright').';">
Build costs
</div>
<div class="flexColumns" style="padding-bottom:4px;color:black;">
<div class="energyCost">
<img alt="nrg" style="vertical-align:top;" src="res/img/icons/energy.png"> '.format($thisEnhancement->BuildCostEnergy).'
</div>
<div class="massCost">
<img alt="mss" style="vertical-align:top;" src="res/img/icons/mass.png"> '.format($thisEnhancement->BuildCostMass).'
</div>
<div class="buildTimeCost">
<img alt="tim" style="vertical-align:top;" src="res/img/icons/time.png"> '.format($thisEnhancement->BuildTime).'
</div>
</div>';
/// If the enhancement offers any yield, or has any drain, lets display that.
if (property_exists($thisEnhancement, 'ProductionPerSecondMass') ||
property_exists($thisEnhancement, 'ProductionPerSecondEnergy') ||
property_exists($thisEnhancement, 'MaintenanceConsumptionPerSecondEnergy') ||
property_exists($thisEnhancement, 'MaintenanceConsumptionPerSecondMass') ||
property_exists($thisEnhancement, 'BuildRate')){
$build = 0;
$nrg = 0;
$mass = 0;
if (property_exists($thisEnhancement, 'MaintenanceConsumptionPerSecondMass')) $mass -= $thisEnhancement->MaintenanceConsumptionPerSecondMass;
if (property_exists($thisEnhancement, 'MaintenanceConsumptionPerSecondEnergy')) $nrg -= $thisEnhancement->MaintenanceConsumptionPerSecondEnergy;
if (property_exists($thisEnhancement, 'BuildRate')) $build += $thisEnhancement->BuildRate;
if (property_exists($thisEnhancement, 'ProductionPerSecondEnergy')) $nrg += $thisEnhancement->ProductionPerSecondEnergy;
if (property_exists($thisEnhancement, 'ProductionPerSecondMass')) $mass += $thisEnhancement->ProductionPerSecondMass;
if (property_exists($thisEnhancement, 'BuildRate')) $nrg += $thisEnhancement->BuildRate;
echo '<div class="sheetSection">
<div class="info" style="font-weight:normal;color:'.getFactionColor($info['Faction'], 'bright').';">
Production / Consumption
</div>
<div class="flexColumns" style="padding-bottom:4px;color:black;">
<div class="energyCost">
<img alt="nrg" style="vertical-align:top;" src="res/img/icons/energy.png"> '.$nrg.'
</div>
<div class="massCost">
<img alt="mss" style="vertical-align:top;" src="res/img/icons/mass.png"> '.$mass.'
</div>
<div class="buildTimeCost">
<img alt="tim" style="vertical-align:top;" src="res/img/icons/time.png"> '.$build.'
</div>
</div>
</div>';
}
/// Now let's dump every enhancement info with its rough name and value
/// This is a list of values we don't want to display. They are useless to us, or already displayed elsewhere.
/// Should one of those values be encountered in the enhancement, it will be skipped
$blacklist = ['Slot',
'BuildCostEnergy',
'BuildCostMass',
'MaintenanceConsumptionPerSecondEnergy',
'MaintenanceConsumptionPerSecondMass',
'ProductionPerSecondEnergy',
'ProductionPerSecondMass',
'BuildTime',
'Name',
'Icon',
'BuildableCategoryAdds',
'Prerequisite',
'ShieldRegenStartTime',
'ShowBones',
'UpgradeEffectBones',
'UpgradeUnitAmbientBones',
'HideBones',
'OwnerShieldMesh',
'ImpactEffects',
'ShieldEnergyDrainRechargeTime',
'ImpactMesh',
'Mesh',
'MeshZ',
'ShieldEnhancementNumber',
'ShieldVerticalOffset',
'ShieldSpillOverDamageMod'];
foreach($thisEnhancement as $propName=>$property){
if (!in_array($propName, $blacklist)){
echo '
<div class="flexColumns" style="padding-bottom:6px;">';
// NEW HEALTH has the same formating has an unit healthbar
if ($propName == "NewHealth"){
echo '
<div class="littleInfo">
'.$propName.'
</div>
<div class="healthBar" style="height:auto;vertical-align:middle;margin:0px;">
'.($info['Health']+$property).'
</div>';
}
// SHIELD Health also has a custom formatting with pretty colours
else if ($propName == "ShieldMaxHealth"){
echo '
<div class="littleInfo">
'.$propName.'
</div>
<div class="shieldBar">
'.($property).'
</div>';
}
/// "Rates" have a value /per/second displayed
else if ($propName == "ShieldRegenRate" ||
$propName == "NewRateOfFire"){
echo '
<div class="littleInfo">
'.$propName.'
</div>
<div class="littleInfoVar">
'.$property.'/s
</div>';
}
/// Health regen rate has the same formatting as healthbar regen rate (+/s)
else if ($propName == "NewRegenRate"){
echo '
<div class="littleInfo">
'.$propName.'
</div>
<div class="littleInfoVar">
+'.($info['Regen']+$property).'/s
</div>';
}
/// Everything else is just displayed as-is
else{
echo '
<div class="littleInfo">
'.$propName.'
</div>
<div class="littleInfoVar">
'.$property.'
</div>';
}
echo '
</div>';
}
}
echo '
</div>
</details>';
}
}
echo '
</div>
</div>';
}
}
function displayWeaponList($info, $thisUnit, $dataLoc, $userSettings, $dataMissiles){
if (property_exists($thisUnit, "Weapon")){
echo '<div class="sheetSection">
<div class="smallTitle" style="color:'.getFactionColor($info['Faction'], 'bright').';">
Weapons
</div>
<div class="flexColumn" style="width:100%;color:'.getFactionColor($info['Faction'], 'bright').';">';
$weapons = $thisUnit->Weapon;
/// Count duplicate weapons so we can display them as "x2" "x3" etc
$alreadyDisplayed = array(); // Used to not display dupes twice
$registeredWeapons = array(); // Used to count amount of same weapons
foreach($weapons as $property=>$thisWeapon){
$found = false;
foreach($registeredWeapons as $key=>$thisRegisteredWeapon){
if (sameWeapon($thisWeapon, $thisRegisteredWeapon)){
$thisRegisteredWeapon = (array)$thisRegisteredWeapon;
if (!array_key_exists("Occurences", $thisRegisteredWeapon)){
$thisRegisteredWeapon ["Occurences"] = 1;
}
$thisRegisteredWeapon ["Occurences"]++;
$thisRegisteredWeapon = (object)$thisRegisteredWeapon;
$registeredWeapons[$key] = $thisRegisteredWeapon;
$found = true;
}
}
if (!$found){
$thisWeapon = (array)$thisWeapon;
$thisWeapon ["Occurences"] = 1;
$thisWeapon = (object)$thisWeapon;
$registeredWeapons[]= $thisWeapon;
}
}
$weapons = $registeredWeapons;
/// For each weapon...
foreach($weapons as $thisWeapon){
$skip = false;
foreach($alreadyDisplayed as $alreadyDisplayedWeapon){
if (sameWeapon($alreadyDisplayedWeapon, $thisWeapon)){
$skip = true;
break;
}
}
if (!$skip){
displayWeapon($thisWeapon, $info, $thisUnit, $dataLoc, $userSettings, $dataMissiles, $thisWeapon->Occurences);
$alreadyDisplayed [] = $thisWeapon;
}
}
echo ' </div>';
echo ' </div>';
}
}
function sameWeapon($wep1, $wep2){
// Checks if two weapons are the same, omitting Blueprint->Json artifacts (PropertyXXX, ...) by checking only some important values
$valuesToCheck = array('DisplayName', 'Damage', 'RateOfFire', 'DamageType');
$same = true;
foreach($valuesToCheck as $thisProperty){
if (
!property_exists($wep1, $thisProperty) ||
!property_exists($wep2, $thisProperty) ||
$wep1->$thisProperty != $wep2->$thisProperty
){
$same = false;
}
}
return $same;
}
function displayWeapon($thisWeapon, $info, $thisUnit, $dataLoc, $userSettings, $dataMissiles, $occurences=1){
if (property_exists($thisWeapon, 'DisplayName')){
$autoOpen = '';
/// Automatically unfolds weapon if "AutoExpand" user setting is set.
if ($userSettings['autoExpand']){
$autoOpen = 'open';
}
/// If the weapon is present multiple times, like for the Megalith for example, we display a little "x2" or "x3" with its name.
$duplicates = "";
if ($occurences > 1){
$duplicates = "[x".$occurences."] ";
}
/// Displaying name of the weapon
echo '<details class="weaponList" '.$autoOpen.'>
<summary class="weaponCategory">
'.$duplicates.(attemptTranslation($thisWeapon->DisplayName, $dataLoc, $userSettings['lang'])).'
</summary>
<div class="flexRows">';
//// The following properties will be displayed (the rough value, without units) if found.
$propertiesToDisplay = ['SlavedToBodyArcRange', 'FiringRandomnessWhileMoving', 'FiringRandomness', 'MaxProjectileStorage', 'DamageToShields', 'InitialDamage', 'DoTPulses', 'DoTTime'];
//// The following properties will be displayed (the rough value, without units) if found AND if their rough value is greater than 0.
$propertiesToDisplayGreaterThanZero = ['DamageRadius', 'MuzzleVelocity', 'FiringTolerance'];
//// The following properties will be displayed (the rough value, without units) if found AND if their rough value is greater than 1.
$propertiesToDisplayGreaterThanOne = ['MuzzleSalvoSize'];
// Displaying a colored name for the weapon category
if (property_exists($thisWeapon, 'WeaponCategory')){
echo '<div class="flexColumns weaponLine">
<div class="littleInfo" style="width:50%;">
Weapon Category
</div>
<div class="littleInfoVar" style="color:'.getWeaponCategoryColor($thisWeapon->WeaponCategory).';width:50%;text-align:left;">
'.($thisWeapon->WeaponCategory).'
</div>
</div>';
}
/// Displaying damage type if necessary
if (property_exists($thisWeapon, 'DamageType') &&
$thisWeapon->DamageType != "Normal"){
echo '<div class="flexColumns weaponLine">
<div class="littleInfo" >
DamageType
</div>
<div class="littleInfoVar" >
'.($thisWeapon->DamageType).'
</div>
</div>';
}
/// If the weapon uses a missile, and we have this missile in the $data, lets display more information about the missile
/// We need to find the missile/projectile before the DPS calculation, in case it uses a fragmentation weapon.
$WeaponProjectile = NULL;
if (property_exists($thisWeapon, 'ProjectileId')) {
$foundArr = [];
$found = preg_match('~(?<=projectiles\/).*(?=\/)~', $thisWeapon->ProjectileId, $foundArr);
if ($found) {
$projectileId = $foundArr[0];
/// There has got to be a better way to do this, right? Should make an array for projectiles at some future point.
if (strlen($projectileId) > 0) {
/// searching the needle in the haystack...
foreach ($dataMissiles as $thisMissile) {
if (strtoupper($thisMissile->Id) == strtoupper($projectileId)) {
// found it !
$WeaponProjectile = $thisMissile;
break;
}
}
}
}
}
/// Approximate DPS
if (property_exists($thisWeapon, 'Damage') &&
$thisWeapon->Damage > 0 &&
$thisWeapon->WeaponCategory != "Death"){
echo '<div class="flexColumns weaponLine" style="background-color:'.getFactionColor($info['Faction'], 'bright').';">
<div class="littleInfo" style="color:'.getFactionColor($info['Faction'], 'dark').';">
<b>Approximate DPS</b>
</div>
<div class="littleInfoVar" style="color:'.getFactionColor($info['Faction'], 'dark').';">
<b>'.format(calculateDps($thisWeapon, $info['Id'], $WeaponProjectile)).'</b>
</div>
</div>';
}
/// Specific Damage styled display if the weapon has damage
if (property_exists($thisWeapon, 'Damage') &&
$thisWeapon->Damage > 0){
echo '<div class="flexColumns weaponLine">
<div class="littleInfo" >
Raw Dmg
</div>
<div class="littleInfoVar" >
'.format($thisWeapon->Damage).'
</div>
';
if (property_exists($thisWeapon, 'RateOfFire')){
echo '<div class="littleInfo" style="text-align:right;border-left:1px dotted grey;">
Firerate
</div>
<div class="littleInfoVar" >
'.number_format (($thisWeapon->RateOfFire), 2).' /s
</div>';
}
echo '
</div>';
}
/// Displaying the rate of fire differently depending if the weapon has a continuous beam or not
if (property_exists($thisWeapon,'ContinuousBeam') &&
$thisWeapon->ContinuousBeam){
echo '<div class="flexColumns weaponLine">
<div class="littleInfo" >
Fire cycle
</div>
<div class="littleInfoVar" >
Continuous
</div>
</div>';
}
else if (property_exists($thisWeapon, 'MuzzleSalvoSize')){
echo '<div class="flexColumns weaponLine">
<div class="littleInfo" >
Fire cycle
</div>
<div class="littleInfoVar" >
'.calculateFireCycle($thisWeapon, $info['Id']).' projectiles / shot
</div>
</div>';
}
// Displaying range of the weapon - both minradius and maxradius if available
if (property_exists($thisWeapon, 'MaxRadius') &&
$thisWeapon->MaxRadius > 0){
echo '<div class="flexColumns weaponLine">
<div class="littleInfo" >
Range
</div>
<div class="littleInfoVar" >
';
if (property_exists($thisWeapon, 'MinRadius') &&
$thisWeapon->MinRadius > 0){
echo ($thisWeapon->MinRadius).'-';
}