Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiberian Dawn Lua code cleanup #20275

Merged
merged 1 commit into from Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions mods/cnc/maps/funpark01/scj01ea.lua
Expand Up @@ -13,18 +13,18 @@ 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.")

InitObjectives(Nod)

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

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions mods/cnc/maps/gdi01/gdi01.lua
Expand Up @@ -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)
Expand All @@ -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
18 changes: 9 additions & 9 deletions mods/cnc/maps/gdi02/gdi02.lua
Expand Up @@ -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" }
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions mods/cnc/maps/gdi04a/gdi04a.lua
Expand Up @@ -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
Expand Down
24 changes: 10 additions & 14 deletions mods/cnc/maps/gdi04b/gdi04b.lua
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions mods/cnc/maps/gdi04c/gdi04c.lua
Expand Up @@ -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 }
Expand All @@ -41,7 +40,6 @@ end

TownAttackAction = function(actor)
Trigger.OnIdle(actor, TownAttackersIdleAction)
FollowWaypoints(actor, TownAttackWpts)
Mailaender marked this conversation as resolved.
Show resolved Hide resolved
end

AttackTown = function()
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions mods/cnc/maps/gdi07/gdi07.lua
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions mods/cnc/maps/gdi08a/gdi08a-AI.lua
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions mods/cnc/maps/gdi08b/gdi08b-AI.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions mods/cnc/maps/gdi08b/gdi08b.lua
Expand Up @@ -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)
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions mods/cnc/maps/gdi09/gdi09-AI.lua
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mods/cnc/maps/nod07a/nod07a-AI.lua
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions mods/cnc/maps/nod07a/nod07a.lua
Expand Up @@ -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 })
Expand All @@ -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()
Expand Down