Mercurial > hg > early-roguelike
comparison arogue5/monsters.c @ 63:0ed67132cf10
Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
| author | elwin | 
|---|---|
| date | Thu, 09 Aug 2012 22:58:48 +0000 | 
| parents | |
| children | 56e748983fa8 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 62:0ef99244acb8 | 63:0ed67132cf10 | 
|---|---|
| 1 /* | |
| 2 * File with various monster functions in it | |
| 3 * | |
| 4 * Advanced Rogue | |
| 5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
| 6 * All rights reserved. | |
| 7 * | |
| 8 * Based on "Rogue: Exploring the Dungeons of Doom" | |
| 9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 10 * All rights reserved. | |
| 11 * | |
| 12 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 13 */ | |
| 14 | |
| 15 #include "curses.h" | |
| 16 #include "rogue.h" | |
| 17 #include <ctype.h> | |
| 18 #include <string.h> | |
| 19 | |
| 20 | |
| 21 /* | |
| 22 * Check_residue takes care of any effect of the monster | |
| 23 */ | |
| 24 check_residue(tp) | |
| 25 register struct thing *tp; | |
| 26 { | |
| 27 /* | |
| 28 * Take care of special abilities | |
| 29 */ | |
| 30 if (on(*tp, DIDHOLD) && (--hold_count == 0)) turn_off(player, ISHELD); | |
| 31 | |
| 32 /* If it has lowered player, give him back a level */ | |
| 33 if (on(*tp, DIDDRAIN)) raise_level(FALSE); | |
| 34 | |
| 35 /* If frightened of this monster, stop */ | |
| 36 if (on(player, ISFLEE) && | |
| 37 player.t_dest == &tp->t_pos) turn_off(player, ISFLEE); | |
| 38 | |
| 39 /* If monster was suffocating player, stop it */ | |
| 40 if (on(*tp, DIDSUFFOCATE)) extinguish(suffocate); | |
| 41 | |
| 42 /* If something with fire, may darken */ | |
| 43 if (on(*tp, HASFIRE)) { | |
| 44 register struct room *rp=roomin(&tp->t_pos); | |
| 45 register struct linked_list *fire_item; | |
| 46 | |
| 47 if (rp) { | |
| 48 for (fire_item = rp->r_fires; fire_item != NULL; | |
| 49 fire_item = next(fire_item)) { | |
| 50 if (THINGPTR(fire_item) == tp) { | |
| 51 detach(rp->r_fires, fire_item); | |
| 52 destroy_item(fire_item); | |
| 53 if (rp->r_fires == NULL) { | |
| 54 rp->r_flags &= ~HASFIRE; | |
| 55 if (cansee(tp->t_pos.y, tp->t_pos.x)) light(&hero); | |
| 56 } | |
| 57 break; | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 /* | |
| 65 * Creat_mons creates the specified monster -- any if 0 | |
| 66 */ | |
| 67 | |
| 68 bool | |
| 69 creat_mons(person, monster, report) | |
| 70 struct thing *person; /* Where to create next to */ | |
| 71 short monster; | |
| 72 bool report; | |
| 73 { | |
| 74 struct linked_list *nitem; | |
| 75 register struct thing *tp; | |
| 76 struct room *rp; | |
| 77 coord *mp; | |
| 78 | |
| 79 if (levtype == POSTLEV) | |
| 80 return(FALSE); | |
| 81 if ((mp = fallpos(&(person->t_pos), FALSE, 2)) != NULL) { | |
| 82 nitem = new_item(sizeof (struct thing)); | |
| 83 new_monster(nitem, | |
| 84 monster == 0 ? randmonster(FALSE, FALSE) | |
| 85 : monster, | |
| 86 mp, | |
| 87 TRUE); | |
| 88 tp = THINGPTR(nitem); | |
| 89 runto(tp, &hero); | |
| 90 tp->t_no_move = 1; /* since it just got here, it is disoriented */ | |
| 91 carry_obj(tp, monsters[tp->t_index].m_carry/2); /* only half chance */ | |
| 92 if (on(*tp, HASFIRE)) { | |
| 93 rp = roomin(&tp->t_pos); | |
| 94 if (rp) { | |
| 95 register struct linked_list *fire_item; | |
| 96 | |
| 97 /* Put the new fellow in the room list */ | |
| 98 fire_item = creat_item(); | |
| 99 ldata(fire_item) = (char *) tp; | |
| 100 attach(rp->r_fires, fire_item); | |
| 101 | |
| 102 rp->r_flags |= HASFIRE; | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 /* | |
| 107 * If we can see this monster, set oldch to ' ' to make light() | |
| 108 * think the creature used to be invisible (ie. not seen here) | |
| 109 */ | |
| 110 if (cansee(tp->t_pos.y, tp->t_pos.x)) tp->t_oldch = ' '; | |
| 111 return(TRUE); | |
| 112 } | |
| 113 if (report) msg("You hear a faint cry of anguish in the distance."); | |
| 114 return(FALSE); | |
| 115 } | |
| 116 | |
| 117 /* | |
| 118 * Genmonsters: | |
| 119 * Generate at least 'least' monsters for this single room level. | |
| 120 * 'Treas' indicates whether this is a "treasure" level. | |
| 121 */ | |
| 122 | |
| 123 void | |
| 124 genmonsters(least, treas) | |
| 125 register int least; | |
| 126 bool treas; | |
| 127 { | |
| 128 reg int i; | |
| 129 reg struct room *rp = &rooms[0]; | |
| 130 reg struct linked_list *item; | |
| 131 reg struct thing *mp; | |
| 132 coord tp; | |
| 133 | |
| 134 for (i = 0; i < level + least; i++) { | |
| 135 if (!treas && rnd(100) < 50) /* put in some little buggers */ | |
| 136 continue; | |
| 137 /* | |
| 138 * Put the monster in | |
| 139 */ | |
| 140 item = new_item(sizeof *mp); | |
| 141 mp = THINGPTR(item); | |
| 142 do { | |
| 143 rnd_pos(rp, &tp); | |
| 144 } until(mvwinch(stdscr, tp.y, tp.x) == FLOOR); | |
| 145 | |
| 146 new_monster(item, randmonster(FALSE, FALSE), &tp, FALSE); | |
| 147 /* | |
| 148 * See if we want to give it a treasure to carry around. | |
| 149 */ | |
| 150 carry_obj(mp, monsters[mp->t_index].m_carry); | |
| 151 | |
| 152 /* Is it going to give us some light? */ | |
| 153 if (on(*mp, HASFIRE)) { | |
| 154 register struct linked_list *fire_item; | |
| 155 | |
| 156 fire_item = creat_item(); | |
| 157 ldata(fire_item) = (char *) mp; | |
| 158 attach(rp->r_fires, fire_item); | |
| 159 rp->r_flags |= HASFIRE; | |
| 160 } | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 /* | |
| 165 * id_monst returns the index of the monster given its letter | |
| 166 */ | |
| 167 | |
| 168 short | |
| 169 id_monst(monster) | |
| 170 register char monster; | |
| 171 { | |
| 172 register short result; | |
| 173 | |
| 174 result = NLEVMONS*vlevel; | |
| 175 if (result > NUMMONST) result = NUMMONST; | |
| 176 | |
| 177 for(; result>0; result--) | |
| 178 if (monsters[result].m_appear == monster) return(result); | |
| 179 for (result=(NLEVMONS*vlevel)+1; result <= NUMMONST; result++) | |
| 180 if (monsters[result].m_appear == monster) return(result); | |
| 181 return(0); | |
| 182 } | |
| 183 | |
| 184 | |
| 185 /* | |
| 186 * new_monster: | |
| 187 * Pick a new monster and add it to the list | |
| 188 */ | |
| 189 | |
| 190 new_monster(item, type, cp, max_monster) | |
| 191 struct linked_list *item; | |
| 192 short type; | |
| 193 register coord *cp; | |
| 194 bool max_monster; | |
| 195 { | |
| 196 register struct thing *tp; | |
| 197 register struct monster *mp; | |
| 198 register char *ip, *hitp; | |
| 199 register int i, min_intel, max_intel; | |
| 200 register int num_dice, num_sides=8, num_extra=0; | |
| 201 | |
| 202 attach(mlist, item); | |
| 203 tp = THINGPTR(item); | |
| 204 tp->t_turn = TRUE; | |
| 205 tp->t_pack = NULL; | |
| 206 tp->t_index = type; | |
| 207 tp->t_wasshot = FALSE; | |
| 208 tp->t_type = monsters[type].m_appear; | |
| 209 tp->t_ctype = C_MONSTER; | |
| 210 tp->t_no_move = 0; | |
| 211 tp->t_doorgoal = 0; | |
| 212 tp->t_quiet = 0; | |
| 213 tp->t_pos = tp->t_oldpos = *cp; | |
| 214 tp->t_oldch = CCHAR( mvwinch(cw, cp->y, cp->x) ); | |
| 215 mvwaddch(mw, cp->y, cp->x, tp->t_type); | |
| 216 mp = &monsters[tp->t_index]; | |
| 217 | |
| 218 /* Figure out monster's hit points */ | |
| 219 hitp = mp->m_stats.s_hpt; | |
| 220 num_dice = atoi(hitp); | |
| 221 if ((hitp = strchr(hitp, 'd')) != NULL) { | |
| 222 num_sides = atoi(++hitp); | |
| 223 if ((hitp = strchr(hitp, '+')) != NULL) | |
| 224 num_extra = atoi(++hitp); | |
| 225 } | |
| 226 | |
| 227 tp->t_stats.s_lvl = mp->m_stats.s_lvl; | |
| 228 tp->t_stats.s_arm = mp->m_stats.s_arm; | |
| 229 strncpy(tp->t_stats.s_dmg,mp->m_stats.s_dmg,sizeof(tp->t_stats.s_dmg)); | |
| 230 tp->t_stats.s_str = mp->m_stats.s_str; | |
| 231 if (vlevel > HARDER) { /* the deeper, the meaner we get */ | |
| 232 tp->t_stats.s_lvl += (vlevel - HARDER); | |
| 233 num_dice += (vlevel - HARDER)/2; | |
| 234 } | |
| 235 if (max_monster) | |
| 236 tp->t_stats.s_hpt = num_dice * num_sides + num_extra; | |
| 237 else | |
| 238 tp->t_stats.s_hpt = roll(num_dice, num_sides) + num_extra; | |
| 239 tp->t_stats.s_exp = mp->m_stats.s_exp + mp->m_add_exp*tp->t_stats.s_hpt; | |
| 240 | |
| 241 /* | |
| 242 * just initailize others values to something reasonable for now | |
| 243 * maybe someday will *really* put these in monster table | |
| 244 */ | |
| 245 tp->t_stats.s_wisdom = 8 + rnd(4); | |
| 246 tp->t_stats.s_dext = 8 + rnd(4); | |
| 247 tp->t_stats.s_const = 8 + rnd(4); | |
| 248 tp->t_stats.s_charisma = 8 + rnd(4); | |
| 249 | |
| 250 /* Set the initial flags */ | |
| 251 for (i=0; i<16; i++) tp->t_flags[i] = 0; | |
| 252 for (i=0; i<MAXFLAGS; i++) | |
| 253 turn_on(*tp, mp->m_flags[i]); | |
| 254 | |
| 255 /* suprising monsters don't always surprise you */ | |
| 256 if (!max_monster && on(*tp, CANSURPRISE) && | |
| 257 off(*tp, ISUNIQUE) && rnd(100) < 20) | |
| 258 turn_off(*tp, CANSURPRISE); | |
| 259 | |
| 260 /* If this monster is unique, gen it */ | |
| 261 if (on(*tp, ISUNIQUE)) mp->m_normal = FALSE; | |
| 262 | |
| 263 /* | |
| 264 * if is it the quartermaster, then compute his level and exp pts | |
| 265 * based on the level. This will make it fair when thieves try to | |
| 266 * steal and give them reasonable experience if they succeed. | |
| 267 */ | |
| 268 if (on(*tp, CANSELL)) { | |
| 269 tp->t_stats.s_exp = vlevel * 100; | |
| 270 tp->t_stats.s_lvl = vlevel/2 + 1; | |
| 271 attach(tp->t_pack, new_thing(ALL)); | |
| 272 } | |
| 273 | |
| 274 /* Normally scared monsters have a chance to not be scared */ | |
| 275 if (on(*tp, ISFLEE) && (rnd(4) == 0)) turn_off(*tp, ISFLEE); | |
| 276 | |
| 277 /* Figure intelligence */ | |
| 278 min_intel = atoi(mp->m_intel); | |
| 279 if ((ip = (char *) strchr(mp->m_intel, '-')) == NULL) | |
| 280 tp->t_stats.s_intel = min_intel; | |
| 281 else { | |
| 282 max_intel = atoi(++ip); | |
| 283 if (max_monster) | |
| 284 tp->t_stats.s_intel = max_intel; | |
| 285 else | |
| 286 tp->t_stats.s_intel = min_intel + rnd(max_intel - min_intel); | |
| 287 } | |
| 288 if (vlevel > HARDER) | |
| 289 tp->t_stats.s_intel += ((vlevel - HARDER)/2); | |
| 290 tp->maxstats = tp->t_stats; | |
| 291 | |
| 292 /* If the monster can shoot, it may have a weapon */ | |
| 293 if (on(*tp, CANSHOOT) && ((rnd(100) < (22 + vlevel)) || max_monster)) { | |
| 294 struct linked_list *item1; | |
| 295 register struct object *cur, *cur1; | |
| 296 | |
| 297 item = new_item(sizeof *cur); | |
| 298 item1 = new_item(sizeof *cur1); | |
| 299 cur = OBJPTR(item); | |
| 300 cur1 = OBJPTR(item1); | |
| 301 cur->o_hplus = (rnd(4) < 3) ? 0 | |
| 302 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
| 303 cur->o_dplus = (rnd(4) < 3) ? 0 | |
| 304 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
| 305 cur1->o_hplus = (rnd(4) < 3) ? 0 | |
| 306 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
| 307 cur1->o_dplus = (rnd(4) < 3) ? 0 | |
| 308 : (rnd(3) + 1) * ((rnd(3) < 2) ? 1 : -1); | |
| 309 strcpy(cur->o_damage,"0d0"); | |
| 310 strcpy(cur->o_hurldmg,"0d0"); | |
| 311 strcpy(cur1->o_damage,"0d0"); | |
| 312 strcpy(cur1->o_hurldmg,"0d0"); | |
| 313 cur->o_ac = cur1->o_ac = 11; | |
| 314 cur->o_count = cur1->o_count = 1; | |
| 315 cur->o_group = cur1->o_group = 0; | |
| 316 cur->contents = cur1->contents = NULL; | |
| 317 if ((cur->o_hplus <= 0) && (cur->o_dplus <= 0)) cur->o_flags = ISCURSED; | |
| 318 if ((cur1->o_hplus <= 0) && (cur1->o_dplus <= 0)) | |
| 319 cur1->o_flags = ISCURSED; | |
| 320 cur->o_flags = cur1->o_flags = 0; | |
| 321 cur->o_type = cur1->o_type = WEAPON; | |
| 322 cur->o_mark[0] = cur1->o_mark[0] = '\0'; | |
| 323 | |
| 324 /* The monster may use a crossbow, sling, or an arrow */ | |
| 325 i = rnd(100); | |
| 326 if (i < 10) { | |
| 327 cur->o_which = CROSSBOW; | |
| 328 cur1->o_which = BOLT; | |
| 329 init_weapon(cur, CROSSBOW); | |
| 330 init_weapon(cur1, BOLT); | |
| 331 } | |
| 332 else if (i < 70) { | |
| 333 cur->o_which = BOW; | |
| 334 cur1->o_which = ARROW; | |
| 335 init_weapon(cur, BOW); | |
| 336 init_weapon(cur1, ARROW); | |
| 337 } | |
| 338 else { | |
| 339 cur->o_which = SLING; | |
| 340 cur1->o_which = ROCK; | |
| 341 init_weapon(cur, SLING); | |
| 342 init_weapon(cur1, ROCK); | |
| 343 } | |
| 344 | |
| 345 attach(tp->t_pack, item); | |
| 346 attach(tp->t_pack, item1); | |
| 347 } | |
| 348 | |
| 349 | |
| 350 if (ISWEARING(R_AGGR)) | |
| 351 runto(tp, &hero); | |
| 352 if (on(*tp, ISDISGUISE)) | |
| 353 { | |
| 354 char mch = 0; | |
| 355 | |
| 356 if (tp->t_pack != NULL) | |
| 357 mch = (OBJPTR(tp->t_pack))->o_type; | |
| 358 else | |
| 359 switch (rnd(10)) { | |
| 360 case 0: mch = GOLD; | |
| 361 when 1: mch = POTION; | |
| 362 when 2: mch = SCROLL; | |
| 363 when 3: mch = FOOD; | |
| 364 when 4: mch = WEAPON; | |
| 365 when 5: mch = ARMOR; | |
| 366 when 6: mch = RING; | |
| 367 when 7: mch = STICK; | |
| 368 when 8: mch = monsters[randmonster(FALSE, FALSE)].m_appear; | |
| 369 when 9: mch = MM; | |
| 370 } | |
