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
|
2017-11-20 23:27:03 -08:00
|
|
|
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
|
2017-05-19 00:47:24 -07:00
|
|
|
|
|
|
|
-- imported functions
|
|
|
|
|
|
|
|
-- module code
|
|
|
|
|
|
|
|
function aiPredicates.canAttack(natives, surface)
|
2018-02-10 00:42:17 -08:00
|
|
|
return ((natives.state == AI_STATE_AGGRESSIVE) or
|
|
|
|
aiPredicates.canAttackDark(natives, surface) or
|
2018-02-09 23:57:04 -08:00
|
|
|
(natives.state == AI_STATE_RAIDING)) and not surface.peaceful_mode
|
2017-05-19 00:47:24 -07:00
|
|
|
end
|
|
|
|
|
2019-02-02 22:01:28 -08:00
|
|
|
function aiPredicates.canMigrate(natives, surface)
|
2018-02-12 23:10:17 -08:00
|
|
|
return ((natives.state == AI_STATE_MIGRATING) or
|
2018-02-18 20:18:04 -08:00
|
|
|
(natives.state == AI_STATE_SIEGE) or
|
2019-02-02 22:01:28 -08:00
|
|
|
aiPredicates.canAttackDark(natives, surface)) and natives.expansion and natives.enabledMigration
|
2018-02-12 23:10:17 -08:00
|
|
|
end
|
|
|
|
|
2017-11-20 23:27:03 -08:00
|
|
|
function aiPredicates.isDark(surface)
|
|
|
|
return surface.darkness > 0.65
|
|
|
|
end
|
|
|
|
|
|
|
|
function aiPredicates.canAttackDark(natives, surface)
|
|
|
|
return aiPredicates.isDark(surface) and natives.state == AI_STATE_NOCTURNAL
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2017-05-19 00:47:24 -07:00
|
|
|
return aiPredicates
|