From 14b2270bdd52ecc8185ed06436d99e5195d33af5 Mon Sep 17 00:00:00 2001 From: Aaron Veden Date: Thu, 19 Jan 2023 20:43:41 -0800 Subject: [PATCH] a498fd7: Fixed /rampantSetAIState command around invalid or missing parameters --- changelog.txt | 1 + control.lua | 20 +++++++++++--------- libs/AIPlanning.lua | 4 ++-- libs/Constants.lua | 14 +++++++------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/changelog.txt b/changelog.txt index 5b049d8..13eff84 100644 --- a/changelog.txt +++ b/changelog.txt @@ -51,6 +51,7 @@ Version: 3.2.0 - Fixed projectiles not being able to collide with spawner eggs and wasps - Fixed bases being able to mutate to the same factions - Fixed players disconnecting on multiplayer could leave residual player pheromone that never dissipated + - Fixed /rampantSetAIState command could error if not provide correct parameters or didn't display a message if parameters were missing Optimizations: - Moved most constants out of global - Removed new enemy variations setting diff --git a/control.lua b/control.lua index b630b7e..07d5626 100644 --- a/control.lua +++ b/control.lua @@ -1344,29 +1344,31 @@ local function rampantSetAIState(event) end end - if target ~= constants.BASE_AI_STATE_PEACEFUL and - target ~= constants.BASE_AI_STATE_AGGRESSIVE and - target ~= constants.BASE_AI_STATE_RAIDING and - target ~= constants.BASE_AI_STATE_MIGRATING and - target ~= constants.BASE_AI_STATE_SIEGE and - target ~= constants.BASE_AI_STATE_ONSLAUGHT - then + if not target or not constants.STATE_ENGLISH[target] then game.print(target .. " is not a valid state. /rampantSetAIState ") - return else + if not baseId then + game.print("Invalid baseId. /rampantSetAIState ") + return + end local base = universe.bases[baseId] if not base then game.print(baseId .. " is not a valid base. /rampantSetAIState ") return end + local previousState = base.stateAI base.stateAI = target local surface = base.map.surface if not surface.valid then game.print("Base is invalid because surface is invalid") return end - game.print("id:" .. baseId .. " on surface:" .. surface.name .. " is now in " .. constants.stateEnglish[base.stateAI]) + game.print("id:" .. baseId .. " on surface:" .. surface.name + .. " was in " .. constants.STATE_ENGLISH[previousState] + .. " is now in " .. constants.STATE_ENGLISH[base.stateAI]) end + else + game.print("Missing parameters: /rampantSetAIState ") end end diff --git a/libs/AIPlanning.lua b/libs/AIPlanning.lua index 5c02105..a8dfbce 100644 --- a/libs/AIPlanning.lua +++ b/libs/AIPlanning.lua @@ -359,7 +359,7 @@ local function temperamentPlanner(base, evolutionLevel) base.builtEnemyBuilding .. ", iCB:" .. base.ionCannonBlasts .. ", aB:" .. base.artilleryBlasts .. ", temp:" .. base.temperament .. ", tempScore:" .. base.temperamentScore .. ", points:" .. base.points .. ", unitPoints:" .. base.unitPoints .. ", state:" .. - constants.stateEnglish[base.stateAI] .. ", surface:" .. base.map.surface.index .. " [" .. + constants.STATE_ENGLISH[base.stateAI] .. ", surface:" .. base.map.surface.index .. " [" .. base.map.surface.name .. "]" .. ", aS:" .. universe.squadCount .. ", aB:" .. universe.builderCount .. ", atkSize:" .. universe.attackWaveSize .. ", stlSize:" .. universe.settlerWaveSize .. ", formGroup:" .. universe.formSquadThreshold .. ", sAgg:".. base.sentAggressiveGroups .. @@ -555,7 +555,7 @@ local function processState(universe, base, tick) base.stateAITick = randomTickEvent(universe.random, tick, BASE_AI_MIN_STATE_DURATION, BASE_AI_MAX_STATE_DURATION) if universe.printAIStateChanges then - game.print(base.id .. ": AI is now: " .. constants.stateEnglish[base.stateAI] .. ", Next state change is in " + game.print(base.id .. ": AI is now: " .. constants.STATE_ENGLISH[base.stateAI] .. ", Next state change is in " .. string.format("%.2f", (base.stateAITick - tick) / (60*60)) .. " minutes @ " .. getTimeStringFromTick(base.stateAITick) .. " playtime") end diff --git a/libs/Constants.lua b/libs/Constants.lua index 232d4ec..9e81c13 100644 --- a/libs/Constants.lua +++ b/libs/Constants.lua @@ -117,13 +117,13 @@ constants.BASE_AI_STATE_MIGRATING = 5 constants.BASE_AI_STATE_SIEGE = 6 constants.BASE_AI_STATE_ONSLAUGHT = 7 -constants.stateEnglish = {} -constants.stateEnglish[constants.BASE_AI_STATE_PEACEFUL] = "AI_STATE_PEACEFUL" -constants.stateEnglish[constants.BASE_AI_STATE_AGGRESSIVE] = "AI_STATE_AGGRESSIVE" -constants.stateEnglish[constants.BASE_AI_STATE_RAIDING] = "AI_STATE_RAIDING" -constants.stateEnglish[constants.BASE_AI_STATE_MIGRATING] = "AI_STATE_MIGRATING" -constants.stateEnglish[constants.BASE_AI_STATE_SIEGE] = "AI_STATE_SIEGE" -constants.stateEnglish[constants.BASE_AI_STATE_ONSLAUGHT] = "AI_STATE_ONSLAUGHT" +constants.STATE_ENGLISH = {} +constants.STATE_ENGLISH[constants.BASE_AI_STATE_PEACEFUL] = "AI_STATE_PEACEFUL" +constants.STATE_ENGLISH[constants.BASE_AI_STATE_AGGRESSIVE] = "AI_STATE_AGGRESSIVE" +constants.STATE_ENGLISH[constants.BASE_AI_STATE_RAIDING] = "AI_STATE_RAIDING" +constants.STATE_ENGLISH[constants.BASE_AI_STATE_MIGRATING] = "AI_STATE_MIGRATING" +constants.STATE_ENGLISH[constants.BASE_AI_STATE_SIEGE] = "AI_STATE_SIEGE" +constants.STATE_ENGLISH[constants.BASE_AI_STATE_ONSLAUGHT] = "AI_STATE_ONSLAUGHT" constants.BASE_GENERATION_STATE_DORMANT = 0 constants.BASE_GENERATION_STATE_ACTIVE = 1