From e2f954b7f6e17eb227ada0fbca3f7c751655f2c1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Dec 2017 10:16:56 +0100 Subject: [PATCH] BUG 2392: anyone can use weapons, as long as they have _some_ skill. --- src/battle.c | 2 -- src/battle.test.c | 4 ++-- src/economy.test.c | 2 +- src/guard.test.c | 27 ++++++++++++++------------- src/kernel/item.c | 4 +--- src/kernel/item.h | 3 +-- src/kernel/xmlreader.c | 4 +--- src/laws.c | 3 +-- src/laws.test.c | 17 ++++++----------- src/spy.test.c | 2 +- 10 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/battle.c b/src/battle.c index 823fd89f1..bb269d119 100644 --- a/src/battle.c +++ b/src/battle.c @@ -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; diff --git a/src/battle.test.c b/src/battle.test.c index 3669f25d1..901c3e108 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -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); diff --git a/src/economy.test.c b/src/economy.test.c index 437f59d79..ddb715af8 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -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); diff --git a/src/guard.test.c b/src/guard.test.c index 8302bcc9a..b9bb69dcf 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -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); diff --git a/src/kernel/item.c b/src/kernel/item.c index a633d5463..ef6b9d22c 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -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; diff --git a/src/kernel/item.h b/src/kernel/item.h index 6477a4923..cc5991ed6 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -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); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index ace0a4cc6..649b61135 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -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; diff --git a/src/laws.c b/src/laws.c index 873dc470f..d12406048 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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; } diff --git a/src/laws.test.c b/src/laws.test.c index b00361dbe..898ae4627 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -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); diff --git a/src/spy.test.c b/src/spy.test.c index 11c8c1ff1..64ca60541 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -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);