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,36 +6,37 @@
the License, or (at your option) any later version. For more
information, see COPYING.
]]
WaypointGroup1 = { waypoint0, waypoint15 }
WaypointGroup2 = { waypoint0, waypoint1, waypoint2, waypoint3, waypoint4, waypoint5, waypoint8 }
WaypointGroup3 = { waypoint0, waypoint1, waypoint2, waypoint3, waypoint9, waypoint10, waypoint11, waypoint6, waypoint7 }
WaypointGroup4 = { waypoint9, waypoint10, waypoint11, waypoint6, waypoint7, waypoint14 }
GDI1 = { units = { ['e2'] = 2, ['e6'] = 1 }, waypoints = WaypointGroup4, delay = 40 }
GDI2 = { units = { ['e1'] = 1, ['e2'] = 1}, waypoints = WaypointGroup3, delay = 40 }
GDI3 = { units = { ['e2'] = 1, ['e3'] = 1, ['jeep'] = 1 }, waypoints = WaypointGroup2, delay = 40 }
GDI4 = { units = { ['mtnk'] = 1 }, waypoints = WaypointGroup3, delay = 40 }
GDI5 = { units = { ['e1'] = 1, ['e2'] = 2 }, waypoints = WaypointGroup2, delay = 40 }
GDI6 = { units = { ['e2'] = 2, ['e2'] = 3 }, waypoints = WaypointGroup1, delay = 40 }
Auto1 = { units = { ['e1'] = 3, ['e2'] = 2 }, waypoints = WaypointGroup3, delay = 40 }
Auto2 = { units = { ['e1'] = 1, ['e2'] = 2 }, waypoints = WaypointGroup2, delay = 40 }
Auto3 = { units = { ['e1'] = 1, ['e3'] = 2 }, waypoints = WaypointGroup2, delay = 40 }
Auto4 = { units = { ['e2'] = 2, ['e3'] = 2 }, waypoints = WaypointGroup3, delay = 40 }
Auto5 = { units = { ['jeep'] = 1 }, waypoints = WaypointGroup2, delay = 50 }
Auto6 = { units = { ['jeep'] = 1 }, waypoints = WaypointGroup3, delay = 40 }
Auto7 = { units = { ['mtnk'] = 1 }, waypoints = WaypointGroup2, delay = 50 }
Auto8 = { units = { ['mtnk'] = 1 }, waypoints = WaypointGroup3, delay = 30 }
GDI1 = { units = { "e2", "e2", "e6" }, waypoints = WaypointGroup4, delay = 40 }
GDI2 = { units = { "e1", "e2" }, waypoints = WaypointGroup3, delay = 40 }
GDI3 = { units = { "e2", "e3", "jeep" }, waypoints = WaypointGroup2, delay = 40 }
GDI4 = { units = { "mtnk" }, waypoints = WaypointGroup3, delay = 40 }
GDI5 = { units = { "e1", "e2" }, waypoints = WaypointGroup2, delay = 40 }
GDI6 = { units = { "e2", "e2", "e2", "e2", "e2" }, waypoints = WaypointGroup1, delay = 40 }
Auto1 = { units = { "e1", "e1", "e1", "e2", "e2" }, waypoints = WaypointGroup3, delay = 40 }
Auto2 = { units = { "e1", "e2", "e2" }, waypoints = WaypointGroup2, delay = 40 }
Auto3 = { units = { "e1", "e3", "e3" }, waypoints = WaypointGroup2, delay = 40 }
Auto4 = { units = { "e2", "e2", "e3", "e3" }, waypoints = WaypointGroup3, delay = 40 }
Auto5 = { units = { "jeep" }, waypoints = WaypointGroup2, delay = 50 }
Auto6 = { units = { "jeep" }, waypoints = WaypointGroup3, delay = 40 }
Auto7 = { units = { "mtnk" }, waypoints = WaypointGroup2, delay = 50 }
Auto8 = { units = { "mtnk" }, waypoints = WaypointGroup3, delay = 30 }
AirstrikeDelay = DateTime.Minutes(2) + DateTime.Seconds(10)
AutoAttackWaves = { Auto1, Auto2, Auto3, Auto4, Auto5, Auto6, Auto7, Auto8 }
WhitelistedStructures = { 'afld', 'hand', 'hq', 'nuke', 'silo', 'proc', 'sam' }
WhitelistedStructures = { "afld", "hand", "hq", "nuke", "silo", "proc", "sam" }
NodUnitsTanks = { 'ltnk', 'ltnk', 'ltnk' }
NodUnitsBikes = { 'bike', 'bike', 'bike' }
NodUnitsBuggys = { 'bggy', 'bggy', 'bggy' }
NodUnitsRockets = { 'e3', 'e3', 'e3' }
NodUnitsGunners = { 'e1', 'e1', 'e1' }
NodUnitsTanks = { "ltnk", "ltnk", "ltnk" }
NodUnitsBikes = { "bike", "bike", "bike" }
NodUnitsBuggys = { "bggy", "bggy", "bggy" }
NodUnitsRockets = { "e3", "e3", "e3" }
NodUnitsGunners = { "e1", "e1", "e1" }
Atk1 = { CPos.New(11, 43), CPos.New(10, 43), CPos.New(9, 43), CPos.New(8, 43), CPos.New(7, 43), CPos.New(6, 43), CPos.New(5, 43), CPos.New(11, 42), CPos.New(10, 42), CPos.New(9, 42), CPos.New(8, 42), CPos.New(7, 42), CPos.New(6, 42), CPos.New(5, 42), CPos.New(23, 38), CPos.New(22, 38), CPos.New(21, 38), CPos.New(20, 38), CPos.New(19, 38), CPos.New(24, 37), CPos.New(23, 37), CPos.New(22, 37), CPos.New(21, 37), CPos.New(20, 37), CPos.New(19, 37) }
Atk2 = { CPos.New(16, 52), CPos.New(15, 52), CPos.New(14, 52), CPos.New(13, 52), CPos.New(12, 52), CPos.New(11, 52), CPos.New(10, 52), CPos.New(9, 52), CPos.New(8, 52), CPos.New(16, 51), CPos.New(15, 51), CPos.New(14, 51), CPos.New(13, 51), CPos.New(12, 51), CPos.New(11, 51), CPos.New(10, 51), CPos.New(9, 51), CPos.New(8, 51), CPos.New(31, 44), CPos.New(30, 44), CPos.New(29, 44), CPos.New(28, 44), CPos.New(27, 44), CPos.New(26, 44), CPos.New(25, 44), CPos.New(24, 44), CPos.New(23, 44), CPos.New(22, 44), CPos.New(21, 44), CPos.New(31, 43), CPos.New(30, 43), CPos.New(29, 43), CPos.New(28, 43), CPos.New(27, 43), CPos.New(26, 43), CPos.New(25, 43), CPos.New(24, 43), CPos.New(23, 43), CPos.New(22, 43), CPos.New(21, 43) }
@@ -44,97 +45,42 @@ Atk4 = { CPos.New(54, 47), CPos.New(53, 47), CPos.New(52, 47), CPos.New(51, 47),
CaptureStructures = function(actor)
for i = 1, #WhitelistedStructures do
structures = player.GetActorsByType(WhitelistedStructures[i])
if #structures > 0 then
if not actor.IsDead and not structures[1].IsDead then
actor.Capture(structures[1])
return
end
structures = Nod.GetActorsByType(WhitelistedStructures[i])
if #structures > 0 and not actor.IsDead and not structures[1].IsDead then
actor.Capture(structures[1])
return
end
end
end
CheckForSams = function()
local sams = player.GetActorsByType("sam")
local sams = Nod.GetActorsByType("sam")
return #sams >= 3
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
GetCargo = function(team)
cargo = { }
for type, count in pairs(team.units) do
for i = 1, count, 1 do
cargo[#cargo + 1] = type
end
end
return cargo
end
InsertNodUnits = function()
Media.PlaySpeechNotification(player, "Reinforce")
Reinforcements.Reinforce(player, NodUnitsBikes, { ReinforcementsSpawnLeft.Location, ReinforcementsBikesRally.Location }, 1)
Reinforcements.Reinforce(player, NodUnitsBuggys, { ReinforcementsSpawnRight.Location, ReinforcementsBuggyRally.Location }, 50)
Reinforcements.Reinforce(player, NodUnitsGunners, { ReinforcementsSpawnLeft.Location, ReinforcementsGunnersRally.Location }, 50)
Reinforcements.Reinforce(player, NodUnitsRockets, { ReinforcementsSpawnRight.Location, ReinforcementsRocketsRally.Location }, 50)
Media.PlaySpeechNotification(Nod, "Reinforce")
Reinforcements.Reinforce(Nod, NodUnitsBikes, { ReinforcementsSpawnLeft.Location, ReinforcementsBikesRally.Location }, 1)
Reinforcements.Reinforce(Nod, NodUnitsBuggys, { ReinforcementsSpawnRight.Location, ReinforcementsBuggyRally.Location }, 50)
Reinforcements.Reinforce(Nod, NodUnitsGunners, { ReinforcementsSpawnLeft.Location, ReinforcementsGunnersRally.Location }, 50)
Reinforcements.Reinforce(Nod, NodUnitsRockets, { ReinforcementsSpawnRight.Location, ReinforcementsRocketsRally.Location }, 50)
Trigger.AfterDelay(DateTime.Seconds(6), function()
Reinforcements.Reinforce(player, { 'mcv' }, { ReinforcementsSpawnCenter.Location, ReinforcementsMCVRally.Location })
Reinforcements.Reinforce(player, NodUnitsTanks, { ReinforcementsSpawnCenter.Location, ReinforcementsTanksRally.Location }, 50)
Reinforcements.Reinforce(Nod, { "mcv" }, { ReinforcementsSpawnCenter.Location, ReinforcementsMCVRally.Location })
Reinforcements.Reinforce(Nod, NodUnitsTanks, { ReinforcementsSpawnCenter.Location, ReinforcementsTanksRally.Location }, 50)
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)
if actor.Type == "e6" then
CaptureStructures(actor)
else
IdleHunt(actor)
end
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
Utils.Do(team.units, function(unitType)
local actors = Utils.Where(GDI.GetActorsByType(unitType), function(unit) return unit.IsIdle end)
MoveAndHunt(Utils.Take(1, actors), team.waypoints)
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)
@@ -154,17 +100,18 @@ SendWaves = function(counter, Waves)
end
SendReinforcementsWave = function(team)
Reinforcements.ReinforceWithTransport(enemy, "apc", GetCargo(team), { ReinforcementsGDISpawn.Location, waypoint12.Location}, nil, function(transport, passengers)
SetReinforcementsWaypoints(transport, team.waypoints)
Reinforcements.ReinforceWithTransport(GDI, "apc", GetCargo(team), { ReinforcementsGDISpawn.Location, waypoint12.Location}, nil, function(transport, passengers)
MoveAndHunt(transport, team.waypoints)
transport.UnloadPassengers()
Trigger.OnPassengerExited(transport, function(_, passenger)
Utils.Do(passengers, function(actor)
if actor.Type == "e6" then
if actor.Type == "e6" then
CaptureStructures(actor)
else
IdleHunt(actor)
end
end)
if not transport.HasPassengers then
IdleHunt(transport)
end
@@ -172,102 +119,69 @@ SendReinforcementsWave = function(team)
end)
end
SetReinforcementsWaypoints = function(actor, waypoints)
if not actor.IsDead then
Utils.Do(waypoints, function(waypoint)
actor.Move(waypoint.Location)
end)
IdleHunt(actor)
end
end
StartWaves = function()
SendWaves(1, AutoAttackWaves)
end
Trigger.OnEnteredFootprint(Atk1, function(a, id)
if not atk1Trigger and a.Owner == player then
if not atk1Trigger and a.Owner == Nod then
atk1Trigger = true
SendAttackWave(GDI5)
Trigger.RemoveFootprintTrigger(id)
end
end)
Trigger.OnEnteredFootprint(Atk2, function(a, id)
if not atk2Trigger and a.Owner == player then
if not atk2Trigger and a.Owner == Nod then
atk2Trigger = true
SendAttackWave(GDI4)
Trigger.RemoveFootprintTrigger(id)
end
end)
Trigger.OnEnteredFootprint(Atk3, function(a, id)
if not atk3Trigger and a.Owner == player then
if not atk3Trigger and a.Owner == Nod then
atk3Trigger = true
SendAttackWave(GDI6)
Trigger.RemoveFootprintTrigger(id)
end
end)
Trigger.OnEnteredFootprint(Atk4, function(a, id)
if not atk4Trigger and a.Owner == player then
if not atk4Trigger and a.Owner == Nod then
atk4Trigger = true
SendReinforcementsWave(GDI1)
Trigger.RemoveFootprintTrigger(id)
end
end)
WorldLoaded = function()
player = Player.GetPlayer("Nod")
enemy = Player.GetPlayer("GDI")
Nod = Player.GetPlayer("Nod")
GDI = Player.GetPlayer("GDI")
Camera.Position = waypoint26.CenterPosition
InsertNodUnits()
StartAI(GDICYard)
StartAI()
Trigger.AfterDelay(DateTime.Seconds(10), function() SendAttackWave(GDI2) end)
Trigger.AfterDelay(DateTime.Seconds(55), function() SendAttackWave(GDI2) end)
Trigger.AfterDelay(DateTime.Seconds(85), function() SendAttackWave(GDI3) 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)
Trigger.OnPlayerDiscovered(GDI, function() SendWaves(1, AutoAttackWaves) end)
Trigger.OnPlayerDiscovered(player, StartWaves)
InitObjectives(Nod)
Trigger.OnObjectiveAdded(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
end)
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("Eliminate all GDI forces in the area.")
NodObjective2 = player.AddSecondaryObjective("Build 3 SAMs to fend off the GDI bombers.")
GDIObjective = enemy.AddPrimaryObjective("Eliminate all Nod forces in the area.")
EliminateGDI = Nod.AddObjective("Eliminate all GDI forces in the area.")
BuildSAMs = Nod.AddObjective("Build 3 SAMs to fend off the GDI bombers.", "Secondary", false)
end
Tick = function()
if DateTime.GameTime > 2 and player.HasNoRequiredUnits() then
enemy.MarkCompletedObjective(GDIObjective)
if DateTime.GameTime > 2 and Nod.HasNoRequiredUnits() then
Nod.MarkFailedObjective(EliminateGDI)
end
if DateTime.GameTime > 2 and enemy.HasNoRequiredUnits() then
player.MarkCompletedObjective(NodObjective1)
if DateTime.GameTime > 2 and GDI.HasNoRequiredUnits() then
Nod.MarkCompletedObjective(EliminateGDI)
end
if not player.IsObjectiveCompleted(NodObjective2) and CheckForSams() then
player.MarkCompletedObjective(NodObjective2)
if not Nod.IsObjectiveCompleted(BuildSAMs) and CheckForSams() then
Nod.MarkCompletedObjective(BuildSAMs)
end
end