set infotext for beds and workspaces
This commit is contained in:
parent
38befc5463
commit
d2d6ede246
@ -402,7 +402,7 @@ mg_villages.add_building = function( building_data )
|
||||
local paths = mg_villages.path_info[ building_data.short_file_name.."|WORKPLACE"];
|
||||
if( paths and paths[1] ) then
|
||||
for i,p in ipairs( paths[1] ) do
|
||||
if( p and p[1]) then
|
||||
if( p and p[1] and i<#paths[1]) then
|
||||
building_data.workplace_list[i] = p[1];
|
||||
end
|
||||
end
|
||||
|
@ -267,6 +267,9 @@ minetest.register_chatcommand( 'village_mob_repopulate', {
|
||||
mg_villages.inhabitants.assign_mobs( v, village_id, true);
|
||||
-- save the modified data
|
||||
save_restore.save_data( 'mg_all_villages.data', mg_villages.all_villages );
|
||||
|
||||
-- adjust beds and workplaces
|
||||
mg_villages.inhabitants.prepare_metadata( v, village_id, nil, nil );
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
@ -1250,6 +1250,59 @@ mg_villages.inhabitants.assign_mobs = function( village, village_id, force_repop
|
||||
end
|
||||
|
||||
|
||||
-- set metadata and/or infotexts for beds and workplace markers
|
||||
mg_villages.inhabitants.prepare_metadata = function( village, village_id, minp, maxp )
|
||||
local bpos_list = village.to_add_data.bpos;
|
||||
for plot_nr,bpos in ipairs(bpos_list) do
|
||||
-- put labels on beds
|
||||
if( bpos.beds ) then
|
||||
for bed_nr, bed in ipairs( bpos.beds ) do
|
||||
-- if the bed is located withhin the given area OR no area is given
|
||||
-- (for manual calls later on, outside of mapgen)
|
||||
if( not( minp ) or not( maxp )
|
||||
or ( minp.x <= bed.x and maxp.x >= bed.x
|
||||
and minp.y <= bed.y and maxp.y >= bed.y
|
||||
and minp.z <= bed.z and maxp.z >= bed.z)) then
|
||||
local meta = minetest.get_meta( bed );
|
||||
meta:set_string('infotext', 'Bed of '..
|
||||
mg_villages.inhabitants.mob_get_full_name( bed, bpos.beds[1] ));
|
||||
meta:set_string('village_id', village_id );
|
||||
meta:set_int( 'plot_nr', plot_nr);
|
||||
meta:set_int( 'bed_nr', bed_nr);
|
||||
end
|
||||
-- there might be a workplace belonging to the bed/mob
|
||||
if( bed.works_at and bed.workplace
|
||||
and bed.workplace>0
|
||||
and bpos_list[ bed.works_at ]
|
||||
and bpos_list[ bed.works_at ].btype
|
||||
and mg_villages.BUILDINGS[ bpos_list[ bed.works_at ].btype ]
|
||||
and mg_villages.BUILDINGS[ bpos_list[ bed.works_at ].btype ].workplace_list
|
||||
and #mg_villages.BUILDINGS[ bpos_list[ bed.works_at ].btype ].workplace_list >= bed.workplace ) then
|
||||
local p = mg_villages.BUILDINGS[ bpos_list[ bed.works_at ].btype ].workplace_list[ bed.workplace ];
|
||||
local bpos_work = bpos_list[ bed.works_at ];
|
||||
local p_akt = mg_villages.transform_coordinates( {p[1],p[2],p[3]}, bpos_work);
|
||||
if( not( minp ) or not( maxp )
|
||||
or ( minp.x <= p_akt.x and maxp.x >= bed.x
|
||||
and minp.y <= p_akt.y and maxp.y >= p_akt.y
|
||||
and minp.z <= p_akt.z and maxp.z >= p_akt.z)) then
|
||||
local meta = minetest.get_meta( p_akt );
|
||||
meta:set_string('infotext', 'Workplace of '..
|
||||
mg_villages.inhabitants.mob_get_full_name( bed, bed ));
|
||||
meta:set_string('village_id', village_id );
|
||||
-- data about the workplace itshelf
|
||||
meta:set_int( 'plot_nr', bed.works_at );
|
||||
meta:set_int( 'workplace_nr', bed.workplace );
|
||||
-- the data of the *mob* might be more relevant for spawning
|
||||
meta:set_int( 'lives_at', plot_nr );
|
||||
meta:set_int( 'bed_nr', bed_nr );
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- spawn mobs in villages
|
||||
mg_villages.inhabitants.part_of_village_spawned = function( village, minp, maxp, data, param2_data, a, cid )
|
||||
-- for each building in the village
|
||||
|
19
mapgen.lua
19
mapgen.lua
@ -1240,23 +1240,8 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
|
||||
local village_id = tostring( village.vx )..':'..tostring( village.vz );
|
||||
-- analyze road network, assign workers to buildings, assign mobs to beds
|
||||
mg_villages.inhabitants.assign_mobs( village, village_id, false );
|
||||
-- TODO: set up workplace markers based on what was assigned in the function above
|
||||
-- TODO: also label beds?
|
||||
-- set up the workplace markers
|
||||
for building_nr_in_bpos,pos in ipairs( village.to_add_data.bpos ) do
|
||||
if( pos.workplaces and #pos.workplaces>0) then
|
||||
for workplace_nr, wp in ipairs( pos.workplaces ) do
|
||||
-- store where to find information about the mob this workplace is responsible for
|
||||
local meta = minetest.get_meta( wp );
|
||||
meta:set_string('village_id', village_id );
|
||||
meta:set_int( 'plot_nr', building_nr_in_bpos);
|
||||
meta:set_int( 'workplace_nr', workplace_nr );
|
||||
-- TODO: that infotext might be irritating for players; it is mostly useful just for debugging
|
||||
meta:set_string('infotext', 'WORKPLACE nr '..tostring(workplace_nr)..' on plot nr '..tostring( building_nr_in_bpos )..' in village '..tostring( village_id ));
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
-- set infotexts for beds and workplace markers
|
||||
mg_villages.inhabitants.prepare_metadata( village, village_id, minp, maxp);
|
||||
end
|
||||
|
||||
-- useful for spawning mobs etc.
|
||||
|
Loading…
Reference in New Issue
Block a user