Mercurial > hg > early-roguelike
comparison rogue5/pack.c @ 33:f502bf60e6e4
Import Rogue 5.4 from the Roguelike Restoration Project (r1490)
| author | elwin |
|---|---|
| date | Mon, 24 May 2010 20:10:59 +0000 |
| parents | |
| children | e5a15b09ce1d |
comparison
equal
deleted
inserted
replaced
| 32:2dcd75e6a736 | 33:f502bf60e6e4 |
|---|---|
| 1 /* | |
| 2 * Routines to deal with the pack | |
| 3 * | |
| 4 * @(#)pack.c 4.40 (Berkeley) 02/05/99 | |
| 5 * | |
| 6 * Rogue: Exploring the Dungeons of Doom | |
| 7 * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman | |
| 8 * All rights reserved. | |
| 9 * | |
| 10 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 11 */ | |
| 12 | |
| 13 #include <string.h> | |
| 14 #include <curses.h> | |
| 15 #include <ctype.h> | |
| 16 #include "rogue.h" | |
| 17 | |
| 18 /* | |
| 19 * update_mdest: | |
| 20 * Called after picking up an object, before discarding it. | |
| 21 * If this was the object of something's desire, that monster will | |
| 22 * get mad and run at the hero | |
| 23 */ | |
| 24 update_mdest(obj) | |
| 25 register THING *obj; | |
| 26 { | |
| 27 register THING *mp; | |
| 28 | |
| 29 for (mp = mlist; mp != NULL; mp = next(mp)) | |
| 30 if (mp->t_dest == &obj->o_pos) | |
| 31 mp->t_dest = &hero; | |
| 32 } | |
| 33 | |
| 34 /* | |
| 35 * add_pack: | |
| 36 * Pick up an object and add it to the pack. If the argument is | |
| 37 * non-null use it as the linked_list pointer instead of gettting | |
| 38 * it off the ground. | |
| 39 */ | |
| 40 | |
| 41 void | |
| 42 add_pack(THING *obj, int silent) | |
| 43 { | |
| 44 THING *op, *lp; | |
| 45 int from_floor; | |
| 46 int discarded = 0; | |
| 47 | |
| 48 from_floor = FALSE; | |
| 49 if (obj == NULL) | |
| 50 { | |
| 51 if ((obj = find_obj(hero.y, hero.x)) == NULL) | |
| 52 return; | |
| 53 from_floor = TRUE; | |
| 54 } | |
| 55 | |
| 56 /* | |
| 57 * Check for and deal with scare monster scrolls | |
| 58 */ | |
| 59 if (obj->o_type == SCROLL && obj->o_which == S_SCARE) | |
| 60 if (obj->o_flags & ISFOUND) | |
| 61 { | |
| 62 detach(lvl_obj, obj); | |
| 63 mvaddch(hero.y, hero.x, floor_ch()); | |
| 64 chat(hero.y, hero.x) = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR; | |
| 65 update_mdest(obj); | |
| 66 discarded = 1; | |
| 67 discard(obj); | |
| 68 msg("the scroll turns to dust as you pick it up"); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 if (pack == NULL) | |
| 73 { | |
| 74 pack = obj; | |
| 75 obj->o_packch = pack_char(); | |
| 76 inpack++; | |
| 77 } | |
| 78 else | |
| 79 { | |
| 80 lp = NULL; | |
| 81 for (op = pack; op != NULL; op = next(op)) | |
| 82 { | |
| 83 if (op->o_type != obj->o_type) | |
| 84 lp = op; | |
| 85 else | |
| 86 { | |
| 87 while (op->o_type == obj->o_type && op->o_which != obj->o_which) | |
| 88 { | |
| 89 lp = op; | |
| 90 if (next(op) == NULL) | |
| 91 break; | |
| 92 else | |
| 93 op = next(op); | |
| 94 } | |
| 95 if (op->o_type == obj->o_type && op->o_which == obj->o_which) | |
| 96 { | |
| 97 if (ISMULT(op->o_type)) | |
| 98 { | |
| 99 if (!pack_room(from_floor, obj)) | |
| 100 return; | |
| 101 op->o_count++; | |
| 102 dump_it: | |
| 103 update_mdest(obj); | |
| 104 discard(obj); | |
| 105 obj = op; | |
| 106 discarded = 1; | |
| 107 lp = NULL; | |
| 108 goto out; | |
| 109 } | |
| 110 else if (obj->o_group) | |
| 111 { | |
| 112 lp = op; | |
| 113 while (op->o_type == obj->o_type | |
| 114 && op->o_which == obj->o_which | |
| 115 && op->o_group != obj->o_group) | |
| 116 { | |
| 117 lp = op; | |
| 118 if (next(op) == NULL) | |
| 119 break; | |
| 120 else | |
| 121 op = next(op); | |
| 122 } | |
| 123 if (op->o_type == obj->o_type | |
| 124 && op->o_which == obj->o_which | |
| 125 && op->o_group == obj->o_group) | |
| 126 { | |
| 127 op->o_count += obj->o_count; | |
| 128 inpack--; | |
| 129 if (!pack_room(from_floor, obj)) | |
| 130 return; | |
| 131 goto dump_it; | |
| 132 } | |
| 133 } | |
| 134 else | |
| 135 lp = op; | |
| 136 } | |
| 137 out: | |
| 138 break; | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 if (lp != NULL) | |
| 143 { | |
| 144 if (!pack_room(from_floor, obj)) | |
| 145 return; | |
| 146 else | |
| 147 { | |
| 148 obj->o_packch = pack_char(); | |
| 149 next(obj) = next(lp); | |
| 150 prev(obj) = lp; | |
| 151 if (next(lp) != NULL) | |
| 152 prev(next(lp)) = obj; | |
| 153 next(lp) = obj; | |
| 154 } | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 obj->o_flags |= ISFOUND; | |
| 159 | |
| 160 /* | |
| 161 * If this was the object of something's desire, that monster will | |
| 162 * get mad and run at the hero. | |
| 163 */ | |
| 164 if (!discarded) | |
| 165 update_mdest(obj); | |
| 166 | |
| 167 if (obj->o_type == AMULET) | |
| 168 amulet = TRUE; | |
| 169 /* | |
| 170 * Notify the user | |
| 171 */ | |
| 172 if (!silent) | |
| 173 { | |
| 174 if (!terse) | |
| 175 addmsg("you now have "); | |
| 176 msg("%s (%c)", inv_name(obj, !terse), obj->o_packch); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 /* | |
| 181 * pack_room: | |
| 182 * See if there's room in the pack. If not, print out an |
