npc: respect wallmounted nodes should be placed before the attached node
less-prefer liquids
This commit is contained in:
parent
edcb6a38d9
commit
a7da7142ee
@ -81,10 +81,12 @@ License: LGPLv2
|
||||
- content_id, node_def - game references, VoxelMap ID and registered_nodes definition
|
||||
- final_node_name - if set, the node is not deleted from plan by place(). Contains the node name to be placed at the end. used for replacing by air before build the node
|
||||
- world_node_name - contains the node name currently placed to the world
|
||||
- param2_plan_rotation - param2 value before rotation
|
||||
- node_obj:place() - place node to world using "add_node" and remove them from plan
|
||||
- node_obj:remove_from_plan() - remove this node from plan
|
||||
- node_obj:get_under() - returns the node under this one if exists in plan
|
||||
- node_obj:get_above() - returns the node above this one if exists in plan
|
||||
- node_obj:get_attached_to() - returns the position the node is attached to
|
||||
- node_obj:rotate_facedir(facedir) - rotate the node - is internally used for plan rotation in get_mapped() - supported 0-3 (x+ axis) only
|
||||
|
||||
### object-attributes
|
||||
|
31
node.lua
31
node.lua
@ -49,6 +49,7 @@ end
|
||||
function node_class:rotate_facedir(facedir)
|
||||
-- rotate wallmounted
|
||||
local mapped = self.mapped
|
||||
mapped.param2_plan_rotation = mapped.param2
|
||||
if mapped.node_def.paramtype2 == "wallmounted" then
|
||||
local param2_dir = mapped.param2 % 8
|
||||
local param2_color = mapped.param2 - param2_dir
|
||||
@ -121,6 +122,27 @@ function node_class:get_under()
|
||||
return self.plan:get_node({x=self._plan_pos.x, y=self._plan_pos.y-1, z=self._plan_pos.z})
|
||||
end
|
||||
|
||||
--------------------------------------
|
||||
-- get plan_pos of attached node, or nil if not attached
|
||||
--------------------------------------
|
||||
function node_class:get_attached_to()
|
||||
local mapped = self:get_mapped()
|
||||
local attached_wallmounted
|
||||
if mapped.name == "doors:hidden" then
|
||||
attached_wallmounted = 1 --bellow
|
||||
elseif mapped.node_def.groups.attached_node then
|
||||
if mapped.node_def.paramtype2 == "wallmounted" then
|
||||
attached_wallmounted = mapped.param2_plan_rotation
|
||||
else
|
||||
attached_wallmounted = 1 --bellow
|
||||
end
|
||||
end
|
||||
if attached_wallmounted then
|
||||
local dir = node.wallmounted_to_dir[attached_wallmounted]
|
||||
return vector.add(self._plan_pos, dir)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------
|
||||
-- get node above this one if exists
|
||||
--------------------------------------
|
||||
@ -173,6 +195,15 @@ node.rotation_facedir_map = {
|
||||
}
|
||||
node.rotation_facedir_mirrored_map = {3, 2, 1, 4, 7, 6, 5, 8, 11,10,9,16,19,18,17,12,15,14,13,20,23,22,21,[0] = 0}
|
||||
|
||||
|
||||
node.wallmounted_to_dir = {
|
||||
[0] = {x=0,y=1,z=0},
|
||||
[1] = {x=0,y=-1,z=0},
|
||||
[2] = {x=1,y=0,z=0},
|
||||
[3] = {x=-1,y=0,z=0},
|
||||
[4] = {x=0,y=0,z=1},
|
||||
[5] = {x=0,y=0,z=-1},
|
||||
}
|
||||
--[[
|
||||
--- Temporary code to calculate the wallmounted map
|
||||
node.rotation_wallmounted_map = {}
|
||||
|
15
npc_ai.lua
15
npc_ai.lua
@ -53,8 +53,14 @@ function npc_ai_class:get_if_buildable(node)
|
||||
end
|
||||
node_index = self.plan.vm_area:indexp(world_pos)
|
||||
world_content_id = self.plan.vm_data[node_index]
|
||||
|
||||
node.world_node_name = minetest.get_name_from_content_id(world_content_id)
|
||||
|
||||
-- place attached nodes after the node under
|
||||
local attached_pos = node:get_attached_to()
|
||||
if attached_pos and self.plan:get_node(attached_pos) then
|
||||
return -- attaching not possible
|
||||
end
|
||||
|
||||
if world_content_id == mapped.content_id then
|
||||
-- right node is at the place. there are no costs to touch them. Check if a touch needed
|
||||
if mapped.node_def.paramtype2 and (mapped.param2 ~= self.plan.vm_param2_data[node_index]) then
|
||||
@ -93,6 +99,11 @@ function npc_ai_class:get_node_rating(node, npcpos)
|
||||
local distance_pos = table.copy(world_pos)
|
||||
local prefer = 0
|
||||
|
||||
-- build water at the later time
|
||||
if mapped.node_def.groups.liquid then
|
||||
prefer = prefer - self.build_distance
|
||||
end
|
||||
|
||||
--prefer same items in building order
|
||||
if self.lasttarget_name then
|
||||
if self.lasttarget_name == mapped.name then
|
||||
@ -111,7 +122,7 @@ function npc_ai_class:get_node_rating(node, npcpos)
|
||||
prefer = prefer + self.build_distance + 1
|
||||
else
|
||||
if node:get_under() then
|
||||
prefer = prefer - (2 * self.build_distance)
|
||||
prefer = prefer - 2
|
||||
end
|
||||
distance_pos.y = distance_pos.y + self.build_distance
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user