annotate arogue5/pack.c @ 93:8f7c082fde46

Don't set DESTDIR via configure. DESTDIR ought to be set via option passed to 'make install'.
author John "Elwin" Edwards
date Mon, 26 Aug 2013 19:58:44 -0700
parents 0ed67132cf10
children 56e748983fa8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
1 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
2 * Routines to deal with the pack
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
3 *
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
4 * Advanced Rogue
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
6 * All rights reserved.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
7 *
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
8 * Based on "Rogue: Exploring the Dungeons of Doom"
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
10 * All rights reserved.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
11 *
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
12 * See the file LICENSE.TXT for full copyright and licensing information.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
13 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
14
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
15 #include "curses.h"
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
16 #include <ctype.h>
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
17 #include "rogue.h"
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
18
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
19 char outstring[512]; /* ridiculously long string for use with msg */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
20
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
21 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
22 * add_pack:
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
23 * Pick up an object and add it to the pack. If the argument is non-null
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
24 * use it as the linked_list pointer instead of gettting it off the ground.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
25 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
26 bool
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
27 add_pack(item, silent, packret)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
28 register struct linked_list *item, **packret;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
29 bool silent;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
30 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
31 register struct linked_list *ip, *lp = NULL, *ap;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
32 register struct object *obj, *op = NULL;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
33 register bool exact, from_floor;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
34
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
35 if (packret != NULL)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
36 *packret = NULL;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
37
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
38 if (item == NULL)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
39 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
40 from_floor = TRUE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
41 if ((item = find_obj(hero.y, hero.x)) == NULL)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
42 return(FALSE);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
43 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
44 else
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
45 from_floor = FALSE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
46 obj = OBJPTR(item);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
47 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
48 * If it is gold, just add its value to rogue's purse and get rid
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
49 * of it.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
50 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
51 if (obj->o_type == GOLD) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
52 register struct linked_list *mitem;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
53 register struct thing *tp;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
54
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
55 if (!silent) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
56 if (!terse) addmsg("You found ");
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
57 msg("%d gold pieces.", obj->o_count);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
58 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
59
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
60 /* First make sure no greedy monster is after this gold.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
61 * If so, make the monster run after the rogue instead.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
62 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
63 for (mitem = mlist; mitem != NULL; mitem = next(mitem)) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
64 tp = THINGPTR(mitem);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
65 if (tp->t_dest == &obj->o_pos) tp->t_dest = &hero;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
66 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
67
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
68 purse += obj->o_count;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
69 if (from_floor) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
70 detach(lvl_obj, item);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
71 if ((ap = find_obj(hero.y, hero.x)) == NULL)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
72 mvaddch(hero.y,hero.x,(roomin(&hero)==NULL ? PASSAGE : FLOOR));
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
73 else
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
74 mvaddch(hero.y,hero.x,(OBJPTR(ap))->o_type);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
75 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
76 o_discard(item);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
77 return(TRUE);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
78 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
79
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
80 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
81 * see if he can carry any more weight
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
82 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
83 if (itemweight(obj) + pstats.s_pack > pstats.s_carry) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
84 msg("Too much for you to carry.");
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
85 return FALSE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
86 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
87 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
88 * Link it into the pack. Search the pack for a object of similar type
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
89 * if there isn't one, stuff it at the beginning, if there is, look for one
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
90 * that is exactly the same and just increment the count if there is.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
91 * it that. Food is always put at the beginning for ease of access, but
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
92 * is not ordered so that you can't tell good food from bad. First check
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
93 * to see if there is something in thr same group and if there is then
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
94 * increment the count.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
95 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
96 if (obj->o_group)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
97 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
98 for (ip = pack; ip != NULL; ip = next(ip))
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
99 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
100 op = OBJPTR(ip);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
101 if (op->o_group == obj->o_group)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
102 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
103 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
104 * Put it in the pack and notify the user
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
105 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin