Mercurial > hg > early-roguelike
comparison xrogue/fight.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 | 7c1cb43f346e |
comparison
equal
deleted
inserted
replaced
224:4d0f53998e8a | 225:4f6e056438eb |
---|---|
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 <string.h> |
22 #include <stdlib.h> | |
22 #include "rogue.h" | 23 #include "rogue.h" |
23 | 24 |
24 #define CONF_DAMAGE -1 | 25 #define CONF_DAMAGE -1 |
25 #define PARAL_DAMAGE -2 | 26 #define PARAL_DAMAGE -2 |
26 #define DEST_DAMAGE -3 | 27 #define DEST_DAMAGE -3 |
27 #define DRAIN_DAMAGE -4 | 28 #define DRAIN_DAMAGE -4 |
28 | 29 |
30 bool roll_em(struct thing *att_er, struct thing *def_er, struct object *weap, | |
31 bool hurl, struct object *cur_weapon, bool back_stab); | |
32 void hit(struct object *weapon, bool see_att, bool see_def, char *er, char *ee, | |
33 bool back_stab, bool thrown, bool short_msg); | |
34 void miss(struct object *weapon, bool see_att, bool see_def, char *er, char *ee, | |
35 bool thrown, bool short_msg); | |
36 int add_dam(short str); | |
37 int hung_dam(void); | |
38 | |
29 int killed_chance = 0; /* cumulative chance for goodies to loose it */ | 39 int killed_chance = 0; /* cumulative chance for goodies to loose it */ |
30 | 40 |
31 /* | 41 /* |
32 * returns true if player has a any chance to hit the monster | 42 * returns true if player has a any chance to hit the monster |
33 */ | 43 */ |
34 | 44 |
35 player_can_hit(tp, weap) | 45 bool |
36 register struct thing *tp; | 46 player_can_hit(struct thing *tp, struct object *weap) |
37 register struct object *weap; | |
38 { | 47 { |
39 if (off(*tp, CMAGICHIT) && off(*tp, BMAGICHIT) && off(*tp, MAGICHIT)) | 48 if (off(*tp, CMAGICHIT) && off(*tp, BMAGICHIT) && off(*tp, MAGICHIT)) |
40 return(TRUE); | 49 return(TRUE); |
41 if (weap && weap->o_type == RELIC) | 50 if (weap && weap->o_type == RELIC) |
42 return(TRUE); | 51 return(TRUE); |
60 /* | 69 /* |
61 * fight: | 70 * fight: |
62 * The player attacks the monster. | 71 * The player attacks the monster. |
63 */ | 72 */ |
64 | 73 |
65 fight(mp, weap, thrown) | 74 bool |
66 register coord *mp; | 75 fight(coord *mp, struct object *weap, bool thrown) |
67 struct object *weap; | |
68 bool thrown; | |
69 { | 76 { |
70 register struct thing *tp; | 77 register struct thing *tp; |
71 register struct linked_list *item; | 78 register struct linked_list *item; |
72 register bool did_hit = TRUE; | 79 register bool did_hit = TRUE; |
73 bool see_def, back_stab = FALSE; | 80 bool see_def, back_stab = FALSE; |
224 /* | 231 /* |
225 * attack: | 232 * attack: |
226 * The monster attacks the player | 233 * The monster attacks the player |
227 */ | 234 */ |
228 | 235 |
229 attack(mp, weapon, thrown) | 236 bool |
230 register struct thing *mp; | 237 attack(struct thing *mp, struct object *weapon, bool thrown) |
231 register struct object *weapon; | |
232 bool thrown; | |
233 { | 238 { |
234 register char *mname; | 239 register char *mname; |
235 register bool see_att, did_hit = FALSE; | 240 register bool see_att, did_hit = FALSE; |
236 register struct object *wielded; /* The wielded weapon */ | 241 register struct object *wielded; /* The wielded weapon */ |
237 struct linked_list *get_wield; /* Linked list header for wielded */ | 242 struct linked_list *get_wield; /* Linked list header for wielded */ |
303 /* | 308 /* |
304 * swing: | 309 * swing: |
305 * returns true if the swing hits | 310 * returns true if the swing hits |
306 */ | 311 */ |
307 | 312 |
308 swing(class, at_lvl, op_arm, wplus) | 313 bool |
309 short class; | 314 swing(short class, int at_lvl, int op_arm, int wplus) |
310 int at_lvl, op_arm, wplus; | |
311 { | 315 { |
312 register int res = rnd(20)+1; | 316 register int res = rnd(20)+1; |
313 register int need; | 317 register int need; |
314 | 318 |
315 need = char_class[class].base - | 319 need = char_class[class].base - |
325 /* | 329 /* |
326 * roll_em: | 330 * roll_em: |
327 * Roll several attacks | 331 * Roll several attacks |
328 */ | 332 */ |
329 | 333 |
330 roll_em(att_er, def_er, weap, hurl, cur_weapon, back_stab) | 334 bool |
331 struct thing *att_er, *def_er; | 335 roll_em(struct thing *att_er, struct thing *def_er, struct object *weap, |
332 struct object *weap; | 336 bool hurl, struct object *cur_weapon, bool back_stab) |
333 bool hurl; | |
334 struct object *cur_weapon; | |
335 bool back_stab; | |
336 { | 337 { |
337 register struct stats *att, *def; | 338 register struct stats *att, *def; |
338 register char *cp = NULL; | 339 register char *cp = NULL; |
339 register int ndice, nsides, nplus, def_arm; | 340 register int ndice, nsides, nplus, def_arm; |
340 char dmgbuf[20]; | 341 char dmgbuf[20]; |
737 * prname: | 738 * prname: |
738 * The print name of a combatant | 739 * The print name of a combatant |
739 */ | 740 */ |
740 | 741 |
741 char * | 742 char * |
742 prname(who, upper) | 743 prname(char *who, bool upper) |
743 register char *who; | |
744 bool upper; | |
745 { | 744 { |
746 static char tbuf[LINELEN]; | 745 static char tbuf[LINELEN]; |
747 | 746 |
748 *tbuf = '\0'; | 747 *tbuf = '\0'; |
749 if (who == 0) | 748 if (who == 0) |
764 /* | 763 /* |
765 * hit: | 764 * hit: |
766 * Print a message to indicate a succesful hit | 765 * Print a message to indicate a succesful hit |
767 */ | 766 */ |
768 | 767 |
769 hit(weapon, see_att, see_def, er, ee, back_stab, thrown, short_msg) | 768 void |
770 register struct object *weapon; | 769 hit(struct object *weapon, bool see_att, bool see_def, char *er, char *ee, |
771 bool see_att, see_def; | 770 bool back_stab, bool thrown, bool short_msg) |
772 register char *er, *ee; | |
773 bool back_stab, thrown, short_msg; | |
774 { | 771 { |
775 register char *s = NULL; | 772 register char *s = NULL; |
776 char att_name[LINELEN], /* Name of attacker */ | 773 char att_name[LINELEN], /* Name of attacker */ |
777 def_name[LINELEN]; /* Name of defender */ | 774 def_name[LINELEN]; /* Name of defender */ |
778 | 775 |
828 /* | 825 /* |
829 * miss: | 826 * miss: |
830 * Print a message to indicate a poor swing | 827 * Print a message to indicate a poor swing |
831 */ | 828 */ |
832 | 829 |
833 miss(weapon, see_att, see_def, er, ee, thrown, short_msg) | 830 void |
834 register struct object *weapon; | 831 miss(struct object *weapon, bool see_att, bool see_def, char *er, char *ee, |
835 bool see_att, see_def; | 832 bool thrown, bool short_msg) |
836 register char *er, *ee; | |
837 bool thrown, short_msg; | |
838 { | 833 { |
839 register char *s = NULL; | 834 register char *s = NULL; |
840 char att_name[LINELEN], /* Name of attacker */ | 835 char att_name[LINELEN], /* Name of attacker */ |
841 def_name[LINELEN]; /* Name of defender */ | 836 def_name[LINELEN]; /* Name of defender */ |
842 | 837 |
872 /* | 867 /* |
873 * dext_plus: | 868 * dext_plus: |
874 * compute to-hit bonus for dexterity | 869 * compute to-hit bonus for dexterity |
875 */ | 870 */ |
876 | 871 |
877 dext_plus(dexterity) | 872 int |
878 register int dexterity; | 873 dext_plus(int dexterity) |
879 { | 874 { |
880 return (dexterity > 10 ? (dexterity-13)/3 : (dexterity-10)/3); | 875 return (dexterity > 10 ? (dexterity-13)/3 : (dexterity-10)/3); |
881 } | 876 } |
882 | 877 |
883 | 878 |
884 /* | 879 /* |
885 * dext_prot: | 880 * dext_prot: |
886 * compute armor class bonus for dexterity | 881 * compute armor class bonus for dexterity |
887 */ | 882 */ |
888 | 883 |
889 dext_prot(dexterity) | 884 int |
890 register int dexterity; | 885 dext_prot(int dexterity) |
891 { | 886 { |
892 return ((dexterity-10)/2); | 887 return ((dexterity-10)/2); |
893 } | 888 } |
894 | 889 |
895 /* | 890 /* |
896 * str_plus: | 891 * str_plus: |
897 * compute bonus/penalties for strength on the "to hit" roll | 892 * compute bonus/penalties for strength on the "to hit" roll |
898 */ | 893 */ |
899 | 894 |
900 str_plus(str) | 895 int |
901 register short str; | 896 str_plus(short str) |
902 { | 897 { |
903 return((str-10)/3); | 898 return((str-10)/3); |
904 } | 899 } |
905 | 900 |
906 /* | 901 /* |
907 * add_dam: | 902 * add_dam: |
908 * compute additional damage done for exceptionally high or low strength | 903 * compute additional damage done for exceptionally high or low strength |
909 */ | 904 */ |
910 | 905 |
911 add_dam(str) | 906 int |
912 register short str; | 907 add_dam(short str) |
913 { | 908 { |
914 return((str-9)/2); | 909 return((str-9)/2); |
915 } | 910 } |
916 | 911 |
917 /* | 912 /* |
918 * hung_dam: | 913 * hung_dam: |
919 * Calculate damage depending on players hungry state | 914 * Calculate damage depending on players hungry state |
920 */ | 915 */ |
921 | 916 |
922 hung_dam() | 917 int |
918 hung_dam(void) | |
923 { | 919 { |
924 reg int howmuch = 0; | 920 reg int howmuch = 0; |
925 | 921 |
926 switch(hungry_state) { | 922 switch(hungry_state) { |
927 case F_SATIATED: | 923 case F_SATIATED: |
936 /* | 932 /* |
937 * is_magic: | 933 * is_magic: |
938 * Returns true if an object radiates magic | 934 * Returns true if an object radiates magic |
939 */ | 935 */ |
940 | 936 |
941 is_magic(obj) | 937 bool |
942 register struct object *obj; | 938 is_magic(struct object *obj) |
943 { | 939 { |
944 switch (obj->o_type) | 940 switch (obj->o_type) |
945 { | 941 { |
946 case ARMOR: | 942 case ARMOR: |
947 return obj->o_ac != armors[obj->o_which].a_class; | 943 return obj->o_ac != armors[obj->o_which].a_class; |
961 /* | 957 /* |
962 * killed: | 958 * killed: |
963 * Called to put a monster to death | 959 * Called to put a monster to death |
964 */ | 960 */ |
965 | 961 |
966 killed(item, pr, points, treasure) | 962 void |
967 register struct linked_list *item; | 963 killed(struct linked_list *item, bool pr, bool points, bool treasure) |
968 bool pr, points, treasure; | |
969 { | 964 { |
970 register struct thing *tp, *mp; | 965 register struct thing *tp, *mp; |
971 register struct linked_list *pitem, *nexti, *mitem; | 966 register struct linked_list *pitem, *nexti, *mitem; |
972 char *monst; | 967 char *monst; |
973 int adj; /* used for hit point adj. below. */ | 968 int adj; /* used for hit point adj. below. */ |
1113 * the given thrown weapon. If no thrown item is given, try to find any | 1108 * the given thrown weapon. If no thrown item is given, try to find any |
1114 * decent weapon. | 1109 * decent weapon. |
1115 */ | 1110 */ |
1116 | 1111 |
1117 struct linked_list * | 1112 struct linked_list * |
1118 wield_weap(thrown, mp) | 1113 wield_weap(struct object *thrown, struct thing *mp) |
1119 struct object *thrown; | |
1120 struct thing *mp; | |
1121 { | 1114 { |
1122 int look_for = 0, /* The projectile weapon we are looking for */ | 1115 int look_for = 0, /* The projectile weapon we are looking for */ |
1123 new_rate, /* The rating of a prospective weapon */ | 1116 new_rate, /* The rating of a prospective weapon */ |
1124 cand_rate = -1; /* Rating of current candidate -- higher is better */ | 1117 cand_rate = -1; /* Rating of current candidate -- higher is better */ |
1125 register struct linked_list *pitem, *candidate = NULL; | 1118 register struct linked_list *pitem, *candidate = NULL; |
1196 } | 1189 } |
1197 } | 1190 } |
1198 | 1191 |
1199 return(candidate); | 1192 return(candidate); |
1200 } | 1193 } |
1201 explode(tp) | 1194 |
1202 register struct thing *tp; | 1195 void |
1196 explode(struct thing *tp) | |
1203 { | 1197 { |
1204 | 1198 |
1205 register int x,y, damage; | 1199 register int x,y, damage; |
1206 struct linked_list *item; | 1200 struct linked_list *item; |
1207 struct thing *th; | 1201 struct thing *th; |
1251 /* | 1245 /* |
1252 * skirmish: | 1246 * skirmish: |
1253 * Called when one monster attacks another monster. | 1247 * Called when one monster attacks another monster. |
1254 */ | 1248 */ |
1255 | 1249 |
1256 skirmish(attacker, mp, weap, thrown) | 1250 bool |
1257 register struct thing *attacker; | 1251 skirmish(struct thing *attacker, coord *mp, struct object *weap, bool thrown) |
1258 register coord *mp; | |
1259 struct object *weap; | |
1260 bool thrown; | |
1261 { | 1252 { |
1262 register struct thing *defender; | 1253 register struct thing *defender; |
1263 register struct linked_list *item; | 1254 register struct linked_list *item; |
1264 register bool did_hit = TRUE, see_att, see_def; | 1255 register bool did_hit = TRUE, see_att, see_def; |
1265 char attname[LINELEN+1], defname[LINELEN+1]; | 1256 char attname[LINELEN+1], defname[LINELEN+1]; |