/* * Door creation routines. */ #include #include "vars.h" #include "dice.h" #include "digdungeon.h" #include "digdoors.h" /* * Return true if the arguments describe an acceptable place for a * door. * * This is used during dungeon creation, when LF_FLAGB indicates "do * not put doors here", so that flag bit always makes this reutrn * false. Otherwise, for it to be an acceptable place for a door, * * - It must be CAVE/JUSTCAVE or WALL, and * - Either the LOCs above and below are WALL and the ones left and * right are CAVE or the other way around. */ static int doorok(LEVEL *lv, int x, int y) { LOC *lc; LOC *lcu; LOC *lcd; LOC *lcl; LOC *lcr; lc = &lv->cells[x][y]; if (lc->flags & LF_FLAGB) return(0); if ( ((lc->type == LOC_CAVE) && (lc->cavetype == LOC_JUSTCAVE)) || (lc->type == LOC_WALL) ) { lcu = &lv->cells[x][y-1]; lcd = &lv->cells[x][y+1]; lcl = &lv->cells[x-1][y]; lcr = &lv->cells[x+1][y]; return( ( (lcu->type == LOC_WALL) && (lcd->type == LOC_WALL) && (lcl->type == LOC_CAVE) && (lcr->type == LOC_CAVE) ) || ( (lcl->type == LOC_WALL) && (lcr->type == LOC_WALL) && (lcu->type == LOC_CAVE) && (lcd->type == LOC_CAVE) ) ); } return(0); } /* * Dig a door. The first three arguments specify where; if secretp is * true, the door is secret (and perforce closed), while if secretp is * false, openp specifies whether the door is to be open (true) or not * (false). */ void digdoor(LEVEL *lv, int x, int y, int secretp, int openp) { LOC *lc; lc = &lv->cells[x][y]; if (lc->type != LOC_CAVE) digcell(lc->on,lc->x,lc->y); if (secretp) { lc->type = LOC_SDOOR; lc->walldoor = LOC_UWALL; } else { lc->type = LOC_DOOR; lc->walldoor = (openp ? LOC_DOOR_OPEN : LOC_DOOR_CLOSED) | ((lv->cells[x][y-1].type == LOC_CAVE) ? LOC_VWALL : LOC_HWALL); } } /* * Dig doors on a level. * * This just picks 100 random locations on the level and, for each one, * if it's an acceptable place for a door, it digs a door there. * There's a one-in-three chance each door will be secret; for * non-secret doors, there's a one-in-three chance it will be open. * * This is called even for the elemental planes, though it ends up * doing nothing there because none of the locations are acceptable * door locations. */ static void digdoors(LEVEL *lv) { int i; int x; int y; LOC *lc; for (i=0;i<100;i++) { x = 1 + rnd(LEV_X-2); y = 1 + rnd(LEV_Y-2); lc = &lv->cells[x][y]; if (doorok(lv,x,y)) digdoor(lv,x,y,onein(3),onein(3)); } } /* * Called during dungeon creation. THis digs doors throughout the * dungeon. */ void makedoors(void) { int l; for (l=0;l