From 55fb50e0ccba9a54f321a1d85d94bcf8c7b3799d Mon Sep 17 00:00:00 2001 From: kyranf Date: Mon, 16 Aug 2021 18:20:34 -0700 Subject: [PATCH] deployed v0.4.11 --- Changelist.txt | 12 ++++++- README.md | 4 +-- control.lua | 11 +++---- info.json | 2 +- migrations/robotarmy_0.4.11.lua | 55 +++++++++++++++++++++++++++++++++ prototypes/defender-unit.lua | 28 +++++++++++------ prototypes/destroyer-unit.lua | 16 ++++++++-- prototypes/distractor-unit.lua | 14 +++++++-- prototypes/entity.lua | 29 +++++++++++++++-- prototypes/recipe.lua | 5 +-- robolib/Squad.lua | 2 +- robolib/eventhandlers.lua | 28 ++++++++++++++--- 12 files changed, 173 insertions(+), 33 deletions(-) create mode 100644 migrations/robotarmy_0.4.11.lua diff --git a/Changelist.txt b/Changelist.txt index e53e12f..94c126d 100644 --- a/Changelist.txt +++ b/Changelist.txt @@ -17,4 +17,14 @@ changes from 0.4.8 to 0.4.9: - upgrading the version requirement of Unit Control (optional mod) to 3.10 for supporting the new API - fixes to how the mod uses the new Unit Control API for raising unit events from known deployers. - adding Guard Station to deployer supported for Unit Control - - reducing how/when the guard and assembler stations try to run logic when spawning units while Unit Control is active. Basically all droid processing is halted. \ No newline at end of file + - reducing how/when the guard and assembler stations try to run logic when spawning units while Unit Control is active. Basically all droid processing is halted. + + changes from 0.4.9 to 0.4.10: + - if unit control is active, don't run the runtime logic for assemblers squad management/merging/retreat and assembler-centric targetting, + and don't run the squad logic at all. This should help in-progress games which add unit control halfway through. + - added ai_settings to all droid units and flying units to try to prevent units from being deleted if they fail a command, and for them to attempt to spread out from eachother and not stack up. + + changes from 0.4.10 to 0.4.11: + - added a for-each-force loop instead of specific forces, during init routine to set up each force + - added a handleOnScriptRaisedBuilt function for script-spawned entity event handling. + - adding migration file to help players who add mod after starting game to auto detect existing techs and unlock recipes properly for them. \ No newline at end of file diff --git a/README.md b/README.md index 2dd91f6..54e60dd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Robot Army mod for Factorio V1.1+ ## Version -0.4.9, -Known to be compatible with Factorio v1.1.37. Requires at least v1.1.1 due to mod script API changes and tech name changes. +0.4.11, +Known to be compatible with Factorio v1.1.37. Requires at least v1.1.5 due to mod script API changes and tech name changes. ## Description diff --git a/control.lua b/control.lua index 2e45927..1e7fff7 100644 --- a/control.lua +++ b/control.lua @@ -50,12 +50,10 @@ function init_robotarmy() --deal with player force as default set-up process event = {} --event stub, to match function inputs - event.force = game.forces["player"] - handleForceCreated(event) - event.force = game.forces["enemy"] - handleForceCreated(event) - event.force = game.forces["neutral"] - handleForceCreated(event) + for _, v in pairs(game.forces) do + event.force = v + handleForceCreated(event) + end LOGGER.log("Robot Army mod Init script finished...") game.print("Robot Army mod Init completed!") end @@ -66,6 +64,7 @@ script.on_init(init_robotarmy) script.on_event(defines.events.on_force_created, handleForceCreated) script.on_event(defines.events.on_built_entity, handleOnBuiltEntity) script.on_event(defines.events.on_robot_built_entity, handleOnRobotBuiltEntity) +script.on_event(defines.events.script_raised_built, handleOnScriptRaisedBuilt) function playerSelectedArea(event) reportSelectedUnits(event, false) diff --git a/info.json b/info.json index b94e533..8931f51 100644 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "name": "robotarmy", - "version": "0.4.9", + "version": "0.4.11", "title": "Robot Army", "author": "Kyranzor", "contact": "kyranzor@gmail.com", diff --git a/migrations/robotarmy_0.4.11.lua b/migrations/robotarmy_0.4.11.lua new file mode 100644 index 0000000..0022d9b --- /dev/null +++ b/migrations/robotarmy_0.4.11.lua @@ -0,0 +1,55 @@ +require("config.config") +game.reload_script() + + +--ensure all force-specific tables and researches are handled/created +for i, force in pairs(game.forces) do + force.reset_recipes() + force.reset_technologies() + + --force all of the known recipes to be enabled if the appropriate research is already done. + if force.technologies["military"].researched then + force.recipes["droid-rifle"].enabled=true + force.recipes["droid-rifle-deploy"].enabled=true + if(GRAB_ARTIFACTS == 1) then + force.recipes["loot-chest"].enabled=true + end + force.recipes["patrol-pole"].enabled=true + force.recipes["droid-guard-station"].enabled=true + force.recipes["droid-assembling-machine"].enabled=true + force.recipes["droid-pickup-tool"].enabled=true + force.recipes["droid-selection-tool"].enabled=true + force.recipes["droid-counter"].enabled=true + force.recipes["droid-settings"].enabled = true + end + + + if force.technologies["military-2"].researched then + force.recipes["droid-smg"].enabled=true + force.recipes["droid-smg-deploy"].enabled=true + force.recipes["droid-rocket"].enabled=true + force.recipes["droid-rocket-deploy"].enabled=true + force.recipes["droid-flame"].enabled=true + force.recipes["droid-flame-deploy"].enabled=true + end + + if force.technologies["military-3"].researched then + force.recipes["terminator"].enabled=true + force.recipes["terminator-deploy"].enabled=true + end + + if force.technologies["defender"].researched then + force.recipes["defender-unit"].enabled=true + force.recipes["defender-unit-deploy"].enabled=true + end + + if force.technologies["distractor"].researched then + force.recipes["distractor-unit"].enabled=true + force.recipes["distractor-unit-deploy"].enabled=true + end + if force.technologies["destroyer"].researched then + force.recipes["destroyer-unit"].enabled=true + force.recipes["destroyer-unit-deploy"].enabled=true + end + +end \ No newline at end of file diff --git a/prototypes/defender-unit.lua b/prototypes/defender-unit.lua index 6d8e676..5710a04 100644 --- a/prototypes/defender-unit.lua +++ b/prototypes/defender-unit.lua @@ -1,14 +1,14 @@ require("config.config") data:extend({ { - type = "unit", - name = "defender-unit", - icon_size = 32, - icon = "__base__/graphics/icons/defender.png", - flags = {"placeable-player", "player-creation", "placeable-off-grid"}, - subgroup="creatures", - has_belt_immunity = true, - max_health = 65 * HEALTH_SCALAR, + type = "unit", + name = "defender-unit", + icon_size = 32, + icon = "__base__/graphics/icons/defender.png", + flags = {"placeable-player", "player-creation", "placeable-off-grid"}, + subgroup="creatures", + has_belt_immunity = true, + max_health = 65 * HEALTH_SCALAR, minable = {hardness = 0.1, mining_time = 0.1, result = "defender-unit"}, alert_when_damaged = false, order="b-b-a", @@ -17,7 +17,12 @@ data:extend({ { type = "physical", decrease = 4, - } + }, + { + type = "acid", + decrease = 1, + percent = 30 + }, }, healing_per_tick = 0, collision_box = nil, @@ -26,6 +31,11 @@ data:extend({ sticker_box = {{-0.1, -0.1}, {0.1, 0.1}}, distraction_cooldown = 300, + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, attack_parameters = { diff --git a/prototypes/destroyer-unit.lua b/prototypes/destroyer-unit.lua index 2363f4c..2ab8b32 100644 --- a/prototypes/destroyer-unit.lua +++ b/prototypes/destroyer-unit.lua @@ -16,8 +16,13 @@ data:extend({ { { type = "physical", - decrease = 4, - } + decrease = 8, + }, + { + type = "acid", + decrease = 5, + percent = 70 + }, }, healing_per_tick = 0, collision_box = {{0, 0}, {0, 0}}, @@ -25,7 +30,12 @@ data:extend({ sticker_box = {{-0.1, -0.1}, {0.1, 0.1}}, distraction_cooldown = 300, - + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, + attack_parameters = { type = "beam", diff --git a/prototypes/distractor-unit.lua b/prototypes/distractor-unit.lua index 1e31ba4..5d591d2 100644 --- a/prototypes/distractor-unit.lua +++ b/prototypes/distractor-unit.lua @@ -17,14 +17,24 @@ data:extend({ { type = "physical", decrease = 4, - } + }, + { + type = "acid", + decrease = 1, + percent = 30 + }, }, healing_per_tick = 0, collision_box = {{0, 0}, {0, 0}}, selection_box = {{-0.3, -0.3}, {0.3, 0.3}}, sticker_box = {{-0.1, -0.1}, {0.1, 0.1}}, distraction_cooldown = 300, - + + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, attack_parameters = { diff --git a/prototypes/entity.lua b/prototypes/entity.lua index dbf2311..88d95fc 100644 --- a/prototypes/entity.lua +++ b/prototypes/entity.lua @@ -120,6 +120,11 @@ local droid_smg = vision_distance = 30, radar_range = 1, can_open_gates = true, + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, movement_speed = 0.11, minable = {hardness = 0.1, mining_time = 0.1, result = "droid-smg"}, pollution_to_join_attack = 0.0, @@ -144,9 +149,9 @@ local droid_smg = decrease = 1, percent = 30 }, - { + { type = "fire", - decrease = 5, + decrease = 5, percent = 95 } }, @@ -296,6 +301,11 @@ local droid_flame = vision_distance = 30, radar_range = 1, can_open_gates = true, + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, movement_speed = 0.09, minable = {hardness = 0.1, mining_time = 0.1, result = "droid-flame"}, pollution_to_join_attack = 0.0, @@ -480,6 +490,11 @@ local droid_rifle = vision_distance = 30, radar_range = 1, can_open_gates = true, + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, movement_speed = 0.08, friendly_map_color = droidMapColour, minable = {hardness = 0.1, mining_time = 0.1, result = "droid-rifle"}, @@ -659,6 +674,11 @@ local droid_rocket = vision_distance = 30, radar_range = 1, can_open_gates = true, + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, friendly_map_color = droidMapColour, movement_speed = 0.11, minable = {hardness = 0.1, mining_time = 0.1, result = "droid-rocket"}, @@ -823,6 +843,11 @@ local terminator = vision_distance = 30, radar_range = 1, can_open_gates = true, + ai_settings = + { + allow_destroy_when_commands_fail = false, + do_separation = true + }, movement_speed = 0.18, minable = {hardness = 0.1, mining_time = 0.1, result = "terminator"}, pollution_to_join_attack = 0.0, diff --git a/prototypes/recipe.lua b/prototypes/recipe.lua index affed17..6add797 100644 --- a/prototypes/recipe.lua +++ b/prototypes/recipe.lua @@ -340,6 +340,8 @@ table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",re table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-guard-station"}) table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-selection-tool"}) table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-pickup-tool"}) +table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-counter"}) +table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-settings"}) table.insert(data.raw["technology"]["military-2"].effects,{type="unlock-recipe",recipe="droid-smg-deploy"}) table.insert(data.raw["technology"]["military-2"].effects,{type="unlock-recipe",recipe="droid-smg"}) @@ -351,8 +353,7 @@ table.insert(data.raw["technology"]["military-2"].effects,{type="unlock-recipe", table.insert(data.raw["technology"]["military-3"].effects,{type="unlock-recipe",recipe="terminator-deploy"}) table.insert(data.raw["technology"]["military-3"].effects,{type="unlock-recipe",recipe="terminator"}) -table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-counter"}) -table.insert(data.raw["technology"]["military"].effects,{type="unlock-recipe",recipe="droid-settings"}) + table.insert(data.raw["technology"]["defender"].effects,{type="unlock-recipe", recipe="defender-unit"}) table.insert(data.raw["technology"]["defender"].effects,{type="unlock-recipe", recipe="defender-unit-deploy"}) diff --git a/robolib/Squad.lua b/robolib/Squad.lua index 38120d0..3230299 100644 --- a/robolib/Squad.lua +++ b/robolib/Squad.lua @@ -823,7 +823,7 @@ function orderSquadToAttack(squad, position) debugSquadOrder(squad, "*ATTACK*", position) squad.unitGroup.set_command({type=defines.command.attack_area, destination=position, - radius=50, distraction=defines.distraction.by_anything}) + radius=2, distraction=defines.distraction.by_anything}) squad.command.state_changed_since_last_command = false squad.command.tick = game.tick squad.unitGroup.start_moving() diff --git a/robolib/eventhandlers.lua b/robolib/eventhandlers.lua index 68f0c34..2406e6c 100644 --- a/robolib/eventhandlers.lua +++ b/robolib/eventhandlers.lua @@ -370,14 +370,17 @@ function tickForces(forces, tick) processDroidAssemblers(force) processDroidGuardStations(force) end - processDroidAssemblersForTick(force, tick) - processSquadUpdatesForTick(force.name, tick % 60 + 1) - + + if not game.active_mods["Unit_Control"] then + processDroidAssemblersForTick(force, tick) + processSquadUpdatesForTick(force.name, tick % 60 + 1) + updateSelectionCircles(force) + end if tick % 1200 == 0 then log_session_statistics(force) end - updateSelectionCircles(force) + end end @@ -460,6 +463,23 @@ function handleOnRobotBuiltEntity(event) end end -- handleOnRobotBuiltEntity +function handleOnScriptRaisedBuilt(event) + local entity = event.entity + event.created_entity = event.entity + if(entity.name == "droid-assembling-machine") then + handleDroidAssemblerPlaced(event) + elseif(entity.name == "droid-guard-station") then + handleGuardStationPlaced(event) + elseif(entity.name == "droid-counter") then + handleBuiltDroidCounter(event) + elseif(entity.name == "droid-settings") then + handleBuiltDroidSettings(event) + elseif entity.name == "rally-beacon" then + handleBuiltRallyBeacon(event) + elseif entity.name == "loot-chest" then + handleBuiltLootChest(event) + end +end -- handleOnScriptRaisedBuilt -- MAIN ENTRY POINT IN-GAME -- during the on-tick event, lets check if we need to update squad AI, spawn droids from assemblers, or update bot counters, etc