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

FACTO-233: Adding biter squad compression

This commit is contained in:
Aaron Veden 2023-03-26 14:26:15 -07:00
parent d6256337b9
commit a4cceae192
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
6 changed files with 116 additions and 3 deletions

View File

@ -18,6 +18,7 @@ Version: 3.2.0
- Hives now produce two upper tier units
- Hives now have a controlled expansion that doesn't use the unit-spawner non-unit spawning capabilities of the factorio engine
- Unit groups now path upto 4 chunks at a time
- Added biter squad compression with adjustable unit group size threshold for when to apply compression
Compatibility:
- Added interface for adding and removing excluded surfaces
Tweaks:

View File

@ -141,6 +141,9 @@ local getDrainPylonPair = ChunkPropertyUtils.getDrainPylonPair
local createDrainPylon = UnitUtils.createDrainPylon
local compressSquad = Squad.compressSquad
local decompressSquad = Squad.decompressSquad
local isDrained = ChunkPropertyUtils.isDrained
local setDrainedTick = ChunkPropertyUtils.setDrainedTick
local getCombinedDeathGeneratorRating = ChunkPropertyUtils.getCombinedDeathGeneratorRating
@ -293,6 +296,7 @@ local function onModSettingsChange(event)
Universe["legacyChunkScanning"] = settings.global["rampant--legacyChunkScanning"].value
Universe["enabledPurpleSettlerCloud"] = settings.global["rampant--enabledPurpleSettlerCloud"].value
Universe["squadCompressionThreshold"] = settings.global["rampant--squadCompressionThreshold"].value
Universe["AI_MAX_SQUAD_COUNT"] = settings.global["rampant--maxNumberOfSquads"].value
Universe["AI_MAX_BUILDER_COUNT"] = settings.global["rampant--maxNumberOfBuilders"].value
@ -464,8 +468,11 @@ local function onDeath(event)
local group = entity.unit_group
if group then
local squad = Universe.groupNumberToSquad[group.group_number]
if damageTypeName and squad then
base = squad.base
if squad then
decompressSquad(squad)
if damageTypeName then
base = squad.base
end
end
end
end
@ -820,6 +827,7 @@ local function onGroupFinishedGathering(event)
if squad then
if squad.settler then
if (Universe.builderCount <= Universe.AI_MAX_BUILDER_COUNT) then
compressSquad(squad)
squadDispatch(map, squad, event.tick)
else
group.destroy()
@ -832,6 +840,7 @@ local function onGroupFinishedGathering(event)
end
if (Universe.squadCount <= Universe.AI_MAX_SQUAD_COUNT) then
compressSquad(squad)
squadDispatch(map, squad, event.tick)
else
group.destroy()
@ -871,6 +880,7 @@ local function onGroupFinishedGathering(event)
else
Universe.squadCount = Universe.squadCount + 1
end
compressSquad(squad)
squadDispatch(map, squad, event.tick)
end
end

View File

