Skip to content
Permalink
Browse files

Scavenger blueprints rework - prototype

  • Loading branch information
Damgam committed Jan 3, 2020
1 parent c6276ce commit bba2115be49f937191a3514950b615fea1ec802d
@@ -0,0 +1,71 @@

-- table.insert(ScavengerBlueprintsT0,FunctionName)
-- table.insert(ScavengerBlueprintsT1,FunctionName)
-- table.insert(ScavengerBlueprintsT2,FunctionName)
-- table.insert(ScavengerBlueprintsT3,FunctionName)

-- example blueprint:
-- local function a(posx, posy, posz, GaiaTeamID, radiusCheck)
-- local posradius = 120
-- if radiusCheck then
-- return posradius
-- else
-- Spring.CreateUnit("unitname", posx, posy, posz, math.random(0,3),GaiaTeamID)
-- Spring.CreateUnit("unitname", posx-100, posy, posz, math.random(0,3),GaiaTeamID)
-- Spring.CreateUnit("unitname", posx+100, posy, posz, math.random(0,3),GaiaTeamID)
-- Spring.CreateUnit("unitname", posx, posy, posz-100, math.random(0,3),GaiaTeamID)
-- Spring.CreateUnit("unitname", posx, posy, posz+100, math.random(0,3),GaiaTeamID)
-- end
-- end
-- table.insert(ScavengerBlueprintsT1,a)

local UDN = UnitDefNames

local function placeholderradar1(scav, posx, posy, posz, GaiaTeamID, radiusCheck)
local posradius = 150
if radiusCheck then
return posradius
else
Spring.GiveOrderToUnit(scav, -(UDN.eradar2.id), {posx, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.elightturret2.id), {posx-200, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.elightturret2.id), {posx+200, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.elightturret2.id), {posx, posy, posz-200, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.elightturret2.id), {posx, posy, posz+200, 0}, {"shift"})
end
end
table.insert(ScavengerConstructorBlueprintsT0,placeholderradar1)
table.insert(ScavengerConstructorBlueprintsT1,placeholderradar1)
table.insert(ScavengerConstructorBlueprintsT2,placeholderradar1)
table.insert(ScavengerConstructorBlueprintsT3,placeholderradar1)

local function placeholderradar2(scav, posx, posy, posz, GaiaTeamID, radiusCheck)
local posradius = 150
if radiusCheck then
return posradius
else
Spring.GiveOrderToUnit(scav, -(UDN.eradar2.id), {posx, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.eheavyturret2.id), {posx-200, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.eheavyturret2.id), {posx+200, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.eheavyturret2.id), {posx, posy, posz-200, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.eheavyturret2.id), {posx, posy, posz+200, 0}, {"shift"})
end
end
table.insert(ScavengerConstructorBlueprintsT2,placeholderradar2)
table.insert(ScavengerConstructorBlueprintsT3,placeholderradar2)

local function placeholderradar1(scav, posx, posy, posz, GaiaTeamID, radiusCheck)
local posradius = 150
if radiusCheck then
return posradius
else
Spring.GiveOrderToUnit(scav, -(UDN.emine.id), {posx, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.emine.id), {posx-100, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.emine.id), {posx+100, posy, posz, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.emine.id), {posx, posy, posz-100, 0}, {"shift"})
Spring.GiveOrderToUnit(scav, -(UDN.emine.id), {posx, posy, posz+100, 0}, {"shift"})
end
end
table.insert(ScavengerConstructorBlueprintsT0,placeholderradar1)
table.insert(ScavengerConstructorBlueprintsT1,placeholderradar1)
table.insert(ScavengerConstructorBlueprintsT2,placeholderradar1)
table.insert(ScavengerConstructorBlueprintsT3,placeholderradar1)
@@ -0,0 +1 @@
Blueprints for scavenger contstructor unit
@@ -1 +1,2 @@
--CURRENTLY UNUSED, USE CONSTRUCTOR FOLDER INSTEAD
You can add more files with blueprints into this folder. Script will automatically load all of them
@@ -21,13 +21,23 @@ ScavengerBlueprintsT0 = {}
ScavengerBlueprintsT1 = {}
ScavengerBlueprintsT2 = {}
ScavengerBlueprintsT3 = {}
ScavengerConstructorBlueprintsT0 = {}
ScavengerConstructorBlueprintsT1 = {}
ScavengerConstructorBlueprintsT2 = {}
ScavengerConstructorBlueprintsT3 = {}

