Code cleanup in the Tiberian Dawn Lua scripts.

Uppercase global variables.
Declare local variables.
Remove unused variable.
This commit is contained in:
Matthias Mailänder
2022-09-09 10:13:24 +02:00
committed by Gustas
parent ca45e02265
commit b8e261ff2f
18 changed files with 108 additions and 115 deletions

View File

@@ -13,8 +13,8 @@ BikeReinforcments = { "bike" }
WorldLoaded = function()
Nod = Player.GetPlayer("Nod")
dinosaur = Player.GetPlayer("Dinosaur")
civilian = Player.GetPlayer("Civilian")
Dinosaur = Player.GetPlayer("Dinosaur")
Civilian = Player.GetPlayer("Civilian")
InvestigateObj = Nod.AddObjective("Investigate the nearby village for reports of\nstrange activity.")
@@ -22,9 +22,9 @@ WorldLoaded = function()
ReachVillageObj = Nod.AddObjective("Reach the village.")
Trigger.OnPlayerDiscovered(civilian, function(_, discoverer)
Trigger.OnPlayerDiscovered(Civilian, function(_, discoverer)
if discoverer == Nod and not Nod.IsObjectiveCompleted(ReachVillageObj) then
if not dinosaur.HasNoRequiredUnits() then
if not Dinosaur.HasNoRequiredUnits() then
KillDinos = Nod.AddObjective("Kill all creatures in the area.")
end
@@ -60,7 +60,7 @@ Tick = function()
Nod.MarkFailedObjective(InvestigateObj)
end
if dinosaur.HasNoRequiredUnits() then
if Dinosaur.HasNoRequiredUnits() then
if KillDinos then Nod.MarkCompletedObjective(KillDinos) end
Nod.MarkCompletedObjective(InvestigateObj)
end

View File

@@ -32,8 +32,8 @@ WorldLoaded = function()
InitObjectives(GDI)
secureAreaObjective = GDI.AddObjective("Eliminate all Nod forces in the area.")
beachheadObjective = GDI.AddObjective("Establish a beachhead.", "Secondary", false)
SecureAreaObjective = GDI.AddObjective("Eliminate all Nod forces in the area.")
BeachheadObjective = GDI.AddObjective("Establish a beachhead.", "Secondary", false)
ReinforceWithLandingCraft(GDI, MCVReinforcements, lstStart.Location + CVec.New(2, 0), lstEnd.Location + CVec.New(2, 0), mcvTarget.Location)
Reinforce(InfantryReinforcements)
@@ -46,15 +46,15 @@ end
Tick = function()
if Nod.HasNoRequiredUnits() then
GDI.MarkCompletedObjective(secureAreaObjective)
GDI.MarkCompletedObjective(SecureAreaObjective)
end
if DateTime.GameTime > DateTime.Seconds(5) and GDI.HasNoRequiredUnits() then
GDI.MarkFailedObjective(beachheadObjective)
GDI.MarkFailedObjective(secureAreaObjective)
GDI.MarkFailedObjective(BeachheadObjective)
GDI.MarkFailedObjective(SecureAreaObjective)
end
if DateTime.GameTime % DateTime.Seconds(1) == 0 and not GDI.IsObjectiveCompleted(beachheadObjective) and CheckForBase(GDI, GDIBaseBuildings) then
GDI.MarkCompletedObjective(beachheadObjective)
if DateTime.GameTime % DateTime.Seconds(1) == 0 and not GDI.IsObjectiveCompleted(BeachheadObjective) and CheckForBase(GDI, GDIBaseBuildings) then
GDI.MarkCompletedObjective(BeachheadObjective)
end
end

View File

@@ -7,7 +7,7 @@
information, see COPYING.
]]
nodInBaseTeam = { RushBuggy, RushRifle1, RushRifle2, RushRifle3 }
NodInBaseTeam = { RushBuggy, RushRifle1, RushRifle2, RushRifle3 }
MobileConstructionVehicle = { "mcv" }
EngineerReinforcements = { "e6", "e6", "e6" }
VehicleReinforcements = { "jeep" }
@@ -44,22 +44,22 @@ WorldLoaded = function()
InitObjectives(GDI)
nodObjective = Nod.AddObjective("Destroy all GDI troops.")
gdiObjective1 = GDI.AddObjective("Eliminate all Nod forces in the area.")
gdiObjective2 = GDI.AddObjective("Capture the Tiberium refinery.", "Secondary", false)
NodObjective = Nod.AddObjective("Destroy all GDI troops.")
GDIObjective1 = GDI.AddObjective("Eliminate all Nod forces in the area.")
GDIObjective2 = GDI.AddObjective("Capture the Tiberium refinery.", "Secondary", false)
Trigger.OnCapture(NodRefinery, function() GDI.MarkCompletedObjective(gdiObjective2) end)
Trigger.OnKilled(NodRefinery, function() GDI.MarkFailedObjective(gdiObjective2) end)
Trigger.OnCapture(NodRefinery, function() GDI.MarkCompletedObjective(GDIObjective2) end)
Trigger.OnKilled(NodRefinery, function() GDI.MarkFailedObjective(GDIObjective2) end)
Trigger.OnAllKilled(nodInBaseTeam, BridgeheadSecured)
Trigger.OnAllKilled(NodInBaseTeam, BridgeheadSecured)
end
Tick = function()
if GDI.HasNoRequiredUnits() then
Nod.MarkCompletedObjective(nodObjective)
Nod.MarkCompletedObjective(NodObjective)
end
if Nod.HasNoRequiredUnits() then
GDI.MarkCompletedObjective(gdiObjective1)
GDI.MarkCompletedObjective(GDIObjective1)
end
end

