mirror of
https://github.com/veden/Rampant.git
synced 2025-01-14 02:23:01 +02:00
upgrade unit spawner work started
This commit is contained in:
parent
59b364398d
commit
0e9936284f
@ -1,7 +1,7 @@
|
||||
-- imports
|
||||
|
||||
local biterUtils = require("prototypes/enemies/BiterUtils")
|
||||
local swarmUtils = require("Swarmutils")
|
||||
local swarmUtils = require("SwarmUtils")
|
||||
|
||||
-- imported functions
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.16.3
|
||||
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:
|
||||
- Removed squad limit
|
||||
Optimizations:
|
||||
|
@ -423,7 +423,7 @@ local function onEnemyBaseBuild(event)
|
||||
local entity = event.entity
|
||||
local surface = entity.surface
|
||||
if (surface.index == 1) then
|
||||
registerEnemyBaseStructure(map, entity, nil)
|
||||
event.entity = registerEnemyBaseStructure(map, entity, surface, natives)
|
||||
end
|
||||
end
|
||||
|
||||
@ -436,7 +436,7 @@ local function onSurfaceTileChange(event)
|
||||
local position = positions[i]
|
||||
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
|
||||
map.chunkToPassScan[chunk] = true
|
||||
else
|
||||
|
2
data.lua
2
data.lua
@ -9,7 +9,7 @@ require("prototypes/tile/fillableDirt")
|
||||
|
||||
|
||||
if settings.startup["rampant-newEnemies"].value then
|
||||
require("BuildSwarm")
|
||||
require("UnitClasses")
|
||||
end
|
||||
|
||||
-- require("prototypes/enemies/UnitSuicideBiters")
|
||||
|
@ -27,8 +27,9 @@ function baseProcessor.processBases(map, surface, natives, tick)
|
||||
for index = baseIndex, endIndex do
|
||||
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
|
||||
|
||||
if (endIndex == #bases) then
|
||||
|
@ -2,13 +2,10 @@ local baseUtils = {}
|
||||
|
||||
-- imports
|
||||
|
||||
local stringUtils = require("StringUtils")
|
||||
local mathUtils = require("MathUtils")
|
||||
local constants = require("Constants")
|
||||
|
||||
-- local tendrilUtils = require("TendrilUtils")
|
||||
|
||||
local nestUtils = require("NestUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
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 buildHive = nestUtils.buildHive
|
||||
local isRampant = stringUtils.isRampant
|
||||
|
||||
local mFloor = math.floor
|
||||
|
||||
@ -47,6 +44,17 @@ function baseUtils.findNearbyBase(natives, position)
|
||||
return foundBase
|
||||
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)
|
||||
local bases = natives.bases
|
||||
local distance = euclideanDistancePoints(position.x, position.y, 0, 0)
|
||||
|
@ -2,6 +2,7 @@ local chunkUtils = {}
|
||||
|
||||
-- imports
|
||||
|
||||
local baseUtils = require("BaseUtils")
|
||||
local constants = require("Constants")
|
||||
local mapUtils = require("MapUtils")
|
||||
|
||||
@ -39,6 +40,8 @@ local RESOURCE_GENERATOR_INCREMENT = constants.RESOURCE_GENERATOR_INCREMENT
|
||||
|
||||
local getChunkByUnalignedXY = mapUtils.getChunkByUnalignedXY
|
||||
|
||||
local upgradeEntity = baseUtils.upgradeEntity
|
||||
|
||||
local tRemove = table.remove
|
||||
|
||||
local mFloor = math.floor
|
||||
@ -78,7 +81,7 @@ local function fullScan(chunk, can_place_entity, canPlaceQuery)
|
||||
return passableNorthSouth, passableEastWest
|
||||
end
|
||||
|
||||
local function addEnemyStructureToChunk(map, chunk, entity, base)
|
||||
local function addEnemyStructureToChunk(map, chunk, entity)
|
||||
local lookup
|
||||
if (entity.type == "unit-spawner") then
|
||||
lookup = map.chunkToNests
|
||||
@ -323,31 +326,6 @@ function chunkUtils.analyzeChunk(chunk, natives, surface, map)
|
||||
chunkUtils.setPlayerBaseGenerator(map, chunk, playerObjects)
|
||||
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)
|
||||
return map.chunkToNests[chunk] or 0
|
||||
end
|
||||
@ -510,24 +488,28 @@ function chunkUtils.entityForPassScan(map, entity)
|
||||
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
|
||||
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then
|
||||
local leftTop, rightTop, leftBottom, rightBottom = getEntityOverlapChunks(map, entity)
|
||||
|
||||
if (leftTop ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
addEnemyStructureToChunk(map, leftTop, entity, base)
|
||||
addEnemyStructureToChunk(map, leftTop, entity)
|
||||
end
|
||||
if (rightTop ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
addEnemyStructureToChunk(map, rightTop, entity, base)
|
||||
addEnemyStructureToChunk(map, rightTop, entity)
|
||||
end
|
||||
if (leftBottom ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
addEnemyStructureToChunk(map, leftBottom, entity, base)
|
||||
addEnemyStructureToChunk(map, leftBottom, entity)
|
||||
end
|
||||
if (rightBottom ~= SENTINEL_IMPASSABLE_CHUNK) then
|
||||
addEnemyStructureToChunk(map, rightBottom, entity, base)
|
||||
addEnemyStructureToChunk(map, rightBottom, entity)
|
||||
end
|
||||
end
|
||||
|
||||
return entity
|
||||
end
|
||||
|
||||
function chunkUtils.unregisterEnemyBaseStructure(map, entity)
|
||||
|
@ -31,130 +31,130 @@ local getChunkByPosition = mapUtils.getChunkByPosition
|
||||
|
||||
-- module code
|
||||
|
||||
function nestUtils.buildNest(map, base, surface, targetPosition, name)
|
||||
local position = surface.find_non_colliding_position(name, targetPosition, DOUBLE_CHUNK_SIZE, 2)
|
||||
local chunk = getChunkByPosition(map, position)
|
||||
local nest = nil
|
||||
if position and (chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (chunk[NEST_COUNT] < 3) then
|
||||
local biterSpawner = {name=name, position=position}
|
||||
nest = surface.create_entity(biterSpawner)
|
||||
registerEnemyBaseStructure(map, nest, base)
|
||||
end
|
||||
return nest
|
||||
end
|
||||
-- function nestUtils.buildNest(map, base, surface, targetPosition, name)
|
||||
-- local position = surface.find_non_colliding_position(name, targetPosition, DOUBLE_CHUNK_SIZE, 2)
|
||||
-- local chunk = getChunkByPosition(map, position)
|
||||
-- local nest = nil
|
||||
-- if position and (chunk ~= SENTINEL_IMPASSABLE_CHUNK) and (chunk[NEST_COUNT] < 3) then
|
||||
-- local biterSpawner = {name=name, position=position}
|
||||
-- nest = surface.create_entity(biterSpawner)
|
||||
-- registerEnemyBaseStructure(map, nest, base)
|
||||
-- end
|
||||
-- return nest
|
||||
-- end
|
||||
|
||||
function nestUtils.buildHive(map, base, surface)
|
||||
local valid = false
|
||||
local hive = nestUtils.buildNest(map, base, surface, base, "biter-spawner-hive-rampant")
|
||||
if hive then
|
||||
if (#base.hives == 0) then
|
||||
base.x = hive.position.x
|
||||
base.y = hive.position.y
|
||||
end
|
||||
base.hives[#base.hives+1] = hive
|
||||
valid = true
|
||||
end
|
||||
return valid
|
||||
end
|
||||
-- function nestUtils.buildHive(map, base, surface)
|
||||
-- local valid = false
|
||||
-- local hive = nestUtils.buildNest(map, base, surface, base, "biter-spawner-hive-rampant")
|
||||
-- if hive then
|
||||
-- if (#base.hives == 0) then
|
||||
-- base.x = hive.position.x
|
||||
-- base.y = hive.position.y
|
||||
-- end
|
||||
-- base.hives[#base.hives+1] = hive
|
||||
-- valid = true
|
||||
-- end
|
||||
-- return valid
|
||||
-- end
|
||||
|
||||
function nestUtils.buildOutpost(map, natives, base, surface, tendril)
|
||||
local foundHive = false
|
||||
for _,_ in pairs(base.hives) do
|
||||
foundHive = true
|
||||
break
|
||||
end
|
||||
if not foundHive or (base.upgradePoints < 10) then
|
||||
return
|
||||
end
|
||||
-- function nestUtils.buildOutpost(map, natives, base, surface, tendril)
|
||||
-- local foundHive = false
|
||||
-- for _,_ in pairs(base.hives) do
|
||||
-- foundHive = true
|
||||
-- break
|
||||
-- end
|
||||
-- if not foundHive or (base.upgradePoints < 10) then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
if not tendril.unit.valid then
|
||||
return
|
||||
end
|
||||
local position = tendril.unit.position
|
||||
local generator = natives.randomGenerator
|
||||
generator.re_seed(mRandom(MAGIC_MAXIMUM_BASE_NUMBER))
|
||||
-- if not tendril.unit.valid then
|
||||
-- return
|
||||
-- end
|
||||
-- local position = tendril.unit.position
|
||||
-- local generator = natives.randomGenerator
|
||||
-- generator.re_seed(mRandom(MAGIC_MAXIMUM_BASE_NUMBER))
|
||||
|
||||
for level=0,(base.level * 0.5) do
|
||||
local slices = (level * 3)
|
||||
slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator)
|
||||
local slice = (2 * math.pi) / slices
|
||||
local pos = 0
|
||||
local thing
|
||||
local cost
|
||||
local radiusAdjustment
|
||||
if (generator() < 0.3) then
|
||||
thing = "small-worm-turret"
|
||||
cost = AI_WORM_COST
|
||||
radiusAdjustment = -4
|
||||
else
|
||||
thing = "biter-spawner"
|
||||
cost = AI_NEST_COST
|
||||
radiusAdjustment = 0
|
||||
end
|
||||
for _ = 1, slices do
|
||||
if (base.upgradePoints < 10) then
|
||||
return
|
||||
end
|
||||
local radius = 10 * level
|
||||
local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator)
|
||||
local nestPosition = {x = position.x + (distortion * math.cos(pos)),
|
||||
y = position.y + (distortion * math.sin(pos))}
|
||||
local biterSpawner = {name=thing, position=nestPosition}
|
||||
if surface.can_place_entity(biterSpawner) then
|
||||
registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base)
|
||||
base.upgradePoints = base.upgradePoints - cost
|
||||
end
|
||||
pos = pos + slice
|
||||
end
|
||||
end
|
||||
end
|
||||
-- for level=0,(base.level * 0.5) do
|
||||
-- local slices = (level * 3)
|
||||
-- slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator)
|
||||
-- local slice = (2 * math.pi) / slices
|
||||
-- local pos = 0
|
||||
-- local thing
|
||||
-- local cost
|
||||
-- local radiusAdjustment
|
||||
-- if (generator() < 0.3) then
|
||||
-- thing = "small-worm-turret"
|
||||
-- cost = AI_WORM_COST
|
||||
-- radiusAdjustment = -4
|
||||
-- else
|
||||
-- thing = "biter-spawner"
|
||||
-- cost = AI_NEST_COST
|
||||
-- radiusAdjustment = 0
|
||||
-- end
|
||||
-- for _ = 1, slices do
|
||||
-- if (base.upgradePoints < 10) then
|
||||
-- return
|
||||
-- end
|
||||
-- local radius = 10 * level
|
||||
-- local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator)
|
||||
-- local nestPosition = {x = position.x + (distortion * math.cos(pos)),
|
||||
-- y = position.y + (distortion * math.sin(pos))}
|
||||
-- local biterSpawner = {name=thing, position=nestPosition}
|
||||
-- if surface.can_place_entity(biterSpawner) then
|
||||
-- registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base)
|
||||
-- base.upgradePoints = base.upgradePoints - cost
|
||||
-- end
|
||||
-- pos = pos + slice
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function nestUtils.buildOrder(map, natives, base, surface)
|
||||
local foundHive = false
|
||||
for _,_ in pairs(base.hives) do
|
||||
foundHive = true
|
||||
break
|
||||
end
|
||||
if not foundHive or (base.upgradePoints < 10) then
|
||||
return
|
||||
end
|
||||
-- function nestUtils.buildOrder(map, natives, base, surface)
|
||||
-- local foundHive = false
|
||||
-- for _,_ in pairs(base.hives) do
|
||||
-- foundHive = true
|
||||
-- break
|
||||
-- end
|
||||
-- if not foundHive or (base.upgradePoints < 10) then
|
||||
-- return
|
||||
-- end
|
||||
|
||||
local generator = natives.randomGenerator
|
||||
generator.re_seed(base.pattern)
|
||||
-- local generator = natives.randomGenerator
|
||||
-- generator.re_seed(base.pattern)
|
||||
|
||||
for level=0,base.level do
|
||||
local slices = (level * 3)
|
||||
slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator)
|
||||
local slice = (2 * math.pi) / slices
|
||||
local pos = 0
|
||||
local thing
|
||||
local cost
|
||||
local radiusAdjustment
|
||||
if (generator() < 0.3) then
|
||||
thing = "small-worm-turret"
|
||||
cost = AI_WORM_COST
|
||||
radiusAdjustment = -4
|
||||
else
|
||||
thing = "biter-spawner"
|
||||
cost = AI_NEST_COST
|
||||
radiusAdjustment = 0
|
||||
end
|
||||
for _ = 1, slices do
|
||||
if (base.upgradePoints < 10) then
|
||||
return
|
||||
end
|
||||
local radius = 10 * level
|
||||
local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator)
|
||||
local nestPosition = {x = base.x + (distortion * math.cos(pos)),
|
||||
y = base.y + (distortion * math.sin(pos))}
|
||||
local biterSpawner = {name=thing, position=nestPosition}
|
||||
if surface.can_place_entity(biterSpawner) then
|
||||
registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base)
|
||||
base.upgradePoints = base.upgradePoints - cost
|
||||
end
|
||||
pos = pos + slice
|
||||
end
|
||||
end
|
||||
end
|
||||
-- for level=0,base.level do
|
||||
-- local slices = (level * 3)
|
||||
-- slices = gaussianRandomRange(slices, slices * 0.1, slices * 0.6, slices * 1.4, generator)
|
||||
-- local slice = (2 * math.pi) / slices
|
||||
-- local pos = 0
|
||||
-- local thing
|
||||
-- local cost
|
||||
-- local radiusAdjustment
|
||||
-- if (generator() < 0.3) then
|
||||
-- thing = "small-worm-turret"
|
||||
-- cost = AI_WORM_COST
|
||||
-- radiusAdjustment = -4
|
||||
-- else
|
||||
-- thing = "biter-spawner"
|
||||
-- cost = AI_NEST_COST
|
||||
-- radiusAdjustment = 0
|
||||
-- end
|
||||
-- for _ = 1, slices do
|
||||
-- if (base.upgradePoints < 10) then
|
||||
-- return
|
||||
-- end
|
||||
-- local radius = 10 * level
|
||||
-- local distortion = gaussianRandomRange(radius, 10, radius - 7.5 + radiusAdjustment, radius + 7.5 + radiusAdjustment, generator)
|
||||
-- local nestPosition = {x = base.x + (distortion * math.cos(pos)),
|
||||
-- y = base.y + (distortion * math.sin(pos))}
|
||||
-- local biterSpawner = {name=thing, position=nestPosition}
|
||||
-- if surface.can_place_entity(biterSpawner) then
|
||||
-- registerEnemyBaseStructure(natives, map, surface.create_entity(biterSpawner), base)
|
||||
-- base.upgradePoints = base.upgradePoints - cost
|
||||
-- end
|
||||
-- pos = pos + slice
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
return nestUtils
|
||||
|
15
libs/StringUtils.lua
Executable file
15
libs/StringUtils.lua
Executable 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
|
6
make.rkt
6
make.rkt
@ -34,7 +34,8 @@
|
||||
(string->path "changelog.txt")
|
||||
(string->path "Upgrade.lua")
|
||||
(string->path "settings.lua")
|
||||
(string->path "BuildSwarm.lua")
|
||||
(string->path "SwarmUtils.lua")
|
||||
(string->path "UnitClasses.lua")
|
||||
(string->path "README.md")
|
||||
(string->path "NOTICE")
|
||||
(string->path "libs")
|
||||
@ -74,7 +75,8 @@
|
||||
(copyFile "changelog.txt" modFolder)
|
||||
(copyFile "Upgrade.lua" modFolder)
|
||||
(copyFile "tests.lua" modFolder)
|
||||
(copyFile "BuildSwarm.lua" modFolder)
|
||||
(copyFile "SwarmUtils.lua" modFolder)
|
||||
(copyFile "UnitClasses.lua" modFolder)
|
||||
(copyDirectory "libs" modFolder)
|
||||
(copyDirectory "locale" modFolder)
|
||||
(copyDirectory "sounds" modFolder)
|
||||
|
Loading…
Reference in New Issue
Block a user