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 } }
GDIBase = { GDICYard, GDIPyle, GDIWeap, GDIHQ, GDIProc, GDINuke1, GDINuke2, GDINuke3, GDIBuilding1, GDIBuilding2, GDIBuilding3, GDIBuilding4, GDIBuilding5, GDIBuilding6, GDIBuilding7, GDIBuilding8 }
InfantryAttackGroup = { }
@@ -19,39 +20,33 @@ VehicleProductionCooldown = DateTime.Minutes(4)
VehicleProductionTypes = { "jeep", "jeep", "mtnk", "mtnk", "mtnk" }
StartingCash = 4000
BaseProc = { type = "proc", pos = CPos.New(22, 51), cost = 1500, exists = true }
BaseNuke1 = { type = "nuke", pos = CPos.New(16, 56), cost = 500, exists = true }
BaseNuke2 = { type = "nuke", pos = CPos.New(18, 57), cost = 500, exists = true }
BaseNuke3 = { type = "nuke", pos = CPos.New(27, 51), cost = 500, exists = true }
InfantryProduction = { type = "pyle", pos = CPos.New(18, 54), cost = 500, exists = true }
VehicleProduction = { type = "weap", pos = CPos.New(27, 55), cost = 2000, exists = true }
BaseProc = { type = "proc", pos = CPos.New(22, 51), cost = 1500 }
BaseNuke1 = { type = "nuke", pos = CPos.New(16, 56), cost = 500 }
BaseNuke2 = { type = "nuke", pos = CPos.New(18, 57), cost = 500 }
BaseNuke3 = { type = "nuke", pos = CPos.New(27, 51), cost = 500 }
InfantryProduction = { type = "pyle", pos = CPos.New(18, 54), cost = 500 }
VehicleProduction = { type = "weap", pos = CPos.New(27, 55), cost = 2000 }
BaseBuildings = { BaseProc, BaseNuke1, BaseNuke2, BaseNuke3, InfantryProduction, VehicleProduction }
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)
@@ -59,37 +54,19 @@ 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
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
@@ -100,10 +77,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))
@@ -113,22 +91,22 @@ 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))
@@ -138,7 +116,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
@@ -147,55 +125,35 @@ 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)
StartAI = function()
RepairNamedActors(GDI, 0.75)
GDI.Cash = StartingCash
Trigger.AfterDelay(DateTime.Minutes(2), function() ProduceInfantry(GDIPyle) end)
Trigger.AfterDelay(DateTime.Minutes(3), function() ProduceVehicle(GDIWeap) end)
end
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)
end
Trigger.OnAllKilledOrCaptured(GDIBase, function()
IdlingUnits(enemy)
Trigger.OnKilled(GDIProc, function()
BuildBuilding(BaseProc, GDICYard)
end)
Trigger.OnKilled(GDIProc, function(building)
BaseProc.exists = false
Trigger.OnKilled(GDINuke1, function()
BuildBuilding(BaseNuke1, GDICYard)
end)
Trigger.OnKilled(GDINuke1, function(building)
BaseNuke1.exists = false
Trigger.OnKilled(GDINuke2, function()
BuildBuilding(BaseNuke2, GDICYard)
end)
Trigger.OnKilled(GDINuke2, function(building)
BaseNuke2.exists = false
Trigger.OnKilled(GDINuke3, function()
BuildBuilding(BaseNuke3, GDICYard)
end)
Trigger.OnKilled(GDINuke3, function(building)
BaseNuke3.exists = false
Trigger.OnKilled(GDIPyle, function()
BuildBuilding(InfantryProduction, GDICYard)
end)
Trigger.OnKilled(GDIPyle, function(building)
InfantryProduction.exists = false
end)
Trigger.OnKilled(GDIWeap, function(building)
VehicleProduction.exists = false
Trigger.OnKilled(GDIWeap, function()
BuildBuilding(VehicleProduction, GDICYard)
end)