turned who-lives-here into formspec

This commit is contained in:
Sokomine 2017-07-23 23:35:31 +02:00
parent 20995e4be1
commit b18a828683
2 changed files with 49 additions and 22 deletions

View File

@ -102,11 +102,11 @@ mg_villages.inhabitants.mob_get_full_name = function( data, worker_data )
return; return;
end end
local str = data.first_name; local str = data.first_name;
if( data.mob_id ) then -- if( data.mob_id ) then
str = "["..data.mob_id.."] "..minetest.pos_to_string( data ).." "..data.first_name; -- str = "["..data.mob_id.."] "..minetest.pos_to_string( data ).." "..data.first_name;
else -- else
str = " -no mob assigned - "..minetest.pos_to_string( data ).." "..data.first_name; -- str = " -no mob assigned - "..minetest.pos_to_string( data ).." "..data.first_name;
end -- end
if( data.middle_name ) then if( data.middle_name ) then
str = str.." "..data.middle_name.."."; str = str.." "..data.middle_name..".";
@ -419,31 +419,43 @@ mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, h
building_data = { typ = bpos.btype }; building_data = { typ = bpos.btype };
end end
local str = "Plot Nr. "..tostring( house_nr ).." ["..tostring( building_data.typ or "-?-").."] "; local str = "Plot Nr. "..tostring( house_nr ).." ["..tostring( building_data.typ or "-?-").."] ";
local people_str = "";
local add_str = "";
if( bpos.btype == "road" ) then if( bpos.btype == "road" ) then
str = str.."is a road.\n"; str = str.."is a road.";
-- wagon, shed, field and pasture -- wagon, shed, field and pasture
elseif( bpos.belongs_to and village_to_add_data_bpos[ bpos.belongs_to ].beds) then elseif( bpos.belongs_to and village_to_add_data_bpos[ bpos.belongs_to ].beds) then
local owner = village_to_add_data_bpos[ bpos.belongs_to ].beds[1]; local owner = village_to_add_data_bpos[ bpos.belongs_to ].beds[1];
if( not( owner ) or not( owner.first_name )) then if( not( owner ) or not( owner.first_name )) then
str = str.."WARNING: NO ONE owns this plot.\n"; str = str.."WARNING: NO ONE owns this plot.";
else else
str = str.."belongs to: "..mg_villages.inhabitants.mob_get_full_name( owner, owner ).."\n"; str = str.."belongs to:";
people_str = minetest.formspec_escape( mg_villages.inhabitants.mob_get_full_name( owner, owner ).." owns this plot");
end end
elseif( not( bpos.beds ) or #bpos.beds<1 and bpos.worker and bpos.worker.title) then elseif( not( bpos.beds ) or #bpos.beds<1 and bpos.worker and bpos.worker.title) then
if( not( bpos.worker.lives_at)) then if( not( bpos.worker.lives_at)) then
str = str.."WARNING: NO WORKER assigned to this plot.\n"; str = str.."WARNING: NO WORKER assigned to this plot.";
else else
local worker = village_to_add_data_bpos[ bpos.worker.lives_at ].beds[1]; local worker = village_to_add_data_bpos[ bpos.worker.lives_at ].beds[1];
str = str..mg_villages.inhabitants.mob_get_full_name( worker, worker ).." works here.\n"; str = str.."provides work:";
local btype2 = mg_villages.BUILDINGS[ village_to_add_data_bpos[ bpos.worker.lives_at ].btype];
people_str = minetest.formspec_escape( mg_villages.inhabitants.mob_get_full_name( worker, worker ).." who lives at the "..tostring( btype2.typ ).." on plot "..tostring( bpos.worker.lives_at )..", works here");
end end
elseif( not( bpos.beds ) or not( bpos.beds[1])) then elseif( not( bpos.beds ) or not( bpos.beds[1])) then
str = str.."provides neither work nor housing.\n"; str = str.."provides neither work nor housing.";
else else
str = str.."is inhabitated by:\n"; str = str.."is inhabitated by ";
if( #bpos.beds == 1 ) then
str = str.."only one person:";
elseif( #bpos.beds > 1 ) then
str = str..tostring( #bpos.beds ).." people:";
else
str = str.."nobody:";
end
-- make sure all mobs living here are spawned -- make sure all mobs living here are spawned
mg_villages.inhabitants.spawn_mobs_for_one_house( bpos, nil, nil, village_id, house_nr ); mg_villages.inhabitants.spawn_mobs_for_one_house( bpos, nil, nil, village_id, house_nr );
for i,v in ipairs( bpos.beds ) do for i,v in ipairs( bpos.beds ) do
@ -452,32 +464,43 @@ mg_villages.inhabitants.print_house_info = function( village_to_add_data_bpos, h
if( v and v.works_at ) then if( v and v.works_at ) then
worker_data = v; worker_data = v;
end end
str = str.." "..mg_villages.inhabitants.mob_get_full_name( v, worker_data ); people_str = people_str..
tostring( i )..". "..
minetest.formspec_escape( mg_villages.inhabitants.mob_get_full_name( v, worker_data ));
if(v and v.works_at and v.works_at==house_nr ) then if(v and v.works_at and v.works_at==house_nr ) then
str = str.." who lives and works here\n"; people_str = people_str.." who lives and works here,";
elseif( v and v.works_at ) then elseif( v and v.works_at ) then
local works_at = bpos.beds[1].works_at; local works_at = bpos.beds[1].works_at;
local btype2 = mg_villages.BUILDINGS[ village_to_add_data_bpos[ works_at ].btype]; local btype2 = mg_villages.BUILDINGS[ village_to_add_data_bpos[ works_at ].btype];
str = str.." who works at the "..tostring( btype2.typ ).." on plot "..tostring(works_at).."\n"; people_str = people_str.." who works at the "..tostring( btype2.typ ).." on plot "..tostring(works_at)..",";
else elseif( i ~= #bpos.beds ) then
str = str.."\n"; people_str = people_str..",";
end end
end end
end end
-- other plots owned -- other plots owned
if( bpos.beds and bpos.beds[1] and bpos.beds[1].owns ) then if( bpos.beds and bpos.beds[1] and bpos.beds[1].owns ) then
str = str.."The family also owns the plot(s) "; add_str = "The family also owns the plot(s) ";
for i,v in ipairs( bpos.beds[1].owns ) do for i,v in ipairs( bpos.beds[1].owns ) do
if( i>1 ) then if( i>1 ) then
str = str..", "; add_str = add_str..", ";
end end
local building_data = mg_villages.BUILDINGS[ village_to_add_data_bpos[v].btype ]; local building_data = mg_villages.BUILDINGS[ village_to_add_data_bpos[v].btype ];
str = str.."Nr. "..tostring( v ).." ("..building_data.typ..")"; add_str = add_str.."Nr. "..tostring( v ).." ("..building_data.typ..")";
end end
str = str.."\n"; add_str = add_str..".";
end end
end end
return str; if( people_str == "" ) then
people_str = "- nobody lives or works here permanently -";
end
return 'size[12,4.5]'..
'button_exit[9.5,0;2,0.5;back;Back]'..
'label[0.5,0.5;'..minetest.formspec_escape(str)..']'..
'label[0.5,4.1;'..minetest.formspec_escape(add_str)..']'..
'tablecolumns[' ..
'text,align=left]'.. -- name and description of inhabitant
'table[0.1,1.0;11.4,3.0;mg:plot_mob_list;'..people_str..']';
end end

View File

@ -49,6 +49,10 @@ mg_villages.plotmarker_formspec = function( pos, formname, fields, player )
+ (village.vz - pos.z ) * (village.vz - pos.z ) )); + (village.vz - pos.z ) * (village.vz - pos.z ) ));
if( fields and fields.inhabitants ) then if( fields and fields.inhabitants ) then
minetest.show_formspec( pname, "mg_villages:plot_mob_list",
mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr ));
if( true ) then return; end
minetest.chat_send_player( player:get_player_name(), mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr )); minetest.chat_send_player( player:get_player_name(), mg_villages.inhabitants.print_house_info( village.to_add_data.bpos, plot_nr ));
if( not( minetest.get_modpath( "mob_world_interaction"))) then if( not( minetest.get_modpath( "mob_world_interaction"))) then