1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-28 03:29:34 +02:00

upgrade unit spawner work started

This commit is contained in:
Aaron Veden 2018-01-13 23:07:29 -08:00
parent 59b364398d
commit 0e9936284f
11 changed files with 174 additions and 162 deletions

View File

@ -1,7 +1,7 @@
-- imports -- imports
local biterUtils = require("prototypes/enemies/BiterUtils") local biterUtils = require("prototypes/enemies/BiterUtils")
local swarmUtils = require("Swarmutils") local swarmUtils = require("SwarmUtils")
-- imported functions -- imported functions

View File

@ -1,6 +1,10 @@
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 0.16.3 Version: 0.16.3
Date: 1. 13. 2018 Date: 1. 13. 2018
Features:
- Seeded unit, unit spawner, and worm generation for the swarm
Bugfixes:
- Fixed a cause where squads could get stuck on hard to pass terrain
Improvements: Improvements:
- Removed squad limit - Removed squad limit
Optimizations: Optimizations:

View File

@ -423,7 +423,7 @@ local function onEnemyBaseBuild(event)
local entity = event.entity local entity = event.entity
local surface = entity.surface local surface = entity.surface
if (surface.index == 1) then if (surface.index == 1) then
registerEnemyBaseStructure(map, entity, nil) event.entity = registerEnemyBaseStructure(map, entity, surface, natives)
end end
end end
@ -436,7 +436,7 @@ local function onSurfaceTileChange(event)
local position = positions[i] local position = positions[i]
local chunk = mapUtils.getChunkByPosition(map, position, true) local chunk = mapUtils.getChunkByPosition(map, position, true)
-- weird bug with table pointer equality using name instead pointer comparison -- weird bug with table pointer equality using name instead of pointer comparison
if not chunk.name then if not chunk.name then
map.chunkToPassScan[chunk] = true map.chunkToPassScan[chunk] = true
else else

View File

@ -9,7 +9,7 @@ require("prototypes/tile/fillableDirt")
if settings.startup["rampant-newEnemies"].value then if settings.startup["rampant-newEnemies"].value then
require("BuildSwarm") require("UnitClasses")
end end
-- require("prototypes/enemies/UnitSuicideBiters") -- require("prototypes/enemies/UnitSuicideBiters")

View File

