Skip to content

Commit aa6821a

Browse files
committed
Fixed bugs with being able to move units before the indicator requests that they be selected.
Now the units will not move until the indicator is ready and the condition is met.
1 parent 95fa7d3 commit aa6821a

File tree

1 file changed

+138
-29
lines changed

1 file changed

+138
-29
lines changed

mods/redux/redux/DOMDocument.xml

Lines changed: 138 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function max() {
2525
function sgn() {
2626
return _level1.sgn.apply(_root._level1, arguments);
2727
}
28+
function isArray() {
29+
return _level1.isArray.apply(_root.level1, arguments);
30+
}
2831
2932
function kvEvent() {
3033
return _level1.kvEvent.apply(_root._level1, arguments);
@@ -442,14 +445,111 @@ function registerCheat(id:String, code:String, linked:Array) {
442445
warn += "\nAssigned next available tile position {x: " + parent.tilePos.x + ", y: " + parent.tilePos.y + "} to avoid crash!";
443446
_level0.Log(warn);
444447
}
448+
}]]></script>
449+
</Actionscript>
450+
<elements/>
451+
</DOMFrame>
452+
</frames>
453+
</DOMLayer>
454+
<DOMLayer name="Indicator" color="#9933CC" locked="true" autoNamed="false" visible="false" layerType="folder"/>
455+
<DOMLayer name="IndicatorHook" color="#FF800A" parentLayerIndex="17" locked="true" autoNamed="false" visible="false">
456+
<frames>
457+
<DOMFrame index="0" keyMode="9728">
458+
<Actionscript>
459+
<script><![CDATA[function IndicatorHook(parent, objA, objB, message, conditionType, lifespan) {
460+
461+
// If this indicator is of the objective to select one or more units...
462+
if (this.conditionType == "selected") {
463+
if (isArray(this.objA)) {
464+
// Save each unit's current speed and temporarily set it to 0 so they cannot move.
465+
for (var i in this.objA) {
466+
this.objA[i].stats.indicatorHackSpeed = this.objA[i].stats.speed;
467+
this.objA[i].stats.speed = 0;
468+
}
469+
} else {
470+
// Save the unit's current speed and temporarily set it to 0 so it cannot move.
471+
this.objA.stats.indicatorHackSpeed = this.objA.stats.speed;
472+
this.objA.stats.speed = 0;
473+
}
474+
}
475+
476+
this.conditionMet = function() {
477+
this.updatePos();
478+
if (this.lifespan) {
479+
this.lifespan--;
480+
if (!this.lifespan) {
481+
return true;
482+
}
483+
}
484+
if (this.conditionType == "focus") {
485+
return true;
486+
}
487+
if (this.conditionType == "selected") {
488+
if (isArray(this.objA)) {
489+
for (var i in this.objA) {
490+
if (!this.objA[i].selected) {
491+
return false;
492+
}
493+
}
494+
// Restore the speed for each of the units.
495+
for (var i in this.objA) {
496+
this.objA[i].stats.speed = this.objA[i].stats.indicatorHackSpeed;
497+
}
498+
return true;
499+
}
500+
if (this.objA.selected) {
501+
// Restore the speed for the unit.
502+
this.objA.stats.speed = this.objA.stats.indicatorHackSpeed;
503+
return true;
504+
}
505+
}
506+
if (this.conditionType == "voyage") {
507+
if ((this.objA.tilePos.x == this.objB.tilePos.x) && (this.objA.tilePos.y == this.objB.tilePos.y)) {
508+
return true;
509+
}
510+
}
511+
if (this.conditionType == "construction") {
512+
if (this.parent.findBuilding(this.objA)) {
513+
return true;
514+
}
515+
if (this.parent.findUnit(this.objA)) {
516+
return true;
517+
}
518+
this.parent.parent.hud.showMessage(dialogue("int_construction_hint"));
519+
}
520+
if (this.conditionType == "message") {
521+
if ((this.lifespan == undefined) || (this.lifespan >= 40)) {
522+
this.parent.parent.hud.showMessage(this.message);
523+
}
524+
}
525+
return false;
526+
};
527+
528+
// This function is not in the original code, it's mainly just to revert the
529+
// speed hack for selection type indicators. See LevelHook hack_init function.
530+
this.cancel = function() {
531+
if (this.conditionType == "selected") {
532+
if (isArray(this.objA)) {
533+
// Restore the speed for each of the units.
534+
for (var i in this.objA) {
535+
this.objA[i].stats.speed = this.objA[i].stats.indicatorHackSpeed;
536+
}
537+
}
538+
if (this.objA.selected) {
539+
// Restore the speed for the unit.
540+
this.objA.stats.speed = this.objA.stats.indicatorHackSpeed;
541+
}
542+
}
543+
};
544+
445545
}]]></script>
446546
</Actionscript>
447547
<elements/>
448548
</DOMFrame>
449549
</frames>
450550
</DOMLayer>
451551
<DOMLayer name="LevelStats" color="#FF4FFF" locked="true" autoNamed="false" visible="false" layerType="folder"/>
452-
<DOMLayer name="outcomeOverride" color="#4FFF4F" parentLayerIndex="17" locked="true" autoNamed="false" visible="false">
552+
<DOMLayer name="outcomeOverride" color="#4FFF4F" parentLayerIndex="19" locked="true" autoNamed="false" visible="false">
453553
<frames>
454554
<DOMFrame index="0" keyMode="9728">
455555
<Actionscript>
@@ -658,7 +758,7 @@ function registerCheat(id:String, code:String, linked:Array) {
658758
</DOMFrame>
659759
</frames>
660760
</DOMLayer>
661-
<DOMLayer name="LevelStatsHook" color="#9933CC" parentLayerIndex="17" locked="true" autoNamed="false" visible="false">
761+
<DOMLayer name="LevelStatsHook" color="#9933CC" parentLayerIndex="19" locked="true" autoNamed="false" visible="false">
662762
<frames>
663763
<DOMFrame index="0" keyMode="9728">
664764
<Actionscript>
@@ -2102,7 +2202,7 @@ function registerCheat(id:String, code:String, linked:Array) {
21022202
</frames>
21032203
</DOMLayer>
21042204
<DOMLayer name="Level" color="#4FFFFF" locked="true" autoNamed="false" visible="false" layerType="folder"/>
2105-
<DOMLayer name="shootHook" color="#4FFF4F" parentLayerIndex="20" locked="true" autoNamed="false" visible="false">
2205+
<DOMLayer name="shootHook" color="#4FFF4F" parentLayerIndex="22" locked="true" autoNamed="false" visible="false">
21062206
<frames>
21072207
<DOMFrame index="0" keyMode="9728">
21082208
<Actionscript>
@@ -2117,7 +2217,7 @@ function registerCheat(id:String, code:String, linked:Array) {
21172217
</DOMFrame>
21182218
</frames>
21192219
</DOMLayer>
2120-
<DOMLayer name="LevelHook" color="#4FFF4F" parentLayerIndex="20" locked="true" autoNamed="false" visible="false">
2220+
<DOMLayer name="LevelHook" color="#4FFF4F" parentLayerIndex="22" locked="true" autoNamed="false" visible="false">
21212221
<frames>
21222222
<DOMFrame index="0" keyMode="9728">
21232223
<Actionscript>
@@ -2312,6 +2412,10 @@ function registerCheat(id:String, code:String, linked:Array) {
23122412
// This prevents impossible to fulfill indicator conditions.
23132413
if (this.parent.team != this.parent.parent.teams1337[this.level]) {
23142414
if (this.indicators.length > 0) {
2415+
for (var i in this.indicators) {
2416+
// Give the indicator a chance to revert any changes it might have made.
2417+
this.indicators[i].cancel();
2418+
}
23152419
this.indicators.splice(0);
23162420
}
23172421
}
@@ -2326,7 +2430,7 @@ function registerCheat(id:String, code:String, linked:Array) {
23262430
</frames>
23272431
</DOMLayer>
23282432
<DOMLayer name="Control" color="#4FFF4F" locked="true" autoNamed="false" visible="false" layerType="folder"/>
2329-
<DOMLayer name="ControlHook" color="#9933CC" parentLayerIndex="23" locked="true" autoNamed="false" visible="false">
2433+
<DOMLayer name="ControlHook" color="#9933CC" parentLayerIndex="25" locked="true" autoNamed="false" visible="false">
23302434
<frames>
23312435
<DOMFrame index="0" keyMode="9728">
23322436
<Actionscript>
@@ -2541,7 +2645,7 @@ function registerCheat(id:String, code:String, linked:Array) {
25412645
</frames>
25422646
</DOMLayer>
25432647
<DOMLayer name="Game" color="#4FFFFF" locked="true" autoNamed="false" visible="false" layerType="folder"/>
2544-
<DOMLayer name="GameHook" color="#4FFF4F" parentLayerIndex="25" locked="true" autoNamed="false" visible="false">
2648+
<DOMLayer name="GameHook" color="#4FFF4F" parentLayerIndex="27" locked="true" autoNamed="false" visible="false">
25452649
<frames>
25462650
<DOMFrame index="0" keyMode="9728">
25472651
<Actionscript offsets="1240,332">
@@ -2621,7 +2725,7 @@ function registerCheat(id:String, code:String, linked:Array) {
26212725
</frames>
26222726
</DOMLayer>
26232727
<DOMLayer name="Panel" color="#808080" locked="true" autoNamed="false" visible="false" layerType="folder"/>
2624-
<DOMLayer name="PanelAppend" color="#4FFF4F" parentLayerIndex="27" locked="true" autoNamed="false" visible="false">
2728+
<DOMLayer name="PanelAppend" color="#4FFF4F" parentLayerIndex="29" locked="true" autoNamed="false" visible="false">
26252729
<frames>
26262730
<DOMFrame index="0" keyMode="9728">
26272731
<Actionscript>
@@ -2833,7 +2937,7 @@ function registerCheat(id:String, code:String, linked:Array) {
28332937
</frames>
28342938
</DOMLayer>
28352939
<DOMLayer name="Mod" color="#FF800A" locked="true" autoNamed="false" visible="false" layerType="folder"/>
2836-
<DOMLayer name="CACMod" color="#00FF00" parentLayerIndex="29" locked="true" current="true" isSelected="true" autoNamed="false" visible="false">
2940+
<DOMLayer name="CACMod" color="#00FF00" parentLayerIndex="31" locked="true" current="true" isSelected="true" autoNamed="false" visible="false">
28372941
<frames>
28382942
<DOMFrame index="0" keyMode="9728">
28392943
<Actionscript>
@@ -2908,6 +3012,11 @@ function CACMod_OnGameMenu():Void {
29083012
var hook10:Object = wrapper.addPostHook(game.Unit, UnitHook);
29093013
game.Unit = hook10.override;
29103014
3015+
// Hook Indicator to fix bugs with being able to move units before the indicator requests that they be selected.
3016+
// Now the units will not move until the indicator is ready and the condition is met.
3017+
var hook11:Object = wrapper.addPostHook(game.Indicator, IndicatorHook);
3018+
game.Indicator = hook11.override;
3019+
29113020
PanelAppend.apply(game.panel);
29123021
29133022
// For fun of course ;)
@@ -2927,7 +3036,7 @@ function CACMod_OnGameMenu():Void {
29273036
</DOMFrame>
29283037
</frames>
29293038
</DOMLayer>
2930-
<DOMLayer name="My Code" color="#FF800A" parentLayerIndex="29" locked="true" autoNamed="false" visible="false">
3039+
<DOMLayer name="My Code" color="#FF800A" parentLayerIndex="31" locked="true" autoNamed="false" visible="false">
29313040
<frames>
29323041
<DOMFrame index="0" keyMode="9728">
29333042
<Actionscript>
@@ -2946,25 +3055,25 @@ function CACMod_OnGameMenu():Void {
29463055
</persistentData>
29473056
<PrinterSettings/>
29483057
<publishHistory>
2949-
<PublishItem publishSize="17259" publishTime="1494125320"/>
2950-
<PublishItem publishSize="17259" publishTime="1494123872"/>
2951-
<PublishItem publishSize="16975" publishTime="1494102691"/>
2952-
<PublishItem publishSize="17015" publishTime="1494102575"/>
2953-
<PublishItem publishSize="17048" publishTime="1494102419"/>
2954-
<PublishItem publishSize="17047" publishTime="1494102191"/>
2955-
<PublishItem publishSize="16994" publishTime="1494101744"/>
2956-
<PublishItem publishSize="16994" publishTime="1494101736"/>
2957-
<PublishItem publishSize="16956" publishTime="1494100447"/>
2958-
<PublishItem publishSize="16956" publishTime="1494100262"/>
2959-
<PublishItem publishSize="16955" publishTime="1494100220"/>
2960-
<PublishItem publishSize="16953" publishTime="1494100175"/>
2961-
<PublishItem publishSize="16953" publishTime="1494100129"/>
2962-
<PublishItem publishSize="16953" publishTime="1494099435"/>
2963-
<PublishItem publishSize="16953" publishTime="1494099412"/>
2964-
<PublishItem publishSize="16953" publishTime="1494099359"/>
2965-
<PublishItem publishSize="16953" publishTime="1494099325"/>
2966-
<PublishItem publishSize="16953" publishTime="1494098849"/>
2967-
<PublishItem publishSize="16953" publishTime="1494098831"/>
2968-
<PublishItem publishSize="16946" publishTime="1494097001"/>
3058+
<PublishItem publishSize="17742" publishTime="1494136748"/>
3059+
<PublishItem publishSize="17742" publishTime="1494136740"/>
3060+
<PublishItem publishSize="17687" publishTime="1494135653"/>
3061+
<PublishItem publishSize="17687" publishTime="1494134166"/>
3062+
<PublishItem publishSize="17665" publishTime="1494133937"/>
3063+
<PublishItem publishSize="17664" publishTime="1494132687"/>
3064+
<PublishItem publishSize="17657" publishTime="1494132634"/>
3065+
<PublishItem publishSize="17658" publishTime="1494132468"/>
3066+
<PublishItem publishSize="17338" publishTime="1494131730"/>
3067+
<PublishItem publishSize="17888" publishTime="1494131319"/>
3068+
<PublishItem publishSize="17888" publishTime="1494131267"/>
3069+
<PublishItem publishSize="17883" publishTime="1494131081"/>
3070+
<PublishItem publishSize="17938" publishTime="1494130972"/>
3071+
<PublishItem publishSize="17947" publishTime="1494130887"/>
3072+
<PublishItem publishSize="17945" publishTime="1494130838"/>
3073+
<PublishItem publishSize="17932" publishTime="1494130781"/>
3074+
<PublishItem publishSize="17931" publishTime="1494130737"/>
3075+
<PublishItem publishSize="17909" publishTime="1494130576"/>
3076+
<PublishItem publishSize="17912" publishTime="1494130488"/>
3077+
<PublishItem publishSize="17907" publishTime="1494130320"/>
29693078
</publishHistory>
29703079
</DOMDocument>

0 commit comments

Comments
 (0)