Mercurial > hg > early-roguelike
comparison rogue4/pack.c @ 12:9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
| author | edwarj4 |
|---|---|
| date | Sat, 24 Oct 2009 16:52:52 +0000 |
| parents | |
| children | 1b73a8641b37 |
comparison
equal
deleted
inserted
replaced
| 11:949d558c2162 | 12:9535a08ddc39 |
|---|---|
| 1 /* | |
| 2 * Routines to deal with the pack | |
| 3 * | |
| 4 * @(#)pack.c 4.15 (Berkeley) 4/6/82 | |
| 5 * | |
| 6 * Rogue: Exploring the Dungeons of Doom | |
| 7 * Copyright (C) 1980, 1981, 1982 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 <curses.h> | |
| 14 #include <ctype.h> | |
| 15 #include "rogue.h" | |
| 16 | |
| 17 /* | |
| 18 * update_mdest: | |
| 19 * Called after picking up an object, before discarding it. | |
| 20 * If this was the object of something's desire, that monster will | |
| 21 * get mad and run at the hero | |
| 22 */ | |
| 23 update_mdest(obj) | |
| 24 register THING *obj; | |
| 25 { | |
| 26 register THING *mp; | |
| 27 | |
| 28 for (mp = mlist; mp != NULL; mp = next(mp)) | |
| 29 if (mp->t_dest == &obj->o_pos) | |
| 30 mp->t_dest = &hero; | |
| 31 } | |
| 32 | |
| 33 /* | |
| 34 * add_pack: | |
| 35 * Pick up an object and add it to the pack. If the argument is | |
| 36 * non-null use it as the linked_list pointer instead of gettting | |
| 37 * it off the ground. | |
| 38 */ | |
| 39 add_pack(obj, silent) | |
| 40 register THING *obj; | |
| 41 bool silent; | |
| 42 { | |
| 43 register THING *op, *lp = NULL; | |
| 44 register bool exact, from_floor; | |
| 45 register char floor; | |
| 46 int discarded = 0; | |
| 47 | |
| 48 if (obj == NULL) | |
| 49 { | |
| 50 from_floor = TRUE; | |
| 51 if ((obj = find_obj(hero.y, hero.x)) == NULL) | |
| 52 return; | |
| 53 } | |
| 54 else | |
| 55 from_floor = FALSE; | |
| 56 /* | |
| 57 * Link it into the pack. Search the pack for a object of similar type | |
| 58 * if there isn't one, stuff it at the beginning, if there is, look for one | |
| 59 * that is exactly the same and just increment the count if there is. | |
| 60 * it that. Food is always put at the beginning for ease of access, but | |
| 61 * is not ordered so that you can't tell good food from bad. First check | |
| 62 * to see if there is something in thr same group and if there is then | |
| 63 * increment the count. | |
| 64 */ | |
| 65 /* floor = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR; */ | |
| 66 if (proom) floor = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR; | |
| 67 else floor = FLOOR; | |
| 68 if (obj->o_group) | |
| 69 { | |
| 70 for (op = pack; op != NULL; op = next(op)) | |
| 71 { | |
| 72 if (op->o_group == obj->o_group) | |
| 73 { | |
| 74 /* | |
| 75 * Put it in the pack and notify the user | |
| 76 */ | |
| 77 op->o_count++; | |
| 78 if (from_floor) | |
| 79 { | |
| 80 detach(lvl_obj, obj); | |
| 81 mvaddch(hero.y, hero.x, floor); | |
| 82 chat(hero.y, hero.x) = floor; | |
| 83 } | |
| 84 update_mdest(obj); | |
| 85 discard(obj); | |
| 86 obj = op; | |
| 87 discarded = 1; | |
| 88 goto picked_up; | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 /* | |
| 93 * Check if there is room | |
| 94 */ | |
| 95 if (inpack == MAXPACK-1) | |
| 96 { | |
| 97 msg("you can't carry anything else"); | |
| 98 return; | |
| 99 } | |
| 100 /* | |
| 101 * Check for and deal with scare monster scrolls | |
| 102 */ | |
| 103 if (obj->o_type == SCROLL && obj->o_which == S_SCARE) | |
| 104 if (obj->o_flags & ISFOUND) | |
| 105 { | |
| 106 detach(lvl_obj, obj); | |
| 107 mvaddch(hero.y, hero.x, floor); | |
| 108 chat(hero.y, hero.x) = floor; | |
| 109 msg("the scroll turns to dust as you pick it up"); | |
| 110 return; | |
| 111 } | |
| 112 else | |
| 113 obj->o_flags |= ISFOUND; | |
| 114 | |
| 115 inpack++; | |
| 116 if (from_floor) | |
| 117 { | |
| 118 detach(lvl_obj, obj); | |
| 119 mvaddch(hero.y, hero.x, floor); | |
| 120 chat(hero.y, hero.x) = floor; | |
| 121 } | |
| 122 /* | |
| 123 * Search for an object of the same type | |
| 124 */ | |
| 125 exact = FALSE; | |
| 126 for (op = pack; op != NULL; op = next(op)) | |
| 127 if (obj->o_type == op->o_type) | |
| 128 break; | |
| 129 if (op == NULL) | |
| 130 { | |
| 131 /* | |
| 132 * Put it at the end of the pack since it is a new type | |
| 133 */ | |
| 134 for (op = pack; op != NULL; op = next(op)) | |
| 135 { | |
| 136 if (op->o_type != FOOD) | |
| 137 break; | |
| 138 lp = op; | |
| 139 } | |
| 140 } | |
| 141 else | |
| 142 { | |
| 143 /* | |
| 144 * Search for an object which is exactly the same | |
| 145 */ | |
| 146 while (op->o_type == obj->o_type) | |
| 147 { | |
| 148 if (op->o_which == obj->o_which) | |
| 149 { | |
| 150 exact = TRUE; | |
| 151 break; | |
| 152 } | |
| 153 lp = op; | |
| 154 if ((op = next(op)) == NULL) | |
| 155 break; | |
| 156 } | |
| 157 } | |
| 158 if (op == NULL) | |
| 159 { | |
| 160 /* | |
| 161 * Didn't find an exact match, just stick it here | |
| 162 */ | |
| 163 if (pack == NULL) | |
| 164 pack = obj; | |
| 165 else | |
| 166 { | |
| 167 lp->l_next = obj; | |
| 168 obj->l_prev = lp; | |
| 169 obj->l_next = NULL; | |
| 170 } | |
| 171 } | |
| 172 else | |
| 173 { | |
| 174 /* | |
| 175 * If we found an exact match. If it is a potion, food, or a | |
| 176 * scroll, increase the count, otherwise put it with its clones. | |
| 177 */ | |
| 178 if (exact && ISMULT(obj->o_type)) | |
| 179 { | |
