2011-03-13 02:01:20 +01:00
|
|
|
#include <platform.h>
|
2014-08-27 06:40:18 +02:00
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
#include "battle.h"
|
2011-03-16 05:04:38 +01:00
|
|
|
#include "skill.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
|
2015-11-21 19:02:14 +01:00
|
|
|
#include <kernel/config.h>
|
2014-08-27 06:40:18 +02:00
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/faction.h>
|
2016-08-29 09:53:09 +02:00
|
|
|
#include <kernel/curse.h>
|
2014-08-27 06:40:18 +02:00
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/unit.h>
|
2015-01-12 20:23:25 +01:00
|
|
|
#include <util/functions.h>
|
2012-06-24 07:36:17 +02:00
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
#include <CuTest.h>
|
2012-06-24 07:36:17 +02:00
|
|
|
#include "tests.h"
|
2011-03-13 02:01:20 +01:00
|
|
|
|
2011-03-16 05:04:38 +01:00
|
|
|
static void test_make_fighter(CuTest * tc)
|
|
|
|
{
|
2014-06-25 07:44:05 +02:00
|
|
|
unit *au;
|
|
|
|
region *r;
|
|
|
|
fighter *af;
|
|
|
|
battle *b;
|
|
|
|
side *as;
|
|
|
|
faction * f;
|
|
|
|
const resource_type *rtype;
|
2011-03-16 05:04:38 +01:00
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2015-11-07 23:34:51 +01:00
|
|
|
test_create_horse();
|
|
|
|
r = test_create_region(0, 0, 0);
|
2015-01-12 20:23:25 +01:00
|
|
|
f = test_create_faction(NULL);
|
2014-06-25 07:44:05 +02:00
|
|
|
au = test_create_unit(f, r);
|
|
|
|
enable_skill(SK_MAGIC, true);
|
|
|
|
enable_skill(SK_RIDING, true);
|
|
|
|
set_level(au, SK_MAGIC, 3);
|
|
|
|
set_level(au, SK_RIDING, 3);
|
|
|
|
au->status = ST_BEHIND;
|
|
|
|
rtype = get_resourcetype(R_HORSE);
|
|
|
|
i_change(&au->items, rtype->itype, 1);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2014-06-25 07:44:05 +02:00
|
|
|
b = make_battle(r);
|
|
|
|
as = make_side(b, au->faction, 0, 0, 0);
|
|
|
|
af = make_fighter(b, au, as, false);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2014-06-25 07:44:05 +02:00
|
|
|
CuAssertIntEquals(tc, 1, b->nfighters);
|
|
|
|
CuAssertPtrEquals(tc, 0, af->building);
|
|
|
|
CuAssertPtrEquals(tc, as, af->side);
|
|
|
|
CuAssertIntEquals(tc, 0, af->run.hp);
|
|
|
|
CuAssertIntEquals(tc, ST_BEHIND, af->status);
|
|
|
|
CuAssertIntEquals(tc, 0, af->run.number);
|
|
|
|
CuAssertIntEquals(tc, au->hp, af->person[0].hp);
|
|
|
|
CuAssertIntEquals(tc, 1, af->person[0].speed);
|
|
|
|
CuAssertIntEquals(tc, au->number, af->alive);
|
|
|
|
CuAssertIntEquals(tc, 0, af->removed);
|
|
|
|
CuAssertIntEquals(tc, 3, af->magic);
|
|
|
|
CuAssertIntEquals(tc, 1, af->horses);
|
|
|
|
CuAssertIntEquals(tc, 0, af->elvenhorses);
|
2014-12-12 11:13:25 +01:00
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
2011-03-16 05:04:38 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 19:38:46 +01:00
|
|
|
static building_type * setup_castle(void) {
|
|
|
|
building_type * btype;
|
|
|
|
construction *cons;
|
|
|
|
|
|
|
|
btype = bt_get_or_create("castle");
|
|
|
|
btype->flags |= BTF_FORTIFICATION;
|
|
|
|
cons = btype->construction = calloc(1, sizeof(construction));
|
|
|
|
cons->maxsize = 5;
|
|
|
|
cons = cons->improvement = calloc(1, sizeof(construction));
|
|
|
|
cons->maxsize = -1;
|
|
|
|
return btype;
|
|
|
|
}
|
|
|
|
|
2011-03-13 02:54:57 +01:00
|
|
|
static void test_defenders_get_building_bonus(CuTest * tc)
|
2011-03-13 02:01:20 +01:00
|
|
|
{
|
2015-01-12 16:57:05 +01:00
|
|
|
unit *du, *au;
|
|
|
|
region *r;
|
|
|
|
building * bld;
|
|
|
|
fighter *df, *af;
|
|
|
|
battle *b;
|
|
|
|
side *ds, *as;
|
|
|
|
troop dt, at;
|
|
|
|
building_type * btype;
|
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2017-02-22 19:38:46 +01:00
|
|
|
btype = setup_castle();
|
2015-11-07 23:34:51 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
2015-01-12 16:57:05 +01:00
|
|
|
bld = test_create_building(r, btype);
|
|
|
|
|
2015-01-12 20:23:25 +01:00
|
|
|
du = test_create_unit(test_create_faction(NULL), r);
|
|
|
|
au = test_create_unit(test_create_faction(NULL), r);
|
2015-01-12 16:57:05 +01:00
|
|
|
u_set_building(du, bld);
|
|
|
|
|
|
|
|
b = make_battle(r);
|
|
|
|
ds = make_side(b, du->faction, 0, 0, 0);
|
|
|
|
df = make_fighter(b, du, ds, false);
|
|
|
|
as = make_side(b, au->faction, 0, 0, 0);
|
|
|
|
af = make_fighter(b, au, as, true);
|
|
|
|
|
|
|
|
CuAssertPtrEquals(tc, bld, df->building);
|
|
|
|
CuAssertPtrEquals(tc, 0, af->building);
|
|
|
|
|
|
|
|
dt.fighter = df;
|
|
|
|
dt.index = 0;
|
|
|
|
at.fighter = af;
|
|
|
|
at.index = 0;
|
|
|
|
|
2017-02-22 19:38:46 +01:00
|
|
|
bld->size = 10; /* stage 1 building */
|
|
|
|
CuAssertIntEquals(tc, -1, skilldiff(at, dt, 0));
|
|
|
|
CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0));
|
|
|
|
|
|
|
|
bld->size = 1; /* stage 0 building */
|
|
|
|
CuAssertIntEquals(tc, 0, skilldiff(at, dt, 0));
|
|
|
|
CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0));
|
2015-01-12 16:57:05 +01:00
|
|
|
|
2014-12-12 11:13:25 +01:00
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
2011-03-13 02:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_attackers_get_no_building_bonus(CuTest * tc)
|
|
|
|
{
|
2015-01-12 16:57:05 +01:00
|
|
|
unit *au;
|
|
|
|
region *r;
|
|
|
|
building * bld;
|
|
|
|
fighter *af;
|
|
|
|
battle *b;
|
|
|
|
side *as;
|
|
|
|
building_type * btype;
|
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2015-11-07 23:34:51 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
2017-02-22 19:38:46 +01:00
|
|
|
btype = setup_castle();
|
|
|
|
btype->flags |= BTF_FORTIFICATION;
|
2015-01-12 16:57:05 +01:00
|
|
|
bld = test_create_building(r, btype);
|
|
|
|
bld->size = 10;
|
|
|
|
|
2015-01-12 20:23:25 +01:00
|
|
|
au = test_create_unit(test_create_faction(NULL), r);
|
2015-01-12 16:57:05 +01:00
|
|
|
u_set_building(au, bld);
|
|
|
|
|
|
|
|
b = make_battle(r);
|
|
|
|
as = make_side(b, au->faction, 0, 0, 0);
|
|
|
|
af = make_fighter(b, au, as, true);
|
|
|
|
|
|
|
|
CuAssertPtrEquals(tc, 0, af->building);
|
2014-12-12 11:13:25 +01:00
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
2011-03-13 02:01:20 +01:00
|
|
|
}
|
|
|
|
|
2011-03-16 05:04:38 +01:00
|
|
|
static void test_building_bonus_respects_size(CuTest * tc)
|
|
|
|
{
|
2015-01-12 16:57:05 +01:00
|
|
|
unit *au, *du;
|
|
|
|
region *r;
|
|
|
|
building * bld;
|
|
|
|
fighter *af, *df;
|
|
|
|
battle *b;
|
|
|
|
side *as;
|
|
|
|
building_type * btype;
|
|
|
|
faction * f;
|
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2017-02-22 19:38:46 +01:00
|
|
|
btype = setup_castle();
|
2015-11-07 23:34:51 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
2017-02-22 19:38:46 +01:00
|
|
|
btype->flags |= BTF_FORTIFICATION;
|
2015-01-12 16:57:05 +01:00
|
|
|
bld = test_create_building(r, btype);
|
|
|
|
bld->size = 10;
|
|
|
|
|
2015-01-12 20:23:25 +01:00
|
|
|
f = test_create_faction(NULL);
|
2015-01-12 16:57:05 +01:00
|
|
|
au = test_create_unit(f, r);
|
|
|
|
scale_number(au, 9);
|
|
|
|
u_set_building(au, bld);
|
|
|
|
du = test_create_unit(f, r);
|
|
|
|
u_set_building(du, bld);
|
|
|
|
scale_number(du, 2);
|
|
|
|
|
|
|
|
b = make_battle(r);
|
|
|
|
as = make_side(b, au->faction, 0, 0, 0);
|
|
|
|
af = make_fighter(b, au, as, false);
|
|
|
|
df = make_fighter(b, du, as, false);
|
|
|
|
|
|
|
|
CuAssertPtrEquals(tc, bld, af->building);
|
|
|
|
CuAssertPtrEquals(tc, 0, df->building);
|
2014-12-12 11:13:25 +01:00
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
2011-03-16 05:04:38 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 16:57:05 +01:00
|
|
|
static void test_building_defence_bonus(CuTest * tc)
|
|
|
|
{
|
|
|
|
building_type * btype;
|
2015-10-14 12:09:35 +02:00
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2017-02-22 19:38:46 +01:00
|
|
|
btype = setup_castle();
|
|
|
|
|
|
|
|
btype->maxsize = -1; /* unlimited buildigs get the castle bonus */
|
|
|
|
CuAssertIntEquals(tc, 0, building_protection(btype, 0));
|
|
|
|
CuAssertIntEquals(tc, 1, building_protection(btype, 1));
|
|
|
|
CuAssertIntEquals(tc, 3, building_protection(btype, 2));
|
|
|
|
CuAssertIntEquals(tc, 5, building_protection(btype, 3));
|
|
|
|
CuAssertIntEquals(tc, 8, building_protection(btype, 4));
|
|
|
|
CuAssertIntEquals(tc, 12, building_protection(btype, 5));
|
|
|
|
CuAssertIntEquals(tc, 12, building_protection(btype, 6));
|
|
|
|
|
|
|
|
btype->maxsize = 10; /* limited-size buildings are treated like an E3 watchtower */
|
|
|
|
CuAssertIntEquals(tc, 0, building_protection(btype, 0));
|
|
|
|
CuAssertIntEquals(tc, 1, building_protection(btype, 1));
|
|
|
|
CuAssertIntEquals(tc, 2, building_protection(btype, 2));
|
|
|
|
CuAssertIntEquals(tc, 2, building_protection(btype, 3));
|
2015-01-12 16:57:05 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-11-21 19:02:14 +01:00
|
|
|
static fighter *setup_fighter(battle **bp, unit *u) {
|
2016-08-29 09:04:43 +02:00
|
|
|
battle *b = *bp;
|
|
|
|
side *s;
|
|
|
|
|
|
|
|
if (!b) {
|
|
|
|
*bp = b = make_battle(u->region);
|
|
|
|
}
|
|
|
|
s = make_side(b, u->faction, 0, 0, 0);
|
|
|
|
return make_fighter(b, u, s, false);
|
2015-11-03 18:59:09 +01:00
|
|
|
}
|
|
|
|
|
2015-11-21 19:02:14 +01:00
|
|
|
static void test_natural_armor(CuTest * tc)
|
|
|
|
{
|
|
|
|
race *rc;
|
|
|
|
unit *u;
|
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2015-11-21 19:02:14 +01:00
|
|
|
rc = test_create_race("human");
|
|
|
|
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
|
|
|
|
set_level(u, SK_STAMINA, 2);
|
2017-02-04 23:16:16 +01:00
|
|
|
CuAssertIntEquals(tc, 0, rc_armor_bonus(rc));
|
2015-11-21 19:02:14 +01:00
|
|
|
CuAssertIntEquals(tc, 0, natural_armor(u));
|
2017-02-05 16:55:51 +01:00
|
|
|
rc_set_param(rc, "armor.stamina", "1");
|
2017-02-04 23:16:16 +01:00
|
|
|
CuAssertIntEquals(tc, 1, rc_armor_bonus(rc));
|
2015-11-21 19:02:14 +01:00
|
|
|
CuAssertIntEquals(tc, 2, natural_armor(u));
|
2017-02-05 16:55:51 +01:00
|
|
|
rc_set_param(rc, "armor.stamina", "2");
|
2017-02-04 23:16:16 +01:00
|
|
|
CuAssertIntEquals(tc, 2, rc_armor_bonus(rc));
|
2015-11-21 19:02:14 +01:00
|
|
|
CuAssertIntEquals(tc, 1, natural_armor(u));
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-11-03 14:22:50 +01:00
|
|
|
static void test_calculate_armor(CuTest * tc)
|
|
|
|
{
|
|
|
|
troop dt;
|
2016-08-29 09:04:43 +02:00
|
|
|
battle *b = NULL;
|
2015-11-03 14:22:50 +01:00
|
|
|
region *r;
|
|
|
|
unit *du;
|
2015-11-03 18:59:09 +01:00
|
|
|
weapon_type *wtype;
|
|
|
|
armor_type *ashield, *achain;
|
|
|
|
item_type *ibelt, *ishield, *ichain;
|
|
|
|
race *rc;
|
2017-02-24 20:47:47 +01:00
|
|
|
variant magres = frac_zero;
|
|
|
|
variant v50p = frac_make(1, 2);
|
2015-11-03 14:22:50 +01:00
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2015-11-03 14:22:50 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
2015-11-03 18:59:09 +01:00
|
|
|
ibelt = it_get_or_create(rt_get_or_create("trollbelt"));
|
|
|
|
ishield = it_get_or_create(rt_get_or_create("shield"));
|
2017-02-24 20:47:47 +01:00
|
|
|
ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
|
2015-11-03 18:59:09 +01:00
|
|
|
ichain = it_get_or_create(rt_get_or_create("chainmail"));
|
2017-02-24 20:47:47 +01:00
|
|
|
achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE);
|
|
|
|
wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1);
|
2015-11-03 18:59:09 +01:00
|
|
|
rc = test_create_race("human");
|
|
|
|
du = test_create_unit(test_create_faction(rc), r);
|
2015-11-03 19:11:03 +01:00
|
|
|
dt.index = 0;
|
2015-11-03 18:59:09 +01:00
|
|
|
|
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
CuAssertIntEquals_Msg(tc, "default ac", 0, calculate_armor(dt, 0, 0, &magres));
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[0], magres.sa[1]);
|
2015-11-03 18:59:09 +01:00
|
|
|
free_battle(b);
|
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
b = NULL;
|
2015-11-03 18:59:09 +01:00
|
|
|
i_change(&du->items, ibelt, 1);
|
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
CuAssertIntEquals_Msg(tc, "magical armor", 1, calculate_armor(dt, 0, 0, 0));
|
|
|
|
rc->armor = 2;
|
|
|
|
CuAssertIntEquals_Msg(tc, "natural armor", 3, calculate_armor(dt, 0, 0, 0));
|
|
|
|
rc->armor = 0;
|
|
|
|
free_battle(b);
|
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
b = NULL;
|
2015-11-03 18:59:09 +01:00
|
|
|
i_change(&du->items, ishield, 1);
|
|
|
|
i_change(&du->items, ichain, 1);
|
|
|
|
dt.fighter = setup_fighter(&b, du);
|
2015-12-05 17:17:21 +01:00
|
|
|
rc->battle_flags &= ~BF_EQUIPMENT;
|
2015-11-03 18:59:09 +01:00
|
|
|
CuAssertIntEquals_Msg(tc, "require BF_EQUIPMENT", 1, calculate_armor(dt, 0, 0, 0));
|
|
|
|
free_battle(b);
|
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
b = NULL;
|
2015-11-03 18:59:09 +01:00
|
|
|
rc->battle_flags |= BF_EQUIPMENT;
|
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
CuAssertIntEquals_Msg(tc, "stack equipment rc", 5, calculate_armor(dt, 0, 0, 0));
|
|
|
|
rc->armor = 2;
|
|
|
|
CuAssertIntEquals_Msg(tc, "natural armor adds 50%", 6, calculate_armor(dt, 0, 0, 0));
|
|
|
|
wtype->flags = WTF_NONE;
|
|
|
|
CuAssertIntEquals_Msg(tc, "regular weapon has no effect", 6, calculate_armor(dt, 0, wtype, 0));
|
|
|
|
wtype->flags = WTF_ARMORPIERCING;
|
|
|
|
CuAssertIntEquals_Msg(tc, "armor piercing weapon", 3, calculate_armor(dt, 0, wtype, 0));
|
|
|
|
wtype->flags = WTF_NONE;
|
|
|
|
|
|
|
|
CuAssertIntEquals_Msg(tc, "magical attack", 3, calculate_armor(dt, 0, 0, &magres));
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[1], magres.sa[0]);
|
2015-11-03 18:59:09 +01:00
|
|
|
|
|
|
|
ashield->flags |= ATF_LAEN;
|
|
|
|
achain->flags |= ATF_LAEN;
|
2017-02-24 20:47:47 +01:00
|
|
|
magres = frac_one;
|
2015-11-03 18:59:09 +01:00
|
|
|
CuAssertIntEquals_Msg(tc, "laen armor", 3, calculate_armor(dt, 0, 0, &magres));
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssertIntEquals_Msg(tc, "laen magres bonus", 4, magres.sa[1]);
|
2015-11-03 18:59:09 +01:00
|
|
|
free_battle(b);
|
2015-11-03 14:22:50 +01:00
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-12-05 17:17:21 +01:00
|
|
|
static void test_magic_resistance(CuTest *tc)
|
|
|
|
{
|
|
|
|
troop dt;
|
2016-08-29 09:04:43 +02:00
|
|
|
battle *b = NULL;
|
2015-12-05 17:17:21 +01:00
|
|
|
region *r;
|
|
|
|
unit *du;
|
|
|
|
armor_type *ashield, *achain;
|
2015-12-05 17:25:47 +01:00
|
|
|
item_type *ishield, *ichain;
|
2015-12-05 17:17:21 +01:00
|
|
|
race *rc;
|
2017-02-24 20:47:47 +01:00
|
|
|
variant magres;
|
|
|
|
variant v50p = frac_make(1, 2);
|
|
|
|
variant v10p = frac_make(1, 10);
|
2015-12-05 17:17:21 +01:00
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2015-12-05 17:17:21 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
ishield = it_get_or_create(rt_get_or_create("shield"));
|
2017-02-24 20:47:47 +01:00
|
|
|
ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
|
2015-12-05 17:17:21 +01:00
|
|
|
ichain = it_get_or_create(rt_get_or_create("chainmail"));
|
2017-02-24 20:47:47 +01:00
|
|
|
achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE);
|
2015-12-05 17:17:21 +01:00
|
|
|
rc = test_create_race("human");
|
|
|
|
du = test_create_unit(test_create_faction(rc), r);
|
|
|
|
dt.index = 0;
|
|
|
|
|
2017-02-24 20:47:47 +01:00
|
|
|
i_change(&du->items, ishield, 1);
|
2015-12-05 17:17:21 +01:00
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
calculate_armor(dt, 0, 0, &magres);
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssertIntEquals_Msg(tc, "no magres reduction", magres.sa[1], magres.sa[0]);
|
|
|
|
magres = magic_resistance(du);
|
|
|
|
CuAssertIntEquals_Msg(tc, "no magres reduction", 0, magres.sa[0]);
|
2015-12-05 17:17:21 +01:00
|
|
|
|
|
|
|
ashield->flags |= ATF_LAEN;
|
2017-02-24 20:47:47 +01:00
|
|
|
ashield->magres = v10p;
|
2015-12-05 17:17:21 +01:00
|
|
|
calculate_armor(dt, 0, 0, &magres);
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssert(tc, "laen reduction => 10%%", frac_equal(frac_make(9, 10), magres));
|
2015-12-05 17:17:21 +01:00
|
|
|
free_battle(b);
|
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
b = NULL;
|
2015-12-05 17:17:21 +01:00
|
|
|
i_change(&du->items, ichain, 1);
|
|
|
|
achain->flags |= ATF_LAEN;
|
2017-02-24 20:47:47 +01:00
|
|
|
achain->magres = v10p;
|
2015-12-05 17:17:21 +01:00
|
|
|
ashield->flags |= ATF_LAEN;
|
2017-02-24 20:47:47 +01:00
|
|
|
ashield->magres = v10p;
|
2015-12-05 17:17:21 +01:00
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
calculate_armor(dt, 0, 0, &magres);
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssert(tc, "2x laen reduction => 81%%", frac_equal(frac_make(81, 100), magres));
|
2015-12-05 17:17:21 +01:00
|
|
|
free_battle(b);
|
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
b = NULL;
|
2015-12-05 17:17:21 +01:00
|
|
|
i_change(&du->items, ishield, -1);
|
|
|
|
i_change(&du->items, ichain, -1);
|
|
|
|
set_level(du, SK_MAGIC, 2);
|
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
calculate_armor(dt, 0, 0, &magres);
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssert(tc, "skill reduction => 90%%", frac_equal(magres, frac_make(9, 10)));
|
|
|
|
magres = magic_resistance(du);
|
|
|
|
CuAssert(tc, "skill reduction", frac_equal(magres, v10p));
|
|
|
|
rc->magres = v50p; /* percentage, gets added to skill bonus */
|
2015-12-06 18:34:31 +01:00
|
|
|
calculate_armor(dt, 0, 0, &magres);
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssert(tc, "race reduction => 40%%", frac_equal(magres, frac_make(4, 10)));
|
|
|
|
magres = magic_resistance(du);
|
|
|
|
CuAssert(tc, "race bonus => 60%%", frac_equal(magres, frac_make(60, 100)));
|
2015-12-06 18:34:31 +01:00
|
|
|
|
2017-02-24 20:47:47 +01:00
|
|
|
rc->magres = frac_make(15, 10); /* 150% resistance should not cause negative damage multiplier */
|
|
|
|
magres = magic_resistance(du);
|
|
|
|
CuAssert(tc, "magic resistance is never > 0.9", frac_equal(magres, frac_make(9, 10)));
|
2015-12-06 18:34:31 +01:00
|
|
|
calculate_armor(dt, 0, 0, &magres);
|
2017-02-24 20:47:47 +01:00
|
|
|
CuAssert(tc, "damage reduction is never < 0.1", frac_equal(magres, frac_make(1, 10)));
|
2015-12-05 17:17:21 +01:00
|
|
|
|
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2015-11-03 19:11:03 +01:00
|
|
|
static void test_projectile_armor(CuTest * tc)
|
|
|
|
{
|
|
|
|
troop dt;
|
2016-08-29 09:04:43 +02:00
|
|
|
battle *b = NULL;
|
2015-11-03 19:11:03 +01:00
|
|
|
region *r;
|
|
|
|
unit *du;
|
|
|
|
weapon_type *wtype;
|
|
|
|
armor_type *ashield, *achain;
|
|
|
|
item_type *ishield, *ichain;
|
|
|
|
race *rc;
|
2017-02-24 20:47:47 +01:00
|
|
|
variant v50p = frac_make(1, 2);
|
2015-11-03 19:11:03 +01:00
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2015-11-03 19:11:03 +01:00
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
ishield = it_get_or_create(rt_get_or_create("shield"));
|
2017-02-24 20:47:47 +01:00
|
|
|
ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
|
2015-11-03 19:11:03 +01:00
|
|
|
ichain = it_get_or_create(rt_get_or_create("chainmail"));
|
2017-02-24 20:47:47 +01:00
|
|
|
achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE);
|
|
|
|
wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1);
|
2015-11-03 19:11:03 +01:00
|
|
|
rc = test_create_race("human");
|
|
|
|
rc->battle_flags |= BF_EQUIPMENT;
|
|
|
|
du = test_create_unit(test_create_faction(rc), r);
|
|
|
|
dt.index = 0;
|
|
|
|
|
|
|
|
i_change(&du->items, ishield, 1);
|
|
|
|
i_change(&du->items, ichain, 1);
|
|
|
|
dt.fighter = setup_fighter(&b, du);
|
|
|
|
wtype->flags = WTF_MISSILE;
|
|
|
|
achain->projectile = 1.0;
|
|
|
|
CuAssertIntEquals_Msg(tc, "projectile armor", -1, calculate_armor(dt, 0, wtype, 0));
|
|
|
|
achain->projectile = 0.0;
|
|
|
|
ashield->projectile = 1.0;
|
|
|
|
CuAssertIntEquals_Msg(tc, "projectile shield", -1, calculate_armor(dt, 0, wtype, 0));
|
|
|
|
wtype->flags = WTF_NONE;
|
|
|
|
CuAssertIntEquals_Msg(tc, "no projectiles", 4, calculate_armor(dt, 0, wtype, 0));
|
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2016-08-29 09:53:09 +02:00
|
|
|
static void test_battle_skilldiff(CuTest *tc)
|
2016-08-29 09:04:43 +02:00
|
|
|
{
|
|
|
|
troop ta, td;
|
|
|
|
region *r;
|
|
|
|
unit *ua, *ud;
|
|
|
|
battle *b = NULL;
|
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2016-08-29 09:53:09 +02:00
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
ud = test_create_unit(test_create_faction(0), r);
|
|
|
|
ua = test_create_unit(test_create_faction(0), r);
|
|
|
|
td.fighter = setup_fighter(&b, ud);
|
|
|
|
td.index = 0;
|
|
|
|
ta.fighter = setup_fighter(&b, ua);
|
|
|
|
ta.index = 0;
|
|
|
|
ua = test_create_unit(test_create_faction(0), r);
|
|
|
|
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
|
|
|
|
|
|
|
ta.fighter->person[0].attack = 2;
|
|
|
|
td.fighter->person[0].defence = 1;
|
|
|
|
CuAssertIntEquals(tc, 1, skilldiff(ta, td, 0));
|
|
|
|
|
2016-08-29 09:53:09 +02:00
|
|
|
td.fighter->person[0].flags |= FL_SLEEPING;
|
|
|
|
CuAssertIntEquals(tc, 3, skilldiff(ta, td, 0));
|
|
|
|
|
2017-02-18 21:15:14 +01:00
|
|
|
/* TODO: unarmed halfling vs. dragon: +5 */
|
|
|
|
/* TODO: rule_goblin_bonus */
|
|
|
|
/* TODO: weapon modifiers, missiles, skill_formula */
|
2016-08-29 09:53:09 +02:00
|
|
|
|
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_battle_skilldiff_building(CuTest *tc)
|
|
|
|
{
|
|
|
|
troop ta, td;
|
|
|
|
region *r;
|
|
|
|
unit *ua, *ud;
|
|
|
|
battle *b = NULL;
|
|
|
|
building_type *btype;
|
2016-08-29 21:34:30 +02:00
|
|
|
const curse_type *strongwall_ct, *magicwalls_ct;
|
2016-08-29 09:53:09 +02:00
|
|
|
|
2017-02-22 20:16:51 +01:00
|
|
|
test_setup();
|
2017-02-22 19:38:46 +01:00
|
|
|
btype = setup_castle();
|
2016-08-29 09:53:09 +02:00
|
|
|
strongwall_ct = ct_find("strongwall");
|
|
|
|
magicwalls_ct = ct_find("magicwalls");
|
|
|
|
|
|
|
|
r = test_create_region(0, 0, 0);
|
|
|
|
ud = test_create_unit(test_create_faction(0), r);
|
|
|
|
ud->building = test_create_building(ud->region, btype);
|
|
|
|
ua = test_create_unit(test_create_faction(0), r);
|
|
|
|
td.fighter = setup_fighter(&b, ud);
|
|
|
|
td.index = 0;
|
|
|
|
ta.fighter = setup_fighter(&b, ua);
|
|
|
|
ta.index = 0;
|
|
|
|
ua = test_create_unit(test_create_faction(0), r);
|
|
|
|
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
|
|
|
|
2017-02-22 19:38:46 +01:00
|
|
|
ud->building->size = 10;
|
|
|
|
CuAssertIntEquals(tc, -1, skilldiff(ta, td, 0));
|
2016-08-29 09:53:09 +02:00
|
|
|
|
|
|
|
create_curse(NULL, &ud->building->attribs, magicwalls_ct, 1, 1, 1, 1);
|
2017-02-22 19:38:46 +01:00
|
|
|
CuAssertIntEquals(tc, -2, skilldiff(ta, td, 0));
|
2016-08-29 09:53:09 +02:00
|
|
|
|
|
|
|
create_curse(NULL, &ud->building->attribs, strongwall_ct, 1, 1, 2, 1);
|
2017-02-22 19:38:46 +01:00
|
|
|
CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0));
|
2016-08-29 09:53:09 +02:00
|
|
|
|
2016-08-29 09:04:43 +02:00
|
|
|
free_battle(b);
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
CuSuite *get_battle_suite(void)
|
|
|
|
{
|
2015-01-12 16:57:05 +01:00
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_make_fighter);
|
2016-08-29 09:04:43 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_battle_skilldiff);
|
2016-08-29 09:53:09 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_battle_skilldiff_building);
|
2015-01-12 16:57:05 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
|
|
|
|
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
|
|
|
|
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
|
|
|
|
SUITE_ADD_TEST(suite, test_building_defence_bonus);
|
2015-11-03 14:22:50 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_calculate_armor);
|
2015-11-21 19:02:14 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_natural_armor);
|
2015-12-05 17:17:21 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_magic_resistance);
|
2015-11-03 19:11:03 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_projectile_armor);
|
2015-01-12 16:57:05 +01:00
|
|
|
return suite;
|
2011-03-13 02:01:20 +01:00
|
|
|
}
|