2019-02-15 20:17:30 -08:00
|
|
|
if (aiPredicatesG) then
|
|
|
|
return aiPredicatesG
|
|
|
|
end
|
2017-05-19 00:47:24 -07:00
|
|
|
local aiPredicates = {}
|
|
|
|
|
|
|
|
-- imports
|
|
|
|
|
|
|
|
local constants = require("Constants")
|
|
|
|
|
|
|
|
-- constants
|
|
|
|
|
2018-02-09 23:57:04 -08:00
|
|
|
local AI_STATE_RAIDING = constants.AI_STATE_RAIDING
|
2017-05-19 00:47:24 -07:00
|
|
|
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
|
2018-02-14 00:28:42 -08:00
|
|
|
local AI_STATE_MIGRATING = constants.AI_STATE_MIGRATING
|
2018-02-18 20:18:04 -08:00
|
|
|
local AI_STATE_SIEGE = constants.AI_STATE_SIEGE
|
2019-02-08 21:48:00 -08:00
|
|
|
local AI_STATE_ONSLAUGHT = constants.AI_STATE_ONSLAUGHT
|
2017-05-19 00:47:24 -07:00
|
|
|
|
|
|
|
-- imported functions
|
|
|
|
|
|
|
|
-- module code
|
|
|
|
|
2021-11-25 11:11:46 -08:00
|
|
|
function aiPredicates.canAttack(map)
|
2021-02-19 23:31:36 -08:00
|
|
|
local surface = map.surface
|
2021-11-25 11:11:46 -08:00
|
|
|
local goodAI = (((map.state == AI_STATE_AGGRESSIVE) and (map.sentAggressiveGroups < map.maxAggressiveGroups)) or
|
2021-12-11 11:38:20 -08:00
|
|
|
(map.state == AI_STATE_RAIDING) or
|
|
|
|
(map.state == AI_STATE_ONSLAUGHT) or
|
|
|
|
(map.universe.raidAIToggle and (map.state == AI_STATE_SIEGE) and (map.sentSiegeGroups >= map.maxSiegeGroups)))
|
2020-05-15 13:51:38 -07:00
|
|
|
local notPeaceful = not surface.peaceful_mode
|
2021-02-19 23:31:36 -08:00
|
|
|
local nocturalMode = map.universe.aiNocturnalMode
|
|
|
|
local noctural = (not nocturalMode) or (nocturalMode and surface.darkness > 0.65)
|
2020-05-15 13:51:38 -07:00
|
|
|
return goodAI and notPeaceful and noctural
|
2017-05-19 00:47:24 -07:00
|
|
|
end
|
|
|
|
|
2021-02-19 23:31:36 -08:00
|
|
|
function aiPredicates.canMigrate(map)
|
|
|
|
local surface = map.surface
|
2021-02-20 15:31:48 -08:00
|
|
|
local universe = map.universe
|
|
|
|
local nocturalMode = universe.aiNocturnalMode
|
|
|
|
local goodAI = (map.state == AI_STATE_MIGRATING) or (map.state == AI_STATE_SIEGE)
|
|
|
|
local noctural = (not nocturalMode) or (nocturalMode and surface.darkness > 0.65)
|
|
|
|
return goodAI and universe.expansion and not surface.peaceful_mode and noctural
|
2017-11-20 23:27:03 -08:00
|
|
|
end
|
|
|
|
|
2019-02-15 20:17:30 -08:00
|
|
|
aiPredicatesG = aiPredicates
|
2017-05-19 00:47:24 -07:00
|
|
|
return aiPredicates
|