From 471c6fe62df25e4b6da103c321129b9d3fef05a3 Mon Sep 17 00:00:00 2001 From: Aaron Veden Date: Thu, 1 Jun 2017 00:03:07 -0700 Subject: [PATCH] working ion cannon reaction --- README.md | 2 ++ Upgrade.lua | 3 ++- config.lua | 5 +++++ control.lua | 43 ++++++++++++++++++++++++++++++++++++++--- data-updates.lua | 4 ++-- info.json | 2 +- libs/AIAttack.lua | 1 + libs/Constants.lua | 3 ++- libs/UnitGroupUtils.lua | 7 ++++--- tests.lua | 2 +- 10 files changed, 60 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e4a9493..14da380 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Configure Options not in game menu: - No Homing Projectiles - All projectiles are fired at locations and no longer track the player - Pathfinding - Unit groups will use potential fields to perform only single step pathfinding allowing for efficient and dynamic pathing - Peace mode - If something sets peace mode, Rampant will respect it +- Ion Cannon Reaction - When using the Ion Cannon Mod, biters will # Planned Features @@ -56,6 +57,7 @@ Configure Options not in game menu: # Version History 0.15.11 - +- Feature: Ion cannon mod integration - Fixed: Player region scan can no longer overlap passive map scan causing double processing - Tweak: Increased rally cry chance from 0.02(@100 evo) to 0.08(@100 evo) compensate for the once per logic cycle per chunk - Improvement: Changed biter base detection from slow map scan to event diff --git a/Upgrade.lua b/Upgrade.lua index 34b46b2..2d3a321 100644 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -88,7 +88,7 @@ function upgrade.attempt(natives, regionMap) --[[ For making changes to maps that haven't had Rampant loaded and aren't starting from a brand new map - Was causing desyncs when client connected before having the below settings saved into the map + Was causing desyncs when client connected before having the below settings saved into the map 0.15.15 factorio --]] local mapSettings = game.map_settings @@ -124,6 +124,7 @@ function upgrade.attempt(natives, regionMap) natives.unitRefundAmount = 0 natives.attackWaveThreshold = 0 + -- used for breaking up how many squads are processing per logic cycle natives.regroupIndex = 1 natives.useCustomAI = settings.startup["rampant-useCustomAI"].value diff --git a/config.lua b/config.lua index d56b18f..a7ecafb 100644 --- a/config.lua +++ b/config.lua @@ -9,6 +9,11 @@ local mathUtils = require("libs/MathUtils") local gaussianRandomRange = mathUtils.gaussianRandomRange local mCeil = math.ceil + +-- automatic mod detection + +config.ionCannonPresent = settings.startup["ion-cannon-radius"] ~= nil + -- configurations --[[ diff --git a/control.lua b/control.lua index 75bd874..f486450 100644 --- a/control.lua +++ b/control.lua @@ -17,6 +17,7 @@ local tests = require("tests") local upgrade = require("Upgrade") local baseUtils = require("libs/BaseUtils") local mathUtils = require("libs/MathUtils") +local config = require("config") -- constants @@ -25,6 +26,8 @@ local INTERVAL_PROCESS = constants.INTERVAL_PROCESS local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE +local AI_MAX_OVERFLOW_POINTS = constants.AI_MAX_OVERFLOW_POINTS + -- imported functions local roundToNearest = mathUtils.roundToNearest @@ -192,9 +195,9 @@ local function onTick(event) processPlayers(players, regionMap, surface, natives, tick) - -- if (natives.useCustomAI) then - -- processBases(regionMap, surface, natives, tick) - -- end + if natives.useCustomAI then + processBases(regionMap, surface, natives, tick) + end squadBeginAttack(natives, players) squadAttack(regionMap, surface, natives) @@ -218,6 +221,33 @@ local function onPickUp(event) addRemovePlayerEntity(regionMap, event.entity, natives, false, false) end +local function onIonCannonFired(event) + --[[ + event.force, event.surface, event.player_index, event.position, event.radius + --]] + local surface = event.surface + if (surface.index == 1) then + natives.points = natives.points + 3000 + if (natives.points > AI_MAX_OVERFLOW_POINTS) then + natives.points = AI_MAX_OVERFLOW_POINTS + end + local chunk = getChunkByPosition(regionMap, event.position.x, event.position.y) + if chunk then + local tempNeighbors = {false, false, false, false, false, false, false, false} + rallyUnits(chunk, + regionMap, + surface, + natives, + event.tick, + tempNeighbors) + end + end +end + +-- local function onIonCannonTargeted(event) + +-- end + local function onDeath(event) local entity = event.entity local surface = entity.surface @@ -307,6 +337,13 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, onModSettingsChange) script.on_configuration_changed(onConfigChanged) +if config.ionCannonPresent then + script.on_event(remote.call("orbital_ion_cannon", "on_ion_cannon_fired"), + onIonCannonFired) + -- script.on_event(remote.call("orbital_ion_cannon", "on_ion_cannon_targeted"), + -- onIonCannonTargeted) +end + script.on_event(defines.events.on_player_built_tile, onSurfaceTileChange) script.on_event(defines.events.on_biter_base_built, diff --git a/data-updates.lua b/data-updates.lua index b32d0e0..60a3b32 100644 --- a/data-updates.lua +++ b/data-updates.lua @@ -4,11 +4,11 @@ local NEUpdates = require("prototypes/enemies/UpdatesNE") local constants = require("libs/Constants") local function bobsDetected() - return data.raw["turret"]["bob-big-explosive-worm-turret"] ~= nil + return settings.startup["bobmods-enemies-aliensdropartifacts"] ~= nil end local function NEDetected() - return data.raw["unit"]["medium-spitter-Mk3"] ~= nil + return settings.startup["NE_Difficulty"] ~= nil end if settings.startup["rampant-useDumbProjectiles"].value then diff --git a/info.json b/info.json index 08890fc..48e70b9 100644 --- a/info.json +++ b/info.json @@ -6,5 +6,5 @@ "author" : "Veden", "homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445", "description" : "Improves the enemies tactics by using potential fields/pheromones allowing probing of defenses, retreats, reinforcements, counterattacking, breaching, rallying death cry, and player hunting. Also removes homing biter projectiles. Difficulty setting in mod options menu.", - "dependencies" : ["base >= 0.13.17", "? bobenemies", "? Natural_Evolution_Enemies", "? DayNightExtender"] + "dependencies" : ["base >= 0.13.17", "? bobenemies", "? Natural_Evolution_Enemies", "? DayNightExtender", "? Orbital Ion Cannon"] } diff --git a/libs/AIAttack.lua b/libs/AIAttack.lua index 722cb71..648057f 100644 --- a/libs/AIAttack.lua +++ b/libs/AIAttack.lua @@ -72,6 +72,7 @@ function aiAttack.squadAttack(regionMap, surface, natives) radius = 28, distraction = DEFINES_DISTRACTION_BY_ENEMY } end + for i=1,#squads do local squad = squads[i] local group = squad.group diff --git a/libs/Constants.lua b/libs/Constants.lua index e72fcb1..1cb3f8b 100644 --- a/libs/Constants.lua +++ b/libs/Constants.lua @@ -55,12 +55,13 @@ constants.AI_TUNNEL_COST = 100 constants.AI_MAX_POINTS = 10000 constants.AI_MAX_OVERFLOW_POINTS = constants.AI_MAX_POINTS * 3 - constants.AI_UNIT_REFUND = 3 constants.AI_MAX_SQUAD_COUNT = 40 constants.AI_MAX_BITER_GROUP_SIZE = 450 +constants.AI_SQUAD_MERGE_THRESHOLD = constants.AI_MAX_BITER_GROUP_SIZE * 0.75 + constants.AI_STATE_PEACEFUL = 1 constants.AI_STATE_AGGRESSIVE = 2 constants.AI_STATE_NOCTURNAL = 3 diff --git a/libs/UnitGroupUtils.lua b/libs/UnitGroupUtils.lua index 23d439f..aa4c436 100644 --- a/libs/UnitGroupUtils.lua +++ b/libs/UnitGroupUtils.lua @@ -26,6 +26,7 @@ local NO_RETREAT_SQUAD_SIZE_BONUS_MAX = constants.NO_RETREAT_SQUAD_SIZE_BONUS_MA local AI_MAX_OVERFLOW_POINTS = constants.AI_MAX_OVERFLOW_POINTS local AI_MAX_BITER_GROUP_SIZE = constants.AI_MAX_BITER_GROUP_SIZE +local AI_SQUAD_MERGE_THRESHOLD = constants.AI_SQUAD_MERGE_THRESHOLD -- imported functions @@ -152,8 +153,8 @@ function unitGroupUtils.cleanSquads(natives) local weight = natives.unitRefundAmount local cleanSquads = {} - - for i=1,squadCount do + + for i=1, squadCount do local squad = squads[i] local group = squad.group if group.valid then @@ -196,7 +197,7 @@ end function unitGroupUtils.regroupSquads(natives) - local groupThreshold = AI_MAX_BITER_GROUP_SIZE * 0.75 + local groupThreshold = AI_SQUAD_MERGE_THRESHOLD local squads = natives.squads local squadCount = #squads diff --git a/tests.lua b/tests.lua index 942a761..2f38dac 100644 --- a/tests.lua +++ b/tests.lua @@ -42,7 +42,7 @@ function tests.activeSquads() for i=1, #global.natives.squads do local squad = global.natives.squads[i] if squad.group.valid then - print(math.floor(squad.group.position.x * 0.03125), math.floor(squad.group.position.y * 0.03125), squad.status, squad.group.state) + print(math.floor(squad.group.position.x * 0.03125), math.floor(squad.group.position.y * 0.03125), squad.status, squad.group.state, #squad.group.members) print(serpent.dump(squad)) end end