@ -81,6 +81,8 @@ local CHUNK_ALL_DIRECTIONS = Constants.CHUNK_ALL_DIRECTIONS
-- imported functions
local setPositionInQuery = Utils.setPositionInQuery
local getPassable = ChunkPropertyUtils.getPassable
local getRallyTick = ChunkPropertyUtils.getRallyTick
local setRallyTick = ChunkPropertyUtils.setRallyTick
@ -253,6 +255,69 @@ local function addMovementPenalty(squad, chunk)
c = chunk })
end
function Squad.compressSquad(squad)
if not squad.canBeCompressed then
return
end
local compressionSet = {}
local group = squad.group
local members = group.members
if #members < Universe.squadCompressionThreshold then
squad.canBeCompressed = false
return
end
local compressedTotal = 0
local totalTypes = 0
for _, entity in pairs(members) do
local entityName = entity.name
local count = compressionSet[entityName]
if not count then
totalTypes = totalTypes + 1
if totalTypes > 6 then
entity.destroy()
compressionSet[entityName] = 1
else
compressionSet[entityName] = 0
end
else
compressionSet[entityName] = count + 1
compressedTotal = compressedTotal + 1
entity.destroy()
end
end
local query = Queries.renderText
query.surface = group.surface
query.text = compressedTotal
query.target = members[1]
squad.compressionText = rendering.draw_text(query)
squad.compressionSet = compressionSet
squad.canBeCompressed = false
end
function Squad.decompressSquad(squad)
if not squad.compressionSet then
return
end
local group = squad.group
local query = Queries.createEntityQuery
local add_member = group.add_member
local create_entity = squad.map.surface.create_entity
setPositionInQuery(
query,
group.position
)
for name,count in pairs(squad.compressionSet) do
query.name = name
for _ = 1, count do
add_member(create_entity(query))
end
end
rendering.destroy(squad.compressionText)
squad.compressionSet = nil
end
--[[
Expects all neighbors adjacent to a chunk
--]]
@ -365,6 +430,8 @@ local function settleMove(squad)
)
)
then
Squad.decompressSquad(squad)
position = findMovementPosition(surface, groupPosition) or groupPosition
cmd = Queries.settleCommand
@ -438,6 +505,7 @@ local function settleMove(squad)
if lastChunk ~= 4 then
cmd = Queries.settleCommand
squad.status = SQUAD_BUILDING
Squad.decompressSquad(squad)
if squad.kamikaze then
cmd.distraction = DEFINES_DISTRACTION_NONE
else
@ -521,6 +589,7 @@ local function attackMove(squad)
end
if attack then
Squad.decompressSquad(squad)
cmd = Queries.attackCommand
if not squad.rabid then
@ -551,6 +620,8 @@ local function buildMove(map, squad)
setPositionInCommand(Queries.settleCommand, position)
Squad.decompressSquad(squad)
group.set_command(Queries.compoundSettleCommand)
end
@ -824,6 +895,9 @@ function Squad.createSquad(position, map, group, settlers, base)
local squad = {
group = unitGroup,
canBeCompressed = true,
compressionSet = nil,
compressionText = nil,
status = SQUAD_GUARDING,
rabid = false,
penalties = {},
@ -1102,6 +1176,8 @@ local function deploySquad(name, chunk, cost, vengence, attacker)
squad.rabid = Universe.random() < 0.03
Squad.compressSquad(squad)
Universe.groupNumberToSquad[squad.groupNumber] = squad
modifyBaseUnitPoints(base, -cost, name, squadPosition.x, squadPosition.y)
end

View File

@ -296,6 +296,10 @@ local function addCommandSet()
Universe.squadQueries = {}
Universe.squadQueries.targetPosition = {0,0}
Universe.squadQueries.createEntityQuery = {
name = "",
position = {0,0}
}
Universe.squadQueries.attackCommand = {
type = DEFINES_COMMAND_ATTACK_AREA,
destination = {0,0},
@ -379,6 +383,14 @@ local function addCommandSet()
{chunk=-1, direction=-1},
{chunk=-1, direction=-1}
}
Universe.squadQueries.renderText = {
target = nil,
text = "",
target_offset = {0, -10},
color = {r=1,g=1,b=1,a=0.5},
surface = nil,
scale = 5
}
end
function Upgrade.setCommandForces(npcForces, enemyForces)

View File

@ -75,6 +75,7 @@ acid-ball-5-acid-fire-rampant=Acid Pool
hive=Spawns enemy structures
[mod-setting-name]
rampant--squadCompressionThreshold=Optimization: Compress biter groups
rampant--legacyChunkScanning=Optimization: Scan chunks outside raised events
rampant--scaleParticleCount=Optimization: Scale blood particle count
rampant--maxBaseAlignmentHistory=World: Max Base Mutation History
@ -207,6 +208,7 @@ rampant--temperamentRateModifier=AI: Temperament Rate Modifier
rampant--enableLandfillOnDeath=World: Enemies fill water on death
[mod-setting-description]
rampant--squadCompressionThreshold=Will compress biter groups into one unit of each type upto 6 types with a number representing how many units were compressed. Decompression will take place when the groups gets close to player, player structures, or loses a unit. -1 means disabled. Any number above -1 is the minimum number of units in a unit group that should be compressed.
rampant--legacyChunkScanning=Enabling this will cause Rampant to slowly scan chunks for resources, enemies, and player structures that are created or destroyed by mods that dont raise an event when creating or destroying entities.
rampant--maxBaseAlignmentHistory=The number of mutations that a base will remember. Remembered mutations cannot be mutated to again.
rampant--enableLandfillOnDeath=The body parts that are thrown off when dying will landfill water tiles. If Remove blood particles is enabled then this setting will not work.

View File

@ -612,7 +612,19 @@ data:extend({
description = "rampant--legacyChunkScanning",
setting_type = "runtime-global",
default_value = false,
order = "m[total]-c[ai]zz",
order = "m[total]-c[ai]z",
per_user = false
},
{
type = "int-setting",
name = "rampant--squadCompressionThreshold",
description = "rampant--squadCompressionThreshold",
setting_type = "runtime-global",
minimum_value = -1,
default_value = 60,
maximum_value = 600,
order = "m[total]-c[ai]z",
per_user = false
},