@ -27,8 +27,9 @@ function baseProcessor.processBases(map, surface, natives, tick)
for index = baseIndex, endIndex do for index = baseIndex, endIndex do
local base = bases[index] local base = bases[index]
buildOrder(map, natives, base, surface, tick)
advanceTendrils(map, base, surface, tick, natives) -- buildOrder(map, natives, base, surface, tick)
-- advanceTendrils(map, base, surface, tick, natives)
end end
if (endIndex == #bases) then if (endIndex == #bases) then

View File

@ -2,13 +2,10 @@ local baseUtils = {}
-- imports -- imports
local stringUtils = require("StringUtils")
local mathUtils = require("MathUtils") local mathUtils = require("MathUtils")
local constants = require("Constants") local constants = require("Constants")
-- local tendrilUtils = require("TendrilUtils")
local nestUtils = require("NestUtils")
-- constants -- constants
local BASE_DISTANCE_THRESHOLD = constants.BASE_DISTANCE_THRESHOLD local BASE_DISTANCE_THRESHOLD = constants.BASE_DISTANCE_THRESHOLD
@ -22,7 +19,7 @@ local MAGIC_MAXIMUM_BASE_NUMBER = constants.MAGIC_MAXIMUM_BASE_NUMBER
local euclideanDistancePoints = mathUtils.euclideanDistancePoints local euclideanDistancePoints = mathUtils.euclideanDistancePoints
local buildHive = nestUtils.buildHive local isRampant = stringUtils.isRampant
local mFloor = math.floor local mFloor = math.floor
@ -47,6 +44,17 @@ function baseUtils.findNearbyBase(natives, position)
return foundBase return foundBase
end end
function baseUtils.upgradeEntity(map, entity, surface, natives)
if not isRampant(entity.name) then
local position = entity.position
entity.die()
entity = surface.create_entity({name = "rampant-suicide-nest-v" .. mRandom(5) .. "-t1",
position = position})
end
return entity
end
function baseUtils.createBase(map, natives, position, surface, tick) function baseUtils.createBase(map, natives, position, surface, tick)
local bases = natives.bases local bases = natives.bases
local distance = euclideanDistancePoints(position.x, position.y, 0, 0) local distance = euclideanDistancePoints(position.x, position.y, 0, 0)

View File

@ -2,6 +2,7 @@ local chunkUtils = {}
-- imports -- imports
local baseUtils = require("BaseUtils")
local constants = require("Constants") local constants = require("Constants")
local mapUtils = require("MapUtils") local mapUtils = require("MapUtils")
@ -39,6 +40,8 @@ local RESOURCE_GENERATOR_INCREMENT = constants.RESOURCE_GENERATOR_INCREMENT
local getChunkByUnalignedXY = mapUtils.getChunkByUnalignedXY local getChunkByUnalignedXY = mapUtils.getChunkByUnalignedXY
local upgradeEntity = baseUtils.upgradeEntity
local tRemove = table.remove local tRemove = table.remove
local mFloor = math.floor local mFloor = math.floor
@ -78,7 +81,7 @@ local function fullScan(chunk, can_place_entity, canPlaceQuery)
return passableNorthSouth, passableEastWest return passableNorthSouth, passableEastWest
end end
local function addEnemyStructureToChunk(map, chunk, entity, base) local function addEnemyStructureToChunk(map, chunk, entity)
local lookup local lookup
if (entity.type == "unit-spawner") then if (entity.type == "unit-spawner") then
lookup = map.chunkToNests lookup = map.chunkToNests
@ -323,31 +326,6 @@ function chunkUtils.analyzeChunk(chunk, natives, surface, map)
chunkUtils.setPlayerBaseGenerator(map, chunk, playerObjects) chunkUtils.setPlayerBaseGenerator(map, chunk, playerObjects)
end end
-- function chunkUtils.remakeChunk(map, chunk, surface, natives, tick, tempQuery)
-- tempQuery.force = "enemy"
-- local enemies = surface.find_entities_filtered(tempQuery)
-- local points = 0
-- for f=1, #enemies do
-- local enemy = enemies[f]
-- local entityType = enemies[f].type
-- if not ((enemy.name == "small-tendril-biter-rampant") or (enemy.name == "biter-spawner-hive-rampant")) then
-- if (entityType == "unit-spawner") then
-- points = points + 3
-- elseif (entityType == "turret") then
-- points = points + 2
-- elseif (entityType == "unit") then
-- points = points + 1
-- end
-- enemy.destroy()
-- end
-- end
-- -- local foundBase = findNearbyBase(natives, chunk) or createBase(map, natives, chunk, surface, tick)
-- -- if foundBase then
-- -- foundBase.upgradePoints = foundBase.upgradePoints + points
-- -- end
-- end
function chunkUtils.getNestCount(map, chunk) function chunkUtils.getNestCount(map, chunk)
return map.chunkToNests[chunk] or 0 return map.chunkToNests[chunk] or 0
end end
@ -510,24 +488,28 @@ function chunkUtils.entityForPassScan(map, entity)
end end
end end
function chunkUtils.registerEnemyBaseStructure(map, entity, base) function chunkUtils.registerEnemyBaseStructure(map, entity, surface, natives)
entity = upgradeEntity(map, entity, surface, natives)
local entityType = entity.type local entityType = entity.type
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then
local leftTop, rightTop, leftBottom, rightBottom = getEntityOverlapChunks(map, entity) local leftTop, rightTop, leftBottom, rightBottom = getEntityOverlapChunks(map, entity)
if (leftTop ~= SENTINEL_IMPASSABLE_CHUNK) then if (leftTop ~= SENTINEL_IMPASSABLE_CHUNK) then
addEnemyStructureToChunk(map, leftTop, entity, base) addEnemyStructureToChunk(map, leftTop, entity)
end end
if (rightTop ~= SENTINEL_IMPASSABLE_CHUNK) then if (rightTop ~= SENTINEL_IMPASSABLE_CHUNK) then
addEnemyStructureToChunk(map, rightTop, entity, base) addEnemyStructureToChunk(map, rightTop, entity)
end end
if (leftBottom ~= SENTINEL_IMPASSABLE_CHUNK) then if (leftBottom ~= SENTINEL_IMPASSABLE_CHUNK) then
addEnemyStructureToChunk(map, leftBottom, entity, base) addEnemyStructureToChunk(map, leftBottom, entity)
end end
if (rightBottom ~= SENTINEL_IMPASSABLE_CHUNK) then if (rightBottom ~= SENTINEL_IMPASSABLE_CHUNK) then
addEnemyStructureToChunk(map, rightBottom, entity, base) addEnemyStructureToChunk(map, rightBottom, entity)
end end
end end
return entity
end end
function chunkUtils.unregisterEnemyBaseStructure(map, entity) function chunkUtils.unregisterEnemyBaseStructure(map, entity)

View File

@ -31,130 +31,130 @@ local getChunkByPosition = mapUtils.getChunkByPosition
-- module code -- module code
function nestUtils.buildNest(map, base, surface, targetPosition, name) -- function nestUtils.buildNest(map, base, surface, targetPosition, name)
local position = surface.find_non_colliding_position(name, targetPosition, DOUBLE_CHUNK_SIZE, 2) -- local position = surface.find_non_colliding_position(name, targetPosition, DOUBLE_CHUNK_SIZE, 2)
local chunk = getChunkByPosition(map, position) -- local chunk = getChunkByPosition(map, position)
local nest = nil -- local nest = nil
if position and (chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (chunk[NEST_COUNT] < 3) then -- if position and (chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (chunk[NEST_COUNT] < 3) then
local biterSpawner = {name=name, position=position} -- local biterSpawner = {name=name, position=position}
nest = surface.create_entity(biterSpawner) -- nest = surface.create_entity(biterSpawner)
registerEnemyBaseStructure(map, nest, base) -- registerEnemyBaseStructure(map, nest, base)
end -- end
return nest -- return nest
end -- end
function nestUtils.buildHive(map, base, surface) -- function nestUtils.buildHive(map, base, surface)
local valid = false -- local valid = false
local hive = nestUtils.buildNest(map, base, surface, base, "biter-spawner-hive-rampant") -- local hive = nestUtils.buildNest(map, base, surface, base, "biter-spawner-hive-rampant")
if hive then -- if hive then
if (#base.hives == 0) then -- if (#base.hives == 0) then
base.x = hive.position.x -- base.x = hive.position.x
base.y = hive.position.y -- base.y = hive.position.y
end -- end
base.hives[#base.hives+1] = hive -- base.hives[#base.hives+1] = hive
valid = true -- valid = true
end -- end
return valid -- return valid
end -- end
function nestUtils.buildOutpost(map, natives, base, surface, tendril) -- function nestUtils.buildOutpost(map, natives, base, surface, tendril)
local foundHive = false -- local foundHive = false
for _,_ in pairs(base.hives) do -- for _,_ in pairs(base.hives) do
foundHive = true -- foundHive = true
break -- break
end -- end
if not foundHive or (base.upgradePoints < 10) then -- if not foundHive or (base.upgradePoints < 10) then
return -- return
end -- end
if not tendril.unit.valid then -- if not tendril.unit.valid then
return -- return
end -- end
local position = tendril.unit.position -- local position = tendril.unit.position
local generator = natives.randomGenerator -- local generator = natives.randomGenerator
generator.re_seed(mRandom(MAGIC_MAXIMUM_BASE_NUMBER)) -- generator.re_seed(mRandom(MAGIC_MAXIMUM_BASE_NUMBER))
for level=0,(base.level * 0.5) do -- for level=0,(base.level * 0.5) do
local slices = (level * 3) -- local slices = (level * 3)
slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator) -- slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator)
local slice = (2 * math.pi) / slices -- local slice = (2 * math.pi) / slices
local pos = 0 -- local pos = 0
local thing -- local thing
local cost -- local cost
local radiusAdjustment -- local radiusAdjustment
if (generator() < 0.3) then -- if (generator() < 0.3) then
thing = "small-worm-turret" -- thing = "small-worm-turret"
cost = AI_WORM_COST -- cost = AI_WORM_COST
radiusAdjustment = -4 -- radiusAdjustment = -4
else -- else
thing = "biter-spawner" -- thing = "biter-spawner"
cost = AI_NEST_COST -- cost = AI_NEST_COST
radiusAdjustment = 0 -- radiusAdjustment = 0
end -- end
for _ = 1, slices do -- for _ = 1, slices do
if (base.upgradePoints < 10) then -- if (base.upgradePoints < 10) then
return -- return
end -- end
local radius = 10 * level -- local radius = 10 * level
local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator) -- local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator)
local nestPosition = {x = position.x + (distortion * math.cos(pos)), -- local nestPosition = {x = position.x + (distortion * math.cos(pos)),
y = position.y + (distortion * math.sin(pos))} -- y = position.y + (distortion * math.sin(pos))}
local biterSpawner = {name=thing, position=nestPosition} -- local biterSpawner = {name=thing, position=nestPosition}
if surface.can_place_entity(biterSpawner) then -- if surface.can_place_entity(biterSpawner) then
registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base) -- registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base)
base.upgradePoints = base.upgradePoints - cost -- base.upgradePoints = base.upgradePoints - cost
end -- end
pos = pos + slice -- pos = pos + slice
end -- end
end -- end
end -- end
function nestUtils.buildOrder(map, natives, base, surface) -- function nestUtils.buildOrder(map, natives, base, surface)
local foundHive = false -- local foundHive = false
for _,_ in pairs(base.hives) do -- for _,_ in pairs(base.hives) do
foundHive = true -- foundHive = true
break -- break
end -- end
if not foundHive or (base.upgradePoints < 10) then -- if not foundHive or (base.upgradePoints < 10) then
return -- return
end -- end
local generator = natives.randomGenerator -- local generator = natives.randomGenerator
generator.re_seed(base.pattern) -- generator.re_seed(base.pattern)
for level=0,base.level do -- for level=0,base.level do
local slices = (level * 3) -- local slices = (level * 3)
slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator) -- slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator)
local slice = (2 * math.pi) / slices -- local slice = (2 * math.pi) / slices
local pos = 0 -- local pos = 0
local thing -- local thing
local cost -- local cost
local radiusAdjustment -- local radiusAdjustment
if (generator() < 0.3) then -- if (generator() < 0.3) then
thing = "small-worm-turret" -- thing = "small-worm-turret"
cost = AI_WORM_COST -- cost = AI_WORM_COST
radiusAdjustment = -4 -- radiusAdjustment = -4
else -- else
thing = "biter-spawner" -- thing = "biter-spawner"
cost = AI_NEST_COST -- cost = AI_NEST_COST
radiusAdjustment = 0 -- radiusAdjustment = 0
end -- end
for _ = 1, slices do -- for _ = 1, slices do
if (base.upgradePoints < 10) then -- if (base.upgradePoints < 10) then
return -- return
end -- end
local radius = 10 * level -- local radius = 10 * level
local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator) -- local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator)
local nestPosition = {x = base.x + (distortion * math.cos(pos)), -- local nestPosition = {x = base.x + (distortion * math.cos(pos)),
y = base.y + (distortion * math.sin(pos))} -- y = base.y + (distortion * math.sin(pos))}
local biterSpawner = {name=thing, position=nestPosition} -- local biterSpawner = {name=thing, position=nestPosition}
if surface.can_place_entity(biterSpawner) then -- if surface.can_place_entity(biterSpawner) then
registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base) -- registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base)
base.upgradePoints = base.upgradePoints - cost -- base.upgradePoints = base.upgradePoints - cost
end -- end
pos = pos + slice -- pos = pos + slice
end -- end
end -- end
end -- end
return nestUtils return nestUtils

