Skip to content

Commit

Permalink
Add more missions
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Apr 14, 2017
1 parent a932df6 commit 42162f2
Show file tree
Hide file tree
Showing 20 changed files with 1,777 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mtrsd2k/maps/harkonnen-03a/map.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MapFormat: 11

RequiresMod: d2k
RequiresMod: mtrsd2k

Title: Harkonnen 03a

Expand Down Expand Up @@ -80,12 +80,6 @@ Actors:
Actor11: wall
Location: 34,52
Owner: Atreides
Actor12: wall
Location: 35,52
Owner: Atreides
Actor13: wall
Location: 40,52
Owner: Atreides
Actor14: wall
Location: 41,52
Owner: Atreides
Expand Down Expand Up @@ -176,5 +170,13 @@ Actors:
HarkonnenEntry: waypoint
Owner: Neutral
Location: 29,2
Actor42: machine_gun_tower
Owner: Atreides
Location: 40,52
TurretFacing: 92
Actor43: machine_gun_tower
Owner: Atreides
Location: 35,52
TurretFacing: 92

Rules: d2k|rules/campaign-rules.yaml, rules.yaml
159 changes: 159 additions & 0 deletions mtrsd2k/maps/harkonnen-03b/harkonnen03b-AI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
IdlingUnits = { }

AttackGroupSize =
{
easy = 6,
normal = 8,
hard = 10
}

AttackDelays =
{
easy = { DateTime.Seconds(4), DateTime.Seconds(9) },
normal = { DateTime.Seconds(2), DateTime.Seconds(7) },
hard = { DateTime.Seconds(1), DateTime.Seconds(5) }
}

AtreidesInfantryTypes = { "light_inf", "light_inf", "light_inf", "trooper", "trooper" }
AtreidesVehicleTypes = { "trike.mg", "trike.mg", "quad.rocket" }

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(atreides, AtreidesInitialReinforcements, AtreidesInitialPath)

Utils.Do(AtreidesBase, 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 ABarracks.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(AtreidesInfantryTypes) }
atreides.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 ALightFactory.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(AtreidesVehicleTypes) }
atreides.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)
end

ActivateAI = function()
Trigger.AfterDelay(0, InitAIUnits)

AConyard.Produce(HarkonnenUpgrades[1])
AConyard.Produce(HarkonnenUpgrades[2])

-- Finish the upgrades first before trying to build something
Trigger.AfterDelay(DateTime.Seconds(14), function()
ProduceInfantry()
ProduceVehicles()
end)
end
197 changes: 197 additions & 0 deletions mtrsd2k/maps/harkonnen-03b/harkonnen03b.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
AtreidesBase = { ABarracks, AWindTrap1, AWindTrap2, AWindTrap3, ALightFactory, AOutpost, AConyard, ARefinery, ASilo1, ASilo2, ASilo3, ASilo4 }
AtreidesBaseAreaTriggers =
{
{ CPos.New(10, 53), CPos.New(11, 53), CPos.New(12, 53), CPos.New(13, 53), CPos.New(14, 53), CPos.New(15, 53), CPos.New(16, 53), CPos.New(17, 53), CPos.New(17, 52), CPos.New(17, 51), CPos.New(17, 50), CPos.New(17, 49), CPos.New(17, 48), CPos.New(17, 47), CPos.New(17, 46), CPos.New(17, 45), CPos.New(17, 44), CPos.New(17, 43), CPos.New(17, 42), CPos.New(17, 41), CPos.New(17, 40), CPos.New(17, 39), CPos.New(17, 38), CPos.New(2, 35), CPos.New(3, 35), CPos.New(4, 35), CPos.New(5, 35), CPos.New(6, 35), CPos.New(7, 35), CPos.New(8, 35), CPos.New(9, 35), CPos.New(10, 35), CPos.New(11, 35), CPos.New(12, 35) },
{ CPos.New(49, 25), CPos.New(50, 25), CPos.New(51, 25), CPos.New(52, 25), CPos.New(53, 25), CPos.New(54, 25), CPos.New(54, 26), CPos.New(54, 27), CPos.New(54, 28), CPos.New(54, 29) },
{ CPos.New(19, 2), CPos.New(19, 3), CPos.New(19, 4), CPos.New(41, 2), CPos.New(41, 3), CPos.New(41, 4), CPos.New(41, 5), CPos.New(41, 6), CPos.New(41, 7), CPos.New(41, 8), CPos.New(41, 9), CPos.New(41, 10), CPos.New(41, 11) },
{ CPos.New(2, 16), CPos.New(3, 16), CPos.New(4, 16), CPos.New(5, 16), CPos.New(19, 2), CPos.New(19, 3), CPos.New(19, 4) }
}

