Exemplo n.º 1
0
/*
 * picky_inven:
 *	Allow player to inventory a single item
 */
int picky_inven()
{
	struct linked_list *item;
	char ch, mch;

	if (pack == NULL)
		msg("You aren't carrying anything.");
	else if (next(pack) == NULL)
		msg("a) %s", inv_name(OBJPTR(pack), FALSE));
	else {
		msg("Item: ");
		mpos = 0;
		if ((mch = readchar()) == ESCAPE) {
			msg("");
			return 0;
		}
		for (ch='a',item=pack; item != NULL; item=next(item),ch=npch(ch))
			if (ch == mch) {
				msg("%c) %s",ch,inv_name(OBJPTR(item), FALSE));
				return 0;
			}
		if (ch == 'A')
			ch = 'z';
		else
			ch -= 1;
		msg("Range is 'a' to '%c'", ch);
	}
  return 0;
}
Exemplo n.º 2
0
/*
 * inventory:
 *	Show what items are in a specific list
 */
bool inventory(struct linked_list *list,int type)
{
	struct linked_list *pc;
	struct object *obj;
	char ch;
	int cnt;

	if (list == NULL) {			/* empty list */
		msg(type == 0 ? "Empty handed." : "Nothing appropriate.");
		return FALSE;
	}
	else if (next(list) == NULL) {	/* only 1 item in list */
		obj = OBJPTR(list);
		msg("a) %s", inv_name(obj, FALSE));
		return TRUE;
	}
	cnt = 0;
	wclear(hw);
	for (ch = 'a', pc = list; pc != NULL; pc = next(pc), ch = npch(ch)) {
		obj = OBJPTR(pc);
		wprintw(hw,"%c) %s\n\r",ch,inv_name(obj, FALSE));
		if (++cnt > LINES - 2 && next(pc) != NULL) {
			dbotline(hw, morestr);
			cnt = 0;
			wclear(hw);
		} 
	}
	dbotline(hw,spacemsg);
	restscr(cw);
	return TRUE;
}
Exemplo n.º 3
0
void
ring_off(void)
{
    struct object   *obj;
    struct linked_list  *item;

    if (cur_ring[LEFT_1] == NULL && cur_ring[LEFT_2] == NULL &&
        cur_ring[LEFT_3] == NULL && cur_ring[LEFT_4] == NULL &&
        cur_ring[LEFT_5] == NULL &&
        cur_ring[RIGHT_1] == NULL && cur_ring[RIGHT_2] == NULL &&
        cur_ring[RIGHT_3] == NULL && cur_ring[RIGHT_4] == NULL &&
        cur_ring[RIGHT_5] == NULL)
    {
        msg("You aren't wearing any rings.");
        return;
    }
    else if ((item = get_item("remove", RING)) == NULL)
        return;

    mpos = 0;
    obj = OBJPTR(item);

    if ((obj = OBJPTR(item)) == NULL)
        msg("You are not wearing that!");

    if (dropcheck(obj))
    {
        switch (obj->o_which)
        {
            case R_SEEINVIS:
                msg("Your eyes stop tingling.");
                break;

            case R_CARRYING:
                updpack();
                break;

            case R_LEVITATION:
                msg("You float gently to the ground.");
                break;

            case R_LIGHT:
                if (roomin(hero) != NULL)
                {
                    light(&hero);
                    mvwaddch(cw, hero.y, hero.x, PLAYER);
                }
                break;

            case R_TRUESEE:
                msg("Your sensory perceptions return to normal.");
                break;
        }

        msg("Was wearing %s.", inv_name(obj, LOWERCASE));
    }
}
Exemplo n.º 4
0
/*
 * domaze:
 *	Draw the maze on this level.
 */
do_maze()
{
	reg int least;
	reg struct room *rp;
	reg struct linked_list *item;
	reg struct object *obj;
	int cnt;
	bool treas;
	coord tp;

	for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
		rp->r_flags = ISGONE;		/* kill all rooms */
		rp->r_fires = NULL;		/* no fires */
	}
	rp = &rooms[0];				/* point to only room */
	rp->r_flags = ISDARK;			/* mazes always dark */
	rp->r_pos.x = 0;			/* room fills whole screen */
	rp->r_pos.y = 1;
	rp->r_max.x = cols - 1;
	rp->r_max.y = lines - 3;
	draw_maze();				/* put maze into window */
	/*
	 * add some gold to make it worth looking for 
	 */
	item = spec_item(GOLD, NULL, NULL, NULL);
	obj = OBJPTR(item);
	obj->o_count *= (rnd(5) + 5);		/* add in one large hunk */
	attach(lvl_obj, item);
	cnt = 0;
	do {
	    rnd_pos(rp, &tp);
	} until (mvinch(tp.y, tp.x) == FLOOR || cnt++ > 5000);
	mvaddch(tp.y, tp.x, GOLD);
	obj->o_pos = tp;
	/*
	 * add in some food to make sure he has enough
	 */
	item = spec_item(FOOD, NULL, NULL, NULL);
	obj = OBJPTR(item);
	attach(lvl_obj, item);
	do {
	    rnd_pos(rp, &tp);
	} until (mvinch(tp.y, tp.x) == FLOOR || cnt++ > 5000);
	mvaddch(tp.y, tp.x, FOOD);
	obj->o_pos = tp;
	if (rnd(100) < 40) {			/* treasure type maze */
		treas = TRUE;
		least = 10;
		debug("treasure maze");
	}
	else {					/* normal maze level */
		least = 5;
		treas = FALSE;
	}
	genmonsters(least, treas);
}
Exemplo n.º 5
0
void
show_floor(void)
{
    struct linked_list  *item;
    struct object   *obj;

    item = find_obj(hero.y, hero.x);

    if (item != NULL)
    {
        addmsg("%s onto ", terse ? "Moved" : "You moved");

        obj = OBJPTR(item);

        if (obj->next_obj != NULL)
            msg("a stack of things.");
        else if (obj->o_type == GOLD)
            msg("%d gold pieces.", obj->o_count);
        else
        {
            addmsg(inv_name(obj, TRUE));
            addmsg(".");
            endmsg();
        }
    }
}
Exemplo n.º 6
0
/*
 * price_it:
 *	Price the object that the hero stands on
 */
bool price_it()
{
  static char *bargain[] = {
      "great bargain", "quality product", "exceptional find",
  };
  struct linked_list *item;
  struct object *obj;
  int worth;

  if (!open_market()) /* after buying hours */
    return FALSE;
  if ((item = find_obj(hero.y, hero.x)) == NULL)
    return FALSE;
  obj = OBJPTR(item);
  if (curprice == NOTPRICED) {
    worth = get_worth(obj);
    worth += 50 - rnd(100);
    if (worth < 25)
      worth = 25;
    worth *= 3;                       /* slightly expensive */
    curprice = worth;                 /* save price */
    strcpy(curpurch, obj->o_typname); /* save item */
  }
  msg("That %s is a %s for only %d pieces of gold", curpurch, bargain[rnd(3)],
      curprice);
  return TRUE;
}
/*
 * buy_it:
 *	Buy the item on which the hero stands
 */
void
buy_it()
{
	struct linked_list *item;
	struct object *obj;
	int wo;

	if (purse <= 0) {
	    msg("You have no money.");
	    return;
	}

	if ((item = get_item(pack, "buy", ALL)) == NULL)
	    return;
	obj = OBJPTR(item);
	if (!(obj->o_flags & ISUNPAID)) {
		msg("You already own that.");
		return;
	}
	wo = get_worth(obj);

	if (wo > purse) {
	    msg("You can't afford that!");
	    msg("It costs %d pieces of gold.", wo);
	    return;
	}
	purse-=wo;
	not_paid--;
	obj->o_flags &= ~ISUNPAID;
}
Exemplo n.º 8
0
void
swap_top(struct linked_list *top, struct linked_list *node)
{
    struct object   *obt, *obn;

    obt = OBJPTR(top);
    obn = OBJPTR(node);

    detach((obt->next_obj), node);  /* Take it out of the stack */
    attach(lvl_obj, node);  /* and put it into the level */
    detach(lvl_obj, top);   /* Remove item from level */

    obn->next_obj = obt->next_obj;

    if (obn->next_obj)
        obn->next_obj->l_prev = NULL;

    attach((obn->next_obj), top);
}
Exemplo n.º 9
0
/*
 * pack_char:
 *	Get the character of a particular item in the pack
 */
char pack_char(struct object *obj)
{
	struct linked_list *item;
	char c;

	c = 'a';
	for (item = pack; item != NULL; item = next(item))
		if (OBJPTR(item) == obj)
			return c;
		else
			c = npch(c);
	return '%';
}
Exemplo n.º 10
0
/*
 * packweight: Get the total weight of the hero's pack
 */
