comparison arogue7/fight.c @ 219:f9ef86cf22b2

Advanced Rogue 7: convert to ANSI-style function declarations. Almost 1500 lines of compiler warnings remain, and the GCC developers are already working on a new version with even more warnings turned on by default.
author John "Elwin" Edwards
date Fri, 19 Feb 2016 21:02:28 -0500
parents 382ff498acdd
children e1cd27c5464f
comparison
equal deleted inserted replaced
218:56e748983fa8 219:f9ef86cf22b2
18 */ 18 */
19 19
20 #include "curses.h" 20 #include "curses.h"
21 #include <ctype.h> 21 #include <ctype.h>
22 #include <string.h> 22 #include <string.h>
23 #include <stdlib.h>
23 #include "rogue.h" 24 #include "rogue.h"
24 25
25 int hit(struct object *weapon, bool see_att, bool see_def, char *er, char *ee, bool back_stab, bool thrown, bool short_msg); 26 bool roll_em(struct thing *att_er, struct thing *def_er, struct object *weap,
27 bool hurl, struct object *cur_weapon, bool back_stab);
28 void hit(struct object *weapon, bool see_att, bool see_def, char *er, char *ee,
29 bool back_stab, bool thrown, bool short_msg);
30 void miss(struct object *weapon, bool see_att, bool see_def, char *er, char *ee,
31 bool thrown, bool short_msg);
32 int add_dam(short str);
33 int hung_dam(void);
34
26 #define CONF_DAMAGE -1 35 #define CONF_DAMAGE -1
27 #define PARAL_DAMAGE -2 36 #define PARAL_DAMAGE -2
28 #define DEST_DAMAGE -3 37 #define DEST_DAMAGE -3
29 #define DRAIN_DAMAGE -4 38 #define DRAIN_DAMAGE -4
30 39
31 /* 40 /*
32 * returns true if player has a any chance to hit the monster 41 * returns true if player has a any chance to hit the monster
33 */ 42 */
34 player_can_hit(tp, weap) 43 bool
35 register struct thing *tp; 44 player_can_hit(struct thing *tp, struct object *weap)
36 register struct object *weap;
37 { 45 {
38 if (off(*tp, CMAGICHIT) && off(*tp, BMAGICHIT) && off(*tp, MAGICHIT)) 46 if (off(*tp, CMAGICHIT) && off(*tp, BMAGICHIT) && off(*tp, MAGICHIT))
39 return(TRUE); 47 return(TRUE);
40 if (weap && weap->o_type == RELIC) 48 if (weap && weap->o_type == RELIC)
41 return(TRUE); 49 return(TRUE);
59 /* 67 /*
60 * fight: 68 * fight:
61 * The player attacks the monster. 69 * The player attacks the monster.
62 */ 70 */
63 71
64 fight(mp, weap, thrown) 72 bool
65 register coord *mp; 73 fight(coord *mp, struct object *weap, bool thrown)
66 struct object *weap;
67 bool thrown;
68 { 74 {
69 register struct thing *tp; 75 register struct thing *tp;
70 register struct linked_list *item; 76 register struct linked_list *item;
71 register bool did_hit = TRUE; 77 register bool did_hit = TRUE;
72 bool see_def, back_stab = FALSE; 78 bool see_def, back_stab = FALSE;
223 /* 229 /*
224 * attack: 230 * attack:
225 * The monster attacks the player 231 * The monster attacks the player
226 */ 232 */
227 233
228 attack(mp, weapon, thrown) 234 bool
229 register struct thing *mp; 235 attack(struct thing *mp, struct object *weapon, bool thrown)
230 register struct object *weapon;
231 bool thrown;
232 { 236 {
233 register char *mname; 237 register char *mname;
234 register bool see_att, did_hit = FALSE; 238 register bool see_att, did_hit = FALSE;
235 register struct object *wielded; /* The wielded weapon */ 239 register struct object *wielded; /* The wielded weapon */
236 struct linked_list *get_wield; /* Linked list header for wielded */ 240 struct linked_list *get_wield; /* Linked list header for wielded */
299 /* 303 /*
300 * swing: 304 * swing:
301 * returns true if the swing hits 305 * returns true if the swing hits
302 */ 306 */
303 307
304 swing(class, at_lvl, op_arm, wplus) 308 bool
305 short class; 309 swing(short class, int at_lvl, int op_arm, int wplus)
306 int at_lvl, op_arm, wplus;
307 { 310 {
308 register int res = rnd(20)+1; 311 register int res = rnd(20)+1;
309 register int need; 312 register int need;
310 313
311 need = char_class[class].base - 314 need = char_class[class].base -
321 /* 324 /*
322 * roll_em: 325 * roll_em:
323 * Roll several attacks 326 * Roll several attacks
324 */ 327 */
325 328
326 roll_em(att_er, def_er, weap, hurl, cur_weapon, back_stab) 329 bool
327 struct thing *att_er, *def_er; 330 roll_em(struct thing *att_er, struct thing *def_er, struct object *weap,
328 struct object *weap; 331 bool hurl, struct object *cur_weapon, bool back_stab)
329 bool hurl;
330 struct object *cur_weapon;
331 bool back_stab;
332 { 332 {
333 register struct stats *att, *def; 333 register struct stats *att, *def;
334 register char *cp = NULL; 334 register char *cp = NULL;
335 register int ndice, nsides, nplus, def_arm; 335 register int ndice, nsides, nplus, def_arm;
336 bool did_hit = FALSE; 336 bool did_hit = FALSE;
698 * prname: 698 * prname:
699 * The print name of a combatant 699 * The print name of a combatant
700 */ 700 */
701 701
702 char * 702 char *
703 prname(who, upper) 703 prname(char *who, bool upper)
704 register char *who;
705 bool upper;
706 { 704 {
707 static char tbuf[LINELEN]; 705 static char tbuf[LINELEN];
708 706
709 *tbuf = '\0'; 707 *tbuf = '\0';
710 if (who == 0) 708 if (who == 0)
725 /* 723 /*
726 * hit: 724 * hit:
727 * Print a message to indicate a succesful hit 725 * Print a message to indicate a succesful hit
728 */ 726 */
729 727
730 hit(weapon, see_att, see_def, er, ee, back_stab, thrown, short_msg) 728 void
731 register struct object *weapon; 729 hit(struct object *weapon, bool see_att, bool see_def, char *er, char *ee,
732 bool see_att, see_def; 730 bool back_stab, bool thrown, bool short_msg)
733 register char *er, *ee;
734 bool back_stab, thrown, short_msg;
735 { 731 {
736 register char *s = ""; 732 register char *s = "";
737 char att_name[LINELEN], /* Name of attacker */ 733 char att_name[LINELEN], /* Name of attacker */
738 def_name[LINELEN]; /* Name of defender */ 734 def_name[LINELEN]; /* Name of defender */
739 735
789 /* 785 /*
790 * miss: 786 * miss:
791 * Print a message to indicate a poor swing 787 * Print a message to indicate a poor swing
792 */ 788 */
793 789
794 miss(weapon, see_att, see_def, er, ee, thrown, short_msg) 790 void
795 register struct object *weapon; 791 miss(struct object *weapon, bool see_att, bool see_def, char *er, char *ee,
796 bool see_att, see_def; 792 bool thrown, bool short_msg)
797 register char *er, *ee;
798 bool thrown, short_msg;
799 { 793 {
800 register char *s = ""; 794 register char *s = "";
801 char 795 char
802 att_name[LINELEN], /* Name of attacker */ 796 att_name[LINELEN], /* Name of attacker */
803 def_name[LINELEN]; /* Name of defender */ 797 def_name[LINELEN]; /* Name of defender */
834 /* 828 /*
835 * dext_plus: 829 * dext_plus:
836 * compute to-hit bonus for dexterity 830 * compute to-hit bonus for dexterity
837 */ 831 */
838 832
839 dext_plus(dexterity) 833 int
840 register int dexterity; 834 dext_plus(int dexterity)
841 { 835 {
842 return (dexterity > 10 ? (dexterity-13)/3 : (dexterity-10)/3); 836 return (dexterity > 10 ? (dexterity-13)/3 : (dexterity-10)/3);
843 } 837 }
844 838
845 839
846 /* 840 /*
847 * dext_prot: 841 * dext_prot:
848 * compute armor class bonus for dexterity 842 * compute armor class bonus for dexterity
849 */ 843 */
850 844
851 dext_prot(dexterity) 845 int
852 register int dexterity; 846 dext_prot(int dexterity)
853 { 847 {
854 return ((dexterity-10)/2); 848 return ((dexterity-10)/2);
855 } 849 }
856 /* 850 /*
857 * str_plus: 851 * str_plus:
858 * compute bonus/penalties for strength on the "to hit" roll 852 * compute bonus/penalties for strength on the "to hit" roll
859 */ 853 */
860 854
861 str_plus(str) 855 int
862 register short str; 856 str_plus(short str)
863 { 857 {
864 return((str-10)/3); 858 return((str-10)/3);
865 } 859 }
866 860
867 /* 861 /*
868 * add_dam: 862 * add_dam:
869 * compute additional damage done for exceptionally high or low strength 863 * compute additional damage done for exceptionally high or low strength
870 */ 864 */
871 865
872 add_dam(str) 866 int
873 register short str; 867 add_dam(short str)
874 { 868 {
875 return((str-9)/2); 869 return((str-9)/2);
876 } 870 }
877 871
878 /* 872 /*
879 * hung_dam: 873 * hung_dam:
880 * Calculate damage depending on players hungry state 874 * Calculate damage depending on players hungry state
881 */ 875 */
882 hung_dam() 876 int
877 hung_dam(void)
883 { 878 {
884 reg int howmuch; 879 reg int howmuch;
885 880
886 switch(hungry_state) { 881 switch(hungry_state) {
887 case F_SATIATED: 882 case F_SATIATED:
895 890
896 #ifdef THUNK 891 #ifdef THUNK
897 /* 892 /*
898 * thunk: 893 * thunk:
899 * A missile hits a monster 894 * A missile hits a monster
900 */ 895 * tp: defender
901 896 */
902 thunk(weap, tp, mname) 897
903 register struct object *weap; 898 void
904 register struct thing *tp; /* Defender */ 899 thunk(struct object *weap, struct thing *tp, char *mname)
905 register char *mname;
906 { 900 {
907 char *def_name; /* Name of defender */ 901 char *def_name; /* Name of defender */
908 902
909 /* What do we call the defender? */ 903 /* What do we call the defender? */
910 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp)) 904 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp))
922 /* 916 /*
923 * mthunk: 917 * mthunk:
924 * A missile from a monster hits the player 918 * A missile from a monster hits the player
925 */ 919 */
926 920
927 m_thunk(weap, tp, mname) 921 void
928 register struct object *weap; 922 m_thunk(struct object *weap, struct thing *tp, char *mname)
929 register struct thing *tp;
930 register char *mname;
931 { 923 {
932 char *att_name; /* Name of attacker */ 924 char *att_name; /* Name of attacker */
933 925
934 /* What do we call the attacker? */ 926 /* What do we call the attacker? */
935 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp)) 927 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp))
945 } 937 }
946 938
947 /* 939 /*
948 * bounce: 940 * bounce:
949 * A missile misses a monster 941 * A missile misses a monster
950 */ 942 * tp: defender
951 943 */
952 bounce(weap, tp, mname) 944
953 register struct object *weap; 945 void
954 register struct thing *tp; /* Defender */ 946 bounce(struct object *weap, struct thing *tp, char *mname)
955 register char *mname;
956 { 947 {
957 char *def_name; /* Name of defender */ 948 char *def_name; /* Name of defender */
958 949
959 /* What do we call the defender? */ 950 /* What do we call the defender? */
960 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp)) 951 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp))
972 /* 963 /*
973 * m_bounce: 964 * m_bounce:
974 * A missle from a monster misses the player 965 * A missle from a monster misses the player
975 */ 966 */
976 967
977 m_bounce(weap, tp, mname) 968 void
978 register struct object *weap; 969 m_bounce(struct object *weap, struct thing *tp, char *mname)
979 register struct thing *tp;
980 register char *mname;
981 { 970 {
982 char *att_name; /* Name of attacker */ 971 char *att_name; /* Name of attacker */
983 972
984 /* What do we call the attacker? */ 973 /* What do we call the attacker? */
985 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp)) 974 if (!cansee(tp->t_pos.y, tp->t_pos.x) || invisible(tp))
999 /* 988 /*
1000 * is_magic: 989 * is_magic:
1001 * Returns true if an object radiates magic 990 * Returns true if an object radiates magic
1002 */ 991 */
1003 992
1004 is_magic(obj) 993 bool
1005 register struct object *obj; 994 is_magic(struct object *obj)
1006 { 995 {
1007 switch (obj->o_type) 996 switch (obj->o_type)
1008 { 997 {
1009 case ARMOR: 998 case ARMOR:
1010 return obj->o_ac != armors[obj->o_which].a_class; 999 return obj->o_ac != armors[obj->o_which].a_class;
1026 * Called to put a monster to death 1015 * Called to put a monster to death
1027 */ 1016 */
1028 1017
1029 int chance = 0;/* cumulative chance for goodies to loose it */ 1018 int chance = 0;/* cumulative chance for goodies to loose it */
1030 1019
1031 killed(item, pr, points, treasure) 1020 void
1032 register struct linked_list *item; 1021 killed(struct linked_list *item, bool pr, bool points, bool treasure)
1033 bool pr, points, treasure;
1034 { 1022 {
1035 register struct thing *tp, *mp; 1023 register struct thing *tp, *mp;
1036 register struct linked_list *pitem, *nexti, *mitem; 1024 register struct linked_list *pitem, *nexti, *mitem;
1037 char *monst; 1025 char *monst;
1038 1026
1135 * the given thrown weapon. If no thrown item is given, try to find any 1123 * the given thrown weapon. If no thrown item is given, try to find any
1136 * decent weapon. 1124 * decent weapon.
1137 */ 1125 */
1138 1126
1139 struct linked_list * 1127 struct linked_list *
1140 wield_weap(thrown, mp) 1128 wield_weap(struct object *thrown, struct thing *mp)
1141 struct object *thrown;
1142 struct thing *mp;
1143 { 1129 {
1144 int look_for, /* The projectile weapon we are looking for */ 1130 int look_for, /* The projectile weapon we are looking for */
1145 new_rate, /* The rating of a prospective weapon */ 1131 new_rate, /* The rating of a prospective weapon */
1146 cand_rate = -1; /* Rating of current candidate -- higher is better */ 1132 cand_rate = -1; /* Rating of current candidate -- higher is better */
1147 register struct linked_list *pitem, *candidate = NULL; 1133 register struct linked_list *pitem, *candidate = NULL;
1218 } 1204 }
1219 } 1205 }
1220 1206
1221 return(candidate); 1207 return(candidate);
1222 } 1208 }
1223 explode(tp) 1209
1224 register struct thing *tp; 1210 void
1211 explode(struct thing *tp)
1225 { 1212 {
1226 1213
1227 register int x,y, damage; 1214 register int x,y, damage;
1228 struct linked_list *item; 1215 struct linked_list *item;
1229 struct thing *th; 1216 struct thing *th;
1273 /* 1260 /*
1274 * skirmish: 1261 * skirmish:
1275 * Called when one monster attacks another monster. 1262 * Called when one monster attacks another monster.
1276 */ 1263 */
1277 1264
1278 skirmish(attacker, mp, weap, thrown) 1265 bool
1279 register struct thing *attacker; 1266 skirmish(struct thing *attacker, coord *mp, struct object *weap, bool thrown)
1280 register coord *mp;
1281 struct object *weap;
1282 bool thrown;
1283 { 1267 {
1284 register struct thing *defender; 1268 register struct thing *defender;
1285 register struct linked_list *item; 1269 register struct linked_list *item;
1286 register bool did_hit = TRUE, see_att, see_def; 1270 register bool did_hit = TRUE, see_att, see_def;
1287 char attname[LINELEN+1], defname[LINELEN+1]; 1271 char attname[LINELEN+1], defname[LINELEN+1];