Ported allies05a to lua

This commit is contained in:
abcdefg30
2015-01-30 22:26:30 +01:00
parent 5040baac9b
commit aab54218e5
6 changed files with 2348 additions and 0 deletions

View File

@@ -0,0 +1,240 @@
IdlingUnits = { }
AttackGroupSize = 6
Barracks = { Barracks2, Barracks3 }
Rallypoints = { VehicleRallypoint1, VehicleRallypoint2, VehicleRallypoint3, VehicleRallypoint4, VehicleRallypoint5 }
Airfields = { Airfield1, Airfield2 }
Yaks = { }
SovietInfantryTypes = { "e1", "e1", "e2", "e4" }
SovietVehicleTypes = { "3tnk", "3tnk", "3tnk", "v2rl", "v2rl", "apc" }
SovietAircraftType = { "yak" }
HoldProduction = true
BuildVehicles = true
TrainInfantry = true
IdleHunt = function(unit) if not unit.IsDead then Trigger.OnIdle(unit, unit.Hunt) end end
SetupAttackGroup = function()
local units = { }
for i = 0, AttackGroupSize, 1 do
local number = Utils.RandomInteger(1, #IdlingUnits)
if IdlingUnits[number] and not IdlingUnits[number].IsDead then
units[i] = IdlingUnits[number]
table.remove(IdlingUnits, number)
end
end
return units
end
SendAttack = function()
if not Attacking then
return
end
Attacking = false
HoldProduction = false
local units = SetupAttackGroup()
Utils.Do(units, function(unit)
IdleHunt(unit)
end)
Trigger.AfterDelay(DateTime.Minutes(1), function() Attacking = true end)
Trigger.AfterDelay(DateTime.Minutes(2), function() HoldProduction = true end)
end
ProtectHarvester = function(unit)
Trigger.OnDamaged(unit, function(self, attacker)
-- TODO: Send the Harvester to the service depo
if AttackOnGoing then
return
end
AttackOnGoing = true
local Guards = SetupAttackGroup()
Utils.Do(Guards, function(unit)
if attacker.Location then
unit.AttackMove(attacker.Location)
end
IdleHunt(unit)
end)
Trigger.OnAllRemovedFromWorld(Guards, function() AttackOnGoing = false end)
end)
Trigger.OnKilled(unit, function() HarvesterKilled = true end)
end
InitAIUnits = function()
IdlingUnits = Map.ActorsInBox(MainBaseTopLeft.CenterPosition, Map.BottomRight, function(self) return self.Owner == ussr and self.HasProperty("Hunt") end)
local buildings = Map.ActorsInBox(MainBaseTopLeft.CenterPosition, Map.BottomRight, function(self) return self.Owner == ussr and self.HasProperty("StartBuildingRepairs") end)
Utils.Do(buildings, function(actor)
Trigger.OnDamaged(actor, function(building)
if building.Owner == ussr and building.Health < building.MaxHealth * 3/4 then
building.StartBuildingRepairs()
end
end)
end)
end
InitAIEconomy = function()
ussr.Cash = 6000
Harvester.FindResources()
ProtectHarvester(Harvester)
end
InitProductionBuildings = function()
if not Warfactory2.IsDead then
Warfactory2.IsPrimaryBuilding = true
end
Trigger.OnKilled(Warfactory2, function() BuildVehicles = false end)
if not Barracks2.IsDead then
Barracks2.IsPrimaryBuilding = true
Trigger.OnKilled(Barracks2, function()
if not Barracks3.IsDead then
Barracks3.IsPrimaryBuilding = true
else
TrainInfantry = false
end
end)
end
if not Barracks3.IsDead then
Trigger.OnKilled(Barracks3, function() if Barracks2.IsDead then TrainInfantry = false end end)
end
if Map.Difficulty == "Normal" then
if not Airfield1.IsDead then
Trigger.OnKilled(Airfield1, function()
if Airfield2.IsDead then
AirAttacks = false
else
Airfield2.IsPrimaryBuilding = true
Trigger.OnKilled(Airfield2, function() AirAttacks = false end)
end
end)
Airfield1.IsPrimaryBuilding = true
AirAttacks = true
elseif not Airfield2.IsDead then
Trigger.OnKilled(Airfield2, function() AirAttacks = false end)
Airfield2.IsPrimaryBuilding = true
AirAttacks = true
end
end
end
ProduceInfantry = function()
if not TrainInfantry then
return
end
if HoldProduction then
Trigger.AfterDelay(DateTime.Minutes(1), ProduceInfantry)
return
end
local delay = Utils.RandomInteger(DateTime.Seconds(3), DateTime.Seconds(9))
local toBuild = { Utils.Random(SovietInfantryTypes) }
ussr.Build(toBuild, function(unit)
IdlingUnits[#IdlingUnits + 1] = unit[1]
Trigger.AfterDelay(delay, ProduceInfantry)
if #IdlingUnits >= (AttackGroupSize * 2.5) then
SendAttack()
end
end)
end
ProduceVehicles = function()
if not BuildVehicles then
return
end
if HoldProduction then
Trigger.AfterDelay(DateTime.Minutes(1), ProduceVehicles)
return
end
local delay = Utils.RandomInteger(DateTime.Seconds(5), DateTime.Seconds(9))
if HarvesterKilled then
HarvesterKilled = false
ussr.Build({ "harv" }, function(harv)
harv[1].FindResources()
ProtectHarvester(harv[1])
Trigger.AfterDelay(delay, ProduceVehicles)
end)
return
end
Warfactory2.RallyPoint = Utils.Random(Rallypoints).Location
local toBuild = { Utils.Random(SovietVehicleTypes) }
ussr.Build(toBuild, function(unit)
IdlingUnits[#IdlingUnits + 1] = unit[1]
Trigger.AfterDelay(delay, ProduceVehicles)
if #IdlingUnits >= (AttackGroupSize * 2.5) then
SendAttack()
end
end)
end
ProduceAircraft = function()
if not AirAttacks then
return
end
ussr.Build(SovietAircraftType, function(units)
Yaks[#Yaks + 1] = units[1]
if #Yaks == 2 then
Trigger.OnKilled(units[1], ProduceAircraft)
else
Trigger.AfterDelay(DateTime.Minutes(1), ProduceAircraft)
end
local target = nil
Trigger.OnIdle(units[1], function()
if not target or target.IsDead or (not target.IsInWorld) then
local enemies = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(self) return self.Owner == greece and self.HasProperty("Health") end)
if #enemies > 0 then
target = Utils.Random(enemies)
units[1].Attack(target)
end
else
units[1].Attack(target)
end
end)
end)
end
ActivateAI = function()
InitAIUnits()
InitAIEconomy()
InitProductionBuildings()
Trigger.AfterDelay(DateTime.Minutes(5), function()
ProduceInfantry()
ProduceVehicles()
if AirAttacks then
Trigger.AfterDelay(DateTime.Minutes(3), ProduceAircraft)
end
end)
end

View File

@@ -0,0 +1,276 @@
if Map.Difficulty == "Easy" then
TanyaType = "e7"
ReinforceCash = 5000
HoldAITime = DateTime.Minutes(3)
else
TanyaType = "e7.noautotarget"
ChangeStance = true
ReinforceCash = 2500
HoldAITime = DateTime.Minutes(2)
end
SpyType = { "spy" }
SpyEntryPath = { SpyEntry.Location, SpyLoadout.Location }
InsertionTransport = "lst"
TrukPath = { TrukWaypoint1, TrukWaypoint2, TrukWaypoint3, TrukWaypoint4, TrukWaypoint5, TrukWaypoint6 }
ExtractionHeliType = "tran"
ExtractionPath = { ExtractionEntry.Location, ExtractionLZ.Location }
GreeceReinforcements =
{
{ { "2tnk", "2tnk", "2tnk", "arty", "arty" }, { SpyEntry.Location, SpyLoadout.Location } },
{ { "e3", "e3", "e3", "e6", "e6" }, { SpyEntry.Location, GreeceLoadout1.Location } },
{ { "jeep", "jeep", "e1", "e1", "2tnk" }, { SpyEntry.Location, GreeceLoadout2.Location } }
}
DogPatrol = { Dog1, Dog2 }
PatrolA = { PatrolA1, PatrolA2, PatrolA3, PatrolA4, PatrolA5 }
PatrolB = { PatrolB1, PatrolB2, PatrolB3 }
DogPatrolPath = { DogPatrolRally1.Location, DogPatrolRally2.Location, DogPatrolRally3.Location }
PatrolAPath = { PatrolRally.Location, PatrolARally1.Location, PatrolARally2.Location, PatrolARally3.Location }
PatrolBPath = { PatrolBRally1.Location, PatrolBRally2.Location, PatrolBRally3.Location, PatrolRally.Location }
TanyaVoices = { "tuffguy", "bombit", "laugh", "gotit", "lefty", "keepem" }
SamSites = { Sam1, Sam2, Sam3, Sam4 }
GroupPatrol = function(units, waypoints, delay)
local i = 1
local stop = false
Utils.Do(units, function(unit)
Trigger.OnIdle(unit, function()
if stop then
return
end
if unit.Location == waypoints[i] then
local bool = Utils.All(units, function(actor) return actor.IsIdle end)
if bool then
stop = true
i = i + 1
if i > #waypoints then
i = 1
end
Trigger.AfterDelay(delay, function() stop = false end)
end
else
unit.AttackMove(waypoints[i])
end
end)
end)
end
Tick = function()
if FollowTruk then
TrukCamera.Teleport(Truk.Location)
end
if ussr.HasNoRequiredUnits() then
greece.MarkCompletedObjective(KillAll)
end
if GreeceReinforcementsArrived and greece.HasNoRequiredUnits() then
ussr.MarkCompletedObjective(ussrObj)
end
end
SendReinforcements = function()
GreeceReinforcementsArrived = true
Camera.Position = ReinforceCamera.CenterPosition
greece.Cash = greece.Cash + ReinforceCash
Utils.Do(GreeceReinforcements, function(reinforceTable)
Reinforcements.ReinforceWithTransport(greece, InsertionTransport, reinforceTable[1], reinforceTable[2], { SpyEntry.Location })
end)
ActivateAI()
end
ExtractTanya = function()
if ExtractionHeli.IsDead or not ExtractionHeli.HasPassengers then
return
end
ExtractionHeli.Move(CPos.New(ExtractionPath[1].X, ExtractionHeli.Location.Y))
ExtractionHeli.Destroy()
greece.MarkCompletedObjective(mainObj)
SendReinforcements()
PrisonCamera.Destroy()
end
WarfactoryInfiltrated = function()
FollowTruk = true
TrukCamera = Actor.Create("camera.truk", true, { Owner = greece, Location = Truk.Location })
Truk.Wait(DateTime.Seconds(1))
Utils.Do(TrukPath, function(waypoint)
Truk.Move(waypoint.Location)
end)
Trigger.AfterDelay(DateTime.Seconds(2), function()
SpyCameraA.Destroy()
SpyCameraB.Destroy()
end)
end
MissInfiltrated = function()
CloakProvider.Destroy()
for i = 0, 5, 1 do
local sound = Utils.Random(TanyaVoices)
Trigger.AfterDelay(DateTime.Seconds(i), function()
Media.PlaySoundNotification(greece, sound)
end)
end
TanyasColt = Actor.Create("Colt", true, { Owner = greece, Location = Prison.Location + CVec.New(1, 6) })
Trigger.AfterDelay(DateTime.Seconds(6), FreeTanya)
end
FreeTanya = function()
TanyasColt.Destroy()
Tanya = Actor.Create(TanyaType, true, { Owner = greece, Location = Prison.Location + CVec.New(1, 1) })
Prison.Kill()
Tanya.Scatter()
if ChangeStance then
Tanya.Stance = "HoldFire"
Trigger.AfterDelay(DateTime.Seconds(1), function()
Media.DisplayMessage("According to the rules of engagement I need your explicit orders to fire, Commander!", "Tanya")
end)
end
Trigger.OnKilled(Tanya, function() ussr.MarkCompletedObjective(ussrObj) end)
KillSams = greece.AddPrimaryObjective("Destroy all four SAM Sites that block\nthe extraction helicopter.")
end
SendSpy = function()
Camera.Position = SpyEntry.CenterPosition
Spy = Reinforcements.ReinforceWithTransport(greece, InsertionTransport, SpyType, SpyEntryPath, { SpyEntryPath[1] })[2][1]
Trigger.OnKilled(Spy, function() ussr.MarkCompletedObjective(ussrObj) end)
SpyCameraA = Actor.Create("camera", true, { Owner = greece, Location = SpyCamera1.Location })
SpyCameraB = Actor.Create("camera", true, { Owner = greece, Location = SpyCamera2.Location })
end
ActivatePatrols = function()
GroupPatrol(DogPatrol, DogPatrolPath, DateTime.Seconds(2))
Trigger.AfterDelay(DateTime.Seconds(3), function()
GroupPatrol(PatrolA, PatrolAPath, DateTime.Seconds(7))
GroupPatrol(PatrolB, PatrolBPath, DateTime.Seconds(6))
end)
local units = Map.ActorsInBox(Map.TopLeft, Map.BottomRight, function(self) return self.Owner == soviets and self.HasProperty("AutoTarget") end)
Utils.Do(units, function(unit)
unit.Stance = "Defend"
end)
end
InitTriggers = function()
Trigger.OnInfiltrated(Warfactory, function()
Trigger.ClearAll(Spy)
greece.MarkCompletedObjective(infWarfactory)
WarfactoryInfiltrated()
end)
Trigger.OnInfiltrated(Prison, function()
Trigger.ClearAll(Spy)
Trigger.AfterDelay(DateTime.Seconds(2), MissInfiltrated)
end)
Trigger.OnEnteredFootprint({ TrukWaypoint5.Location }, function(a, id)
if a == Truk then
Trigger.RemoveFootprintTrigger(id)
CloakProvider = Actor.Create("CloakUpgrade", true, { Owner = greece, Location = Prison.Location })
Spy = Actor.Create("spy", true, { Owner = greece, Location = TrukWaypoint5.Location })
Spy.Move(SpyWaypoint.Location)
Spy.Move(Prison.Location, 3)
FollowTruk = false
TrukCamera.Destroy()
PrisonCamera = Actor.Create("camera", true, { Owner = greece, Location = TrukWaypoint5.Location })
Trigger.OnKilled(Spy, function() ussr.MarkCompletedObjective(ussrObj) end)
end
end)
Trigger.OnEnteredFootprint({ TrukWaypoint6.Location }, function(a, id)
if a == Truk then
Trigger.RemoveFootprintTrigger(id)
Truk.Stop()
Truk.Kill()
ExplosiveBarrel.Kill()
end
end)
Trigger.OnKilled(Mammoth, function()
Trigger.AfterDelay(HoldAITime - DateTime.Seconds(45), function() HoldProduction = false end)
Trigger.AfterDelay(HoldAITime, function() Attacking = true end)
end)
Trigger.OnKilled(FlameBarrel, function()
if not FlameTower.IsDead then
FlameTower.Kill()
end
end)
Trigger.OnKilled(SamBarrel, Sam1.Kill)
Trigger.OnAllKilled(SamSites, function()
greece.MarkCompletedObjective(KillSams)
local flare = Actor.Create("flare", true, { Owner = greece, Location = ExtractionPath[2] + CVec.New(0, -1) })
Trigger.AfterDelay(DateTime.Seconds(7), flare.Destroy)
Media.PlaySpeechNotification(greece, "SignalFlare")
ExtractionHeli = Reinforcements.ReinforceWithTransport(greece, ExtractionHeliType, nil, ExtractionPath)[1]
Trigger.OnKilled(ExtractionHeli, function() ussr.MarkCompletedObjective(ussrObj) end)
Trigger.OnRemovedFromWorld(Tanya, ExtractTanya)
end)
end
InitObjectives = function()
Trigger.OnObjectiveAdded(greece, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
end)
ussrObj = ussr.AddPrimaryObjective("Deny the allies.")
mainObj = greece.AddPrimaryObjective("Rescue Tanya.")
KillAll = greece.AddPrimaryObjective("Eliminate all soviet units in this area.")
infWarfactory = greece.AddPrimaryObjective("Infiltrate the soviet warfactory")
Trigger.OnObjectiveCompleted(greece, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed")
end)
Trigger.OnObjectiveFailed(greece, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed")
end)
Trigger.OnPlayerLost(greece, function()
Media.PlaySpeechNotification(player, "Lose")
end)
Trigger.OnPlayerWon(greece, function()
Media.PlaySpeechNotification(player, "Win")
end)
end
WorldLoaded = function()
greece = Player.GetPlayer("Greece")
ussr = Player.GetPlayer("USSR")
InitObjectives()
InitTriggers()
SendSpy()
Trigger.AfterDelay(DateTime.Seconds(3), ActivatePatrols)
end

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,7 @@ Allied Campaign:
./mods/ra/maps/allies-02
./mods/ra/maps/allies-03a
./mods/ra/maps/allies-03b
./mods/ra/maps/allies-05a
Soviet Campaign:
./mods/ra/maps/soviet-01