Skip to content

Commit af355d6

Browse files
committed
Fixed issue with RemoteExplosive not working, as it needs global state.
Fixed issue with TimedExplosive implicitly using RemoteExplosive functions. This relies on global state, so avoid it. This should be using require() if we want to share info.
1 parent d70757e commit af355d6

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

Data/Base.rte/Devices/Explosives/RemoteExplosive/RemoteExplosiveDetonator.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
--[[FORCE_SINGLETHREADED]]--
2+
13
function Create(self)
24
self.delayTimer = Timer();
35
self.actionPhase = 0;

Data/Base.rte/Devices/Explosives/RemoteExplosive/RemoteExplosiveSet.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
--[[FORCE_SINGLETHREADED]]--
2+
13
function Create(self)
24
self.blinkTimer = Timer();
35

Data/Coalition.rte/Devices/Explosives/TimedExplosive/TimedExplosiveSet.lua

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Create(self)
2525
self.activateSound = CreateSoundContainer("Explosive Device Activate", "Base.rte");
2626
self.blipSound = CreateSoundContainer("Timed Explosive Blip", "Coalition.rte");
2727

28-
RemoteExplosiveStick(self);
28+
TimedExplosiveStick(self);
2929
end
3030

3131
function Update(self)
@@ -34,7 +34,7 @@ function Update(self)
3434
TimedExplosiveTable[self.tableNum] = self;
3535
end
3636

37-
RemoteExplosiveStick(self);
37+
TimedExplosiveStick(self);
3838

3939
if self.stuck then
4040
if self.lifeTimer:IsPastSimMS(self.detonateDelay) then
@@ -89,6 +89,70 @@ function Update(self)
8989
end
9090
end
9191

92+
function TimedExplosiveStick(self)
93+
if self.actionPhase == 0 then
94+
local checkVec = Vector(self.Vel.X, self.Vel.Y + 1):SetMagnitude(math.max(self.Vel.Magnitude * rte.PxTravelledPerFrame, self.Radius));
95+
--Find a user to ignore hits with
96+
if not self.userID then
97+
self.userID = rte.NoMOID;
98+
local moCheck = SceneMan:CastMORay(self.Pos, checkVec * (-2), self.ID, -1, rte.airID, true, 1);
99+
if moCheck ~= rte.NoMOID then
100+
local rootID = MovableMan:GetMOFromID(moCheck).RootID;
101+
if rootID ~= rte.NoMOID then
102+
self.userID = rootID;
103+
end
104+
end
105+
end
106+
local rayHitPos = Vector();
107+
local rayHit = false;
108+
for i = 1, 2 do
109+
local checkPos = self.Pos + (checkVec/i);
110+
local checkPix = SceneMan:GetMOIDPixel(checkPos.X, checkPos.Y);
111+
if checkPix ~= rte.NoMOID and MovableMan:GetMOFromID(checkPix).RootID ~= self.userID then
112+
checkPos = checkPos + SceneMan:ShortestDistance(checkPos, self.Pos, SceneMan.SceneWrapsX):SetMagnitude(ToMOSprite(self):GetSpriteWidth() * 0.5 - 1);
113+
self.target = ToMOSRotating(MovableMan:GetMOFromID(checkPix));
114+
self.stickPosition = SceneMan:ShortestDistance(self.target.Pos, checkPos, SceneMan.SceneWrapsX);
115+
self.stickRotation = self.target.RotAngle;
116+
self.stickDirection = self.RotAngle;
117+
118+
if self.activateSound then
119+
self.activateSound:Play(self.Pos);
120+
end
121+
self.stuck = true;
122+
rayHit = true;
123+
break;
124+
end
125+
end
126+
if rayHit then
127+
self.actionPhase = 1;
128+
elseif SceneMan:CastStrengthRay(self.Pos, checkVec, 0, rayHitPos, 1, rte.airID, SceneMan.SceneWrapsX) then
129+
self.Pos = rayHitPos + SceneMan:ShortestDistance(rayHitPos, self.Pos, SceneMan.SceneWrapsX):SetMagnitude(ToMOSprite(self):GetSpriteWidth() * 0.5 - 1);
130+
self.PinStrength = 1000;
131+
self.AngularVel = 0;
132+
self.stuck = true;
133+
self.actionPhase = 2;
134+
135+
if self.activateSound then
136+
self.activateSound:Play(self.Pos);
137+
end
138+
end
139+
else
140+
self.Vel = Vector();
141+
self.AngularVel = 0;
142+
if self.actionPhase == 1 then
143+
if self.target and self.target.ID ~= rte.NoMOID and not self.target.ToDelete then
144+
self.Pos = self.target.Pos + Vector(self.stickPosition.X, self.stickPosition.Y):RadRotate(self.target.RotAngle - self.stickRotation);
145+
self.RotAngle = self.stickDirection + (self.target.RotAngle - self.stickRotation);
146+
self.PinStrength = 1000;
147+
self.Vel = Vector();
148+
else
149+
self.PinStrength = 0;
150+
self.actionPhase = 0;
151+
end
152+
end
153+
end
154+
end
155+
92156
function Destroy(self)
93157
TimedExplosiveTable[self.tableNum] = nil;
94158
end

0 commit comments

Comments
 (0)