15
libs/StringUtils.lua Executable file
View File

@ -0,0 +1,15 @@
local stringUtils = {}
function stringUtils.isRampant(str)
return (string.sub(str,1,7) == "rampant")
end
function stringUtils.starts(str, start)
return (string.sub(str,1,string.len(start)) == start)
end
function stringUtils.ends(str, tail)
return (tail == '') or (string.sub(str, -string.len(tail)) == tail)
end
return stringUtils

View File

@ -34,7 +34,8 @@
(string->path "changelog.txt") (string->path "changelog.txt")
(string->path "Upgrade.lua") (string->path "Upgrade.lua")
(string->path "settings.lua") (string->path "settings.lua")
(string->path "BuildSwarm.lua") (string->path "SwarmUtils.lua")
(string->path "UnitClasses.lua")
(string->path "README.md") (string->path "README.md")
(string->path "NOTICE") (string->path "NOTICE")
(string->path "libs") (string->path "libs")
@ -74,7 +75,8 @@
(copyFile "changelog.txt" modFolder) (copyFile "changelog.txt" modFolder)
(copyFile "Upgrade.lua" modFolder) (copyFile "Upgrade.lua" modFolder)
(copyFile "tests.lua" modFolder) (copyFile "tests.lua" modFolder)
(copyFile "BuildSwarm.lua" modFolder) (copyFile "SwarmUtils.lua" modFolder)
(copyFile "UnitClasses.lua" modFolder)
(copyDirectory "libs" modFolder) (copyDirectory "libs" modFolder)
(copyDirectory "locale" modFolder) (copyDirectory "locale" modFolder)
(copyDirectory "sounds" modFolder) (copyDirectory "sounds" modFolder)