Mercurial > hg > early-roguelike
comparison xrogue/util.c @ 220:f54901b9c39b
XRogue: convert to ANSI-style function declarations.
| author | John "Elwin" Edwards |
|---|---|
| date | Wed, 02 Mar 2016 21:13:26 -0500 |
| parents | ce0cf824c192 |
| children | 7c1cb43f346e |
comparison
equal
deleted
inserted
replaced
| 219:f9ef86cf22b2 | 220:f54901b9c39b |
|---|---|
| 24 /* | 24 /* |
| 25 * this routine computes the players current AC without dex bonus's | 25 * this routine computes the players current AC without dex bonus's |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 int | 28 int |
| 29 ac_compute(ignoremetal) | 29 ac_compute(bool ignoremetal) |
| 30 bool ignoremetal; | |
| 31 { | 30 { |
| 32 register int ac; | 31 register int ac; |
| 33 | 32 |
| 34 ac = pstats.s_arm; /* base armor of "skin" */ | 33 ac = pstats.s_arm; /* base armor of "skin" */ |
| 35 if (cur_armor) { | 34 if (cur_armor) { |
| 58 /* | 57 /* |
| 59 * aggravate: | 58 * aggravate: |
| 60 * aggravate all the monsters on this level | 59 * aggravate all the monsters on this level |
| 61 */ | 60 */ |
| 62 | 61 |
| 63 aggravate(do_uniques, do_good) | 62 void |
| 64 bool do_uniques, do_good; | 63 aggravate(bool do_uniques, bool do_good) |
| 65 { | 64 { |
| 66 register struct linked_list *mi; | 65 register struct linked_list *mi; |
| 67 register struct thing *thingptr; | 66 register struct thing *thingptr; |
| 68 | 67 |
| 69 for (mi = mlist; mi != NULL; mi = next(mi)) { | 68 for (mi = mlist; mi != NULL; mi = next(mi)) { |
| 76 /* | 75 /* |
| 77 * cansee: | 76 * cansee: |
| 78 * returns true if the hero can see a certain coordinate. | 77 * returns true if the hero can see a certain coordinate. |
| 79 */ | 78 */ |
| 80 | 79 |
| 81 cansee(y, x) | 80 bool |
| 82 register int y, x; | 81 cansee(int y, int x) |
| 83 { | 82 { |
| 84 register struct room *rer; | 83 register struct room *rer; |
| 85 register int radius; | 84 register int radius; |
| 86 coord tp; | 85 coord tp; |
| 87 | 86 |
| 124 * up through MAXDOUBLE. Then the cap is added in to compute | 123 * up through MAXDOUBLE. Then the cap is added in to compute |
| 125 * further levels | 124 * further levels |
| 126 */ | 125 */ |
| 127 | 126 |
| 128 long | 127 long |
| 129 check_level() | 128 check_level(void) |
| 130 { | 129 { |
| 131 register int i, j, add = 0; | 130 register int i, j, add = 0; |
| 132 register unsigned long exp; | 131 register unsigned long exp; |
| 133 long retval; /* Return value */ | 132 long retval; /* Return value */ |
| 134 int nsides; | 133 int nsides; |
| 168 /* | 167 /* |
| 169 * Used to modify the players strength | 168 * Used to modify the players strength |
| 170 * it keeps track of the highest it has been, just in case | 169 * it keeps track of the highest it has been, just in case |
| 171 */ | 170 */ |
| 172 | 171 |
| 173 chg_str(amt) | 172 void |
| 174 register int amt; | 173 chg_str(int amt) |
| 175 { | 174 { |
| 176 register int ring_str; /* ring strengths */ | 175 register int ring_str; /* ring strengths */ |
| 177 register struct stats *ptr; /* for speed */ | 176 register struct stats *ptr; /* for speed */ |
| 178 | 177 |
| 179 ptr = &pstats; | 178 ptr = &pstats; |
| 193 | 192 |
| 194 /* | 193 /* |
| 195 * let's confuse the player | 194 * let's confuse the player |
| 196 */ | 195 */ |
| 197 | 196 |
| 198 confus_player() | 197 void |
| 198 confus_player(void) | |
| 199 { | 199 { |
| 200 if (off(player, ISCLEAR)) | 200 if (off(player, ISCLEAR)) |
| 201 { | 201 { |
| 202 msg("Wait, what's going on here! Huh? What? Who?"); | 202 msg("Wait, what's going on here! Huh? What? Who?"); |
| 203 if (find_slot(unconfuse)) | 203 if (find_slot(unconfuse)) |
| 211 | 211 |
| 212 /* | 212 /* |
| 213 * this routine computes the players current dexterity | 213 * this routine computes the players current dexterity |
| 214 */ | 214 */ |
| 215 | 215 |
| 216 dex_compute() | 216 int |
| 217 dex_compute(void) | |
| 217 { | 218 { |
| 218 if (cur_misc[WEAR_GAUNTLET] != NULL && | 219 if (cur_misc[WEAR_GAUNTLET] != NULL && |
| 219 cur_misc[WEAR_GAUNTLET]->o_which == MM_G_DEXTERITY) { | 220 cur_misc[WEAR_GAUNTLET]->o_which == MM_G_DEXTERITY) { |
| 220 if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED) | 221 if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED) |
| 221 return (3); | 222 return (3); |
| 229 /* | 230 /* |
| 230 * diag_ok: | 231 * diag_ok: |
| 231 * Check to see if the move is legal if it is diagonal | 232 * Check to see if the move is legal if it is diagonal |
| 232 */ | 233 */ |
| 233 | 234 |
| 234 diag_ok(sp, ep, flgptr) | 235 bool |
| 235 register coord *sp, *ep; | 236 diag_ok(coord *sp, coord *ep, struct thing *flgptr) |
| 236 struct thing *flgptr; | |
| 237 { | 237 { |
| 238 register int numpaths = 0; | 238 register int numpaths = 0; |
| 239 | 239 |
| 240 /* Horizontal and vertical moves are always ok */ | 240 /* Horizontal and vertical moves are always ok */ |
| 241 if (ep->x == sp->x || ep->y == sp->y) | 241 if (ep->x == sp->x || ep->y == sp->y) |
| 252 /* | 252 /* |
| 253 * pick a random position around the give (y, x) coordinates | 253 * pick a random position around the give (y, x) coordinates |
| 254 */ | 254 */ |
| 255 | 255 |
| 256 coord * | 256 coord * |
| 257 fallpos(pos, be_clear, range) | 257 fallpos(coord *pos, bool be_clear, int range) |
| 258 register coord *pos; | |
| 259 bool be_clear; | |
| 260 int range; | |
| 261 { | 258 { |
| 262 register int tried, i, j; | 259 register int tried, i, j; |
| 263 register char ch; | 260 register char ch; |
| 264 static coord ret; | 261 static coord ret; |
| 265 static short masks[] = { | 262 static short masks[] = { |
| 331 /* | 328 /* |
| 332 * findmindex: | 329 * findmindex: |
| 333 * Find the index into the monster table of a monster given its name. | 330 * Find the index into the monster table of a monster given its name. |
| 334 */ | 331 */ |
| 335 | 332 |
| 336 findmindex(name) | 333 int |
| 337 char *name; | 334 findmindex(char *name) |
| 338 { | 335 { |
| 339 int which; | 336 int which; |
| 340 | 337 |
| 341 for (which=1; which<NUMMONST; which++) { | 338 for (which=1; which<NUMMONST; which++) { |
| 342 if (strcmp(name, monsters[which].m_name) == 0) | 339 if (strcmp(name, monsters[which].m_name) == 0) |
| 353 * find_mons: | 350 * find_mons: |
| 354 * Find the monster from his coordinates | 351 * Find the monster from his coordinates |
| 355 */ | 352 */ |
| 356 | 353 |
| 357 struct linked_list * | 354 struct linked_list * |
| 358 find_mons(y, x) | 355 find_mons(int y, int x) |
| 359 register int y; | |
| 360 register int x; | |
| 361 { | 356 { |
| 362 register struct linked_list *item; | 357 register struct linked_list *item; |
| 363 register struct thing *th; | 358 register struct thing *th; |
| 364 | 359 |
| 365 for (item = mlist; item != NULL; item = next(item)) | 360 for (item = mlist; item != NULL; item = next(item)) |
| 375 * find_obj: | 370 * find_obj: |
| 376 * find the unclaimed object at y, x | 371 * find the unclaimed object at y, x |
| 377 */ | 372 */ |
| 378 | 373 |
| 379 struct linked_list * | 374 struct linked_list * |
| 380 find_obj(y, x) | 375 find_obj(int y, int x) |
| 381 register int y; | |
| 382 register int x; | |
| 383 { | 376 { |
| 384 register struct linked_list *obj; | 377 register struct linked_list *obj; |
| 385 register struct object *op; | 378 register struct object *op; |
| 386 | 379 |
| 387 for (obj = lvl_obj; obj != NULL; obj = next(obj)) | 380 for (obj = lvl_obj; obj != NULL; obj = next(obj)) |
| 396 /* | 389 /* |
| 397 * get coordinates from the player using the cursor keys (or mouse) | 390 * get coordinates from the player using the cursor keys (or mouse) |
| 398 */ | 391 */ |
| 399 | 392 |
| 400 coord | 393 coord |
| 401 get_coordinates() | 394 get_coordinates(void) |
| 402 { | 395 { |
| 403 register int which; | 396 register int which; |
| 404 coord c; | 397 coord c; |
| 405 | 398 |
| 406 c = hero; | 399 c = hero; |
| 456 /* | 449 /* |
| 457 * set up the direction co_ordinate for use in various "prefix" commands | 450 * set up the direction co_ordinate for use in various "prefix" commands |
| 458 */ | 451 */ |
| 459 | 452 |
| 460 bool | 453 bool |
| 461 get_dir(direction) | 454 get_dir(coord *direction) |
| 462 coord *direction; | |
| 463 { | 455 { |
| 464 register char *prompt; | 456 register char *prompt; |
| 465 register bool gotit; | 457 register bool gotit; |
| 466 int x,y; | 458 int x,y; |
| 467 | 459 |
| 517 * get_worth: | 509 * get_worth: |
| 518 * Calculate an objects worth in gold | 510 * Calculate an objects worth in gold |
| 519 */ | 511 */ |
| 520 | 512 |
| 521 long | 513 long |
| 522 get_worth(obj) | 514 get_worth(struct object *obj) |
| 523 reg struct object *obj; | |
| 524 { | 515 { |
| 525 reg long worth, wh; | 516 reg long worth, wh; |
| 526 | 517 |
| 527 worth = 0; | 518 worth = 0; |
| 528 wh = obj->o_which; | 519 wh = obj->o_which; |
| 589 /* | 580 /* |
| 590 * invisible() | 581 * invisible() |
| 591 */ | 582 */ |
| 592 | 583 |
| 593 bool | 584 bool |
| 594 invisible(monst) | 585 invisible(struct thing *monst) |
| 595 register struct thing *monst; | |
| 596 { | 586 { |
| 597 register bool ret_code; | 587 register bool ret_code; |
| 598 | 588 |
| 599 ret_code = on(*monst, CANSURPRISE); | 589 ret_code = on(*monst, CANSURPRISE); |
| 600 ret_code &= !ISWEARING(R_ALERT); | 590 ret_code &= !ISWEARING(R_ALERT); |
| 606 | 596 |
| 607 /* | 597 /* |
| 608 * see if the object is one of the currently used items | 598 * see if the object is one of the currently used items |
| 609 */ | 599 */ |
| 610 | 600 |
| 611 is_current(obj) | 601 bool |
| 612 register struct object *obj; | 602 is_current(struct object *obj) |
| 613 { | 603 { |
| 614 if (obj == NULL) | 604 if (obj == NULL) |
| 615 return FALSE; | 605 return FALSE; |
| 616 if (obj == cur_armor || obj == cur_weapon || | 606 if (obj == cur_armor || obj == cur_weapon || |
| 617 obj == cur_ring[LEFT_1] || obj == cur_ring[LEFT_2] || | 607 obj == cur_ring[LEFT_1] || obj == cur_ring[LEFT_2] || |
| 646 | 636 |
| 647 | 637 |
| 648 /* | 638 /* |
| 649 * Look: | 639 * Look: |
| 650 * A quick glance all around the player | 640 * A quick glance all around the player |
| 651 */ | 641 * wakeup: Should we wake up monsters |
| 652 | 642 * runend: At end of a run -- for mazes |
| 653 look(wakeup, runend) | 643 */ |
| 654 bool wakeup; /* Should we wake up monsters */ | 644 |
| 655 bool runend; /* At end of a run -- for mazes */ | 645 void |
| 646 look(bool wakeup, bool runend) | |
| 656 { | 647 { |
| 657 register int x, y, radius; | 648 register int x, y, radius; |
| 658 register unsigned char ch, och; | 649 register unsigned char ch, och; |
| 659 register int oldx, oldy; | 650 register int oldx, oldy; |
| 660 register bool inpass, horiz, vert, do_light = FALSE, do_blank = FALSE; | 651 register bool inpass, horiz, vert, do_light = FALSE, do_blank = FALSE; |
| 935 | 926 |
| 936 /* | 927 /* |
| 937 * Lower a level of experience | 928 * Lower a level of experience |
| 938 */ | 929 */ |
| 939 | 930 |
| 940 lower_level(who) | 931 void |
| 941 short who; | 932 lower_level(short who) |
| 942 { | 933 { |
| 943 int fewer, nsides; | 934 int fewer, nsides; |
| 944 unsigned long exp; | 935 unsigned long exp; |
| 945 | 936 |
| 946 msg("You suddenly feel less skillful."); | 937 msg("You suddenly feel less skillful."); |
| 973 /* | 964 /* |
| 974 * print out the name of a monster | 965 * print out the name of a monster |
| 975 */ | 966 */ |
| 976 | 967 |
| 977 char * | 968 char * |
| 978 monster_name(tp) | 969 monster_name(struct thing *tp) |
| 979 register struct thing *tp; | |
| 980 { | 970 { |
| 981 prbuf[0] = '\0'; | 971 prbuf[0] = '\0'; |
| 982 if (on(*tp, ISFLEE) || on(*tp, WASTURNED)) | 972 if (on(*tp, ISFLEE) || on(*tp, WASTURNED)) |
| 983 strcat(prbuf, "terrified "); | 973 strcat(prbuf, "terrified "); |
| 984 if (on(*tp, ISHUH)) | 974 if (on(*tp, ISHUH)) |
| 1005 * Try to move the hero somplace besides next to where he is. We ask him | 995 * Try to move the hero somplace besides next to where he is. We ask him |
| 1006 * where. There can be restrictions based on why he is moving. | 996 * where. There can be restrictions based on why he is moving. |
| 1007 */ | 997 */ |
| 1008 | 998 |
| 1009 bool | 999 bool |
| 1010 move_hero(why) | 1000 move_hero(int why) |
| 1011 int why; | |
| 1012 { | 1001 { |
| 1013 char *action = NULL; | 1002 char *action = NULL; |
| 1014 unsigned char which; | 1003 unsigned char which; |
| 1015 coord c; | 1004 coord c; |
| 1016 | 1005 |
| 1051 /* | 1040 /* |
| 1052 * raise_level: | 1041 * raise_level: |
| 1053 * The guy just magically went up a level. | 1042 * The guy just magically went up a level. |
| 1054 */ | 1043 */ |
| 1055 | 1044 |
| 1056 raise_level() | 1045 void |
| 1046 raise_level(void) | |
| 1057 { | 1047 { |
| 1058 unsigned long test; /* Next level -- be sure it is not an overflow */ | 1048 unsigned long test; /* Next level -- be sure it is not an overflow */ |
| 1059 | 1049 |
| 1060 test = check_level(); /* Get next boundary */ | 1050 test = check_level(); /* Get next boundary */ |
| 1061 | 1051 |
| 1103 }; | 1093 }; |
| 1104 | 1094 |
| 1105 /* | 1095 /* |
| 1106 * save: | 1096 * save: |
| 1107 * See if a creature saves against something | 1097 * See if a creature saves against something |
| 1108 */ | 1098 * which: which type of save |
| 1109 | 1099 * who: who is saving |
| 1110 save(which, who, adj) | 1100 * adj: saving throw adjustment |
| 1111 int which; /* which type of save */ | 1101 */ |
| 1112 struct thing *who; /* who is saving */ | 1102 |
| 1113 int adj; /* saving throw adjustment */ | 1103 bool |
| 1104 save(int which, struct thing *who, int adj) | |
| 1114 { | 1105 { |
| 1115 register int need, level, protect; | 1106 register int need, level, protect; |
| 1116 | 1107 |
| 1117 protect = 0; | 1108 protect = 0; |
| 1118 level = who->t_stats.s_lvl; | 1109 level = who->t_stats.s_lvl; |
| 1165 /* | 1156 /* |
| 1166 * secret_door: | 1157 * secret_door: |
| 1167 * Figure out what a secret door looks like. | 1158 * Figure out what a secret door looks like. |
| 1168 */ | 1159 */ |
| 1169 | 1160 |
| 1170 secretdoor(y, x) | 1161 char |
| 1171 register int y, x; | 1162 secretdoor(int y, int x) |
| 1172 { | 1163 { |
| 1173 register int i; | 1164 register int i; |
| 1174 register struct room *rp; | 1165 register struct room *rp; |
| 1175 register coord *cpp; | 1166 register coord *cpp; |
| 1176 static coord cp; | 1167 static coord cp; |
| 1190 | 1181 |
| 1191 /* | 1182 /* |
| 1192 * this routine computes the players current strength | 1183 * this routine computes the players current strength |
| 1193 */ | 1184 */ |
| 1194 | 1185 |
| 1195 str_compute() | 1186 int |
| 1187 str_compute(void) | |
| 1196 { | 1188 { |
| 1197 if (cur_misc[WEAR_GAUNTLET] != NULL && | 1189 if (cur_misc[WEAR_GAUNTLET] != NULL && |
| 1198 cur_misc[WEAR_GAUNTLET]->o_which == MM_G_OGRE) { | 1190 cur_misc[WEAR_GAUNTLET]->o_which == MM_G_OGRE) { |
| 1199 if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED) | 1191 if (cur_misc[WEAR_GAUNTLET]->o_flags & ISCURSED) |
| 1200 return (3); | 1192 return (3); |
| 1207 | 1199 |
| 1208 /* | 1200 /* |
| 1209 * copy string using unctrl for things | 1201 * copy string using unctrl for things |
| 1210 */ | 1202 */ |
| 1211 | 1203 |
| 1212 strucpy(s1, s2, len) | 1204 void |
| 1213 register char *s1, *s2; | 1205 strucpy(char *s1, char *s2, int len) |
| 1214 register int len; | |
| 1215 { | 1206 { |
| 1216 register char *sp; | 1207 register char *sp; |
| 1217 while (len--) | 1208 while (len--) |
| 1218 { | 1209 { |
| 1219 strcpy(s1, (sp = unctrl(*s2))); | 1210 strcpy(s1, (sp = unctrl(*s2))); |
| 1227 * tr_name: |
