Skip to content

Commit 0e1d345

Browse files
authored
Merge pull request #167 from cortex-command-community/optimise-techion-effects
Optimise Techion effects
2 parents cd6b982 + b60fb97 commit 0e1d345

File tree

4 files changed

+139
-100
lines changed

4 files changed

+139
-100
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
127127

128128
- `MOSRotating` Lua function `AddWound` now additionally accepts the format `MOSRotating:AddWound(AEmitter* woundToAdd, const Vector& parentOffsetToSet, bool checkGibWoundLimit, bool isEntryWound, bool isExitWound)`, allowing modders to specify added wounds as entry- or exit wounds, for the purpose of not playing multiple burst sounds on the same frame. These new arguments are optional.
129129

130+
- Techion Laser Rifle now has a constant range rather than being dependent on game resolution.
131+
130132
- Various performance improvements.
131133

132134
</details>

Data/Techion.rte/Devices/Shared/Scripts/Disintegrator.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ function Update(self)
124124
for i = 1, radius do
125125
if math.random(radius) > i then
126126

127-
local piece = CreateMOSParticle("Techion.rte/White Goo Particle");
127+
local piece;
128128
if math.random() < 0.3 then
129129
piece = CreateMOPixel("Techion.rte/Nanogoo " .. math.random(6));
130+
else
131+
piece = CreateMOSParticle("Techion.rte/White Goo Particle");
130132
end
133+
131134
local offset = Vector(mo.Radius * mo.Scale * RangeRand(0, 0.5), 0):RadRotate(6.28 * math.random());
132135
piece.Pos = mo.Pos + offset;
133136
piece.Vel = mo.Vel + offset:SetMagnitude(RangeRand(radius, radius * 2)/math.sqrt(1 + offset.Magnitude));

Data/Techion.rte/Devices/Weapons/DihelicalCannon/DihelicalShot.lua

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,59 @@
11
function Create(self)
2+
local var = {};
3+
24
--Range of the shot.
3-
self.range = 600;
5+
var.range = 600;
46

57
--Amplitude of the wave.
6-
self.maxAmplitude = math.floor(1 + math.sqrt(self.Vel.Magnitude) + 0.5);
8+
var.maxAmplitude = math.floor(1 + math.sqrt(self.Vel.Magnitude) + 0.5);
79

810
--Wavelength of the wave.
9-
self.flaceLength = math.floor(3 + math.sqrt(self.Vel.Magnitude) + 0.5);
11+
var.flaceLength = math.floor(3 + math.sqrt(self.Vel.Magnitude) + 0.5);
1012

1113
--Track intersecting beams
12-
self.lastAmplitude = 1;
14+
var.lastAmplitude = 1;
1315

1416
--Speed of the wave (pixels per second).
15-
self.speed = self.Vel.Magnitude * 10;
17+
var.speed = self.Vel.Magnitude * 10;
1618

1719
--Speed of damage particles.
18-
self.damageSpeed = 50 + self.Vel.Magnitude * 0.1;
20+
var.damageSpeed = 50 + self.Vel.Magnitude * 0.1;
1921

2022
--Maximum strength for material penetration (both MOs and terrain).
21-
self.strengthThreshold = 50 + self.Vel.Magnitude * 0.3;
23+
var.strengthThreshold = 50 + self.Vel.Magnitude * 0.3;
2224

2325
--Direction of the wave.
24-
self.direction = Vector(self.Vel.X, self.Vel.Y);
25-
self.direction:SetMagnitude(1);
26-
self.up = Vector(self.direction.X, self.direction.Y);
27-
self.up:RadRotate(math.pi * 0.5);
26+
var.direction = Vector(self.Vel.X, self.Vel.Y);
27+
var.direction:SetMagnitude(1);
28+
var.up = Vector(var.direction.X, var.direction.Y);
29+
var.up:RadRotate(math.pi * 0.5);
2830

2931
--Interval at which to create damage particles.
30-
self.damageInterval = 3;
32+
var.damageInterval = 3;
3133

3234
--Timer for the wave.
33-
self.timer = Timer();
35+
var.timer = Timer();
3436

3537
--The last starting position along the line.
36-
self.lastI = 0;
38+
var.lastI = 0;
3739

3840
--Count MO and terrain hits.
39-
self.hits = 0;
41+
var.hits = 0;
4042

4143
--Disintegration strength.
42-
self.disintegrationStrength = 500;
44+
var.disintegrationStrength = 500;
4345

44-
self.melter = CreateMOPixel("Disintegrator", "Techion.rte");
46+
var.melter = CreateMOPixel("Disintegrator", "Techion.rte");
47+
48+
var.Pos = self.Pos;
49+
self.var = var;
4550
end
4651

4752
function Update(self)
48-
local endPoint = self.timer.ElapsedSimTimeS * self.speed;
49-
if endPoint > self.range then
50-
endPoint = self.range;
53+
local var = self.var;
54+
local endPoint = var.timer.ElapsedSimTimeS * var.speed;
55+
if endPoint > var.range then
56+
endPoint = var.range;
5157
self.ToDelete = true;
5258
else
5359
self.ToDelete = false;
@@ -57,21 +63,21 @@ function Update(self)
5763
endPoint = math.floor(endPoint);
5864