packweight()
{
	struct linked_list  *pc;
	int weight = 0;

	for (pc = pack; pc != NULL; pc = next(pc)) {
	    struct object   *obj = OBJPTR(pc);

	    weight += itemweight(obj) * obj->o_count;
	}
	if (weight < 0)     /* caused by artifacts or blessed items */
	    weight = 0;

	return (weight);
}
Exemplo n.º 11
0
/* 
 * del_pack:
 *	Take something out of the hero's pack
 */
void del_pack(struct linked_list *what)
{
	struct object *op;

	op = OBJPTR(what);
	cur_null(op);		/* check for current stuff */
	if (op->o_count > 1) {
		op->o_count--;
	}
	else {
		detach(pack,what);
		discard(what);
	}
	updpack();
}
Exemplo n.º 12
0
struct linked_list  *
find_obj(int y, int x)
{
    struct linked_list  *obj, *sobj;
    struct object   *op;

    sobj = lvl_obj;

    for (obj = sobj; obj != NULL; obj = next(obj))
    {
        op = OBJPTR(obj);

        if (op && op->o_pos.y == y && op->o_pos.x == x)
            return(obj);
    }

    return(NULL);
}
Exemplo n.º 13
0
void
get_all(struct linked_list *top)
{
    struct linked_list  *node;
    struct object   *obt;

    while (top)
    {
        obt = OBJPTR(top);
        node = obt->next_obj;

        rem_obj(top, FALSE);

        if (!add_pack(top, FALSE))
            return;

        top = node;
    }
}
Exemplo n.º 14
0
/*
 * packweight:
 *	Get the total weight of the hero's pack
 */
int
packweight(void)
{
    reg struct object *obj;
    reg struct linked_list *pc;
    reg int weight;

    weight = 0;
    for(pc = pack ; pc != NULL ; pc = next(pc)) {
        obj = OBJPTR(pc);
        weight += itemweight(obj) * obj->o_count;
    }
    if(ISWEARING(R_CARRYING))
        weight -= (ring_value(R_CARRYING) * weight) / 4;
    if(weight < 0)		/* in case of artifacts and stuff */
        weight = 0;

    return(weight);
}
Exemplo n.º 15
0
void
whatis(struct linked_list *what)
{
    struct object *obj;
    int kludge;
    int print_message = FALSE;

    if (what == NULL)
    {
        print_message = TRUE;

        while ((what = get_item("identify", 0)) == NULL)
            ;
    }

    obj = OBJPTR(what);
    obj->o_flags |= ISKNOW;

    switch (obj->o_type)
    {
        case SCROLL: kludge = TYP_SCROLL; break;
        case POTION: kludge = TYP_POTION; break;
        case STICK:  kludge = TYP_STICK;  break;
        case RING:   kludge = TYP_RING;   break;
        case WEAPON:
        case ARMOR:
        default:     kludge = -1;         break;
    }

    if (kludge != -1)
    {
        know_items[kludge][obj->o_which] = TRUE;

        if (guess_items[kludge][obj->o_which])
        {
            ur_free(guess_items[kludge][obj->o_which]);
            guess_items[kludge][obj->o_which] = NULL;
        }
    }

    if (print_message)
        msg(inv_name(obj, UPPERCASE));
}
Exemplo n.º 16
0
/*
 * do_post:
 *	Put a trading post room and stuff on the screen
 */
void do_post()
{
  struct coord tp;
  int i;
  struct room *rp;
  struct object *op;
  struct linked_list *ll;

  free_list(lvl_obj); /* throw old items away */

  for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
    rp->r_goldval = 0;    /* no gold */
    rp->r_nexits = 0;     /* no exits */
    rp->r_flags = ISGONE; /* kill all rooms */
  }
  rp = &rooms[0];  /* point to only room */
  rp->r_flags = 0; /* this room NOT gone */
  rp->r_max.x = 40;
  rp->r_max.y = 10;                       /* 10 * 40 room */
  rp->r_pos.x = (COLS - rp->r_max.x) / 2; /* center horizontal */
  rp->r_pos.y = 1;                        /* 2nd line */
  draw_room(rp);                          /* draw the only room */
  i = roll(4, 10);                        /* 10 to 40 items */
  for (; i > 0; i--) {                    /* place all the items */
    ll = new_thing(FALSE, ANYTHING);      /* get something */
    attach(lvl_obj, ll);
    op = OBJPTR(ll);
    setoflg(op, ISPOST); /* object in trading post */
    tp = *rnd_pos(rp);
    op->o_pos = tp;
    mvaddch(tp.y, tp.x, op->o_type);
  }
  trader = 0;
  wmove(cw, 12, 0);
  waddstr(cw, "Welcome to Friendly Fiend's Flea Market\n\r");
  waddstr(cw, "=======================================\n\r");
  waddstr(cw, "$: Prices object that you stand upon.\n\r");
  waddstr(cw, "#: Buys the object that you stand upon.\n\r");
  waddstr(cw, "%: Trades in something in your pack for gold.\n\r");
  trans_line();
}
Exemplo n.º 17
0
/*
 * packweight:
 *	Get the total weight of the hero's pack
 */
