Use a global script in Tiberian Dawn

This commit is contained in:
abcdefg30
2019-05-01 23:13:39 +02:00
committed by reaperrr
parent dbe73a06ad
commit b1f6c69fce
71 changed files with 2001 additions and 3877 deletions

View File

@@ -6,6 +6,7 @@
the License, or (at your option) any later version. For more
information, see COPYING.
]]
AttackPaths = { { AttackPath1 }, { AttackPath2 }, { AttackPath3 } }
GDIBase = { GDICYard, GDIPyle, GDIWeap, GDIHQ, GDIProc, GDINuke1, GDINuke2, GDINuke3, GDIBuilding1, GDIBuilding2, GDIBuilding3, GDIBuilding4, GDIBuilding5, GDIBuilding6, GDIBuilding7, GDIBuilding8, GDIBuilding9 }
GDIOrcas = { GDIOrca1, GDIOrca2 }
@@ -20,48 +21,40 @@ VehicleProductionCooldown = DateTime.Minutes(4)
VehicleProductionTypes = { "jeep", "jeep", "mtnk", "mtnk", "mtnk" }
StartingCash = 4000
BaseProc = { type = "proc", pos = CPos.New(50, 16), cost = 1500, exists = true }
BaseNuke1 = { type = "nuke", pos = CPos.New(60, 17), cost = 500, exists = true }
BaseNuke2 = { type = "nuke", pos = CPos.New(59, 19), cost = 500, exists = true }
BaseNuke3 = { type = "nuke", pos = CPos.New(57, 18), cost = 500, exists = true }
BaseNuke4 = { type = "nuke", pos = CPos.New(58, 16), cost = 500, exists = true }
InfantryProduction = { type = "pyle", pos = CPos.New(53, 14), cost = 500, exists = true }
VehicleProduction = { type = "weap", pos = CPos.New(48, 13), cost = 2000, exists = true }
BaseProc = { type = "proc", pos = CPos.New(50, 16), cost = 1500 }
BaseNuke1 = { type = "nuke", pos = CPos.New(60, 17), cost = 500 }
BaseNuke2 = { type = "nuke", pos = CPos.New(59, 19), cost = 500 }
BaseNuke3 = { type = "nuke", pos = CPos.New(57, 18), cost = 500 }
BaseNuke4 = { type = "nuke", pos = CPos.New(58, 16), cost = 500 }
InfantryProduction = { type = "pyle", pos = CPos.New(53, 14), cost = 500 }
VehicleProduction = { type = "weap", pos = CPos.New(48, 13), cost = 2000 }
BaseBuildings = { BaseProc, BaseNuke1, BaseNuke2, BaseNuke3, BaseNuke4, InfantryProduction, VehicleProduction }
AutoGuard = function(guards)
Utils.Do(guards, function(guard)
Trigger.OnDamaged(guard, function(guard)
IdleHunt(guard)
end)
Trigger.OnDamaged(guard, IdleHunt)
end)
end
BuildBase = function(cyard)
Utils.Do(BaseBuildings, function(building)
if not building.exists and not cyardIsBuilding then
BuildBuilding(building, cyard)
return
end
end)
Trigger.AfterDelay(DateTime.Seconds(10), function() BuildBase(cyard) end)
end
BuildBuilding = function(building, cyard)
cyardIsBuilding = true
if CyardIsBuilding or GDI.Cash < building.cost then
Trigger.AfterDelay(DateTime.Seconds(10), function() BuildBuilding(building, cyard) end)
return
end
CyardIsBuilding = true
GDI.Cash = GDI.Cash - building.cost
Trigger.AfterDelay(Actor.BuildTime(building.type), function()
cyardIsBuilding = false
CyardIsBuilding = false
if cyard.IsDead or cyard.Owner ~= enemy then
if cyard.IsDead or cyard.Owner ~= GDI then
GDI.Cash = GDI.Cash + building.cost
return
end
local actor = Actor.Create(building.type, true, { Owner = enemy, Location = building.pos })
enemy.Cash = enemy.Cash - building.cost
building.exists = true
local actor = Actor.Create(building.type, true, { Owner = GDI, Location = building.pos })
if actor.Type == 'pyle' or actor.Type == 'hand' then
Trigger.AfterDelay(DateTime.Seconds(10), function() ProduceInfantry(actor) end)
@@ -69,28 +62,25 @@ BuildBuilding = function(building, cyard)
Trigger.AfterDelay(DateTime.Seconds(10), function() ProduceVehicle(actor) end)
end
Trigger.OnKilled(actor, function() building.exists = false end)
Trigger.OnDamaged(actor, function(building)
if building.Owner == enemy and building.Health < building.MaxHealth * 3/4 then
building.StartBuildingRepairs()
end
Trigger.OnKilled(actor, function()
BuildBuilding(building, cyard)
end)
Trigger.AfterDelay(DateTime.Seconds(10), function() BuildBase(cyard) end)
RepairBuilding(GDI, actor, 0.75)
end)
end
CheckForHarvester = function()
local harv = enemy.GetActorsByType("harv")
local harv = GDI.GetActorsByType("harv")
return #harv > 0
end
GuardBase = function()
Utils.Do(GDIBase, function(building)
Trigger.OnDamaged(building, function(guard)
Trigger.OnDamaged(building, function()
Utils.Do(GDIOrcas, function(guard)
if not guard.IsDead and not building.IsDead then
guard.Stop()
guard.Guard(building)
end
end)
@@ -98,20 +88,6 @@ GuardBase = function()
end)
end
IdleHunt = function(unit)
if not unit.IsDead then
Trigger.OnIdle(unit, unit.Hunt)
end
end
IdlingUnits = function(enemy)
local lazyUnits = enemy.GetGroundAttackers()
Utils.Do(lazyUnits, function(unit)
IdleHunt(unit)
end)
end
ProduceHarvester = function(building)
if not buildingHarvester then
buildingHarvester = true
@@ -122,10 +98,11 @@ ProduceHarvester = function(building)
end
ProduceInfantry = function(building)
if building.IsDead or building.Owner ~= enemy then
if building.IsDead or building.Owner ~= GDI then
return
elseif not CheckForHarvester() then
Trigger.AfterDelay(DateTime.Seconds(10), function() ProduceInfantry(building) end)
return
end
local delay = Utils.RandomInteger(DateTime.Seconds(3), DateTime.Seconds(9))
@@ -135,22 +112,23 @@ ProduceInfantry = function(building)
InfantryAttackGroup[#InfantryAttackGroup + 1] = unit[1]
if #InfantryAttackGroup >= InfantryGroupSize then
SendUnits(InfantryAttackGroup, Path)
MoveAndHunt(InfantryAttackGroup, Path)
InfantryAttackGroup = { }
Trigger.AfterDelay(InfantryProductionCooldown, function() ProduceInfantry(building) end)
else
Trigger.AfterDelay(delay, function() ProduceInfantry(building) end)
end
end)
end
ProduceVehicle = function(building)
if building.IsDead or building.Owner ~= enemy then
if building.IsDead or building.Owner ~= GDI then
return
elseif not CheckForHarvester() then
ProduceHarvester(building)
Trigger.AfterDelay(DateTime.Seconds(10), function() ProduceVehicle(building) end)
return
end
local delay = Utils.RandomInteger(DateTime.Seconds(12), DateTime.Seconds(17))
@@ -160,7 +138,7 @@ ProduceVehicle = function(building)
VehicleAttackGroup[#VehicleAttackGroup + 1] = unit[1]
if #VehicleAttackGroup >= VehicleGroupSize then
SendUnits(VehicleAttackGroup, Path)
MoveAndHunt(VehicleAttackGroup, Path)
VehicleAttackGroup = { }
Trigger.AfterDelay(VehicleProductionCooldown, function() ProduceVehicle(building) end)
else
@@ -169,60 +147,41 @@ ProduceVehicle = function(building)
end)
end
SendUnits = function(units, waypoints)
Utils.Do(units, function(unit)
if not unit.IsDead then
Utils.Do(waypoints, function(waypoint)
unit.AttackMove(waypoint.Location)
end)
IdleHunt(unit)
end
end)
end
StartAI = function()
RepairNamedActors(GDI, 0.75)
StartAI = function(cyard)
Utils.Do(Map.NamedActors, function(actor)
if actor.Owner == enemy and actor.HasProperty("StartBuildingRepairs") then
Trigger.OnDamaged(actor, function(building)
if building.Owner == enemy and building.Health < 3/4 * building.MaxHealth then
building.StartBuildingRepairs()
end
end)
end
end)
enemy.Cash = StartingCash
BuildBase(cyard)
GDI.Cash = StartingCash
GuardBase()
end
Trigger.OnAllKilledOrCaptured(GDIBase, function()
IdlingUnits(enemy)
Utils.Do(GDI.GetGroundAttackers(), IdleHunt)
end)
Trigger.OnKilled(GDIProc, function(building)
BaseProc.exists = false
BuildBuilding(BaseProc, GDICYard)
end)
Trigger.OnKilled(GDINuke1, function(building)
BaseNuke1.exists = false
BuildBuilding(BaseNuke1, GDICYard)
end)
Trigger.OnKilled(GDINuke2, function(building)
BaseNuke2.exists = false
BuildBuilding(BaseNuke2, GDICYard)
end)
Trigger.OnKilled(GDINuke3, function(building)
BaseNuke3.exists = false
BuildBuilding(BaseNuke3, GDICYard)
end)
Trigger.OnKilled(GDINuke4, function(building)
BaseNuke4.exists = false
BuildBuilding(BaseNuke4, GDICYard)
end)
Trigger.OnKilled(GDIPyle, function(building)
InfantryProduction.exists = false
BuildBuilding(InfantryProduction, GDICYard)
end)
Trigger.OnKilled(GDIWeap, function(building)
VehicleProduction.exists = false
BuildBuilding(VehicleProduction, GDICYard)
end)

View File

@@ -6,6 +6,7 @@
the License, or (at your option) any later version. For more
information, see COPYING.
]]
WaypointGroup1 = { waypoint0, waypoint1, waypoint2, waypoint3, waypoint6, waypoint10 }
WaypointGroup2 = { waypoint0, waypoint1, waypoint2, waypoint3, waypoint6, waypoint7, waypoint8, waypoint9, waypoint10 }
WaypointGroup3 = { waypoint0, waypoint1, waypoint2, waypoint3, waypoint4, waypoint5 }
@@ -38,79 +39,36 @@ NodBaseTrigger = { CPos.New(52, 52), CPos.New(52, 53), CPos.New(52, 54), CPos.Ne
AirstrikeDelay = DateTime.Minutes(2) + DateTime.Seconds(20)
NodBaseCapture = function()
nodBaseTrigger = true
player.MarkCompletedObjective(NodObjective1)
FlareCamera = Actor.Create("camera", true, { Owner = Nod, Location = waypoint25.Location })
Flare = Actor.Create("flare", true, { Owner = Nod, Location = waypoint25.Location })
SendHelicopter()
Nod.MarkCompletedObjective(LocateNodBase)
Utils.Do(NodBase, function(actor)
actor.Owner = player
actor.Owner = Nod
end)
Trigger.AfterDelay(DateTime.Seconds(1), function()
Media.PlaySpeechNotification(player, "NewOptions")
Media.PlaySpeechNotification(Nod, "NewOptions")
end)
end
searches = 0
getAirstrikeTarget = function()
local list = player.GetGroundAttackers()
if #list == 0 then
return
end
local target = list[DateTime.GameTime % #list + 1].CenterPosition
local sams = Map.ActorsInCircle(target, WDist.New(8 * 1024), function(actor)
return actor.Type == "sam" end)
if #sams == 0 then
searches = 0
return target
elseif searches < 6 then
searches = searches + 1
return getAirstrikeTarget()
else
searches = 0
return nil
end
end
--Provide the player with a helicopter until the outpost got captured
-- Provide the Nod with a helicopter until the outpost got captured
SendHelicopter = function()
Trigger.AfterDelay(DateTime.Seconds(5), function()
if not outpostCaptured then
Media.PlaySpeechNotification(player, "Reinforce")
TransportHelicopter = Reinforcements.ReinforceWithTransport(player, 'tran', nil, { ReinforcementsHelicopterSpawn.Location, waypoint15.Location })[1]
Trigger.OnKilled(TransportHelicopter, function()
SendHelicopter()
end)
if not Nod.IsObjectiveCompleted(CaptureGDIOutpost) then
Media.PlaySpeechNotification(Nod, "Reinforce")
TransportHelicopter = Reinforcements.ReinforceWithTransport(Nod, 'tran', nil, { ReinforcementsHelicopterSpawn.Location, waypoint15.Location })[1]
Trigger.OnKilled(TransportHelicopter, SendHelicopter)
end
end)
end
SendAttackWave = function(team)
for type, amount in pairs(team.units) do
count = 0
actors = enemy.GetActorsByType(type)
Utils.Do(actors, function(actor)
if actor.IsIdle and count < amount then
SetAttackWaypoints(actor, team.waypoints)
IdleHunt(actor)
count = count + 1
end
end)
end
end
SetAttackWaypoints = function(actor, waypoints)
if not actor.IsDead then
Utils.Do(waypoints, function(waypoint)
actor.AttackMove(waypoint.Location)
end)
end
end
SendGDIAirstrike = function(hq, delay)
if not hq.IsDead and hq.Owner == enemy then
local target = getAirstrikeTarget()
if not hq.IsDead and hq.Owner == GDI then
local target = GetAirstrikeTarget(Nod)
if target then
hq.SendAirstrike(target, false, Facing.NorthEast + 4)
@@ -124,40 +82,35 @@ end
SendWaves = function(counter, Waves)
if counter <= #Waves then
local team = Waves[counter]
SendAttackWave(team)
for type, amount in pairs(team.units) do
MoveAndHunt(Utils.Take(amount, GDI.GetActorsByType(type)), team.waypoints)
end
Trigger.AfterDelay(DateTime.Seconds(team.delay), function() SendWaves(counter + 1, Waves) end)
end
end
StartWaves = function()
SendWaves(1, AutoAttackWaves)
end
Trigger.OnAllKilled(IntroGuards, function()
FlareCamera = Actor.Create("camera", true, { Owner = player, Location = waypoint25.Location })
Flare = Actor.Create("flare", true, { Owner = player, Location = waypoint25.Location })
SendHelicopter()
player.MarkCompletedObjective(NodObjective1)
NodBaseCapture()
if not Nod.IsObjectiveCompleted(LocateNodBase) then
NodBaseCapture()
end
end)
Trigger.OnAllKilledOrCaptured(Outpost, function()
if not outpostCaptured then
outpostCaptured = true
if not Nod.IsObjectiveCompleted(CaptureGDIOutpost) then
Nod.MarkCompletedObjective(CaptureGDIOutpost)
Trigger.AfterDelay(DateTime.Minutes(1), function()
if not GDIHQ.IsDead and (not NodHand.IsDead or not NodNuke.IsDead) then
local airstrikeproxy = Actor.Create("airstrike.proxy", false, { Owner = enemy })
local airstrikeproxy = Actor.Create("airstrike.proxy", false, { Owner = GDI })
airstrikeproxy.SendAirstrike(AirstrikeTarget.CenterPosition, false, Facing.NorthEast + 4)
airstrikeproxy.Destroy()
end
end)
Trigger.AfterDelay(DateTime.Seconds(15), function()
Utils.Do(OutpostGuards, function(unit)
IdleHunt(unit)
end)
Utils.Do(OutpostGuards, IdleHunt)
end)
Trigger.AfterDelay(DateTime.Minutes(1), function()
@@ -165,8 +118,7 @@ Trigger.OnAllKilledOrCaptured(Outpost, function()
Flare.Destroy()
end)
player.MarkCompletedObjective(NodObjective2)
Trigger.AfterDelay(DateTime.Minutes(1), function() StartWaves() end)
Trigger.AfterDelay(DateTime.Minutes(1), function() SendWaves(1, AutoAttackWaves) end)
Trigger.AfterDelay(AirstrikeDelay, function() SendGDIAirstrike(GDIHQ, AirstrikeDelay) end)
Trigger.AfterDelay(DateTime.Minutes(2), function() ProduceInfantry(GDIPyle) end)
Trigger.AfterDelay(DateTime.Minutes(3), function() ProduceVehicle(GDIWeap) end)
@@ -175,65 +127,50 @@ end)
Trigger.OnCapture(OutpostCYard, function()
Trigger.AfterDelay(DateTime.Seconds(4), function()
Media.PlaySpeechNotification(player, "NewOptions")
Media.PlaySpeechNotification(Nod, "NewOptions")
end)
end)
Trigger.OnAnyKilled(Outpost, function()
if not outpostCaptured then
player.MarkFailedObjective(NodObjective2)
if not Nod.IsObjectiveCompleted(CaptureGDIOutpost) then
Nod.MarkFailedObjective(CaptureGDIOutpost)
end
end)
Trigger.OnEnteredFootprint(NodBaseTrigger, function(a, id)
if not nodBaseTrigger and a.Owner == player then
if not Nod.IsObjectiveCompleted(LocateNodBase) and a.Owner == Nod then
NodBaseCapture()
Trigger.RemoveFootprintTrigger(id)
end
end)
WorldLoaded = function()
player = Player.GetPlayer("Nod")
enemy = Player.GetPlayer("GDI")
Camera.Position = waypoint26.CenterPosition
Media.PlaySpeechNotification(player, "Reinforce")
Reinforcements.ReinforceWithTransport(player, 'tran.in', IntroReinforcements, { ReinforcementsHelicopterSpawn.Location, ReinforcementsHelicopterRally.Location }, { ReinforcementsHelicopterSpawn.Location }, nil, nil)
Nod = Player.GetPlayer("Nod")
GDI = Player.GetPlayer("GDI")
StartAI(GDICYard)
Camera.Position = waypoint26.CenterPosition
Media.PlaySpeechNotification(Nod, "Reinforce")
Reinforcements.ReinforceWithTransport(Nod, "tran.in", IntroReinforcements, { ReinforcementsHelicopterSpawn.Location, ReinforcementsHelicopterRally.Location }, { ReinforcementsHelicopterSpawn.Location })
StartAI()
AutoGuard(IntroGuards)
AutoGuard(OutpostGuards)
Trigger.OnObjectiveAdded(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
end)
InitObjectives(Nod)
Trigger.OnObjectiveCompleted(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed")
end)
Trigger.OnObjectiveFailed(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed")
end)
Trigger.OnPlayerWon(player, function()
Media.PlaySpeechNotification(player, "Win")
end)
Trigger.OnPlayerLost(player, function()
Media.PlaySpeechNotification(player, "Lose")
end)
NodObjective1 = player.AddPrimaryObjective("Locate the Nod base.")
NodObjective2 = player.AddPrimaryObjective("Capture the GDI outpost.")
NodObjective3 = player.AddPrimaryObjective("Eliminate all GDI forces in the area.")
GDIObjective = enemy.AddPrimaryObjective("Eliminate all Nod forces in the area.")
LocateNodBase = Nod.AddObjective("Locate the Nod base.")
CaptureGDIOutpost = Nod.AddObjective("Capture the GDI outpost.")
EliminateGDI = Nod.AddObjective("Eliminate all GDI forces in the area.")
GDIObjective = GDI.AddObjective("Eliminate all Nod forces in the area.")
end
Tick = function()
if DateTime.GameTime > 2 and player.HasNoRequiredUnits() then
enemy.MarkCompletedObjective(GDIObjective)
if DateTime.GameTime > 2 and Nod.HasNoRequiredUnits() then
GDI.MarkCompletedObjective(GDIObjective)
end
if DateTime.GameTime > 2 and enemy.HasNoRequiredUnits() then
player.MarkCompletedObjective(NodObjective3)
if DateTime.GameTime > 2 and GDI.HasNoRequiredUnits() then
Nod.MarkCompletedObjective(EliminateGDI)
end
end

View File

@@ -1,6 +1,6 @@
World:
LuaScript:
Scripts: nod08a.lua, nod08a-AI.lua
Scripts: campaign-global.lua, nod08a.lua, nod08a-AI.lua
MusicPlaylist:
StartingMusic: linefire
VictoryMusic: nod_win1