entity_ai/sheep.lua
Auke Kok 8a62d34438 Major refactor.
All step code is now part of the driver engine:
- sound steps
- factor accounting
- factor-based switching
- animation step handling.

Moreover, there is no more local factor state subtable,
and factors need to return or pass factordata to the
driver method. Factordata is only passed to the .start()
method as well, but that can then store the needed data
into the entity_ai_state as needed by the driver itself.

This still has an issue with entity animation sequence
ends, as far as I can see, in the sheep eat driver. This
will need further work.

finders, drivers and factors are now all in separate files.

The sheep script has been partially cleaned up to account
for the differences

Many asserts were added. We need to keep these until things
become more stable, and possibly add a ton more of them to
make sure we're not passing garbage.

A luacheck file is added to keep things sane going forward.
2017-04-05 00:28:22 -07:00

195 lines
3.9 KiB
Lua

--[[
Copyright (c) 2016 - Auke Kok <sofar@foo-projects.org>
* entity_ai is licensed as follows:
- All code is: GNU Affero General Public License, Version 3.0 (AGPL-3.0)
- All artwork is: CC-BY-ND-4.0
A Contributor License Agreement exists, please read:
- https://github.com/sofar/entity_ai/readme.md.
--]]
--
-- sheep entity AI script
--
local sheep_script = {
-- the start driver. Should be able to spawn a monster with a different driver!
driver = "roam",
-- default properties
properties = {
speed = 2.0,
hp_max = 20,
foodnodes = {
"group:grass",
"default:dirt_with_grass",
"default:dirt_with_dry_grass",
"default:grass_1",
"default:grass_2",
"default:grass_3",
"default:grass_4",
"default:grass_5",
"default:dry_grass_1",
"default:dry_grass_2",
"default:dry_grass_3",
"default:dry_grass_4",
"default:dry_grass_5",
},
habitatnodes = {
"group:flora",
"group:snappy",
"group:dirt",
"group:soil",
"group:crumbly",
"group:grass",
"default:dirt_with_grass",
"default:dirt_with_dry_grass",
"default:sand"
,}
},
-- defined animation sets:
-- "name" = { animationspec1, animationspec2, animationspec3 .. }
-- each must be present -> 'nil' required
-- last animation should have 'frame_loop = true'
--FIXME handle repeats (running animation 5x ?)
animations = {
move = {
{{x = 0, y = 40}, frame_speed = 60, frame_loop = true},
},
run = {
{{x = 0, y = 40}, frame_speed = 90, frame_loop = true},
},
idle = {
{{x = 111, y = 129}, frame_speed = 10, frame_loop = true},
},
eat = {
{{x = 41, y = 47}, frame_speed = 15, frame_loop = false},
{{x = 47, y = 75}, frame_speed = 15, frame_loop = true},
},
eat_end = {
{{x = 75, y = 81}, frame_speed = 15, frame_loop = false},
},
startle = {
{{x = 100, y = 110}, frame_speed = 30, frame_loop = false},
{{x = 111, y = 119}, frame_speed = 30, frame_loop = true},
},
death = {
{{x = 82, y = 90}, frame_speed = 15, frame_loop = false},
{{x = 90, y = 99}, frame_speed = 15, frame_loop = true},
},
},
-- sound samples
sounds = {
chatter = {{name = "sheep_chatter", gain = 0.2}, {max_hear_distance = 12}},
footsteps = {{name = "sheep_steps", gain = 0.2}, {max_hear_distance = 12}},
hurt = {{name = "sheep_hurt", gain = 0.5}, {max_hear_distance = 18}},
},
-- monster script states:
roam = {
finders = {
"find_habitat",
},
factors = {
got_hit = "startle",
became_fertile = "fertile",
attractor_nearby = "attracted",
},
sounds = {
random = "footsteps",
},
},
idle = {
factors = {
got_hit = "startle",
became_fertile = "fertile",
attractor_nearby = "attracted",
too_far_from_home = "homing",
near_foodnode = "eat",
},
sounds = {
random = "chatter",
},
},
eat = {
factors = {
got_hit = "startle",
became_fertile = "fertile",
attractor_nearby = "attracted",
},
sounds = {
random = "chatter",
},
},
eat_end = {
factors = {
anim_end = "idle",
}
},
startle = {
factors = {
anim_end = "flee",
},
sounds = {
start = "hurt",
},
},
flee = {
finders = {
"flee_attacker",
},
properties = {
speed = 4.0,
},
factors = {
got_hit = "startle",
},
sounds = {
random = "footsteps",
},
},
attracted = {
factors = {
got_hit = "startle",
became_fertile = "fertile",
approached_too_long = "roam",
},
sounds = {
random = "chatter",
},
},
fertile = {
factors = {
got_hit = "startle",
},
sounds = {
random = "chatter",
},
},
homing = {
factors = {
near_home = "roam",
got_hit = "startle",
},
sounds = {
random = "chatter",
},
},
death = {
sounds = {
start = "hurt",
},
},
}
entity_ai.register_entity("entity_ai:sheep", {
script = sheep_script,
mesh = "sheep.b3d",
textures = {"sheep_fur.png"},
makes_footstep_sound = true,
collisionbox = {-5/16, -1/2, -5/16, 5/16, 4/16, 5/16},
})