added transform_coordinates and get_entrance_list

This commit is contained in:
Sokomine 2017-07-06 18:18:40 +02:00
parent e8c787e0f1
commit 1b44da4316
3 changed files with 73 additions and 4 deletions

View File

@ -78,7 +78,7 @@ local buildings = {
{scm="farm_tiny_4", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=4}, {scm="farm_tiny_4", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=4},
{scm="farm_tiny_5", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=4}, {scm="farm_tiny_5", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=4},
{scm="farm_tiny_6", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=4}, {scm="farm_tiny_6", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=4},
{scm="farm_tiny_7", yoff= 0, orients={1}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=7}, {scm="farm_tiny_7", yoff= 0, orients={3}, farming_plus=1, avoid='', typ='farm_tiny', weight={medieval=1, single=1 }, inh=7},
{scm="taverne_1", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='tavern', weight={medieval=1/2, single=1 }, pervillage=1, inh=6, guests=-3}, -- 19 beds: 10 guest, 3 worker, 6 family {scm="taverne_1", yoff= 0, orients={0}, farming_plus=1, avoid='', typ='tavern', weight={medieval=1/2, single=1 }, pervillage=1, inh=6, guests=-3}, -- 19 beds: 10 guest, 3 worker, 6 family
{scm="taverne_2", yoff= 0, orients={0}, farming_plus=0, avoid='', typ='tavern', weight={medieval=1/2, single=1/3}, pervillage=1, inh=2}, -- no guests {scm="taverne_2", yoff= 0, orients={0}, farming_plus=0, avoid='', typ='tavern', weight={medieval=1/2, single=1/3}, pervillage=1, inh=2}, -- no guests
{scm="taverne_3", yoff= 0, orients={0}, farming_plus=0, avoid='', typ='tavern', weight={medieval=1/2, single=1/3}, pervillage=1, inh=2}, -- no guests {scm="taverne_3", yoff= 0, orients={0}, farming_plus=0, avoid='', typ='tavern', weight={medieval=1/2, single=1/3}, pervillage=1, inh=2}, -- no guests

View File

@ -644,6 +644,74 @@ mg_villages.inhabitants.assign_jobs_to_houses = function( village_to_add_data_bp
end end
-- apply bpos.pos as offset and apply rotation
mg_villages.transform_coordinates = function( pos, bpos )
-- start with the start position as stored in bpos
local p = {x=bpos.x, y=bpos.y, z=bpos.z};
local building_data = mg_villages.BUILDINGS[ bpos.btype ];
-- the height is not affected by rotation
-- the positions are stored as array
p.y = p.y + building_data.yoff + pos[2] - 1;
local rel = {x=pos[1], y=pos[2], z=pos[3]}; -- relative position (usually of entrance)
-- all values start counting with index 1; we need to start with 0 for the offset
local sx = bpos.bsizex-1;
local sz = bpos.bsizez-1;
rel.x = rel.x-1;
rel.z = rel.z-1;
if( bpos.mirror and bpos.btype ) then
local o = building_data.orients[1];
if( (o == 0 or o == 2) and (bpos.brotate==0 or bpos.brotate==2)) then
rel.z = sz - rel.z;
elseif( (o == 0 or o == 2) and (bpos.brotate==1 or bpos.brotate==3)) then
rel.z = sx - rel.z;
elseif( (o == 1 or o == 3) and (bpos.brotate==0 or bpos.brotate==2)) then
rel.x = sx - rel.x;
elseif( (o == 1 or o == 3) and (bpos.brotate==1 or bpos.brotate==3)) then
rel.x = sz - rel.x;
end
end
if( bpos.brotate==0 ) then
p.x = p.x + rel.x;
p.z = p.z + rel.z;
elseif( bpos.brotate==1 ) then
p.x = p.x + rel.z;
p.z = p.z + sz - rel.x; -- bsizex and bsizez are swapped
elseif( bpos.brotate==2 ) then
p.x = p.x + sx - rel.x;
p.z = p.z + sz - rel.z;
elseif( bpos.brotate==3 ) then
p.x = p.x + sx - rel.z; -- bsizex and bsizez are swapped
p.z = p.z + rel.x;
end
return p;
end
mg_villages.get_entrance_list = function( village_id, plot_nr )
if( not( mg_villages.all_villages[ village_id ])
or not( mg_villages.all_villages[ village_id ].to_add_data.bpos[ plot_nr ] )) then
return {};
end
local bpos = mg_villages.all_villages[ village_id ].to_add_data.bpos[ plot_nr ];
local building_data = mg_villages.BUILDINGS[ bpos.btype ];
if( not( building_data ) or not(building_data.all_entrances )) then
return {};
end
local entrance_list = {};
for i,e in ipairs( building_data.all_entrances ) do
table.insert( entrance_list, mg_villages.transform_coordinates( e, bpos ));
end
return entrance_list;
end
-- get the information mg_villages has about a mob (useful for mg_villages:mob_spawner) -- get the information mg_villages has about a mob (useful for mg_villages:mob_spawner)
mg_villages.inhabitants.get_mob_data = function( village_id, plot_nr, bed_nr ) mg_villages.inhabitants.get_mob_data = function( village_id, plot_nr, bed_nr )
if( not( village_id ) or not( plot_nr ) or not( bed_nr ) if( not( village_id ) or not( plot_nr ) or not( bed_nr )

View File

@ -105,9 +105,10 @@ mg_villages.check_if_ground = function( ci )
'ethereal:bush', 'default:grass', 'default:grass_1','default:grass_2','default:grass_3','default:grass_4','default:grass_5', 'ethereal:bush', 'default:grass', 'default:grass_1','default:grass_2','default:grass_3','default:grass_4','default:grass_5',
'farming_plus:banana_leaves', 'farming_plus:banana', 'farming_plus:banana_leaves', 'farming_plus:banana',
'farming_plus:cocoa_sapling', 'farming_plus:cocoa_leaves', 'farming_plus:cocoa', 'farming_plus:cocoa_sapling', 'farming_plus:cocoa_leaves', 'farming_plus:cocoa',
'farming_plus:melon', 'farming_plus:orangeb', 'farming_plus:peach', 'farming_plus:melon',
'farming_plus:lemonb', 'farming_plus:orange', 'farming_plus:preachb', 'farming_plus:lemonb', 'farming_plus:orangeb', 'farming_plus:peachb',
'farming_plus:peach_4b', 'farming_plus:peach_5b', 'farming_plus:lemon', 'farming_plus:orange', 'farming_plus:peach',
'farming_plus:peach_4b', 'farming_plus:peach_5b', 'farming_plus:walnut',
'farming:pumpkin', 'farming:pumpkin_face', 'farming:pumpkin_face_light', 'farming:pumpkin', 'farming:pumpkin_face', 'farming:pumpkin_face_light',
'cavestuff:desert_pebble_2', 'cavestuff:desert_pebble_1', 'cavestuff:desert_pebble_2', 'cavestuff:desert_pebble_1',
'cavestuff:pebble_1', 'cavestuff:pebble_2'}; 'cavestuff:pebble_1', 'cavestuff:pebble_2'};