1
0
mirror of https://github.com/tacigar/maidroid.git synced 2025-07-15 05:40:22 +02:00

Fix indent

This commit is contained in:
tacigar
2016-06-08 14:48:06 +09:00
parent d1db40559b
commit 605612a2b3
5 changed files with 209 additions and 209 deletions

View File

@ -50,14 +50,14 @@ function maidroid.modules._aux.pickup_item(self, radius, target_pred)
if not obj:is_player() and obj:get_luaentity() then
local itemstring = obj:get_luaentity().itemstring
if itemstring then
if pred(itemstring) then
local inv = maidroid._aux.get_maidroid_inventory(self)
local stack = ItemStack(itemstring)
local leftover = inv:add_item("main", stack)
minetest.add_item(obj:getpos(), leftover)
obj:get_luaentity().itemstring = ""
obj:remove()
end
if pred(itemstring) then
local inv = maidroid._aux.get_maidroid_inventory(self)
local stack = ItemStack(itemstring)
local leftover = inv:add_item("main", stack)
minetest.add_item(obj:getpos(), leftover)
obj:get_luaentity().itemstring = ""
obj:remove()
end
end
end
end

View File

@ -7,24 +7,24 @@ local util = maidroid.util
local _aux = maidroid.modules._aux
local state = { idle = 0, chase = 1}
local view_of_range = 7
local stop_of_range = 2
local view_of_range = 7
local stop_of_range = 2
maidroid.register_module("maidroid:chasing_player_module", {
description = "Maidroid Module : Chasing Player",
inventory_image = "maidroid_chasing_player_module.png",
initialize = function(self)
self.state = state.idle
self.object:setacceleration{x = 0, y = -10, z = 0}
self.object:setvelocity{x = 0, y = 0, z = 0}
end,
finalize = function(self)
self.state = nil
self.object:setvelocity{x = 0, y = 0, z = 0}
end,
on_step = function(self, dtime)
local pos = self.object:getpos()
local all_objects = minetest.get_objects_inside_radius(pos, view_of_range)
@ -42,33 +42,33 @@ maidroid.register_module("maidroid:chasing_player_module", {
local vel = self.object:getvelocity()
if (vector.length(dir) < stop_of_range) then
if self.state == state.chase then
self.object:set_animation(maidroid.animations.stand, 15, 0)
self.state = state.idle
self.object:setvelocity({x = 0, y = vel.y, z = 0})
self.object:set_animation(maidroid.animations.stand, 15, 0)
self.state = state.idle
self.object:setvelocity({x = 0, y = vel.y, z = 0})
end
else
if self.state == state.idle then
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.state = state.chase
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.state = state.chase
end
self.object:setvelocity({x = dir.x, y = vel.y, z = dir.z})
end
local yaw = math.atan2(dir.z, dir.x) + math.pi/2
self.object:setyaw(yaw)
-- jump process
if vel.y == 0 and self.state == state.chase then
local rdir = vector.round(dir)
local front_vec = { x = 0, y = 0, z = 0 }
if math.abs((rdir.x / (math.abs(rdir.x) + math.abs(rdir.z)))) > 0.5 then
if rdir.x > 0 then front_vec.x = 1 else front_vec.x = -1 end
if rdir.x > 0 then front_vec.x = 1 else front_vec.x = -1 end
end
if math.abs((rdir.z / (math.abs(rdir.x) + math.abs(rdir.z)))) > 0.5 then
if rdir.z > 0 then front_vec.z = 1 else front_vec.z = -1 end
if rdir.z > 0 then front_vec.z = 1 else front_vec.z = -1 end
end
local front_pos = vector.add(vector.round(pos), front_vec)
if minetest.get_node(front_pos).name ~= "air" then
self.object:setvelocity({x = dir.x, y = 5, z = dir.z})
self.object:setvelocity({x = dir.x, y = 5, z = dir.z})
end
end
end,

View File

@ -40,7 +40,7 @@ end
maidroid.register_module("maidroid:farming_module", {
description = "Maidroid Module : Farming",
inventory_image = "maidroid_farming_module.png",
initialize = function(self)
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.object:setacceleration{x = 0, y = -10, z = 0}
@ -49,14 +49,14 @@ maidroid.register_module("maidroid:farming_module", {
self.time_count = 0
_aux.change_dir(self)
end,
finalize = function(self)
self.state = nil
self.preposition = nil
self.time_count = nil
self.object:setvelocity{x = 0, y = 0, z = 0}
end,
on_step = function(self, dtime)
local pos = self.object:getpos()
local rpos = vector.round(pos)
@ -66,70 +66,70 @@ maidroid.register_module("maidroid:farming_module", {
local forward_pos = vector.add(rpos, forward_vec2)
local forward_node = minetest.get_node(forward_pos)
local forward_under_pos = vector.subtract(forward_pos, {x = 0, y = 1, z = 0})
if self.state == state.walk then -- searching plants or spaces
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
self.state = state.punch
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
self.state = state.punch
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
elseif pos.x == self.preposition.x or pos.z == self.preposition.z then
_aux.change_dir(self)
_aux.change_dir(self)
elseif forward_node.name == "air"
and minetest.get_item_group(minetest.get_node(forward_under_pos).name, "wet") > 0
and has_seed_item(self) then
self.state = state.plant
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
end
-- pickup droped seed items
_aux.pickup_item(self, 1.5, function(itemstring)
return minetest.get_item_group(itemstring, "seed") > 0
end)
elseif self.state == state.punch then
if self.time_count >= max_punch_time then
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
minetest.remove_node(forward_pos)
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = minetest.get_node_drops(forward_node.name)
for _, stack in ipairs(stacks) do
local leftover = inv:add_item("main", stack)
minetest.add_item(forward_pos, leftover)
end
end
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.time_count = 0
_aux.change_dir(self)
else
self.time_count = self.time_count + 1
end
elseif self.state == state.plant then
if self.time_count >= max_plant_time then
if forward_node.name == "air" and minetest.get_item_group(
and minetest.get_item_group(minetest.get_node(forward_under_pos).name, "wet") > 0
and has_seed_item(self) then
self.state = state.plant
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
end
-- pickup droped seed items
_aux.pickup_item(self, 1.5, function(itemstring)
return minetest.get_item_group(itemstring, "seed") > 0
end)
elseif self.state == state.punch then
if self.time_count >= max_punch_time then
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
minetest.remove_node(forward_pos)
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = minetest.get_node_drops(forward_node.name)
for _, stack in ipairs(stacks) do
local leftover = inv:add_item("main", stack)
minetest.add_item(forward_pos, leftover)
end
end
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.time_count = 0
_aux.change_dir(self)
else
self.time_count = self.time_count + 1
end
elseif self.state == state.plant then
if self.time_count >= max_plant_time then
if forward_node.name == "air" and minetest.get_item_group(
minetest.get_node(forward_under_pos).name, "soil") > 0 then
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = inv:get_list("main")
for idx, stack in ipairs(stacks) do
local item_name = stack:get_name()
if minetest.get_item_group(item_name, "seed") > 0 then
minetest.add_node(forward_pos, {name = item_name, param2 = 1})
stack:take_item(1)
inv:set_stack("main", idx, stack)
break
end
end
end
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.time_count = 0
_aux.change_dir(self)
else
self.time_count = self.time_count + 1
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = inv:get_list("main")
for idx, stack in ipairs(stacks) do
local item_name = stack:get_name()
if minetest.get_item_group(item_name, "seed") > 0 then
minetest.add_node(forward_pos, {name = item_name, param2 = 1})
stack:take_item(1)
inv:set_stack("main", idx, stack)
break
end
end
end
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.time_count = 0
_aux.change_dir(self)
else
self.time_count = self.time_count + 1
end
end
self.preposition = pos
return
end
self.preposition = pos
return
end
})
})

View File

@ -41,7 +41,7 @@ end
maidroid.register_module("maidroid:lumberjack_module", {
description = "Maidroid Module : Lumberjack",
inventory_image = "maidroid_lumberjack_module.png",
initialize = function(self)
self.state = state.walk
self.time_count = 0
@ -50,14 +50,14 @@ maidroid.register_module("maidroid:lumberjack_module", {
self.preposition = self.object:getpos()
_aux.change_dir(self)
end,
finalize = function(self)
self.state = nil
self.time_count = nil
self.preposition = nil
self.object:setvelocity{x = 0, y = 0, z = 0}
end,
on_step = function(self, dtime)
local pos = self.object:getpos()
local rpos = vector.round(pos)
@ -68,74 +68,74 @@ maidroid.register_module("maidroid:lumberjack_module", {
local forward_node = minetest.get_node(forward_pos)
local forward_under_pos = _aux.get_under_pos(forward_pos)
local forward_under_node = minetest.get_node(forward_under_pos)
if self.state == state.walk then
if check_punch_flag(forward_pos) then -- punch tree node
self.state = state.punch
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
self.state = state.punch
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
elseif pos.x == self.preposition.x or pos.z == self.preposition.z then
_aux.change_dir(self)
_aux.change_dir(self)
elseif forward_node.name == "air"
and minetest.get_item_group(forward_under_node.name, "soil") > 0
and has_sapling_item(self) then
self.state = state.plant
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
end
-- pickup sapling items
_aux.pickup_item(self, 1.5, function(itemstring)
return util.table_find_value(target_sapling_list, itemstring)
end)
elseif self.state == state.punch then
if self.time_count >= max_punch_time then
local punch_flag, forward_upper_pos, forward_upper_node
= check_punch_flag(forward_pos)
if punch_flag then
minetest.remove_node(forward_upper_pos)
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = minetest.get_node_drops(forward_upper_node.name)
for _, stack in ipairs(stacks) do
local leftover = inv:add_item("main", stack)
minetest.add_item(forward_pos, leftover)
end
end
if (not forward_upper_pos) or (forward_upper_pos and
not check_punch_flag(_aux.get_upper_pos(forward_upper_pos))) then
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
_aux.change_dir(self)
end
self.time_count = 0
else
self.time_count = self.time_count + 1
end
elseif self.state == state.plant then
if self.time_count > max_plant_time then
if forward_node.name == "air"
and minetest.get_item_group(forward_under_node.name, "soil") > 0 then
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = inv:get_list("main")
for i, stack in ipairs(stacks) do
local itemname = stack:get_name()
if util.table_find_value(target_sapling_list, itemname) then
minetest.add_node(forward_pos, {name = itemname, param2 = 1})
stack:take_item(1)
inv:set_stack("main", i, stack)
break
end
end
end
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.time_count = 0
_aux.change_dir(self)
else
self.time_count = self.time_count + 1
and minetest.get_item_group(forward_under_node.name, "soil") > 0
and has_sapling_item(self) then
self.state = state.plant
self.object:set_animation(maidroid.animations.mine, 15, 0)
self.object:setvelocity{x = 0, y = 0, z = 0}
end
-- pickup sapling items
_aux.pickup_item(self, 1.5, function(itemstring)
return util.table_find_value(target_sapling_list, itemstring)
end)
elseif self.state == state.punch then
if self.time_count >= max_punch_time then
local punch_flag, forward_upper_pos, forward_upper_node
= check_punch_flag(forward_pos)
if punch_flag then
minetest.remove_node(forward_upper_pos)
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = minetest.get_node_drops(forward_upper_node.name)
for _, stack in ipairs(stacks) do
local leftover = inv:add_item("main", stack)
minetest.add_item(forward_pos, leftover)
end
end
if (not forward_upper_pos) or (forward_upper_pos and
not check_punch_flag(_aux.get_upper_pos(forward_upper_pos))) then
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
_aux.change_dir(self)
end
self.time_count = 0
else
self.time_count = self.time_count + 1
end
elseif self.state == state.plant then
if self.time_count > max_plant_time then
if forward_node.name == "air"
and minetest.get_item_group(forward_under_node.name, "soil") > 0 then
local inv = minetest.get_inventory{type = "detached", name = self.invname}
local stacks = inv:get_list("main")
for i, stack in ipairs(stacks) do
local itemname = stack:get_name()
if util.table_find_value(target_sapling_list, itemname) then
minetest.add_node(forward_pos, {name = itemname, param2 = 1})
stack:take_item(1)
inv:set_stack("main", i, stack)
break
end
end
end
self.state = state.walk
self.object:set_animation(maidroid.animations.walk, 15, 0)
self.time_count = 0
_aux.change_dir(self)
else
self.time_count = self.time_count + 1
end
end
self.preposition = pos
end
self.preposition = pos
end
})
})