NetBSD/games/hack/hack.mkshop.c

312 lines
6.9 KiB
C
Raw Normal View History

1997-10-19 20:56:41 +04:00
/* $NetBSD: hack.mkshop.c,v 1.5 1997/10/19 16:58:31 christos Exp $ */
1993-08-02 21:16:36 +04:00
/*
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
*/
1997-10-19 20:56:41 +04:00
#include <sys/cdefs.h>
1993-08-02 21:16:36 +04:00
#ifndef lint
1997-10-19 20:56:41 +04:00
__RCSID("$NetBSD: hack.mkshop.c,v 1.5 1997/10/19 16:58:31 christos Exp $");
#endif /* not lint */
1993-03-21 12:45:37 +03:00
1993-04-19 01:52:18 +04:00
#include <stdlib.h>
1993-03-21 12:45:37 +03:00
#ifndef QUEST
#include "hack.h"
1997-10-19 20:56:41 +04:00
#include "extern.h"
1993-03-21 12:45:37 +03:00
#include "def.mkroom.h"
#include "def.eshk.h"
#define ESHK ((struct eshk *)(&(shk->mextra[0])))
1997-10-19 20:56:41 +04:00
schar shprobs[] = {3, 3, 5, 5, 10, 10, 14, 50}; /* their probabilities */
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
void
mkshop()
{
struct mkroom *sroom;
int sh, sx, sy, i = -1;
char let;
int roomno;
struct monst *shk;
1993-03-21 12:45:37 +03:00
#ifdef WIZARD
/* first determine shoptype */
1997-10-19 20:56:41 +04:00
if (wizard) {
char *ep = getenv("SHOPTYPE");
if (ep) {
if (*ep == 'z' || *ep == 'Z') {
1993-03-21 12:45:37 +03:00
mkzoo(ZOO);
return;
}
1997-10-19 20:56:41 +04:00
if (*ep == 'm' || *ep == 'M') {
1993-03-21 12:45:37 +03:00
mkzoo(MORGUE);
return;
}
1997-10-19 20:56:41 +04:00
if (*ep == 'b' || *ep == 'B') {
1993-03-21 12:45:37 +03:00
mkzoo(BEEHIVE);
return;
}
1997-10-19 20:56:41 +04:00
if (*ep == 's' || *ep == 'S') {
1993-03-21 12:45:37 +03:00
mkswamp();
return;
}
1997-10-19 20:56:41 +04:00
for (i = 0; shtypes[i]; i++)
if (*ep == shtypes[i])
break;
1993-03-21 12:45:37 +03:00
goto gottype;
}
}
gottype:
1997-10-19 20:56:41 +04:00
#endif /* WIZARD */
for (sroom = &rooms[0], roomno = 0;; sroom++, roomno++) {
if (sroom->hx < 0)
return;
if (sroom - rooms >= nroom) {
1993-03-21 12:45:37 +03:00
pline("rooms not closed by -1?");
return;
}
1997-10-19 20:56:41 +04:00
if (sroom->rtype)
continue;
if (!sroom->rlit || has_dnstairs(sroom) || has_upstairs(sroom))
1993-03-21 12:45:37 +03:00
continue;
1997-10-19 20:56:41 +04:00
if (
1993-03-21 12:45:37 +03:00
#ifdef WIZARD
1997-10-19 20:56:41 +04:00
(wizard && getenv("SHOPTYPE") && sroom->doorct != 0) ||
#endif /* WIZARD */
(sroom->doorct <= 2 && sroom->doorct > 0))
break;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (i < 0) { /* shoptype not yet determined */
int j;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
for (j = rn2(100), i = 0; (j -= shprobs[i]) >= 0; i++)
if (!shtypes[i])
break; /* superfluous */
if (isbig(sroom) && i + SHOPBASE == WANDSHOP)
i = GENERAL - SHOPBASE;
1993-03-21 12:45:37 +03:00
}
sroom->rtype = i + SHOPBASE;
let = shtypes[i];
sh = sroom->fdoor;
sx = doors[sh].x;
sy = doors[sh].y;
1997-10-19 20:56:41 +04:00
if (sx == sroom->lx - 1)
sx++;
else if (sx == sroom->hx + 1)
sx--;
else if (sy == sroom->ly - 1)
sy++;
else if (sy == sroom->hy + 1)
sy--;
else {
1993-03-21 12:45:37 +03:00
#ifdef WIZARD
1997-10-19 20:56:41 +04:00
/* This is said to happen sometimes, but I've never seen it. */
if (wizard) {
int j = sroom->doorct;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
pline("Where is shopdoor?");
pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly,
sroom->hx, sroom->hy);
pline("doormax=%d doorct=%d fdoor=%d",
doorindex, sroom->doorct, sh);
while (j--) {
pline("door [%d,%d]", doors[sh].x, doors[sh].y);
sh++;
}
more();
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
#endif /* WIZARD */
return;
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
if (!(shk = makemon(PM_SHK, sx, sy)))
return;
1993-03-21 12:45:37 +03:00
shk->isshk = shk->mpeaceful = 1;
shk->msleep = 0;
shk->mtrapseen = ~0; /* we know all the traps already */
ESHK->shoproom = roomno;
ESHK->shoplevel = dlevel;
ESHK->shd = doors[sh];
ESHK->shk.x = sx;
ESHK->shk.y = sy;
ESHK->robbed = 0;
ESHK->visitct = 0;
ESHK->following = 0;
1997-10-19 20:56:41 +04:00
shk->mgold = 1000 + 30 * rnd(100); /* initial capital */
1993-03-21 12:45:37 +03:00
ESHK->billct = 0;
findname(ESHK->shknam, let);
1997-10-19 20:56:41 +04:00
for (sx = sroom->lx; sx <= sroom->hx; sx++)
for (sy = sroom->ly; sy <= sroom->hy; sy++) {
struct monst *mtmp;
if ((sx == sroom->lx && doors[sh].x == sx - 1) ||
(sx == sroom->hx && doors[sh].x == sx + 1) ||
(sy == sroom->ly && doors[sh].y == sy - 1) ||
(sy == sroom->hy && doors[sh].y == sy + 1))
continue;
if (rn2(100) < dlevel && !m_at(sx, sy) &&
(mtmp = makemon(PM_MIMIC, sx, sy))) {
mtmp->mimic = 1;
mtmp->mappearance =
(let && rn2(10) < dlevel) ? let : ']';
continue;
}
(void) mkobj_at(let, sx, sy);
1993-03-21 12:45:37 +03:00
}
}
1997-10-19 20:56:41 +04:00
void
1993-03-21 12:45:37 +03:00
mkzoo(type)
1997-10-19 20:56:41 +04:00
int type;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
struct mkroom *sroom;
struct monst *mon;
int sh, sx, sy, i;
int goldlim = 500 * dlevel;
int moct = 0;
1993-03-21 12:45:37 +03:00
i = nroom;
1997-10-19 20:56:41 +04:00
for (sroom = &rooms[rn2(nroom)];; sroom++) {
if (sroom == &rooms[nroom])
1993-03-21 12:45:37 +03:00
sroom = &rooms[0];
1997-10-19 20:56:41 +04:00
if (!i-- || sroom->hx < 0)
1993-03-21 12:45:37 +03:00
return;
1997-10-19 20:56:41 +04:00
if (sroom->rtype)
1993-03-21 12:45:37 +03:00
continue;
1997-10-19 20:56:41 +04:00
if (type == MORGUE && sroom->rlit)
1993-03-21 12:45:37 +03:00
continue;
1997-10-19 20:56:41 +04:00
if (has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3)))
1993-03-21 12:45:37 +03:00
continue;
1997-10-19 20:56:41 +04:00
if (sroom->doorct == 1 || !rn2(5))
1993-03-21 12:45:37 +03:00
break;
}
sroom->rtype = type;
sh = sroom->fdoor;
1997-10-19 20:56:41 +04:00
for (sx = sroom->lx; sx <= sroom->hx; sx++)
for (sy = sroom->ly; sy <= sroom->hy; sy++) {
if ((sx == sroom->lx && doors[sh].x == sx - 1) ||
(sx == sroom->hx && doors[sh].x == sx + 1) ||
(sy == sroom->ly && doors[sh].y == sy - 1) ||
(sy == sroom->hy && doors[sh].y == sy + 1))
continue;
mon = makemon(
(type == MORGUE) ? morguemon() :
(type == BEEHIVE) ? PM_KILLER_BEE : (struct permonst *) 0,
sx, sy);
if (mon)
mon->msleep = 1;
switch (type) {
case ZOO:
i = sq(dist2(sx, sy, doors[sh].x, doors[sh].y));
if (i >= goldlim)
i = 5 * dlevel;
goldlim -= i;
mkgold((long) (10 + rn2(i)), sx, sy);
break;
case MORGUE:
/*
* Usually there is one dead body in the
* morgue
*/
if (!moct && rn2(3)) {
mksobj_at(CORPSE, sx, sy);
moct++;
}
break;
case BEEHIVE:
if (!rn2(3))
mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy);
break;
}
1993-03-21 12:45:37 +03:00
}
}
struct permonst *
morguemon()
{
1997-10-19 20:56:41 +04:00
int i = rn2(100), hd = rn2(dlevel);
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (hd > 10 && i < 10)
return (PM_DEMON);
if (hd > 8 && i > 85)
return (PM_VAMPIRE);
return ((i < 40) ? PM_GHOST : (i < 60) ? PM_WRAITH : PM_ZOMBIE);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
void
mkswamp()
{ /* Michiel Huisjes & Fred de Wilde */
struct mkroom *sroom;
int sx, sy, i, eelct = 0;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
for (i = 0; i < 5; i++) { /* 5 tries */
1993-03-21 12:45:37 +03:00
sroom = &rooms[rn2(nroom)];
1997-10-19 20:56:41 +04:00
if (sroom->hx < 0 || sroom->rtype ||
has_upstairs(sroom) || has_dnstairs(sroom))
1993-03-21 12:45:37 +03:00
continue;
/* satisfied; make a swamp */
sroom->rtype = SWAMP;
1997-10-19 20:56:41 +04:00
for (sx = sroom->lx; sx <= sroom->hx; sx++)
for (sy = sroom->ly; sy <= sroom->hy; sy++)
if ((sx + sy) % 2 && !o_at(sx, sy) && !t_at(sx, sy)
&& !m_at(sx, sy) && !nexttodoor(sx, sy)) {
levl[sx][sy].typ = POOL;
levl[sx][sy].scrsym = POOL_SYM;
if (!eelct || !rn2(4)) {
(void) makemon(PM_EEL, sx, sy);
eelct++;
}
}
1993-03-21 12:45:37 +03:00
}
}
1997-10-19 20:56:41 +04:00
int
nexttodoor(sx, sy)
int sx, sy;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
int dx, dy;
struct rm *lev;
for (dx = -1; dx <= 1; dx++)
for (dy = -1; dy <= 1; dy++)
if ((lev = &levl[sx + dx][sy + dy])->typ == DOOR ||
lev->typ == SDOOR || lev->typ == LDOOR)
return (1);
return (0);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
1993-03-21 12:45:37 +03:00
has_dnstairs(sroom)
1997-10-19 20:56:41 +04:00
struct mkroom *sroom;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
return (sroom->lx <= xdnstair && xdnstair <= sroom->hx &&
sroom->ly <= ydnstair && ydnstair <= sroom->hy);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
1993-03-21 12:45:37 +03:00
has_upstairs(sroom)
1997-10-19 20:56:41 +04:00
struct mkroom *sroom;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
return (sroom->lx <= xupstair && xupstair <= sroom->hx &&
sroom->ly <= yupstair && yupstair <= sroom->hy);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
1993-03-21 12:45:37 +03:00
isbig(sroom)
1997-10-19 20:56:41 +04:00
struct mkroom *sroom;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
int area = (sroom->hx - sroom->lx) * (sroom->hy - sroom->ly);
return (area > 20);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
dist2(x0, y0, x1, y1)
int x0, y0, x1, y1;
{
return ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
int
sq(a)
int a;
{
return (a * a);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
#endif /* QUEST */