1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-30 04:30:52 +02:00
Rampant/libs/AIPredicates.lua

41 lines
1.1 KiB
Lua
Raw Normal View History

2017-05-19 00:47:24 -07:00
local aiPredicates = {}
-- imports
local constants = require("Constants")
-- constants
local AI_STATE_RAIDING = constants.AI_STATE_RAIDING
2017-05-19 00:47:24 -07:00
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
local AI_STATE_MIGRATING = constants.AI_STATE_MIGRATING
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
(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
(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