forked from mgreach/ta-combat-sim-pro
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathta_sim.user.js
1569 lines (1466 loc) · 69.5 KB
/
ta_sim.user.js
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
// ==UserScript==
// @name Tiberium Alliances Combat Simulator
// @description Allows you to simulate combat before actually attacking.
// @namespace https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @version 1.4.0.9
// @author WildKatana | Updated by CodeEcho, PythEch, Matthias Fuchs, Enceladus, KRS_L, TheLuminary, Panavia2, Da Xue, MrHIDEn, JDuarteDJ
// @require http://sizzlemctwizzle.com/updater.php?id=138212
// ==/UserScript==
(function () {
var TASuite_mainFunction = function () {
console.log("Simulator loaded");
// Using EA's API (Limited Support)
function LimitedCreateTweak() {
var TASuite = {};
qx.Class.define("TASuite.main", {
type: "singleton",
extend: qx.core.Object,
members: {
buttons: {
attack: {
simulate: null, // buttonSimulateCombat
unlock: null // buttonUnlockAttack
},
shiftFormationUp: null,
shiftFormationDown: null,
shiftFormationLeft: null,
shiftFormationRight: null
},
units: null,
saved_units: null,
initialize: function () {
var armyBar = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_ATTACKSETUP);
this.buttons.attack.simulate = new qx.ui.form.Button("Simulate");
this.buttons.attack.simulate.set({
width: 58,
appearance: "button-text-small",
toolTipText: "Start Combat Simulation"
});
this.buttons.attack.simulate.addListener("click", this.startSimulation, this);
armyBar.add(this.buttons.attack.simulate, {
top: 112,
right: 62
});
this.buttons.attack.unlock = new qx.ui.form.Button("Unlock");
this.buttons.attack.unlock.set({
width: 55,
height: 46,
appearance: "button-text-small",
toolTipText: "Unlock Attack Button"
});
this.buttons.attack.unlock.addListener("click", this.unlockAttacks, this);
this.buttons.attack.unlock.setOpacity(0.5);
armyBar.add(this.buttons.attack.unlock, {
top: 107,
right: 4
});
this.buttons.ShiftFormationLeft = new qx.ui.form.Button("<");
this.buttons.ShiftFormationLeft.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units Left"
});
this.buttons.ShiftFormationLeft.addListener("click", this.shiftFormationLeft, this);
this.buttons.ShiftFormationRight = new qx.ui.form.Button(">");
this.buttons.ShiftFormationRight.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units RIGHT"
});
this.buttons.ShiftFormationRight.addListener("click", this.shiftFormationRight, this);
this.buttons.ShiftFormationUp = new qx.ui.form.Button("^");
this.buttons.ShiftFormationUp.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units UP"
});
this.buttons.ShiftFormationUp.addListener("click", this.shiftFormationUp, this);
this.buttons.ShiftFormationDown = new qx.ui.form.Button("v");
this.buttons.ShiftFormationDown.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units DOWN"
});
this.buttons.ShiftFormationDown.addListener("click", this.shiftFormationDown, this);
armyBar.add(this.buttons.ShiftFormationUp, {
top: 21,
right: 77
});
armyBar.add(this.buttons.ShiftFormationLeft, {
top: 40,
right: 92
});
armyBar.add(this.buttons.ShiftFormationRight, {
top: 40,
right: 62
});
armyBar.add(this.buttons.ShiftFormationDown, {
top: 55,
right: 77
});
_this = this;
},
unlockAttacks: function () {
var armyBar = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_ATTACKSETUP);
armyBar.remove(this.buttons.attack.unlock);
var _this = this;
setTimeout(function () {
armyBar.add(_this.buttons.attack.unlock);
}, 2000);
},
startSimulation: function () {
try {
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
ownCity.get_CityArmyFormationsManager().set_CurrentTargetBaseId(city.get_Id());
ClientLib.Data.MainData.GetInstance().get_Combat().Clear();
city.SimulateBattle();
ClientLib.Data.MainData.GetInstance().get_Combat().set_Id(city.get_Id());
var app = qx.core.Init.getApplication();
app.getPlayArea().setView(webfrontend.gui.PlayArea.PlayArea.modes.EMode_CombatAttacker, city.get_Id(), 0, 0);
} catch (e) {
console.log(e);
}
},
getCityPreArmyUnits: function () {
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
var formationManager = ownCity.get_CityArmyFormationsManager();
var units = formationManager.GetFormationByTargetBaseId(formationManager.get_CurrentTargetBaseId());
return units;
},
restoreFormation: function (saved_units) {
var sUnits = saved_units || this.saved_units;
var units = this.getCityPreArmyUnits();
var units_list = units.get_ArmyUnits().l;
for (var idx = 0; idx < sUnits.length; idx++) {
var saved_unit = sUnits[idx];
var uid = saved_unit.id;
for (var i = 0;
(i < units_list.length); i++) {
if (units_list[i].get_Id() === uid) {
units_list[i].MoveBattleUnit(saved_unit.x, saved_unit.y);
if (saved_unit.enabled === undefined) units_list[i].set_Enabled(true);
else units_list[i].set_Enabled(saved_unit.enabled);
}
}
}
units.UpdateFormation(true); //this works and USES the API so works for both servers
//units.CLEZCG(); // UpdateArmyLayout$0() has been renamed to CLEZCG()
//units.WRKUTR(); // RefreshData() has been renamed to WRKUTR()
},
shiftFormation: function (direction) { //left right up down
if (!direction) var direction = window.prompt("indicate a direction to shift units: up(u), down(d), left(l) or right(r)");
if (direction == "up" || direction == "u") var v_shift = -1;
if (direction == "down" || direction == "d") var v_shift = 1;
if (direction == "left" || direction == "l") var h_shift = -1;
if (direction == "right" || direction == "r") var h_shift = 1;
if (!v_shift) var v_shift = 0;
if (!h_shift) var h_shift = 0;
var units = this.getCityPreArmyUnits();
this.units = units.get_ArmyUnits().l;
var Army = [];
//read army, consider use saveFormation(?)
for (var i = 0;
(i < this.units.length); i++) {
var unit = this.units[i];
var armyUnit = {};
var x = unit.get_CoordX() + h_shift;
switch (x) {
case 9:
x = 0;
break;
case -1:
x = 8;
break;
}
var y = unit.get_CoordY() + v_shift;
switch (y) {
case 4:
y = 0;
break;
case -1:
y = 3;
break;
}
armyUnit.x = x;
armyUnit.y = y;
armyUnit.id = unit.get_Id();
armyUnit.enabled = unit.get_Enabled();
Army.push(armyUnit);
}
this.restoreFormation(Army);
},
shiftFormationUp: function () {
this.shiftFormation('u');
},
shiftFormationDown: function () {
this.shiftFormation('d');
},
shiftFormationLeft: function () {
this.shiftFormation('l');
},
shiftFormationRight: function () {
this.shiftFormation('r');
}
}
});
}
function CreateTweak() {
var TASuite = {};
qx.Class.define("TASuite.main", {
type: "singleton",
extend: qx.core.Object,
members: {
buttons: {
attack: {
layout: {
save: null, // buttonLayoutSave
load: null, // buttonLayoutLoad
},
simulate: null, // buttonSimulateCombat
unlock: null, // buttonUnlockAttack
unlockReset: null, // buttonUnlockReset
tools: null, // buttonTools
shiftFormationUp: null,
shiftFormationDown: null,
shiftFormationLeft: null,
shiftFormationRight: null
},
simulate: {
back: null // buttonReturnSetup
}
},
stats: {
spoils: {
tiberium: null, // tiberiumSpoils
crystal: null, // crystalSpoils
credit: null, // creditSpoils
research: null // researchSpoils
},
health: {
infantry: null, // lastInfantryPercentage
vehicle: null, // lastVehiclePercentage
aircraft: null, // lastAirPercentage
overall: null, // lastPercentage
},
repair: {
infantry: null, // lastInfantryRepairTime
vehicle: null, // lastVehicleRepairTime
aircraft: null, // lastAircraftRepairTime
overall: null // lastRepairTime
},
damage: {
units: {
overall: null // lastEnemyUnitsPercentage
},
structures: {
construction: null, // lastCYPercentage
defense: null, // lastDFPercentage
command: null, // lastCCPercentage
overall: null // lastEnemyBuildingsPercentage
},
overall: null // lastEnemyPercentage
}
},
labels: {
health: {
infantry: null, // infantryTroopStrengthLabel
vehicle: null, // vehicleTroopStrengthLabel
aircraft: null, // airTroopStrengthLabel
overall: null // simTroopDamageLabel
},
damage: {
units: {
overall: null // enemyUnitsStrengthLabel
},
structures: {
construction: null, // CYTroopStrengthLabel
defense: null, // DFTroopStrengthLabel
command: null, // CCTroopStrengthLabel
support: null, // enemySupportStrengthLabel
overall: null // enemyBuildingsStrengthLabel
},
overall: null, // enemyTroopStrengthLabel
outcome: null // simVictoryLabel
},
repair: {
overall: null // simRepairTimeLabel
},
time: null, // simTimeLabel
supportlevel: null // enemySupportLevelLabel
},
add_ViewModeChange: null,
add_ArmyChanged: null,
attacker_modules: null,
defender_modules: null,
units: null,
units_list: null,
saved_units: null,
layoutsList: null,
layoutsLabelText: null,
battleResultsBox: null,
statsPage: null,
totalSeconds: null,
isPlayerCity: null,
initializeStats: function (tabView) {
// ////////////////Stats ////////////////////
this.statsPage = new qx.ui.tabview.Page("Stats");
this.statsPage.setLayout(new qx.ui.layout.VBox(5));
this.statsPage.setPadding(1);
tabView.add(this.statsPage);
// The Enemy Vertical Box
var eVBox = new qx.ui.container.Composite();
eVBox.setLayout(new qx.ui.layout.VBox(5));
eVBox.setThemedFont("bold");
eVBox.setThemedPadding(2);
eVBox.setThemedBackgroundColor("#eef");
this.statsPage.add(eVBox);
// The Enemy Troop Strength Label
var eHBox1 = new qx.ui.container.Composite();
eHBox1.setLayout(new qx.ui.layout.HBox(5));
eHBox1.add(new qx.ui.basic.Label("Enemy Base: "));
this.labels.damage.overall = new qx.ui.basic.Label("100");
eHBox1.add(this.labels.damage.overall);
this.labels.damage.overall.setTextColor("red");
eVBox.add(eHBox1);
// Units
var eHBox4 = new qx.ui.container.Composite();
eHBox4.setLayout(new qx.ui.layout.HBox(5));
eHBox4.add(new qx.ui.basic.Label("Defences: "));
this.labels.damage.units.overall = new qx.ui.basic.Label("100");
eHBox4.add(this.labels.damage.units.overall);
this.labels.damage.units.overall.setTextColor("green");
eVBox.add(eHBox4);
// Buildings
var eHBox5 = new qx.ui.container.Composite();
eHBox5.setLayout(new qx.ui.layout.HBox(5));
eHBox5.add(new qx.ui.basic.Label("Buildings: "));
this.labels.damage.structures.overall = new qx.ui.basic.Label("100");
eHBox5.add(this.labels.damage.structures.overall);
this.labels.damage.structures.overall.setTextColor("green");
eVBox.add(eHBox5);
// Command Center
var eHBox2 = new qx.ui.container.Composite();
eHBox2.setLayout(new qx.ui.layout.HBox(5));
eHBox2.add(new qx.ui.basic.Label("Construction Yard: "));
this.labels.damage.structures.construction = new qx.ui.basic.Label("100");
eHBox2.add(this.labels.damage.structures.construction);
this.labels.damage.structures.construction.setTextColor("red");
eVBox.add(eHBox2);
// Defense Facility
var eHBox3 = new qx.ui.container.Composite();
eHBox3.setLayout(new qx.ui.layout.HBox(5));
eHBox3.add(new qx.ui.basic.Label("Defense Facility: "));
this.labels.damage.structures.defense = new qx.ui.basic.Label("100");
eHBox3.add(this.labels.damage.structures.defense);
this.labels.damage.structures.defense.setTextColor("red");
eVBox.add(eHBox3);
// Command Center
var eHBox6 = new qx.ui.container.Composite();
eHBox6.setLayout(new qx.ui.layout.HBox(5));
eHBox6.add(new qx.ui.basic.Label("Command Center: "));
this.labels.damage.structures.command = new qx.ui.basic.Label("100"), eHBox6.add(this.labels.damage.structures.command);
this.labels.damage.structures.command.setTextColor("red");
eVBox.add(eHBox6);
// The Support Horizontal Box
var hboxSupportContainer = new qx.ui.container.Composite();
hboxSupportContainer.setLayout(new qx.ui.layout.HBox(5));
this.labels.supportlevel = new qx.ui.basic.Label("Suport lvl ");
hboxSupportContainer.add(this.labels.supportlevel);
this.labels.damage.structures.support = new qx.ui.basic.Label("--: 100");
hboxSupportContainer.add(this.labels.damage.structures.support);
this.labels.damage.structures.support.setTextColor("red");
eVBox.add(hboxSupportContainer);
// The Troops Vertical Box
var tVBox = new qx.ui.container.Composite();
tVBox.setLayout(new qx.ui.layout.VBox(5));
tVBox.setThemedFont("bold");
tVBox.setThemedPadding(2);
tVBox.setThemedBackgroundColor("#eef");
this.statsPage.add(tVBox);
// The Repair Time Label
var tHBox1 = new qx.ui.container.Composite();
tHBox1.setLayout(new qx.ui.layout.HBox(5));
tHBox1.add(new qx.ui.basic.Label("Repair Time: "));
this.labels.repair.overall = new qx.ui.basic.Label("0:00:00");
tHBox1.add(this.labels.repair.overall);
this.labels.repair.overall.setTextColor("blue");
tVBox.add(tHBox1);
// The Troop Strength Label
var tHBox5 = new qx.ui.container.Composite();
tHBox5.setLayout(new qx.ui.layout.HBox(5));
tHBox5.add(new qx.ui.basic.Label("Overall: "));
this.labels.health.overall = new qx.ui.basic.Label("100");
tHBox5.add(this.labels.health.overall);
this.labels.health.overall.setTextColor("blue");
tVBox.add(tHBox5);
// The Infantry Troop Strength Label
var tHBox2 = new qx.ui.container.Composite();
tHBox2.setLayout(new qx.ui.layout.HBox(5));
tHBox2.add(new qx.ui.basic.Label("Infantry: "));
this.labels.health.infantry = new qx.ui.basic.Label("100");
tHBox2.add(this.labels.health.infantry);
this.labels.health.infantry.setTextColor("green");
tVBox.add(tHBox2);
// The Vehicle Troop Strength Label
var tHBox3 = new qx.ui.container.Composite();
tHBox3.setLayout(new qx.ui.layout.HBox(5));
tHBox3.add(new qx.ui.basic.Label("Vehicle: "));
this.labels.health.vehicle = new qx.ui.basic.Label("100");
tHBox3.add(this.labels.health.vehicle);
this.labels.health.vehicle.setTextColor("green");
tVBox.add(tHBox3);
// The Air Troop Strength Label
var tHBox4 = new qx.ui.container.Composite();
tHBox4.setLayout(new qx.ui.layout.HBox(5));
tHBox4.add(new qx.ui.basic.Label("Aircraft: "));
this.labels.health.aircraft = new qx.ui.basic.Label("100");
tHBox4.add(this.labels.health.aircraft);
this.labels.health.aircraft.setTextColor("green");
tVBox.add(tHBox4);
// The inner Vertical Box
var vBox = new qx.ui.container.Composite();
vBox.setLayout(new qx.ui.layout.VBox(5));
vBox.setThemedFont("bold");
vBox.setThemedPadding(2);
vBox.setThemedBackgroundColor("#eef");
// The Victory Label
var hBox2 = new qx.ui.container.Composite();
hBox2.setLayout(new qx.ui.layout.HBox(5));
hBox2.add(new qx.ui.basic.Label("Outcome: "));
this.labels.damage.outcome = new qx.ui.basic.Label("Unknown");
hBox2.add(this.labels.damage.outcome);
this.labels.damage.outcome.setTextColor("green");
vBox.add(hBox2);
// The Battle Time Label
var hBox1 = new qx.ui.container.Composite();
hBox1.setLayout(new qx.ui.layout.HBox(5));
hBox1.add(new qx.ui.basic.Label("Battle Time: "));
this.labels.time = new qx.ui.basic.Label("120");
hBox1.add(this.labels.time);
this.labels.time.setTextColor("black");
vBox.add(hBox1);
this.statsPage.add(vBox);
},
initializeLayout: function (tabView) {
// ////////////////Layouts ////////////////////
var layoutPage = new qx.ui.tabview.Page("Layouts");
layoutPage.setLayout(new qx.ui.layout.VBox());
tabView.add(layoutPage);
this.layoutsList = new qx.ui.form.List();
this.layoutsList.set({
height: 200,
width: 180,
selectionMode: "one"
});
layoutPage.add(this.layoutsList);
// Add the two buttons for save and load
var layHBox = new qx.ui.container.Composite();
layHBox.setLayout(new qx.ui.layout.HBox(5));
// Load button
this.buttons.attack.layout.load = new qx.ui.form.Button("Load");
this.buttons.attack.layout.load.set({
width: 80,
appearance: "button-text-small",
toolTipText: "Load this saved layout."
});
this.buttons.attack.layout.load.addListener("click", this.loadCityLayout, this);
layHBox.add(this.buttons.attack.layout.load);
// Delete button
this.buttonLayoutDelete = new qx.ui.form.Button("Delete");
this.buttonLayoutDelete.set({
width: 80,
appearance: "button-text-small",
toolTipText: "Delete this saved layout."
});
this.buttonLayoutDelete.addListener("click", this.deleteCityLayout,
this);
layHBox.add(this.buttonLayoutDelete);
layoutPage.add(layHBox);
var layVBox = new qx.ui.container.Composite();
layVBox.setLayout(new qx.ui.layout.VBox(5));
layVBox.setThemedFont("bold");
layVBox.setThemedPadding(2);
layVBox.setThemedBackgroundColor("#eef");
// The Label Textbox
var layHBox2 = new qx.ui.container.Composite();
layHBox2.setLayout(new qx.ui.layout.HBox(5));
layHBox2.add(new qx.ui.basic.Label("Name: "));
this.layoutsLabelText = new qx.ui.form.TextField();
layHBox2.add(this.layoutsLabelText);
layVBox.add(layHBox2);
this.buttons.attack.layout.save = new qx.ui.form.Button("Save");
this.buttons.attack.layout.save.set({
width: 80,
appearance: "button-text-small",
toolTipText: "Save this layout."
});
this.buttons.attack.layout.save.addListener("click", this.saveCityLayout, this);
layVBox.add(this.buttons.attack.layout.save);
layoutPage.add(layVBox);
},
initializeInfo: function (tabView) {
// //////////////// Info ////////////////////
var infoPage = new qx.ui.tabview.Page("Info");
infoPage.setLayout(new qx.ui.layout.VBox(5));
tabView.add(infoPage);
// The Help Vertical Box
var pVBox = new qx.ui.container.Composite();
pVBox.setLayout(new qx.ui.layout.VBox(5));
pVBox.setThemedFont("bold");
pVBox.setThemedPadding(2);
pVBox.setThemedBackgroundColor("#eef");
infoPage.add(pVBox);
var proHelpBar = new qx.ui.basic.Label().set({
value: "<a target='_blank' href='http://userscripts.org/scripts/discuss/130344'>Forums</a>",
rich: true
});
pVBox.add(proHelpBar);
// The Spoils
var psVBox = new qx.ui.container.Composite();
psVBox.setLayout(new qx.ui.layout.VBox(5));
psVBox.setThemedFont("bold");
psVBox.setThemedPadding(2);
psVBox.setThemedBackgroundColor("#eef");
infoPage.add(psVBox);
psVBox.add(new qx.ui.basic.Label("Spoils"));
// Tiberium
this.stats.spoils.tiberium = new qx.ui.basic.Atom("0", "webfrontend/ui/common/icn_res_tiberium.png");
psVBox.add(this.stats.spoils.tiberium);
// Crystal
this.stats.spoils.crystal = new qx.ui.basic.Atom("0", "webfrontend/ui/common/icn_res_chrystal.png");
psVBox.add(this.stats.spoils.crystal);
// Credits
this.stats.spoils.credit = new qx.ui.basic.Atom("0", "webfrontend/ui/common/icn_res_dollar.png");
psVBox.add(this.stats.spoils.credit);
// Research
this.stats.spoils.research = new qx.ui.basic.Atom("0", "webfrontend/ui/common/icn_res_research_mission.png");
psVBox.add(this.stats.spoils.research);
this.battleResultsBox.add(tabView);
},
initialize: function () {
this.add_ViewModeChange = (new ClientLib.Vis.ViewModeChange).LEUXCZ(this, this.onViewChange); //
this.add_ArmyChanged = (new $I.QUXOEF).LEUXCZ(this, this.onUnitMoved); //
this.buttons.attack.simulate = new qx.ui.form.Button("Simulate");
this.buttons.attack.simulate.set({
width: 58,
appearance: "button-text-small",
toolTipText: "Start Combat Simulation"
});
this.buttons.attack.simulate.addListener("click", this.startSimulation, this);
this.buttons.simulate.back = new qx.ui.form.Button("Setup");
this.buttons.simulate.back.set({
width: 80,
appearance: "button-text-small",
toolTipText: "Return to Combat Setup"
});
this.buttons.simulate.back.addListener("click", this.returnSetup, this);
this.buttons.ShiftFormationLeft = new qx.ui.form.Button("<");
this.buttons.ShiftFormationLeft.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units Left"
});
this.buttons.ShiftFormationLeft.addListener("click", this.shiftFormationLeft, this);
this.buttons.ShiftFormationRight = new qx.ui.form.Button(">");
this.buttons.ShiftFormationRight.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units RIGHT"
});
this.buttons.ShiftFormationRight.addListener("click", this.shiftFormationRight, this);
this.buttons.ShiftFormationUp = new qx.ui.form.Button("^");
this.buttons.ShiftFormationUp.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift units UP"
});
this.buttons.ShiftFormationUp.addListener("click", this.shiftFormationUp, this);
this.buttons.ShiftFormationDown = new qx.ui.form.Button("v");
this.buttons.ShiftFormationDown.set({
width: 30,
appearance: "button-text-small",
toolTipText: "Shift DOWN"
});
this.buttons.ShiftFormationDown.addListener("click", this.shiftFormationDown, this);
var replayBar = qx.core.Init.getApplication().getReportReplayOverlay();
replayBar.add(this.buttons.simulate.back, {
top: 10,
left: 0
});
var replayBar = qx.core.Init.getApplication().getReportReplayOverlay();
replayBar.add(this.buttons.simulate.back, {
top: 10,
left: 0
});
var armyBar = qx.core.Init.getApplication().getUIItem(ClientLib.Data.Missions.PATH.BAR_ATTACKSETUP);
this.buttons.attack.unlock = new qx.ui.form.Button("Unlock");
this.buttons.attack.unlock.set({
width: 55,
height: 46,
appearance: "button-text-small",
toolTipText: "Unlock Attack Button"
});
this.buttons.attack.unlock.addListener("click", this.unlockAttacks, this);
this.buttons.attack.unlock.setOpacity(0.5);
armyBar.add(this.buttons.attack.unlock, {
top: 102,
right: 4
});
this.buttons.attack.unlockReset = new qx.ui.form.Button("Unlock");
this.buttons.attack.unlockReset.set({
width: 55,
height: 42,
appearance: "button-text-small",
toolTipText: "Unlock Reset Button"
});
this.buttons.attack.unlockReset.addListener("click", this.unlockResets, this);
this.buttons.attack.unlockReset.setOpacity(0.5);
armyBar.add(this.buttons.attack.unlockReset, {
top: 59,
right: 4
});
this.buttons.attack.tools = new qx.ui.form.Button("Tools");
this.buttons.attack.tools.set({
width: 58,
appearance: "button-text-small",
toolTipText: "Open Simulator Tools"
});
this.buttons.attack.tools.addListener("click", this.toggleTools, this);
var battleUnitData = $I.PJNPPV.prototype;
if (!battleUnitData.set_Enabled_Original) {
battleUnitData.set_Enabled_Original = battleUnitData.set_Enabled;
}
battleUnitData.set_Enabled = function (a) {
this.set_Enabled_Original(a);
var ta = window.TASuite.main.getInstance();
ta.onUnitMoved();
};
_this = this;
setTimeout(
function () {
try {
// Get the active modules
// Doing this the hard and unreliable way for now, until
// we figure out a better way
_this.attacker_modules = {};
_this.attacker_modules.l = [];
var g = ClientLib.Res.ResMain.GetInstance();
// Get the player faction
// var gdi_unit_ids = g.GetFactionUnitIds(1);
// var nod_unit_ids = g.GetFactionUnitIds(2);
// var forgotten_unit_ids = g.GetFactionUnitIds(3);
var player_research = ClientLib.Data.MainData.GetInstance().get_Player().get_PlayerResearch();
for (var i in g.EUIRZQ.units) { //
var ug = g.GetUnit_Obj(i);
var research = player_research.GetResearchItemFomMdbId(ug.tl);
var modules = ug.m;
for (var j in modules) {
var module = modules[j];
if (research && module.r.length > 0) {
try {
// This is an upgradeable ability
var required_level = module.r[0].l;
var current_level = research.get_CurrentLevel();
if (current_level >= required_level) {
_this.attacker_modules.l.push(module.i);
}
} catch (e) {
console.log(e);
}
} else {
_this.attacker_modules.l.push(module.i);
}
}
}
// Get the defender modules
_this.defender_modules = _this.attacker_modules;
ClientLib.Vis.VisMain.GetInstance().add_ViewModeChange(
_this.add_ViewModeChange);
armyBar.add(_this.buttons.attack.tools, {
top: 74,
right: 62
});
armyBar.add(_this.buttons.attack.simulate, {
top: 112,
right: 62
});
armyBar.add(_this.buttons.ShiftFormationUp, {
top: 21,
right: 77
});
armyBar.add(_this.buttons.ShiftFormationLeft, {
top: 40,
right: 92
});
armyBar.add(_this.buttons.ShiftFormationRight, {
top: 40,
right: 62
});
armyBar.add(_this.buttons.ShiftFormationDown, {
top: 55,
right: 77
});
} catch (e) {
console.log(e);
}
}, 10000);
// The Battle Simulator box
this.battleResultsBox = new qx.ui.window.Window("Battle Simulator");
this.battleResultsBox.setPadding(1);
this.battleResultsBox.setLayout(new qx.ui.layout.VBox(1));
this.battleResultsBox.setShowMaximize(false);
this.battleResultsBox.setShowMinimize(false);
this.battleResultsBox.moveTo(125, 125);
this.battleResultsBox.setHeight(300);
this.battleResultsBox.setWidth(200);
var tabView = new qx.ui.tabview.TabView();
tabView.setPadding(5);
this.battleResultsBox.add(tabView);
this.initializeStats(tabView);
this.initializeLayout(tabView);
this.initializeInfo(tabView);
},
closeToolsBox: function () {
try {
var units = this.getCityPreArmyUnits();
if (units) {
units.remove_ArmyChanged(this.add_ArmyChanged);
}
this.battleResultsBox.close();
} catch (e) {
console.log(e);
}
},
toggleTools: function () {
var units = this.getCityPreArmyUnits();
this.units = units.get_ArmyUnits().l;
var cityFaction = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity().get_CityFaction();
this.isPlayerCity = false;
if ((cityFaction === ClientLib.Base.EFactionType.GDIFaction) || (cityFaction === ClientLib.Base.EFactionType.NODFaction)) this.isPlayerCity = true;
if (this.battleResultsBox.isVisible()) {
this.closeToolsBox();
} else {
// Add the event listener for armybar
try {
units.remove_ArmyChanged(this.add_ArmyChanged);
units.add_ArmyChanged(this.add_ArmyChanged);
} catch (e) {
console.log(e);
}
this.updateLayoutsList();
this.calculateLoot();
this.calculateSimResults();
this.updateStatsWindow();
this.battleResultsBox.open();
}
},
getCityPreArmyUnits: function () {
var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
var formationManager = ownCity.get_CityArmyFormationsManager();
var units = formationManager.GetFormationByTargetBaseId(formationManager.get_CurrentTargetBaseId());
return units;
},
calculateLoot: function () {
// Adapted from the CNC Loot script:
// http://userscripts.org/scripts/show/135953
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentCity();
var num = 0;
var spoils = {
1: 0,
2: 0,
3: 0,
6: 0,
7: 0
};
if (city.get_CityBuildingsData().HWFIJH !== null) {
// every building
num = city.get_CityBuildingsData().HWFIJH.l.length;
for (var j = num; --j >= 0;) {
var building = city.get_CityBuildingsData().HWFIJH.l[j];
// TODO: check for destroyed building
var mod = building.get_HitpointsPercent();
for (var i = building.MNNADO.rer.length; --i >= 0;) {
spoils[building.MNNADO.rer[i].t] += mod * building.MNNADO.rer[i].c;
}
}
}
// every unit
if (city.get_CityUnitsData().TXDWUM !== null) {
num = city.get_CityUnitsData().TXDWUM.l.length;
for (j = num; --j >= 0;) {
var unit = city.get_CityUnitsData().TXDWUM.l[j];
mod = unit.get_HitpointsPercent();
for (i = unit.MNNADO.rer.length; --i >= 0;) {
spoils[unit.MNNADO.rer[i].t] += mod * unit.MNNADO.rer[i].c;
}
}
}
this.stats.spoils.tiberium.setLabel(this.formatNumberWithCommas(spoils[1]));
this.stats.spoils.crystal.setLabel(this.formatNumberWithCommas(spoils[2]));
this.stats.spoils.credit.setLabel(this.formatNumberWithCommas(spoils[3]));
this.stats.spoils.research.setLabel(this.formatNumberWithCommas(spoils[6]));
},
calculateSimResults: function () {
var battleground = this.setupBattleground(this.getCityPreArmyUnits());
// Run the simulation until it's done
while (battleground.DHSWQJ.OAEJMD(false)) {}
// DoStep$0 was renamed to OAEJMD, m_Simulation was renamed to DHSWQJ
this.calculateTroopStrengths(battleground);
},
onUnitMoved: function (sender, e) {
if (this.battleResultsBox.isVisible()) {
var ta = window.TASuite.main.getInstance();
ta.calculateSimResults();
ta.updateStatsWindow();
}
},
calculateTroopStrengths: function (battleground) {
var battleground = ClientLib.Vis.VisMain.GetInstance().get_Battleground();
var total_hp = 0;
var end_hp = 0;
var e_total_hp = 0;
var e_end_hp = 0;
var eb_total_hp = 0;
var eb_end_hp = 0;
var eu_total_hp = 0;
var eu_end_hp = 0;
var i_end_hp = 0;
var v_end_hp = 0;
var a_end_hp = 0;
var v_total_hp = 0;
var a_total_hp = 0;
var i_total_hp = 0;
this.stats.damage.structures.defense = 0;
this.stats.damage.structures.construction = 0;
this.stats.damage.structures.command = 0;
this.SupportLevel = 0;
this.lastSupportPercentage = 0;
this.stats.repair.infantry = 0;
this.stats.repair.vehicle = 0;
this.stats.repair.aircraft = 0;
var own_city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
var crd = own_city.get_CityRepairData();
var cud = own_city.get_CityUnitsData();
//Found something similar in the API but the values I get are lower... using cud.GetRepairTimeFromEUnitGroup(ClientLib.Data.EUnitGroup.Infantry) -- note that its a function not an array -- instead of repair[ClientLib.Data.EUnitGroup.Infantry], this example refers to infantery but applies to all members of ClientLib.Data.EUnitGroup
var repair_times = own_city.get_CityUnitsData().EDTHDX.d; // m_FullRawRepairTimeForUnitGroupTypes renamed to EDTHDX
var r_types = ClientLib.Base.EResourceType;
var entities = battleground.NNXRBC.d; // m_Entities has been renamed to NNXRBC
for (var i in entities) {
var entity = entities[i];
var i_entity = entity.QXYJOG; // get_Entity$0() has been removed. Propery is $I.TQL - QXYJOG
var a_entity = entity.GUXBBT; // ??? has been renamed to GUXBBT
var current_hp = i_entity.HOTKDN; // m_iHitpointsCurrent has been renamed to HOTKDN
var max_hp = i_entity.EUJPNP; // m_iHitpoints has been renamed to EUJPNP
if (a_entity.XPEHRJ === 2) { // ??? has been renamed to XPEHRJ, Attacker is 2
// This is one of the good guys
end_hp += current_hp;
total_hp += max_hp;
switch (a_entity.TRKXAB) { // movement type has been renamed toTRKXAB
case ClientLib.Base.EUnitMovementType.Air:
case ClientLib.Base.EUnitMovementType.Air2:
a_end_hp += current_hp;
a_total_hp += max_hp;
break;
case ClientLib.Base.EUnitMovementType.Feet:
i_end_hp += current_hp;
i_total_hp += max_hp;
break;
case ClientLib.Base.EUnitMovementType.Track:
case ClientLib.Base.EUnitMovementType.Wheel:
v_end_hp += current_hp;
v_total_hp += max_hp;
break;
case ClientLib.Base.EUnitMovementType.Structure:
break;
}
} else {
// Enemy Overall
e_total_hp += max_hp;
e_end_hp += current_hp;
if (i_entity.XZXAQZ >= 200 && i_entity.XZXAQZ <= 205) {
this.SupportLevel = parseInt(i_entity.BGYEIQ); // m_iLevel has been renamed to BGYEIQ
this.lastSupportPercentage = (current_hp / max_hp) * 100;
} else {
switch (i_entity.XZXAQZ) {
// m_MDCTypeId has been renamed to XZXAQZ
case 112:
// GDI YARD
case 151:
// NOD CY
case 177:
// FOR CY
this.stats.damage.structures.construction = (current_hp / max_hp) * 100;
break;
case 158:
// NOD DF
case 131:
// GDI DF
case 195:
// FOR DF
this.stats.damage.structures.defense = (current_hp / max_hp) * 100;
break;
case 111:
// GDI CC
case 159:
// NOD CC
this.stats.damage.structures.command = (current_hp / max_hp) * 100;
break;
}
}
switch (a_entity.TRKXAB) {
case ClientLib.Base.EUnitMovementType.Structure:
// Enemy Building
eb_total_hp += max_hp;
eb_end_hp += current_hp;
break;
default:
// Enemy Defence
eu_total_hp += max_hp;
eu_end_hp += current_hp;
break;
}
}
}
// Get MaxHealth for UnitTypes
var totalInfantryHealth = 0;
var totalVehicleHealth = 0;
var totalAirHealth = 0;
for (var i in this.units) {
switch (this.units[i].get_UnitGameData_Obj().at) {
case ClientLib.Data.EUnitGroup.Infantry:
totalInfantryHealth += (this.units[i].get_MaxHealth() * 16);
break;