Mercurial > hg > early-roguelike
comparison xrogue/player.c @ 142:6b5fbd7c3ece
Merge arogue7 and xrogue trees.
| author | John "Elwin" Edwards |
|---|---|
| date | Tue, 12 May 2015 21:39:39 -0400 |
| parents | ce0cf824c192 |
| children | f54901b9c39b |
comparison
equal
deleted
inserted
replaced
| 132:66b0263af424 | 142:6b5fbd7c3ece |
|---|---|
| 1 /* | |
| 2 player.c - functions for dealing with special player abilities | |
| 3 | |
| 4 XRogue: Expeditions into the Dungeons of Doom | |
| 5 Copyright (C) 1991 Robert Pietkivitch | |
| 6 All rights reserved. | |
| 7 | |
| 8 Based on "Advanced Rogue" | |
| 9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
| 10 All rights reserved. | |
| 11 | |
| 12 See the file LICENSE.TXT for full copyright and licensing information. | |
| 13 */ | |
| 14 | |
| 15 #include <ctype.h> | |
| 16 #include <string.h> | |
| 17 #include <curses.h> | |
| 18 #include "rogue.h" | |
| 19 | |
| 20 /* | |
| 21 * affect: | |
| 22 * cleric affecting undead | |
| 23 */ | |
| 24 | |
| 25 affect() | |
| 26 { | |
| 27 register struct linked_list *item; | |
| 28 register struct thing *tp; | |
| 29 register char *mname; | |
| 30 bool see; | |
| 31 coord new_pos; | |
| 32 int lvl; | |
| 33 | |
| 34 if (!(player.t_ctype == C_CLERIC || | |
| 35 (player.t_ctype == C_PALADIN && pstats.s_lvl > 4) || | |
| 36 cur_relic[HEIL_ANKH] != 0)) { | |
| 37 msg("You cannot affect undead."); | |
| 38 return; | |
| 39 } | |
| 40 | |
| 41 new_pos.y = hero.y + player.t_newpos.y; | |
| 42 new_pos.x = hero.x + player.t_newpos.x; | |
| 43 | |
| 44 if (cansee(new_pos.y, new_pos.x)) see = TRUE; | |
| 45 else see = FALSE; | |
| 46 | |
| 47 /* Anything there? */ | |
| 48 if (new_pos.y < 0 || new_pos.y > lines-3 || | |
| 49 new_pos.x < 0 || new_pos.x > cols-1 || | |
| 50 mvwinch(mw, new_pos.y, new_pos.x) == ' ') { | |
| 51 msg("Nothing to affect."); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 if ((item = find_mons(new_pos.y, new_pos.x)) == 0) { | |
| 56 debug("Affect what @ %d,%d?", new_pos.y, new_pos.x); | |
| 57 return; | |
| 58 } | |
| 59 tp = THINGPTR(item); | |
| 60 mname = monster_name(tp); | |
| 61 | |
| 62 if (on(player, ISINVIS) && off(*tp, CANSEE)) { | |
| 63 msg("%s%s cannot see you", see ? "The " : "It", | |
| 64 see ? mname : ""); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 if (off(*tp, TURNABLE) || on(*tp, WASTURNED)) | |
| 69 goto annoy; | |
| 70 turn_off(*tp, TURNABLE); | |
| 71 | |
| 72 lvl = pstats.s_lvl; | |
| 73 if (player.t_ctype == C_PALADIN && cur_relic[HEIL_ANKH] == 0) { | |
| 74 lvl -= 4; | |
| 75 } | |
| 76 /* Can cleric kill it? */ | |
| 77 if (lvl >= 3 * tp->t_stats.s_lvl) { | |
| 78 unsigned long test; /* For overflow check */ | |
| 79 | |
| 80 msg("You have destroyed %s%s.", see ? "the " : "it", see ? mname : ""); | |
| 81 test = pstats.s_exp + tp->t_stats.s_exp; | |
| 82 | |
| 83 /* Be sure there is no overflow before increasing experience */ | |
| 84 if (test > pstats.s_exp) pstats.s_exp = test; | |
| 85 killed(item, FALSE, TRUE, TRUE); | |
| 86 check_level(); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 90 /* Can cleric turn it? */ | |
| 91 if (rnd(100) + 1 > | |
| 92 (100 * ((2 * tp->t_stats.s_lvl) - lvl)) / lvl) { | |
| 93 unsigned long test; /* Overflow test */ | |
| 94 | |
| 95 /* Make the monster flee */ | |
| 96 turn_on(*tp, WASTURNED); /* No more fleeing after this */ | |
| 97 turn_on(*tp, ISFLEE); | |
| 98 runto(tp, &hero); | |
| 99 | |
| 100 /* Disrupt it */ | |
| 101 dsrpt_monster(tp, TRUE, TRUE); | |
| 102 | |
| 103 /* Let player know */ | |
| 104 msg("You have turned %s%s.", see ? "the " : "it", see ? mname : ""); | |
| 105 | |
| 106 /* get points for turning monster -- but check overflow first */ | |
| 107 test = pstats.s_exp + tp->t_stats.s_exp/2; | |
| 108 if (test > pstats.s_exp) pstats.s_exp = test; | |
| 109 check_level(); | |
| 110 | |
| 111 /* If monster was suffocating, stop it */ | |
| 112 if (on(*tp, DIDSUFFOCATE)) { | |
| 113 turn_off(*tp, DIDSUFFOCATE); | |
| 114 extinguish(suffocate); | |
| 115 } | |
| 116 | |
| 117 /* If monster held us, stop it */ | |
| 118 if (on(*tp, DIDHOLD) && (--hold_count == 0)) | |
| 119 turn_off(player, ISHELD); | |
| 120 turn_off(*tp, DIDHOLD); | |
| 121 | |
| 122 /* It is okay to turn tail */ | |
| 123 tp->t_oldpos = tp->t_pos; | |
| 124 | |
| 125 return; | |
| 126 } | |
| 127 | |
| 128 /* Otherwise -- no go */ | |
| 129 annoy: | |
| 130 if (see && tp->t_stats.s_intel > 16) | |
| 131 msg("%s laughs at you...", prname(mname, TRUE)); | |
| 132 else | |
| 133 msg("You do not affect %s%s.", see ? "the " : "it", see ? mname : ""); | |
| 134 | |
| 135 /* Annoy monster */ | |
| 136 if (off(*tp, ISFLEE)) runto(tp, &hero); | |
| 137 } | |
| 138 | |
| 139 /* | |
| 140 * the cleric asks his deity for a spell | |
| 141 */ | |
| 142 | |
| 143 pray() | |
| 144 { | |
| 145 register int num_prayers, prayer_ability, which_prayer; | |
| 146 | |
| 147 which_prayer = num_prayers = prayer_ability = 0; | |
| 148 | |
| 149 if (player.t_ctype != C_CLERIC && player.t_ctype != C_PALADIN && | |
| 150 cur_relic[HEIL_ANKH] == 0) { | |
| 151 msg("You are not permitted to pray."); | |
| 152 return; | |
| 153 } | |
| 154 if (cur_misc[WEAR_CLOAK] != NULL && | |
| 155 cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) { | |
| 156 msg("You can't seem to pray!"); | |
| 157 return; | |
| 158 } | |
| 159 | |
| 160 prayer_ability = pstats.s_lvl * pstats.s_wisdom - 5; | |
| 161 if (player.t_ctype != C_CLERIC) | |
| 162 prayer_ability /= 2; | |
| 163 | |
| 164 if (cur_relic[HEIL_ANKH]) prayer_ability += 75; | |
| 165 | |
| 166 if (player.t_action != C_PRAY) { | |
| 167 num_prayers = 0; | |
| 168 | |
| 169 /* Get the number of avilable prayers */ | |
| 170 if (pstats.s_wisdom > 16) | |
| 171 num_prayers += pstats.s_wisdom - 16; | |
| 172 | |
| 173 num_prayers += pstats.s_lvl; | |
| 174 if (cur_relic[HEIL_ANKH]) | |
| 175 num_prayers += pstats.s_wisdom - 18; | |
| 176 | |
| 177 if (player.t_ctype != C_CLERIC) | |
| 178 num_prayers /= 2; | |
| 179 | |
| 180 if (num_prayers > MAXPRAYERS) | |
| 181 num_prayers = MAXPRAYERS; | |
| 182 if (num_prayers < 1) { | |
| 183 msg("You are not permitted to pray yet."); | |
| 184 return; | |
| 185 } | |
| 186 | |
| 187 /* Prompt for prayer */ | |
| 188 if (pick_spell( cleric_spells, | |
| 189 prayer_ability, | |
| 190 num_prayers, | |
| 191 pray_time, | |
| 192 "offer", | |
| 193 "prayer")) | |
| 194 player.t_action = C_PRAY; | |
| 195 | |
| 196 return; | |
| 197 } | |
| 198 | |
| 199 /* We've waited our required praying time. */ | |
| 200 which_prayer = player.t_selection; | |
| 201 player.t_selection = 0; | |
| 202 player.t_action = A_NIL; | |
| 203 | |
| 204 if (cleric_spells[which_prayer].s_cost + pray_time > prayer_ability) { | |
| 205 msg("Your prayer fails."); | |
| 206 return; | |
| 207 } | |
| 208 | |
| 209 msg("Your prayer has been granted. "); | |
| 210 | |
| 211 if (cleric_spells[which_prayer].s_type == TYP_POTION) | |
| 212 quaff( cleric_spells[which_prayer].s_which, | |
| 213 NULL, | |
| 214 cleric_spells[which_prayer].s_flag, | |
| 215 FALSE); | |
| 216 else if (cleric_spells[which_prayer].s_type == TYP_SCROLL) | |
| 217 read_scroll( cleric_spells[which_prayer].s_which, | |
| 218 cleric_spells[which_prayer].s_flag, | |
| 219 FALSE); | |
| 220 else if (cleric_spells[which_prayer].s_type == TYP_STICK) { | |
| 221 if (!player_zap(cleric_spells[which_prayer].s_which, | |
| 222 cleric_spells[which_prayer].s_flag)) { | |
| 223 after = FALSE; | |
| 224 return; | |
| 225 } | |
| 226 } | |
| 227 pray_time += cleric_spells[which_prayer].s_cost; | |
| 228 } | |
| 229 | |
| 230 /* | |
| 231 * the magician is going to try and cast a spell | |
| 232 */ | |
| 233 | |
| 234 cast() | |
| 235 { | |
| 236 register int spell_ability, which_spell, num_spells; | |
| 237 | |
| 238 if (player.t_ctype != C_MAGICIAN && player.t_ctype != C_RANGER) { | |
| 239 msg("You are not permitted to cast spells."); | |
| 240 return; | |
| 241 } | |
| 242 if (cur_misc[WEAR_CLOAK] != NULL && | |
| 243 cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) { | |
| 244 msg("You can't seem to cast spells!"); | |
| 245 return; | |
| 246 } | |
| 247 spell_ability = pstats.s_lvl * pstats.s_intel - 5; | |
| 248 if (player.t_ctype != C_MAGICIAN) | |
| 249 spell_ability /= 2; | |
| 250 | |
| 251 if (player.t_action != C_CAST) { | |
| 252 /* | |
| 253 * Get the number of avilable spells | |
| 254 */ | |
| 255 num_spells = 0; | |
| 256 if (pstats.s_intel > 16) | |
| 257 num_spells += pstats.s_intel - 16; | |
| 258 | |
| 259 num_spells += pstats.s_lvl; | |
| 260 if (player.t_ctype != C_MAGICIAN) | |
| 261 num_spells /= 2; | |
| 262 if (num_spells > MAXSPELLS) | |
| 263 num_spells = MAXSPELLS; | |
| 264 if (num_spells < 1) { | |
| 265 msg("You are not allowed to cast spells yet."); | |
| 266 return; | |
| 267 } | |
| 268 | |
| 269 /* prompt for spell */ | |
| 270 if (pick_spell( magic_spells, | |
| 271 spell_ability, | |
| 272 num_spells, | |
| 273 spell_power, | |
| 274 "cast", | |
| 275 "spell")) | |
| 276 player.t_action = C_CAST; | |
| 277 return; | |
| 278 } | |
| 279 | |
| 280 /* We've waited our required casting time. */ | |
| 281 which_spell = player.t_selection; | |
| 282 player.t_selection = 0; | |
| 283 player.t_action = A_NIL; | |
| 284 | |
| 285 if ((spell_power + magic_spells[which_spell].s_cost) > spell_ability) { | |
| 286 msg("Your attempt fails."); | |
| 287 return; | |
| 288 } | |
| 289 | |
| 290 msg("Your spell is successful. "); | |
| 291 | |
| 292 if (magic_spells[which_spell].s_type == TYP_POTION) | |
| 293 quaff( magic_spells[which_spell].s_which, | |
| 294 NULL, | |
| 295 magic_spells[which_spell].s_flag, | |
| 296 FALSE); | |
| 297 else if (magic_spells[which_spell].s_type == TYP_SCROLL) | |
| 298 read_scroll( magic_spells[which_spell].s_which, | |
| 299 magic_spells[which_spell].s_flag, | |
| 300 FALSE); | |
| 301 else if (magic_spells[which_spell].s_type == TYP_STICK) { | |
| 302 if (!player_zap(magic_spells[which_spell].s_which, | |
| 303 magic_spells[which_spell].s_flag)) { | |
| 304 after = FALSE; | |
| 305 return; | |
| 306 } | |
| 307 } | |
| 308 spell_power += magic_spells[which_spell].s_cost; | |
| 309 } | |
| 310 | |
| 311 /* | |
| 312 * the druid asks his deity for a spell | |
| 313 */ | |
| 314 | |
| 315 chant() | |
| 316 { | |
| 317 register int num_chants, chant_ability, which_chant; | |
| 318 | |
| 319 which_chant = num_chants = chant_ability = 0; | |
| 320 | |
| 321 if (player.t_ctype != C_DRUID && player.t_ctype != C_MONK) { | |
| 322 msg("You are not permitted to chant."); | |
| 323 return; | |
| 324 } | |
| 325 if (cur_misc[WEAR_CLOAK] != NULL && | |
| 326 cur_misc[WEAR_CLOAK]->o_which == MM_R_POWERLESS) { | |
| 327 msg("You can't seem to chant!"); | |
| 328 return; | |
| 329 } | |
| 330 chant_ability = pstats.s_lvl * pstats.s_wisdom - 5; | |
| 331 if (player.t_ctype != C_DRUID) | |
| 332 chant_ability /= 2; | |
| 333 | |
| 334 if (player.t_action != C_CHANT) { | |
| 335 num_chants = 0; | |
| 336 | |
| 337 /* Get the number of avilable chants */ | |
| 338 if (pstats.s_wisdom > 16) | |
| 339 num_chants += pstats.s_wisdom - 16; | |
| 340 | |
| 341 num_chants += pstats.s_lvl; | |
| 342 | |
| 343 if (player.t_ctype != C_DRUID) | |
| 344 num_chants /= 2; | |
| 345 | |
| 346 if (num_chants > MAXCHANTS) | |
| 347 num_chants = MAXCHANTS; | |
| 348 | |
| 349 if (num_chants < 1) { | |
| 350 msg("You are not permitted to chant yet."); | |
| 351 return; | |
| 352 } | |
| 353 | |
| 354 /* Prompt for chant */ | |
| 355 if (pick_spell( druid_spells, | |
| 356 chant_ability, | |
| 357 num_chants, | |
| 358 chant_time, | |
| 359 "sing", | |
| 360 "chant")) | |
| 361 player.t_action = C_CHANT; | |
| 362 | |
| 363 return; | |
| 364 } | |
| 365 | |
| 366 /* We've waited our required chanting time. */ | |
| 367 which_chant = player.t_selection; | |