View File

@@ -122,16 +122,16 @@ WorldLoaded = function()
end)
Trigger.OnEnteredFootprint(AutoTrigger, function(a, id)
if not autoTrigger and a.Owner == GDI then
autoTrigger = true
if not AutoTriggered and a.Owner == GDI then
AutoTriggered = true
Trigger.RemoveFootprintTrigger(id)
BuildAuto()
end
end)
Trigger.OnEnteredFootprint(GDIHeliTrigger, function(a, id)
if not gdiHeliTrigger and a.Owner == GDI then
gdiHeliTrigger = true
if not GDIHeliTriggered and a.Owner == GDI then
GDIHeliTriggered = true
Trigger.RemoveFootprintTrigger(id)
Reinforcements.ReinforceWithTransport(GDI, "tran", nil, { GDIHeliEntry.Location, GDIHeliLZ.Location })
end

View File

@@ -110,16 +110,16 @@ WorldLoaded = function()
SetupWorld()
Trigger.OnExitedFootprint(BhndTrigger, function(a, id)
if not bhndTrigger and a.Owner == GDI then
bhndTrigger = true
if not BhndTriggered and a.Owner == GDI then
BhndTriggered = true
Trigger.RemoveFootprintTrigger(id)
SendHeli(NodHeli)
end
end)
Trigger.OnExitedFootprint(Atk1Trigger, function(a, id)
if not atk1Trigger and a.Owner == GDI then
atk1Trigger = true
if not Atk1Triggered and a.Owner == GDI then
Atk1Triggered = true
Trigger.RemoveFootprintTrigger(id)
Build(NodxUnits, false, function(actor)
@@ -131,8 +131,8 @@ WorldLoaded = function()
end)
Trigger.OnEnteredFootprint(Atk2Trigger, function(a, id)
if not atk2Trigger and a.Owner == GDI then
atk2Trigger = true
if not Atk2Triggered and a.Owner == GDI then
Atk2Triggered = true
Trigger.RemoveFootprintTrigger(id)
Build(NodxUnits, false, function(actor)
@@ -144,24 +144,20 @@ WorldLoaded = function()
end)
Trigger.OnEnteredFootprint(AutoTrigger, function(a, id)
if not autoTrigger and a.Owner == GDI then
autoTrigger = true
if not AutoTriggered and a.Owner == GDI then
AutoTriggered = true
Trigger.RemoveFootprintTrigger(id)
Build(AutoUnits, true, function(actor)
Trigger.OnKilled(actor, NodUnitKilled)
IdleHunt(actor)
end)
Trigger.AfterDelay(DateTime.Seconds(4), function()
IdleHunt(tank)
end)
end
end)
Trigger.OnEnteredFootprint(GDIHeliTrigger, function(a, id)
if not gdiHeliTrigger and a.Owner == GDI then
gdiHeliTrigger = true
if not GDIHeliTriggered and a.Owner == GDI then
GDIHeliTriggered = true
Trigger.RemoveFootprintTrigger(id)
Reinforcements.ReinforceWithTransport(GDI, "tran", nil, { HeliEntry.Location, GDIHeliLZ.Location })
end

View File

@@ -16,7 +16,6 @@ GDIReinforcementsPart2 = { "e2", "e2", "e2", "e2", "e2" }
TownAttackWave1 = { "bggy", "bggy" }
TownAttackWave2 = { "ltnk", "ltnk" }
TownAttackWave3 = { "e1", "e1", "e1", "e3", "e3", "e3" }
TownAttackWpts = { waypoint1, waypoint2 }
Civvie1Wpts = { CivvieWpts1, CivvieWpts2 }
Civvie2Wpts = { CivvieWpts3, CivvieWpts1, CivvieWpts4, CivvieWpts5, CivvieWpts6, CivvieWpts7, CivvieWpts8, CivvieWpts9, CivvieWpts10, CivvieWpts11 }
@@ -41,7 +40,6 @@ end
TownAttackAction = function(actor)
Trigger.OnIdle(actor, TownAttackersIdleAction)
FollowWaypoints(actor, TownAttackWpts)
end
AttackTown = function()
@@ -80,16 +78,16 @@ WorldLoaded = function()
EliminateNod = GDI.AddPrimaryObjective("Eliminate all Nod forces in the area.")
Trigger.OnExitedFootprint(TownAttackTrigger, function(a, id)
if not townAttackTrigger and a.Owner == GDI then
townAttackTrigger = true
if not TownAttackTriggered and a.Owner == GDI then
TownAttackTriggered = true
Trigger.RemoveFootprintTrigger(id)
AttackTown()
end
end)
Trigger.OnEnteredFootprint(GDIReinforcementsTrigger, function(a, id)
if not gdiReinforcementsTrigger and a.Owner == GDI then
gdiReinforcementsTrigger = true
if not GDIReinforcementsTriggered and a.Owner == GDI then
GDIReinforcementsTriggered = true
Trigger.RemoveFootprintTrigger(id)
SendGDIReinforcements()
end

View File

@@ -38,7 +38,7 @@ end
AttackPlayer = function()
Trigger.AfterDelay(DateTime.Seconds(40), function()
for type, count in pairs({ ['e3'] = 3, ['e4'] = 2 }) do
atk1Actors = Utils.Take(count, Nod.GetActorsByType(type))
local atk1Actors = Utils.Take(count, Nod.GetActorsByType(type))
Utils.Do(atk1Actors, function(unit)
unit.Move(waypoint6.Location)
unit.Move(waypoint7.Location)
@@ -52,7 +52,7 @@ AttackPlayer = function()
Trigger.AfterDelay(DateTime.Seconds(40), function()
for type, count in pairs({ ['e1'] = 3, ['e3'] = 2 }) do
atk2Actors = Utils.Take(count, Nod.GetActorsByType(type))
local atk2Actors = Utils.Take(count, Nod.GetActorsByType(type))
Utils.Do(atk2Actors, function(unit)
unit.Move(waypoint11.Location)
unit.Move(waypoint12.Location)
@@ -65,7 +65,7 @@ AttackPlayer = function()
Trigger.AfterDelay(DateTime.Seconds(80), function()
for type, count in pairs({ ['e3'] = 3, ['e4'] = 2 }) do
atk3Actors = Utils.Take(count, Nod.GetActorsByType(type))
local atk3Actors = Utils.Take(count, Nod.GetActorsByType(type))
Utils.Do(atk3Actors, function(unit)
unit.Move(waypoint6.Location)
unit.Move(waypoint7.Location)
@@ -79,7 +79,7 @@ AttackPlayer = function()
Trigger.AfterDelay(DateTime.Seconds(80), function()
for type, count in pairs({ ['e1'] = 3, ['e3'] = 2 }) do
atk4Actors = Utils.Take(count, Nod.GetActorsByType(type))
local atk4Actors = Utils.Take(count, Nod.GetActorsByType(type))
Utils.Do(atk4Actors, function(unit)
unit.Move(waypoint11.Location)
unit.Move(waypoint12.Location)
@@ -91,7 +91,7 @@ AttackPlayer = function()
end)
Trigger.AfterDelay(DateTime.Seconds(80), function()
atk5Actors = Utils.Take(2, Nod.GetActorsByType('bggy'))
local atk5Actors = Utils.Take(2, Nod.GetActorsByType('bggy'))
Utils.Do(atk5Actors, function(unit)
unit.Move(waypoint11.Location)
unit.Move(waypoint12.Location)

View File

@@ -91,10 +91,10 @@ GuardBase = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end

View File

@@ -94,10 +94,10 @@ ProduceHarvester = function(building)
if building.IsDead or building.Owner ~= Nod then
return
end
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end
@@ -158,7 +158,6 @@ ProduceVehicle = function(building)
VehicleAttackGroup[#VehicleAttackGroup + 1] = unit[1]
if #VehicleAttackGroup >= VehicleGroupSize[Difficulty] then
MoveAndHunt(VehicleAttackGroup, Path)
VehicleAttackGroup = { }
Trigger.AfterDelay(VehicleProductionCooldown[Difficulty], function() ProduceArty(building) end)

View File

@@ -72,7 +72,7 @@ SendWaves = function(counter, Waves)
end
SendHeli = function(heli)
units = Reinforcements.ReinforceWithTransport(Nod, "tran", heli.types, heli.entry, { heli.entry[1] })
local units = Reinforcements.ReinforceWithTransport(Nod, "tran", heli.types, heli.entry, { heli.entry[1] })
Utils.Do(units[2], function(actor)
actor.Hunt()
Trigger.OnIdle(actor, actor.Hunt)
@@ -84,12 +84,12 @@ SendHeli = function(heli)
end
MoveInitialArty = function(arty, waypoints)
units = { arty }
local units = { arty }
MoveAndIdle(units, waypoints)
end
TankTerror = function(tank)
units = { tank }
local units = { tank }
MoveAndHunt(units, WaypointGroupVillageLeft)
end

View File

@@ -90,10 +90,10 @@ GuardBase = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end

View File

@@ -68,10 +68,10 @@ CheckForHarvester = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end

View File

@@ -119,8 +119,8 @@ SendReinforcementsWave = function(team)
end
Trigger.OnEnteredFootprint(AbandonedBaseTrigger, function(a, id)
if not abandonedBaseTrigger and a.Owner == Nod then
abandonedBaseTrigger = true
if not AbandonedBaseTriggered and a.Owner == Nod then
AbandonedBaseTriggered = true
Trigger.RemoveFootprintTrigger(id)
FlareCamera = Actor.Create("camera", true, { Owner = Nod, Location = waypoint25.Location })
@@ -141,8 +141,8 @@ Trigger.OnEnteredFootprint(AbandonedBaseTrigger, function(a, id)
end)
Trigger.OnEnteredFootprint(ReinforcementsTrigger, function(a, id)
if not reinforcementsTrigger and a.Owner == Nod and a.Type ~= "harv" then
reinforcementsTrigger = true
if not ReinforcementsTriggered and a.Owner == Nod and a.Type ~= "harv" then
ReinforcementsTriggered = true
Trigger.RemoveFootprintTrigger(id)
Trigger.AfterDelay(DateTime.Seconds(5), function()

View File

@@ -68,10 +68,10 @@ CheckForHarvester = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end
@@ -139,23 +139,23 @@ Trigger.OnAllKilledOrCaptured(GDIBase, function()
Utils.Do(GDI.GetGroundAttackers(), IdleHunt)
end)
Trigger.OnKilled(GDIProc, function(building)
Trigger.OnKilled(GDIProc, function()
BuildBuilding(BaseProc, GDICYard)
end)
Trigger.OnKilled(GDINuke1, function(building)
Trigger.OnKilled(GDINuke1, function()
BuildBuilding(BaseNuke1, GDICYard)
end)
Trigger.OnKilled(GDINuke2, function(building)
Trigger.OnKilled(GDINuke2, function()
BuildBuilding(BaseNuke2, GDICYard)
end)
Trigger.OnKilled(GDINuke3, function(building)
Trigger.OnKilled(GDINuke3, function()
BuildBuilding(BaseNuke3, GDICYard)
end)
Trigger.OnKilled(GDIPyle, function(building)
Trigger.OnKilled(GDIPyle, function()
BuildBuilding(InfantryProduction, GDICYard)
end)

View File

@@ -121,32 +121,32 @@ SendReinforcementsWave = function(team)
end
Trigger.OnEnteredFootprint(Atk1, function(a, id)
if not atk1Trigger and a.Owner == Nod then
atk1Trigger = true
if not Atk1Triggered and a.Owner == Nod then
Atk1Triggered = true
SendAttackWave(GDI5)
Trigger.RemoveFootprintTrigger(id)
end
end)
Trigger.OnEnteredFootprint(Atk2, function(a, id)
if not atk2Trigger and a.Owner == Nod then
atk2Trigger = true
if not Atk2Triggered and a.Owner == Nod then
Atk2Triggered = true
SendAttackWave(GDI4)
Trigger.RemoveFootprintTrigger(id)
end
end)
Trigger.OnEnteredFootprint(Atk3, function(a, id)
if not atk3Trigger and a.Owner == Nod then
atk3Trigger = true
if not Atk3Triggered and a.Owner == Nod then
Atk3Triggered = true
SendAttackWave(GDI6)
Trigger.RemoveFootprintTrigger(id)
end
end)
Trigger.OnEnteredFootprint(Atk4, function(a, id)
if not atk4Trigger and a.Owner == Nod then
atk4Trigger = true
if not Atk4Triggered and a.Owner == Nod then
Atk4Triggered = true
SendReinforcementsWave(GDI1)
Trigger.RemoveFootprintTrigger(id)
end

View File

@@ -89,10 +89,10 @@ GuardBase = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end
@@ -158,27 +158,27 @@ Trigger.OnAllKilledOrCaptured(GDIBase, function()
Utils.Do(GDI.GetGroundAttackers(), IdleHunt)
end)
Trigger.OnKilled(GDIProc, function(building)
Trigger.OnKilled(GDIProc, function()
BuildBuilding(BaseProc, GDICYard)
end)
Trigger.OnKilled(GDINuke1, function(building)
Trigger.OnKilled(GDINuke1, function()
BuildBuilding(BaseNuke1, GDICYard)
end)
Trigger.OnKilled(GDINuke2, function(building)
Trigger.OnKilled(GDINuke2, function()
BuildBuilding(BaseNuke2, GDICYard)
end)
Trigger.OnKilled(GDINuke3, function(building)
Trigger.OnKilled(GDINuke3, function()
BuildBuilding(BaseNuke3, GDICYard)
end)
Trigger.OnKilled(GDINuke4, function(building)
Trigger.OnKilled(GDINuke4, function()
BuildBuilding(BaseNuke4, GDICYard)
end)
Trigger.OnKilled(GDIPyle, function(building)
Trigger.OnKilled(GDIPyle, function()
BuildBuilding(InfantryProduction, GDICYard)
end)

View File

@@ -89,10 +89,10 @@ GuardBase = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end
@@ -158,30 +158,30 @@ Trigger.OnAllKilledOrCaptured(GDIBase, function()
Utils.Do(GDI.GetGroundAttackers(), IdleHunt)
end)
Trigger.OnKilled(GDIProc, function(building)
Trigger.OnKilled(GDIProc, function()
BuildBuilding(BaseProc, GDICYard)
end)
Trigger.OnKilled(GDINuke1, function(building)
Trigger.OnKilled(GDINuke1, function()
BuildBuilding(BaseNuke1, GDICYard)
end)
Trigger.OnKilled(GDINuke2, function(building)
Trigger.OnKilled(GDINuke2, function()
BuildBuilding(BaseNuke2, GDICYard)
end)
Trigger.OnKilled(GDINuke3, function(building)
Trigger.OnKilled(GDINuke3, function()
BuildBuilding(BaseNuke3, GDICYard)
end)
Trigger.OnKilled(GDINuke4, function(building)
Trigger.OnKilled(GDINuke4, function()
BuildBuilding(BaseNuke4, GDICYard)
end)
Trigger.OnKilled(GDIPyle, function(building)
Trigger.OnKilled(GDIPyle, function()
BuildBuilding(InfantryProduction, GDICYard)
end)
Trigger.OnKilled(GDIWeap, function(building)
Trigger.OnKilled(GDIWeap, function()
BuildBuilding(VehicleProduction, GDICYard)
end)

View File

@@ -93,10 +93,10 @@ GuardBase = function()
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
if not BuildingHarvester then
BuildingHarvester = true
building.Build(HarvesterProductionType, function()
buildingHarvester = false
BuildingHarvester = false
end)
end
end
@@ -162,30 +162,30 @@ Trigger.OnAllKilledOrCaptured(GDIBase, function()
Utils.Do(GDI.GetGroundAttackers(), IdleHunt)
end)
Trigger.OnKilled(GDIProc, function(building)
Trigger.OnKilled(GDIProc, function()
BuildBuilding(BaseProc, GDICYard)
end)
Trigger.OnKilled(GDINuke1, function(building)
Trigger.OnKilled(GDINuke1, function()
BuildBuilding(BaseNuke1, GDICYard)
end)
Trigger.OnKilled(GDINuke2, function(building)
Trigger.OnKilled(GDINuke2, function()
BuildBuilding(BaseNuke2, GDICYard)
end)
Trigger.OnKilled(GDINuke3, function(building)
Trigger.OnKilled(GDINuke3, function()
BuildBuilding(BaseNuke3, GDICYard)
end)
Trigger.OnKilled(GDINuke4, function(building)
Trigger.OnKilled(GDINuke4, function()
BuildBuilding(BaseNuke4, GDICYard)
end)
Trigger.OnKilled(GDIPyle, function(building)
Trigger.OnKilled(GDIPyle, function()
BuildBuilding(InfantryProduction, GDICYard)
end)
Trigger.OnKilled(GDIWeap, function(building)
Trigger.OnKilled(GDIWeap, function()
BuildBuilding(VehicleProduction, GDICYard)
end)