Mercurial > hg > early-roguelike
comparison xrogue/move.c @ 225:4f6e056438eb
Merge the GCC5 and build fix branches.
| author | John "Elwin" Edwards | 
|---|---|
| date | Wed, 02 Mar 2016 21:28:34 -0500 | 
| parents | f54901b9c39b | 
| children | e52a8a7ad4c5 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 224:4d0f53998e8a | 225:4f6e056438eb | 
|---|---|
| 16 See the file LICENSE.TXT for full copyright and licensing information. | 16 See the file LICENSE.TXT for full copyright and licensing information. | 
| 17 */ | 17 */ | 
| 18 | 18 | 
| 19 #include <curses.h> | 19 #include <curses.h> | 
| 20 #include <ctype.h> | 20 #include <ctype.h> | 
| 21 #include <string.h> | |
| 21 #include "rogue.h" | 22 #include "rogue.h" | 
| 22 | 23 | 
| 23 /* | 24 /* | 
| 24 * Used to hold the new hero position | 25 * Used to hold the new hero position | 
| 25 */ | 26 */ | 
| 35 /* | 36 /* | 
| 36 * be_trapped: | 37 * be_trapped: | 
| 37 * The guy stepped on a trap.... Make him pay. | 38 * The guy stepped on a trap.... Make him pay. | 
| 38 */ | 39 */ | 
| 39 | 40 | 
| 40 be_trapped(th, tc) | 41 char | 
| 41 register struct thing *th; | 42 be_trapped(struct thing *th, coord *tc) | 
| 42 register coord *tc; | |
| 43 { | 43 { | 
| 44 register struct trap *tp; | 44 register struct trap *tp; | 
| 45 register char ch, *mname = NULL; | 45 register char ch, *mname = NULL; | 
| 46 register bool is_player = (th == &player), | 46 register bool is_player = (th == &player), | 
| 47 can_see; | 47 can_see; | 
| 502 * blue_light: | 502 * blue_light: | 
| 503 * magically light up a room (or level or make it dark) | 503 * magically light up a room (or level or make it dark) | 
| 504 */ | 504 */ | 
| 505 | 505 | 
| 506 bool | 506 bool | 
| 507 blue_light(blessed, cursed) | 507 blue_light(bool blessed, bool cursed) | 
| 508 bool blessed, cursed; | |
| 509 { | 508 { | 
| 510 register struct room *rp; | 509 register struct room *rp; | 
| 511 bool ret_val=FALSE; /* Whether or not affect is known */ | 510 bool ret_val=FALSE; /* Whether or not affect is known */ | 
| 512 | 511 | 
| 513 rp = roomin(&hero); /* What room is hero in? */ | 512 rp = roomin(&hero); /* What room is hero in? */ | 
| 561 * corr_move: | 560 * corr_move: | 
| 562 * Check to see that a move is legal. If so, return correct character. | 561 * Check to see that a move is legal. If so, return correct character. | 
| 563 * If not, if player came from a legal place, then try to turn him. | 562 * If not, if player came from a legal place, then try to turn him. | 
| 564 */ | 563 */ | 
| 565 | 564 | 
| 566 corr_move(dy, dx) | 565 void | 
| 567 int dy, dx; | 566 corr_move(int dy, int dx) | 
| 568 { | 567 { | 
| 569 int legal=0; /* Number of legal alternatives */ | 568 int legal=0; /* Number of legal alternatives */ | 
| 570 register int y, x, /* Indexes though possible positions */ | 569 register int y, x, /* Indexes though possible positions */ | 
| 571 locy = 0, locx = 0; /* Hold delta of chosen location */ | 570 locy = 0, locx = 0; /* Hold delta of chosen location */ | 
| 572 | 571 | 
| 640 /* | 639 /* | 
| 641 * dip_it: | 640 * dip_it: | 
| 642 * Dip an object into a magic pool | 641 * Dip an object into a magic pool | 
| 643 */ | 642 */ | 
| 644 | 643 | 
| 645 dip_it() | 644 void | 
| 645 dip_it(void) | |
| 646 { | 646 { | 
| 647 reg struct linked_list *what; | 647 reg struct linked_list *what; | 
| 648 reg struct object *ob; | 648 reg struct object *ob; | 
| 649 reg struct trap *tp; | 649 reg struct trap *tp; | 
| 650 reg int wh, i; | 650 reg int wh, i; | 
| 837 * do_move: | 837 * do_move: | 
| 838 * Check to see that a move is legal. If it is handle the | 838 * Check to see that a move is legal. If it is handle the | 
| 839 * consequences (fighting, picking up, etc.) | 839 * consequences (fighting, picking up, etc.) | 
| 840 */ | 840 */ | 
| 841 | 841 | 
| 842 do_move(dy, dx) | 842 void | 
| 843 int dy, dx; | 843 do_move(int dy, int dx) | 
| 844 { | 844 { | 
| 845 register struct room *rp, *orp; | 845 register struct room *rp, *orp; | 
| 846 register unsigned char ch; | 846 register unsigned char ch; | 
| 847 struct linked_list *item; | 847 struct linked_list *item; | 
| 848 register struct thing *tp = NULL; | 848 register struct thing *tp = NULL; | 
| 1187 /* | 1187 /* | 
| 1188 * do_run: | 1188 * do_run: | 
| 1189 * Start the hero running | 1189 * Start the hero running | 
| 1190 */ | 1190 */ | 
| 1191 | 1191 | 
| 1192 do_run(ch) | 1192 void | 
| 1193 char ch; | 1193 do_run(char ch) | 
| 1194 { | 1194 { | 
| 1195 firstmove = TRUE; | 1195 firstmove = TRUE; | 
| 1196 running = TRUE; | 1196 running = TRUE; | 
| 1197 after = FALSE; | 1197 after = FALSE; | 
| 1198 runch = ch; | 1198 runch = ch; | 
| 1204 * y and x delta corresponding to it in the remaining arguments. | 1204 * y and x delta corresponding to it in the remaining arguments. | 
| 1205 * Returns TRUE if it could find it, FALSE otherwise. | 1205 * Returns TRUE if it could find it, FALSE otherwise. | 
| 1206 */ | 1206 */ | 
| 1207 | 1207 | 
| 1208 bool | 1208 bool | 
| 1209 getdelta(match, dy, dx) | 1209 getdelta(char match, int *dy, int *dx) | 
| 1210 char match; | |
| 1211 int *dy, *dx; | |
| 1212 { | 1210 { | 
| 1213 register int y, x; | 1211 register int y, x; | 
| 1214 | 1212 | 
| 1215 for (y = 0; y < 3; y++) | 1213 for (y = 0; y < 3; y++) | 
| 1216 for (x = 0; x < 3; x++) | 1214 for (x = 0; x < 3; x++) | 
| 1226 /* | 1224 /* | 
| 1227 * isatrap: | 1225 * isatrap: | 
| 1228 * Returns TRUE if this character is some kind of trap | 1226 * Returns TRUE if this character is some kind of trap | 
| 1229 */ | 1227 */ | 
| 1230 | 1228 | 
| 1231 isatrap(ch) | 1229 bool | 
| 1232 reg char ch; | 1230 isatrap(char ch) | 
| 1233 { | 1231 { | 
| 1234 switch(ch) { | 1232 switch(ch) { | 
| 1235 case WORMHOLE: | 1233 case WORMHOLE: | 
| 1236 case DARTTRAP: | 1234 case DARTTRAP: | 
| 1237 case TELTRAP: | 1235 case TELTRAP: | 
| 1248 /* | 1246 /* | 
| 1249 * Called to illuminate a room. | 1247 * Called to illuminate a room. | 
| 1250 * If it is dark, remove anything that might move. | 1248 * If it is dark, remove anything that might move. | 
| 1251 */ | 1249 */ | 
| 1252 | 1250 | 
| 1253 light(cp) | 1251 void | 
| 1254 coord *cp; | 1252 light(coord *cp) | 
| 1255 { | 1253 { | 
| 1256 register struct room *rp; | 1254 register struct room *rp; | 
| 1257 register int j, k, x, y; | 1255 register int j, k, x, y; | 
| 1258 register unsigned char ch, rch, sch; | 1256 register unsigned char ch, rch, sch; | 
| 1259 register struct linked_list *item; | 1257 register struct linked_list *item; | 
| 1426 * lit_room: | 1424 * lit_room: | 
| 1427 * Called to see if the specified room is lit up or not. | 1425 * Called to see if the specified room is lit up or not. | 
| 1428 */ | 1426 */ | 
| 1429 | 1427 | 
| 1430 bool | 1428 bool | 
| 1431 lit_room(rp) | 1429 lit_room(struct room *rp) | 
| 1432 register struct room *rp; | |
| 1433 { | 1430 { | 
| 1434 register struct linked_list *fire_item; | 1431 register struct linked_list *fire_item; | 
| 1435 register struct thing *fire_creature; | 1432 register struct thing *fire_creature; | 
| 1436 | 1433 | 
| 1437 if (!(rp->r_flags & ISDARK)) return(TRUE); /* A definitely lit room */ | 1434 if (!(rp->r_flags & ISDARK)) return(TRUE); /* A definitely lit room */ | 
| 1464 * Given a pointer to a player/monster structure, calculate the | 1461 * Given a pointer to a player/monster structure, calculate the | 
| 1465 * movement rate for that character. | 1462 * movement rate for that character. | 
| 1466 */ | 1463 */ | 
| 1467 | 1464 | 
| 1468 short | 1465 short | 
| 1469 movement(tp) | 1466 movement(struct thing *tp) | 
| 1470 register struct thing *tp; | |
| 1471 { | 1467 { | 
| 1472 register int result; | 1468 register int result; | 
| 1473 register int carry; /* Percentage carried */ | 1469 register int carry; /* Percentage carried */ | 
| 1474 | 1470 | 
| 1475 result = 0; | 1471 result = 0; | 
| 1529 * rndmove: | 1525 * rndmove: | 
| 1530 * move in a random direction if the monster/person is confused | 1526 * move in a random direction if the monster/person is confused | 
| 1531 */ | 1527 */ | 
| 1532 | 1528 | 
| 1533 coord | 1529 coord | 
| 1534 rndmove(who) | 1530 rndmove(struct thing *who) | 
| 1535 struct thing *who; | |
| 1536 { | 1531 { | 
| 1537 register int x, y; | 1532 register int x, y; | 
| 1538 register int ex, ey, nopen = 0; | 1533 register int ex, ey, nopen = 0; | 
| 1539 coord ret; /* what we will be returning */ | 1534 coord ret; /* what we will be returning */ | 
| 1540 coord dest; | 1535 coord dest; | 
| 1584 /* | 1579 /* | 
| 1585 * set_trap: | 1580 * set_trap: | 
| 1586 * set a trap at (y, x) on screen. | 1581 * set a trap at (y, x) on screen. | 
| 1587 */ | 1582 */ | 
| 1588 | 1583 | 
| 1589 set_trap(tp, y, x) | 1584 void | 
| 1590 register struct thing *tp; | 1585 set_trap(struct thing *tp, int y, int x) | 
| 1591 register int y, x; | |
| 1592 { | 1586 { | 
| 1593 register bool is_player = (tp == &player); | 1587 register bool is_player = (tp == &player); | 
| 1594 register int selection = rnd(TRAPTYPES-WIZARDTRAPS) + '1'; | 1588 register int selection = rnd(TRAPTYPES-WIZARDTRAPS) + '1'; | 
| 1595 register int i, num_traps; | 1589 register int i, num_traps; | 
| 1596 register unsigned char ch = 0, och; | 1590 register unsigned char ch = 0, och; | 
| 1643 if (menu_overlay) | 1637 if (menu_overlay) | 
| 1644 /* | 1638 /* | 
| 1645 * Put out the selection. The longest line is | 1639 * Put out the selection. The longest line is | 
| 1646 * the prompt line (39 characters long). | 1640 * the prompt line (39 characters long). | 
| 1647 */ | 1641 */ | 
| 1648 over_win(cw, hw, num_traps + 3, 41, 0, 39, NULL); | 1642 over_win(cw, hw, num_traps + 3, 41, 0, 39, '\0'); | 
| 1649 else | 1643 else | 
| 1650 draw(hw); | 1644 draw(hw); | 
| 1651 state = 1; /* Now in prompt window */ | 1645 state = 1; /* Now in prompt window */ | 
| 1652 } | 1646 } | 
| 1653 break; | 1647 break; | 
| 1703 if (menu_overlay) | 1697 if (menu_overlay) | 
| 1704 /* | 1698 /* | 
| 1705 * Put out the selection. The longest line is | 1699 * Put out the selection. The longest line is | 
| 1706 * the prompt line (43 characters long). | 1700 * the prompt line (43 characters long). | 
| 1707 */ | 1701 */ | 
| 1708 over_win(cw, hw, num_traps+3, 45, 0, 43, NULL); | 1702 over_win(cw, hw, num_traps+3, 45, 0, 43, '\0'); | 
| 1709 else | 1703 else | 
| 1710 draw(hw); | 1704 draw(hw); | 
| 1711 } | 1705 } | 
| 1712 else { /* Normal window */ | 1706 else { /* Normal window */ | 
| 1713 mpos = 0; | 1707 mpos = 0; | 
| 1776 /* | 1770 /* | 
| 1777 * show: | 1771 * show: | 
| 1778 * returns what a certain thing will display as to the un-initiated | 1772 * returns what a certain thing will display as to the un-initiated | 
| 1779 */ | 1773 */ | 
| 1780 | 1774 | 
| 1781 show(y, x) | 1775 char | 
| 1782 register int y, x; | 1776 show(int y, int x) | 
| 1783 { | 1777 { | 
| 1784 register unsigned char ch = winat(y, x); | 1778 register unsigned char ch = winat(y, x); | 
| 1785 register struct linked_list *it; | 1779 register struct linked_list *it; | 
| 1786 register struct thing *tp; | 1780 register struct thing *tp; | 
| 1787 | 1781 | 
| 1817 * trap_at: | 1811 * trap_at: | 
| 1818 * find the trap at (y,x) on screen. | 1812 * find the trap at (y,x) on screen. | 
| 1819 */ | 1813 */ | 
| 1820 | 1814 | 
| 1821 struct trap * | 1815 struct trap * | 
| 1822 trap_at(y, x) | 1816 trap_at(int y, int x) | 
| 1823 register int y, x; | |
| 1824 { | 1817 { | 
| 1825 register struct trap *tp, *ep; | 1818 register struct trap *tp, *ep; | 
| 1826 | 1819 | 
| 1827 ep = &traps[ntraps]; | 1820 ep = &traps[ntraps]; | 
| 1828 for (tp = traps; tp < ep; tp++) | 1821 for (tp = traps; tp < ep; tp++) | 
| 1836 /* | 1829 /* | 
| 1837 * weap_move: | 1830 * weap_move: | 
| 1838 * Calculate how many segments it will take to swing the given | 1831 * Calculate how many segments it will take to swing the given | 
| 1839 * weapon (note that the weapon may actually be a stick or | 1832 * weapon (note that the weapon may actually be a stick or | 
| 1840 * even something else). | 1833 * even something else). | 
| 1834 * wielder: Who's wielding the weapon | |
| 1835 * weap: The weapon | |
| 1841 */ | 1836 */ | 
| 1842 | 1837 | 
| 1843 weap_move(wielder, weap) | 1838 int | 
| 1844 register struct thing *wielder; /* Who's wielding the weapon */ | 1839 weap_move(struct thing *wielder, struct object *weap) | 
| 1845 register struct object *weap; /* The weapon */ | |
| 1846 { | 1840 { | 
| 1847 register int weap_rate; | 1841 register int weap_rate; | 
| 1848 int dexterity; | 1842 int dexterity; | 
| 1849 int strength; | 1843 int strength; | 
| 1850 | 1844 | 
