mirror of
https://github.com/veden/Rampant.git
synced 2024-12-30 21:19:46 +02:00
added versioning and on config change
This commit is contained in:
parent
d40ea6fd3d
commit
acfb7fe621
@ -29,5 +29,8 @@ Base Expansion
|
|||||||
|
|
||||||
# Version History
|
# Version History
|
||||||
|
|
||||||
0.0.5 - fix for nil chunk in ai attack, checks for main surface
|
0.0.5 - fix for nil chunk in ai attack (https://mods.factorio.com/mods/Veden/Rampant/discussion/2512)
|
||||||
|
checks for main surface (https://forums.factorio.com/viewtopic.php?f=94&t=31445&p=198228#p198563)
|
||||||
|
updated info with forum homepage
|
||||||
|
|
||||||
0.0.4 - initial release
|
0.0.4 - initial release
|
89
control.lua
89
control.lua
@ -36,22 +36,33 @@ local retreatUnits = aiDefense.retreatUnits
|
|||||||
|
|
||||||
local addRemoveObject = mapUtils.addRemoveObject
|
local addRemoveObject = mapUtils.addRemoveObject
|
||||||
|
|
||||||
|
-- local references to global
|
||||||
|
|
||||||
|
local regionMap
|
||||||
|
local natives
|
||||||
|
local pendingChunks
|
||||||
|
|
||||||
-- hook functions
|
-- hook functions
|
||||||
|
|
||||||
function onInit()
|
function onInit()
|
||||||
-- print("init")
|
-- print("init")
|
||||||
|
global.version = constants.VERSION_5
|
||||||
global.regionMap = {}
|
global.regionMap = {}
|
||||||
global.pendingChunks = {}
|
global.pendingChunks = {}
|
||||||
global.natives = {}
|
global.natives = {}
|
||||||
|
|
||||||
global.regionMap.pQ = {{}} -- processing queue
|
regionMap = global.regionMap
|
||||||
global.regionMap.pI = 1 -- insertion location for chunk processing
|
natives = global.natives
|
||||||
global.regionMap.pP = 1 -- index for the chunk set to process
|
pendingChunks = global.pendingChunks
|
||||||
global.regionMap.pR = -1 -- current processing roll
|
|
||||||
global.natives.squads = {}
|
regionMap.pQ = {{}} -- processing queue
|
||||||
global.natives.scouts = {}
|
regionMap.pI = 1 -- insertion location for chunk processing
|
||||||
global.natives.tunnels = {}
|
regionMap.pP = 1 -- index for the chunk set to process
|
||||||
global.natives.points = 0
|
regionMap.pR = -1 -- current processing roll
|
||||||
|
natives.squads = {}
|
||||||
|
natives.scouts = {}
|
||||||
|
natives.tunnels = {}
|
||||||
|
natives.points = 0
|
||||||
|
|
||||||
-- game.forces.player.research_all_technologies()
|
-- game.forces.player.research_all_technologies()
|
||||||
|
|
||||||
@ -66,16 +77,39 @@ end
|
|||||||
|
|
||||||
function onLoad()
|
function onLoad()
|
||||||
-- print("load")
|
-- print("load")
|
||||||
-- regionMap = global.regionMap
|
regionMap = global.regionMap
|
||||||
-- pendingChunks = global.pendingChunks
|
natives = global.natives
|
||||||
-- natives = global.natives
|
pendingChunks = global.pendingChunks
|
||||||
|
end
|
||||||
|
|
||||||
|
function onConfigChanged()
|
||||||
|
if (global.version == nil) then
|
||||||
|
-- print("reprocess")
|
||||||
|
regionMap.pQ = {{}} -- processing queue
|
||||||
|
regionMap.pI = 1 -- insertion location for chunk processing
|
||||||
|
regionMap.pP = 1 -- index for the chunk set to process
|
||||||
|
regionMap.pR = -1 -- current processing roll
|
||||||
|
natives.squads = {}
|
||||||
|
natives.scouts = {}
|
||||||
|
natives.tunnels = {}
|
||||||
|
natives.points = 0
|
||||||
|
pendingChunks = {}
|
||||||
|
|
||||||
|
local surface = game.surfaces[1]
|
||||||
|
for chunk in surface.get_chunks() do
|
||||||
|
onChunkGenerated({ surface = surface,
|
||||||
|
area = { left_top = { x = chunk.x * 32,
|
||||||
|
y = chunk.y * 32 }}})
|
||||||
|
end
|
||||||
|
global.version = constants.VERSION_5
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function onChunkGenerated(event)
|
function onChunkGenerated(event)
|
||||||
-- queue generated chunk for delayed processing, queuing is required because some mods (RSO) mess with chunk as they
|
-- queue generated chunk for delayed processing, queuing is required because some mods (RSO) mess with chunk as they
|
||||||
-- are generated, which messes up the scoring.
|
-- are generated, which messes up the scoring.
|
||||||
if (event.surface.index == 1) then
|
if (event.surface.index == 1) then
|
||||||
global.pendingChunks[#global.pendingChunks+1] = event
|
pendingChunks[#pendingChunks+1] = event
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -88,33 +122,33 @@ function onTick(event)
|
|||||||
-- game.players[1].cheat_mode = true
|
-- game.players[1].cheat_mode = true
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
accumulatePoints(global.natives)
|
accumulatePoints(natives)
|
||||||
|
|
||||||
-- put down player pheromone for player hunters
|
-- put down player pheromone for player hunters
|
||||||
playerScent(global.regionMap, game.players)
|
playerScent(regionMap, game.players)
|
||||||
|
|
||||||
regroupSquads(global.natives)
|
regroupSquads(natives)
|
||||||
|
|
||||||
-- scouting(regionMap, surface, natives)
|
-- scouting(regionMap, surface, natives)
|
||||||
|
|
||||||
squadAttackPlayer(global.natives, game.players)
|
squadAttackPlayer(natives, game.players)
|
||||||
|
|
||||||
squadBeginAttack(global.natives)
|
squadBeginAttack(natives)
|
||||||
squadAttackLocation(global.regionMap, surface, global.natives)
|
squadAttackLocation(regionMap, surface, natives)
|
||||||
end
|
end
|
||||||
|
|
||||||
processPendingChunks(global.regionMap, surface, global.natives, global.pendingChunks)
|
processPendingChunks(regionMap, surface, natives, pendingChunks)
|
||||||
|
|
||||||
processMap(global.regionMap, surface, global.natives, game.evolution_factor)
|
processMap(regionMap, surface, natives, game.evolution_factor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function onBuild(event)
|
function onBuild(event)
|
||||||
addRemoveObject(global.regionMap, event.created_entity, global.natives, true)
|
addRemoveObject(regionMap, event.created_entity, natives, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onPickUp(event)
|
function onPickUp(event)
|
||||||
addRemoveObject(global.regionMap, event.entity, global.natives, false)
|
addRemoveObject(regionMap, event.entity, natives, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onDeath(event)
|
function onDeath(event)
|
||||||
@ -125,19 +159,19 @@ function onDeath(event)
|
|||||||
local entityPosition = entity.position
|
local entityPosition = entity.position
|
||||||
|
|
||||||
-- drop death pheromone where unit died
|
-- drop death pheromone where unit died
|
||||||
deathScent(global.regionMap, entityPosition.x, entityPosition.y)
|
deathScent(regionMap, entityPosition.x, entityPosition.y)
|
||||||
|
|
||||||
if (event.force ~= nil) and (event.force.name == "player") then
|
if (event.force ~= nil) and (event.force.name == "player") then
|
||||||
local squad = convertUnitGroupToSquad(global.natives, entity.unit_group)
|
local squad = convertUnitGroupToSquad(natives, entity.unit_group)
|
||||||
retreatUnits(entityPosition, squad, global.regionMap, game.surfaces[1], global.natives)
|
retreatUnits(entityPosition, squad, regionMap, game.surfaces[1], natives)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- removeScout(entity, global.natives)
|
-- removeScout(entity, global.natives)
|
||||||
elseif (entity.type == "unit-spawner") then
|
elseif (entity.type == "unit-spawner") then
|
||||||
addRemoveObject(global.regionMap, entity, global.natives, false)
|
addRemoveObject(regionMap, entity, natives, false)
|
||||||
end
|
end
|
||||||
elseif (entity.force.name == "player") then
|
elseif (entity.force.name == "player") then
|
||||||
addRemoveObject(global.regionMap, entity, global.natives, false)
|
addRemoveObject(regionMap, entity, natives, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -153,6 +187,7 @@ end
|
|||||||
|
|
||||||
script.on_init(onInit)
|
script.on_init(onInit)
|
||||||
script.on_load(onLoad)
|
script.on_load(onLoad)
|
||||||
|
script.on_configuration_changed(onConfigChanged)
|
||||||
|
|
||||||
script.on_event(defines.events.on_player_built_tile, onPutItem)
|
script.on_event(defines.events.on_player_built_tile, onPutItem)
|
||||||
|
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
local constants = {}
|
local constants = {}
|
||||||
|
|
||||||
|
-- versions
|
||||||
|
|
||||||
|
constants.VERSION_5 = 5
|
||||||
|
|
||||||
-- misc
|
-- misc
|
||||||
|
|
||||||
constants.MAGIC_MAXIMUM_NUMBER = 1e99 -- used in loops trying to find the lowest/highest score
|
constants.MAGIC_MAXIMUM_NUMBER = 1e99 -- used in loops trying to find the lowest/highest score
|
||||||
|
Loading…
Reference in New Issue
Block a user