… | |
… | |
77 | * and if goodbad is non-zero, luck increases the roll, if zero, it decreases. |
77 | * and if goodbad is non-zero, luck increases the roll, if zero, it decreases. |
78 | * Generally, op should be the player/caster/hitter requesting the roll, |
78 | * Generally, op should be the player/caster/hitter requesting the roll, |
79 | * not the recipient (ie, the poor slob getting hit). [garbled 20010916] |
79 | * not the recipient (ie, the poor slob getting hit). [garbled 20010916] |
80 | */ |
80 | */ |
81 | int |
81 | int |
82 | random_roll (int min, int max, const object *op, int goodbad) |
82 | random_roll (int r_min, int r_max, const object *op, int goodbad) |
83 | { |
83 | { |
84 | int omin, diff, luck, base, ran; |
84 | int base = r_max - r_min > 1 ? 20 : 50; /* d2 and d3 are corner cases */ |
85 | |
85 | |
86 | omin = min; |
86 | if (r_max < 1 || r_max < r_min) |
87 | diff = max - min + 1; |
|
|
88 | ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */ |
|
|
89 | |
|
|
90 | if (max < 1 || diff < 1) |
|
|
91 | { |
87 | { |
92 | LOG (llevError, "Calling random_roll with min=%d max=%d\n", min, max); |
88 | LOG (llevError, "Calling random_roll with min=%d max=%d\n", r_min, r_max); |
93 | return (min); /* avoids a float exception */ |
89 | return r_min; |
94 | } |
90 | } |
95 | |
91 | |
96 | ran = RANDOM (); |
|
|
97 | |
|
|
98 | if (op->type != PLAYER) |
92 | if (op->type == PLAYER) |
99 | return ((ran % diff) + min); |
93 | { |
100 | |
|
|
101 | luck = op->stats.luck; |
94 | int luck = op->stats.luck; |
102 | if (RANDOM () % base < MIN (10, abs (luck))) |
95 | |
|
|
96 | if (rndm (base) < min (10, abs (luck))) |
|
|
97 | { |
|
|
98 | //TODO: take luck into account |
|
|
99 | } |
103 | { |
100 | } |
104 | /* we have a winner */ |
|
|
105 | ((luck > 0) ? (luck = 1) : (luck = -1)); |
|
|
106 | diff -= luck; |
|
|
107 | if (diff < 1) |
|
|
108 | return (omin); /*check again */ |
|
|
109 | ((goodbad) ? (min += luck) : (diff)); |
|
|
110 | |
101 | |
111 | return (MAX (omin, MIN (max, (ran % diff) + min))); |
102 | return rndm (r_min, r_max); |
112 | } |
|
|
113 | return ((ran % diff) + min); |
|
|
114 | } |
103 | } |
115 | |
104 | |
116 | /* |
105 | /* |
117 | * This is a 64 bit version of random_roll above. This is needed |
106 | * This is a 64 bit version of random_roll above. This is needed |
118 | * for exp loss calculations for players changing religions. |
107 | * for exp loss calculations for players changing religions. |