forked from github/server
testing for magic resistance curses.
This commit is contained in:
parent
60fe8e6200
commit
721442584c
3 changed files with 99 additions and 14 deletions
|
@ -1070,8 +1070,9 @@ variant magic_resistance(const unit * target)
|
|||
c = get_curse(target->attribs, &ct_magicresistance);
|
||||
if (c) {
|
||||
/* TODO: legacy. magicresistance-effect is an integer-percentage stored in a double */
|
||||
int effect = curse_geteffect_int(c) * get_cursedmen(target, c);
|
||||
prob = frac_add(prob, frac_make(effect, 100));
|
||||
variant effect = frac_make(curse_geteffect_int(c), 100);
|
||||
effect = frac_mul(effect, frac_make(get_cursedmen(target, c), target->number));
|
||||
prob = frac_add(prob, effect);
|
||||
}
|
||||
|
||||
/* Unicorn +10 */
|
||||
|
|
|
@ -6,13 +6,18 @@
|
|||
#include "give.h"
|
||||
#include "teleport.h"
|
||||
|
||||
#include <kernel/callbacks.h>
|
||||
#include <util/language.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/callbacks.h>
|
||||
#include <kernel/equipment.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/spellbook.h>
|
||||
|
@ -20,10 +25,6 @@
|
|||
#include <kernel/objtypes.h>
|
||||
#include <kernel/pool.h>
|
||||
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <selist.h>
|
||||
#include <tests.h>
|
||||
|
@ -439,7 +440,16 @@ static void test_resist_chance(CuTest *tc) {
|
|||
prob = resist_chance(u1, u4, TYP_UNIT, 10);
|
||||
CuAssertIntEquals(tc, 0, prob.sa[0]);
|
||||
|
||||
/* allied units do not resist */
|
||||
/* allied units can still resist */
|
||||
ally_set(&u3->faction->allies, u1->faction, HELP_GUARD);
|
||||
prob = resist_chance(u1, u3, TYP_UNIT, 0);
|
||||
prob = frac_sub(prob, frac_make(1, 2)); /* resist at 50% base chance */
|
||||
CuAssertIntEquals(tc, 0, prob.sa[0]);
|
||||
prob = resist_chance(u1, u3, TYP_UNIT, 10);
|
||||
prob = frac_sub(prob, frac_make(3, 5)); /* resist at 10% + 50% base chance */
|
||||
CuAssertIntEquals(tc, 0, prob.sa[0]);
|
||||
ally_set(&u3->faction->allies, u1->faction, 0);
|
||||
|
||||
contact_unit(u3, u1);
|
||||
prob = resist_chance(u1, u3, TYP_UNIT, 0);
|
||||
CuAssertIntEquals(tc, 0, prob.sa[0]);
|
||||
|
@ -507,6 +517,14 @@ static void test_magic_resistance(CuTest *tc) {
|
|||
CuAssertTrue(tc, frac_equal(frac_make(1, 5), magic_resistance(u)));
|
||||
set_level(u, SK_MAGIC, 0);
|
||||
|
||||
/* TODO:
|
||||
* - ct_magicresistance
|
||||
* - ct_badmagicresistancezone
|
||||
* - ct_goodmagicresistancezone
|
||||
* - alliedunit
|
||||
* - stone circles
|
||||
*/
|
||||
|
||||
CuAssertTrue(tc, frac_equal(rc->magres, magic_resistance(u)));
|
||||
rc->magres = frac_one;
|
||||
CuAssert(tc, "magic resistance is capped at 0.9", frac_equal(magic_resistance(u), frac_make(9, 10)));
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
#include <platform.h>
|
||||
#include "spells.h"
|
||||
#include "magic.h"
|
||||
|
||||
#include <spells/regioncurse.h>
|
||||
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -6,11 +12,9 @@
|
|||
#include <kernel/region.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/message.h>
|
||||
#include <util/language.h>
|
||||
#include <kernel/attrib.h>
|
||||
#include <spells/regioncurse.h>
|
||||
#include "spells.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
@ -21,6 +25,67 @@
|
|||
#include <assert.h>
|
||||
|
||||
|
||||
static void test_magicresistance_curse_effects(CuTest *tc) {
|
||||
struct region *r;
|
||||
unit *u1, *u2;
|
||||
variant var;
|
||||
curse *c;
|
||||
|
||||
test_setup();
|
||||
r = test_create_plain(0, 0);
|
||||
|
||||
u1 = test_create_unit(test_create_faction(), r);
|
||||
u2 = test_create_unit(test_create_faction(), r);
|
||||
|
||||
/* increase someone's magic resistance by 10 percent */
|
||||
c = create_curse(u1, &u2->attribs, &ct_magicresistance, 1, 1, 10, 1);
|
||||
var = magic_resistance(u2);
|
||||
var = frac_sub(var, frac_make(1, 10));
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
|
||||
/* curse only works for 1 person, is reduced for more */
|
||||
scale_number(u2, 2);
|
||||
var = magic_resistance(u2);
|
||||
var = frac_sub(var, frac_make(1, 20));
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
remove_curse(&u2->attribs, c);
|
||||
|
||||
/* create an increase of magic resistance by 10 percent for our friends */
|
||||
c = create_curse(u1, &r->attribs, &ct_goodmagicresistancezone, 1, 1, 10, 0);
|
||||
/* curse increases our own resistance: */
|
||||
var = magic_resistance(u1);
|
||||
var = frac_sub(var, frac_make(1, 10));
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
/* no effect on non-allied units: */
|
||||
var = magic_resistance(u2);
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
/* allied units also get the bonus: */
|
||||
ally_set(&u1->faction->allies, u2->faction, HELP_GUARD);
|
||||
var = magic_resistance(u2);
|
||||
var = frac_sub(var, frac_make(1, 10));
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
ally_set(&u1->faction->allies, u2->faction, 0);
|
||||
remove_curse(&r->attribs, c);
|
||||
|
||||
/* reduce magic resistance for non-friendly units */
|
||||
c = create_curse(u1, &r->attribs, &ct_badmagicresistancezone, 1, 1, 10, 0);
|
||||
/* we do not affect ourselves: */
|
||||
var = magic_resistance(u1);
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
/* non-allied units get the effect, even if it takes them into negative: */
|
||||
var = magic_resistance(u2);
|
||||
var = frac_add(var, frac_make(1, 10));
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
/* no effect on allied units: */
|
||||
ally_set(&u1->faction->allies, u2->faction, HELP_GUARD);
|
||||
var = magic_resistance(u2);
|
||||
CuAssertIntEquals(tc, 0, var.sa[0]);
|
||||
ally_set(&u1->faction->allies, u2->faction, 0);
|
||||
remove_curse(&r->attribs, c);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_magicresistance_unit(CuTest *tc) {
|
||||
struct region *r;
|
||||
struct faction *f1, *f2;
|
||||
|
@ -79,6 +144,7 @@ static void test_magicresistance_building(CuTest *tc) {
|
|||
CuSuite *get_magicresistance_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_magicresistance_curse_effects);
|
||||
SUITE_ADD_TEST(suite, test_magicresistance_unit);
|
||||
SUITE_ADD_TEST(suite, test_magicresistance_building);
|
||||
return suite;
|
||||
|
|
Loading…
Reference in a new issue