├── models ├── sheep.b3d └── stone_giant.b3d ├── sounds ├── on_punch.1.ogg ├── on_punch.2.ogg ├── on_punch.3.ogg ├── sheep_hurt.1.ogg ├── sheep_chatter.1.ogg ├── sheep_chatter.2.ogg ├── sheep_chatter.3.ogg ├── sheep_chatter.4.ogg └── readme.md ├── textures ├── sheep_fur.png └── stone_giant.png ├── mod.conf ├── .luacheckrc ├── README.md ├── factors.lua ├── TODO.md ├── stone_giant.lua ├── design.md ├── finders.lua ├── sheep.lua ├── path.lua ├── driver.lua ├── drivers.lua ├── init.lua ├── cc-by-sa-4.0.txt └── lgpl-2.1.txt /models/sheep.b3d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/models/sheep.b3d -------------------------------------------------------------------------------- /sounds/on_punch.1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/on_punch.1.ogg -------------------------------------------------------------------------------- /sounds/on_punch.2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/on_punch.2.ogg -------------------------------------------------------------------------------- /sounds/on_punch.3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/on_punch.3.ogg -------------------------------------------------------------------------------- /models/stone_giant.b3d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/models/stone_giant.b3d -------------------------------------------------------------------------------- /sounds/sheep_hurt.1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/sheep_hurt.1.ogg -------------------------------------------------------------------------------- /textures/sheep_fur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/textures/sheep_fur.png -------------------------------------------------------------------------------- /sounds/sheep_chatter.1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/sheep_chatter.1.ogg -------------------------------------------------------------------------------- /sounds/sheep_chatter.2.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/sheep_chatter.2.ogg -------------------------------------------------------------------------------- /sounds/sheep_chatter.3.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/sheep_chatter.3.ogg -------------------------------------------------------------------------------- /sounds/sheep_chatter.4.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/sounds/sheep_chatter.4.ogg -------------------------------------------------------------------------------- /textures/stone_giant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sofar/entity_ai/HEAD/textures/stone_giant.png -------------------------------------------------------------------------------- /mod.conf: -------------------------------------------------------------------------------- 1 | name = entity_ai 2 | depends = default 3 | description = Entity engine - drives monsters, npcs and other entities to behave logically 4 | -------------------------------------------------------------------------------- /.luacheckrc: -------------------------------------------------------------------------------- 1 | unused_args = false 2 | allow_defined_top = true 3 | 4 | read_globals = { 5 | "DIR_DELIM", 6 | "minetest", "core", 7 | "dump", 8 | "vector", "nodeupdate", 9 | "VoxelManip", "VoxelArea", 10 | "PseudoRandom", "ItemStack", 11 | "intllib", 12 | "default", 13 | "unpack", 14 | table = { fields = { "copy", "getn" } } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /sounds/readme.md: -------------------------------------------------------------------------------- 1 | 2 | sheep_chatter.1.ogg: 3 | - http://www.freesound.org/people/n_audioman/sounds/321967/ n_audioman CC-BY-3.0 4 | 5 | sheep_chatter.2.ogg: 6 | - http://www.freesound.org/people/confusion_music/sounds/103442/ ion_music CC-BY-3.0 7 | 8 | sheep_chatter.3.ogg, 9 | sheep_chatter.4.ogg: 10 | - http://www.freesound.org/people/reinsamba/sounds/57796/ reinsamba CC-BY-3.0 11 | 12 | sheep_hurt.1.ogg: 13 | - http://www.freesound.org/people/confusion_music/sounds/103441/ confusion_music CC-BY-3.0 14 | 15 | sheep_steps.1.ogg: 16 | - http://www.freesound.org/people/newagesoup/sounds/342475/ newagesoup CC-BY-3.0 17 | 18 | on_punch.*.ogg: 19 | - http://www.freesound.org/people/Eelke/sounds/266648/ Eelke CC-BY-3.0 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## NAME 3 | 4 | The `entity_ai` name is kind of lame, so, I likely will want to 5 | change the name to something that more appropriately represents it's 6 | architecture. There is absolutely nothing AI about this desing, and 7 | it's more of a finite state machine than anything. Not that that 8 | diminishes the project in any way. But despite it's capability of 9 | plugging in a real AI of sorts, it currently doesn't do that. 10 | 11 | ## LICENSE 12 | 13 | Copyright (c) 2016-2019 - Auke Kok 14 | 15 | `entity_ai` is licensed as follows: 16 | - All code is: LGPL-2.1 17 | - All artwork is: CC-BY-SA-4.0 18 | 19 | except: 20 | - sound files in the `sounds` folder are licensed according to their 21 | respective licenses (documented in sounds/readme.md). 22 | - `stone_giant.png` is identical to `default_stone.png` from `minetest_game` 23 | and licensed as the original. 24 | 25 | ["code" means everything in lua files, "artwork" means everything else, 26 | including documentation, sounds, textures, 3d models] 27 | 28 | ## SPLITTING UP THIS PROJECT * 29 | 30 | In the future, the core API code will be seperated from the monster 31 | definitions. Each monster will be it's own `mod` permitting users to 32 | disable/enable monsters as they see fit. This organization will help 33 | to keep per-mod specific code out of the core and make core functions 34 | better suited to handle all monsters. 35 | -------------------------------------------------------------------------------- /factors.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2016-2019 - Auke Kok 5 | 6 | * entity_ai is licensed as follows: 7 | - All code is: LGPL-2.1 8 | - All artwork is: CC-BY-SA-4.0 9 | 10 | --]] 11 | 12 | entity_ai.register_factor("near_foodnode", function(self, dtime) 13 | local state = self.entity_ai_state 14 | 15 | -- still fed? 16 | if state.ate_enough and state.ate_enough > 0 then 17 | state.ate_enough = state.ate_enough - dtime 18 | return 19 | end 20 | state.ate_enough = nil 21 | 22 | -- don't check too often 23 | if state.near_foodnode_ttl and state.near_foodnode_ttl > 0 then 24 | state.near_foodnode_ttl = state.near_foodnode_ttl - dtime 25 | return 26 | end 27 | state.near_foodnode_ttl = 2.0 28 | 29 | local pos = vector.round(self.object:getpos()) 30 | local yaw = self.object:getyaw() 31 | self.yaw = yaw 32 | local offset = minetest.yaw_to_dir(yaw) 33 | local maxp = vector.add(pos, offset) 34 | local minp = vector.subtract(maxp, {x = 0, y = 1, z = 0 }) 35 | local nodes = minetest.find_nodes_in_area(minp, maxp, self.driver:get_property("foodnodes")) 36 | 37 | if #nodes == 0 then 38 | return 39 | end 40 | 41 | --[[ minetest.add_particle({ 42 | pos = maxp, 43 | velocity = vector.new(), 44 | acceleration = vector.new(), 45 | expirationtime = 3, 46 | size = 6, 47 | collisiondetection = false, 48 | vertical = false, 49 | texture = "wool_pink.png", 50 | playername = nil 51 | }) 52 | --]] 53 | 54 | -- store grass node in our factor result - take topmost in list 55 | return nodes[#nodes] 56 | end) 57 | 58 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | 2 | This is a summary of high-level features that are still missing, 3 | not a detailed bug list. 4 | 5 | 6 | 1 - Monster persistence 7 | 8 | Monsters should be persistent in the world: The default assumption 9 | is that a world is generated by mapgen and is then mostly finished, 10 | and any modification to the world afterwards is persistent. 11 | 12 | For monsters, this means that mapgen should add monsters to the 13 | mapblocks. If these monsters should die, they are in principle removed 14 | from the world forever. 15 | 16 | A `/clearobjects` call should not affect this. We can get this behavior 17 | by using ABM's to respawn missing monsters. This may replace normal 18 | block saving entirely, which is the default method to save/load entities. 19 | 20 | Initial monster addition to the world should be done using generic 21 | algorithms that use e.g. perlin noise to place monsters in the proper 22 | locations, density and type. 23 | 24 | Additonal spawning algorithms (e.g. respawning, or randomly spawning 25 | more mobs after a while) should be optional and possibly done by 26 | an external mod. 27 | 28 | 29 | 2 - Finish the Sheep 30 | 31 | Various "basic" things about sheep are not implemented. This includes 32 | gender and reproduction, shearing/wool, handling drops. 33 | 34 | 35 | 3 - Finish the Stone Monster 36 | 37 | Missing fighting sequence, initial trapped state, drops etc.. 38 | 39 | 40 | 4 - Decide on additional monsters to be implemented 41 | 42 | Ideally, we add 1 swimmer and 1 flyer, just so that we cover all of the 43 | movement types and implement all the needed path finding codes to support 44 | them. I'm declaring a 5-monster maximum for now - the API is open enough 45 | that additional monsters can become modules. 46 | 47 | -------------------------------------------------------------------------------- /stone_giant.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2016-2019 - Auke Kok 5 | 6 | * entity_ai is licensed as follows: 7 | - All code is: LGPL-2.1 8 | - All artwork is: CC-BY-SA-4.0 9 | 10 | --]] 11 | 12 | -- 13 | -- stone giant entity AI script 14 | -- 15 | 16 | local stone_giant_script = { 17 | -- the start driver. Should be able to spawn a monster with a different driver! 18 | driver = "roam", 19 | -- default properties 20 | properties = { 21 | speed = 0.666, 22 | hp_max = 20, 23 | habitatnodes = { 24 | "group:stone", 25 | "group:cracky", 26 | "default:sand" 27 | ,} 28 | }, 29 | -- defined animation sets: 30 | -- "name" = { animationspec1, animationspec2, animationspec3 .. } 31 | -- each must be present -> 'nil' required 32 | -- last animation should have 'frame_loop = true' 33 | --FIXME handle repeats (running animation 5x ?) 34 | animations = { 35 | move = { 36 | {{x = 216, y = 240}, frame_speed = 24, frame_loop = false}, 37 | {{x = 240, y = 320}, frame_speed = 24, frame_loop = true}, 38 | }, 39 | idle = { 40 | {{x = 120, y = 216}, frame_speed = 24, frame_loop = true}, 41 | }, 42 | punch = { 43 | {{x = 329, y = 367}, frame_speed = 24, frame_loop = false}, 44 | }, 45 | smash = { 46 | {{x = 367, y = 420}, frame_speed = 24, frame_loop = false}, 47 | }, 48 | death = { 49 | {{x = 420, y = 453}, frame_speed = 24, frame_loop = false}, 50 | }, 51 | }, 52 | -- sound samples 53 | sounds = { 54 | }, 55 | -- monster script states: 56 | roam = { 57 | finders = { 58 | "find_habitat", 59 | }, 60 | factors = {}, 61 | }, 62 | idle = { 63 | factors = {}, 64 | }, 65 | death = { 66 | sounds = { 67 | start = "hurt", 68 | }, 69 | }, 70 | } 71 | 72 | entity_ai.register_entity("entity_ai:stone_giant", { 73 | script = stone_giant_script, 74 | mesh = "stone_giant.b3d", 75 | textures = {"stone_giant.png"}, 76 | makes_footstep_sound = true, 77 | collisionbox = {-1/2, -1/2, -1/2, 1/2, 1, 1/2}, 78 | }) 79 | 80 | -------------------------------------------------------------------------------- /design.md: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | THIS DOCUMENT IS OBSOLETE, AND ONLY A GUIDELINE 5 | 6 | --]] 7 | 8 | - entity programming should use object:method() design. 9 | - creating an entity should use simple methods as follows: 10 | 11 | minetest.register_entity("sofar:sheep", { 12 | object = {}, 13 | ..., 14 | on_activate = entity_ai:on_activate, 15 | on_step = entity_ai:on_step, 16 | on_punch = entity_ai:on_punch, 17 | on_rightclick = entity_ai:on_rightclick, 18 | get_staticdata = entity_ai:get_staticdata, 19 | }) 20 | 21 | entity activity is a structure organized as a graph: 22 | 23 | events may cause: 24 | -> [flee] 25 | -> [defend] 26 | -> [dead] 27 | -> [return] 28 | initial states 29 | [roam] 30 | [guard] 31 | [hunt] 32 | 33 | etc.. 34 | 35 | Each state may have several substates 36 | 37 | [idle] -> { idle.1, idle.2, idle.3 } 38 | 39 | Each state has a "driver". This is the algorithm that makes the entity do 40 | stuff. "do stuff" can mean "stand still", "move to a pos", "attack something" or 41 | a combination of any of these, including "use a node", "place a node" etc. 42 | 43 | -- returns: nil 44 | obj:driver_eat_grass = function(self) end 45 | obj:driver_idle = function(self) end 46 | obj:driver_find_food = function(self) end 47 | obj:driver_defend = ... 48 | obj:driver_death = ... 49 | obj:driver_mate = ... 50 | 51 | Each state has several "factors". These are conditions that may be met at any 52 | point in time. Factors can be "A node is nearby that can be grazed on", "close to water", 53 | "fertile", "was hit recently", "took damage recently", "a hostile faction is nearby" 54 | 55 | -- returns: bool 56 | obj:factor_is_fertile = function(self) end 57 | obj:factor_is_near_grass = function(self) end 58 | obj:factor_was_hit = function(self) end 59 | obj:factor_is_near_mate = ... 60 | 61 | sheep_script = { 62 | "roam" = { 63 | driver = "roaming", 64 | factors = { 65 | got_hit = "startle", 66 | became_fertile = "fertile", 67 | attractor_nearby = "attracted", 68 | too_far_from_home = "homing", 69 | }, 70 | } 71 | "eat" = { 72 | driver = "eat", 73 | factors = { 74 | ate_enough = "roam", 75 | became_fertile = "fertile", 76 | attractor_nearby = "attracted", 77 | } 78 | }, 79 | "startle" = { 80 | driver = "startle", 81 | factors = { 82 | got_hit = "flee", 83 | }, 84 | "flee" = { 85 | driver = "flee", 86 | factors = { 87 | got_hit = "startle", 88 | fleed_too_long = "roam", 89 | }, 90 | }, 91 | "attracted" = { 92 | driver = "approach", 93 | factors = { 94 | became_fertile = "fertile", 95 | approached_too_long = "roam", 96 | } 97 | }, 98 | "fertile" = { 99 | driver = "mate", 100 | factors = { 101 | got_hit = "startle", 102 | } 103 | "homing" = { 104 | driver = "homing", 105 | factors = { 106 | near_home = "roam", 107 | got_hit = "startle", 108 | } 109 | }, 110 | "death" = { 111 | driver = "death", 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /finders.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2016-2019 - Auke Kok 5 | 6 | * entity_ai is licensed as follows: 7 | - All code is: LGPL-2.1 8 | - All artwork is: CC-BY-SA-4.0 9 | 10 | --]] 11 | 12 | entity_ai.register_finder("find_habitat", function(self) 13 | local pos = self.object:getpos() 14 | local minp, maxp = vector.sort({ 15 | x = math.random(pos.x - 10, pos.x + 10), 16 | y = pos.y - 5, 17 | z = math.random(pos.z - 10, pos.z + 10) 18 | }, { 19 | x = math.random(pos.x - 10, pos.x + 10), 20 | y = pos.y + 5, 21 | z = math.random(pos.z - 10, pos.z + 10) 22 | }) 23 | local nodes = minetest.find_nodes_in_area_under_air(minp, maxp, self.driver:get_property("habitatnodes")) 24 | if #nodes == 0 then 25 | return nil 26 | end 27 | 28 | local pick = nodes[math.random(1, #nodes)] 29 | -- find top walkable node 30 | while true do 31 | local node = minetest.get_node(pick) 32 | if not minetest.registered_nodes[node.name].walkable then 33 | pick.y = pick.y - 1 34 | else 35 | -- one up at the end 36 | pick.y = pick.y + 1 37 | break 38 | end 39 | end 40 | -- move to the top surface of pick 41 | if not pick then 42 | return nil 43 | end 44 | 45 | --[[ minetest.add_particle({ 46 | pos = {x = pick.x, y = pick.y - 0.1, z = pick.z}, 47 | velocity = vector.new(), 48 | acceleration = vector.new(), 49 | expirationtime = 3, 50 | size = 6, 51 | collisiondetection = false, 52 | vertical = false, 53 | texture = "wool_red.png", 54 | playername = nil 55 | }) 56 | --]] 57 | return pick 58 | end) 59 | 60 | entity_ai.register_finder("flee_attacker", function(self) 61 | local state = self.entity_ai_state 62 | local from = state.attacked_at 63 | if state.attacker and state.attacker ~= "" then 64 | local player = minetest.get_player_by_name(state.attacker) 65 | if player then 66 | from = player:getpos() 67 | end 68 | end 69 | if not from then 70 | from = self.object:getpos() 71 | state.attacked_at = from 72 | end 73 | 74 | from = vector.round(from) 75 | 76 | local pos = self.object:getpos() 77 | local dir = vector.subtract(pos, from) 78 | dir = vector.normalize(dir) 79 | dir = vector.multiply(dir, 10) 80 | local to = vector.add(pos, dir) 81 | 82 | local nodes = minetest.find_nodes_in_area_under_air( 83 | vector.subtract(to, 4), 84 | vector.add(to, 4), 85 | {"group:crumbly", "group:cracky", "group:stone"}) 86 | 87 | if #nodes == 0 then 88 | -- failed to get a target, just run away from attacker?! 89 | print("No target found, stopped") 90 | return 91 | end 92 | 93 | -- find top walkable node 94 | local pick = nodes[math.random(1, #nodes)] 95 | while true do 96 | local node = minetest.get_node(pick) 97 | if not minetest.registered_nodes[node.name].walkable then 98 | pick.y = pick.y - 1 99 | else 100 | -- one up at the end 101 | pick.y = pick.y + 1 102 | break 103 | end 104 | end 105 | 106 | -- move to the top surface of pick 107 | if not pick then 108 | return false 109 | end 110 | --[[ 111 | minetest.add_particle({ 112 | pos = {x = pick.x, y = pick.y - 0.1, z = pick.z}, 113 | velocity = vector.new(), 114 | acceleration = vector.new(), 115 | expirationtime = 3, 116 | size = 6, 117 | collisiondetection = false, 118 | vertical = false, 119 | texture = "wool_red.png", 120 | playername = nil 121 | }) 122 | --]] 123 | return pick 124 | end) 125 | -------------------------------------------------------------------------------- /sheep.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2016-2019 - Auke Kok 5 | 6 | * entity_ai is licensed as follows: 7 | - All code is: LGPL-2.1 8 | - All artwork is: CC-BY-SA-4.0 9 | 10 | --]] 11 | 12 | -- 13 | -- sheep entity AI script 14 | -- 15 | 16 | local sheep_script = { 17 | -- the start driver. Should be able to spawn a monster with a different driver! 18 | driver = "roam", 19 | -- default properties 20 | properties = { 21 | speed = 2.0, 22 | hp_max = 20, 23 | foodnodes = { 24 | "group:grass", 25 | "default:dirt_with_grass", 26 | "default:dirt_with_dry_grass", 27 | "default:grass_1", 28 | "default:grass_2", 29 | "default:grass_3", 30 | "default:grass_4", 31 | "default:grass_5", 32 | "default:dry_grass_1", 33 | "default:dry_grass_2", 34 | "default:dry_grass_3", 35 | "default:dry_grass_4", 36 | "default:dry_grass_5", 37 | }, 38 | habitatnodes = { 39 | "group:flora", 40 | "group:snappy", 41 | "group:dirt", 42 | "group:soil", 43 | "group:crumbly", 44 | "group:grass", 45 | "default:dirt_with_grass", 46 | "default:dirt_with_dry_grass", 47 | "default:sand" 48 | ,} 49 | }, 50 | -- defined animation sets: 51 | -- "name" = { animationspec1, animationspec2, animationspec3 .. } 52 | -- each must be present -> 'nil' required 53 | -- last animation should have 'frame_loop = true' 54 | --FIXME handle repeats (running animation 5x ?) 55 | animations = { 56 | move = { 57 | {{x = 0, y = 40}, frame_speed = 60, frame_loop = true}, 58 | }, 59 | run = { 60 | {{x = 0, y = 40}, frame_speed = 90, frame_loop = true}, 61 | }, 62 | idle = { 63 | {{x = 111, y = 129}, frame_speed = 10, frame_loop = true}, 64 | }, 65 | eat = { 66 | {{x = 41, y = 47}, frame_speed = 15, frame_loop = false}, 67 | {{x = 47, y = 75}, frame_speed = 15, frame_loop = true}, 68 | }, 69 | eat_end = { 70 | {{x = 75, y = 81}, frame_speed = 15, frame_loop = false}, 71 | }, 72 | startle = { 73 | {{x = 100, y = 110}, frame_speed = 30, frame_loop = false}, 74 | {{x = 111, y = 119}, frame_speed = 30, frame_loop = true}, 75 | }, 76 | death = { 77 | {{x = 82, y = 90}, frame_speed = 15, frame_loop = false}, 78 | {{x = 90, y = 99}, frame_speed = 15, frame_loop = true}, 79 | }, 80 | }, 81 | -- sound samples 82 | sounds = { 83 | chatter = {{name = "sheep_chatter", gain = 0.2}, {max_hear_distance = 12}}, 84 | footsteps = {{name = "sheep_steps", gain = 0.2}, {max_hear_distance = 12}}, 85 | hurt = {{name = "sheep_hurt", gain = 0.5}, {max_hear_distance = 18}}, 86 | }, 87 | -- monster script states: 88 | roam = { 89 | finders = { 90 | "find_habitat", 91 | }, 92 | factors = { 93 | got_hit = "startle", 94 | became_fertile = "fertile", 95 | attractor_nearby = "attracted", 96 | }, 97 | sounds = { 98 | random = "footsteps", 99 | }, 100 | }, 101 | idle = { 102 | factors = { 103 | got_hit = "startle", 104 | became_fertile = "fertile", 105 | attractor_nearby = "attracted", 106 | too_far_from_home = "homing", 107 | near_foodnode = "eat", 108 | }, 109 | sounds = { 110 | random = "chatter", 111 | }, 112 | }, 113 | eat = { 114 | factors = { 115 | got_hit = "startle", 116 | became_fertile = "fertile", 117 | attractor_nearby = "attracted", 118 | }, 119 | sounds = { 120 | random = "chatter", 121 | }, 122 | }, 123 | eat_end = { 124 | factors = { 125 | anim_end = "idle", 126 | } 127 | }, 128 | startle = { 129 | factors = { 130 | anim_end = "flee", 131 | }, 132 | sounds = { 133 | start = "hurt", 134 | }, 135 | }, 136 | flee = { 137 | finders = { 138 | "flee_attacker", 139 | }, 140 | properties = { 141 | speed = 4.0, 142 | }, 143 | factors = { 144 | got_hit = "startle", 145 | }, 146 | sounds = { 147 | random = "footsteps", 148 | }, 149 | }, 150 | attracted = { 151 | factors = { 152 | got_hit = "startle", 153 | became_fertile = "fertile", 154 | approached_too_long = "roam", 155 | }, 156 | sounds = { 157 | random = "chatter", 158 | }, 159 | }, 160 | fertile = { 161 | factors = { 162 | got_hit = "startle", 163 | }, 164 | sounds = { 165 | random = "chatter", 166 | }, 167 | }, 168 | homing = { 169 | factors = { 170 | near_home = "roam", 171 | got_hit = "startle", 172 | }, 173 | sounds = { 174 | random = "chatter", 175 | }, 176 | }, 177 | death = { 178 | sounds = { 179 | start = "hurt", 180 | }, 181 | }, 182 | } 183 | 184 | entity_ai.register_entity("entity_ai:sheep", { 185 | script = sheep_script, 186 | mesh = "sheep.b3d", 187 | textures = {"sheep_fur.png"}, 188 | makes_footstep_sound = true, 189 | collisionbox = {-5/16, -1/2, -5/16, 5/16, 4/16, 5/16}, 190 | }) 191 | 192 | -------------------------------------------------------------------------------- /path.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2016-2019 - Auke Kok 4 | 5 | * entity_ai is licensed as follows: 6 | - All code is: LGPL-2.1 7 | - All artwork is: CC-BY-SA-4.0 8 | 9 | --]] 10 | 11 | -- 12 | -- Path class - manage and execute an entity path 13 | -- 14 | 15 | 16 | -- Class definition 17 | Path = {} 18 | Path.__index = Path 19 | 20 | setmetatable(Path, { 21 | __call = function(c, ...) 22 | return c.new(...) 23 | end, 24 | }) 25 | 26 | -- constructor 27 | function Path.new(obj) 28 | local self = setmetatable({}, Path) 29 | self.object = obj.object 30 | self.driver = obj.object:get_luaentity().driver 31 | self.origin = self.object:getpos() 32 | self.config = { 33 | distance = 30, 34 | jump = 1.0, 35 | fall = 3.0, 36 | algorithm = "Dijkstra", 37 | } 38 | self.path = {} 39 | return self 40 | end 41 | 42 | -- to help serialization 43 | function Path:save() 44 | return { 45 | target = self.target, 46 | config = self.config 47 | } 48 | end 49 | 50 | function Path:find(finder) 51 | -- select a finder 52 | if not finder then 53 | local finders = self.object:get_luaentity().script[self.driver.name].finders 54 | if not finders then 55 | print("No finder for driver: " .. self.driver.name) 56 | return false 57 | end 58 | for _, v in ipairs(finders) do 59 | -- use the finder 60 | self.target = entity_ai.registered_finders[v](self.object:get_luaentity()) 61 | if self.target then 62 | break 63 | end 64 | end 65 | else 66 | self.target = entity_ai.registered_finders[finder](self.object:get_luaentity()) 67 | end 68 | if not self.target then 69 | return false 70 | end 71 | 72 | -- pathing will fail if we're on a ledge. We can fix this by 73 | -- pathing from the node below instead 74 | local pos = vector.round(self.origin) 75 | local onpos = {x = pos.x, y = pos.y - 1, z = pos.z} 76 | local on = minetest.get_node(onpos) 77 | 78 | if not minetest.registered_nodes[on.name].walkable then 79 | pos.y = onpos.y 80 | end 81 | 82 | local config = self.config 83 | self.path = minetest.find_path(pos, vector.round(self.target), config.distance, config.jump, 84 | config.fall, config.algorithm) 85 | --[[ 86 | if self.path ~= nil then 87 | for k, v in pairs(self.path) do 88 | minetest.add_particle({ 89 | pos = v, 90 | velocity = vector.new(), 91 | acceleration = vector.new(), 92 | expirationtime = 3, 93 | size = 3, 94 | collisiondetection = false, 95 | vertical = false, 96 | texture = "wool_white.png", 97 | playername = nil 98 | }) 99 | end 100 | end 101 | --]] 102 | 103 | return self.path ~= nil 104 | end 105 | 106 | function Path:step(dtime) 107 | local curspd = self.object:getvelocity() 108 | local pos = self.object:getpos() 109 | -- if jumping, let jump finish before making more adjustments 110 | if curspd.y >= 0 and curspd.y <= 2 then 111 | local i, v = next(self.path, nil) 112 | if not i then 113 | return false 114 | end 115 | if vector.distance(pos, v) < 0.3 then 116 | -- remove one 117 | --FIXME shouldn't return here 118 | local _, v2 = next(self.path, i) 119 | if not v2 then 120 | return false 121 | end 122 | end 123 | -- prune path more? 124 | local ii, vv = next(self.path, i) 125 | local _, vvv = next(self.path, ii) 126 | if vv and vvv and vvv.y == v.y and vector.distance(vv,v) < 2 then 127 | -- prune one 128 | self.path[ii] = nil 129 | end 130 | -- done pruning 131 | --[[ 132 | minetest.add_particle({ 133 | pos = {x = v.x, y = v.y + 0.2, z = v.z}, 134 | velocity = vector.new(), 135 | acceleration = vector.new(), 136 | expirationtime = 1, 137 | size = 2, 138 | collisiondetection = false, 139 | vertical = false, 140 | texture = "wool_yellow.png", 141 | playername = nil 142 | }) 143 | --]] 144 | local vo = {x = v.x, y = v.y - 0.5, z = v.z} 145 | local vec = vector.subtract(vo, pos) 146 | local len = vector.length(vec) 147 | local vdif = vec.y 148 | vec.y = 0 149 | local dir = vector.normalize(vec) 150 | local spd = vector.multiply(dir, self.driver:get_property("speed")) 151 | -- don't jump from too far away 152 | if vdif > 0.1 and len < 1.5 then 153 | -- jump 154 | spd = {x = spd.x/4, y = 5, z = spd.z/4} 155 | self.object:setvelocity(spd) 156 | elseif vdif < 0 and len <= 1.1 then 157 | -- drop one path node just to be sure 158 | self.path[i] = nil 159 | -- falling down, just let if fall 160 | else 161 | spd.y = self.object:getvelocity().y 162 | -- don't change yaw when jumping 163 | self.object:setyaw(minetest.dir_to_yaw(spd)) 164 | self.object:setvelocity(spd) 165 | end 166 | end 167 | 168 | return true 169 | end 170 | 171 | function Path:distance() 172 | if not self.path then 173 | return 0 174 | end 175 | if not self.target then 176 | return 0 177 | end 178 | 179 | return vector.distance(self.object:getpos(), self.target) 180 | end 181 | 182 | function Path:length() 183 | if not self.path then 184 | return 0 185 | end 186 | 187 | return #self.path 188 | end 189 | 190 | function Path:get_config() 191 | return self.config 192 | end 193 | 194 | function Path:set_config(conf) 195 | self.config = conf 196 | end 197 | 198 | -------------------------------------------------------------------------------- /driver.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2016-2019 - Auke Kok 4 | 5 | * entity_ai is licensed as follows: 6 | - All code is: LGPL-2.1 7 | - All artwork is: CC-BY-SA-4.0 8 | 9 | --]] 10 | 11 | -- 12 | -- Driver class - manage driver execution 13 | -- 14 | 15 | 16 | -- Class definition 17 | Driver = {} 18 | Driver.__index = Driver 19 | 20 | setmetatable(Driver, { 21 | __call = function(c, ...) 22 | return c.new(...) 23 | end, 24 | }) 25 | 26 | 27 | -- private functions 28 | local function driver_setup(self, driver) 29 | self.name = driver 30 | self.driver = entity_ai.registered_drivers[driver] 31 | self.properties = table.copy(self.object.script.properties) 32 | local driver_script = self.object.script[driver] 33 | if driver_script.properties then 34 | for k, v in pairs(driver_script.properties) do 35 | self.properties[k] = v 36 | end 37 | end 38 | end 39 | 40 | 41 | --- constructor 42 | function Driver.new(object, driver) 43 | local self = setmetatable({}, Driver) 44 | self.object = object 45 | driver_setup(self, driver) 46 | return self 47 | end 48 | 49 | 50 | -- public methods 51 | function Driver:switch(driver, factordata) 52 | self:stop() 53 | driver_setup(self, driver) 54 | self:start(factordata) 55 | end 56 | 57 | function Driver:start(factordata) 58 | -- sounds 59 | local script = self.object.script 60 | local sounds = script[self.name].sounds 61 | if sounds and sounds.start then 62 | local sound = script.sounds[sounds.start] 63 | if sound then 64 | local params = {max_hear_distance = sound[2].max_hear_distance, 65 | object = self.object.object} 66 | minetest.sound_play(sound[1], params) 67 | else 68 | minetest.log("error", "unknown sound '" .. sounds.start 69 | .. "' from " .. self.name .. " driver") 70 | end 71 | end 72 | --print("Calling driver start for driver " .. self.name) 73 | self.driver.start(self.object, factordata) 74 | end 75 | 76 | 77 | function Driver:stop() 78 | self.driver.stop(self.object) 79 | end 80 | 81 | function Driver:get_property(property) 82 | return self.properties[property] 83 | end 84 | 85 | function Driver:factor(name, data) 86 | -- valid factor for current driver? 87 | local script = self.object.script 88 | local driver = script[self.name].factors[name] 89 | if not driver then 90 | -- not valid for current driver! 91 | print("notice: invalid factor " .. name .. " for driver " .. self.name) 92 | return 93 | end 94 | self:switch(driver, {[name] = data}) 95 | end 96 | 97 | function Driver:step(dtime) 98 | -- factor handling 99 | local script = self.object.script 100 | for factor, factordriver in pairs(script[self.name].factors) do 101 | -- do we have a test we need to run? 102 | local factordata = nil 103 | if entity_ai.registered_factors[factor] and not factordata then 104 | factordata = entity_ai.registered_factors[factor](self.object, dtime) 105 | end 106 | -- check results 107 | if factordata then 108 | print("factor " .. factor .. " affects " .. self.name .. " driver changed to " .. factordriver) 109 | self:switch(factordriver, {[factor] = factordata}) 110 | return 111 | end 112 | end 113 | 114 | -- animation handling 115 | local state = self.object.entity_ai_state 116 | 117 | if state.animttl then 118 | state.animttl = state.animttl - dtime 119 | if state.animttl <= 0 then 120 | state.animttl = nil 121 | self:animation(state.animation, state.segment + 1) 122 | self:factor("anim_end", true) 123 | end 124 | end 125 | 126 | -- sound handling 127 | local sounds = script[self.name].sounds 128 | if math.random(1, 200) == 1 and sounds and sounds.random then 129 | local sound = script.sounds[sounds.random] 130 | if sound then 131 | local params = {max_hear_distance = sound[2].max_hear_distance, 132 | object = self.object.object} 133 | minetest.sound_play(sound[1], params) 134 | else 135 | minetest.log("error", "unknown sound '" .. sounds.random 136 | .. "' from " .. self.name .. " driver") 137 | end 138 | end 139 | 140 | -- execute driver specific step code 141 | self.driver.step(self.object, dtime) 142 | end 143 | 144 | function Driver:animation(animation, segment) 145 | local state = self.object.entity_ai_state 146 | state.animation = animation 147 | --print(self.name .. ": driver = " .. self.driver.name .. ", animation = " .. 148 | -- animation .. ", segment = " .. (segment or 0)) 149 | if not segment then 150 | local animations = self.object.script.animations[animation] 151 | if not animations then 152 | print(self.object.name .. ": no animations for " .. animation .. 153 | ", segment = " .. (segment or 0)) 154 | return 155 | end 156 | for i = 1, 3 do 157 | local animdef = animations[i] 158 | if animdef then 159 | state.segment = i 160 | -- calculate when to advance to next segment 161 | if not animdef.frame_loop then 162 | local animlen = (animdef[1].y - animdef[1].x) / animdef.frame_speed 163 | state.animttl = animlen 164 | else 165 | state.animttl = nil 166 | end 167 | self.object.object:set_animation(animdef[1], animdef.frame_speed, animdef.frame_loop) 168 | return 169 | end 170 | end 171 | else 172 | local animdef = self.object.script.animations[animation][segment] 173 | if animdef then 174 | state.segment = segment 175 | self.object.object:set_animation(animdef[1], animdef.frame_speed, animdef.frame_loop) 176 | return 177 | end 178 | end 179 | print("animation_select: can't find animation " .. state.animation .. " for driver " .. 180 | state.driver .. " for entity " .. self.object.name) 181 | end 182 | -------------------------------------------------------------------------------- /drivers.lua: -------------------------------------------------------------------------------- 1 | 2 | --[[ 3 | 4 | Copyright (c) 2016-2019 - Auke Kok 5 | 6 | * entity_ai is licensed as follows: 7 | - All code is: LGPL-2.1 8 | - All artwork is: CC-BY-SA-4.0 9 | 10 | --]] 11 | 12 | entity_ai.register_driver("roam", { 13 | start = function(self) 14 | -- start with idle animation unless we get a path 15 | self.driver:animation("idle") 16 | local state = self.entity_ai_state 17 | state.roam_ttl = math.random(3, 9) 18 | 19 | self.path = Path(self) 20 | if not self.path:find() then 21 | --print("Unable to calculate path") 22 | self.driver:switch("idle") 23 | return 24 | end 25 | 26 | -- done, roaming mode good! 27 | self.driver:animation("move") 28 | end, 29 | step = function(self, dtime) 30 | -- handle movement stuff 31 | local state = self.entity_ai_state 32 | if state.roam_ttl and state.roam_ttl <= 0 then 33 | self.driver:switch("idle") 34 | return 35 | end 36 | state.roam_ttl = state.roam_ttl - dtime 37 | 38 | -- do path movement 39 | if not self.path or self.path:distance() < 0.7 or 40 | not self.path:step(dtime) then 41 | self.driver:switch("idle") 42 | return 43 | end 44 | end, 45 | stop = function(self) 46 | local state = self.entity_ai_state 47 | state.roam_ttl = nil 48 | end, 49 | }) 50 | 51 | entity_ai.register_driver("idle", { 52 | start = function(self) 53 | self.driver:animation("idle") 54 | self.object:setvelocity(vector.new()) 55 | local state = self.entity_ai_state 56 | state.idle_ttl = math.random(2, 20) 57 | -- sanity checks 58 | check_trapped_and_escape(self) 59 | end, 60 | step = function(self, dtime) 61 | local state = self.entity_ai_state 62 | state.idle_ttl = state.idle_ttl - dtime 63 | if state.idle_ttl <= 0 then 64 | self.driver:switch("roam") 65 | return 66 | end 67 | end, 68 | stop = function(self) 69 | local state = self.entity_ai_state 70 | state.idle_ttl = nil 71 | end, 72 | }) 73 | 74 | entity_ai.register_driver("startle", { 75 | start = function(self, factordata) 76 | -- startle animation 77 | self.driver:animation("startle") 78 | self.object:setvelocity(vector.new()) 79 | -- collect info we want to use in this driver 80 | local state = self.entity_ai_state 81 | if factordata and factordata["got_hit"] then 82 | state.attacker = factordata["got_hit"][1] 83 | state.attacked_at = factordata["got_hit"][5] 84 | end 85 | end, 86 | step = function(self, dtime) 87 | end, 88 | stop = function(self) 89 | -- play out remaining animations 90 | end, 91 | }) 92 | 93 | entity_ai.register_driver("eat", { 94 | start = function(self, factordata) 95 | self.driver:animation("eat") 96 | self.object:setvelocity(vector.new()) 97 | -- collect info we want to use in this driver 98 | local state = self.entity_ai_state 99 | state.eat_ttl = math.random(30, 60) 100 | if factordata and factordata.near_foodnode then 101 | state.food = factordata.near_foodnode 102 | end 103 | end, 104 | step = function(self, dtime) 105 | local state = self.entity_ai_state 106 | if state.eat_ttl > 0 then 107 | state.eat_ttl = state.eat_ttl - dtime 108 | return 109 | end 110 | state.ate_enough = math.random(200, 300) 111 | self.driver:switch("eat_end") 112 | end, 113 | stop = function(self) 114 | local state = self.entity_ai_state 115 | state.eat_ttl = nil 116 | -- increase HP 117 | local hp = self.object:get_hp() 118 | if hp < self.driver:get_property("hp_max") then 119 | self.object:set_hp(hp + 1) 120 | end 121 | 122 | -- eat foodnode 123 | local food = state.food 124 | if not food then 125 | return 126 | end 127 | 128 | local node = minetest.get_node(food) 129 | minetest.sound_play(minetest.registered_nodes[node.name].sounds.dug, {pos = food, max_hear_distance = 18}) 130 | if node.name == "default:dirt_with_grass" or node.name == "default:dirt_with_dry_grass" then 131 | minetest.set_node(food, {name = "default:dirt"}) 132 | --elseif node.name == "default:grass_1" or node.name == "default:dry_grass_1" then 133 | -- minetest.remove_node(food) 134 | elseif node.name == "default:grass_2" then 135 | minetest.set_node(food, {name = "default:grass_1"}) 136 | elseif node.name == "default:grass_3" then 137 | minetest.set_node(food, {name = "default:grass_2"}) 138 | elseif node.name == "default:grass_4" then 139 | minetest.set_node(food, {name = "default:grass_3"}) 140 | elseif node.name == "default:grass_5" then 141 | minetest.set_node(food, {name = "default:grass_4"}) 142 | elseif node.name == "default:dry_grass_2" then 143 | minetest.set_node(food, {name = "default:dry_grass_1"}) 144 | elseif node.name == "default:dry_grass_3" then 145 | minetest.set_node(food, {name = "default:dry_grass_2"}) 146 | elseif node.name == "default:dry_grass_4" then 147 | minetest.set_node(food, {name = "default:dry_grass_3"}) 148 | elseif node.name == "default:dry_grass_5" then 149 | minetest.set_node(food, {name = "default:dry_grass_4"}) 150 | end 151 | 152 | state.food = nil 153 | end, 154 | }) 155 | 156 | entity_ai.register_driver("eat_end", { 157 | start = function(self) 158 | self.driver:animation("eat") 159 | self.object:setvelocity(vector.new()) 160 | end, 161 | step = function(self, dtime) 162 | end, 163 | stop = function(self) 164 | end, 165 | }) 166 | 167 | 168 | entity_ai.register_driver("flee", { 169 | start = function(self) 170 | self.driver:animation("move") 171 | local state = self.entity_ai_state 172 | state.flee_start = minetest.get_us_time() 173 | end, 174 | step = function(self, dtime) 175 | -- check timer ourselves 176 | local state = self.entity_ai_state 177 | if (minetest.get_us_time() - state.flee_start) > (15 * 1000000) then 178 | state.flee_start = nil 179 | self.driver:switch("roam") 180 | return 181 | end 182 | 183 | -- are we fleeing yet? 184 | if self.path and self.path.distance then 185 | -- stop fleeing if we're at a safe distance 186 | -- execute flee path 187 | if self.path:distance() < 2.0 then 188 | -- get a new flee path 189 | self.path = {} 190 | else 191 | -- follow path 192 | if not self.path:step() then 193 | self.path = {} 194 | end 195 | end 196 | else 197 | self.path = Path(self) 198 | if not self.path:find() then 199 | --print("Unable to calculate path") 200 | return 201 | end 202 | 203 | -- done, flee path good! 204 | self.driver:animation("move") 205 | end 206 | end, 207 | stop = function(self) 208 | -- play out remaining animations 209 | end, 210 | }) 211 | 212 | entity_ai.register_driver("death", { 213 | start = function(self) 214 | -- start with moving animation 215 | self.driver:animation("idle") 216 | end, 217 | step = function(self, dtime) 218 | end, 219 | stop = function(self) 220 | -- play out remaining animations 221 | end, 222 | }) 223 | 224 | -------------------------------------------------------------------------------- /init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | Copyright (c) 2016-2019 - Auke Kok 4 | 5 | * entity_ai is licensed as follows: 6 | - All code is: LGPL-2.1 7 | - All artwork is: CC-BY-SA-4.0 8 | 9 | --]] 10 | 11 | --[[ 12 | General API design ideas: 13 | -- spawning a new entity 14 | obj = Entity({name = "sheep", state = {}}) 15 | 16 | -- drivers 17 | self.driver:switch(self, driver) 18 | self.driver:step() 19 | self.driver:start() 20 | self.driver:stop() 21 | 22 | - entity programming should use object:method() design. 23 | - creating an entity should use simple methods as follows: 24 | 25 | minetest.register_entity("sofar:sheep", { 26 | ..., 27 | on_activate = entity_ai:on_activate, 28 | on_step = entity_ai:on_step, 29 | on_punch = entity_ai:on_punch, 30 | on_rightclick = entity_ai:on_rightclick, 31 | get_staticdata = entity_ai:get_staticdata, 32 | }) 33 | 34 | entity activity is a structure organized as a graph: 35 | 36 | events may cause: 37 | -> [flee] 38 | -> [defend] 39 | -> [dead] 40 | -> [return] 41 | initial states 42 | [roam] 43 | [guard] 44 | [hunt] 45 | 46 | etc.. 47 | 48 | Each state may have several substates 49 | 50 | [idle] -> { idle.1, idle.2, idle.3 } 51 | 52 | Each state has a "driver". This is the algorithm that makes the entity do 53 | stuff. "do stuff" can mean "stand still", "move to a pos", "attack something" or 54 | a combination of any of these, including "use a node", "place a node" etc. 55 | 56 | -- returns: nil 57 | obj:driver_eat_grass = function(self) end 58 | obj:driver_idle = function(self) end 59 | obj:driver_find_food = function(self) end 60 | obj:driver_defend = ... 61 | obj:driver_death = ... 62 | obj:driver_mate = ... 63 | 64 | Each state has several "factors". These are conditions that may be met at any 65 | point in time. Factors can be "A node is nearby that can be grazed on", "close to water", 66 | "fertile", "was hit recently", "took damage recently", "a hostile faction is nearby" 67 | 68 | -- returns: bool 69 | obj:factor_is_fertile = function(self) end 70 | obj:factor_is_near_foodnode = function(self) end 71 | obj:factor_was_hit = function(self) end 72 | obj:factor_is_near_mate = ... 73 | 74 | --]] 75 | 76 | -- 77 | -- misc functions 78 | -- 79 | 80 | 81 | function check_trapped_and_escape(self) 82 | local pos = vector.round(self.object:getpos()) 83 | local node = minetest.get_node(pos) 84 | if minetest.registered_nodes[node.name].walkable then 85 | -- stuck, can we go up? 86 | local p2 = {x = pos.x, y = pos.y + 1, z = pos.z} 87 | local n2 = minetest.get_node(p2) 88 | if not minetest.registered_nodes[n2.name].walkable then 89 | --print("monster trapped, escaped upward!") 90 | self.object:setpos({x = pos.x, y = p2.y + 0.5, z = pos.z}) 91 | else 92 | print("monster trapped but can't escape upward!", minetest.pos_to_string(pos)) 93 | end 94 | end 95 | end 96 | 97 | -- 98 | -- globals 99 | -- 100 | entity_ai = {} 101 | 102 | entity_ai.registered_drivers = {} 103 | function entity_ai.register_driver(name, def) 104 | assert(not entity_ai.registered_drivers[name]) 105 | entity_ai.registered_drivers[name] = def 106 | end 107 | 108 | entity_ai.registered_factors = {} 109 | function entity_ai.register_factor(name, func) 110 | assert(not entity_ai.registered_factors[name]) 111 | entity_ai.registered_factors[name] = func 112 | end 113 | 114 | entity_ai.registered_finders = {} 115 | function entity_ai.register_finder(name, func) 116 | assert(not entity_ai.registered_finders[name]) 117 | entity_ai.registered_finders[name] = func 118 | end 119 | 120 | 121 | -- 122 | -- includes 123 | -- 124 | local modpath = minetest.get_modpath(minetest.get_current_modname()) 125 | 126 | dofile(modpath .. "/path.lua") 127 | dofile(modpath .. "/driver.lua") 128 | 129 | -- 130 | -- standard entity methods 131 | -- 132 | 133 | local function entity_ai_on_activate(self, staticdata) 134 | self.entity_ai_state = {} 135 | 136 | local driver 137 | 138 | if staticdata ~= "" then 139 | -- load staticdata 140 | self.entity_ai_state = minetest.deserialize(staticdata) 141 | if not self.entity_ai_state then 142 | print("entity_ai entity without saved state, removing") 143 | self.object:remove() 144 | return 145 | end 146 | 147 | local state = self.entity_ai_state 148 | 149 | -- driver class, has to come before path 150 | if state.driver_save then 151 | driver = state.driver_save 152 | state.driver_save = nil 153 | else 154 | driver = self.script.driver 155 | end 156 | self.driver = Driver(self, driver) 157 | state.driver_save = nil 158 | 159 | -- path class 160 | if self.script[driver].finders then 161 | if state.path_save then 162 | self.path = Path(self, state.path_save.target) 163 | self.path:set_config(state.path_save.config) 164 | self.path:find() 165 | state.path_save = {} 166 | end 167 | end 168 | 169 | --print("loaded: " .. self.name .. ", driver=" .. driver ) 170 | else 171 | -- set initial monster driver 172 | driver = self.script.driver 173 | self.driver = Driver(self, driver) 174 | --print("activate: " .. self.name .. ", driver=" .. driver) 175 | end 176 | 177 | -- properties 178 | self.object:set_hp(self.driver:get_property("hp_max")) 179 | 180 | -- gravity 181 | self.object:setacceleration({x = 0, y = -9.81, z = 0}) 182 | 183 | -- init driver 184 | self.driver:start() 185 | end 186 | 187 | local function entity_ai_on_step(self, dtime) 188 | self.driver:step(dtime) 189 | end 190 | 191 | local function entity_ai_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) 192 | -- sounds? 193 | minetest.sound_play("on_punch", {object = self.object}) 194 | 195 | -- hp dmg 196 | if self.object:get_hp() == 0 then 197 | --FIXME 198 | print("death") 199 | self.driver:switch("death") 200 | return 201 | end 202 | 203 | -- factor 204 | self.driver:factor("got_hit", { 205 | puncher:get_player_name(), 206 | time_from_last_punch, 207 | tool_capabilities, 208 | dir, 209 | self.object:getpos() 210 | }) 211 | end 212 | 213 | local function entity_ai_on_rightclick(self, clicker) 214 | end 215 | 216 | local function entity_ai_get_staticdata(self) 217 | --print("saved: " .. self.name) 218 | local state = self.entity_ai_state 219 | state.driver_save = self.driver.name 220 | if self.path and self.path.save then 221 | state.path_save = self.path:save() 222 | end 223 | return minetest.serialize(state) 224 | end 225 | 226 | 227 | function entity_ai.register_entity(name, def) 228 | -- FIXME add some sort of entity registration table 229 | -- FIXME handle spawning and reloading? 230 | def.name = name 231 | def.physical = def.physical or true 232 | def.visual = def.visual or "mesh" 233 | def.makes_footstep_sound = def.makes_footstep_sound or true 234 | def.stepheight = def.stepheight or 0.55 235 | def.collisionbox = def.collisionbox or {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2} 236 | -- entity_ai callbacks 237 | def.on_activate = entity_ai_on_activate 238 | def.on_step = entity_ai_on_step 239 | def.on_punch = entity_ai_on_punch 240 | def.on_rightclick = entity_ai_on_rightclick 241 | def.get_staticdata = entity_ai_get_staticdata 242 | 243 | minetest.register_entity(name, def) 244 | end 245 | 246 | -- load builtin registrations 247 | dofile(modpath .. "/finders.lua") 248 | dofile(modpath .. "/factors.lua") 249 | dofile(modpath .. "/drivers.lua") 250 | 251 | -- load entities 252 | dofile(modpath .. "/sheep.lua") 253 | dofile(modpath .. "/stone_giant.lua") 254 | 255 | 256 | -- misc. 257 | --minetest.register_on_joinplayer(function(player) 258 | -- minetest.add_entity({x=31.0,y=2.0,z=96.0}, "entity_ai:stone_giant") 259 | --end) 260 | -------------------------------------------------------------------------------- /cc-by-sa-4.0.txt: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. 428 | 429 | -------------------------------------------------------------------------------- /lgpl-2.1.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | --------------------------------------------------------------------------------