#include "obj.h" #include "vars.h" #include "dice.h" #include "structs.h" #include "digdoors.h" #include "objtypes.h" #include "digdungeon.h" #include "vault.h" typedef struct vault VAULT; struct vault { LOC *centre; LOC *entrance; } ; #define MAXVAULTS 2 static VAULT vaults[MAXVAULTS]; static int nvaults; /* * Dig a vault. We generate random locations until we either find one * that's suitable or we've tried too many locations. A location must * (a) be on level 5 or higher and (b) must be a place where we can * dig a 3x3 room with a 1x1 entry point behind a secret door, without * overlapping anything. * * All the cells (walls, cave, and the secret door) are set LF_VAULT. */ static void digavault(void) { static int d[4][2] = { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } }; int nt; int x; int y; LEVEL *lv; for (nt=100;nt>0;nt--) { int o[4]; int i; lv = &levels[4+rnd(DUNGEON_LEVELS-4)]; x = 1 + rnd(LEV_X-2-3); y = 1 + rnd(LEV_Y-2-3); if (solidrock(lv,3,3,x,y)) { for (i=0;i<4;i++) o[i] = i; for (i=4;i>0;i--) { int j; int dx; int dy; int xx; int yy; j = rnd(i); dx = d[o[j]][0]; dy = d[o[j]][1]; xx = x + 1 + (4 * dx); yy = y + 1 + (4 * dy); if ( (xx >= 0) && (yy >= 0) && (xx < LEV_X) && (yy < LEV_Y) && solidrock(lv,1,1,x+1+(2*dx),y+1+(2*dy)) && solidrock(lv,1,1,x+1+(3*dx),y+1+(3*dy)) ) { for (xx=0;xx<3;xx++) for (yy=0;yy<3;yy++) digcell(lv,x+xx,y+yy); for (xx=-1;xx<4;xx++) for (yy=-1;yy<4;yy++) lv->cells[x+xx][y+yy].flags |= LF_VAULT; digcell(lv,x+1+(2*dx),y+1+(2*dy)); digcell(lv,x+1+(3*dx),y+1+(3*dy)); lv->cells[x+1+(3*dx) ][y+1+(3*dy) ].flags |= LF_VAULT; lv->cells[x+1+(3*dx)+dy][y+1+(3*dy)+dx].flags |= LF_VAULT; lv->cells[x+1+(3*dx)-dy][y+1+(3*dy)-dx].flags |= LF_VAULT; lv->cells[x+1+(4*dx) ][y+1+(4*dy) ].flags |= LF_VAULT; lv->cells[x+1+(4*dx)+dy][y+1+(4*dy)+dx].flags |= LF_VAULT; lv->cells[x+1+(4*dx)-dy][y+1+(4*dy)-dx].flags |= LF_VAULT; digdoor(lv,x+1+(2*dx),y+1+(2*dy),0,0); vaults[nvaults].centre = &lv->cells[x+1][y+1]; vaults[nvaults].entrance = &lv->cells[x+1+(3*dx)][y+1+(3*dy)]; nvaults ++; return; } else { if (j < i-1) o[j] = o[i-1]; } } } } } /* * Called during dungeon generation to create vaults. */ void makevaults(void) { int i; nvaults = 0; for (i=MAXVAULTS;i>0;i--) digavault(); } /* * Create money on a vault cell. */ static void vaultmoney(LOC *lc) { OBJ *g; g = obj_make(OBJ_GOLD); g->number = roll("4d500+500"); add_obj_to_inv(g,&lc->objs); } /* * Fill a vault with money. */ static void fillvault(VAULT *v) { int dx; int dy; for (dx=-1;dx<=1;dx++) for (dy=-1;dy<=1;dy++) vaultmoney(&v->centre->on->cells[v->centre->x+dx][v->centre->y+dy]); } /* * Called during dungeon generation to fill vaults. */ void fillvaults(void) { int i; for (i=nvaults-1;i>=0;i--) fillvault(&vaults[i]); }