Skip to content

Commit

Permalink
see readme
Browse files Browse the repository at this point in the history
  • Loading branch information
veden committed May 6, 2017
1 parent 8275393 commit 65aa977
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 219 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ Configure Options not in game menu:

# Version History

0.15.5 -
- Tweak: Increased ai refund from 2 to 3
- Fix: Signals, Chain Signals, and Train stops now correctly rebuild when the corresponding make safe is toggled
- Feature: Remote interfaces for adjusting wave size, thresholds, ai build points, ai state, player thresholds, and attack triggers
- Improvement: Added reactor, programmable speaker, radars, lights, and rocket silo to biter targets
- Improvement: Switched all configs to global runtime except Dumb projectiles and NE Unit Launcher Options

0.15.4 -
- Fixed: Changed setting name from "make buildings safe from biters" to "Enable building safety." This is to clarify what the setting does.
- Fix: Changed setting name from "make buildings safe from biters" to "Enable building safety." This is to clarify what the setting does.

0.15.3 -
- Improvement: Added configuration for safe buildings. This will be improved after a bug fix in factorio
Expand Down
16 changes: 3 additions & 13 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@ local config = {}
local mathUtils = require("libs/MathUtils")
local gaussianRandomRange = mathUtils.gaussianRandomRange

--[[
Causes buildings to regenerate and become untargetable after they are destroyed by biters
--]]
config.safeBuildings = settings.startup["rampant-safeBuildings"].value
config.safeEntities = {}
config.safeEntityName = {}
config.safeEntities["curved-rail"] = settings.startup["rampant-safeBuildings-curvedRail"].value
config.safeEntities["straight-rail"] = settings.startup["rampant-safeBuildings-straightRail"].value
config.safeEntityName["big-electric-pole"] = settings.startup["rampant-safeBuildings-bigElectricPole"].value

--[[
attackWaveScaling is used to calculate the attack wave size from the evolutionFactor
default is config.attackWaveMaxSize * (evolutionFactor ^ 1.666667)
default is natives.attackWaveMaxSize * (evolutionFactor ^ 1.666667)
DOES NOT affect vanilla biters waves
--]]
config.attackWaveScaling = function (evolutionFactor)
local attackWaveMaxSize = settings.startup["rampant-attackWaveMaxSize"].value
config.attackWaveScaling = function (evolutionFactor, natives)
local attackWaveMaxSize = natives.attackWaveMaxSize
return math.ceil(gaussianRandomRange(attackWaveMaxSize * (evolutionFactor ^ 1.66667),
(attackWaveMaxSize * 0.5) * 0.333,
1,
Expand Down
59 changes: 43 additions & 16 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ local aiAttack = require("libs/AIAttack")
local aiBuilding = require("libs/AIBuilding")
local aiPlanning = require("libs/AIPlanning")
local mathUtils = require("libs/MathUtils")
local interop = require("libs/Interop")
local tests = require("tests")
local config = require("config")

-- constants

local INTERVAL_LOGIC = constants.INTERVAL_LOGIC
local INTERVAL_PROCESS = constants.INTERVAL_PROCESS

local MAX_RALLY_CRIES = constants.MAX_RALLY_CRIES
local MAX_RETREATS = constants.MAX_RETREATS

local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE

Expand All @@ -43,8 +42,6 @@ local processPlayers = mapProcessor.processPlayers
local scanMap = mapProcessor.scanMap

local planning = aiPlanning.planning
-- local removeScout = aiBuilding.removeScout
-- local scouting = aiBuilding.scouting

local rallyUnits = aiBuilding.rallyUnits

Expand All @@ -60,7 +57,7 @@ local squadBeginAttack = aiAttack.squadBeginAttack
local retreatUnits = aiDefense.retreatUnits

local addRemoveEntity = entityUtils.addRemoveEntity
local makeImmortalEntity = entityUtils.makeImmortalEntity
--local makeImmortalEntity = entityUtils.makeImmortalEntity

local roundToNearest = mathUtils.roundToNearest

Expand All @@ -86,6 +83,32 @@ local function onChunkGenerated(event)
end
end

local function onModSettingsChange(event)

if event and (string.sub(event.setting, 1, 7) ~= "rampant") then
return
end

natives.safeBuildings = settings.global["rampant-safeBuildings"].value

natives.safeEntities["curved-rail"] = settings.global["rampant-safeBuildings-curvedRail"].value
natives.safeEntities["straight-rail"] = settings.global["rampant-safeBuildings-straightRail"].value
natives.safeEntities["rail-signal"] = settings.global["rampant-safeBuildings-railSignals"].value
natives.safeEntities["rail-chain-signal"] = settings.global["rampant-safeBuildings-railChainSignals"].value
natives.safeEntities["train-stop"] = settings.global["rampant-safeBuildings-trainStops"].value

natives.safeEntityName["big-electric-pole"] = settings.global["rampant-safeBuildings-bigElectricPole"].value

natives.attackUsePlayer = settings.global["rampant-attackWaveGenerationUsePlayerProximity"].value
natives.attackUsePollution = settings.global["rampant-attackWaveGenerationUsePollution"].value

natives.attackThresholdMin = settings.global["rampant-attackWaveGenerationThresholdMin"].value
natives.attackThresholdMax = settings.global["rampant-attackWaveGenerationThresholdMax"].value
natives.attackThresholdRange = natives.attackThresholdMax - natives.attackThresholdMin
natives.attackWaveMaxSize = settings.global["rampant-attackWaveMaxSize"].value
natives.attackPlayerThreshold = settings.global["rampant-attackPlayerThreshold"].value
end

local function onConfigChanged()
if (global.version == nil) then

Expand Down Expand Up @@ -171,7 +194,12 @@ local function onConfigChanged()
game.surfaces[1].print("Rampant - Version 0.14.13")
global.version = constants.VERSION_16
end
if (global.version < constants.VERSION_17) then
if (global.version < constants.VERSION_18) then

natives.safeEntities = {}
natives.safeEntityName = {}

onModSettingsChange(nil)

-- clear old regionMap processing Queue
-- prevents queue adding duplicate chunks
Expand All @@ -182,7 +210,6 @@ local function onConfigChanged()
-- clear pending chunks, will be added when loop runs below
pendingChunks = {}


-- queue all current chunks that wont be generated during play
local surface = game.surfaces[1]
for chunk in surface.get_chunks() do
Expand All @@ -191,8 +218,8 @@ local function onConfigChanged()
y = chunk.y * 32 }}})
end

