mirror of
https://github.com/veden/Rampant.git
synced 2025-01-16 02:33:53 +02:00
finished item collector
This commit is contained in:
parent
baee711d7d
commit
59186e388e
@ -58,8 +58,15 @@ Configure Options not in game menu:
|
||||
# Version History
|
||||
|
||||
0.15.18 -
|
||||
- Feature: Adds an item collector for things like alien artifacts
|
||||
- Improvement: Added checks for how many squads have been created to enfore global limit over all squad creation methods
|
||||
- Tweak: Increased breach multiplier from 10000 to 100000
|
||||
- Fixed: Current version wasn't be set causing the upgrade code to run repeatedly
|
||||
- Fixed: Neighbors function not correctly clearing its state between calls
|
||||
- Optimization: Reduced number of chunks processed per cycle from 500 to 400
|
||||
- Optimization: Reduced number of squads to regroup per cycle from 5 to 2
|
||||
- Optimization: Reduced number of chunks to scan per cycle from 6 to 5
|
||||
- Optimization: Added additional short circuits for chunk scoring
|
||||
|
||||
0.15.17 -
|
||||
- Fixed: Remote call load issue. (https://github.com/veden/Rampant/issues/5)
|
||||
|
87
control.lua
87
control.lua
@ -56,6 +56,7 @@ local getPlayerCursorStack = playerUtils.getPlayerCursorStack
|
||||
|
||||
local swapItemStack = inventoryUtils.swapItemStack
|
||||
local swapItemInventory = inventoryUtils.swapItemInventory
|
||||
local topOffHand = inventoryUtils.topOffHand
|
||||
|
||||
local processWorld = worldProcessor.processWorld
|
||||
|
||||
@ -250,8 +251,9 @@ end
|
||||
local function onTick(event)
|
||||
local tick = event.tick
|
||||
if (tick == regionMap.processTick) then
|
||||
local gameRef = game
|
||||
regionMap.processTick = regionMap.processTick + INTERVAL_PROCESS
|
||||
local surface = game.surfaces[1]
|
||||
local surface = gameRef.surfaces[1]
|
||||
|
||||
processPendingChunks(natives, regionMap, surface, pendingChunks, tick)
|
||||
scanMap(regionMap, surface, natives)
|
||||
@ -259,10 +261,10 @@ local function onTick(event)
|
||||
if (tick == regionMap.logicTick) then
|
||||
regionMap.logicTick = regionMap.logicTick + INTERVAL_LOGIC
|
||||
|
||||
local players = game.players
|
||||
local players = gameRef.players
|
||||
|
||||
planning(natives,
|
||||
game.forces.enemy.evolution_factor,
|
||||
gameRef.forces.enemy.evolution_factor,
|
||||
tick,
|
||||
surface)
|
||||
|
||||
@ -296,11 +298,12 @@ local function onBuild(event)
|
||||
end
|
||||
|
||||
local function onMine(event)
|
||||
addRemovePlayerEntity(regionMap,
|
||||
mineComplexEntity(event.entity, world),
|
||||
natives,
|
||||
false,
|
||||
false)
|
||||
mineComplexEntity(addRemovePlayerEntity(regionMap,
|
||||
event.entity,
|
||||
natives,
|
||||
false,
|
||||
false),
|
||||
world)
|
||||
end
|
||||
|
||||
local function onDeath(event)
|
||||
@ -397,35 +400,65 @@ end
|
||||
-- end
|
||||
|
||||
local function onCursorChange(event)
|
||||
local player = game.players[event.player_index]
|
||||
swapItemStack(getPlayerCursorStack(player),
|
||||
"item-collector-base-rampant",
|
||||
"item-collector-base-overlay-rampant")
|
||||
if settings.startup["rampant-enableBuildings"].value then
|
||||
local player = game.players[event.player_index]
|
||||
swapItemStack(getPlayerCursorStack(player),
|
||||
"item-collector-base-rampant",
|
||||
"item-collector-base-overlay-rampant")
|
||||
local inventory = getPlayerInventory(player,
|
||||
DEFINES_INVENTORY_PLAYER_QUICKBAR,
|
||||
DEFINES_INVENTORY_GOD_QUICKBAR)
|
||||
topOffHand(inventory,
|
||||
player.cursor_stack,
|
||||
"item-collector-base-rampant",
|
||||
"item-collector-base-overlay-rampant")
|
||||
inventory = getPlayerInventory(player,
|
||||
DEFINES_INVENTORY_PLAYER_MAIN,
|
||||
DEFINES_INVENTORY_GOD_MAIN)
|
||||
topOffHand(inventory,
|
||||
player.cursor_stack,
|
||||
"item-collector-base-rampant",
|
||||
"item-collector-base-overlay-rampant")
|
||||
end
|
||||
end
|
||||
|
||||
local function onPlayerDropped(event)
|
||||
local item = event.entity
|
||||
if item.valid then
|
||||
swapItemStack(item.stack,
|
||||
"item-collector-base-overlay-rampant",
|
||||
"item-collector-base-rampant")
|
||||
if settings.startup["rampant-enableBuildings"].value then
|
||||
local item = event.entity
|
||||
if item.valid then
|
||||
swapItemStack(item.stack,
|
||||
"item-collector-base-overlay-rampant",
|
||||
"item-collector-base-rampant")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onMainInventoryChanged(event)
|
||||
swapItemInventory(getPlayerInventory(game.players[event.player_index],
|
||||
DEFINES_INVENTORY_PLAYER_MAIN,
|
||||
DEFINES_INVENTORY_GOD_MAIN),
|
||||
"item-collector-base-overlay-rampant",
|
||||
"item-collector-base-rampant")
|
||||
if settings.startup["rampant-enableBuildings"].value then
|
||||
local player = game.players[event.player_index]
|
||||
local inventory = getPlayerInventory(player,
|
||||
DEFINES_INVENTORY_PLAYER_MAIN,
|
||||
DEFINES_INVENTORY_GOD_MAIN)
|
||||
swapItemInventory(inventory,
|
||||
"item-collector-base-overlay-rampant",
|
||||
"item-collector-base-rampant")
|
||||
end
|
||||
end
|
||||
|
||||
local function onQuickInventoryChanged(event)
|
||||
swapItemInventory(getPlayerInventory(game.players[event.player_index],
|
||||
DEFINES_INVENTORY_PLAYER_QUICKBAR,
|
||||
DEFINES_INVENTORY_GOD_QUICKBAR),
|
||||
"item-collector-base-overlay-rampant",
|
||||
"item-collector-base-rampant")
|
||||
if settings.startup["rampant-enableBuildings"].value then
|
||||
local player = game.players[event.player_index]
|
||||
local inventory = getPlayerInventory(player,
|
||||
DEFINES_INVENTORY_PLAYER_QUICKBAR,
|
||||
DEFINES_INVENTORY_GOD_QUICKBAR)
|
||||
swapItemInventory(inventory,
|
||||
"item-collector-base-overlay-rampant",
|
||||
"item-collector-base-rampant")
|
||||
topOffHand(inventory,
|
||||
player.cursor_stack,
|
||||
"item-collector-base-rampant",
|
||||
"item-collector-base-overlay-rampant")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 18 KiB |
BIN
graphics/entities/chest/itemCollectorOverlay2.5.png
Executable file
BIN
graphics/entities/chest/itemCollectorOverlay2.5.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
Before Width: | Height: | Size: 41 KiB |
Binary file not shown.
Before Width: | Height: | Size: 79 KiB |
@ -8,9 +8,9 @@ function buildUtils.buildComplexEntity(entity, world)
|
||||
local x = entity.position.x
|
||||
local y = entity.position.y
|
||||
local chest
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
if (entity.name == "item-collector-base-overlay-rampant") then
|
||||
local position = entity.position
|
||||
local force = entity.force
|
||||
entity.destroy()
|
||||
chest = surface.create_entity({name = "item-collector-chest-rampant",
|
||||
position = position,
|
||||
@ -31,6 +31,10 @@ function buildUtils.buildComplexEntity(entity, world)
|
||||
local conflicts
|
||||
conflicts, chest = ghost.revive()
|
||||
end
|
||||
else
|
||||
chest = surface.create_entity({name = "item-collector-chest-rampant",
|
||||
position = position,
|
||||
force = force})
|
||||
end
|
||||
end
|
||||
if chest and chest.valid then
|
||||
@ -53,7 +57,7 @@ function buildUtils.mineComplexEntity(entity, world, destroyed)
|
||||
if chest and chest.valid then
|
||||
world.itemCollectorLookup[chest.unit_number] = nil
|
||||
if destroyed and (entity == chest) then
|
||||
chest.destroy()
|
||||
chest.die()
|
||||
elseif (entity ~= chest) then
|
||||
chest.destroy()
|
||||
end
|
||||
|
@ -86,7 +86,7 @@ local function fullScan(chunkTiles, x, y, get_tile)
|
||||
break
|
||||
end
|
||||
end
|
||||
return validTiles * 0.009765625, passableNorthSouth, passableEastWest
|
||||
return validTiles * 0.0009765625, passableNorthSouth, passableEastWest
|
||||
end
|
||||
|
||||
local function spotCheck(x, y, get_tile)
|
||||
|
@ -26,7 +26,7 @@ constants.PROCESS_QUEUE_SIZE = 400
|
||||
constants.SCAN_QUEUE_SIZE = 5
|
||||
constants.ITEM_COLLECTOR_QUEUE_SIZE = 6
|
||||
constants.BASE_QUEUE_SIZE = 1
|
||||
constants.SQUAD_QUEUE_SIZE = 5
|
||||
constants.SQUAD_QUEUE_SIZE = 2
|
||||
constants.PROCESS_PLAYER_BOUND = 4
|
||||
|
||||
constants.ITEM_COLLECTOR_MAX_QUEUE_SIZE = 20
|
||||
@ -43,7 +43,7 @@ constants.DEV_CUSTOM_AI = false
|
||||
|
||||
-- item collector
|
||||
|
||||
constants.ITEM_COLLECTOR_DISTANCE = 44
|
||||
constants.ITEM_COLLECTOR_DISTANCE = 50
|
||||
|
||||
-- chunk properties
|
||||
|
||||
@ -198,7 +198,7 @@ constants.retreatFilter[constants.SQUAD_RETREATING] = true
|
||||
constants.PATH_FINDER_SHORT_REQUEST_RATIO = 0.8
|
||||
constants.PATH_FINDER_SHORT_CACHE_SIZE = 25
|
||||
constants.PATH_FINDER_LONG_REQUEST_RATIO = 5
|
||||
constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH = 100
|
||||
constants.PATH_FINDER_MIN_STEPS_TO_CHECK_PATH = 1000
|
||||
|
||||
constants.MAX_FAILED_BEHAVIORS = 10
|
||||
|
||||
|
@ -1,17 +1,38 @@
|
||||
local inventoryUtils = {}
|
||||
|
||||
-- imported functions
|
||||
|
||||
local mMin = math.min
|
||||
|
||||
-- modules code
|
||||
|
||||
function inventoryUtils.swapItemInventory(inventory, src, dst)
|
||||
if inventory and inventory.valid then
|
||||
local itemCount = inventory.get_item_count(src)
|
||||
if (itemCount > 0) then
|
||||
inventory.insert({name = dst, count = itemCount})
|
||||
inventory.remove({name = src, count = itemCount})
|
||||
inventory.insert({name = dst, count = itemCount})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function inventoryUtils.topOffHand(inventory, handStack, src, dst)
|
||||
if inventory and inventory.valid then
|
||||
local itemCount = inventory.get_item_count(src)
|
||||
if (itemCount > 0) then
|
||||
if handStack and handStack.valid and handStack.valid_for_read and (handStack.prototype.name == dst) then
|
||||
local remaining = mMin(itemCount, handStack.prototype.stack_size - handStack.count)
|
||||
if (remaining > 0) then
|
||||
local stack = { name = src, count = remaining + handStack.count }
|
||||
if (handStack.can_set_stack(stack)) and handStack.set_stack(stack) then
|
||||
inventory.remove({name = src, count = remaining})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function inventoryUtils.swapItemStack(stack, src, dst)
|
||||
if stack and stack.valid_for_read and (stack.name == src) then
|
||||
local item = { name = dst, count = stack.count }
|
||||
|
@ -47,9 +47,9 @@ end
|
||||
6 7 8
|
||||
]]--
|
||||
function mapUtils.getNeighborChunks(regionMap, chunkX, chunkY)
|
||||
local neighbors = regionMap.neighbors
|
||||
local chunkYRow1 = chunkY - 1
|
||||
local chunkYRow3 = chunkY + 1
|
||||
local neighbors = regionMap.neighbors
|
||||
local xChunks = regionMap[chunkX-1]
|
||||
if xChunks then
|
||||
neighbors[1] = xChunks[chunkYRow1]
|
||||
@ -100,8 +100,8 @@ function mapUtils.canMoveChunkDirection(direction, startChunk, endChunk)
|
||||
end
|
||||
|
||||
function mapUtils.getCardinalChunks(regionMap, chunkX, chunkY)
|
||||
local xChunks = regionMap[chunkX]
|
||||
local neighbors = regionMap.cardinalNeighbors
|
||||
local xChunks = regionMap[chunkX]
|
||||
if xChunks then
|
||||
neighbors[1] = xChunks[chunkY-1]
|
||||
neighbors[4] = xChunks[chunkY+1]
|
||||
|
@ -59,7 +59,7 @@ end
|
||||
|
||||
function pheromoneUtils.victoryScent(chunk, entityType)
|
||||
local value = BUILDING_PHEROMONES[entityType]
|
||||
if (value ~= nil) and (chunk[PASSABLE] ~= CHUNK_IMPASSABLE) then
|
||||
if value and (chunk[PASSABLE] ~= CHUNK_IMPASSABLE) then
|
||||
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] + (value * 100000)
|
||||
end
|
||||
end
|
||||
@ -81,8 +81,6 @@ function pheromoneUtils.processPheromone(regionMap, chunk)
|
||||
if (chunk[PASSABLE] == CHUNK_IMPASSABLE) then
|
||||
return
|
||||
end
|
||||
|
||||
local tempNeighbors = getCardinalChunks(regionMap, chunk.cX, chunk.cY)
|
||||
|
||||
local chunkMovement = chunk[MOVEMENT_PHEROMONE]
|
||||
local chunkBase = chunk[BASE_PHEROMONE]
|
||||
@ -94,6 +92,8 @@ function pheromoneUtils.processPheromone(regionMap, chunk)
|
||||
local totalBase = 0
|
||||
local totalPlayer = 0
|
||||
local totalResource = 0
|
||||
|
||||
local tempNeighbors = getCardinalChunks(regionMap, chunk.cX, chunk.cY)
|
||||
|
||||
for i=1,4 do
|
||||
local neighborChunk = tempNeighbors[i]
|
||||
|
@ -15,55 +15,63 @@ local ITEM_COLLECTOR_QUEUE_SIZE = constants.ITEM_COLLECTOR_QUEUE_SIZE
|
||||
-- module code
|
||||
|
||||
function worldProcessor.processWorld(surface, world, tick)
|
||||
local collectorLookup = world.itemCollectorLookup
|
||||
local collectors = world.itemCollectorEvents
|
||||
if (#collectors > 0) then
|
||||
local collectorLookup = world.itemCollectorLookup
|
||||
|
||||
local topLeftPosition = {x = 0, y = 0}
|
||||
local bottomRightPosition = {x = 0, y = 0}
|
||||
local boundingArea = {topLeftPosition,
|
||||
bottomRightPosition}
|
||||
local inserter = {name="", count=0}
|
||||
local topLeftPosition = {x = 0, y = 0}
|
||||
local bottomRightPosition = {x = 0, y = 0}
|
||||
local boundingArea = {topLeftPosition,
|
||||
bottomRightPosition}
|
||||
|
||||
local count = 0
|
||||
for index = #collectors, 1, -1 do
|
||||
count = count + 1
|
||||
local itemCollectorPair = collectorLookup[collectors[index]]
|
||||
collectors[index] = nil
|
||||
local chest = itemCollectorPair[1]
|
||||
local dish = itemCollectorPair[2]
|
||||
|
||||
if chest.valid and dish.valid then
|
||||
|
||||
local collectorPosition = dish.position
|
||||
local count = 0
|
||||
for index = #collectors, 1, -1 do
|
||||
count = count + 1
|
||||
local itemCollectorPair = collectorLookup[collectors[index]]
|
||||
collectors[index] = nil
|
||||
local chest = itemCollectorPair[1]
|
||||
local dish = itemCollectorPair[2]
|
||||
|
||||
topLeftPosition.x = collectorPosition.x - ITEM_COLLECTOR_DISTANCE
|
||||
topLeftPosition.y = collectorPosition.y - ITEM_COLLECTOR_DISTANCE
|
||||
if chest.valid and dish.valid then
|
||||
|
||||
bottomRightPosition.x = collectorPosition.x + ITEM_COLLECTOR_DISTANCE
|
||||
bottomRightPosition.y = collectorPosition.y + ITEM_COLLECTOR_DISTANCE
|
||||
|
||||
local items = surface.find_entities_filtered({area = boundingArea,
|
||||
name = "item-on-ground"})
|
||||
|
||||
local counts = {}
|
||||
if (#items > 0) then
|
||||
for x=1,#items do
|
||||
local item = items[x]
|
||||
if not counts[item.stack.name] then
|
||||
counts[item.stack.name] = 1
|
||||
else
|
||||
counts[item.stack.name] = counts[item.stack.name] + 1
|
||||
local collectorPosition = dish.position
|
||||
|
||||
topLeftPosition.x = collectorPosition.x - ITEM_COLLECTOR_DISTANCE
|
||||
topLeftPosition.y = collectorPosition.y - ITEM_COLLECTOR_DISTANCE
|
||||
|
||||
bottomRightPosition.x = collectorPosition.x + ITEM_COLLECTOR_DISTANCE
|
||||
bottomRightPosition.y = collectorPosition.y + ITEM_COLLECTOR_DISTANCE
|
||||
|
||||
local items = surface.find_entities_filtered({area = boundingArea,
|
||||
name = "item-on-ground"})
|
||||
|
||||
local counts = {}
|
||||
if (#items > 0) then
|
||||
for x=1,#items do
|
||||
local item = items[x]
|
||||
local itemName = item.stack.name
|
||||
if not counts[itemName] then
|
||||
counts[itemName] = {item}
|
||||
else
|
||||
counts[#counts[itemName]+1] = item
|
||||
end
|
||||
end
|
||||
item.destroy()
|
||||
for k,a in pairs(counts) do
|
||||
inserter.name = k
|
||||
inserter.count = #a
|
||||
local stored = chest.insert(inserter)
|
||||
for i=1,stored do
|
||||
a[i].destroy()
|
||||
end
|
||||
end
|
||||
-- dish.surface.create_entity({name="item-collector-base-particle-rampant",
|
||||
-- position=dish.position})
|
||||
end
|
||||
for k,c in pairs(counts) do
|
||||
chest.insert({name=k, count=c})
|
||||
end
|
||||
-- dish.surface.create_entity({name="item-collector-base-particle-rampant",
|
||||
-- position=dish.position})
|
||||
end
|
||||
end
|
||||
if (count >= ITEM_COLLECTOR_QUEUE_SIZE) then
|
||||
return
|
||||
if (count >= ITEM_COLLECTOR_QUEUE_SIZE) then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -13,6 +13,7 @@ biter-spawner-hive=Small Hive
|
||||
|
||||
small-tendril-biter-rampant=Small Tendril
|
||||
item-collector-base-rampant=Item Collector
|
||||
item-collector-base-overlay-rampant=Item Collector
|
||||
item-collector-chest-rampant=Item Collector Storage
|
||||
|
||||
[item-description]
|
||||
|
6
make.rkt
6
make.rkt
@ -76,8 +76,8 @@
|
||||
(copyDirectory "prototypes" modFolder)))
|
||||
|
||||
(define (run)
|
||||
(copyFiles modFolder)
|
||||
;; (copyFiles zipModFolder)
|
||||
;(makeZip modFolder)
|
||||
;;(copyFiles modFolder)
|
||||
;;(copyFiles zipModFolder)
|
||||
(makeZip modFolder)
|
||||
)
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ radar.pictures = {
|
||||
apply_projection = false,
|
||||
direction_count = 64,
|
||||
line_length = 8,
|
||||
shift = {0.1875, -0.2}
|
||||
shift = {0.1875, -0.24}
|
||||
}
|
||||
radar.minable = { result = "item-collector-base-rampant",
|
||||
mining_time = 1 }
|
||||
@ -62,9 +62,9 @@ radar.minable = { result = "item-collector-base-rampant",
|
||||
|
||||
local radarOverlay = util.table.deepcopy(radar)
|
||||
radarOverlay.name = "item-collector-base-overlay-rampant"
|
||||
radarOverlay.pictures.filename = "__Rampant__/graphics/entities/chest/itemCollectorOverlay2.png"
|
||||
radarOverlay.pictures.width = 2800
|
||||
radarOverlay.pictures.height = 2800
|
||||
radarOverlay.pictures.filename = "__Rampant__/graphics/entities/chest/itemCollectorOverlay2.5.png"
|
||||
radarOverlay.pictures.width = 3200
|
||||
radarOverlay.pictures.height = 3200
|
||||
radarOverlay.pictures.direction_count = 1
|
||||
radarOverlay.pictures.line_length = 1
|
||||
radarOverlay.pictures.shift[2] = 0.07
|
||||
|
Loading…
Reference in New Issue
Block a user