forked from github/server
BUG 2392: anyone can use weapons, as long as they have _some_ skill.
This commit is contained in:
parent
0f014153c0
commit
e2f954b7f6
|
@ -640,8 +640,6 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking)
|
|||
if (!i_canuse(u, wtype->itype))
|
||||
return -1;
|
||||
skill = effskill(u, wtype->skill, 0);
|
||||
if (skill < wtype->minskill)
|
||||
skill = 0;
|
||||
if (skill > 0) {
|
||||
if (attacking) {
|
||||
skill += u_race(u)->at_bonus;
|
||||
|
|
|
@ -268,7 +268,7 @@ static void test_calculate_armor(CuTest * tc)
|
|||
ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
|
||||
ichain = it_get_or_create(rt_get_or_create("chainmail"));
|
||||
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);
|
||||
wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE);
|
||||
rc = test_create_race("human");
|
||||
du = test_create_unit(test_create_faction(rc), r);
|
||||
dt.index = 0;
|
||||
|
@ -409,7 +409,7 @@ static void test_projectile_armor(CuTest * tc)
|
|||
ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
|
||||
ichain = it_get_or_create(rt_get_or_create("chainmail"));
|
||||
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);
|
||||
wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE);
|
||||
rc = test_create_race("human");
|
||||
rc->battle_flags |= BF_EQUIPMENT;
|
||||
du = test_create_unit(test_create_faction(rc), r);
|
||||
|
|
|
@ -326,7 +326,7 @@ static void test_tax_cmd(CuTest *tc) {
|
|||
silver = get_resourcetype(R_SILVER)->itype;
|
||||
|
||||
sword = test_create_itemtype("sword");
|
||||
new_weapontype(sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 1);
|
||||
new_weapontype(sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
i_change(&u->items, sword, 1);
|
||||
set_level(u, SK_MELEE, 1);
|
||||
|
||||
|
|
|
@ -44,14 +44,19 @@ static void test_guard_unskilled(CuTest * tc)
|
|||
|
||||
test_setup();
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
r = test_create_region(0, 0, 0);
|
||||
u = test_create_unit(test_create_faction(0), r);
|
||||
ug = test_create_unit(test_create_faction(0), r);
|
||||
i_change(&ug->items, itype, 1);
|
||||
|
||||
setguard(ug, true);
|
||||
CuAssertPtrEquals(tc, NULL, is_guarded(r, u));
|
||||
|
||||
set_level(ug, SK_MELEE, 1);
|
||||
setguard(ug, true);
|
||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u));
|
||||
CuAssertPtrEquals(tc, ug, is_guarded(r, u));
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
|
@ -63,7 +68,7 @@ static void test_guard_armed(CuTest * tc)
|
|||
|
||||
test_setup();
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
r = test_create_region(0, 0, 0);
|
||||
u = test_create_unit(test_create_faction(0), r);
|
||||
ug = test_create_unit(test_create_faction(0), r);
|
||||
|
@ -82,18 +87,14 @@ static void test_is_guard(CuTest * tc)
|
|||
|
||||
test_setup();
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
r = test_create_region(0, 0, 0);
|
||||
ug = test_create_unit(test_create_faction(0), r);
|
||||
i_change(&ug->items, itype, 1);
|
||||
set_level(ug, SK_MELEE, 2);
|
||||
setguard(ug, true);
|
||||
CuAssertIntEquals(tc, 1, armedmen(ug, false));
|
||||
CuAssertTrue(tc, is_guard(ug));
|
||||
set_level(ug, SK_MELEE, 1);
|
||||
CuAssertIntEquals(tc, 0, armedmen(ug, false));
|
||||
CuAssertTrue(tc, !is_guard(ug));
|
||||
set_level(ug, SK_MELEE, 2);
|
||||
set_level(ug, SK_MELEE, 1);
|
||||
CuAssertIntEquals(tc, 1, armedmen(ug, false));
|
||||
CuAssertTrue(tc, is_guard(ug));
|
||||
test_cleanup();
|
||||
|
@ -142,11 +143,11 @@ static void test_update_guard(CuTest * tc)
|
|||
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
||||
t_plain = test_create_terrain("packice", ARCTIC_REGION);
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
r = test_create_region(0, 0, t_plain);
|
||||
ug = test_create_unit(test_create_faction(0), r);
|
||||
i_change(&ug->items, itype, 1);
|
||||
set_level(ug, SK_MELEE, 2);
|
||||
set_level(ug, SK_MELEE, 1);
|
||||
setguard(ug, true);
|
||||
CuAssertIntEquals(tc, 1, armedmen(ug, false));
|
||||
CuAssertTrue(tc, is_guard(ug));
|
||||
|
@ -169,11 +170,11 @@ static void test_guard_on(CuTest * tc)
|
|||
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
||||
t_plain = test_create_terrain("plain", LAND_REGION);
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
r = test_create_region(0, 0, t_plain);
|
||||
ug = test_create_unit(test_create_faction(0), r);
|
||||
i_change(&ug->items, itype, 1);
|
||||
set_level(ug, SK_MELEE, 2);
|
||||
set_level(ug, SK_MELEE, 1);
|
||||
ug->thisorder = create_order(K_GUARD, ug->faction->locale, NULL);
|
||||
|
||||
setguard(ug, false);
|
||||
|
|
|
@ -271,11 +271,10 @@ luxury_type *new_luxurytype(item_type * itype, int price)
|
|||
|
||||
weapon_type *new_weapontype(item_type * itype,
|
||||
int wflags, variant magres, const char *damage[], int offmod, int defmod,
|
||||
int reload, skill_t sk, int minskill)
|
||||
int reload, skill_t sk)
|
||||
{
|
||||
weapon_type *wtype;
|
||||
|
||||
assert(minskill > 0);
|
||||
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
||||
|
||||
wtype = calloc(sizeof(weapon_type), 1);
|
||||
|
@ -287,7 +286,6 @@ weapon_type *new_weapontype(item_type * itype,
|
|||
wtype->flags |= wflags;
|
||||
wtype->itype = itype;
|
||||
wtype->magres = magres;
|
||||
wtype->minskill = minskill;
|
||||
wtype->offmod = offmod;
|
||||
wtype->reload = reload;
|
||||
wtype->skill = sk;
|
||||
|
|
|
@ -187,7 +187,6 @@ extern "C" {
|
|||
char *damage[2];
|
||||
unsigned int flags;
|
||||
skill_t skill;
|
||||
int minskill;
|
||||
int offmod;
|
||||
int defmod;
|
||||
variant magres;
|
||||
|
@ -232,7 +231,7 @@ extern "C" {
|
|||
luxury_type *new_luxurytype(item_type * itype, int price);
|
||||
weapon_type *new_weapontype(item_type * itype, int wflags,
|
||||
variant magres, const char *damage[], int offmod, int defmod, int reload,
|
||||
skill_t sk, int minskill);
|
||||
skill_t sk);
|
||||
armor_type *new_armortype(item_type * itype, double penalty,
|
||||
variant magres, int prot, unsigned int flags);
|
||||
potion_type *new_potiontype(item_type * itype, int level);
|
||||
|
|
|
@ -523,7 +523,6 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
|||
xmlChar *propValue;
|
||||
int k;
|
||||
skill_t sk;
|
||||
int minskill = xml_ivalue(node, "minskill", 1);
|
||||
int offmod = xml_ivalue(node, "offmod", 0);
|
||||
int defmod = xml_ivalue(node, "defmod", 0);
|
||||
int reload = xml_ivalue(node, "reload", 0);
|
||||
|
@ -555,8 +554,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
|||
xmlFree(propValue);
|
||||
|
||||
wtype =
|
||||
new_weapontype(itype, flags, magres, NULL, offmod, defmod, reload, sk,
|
||||
minskill);
|
||||
new_weapontype(itype, flags, magres, NULL, offmod, defmod, reload, sk);
|
||||
|
||||
/* reading weapon/damage */
|
||||
xpath->node = node;
|
||||
|
|
|
@ -3904,9 +3904,8 @@ int armedmen(const unit * u, bool siege_weapons)
|
|||
const weapon_type *wtype = resource2weapon(itm->type->rtype);
|
||||
if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE)))
|
||||
continue;
|
||||
if (effskill(u, wtype->skill, 0) >= wtype->minskill)
|
||||
if (effskill(u, wtype->skill, 0) >= 1)
|
||||
n += itm->number;
|
||||
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
||||
if (n >= u->number)
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -720,9 +720,9 @@ void setup_guard(guard_fixture *fix, bool armed) {
|
|||
if (armed) {
|
||||
item_type *itype;
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
i_change(&u->items, itype, 1);
|
||||
set_level(u, SK_MELEE, 2);
|
||||
set_level(u, SK_MELEE, 1);
|
||||
}
|
||||
fix->u = u;
|
||||
}
|
||||
|
@ -786,11 +786,11 @@ static void test_monsters_can_guard(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_low_skill_cannot_guard(CuTest *tc) {
|
||||
static void test_unskilled_cannot_guard(CuTest *tc) {
|
||||
guard_fixture fix;
|
||||
|
||||
setup_guard(&fix, true);
|
||||
set_level(fix.u, SK_MELEE, 1);
|
||||
set_level(fix.u, SK_MELEE, 0);
|
||||
CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u));
|
||||
update_guards();
|
||||
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||
|
@ -1638,7 +1638,7 @@ static void test_armedmen(CuTest *tc) {
|
|||
test_setup();
|
||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||
it_sword = test_create_itemtype("sword");
|
||||
wtype = new_weapontype(it_sword, 0, frac_make(1, 2), 0, 0, 0, 0, SK_MELEE, 1);
|
||||
wtype = new_weapontype(it_sword, 0, frac_make(1, 2), 0, 0, 0, 0, SK_MELEE);
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, true));
|
||||
set_level(u, SK_MELEE, 1);
|
||||
|
@ -1655,11 +1655,6 @@ static void test_armedmen(CuTest *tc) {
|
|||
set_level(u, SK_MELEE, 1);
|
||||
i_change(&u->items, it_sword, -1);
|
||||
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||
wtype->minskill = 2;
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||
set_level(u, SK_MELEE, 2);
|
||||
CuAssertIntEquals(tc, 1, armedmen(u, false));
|
||||
CuAssertIntEquals(tc, 1, armedmen(u, true));
|
||||
wtype->flags |= WTF_SIEGE;
|
||||
CuAssertIntEquals(tc, 0, armedmen(u, false));
|
||||
CuAssertIntEquals(tc, 1, armedmen(u, true));
|
||||
|
@ -1806,7 +1801,7 @@ CuSuite *get_laws_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_unarmed_races_can_guard);
|
||||
SUITE_ADD_TEST(suite, test_monsters_can_guard);
|
||||
SUITE_ADD_TEST(suite, test_fleeing_cannot_guard);
|
||||
SUITE_ADD_TEST(suite, test_low_skill_cannot_guard);
|
||||
SUITE_ADD_TEST(suite, test_unskilled_cannot_guard);
|
||||
SUITE_ADD_TEST(suite, test_reserve_self);
|
||||
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
||||
SUITE_ADD_TEST(suite, test_pay_cmd);
|
||||
|
|
|
@ -64,7 +64,7 @@ static void test_all_spy_message(CuTest *tc) {
|
|||
set_factionstealth(fix.victim, fix.spy->faction);
|
||||
|
||||
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
|
||||
i_change(&fix.victim->items, itype, 1);
|
||||
|
||||
spy_message(99, fix.spy, fix.victim);
|
||||
|
|
Loading…
Reference in New Issue