1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-16 02:33:53 +02:00

adding raiding ai state, interop unit group registering

This commit is contained in:
Aaron Veden 2018-02-09 23:57:04 -08:00
parent 7c7d1477ac
commit 2b40676e53
8 changed files with 41 additions and 9 deletions

View File

@ -197,10 +197,10 @@ function upgrade.attempt(natives)
game.surfaces[1].print("Rampant - Version 0.16.16")
global.version = constants.VERSION_51
end
if (global.version < constants.VERSION_53) then
if (global.version < constants.VERSION_54) then
game.surfaces[1].print("Rampant - Version 0.16.18")
global.version = constants.VERSION_53
game.surfaces[1].print("Rampant - Version 0.16.19")
global.version = constants.VERSION_54
end
return starting ~= global.version, natives

View File

@ -4,11 +4,16 @@ Date: 2. 09. 2018
Features:
- Blockable projectiles, most projectiles will be stop by walls and other objects
- Rocket launches now agitate biters
- Added Raiding phase where for a short period of time the ai no longer needs pollution to trigger an attack wave
Improvements:
- Switched linear tier generation from rounding using ceiling to nearest number
- Spawner faction spitters now degrade when attacking and check buildability for units to prevent infinite biter masses when attacking
Bugfixes:
- Added check for null group (https://github.com/veden/Rampant/issues/16)
Tweaks:
- Changed Spawner baseline evolution requirement from 60 to 70%
Framework:
- Added interop function for registering unit groups from other mods for Rampant AI management
---------------------------------------------------------------------------------------------------

View File

@ -515,7 +515,7 @@ local function onResourceDepleted(event)
end
local function onTriggerEntityCreated(event)
print("triggered", event.tick)
end
local function onUsedCapsule(event)

View File

@ -31,6 +31,10 @@ local RALLY_CRY_DISTANCE = constants.RALLY_CRY_DISTANCE
local DEFINES_COMMAND_GROUP = defines.command.group
local DEFINES_DISTRACTION_NONE = defines.distraction.none
local RAIDING_MINIMUM_BASE_THRESHOLD = constants.RAIDING_MINIMUM_BASE_THRESHOLD
local AI_STATE_RAIDING = constants.AI_STATE_RAIDING
local SENTINEL_IMPASSABLE_CHUNK = constants.SENTINEL_IMPASSABLE_CHUNK
local PASSABLE = constants.PASSABLE
@ -67,8 +71,14 @@ local function attackWaveValidCandidate(chunk, natives, surface)
end
end
local hasBasePheromone = false
if (chunk[BASE_PHEROMONE] > 0) then
local basePheromone = chunk[BASE_PHEROMONE]
if (basePheromone > 0) then
hasBasePheromone = true
if (natives.state == AI_STATE_RAIDING) then
if (basePheromone > RAIDING_MINIMUM_BASE_THRESHOLD) then
total = total + basePheromone
end
end
end
if natives.attackUsePollution then
total = total + surface.get_pollution(chunk)

View File

@ -13,6 +13,7 @@ local NO_RETREAT_EVOLUTION_BONUS_MAX = constants.NO_RETREAT_EVOLUTION_BONUS_MAX
local AI_STATE_PEACEFUL = constants.AI_STATE_PEACEFUL
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
local AI_STATE_RAIDING = constants.AI_STATE_RAIDING
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
local AI_UNIT_REFUND = constants.AI_UNIT_REFUND
@ -95,7 +96,12 @@ function aiPlanning.planning(natives, evolution_factor, tick, surface, connected
elseif natives.aiNocturnalMode then
natives.state = AI_STATE_NOCTURNAL
else
natives.state = AI_STATE_AGGRESSIVE
roll = mRandom()
if (roll > 0.03) then
natives.state = AI_STATE_AGGRESSIVE
else
natives.state = AI_STATE_RAIDING
end
end
natives.stateTick = randomTickEvent(tick, AI_MIN_STATE_DURATION, AI_MAX_STATE_DURATION)
end

View File

@ -6,6 +6,7 @@ local constants = require("Constants")
-- constants
local AI_STATE_RAIDING = constants.AI_STATE_RAIDING
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
@ -14,7 +15,8 @@ local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
-- module code
function aiPredicates.canAttack(natives, surface)
return ((natives.state == AI_STATE_AGGRESSIVE) or aiPredicates.canAttackDark(natives, surface)) and not surface.peaceful_mode
return ((natives.state == AI_STATE_AGGRESSIVE) or aiPredicates.canAttackDark(natives, surface) or
(natives.state == AI_STATE_RAIDING)) and not surface.peaceful_mode
end
function aiPredicates.isDark(surface)

View File

@ -20,7 +20,7 @@ constants.VERSION_38 = 38
constants.VERSION_41 = 41
constants.VERSION_44 = 44
constants.VERSION_51 = 51
constants.VERSION_53 = 53
constants.VERSION_54 = 54
-- misc
@ -85,6 +85,8 @@ constants.AI_TUNNEL_COST = 100
constants.AI_MAX_POINTS = 10000
constants.AI_MAX_OVERFLOW_POINTS = constants.AI_MAX_POINTS * 3
constants.RAIDING_MINIMUM_BASE_THRESHOLD = 250
constants.AI_UNIT_REFUND = 3
-- constants.AI_MAX_SQUAD_COUNT = 30
@ -95,6 +97,7 @@ 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
constants.AI_STATE_RAIDING = 4
constants.AI_MIN_STATE_DURATION = 1
constants.AI_MAX_STATE_DURATION = 4
@ -187,7 +190,7 @@ constants.BASE_ALIGNMENT_EVOLUTION_BASELINE = {
[constants.BASE_ALIGNMENT_FIRE] = 0.4,
[constants.BASE_ALIGNMENT_FAST] = 0.5,
[constants.BASE_ALIGNMENT_TROLL] = 0.5,
[constants.BASE_ALIGNMENT_SPAWNER] = 0.6,
[constants.BASE_ALIGNMENT_SPAWNER] = 0.7,
[constants.BASE_ALIGNMENT_INFERNO] = 0.6,
[constants.BASE_ALIGNMENT_NUCLEAR] = 0.7
}

View File

@ -1,5 +1,7 @@
local interop = {}
local unitGroupUtils = require("UnitGroupUtils")
function interop.addAIPoints(value)
global.natives.points = global.natives.points + value
end
@ -78,4 +80,8 @@ function interop.getAttackUsePlayer()
return global.natives.attackUsePlayer
end
function interop.registerUnitGroup(unitGroup)
unitGroupUtils.createSquad(unitGroup.position, unitGroup.surface, global.natives, unitGroup)
end
return interop