added function analyze_building_for_mobs_search_nodes

This commit is contained in:
Sokomine 2018-07-29 22:11:05 +02:00
parent 19aebfcfbb
commit a122017bf0

View File

@ -1,3 +1,45 @@
-- helper function for mg_villages.analyze_building_for_mobs
-- "res" is the raw data as provided by analyze_file
-- "node_name" is the name of the node we are looking for
mg_villages.analyze_building_for_mobs_search_nodes = function( res, node_name, check_place_for_standing )
local node_positions = {};
-- find out if the building contains any of the nodes we are looking for
local found = -1;
for i,n in ipairs( res.nodenames ) do
if( n == node_name ) then
found = i;
end
end
-- that node does not exist in the building
if( found == -1 ) then
return {};
end
for z = 1, res.size.z do
for y = 1, res.size.y do
for x = 1, res.size.x do
if( res.scm_data_cache[y]
and res.scm_data_cache[y][x]
and res.scm_data_cache[y][x][z]
and res.scm_data_cache[y][x][z][1] == found ) then
if( (check_place_for_standing==false)
) then
-- or ( mob_world_interaction.can_stand_in_node_type( TODO )
-- and mob_world_interaction.can_stand_in_node_type( TODO ))) then
table.insert( node_positions, {x=x, y=y, z=z, p2=res.scm_data_cache[y][x][z][2]});
end
end
end
end
end
return node_positions;
end
-- changes mg_villages.path_info and adds paths from beds and workplaces to front of building
-- mg_villages.path_info[ short_file_name ] contains the paths from the beds
-- mg_villages.path_info[ short_file_name.."|WORKPLACE" ] contains the paths from the workplaces
@ -35,30 +77,13 @@ mg_villages.analyze_building_for_mobs = function( file_name, building_data, res
-- some buildings (i.e. a tavern, school, shop, church, ...) contain places where a mob working
-- there will most likely be standing, awaiting his guests/doing his job. Such places can be
-- manually marked by placing mg_villages:mob_workplace_marker
local workplace_list = {};
-- find out if the building contains any workplace markers at all
local found = -1;
for i,n in ipairs( res.nodenames ) do
if( n == "mg_villages:mob_workplace_marker" ) then
found = i;
end
end
-- this is diffrent information from the normal bed list
local store_as = short_file_name.."|WORKPLACE";
if( found>0
and not( mg_villages.path_info[ store_as ] )) then
for z = 1, res.size.z do
for y = 1, res.size.y do
for x = 1, res.size.x do
if( res.scm_data_cache[y]
and res.scm_data_cache[y][x]
and res.scm_data_cache[y][x][z]
and res.scm_data_cache[y][x][z][1] == found ) then
table.insert( workplace_list, {x=x, y=y, z=z, p2=res.scm_data_cache[y][x][z][2]});
end
end
end
end
if(not( mg_villages.path_info[ store_as ] )) then
local workplace_list = mg_villages.analyze_building_for_mobs_search_nodes( res, "mg_villages:mob_workplace_marker", false );
if( workplace_list and #workplace_list>0) then
-- store it for later use
building_data.workplace_list = workplace_list;
@ -81,6 +106,27 @@ mg_villages.analyze_building_for_mobs = function( file_name, building_data, res
-- else
-- print("NO workplace found in "..tostring(building_data.short_file_name ));
end
end
--[[
TODO: check if 2 nodes above the target node are air or walkable;
TODO: exceptions to that: bench (only 1 above needs to be walkable)
TODO: other exceptions: furnace, chests, washing place: place in front is wanted - not on top
TODO: search for:
local pos_list = mg_villages.analyze_building_for_mobs_search_nodes( res, "farming:soil_wet", true );
farming:soil farming:soil_wet
cottages:straw_ground
default:chest cottages:shelf cottages:chest_storage cottages:chest_private cottages:chest_work
cottages:bench (cottages:table?)
cottages:washing
default:furnace
cottages:barrel (and variants); cottages:tub
default:ladder
default:fence_wood cottages:gate_closed cottages:gate_open
any door...
any hatch...
--]]
-- some debug information
if( mg_villages.DEBUG_LEVEL and mg_villages.DEBUG_LEVEL == mg_villages.DEBUG_LEVEL_TIMING ) then