Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit f614a00

Browse files
committed
Enhancements to shared device scripts TrajectoryGuide and SmokeTrail
1 parent be72315 commit f614a00

File tree

3 files changed

+122
-27
lines changed

3 files changed

+122
-27
lines changed

Base.rte/Devices/Shared/Scripts/TrajectoryGuide.lua

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ function Create(self)
2222
end
2323

2424
self.guideRadius = self:NumberValueExists("TrajectoryGuideBlastRadius") and self:GetNumberValue("TrajectoryGuideBlastRadius") or 12;
25+
self.guideAccuracy = self:NumberValueExists("TrajectoryGuideAccuracy") and self:GetNumberValue("TrajectoryGuideAccuracy") or 1;
2526
self.maxTrajectoryPars = self:NumberValueExists("TrajectoryGuideLength") and self:GetNumberValue("TrajectoryGuideLength") or 60;
2627
self.guideColor = self:NumberValueExists("TrajectoryGuideColorIndex") and self:GetNumberValue("TrajectoryGuideColorIndex") or 120;
2728
self.skipLines = self:NumberValueExists("TrajectoryGuideSkipLines") and self:GetNumberValue("TrajectoryGuideSkipLines") or 1;
28-
self.drawHitsOnly = self:GetNumberValue("TrajectoryGuideDrawHitsOnly") == 1;
29+
self.viewCorrection = self:NumberValueExists("TrajectoryGuideViewCorrection") and self:GetNumberValue("TrajectoryGuideViewCorrection") or 0;
30+
self.drawHitsOnly = self:NumberValueExists("TrajectoryGuideDrawHitsOnly");
31+
self.includeMOHits = self:NumberValueExists("TrajectoryGuideIncludeMOHits");
2932
end
3033

