mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
added unit group command timeout + wander to allow gathering
This commit is contained in:
parent
5cdadbebb3
commit
ed2b588a06
18
Upgrade.lua
18
Upgrade.lua
@ -284,6 +284,13 @@ local function addCommandSet(queriesAndCommands)
|
||||
ticks_to_wait = 36000
|
||||
}
|
||||
|
||||
queriesAndCommands.wander2Command = {
|
||||
type = DEFINES_COMMAND_WANDER,
|
||||
wander_in_group = true,
|
||||
radius = TRIPLE_CHUNK_SIZE*2,
|
||||
ticks_to_wait = 2 * 60
|
||||
}
|
||||
|
||||
queriesAndCommands.stopCommand = {
|
||||
type = DEFINES_COMMAND_STOP
|
||||
}
|
||||
@ -417,8 +424,6 @@ function upgrade.attempt(universe)
|
||||
|
||||
universe.builderCount = 0
|
||||
universe.squadCount = 0
|
||||
|
||||
addCommandSet(universe)
|
||||
end
|
||||
if global.version < 116 then
|
||||
global.version = 116
|
||||
@ -436,16 +441,21 @@ function upgrade.attempt(universe)
|
||||
|
||||
game.print("Rampant - Version 1.1.4")
|
||||
end
|
||||
if global.version < 120 then
|
||||
global.version = 120
|
||||
if global.version < 121 then
|
||||
global.version = 121
|
||||
|
||||
addCommandSet(universe)
|
||||
if (universe.maps) then
|
||||
local tick = game.tick
|
||||
for _,map in pairs(universe.maps) do
|
||||
map.pendingUpgrades = {}
|
||||
for i=1,#map.processQueue do
|
||||
local chunk = map.processQueue[i]
|
||||
map.processQueue[i].dOrigin = euclideanDistancePoints(chunk.x, chunk.y, 0, 0)
|
||||
end
|
||||
for _,squad in pairs(map.groupNumberToSquad) do
|
||||
squad.commandTick = tick
|
||||
end
|
||||
tSort(map.processQueue, sorter)
|
||||
for _,base in pairs(map.bases) do
|
||||
base.mutations = 0
|
||||
|
@ -11,6 +11,7 @@ Date: 23. 11. 2021
|
||||
- Optimized regional base upgrades so that the work is spread over many ticks reducing lag spikes
|
||||
- Optimized adding new chunks to the Rampant in-memory state map
|
||||
- Added minimum building cost upgrade check before base upgrade performs scanning
|
||||
- Added command timeout for unit groups in case a command hangs or unit groups are stuck gathering (Thank you Dimm2101)
|
||||
Tweaks:
|
||||
- Increase chance to upgrade an enemy structure from 5% to 30%
|
||||
- New enemy regional bases that have two factions now do 75% on one faction and 25% on the faction for building and upgrading enemy structures
|
||||
|
11
control.lua
11
control.lua
@ -23,6 +23,7 @@ local stringUtils = require("libs/StringUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local COMMAND_TIMEOUT = constants.COMMAND_TIMEOUT
|
||||
local AI_SQUAD_COST = constants.AI_SQUAD_COST
|
||||
local AI_SETTLER_COST = constants.AI_SETTLER_COST
|
||||
|
||||
@ -932,7 +933,7 @@ local function onGroupFinishedGathering(event)
|
||||
if squad then
|
||||
if squad.settler then
|
||||
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) then
|
||||
squadDispatch(map, squad)
|
||||
squadDispatch(map, squad, event.tick)
|
||||
else
|
||||
group.destroy()
|
||||
map.points = map.points + AI_SETTLER_COST
|
||||
@ -942,7 +943,7 @@ local function onGroupFinishedGathering(event)
|
||||
end
|
||||
else
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) then
|
||||
squadDispatch(map, squad)
|
||||
squadDispatch(map, squad, event.tick)
|
||||
else
|
||||
group.destroy()
|
||||
map.points = map.points + AI_SQUAD_COST
|
||||
@ -972,7 +973,7 @@ local function onGroupFinishedGathering(event)
|
||||
else
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
squadDispatch(map, squad)
|
||||
squadDispatch(map, squad, event.tick)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1016,6 +1017,8 @@ local function onBuilderArrived(event)
|
||||
targetPosition.x = builder.position.x
|
||||
targetPosition.y = builder.position.y
|
||||
|
||||
local squad = universe.maps[builder.surface.index].groupNumberToSquad[builder.group_number]
|
||||
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print("Settled: [gps=" .. targetPosition.x .. "," .. targetPosition.y .."]")
|
||||
end
|
||||
@ -1073,7 +1076,7 @@ script.on_event(defines.events.on_tick,
|
||||
processActiveNests(map, tick)
|
||||
processPendingUpgrades(map, tick)
|
||||
processPendingUpgrades(map, tick)
|
||||
cleanSquads(map)
|
||||
cleanSquads(map, tick)
|
||||
|
||||
-- game.print({"", "--dispatch4 ", profiler, ", ", pick, ", ", game.tick, " ", mRandom()})
|
||||
end)
|
||||
|
@ -228,6 +228,8 @@ constants.GROUP_MERGE_DISTANCE = 28
|
||||
|
||||
constants.MAX_PENALTY_BEFORE_PURGE = 36000
|
||||
|
||||
constants.COMMAND_TIMEOUT = 30 * 60
|
||||
|
||||
-- player building pheromones
|
||||
|
||||
constants.GENERATOR_PHEROMONE_LEVEL_1 = 25
|
||||
|
@ -13,6 +13,7 @@ local chunkPropertyUtils = require("ChunkPropertyUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local COMMAND_TIMEOUT = constants.COMMAND_TIMEOUT
|
||||
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
|
||||
local BASE_PHEROMONE = constants.BASE_PHEROMONE
|
||||
local RESOURCE_PHEROMONE = constants.RESOURCE_PHEROMONE
|
||||
@ -319,7 +320,7 @@ local function buildMove(map, squad)
|
||||
group.set_command(universe.compoundSettleCommand)
|
||||
end
|
||||
|
||||
function squadAttack.cleanSquads(map)
|
||||
function squadAttack.cleanSquads(map, tick)
|
||||
local squads = map.groupNumberToSquad
|
||||
local k = map.squadIterator
|
||||
local squad
|
||||
@ -351,20 +352,28 @@ function squadAttack.cleanSquads(map)
|
||||
end
|
||||
squads[k] = nil
|
||||
elseif (group.state == 4) then
|
||||
squadAttack.squadDispatch(map, squad)
|
||||
squadAttack.squadDispatch(map, squad, tick)
|
||||
elseif (squad.commandTick and (squad.commandTick < tick)) then
|
||||
local cmd = map.universe.wander2Command
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
group.set_command(cmd)
|
||||
group.start_moving()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function squadAttack.squadDispatch(map, squad)
|
||||
function squadAttack.squadDispatch(map, squad, tick)
|
||||
local group = squad.group
|
||||
if group and group.valid then
|
||||
local status = squad.status
|
||||
if (status == SQUAD_RAIDING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
attackMove(map, squad)
|
||||
elseif (status == SQUAD_SETTLING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
settleMove(map, squad)
|
||||
elseif (status == SQUAD_RETREATING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
if squad.settlers then
|
||||
squad.status = SQUAD_SETTLING
|
||||
settleMove(map, squad)
|
||||
@ -373,9 +382,11 @@ function squadAttack.squadDispatch(map, squad)
|
||||
attackMove(map, squad)
|
||||
end
|
||||
elseif (status == SQUAD_BUILDING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
removeSquadFromChunk(map, squad)
|
||||
buildMove(map, squad)
|
||||
elseif (status == SQUAD_GUARDING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
if squad.settlers then
|
||||
squad.status = SQUAD_SETTLING
|
||||
settleMove(map, squad)
|
||||
|
@ -91,6 +91,7 @@ function unitGroupUtils.createSquad(position, surface, group, settlers)
|
||||
groupNumber = unitGroup.group_number,
|
||||
originPosition = {x = 0,
|
||||
y = 0},
|
||||
commandTick = nil,
|
||||
chunk = -1
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user