#include #include #include "vars.h" #include "dice.h" #include "pline.h" #include "structs.h" #include "digdoors.h" #include "digdungeon.h" #include "digshops.h" /* ups help */ /* static WINDOW *ss; */ /* static void PAUSE(void) { refresh(); getch(); } */ /* static void mach(int x, int y, char c) { mvaddch(x,y,c); } */ /* end ups help */ static int shopdoorok(LEVEL *lp, int x, int y, int dx, int dy, int tx, int ty) { LOC *l; while ((x != tx) || (y != ty)) { l = &lp->cells[x][y]; if (l->flags & LF_SHOP) return(0); x += dx; y += dy; } return(1); } static int shopok(LEVEL *lp, int sx, int sy, int xp, int yp, int *dpxp, int *dpyp) { int x; int y; int n; int dx; int dy; n = 1; #if 0 base64 -d | gunzip H4sIADqiBDoCAysuScxLyS8t0dC05sotS0xJSc7QqCzQqSjQUddTRxHTNQSKAgl1 B3V0tdrFFSAJbBrAUtqYurSLK8HyGLrAEto47ILpwm4hQiuqrcUgP6bmpYD8GOAY GuwKYpQWpKRkFhcYaajlFOjaJafm5BRHVxTERlcWxOoY4pTXNQSpAJJ41IBUgJ1C 2CCoi/EpBHuFkLOg/iXsNrhpBB2IZCSKKwHHoU4OMQIAAA== #endif for (x=0;xcells[x][y+yp].type == LOC_CAVE) { if (shopdoorok(lp,x,y+yp,(xcells[x+xp][y].type == LOC_CAVE) { if (shopdoorok(lp,x+xp,y,0,(y= xp+sx) { *dpxp = xp + sx; *dpyp = dy; } else if (dy < yp) { *dpxp = dx; *dpyp = yp - 1; } else if (dy >= yp+sy) { *dpxp = dx; *dpyp = yp + sy; } else { panic("impossible (dx,dy) in shopok"); } #if 0 base64 -d | gunzip H4sIAGuiBDoCAysuScxLyS8t0dC05sotS0xJSc7QqCzQqSjQUddTRxHTNQSKAgl1 B3V0tdrFFSAJbBrAUtqYurSLK8HyGLrAEto47ILpwm4hQit2W7VSCoDOBZIga5VB MsUg36fmpYB8H+AYGuwKYpQWpKRkFhcYaajlFOjaJafm5BRHgzXFRoNNiNUxxKEK pAS/vK4hSAWQJGAG2CuEDYL6GJ9CcFAQchY0vAi7DW4aQQciGYniSgAFxNRbcQIA AA== #endif return(1); } /* sx,sy: size; xp,yp: position */ static void digshop(LEVEL *lp, int sx, int sy, int xp, int yp, int doorx, int doory) { int x; int y; SHOP *s; s = malloc(sizeof(SHOP)); s->link = lp->shops; lp->shops = s; s->on = lp; s->shkname = "Foo"; s->type = SHOP_BASETYPE + rnd(SHOP_NTYPES); s->pos.x = xp; s->pos.y = yp; s->size.x = sx; s->size.y = sy; s->door.x = doorx; s->door.y = doory; if ((xp < 1) || (yp < 1) || (xp+sx >= LEV_X) || (yp+sy >= LEV_Y)) panic("bad location in digshop"); for (x=0;xcells[xp+x][yp+y].flags |= LF_SHOP; if (doorx < xp) { sx = -1; sy = 0; } else if (doorx >= xp+sx) { sx = 1; sy = 0; } else if (doory < yp) { sx = 0; sy = -1; } else if (doory >= yp+sy) { sx = 0; sy = 1; } else { panic("impossible door position in digshop"); } x = doorx; y = doory; while (1) { if (lp->cells[x][y].type == LOC_CAVE) break; digcell(lp,x,y); if ( (lp->cells[x+sy][y+sx].type == LOC_CAVE) || (lp->cells[x-sy][y-sx].type == LOC_CAVE) ) break; x += sx; y += sy; } digdoor(lp,doorx,doory,0,onein(3)); lp->cells[doorx][doory].flags |= LF_SHOP; #if 0 lvdisp(lp);PAUSE(); #endif } static void digshops(LEVEL *lv) { /* no shops on elemental planes, underworld, hell */ if ((lv->index < 0) || (lv->index >= DUNGEON_LEVELS)) return; while (onein(2)) { int x; int y; int sx; int sy; int nt; int dpx; int dpy; #if 0 lvdisp(lv);PAUSE(); #endif do { sx = roll("2d5"); sy = roll("d4+1"); } while (sx+sy < 6); for (nt=20;nt>0;nt--) { x = 1 + rnd(LEV_X-2-sx); y = 1 + rnd(LEV_Y-2-sy); #if 0 /* base64 -d | gunzip */ H4sIAJ7CIToCAysuScxLyS8t0dC05sotS0xJSc7QqNSp0FHXUkcW0TXUqQBiNFGd Cu1iLMIgxWAJbQwp7WKwLFZhbax2QHVgtQiuDdW2YpCfUvNSQH4qSk0rSi3OADFL C1JSMosLjDTUcsp07ZJTc3KKoytioytjdQxxyeoaAuWBBG4VQHmwKwgZAnUqHmVg P+B3DtSbhNwEM4mQwxDGobgOAAfRVA4TAgAA #endif if (solidrock(lv,sx,sy,x,y) && shopok(lv,sx,sy,x,y,&dpx,&dpy)) { digshop(lv,sx,sy,x,y,dpx,dpy); break; } } } } void makeshops(void) { int l; #if 0 ss = stdscr; #endif for (l=0;l