AtreidesReinforcements =
{
easy =
{
{ "light_inf", "trike.mg", "trooper" },
{ "light_inf", "trike.mg", "quad.rocket" },
{ "light_inf", "light_inf", "trooper", "trike.mg", "trike.mg", "quad.rocket" }
},

normal =
{
{ "light_inf", "trike.mg", "trooper" },
{ "light_inf", "trike.mg", "trike.mg" },
{ "light_inf", "light_inf", "trooper", "trike.mg", "trike.mg", "quad.rocket" },
{ "light_inf", "light_inf", "trooper", "trooper" },
{ "light_inf", "light_inf", "light_inf", "light_inf" },
{ "light_inf", "trike.mg", "quad.rocket", "quad.rocket" }
},

hard =
{
{ "trike.mg", "trike.mg", "quad.rocket" },
{ "light_inf", "trike.mg", "trike.mg" },
{ "trooper", "trooper", "light_inf", "trike.mg" },
{ "light_inf", "light_inf", "light_inf", "trike.mg", "trike.mg" },
{ "light_inf", "light_inf", "trooper", "trooper" },
{ "trike.mg", "trike.mg", "quad.rocket", "quad.rocket", "quad.rocket", "trike.mg" },
{ "light_inf", "light_inf", "light_inf", "trike.mg", "trike.mg" },
{ "light_inf", "trike.mg", "light_inf", "trooper", "trooper", "quad.rocket" },
{ "trike.mg", "trike.mg", "quad.rocket", "quad.rocket", "quad.rocket", "trike.mg" }
}
}

AtreidesAttackDelay =
{
easy = DateTime.Minutes(5),
normal = DateTime.Minutes(2) + DateTime.Seconds(40),
hard = DateTime.Minutes(1) + DateTime.Seconds(20)
}

AtreidesAttackWaves =
{
easy = 3,
normal = 6,
hard = 9
}

AtreidesHunters =
{
{ "trooper", "trooper", "trooper" },
{ "trike.mg", "light_inf", "light_inf", "light_inf", "light_inf" },
{ "trooper", "trooper", "trooper", "trike.mg", "trike.mg" },
{ "light_inf", "light_inf", "light_inf", "light_inf", "light_inf", "trooper", "trooper", "trooper", "trooper", "trooper" }
}

AtreidesPaths =
{
{ AtreidesEntry4.Location, AtreidesRally4.Location },
{ AtreidesEntry7.Location, AtreidesRally7.Location },
{ AtreidesEntry8.Location, AtreidesRally8.Location }
}

AtreidesHunterPaths =
{
{ AtreidesEntry6.Location, AtreidesRally6.Location },
{ AtreidesEntry5.Location, AtreidesRally5.Location },
{ AtreidesEntry3.Location, AtreidesRally3.Location },
{ AtreidesEntry1.Location, AtreidesRally1.Location }
}

AtreidesInitialPath = { AtreidesEntry2.Location, AtreidesRally2.Location }
AtreidesInitialReinforcements = { "light_inf", "light_inf", "quad.rocket", "quad.rocket", "trike.mg", "trike.mg", "trooper", "trooper" }

