@@ -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 );
0 commit comments