Various fixes, improvements, wip
parent
d0f4bb185c
commit
6a9e37a3bb
12
README.md
12
README.md
|
@ -212,7 +212,13 @@ Dig the node at the given position. Must be within range.
|
|||
#### place, with pos={x,y,z} and item=name
|
||||
Places the given item. Must be in the inventory, and in range.
|
||||
|
||||
#### stash, with dest="nodename" and items={"item1", "itemn"}
|
||||
#### stash
|
||||
|
||||
* Required parameter: items={"item1", ..."itemn"}
|
||||
* Optional parameter: pos={x,y,z} - position of node to stash in
|
||||
* Optional parameter: dest="node" - node name to stash in
|
||||
(e.g. "default:chest")
|
||||
|
||||
Places items into a destination node, which should be something like a chest.
|
||||
Specifically, it needs to be a node with a "main" inventory list. So for a
|
||||
normal chest, use "default:chest" for the nodename.
|
||||
|
@ -247,8 +253,8 @@ All parameters are optional:
|
|||
So calling with no parameters at all turns off gathering.
|
||||
|
||||
Gathering remains in effect until it is switched off, or until the person
|
||||
is re-programmed. Gathering actually happens during "go" actions only (but
|
||||
this includes any action that uses "go" as a subaction).
|
||||
is re-programmed. Gathering actually happens during "go" and "wait" actions
|
||||
only (but this includes any action that uses "go" as a subaction).
|
||||
|
||||
#### step
|
||||
Allow's the person's lua code to handle on_step itself. It will receive
|
||||
|
|
|
@ -9,8 +9,9 @@ people.actions.dig = function(state)
|
|||
end
|
||||
|
||||
local distance = vector.distance(state.pos, state.action.pos)
|
||||
if distance > 5 then
|
||||
dbg.v1(state.ent.name.." too far away to dig "..minetest.pos_to_string(foundpos))
|
||||
if distance > 7 then
|
||||
dbg.v1(state.ent.name.." too far away to dig "..minetest.pos_to_string(state.action.pos)..
|
||||
" from "..minetest.pos_to_string(state.pos).." - "..distance)
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ people.actions.go = function(state)
|
|||
state.action.intermediate = nil
|
||||
end
|
||||
state.wait = 2
|
||||
return false
|
||||
return true
|
||||
|
||||
else
|
||||
if not state.action.intermediate then
|
||||
|
@ -233,6 +233,39 @@ people.actions.go = function(state)
|
|||
state.speed = 2
|
||||
end
|
||||
state.yaw = vector.get_yaw(state.pos, curdest)
|
||||
|
||||
-- Abort if we're going to walk somewhere unpleasant
|
||||
local erk = nil
|
||||
local ahead = state.speed
|
||||
if ahead > 0.5 then ahead = 0.5 end
|
||||
local nd = vector.from_speed_yaw(ahead, state.yaw)
|
||||
local nextpos = vector.add(state.pos, nd)
|
||||
nextpos.y = nextpos.y + 1
|
||||
local ncount = 4
|
||||
while ncount > 0 do
|
||||
local nn = minetest.get_node(nextpos).name
|
||||
if nn == "default:water_flowing" or nn == "default:water_source" or nn == "default:lava_flowing" or nn == "default:lava_source" then
|
||||
erk = nn
|
||||
break
|
||||
end
|
||||
nd = minetest.registered_nodes[nn]
|
||||
if not nd then
|
||||
erk = nn
|
||||
break
|
||||
end
|
||||
if nd.walkable then
|
||||
break
|
||||
end
|
||||
nextpos.y = nextpos.y - 1
|
||||
ncount = ncount - 1
|
||||
end
|
||||
if ncount == 0 then erk = "fall" end
|
||||
if erk then
|
||||
dbg.v1(state.ent.name.." aborted go due to fear of " .. erk)
|
||||
state.speed = 0
|
||||
state.wait = 2
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -38,8 +38,10 @@ people.footpath_load = function()
|
|||
-- Now we need to undo the dereferencing we did when we saved it...
|
||||
for _, nn in pairs(pathnodes) do
|
||||
local nei = {}
|
||||
for _, ne in pairs(nn.neighbours) do
|
||||
table.insert(nei, pathnodes[ne])
|
||||
if nn.neighbours then
|
||||
for _, ne in pairs(nn.neighbours) do
|
||||
table.insert(nei, pathnodes[ne])
|
||||
end
|
||||
end
|
||||
nn.neighbours = nei
|
||||
end
|
||||
|
|
60
init.lua
60
init.lua
|
@ -30,7 +30,7 @@ dofile(people_modpath .. "/actions/stash_and_retrieve.lua")
|
|||
people.footpath_load()
|
||||
|
||||
people.presets = {}
|
||||
for _, p in ipairs({"FollowOwner", "SimpleCommands", "RouteWalker", "FarmHand"}) do
|
||||
for _, p in ipairs({"FollowOwner", "SimpleCommands", "RouteWalker", "FarmHand", "TreeFarmer"}) do
|
||||
local file = io.open(minetest.get_modpath("people").."/presets/"..p..".lua", "r")
|
||||
local code
|
||||
if file then
|
||||
|
@ -110,8 +110,14 @@ function people.get_inv(self, name)
|
|||
end
|
||||
|
||||
minetest.register_entity("people:person" ,{
|
||||
hp_max = 1,
|
||||
hp_max = 20,
|
||||
physical = true,
|
||||
|
||||
-- TODO For now at least, don't collide with objects - specifically I don't
|
||||
-- want them colliding with other 'people' or players, for the same reason
|
||||
-- players don't collide with each other.
|
||||
collide_with_objects = false,
|
||||
|
||||
armor_groups = {immortal=1},
|
||||
collisionbox = {-0.35,0,-0.35, 0.35,1.75,0.35},
|
||||
visual = "mesh",
|
||||
|
@ -249,16 +255,21 @@ minetest.register_entity("people:person" ,{
|
|||
end,
|
||||
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, killed)
|
||||
local playername = puncher:get_player_name()
|
||||
if killed then
|
||||
if people.people[self.name] then
|
||||
people.people[self.name].dead = true
|
||||
if playername then
|
||||
dbg.v1(self.name.." killed by "..playername)
|
||||
else
|
||||
dbg.v1(self.name.." killed by something mysterious")
|
||||
end
|
||||
else
|
||||
dbg.v1("Unknown person killed")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local playername = puncher:get_player_name()
|
||||
if playername then
|
||||
local event = {type="punched", puncher=playername}
|
||||
local err = people.exec_event(self, event)
|
||||
|
@ -322,30 +333,59 @@ minetest.register_entity("people:person" ,{
|
|||
local done = false
|
||||
|
||||
if #self.gather.nodes > 0 then
|
||||
dbg.v1(self.name.." looking for "..dump(self.gather.nodes).." near "..minetest.pos_to_string(pos))
|
||||
local foundpos = minetest.find_node_near(vector.round(pos), 3, self.gather.nodes)
|
||||
dbg.v2(self.name.." looking for "..dump(self.gather.nodes).." near "..minetest.pos_to_string(pos))
|
||||
local foundpos = minetest.find_node_near(
|
||||
vector.add(vector.round(pos), {x=0,y=1,z=0}),
|
||||
3, self.gather.nodes)
|
||||
if foundpos then
|
||||
local n = minetest.get_node(foundpos)
|
||||
dbg.v1(self.name.." found "..n.name.." at "..minetest.pos_to_string(foundpos))
|
||||
dbg.v2(self.name.." found "..n.name.." at "..minetest.pos_to_string(foundpos))
|
||||
self.action = {"dig", pos=foundpos, prevaction=self.action}
|
||||
done = true
|
||||
end
|
||||
end
|
||||
if not done and #self.gather.items > 0 then
|
||||
dbg.v2(self.name.." looking for items "..dump(self.gather.items).." near "..minetest.pos_to_string(pos))
|
||||
local objects = minetest.get_objects_inside_radius(
|
||||
vector.add(vector.round(pos), {x=0,y=1,z=0}), 6)
|
||||
for _, obj in ipairs(objects) do
|
||||
if obj:get_entity_name() == "__builtin:item" then
|
||||
local ent = obj:get_lua_entity()
|
||||
if ent.itemstring then
|
||||
for _, ti in ipairs(self.gather.items) do
|
||||
if string.match("^" + ti + " .*", ent.itemstring) then
|
||||
self.action = {"pickup", pos=obj:get_pos(),
|
||||
item=ti, prevaction=self.action}
|
||||
done = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if done then break end
|
||||
end
|
||||
end
|
||||
|
||||
if not done and self.gather.plant then
|
||||
|
||||
if self.gather.plant and type(self.gather.plant) == "string" and
|
||||
self.inventory:contains_item("main", ItemStack(self.gather.plant)) then
|
||||
|
||||
if self.gather.plant == "default:sapling" then
|
||||
soilitems = {"default:dirt", "default:dirt_with_grass"}
|
||||
else
|
||||
soilitems = {"farming:soil_wet"}
|
||||
end
|
||||
|
||||
soils = minetest.find_nodes_in_area(
|
||||
{x=pos.x-3, y=pos.y-2, z=pos.z-3},
|
||||
{x=pos.x+3, y=pos.y+2, z=pos.z+3},
|
||||
{"farming:soil_wet"})
|
||||
{x=pos.x-3, y=pos.y-2, z=pos.z-3},
|
||||
{x=pos.x+3, y=pos.y+2, z=pos.z+3},
|
||||
soilitems)
|
||||
for _, foundpos in pairs(soils) do
|
||||
plantpos = {x=foundpos.x,y=foundpos.y+1,z=foundpos.z}
|
||||
local n = minetest.get_node(plantpos)
|
||||
if n.name == "air" then
|
||||
dbg.v1(self.name.." found empty wet soil below "..minetest.pos_to_string(plantpos))
|
||||
dbg.v1(self.name.." found empty soil below "..minetest.pos_to_string(plantpos))
|
||||
self.action = {"place", pos=plantpos, item=self.gather.plant, prevaction=self.action}
|
||||
done = true
|
||||
break
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
if event.type == "program" then
|
||||
mem.cur = 1
|
||||
mem.actions = {
|
||||
|
||||
{"go", name="Jeiffel Tree Farm"},
|
||||
{"wait", time=10},
|
||||
|
||||
{"go", pos={x=-173,y=9.5,z=-244}},
|
||||
{"gather", nodes={"default:tree", "default:leaves", "default:apple"},
|
||||
items={"default:apple", "default:sapling"},
|
||||
plant="default:sapling"}
|
||||
{"go", pos={x=-173,y=9.5,z=-250}},
|
||||
{"go", pos={x=-169,y=9.5,z=-250}},
|
||||
{"go", pos={x=-169,y=9.5,z=-244}},
|
||||
{"wait", time=120},
|
||||
|
||||
-- Leave the item gathering on for the rest of the time - might as
|
||||
-- well clean up any that are lying around near the paths.
|
||||
{"gather", items={"default:apple", "default:sapling"}},
|
||||
|
||||
-- Chuck all harvested stuff in the recycle bin. It will end up
|
||||
-- at the factory.
|
||||
{"go", name="Jeiffel Tower"},
|
||||
{"wait", time=5},
|
||||
{"go", pos={x=-221,y=1.5,z=-187}},
|
||||
{"stash", dest="default:chest",
|
||||
items={"*default:tree",
|
||||
"*default:leaves",
|
||||
"*default:apple",
|
||||
"*default:sapling"}}
|
||||
|
||||
}
|
||||
|
||||
elseif event.type == "act" then
|
||||
|
||||
action = mem.actions[mem.cur]
|
||||
|
||||
mem.cur = mem.cur + 1
|
||||
if mem.cur > #mem.actions then
|
||||
mem.cur = 1
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue