Ticket #1700: 0002-Add-PF_MAGICAL-player-flag.txt

File 0002-Add-PF_MAGICAL-player-flag.txt, 4.6 KB (added by daniel.santos, 7 years ago)
Line 
1From 211fc4a53183cf091191d1f633156e851383542d Mon Sep 17 00:00:00 2001
2From: Daniel Santos <daniel.santos@pobox.com>
3Date: Wed, 7 Nov 2012 13:17:52 -0600
4Subject: Add PF_MAGICAL player flag
5
6Intended for "magical races", who are able to use magic more easily and
7has two parts.
8
91. Reduced spell failures - Halves the chance for spell failure. Classes
10   w/o ZERO_FAIL have their minimum fail rate reduced to 3.
11
122. Grants chance to cast spells/recite prayers at a reduced cost
13   (10%-60%) or greatly reduced cost (1%-10%) dependent upon level.
14   o Chance of reduced cost is 5% at level 1 and 50% at level 50
15     ((lev - 1) * 46 / 50 + 5).
16   o Chance of greatly reduced cost is 1% at level 10 and 5% at level 50
17     (level / 10).
18
19In order to facilitate the second bonus, this patch converts the manna
20usage code in spell_cast to use a 32-bit manna + fraction value instead
21of only working with the non-fraction portion.  Otherwise, this wouldn't
22behave correctly and would have to either allow spell casting sometimes
23for free, or never reduce the cost of spells that take 1 manna.
24---
25 src/list-player-flags.h |    1 +
26 src/player/spell.c      |   43 +++++++++++++++++++++++++++++++++++++++----
27 src/ui-birth.c          |    1 +
28 3 files changed, 41 insertions(+), 4 deletions(-)
29
30diff --git a/src/list-player-flags.h b/src/list-player-flags.h
31index 89ba3b4..c83bf7b 100644
32--- a/src/list-player-flags.h
33+++ b/src/list-player-flags.h
34@@ -20,3 +20,4 @@ PF(KNOW_MUSHROOM,    "easily recognize mushrooms")
35 PF(KNOW_ZAPPER,      "easily recognize magic devices")
36 PF(SEE_ORE,          "can sense ore in the walls")
37 PF(FAST,             "receive 1 + level / 10 haste bonus")
38+PF(MAGICAL,          "halves spell failures and gives chance to reduce mana costs")
39diff --git a/src/player/spell.c b/src/player/spell.c
40index 3f3cbe8..3389ec2 100644
41--- a/src/player/spell.c
42+++ b/src/player/spell.c
43@@ -250,6 +250,13 @@ s16b spell_chance(int spell)
44                minfail = 5;
45        }
46 
47+       /* magical race bonus (also an exception to the above, but 3% limit) */
48+       if (player_has(PF_MAGICAL))
49+       {
50+               minfail = (minfail + 1) / 2;
51+               chance = (chance + 1) / 2;
52+       }
53+
54        /* Priest prayer penalty for "edged" weapons (before minfail) */
55        if (p_ptr->state.icky_wield)
56        {
57@@ -344,6 +351,10 @@ bool spell_cast(int spell, int dir)
58        /* Get the spell */
59        const magic_type *s_ptr = &p_ptr->class->spells.info[spell];
60 
61+       /* convert cur manna & spell cost to manna * 2^16 + fraction */
62+       u32b cmana = (p_ptr->csp << 16) + p_ptr->csp_frac;
63+       u32b smana = s_ptr->smana << 16;
64+
65        /* Spell failure chance */
66        chance = spell_chance(spell);
67 
68@@ -376,19 +387,43 @@ bool spell_cast(int spell, int dir)
69                        /* Redraw object recall */
70                        p_ptr->redraw |= (PR_OBJECT);
71                }
72+
73+               /* Chance for magical races to use less manna, can even avoid the
74+                * over-exertion penalty. */
75+               if (player_has(PF_MAGICAL)) {
76+                       int roll = randint0(100);
77+
78+                       /* Chance of critical success is 0% at level 1, 5% at level 50,
79+                        * spell cost is reduced to 1-10%
80+                        */
81+                       if (roll < p_ptr->lev / 10) {
82+                               smana = smana / 100 * rand_range(1, 10);
83+                               msg("You cast the spell with great ease.");
84+
85+
86+                       /* Chance of normal success is 5% at level 1, 50% at level 50,
87+                        * spell cost is reduced to 10-60%
88+                        */
89+                       } else if (roll < ((p_ptr->lev - 1) * 46 / 50 + 5)) {
90+                               smana = smana / 100 * rand_range(10, 60);
91+                               msg("You cast the spell with ease.");
92+                       }
93+               }
94        }
95 
96        /* Sufficient mana */
97-       if (s_ptr->smana <= p_ptr->csp)
98+       if (smana <= cmana)
99        {
100                /* Use some mana */
101-               p_ptr->csp -= s_ptr->smana;
102+               cmana -= smana;
103+               p_ptr->csp = cmana >> 16;
104+               p_ptr->csp_frac = cmana & 0xffff;
105        }
106 
107        /* Over-exert the player */
108        else
109        {
110-               int oops = s_ptr->smana - p_ptr->csp;
111+               int oops = smana - cmana;
112 
113                /* No mana left */
114                p_ptr->csp = 0;
115@@ -398,7 +433,7 @@ bool spell_cast(int spell, int dir)
116                msg("You faint from the effort!");
117 
118                /* Bypass free action */
119-               (void)player_inc_timed(p_ptr, TMD_PARALYZED, randint1(5 * oops + 1), TRUE, FALSE);
120+               (void)player_inc_timed(p_ptr, TMD_PARALYZED, randint1(5 * oops + 0x10000) >> 16, TRUE, FALSE);
121 
122                /* Damage CON (possibly permanently) */
123                if (randint0(100) < 50)
124diff --git a/src/ui-birth.c b/src/ui-birth.c
125index b1cfa6e..18e0871 100644
126--- a/src/ui-birth.c
127+++ b/src/ui-birth.c
128@@ -255,6 +255,7 @@ static const char *get_pflag_desc(bitflag flag)
129                case PF_KNOW_ZAPPER: return "Identifies magic devices";
130                case PF_SEE_ORE: return "Senses ore/minerals";
131                case PF_FAST: return "Gains speed bonus";
132+               case PF_MAGICAL: return "Spells fail less and sometimes use less mana";
133                default: return "Undocumented pflag";
134        }
135 }
136--
1371.7.10.4
138