int packweight()
{
  struct object *obj;
  struct linked_list *pc;
  int weight, i;

  weight = 0;
  for (pc = pack; pc != NULL; pc = next(pc)) {
    obj = OBJPTR(pc);
    weight += itemweight(obj) * obj->o_count;
  }
  if (weight < 0) /* in case of amulet */
    weight = 0;
  for (i = LEFT; i <= RIGHT; i += 1) {
    obj = cur_ring[i];
    if (obj != NULL) {
      if (obj->o_type == R_HEAVY && o_off(obj, ISBLESS))
        weight += weight / 4;
    }
  }
  return weight;
}
Exemplo n.º 18
0
void
wield(void)
{
    struct linked_list *item;
    struct object *obj, *oweapon;

    oweapon = cur_weapon;

    if (!dropcheck(cur_weapon))
    {
        cur_weapon = oweapon;
        return;
    }

    cur_weapon = oweapon;

    if ((item = get_item("wield", WEAPON)) == NULL)
    {
        after = FALSE;
        return;
    }

    obj = OBJPTR(item);

    if (is_current(obj))
    {
        after = FALSE;
        return;
    }

    wield_ok(&player, obj, TRUE);

    msg("You are now wielding %s.", inv_name(obj, LOWERCASE));

    cur_weapon = obj;
}
Exemplo n.º 19
0
struct object *
pick_weap(struct thing *tp)
{
    int weap_dam = maxdamage(tp->t_stats.s_dmg);
    struct object   *ret_obj = NULL;
    struct linked_list  *pitem;

    if (on(*tp, CANWIELD))
    {
        for (pitem = tp->t_pack; pitem != NULL; pitem = next(pitem))
        {
            struct object   *obj = OBJPTR(pitem);

            if (obj->o_type != WEAPON && !(obj->o_flags&(ISLAUNCHER|ISMISL)) &&
                maxdamage(obj->o_damage) > weap_dam)
            {
                weap_dam = maxdamage(obj->o_damage);
                ret_obj = obj;
            }
        }
    }

    return (ret_obj);
}
Exemplo n.º 20
0
struct linked_list *
get_stack(struct linked_list *item)
{
    struct object   *obj;
    char    buf[2 * LINELEN];
    int i = 0, j;
    struct linked_list  *ll;
    mpos = 0;
    obj = OBJPTR(item);

    ll = obj->next_obj;

    sprintf(buf, "You are standing on top of the following items: ");
    add_line(buf);
    sprintf(buf, "%d) -- %s", i, inv_name(obj, TRUE));
    add_line(buf);

    while (ll)
    {
        i++;
        obj = OBJPTR(ll);
        sprintf(buf, "%d) -- %s", i, inv_name(obj, TRUE));
        add_line(buf);
        ll = next(ll);
    }

    end_line();

    msg("Which one do you want to pick up? [* for all] ");

    switch(get_string(buf, cw))
    {
    case NORM:
        break;
    case QUIT:  /* pick up nothing */
        msg("");
        return (NULL);
    }

    if (buf[0] == '*')
    {
        get_all(item);
        msg("");
        return(NULL);
    }
    else
    {
        i = atoi(buf);

        if (i)
        {
            obj = OBJPTR(item);
            ll = obj->next_obj;
            j = 1;

            while (ll && (j != i))
            {
                ll = next(ll);
                j++;
            }

            if (ll)
            {
                swap_top(item, ll);
                return(ll);
            }
            else
            {
                debug("Got past last item while picking up.");
                return(item);
            }
        }
        else
            return (item);
    }
}
Exemplo n.º 21
0
void
missile(int ydelta, int xdelta, struct linked_list *item, struct thing *tp)
{
    struct object   *obj;
    struct linked_list  *nitem;

    if (item == NULL)   /* Get which thing we are hurling */
        return;

    obj = OBJPTR(item);

    if (!dropcheck(obj) || is_current(obj))
        return;

    /*
     * Get rid of the thing. If it is a non-multiple item object, or if
     * it is the last thing, just drop it. Otherwise, create a new item
     * with a count of one.
    */

    if (obj->o_count < 2)
    {
        if (tp->t_pack == pack)
            rem_pack(obj);
        else
            detach(tp->t_pack, item);
    }
    else
    {
        obj->o_count--;
        nitem = (struct linked_list *) new_item(sizeof *obj);
        obj = OBJPTR(nitem);
        *obj = *(OBJPTR(item));
        obj->o_count = 1;
        item = nitem;
    }

    switch (obj->o_type)
    {
        case ARTIFACT:
            has_artifact &= ~(1 << obj->o_which);
            break;

        case SCROLL:
            if (obj->o_which == S_SCARE && obj->o_flags & ISBLESSED)
                obj->o_flags &= ~ISBLESSED;
            else
                obj->o_flags |= ISCURSED;
    }

    updpack();
    obj->o_pos = do_motion(obj->o_type, ydelta, xdelta, tp);

    /*
     * AHA! Here it has hit something. If it is a wall or a door, or if
     * it misses (combat) the monster, put it on the floor
     */

    if (!hit_monster(obj->o_pos.y, obj->o_pos.x, obj, tp))
    {
        if (obj->o_type == WEAPON && obj->o_which == GRENADE)
        {
            hearmsg("BOOOM!");
            aggravate();

            if (ntraps + 1 < 2 * MAXTRAPS &&
                fallpos(obj->o_pos, &traps[ntraps].tr_pos))
            {
                mvaddch(traps[ntraps].tr_pos.y, traps[ntraps].tr_pos.x,
                    TRAPDOOR);
                traps[ntraps].tr_type = TRAPDOOR;
                traps[ntraps].tr_flags = ISFOUND;
                traps[ntraps].tr_show = TRAPDOOR;
                ntraps++;
                light(&hero);
            }
            discard(item);
        }
        else if (obj->o_flags & ISLOST)
        {
            if (obj->o_type == WEAPON)
                addmsg("The %s", weaps[obj->o_which].w_name);
            else
                addmsg(inv_name(obj, LOWERCASE));

            msg(" vanishes in a puff of greasy smoke.");
            discard(item);
        }
        else
        {
            fall(&player, item, TRUE, TRUE);

            if (obj->o_flags & CANRETURN)
                msg("You have %s.", inv_name(obj, LOWERCASE));
        }
    }
    else if (obj->o_flags & ISOWNED)
    {
        add_pack(item, NOMESSAGE);
        msg("You have %s.", inv_name(obj, LOWERCASE));
    }

    mvwaddch(cw, hero.y, hero.x, PLAYER);
}
Exemplo n.º 22
0
void
fall(struct thing *tp, struct linked_list *item, int pr, int player_owned)
{
    struct object *obj;
    struct room   *rp;
    coord   fpos;

    obj = OBJPTR(item);
    rp = roomin(tp->t_pos);

    if (player_owned && obj->o_flags & CANRETURN)
    {
        add_pack(item, NOMESSAGE);
        msg("You have %s.", inv_name(obj, LOWERCASE));
        return;
    }
    else if (fallpos(obj->o_pos, &fpos))
    {
        if (obj->o_flags & CANBURN && obj->o_type == WEAPON
            && obj->o_which == MOLOTOV
            && ntraps + 1 < 2 * MAXTRAPS)
        {
            mvaddch(fpos.y, fpos.x, FIRETRAP);
            traps[ntraps].tr_type  = FIRETRAP;
            traps[ntraps].tr_flags = ISFOUND;
            traps[ntraps].tr_show  = FIRETRAP;
            traps[ntraps].tr_pos   = fpos;
            ntraps++;

            if (rp != NULL)
                rp->r_flags &= ~ISDARK;
        }
        else
        {
            obj->o_pos = fpos;
            add_obj(item, fpos.y, fpos.x);
        }

        if (rp != NULL &&
            (!(rp->r_flags & ISDARK) ||
             (rp->r_flags & HASFIRE)))
        {
            light(&hero);
            mvwaddch(cw, hero.y, hero.x, PLAYER);
        }
        return;
    }

    /* get here only if there isn't a place to put it */
	
    if (pr)
    {
        if (cansee(obj->o_pos.y, obj->o_pos.x))
        {
            if (obj->o_type == WEAPON)
                addmsg("The %s", weaps[obj->o_which].w_name);
            else
                addmsg(inv_name(obj, LOWERCASE));

            msg(" vanishes as it hits the ground.");
        }
    }
    discard(item);
}
Exemplo n.º 23
0
struct linked_list *
wake_monster(int y, int x)
{
    struct thing    *tp;
    struct linked_list  *it;
    struct room *trp;
    char    *mname;

    if ((it = find_mons(y, x)) == NULL)
    {
        debug("Can't find monster in show.");
        return(NULL);
    }

    tp = THINGPTR(it);

    if ((good_monster(*tp)) || on(player, SUMMONING))
    {
        chase_it(&tp->t_pos, &player);
        turn_off(*tp, ISINVIS);
        turn_off(*tp, CANSURPRISE);
        return(it);
    }

    trp = roomin(tp->t_pos);   /* Current room for monster */
    mname = monsters[tp->t_index].m_name;

    /* Let greedy ones guard gold */

    if (on(*tp, ISGREED) && off(*tp, ISRUN))
        if ((trp != NULL) && (lvl_obj != NULL))
        {
            struct linked_list  *item;
            struct object   *cur;

            for (item = lvl_obj; item != NULL; item = next(item))
            {
                cur = OBJPTR(item);

                if ((cur->o_type == GOLD) &&
                    (roomin(cur->o_pos) == trp))
                {
                    /* Run to the gold */
                    tp->t_horde = cur;
                    turn_on(*tp, ISRUN);
                    turn_off(*tp, ISDISGUISE);
                    tp->t_ischasing = FALSE;
                    /* Make it worth protecting */
                    cur->o_count += roll(2, 3) * GOLDCALC;
                    break;
                }
            }
        }

    /*
     * Every time he sees mean monster, it might start chasing him unique
     * monsters always do
     */

    if (  (on(*tp, ISUNIQUE)) ||
          ( (rnd(100) > 33) &&
            on(*tp, ISMEAN) &&
            off(*tp, ISHELD) &&
            off(*tp, ISRUN) &&
            !is_stealth(&player) &&
            (off(player, ISINVIS) || on(*tp, CANSEE))
          )
       )
    {
        chase_it(&tp->t_pos, &player);
    }

    /* Handle gaze attacks */

    if (on(*tp, ISRUN) && cansee(tp->t_pos.y, tp->t_pos.x) &&
            off(player, ISINVIS))
    {
        if (on(*tp, CANHUH))    /* Confusion */
        {
            if (on(player, CANREFLECT))
            {
                msg("You reflect the bewildering stare of the %s.", mname);

                if (save_throw(VS_MAGIC, tp))
                {
                    msg("The %s is confused!", mname);
                    turn_on(*tp, ISHUH);
                }
                else
                    msg("The %s staggers for a moment.", mname);
            }
            else if (save(VS_MAGIC))
            {
                msg("You feel dizzy for a moment, but it quickly passes.");

                if (rnd(100) < 67)
                    turn_off(*tp, CANHUH);
            }
            else if (off(player, ISCLEAR))
            {
                if (off(player, ISHUH))
                {
                    light_fuse(FUSE_UNCONFUSE, 0, rnd(20) + HUHDURATION, AFTER);
                    msg("The %s's gaze has confused you.", mname);
                    turn_on(player, ISHUH);
                }
                else
                    lengthen_fuse(FUSE_UNCONFUSE, rnd(20) + HUHDURATION);
            }
        }

        if (on(*tp, CANSNORE))      /* Sleep */
        {
            if (on(player, CANREFLECT))
            {
                msg("You reflect the lethargic glance of the %s", mname);

                if (save_throw(VS_PARALYZATION, tp))
                {
                    msg("The %s falls asleep!", mname);
                    tp->t_no_move += SLEEPTIME;
                }
            }
            else if (no_command == 0 && !save(VS_PARALYZATION))
            {
                if (is_wearing(R_ALERT))
                    msg("You feel slightly drowsy for a moment.");
                else
                {
                    msg("The %s's gaze puts you to sleep.", mname);
                    no_command = SLEEPTIME;

                    if (rnd(100) < 50)
                        turn_off(*tp, CANSNORE);
                }
            }
        }

        if (on(*tp, CANFRIGHTEN))   /* Fear */
        {
            turn_off(*tp, CANFRIGHTEN);

            if (on(player, CANREFLECT))
            {
                msg("The %s sees its reflection. ", mname);

                if (save_throw(VS_MAGIC,tp))
                {
                    msg("The %s is terrified by its reflection!", mname);
                    turn_on(*tp, ISFLEE);
                }
            }
            else
            {
                if (!save(VS_WAND) && !(on(player, ISFLEE) &&
                       (player.t_chasee==tp)))
                {
                    if ((player.t_ctype != C_PALADIN) &&
                        off(player, SUPERHERO))
                    {
                        turn_on(player, ISFLEE);
                        player.t_ischasing = FALSE;
                        player.t_chasee    = tp;
                        msg("The sight of the %s terrifies you.", mname);
                    }
                    else
                        msg("My, the %s looks ugly.", mname);
                }
            }
        }

        if (on(*tp, LOOKSLOW))     /* Slow */
        {
            turn_off(*tp, LOOKSLOW);

            if (on(player, CANREFLECT))
            {
                msg("You reflect the mournful glare of the %s.", mname);

                if (save_throw(VS_MAGIC,tp))
                {
                    msg("The %s is slowing down!", mname);
                    turn_on(*tp, ISSLOW);
                }
            }
            else if (is_wearing(R_FREEDOM) || save(VS_MAGIC))
                msg("You feel run-down for a moment.");
            else
            {
                if (on(player, ISHASTE))    /* Already sped up */
                {
                    extinguish_fuse(FUSE_NOHASTE);
                    nohaste(NULL);
                }
                else
                {
                    msg("You feel yourself moving %sslower.",
                     on(player, ISSLOW) ? "even " : "");

                    if (on(player, ISSLOW))
                        lengthen_fuse(FUSE_NOSLOW, rnd(4) + 4);
                    else
                    {
                        turn_on(player, ISSLOW);
                        player.t_turn = TRUE;
                        light_fuse(FUSE_NOSLOW, 0, rnd(4) + 4, AFTER);
                    }
                }
            }
        }

        if (on(*tp, CANBLIND))  /* Blinding */
        {
            turn_off(*tp, CANBLIND);

            if (on(player, CANREFLECT))
            {
                msg("You reflect the blinding stare of the %s.", mname);

                if (save_throw(VS_WAND, tp))
                {
                    msg("The %s is blinded!", mname);
                    turn_on(*tp, ISHUH);
                }
            }
            else if (off(player, ISBLIND))
                if (save(VS_WAND) || is_wearing(R_TRUESEE) || is_wearing(R_SEEINVIS))
                    msg("Your eyes film over for a moment.");
                else
                {
                    msg("The gaze of the %s blinds you.", mname);
                    turn_on(player, ISBLIND);
                    light_fuse(FUSE_SIGHT, 0, rnd(30) + 20, AFTER);
                    look(FALSE);
                }
        }

        if (on(*tp, LOOKSTONE))  /* Stoning */
        {
            turn_off(*tp, LOOKSTONE);

            if (on(player, CANREFLECT))
            {
                msg("You reflect the flinty look of the %s.", mname);

                if (save_throw(VS_PETRIFICATION,tp))
                {
                    msg("The %s suddenly stiffens", mname);
                    tp->t_no_move += STONETIME;
                }
                else
                {
                    msg("The %s is turned to stone!", mname);
                    killed(&player, it, NOMESSAGE, POINTS);
                }
            }
            else
            {
                if (on(player, CANINWALL))
                    msg("The %s cannot focus on you.", mname);
                else
                {
                    msg("The gaze of the %s stiffens your limbs.", mname);

                    if (save(VS_PETRIFICATION))
                        no_command = STONETIME;
                    else if (rnd(100))
                        no_command = STONETIME * 3;
                    else
                    {
                        msg("The gaze of the %s petrifies you.", mname);
                        msg("You are turned to stone!!! --More--");
                        wait_for(' ');
                        death(D_PETRIFY);
                        return(it);
                    }
                }
            }
        }
    }

    /*
     * True Sight sees all Never see ISINWALL or CANSURPRISE See ISSHADOW
     * 80% See ISINVIS with See Invisibilty
     */

    if (off(player, CANTRUESEE) &&
        on(*tp, ISINWALL) || on(*tp, CANSURPRISE) ||
        (on(*tp, ISSHADOW) && rnd(100) < 80) ||
        (on(*tp, ISINVIS) && off(player, CANSEE)))
	{
	    /* 
	    TODO: incomplete - need to finish logic
	    int ch = mvwinch(stdscr, y, x); 
	    */
	}
	

    /* hero might be able to hear or smell monster if he can't see it */

    if ((rnd(player.t_ctype == C_THIEF ? 40 : 200) == 0 ||
            on(player, CANHEAR)) && !cansee(tp->t_pos.y, tp->t_pos.x))
        msg("You hear a %s nearby.", mname);
    else if ((rnd(player.t_ctype == C_THIEF ? 40 : 200) == 0 ||
            on(player, CANSCENT)) && !cansee(tp->t_pos.y, tp->t_pos.x))
        msg("You smell a %s nearby.", mname);

    return(it);
}
Exemplo n.º 24
0
void
new_monster(struct linked_list *item, int type, coord *cp, int max_monster)
{
    struct thing    *tp;
    struct monster  *mp;
    char    *ip, *hitp;
    int   i, min_intel, max_intel;
    int   num_dice, num_sides = 8, num_extra = 0;
    int eff_charisma = pstats.s_charisma;
    int eff_intel = pstats.s_intel;

    attach(mlist, item);
    tp = THINGPTR(item);
    tp->t_index = type;
    tp->t_wasshot = FALSE;
    tp->t_type = monsters[type].m_appear;
    tp->t_ctype = C_MONSTER;
    tp->t_no_move = 0;
    tp->t_doorgoal = -1;
    tp->t_pos = *cp;
    tp->t_oldpos = *cp;
    tp->t_oldch = CCHAR( mvwinch(cw, cp->y, cp->x) );
    mvwaddch(mw, cp->y, cp->x, tp->t_type);
    mp = &monsters[tp->t_index];

    /* Figure out monster's hit points */

    hitp = mp->m_stats.s_hpt;
    num_dice = atoi(hitp);

    if ((hitp = strchr(hitp, 'd')) != NULL)
    {
        num_sides = atoi(++hitp);

        if ((hitp = strchr(hitp, '+')) != NULL)
            num_extra = atoi(++hitp);
    }

    if (max_monster == MAXSTATS)
        tp->t_stats.s_hpt = num_dice * num_sides + num_extra;
    else
        tp->t_stats.s_hpt = roll(num_dice, num_sides) + num_extra;

    tp->t_stats.s_lvl = mp->m_stats.s_lvl;
    tp->t_stats.s_arm = mp->m_stats.s_arm;
    tp->t_stats.s_dmg = mp->m_stats.s_dmg;
    tp->t_stats.s_exp = mp->m_stats.s_exp + mp->m_add_exp * tp->t_stats.s_hpt;
    tp->t_stats.s_str = mp->m_stats.s_str;

    if (max_level > 30)
    {
        tp->t_stats.s_hpt += roll(4, (max_level - 60) * 2);
        tp->t_stats.s_lvl += roll(4, (max_level - 60) / 8);
        tp->t_stats.s_arm -= roll(2, (max_level - 60) / 8);
        tp->t_stats.s_str += roll(2, (max_level - 60) / 12);
        tp->t_stats.s_exp += roll(4, (max_level - 60) * 2) * mp->m_add_exp;
    }

    /*
     * just initailize others values to something reasonable for now
     * maybe someday will *really* put these in monster table
     */

    tp->t_stats.s_wisdom = 8 + rnd(4);
    tp->t_stats.s_dext = 8 + rnd(4);
    tp->t_stats.s_const = 8 + rnd(4);
    tp->t_stats.s_charisma = 8 + rnd(4);

    if (max_level > 45)
        tp->t_stats.s_dext += roll(2, (max_level - 50) / 8);

    /* Set the initial flags */

    for (i = 0; i < 16; i++)
        tp->t_flags[i] = 0;

    for (i = 0; i < 16; i++)
        turn_on(*tp, mp->m_flags[i]);

    /* suprising monsters don't always surprise you */

    if (!max_monster && on(*tp, CANSURPRISE) && rnd(100) < 20)
        turn_off(*tp, CANSURPRISE);

    /* If this monster is unique, genocide it */

    if (on(*tp, ISUNIQUE))
        mp->m_normal = FALSE;

    /* gods automatically get special abilities */

    if (on(*tp, ISGOD))
    {
        turn_on(*tp, CANFRIGHTEN);
        turn_on(*tp, CANCAST);
        turn_on(*tp, CANFLY);
        turn_on(*tp, CANBARGAIN);
        turn_on(*tp, ISLARGE);
        turn_on(*tp, CANTELEPORT);
        turn_on(*tp, CANSPEAK);
        turn_on(*tp, CANDARKEN);
        turn_on(*tp, CANSEE);
        turn_on(*tp, CANLIGHT);
        turn_on(*tp, BMAGICHIT);
    }

    tp->t_turn = TRUE;
    tp->t_pack = NULL;

    /* Figure intelligence */

    min_intel = atoi(mp->m_intel);

    if ((ip = (char *) strchr(mp->m_intel, '-')) == NULL)
        tp->t_stats.s_intel = min_intel;
    else
    {
        max_intel = atoi(++ip);

        if (max_monster)
            tp->t_stats.s_intel = max_intel;
        else
            tp->t_stats.s_intel = min_intel + rnd(max_intel - min_intel);
    }

    tp->t_stats.s_power = (rnd(tp->t_stats.s_lvl / 5) + 1) * tp->t_stats.s_intel;

    tp->maxstats = tp->t_stats; /* structure assignment */

    /* If the monster can shoot, it may have a weapon */

    if (on(*tp, CANSHOOT) && (max_monster || rnd(9) < 6))
    {
        struct linked_list  *thrower_item, *missile_item;
        struct object *thrower, *a_missile;

        thrower_item = new_item(sizeof *thrower);
        thrower = OBJPTR(thrower_item);
        carried_weapon(tp, thrower);

        missile_item = new_item(sizeof *a_missile);
        a_missile = OBJPTR(missile_item);
        carried_weapon(tp, a_missile);

        /* The monster may use a crossbow, sling, footbow, or an arrow */
        /* Take racial preferences into account */

        if ((strcmp(mp->m_name, "elf") == 0) ||
            (strcmp(mp->m_name, "noldor elf") == 0))
        {
            thrower->o_which = BOW;

            if (rnd(5) == 0)
                a_missile->o_which = SILVERARROW;
            else
                a_missile->o_which = ARROW;
        }
        else if ((strcmp(mp->m_name, "dwarf") == 0) ||
                (strcmp(mp->m_name, "kazad dwarf") == 0))
        {
            thrower->o_which = CROSSBOW;
            a_missile->o_which = BOLT;
        }
        else if (on(*tp, ISSMALL))
        {
            switch (rnd(3))
            {
                case 0:
                    thrower->o_which = SLING;
                    a_missile->o_which = BULLET;
                    break;
                default:
                    thrower->o_which = SLING;
                    a_missile->o_which = ROCK;
            }
        }
        else if (on(*tp, ISLARGE))
        {
            switch (rnd(4))
            {
                case 0:
                    thrower->o_which = CROSSBOW;
                    a_missile->o_which = BOLT;
                    break;

                case 1:
                    thrower->o_which = FOOTBOW;
                    a_missile->o_which = FBBOLT;
                    break;

                default:
                    thrower->o_which = BOW;

                    if (rnd(5) == 0)
                        a_missile->o_which = FLAMEARROW;
                    else
                        a_missile->o_which = ARROW;

                    break;
            }
        }
        else
        {
            switch (rnd(6))
            {
                case 1:
                    thrower->o_which = SLING;
                    a_missile->o_which = ROCK;
                    break;

                case 2:
                    thrower->o_which = CROSSBOW;
                    a_missile->o_which = BOLT;
                    break;

                case 3:
                    thrower->o_which = FOOTBOW;
                    a_missile->o_which = FBBOLT;
                    break;

                case 4:
                    thrower->o_which = BOW;
                    a_missile->o_which = ARROW;
                    break;

                default:
                    thrower->o_which = SLING;
                    a_missile->o_which = BULLET;
                    break;
            }
        }

        init_weapon(thrower, thrower->o_which);
        init_weapon(a_missile, a_missile->o_which);

        attach(tp->t_pack, thrower_item);
        attach(tp->t_pack, missile_item);
    }

    /* monsters that wield weapons */

    if (on(*tp, CANWIELD))
    {
        if (max_monster || rnd(3))
        {
            struct linked_list  *wield_item;
            struct object   *wielded;

            wield_item = new_item(sizeof *wielded);
            wielded = OBJPTR(wield_item);
            carried_weapon(tp, wielded);

            i = rnd(CLAYMORE - CLUB) + rnd(2 * tp->t_stats.s_lvl);
            i = min(i, CLAYMORE);
            wielded->o_which = i;
            init_weapon(wielded, wielded->o_which);

            /* Is it too heavy? */

            if (itemweight(wielded) > 8 * tp->t_stats.s_str)
                discard(wield_item);
            else
                attach(tp->t_pack, wield_item);
        }
    }

    if (is_wearing(R_AGGR))
        chase_it(cp, &player);
    else
    {
        turn_off(*tp, ISRUN);

        if (on(*tp, ISFLEE) && (rnd(4) == 0))
            turn_off(*tp, ISFLEE);

        if (rnd(luck) == 0)
            switch (player.t_ctype)
            {
                case C_MAGICIAN:
                case C_ILLUSION:
                    eff_intel = 2 * pstats.s_intel;
                    break;
                case C_DRUID:
                    eff_intel = 2 * pstats.s_intel;
                case C_RANGER:
                    eff_charisma = 2 * pstats.s_charisma;
                    break;
                case C_ASSASIN:
                case C_THIEF:
                case C_NINJA:
                    eff_charisma = pstats.s_charisma / 2;
                    break;
            }

        /* LOWFRIENDLY monsters might be friendly */

        i = roll(1,100);

        if (i == 0 || (on(*tp, LOWFRIENDLY) && i < eff_charisma) ||
            (on(*tp, MEDFRIENDLY) && i < 3 * eff_charisma) ||
            (on(*tp, HIGHFRIENDLY) && i < 5 * eff_charisma))
        {
            turn_on(*tp, ISFRIENDLY);
            turn_off(*tp, ISMEAN);
        }

        i = roll(1,100);

        if (i == 0 || (on(*tp, LOWCAST) && i < eff_intel) ||
            (on(*tp, MEDCAST) && i < 3 * eff_intel) ||
            (on(*tp, HIGHCAST) && i < 5 * eff_intel))
        {
            turn_on(*tp, CANCAST);
        }

        if (on(*tp, ISDISGUISE))
        {
            char    mch = 0;

            if (tp->t_pack != NULL)
                mch = (OBJPTR(tp->t_pack))->o_type;
            else
                switch (rnd(level > arts[0].ar_level ? 10 : 9))
                {
                    case 0: mch = GOLD;     break;
                    case 1: mch = POTION;   break;
                    case 2: mch = SCROLL;   break;
                    case 3: mch = FOOD;     break;
                    case 4: mch = WEAPON;   break;
                    case 5: mch = ARMOR;    break;
                    case 6: mch = RING;     break;
                    case 7: mch = STICK;    break;
                    case 8: mch = monsters[randmonster(NOWANDER, NOGRAB)].m_appear;
                                break;
                    case 9: mch = ARTIFACT; break;
                }

            tp->t_disguise = mch;
        }
    }
}
Exemplo n.º 25
0
void
sell(struct thing *tp)
{
    struct linked_list  *item;
    int i, j, min_worth, nitems, chance, which_item, w;
    char goods;
    struct object   *obj;
    char    buffer[2 * LINELEN];
    char    dbuf[2 * LINELEN];

    struct
    {
        int which;
        int plus1, plus2;
        int count;
        int worth;
        int flags;
        char    *name;
    }
    selection[SELL_ITEMS];

    int effective_purse = ((player.t_ctype == C_PALADIN) ?
                   (9 * purse / 10) : purse);

    min_worth = -1;     /* hope item is never worth less than this */
    item = find_mons(tp->t_pos.y, tp->t_pos.x); /* Get pointer to monster */

    /* Select the items */

    nitems = rnd(6) + 5;

    switch (rnd(6))
    {
        /* Armor */
        case 0:
        case 1:
            goods = ARMOR;
            for (i = 0; i < nitems; i++)
            {
                chance = rnd(100);

                for (j = 0; j < maxarmors; j++)
                    if (chance < armors[j].a_prob)
                        break;

                if (j == maxarmors)
                {
                    debug("Picked a bad armor %d", chance);
                    j = 0;
                }

                selection[i].which = j;
                selection[i].count = 1;

                if (rnd(100) < 40)
                    selection[i].plus1 = rnd(5) + 1;
                else
                    selection[i].plus1 = 0;

                selection[i].name = armors[j].a_name;

                switch (luck)
                {
                    case 0: break;
                    case 1:
                        if (rnd(3) == 0)
                        {
                            selection[i].flags |=  ISCURSED;
                            selection[i].plus1 =  -1 - rnd(5);
                        }
                        break;

                    default:
                        if (rnd(luck))
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 =  -1 - rnd(5);
                        }
                        break;
                }

                /* Calculate price */

                w = armors[j].a_worth;
                w *= (1 + luck + (10 * selection[i].plus1));
                w = (w / 2) + (roll(6, w) / 6);
                selection[i].worth = max(w, 25);

                if (min_worth > selection[i].worth || i == 1)
                    min_worth = selection[i].worth;
            }
            break;

            /* Weapon */
        case 2:
        case 3:
            goods = WEAPON;
            for (i = 0; i < nitems; i++)
            {
                selection[i].which = rnd(maxweapons);
                selection[i].count = 1;

                if (rnd(100) < 35)
                {
                    selection[i].plus1 = rnd(3);
                    selection[i].plus2 = rnd(3);
                }
                else
                {
                    selection[i].plus1 = 0;
                    selection[i].plus2 = 0;
                }

                if (weaps[selection[i].which].w_flags & ISMANY)
                    selection[i].count = rnd(15) + 8;

                selection[i].name = weaps[selection[i].which].w_name;

                switch (luck)
                {
                    case 0: break;
                    case 1:
                        if (rnd(3) == 0)
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 =  -rnd(3);
                            selection[i].plus2 =  -rnd(3);
                        }
                        break;

                    default:
                        if (rnd(luck))
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 =  -rnd(3);
                            selection[i].plus2 =  -rnd(3);
                        }
                        break;
                }

                w = weaps[selection[i].which].w_worth * selection[i].count;
                w *= (1 + luck + (10 * selection[i].plus1 +
                          10 * selection[i].plus2));
                w = (w / 2) + (roll(6, w) / 6);
                selection[i].worth = max(w, 25);

                if (min_worth > selection[i].worth || i == 1)
                    min_worth = selection[i].worth;
            }
            break;

            /* Staff or wand */
        case 4:
            goods = STICK;

            for (i = 0; i < nitems; i++)
            {
                selection[i].which = pick_one(ws_magic, maxsticks);
                selection[i].plus1 = rnd(11) + 5;
                selection[i].count = 1;
                selection[i].name = ws_magic[selection[i].which].mi_name;

                switch (luck)
                {
                    case 0: break;
                    case 1:
                        if (rnd(3) == 0)
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 = 1;
                        }
                        break;

                    default:
                        if (rnd(luck))
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 = 1;
                        }
                }

                w = ws_magic[selection[i].which].mi_worth;
                w += (luck + 1) * 20 * selection[i].plus1;
                w = (w / 2) + (roll(6, w) / 6);
                selection[i].worth = max(w, 25);

                if (min_worth > selection[i].worth || i == 1)
                    min_worth = selection[i].worth;
            }
            break;

            /* Ring */

        case 5:
            goods = RING;
            for (i = 0; i < nitems; i++)
            {
                selection[i].which = pick_one(r_magic, maxrings);
                selection[i].plus1 = rnd(2) + 1;
                selection[i].count = 1;

                if (rnd(100) < r_magic[selection[i].which].mi_bless + 10)
                    selection[i].plus1 += rnd(2) + 1;

                selection[i].name = r_magic[selection[i].which].mi_name;

                switch (luck)
                {
                    case 0: break;
                    case 1:
                        if (rnd(3) == 0)
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 =  -1 - rnd(2);
                        }
                        break;

                    default:
                        if (rnd(luck))
                        {
                            selection[i].flags |= ISCURSED;
                            selection[i].plus1 =  -1 - rnd(2);
                        }
                }

                w = r_magic[selection[i].which].mi_worth;

                switch(selection[i].which)
                {
                    case R_DIGEST:
                        if (selection[i].plus1 > 2)
                            selection[i].plus1 = 2;
                        else if (selection[i].plus1 < 1)
                            selection[i].plus1 = 1;
                    /* fall thru here to other cases */
                    case R_ADDSTR:
                    case R_ADDDAM:
                    case R_PROTECT:
                    case R_ADDHIT:
                    case R_ADDINTEL:
                    case R_ADDWISDOM:
                        if (selection[i].plus1 > 0)
                            w += selection[i].plus1 * 50;
                }

                w *= (1 + luck);
                w = (w / 2) + (roll(6, w) / 6);
                selection[i].worth = max(w, 25);

                if (min_worth > selection[i].worth * selection[i].count)
                    min_worth = selection[i].worth;
            }
    }

    /* See if player can afford an item */

    if (min_worth > effective_purse)
    {
        msg("The %s eyes your small purse and departs.",
            monsters[nummonst].m_name);

        /* Get rid of the monster */

        killed(NULL, item, NOMESSAGE, NOPOINTS);

        return;
    }

    /* Display the goods */

    msg("The %s shows you his wares.", monsters[nummonst].m_name);
    wstandout(cw);
    mvwaddstr(cw, 0, mpos, morestr);
    wstandend(cw);
    wrefresh(cw);
    wait_for(' ');
    msg("");
    clearok(cw, TRUE);
    touchwin(cw);

    wclear(hw);
    touchwin(hw);

    for (i = 0; i < nitems; i++)
    {
        if (selection[i].worth > effective_purse)
            continue;

        wmove(hw, i + 2, 0);
        sprintf(dbuf, "[%c] ", ('a' + i));

        switch(goods)
        {
            case ARMOR:
                strcat(dbuf, "Some ");
                break;
            case WEAPON:
                if (selection[i].count == 1)
                    strcat(dbuf, "A ");
                else
                {
                    sprintf(buffer, "%2d ", selection[i].count);
                    strcat(dbuf, buffer);
                }
                break;

            case STICK:
                strcat(dbuf, "A ");
                strcat(dbuf, ws_type[selection[i].which]);
                strcat(dbuf, " of ");
                break;

            case RING:
                strcat(dbuf, "A ring of ");
                break;
        }

        strcat(dbuf, selection[i].name);

        if (selection[i].count > 1)
            strcat(dbuf, "s");

        sprintf(buffer, "%-50s Price:  %d", dbuf, selection[i].worth);
        waddstr(hw, buffer);
    }

    sprintf(buffer, "Purse:  %d", purse);
    mvwaddstr(hw, nitems + 3, 0, buffer);
    mvwaddstr(hw, 0, 0, "How about one of the following goods? ");
    wrefresh(hw);

    /* Get rid of the monster */

    killed(NULL, item, NOMESSAGE, NOPOINTS);

    which_item = (short) ((readchar() & 0177) - 'a');

    while (which_item < 0 || which_item >= nitems ||
        selection[which_item].worth > effective_purse)
    {
        if (which_item == (short) ESCAPE - (short) 'a')
            return;

        mvwaddstr(hw, 0, 0, "Please enter one of the listed items: ");
        wrefresh(hw);
        which_item = (short) ((readchar() & 0177) - 'a');
    }

    if (purse > selection[which_item].worth)
         purse -= selection[which_item].worth;
    else
         purse = 0L;

    item = spec_item(goods, selection[which_item].which,
          selection[which_item].plus1, selection[which_item].plus2);

    obj = OBJPTR(item);

    if (selection[which_item].count > 1)
    {
        obj->o_count = selection[which_item].count;
        obj->o_group = ++group;
    }

    /* If a stick or ring, let player know the type */

    switch (goods)
    {
        case STICK: know_items[TYP_STICK][selection[which_item].which] = TRUE;
                    break;
        case RING:  know_items[TYP_RING][selection[which_item].which] = TRUE;
                    break;
    }

    if (add_pack(item, MESSAGE) == FALSE)
    {
        obj->o_pos = hero;
        fall(&player, item, TRUE, FALSE);
    }
}
Exemplo n.º 26
0
void
del_pack(struct linked_list *what)
{
    rem_pack(OBJPTR(what));
    discard(what);
}
Exemplo n.º 27
0
/*
 * quaff:
 *	Let the hero drink a potion
 */