game.surfaces[1].print("Rampant - Version 0.15.1")
global.version = constants.VERSION_17
game.surfaces[1].print("Rampant - Version 0.15.5")
global.version = constants.VERSION_18
end
end

Expand All @@ -212,16 +239,12 @@ local function onTick(event)

natives.rallyCries = MAX_RALLY_CRIES

natives.retreats = MAX_RETREATS

planning(natives, evolutionFactor, tick, surface)

regroupSquads(natives, evolutionFactor)

processPlayers(players, regionMap, surface, natives, evolutionFactor, tick)

-- scouting(regionMap, natives)

squadBeginAttack(natives, players, evolutionFactor)
squadAttack(regionMap, surface, natives)
end
Expand Down Expand Up @@ -287,7 +310,7 @@ local function onDeath(event)
local victoryChunk = getChunkByPosition(regionMap, entityPosition.x, entityPosition.y)
victoryScent(victoryChunk, entity.type)
end
if creditNatives and config.safeBuildings and (config.safeEntities[entity.type] or config.safeEntityName[entity.name]) then
if creditNatives and natives.safeBuildings and (natives.safeEntities[entity.type] or natives.safeEntityName[entity.name]) then
-- makeImmortalEntity(surface, entity)

-- patch (Needs to be removed)
Expand Down Expand Up @@ -337,6 +360,8 @@ end

script.on_init(onInit)
script.on_load(onLoad)
script.on_event(defines.events.on_runtime_mod_setting_changed,
onModSettingsChange)
script.on_configuration_changed(onConfigChanged)

script.on_event(defines.events.on_player_built_tile, onSurfaceTileChange)
Expand All @@ -352,7 +377,7 @@ script.on_event(defines.events.on_entity_died, onDeath)
script.on_event(defines.events.on_tick, onTick)
script.on_event(defines.events.on_chunk_generated, onChunkGenerated)

remote.add_interface("rampant", {
remote.add_interface("rampantTests", {
test1 = tests.test1,
test2 = tests.test2,
test3 = tests.test3,
Expand All @@ -363,5 +388,7 @@ remote.add_interface("rampant", {
test8 = tests.test8,
test9 = tests.test9,
test10 = tests.test10,
test11 = tests.test11
test11 = tests.test11
})

remote.add_interface("rampant", interop)
1 change: 0 additions & 1 deletion data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ require("prototypes/tile/fillableDirt")

require("prototypes/enemies/UnitSuicideBiters")
require("prototypes/enemies/UnitFireSpitters")

2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "Rampant",
"factorio_version" : "0.15",
"version" : "0.15.4",
"version" : "0.15.5",
"title" : "Rampant AI",
"author" : "Veden",
"homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445",
Expand Down
2 changes: 1 addition & 1 deletion libs/AIAttack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function aiAttack.squadBeginAttack(natives, players, evolution_factor)
for i=1,#squads do
local squad = squads[i]
if (squad.status == SQUAD_GUARDING) and squad.group.valid then
local kamikazeThreshold = calculateKamikazeThreshold(squad, evolution_factor)
local kamikazeThreshold = calculateKamikazeThreshold(squad, natives, evolution_factor)

local playerNearby = playersWithinProximityToPosition(players, squad.group.position, 100)
if playerNearby then
Expand Down
Loading

0 comments on commit 65aa977

Please sign in to comment.