Skip to content

Commit 33a4e20

Browse files
committed
Big cleanup. This definitely hasn't caught everything, but is a step in the right direction.
* No empty lines at the start/end of functions. Instead use a space between functions, which makes far more sense and is actually useful for quickly visually differentiating between functions * No empty spaces at the start/end of if/while/for blocks etc either * Empty space after an end block unless it's immediately followed by another end * Lines should end in ; These make the rules for where to put spaces consistent with the K&R style which the C++ codebase follows, just with any block beginning (i.e function def, "then", "while" etc) and "end" instead of "{" and "}". Going forward I will be more restrictive about the formatting of scripts to be merged. Code should follow this style for integration into vanilla unless it's an extreme case (i.e third-party lua libraries).
1 parent 2492b43 commit 33a4e20

File tree

111 files changed

+459
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+459
-449
lines changed

Data/Base.rte/Actors/Mecha/AADrone/AADrone.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function Create(self)
105105
+ self.SAM_Target:RotateOffset(self.SAM_Offset)
106106
+ self.SAM_Target.Vel * math.min(range / 50, 20)
107107
)
108-
* 0.4 -- Filter the AimPos to reduce noise
108+
* 0.4; -- Filter the AimPos to reduce noise
109109
end
110110
end
111111

Data/Base.rte/Craft/Shared/AttachableTurret.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ function Update(self)
3636
self.verticalFactor = self.verticalFactor - self.turnSpeed;
3737
end
3838
end
39+
3940
if math.abs(self.rotation) > 0.001 then
4041
self.rotation = self.rotation/(1 + self.turnSpeed * 2);
4142
else
4243
self.rotation = 0;
4344
end
45+
4446
if math.abs(self.verticalFactor) > 0.001 then
4547
self.verticalFactor = self.verticalFactor/(1 + self.turnSpeed * 4);
4648
else
4749
self.verticalFactor = 0;
4850
end
51+
4952
if self.areaMode then --Area Mode
5053
local aimPos = self.Pos + Vector((self.searchRange * 0.5), 0):RadRotate(self.RotAngle);
5154
--Debug: visualize aim area
@@ -84,6 +87,7 @@ function Update(self)
8487
target = MovableMan:GetMOFromID(MovableMan:GetMOFromID(moCheck2).RootID);
8588
end
8689
end
90+
8791
local color = 13; --Debug trace color: red
8892
if target and IsActor(target) and ToActor(target).Status < Actor.INACTIVE then
8993
self:EnableEmission(true);
@@ -94,13 +98,15 @@ function Update(self)
9498
color = 254; --Debug trace color: white
9599
end
96100
end
101+
97102
--Debug: visualize aim traces
98103
if self.showAim then
99104
PrimitiveMan:DrawLinePrimitive(self.Team, self.Pos, self.Pos + aimTrace:RadRotate(1/math.sqrt(self.searchRange)), color);
100105
PrimitiveMan:DrawLinePrimitive(self.Team, self.Pos, self.Pos + aimTrace:RadRotate(-1/math.sqrt(self.searchRange)), color);
101106
end
102107
end
103108
end
109+
104110
if self.fireTimer:IsPastSimTimeLimit() then
105111
self:EnableEmission(false);
106112
end

Data/Base.rte/Devices/Explosives/AntiPersonnelMine/MineDeploy.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function Update(self)
77
if IsActor(parent) then
88
self.alliedTeam = ToActor(parent).Team;
99
elseif self:IsActivated() then
10-
1110
local mine = CreateMOSRotating("Anti Personnel Mine Active");
1211
mine.Pos = self.Pos;
1312
mine.Vel = self.Vel;

Data/Base.rte/Devices/Explosives/AntiPersonnelMine/MineSet.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ function Update(self)
4040
AntiPersonnelMineTable = {};
4141
AntiPersonnelMineTable[self.tableNum] = self;
4242
end
43+
4344
if self.Sharpness ~= 0 then
4445
self.ToDelete = true;
4546
end
4647

4748
if self.actionPhase == 0 then
48-
4949
local trace = Vector(self.Vel.X, self.Vel.Y + 1):SetMagnitude(math.max(self.Vel.Magnitude * rte.PxTravelledPerFrame, self.Radius));
5050
local rayHitPos = Vector();
5151
local terrainRaycast = SceneMan:CastStrengthRay(self.Pos, trace, 5, rayHitPos, 0, rte.airID, SceneMan.SceneWrapsX);
5252

5353
if terrainRaycast == true then
54-
5554
trace = Vector(trace.X, trace.Y):SetMagnitude(trace.Magnitude + 5);
5655
local rayHitPosA = Vector();
5756
local terrainRaycastA = SceneMan:CastStrengthRay(self.Pos + Vector(0, 3):RadRotate(Vector(self.Vel.X, self.Vel.Y).AbsRadAngle), trace, 5, rayHitPosA, 0, rte.airID, SceneMan.SceneWrapsX);
@@ -72,13 +71,10 @@ function Update(self)
7271
self.activateSound:Play(self.Pos);
7372
self.delayTimer:Reset();
7473
end
75-
7674
elseif self.actionPhase == 1 then
77-
7875
self.Vel = self.PinStrength == 0 and self.Vel or Vector();
7976