ConfigsList = VFS.DirList('LuaRules/Configs/ScavengerBlueprints/','*.lua')
for i = 1,#ConfigsList do
VFS.Include(ConfigsList[i])
Spring.Echo("Direction: " ..ConfigsList[i])
end

ConfigsList2 = VFS.DirList('LuaRules/Configs/ScavengerBlueprints/Constructor/','*.lua')
for i = 1,#ConfigsList2 do
VFS.Include(ConfigsList2[i])
Spring.Echo("Direction: " ..ConfigsList2[i])
end

------------------------------------------------------------------------

local GaiaTeamID = Spring.GetGaiaTeamID()
@@ -44,7 +54,7 @@ end
local failcounter = 0
--local discoscavengers = tonumber(Spring.GetModOptions().discoscavengers) or 0

local BonusUnits = {"eorb", "ehbotengineer", "ebox", "escoutdrone", "eallterrshield", "zairscout",}
local BonusUnits = {"scavcommanderateran", "eorb", "ehbotengineer", "ebox", "escoutdrone", "eallterrshield", "zairscout",}

local T0Units = {
-- Z
@@ -202,15 +212,18 @@ local dz = {}
local olddx = {}
local olddy = {}
local olddz = {}
local isScavCommander = {}
local selfdestructcounter = 0
local posx = 0
local posy = 0
local posz = 0
local posradius = 0
local canSpawnHere = false
local canBuildHere = false
local canConstructHere = false
local blueprint = 0
local radiusCheck = false
local FailedToGiveBlueprint = 0



@@ -225,6 +238,16 @@ function gadget:Initialize()

end

-- function gadget:UnitCreated(unitID, unitDefID, unitTeam)
-- if unitTeam == GaiaTeamID then
-- if string.find(UnitDefs[unitDefID].name,"scavcommander") then
-- isScavCommander[unitID] = true
-- else
-- isScavCommander[unitID] = false
-- end
-- end
-- end

local function posCheck(posx, posy, posz, posradius)
-- if true then can spawn
local testpos1 = Spring.GetGroundHeight((posx + posradius), (posz + posradius) )
@@ -312,55 +335,55 @@ function gadget:GameFrame(n)
Spring.SetTeamResource(GaiaTeamID, "m", 100000)
Spring.SetTeamResource(GaiaTeamID, "e", 100000)
end
if n%90 == 0 and n > 3000 then
local gaiaUnitCount = Spring.GetTeamUnitCount(GaiaTeamID)
local spawnchance = math.random(0,20)
if spawnchance == 0 or canBuildHere == false then
posx = math.random(200,mapsizeX-200)
posz = math.random(200,mapsizeZ-200)
posy = Spring.GetGroundHeight(posx, posz)
--blueprint = ScavengerBlueprintsStart[math.random(1,#ScavengerBlueprintsStart)]
if n > 54000 then
local r = math.random(0,1)
if r == 0 then
blueprint = ScavengerBlueprintsT3[math.random(1,#ScavengerBlueprintsT3)]
else
blueprint = ScavengerBlueprintsT2[math.random(1,#ScavengerBlueprintsT2)]
end
elseif n > 36000 then
local r = math.random(0,2)
if r == 0 then
blueprint = ScavengerBlueprintsT2[math.random(1,#ScavengerBlueprintsT2)]
elseif r == 1 then
blueprint = ScavengerBlueprintsT1[math.random(1,#ScavengerBlueprintsT1)]
else
blueprint = ScavengerBlueprintsT0[math.random(1,#ScavengerBlueprintsT0)]
end
elseif n > 18000 then
local r = math.random(0,1)
if r == 0 then
blueprint = ScavengerBlueprintsT1[math.random(1,#ScavengerBlueprintsT1)]
else
blueprint = ScavengerBlueprintsT0[math.random(1,#ScavengerBlueprintsT0)]
end
else
blueprint = ScavengerBlueprintsT0[math.random(1,#ScavengerBlueprintsT0)]
end
posradius = blueprint(posx, posy, posz, GaiaTeamID, true)
canBuildHere = posLosCheck(posx, posy, posz, posradius)
if canBuildHere then
canBuildHere = posOccupied(posx, posy, posz, posradius)
end
if canBuildHere then
canBuildHere = posCheck(posx, posy, posz, posradius)
end
-- if n%90 == 0 and n > 3000 then
-- local gaiaUnitCount = Spring.GetTeamUnitCount(GaiaTeamID)
-- local spawnchance = math.random(0,20)
-- if spawnchance == 0 or canBuildHere == false then
-- posx = math.random(200,mapsizeX-200)
-- posz = math.random(200,mapsizeZ-200)
-- posy = Spring.GetGroundHeight(posx, posz)
-- --blueprint = ScavengerBlueprintsStart[math.random(1,#ScavengerBlueprintsStart)]
-- if n > 54000 then
-- local r = math.random(0,1)
-- if r == 0 then
-- blueprint = ScavengerBlueprintsT3[math.random(1,#ScavengerBlueprintsT3)]
-- else
-- blueprint = ScavengerBlueprintsT2[math.random(1,#ScavengerBlueprintsT2)]
-- end
-- elseif n > 36000 then
-- local r = math.random(0,2)
-- if r == 0 then
-- blueprint = ScavengerBlueprintsT2[math.random(1,#ScavengerBlueprintsT2)]
-- elseif r == 1 then
-- blueprint = ScavengerBlueprintsT1[math.random(1,#ScavengerBlueprintsT1)]
-- else
-- blueprint = ScavengerBlueprintsT0[math.random(1,#ScavengerBlueprintsT0)]
-- end
-- elseif n > 18000 then
-- local r = math.random(0,1)
-- if r == 0 then
-- blueprint = ScavengerBlueprintsT1[math.random(1,#ScavengerBlueprintsT1)]
-- else
-- blueprint = ScavengerBlueprintsT0[math.random(1,#ScavengerBlueprintsT0)]
-- end
-- else
-- blueprint = ScavengerBlueprintsT0[math.random(1,#ScavengerBlueprintsT0)]
-- end
-- posradius = blueprint(posx, posy, posz, GaiaTeamID, true)
-- canBuildHere = posLosCheck(posx, posy, posz, posradius)
-- if canBuildHere then
-- canBuildHere = posOccupied(posx, posy, posz, posradius)
-- end
-- if canBuildHere then
-- canBuildHere = posCheck(posx, posy, posz, posradius)
-- end

if canBuildHere then
-- let's do this shit
blueprint(posx, 5000, posz, GaiaTeamID, false)
end
end
end
-- if canBuildHere then
-- -- let's do this shit
-- blueprint(posx, 5000, posz, GaiaTeamID, false)
-- end
-- end
-- end

if n%30 == 0 and n > 5400 then
local gaiaUnitCount = Spring.GetTeamUnitCount(GaiaTeamID)
@@ -411,9 +434,9 @@ function gadget:GameFrame(n)
local scav = scavengerunits[i]
local scavDef = Spring.GetUnitDefID(scav)
local scavStructure = UnitDefs[scavDef].isBuilding
-- if UnitDefs[scavDef].name == "cormaw" or UnitDefs[scavDef].name == "armclaw" or UnitDefs[scavDef].name == "cornanotc" or UnitDefs[scavDef].name == "armnanotc" then
-- scavStructure = true
-- end
if string.find(UnitDefs[scavDef].name, "scavcommander") then
scavStructure = true
end
if not scavStructure and n%900 == 0 then
if dx[scav] then
olddx[scav] = dx[scav]
@@ -430,12 +453,64 @@ function gadget:GameFrame(n)
selfdestructcounter = selfdestructcounter + 1
end
end
if not scavStructure and Spring.GetCommandQueue(scav, 0) <= 1 then
local nearest = Spring.GetUnitNearestEnemy(scav, 200000, false)
local x,y,z = Spring.GetUnitPosition(nearest)
local x = x + math.random(-50,50)
local z = z + math.random(-50,50)
Spring.GiveOrderToUnit(scav, CMD.FIGHT,{x,y,z}, {})
if (not scavStructure and Spring.GetCommandQueue(scav, 0) <= 1) or (string.find(UnitDefs[scavDef].name, "scavcommander") and Spring.GetCommandQueue(scav, 0) <= 1) then

if string.find(UnitDefs[scavDef].name,"scavcommander") then
local x,y,z = Spring.GetUnitPosition(scav)
local posx = math.random(x-1000,x+1000)
local posz = math.random(z-1000,z+1000)
local posy = Spring.GetGroundHeight(posx, posz)
if n > 54000 then
local r = math.random(0,1)
if r == 0 then
blueprint = ScavengerConstructorBlueprintsT3[math.random(1,#ScavengerConstructorBlueprintsT3)]
else
blueprint = ScavengerConstructorBlueprintsT2[math.random(1,#ScavengerConstructorBlueprintsT2)]
end
elseif n > 36000 then
local r = math.random(0,2)
if r == 0 then
blueprint = ScavengerConstructorBlueprintsT2[math.random(1,#ScavengerConstructorBlueprintsT2)]
elseif r == 1 then
blueprint = ScavengerConstructorBlueprintsT1[math.random(1,#ScavengerConstructorBlueprintsT1)]
else
blueprint = ScavengerConstructorBlueprintsT0[math.random(1,#ScavengerConstructorBlueprintsT0)]
end
elseif n > 18000 then
local r = math.random(0,1)
if r == 0 then
blueprint = ScavengerConstructorBlueprintsT1[math.random(1,#ScavengerConstructorBlueprintsT1)]
else
blueprint = ScavengerConstructorBlueprintsT0[math.random(1,#ScavengerConstructorBlueprintsT0)]
end
else
blueprint = ScavengerConstructorBlueprintsT0[math.random(1,#ScavengerConstructorBlueprintsT0)]
end

posradius = blueprint(scav, posx, posy, posz, GaiaTeamID, true)
canConstructHere = posOccupied(posx, posy, posz, posradius)
if canConstructHere then
canConstructHere = posCheck(posx, posy, posz, posradius)
end
if canConstructHere then
-- let's do this shit
blueprint(scav, posx, posy, posz, GaiaTeamID, false)
local x = math.random(100,mapsizeX-100)
local z = math.random(100,mapsizeZ-100)
local y = Spring.GetGroundHeight(x,z)
Spring.GiveOrderToUnit(scav, CMD.MOVE,{x,y,z}, {"shift"})
local x = math.random(x-100,x+100)
local z = math.random(z-100,z+100)
local y = Spring.GetGroundHeight(x,z)
Spring.GiveOrderToUnit(scav, CMD.MOVE,{x,y,z}, {"shift"})
end
else
local nearest = Spring.GetUnitNearestEnemy(scav, 200000, false)
local x,y,z = Spring.GetUnitPosition(nearest)
local x = x + math.random(-50,50)
local z = z + math.random(-50,50)
Spring.GiveOrderToUnit(scav, CMD.FIGHT,{x,y,z}, {"shift"})
end
end
end
if selfdestructcounter and selfdestructcounter > 0 and devswitch == 1 then
@@ -455,5 +530,6 @@ function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
olddx[unitID] = nil
olddy[unitID] = nil
olddz[unitID] = nil
isScavCommander[unitID] = nil
end
end

0 comments on commit bba2115

Please sign in to comment.
You can’t perform that action at this time.