2017-05-19 09:47:24 +02:00
|
|
|
local aiPredicates = {}
|
|
|
|
|
|
|
|
-- imports
|
|
|
|
|
|
|
|
local constants = require("Constants")
|
|
|
|
|
|
|
|
-- constants
|
|
|
|
|
2018-02-10 09:57:04 +02:00
|
|
|
local AI_STATE_RAIDING = constants.AI_STATE_RAIDING
|
2017-05-19 09:47:24 +02:00
|
|
|
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
|
2018-02-14 10:28:42 +02:00
|
|
|
local AI_STATE_MIGRATING = constants.AI_STATE_MIGRATING
|
2017-11-21 09:27:03 +02:00
|
|
|
local AI_STATE_NOCTURNAL = constants.AI_STATE_NOCTURNAL
|
2017-05-19 09:47:24 +02:00
|
|
|
|
|
|
|
-- imported functions
|
|
|
|
|
|
|
|
-- module code
|
|
|
|
|
|
|
|
function aiPredicates.canAttack(natives, surface)
|
2018-02-10 10:42:17 +02:00
|
|
|
return ((natives.state == AI_STATE_AGGRESSIVE) or
|
|
|
|
aiPredicates.canAttackDark(natives, surface) or
|
2018-02-10 09:57:04 +02:00
|
|
|
(natives.state == AI_STATE_RAIDING)) and not surface.peaceful_mode
|
2017-05-19 09:47:24 +02:00
|
|
|
end
|
|
|
|
|
2018-02-17 03:44:19 +02:00
|
|
|
function aiPredicates.canMigrate(natives, surface)
|
2018-02-13 09:10:17 +02:00
|
|
|
return ((natives.state == AI_STATE_MIGRATING) or
|
|
|
|
aiPredicates.canAttackDark(natives, surface)) and natives.expansion
|
|
|
|
end
|
|
|
|
|
2017-11-21 09:27:03 +02: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 09:47:24 +02:00
|
|
|
return aiPredicates
|