8077
if self.blinkTimer:IsPastSimMS(500) then
81-
8278
self.blinkTimer:Reset();
8379

8480
if self.blink == false then
@@ -120,9 +116,7 @@ function Update(self)
120116
MovableMan:AddParticle(effectpar);
121117
end
122118
end
123-
124119
elseif self.actionPhase == 2 then
125-
126120
if self.blink == false then
127121
self.blink = true;
128122
self.Frame = ((self.alliedTeam + 1) * 2) + 1;

Data/Base.rte/Devices/Shared/Scripts/FlakShell.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function Update(self)
1717
checkPos = Vector(SceneMan.SceneWidth + checkPos.X, checkPos.Y);
1818
end
1919
end
20+
2021
local moCheck = SceneMan:GetMOIDPixel(checkPos.X, checkPos.Y);
2122
if moCheck ~= rte.NoMOID then
2223
local actor = MovableMan:GetMOFromID(MovableMan:GetMOFromID(moCheck).RootID);

Data/Base.rte/Devices/Shared/Scripts/FlamerFlame.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ function Update(self)
66
if math.abs(self.lastVel.AbsRadAngle - self.Vel.AbsRadAngle) > 0.25 then
77
self.Vel = Vector(self.lastVel.Magnitude, 0):RadRotate(self.Vel.AbsRadAngle + (math.random() * 0.4) - 0.2);
88
end
9+
910
self.lastVel = Vector(self.Vel.X, self.Vel.Y);
1011
end

Data/Base.rte/Devices/Shared/Scripts/GrenadeBandolierAttachable.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ function Destroy(self)
174174
bandolierAngularVel = self.grenadePreviouslyHeldByRootParent.AngularVel;
175175
end
176176
end
177+
177178
if self.currentGrenadeCount > 0 then
178179
self.bandolierObjectForDropping:SetNumberValue("GrenadesRemainingInBandolier", self.currentGrenadeCount);
179180

Data/Base.rte/Devices/Shared/Scripts/RevolverCylinderReload.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function Update(self)
1515
shell.AngularVel = RangeRand(-1, 1);
1616
MovableMan:AddParticle(shell);
1717
end
18+
1819
self.shellsToEject = 0;
1920
end
2021
end
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
function Create(self)
2-
32
self.shieldWalkSound = CreateSoundContainer("Metal Shield Walk", "Base.rte");
43
self.shieldWalkTimer = Timer();
5-
64
end
7-
function ThreadedUpdate(self)
85

6+
function ThreadedUpdate(self)
97
self.shieldWalkSound.Pos = self.Pos;
108
self.parent = self:GetRootParent();
119

@@ -15,5 +13,4 @@ function ThreadedUpdate(self)
1513
self.shieldWalkSound:Play(self.Pos);
1614
end
1715
end
18-
1916
end

Data/Base.rte/Devices/Tools/Constructor/Constructor.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function ConstructorWrapPos(checkPos)
66
checkPos = Vector(SceneMan.SceneWidth + checkPos.X, checkPos.Y);
77
end
88
end
9+
910
return checkPos;
1011
end
1112

