mirror of
https://github.com/veden/Rampant.git
synced 2025-01-26 03:20:07 +02:00
fixing ai points nil error, changed upgrade process
This commit is contained in:
parent
6d34fa0b10
commit
eea06a6c74
125
Upgrade.lua
Normal file
125
Upgrade.lua
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
local upgrade = {}
|
||||||
|
|
||||||
|
-- imports
|
||||||
|
|
||||||
|
local constants = require("libs/Constants")
|
||||||
|
local mathUtils = require("libs/MathUtils")
|
||||||
|
|
||||||
|
-- constants
|
||||||
|
|
||||||
|
local INTERVAL_LOGIC = constants.INTERVAL_LOGIC
|
||||||
|
local INTERVAL_PROCESS = constants.INTERVAL_PROCESS
|
||||||
|
|
||||||
|
local MAX_RALLY_CRIES = constants.MAX_RALLY_CRIES
|
||||||
|
|
||||||
|
-- imported functions
|
||||||
|
|
||||||
|
local roundToNearest = mathUtils.roundToNearest
|
||||||
|
|
||||||
|
-- module code
|
||||||
|
|
||||||
|
function upgrade.attempt(natives, regionMap)
|
||||||
|
local starting = global.version
|
||||||
|
if (global.version == nil) then
|
||||||
|
|
||||||
|
-- removed in version 9
|
||||||
|
-- regionMap.pQ = {{}} -- processing queue
|
||||||
|
-- regionMap.pI = 1 -- insertion location for chunk processing
|
||||||
|
-- regionMap.pP = 1 -- index for the chunk set to process
|
||||||
|
-- regionMap.pR = -1 -- current processing roll
|
||||||
|
natives.squads = {}
|
||||||
|
natives.scouts = {}
|
||||||
|
natives.tunnels = {}
|
||||||
|
natives.points = 0
|
||||||
|
|
||||||
|
global.version = constants.VERSION_5
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_9) then
|
||||||
|
|
||||||
|
-- remove version 5 references
|
||||||
|
regionMap.pQ = nil
|
||||||
|
regionMap.pI = nil
|
||||||
|
regionMap.pP = nil
|
||||||
|
regionMap.pR = nil
|
||||||
|
|
||||||
|
global.version = constants.VERSION_9
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_10) then
|
||||||
|
for _,squad in pairs(natives.squads) do
|
||||||
|
squad.frenzy = false
|
||||||
|
squad.frenzyPosition = {x=0,y=0}
|
||||||
|
squad.rabid = false
|
||||||
|
end
|
||||||
|
|
||||||
|
global.version = constants.VERSION_10
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_11) then
|
||||||
|
natives.state = constants.AI_STATE_AGGRESSIVE
|
||||||
|
natives.temperament = 0
|
||||||
|
-- needs to be on inner logic tick loop interval
|
||||||
|
natives.stateTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
||||||
|
natives.temperamentTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
||||||
|
|
||||||
|
global.version = constants.VERSION_11
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_12) then
|
||||||
|
for _,squad in pairs(natives.squads) do
|
||||||
|
squad.status = constants.SQUAD_GUARDING
|
||||||
|
squad.kamikaze = false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- reset ai build points due to error in earning points
|
||||||
|
natives.points = 0
|
||||||
|
|
||||||
|
global.version = constants.VERSION_12
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_13) then
|
||||||
|
-- switched over to tick event
|
||||||
|
regionMap.logicTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
||||||
|
regionMap.processTick = roundToNearest(game.tick + INTERVAL_PROCESS, INTERVAL_PROCESS)
|
||||||
|
|
||||||
|
-- used to rate limit the number of rally cries during a period of time
|
||||||
|
natives.rallyCries = MAX_RALLY_CRIES
|
||||||
|
|
||||||
|
global.version = constants.VERSION_13
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_14) then
|
||||||
|
game.map_settings.unit_group.member_disown_distance = 5
|
||||||
|
game.map_settings.unit_group.max_member_speedup_when_behind = 1.1
|
||||||
|
game.map_settings.unit_group.max_member_slowdown_when_ahead = 1.0
|
||||||
|
game.map_settings.unit_group.max_group_slowdown_factor = 0.9
|
||||||
|
|
||||||
|
game.surfaces[1].print("Rampant - Version 0.14.11")
|
||||||
|
global.version = constants.VERSION_14
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_16) then
|
||||||
|
|
||||||
|
natives.lastShakeMessage = 0
|
||||||
|
--remove version 14 retreat limit, it has been made redundant
|
||||||
|
natives.retreats = nil
|
||||||
|
|
||||||
|
game.map_settings.unit_group.max_group_radius = 20
|
||||||
|
|
||||||
|
game.surfaces[1].print("Rampant - Version 0.14.13")
|
||||||
|
global.version = constants.VERSION_16
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_18) then
|
||||||
|
|
||||||
|
natives.safeEntities = {}
|
||||||
|
natives.safeEntityName = {}
|
||||||
|
|
||||||
|
game.surfaces[1].print("Rampant - Version 0.15.5")
|
||||||
|
global.version = constants.VERSION_18
|
||||||
|
end
|
||||||
|
if (global.version < constants.VERSION_20) then
|
||||||
|
|
||||||
|
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
|
||||||
|
natives.aiNocturnalMode = settings.global["rampant-permanentNocturnal"].value
|
||||||
|
|
||||||
|
game.surfaces[1].print("Rampant - Version 0.15.8")
|
||||||
|
global.version = constants.VERSION_20
|
||||||
|
end
|
||||||
|
return starting ~= global.version
|
||||||
|
end
|
||||||
|
|
||||||
|
return upgrade
|
104
control.lua
104
control.lua
@ -1,5 +1,6 @@
|
|||||||
-- imports
|
-- imports
|
||||||
|
|
||||||
|
local upgrade = require("Upgrade")
|
||||||
local entityUtils = require("libs/EntityUtils")
|
local entityUtils = require("libs/EntityUtils")
|
||||||
local mapUtils = require("libs/MapUtils")
|
local mapUtils = require("libs/MapUtils")
|
||||||
local unitGroupUtils = require("libs/UnitGroupUtils")
|
local unitGroupUtils = require("libs/UnitGroupUtils")
|
||||||
@ -112,102 +113,10 @@ local function onModSettingsChange(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function onConfigChanged()
|
local function onConfigChanged()
|
||||||
if (global.version == nil) then
|
if upgrade.attempt(natives, regionMap) then
|
||||||
|
|
||||||
-- removed in version 9
|
|
||||||
-- regionMap.pQ = {{}} -- processing queue
|
|
||||||
-- regionMap.pI = 1 -- insertion location for chunk processing
|
|
||||||
-- regionMap.pP = 1 -- index for the chunk set to process
|
|
||||||
-- regionMap.pR = -1 -- current processing roll
|
|
||||||
natives.squads = {}
|
|
||||||
natives.scouts = {}
|
|
||||||
natives.tunnels = {}
|
|
||||||
natives.points = 0
|
|
||||||
pendingChunks = {}
|
|
||||||
|
|
||||||
global.version = constants.VERSION_5
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_9) then
|
|
||||||
|
|
||||||
-- remove version 5 references
|
|
||||||
regionMap.pQ = nil
|
|
||||||
regionMap.pI = nil
|
|
||||||
regionMap.pP = nil
|
|
||||||
regionMap.pR = nil
|
|
||||||
|
|
||||||
global.version = constants.VERSION_9
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_10) then
|
|
||||||
for _,squad in pairs(natives.squads) do
|
|
||||||
squad.frenzy = false
|
|
||||||
squad.frenzyPosition = {x=0,y=0}
|
|
||||||
squad.rabid = false
|
|
||||||
end
|
|
||||||
|
|
||||||
global.version = constants.VERSION_10
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_11) then
|
|
||||||
natives.state = constants.AI_STATE_AGGRESSIVE
|
|
||||||
natives.temperament = 0
|
|
||||||
-- needs to be on inner logic tick loop interval
|
|
||||||
natives.stateTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
|
||||||
natives.temperamentTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
|
||||||
|
|
||||||
global.version = constants.VERSION_11
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_12) then
|
|
||||||
for _,squad in pairs(natives.squads) do
|
|
||||||
squad.status = constants.SQUAD_GUARDING
|
|
||||||
squad.kamikaze = false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- reset ai build points due to error in earning points
|
|
||||||
natives.points = 0
|
|
||||||
|
|
||||||
global.version = constants.VERSION_12
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_13) then
|
|
||||||
-- switched over to tick event
|
|
||||||
regionMap.logicTick = roundToNearest(game.tick + INTERVAL_LOGIC, INTERVAL_LOGIC)
|
|
||||||
regionMap.processTick = roundToNearest(game.tick + INTERVAL_PROCESS, INTERVAL_PROCESS)
|
|
||||||
|
|
||||||
-- used to rate limit the number of rally cries during a period of time
|
|
||||||
natives.rallyCries = MAX_RALLY_CRIES
|
|
||||||
|
|
||||||
global.version = constants.VERSION_13
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_14) then
|
|
||||||
game.map_settings.unit_group.member_disown_distance = 5
|
|
||||||
game.map_settings.unit_group.max_member_speedup_when_behind = 1.1
|
|
||||||
game.map_settings.unit_group.max_member_slowdown_when_ahead = 1.0
|
|
||||||
game.map_settings.unit_group.max_group_slowdown_factor = 0.9
|
|
||||||
|
|
||||||
game.surfaces[1].print("Rampant - Version 0.14.11")
|
|
||||||
global.version = constants.VERSION_14
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_16) then
|
|
||||||
|
|
||||||
natives.lastShakeMessage = 0
|
|
||||||
--remove version 14 retreat limit, it has been made redundant
|
|
||||||
natives.retreats = nil
|
|
||||||
|
|
||||||
game.map_settings.unit_group.max_group_radius = 20
|
|
||||||
|
|
||||||
game.surfaces[1].print("Rampant - Version 0.14.13")
|
|
||||||
global.version = constants.VERSION_16
|
|
||||||
end
|
|
||||||
if (global.version < constants.VERSION_18) then
|
|
||||||
|
|
||||||
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)
|
onModSettingsChange(nil)
|
||||||
|
|
||||||
|
game.surfaces[1].print("Reindexing chunks, please wait")
|
||||||
-- clear old regionMap processing Queue
|
-- clear old regionMap processing Queue
|
||||||
-- prevents queue adding duplicate chunks
|
-- prevents queue adding duplicate chunks
|
||||||
-- chunks are by key, so should overwrite old
|
-- chunks are by key, so should overwrite old
|
||||||
@ -224,10 +133,7 @@ local function onConfigChanged()
|
|||||||
area = { left_top = { x = chunk.x * 32,
|
area = { left_top = { x = chunk.x * 32,
|
||||||
y = chunk.y * 32 }}})
|
y = chunk.y * 32 }}})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
game.surfaces[1].print("Rampant - Version 0.15.6")
|
|
||||||
global.version = constants.VERSION_19
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onTick(event)
|
local function onTick(event)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name" : "Rampant",
|
"name" : "Rampant",
|
||||||
"factorio_version" : "0.15",
|
"factorio_version" : "0.15",
|
||||||
"version" : "0.15.7",
|
"version" : "0.15.8",
|
||||||
"title" : "Rampant AI",
|
"title" : "Rampant AI",
|
||||||
"author" : "Veden",
|
"author" : "Veden",
|
||||||
"homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445",
|
"homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445",
|
||||||
|
@ -38,6 +38,10 @@ function aiPlanning.planning(natives, evolution_factor, tick, surface)
|
|||||||
maxPoints = maxPoints * 0.85
|
maxPoints = maxPoints * 0.85
|
||||||
end
|
end
|
||||||
if (natives.points < maxPoints) then
|
if (natives.points < maxPoints) then
|
||||||
|
-- check for ai points scaler being nil
|
||||||
|
if not natives.aiPointsScaler then
|
||||||
|
natives.aiPointsScaler = settings.global["rampant-aiPointsScaler"].value
|
||||||
|
end
|
||||||
natives.points = natives.points + math.floor((AI_POINT_GENERATOR_AMOUNT * math.random()) + ((AI_POINT_GENERATOR_AMOUNT * 0.7) * (evolution_factor ^ 2.5)) * natives.aiPointsScaler)
|
natives.points = natives.points + math.floor((AI_POINT_GENERATOR_AMOUNT * math.random()) + ((AI_POINT_GENERATOR_AMOUNT * 0.7) * (evolution_factor ^ 2.5)) * natives.aiPointsScaler)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ constants.VERSION_16 = 16
|
|||||||
constants.VERSION_17 = 17
|
constants.VERSION_17 = 17
|
||||||
constants.VERSION_18 = 18
|
constants.VERSION_18 = 18
|
||||||
constants.VERSION_19 = 19
|
constants.VERSION_19 = 19
|
||||||
|
constants.VERSION_20 = 20
|
||||||
|
|
||||||
-- misc
|
-- misc
|
||||||
|
|
||||||
|
6
make.rkt
6
make.rkt
@ -30,6 +30,7 @@
|
|||||||
(string->path "data-updates.lua")
|
(string->path "data-updates.lua")
|
||||||
(string->path "LICENSE.md")
|
(string->path "LICENSE.md")
|
||||||
(string->path "tests.lua")
|
(string->path "tests.lua")
|
||||||
|
(string->path "Upgrade.lua")
|
||||||
(string->path "settings.lua")
|
(string->path "settings.lua")
|
||||||
(string->path "README.md")
|
(string->path "README.md")
|
||||||
(string->path "NOTICE")
|
(string->path "NOTICE")
|
||||||
@ -66,6 +67,7 @@
|
|||||||
(copyFile "data.lua" modFolder)
|
(copyFile "data.lua" modFolder)
|
||||||
(copyFile "data-updates.lua" modFolder)
|
(copyFile "data-updates.lua" modFolder)
|
||||||
(copyFile "settings.lua" modFolder)
|
(copyFile "settings.lua" modFolder)
|
||||||
|
(copyFile "Upgrade.lua" modFolder)
|
||||||
(copyFile "tests.lua" modFolder)
|
(copyFile "tests.lua" modFolder)
|
||||||
(copyDirectory "libs" modFolder)
|
(copyDirectory "libs" modFolder)
|
||||||
(copyDirectory "locale" modFolder)
|
(copyDirectory "locale" modFolder)
|
||||||
@ -73,7 +75,7 @@
|
|||||||
(copyDirectory "prototypes" modFolder)))
|
(copyDirectory "prototypes" modFolder)))
|
||||||
|
|
||||||
(define (run)
|
(define (run)
|
||||||
;;(copyFiles modFolder)
|
(copyFiles modFolder)
|
||||||
(makeZip modFolder)
|
;;(makeZip modFolder)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user