Created
March 5, 2017 09:11
-
-
Save MustaphaTR/e485bb258f7da2a2a3cc2eafb7516316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Base = | |
| { | |
| Atreides = { AConyard, ABarracks1, ABarracks2, AHeavyFactory, ALightFactory1, ALightFactory2, AOutpost, ARepairPad, AStarport, AResearch, ARefinery1, ARefinery2, ARefinery3, ARefinery4, APalace, AHighTech }, | |
| Harkonnen = { HConyard, HBarracks1, HBarracks2, HHeavyFactory, HLightFactory1, HLightFactory2, HOutpost, HRepairPad, HStarport, HResearch, HRefinery1, HRefinery2, HRefinery3, HRefinery4, HPalace, HHighTech }, | |
| Ordos = { OConyard, OBarracks1, OBarracks2, OHeavyFactory, OLightFactory1, OLightFactory2, OOutpost, ORepairPad, OStarport, OResearch, ORefinery1, ORefinery2, ORefinery3, ORefinery4, OPalace, OHighTech }, | |
| Smugglers = { SBarracks, SLightFactory, SOutpost, SPower1, SPower2, SPower3, SPower4, SSilo1, SSilo2, SSilo3, SGunt1, SGunt2, SGunt3 } | |
| } | |
| IdlingUnits = | |
| { | |
| Atreides = { }, | |
| Harkonnen = { }, | |
| Ordos = { }, | |
| Smugglers = { } | |
| } | |
| AttackGroupSize = | |
| { | |
| easy = 6, | |
| normal = 8, | |
| hard = 10 | |
| } | |
| AttackDelays = | |
| { | |
| easy = { DateTime.Seconds(4), DateTime.Seconds(7) }, | |
| normal = { DateTime.Seconds(2), DateTime.Seconds(5) }, | |
| hard = { DateTime.Seconds(1), DateTime.Seconds(3) } | |
| } | |
| AttackLocations1 = { | |
| Atreides = { HConyard.Location, OConyard.Location }, | |
| Harkonnen = { AConyard.Location, OConyard.Location }, | |
| Ordos = { AConyard.Location, HConyard.Location }, | |
| Smugglers = { AConyard.Location, HConyard.Location, OConyard.Location } | |
| } | |
| AttackLocations2 = { | |
| Atreides = { HConyard.Location, OConyard.Location, ChronoSphere.Location, SOutpost.Location, SBarracks.Location }, | |
| Harkonnen = { AConyard.Location, OConyard.Location, ChronoSphere.Location, SOutpost.Location, SBarracks.Location }, | |
| Ordos = { AConyard.Location, HConyard.Location, ChronoSphere.Location, SOutpost.Location, SBarracks.Location }, | |
| Smugglers = { AConyard.Location, HConyard.Location, OConyard.Location } | |
| } | |
| AtreidesBarrackses = { ABarracks1, ABarracks2 } | |
| HarkonnenBarrackses = { HBarracks1, HBarracks2 } | |
| OrdosBarrackses = { OBarracks1, OBarracks2 } | |
| SmugglerBarracks = { SBarracks } | |
| AtreidesLightFactories = { ALightFactory1, ALightFactory2 } | |
| HarkonnenLightFactories = { HLightFactory1, HLightFactory2 } | |
| OrdosLightFactories = { OLightFactory1, OLightFactory2 } | |
| SmugglerLightFactory = { SLightFactory } | |
| AtreidesHeavyFactory = { AHeavyFactory } | |
| HarkonnenHeavyFactory = { HHeavyFactory } | |
| OrdosHeavyFactory = { OHeavyFactory } | |
| AtreidesInfantryTypes = { "light_inf", "light_inf", "light_inf", "trooper", "trooper", "grenadier" } | |
| AtreidesVehicleTypes = { "trike", "trike", "quad" } | |
| AtreidesTankTypes = { "combat_tank_h, combat_tank_h, combat_tank_h, missile_tank, missile_tank, siege_tank, sonic_tank" } | |
| HarkonnenInfantryTypes = { "light_inf", "light_inf", "light_inf", "trooper", "trooper", "sardaukar" } | |
| HarkonnenVehicleTypes = { "trike", "trike", "quad" } | |
| HarkonnenTankTypes = { "combat_tank_h, combat_tank_h, combat_tank_h, missile_tank, missile_tank, siege_tank, devestator" } | |
| OrdosInfantryTypes = { "light_inf", "light_inf", "light_inf", "trooper", "trooper" } | |
| OrdosVehicleTypes = { "raider", "raider", "raider", "quad", "quad", "stealth_raider" } | |
| OrdosTankTypes = { "combat_tank_h, combat_tank_h, combat_tank_h, missile_tank, missile_tank, siege_tank, deviator" } | |
| SmugglerInfantryTypes = { "light_inf", "light_inf", "light_inf", "trooper", "trooper" } | |
| SmugglerVehicleTypes = { "raider", "raider", "quad" } | |
| IsAttacking = | |
| { | |
| Atreides = false, | |
| Harkonnen = false, | |
| Ordos = false, | |
| Smugglers = false | |
| } | |
| IsDefending = | |
| { | |
| Atreides = false, | |
| Harkonnen = false, | |
| Ordos = false, | |
| Smugglers = false | |
| } | |
| HoldProduction = | |
| { | |
| Atreides = false, | |
| Harkonnen = false, | |
| Ordos = false, | |
| Smugglers = false | |
| } | |
| HarvesterKilled = | |
| { | |
| Atreides = false, | |
| Harkonnen = false, | |
| Ordos = false, | |
| Smugglers = false | |
| } | |
| IdleHunt = function(unit) if not unit.IsDead then Trigger.OnIdle(unit, unit.Hunt) end end | |
| SetupAttackGroup = function(house) | |
| local units = { } | |
| for i = 0, AttackGroupSize[Difficulty], 1 do | |
| if #IdlingUnits[house.Name] == 0 then | |
| return units | |
| end | |
| local number = Utils.RandomInteger(1, #IdlingUnits[house.Name]) | |
| if IdlingUnits[house.Name][number] and not IdlingUnits[house.Name][number].IsDead then | |
| units[i] = IdlingUnits[house.Name][number] | |
| table.remove(IdlingUnits[house.Name], number) | |
| end | |
| end | |
| return units | |
| end | |
| SendAttack = function(house) | |
| if IsAttacking[house.Name] then | |
| return | |
| end | |
| IsAttacking[house.Name] = true | |
| HoldProduction[house.Name] = true | |
| local units = SetupAttackGroup(house) | |
| Utils.Do(units, function(unit) | |
| unit.AttackMove(Utils.Random(AttackLocations1[house.Name])) | |
| IdleHunt(unit) | |
| end) | |
| Trigger.OnAllRemovedFromWorld(units, function() | |
| IsAttacking[house.Name] = false | |
| HoldProduction[house.Name] = false | |
| end) | |
| end | |
| ProtectHarvester = function(unit, house) | |
| DefendActor(unit, house) | |
| Trigger.OnKilled(unit, function() HarvesterKilled[house.Name] = true end) | |
| end | |
| DefendActor = function(unit, house) | |
| Trigger.OnDamaged(unit, function(self, attacker) | |
| if IsDefending[house.Name] then | |
| return | |
| end | |
| IsDefending[house.Name] = true | |
| if attacker and attacker.Type == "spicebloom" then | |
| return | |
| end | |
| local Guards = SetupAttackGroup(house) | |
| if #Guards <= 0 then | |
| IsDefending[house.Name] = 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() IsDefending[house.Name] = false end) | |
| end) | |
| end | |
| InitAIUnits = function(house) | |
| Utils.Do(Base[house.Name], function(actor) | |
| DefendActor(actor, house) | |
| Trigger.OnDamaged(actor, function(building) | |
| if building.Health < building.MaxHealth * 3/4 and building.Owner.Name == house.Name then | |
| building.StartBuildingRepairs() | |
| end | |
| end) | |
| end) | |
| end | |
| Produce = function(house, units, factories, check) | |
| if check == true then | |
| return | |
| end | |
| if HoldProduction[house.Name] then | |
| Trigger.AfterDelay(DateTime.Seconds(30), function() Produce(house, units, factories, check) end) | |
| return | |
| end | |
| Trigger.OnAllRemovedFromWorld(factories, function() | |
| check = true | |
| end) | |
| local delay = Utils.RandomInteger(AttackDelays[Difficulty][1], AttackDelays[Difficulty][2] + 1) | |
| local toBuild = { Utils.Random(units) } | |
| house.Build(toBuild, function(unit) | |
| local unitCount = 1 | |
| if IdlingUnits[house.Name] then | |
| unitCount = 1 + #IdlingUnits[house.Name] | |
| end | |
| IdlingUnits[house.Name][unitCount] = unit[1] | |
| Trigger.AfterDelay(delay, function() Produce(house, units, factories, check) end) | |
| if unitCount >= (AttackGroupSize[Difficulty] * 2.5) then | |
| SendAttack(house) | |
| end | |
| end) | |
| end | |
| ActivateAI = function() | |
| InitAIUnits(atreides) | |
| InitAIUnits(harkonnen) | |
| InitAIUnits(ordos) | |
| InitAIUnits(smuggler) | |
| Trigger.AfterDelay(DateTime.Seconds(14), function() | |
| Produce(atreides, AtreidesInfantryTypes, AtreidesBarrackses, Check1) | |
| Produce(atreides, AtreidesVehicleTypes, AtreidesLightFactories, Check2) | |
| Produce(atreides, AtreidesTankType, AtreidesHeavyFactory, Check3) | |
| Produce(harkonnen, HarkonnenInfantryTypes, HarkonnenBarrackses, Check4) | |
| Produce(harkonnen, HarkonnenVehicleTypes, HarkonnenLightFactories, Check5) | |
| Produce(harkonnen, HarkonnenTankType, HarkonnenHeavyFactory, Check6) | |
| Produce(ordos, OrdosInfantryTypes, OrdosBarrackses, Check7) | |
| Produce(ordos, OrdosVehicleTypes, OrdosLightFactories, Check8) | |
| Produce(ordos, OrdosTankType, OrdosHeavyFactory, Check9) | |
| end) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment