Skip to content

Commit b828e83

Browse files
committed
limit charming to units of max size force * force
1 parent 3ec5e96 commit b828e83

2 files changed

Lines changed: 43 additions & 27 deletions

File tree

src/spells/charming.c

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ int sp_charmingsong(castorder *co)
220220
spellparameter *param = co->a_params;
221221
int duration, resist_bonus = 0;
222222
int tb = 0;
223+
bool resists = false;
223224

224225
/* wenn Ziel gefunden, dieses aber Magieresistent war, Zauber
225226
* abbrechen aber kosten lassen */
@@ -249,39 +250,47 @@ int sp_charmingsong(castorder *co)
249250
if (target->number > force) {
250251
resist_bonus += (int)((target->number - force) * 10);
251252
}
252-
/* Magieresistensbonus fuer hoehere Talentwerte */
253-
for (i = 0; i < MAXSKILLS; i++) {
254-
int sk = effskill(target, i, NULL);
255-
if (tb < sk)
256-
tb = sk;
253+
if (target->number > force * force) {
254+
resists = true;
257255
}
258-
if (tb > 0) {
259-
tb -= effskill(mage, SK_MAGIC, NULL);
256+
else {
257+
/* Magieresistensbonus fuer hoehere Talentwerte */
258+
for (i = 0; i < MAXSKILLS; i++) {
259+
int sk = effskill(target, i, NULL);
260+
if (tb < sk)
261+
tb = sk;
262+
}
260263
if (tb > 0) {
261-
resist_bonus += tb * 15;
264+
tb -= effskill(mage, SK_MAGIC, NULL);
265+
if (tb > 0) {
266+
resist_bonus += tb * 15;
267+
}
262268
}
263-
}
264-
/* Increased chance for magical resistence */
265-
if (resist_bonus > 0) {
266-
variant p_regular = resist_chance(mage, target, TYP_UNIT, 0);
267-
variant p_modified = resist_chance(mage, target, TYP_UNIT, resist_bonus);
268-
variant prob = frac_div(p_regular, p_modified);
269-
if (prob.sa[0] > 0) {
270-
/**
271-
* given a failure chance of A/B, we roll a
272-
* B-sided die, and if the result is less than B - A,
273-
* the spell fails.
274-
* This formula is a bit odd, because we want it to fail
275-
* on low dice rolls, to simplify testing.
276-
*/
277-
if (rng_int() % prob.sa[1] < prob.sa[1] - prob.sa[0]) {
278-
/* target resists after all, because of bonus */
279-
ADDMSG(&mage->faction->msgs, msg_message("spellunitresists",
280-
"unit region command target", mage, mage->region, co->order, target));
281-
return cast_level;
269+
/* Increased chance for magical resistence */
270+
if (resist_bonus > 0) {
271+
variant p_regular = resist_chance(mage, target, TYP_UNIT, 0);
272+
variant p_modified = resist_chance(mage, target, TYP_UNIT, resist_bonus);
273+
variant prob = frac_div(p_regular, p_modified);
274+
if (prob.sa[0] > 0) {
275+
/**
276+
* given a failure chance of A/B, we roll a
277+
* B-sided die, and if the result is less than B - A,
278+
* the spell fails.
279+
* This formula is a bit odd, because we want it to fail
280+
* on low dice rolls, to simplify testing.
281+
*/
282+
if (rng_int() % prob.sa[1] < prob.sa[1] - prob.sa[0]) {
283+
resists = true;
284+
}
282285
}
283286
}
284287
}
288+
if (resists) {
289+
/* target resists after all, because of bonus */
290+
ADDMSG(&mage->faction->msgs, msg_message("spellunitresists",
291+
"unit region command target", mage, mage->region, co->order, target));
292+
return cast_level;
293+
}
285294

286295
duration = 3 + rng_int() % (int)force;
287296
charm_unit(target, mage, force, duration);

src/spells/charming.test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ static void test_charmingsong(CuTest *tc) {
155155
scale_number(u2, (int)co.force);
156156
test_clear_messages(f);
157157

158+
// very big unit, cannot be charmed:
159+
scale_number(u2, 1 + (int)(co.force * co.force));
160+
CuAssertIntEquals(tc, co.level, sp_charmingsong(&co));
161+
CuAssertPtrNotNull(tc, test_find_faction_message(f, "spellunitresists"));
162+
scale_number(u2, (int)co.force);
163+
test_clear_messages(f);
164+
158165
// success:
159166
CuAssertIntEquals(tc, co.level, sp_charmingsong(&co));
160167
CuAssertPtrEquals(tc, u->faction, u2->faction);

0 commit comments

Comments
 (0)