mirror of
https://github.com/veden/Rampant.git
synced 2024-12-26 20:54:12 +02:00
Added nocturnal mode
This commit is contained in:
parent
65aa977f1e
commit
b87e4eece0
13
control.lua
13
control.lua
@ -107,6 +107,7 @@ local function onModSettingsChange(event)
|
||||
natives.attackThresholdRange = natives.attackThresholdMax - natives.attackThresholdMin
|
||||
natives.attackWaveMaxSize = settings.global["rampant-attackWaveMaxSize"].value
|
||||
natives.attackPlayerThreshold = settings.global["rampant-attackPlayerThreshold"].value
|
||||
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
|
||||
end
|
||||
|
||||
local function onConfigChanged()
|
||||
@ -198,7 +199,12 @@ local function onConfigChanged()
|
||||
|
||||
natives.safeEntities = {}
|
||||
natives.safeEntityName = {}
|
||||
|
||||
|
||||
game.surfaces[1].print("Rampant - Version 0.15.5")
|
||||
global.version = constants.VERSION_18
|
||||
end
|
||||
if (global.version < constants.VERSION_19) then
|
||||
|
||||
onModSettingsChange(nil)
|
||||
|
||||
-- clear old regionMap processing Queue
|
||||
@ -218,8 +224,8 @@ local function onConfigChanged()
|
||||
y = chunk.y * 32 }}})
|
||||
end
|
||||
|
||||
game.surfaces[1].print("Rampant - Version 0.15.5")
|
||||
global.version = constants.VERSION_18
|
||||
game.surfaces[1].print("Rampant - Version 0.15.6")
|
||||
global.version = constants.VERSION_19
|
||||
end
|
||||
end
|
||||
|
||||
@ -355,7 +361,6 @@ local function onInit()
|
||||
onConfigChanged()
|
||||
end
|
||||
|
||||
|
||||
-- hooks
|
||||
|
||||
script.on_init(onInit)
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name" : "Rampant",
|
||||
"factorio_version" : "0.15",
|
||||
"version" : "0.15.5",
|
||||
"version" : "0.15.6",
|
||||
"title" : "Rampant AI",
|
||||
"author" : "Veden",
|
||||
"homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445",
|
||||
|
@ -9,7 +9,7 @@ local playerUtils = require("PlayerUtils")
|
||||
local neighborUtils = require("NeighborUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
|
||||
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
|
||||
local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE
|
||||
local BASE_PHEROMONE = constants.BASE_PHEROMONE
|
||||
@ -126,7 +126,7 @@ function aiAttack.squadBeginAttack(natives, players, evolution_factor)
|
||||
squad.frenzyPosition.x = squad.group.position.x
|
||||
squad.frenzyPosition.y = squad.group.position.y
|
||||
end
|
||||
|
||||
|
||||
if (math.random() < 0.70) then
|
||||
if (math.random() < kamikazeThreshold) then
|
||||
squad.kamikaze = true
|
||||
|
@ -6,6 +6,7 @@ local constants = require("Constants")
|
||||
local mapUtils = require("MapUtils")
|
||||
local unitGroupUtils = require("UnitGroupUtils")
|
||||
local neighborUtils = require("NeighborUtils")
|
||||
local nocturnalUtils = require("NocturnalUtils")
|
||||
package.path = "../?.lua;" .. package.path
|
||||
local config = require("config")
|
||||
|
||||
@ -22,6 +23,8 @@ local AI_MAX_SQUAD_COUNT = constants.AI_MAX_SQUAD_COUNT
|
||||
local AI_SQUAD_COST = constants.AI_SQUAD_COST
|
||||
local AI_VENGENCE_SQUAD_COST = constants.AI_VENGENCE_SQUAD_COST
|
||||
|
||||
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
|
||||
|
||||
local HALF_CHUNK_SIZE = constants.HALF_CHUNK_SIZE
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
local NORTH_SOUTH_PASSABLE = constants.NORTH_SOUTH_PASSABLE
|
||||
@ -37,6 +40,8 @@ local scoreNeighbors = neighborUtils.scoreNeighbors
|
||||
local createSquad = unitGroupUtils.createSquad
|
||||
local attackWaveScaling = config.attackWaveScaling
|
||||
|
||||
local canAttackNocturnal = nocturnalUtils.canAttack
|
||||
|
||||
local mMax = math.max
|
||||
|
||||
-- module code
|
||||
@ -92,7 +97,7 @@ end
|
||||
-- local enemy = surface.find_nearest_enemy({ position = { x = chunk.pX + HALF_CHUNK_SIZE,
|
||||
-- y = chunk.pY + HALF_CHUNK_SIZE },
|
||||
-- max_distance = 100})
|
||||
|
||||
|
||||
-- if (enemy ~= nil) and enemy.valid and (enemy.type == "unit") then
|
||||
-- natives.points = natives.points - AI_SCOUT_COST
|
||||
-- global.natives.scouts[#global.natives.scouts+1] = enemy
|
||||
|
@ -4,11 +4,13 @@ local aiPlanning = {}
|
||||
|
||||
local constants = require("Constants")
|
||||
local mathUtils = require("MathUtils")
|
||||
local nocturnalUtils = require("NocturnalUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local AI_STATE_PEACEFUL = constants.AI_STATE_PEACEFUL
|
||||
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
|
||||
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
|
||||
|
||||
local AI_MAX_POINTS = constants.AI_MAX_POINTS
|
||||
local AI_POINT_GENERATOR_AMOUNT = constants.AI_POINT_GENERATOR_AMOUNT
|
||||
@ -22,6 +24,8 @@ local TICKS_A_MINUTE = constants.TICKS_A_MINUTE
|
||||
|
||||
-- imported functions
|
||||
|
||||
local canAttackNocturnal = nocturnalUtils.canAttack
|
||||
|
||||
local randomTickEvent = mathUtils.randomTickEvent
|
||||
|
||||
local mMax = math.max
|
||||
@ -30,6 +34,9 @@ local mMax = math.max
|
||||
|
||||
function aiPlanning.planning(natives, evolution_factor, tick, surface)
|
||||
local maxPoints = AI_MAX_POINTS * evolution_factor
|
||||
if natives.aiNocturnalMode then
|
||||
maxPoints = maxPoints * 0.85
|
||||
end
|
||||
if (natives.points < maxPoints) then
|
||||
natives.points = natives.points + math.floor((AI_POINT_GENERATOR_AMOUNT * math.random()) + ((AI_POINT_GENERATOR_AMOUNT * 0.7) * (evolution_factor ^ 2.5)))
|
||||
end
|
||||
@ -43,13 +50,15 @@ function aiPlanning.planning(natives, evolution_factor, tick, surface)
|
||||
local roll = math.random() * mMax(1 - evolution_factor, 0.15)
|
||||
if (roll > natives.temperament) then
|
||||
natives.state = AI_STATE_PEACEFUL
|
||||
elseif (natives.aiNocturnalMode) then
|
||||
natives.state = AI_STATE_NOCTURNAL
|
||||
else
|
||||
natives.state = AI_STATE_AGGRESSIVE
|
||||
end
|
||||
natives.stateTick = randomTickEvent(tick, AI_MIN_STATE_DURATION, AI_MAX_STATE_DURATION)
|
||||
end
|
||||
|
||||
if (natives.state == AI_STATE_AGGRESSIVE) and (tick - natives.lastShakeMessage > TICKS_A_MINUTE * 5) and (natives.points > AI_MAX_POINTS) then
|
||||
if ((natives.state == AI_STATE_AGGRESSIVE) or canAttackNocturnal(natives, surface)) and (tick - natives.lastShakeMessage > TICKS_A_MINUTE * 5) and (natives.points > AI_MAX_POINTS) then
|
||||
natives.lastShakeMessage = tick
|
||||
surface.print("Rampant: The ground begins to shake")
|
||||
end
|
||||
|
@ -13,6 +13,7 @@ constants.VERSION_15 = 15
|
||||
constants.VERSION_16 = 16
|
||||
constants.VERSION_17 = 17
|
||||
constants.VERSION_18 = 18
|
||||
constants.VERSION_19 = 19
|
||||
|
||||
-- misc
|
||||
|
||||
@ -47,6 +48,7 @@ constants.AI_MAX_BITER_GROUP_SIZE = 450
|
||||
|
||||
constants.AI_STATE_PEACEFUL = 1
|
||||
constants.AI_STATE_AGGRESSIVE = 2
|
||||
constants.AI_STATE_NOCTURNAL = 3
|
||||
|
||||
constants.AI_MIN_STATE_DURATION = 1
|
||||
constants.AI_MAX_STATE_DURATION = 4
|
||||
|
@ -6,6 +6,7 @@ local pheromoneUtils = require("PheromoneUtils")
|
||||
local aiBuilding = require("AIBuilding")
|
||||
local constants = require("Constants")
|
||||
local mapUtils = require("MapUtils")
|
||||
local nocturnalUtils = require("NocturnalUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -20,6 +21,7 @@ local AI_UNIT_REFUND = constants.AI_UNIT_REFUND
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
local ENEMY_BASE_GENERATOR = constants.ENEMY_BASE_GENERATOR
|
||||
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
|
||||
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
|
||||
|
||||
local PROCESS_PLAYER_BOUND = constants.PROCESS_PLAYER_BOUND
|
||||
local CHUNK_TICK = constants.CHUNK_TICK
|
||||
@ -44,6 +46,8 @@ local getChunkByPosition = mapUtils.getChunkByPosition
|
||||
|
||||
local playerScent = pheromoneUtils.playerScent
|
||||
|
||||
local canAttackNocturnal = nocturnalUtils.canAttack
|
||||
|
||||
local mMin = math.min
|
||||
|
||||
-- module code
|
||||
@ -78,8 +82,8 @@ function mapProcessor.processMap(regionMap, surface, natives, evolution_factor)
|
||||
roll = math.random()
|
||||
regionMap.processRoll = roll
|
||||
end
|
||||
|
||||
if (natives.state == AI_STATE_AGGRESSIVE) and (0.11 <= roll) and (roll <= 0.35) then
|
||||
|
||||
if ((natives.state == AI_STATE_AGGRESSIVE) or canAttackNocturnal(natives, surface)) and (0.11 <= roll) and (roll <= 0.35) then
|
||||
squads = true
|
||||
end
|
||||
|
||||
@ -119,7 +123,7 @@ function mapProcessor.processPlayers(players, regionMap, surface, natives, evolu
|
||||
local vengenceThreshold = -(evolution_factor * RETREAT_MOVEMENT_PHEROMONE_LEVEL)
|
||||
local roll = math.random()
|
||||
|
||||
if (natives.state == AI_STATE_AGGRESSIVE) and (0.11 <= roll) and (roll <= 0.20) then
|
||||
if ((natives.state == AI_STATE_AGGRESSIVE) or canAttackNocturnal(natives, surface)) and (0.11 <= roll) and (roll <= 0.20) then
|
||||
squads = true
|
||||
end
|
||||
|
||||
@ -142,7 +146,8 @@ function mapProcessor.processPlayers(players, regionMap, surface, natives, evolu
|
||||
|
||||
if (playerChunk ~= nil) then
|
||||
local vengence = false
|
||||
if (playerChunk[ENEMY_BASE_GENERATOR] ~= 0) or (playerChunk[MOVEMENT_PHEROMONE] < vengenceThreshold) then
|
||||
if ((playerChunk[ENEMY_BASE_GENERATOR] ~= 0) or (playerChunk[MOVEMENT_PHEROMONE] < vengenceThreshold)) and
|
||||
(natives.state == AI_STATE_AGGRESSIVE or canAttackNocturnal(natives, surface)) then
|
||||
vengence = true
|
||||
end
|
||||
for x=playerChunk.cX - PROCESS_PLAYER_BOUND, playerChunk.cX + PROCESS_PLAYER_BOUND do
|
||||
@ -204,7 +209,7 @@ function mapProcessor.scanMap(regionMap, surface, natives, evolution_factor)
|
||||
if (unitCount > 550) then
|
||||
local weight = AI_UNIT_REFUND * evolution_factor
|
||||
local units = surface.find_enemy_units({chunk.pX, chunk.pY},
|
||||
CHUNK_SIZE * 3)
|
||||
CHUNK_SIZE * 3)
|
||||
|
||||
for i=1,#units do
|
||||
units[i].destroy()
|
||||
|
21
libs/NocturnalUtils.lua
Normal file
21
libs/NocturnalUtils.lua
Normal file
@ -0,0 +1,21 @@
|
||||
local nocturnalUtils = {}
|
||||
|
||||
-- imports
|
||||
|
||||
local constants = require("Constants")
|
||||
|
||||
-- constants
|
||||
|
||||
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
|
||||
|
||||
-- module code
|
||||
|
||||
function nocturnalUtils.isDark(surface)
|
||||
return surface.darkness > 0.55
|
||||
end
|
||||
|
||||
function nocturnalUtils.canAttack(natives, surface)
|
||||
return nocturnalUtils.isDark(surface) and natives.state == AI_STATE_NOCTURNAL
|
||||
end
|
||||
|
||||
return nocturnalUtils
|
@ -4,6 +4,7 @@ local unitGroupUtils = {}
|
||||
|
||||
local mapUtils = require("MapUtils")
|
||||
local constants = require("Constants")
|
||||
local nocturnalUtils = require("NocturnalUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
[entity-name]
|
||||
tunnel-entrance=Tunnel Entrance
|
||||
|
||||
@ -36,6 +35,7 @@ rampant-safeBuildings-railChainSignals=Make rail chain signals safe from biters
|
||||
rampant-safeBuildings-railSignals=Make rail signals safe from biters
|
||||
rampant-safeBuildings-trainStops=Make train stops safe from biters
|
||||
rampant-attackPlayerThreshold=Player score contribution threshold
|
||||
rampant-permanentNocturnal=Permanent Noctural Mode
|
||||
|
||||
[mod-setting-description]
|
||||
rampant-useDumbProjectiles=Turns off homing projectiles for worms and spitters
|
||||
@ -53,3 +53,4 @@ rampant-safeBuildings-railChainSignals=Make rail chain signals safe from biters
|
||||
rampant-safeBuildings-railSignals=Make rail signals safe from biters
|
||||
rampant-safeBuildings-trainStops=Make train stops safe from biters
|
||||
rampant-attackPlayerThreshold=The score that a chunk must reach for it to contribute to the attack threshold. Increasing reduces player pheromone cloud impact.
|
||||
rampant-permanentNocturnal=Toggling this will cause Rampant attack waves to spawn at night and retreat in the morning. DOES NOT turn off vanilla attack groups yet. Works better with Day/Night extender mod.
|
||||
|
11
settings.lua
11
settings.lua
@ -140,6 +140,15 @@ data:extend({
|
||||
default_value = false,
|
||||
order = "e[modifier]-g[safe]",
|
||||
per_user = false
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
type = "bool-setting",
|
||||
name = "rampant-permanentNocturnal",
|
||||
description = "rampant-permanentNocturnal",
|
||||
setting_type = "runtime-global",
|
||||
default_value = false,
|
||||
order = "f[modifier]-a[ai]",
|
||||
per_user = false
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user