5965
--Draw out the path.
60-
for i = self.lastI, endPoint, 1 do
61-
local amplitude = math.sin((i/self.flaceLength) * 2 * math.pi) * self.maxAmplitude;
62-
local waveOffset = Vector(self.up.X, self.up.Y);
66+
for i = var.lastI, endPoint, 1 do
67+
local amplitude = math.sin((i/var.flaceLength) * 2 * math.pi) * var.maxAmplitude;
68+
local waveOffset = Vector(var.up.X, var.up.Y);
6369
waveOffset:SetMagnitude(amplitude);
6470

65-
local linePos = self.Pos + Vector(self.direction.X, self.direction.Y):SetMagnitude(i * 2);
66-
local fireVector = Vector(self.direction.X, self.direction.Y):SetMagnitude(self.damageSpeed);
71+
local linePos = var.Pos + Vector(var.direction.X, var.direction.Y):SetMagnitude(i * 2);
72+
local fireVector = Vector(var.direction.X, var.direction.Y):SetMagnitude(var.damageSpeed);
6773
local upPos = linePos + waveOffset;
6874
local downPos = linePos - waveOffset * 0.2;
6975

7076
--Cancel the beam if there's a terrain collision.
71-
local trace = Vector(fireVector.X, fireVector.Y):SetMagnitude(self.damageSpeed * 0.1);
77+
local trace = Vector(fireVector.X, fireVector.Y):SetMagnitude(var.damageSpeed * 0.1);
7278

7379
local strSumRay = SceneMan:CastStrengthSumRay(downPos, downPos + trace, 3, 160);
74-
self.hits = self.hits + math.sqrt(strSumRay);
80+
var.hits = var.hits + math.sqrt(strSumRay);
7581

7682
if SceneMan:GetTerrMatter(upPos.X, upPos.Y) == rte.airID then
7783
--Add the blue wave effect.
@@ -99,7 +105,7 @@ function Update(self)
99105
frontB.Vel = (fireVector + waveOffset) * 0.04;
100106
MovableMan:AddParticle(frontB);
101107

102-
if i % self.damageInterval == 0 then
108+
if i % var.damageInterval == 0 then
103109
local pos = {upPos, downPos};
104110
local hitID = rte.NoMOID;
105111
for i = 1, #pos do
@@ -126,15 +132,15 @@ function Update(self)
126132

127133
local rootMO = mo:GetRootParent();
128134
if i == 2 and IsActor(rootMO) then
129-
local melter = self.melter:Clone();
135+
local melter = var.melter:Clone();
130136
melter.Pos = hitPos;
131137
melter.Team = self.Team;
132138
melter.Sharpness = rootMO.ID;
133-
melter.PinStrength = self.disintegrationStrength;
139+
melter.PinStrength = var.disintegrationStrength;
134140
MovableMan:AddMO(melter);
135141
end
136142

137-
self.hits = self.hits + (i == 2 and math.sqrt(mo.Material.StructuralIntegrity) + math.sqrt(mo.Radius + mo.Mass) * 0.1 or 1);
143+
var.hits = var.hits + (i == 2 and math.sqrt(mo.Material.StructuralIntegrity) + math.sqrt(mo.Radius + mo.Mass) * 0.1 or 1);
138144

139145
--Add the dissipate effect.
140146
local effect = CreateAEmitter("Techion.rte/Laser Dissipate Effect");
@@ -145,31 +151,31 @@ function Update(self)
145151
end
146152
end
147153

148-
if (self.lastAmplitude > 0 and amplitude < 0) or (self.lastAmplitude < 0 and amplitude > 0) then
154+
if (var.lastAmplitude > 0 and amplitude < 0) or (var.lastAmplitude < 0 and amplitude > 0) then
149155
local part = CreateMOPixel("Techion.rte/Dihelical Cannon Large Effect Particle");
150-
part.Pos = linePos - Vector(self.direction.X, self.direction.Y):SetMagnitude(2);
156+
part.Pos = linePos - Vector(var.direction.X, var.direction.Y):SetMagnitude(2);
151157
part.Vel = fireVector * 0.1;
152158
MovableMan:AddParticle(part);
153159
end
154160

155-
self.lastAmplitude = amplitude;
156-
if self.hits > self.strengthThreshold then
161+
var.lastAmplitude = amplitude;
162+
if var.hits > var.strengthThreshold then
157163

158164
local effect = CreateAEmitter("Techion.rte/Dihelical Cannon Impact Particle");
159-
effect.Pos = linePos - Vector(self.direction.X, self.direction.Y):SetMagnitude(2);
165+
effect.Pos = linePos - Vector(var.direction.X, var.direction.Y):SetMagnitude(2);
160166
effect.Team = self.Team;
161167
effect.IgnoresTeamHits = true;
162168
MovableMan:AddParticle(effect);
163169

164170
self.ToDelete = true;
165171
break;
166172
else
167-
self.hits = self.hits * 0.9;
173+
var.hits = var.hits * 0.9;
168174
end
169175

170-
self.flaceLength = self.flaceLength * (1 + 0.05/self.flaceLength);
171-
self.maxAmplitude = self.flaceLength * 0.5;
176+
var.flaceLength = var.flaceLength * (1 + 0.05/var.flaceLength);
177+
var.maxAmplitude = var.flaceLength * 0.5;
172178
end
173179

174-
self.lastI = endPoint;
180+
var.lastI = endPoint;
175181
end

0 commit comments

Comments
 (0)