From 081e86e3ce19902ca71dc5664892b401ff471559 Mon Sep 17 00:00:00 2001 From: kyranf Date: Mon, 18 Oct 2021 11:48:21 -0700 Subject: [PATCH] fixing 2 bugs and migration issue attempting to fix github issue #164 attempting to fix github issue #172 fixing migration script issue with the 0.4.12 migration where it would chew up peoples RAM and break their computers. made it do +-1000 tiles instead of +-15000 tiles for each surface, and each force. --- Changelist.txt | 6 +++++- README.md | 4 ++-- info.json | 2 +- migrations/robotarmy_0.4.12.lua | 8 ++++++-- robolib/Squad.lua | 14 +++++++++++++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Changelist.txt b/Changelist.txt index 7a1c61f..932af77 100644 --- a/Changelist.txt +++ b/Changelist.txt @@ -34,4 +34,8 @@ changes from 0.4.8 to 0.4.9: - added Russian language translations thanks to Varoga on Github - added migration script to detect and add all droid units to script-tracked array - added AI distraction custom commands for selecting nearest target instead of random target (overriding default ai behaviour of biters) thanks to Klonan - \ No newline at end of file + +changes from 0.4.12 to 0.4.13: + - attempting to fix github issue #164 + - attempting to fix github issue #172 + - fixing migration script issue with the 0.4.12 migration where it would chew up peoples RAM and break their computers. made it do +-1000 tiles instead of +-15000 tiles for each surface, and each force. diff --git a/README.md b/README.md index 8b65460..9bcfbce 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Robot Army mod for Factorio V1.1+ ## Version -0.4.12, -Known to be compatible with Factorio v1.1.38. Requires at least v1.1.38 due to mod script API features used. +0.4.13, +Known to be compatible with Factorio v1.1.42. Requires at least v1.1.38 due to mod script API features used. ## Description diff --git a/info.json b/info.json index a48579e..4913284 100644 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "name": "robotarmy", - "version": "0.4.12", + "version": "0.4.13", "title": "Robot Army", "author": "Kyranzor", "contact": "kyranzor@gmail.com", diff --git a/migrations/robotarmy_0.4.12.lua b/migrations/robotarmy_0.4.12.lua index 189e415..8a413aa 100644 --- a/migrations/robotarmy_0.4.12.lua +++ b/migrations/robotarmy_0.4.12.lua @@ -15,6 +15,10 @@ end local numUnitsAdded = 0; + + +Game.print_all(string.format("Robot army processing %d forces, in %d surfaces", #game.forces, #game.surfaces)) + --ensure all force-specific tables and researches are handled/created for i, force_ in pairs(game.forces) do -- for each force @@ -22,7 +26,7 @@ for i, force_ in pairs(game.forces) do -- get the list of units -- for each unit in the list, check the type and name is what we want, add to the list. - local units = surface_.find_units({area = {{-15000, -15000},{15000, 15000}}, force = force_.name, condition = "same"}) + local units = surface_.find_units({area = {{-1000, -1000},{1000, 1000}}, force = force_.name, condition = "same"}) for _, unitFound in pairs(units) do if names[unitFound.name] then if unitFound.valid then @@ -37,4 +41,4 @@ for i, force_ in pairs(game.forces) do end end -Game.print_all(string.format("units added in migration script: %d", numUnitsAdded)) \ No newline at end of file +Game.print_all(string.format("units added in robot army migration script: %d", numUnitsAdded)) \ No newline at end of file diff --git a/robolib/Squad.lua b/robolib/Squad.lua index 3230299..22b867c 100644 --- a/robolib/Squad.lua +++ b/robolib/Squad.lua @@ -234,6 +234,8 @@ end function shouldHunt(squad) + if not squad then return false end + return (squad.command.type ~= commands.follow) and (squad.numMembers >= getSquadHuntSize(squad.force) or (squad.command.type == commands.hunt and squad.numMembers > getSquadRetreatSize(squad.force))) end @@ -623,10 +625,20 @@ function validateSquadIntegrity(squad) squad.unitGroupFailureTick = game.tick end + + --do another check for the unit group being valid before doing the next steps + if not squad.unitGroup or not squad.unitGroup.valid then + squad.unitGroup = recreateUnitGroupForSquad(squad, pos) + end + + if not squad.unitGroup or not squad.unitGroup.valid then + return nil, false --give up + end + -- check each droid individually to confirm that it is part of the unitGroup for key, soldier in pairs(squad.members) do if soldier and soldier.valid and (soldier.force ~= squad.unitGroup.force) then - soldier.destroy() + soldier.destroy() --destroy the unit if they are in the squad but of the wrong force... maybe this needs more finesse, if a mod has some kind of AOE2 monk team-changing ability? else if not table.contains(squad.unitGroup.members, soldier) then if not recreatedUG then