Convert Lua array-like structures to use named entries

This commit is contained in:
atlimit8
2015-10-18 15:14:11 -05:00
parent c87c2270ca
commit f79ac636f2
18 changed files with 265 additions and 267 deletions

View File

@@ -11,13 +11,12 @@ IdlingUnits = function()
end)
end
BaseBuildings =
{
{ "powr", CVec.New(-4, -2), 300, true },
{ "tent", CVec.New(-8, 1), 400, true },
{ "proc", CVec.New(-5, 1), 1400, true },
{ "weap", CVec.New(-12, -1), 2000, true }
}
BasePower = { type = "powr", pos = CVec.New(-4, -2), cost = 300, exists = true }
BaseBarracks = { type = "tent", pos = CVec.New(-8, 1), cost = 400, exists = true }
BaseProc = { type = "proc", pos = CVec.New(-5, 1), cost = 1400, exists = true }
BaseWeaponsFactory = { type = "weap", pos = CVec.New(-12, -1), cost = 2000, exists = true }
BaseBuildings = { BasePower, BaseBarracks, BaseProc, BaseWeaponsFactory }
BuildBase = function()
if CYard.IsDead or CYard.Owner ~= Greece then
@@ -27,7 +26,7 @@ BuildBase = function()
end
for i,v in ipairs(BaseBuildings) do
if not v[4] then
if not v.exists then
BuildBuilding(v)
return
end
@@ -37,12 +36,12 @@ BuildBase = function()
end
BuildBuilding = function(building)
Trigger.AfterDelay(Actor.BuildTime(building[1]), function()
local actor = Actor.Create(building[1], true, { Owner = Greece, Location = GreeceCYard.Location + building[2] })
Greece.Cash = Greece.Cash - building[3]
Trigger.AfterDelay(Actor.BuildTime(building.type), function()
local actor = Actor.Create(building.type, true, { Owner = Greece, Location = GreeceCYard.Location + building.pos })
Greece.Cash = Greece.Cash - building.cost
building[4] = true
Trigger.OnKilled(actor, function() building[4] = true end)
building.exists = true
Trigger.OnKilled(actor, function() building.exists = false end)
Trigger.OnDamaged(actor, function(building)
if building.Owner == Greece and building.Health < building.MaxHealth * 3/4 then
building.StartBuildingRepairs()
@@ -54,7 +53,7 @@ BuildBuilding = function(building)
end
ProduceInfantry = function()
if not BaseBuildings[2][4] then
if not BaseBarracks.exists then
return
elseif Harvester.IsDead and Greece.Resources <= 299 then
return
@@ -77,7 +76,7 @@ ProduceInfantry = function()
end
ProduceArmor = function()
if not BaseBuildings[4][4] then
if not BaseWeaponsFactory.exists then
return
elseif Harvester.IsDead and Greece.Resources <= 599 then
return

View File

@@ -22,19 +22,19 @@ RunInitialActivities = function()
end)
Trigger.OnKilled(Powr, function(building)
BaseBuildings[1][4] = false
BasePower.exists = false
end)
Trigger.OnKilled(Barr, function(building)
BaseBuildings[2][4] = false
BaseBarracks.exists = false
end)
Trigger.OnKilled(Proc, function(building)
BaseBuildings[3][4] = false
BaseProc.exists = false
end)
Trigger.OnKilled(Weap, function(building)
BaseBuildings[4][4] = false
BaseWeaponsFactory.exists = false
end)
Trigger.OnEnteredFootprint(VillageCamArea, function(actor, id)