mirror of
https://github.com/tacigar/maidroid.git
synced 2024-11-16 15:20:21 +01:00
Update farming core
This commit is contained in:
parent
70d8a67a73
commit
712efe7fee
|
@ -65,7 +65,7 @@ do -- register farming core
|
||||||
|
|
||||||
local function is_near(self, pos, distance)
|
local function is_near(self, pos, distance)
|
||||||
local p = self.object:getpos()
|
local p = self.object:getpos()
|
||||||
p.y = p.y + 0.5
|
-- p.y = p.y + 0.5
|
||||||
return vector.distance(p, pos) < distance
|
return vector.distance(p, pos) < distance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,10 +92,6 @@ do -- register farming core
|
||||||
if destination ~= nil then
|
if destination ~= nil then
|
||||||
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
|
local path = minetest.find_path(self.object:getpos(), destination, 10, 1, 1, "A*")
|
||||||
if path ~= nil then -- to walk to mow state.
|
if path ~= nil then -- to walk to mow state.
|
||||||
for _, p in ipairs(path) do
|
|
||||||
print(p.x, p.y, p.z)
|
|
||||||
end
|
|
||||||
|
|
||||||
to_walk_to_mow(self, path, destination)
|
to_walk_to_mow(self, path, destination)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -111,12 +107,19 @@ do -- register farming core
|
||||||
else
|
else
|
||||||
self.time_counters[1] = self.time_counters[1] + 1
|
self.time_counters[1] = self.time_counters[1] + 1
|
||||||
self.time_counters[2] = self.time_counters[2] + 1
|
self.time_counters[2] = self.time_counters[2] + 1
|
||||||
|
|
||||||
|
local velocity = self.object:getvelocity()
|
||||||
|
if velocity.y == 0 then
|
||||||
|
local front_node = self:get_front_node()
|
||||||
|
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name].walkable then
|
||||||
|
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
|
||||||
|
end
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
to_walk_randomly = function(self)
|
to_walk_randomly = function(self)
|
||||||
print("to walk randomly")
|
|
||||||
self.state = state.WALK_RANDOMLY
|
self.state = state.WALK_RANDOMLY
|
||||||
self.time_counters[1] = 0
|
self.time_counters[1] = 0
|
||||||
self.time_counters[2] = 0
|
self.time_counters[2] = 0
|
||||||
|
@ -125,7 +128,6 @@ do -- register farming core
|
||||||
end
|
end
|
||||||
|
|
||||||
to_walk_to_plant = function(self, path, destination)
|
to_walk_to_plant = function(self, path, destination)
|
||||||
print("to walk to plant")
|
|
||||||
self.state = state.WALK_TO_PLANT
|
self.state = state.WALK_TO_PLANT
|
||||||
self.path = path
|
self.path = path
|
||||||
self.destination = destination
|
self.destination = destination
|
||||||
|
@ -136,7 +138,6 @@ do -- register farming core
|
||||||
end
|
end
|
||||||
|
|
||||||
to_walk_to_mow = function(self, path, destination)
|
to_walk_to_mow = function(self, path, destination)
|
||||||
print("to walk to mow")
|
|
||||||
self.state = state.WALK_TO_MOW
|
self.state = state.WALK_TO_MOW
|
||||||
self.path = path
|
self.path = path
|
||||||
self.destination = destination
|
self.destination = destination
|
||||||
|
@ -147,7 +148,6 @@ do -- register farming core
|
||||||
end
|
end
|
||||||
|
|
||||||
to_plant = function(self)
|
to_plant = function(self)
|
||||||
print("to plant")
|
|
||||||
if self:move_main_to_wield(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
|
if self:move_main_to_wield(function(itemname) return (minetest.get_item_group(itemname, "seed") > 0) end) then
|
||||||
self.state = state.PLANT
|
self.state = state.PLANT
|
||||||
self.time_counters[1] = 0
|
self.time_counters[1] = 0
|
||||||
|
@ -161,7 +161,6 @@ do -- register farming core
|
||||||
end
|
end
|
||||||
|
|
||||||
to_mow = function(self)
|
to_mow = function(self)
|
||||||
print("to mow")
|
|
||||||
self.state = state.MOW
|
self.state = state.MOW
|
||||||
self.time_counters[1] = 0
|
self.time_counters[1] = 0
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
|
@ -169,7 +168,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 is_near(self, self.destination, 1.0) then
|
if is_near(self, self.destination, 1.5) 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
|
||||||
|
@ -188,9 +187,7 @@ do -- register farming core
|
||||||
self.time_counters[2] = self.time_counters[2] + 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
|
|
||||||
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*")
|
||||||
if path == nil then
|
if path == nil then
|
||||||
to_walk_randomly(self)
|
to_walk_randomly(self)
|
||||||
|
@ -200,8 +197,7 @@ do -- register farming core
|
||||||
end
|
end
|
||||||
|
|
||||||
-- follow path
|
-- follow path
|
||||||
if is_near(self, self.path[1], 0.01) then
|
if is_near(self, self.path[1], 0.5) 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
|
||||||
|
@ -223,8 +219,8 @@ do -- register farming core
|
||||||
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()
|
||||||
if front_node.name ~= "air" then
|
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name].walkable then
|
||||||
self.object:setvelocity{x = velocity.x, y = 3, z = velocity.z}
|
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -267,16 +263,12 @@ do -- register farming core
|
||||||
|
|
||||||
local function on_step(self, dtime)
|
local function on_step(self, dtime)
|
||||||
if self.state == state.WALK_RANDOMLY then
|
if self.state == state.WALK_RANDOMLY then
|
||||||
-- print("== now walk randomly")
|
|
||||||
walk_randomly(self, dtime)
|
walk_randomly(self, dtime)
|
||||||
elseif self.state == state.WALK_TO_PLANT or self.state == state.WALK_TO_MOW then
|
elseif self.state == state.WALK_TO_PLANT or self.state == state.WALK_TO_MOW then
|
||||||
-- print("== now walk to *")
|
|
||||||
walk_to_plant_and_mow_common(self, dtime)
|
walk_to_plant_and_mow_common(self, dtime)
|
||||||
elseif self.state == state.PLANT then
|
elseif self.state == state.PLANT then
|
||||||
-- print("== now plant")
|
|
||||||
plant(self, dtime)
|
plant(self, dtime)
|
||||||
elseif self.state == state.MOW then
|
elseif self.state == state.MOW then
|
||||||
-- print("== now mow")
|
|
||||||
mow(self, dtime)
|
mow(self, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user