3134
function Update(self)
@@ -34,11 +37,7 @@ function Update(self)
3437
if MovableMan:IsActor(actor) and ToActor(actor):IsPlayerControlled() then
3538
local actor = ToActor(actor);
3639
local controller = actor:GetController();
37-
if self.isThrownDevice then
38-
if not self.throwTimer and controller:IsState(Controller.WEAPON_FIRE) then
39-
self.throwTimer = Timer();
40-
end
41-
elseif (self:DoneReloading() or self.FiredFrame) and self.Magazine and self.Magazine.RoundCount ~= 0 then
40+
if not self.isThrownDevice and (self:DoneReloading() or self.FiredFrame) and self.Magazine and self.Magazine.RoundCount ~= 0 then
4241
self.projectileVel = self.Magazine.NextRound.FireVel;
4342
self.projectileGravity = self.Magazine.NextRound.NextParticle.GlobalAccScalar;
4443
end
@@ -57,9 +56,9 @@ function Update(self)
5756
local rotationThisFrame = actor.AngularVel * TimerMan.DeltaTimeSecs;
5857
local maxVel = self.projectileVelMax or (actor.FGArm.ThrowStrength + math.abs(actor.AngularVel * 0.5))/math.sqrt(math.abs(self.Mass) + 1);
5958
local minVel = self.projectileVelMin or maxVel * 0.2;
60-
--The following offset is as found in the source code (To-do: expose and utilize EndThrowOffset properly instead)
59+
--The following offset is as found in the source code (TODO: utilize EndThrowOffset properly instead)
6160
guideParPos = actor.Pos + actor.Vel * rte.PxTravelledPerFrame + Vector((actor.FGArm.ParentOffset.X + actor.FGArm.MaxLength) * actor.FlipFactor, actor.FGArm.ParentOffset.Y - actor.FGArm.MaxLength * 0.5):RadRotate(actor:GetAimAngle(false) * actor.FlipFactor);
62-
local projectileVel = self.throwTimer and minVel + (maxVel - minVel) * math.min(self.throwTimer.ElapsedSimTimeMS, actor.ThrowPrepTime)/actor.ThrowPrepTime or maxVel;
61+
local projectileVel = minVel + (maxVel - minVel) * actor.ThrowProgress;
6362
guideParVel = Vector(projectileVel, 0):RadRotate(actor.RotAngle + actor:GetAimAngle(true) + rotationThisFrame);
6463
else
6564
guideParPos = self.MuzzlePos;
@@ -74,12 +73,24 @@ function Update(self)
7473
if self.projectileAirResistance ~= 0 and guideParVel.Largest >= self.projectileAirThreshold then
7574
guideParVel:SetMagnitude(guideParVel.Magnitude * (1 - (self.projectileAirResistance * TimerMan.DeltaTimeSecs * 2.5))); --To-do: replace "* 2.5" with something more intangible
7675
end
77-
guideParPos = guideParPos + guideParVel;
78-
if SceneMan:GetTerrMatter(guideParPos.X, guideParPos.Y) == rte.airID then
79-
self.guideTable[#self.guideTable + 1] = guideParPos;
80-
else
76+
local roughHit = false;
77+
for i = 1, self.guideAccuracy do
78+
local moCheck = self.includeMOHits and SceneMan:GetMOIDPixel(guideParPos.X, guideParPos.Y) or rte.NoMOID;
79+
if SceneMan:GetTerrMatter(guideParPos.X, guideParPos.Y) == rte.airID and (moCheck == rte.NoMOID or moCheck == self.ID) then
80+
self.guideTable[#self.guideTable + 1] = guideParPos;
81+
else
82+
roughHit = true;
83+
break;
84+
end
85+
guideParPos = guideParPos + guideParVel/self.guideAccuracy;
86+
end
87+
if roughHit then
8188
hitPos = Vector(self.guideTable[#self.guideTable].X, self.guideTable[#self.guideTable].Y);
82-
SceneMan:CastStrengthRay(self.guideTable[#self.guideTable], SceneMan:ShortestDistance(self.guideTable[#self.guideTable], guideParPos, false), 0, hitPos, 3, rte.airID, false);
89+
if self.includeMOHits then
90+
SceneMan:CastObstacleRay(self.guideTable[#self.guideTable], SceneMan:ShortestDistance(self.guideTable[#self.guideTable], guideParPos, false), Vector(), hitPos, self.ID, -2, rte.airID, 3);
91+
else
92+
SceneMan:CastStrengthRay(self.guideTable[#self.guideTable], SceneMan:ShortestDistance(self.guideTable[#self.guideTable], guideParPos, false), 0, hitPos, 3, rte.airID, false);
93+
end
8394
self.guideTable[#self.guideTable + 1] = hitPos;
8495
break;
8596
end
@@ -90,20 +101,20 @@ function Update(self)
90101
self.guideTable = {};
91102
end
92103
if #self.guideTable > 1 and (not self.drawHitsOnly or hitPos) then
104+
local screen = ActivityMan:GetActivity():ScreenOfPlayer(controller.Player);
93105
if self.skipLines > 0 then
94106
for i = 1, #self.guideTable - 1 do
95107
if self.skipLines == 0 or i % (self.skipLines + 1) == 0 then
96-
PrimitiveMan:DrawLinePrimitive(controller.Player, self.guideTable[i], self.guideTable[i + 1], self.guideColor);
108+
PrimitiveMan:DrawLinePrimitive(screen, self.guideTable[i], self.guideTable[i + 1], self.guideColor);
97109
end
98110
end
99111
end
100-
PrimitiveMan:DrawCirclePrimitive(controller.Player, self.guideTable[#self.guideTable], self.guideRadius, self.guideColor);
101-
--Optional: move view point closer to guide point?
102-
--local viewLength = SceneMan:ShortestDistance(actor.EyePos, actor.ViewPoint, SceneMan.SceneWrapsX).Magnitude;
103-
--local viewPoint = actor.ViewPoint + SceneMan:ShortestDistance(actor.ViewPoint, self.guideTable[#self.guideTable], SceneMan.SceneWrapsX):SetMagnitude(viewLength);
104-
--SceneMan:SetScrollTarget(viewPoint, 0.1, false, ActivityMan:GetActivity():ScreenOfPlayer(controller.Player));
112+
PrimitiveMan:DrawCirclePrimitive(screen, self.guideTable[#self.guideTable], self.guideRadius, self.guideColor);
113+
if self.viewCorrection > 0 then
114+
local viewLength = SceneMan:ShortestDistance(actor.EyePos, actor.ViewPoint, SceneMan.SceneWrapsX).Magnitude;
115+
local viewPoint = actor.ViewPoint + SceneMan:ShortestDistance(actor.ViewPoint, self.guideTable[#self.guideTable], SceneMan.SceneWrapsX):SetMagnitude(viewLength);
116+
SceneMan:SetScrollTarget(viewPoint, self.viewCorrection, false, screen);
117+
end
105118
end
106-
else
107-
self.throwTimer = nil;
108119
end
109120
end

Base.rte/Effects/Pyro.ini

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,27 @@ AddEffect = AEmitter
17291729
// Smoke Trails
17301730

17311731

1732+
AddEffect = MOSParticle
1733+
CopyOf = Small Smoke Ball 1
1734+
PresetName = Small Smoke Trail 1
1735+
LifeTime = 250
1736+
GlobalAccScalar = -0.1
1737+
AirResistance = 0.18
1738+
AirThreshold = 1
1739+
1740+
1741+
AddEffect = MOSParticle
1742+
CopyOf = Small Smoke Trail 1
1743+
PresetName = Small Smoke Trail 2
1744+
LifeTime = 220
1745+
1746+
1747+
AddEffect = MOSParticle
1748+
CopyOf = Small Smoke Trail 1
1749+
PresetName = Small Smoke Trail 3
1750+
LifeTime = 190
1751+
1752+
17321753
AddEffect = MOSParticle
17331754
CopyOf = Tiny Smoke Ball 1
17341755
PresetName = Tiny Smoke Trail 1
@@ -1750,6 +1771,67 @@ AddEffect = MOSParticle
17501771
LifeTime = 150
17511772

17521773

1774+
AddEffect = MOPixel
1775+
PresetName = Micro Smoke Trail 1
1776+
Mass = 0.5
1777+
RestThreshold = -1
1778+
GlobalAccScalar = -0.1
1779+
AirResistance = 0.2
1780+
AirThreshold = 1
1781+
LifeTime = 200
1782+
Sharpness = 0.1
1783+
Color = Color
1784+
R = 210
1785+
G = 198
1786+
B = 178
1787+
Atom = Atom
1788+
Material = Material
1789+
CopyOf = Air
1790+
TrailColor = Color
1791+
R = 178
1792+
G = 170
1793+
B = 149
1794+
TrailLength = 4
1795+
TrailLengthVariation = 0.6
1796+
1797+
1798+
AddEffect = MOPixel
1799+
CopyOf = Micro Smoke Trail 1
1800+
PresetName = Micro Smoke Trail 2
1801+
LifeTime = 175
1802+
Color = Color
1803+
R = 190
1804+
G = 182
1805+
B = 178
1806+
Atom = Atom
1807+
Material = Material
1808+
CopyOf = Air
1809+
TrailColor = Color
1810+
R = 161
1811+
G = 117
1812+
B = 109
1813+
TrailLength = 3
1814+
TrailLengthVariation = 0.4
1815+
1816+
1817+
AddEffect = MOPixel
1818+
CopyOf = Micro Smoke Trail 1
1819+
PresetName = Micro Smoke Trail 3
1820+
LifeTime = 150
1821+
Color = Color
1822+
R = 170
1823+
G = 149
1824+
B = 137
1825+
Atom = Atom
1826+
Material = Material
1827+
CopyOf = Air
1828+
TrailColor = Color
1829+
R = 121
1830+
G = 101
1831+
B = 89
1832+
TrailLength = 2
1833+
1834+
17531835
AddAmmo = AEmitter
17541836
PresetName = Smoke Trail Medium
17551837
Mass = 0.001

Base.rte/Scripts/Shared/SmokeTrail.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function Create(self)
22
self.smokeTrailLifeTime = self:NumberValueExists("SmokeTrailLifeTime") and self:GetNumberValue("SmokeTrailLifeTime") or 150;
3+
self.smokeTrailSize = self:NumberValueExists("SmokeTrailSize") and self:GetNumberValue("SmokeTrailSize") or 2;
34
self.smokeTrailRadius = self:NumberValueExists("SmokeTrailRadius") and self:GetNumberValue("SmokeTrailRadius") or ToMOSprite(self):GetSpriteHeight() * 0.5 - 1;
45
self.smokeTrailTwirl = self:NumberValueExists("SmokeTrailTwirl") and self:GetNumberValue("SmokeTrailTwirl") or 0;
56

@@ -9,20 +10,21 @@ end
910
function Update(self)
1011
local offset = self.Vel * rte.PxTravelledPerFrame; --The effect will be created the next frame so move it one frame backwards towards the barrel
1112

12-
local trailLength = math.floor(offset.Magnitude * 0.5 - 1);
13+
local trailLength = math.floor(offset.Magnitude/self.smokeTrailSize - self.smokeTrailSize);
14+
local setVel = Vector(self.Vel.X, self.Vel.Y):SetMagnitude(math.sqrt(self.Vel.Magnitude));
1315
for i = 1, trailLength do
14-
local effect = CreateMOSParticle("Tiny Smoke Trail 1", "Base.rte");
16+
local effect = self.smokeTrailSize < 2 and CreateMOPixel("Micro Smoke Trail " .. math.random(3), "Base.rte") or CreateMOSParticle((self.smokeTrailSize < 3 and "Tiny" or "Small") .. " Smoke Trail " .. math.random(3), "Base.rte");
1517
effect.Pos = self.Pos - (offset * i/trailLength) + Vector(RangeRand(-1, 1), RangeRand(-1, 1)) * self.smokeTrailRadius;
16-
effect.Vel = self.Vel * RangeRand(0.75, 1);
17-
effect.Lifetime = self.smokeTrailLifeTime * RangeRand(0.5, 1) * (self.Lifetime > 1 and 1 - self.Age/self.Lifetime or 1);
18-
effect.AirResistance = effect.AirResistance * RangeRand(0.9, 1);
18+
effect.Vel = setVel * RangeRand(0.6, 1);
19+
effect.Lifetime = self.smokeTrailLifeTime * RangeRand(0.4, 1) * (self.Lifetime > 1 and 1 - self.Age/self.Lifetime or 1);
20+
effect.AirResistance = effect.AirResistance * RangeRand(0.8, 1);
1921
effect.AirThreshold = self.smokeAirThreshold;
2022

2123
if self.smokeTrailTwirl > 0 then
2224
effect.GlobalAccScalar = effect.GlobalAccScalar * math.random();
2325

2426
effect.Pos = self.Pos - offset + (offset * i/trailLength);
25-
effect.Vel = self.Vel + Vector(0, math.sin(self.smokeTwirlCounter) * self.smokeTrailTwirl + RangeRand(-0.1, 0.1)):RadRotate(self.Vel.AbsRadAngle);
27+
effect.Vel = setVel + Vector(0, math.sin(self.smokeTwirlCounter) * self.smokeTrailTwirl + RangeRand(-0.1, 0.1)):RadRotate(self.Vel.AbsRadAngle);
2628

2729
self.smokeTwirlCounter = self.smokeTwirlCounter + RangeRand(-0.2, 0.4);
2830
end

0 commit comments

Comments
 (0)