Something went wrong. Try again.
[Archived] evolutionary genetic algorithm project and mob plugin for Minetest as part of a bachelor degree final thesis
Something went wrong. Try again.
adaptive-mob api.lua
2.1 kB · 76 lines
Lua
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
----------------------- ADAPTIVE AI API -----------------------
local random = math.random
local ai_pathfinding = adaptive_ai.ai_pathfindinglocal ai_manager = adaptive_ai.ai_managerlocal 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 :: boolbreed :: function(parent) if asexualbreed :: function(mother, father) if not asexualactions :: list of stringsaction_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 respectedStates 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 nilend