HarkonnenReinforcements = { "trike.rocket", "trike.rocket" }
HarkonnenPath = { HarkonnenEntry.Location, HarkonnenRally.Location }

HarkonnenBaseBuildings = { "barracks", "light_factory" }
HarkonnenUpgrades = { "upgrade.barracks", "upgrade.light" }

wave = 0
SendAtreides = function()
Trigger.AfterDelay(AtreidesAttackDelay[Map.LobbyOption("difficulty")], function()
if player.IsObjectiveCompleted(KillAtreides) then
return
end

wave = wave + 1
if wave > AtreidesAttackWaves[Map.LobbyOption("difficulty")] then
return
end

local path = Utils.Random(AtreidesPaths)
local units = Reinforcements.ReinforceWithTransport(atreides, "carryall.reinforce", AtreidesReinforcements[Map.LobbyOption("difficulty")][wave], path, { path[1] })[2]
Utils.Do(units, IdleHunt)

SendAtreides()
end)
end

MessageCheck = function(index)
return #player.GetActorsByType(HarkonnenBaseBuildings[index]) > 0 and not player.HasPrerequisites({ HarkonnenUpgrades[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(atreides, "carryall.reinforce", unit, path, { path[1] })[2]
Utils.Do(units, IdleHunt)
check = true
end
end)
end

Tick = function()
if player.HasNoRequiredUnits() then
atreides.MarkCompletedObjective(KillHarkonnen)
end

if atreides.HasNoRequiredUnits() and not player.IsObjectiveCompleted(KillAtreides) then
Media.DisplayMessage("The Atreides have been annihilated!", "Mentat")
player.MarkCompletedObjective(KillAtreides)
end

if DateTime.GameTime % DateTime.Seconds(30) and HarvesterKilled then
local units = atreides.GetActorsByType("harvester")

if #units > 0 then
HarvesterKilled = false
ProtectHarvester(units[1])
end
end

if DateTime.GameTime % DateTime.Seconds(32) == 0 and (MessageCheck(1) or MessageCheck(2)) then
Media.DisplayMessage("Upgrade barracks and light factory to produce more advanced units.", "Mentat")
end
end

WorldLoaded = function()
atreides = Player.GetPlayer("Atreides")
player = Player.GetPlayer("Harkonnen")

InitObjectives()

Camera.Position = HConyard.CenterPosition

Trigger.OnAllKilled(AtreidesBase, function()
Utils.Do(atreides.GetGroundAttackers(), IdleHunt)
end)

SendAtreides()
ActivateAI()

Trigger.AfterDelay(DateTime.Minutes(2) + DateTime.Seconds(30), function()
Reinforcements.ReinforceWithTransport(player, "carryall.reinforce", HarkonnenReinforcements, HarkonnenPath, { HarkonnenPath[1] })
end)

SendHunters(AtreidesBaseAreaTriggers[1], AtreidesHunters[1], AtreidesHunterPaths[1], HuntersSent1)
SendHunters(AtreidesBaseAreaTriggers[2], AtreidesHunters[2], AtreidesHunterPaths[2], HuntersSent2)
SendHunters(AtreidesBaseAreaTriggers[3], AtreidesHunters[3], AtreidesHunterPaths[3], HuntersSent3)
SendHunters(AtreidesBaseAreaTriggers[4], AtreidesHunters[4], AtreidesHunterPaths[4], HuntersSent4)
end

InitObjectives = function()
Trigger.OnObjectiveAdded(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "New " .. string.lower(p.GetObjectiveType(id)) .. " objective")
end)

KillHarkonnen = atreides.AddPrimaryObjective("Kill all Harkonnen units.")
KillAtreides = player.AddPrimaryObjective("Eliminate all Atreides 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)
end
Binary file added mtrsd2k/maps/harkonnen-03b/map.bin
Binary file not shown.
Binary file added mtrsd2k/maps/harkonnen-03b/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 42162f2

Please sign in to comment.