1
0
mirror of https://github.com/tacigar/maidroid.git synced 2024-11-05 01:30:31 +01:00

Update farming core

This commit is contained in:
tacigar 2016-12-22 19:56:50 +09:00
parent bac29556f0
commit 0e9ca5a64b

View File

@ -57,7 +57,16 @@ do -- register farming core
end end
local function on_stop(self) local function on_stop(self)
self.object:setvelocity{x = 0, y = 0, z = 0}
self.state = nil
self.time_counters = nil
self.path = nil
end
local function is_near(self, pos, distance)
local p = self.object:getpos()
p.y = p.y + 0.5
return vector.distance(p, pos) < distance
end end
local searching_range = {x = 5, y = 2, z = 5} local searching_range = {x = 5, y = 2, z = 5}
@ -160,7 +169,7 @@ do -- register farming core
end end
walk_to_plant_and_mow_common = function(self, dtime) walk_to_plant_and_mow_common = function(self, dtime)
if vector.distance(self.object:getpos(), self.destination) < 1.0 then if is_near(self, self.destination, 1.0) then
if self.state == state.WALK_TO_PLANT then if self.state == state.WALK_TO_PLANT then
to_plant(self) to_plant(self)
return return
@ -175,7 +184,11 @@ do -- register farming core
return return
end end
self.time_counters[1] = self.time_counters[1] + 1
self.time_counters[2] = self.time_counters[2] + 1
if self.time_counters[1] >= FIND_PATH_TIME_INTERVAL then if self.time_counters[1] >= FIND_PATH_TIME_INTERVAL then
print("KOKOKOK")
self.time_counters[1] = 0 self.time_counters[1] = 0
self.time_counters[2] = self.time_counters[2] + 1 self.time_counters[2] = self.time_counters[2] + 1
local path = minetest.find_path(self.object:getpos(), self.destination, 10, 1, 1, "A*") local path = minetest.find_path(self.object:getpos(), self.destination, 10, 1, 1, "A*")
@ -187,7 +200,8 @@ do -- register farming core
end end
-- follow path -- follow path
if vector.distance(self.path[1], self.object:getpos()) < 0.01 then if is_near(self, self.path[1], 0.01) then
print("KOK")
table.remove(self.path, 1) table.remove(self.path, 1)
if #self.path == 0 then -- end of path if #self.path == 0 then -- end of path
@ -205,6 +219,7 @@ do -- register farming core
else else
-- self:change_direction(self.path[1]) -- self:change_direction(self.path[1])
-- if maidroid is stopped by obstacles, the maidroid must jump. -- if maidroid is stopped by obstacles, the maidroid must jump.
-- self:change_direction(self.path[1])
local velocity = self.object:getvelocity() local velocity = self.object:getvelocity()
if velocity.y == 0 then if velocity.y == 0 then
local front_node = self:get_front_node() local front_node = self:get_front_node()
@ -219,9 +234,10 @@ do -- register farming core
if self.time_counters[1] >= 15 then if self.time_counters[1] >= 15 then
if is_plantable_place(self.destination) then if is_plantable_place(self.destination) then
local stack = self:get_wield_item_stack() local stack = self:get_wield_item_stack()
local itemname = stack:get_name()
minetest.add_node(self.destination, {name = itemname, param2 = 1})
stack:take_item(1) stack:take_item(1)
self:set_wield_item_stack(stack) self:set_wield_item_stack(stack)
return
end end
to_walk_randomly(self) to_walk_randomly(self)
return return