Annotation of early-roguelike/urogue/daemon.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: daemon.c - functions for dealing with things that happen in the future
! 3:
! 4: UltraRogue: The Ultimate Adventure in the Dungeons of Doom
! 5: Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong
! 6: All rights reserved.
! 7:
! 8: Based on "Advanced Rogue"
! 9: Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka
! 10: All rights reserved.
! 11:
! 12: Based on "Rogue: Exploring the Dungeons of Doom"
! 13: Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
! 14: All rights reserved.
! 15:
! 16: See the file LICENSE.TXT for full copyright and licensing information.
! 17: */
! 18:
! 19: /*
! 20: Needs to be rewritten again to work on a per creature basis.
! 21: Either each monster will have a list of effect, or each
! 22: fuse will take a creature pointer and multiple entries
! 23: for each fuse will be allowed. I tend to want to attach
! 24: the effects to the creature.
! 25: */
! 26:
! 27: #include "rogue.h"
! 28:
! 29: int demoncnt;
! 30:
! 31: struct daemon daemons[DAEMON_MAX] =
! 32: {
! 33: { DAEMON_NULL, NULL },
! 34: { DAEMON_DOCTOR, doctor },
! 35: { DAEMON_ROLLWAND, rollwand },
! 36: { DAEMON_STOMACH, stomach },
! 37: { DAEMON_RUNNERS, runners }
! 38: };
! 39:
! 40: struct fuse fuses[FUSE_MAX] =
! 41: {
! 42: { FUSE_NULL, NULL },
! 43: { FUSE_SWANDER, swander },
! 44: { FUSE_UNCONFUSE, unconfuse },
! 45: { FUSE_UNSCENT, unscent },
! 46: { FUSE_SCENT, scent },
! 47: { FUSE_UNHEAR, unhear },
! 48: { FUSE_HEAR, hear },
! 49: { FUSE_UNSEE, unsee },
! 50: { FUSE_UNSTINK, unstink },
! 51: { FUSE_UNCLRHEAD, unclrhead },
! 52: { FUSE_UNPHASE, unphase },
! 53: { FUSE_SIGHT, sight },
! 54: { FUSE_RES_STRENGTH, res_strength },
! 55: { FUSE_NOHASTE, nohaste },
! 56: { FUSE_NOSLOW, noslow },
! 57: { FUSE_SUFFOCATE, suffocate },
! 58: { FUSE_CURE_DISEASE, cure_disease },
! 59: { FUSE_UNITCH, un_itch },
! 60: { FUSE_APPEAR, appear },
! 61: { FUSE_UNELECTRIFY, unelectrify },
! 62: { FUSE_UNBHERO, unbhero },
! 63: { FUSE_UNSHERO, unshero },
! 64: { FUSE_UNXRAY, NULL },
! 65: { FUSE_UNDISGUISE, undisguise },
! 66: { FUSE_SHERO, shero },
! 67: { FUSE_WGHTCHK, wghtchk },
! 68: { FUSE_UNSUMMON, unsummon },
! 69: { FUSE_UNGAZE, ungaze },
! 70: { FUSE_UNCOLD, uncold },
! 71: { FUSE_UNHOT, unhot },
! 72: { FUSE_UNFLY, unfly },
! 73: { FUSE_UNBREATHE, unbreathe },
! 74: { FUSE_UNREGEN, unregen },
! 75: { FUSE_UNSUPEREAT, unsupereat },
! 76: { FUSE_UNSHIELD, unshield },
! 77: { FUSE_UNMSHIELD, unmshield },
! 78: { FUSE_UNTRUESEE, untruesee }
! 79: };
! 80:
! 81: /*
! 82: d_slot()
! 83: Find an empty slot in the daemon/fuse list
! 84: */
! 85:
! 86: struct delayed_action *
! 87: d_slot(void)
! 88: {
! 89: int i;
! 90: struct delayed_action *dev;
! 91:
! 92: for (i = 0, dev = d_list; i < MAXDAEMONS; i++, dev++)
! 93: if (dev->d_type == EMPTY)
! 94: return(dev);
! 95:
! 96: return(NULL);
! 97: }
! 98:
! 99:
! 100: /*
! 101: find_slot()
! 102: Find a particular slot in the table
! 103: */
! 104:
! 105: struct delayed_action *
! 106: find_slot(int type, int id)
! 107: {
! 108: int i;
! 109: struct delayed_action *dev;
! 110:
! 111: for (i = 0, dev = d_list; i < MAXDAEMONS; i++, dev++)
! 112: if ( (dev->d_type == type) && (id == dev->d_id) )
! 113: return(dev);
! 114:
! 115: return(NULL);
! 116: }
! 117:
! 118:
! 119: /*
! 120: daemon()
! 121: Start a daemon, takes a function.
! 122: */
! 123:
! 124: void
! 125: start_daemon(int id, void *arg, int whendo)
! 126: {
! 127: struct delayed_action *dev;
! 128:
! 129: dev = d_slot();
! 130:
! 131: if (dev != NULL)
! 132: {
! 133: dev->d_type = DAEMON;
! 134: dev->d_when = whendo;
! 135: dev->d_id = id;
! 136: dev->d_arg = arg;
! 137: dev->d_time = 1;
! 138: demoncnt += 1; /* update count */
! 139: }
! 140: }
! 141:
! 142:
! 143: /*
! 144: kill_daemon()
! 145: Remove a daemon from the list
! 146: */
! 147:
! 148: void
! 149: kill_daemon(int id)
! 150: {
! 151: struct delayed_action *dev;
! 152:
! 153: if ((dev = find_slot(DAEMON, id)) == NULL)
! 154: return;
! 155:
! 156: /* Take it out of the list */
! 157:
! 158: dev->d_type = EMPTY;
! 159: demoncnt -= 1; /* update count */
! 160:
! 161: return;
! 162: }
! 163:
! 164:
! 165: /*
! 166: do_daemons()
! 167: Run all the daemons that are active with the current flag,
! 168: passing the argument to the function.
! 169: */
! 170:
! 171: void
! 172: do_daemons(int now)
! 173: {
! 174: struct delayed_action *dev;
! 175:
! 176: /* Loop through the devil list */
! 177:
! 178: for (dev = d_list; dev < &d_list[MAXDAEMONS]; dev++)
! 179: /* Executing each one, giving it the proper arguments */
! 180: if ( (dev->d_when == now) && (dev->d_type == DAEMON))
! 181: {
! 182: if ((dev->d_id < 1) || (dev->d_id >= DAEMON_MAX))
! 183: printf("Bad daemon id %d\n", dev->d_id);
! 184: else if (daemons[dev->d_id].func == NULL)
! 185: printf("No action for daemon %d!!!\n", dev->d_id);
! 186: else
! 187: {
! 188: daemon_arg arg;
! 189:
! 190: arg.varg = dev->d_arg;
! 191: daemons[dev->d_id].func(&arg);
! 192: }
! 193: }
! 194:
! 195: }
! 196:
! 197:
! 198: /*
! 199: fuse()
! 200: Start a fuse to go off in a certain number of turns
! 201: */
! 202:
! 203: void
! 204: light_fuse(int id, void *arg, int time, int whendo)
! 205: {
! 206: struct delayed_action *wire;
! 207:
! 208: wire = d_slot();
! 209:
! 210: if (wire != NULL)
! 211: {
! 212: wire->d_type = FUSE;
! 213: wire->d_when = whendo;
! 214: wire->d_id = id;
! 215: wire->d_arg = arg;
! 216: wire->d_time = time;
! 217: demoncnt += 1; /* update count */
! 218: }
! 219: }
! 220:
! 221:
! 222: /*
! 223: lengthen()
! 224: Increase the time until a fuse goes off
! 225: */
! 226:
! 227: void
! 228: lengthen_fuse(int id, int xtime)
! 229: {
! 230: struct delayed_action *wire;
! 231:
! 232: if ((wire = find_slot(FUSE,id)) == NULL)
! 233: return;
! 234:
! 235: wire->d_time += xtime;
! 236:
! 237: return;
! 238: }
! 239:
! 240:
! 241: /*
! 242: extinguish()
! 243: Put out a fuse
! 244: */
! 245:
! 246: void
! 247: extinguish_fuse(int id)
! 248: {
! 249: struct delayed_action *wire;
! 250:
! 251: if ((wire = find_slot(FUSE,id)) == NULL)
! 252: return;
! 253:
! 254: wire->d_type = EMPTY;
! 255: demoncnt -= 1;
! 256:
! 257: return;
! 258: }
! 259:
! 260:
! 261: /*
! 262: do_fuses()
! 263: Decrement counters and start needed fuses
! 264: */
! 265:
! 266: void
! 267: do_fuses(int now)
! 268: {
! 269: struct delayed_action *wire;
! 270:
! 271: /* Step though the list */
! 272:
! 273: for (wire = d_list; wire < &d_list[MAXDAEMONS]; wire++)
! 274: {
! 275: /*
! 276: * Decrementing counters and starting things we want. We
! 277: * also need to remove the fuse from the list once it has
! 278: * gone off.
! 279: */
! 280:
! 281: if( (wire->d_type == FUSE) && (wire->d_when == now) )
! 282: {
! 283: if (--wire->d_time <= 0)
! 284: {
! 285: if (wire->d_id < 0 || wire->d_id >= FUSE_MAX)
! 286: printf("Bad fuse id %d\n", wire->d_id);
! 287: else if (fuses[wire->d_id].func == NULL)
! 288: printf("No action for fuse %d!\n", wire->d_id);
! 289: else
! 290: {
! 291: fuse_arg arg;
! 292:
! 293: arg.varg = wire->d_arg;
! 294: fuses[wire->d_id].func(&arg);
! 295: }
! 296: wire->d_type = EMPTY;
! 297: demoncnt -= 1;
! 298: }
! 299: }
! 300:
! 301: }
! 302:
! 303: return;
! 304: }
! 305:
! 306:
! 307: /*
! 308: activity()
! 309: Show wizard number of demaons and memory blocks used
! 310: */
! 311:
! 312: void
! 313: activity(void)
! 314: {
! 315: msg("Daemons = %d : Memory Items = %d ", demoncnt, total);
! 316: return;
! 317: }
! 318:
! 319: /*
! 320: waste_time()
! 321: Do nothing but let other things happen
! 322: */
! 323:
! 324: void
! 325: waste_time(void)
! 326: {
! 327: if (inwhgt) /* if from wghtchk then done */
! 328: return;
! 329:
! 330: do_daemons(BEFORE);
! 331: do_fuses(BEFORE);
! 332: do_daemons(AFTER);
! 333: do_fuses(AFTER);
! 334: }
CVSweb