var dist=21,xx=argument[0],yy=argument[1],bkg=argument[2];//Grid positions
var tx=(xx-yy)*TILE,ty=(xx+yy)*TILE/2-TILE*4;//Isometric positions
for(var i=0;i<array_height_2d(house);i++){//List of predefined houses
var posx=house[i,0],posy=house[i,1],w=house[i,2],h=house[i,3],off=house[i,4]*TILE*2,d=(posx+w/2+posy+h/2)*TILE/2+TILE*50;//House parameters
if house[i,6]>0{//Side room
if w<h&&xx>=posx+w+1&&yy>=posy&&xx<=posx+w+house[i,6]&&yy<=posy+w{
if house[i,5]=1{//Gable Roof
if yy<posy+w/2{//right&up
if !random(50)&&yy!=posy{
tile_add(bkg,TILE*8,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);//Chimney
}else if !random(20)&&yy!=posy{
tile_add(bkg,TILE*16,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);//Skylight
}else{
tile_add(bkg,0,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}
}else{//left&bottom
if !random(50)&&yy!=posy+w{
tile_add(bkg,TILE*10,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy+w{
tile_add(bkg,TILE*18,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*2,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}
}
}else{//Hip Roof
if yy<posy+w/2{
if xx-posx-house[i,6]<abs(yy-posy-w){
if !random(50)&&yy!=posy{
tile_add(bkg,TILE*8,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy{
tile_add(bkg,TILE*16,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else{
tile_add(bkg,0,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}
}else if xx-posx-house[i,6]=abs(yy-posy-w){
tile_add(bkg,TILE*28,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}
}else{
if xx-posx-w-house[i,6]<yy-posy-w{
if !random(50)&&yy!=posy+w{
tile_add(bkg,TILE*10,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy+w{
tile_add(bkg,TILE*18,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*2,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}
}else if xx-posx-w-house[i,6]=yy-posy-w{
tile_add(bkg,TILE*24,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}
}
if xx>posx+w+house[i,6]-w/2+1{
if yy-posy>abs(xx-posx-w-house[i,6])&&yy-posy-w<xx-posx-w-house[i,6]{
if !random(50)&&xx!=posx+h{
tile_add(bkg,TILE*12,off,TILE*2,TILE*2,tx,ty-(house[i,6]-xx+posx+w)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx+w{
tile_add(bkg,TILE*20,off,TILE*2,TILE*2,tx,ty-(house[i,6]-xx+posx+w)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*4,off,TILE*2,TILE*2,tx,ty-(house[i,6]-xx+posx+w)*(TILE-dist),-d);
}
}
}
}
}else if w>h&&xx>=posx&&yy>=posy+h+1&&xx<=posx+h&&yy<=posy+h+house[i,6]{
if house[i,5]=1{//Gable Roof
if xx<posx+h/2{
if !random(50)&&xx!=posx{
tile_add(bkg,TILE*14,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx{
tile_add(bkg,TILE*22,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*6,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}
}else{
if !random(50)&&xx!=posx+h{
tile_add(bkg,TILE*12,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx+h{
tile_add(bkg,TILE*20,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*4,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}
}
}else{//Hip Roof
if xx<posx+h/2{
if yy-posy-house[i,6]<abs(xx-posx-h){
if !random(50)&&xx!=posx{
tile_add(bkg,TILE*14,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx{
tile_add(bkg,TILE*22,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*6,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}
}else if yy-posy-house[i,6]=abs(xx-posx-h){
tile_add(bkg,TILE*26,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}
}else{
if yy-posy-h-house[i,6]<xx-posx-h{
if !random(50)&&xx!=posx+h{
tile_add(bkg,TILE*12,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx+w{
tile_add(bkg,TILE*20,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*4,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}
}else if yy-posy-h-house[i,6]=xx-posx-h{
tile_add(bkg,TILE*24,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}
}
if yy>posy+h+house[i,6]-w/2+1{
if xx-posx>abs(yy-posy-h-house[i,6])&&xx-posx-h<yy-posy-h-house[i,6]{
if !random(50)&&yy!=posy+w{
tile_add(bkg,TILE*10,off,TILE*2,TILE*2,tx,ty-(house[i,6]-yy+posy+h)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy+w{
tile_add(bkg,TILE*18,off,TILE*2,TILE*2,tx,ty-(house[i,6]-yy+posy+h)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*2,off,TILE*2,TILE*2,tx,ty-(house[i,6]-yy+posy+h)*(TILE-dist),-d);
}
}
}
}
}
}
if xx>=posx&&yy>=posy&&xx<=posx+w&&yy<=posy+h{
if house[i,5]=0{//Hip Roof
if house[i,6]>0{
if w<h&&yy>posy+w/2&&yy<posy+w&&yy-posy-w/2<xx-posx-w/2{
if !random(50)&&yy!=posy+h{
tile_add(bkg,TILE*10,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy+h{
tile_add(bkg,TILE*18,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*2,off,TILE*2,TILE*2,tx,ty-(w-yy+posy)*(TILE-dist),-d);
}
}
if w>h&&xx>posx+h/2&&xx<posx+h&&xx-posx-h/2<yy-posy-h/2{
if !random(50)&&xx!=posx+w{
tile_add(bkg,TILE*12,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx+w{
tile_add(bkg,TILE*20,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*4,off,TILE*2,TILE*2,tx,ty-(h-xx+posx)*(TILE-dist),-d);
}
}
}
if xx<posx+w/2{
if yy-posy>xx-posx&&(yy-posy<abs(xx-posx-h)||(house[i,6]>0&&w>h&&xx<posx+h/2)){
if !random(50)&&xx!=posx{
tile_add(bkg,TILE*14,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx{
tile_add(bkg,TILE*22,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*6,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}
}else if yy-posy=xx-posx&&w<=h{
tile_add(bkg,TILE*30,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else if yy-posy=abs(xx-posx-h)&&w<=h{//||house[i,6]=0)
tile_add(bkg,TILE*26,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}
}else{
if yy-posy-h<xx-posx-w&&yy-posy>abs(xx-posx-w)&&(house[i,6]=0||w>h||yy-posy-w>xx-posx-w){
if !random(50)&&xx!=posx+w{
tile_add(bkg,TILE*12,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx+w{
tile_add(bkg,TILE*20,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*4,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}
}else if house[i,6]>0&&w<h&&yy-posy-w=xx-posx-w{
tile_add(bkg,TILE*30,off+TILE*16,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}else if yy-posy-h=xx-posx-w&&w<=h{
tile_add(bkg,TILE*24,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}else if yy-posy=abs(xx-posx-w)&&w<=h{
tile_add(bkg,TILE*28,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}
}
if yy<posy+h/2{
if xx-posx>yy-posy&&(xx-posx<abs(yy-posy-w)||(house[i,6]>0&&w<h&&yy<posy+w/2)){
if !random(50)&&yy!=posy{
tile_add(bkg,TILE*8,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy{
tile_add(bkg,TILE*16,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else{
tile_add(bkg,0,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}
}else if xx-posx=yy-posy&&w>h{
tile_add(bkg,TILE*30,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else if xx-posx=abs(yy-posy-w)&&w>h{
tile_add(bkg,TILE*28,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}
}else{
if xx-posx-w<yy-posy-h&&xx-posx>abs(yy-posy-h)&&(house[i,6]=0||w<h||xx-posx-h>yy-posy-h){
if !random(50)&&yy!=posy+h{
tile_add(bkg,TILE*10,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy+h{
tile_add(bkg,TILE*18,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*2,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}
}else if house[i,6]>0&&w>h&&xx-posx-h=yy-posy-h{
tile_add(bkg,TILE*30,off+TILE*16,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}else if xx-posx-w=yy-posy-h&&w>h{
tile_add(bkg,TILE*24,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}else if xx-posx=abs(yy-posy-h)&&w>h&&house[i,6]=0{
tile_add(bkg,TILE*26,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}
}
}else{//Gable Roof
if w<h{
if xx<posx+w/2{
if !random(50)&&xx!=posx{
tile_add(bkg,TILE*14,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx{
tile_add(bkg,TILE*22,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*6,off,TILE*2,TILE*2,tx,ty-(xx-posx)*(TILE-dist),-d);
}
}else{
if !random(50)&&xx!=posx+w{
tile_add(bkg,TILE*12,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}else if !random(20)&&xx!=posx+w{
tile_add(bkg,TILE*20,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*4,off,TILE*2,TILE*2,tx,ty-(w-xx+posx)*(TILE-dist),-d);
}
}
}else{
if yy<posy+h/2{
if !random(50)&&yy!=posy{
tile_add(bkg,TILE*8,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy{
tile_add(bkg,TILE*16,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}else{
tile_add(bkg,0,off,TILE*2,TILE*2,tx,ty-(yy-posy)*(TILE-dist),-d);
}
}else{
if !random(50)&&yy!=posy+h{
tile_add(bkg,TILE*10,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}else if !random(20)&&yy!=posy+h{
tile_add(bkg,TILE*18,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}else{
tile_add(bkg,TILE*2,off,TILE*2,TILE*2,tx,ty-(h-yy+posy)*(TILE-dist),-d);
}
}
}
}
}
}