int quaff()
{
	struct object *obj;
	struct linked_list *item, *titem;
	struct thing *th;
	int wh;
	char buf[LINLEN];
	bool bless, curse;

	/*
	 * Make certain that it is somethings that we want to drink
	 */
	if ((item = get_item("quaff", POTION)) == NULL)
		return 0;
	obj = OBJPTR(item);
	if (obj->o_type != POTION) {
		msg("That's undrinkable!");
		after = FALSE;
		return 0;
	}
	wh = obj->o_which;
	bless = o_on(obj, ISBLESS);
	curse = o_on(obj, ISCURSED);
	del_pack(item);		/* get rid of it */

	/*
	 * Calculate the effect it has on the poor guy.
	 */
	switch(wh) {
	case P_CONFUSE:
		if (!bless) {
			if (pl_on(ISINVINC))
				msg("You remain level-headed.");
			else {
				chg_abil(WIS,-1,TRUE);		/* confuse his mind */
				if (pl_off(ISHUH)) {
					msg("Wait, what's going on here. Huh? What? Who?");
					if (pl_on(ISHUH))
						lengthen(unconfuse,rnd(8)+HUHDURATION);
					else
						fuse(unconfuse,TRUE,rnd(8)+HUHDURATION);
					player.t_flags |= ISHUH;
				}
			}
			p_know[P_CONFUSE] = TRUE;
		}
	when P_POISON:
		if (!bless) {
			if (pl_off(ISINVINC) && !iswearing(R_SUSTSTR) &&
			  !iswearing(R_SUSAB)) {
				chg_abil(CON,-1,TRUE);		
				chg_abil(STR,-(rnd(3)+1),TRUE);
				msg("You feel very sick now.");
			}
			else
				msg("You feel momentarily sick.");
			p_know[P_POISON] = TRUE;
		}
	when P_HEALING:
		if (!curse) {
			heal_self(4, TRUE);
			msg("You begin to feel better.");
			if (!iswearing(R_SLOW))
				notslow(FALSE);
			sight(FALSE);
			p_know[P_HEALING] = TRUE;
		}
	when P_STRENGTH:
		if (!curse) {
			msg("You feel stronger, now.  What bulging muscles!");
			chg_abil(STR,1,TRUE);
			p_know[P_STRENGTH] = TRUE;
		}
	when P_MFIND:
		/*
		 * Potion of monster detection - find all monsters
		 */
		if (mlist != NULL && !curse) {
			dispmons();
			mpos = 0;
			msg("You begin to sense the presence of monsters--More--");
			p_know[P_MFIND] = TRUE;
			wait_for(cw,' ');
			msg("");		/* clear line */
		}
		else
			msg("You have a strange feeling for a moment, then it passes.");
	when P_TFIND:
		/*
		 * Potion of magic detection.  Show the potions and scrolls
		 */
		if (lvl_obj != NULL && !curse) {
			struct linked_list *mobj;
			struct object *tp;
			bool show;

			show = FALSE;
			wclear(hw);
			for (mobj = lvl_obj; mobj != NULL; mobj = next(mobj)) {
				tp = OBJPTR(mobj);
				if (is_magic(tp)) {
					show = TRUE;
					mvwaddch(hw, tp->o_pos.y, tp->o_pos.x, MAGIC);
				}
			}
			for(titem = mlist; titem != NULL; titem = next(titem)) {
				struct linked_list *pitem;

				th = THINGPTR(titem);
				for(pitem=th->t_pack;pitem!=NULL;pitem=next(pitem)) {
					if (is_magic(ldata(pitem))) {
						show = TRUE;
						mvwaddch(hw,th->t_pos.y, th->t_pos.x, MAGIC);
					}
				}
			}
			if (show) {
				msg("You begin to sense the presence of magic.");
				overlay(hw,cw);
				p_know[P_TFIND] = TRUE;
				break;
			}
		}
		msg("You have a strange feeling for a moment, then it passes.");
	when P_PARALYZE:
		if (!bless) {
			if (pl_on(ISINVINC))
				msg("You feel numb for a moment.");
			else {
				msg("You can't move.");
				player.t_nocmd = HOLDTIME;
			}
			p_know[P_PARALYZE] = TRUE;
		}
	when P_SEEINVIS:
		if (!curse) {
			int invlen = roll(40,20);

			msg("This potion tastes like %s juice.", fruit);
			if (pl_off(CANSEE)) {
				player.t_flags |= CANSEE;
				fuse(unsee, TRUE, invlen);
				light(&hero);
			}
			else
				lengthen(unsee, invlen);
			sight(FALSE);
		}
	when P_RAISE:
		if (!curse) {
			msg("You suddenly feel much more skillful.");
			p_know[P_RAISE] = TRUE;
			chg_abil(DEX,1,TRUE);
			chg_abil(WIS,1,TRUE);
			chg_abil(CON,1,TRUE);
			raise_level();
		}
	when P_XHEAL:
		if (!curse) {
			heal_self(8, TRUE);
			if (rnd(100) < 50)
				chg_abil(CON,1,TRUE);
			msg("You begin to feel much better.");
			p_know[P_XHEAL] = TRUE;
			if (!iswearing(R_SLOW))
				notslow(FALSE);
			unconfuse();
			extinguish(unconfuse);
			sight(FALSE);
		}
	when P_HASTE:
		if (!curse) {
			add_haste(TRUE);
			msg("You feel yourself moving much faster.");
			p_know[P_HASTE] = TRUE;
		}
	when P_INVINC:
		if (!curse) {
			int time = rnd(400) + 350;

			msg("You feel invincible.");
			if (player.t_flags & ISINVINC)
				lengthen(notinvinc,time);
			else
				fuse(notinvinc,TRUE,time);
			player.t_flags |= ISINVINC;
			p_know[P_INVINC] = TRUE;
		}
	when P_SMART:
		if (!curse) {
			msg("You feel more perceptive.");
			p_know[P_SMART] = TRUE;
			chg_abil(WIS,1,TRUE);
		}
	when P_RESTORE:
		if (!curse) {
			msg("Hey, this tastes great. You feel warm all over.");
			him->s_re = max_stats.s_re;
			him->s_ef = max_stats.s_re;
			ringabil();				/* add in rings */
			updpack();				/* update weight */
			p_know[P_RESTORE] = TRUE;
			extinguish(rchg_str);	/* kill restore in from ulodyte */
		}
	when P_BLIND:
		if (!bless) {
			if (pl_on(ISINVINC))
				msg("The light dims for a moment.");
			else {
				chg_abil(WIS,-1,TRUE);
				msg("A cloak of darkness falls around you.");
				if (pl_off(ISBLIND)) {
					player.t_flags |= ISBLIND;
					fuse(sight, TRUE, rnd(400) + 450);
					light(&hero);
				}
			}
			p_know[P_BLIND] = TRUE;
		}
	when P_ETH:
		if (!curse) {
			int ethlen = roll(40,20);

			msg("You feel more vaporous.");
			if (pl_on(ISETHER))
				lengthen(noteth,ethlen);
			else
				fuse(noteth,TRUE,ethlen);
			player.t_flags |= ISETHER;
			p_know[P_ETH] = TRUE;
		}
	when P_NOP:
		msg("This potion tastes extremely dull.");
	when P_DEX:
		if (!curse) {
			chg_abil(DEX,1,TRUE);		/* increase dexterity */
			p_know[P_DEX] = TRUE;
			msg("You feel much more agile.");
		}
	when P_REGEN:
		if (!curse) {
			int reglen = rnd(450) + 450;

			if (pl_on(ISREGEN))
				lengthen(notregen, reglen);
			else
				fuse(notregen, TRUE, reglen);
			player.t_flags |= ISREGEN;
			msg("You feel yourself improved.");
			p_know[P_REGEN] = TRUE;
		}
	when P_DECREP:
	case P_SUPHERO: {
		int howmuch = rnd(3) + 1;

		if (wh == P_DECREP) {
			if (!bless) {
				if (iswearing(R_SUSAB) || pl_on(ISINVINC)) {
					msg("You feel momentarily woozy.");
					howmuch = 0;
				}
				else {
					msg("You feel crippled.");
					howmuch = -howmuch;
					if (!iswearing(R_SUSTSTR))
						chg_abil(STR,howmuch,TRUE);
				}
			}
			else
				howmuch = 0;
		}
		else {			/* potion of superhero */
			if (curse)
				howmuch = 0;
			msg("You feel invigorated.");
			chg_abil(STR,howmuch,TRUE);
		}
		chg_abil(CON,howmuch,TRUE);
		chg_abil(DEX,howmuch,TRUE);
		chg_abil(WIS,howmuch,TRUE);		/* change abilities */
		p_know[wh] = TRUE;
	}
	otherwise:
		msg("What an odd tasting potion!");
		return 0;
	}
	nochange = FALSE;
	if (p_know[wh] && p_guess[wh]) {
		free(p_guess[wh]);
		p_guess[wh] = NULL;
	}
	else if(!p_know[wh] && p_guess[wh] == NULL) {
		strcpy(buf, p_colors[wh]);
		msg(callit);
		if (get_str(buf, cw) == NORM) {
			p_guess[wh] = new(strlen(buf) + 1);
			strcpy(p_guess[wh], buf);
		}
Exemplo n.º 28
0
void
death(int monst)
{
    char **dp = (char **) rip, *killer;
    struct tm   *lt;
    time_t  date;
    char    buf[80];
	int c;

    if (is_wearing(R_RESURRECT) || rnd(wizard ? 3 : 67) == 0)
    {
        int die = TRUE;

        if (resurrect-- == 0)
            msg("You've run out of lives.");
        else if (!save_resurrect(ring_value(R_RESURRECT)))
            msg("Your attempt to return from the grave fails.");
        else
        {
            struct linked_list  *item;
            struct linked_list  *next_item;
            struct object   *obj;
            int rm, flags;
            coord   pos;

            die = FALSE;
            msg("You feel a sudden warmth and then nothingness.");
            teleport();

            if (ring_value(R_RESURRECT) > 1 && rnd(10))
            {
                pstats.s_hpt = 2 * pstats.s_const;
                pstats.s_const = max(pstats.s_const - 1, 3);
            }
            else
            {
                for (item = pack; item != NULL; item = next_item)
                {
                    obj = OBJPTR(item);

                    if (obj->o_flags & ISOWNED || obj->o_flags & ISPROT)
                    {
                        next_item = next(item);
                        continue;
                    }

                    flags = obj->o_flags;
                    obj->o_flags &= ~ISCURSED;
                    dropcheck(obj);
                    obj->o_flags = flags;
                    next_item = next(item);
                    rem_pack(obj);

                    if (obj->o_type == ARTIFACT)
                        has_artifact &= ~(1 << obj->o_which);

                    do
                    {
                        rm = rnd_room();
                        rnd_pos(&rooms[rm], &pos);
                    }
                    while(winat(pos.y, pos.x) != FLOOR);

                    obj->o_pos = pos;
                    add_obj(item, obj->o_pos.y, obj->o_pos.x);
                }

                pstats.s_hpt = pstats.s_const;
                pstats.s_const = max(pstats.s_const - roll(2, 2), 3);
            }

            chg_str(roll(1, 4), TRUE, FALSE);
            pstats.s_lvl = max(pstats.s_lvl, 1);
            no_command += 2 + rnd(4);

            if (on(player, ISHUH))
                lengthen_fuse(FUSE_UNCONFUSE, rnd(8) + HUHDURATION);
            else
                light_fuse(FUSE_UNCONFUSE, 0, rnd(8) + HUHDURATION, AFTER);

            turn_on(player, ISHUH);
            light(&hero);
        }

        if (die)
        {
            wmove(cw, mpos, 0);
            waddstr(cw, morestr);
            wrefresh(cw);
            wait_for(' ');
        }
        else
            return;
    }

    time(&date);
    lt = localtime(&date);
    clear();
    wclear(cw);
    move(8, 0);

    while (*dp)
        printw("%s\n", *dp++);

    mvaddstr(14, 28 - ((int)(strlen(whoami) + 1) / 2), whoami);
    sprintf(buf, "%d+%ld Points", pstats.s_lvl, pstats.s_exp);
    mvaddstr(15, 28 - ((int)(strlen(buf) + 1) / 2), buf);
    killer = killname(monst,buf);
    mvaddstr(17, 28 - ((int)(strlen(killer) + 1) / 2), killer);
    mvaddstr(18, 28, (sprintf(prbuf, "%2d", lt->tm_year), prbuf));
    move(LINES - 1, 0);

    mvaddstr(LINES - 1, 0, retstr);

    while ((c = readcharw(stdscr)) != '\n' && c != '\r')
        continue;
    idenpack();
    wrefresh(cw);
    refresh();

    score(pstats.s_exp, pstats.s_lvl, KILLED, monst);
    byebye();
}
Exemplo n.º 29
0
void
showpack(char *howso)
{
    char    *iname;
    unsigned int worth;
    int cnt, ch, oldpurse;
    struct linked_list  *item;
    struct object   *obj;
    struct linked_list  *bag = NULL;

    cnt = 1;
    clear();
    mvprintw(0, 0, "Contents of your pack %s:\n", howso);
    ch = 0;
    oldpurse = purse;
    purse = 0;

    for (item = pack; item != NULL; item = next(item))
    {
        obj = OBJPTR(item);
        worth = get_worth(obj);
        whatis(item);
        purse += worth;

        if (obj->o_type == ARTIFACT && obj->o_which == TR_PURSE)
            bag = obj->o_bag;

        iname = inv_name(obj, UPPERCASE);
        mvprintw(cnt, 0, "%d) %s\n", ch, iname);
        ch += 1;

        if (++cnt > LINES - 5 && next(item) != NULL)
        {
            cnt = 1;
            mvaddstr(LINES - 1, 0, morestr);
            refresh();
            wait_for(' ');
            clear();
        }
    }

    if (bag != NULL)
    {
        mvaddstr(LINES - 1, 0, morestr);
        refresh();
        wait_for(' ');
        clear();
        cnt = 1;
        ch = 0;

        mvprintw(0, 0, "Contents of the Magic Purse of Yendor %s:\n", howso);

        for (item = bag; item != NULL; item = next(item))
        {
            obj = OBJPTR(item);
            worth = get_worth(obj);
            whatis(item);
            purse += worth;
            mvprintw(cnt, 0, "%d) %s\n", ch, inv_name(obj, UPPERCASE));
            ch += 1;

            if (++cnt > LINES - 5 && next(item) != NULL)
            {
                cnt = 1;
                mvaddstr(LINES - 1, 0, morestr);
                refresh();
                wait_for(' ');
                clear();
            }
        }
    }

    mvprintw(cnt + 1, 0, "Carrying %d gold pieces", oldpurse);
    mvprintw(cnt + 2, 0, "Carrying objects worth %d gold pieces", purse);
    purse += oldpurse;
    refresh();
}
Exemplo n.º 30
0
void
total_winner(void)
{
    struct linked_list  *item;
    struct object   *obj;
    int worth, oldpurse;
    char    c;
    struct linked_list  *bag = NULL;

    clear();
    standout();
    addstr("                                                               \n");
    addstr("  @   @               @   @           @          @@@  @     @  \n");
    addstr("  @   @               @@ @@           @           @   @     @  \n");
    addstr("  @   @  @@@  @   @   @ @ @  @@@   @@@@  @@@      @  @@@    @  \n");
    addstr("   @@@@ @   @ @   @   @   @     @ @   @ @   @     @   @     @  \n");
    addstr("      @ @   @ @   @   @   @  @@@@ @   @ @@@@@     @   @     @  \n");
    addstr("  @   @ @   @ @  @@   @   @ @   @ @   @ @         @   @  @     \n");
    addstr("   @@@   @@@   @@ @   @   @  @@@@  @@@@  @@@     @@@   @@   @  \n");
    addstr("                                                               \n");
    addstr("     Congratulations, you have made it to the light of day!    \n");
    standend();
    addstr("\nYou have joined the elite ranks of those who have \n");
    addstr("escaped the Dungeons of Doom alive.  You journey home \n");
    addstr("and sell all your loot at a great profit.\n");
    addstr("The White Council approves the recommendation of\n");

    if (player.t_ctype == C_FIGHTER)
        addstr("the fighters guild and appoints you Lord Protector\n");
    else if (player.t_ctype == C_ASSASIN)
        addstr("the assassins guild and appoints you Master Murderer\n");
    else if (player.t_ctype == C_NINJA)
        addstr("the ninja guild and appoints you Master of the Wind\n");
    else if (player.t_ctype == C_ILLUSION)
        addstr("the illusionists guild and appoints you Master Wizard\n");
    else if (player.t_ctype == C_MAGICIAN)
        addstr("the magicians guild and appoints you Master Wizard\n");
    else if (player.t_ctype == C_CLERIC)
        addstr("the temple priests and appoints you Master of the Flowers\n");
    else if (player.t_ctype == C_DRUID)
        addstr("the temple priests and appoints you Master of the Flowers\n");
    else if (player.t_ctype == C_RANGER)
        addstr("the rangers guild and appoints you Master Ranger\n");
    else if (player.t_ctype == C_PALADIN)
        addstr("the paladins guild and appoints you Master Paladin\n");
    else if (player.t_ctype == C_THIEF)
    {
        addstr("the thieves guild under protest and appoints you\n");
        addstr("Master of the Highways\n");
    }

    addstr("of the Land Between the Mountains.\n");
    mvaddstr(LINES - 1, 0, spacemsg);
    refresh();
    wait_for(' ');
    clear();
    idenpack();
    oldpurse = purse;
    mvaddstr(0, 0, "   Worth  Item");

    for (c = 'a', item = pack; item != NULL; c++, item = next(item))
    {
        obj = OBJPTR(item);
        worth = get_worth(obj);
        purse += worth;

        if (obj->o_type == ARTIFACT && obj->o_which == TR_PURSE)
            bag = obj->o_bag;

        mvprintw(c - 'a' + 1, 0, "%c) %8d  %s", c,
             worth, inv_name(obj, UPPERCASE));
    }

    if (bag != NULL)
    {
        mvaddstr(LINES - 1, 0, morestr);
        refresh();
        wait_for(' ');
        clear();
        mvprintw(0, 0, "Contents of the Magic Purse of Yendor:\n");

        for (c = 'a', item = bag; item != NULL; c++, item = next(item))
        {
            obj = OBJPTR(item);
            worth = get_worth(obj);
            whatis(item);
            purse += worth;
            mvprintw(c - 'a' + 1, 0, "%c) %8d %s\n", c,
                 worth, inv_name(obj, UPPERCASE));
        }
    }

    mvprintw(c - 'a' + 1, 0, "   %6d  Gold Pieces          ", oldpurse);
    refresh();

    if (has_artifact == 255)
        score(pstats.s_exp, pstats.s_lvl, TOTAL, 0);
    else
        score(pstats.s_exp, pstats.s_lvl, WINNER, 0);

    byebye();
}