adaptive-ai/api.lua
2018-06-26 19:20:49 +02:00

76 lines
2 KiB
Lua

---------------------
-- ADAPTIVE AI API --
---------------------
local random = math.random
local ai_pathfinding = adaptive_ai.ai_pathfinding
local ai_manager = adaptive_ai.ai_manager
local ai_on_step = adaptive_ai.ai_on_step
adaptive_ai.breeding = {}
function adaptive_ai:register_ai(name, def)
adaptive_ai.breeding[name] = {
asexual = def.asexual or false,
breed = def.breed
}
if not def.do_custom then
if not def.ai_manager then
def.ai_manager = adaptive_ai.ai_manager
end
def.do_custom = function(self, dtime)
--chat_log("do custom "..())
if def.action_managers then
-- there's a manager function per action
if self.action then
--chat_log("action managers in action")
def.action_managers[self.action](self, dtime)
end
end
local skip = def.ai_manager(self, dtime)
if skip == false then return false end
ai_on_step(self, dtime)
return false
end
end
mobs:register_mob(name, def)
end
--[[
def (adaptive_ai.api related):
asexual :: bool
breed :: function(parent) if asexual
breed :: function(mother, father) if not asexual
actions :: list of strings
action_managers :: list of functions (index corresponds with action index)
camp :: if there's a node the creature is bound to (like a spawner)
Notes:
do_custom API functionality from mobs_redo is respected
States from mobs_redo are overwritten with internal adaptive_ai state management
-- stand (stationary idle)
-- wander (equivalent to mob_redo's idle + walk_chance)
-- move (towards or away from a target - with or without pathfinding)
Actions are custom mob states with a different name to avoid conflict with previous states
--]]
function adaptive_ai:place_ai(def)
local name = def.name
--local setup = def.setup
local pos = def.pos
--local height = minetest.registered_entities[name].jump_height
local obj = minetest.add_entity(pos, name)
local ent = obj and obj:get_luaentity() or nil
if def.setup and ent then
def.setup(ent)
end
return ent or nil
end