1
0
mirror of https://github.com/veden/Rampant.git synced 2025-03-17 20:58:35 +02:00

switching to other features

This commit is contained in:
Aaron Veden 2017-05-13 11:39:27 -07:00
parent 0cf8214488
commit 0bc8a220f0
4 changed files with 97 additions and 43 deletions

View File

@ -56,7 +56,7 @@ function baseUtils.annexChunk(natives, chunk, tick, surface)
if (annex ~= nil) then
return annex
end
return baseUtils.createBase(natives, chunk, tick, surface)
return nil
end
function baseUtils.removeNest(natives, chunk)
@ -110,12 +110,45 @@ function baseUtils.createBase(natives, chunk, tick, surface)
chunks[#chunks+1] = chunk
chunk[CHUNK_BASE] = base
bases[#bases+1] = base
if (surface.can_place_entity({name="biter-spawner", position={base.cX * 32, base.cY * 32}})) then
surface.create_entity({name="biter-spawner", position={base.cX * 32, base.cY * 32}})
local basePlacement = {
name="biter-spawner",
position={
chunk.pX,
chunk.pY
}
}
print("creating base")
if (surface.can_place_entity(basePlacement)) then
print("created base")
local nest = surface.create_entity(basePlacement)
addRemoveEnemyEntity
end
return base
end
function baseUtils.addBaseToChunk(chunk, entity, base)
local bases = chunk[CHUNK_BASE]
bases[#bases+1] = base
base.nests[entity.unit_number] = entity
end
function baseUtils.removeBaseFromChunk(chunk, entity, base)
if (chunk[ENEMY_BUILDING_COUNT] - 1 <= 0) then
local bases = chunk[CHUNK_BASE]
local baseIndex
for i=1,#bases do
local b = bases[i]
if (b == base) then
table.remove(bases, i)
return true
end
end
else
base.nests[entity.unit_number] = nil
end
return false
end
-- function baseUtils.mergeBases(natives)
-- local bases = natives.bases
-- for x=#bases,1,-1 do

View File

@ -14,6 +14,7 @@ local BASE_PHEROMONE = constants.BASE_PHEROMONE
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE
local BUILDING_PHEROMONES = constants.BUILDING_PHEROMONES
local ENEMY_BUILDING_COUNT = constants.ENEMY_BUILDING_COUNT
local PLAYER_BASE_GENERATOR = constants.PLAYER_BASE_GENERATOR
@ -33,6 +34,7 @@ local CHUNK_BASE = constants.CHUNK_BASE
local addRemoveEntity = entityUtils.addRemoveEntity
local annexChunk = baseUtils.annexChunk
local createBase = baseUtils.createBase
-- module code
@ -93,22 +95,25 @@ function chunkUtils.scoreChunk(chunk, surface, regionMap, natives, tick)
local nestsRemoved = 0
local wormsRemoved = 0
local bitersRemoved = 0
for i=1, #enemies do
local entityType = enemies[i].type
if (entityType == "unit-spawner") then
nestsRemoved = nestsRemoved + 1
nestsRemoved = nestsRemoved + 3
elseif (entityType == "turret") then
wormsRemoved = wormsRemoved + 1
wormsRemoved = wormsRemoved + 2
elseif (entityType == "unit") then
bitersRemoved = bitersRemoved + 1
end
end
if ((nestsRemoved > 0) or (wormsRemoved > 0)) and (chunk[CHUNK_BASE] == nil) then
local base = annexChunk(natives, chunk, tick, surface)
if ((nestsRemoved > 0) or (wormsRemoved > 0) or (bitersRemoved > 0)) and (chunk[CHUNK_BASE] == nil) then
for i=1, #enemies do
enemies[i].destroy()
end
base.upgradePoints = base.upgradePoints + (nestsRemoved * 2) + wormsRemoved
local foundBase = annexChunk(natives, chunk, tick, surface) or createBase(natives, chunk, tick, surface)
foundBase.upgradePoints = foundBase.upgradePoints + nestsRemoved + wormsRemoved + bitersRemoved
end
local playerObjects = 0
@ -137,11 +142,12 @@ function chunkUtils.createChunk(topX, topY)
chunk[BASE_PHEROMONE] = 0
chunk[PLAYER_PHEROMONE] = 0
chunk[PLAYER_BASE_GENERATOR] = 0
chunk[ENEMY_BUILDING_COUNT] = 0
chunk[NORTH_SOUTH_PASSABLE] = false
chunk[EAST_WEST_PASSABLE] = false
chunk[CHUNK_TICK] = 0
chunk[RETREAT_TRIGGERED] = 0
chunk[CHUNK_BASE] = nil
chunk[CHUNK_BASE] = {}
return chunk
end

View File

@ -4,6 +4,7 @@ local entityUtils = {}
local mapUtils = require("MapUtils")
local constants = require("Constants")
local baseUtils = require("BaseUtils")
-- constants
@ -11,12 +12,13 @@ local BUILDING_PHEROMONES = constants.BUILDING_PHEROMONES
local PLAYER_BASE_GENERATOR = constants.PLAYER_BASE_GENERATOR
local ENEMY_BASE_PHEROMONE_GENERATOR_AMOUNT = constants.ENEMY_BASE_PHEROMONE_GENERATOR_AMOUNT
-- imported functions
local getChunkByIndex = mapUtils.getChunkByIndex
local addBaseToChunk = baseUtils.addBaseToChunk
local removeBaseFromChunk = baseUtils.removeBaseFromChunk
local mFloor = math.floor
-- module code
@ -77,42 +79,55 @@ local function getEntityOverlapChunks(regionMap, entity)
return leftTopChunk, rightTopChunk, leftBottomChunk, rightBottomChunk
end
function entityUtils.addRemoveEntity(regionMap, entity, natives, addObject, creditNatives)
function entityUtils.addRemovePlayerEntity(regionMap, entity, natives, addObject, creditNatives)
local leftTop, rightTop, leftBottom, rightBottom
local entityValue
local pheromoneType
local enemy = false
if (BUILDING_PHEROMONES[entity.type] ~= nil) and (entity.force.name == "player") then
entityValue = BUILDING_PHEROMONES[entity.type]
pheromoneType = PLAYER_BASE_GENERATOR
elseif (entity.type == "unit-spawner") and (entity.force.name == "enemy") then
entityValue = ENEMY_BASE_PHEROMONE_GENERATOR_AMOUNT
enemy = true
elseif (entity.type == "turret") and (entity.force.name == "enemy") then
entityValue = 1
enemy = true
leftTop, rightTop, leftBottom, rightBottom = getEntityOverlapChunks(regionMap, entity)
if not addObject then
if creditNatives then
natives.points = natives.points + entityValue
end
entityValue = -entityValue
end
if (leftTop ~= nil) then
leftTop[PLAYER_BASE_GENERATOR] = leftTop[PLAYER_BASE_GENERATOR] + entityValue
end
if (rightTop ~= nil) then
rightTop[PLAYER_BASE_GENERATOR] = rightTop[PLAYER_BASE_GENERATOR] + entityValue
end
if (leftBottom ~= nil) then
leftBottom[PLAYER_BASE_GENERATOR] = leftBottom[PLAYER_BASE_GENERATOR] + entityValue
end
if (rightBottom ~= nil) then
rightBottom[PLAYER_BASE_GENERATOR] = rightBottom[PLAYER_BASE_GENERATOR] + entityValue
end
end
end
function entityUtils.addRemoveEnemyEntity(regionMap, entity, base, addObject)
local leftTop, rightTop, leftBottom, rightBottom
local entityType = entity.type
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then
leftTop, rightTop, leftBottom, rightBottom = getEntityOverlapChunks(regionMap, entity)
local op = (addObject and addBaseToChunk) or removeBaseFromChunk
if (leftTop ~= nil) then
op(leftTop, base)
end
if (rightTop ~= nil) then
op(rightTop, base)
end
if (leftBottom ~= nil) then
op(leftBottom, base)
end
if (rightBottom ~= nil) then
op(rightBottom, base)
end
end
-- if (entityValue ~= nil) then
-- leftTop, rightTop, leftBottom, rightBottom = getEntityOverlapChunks(regionMap, entity)
-- if not addObject then
-- if creditNatives and not enemy then
-- natives.points = natives.points + entityValue
-- end
-- entityValue = -entityValue
-- end
-- if (leftTop ~= nil) then
-- leftTop[pheromoneType] = leftTop[pheromoneType] + entityValue
-- end
-- if (rightTop ~= nil) then
-- rightTop[pheromoneType] = rightTop[pheromoneType] + entityValue
-- end
-- if (leftBottom ~= nil) then
-- leftBottom[pheromoneType] = leftBottom[pheromoneType] + entityValue
-- end
-- if (rightBottom ~= nil) then
-- rightBottom[pheromoneType] = rightBottom[pheromoneType] + entityValue
-- end
-- end
end

View File

@ -141,5 +141,5 @@ data:extend({
order = "e[modifier]-g[safe]",
per_user = false
}
})