root/trunk/src/xtra1.c

Revision 904, 39.9 kB (checked in by takkaria, 7 hours ago)

Add AFRAID flag, which induces perma-fear.

Line 
1 /*
2  * File: xtra1.c
3  * Purpose: Player status calculation, signalling ui events based on status
4  *          changes.
5  *
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This work is free software; you can redistribute it and/or modify it
9  * under the terms of either:
10  *
11  * a) the GNU General Public License as published by the Free Software
12  *    Foundation, version 2, or
13  *
14  * b) the "Angband licence":
15  *    This software may be copied and distributed for educational, research,
16  *    and not for profit purposes provided that this copyright and statement
17  *    are included in all such copies.  Other copyrights may also apply.
18  */
19 #include "angband.h"
20 #include "game-event.h"
21 #include "tvalsval.h"
22
23
24 struct flag_event_trigger
25 {
26         u32b flag;
27         game_event_type event;
28 };
29
30 /*
31  * Modify a stat value by a "modifier", return new value
32  *
33  * Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
34  * Or even: 18/13, 18/23, 18/33, ..., 18/220
35  *
36  * Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
37  * Or even: 18/13, 18/03, 18, 17, ..., 3
38  */
39 s16b modify_stat_value(int value, int amount)
40 {
41         int i;
42
43         /* Reward */
44         if (amount > 0)
45         {
46                 /* Apply each point */
47                 for (i = 0; i < amount; i++)
48                 {
49                         /* One point at a time */
50                         if (value < 18) value++;
51
52                         /* Ten "points" at a time */
53                         else value += 10;
54                 }
55         }
56
57         /* Penalty */
58         else if (amount < 0)
59         {
60                 /* Apply each point */
61                 for (i = 0; i < (0 - amount); i++)
62                 {
63                         /* Ten points at a time */
64                         if (value >= 18+10) value -= 10;
65
66                         /* Hack -- prevent weirdness */
67                         else if (value > 18) value = 18;
68
69                         /* One point at a time */
70                         else if (value > 3) value--;
71                 }
72         }
73
74         /* Return new value */
75         return (value);
76 }
77
78
79 /*
80  * Calculate number of spells player should have, and forget,
81  * or remember, spells until that number is properly reflected.
82  *
83  * Note that this function induces various "status" messages,
84  * which must be bypasses until the character is created.
85  */
86 static void calc_spells(void)
87 {
88         int i, j, k, levels;
89         int num_allowed, num_known;
90         int percent_spells;
91
92         const magic_type *s_ptr;
93
94         s16b old_spells;
95
96         cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer");
97
98
99         /* Hack -- must be literate */
100         if (!cp_ptr->spell_book) return;
101
102         /* Hack -- wait for creation */
103         if (!character_generated) return;
104
105         /* Hack -- handle "xtra" mode */
106         if (character_xtra) return;
107
108         /* Save the new_spells value */
109         old_spells = p_ptr->new_spells;
110
111
112         /* Determine the number of spells allowed */
113         levels = p_ptr->lev - cp_ptr->spell_first + 1;
114
115         /* Hack -- no negative spells */
116         if (levels < 0) levels = 0;
117
118         /* Number of 1/100 spells per level */
119         percent_spells = adj_mag_study[p_ptr->stat_ind[cp_ptr->spell_stat]];
120
121         /* Extract total allowed spells (rounded up) */
122         num_allowed = (((percent_spells * levels) + 50) / 100);
123
124         /* Assume none known */
125         num_known = 0;
126
127         /* Count the number of spells we know */
128         for (j = 0; j < PY_MAX_SPELLS; j++)
129         {
130                 /* Count known spells */
131                 if (p_ptr->spell_flags[j] & PY_SPELL_LEARNED)
132                 {
133                         num_known++;
134                 }
135         }
136
137         /* See how many spells we must forget or may learn */
138         p_ptr->new_spells = num_allowed - num_known;
139
140
141
142         /* Forget spells which are too hard */
143         for (i = PY_MAX_SPELLS - 1; i >= 0; i--)
144         {
145                 /* Get the spell */
146                 j = p_ptr->spell_order[i];
147
148                 /* Skip non-spells */
149                 if (j >= 99) continue;
150
151                 /* Get the spell */
152                 s_ptr = &mp_ptr->info[j];
153
154                 /* Skip spells we are allowed to know */
155                 if (s_ptr->slevel <= p_ptr->lev) continue;
156
157                 /* Is it known? */
158                 if (p_ptr->spell_flags[j] & PY_SPELL_LEARNED)
159                 {
160                         /* Mark as forgotten */
161                         p_ptr->spell_flags[j] |= PY_SPELL_FORGOTTEN;
162
163                         /* No longer known */
164                         p_ptr->spell_flags[j] &= ~PY_SPELL_LEARNED;
165
166                         /* Message */
167                         msg_format("You have forgotten the %s of %s.", p,
168                                    get_spell_name(cp_ptr->spell_book, j));
169
170                         /* One more can be learned */
171                         p_ptr->new_spells++;
172                 }
173         }
174
175
176         /* Forget spells if we know too many spells */
177         for (i = PY_MAX_SPELLS - 1; i >= 0; i--)
178         {
179                 /* Stop when possible */
180                 if (p_ptr->new_spells >= 0) break;
181
182                 /* Get the (i+1)th spell learned */
183                 j = p_ptr->spell_order[i];
184
185                 /* Skip unknown spells */
186                 if (j >= 99) continue;
187
188                 /* Forget it (if learned) */
189                 if (p_ptr->spell_flags[j] & PY_SPELL_LEARNED)
190                 {
191                         /* Mark as forgotten */
192                         p_ptr->spell_flags[j] |= PY_SPELL_FORGOTTEN;
193
194                         /* No longer known */
195                         p_ptr->spell_flags[j] &= ~PY_SPELL_LEARNED;
196
197                         /* Message */
198                         msg_format("You have forgotten the %s of %s.", p,
199                                    get_spell_name(cp_ptr->spell_book, j));
200
201                         /* One more can be learned */
202                         p_ptr->new_spells++;
203                 }
204         }
205
206
207         /* Check for spells to remember */
208         for (i = 0; i < PY_MAX_SPELLS; i++)
209         {
210                 /* None left to remember */
211                 if (p_ptr->new_spells <= 0) break;
212
213                 /* Get the next spell we learned */
214                 j = p_ptr->spell_order[i];
215
216                 /* Skip unknown spells */
217                 if (j >= 99) break;
218
219                 /* Get the spell */
220                 s_ptr = &mp_ptr->info[j];
221
222                 /* Skip spells we cannot remember */
223                 if (s_ptr->slevel > p_ptr->lev) continue;
224
225                 /* First set of spells */
226                 if (p_ptr->spell_flags[j] & PY_SPELL_FORGOTTEN)
227                 {
228                         /* No longer forgotten */
229                         p_ptr->spell_flags[j] &= ~PY_SPELL_FORGOTTEN;
230
231                         /* Known once more */
232                         p_ptr->spell_flags[j] |= PY_SPELL_LEARNED;
233
234                         /* Message */
235                         msg_format("You have remembered the %s of %s.",
236                                    p, get_spell_name(cp_ptr->spell_book, j));
237
238                         /* One less can be learned */
239                         p_ptr->new_spells--;
240                 }
241         }
242
243
244         /* Assume no spells available */
245         k = 0;
246
247         /* Count spells that can be learned */
248         for (j = 0; j < PY_MAX_SPELLS; j++)
249         {
250                 /* Get the spell */
251                 s_ptr = &mp_ptr->info[j];
252
253                 /* Skip spells we cannot remember */
254                 if (s_ptr->slevel > p_ptr->lev) continue;
255
256                 /* Skip spells we already know */
257                 if (p_ptr->spell_flags[j] & PY_SPELL_LEARNED)
258                 {
259                         continue;
260                 }
261
262                 /* Count it */
263                 k++;
264         }
265
266         /* Cannot learn more spells than exist */
267         if (p_ptr->new_spells > k) p_ptr->new_spells = k;
268
269         /* Spell count changed */
270         if (old_spells != p_ptr->new_spells)
271         {
272                 /* Message if needed */
273                 if (p_ptr->new_spells)
274                 {
275                         /* Message */
276                         msg_format("You can learn %d more %s%s.",
277                                    p_ptr->new_spells, p,
278                                    (p_ptr->new_spells != 1) ? "s" : "");
279                 }
280
281                 /* Redraw Study Status */
282                 p_ptr->redraw |= (PR_STUDY | PR_OBJECT);
283         }
284 }
285
286
287 /*
288  * Calculate maximum mana.  You do not need to know any spells.
289  * Note that mana is lowered by heavy (or inappropriate) armor.
290  *
291  * This function induces status messages.
292  */
293 static void calc_mana(void)
294 {
295         int msp, levels, cur_wgt, max_wgt;
296
297         object_type *o_ptr;
298
299         bool old_cumber_glove = p_ptr->cumber_glove;
300         bool old_cumber_armor = p_ptr->cumber_armor;
301
302         /* Hack -- Must be literate */
303         if (!cp_ptr->spell_book) return;
304
305
306         /* Extract "effective" player level */
307         levels = (p_ptr->lev - cp_ptr->spell_first) + 1;
308         if (levels > 0)
309         {
310                 msp = 1;
311                 msp += adj_mag_mana[p_ptr->stat_ind[cp_ptr->spell_stat]] * levels / 100;
312         }
313         else
314         {
315                 levels = 0;
316                 msp = 0;
317         }
318
319         /* Process gloves for those disturbed by them */
320         if (cp_ptr->flags & CF_CUMBER_GLOVE)
321         {
322                 u32b f1, f2, f3;
323
324                 /* Assume player is not encumbered by gloves */
325                 p_ptr->cumber_glove = FALSE;
326
327                 /* Get the gloves */
328                 o_ptr = &inventory[INVEN_HANDS];
329
330                 /* Examine the gloves */
331                 object_flags(o_ptr, &f1, &f2, &f3);
332
333                 /* Normal gloves hurt mage-type spells */
334                 if (o_ptr->k_idx &&
335                     !(f3 & (TR3_FREE_ACT)) &&
336                     !((f1 & (TR1_DEX)) && (o_ptr->pval > 0)))
337                 {
338                         /* Encumbered */
339                         p_ptr->cumber_glove = TRUE;
340
341                         /* Reduce mana */
342                         msp = (3 * msp) / 4;
343                 }
344         }
345
346
347         /* Assume player not encumbered by armor */
348         p_ptr->cumber_armor = FALSE;
349
350         /* Weigh the armor */
351         cur_wgt = 0;
352         cur_wgt += inventory[INVEN_BODY].weight;
353         cur_wgt += inventory[INVEN_HEAD].weight;
354         cur_wgt += inventory[INVEN_ARM].weight;
355         cur_wgt += inventory[INVEN_OUTER].weight;
356         cur_wgt += inventory[INVEN_HANDS].weight;
357         cur_wgt += inventory[INVEN_FEET].weight;
358
359         /* Determine the weight allowance */
360         max_wgt = cp_ptr->spell_weight;
361
362         /* Heavy armor penalizes mana */
363         if (((cur_wgt - max_wgt) / 10) > 0)
364         {
365                 /* Encumbered */
366                 p_ptr->cumber_armor = TRUE;
367
368                 /* Reduce mana */
369                 msp -= ((cur_wgt - max_wgt) / 10);
370         }
371
372
373         /* Mana can never be negative */
374         if (msp < 0) msp = 0;
375
376
377         /* Maximum mana has changed */
378         if (p_ptr->msp != msp)
379         {
380                 /* Save new limit */
381                 p_ptr->msp = msp;
382
383                 /* Enforce new limit */
384                 if (p_ptr->csp >= msp)
385                 {
386                         p_ptr->csp = msp;
387                         p_ptr->csp_frac = 0;
388                 }
389
390                 /* Display mana later */
391                 p_ptr->redraw |= (PR_MANA);
392         }
393
394
395         /* Hack -- handle "xtra" mode */
396         if (character_xtra) return;
397
398         /* Take note when "glove state" changes */
399         if (old_cumber_glove != p_ptr->cumber_glove)
400         {
401                 /* Message */
402                 if (p_ptr->cumber_glove)
403                 {
404                         msg_print("Your covered hands feel unsuitable for spellcasting.");
405                 }
406                 else
407                 {
408                         msg_print("Your hands feel more suitable for spellcasting.");
409                 }
410         }
411
412
413         /* Take note when "armor state" changes */
414         if (old_cumber_armor != p_ptr->cumber_armor)
415         {
416                 /* Message */
417                 if (p_ptr->cumber_armor)
418                 {
419                         msg_print("The weight of your armor encumbers your movement.");
420                 }
421                 else
422                 {
423                         msg_print("You feel able to move more freely.");
424                 }
425         }
426 }
427
428
429 /*
430  * Calculate the players (maximal) hit points
431  *
432  * Adjust current hitpoints if necessary
433  */
434 static void calc_hitpoints(void)
435 {
436         long bonus;
437         int mhp;
438
439         /* Get "1/100th hitpoint bonus per level" value */
440         bonus = adj_con_mhp[p_ptr->stat_ind[A_CON]];
441
442         /* Calculate hitpoints */
443         mhp = p_ptr->player_hp[p_ptr->lev-1] + (bonus * p_ptr->lev / 100);
444
445         /* Always have at least one hitpoint per level */
446         if (mhp < p_ptr->lev + 1) mhp = p_ptr->lev + 1;
447
448         /* New maximum hitpoints */
449         if (p_ptr->mhp != mhp)
450         {
451                 /* Save new limit */
452                 p_ptr->mhp = mhp;
453
454                 /* Enforce new limit */
455                 if (p_ptr->chp >= mhp)
456                 {
457                         p_ptr->chp = mhp;
458                         p_ptr->chp_frac = 0;
459                 }
460
461                 /* Display hitpoints (later) */
462                 p_ptr->redraw |= (PR_HP);
463         }
464 }
465
466
467 /*
468  * Calculate and set the current light radius.
469  *
470  * The brightest wielded object counts as the light source; radii do not add
471  * up anymore.
472  *
473  * Note that a cursed light source no longer emits light.
474  */
475 static void calc_torch(void)
476 {
477         int i;
478
479         s16b old_lite = p_ptr->cur_lite;
480         bool burn_light = TRUE;
481
482         s16b new_lite = 0;
483         int extra_lite = 0;
484
485
486
487         /* Ascertain lightness if in the town */
488         if (!p_ptr->depth && ((turn % (10L * TOWN_DAWN)) < ((10L * TOWN_DAWN) / 2)))
489                 burn_light = FALSE;
490
491
492         /* Examine all wielded objects, use the brightest */
493         for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
494         {
495                 u32b f1, f2, f3;
496
497                 int amt = 0;
498                 object_type *o_ptr = &inventory[i];
499
500                 /* Skip empty slots */
501                 if (!o_ptr->k_idx) continue;
502
503                 /* Extract the flags */
504                 object_flags(o_ptr, &f1, &f2, &f3);
505
506                 /* Cursed objects emit no light */
507                 if (f3 & TR3_LIGHT_CURSE)
508                 {
509                         amt = 0;
510                 }
511
512                 /* Examine actual lites */
513                 else if (o_ptr->tval == TV_LITE)
514                 {
515                         int flag_inc = (f3 & TR3_LITE) ? 1 : 0;
516
517                         /* Artifact Lites provide permanent bright light */
518                         if (artifact_p(o_ptr))
519                                 amt = 3 + flag_inc;
520
521                         /* Non-artifact lights and those without fuel provide no light */
522                         else if (!burn_light || o_ptr->timeout == 0)
523                                 amt = 0;
524
525                         /* All lit lights provide at least radius 2 light */
526                         else
527                         {
528                                 amt = 2 + flag_inc;
529
530                                 /* Torches below half fuel provide less light */
531                                 if (o_ptr->sval == SV_LITE_TORCH && o_ptr->timeout < (FUEL_TORCH / 4))
532                                     amt--;
533                         }
534                 }
535
536                 else
537                 {
538                         /* LITE flag on an non-cursed non-lights always increases radius */
539                         if (f3 & TR3_LITE) extra_lite++;
540                 }
541
542                 /* Alter p_ptr->cur_lite if reasonable */
543                 if (new_lite < amt)
544                     new_lite = amt;
545         }
546
547         /* Add bonus from LITE flags */
548         new_lite += extra_lite;
549
550         /* Limit light */
551         new_lite = MIN(new_lite, 5);
552         new_lite = MAX(new_lite, 0);
553
554         /* Notice changes in the "lite radius" */
555         if (old_lite != new_lite)
556         {
557                 /* Update the visuals */
558                 p_ptr->cur_lite = new_lite;
559                 p_ptr->update |= (PU_UPDATE_VIEW | PU_MONSTERS);
560         }
561 }
562
563 /*
564  * Calculate the blows a player would get, in current condition, wielding "o_ptr".
565  */
566 int calc_blows(const object_type *o_ptr)
567 {
568         int blows;
569         int str_index1, str_index2, dex_index1, dex_index2;
570         int div;
571        
572         object_type *j_ptr = &inventory[INVEN_WIELD];
573
574         /* Enforce a minimum "weight" (tenth pounds) */
575         div = ((o_ptr->weight < cp_ptr->min_weight) ? cp_ptr->min_weight : o_ptr->weight);
576
577         /* If we're wielding this weapon, use the current stats */
578         if (o_ptr == j_ptr)
579         {
580                 str_index1 = p_ptr->stat_ind[A_STR];
581                 dex_index1 = p_ptr->stat_ind[A_DEX];
582         }
583         else
584         {
585                 /* Recalculate bonuses as if we were wielding this weapon */
586                
587                 int str_change = 0, dex_change = 0;
588                 int new_str = p_ptr->stat_use[A_STR];
589                 int new_dex = p_ptr->stat_use[A_DEX];
590                
591                 /* object_type *j_ptr = &inventory[INVEN_WIELD]; */
592                
593                 u32b jf1, jf2, jf3;
594                 u32b of1, of2, of3;
595                
596                 /* Examine the wielded weapon */
597                 object_flags(j_ptr, &jf1, &jf2, &jf3);
598                 if (jf1 & (TR1_STR)) str_change -= j_ptr->pval;
599                 if (jf1 & (TR1_DEX)) dex_change -= j_ptr->pval;
600
601                 /* Examine the weapon in the pack*/
602                 object_flags(o_ptr, &of1, &of2, &of3);
603                 if (of1 & (TR1_STR)) str_change += o_ptr->pval;
604                 if (of1 & (TR1_DEX)) dex_change += o_ptr->pval;
605
606                 new_str = modify_stat_value(new_str, str_change);
607                 new_dex = modify_stat_value(new_dex, dex_change);
608                
609                 if (new_str <= 18)
610                         str_index1 = new_str - 3;
611                 else if (new_str <= 18+219)
612                         str_index1 = (15 + (new_str - 18) / 10);
613                 else
614                         str_index1 = 37;
615                        
616                 if (new_dex <= 18)
617                         dex_index1 = new_dex - 3;
618                 else if (new_dex <= 18+219)
619                         dex_index1 = (15 + (new_dex - 18) / 10);
620                 else
621                         dex_index1 = 37;
622         }
623        
624
625         /* Get the strength vs weight */
626         str_index2 = (adj_str_blow[str_index1] * cp_ptr->att_multiply / div);
627
628         /* Maximal value */
629         if (str_index2 > 11) str_index2 = 11;
630
631         /* Index by dexterity */
632         dex_index2 = MIN(adj_dex_blow[dex_index1], 11);
633
634         /* Use the blows table */
635         blows = MIN(blows_table[str_index2][dex_index2], cp_ptr->max_attacks);
636
637         /* Require at least one blow */
638         return MAX(blows, 1);
639 }
640
641
642 /*
643  * Computes current weight limit.
644  */
645 static int weight_limit(void)
646 {
647         int i;
648
649         /* Weight limit based only on strength */
650         i = adj_str_wgt[p_ptr->stat_ind[A_STR]] * 100;
651
652         /* Return the result */
653         return (i);
654 }
655
656
657 /*
658  * Calculate the players current "state", taking into account
659  * not only race/class intrinsics, but also objects being worn
660  * and temporary spell effects.
661  *
662  * See also calc_mana() and calc_hitpoints().
663  *
664  * Take note of the new "speed code", in particular, a very strong
665  * player will start slowing down as soon as he reaches 150 pounds,
666  * but not until he reaches 450 pounds will he be half as fast as
667  * a normal kobold.  This both hurts and helps the player, hurts
668  * because in the old days a player could just avoid 300 pounds,
669  * and helps because now carrying 300 pounds is not very painful.
670  *
671  * The "weapon" and "bow" do *not* add to the bonuses to hit or to
672  * damage, since that would affect non-combat things.  These values
673  * are actually added in later, at the appropriate place.
674  *
675  * This function induces various "status" messages.
676  */
677 static void calc_bonuses(void)
678 {
679         int i, j, hold;
680
681         int old_speed;
682
683         int old_telepathy;
684         int old_see_inv;
685
686         int old_dis_ac;
687         int old_dis_to_a;
688
689         int extra_blows;
690         int extra_shots;
691         int extra_might;
692
693         int old_stat_top[A_MAX];
694         int old_stat_use[A_MAX];
695         int old_stat_ind[A_MAX];
696
697         bool old_heavy_shoot;
698         bool old_heavy_wield;
699         bool old_icky_wield;
700
701         object_type *o_ptr;
702
703         u32b f1, f2, f3;
704
705
706         /*** Memorize ***/
707
708         /* Save the old speed */
709         old_speed = p_ptr->pspeed;
710
711         /* Save the old vision stuff */
712         old_telepathy = p_ptr->telepathy;
713         old_see_inv = p_ptr->see_inv;
714
715         /* Save the old armor class */
716         old_dis_ac = p_ptr->dis_ac;
717         old_dis_to_a = p_ptr->dis_to_a;
718
719         /* Save the old stats */
720         for (i = 0; i < A_MAX; i++)
721         {
722                 old_stat_top[i] = p_ptr->stat_top[i];
723                 old_stat_use[i] = p_ptr->stat_use[i];
724                 old_stat_ind[i] = p_ptr->stat_ind[i];
725         }
726
727         old_heavy_shoot = p_ptr->heavy_shoot;
728         old_heavy_wield = p_ptr->heavy_wield;
729         old_icky_wield = p_ptr->icky_wield;
730
731
732         /*** Reset ***/
733
734         /* Reset player speed */
735         p_ptr->pspeed = 110;
736
737         /* Reset "blow" info */
738         p_ptr->num_blow = 1;
739         extra_blows = 0;
740
741         /* Reset "fire" info */
742         p_ptr->num_fire = 0;
743         p_ptr->ammo_mult = 0;
744         p_ptr->ammo_tval = 0;
745         extra_shots = 0;
746         extra_might = 0;
747
748         /* Clear the stat modifiers */
749         for (i = 0; i < A_MAX; i++) p_ptr->stat_add[i] = 0;
750
751         /* Clear the Displayed/Real armor class */
752         p_ptr->dis_ac = p_ptr->ac = 0;
753
754         /* Clear the Displayed/Real Bonuses */
755         p_ptr->dis_to_h = p_ptr->to_h = 0;
756         p_ptr->dis_to_d = p_ptr->to_d = 0;
757         p_ptr->dis_to_a = p_ptr->to_a = 0;
758
759         /* Clear all the flags */
760         p_ptr->aggravate = FALSE;
761         p_ptr->teleport = FALSE;
762         p_ptr->exp_drain = FALSE;
763         p_ptr->bless_blade = FALSE;
764         p_ptr->impact = FALSE;
765         p_ptr->see_inv = FALSE;
766         p_ptr->free_act = FALSE;
767         p_ptr->slow_digest = FALSE;
768         p_ptr->impair_hp = FALSE;
769         p_ptr->impair_mana = FALSE;
770         p_ptr->regenerate = FALSE;
771         p_ptr->ffall = FALSE;
772         p_ptr->hold_life = FALSE;
773         p_ptr->afraid = FALSE;
774         p_ptr->telepathy = FALSE;
775         p_ptr->sustain_str = FALSE;
776         p_ptr->sustain_int = FALSE;
777         p_ptr->sustain_wis = FALSE;
778         p_ptr->sustain_con = FALSE;
779         p_ptr->sustain_dex = FALSE;
780         p_ptr->sustain_chr = FALSE;
781         p_ptr->resist_acid = FALSE;
782         p_ptr->resist_elec = FALSE;
783         p_ptr->resist_fire = FALSE;
784         p_ptr->resist_cold = FALSE;
785         p_ptr->resist_pois = FALSE;
786         p_ptr->resist_fear = FALSE;
787         p_ptr->resist_lite = FALSE;
788         p_ptr->resist_dark = FALSE;
789         p_ptr->resist_blind = FALSE;
790         p_ptr->resist_confu = FALSE;
791         p_ptr->resist_sound = FALSE;
792         p_ptr->resist_chaos = FALSE;
793         p_ptr->resist_disen = FALSE;
794         p_ptr->resist_shard = FALSE;
795         p_ptr->resist_nexus = FALSE;
796         p_ptr->resist_nethr = FALSE;
797         p_ptr->immune_acid = FALSE;
798         p_ptr->immune_elec = FALSE;
799         p_ptr->immune_fire = FALSE;
800         p_ptr->immune_cold = FALSE;
801         p_ptr->vuln_acid = FALSE;
802         p_ptr->vuln_elec = FALSE;
803         p_ptr->vuln_fire = FALSE;
804         p_ptr->vuln_cold = FALSE;
805
806
807         /*** Extract race/class info ***/
808
809         /* Base infravision (purely racial) */
810         p_ptr->see_infra = rp_ptr->infra;
811
812         /* Base skills */
813         for (i = 0; i < SKILL_MAX_NO_RACE_CLASS; i++)
814         {
815                 p_ptr->skills[i] = rp_ptr->r_skills[i] + cp_ptr->c_skills[i];
816         }
817
818         /* Base skill -- combat (throwing) */
819         p_ptr->skills[SKILL_TO_HIT_THROW] = p_ptr->skills[SKILL_TO_HIT_BOW];
820
821         /* Base skill -- digging */
822         p_ptr->skills[SKILL_DIGGING] = 0;
823
824         /*** Analyze player ***/
825
826         /* Extract the player flags */
827         player_flags(&f1, &f2, &f3);
828
829         /* Good flags */
830         if (f3 & (TR3_SLOW_DIGEST)) p_ptr->slow_digest = TRUE;
831         if (f3 & (TR3_FEATHER)) p_ptr->ffall = TRUE;
832         if (f3 & (TR3_REGEN)) p_ptr->regenerate = TRUE;
833         if (f3 & (TR3_TELEPATHY)) p_ptr->telepathy = TRUE;
834         if (f3 & (TR3_SEE_INVIS)) p_ptr->see_inv = TRUE;
835         if (f3 & (TR3_FREE_ACT)) p_ptr->free_act = TRUE;
836         if (f3 & (TR3_HOLD_LIFE)) p_ptr->hold_life = TRUE;
837
838         /* Weird flags */
839         if (f3 & (TR3_BLESSED)) p_ptr->bless_blade = TRUE;
840
841         /* Bad flags */
842         if (f3 & (TR3_IMPACT)) p_ptr->impact = TRUE;
843         if (f3 & (TR3_AGGRAVATE)) p_ptr->aggravate = TRUE;
844         if (f3 & (TR3_TELEPORT)) p_ptr->teleport = TRUE;
845         if (f3 & (TR3_DRAIN_EXP)) p_ptr->exp_drain = TRUE;
846         if (f3 & (TR3_IMPAIR_HP)) p_ptr->impair_hp = TRUE;
847         if (f3 & (TR3_IMPAIR_MANA)) p_ptr->impair_mana = TRUE;
848         if (f3 & (TR3_AFRAID)) p_ptr->afraid = TRUE;
849
850         /* Vulnerability flags */
851         if (f2 & (TR2_VULN_FIRE)) p_ptr->vuln_fire = TRUE;
852         if (f2 & (TR2_VULN_ACID)) p_ptr->vuln_acid = TRUE;
853         if (f2 & (TR2_VULN_COLD)) p_ptr->vuln_cold = TRUE;
854         if (f2 & (TR2_VULN_ELEC)) p_ptr->vuln_elec = TRUE;
855
856         /* Immunity flags */
857         if (f2 & (TR2_IM_FIRE)) p_ptr->immune_fire = TRUE;
858         if (f2 & (TR2_IM_ACID)) p_ptr->immune_acid = TRUE;
859         if (f2 & (TR2_IM_COLD)) p_ptr->immune_cold = TRUE;
860         if (f2 & (TR2_IM_ELEC)) p_ptr->immune_elec = TRUE;
861
862         /* Resistance flags */
863         if (f2 & (TR2_RES_ACID)) p_ptr->resist_acid = TRUE;
864         if (f2 & (TR2_RES_ELEC)) p_ptr->resist_elec = TRUE;
865         if (f2 & (TR2_RES_FIRE)) p_ptr->resist_fire = TRUE;
866         if (f2 & (TR2_RES_COLD)) p_ptr->resist_cold = TRUE;
867         if (f2 & (TR2_RES_POIS)) p_ptr->resist_pois = TRUE;
868         if (f2 & (TR2_RES_FEAR)) p_ptr->resist_fear = TRUE;
869         if (f2 & (TR2_RES_LITE)) p_ptr->resist_lite = TRUE;
870         if (f2 & (TR2_RES_DARK)) p_ptr->resist_dark = TRUE;
871         if (f2 & (TR2_RES_BLIND)) p_ptr->resist_blind = TRUE;
872         if (f2 & (TR2_RES_CONFU)) p_ptr->resist_confu = TRUE;
873         if (f2 & (TR2_RES_SOUND)) p_ptr->resist_sound = TRUE;
874         if (f2 & (TR2_RES_SHARD)) p_ptr->resist_shard = TRUE;
875         if (f2 & (TR2_RES_NEXUS)) p_ptr->resist_nexus = TRUE;
876         if (f2 & (TR2_RES_NETHR)) p_ptr->resist_nethr = TRUE;
877         if (f2 & (TR2_RES_CHAOS)) p_ptr->resist_chaos = TRUE;
878         if (f2 & (TR2_RES_DISEN)) p_ptr->resist_disen = TRUE;
879
880         /* Sustain flags */
881         if (f2 & (TR2_SUST_STR)) p_ptr->sustain_str = TRUE;
882         if (f2 & (TR2_SUST_INT)) p_ptr->sustain_int = TRUE;
883         if (f2 & (TR2_SUST_WIS)) p_ptr->sustain_wis = TRUE;
884         if (f2 & (TR2_SUST_DEX)) p_ptr->sustain_dex = TRUE;
885         if (f2 & (TR2_SUST_CON)) p_ptr->sustain_con = TRUE;
886         if (f2 & (TR2_SUST_CHR)) p_ptr->sustain_chr = TRUE;
887
888
889         /*** Analyze equipment ***/
890
891         /* Scan the equipment */
892         for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
893         {
894                 o_ptr = &inventory[i];
895
896                 /* Skip non-objects */
897                 if (!o_ptr->k_idx) continue;
898
899                 /* Extract the item flags */
900                 object_flags(o_ptr, &f1, &f2, &f3);
901
902                 /* Affect stats */
903                 if (f1 & (TR1_STR)) p_ptr->stat_add[A_STR] += o_ptr->pval;
904                 if (f1 & (TR1_INT)) p_ptr->stat_add[A_INT] += o_ptr->pval;
905                 if (f1 & (TR1_WIS)) p_ptr->stat_add[A_WIS] += o_ptr->pval;
906                 if (f1 & (TR1_DEX)) p_ptr->stat_add[A_DEX] += o_ptr->pval;
907                 if (f1 & (TR1_CON)) p_ptr->stat_add[A_CON] += o_ptr->pval;
908                 if (f1 & (TR1_CHR)) p_ptr->stat_add[A_CHR] += o_ptr->pval;
909
910                 /* Affect stealth */
911                 if (f1 & (TR1_STEALTH)) p_ptr->skills[SKILL_STEALTH] += o_ptr->pval;
912
913                 /* Affect searching ability (factor of five) */
914                 if (f1 & (TR1_SEARCH)) p_ptr->skills[SKILL_SEARCH] += (o_ptr->pval * 5);
915
916                 /* Affect searching frequency (factor of five) */
917                 if (f1 & (TR1_SEARCH)) p_ptr->skills[SKILL_SEARCH_FREQUENCY] += (o_ptr->pval * 5);
918
919                 /* Affect infravision */
920                 if (f1 & (TR1_INFRA)) p_ptr->see_infra += o_ptr->pval;
921
922                 /* Affect digging (factor of 20) */
923                 if (f1 & (TR1_TUNNEL)) p_ptr->skills[SKILL_DIGGING] += (o_ptr->pval * 20);
924
925                 /* Affect speed */
926                 if (f1 & (TR1_SPEED)) p_ptr->pspeed += o_ptr->pval;
927
928                 /* Affect blows */