Add a global script for campaign missions in d2k
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
IdlingUnits = { }
|
||||
--[[
|
||||
Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
|
||||
This file is part of OpenRA, which is free software. It is made
|
||||
available to you under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version. For more
|
||||
information, see COPYING.
|
||||
]]
|
||||
|
||||
AttackGroupSize =
|
||||
{
|
||||
@@ -17,143 +24,27 @@ AttackDelays =
|
||||
HarkonnenInfantryTypes = { "light_inf", "light_inf", "light_inf", "trooper", "trooper" }
|
||||
HarkonnenVehicleTypes = { "trike", "trike", "quad" }
|
||||
|
||||
HarvesterKilled = true
|
||||
|
||||
IdleHunt = function(unit) if not unit.IsDead then Trigger.OnIdle(unit, unit.Hunt) end end
|
||||
|
||||
SetupAttackGroup = function()
|
||||
local units = { }
|
||||
|
||||
for i = 0, AttackGroupSize[Map.LobbyOption("difficulty")], 1 do
|
||||
if #IdlingUnits == 0 then
|
||||
return units
|
||||
end
|
||||
|
||||
local number = Utils.RandomInteger(1, #IdlingUnits + 1)
|
||||
|
||||
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 IsAttacking then
|
||||
return
|
||||
end
|
||||
IsAttacking = true
|
||||
HoldProduction = true
|
||||
|
||||
local units = SetupAttackGroup()
|
||||
Utils.Do(units, function(unit)
|
||||
IdleHunt(unit)
|
||||
end)
|
||||
|
||||
Trigger.OnAllRemovedFromWorld(units, function()
|
||||
IsAttacking = false
|
||||
HoldProduction = false
|
||||
end)
|
||||
end
|
||||
|
||||
ProtectHarvester = function(unit)
|
||||
DefendActor(unit)
|
||||
Trigger.OnKilled(unit, function() HarvesterKilled = true end)
|
||||
end
|
||||
|
||||
DefendActor = function(unit)
|
||||
Trigger.OnDamaged(unit, function(self, attacker)
|
||||
if AttackOnGoing then
|
||||
return
|
||||
end
|
||||
AttackOnGoing = true
|
||||
|
||||
local Guards = SetupAttackGroup()
|
||||
|
||||
if #Guards <= 0 then
|
||||
AttackOnGoing = false
|
||||
return
|
||||
end
|
||||
|
||||
Utils.Do(Guards, function(unit)
|
||||
if not self.IsDead then
|
||||
unit.AttackMove(self.Location)
|
||||
end
|
||||
IdleHunt(unit)
|
||||
end)
|
||||
|
||||
Trigger.OnAllRemovedFromWorld(Guards, function() AttackOnGoing = false end)
|
||||
end)
|
||||
end
|
||||
|
||||
InitAIUnits = function()
|
||||
IdlingUnits = Reinforcements.Reinforce(harkonnen, HarkonnenInitialReinforcements, HarkonnenInitialPath)
|
||||
IdlingUnits[harkonnen] = Reinforcements.Reinforce(harkonnen, HarkonnenInitialReinforcements, HarkonnenInitialPath)
|
||||
|
||||
Utils.Do(HarkonnenBase, function(actor)
|
||||
DefendActor(actor)
|
||||
Trigger.OnDamaged(actor, function(building)
|
||||
if building.Health < building.MaxHealth * 3/4 then
|
||||
building.StartBuildingRepairs()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
ProduceInfantry = function()
|
||||
if HBarracks.IsDead then
|
||||
return
|
||||
end
|
||||
|
||||
if HoldProduction then
|
||||
Trigger.AfterDelay(DateTime.Minutes(1), ProduceInfantry)
|
||||
return
|
||||
end
|
||||
|
||||
local delay = Utils.RandomInteger(AttackDelays[Map.LobbyOption("difficulty")][1], AttackDelays[Map.LobbyOption("difficulty")][2] + 1)
|
||||
local toBuild = { Utils.Random(HarkonnenInfantryTypes) }
|
||||
harkonnen.Build(toBuild, function(unit)
|
||||
IdlingUnits[#IdlingUnits + 1] = unit[1]
|
||||
Trigger.AfterDelay(delay, ProduceInfantry)
|
||||
|
||||
if #IdlingUnits >= (AttackGroupSize[Map.LobbyOption("difficulty")] * 2.5) then
|
||||
SendAttack()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
ProduceVehicles = function()
|
||||
if HLightFactory.IsDead then
|
||||
return
|
||||
end
|
||||
|
||||
if HoldProduction then
|
||||
Trigger.AfterDelay(DateTime.Minutes(1), ProduceVehicles)
|
||||
return
|
||||
end
|
||||
|
||||
local delay = Utils.RandomInteger(AttackDelays[Map.LobbyOption("difficulty")][1], AttackDelays[Map.LobbyOption("difficulty")][2] + 1)
|
||||
local toBuild = { Utils.Random(HarkonnenVehicleTypes) }
|
||||
harkonnen.Build(toBuild, function(unit)
|
||||
IdlingUnits[#IdlingUnits + 1] = unit[1]
|
||||
Trigger.AfterDelay(delay, ProduceVehicles)
|
||||
|
||||
if #IdlingUnits >= (AttackGroupSize[Map.LobbyOption("difficulty")] * 2.5) then
|
||||
SendAttack()
|
||||
end
|
||||
end)
|
||||
DefendAndRepairBase(harkonnen, HarkonnenBase, 0.75, AttackGroupSize[Difficulty])
|
||||
end
|
||||
|
||||
ActivateAI = function()
|
||||
HarvesterKilled[harkonnen] = true
|
||||
Trigger.AfterDelay(0, InitAIUnits)
|
||||
|
||||
HConyard.Produce(OrdosUpgrades[1])
|
||||
HConyard.Produce(OrdosUpgrades[2])
|
||||
|
||||
local delay = function() return Utils.RandomInteger(AttackDelays[Difficulty][1], AttackDelays[Difficulty][2] + 1) end
|
||||
local infantryToBuild = function() return { Utils.Random(HarkonnenInfantryTypes) } end
|
||||
local vehilcesToBuild = function() return { Utils.Random(HarkonnenVehicleTypes) } end
|
||||
local attackThresholdSize = AttackGroupSize[Difficulty] * 2.5
|
||||
|
||||
-- Finish the upgrades first before trying to build something
|
||||
Trigger.AfterDelay(DateTime.Seconds(14), function()
|
||||
ProduceInfantry()
|
||||
ProduceVehicles()
|
||||
ProduceUnits(harkonnen, HBarracks, delay, infantryToBuild, AttackGroupSize[Difficulty], attackThresholdSize)
|
||||
ProduceUnits(harkonnen, HLightFactory, delay, vehilcesToBuild, AttackGroupSize[Difficulty], attackThresholdSize)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
--[[
|
||||
Copyright 2007-2017 The OpenRA Developers (see AUTHORS)
|
||||
This file is part of OpenRA, which is free software. It is made
|
||||
available to you under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version. For more
|
||||
information, see COPYING.
|
||||
]]
|
||||
|
||||
HarkonnenBase = { HBarracks, HWindTrap1, HWindTrap2, HLightFactory, HOutpost, HConyard, HRefinery, HSilo1, HSilo2, HSilo3, HSilo4 }
|
||||
HarkonnenBaseAreaTrigger = { CPos.New(2, 58), CPos.New(3, 58), CPos.New(4, 58), CPos.New(5, 58), CPos.New(6, 58), CPos.New(7, 58), CPos.New(8, 58), CPos.New(9, 58), CPos.New(10, 58), CPos.New(11, 58), CPos.New(12, 58), CPos.New(13, 58), CPos.New(14, 58), CPos.New(15, 58), CPos.New(16, 58), CPos.New(16, 59), CPos.New(16, 60) }
|
||||
|
||||
@@ -67,40 +76,10 @@ OrdosPath = { OrdosEntry.Location, OrdosRally.Location }
|
||||
OrdosBaseBuildings = { "barracks", "light_factory" }
|
||||
OrdosUpgrades = { "upgrade.barracks", "upgrade.light" }
|
||||
|
||||
wave = 0
|
||||
SendHarkonnen = function()
|
||||
Trigger.AfterDelay(HarkonnenAttackDelay[Map.LobbyOption("difficulty")], function()
|
||||
if player.IsObjectiveCompleted(KillHarkonnen) then
|
||||
return
|
||||
end
|
||||
|
||||
wave = wave + 1
|
||||
if wave > HarkonnenAttackWaves[Map.LobbyOption("difficulty")] then
|
||||
return
|
||||
end
|
||||
|
||||
local path = Utils.Random(HarkonnenPaths)
|
||||
local units = Reinforcements.ReinforceWithTransport(harkonnen, "carryall.reinforce", HarkonnenReinforcements[Map.LobbyOption("difficulty")][wave], path, { path[1] })[2]
|
||||
Utils.Do(units, IdleHunt)
|
||||
|
||||
SendHarkonnen()
|
||||
end)
|
||||
end
|
||||
|
||||
MessageCheck = function(index)
|
||||
return #player.GetActorsByType(OrdosBaseBuildings[index]) > 0 and not player.HasPrerequisites({ OrdosUpgrades[index] })
|
||||
end
|
||||
|
||||
SendHunters = function(areaTrigger, unit, path, check)
|
||||
Trigger.OnEnteredFootprint(areaTrigger, function(a, id)
|
||||
if not check and a.Owner == player then
|
||||
local units = Reinforcements.ReinforceWithTransport(harkonnen, "carryall.reinforce", unit, path, { path[1] })[2]
|
||||
Utils.Do(units, IdleHunt)
|
||||
check = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Tick = function()
|
||||
if player.HasNoRequiredUnits() then
|
||||
harkonnen.MarkCompletedObjective(KillOrdos)
|
||||
@@ -111,12 +90,12 @@ Tick = function()
|
||||
player.MarkCompletedObjective(KillHarkonnen)
|
||||
end
|
||||
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled then
|
||||
if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled[harkonnen] then
|
||||
local units = harkonnen.GetActorsByType("harvester")
|
||||
|
||||
if #units > 0 then
|
||||
HarvesterKilled = false
|
||||
ProtectHarvester(units[1])
|
||||
HarvesterKilled[harkonnen] = false
|
||||
ProtectHarvester(units[1], harkonnen, AttackGroupSize[Difficulty])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,7 +108,9 @@ WorldLoaded = function()
|
||||
harkonnen = Player.GetPlayer("Harkonnen")
|
||||
player = Player.GetPlayer("Ordos")
|
||||
|
||||
InitObjectives()
|
||||
InitObjectives(player)
|
||||
KillOrdos = harkonnen.AddPrimaryObjective("Kill all Ordos units.")
|
||||
KillHarkonnen = player.AddPrimaryObjective("Eliminate all Harkonnen units and reinforcements\nin the area.")
|
||||
|
||||
Camera.Position = OConyard.CenterPosition
|
||||
|
||||
@@ -137,39 +118,14 @@ WorldLoaded = function()
|
||||
Utils.Do(harkonnen.GetGroundAttackers(), IdleHunt)
|
||||
end)
|
||||
|
||||
SendHarkonnen()
|
||||
local path = function() return Utils.Random(HarkonnenPaths) end
|
||||
local waveCondition = function() return player.IsObjectiveCompleted(KillHarkonnen) end
|
||||
SendCarryallReinforcements(harkonnen, 0, HarkonnenAttackWaves[Difficulty], HarkonnenAttackDelay[Difficulty], path, HarkonnenReinforcements[Difficulty], waveCondition)
|
||||
ActivateAI()
|
||||
|
||||
Trigger.AfterDelay(DateTime.Minutes(2) + DateTime.Seconds(30), function()
|
||||
Reinforcements.ReinforceWithTransport(player, "carryall.reinforce", OrdosReinforcements, OrdosPath, { OrdosPath[1] })
|
||||
end)
|
||||
|
||||
SendHunters(HarkonnenBaseAreaTrigger, HarkonnenHunters, HarkonnenHunterPath, HuntersSent)
|
||||
end
|
||||
|
||||
InitObjectives = function()
|
||||
Trigger.OnObjectiveAdded(player, function(p, id)
|
||||
Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
|
||||
end)
|
||||
|
||||
KillOrdos = harkonnen.AddPrimaryObjective("Kill all Ordos units.")
|
||||
KillHarkonnen = player.AddPrimaryObjective("Eliminate all Harkonnen units and reinforcements\nin the area.")
|
||||
|
||||
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.OnPlayerLost(player, function()
|
||||
Trigger.AfterDelay(DateTime.Seconds(1), function()
|
||||
Media.PlaySpeechNotification(player, "Lose")
|
||||
end)
|
||||
end)
|
||||
Trigger.OnPlayerWon(player, function()
|
||||
Trigger.AfterDelay(DateTime.Seconds(1), function()
|
||||
Media.PlaySpeechNotification(player, "Win")
|
||||
end)
|
||||
end)
|
||||
TriggerCarryallReinforcements(player, harkonnen, HarkonnenBaseAreaTrigger, HarkonnenHunters, HarkonnenHunterPath)
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ Player:
|
||||
|
||||
World:
|
||||
LuaScript:
|
||||
Scripts: ordos03a.lua, ordos03a-AI.lua
|
||||
Scripts: campaign-global.lua, ordos03a.lua, ordos03a-AI.lua
|
||||
MissionData:
|
||||
Briefing: The Harkonnen hinder the production of Spice. A Harkonnen attack will disrupt efficient production. Inefficiency cannot be tolerated. The Harkonnen must be eliminated.\n\nNew weapons are available - the Quads. Newer weapons are more powerful. Powerful weapons ensure victory.
|
||||
BriefingVideo: O_BR03_E.VQA
|
||||
|
||||
Reference in New Issue
Block a user