@@ -20,18 +21,21 @@ function ConstructorFloodFill(x, y, startnum, maxnum, array, realposition, reals
2021
ConstructorFloodFill(x + 1, y, startnum + 1, maxnum, array, checkPos, realspacing);
2122
end
2223
end
24+
2325
if array[x - 1][y] == -1 or array[x - 1][y] > startnum then
2426
local checkPos = ConstructorWrapPos(realposition + Vector(-realspacing, 0));
2527
if SceneMan:GetTerrMatter(checkPos.X + (realspacing * 0.5), checkPos.Y + (realspacing * 0.5)) == rte.airID then
2628
ConstructorFloodFill(x - 1, y, startnum + 1, maxnum, array, checkPos, realspacing);
2729
end
2830
end
31+
2932
if array[x][y + 1] == -1 or array[x][y + 1] > startnum then
3033
local checkPos = ConstructorWrapPos(realposition + Vector(0, realspacing));
3134
if SceneMan:GetTerrMatter(checkPos.X + (realspacing * 0.5), checkPos.Y + (realspacing * 0.5)) == rte.airID then
3235
ConstructorFloodFill(x, y + 1, startnum + 1, maxnum, array, checkPos, realspacing);
3336
end
3437
end
38+
3539
if array[x][y - 1] == -1 or array[x][y - 1] > startnum then
3640
local checkPos = ConstructorWrapPos(realposition + Vector(0, -realspacing));
3741
if SceneMan:GetTerrMatter(checkPos.X + (realspacing * 0.5), checkPos.Y + (realspacing * 0.5)) == rte.airID then
@@ -272,6 +276,7 @@ function Update(self)
272276
break;
273277
end
274278
end
279+
275280
if freeSlot then
276281
local buildThis = {};
277282
buildThis[1] = mapX;
@@ -288,6 +293,7 @@ function Update(self)
288293
else
289294
self.toAutoBuild = false;
290295
end
296+
291297
local mode = self:GetNumberValue("BuildMode");
292298
if mode == 0 and not self.cursor then
293299
-- activation
@@ -355,6 +361,7 @@ function Update(self)
355361
end
356362
end
357363
end
364+
358365
if found > 0 then
359366
if digWeightTotal > 0 then
360367
digWeightTotal = digWeightTotal/9;
@@ -381,7 +388,6 @@ function Update(self)
381388

382389
self.buildList = {};
383390
self.cursor = nil;
384-
385391
elseif mode == 2 then -- build
386392
self:RemoveNumberValue("BuildMode");
387393

@@ -404,7 +410,6 @@ function Update(self)
404410
end
405411

406412
if self.cursor then
407-
408413
local cursorMovement = Vector();
409414
local mouseControlled = ctrl:IsMouseControlled();
410415
local aiming = false;
@@ -416,22 +421,27 @@ function Update(self)
416421
if ctrl:IsState(Controller.HOLD_UP) or ctrl:IsState(Controller.BODY_JUMP) then
417422
cursorMovement = cursorMovement + Vector(0, -1);
418423
end
424+
419425
if ctrl:IsState(Controller.HOLD_DOWN) or ctrl:IsState(Controller.BODY_CROUCH) then
420426
cursorMovement = cursorMovement + Vector(0, 1);
421427
end
428+
422429
if ctrl:IsState(Controller.HOLD_LEFT) then
423430
cursorMovement = cursorMovement + Vector(-1, 0);
424431
end
432+
425433
if ctrl:IsState(Controller.HOLD_RIGHT) then
426434
cursorMovement = cursorMovement + Vector(1, 0);
427435
end
428436
end
437+
429438
if ctrl:IsState(Controller.WEAPON_CHANGE_NEXT) then
430439
self.buildSize = self.buildSize * 2;
431440
if self.buildSize > self.buildSizeMax then
432441
self.buildSize = self.buildSizeMin;
433442
end
434443
end
444+
435445
if ctrl:IsState(Controller.WEAPON_CHANGE_PREV) then
436446
self.buildSize = self.buildSize/2;
437447
if self.buildSize < self.buildSizeMin then
@@ -442,6 +452,7 @@ function Update(self)
442452
if cursorMovement:MagnitudeIsGreaterThan(0) then
443453
self.cursor = self.cursor + (mouseControlled and cursorMovement or cursorMovement:SetMagnitude(self.cursorMoveSpeed * (aiming and 0.5 or 1)));
444454
end
455+
445456
local precise = not mouseControlled and aiming;
446457
local map = Vector();
447458
if precise then
@@ -453,12 +464,14 @@ function Update(self)
453464
PrimitiveMan:DrawLinePrimitive(screen, self.cursor + Vector(0, 4), self.cursor + Vector(0, -4), displayColorYellow);
454465
PrimitiveMan:DrawLinePrimitive(screen, self.cursor + Vector(4, 0), self.cursor + Vector(-4, 0), displayColorYellow);
455466
end
467+
456468
PrimitiveMan:DrawBoxPrimitive(screen, map, map + Vector(self.buildSize - 1, self.buildSize - 1), displayColorYellow);
457469

458470
local dist = SceneMan:ShortestDistance(actor.ViewPoint, self.cursor, SceneMan.SceneWrapsX);
459471
if math.abs(dist.X) > self.maxCursorDist.X then
460472
self.cursor.X = actor.ViewPoint.X + self.maxCursorDist.X * (dist.X < 0 and -1 or 1);
461473
end
474+
462475
if math.abs(dist.Y) > self.maxCursorDist.Y then
463476
self.cursor.Y = actor.ViewPoint.Y + self.maxCursorDist.Y * (dist.Y < 0 and -1 or 1);
464477
end
@@ -491,6 +504,7 @@ function Update(self)
491504
self.cursor = nil;
492505
end
493506
end
507+
494508
-- clean up the build list of nil slots and draw the squares to show the build layout
495509
local tempList = {};
496510
for i = 1, #self.buildList do
@@ -505,6 +519,7 @@ function Update(self)
505519
end
506520
end
507521
end
522+
508523
self.buildList = tempList;
509524

510525
-- building up the first block in the build queue
@@ -535,6 +550,7 @@ function Update(self)
535550
else
536551
name = "Base.rte/Constructor Tile " .. math.random(16);
537552
end
553+
538554
local terrainObject = CreateTerrainObject(name);
539555
terrainObject.Pos = pos;
540556
SceneMan:AddSceneObject(terrainObject);
@@ -554,6 +570,7 @@ function Update(self)
554570
PrimitiveMan:DrawBoxFillPrimitive(otherScreen, Vector(bx + self.buildList[1][1] + 1, by + self.buildList[1][2] + 1), Vector(bx + self.buildList[1][1] + cellSize, by + self.buildList[1][2] + cellSize), displayColorWhite);
555571
end
556572
end
573+
557574
if screen ~= -1 then
558575
PrimitiveMan:DrawLinePrimitive(screen, self.Pos, buildPos, displayColorBlue);
559576
end

0 commit comments

Comments
 (0)