Bug 2569: Rostregen macht zu viele Waffen kaputt.

This commit is contained in:
Enno Rehling 2019-03-31 21:03:31 +02:00
parent 8f5eff063e
commit 17484e220f
4 changed files with 2840 additions and 2838 deletions

File diff suppressed because it is too large Load Diff

View File

@ -121,7 +121,6 @@ extern "C" {
} battle; } battle;
typedef struct weapon { typedef struct weapon {
int count, used;
const struct weapon_type *type; const struct weapon_type *type;
int attackskill; int attackskill;
int defenseskill; int defenseskill;

View File

@ -96,6 +96,7 @@ static void test_make_fighter(CuTest * tc)
static void test_select_weapon_restricted(CuTest *tc) { static void test_select_weapon_restricted(CuTest *tc) {
item_type *itype; item_type *itype;
weapon_type * wtype;
unit *au; unit *au;
fighter *af; fighter *af;
battle *b; battle *b;
@ -104,7 +105,7 @@ static void test_select_weapon_restricted(CuTest *tc) {
test_setup(); test_setup();
au = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); au = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
itype = test_create_itemtype("halberd"); itype = test_create_itemtype("halberd");
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); wtype = new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE);
i_change(&au->items, itype, 1); i_change(&au->items, itype, 1);
rc = test_create_race("smurf"); rc = test_create_race("smurf");
CuAssertIntEquals(tc, 0, rc->mask_item & au->_race->mask_item); CuAssertIntEquals(tc, 0, rc->mask_item & au->_race->mask_item);
@ -112,15 +113,15 @@ static void test_select_weapon_restricted(CuTest *tc) {
b = make_battle(au->region); b = make_battle(au->region);
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
CuAssertPtrNotNull(tc, af->weapons); CuAssertPtrNotNull(tc, af->weapons);
CuAssertIntEquals(tc, 1, af->weapons[0].count); CuAssertPtrEquals(tc, wtype, (void *)af->weapons[0].type);
CuAssertIntEquals(tc, 0, af->weapons[1].count); CuAssertPtrEquals(tc, NULL, (void *)af->weapons[1].type);
free_battle(b); free_battle(b);
itype->mask_deny = rc_mask(au->_race); itype->mask_deny = rc_mask(au->_race);
b = make_battle(au->region); b = make_battle(au->region);
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
CuAssertPtrNotNull(tc, af->weapons); CuAssertPtrNotNull(tc, af->weapons);
CuAssertIntEquals(tc, 0, af->weapons[0].count); CuAssertPtrEquals(tc, NULL, (void *)af->weapons[0].type);
free_battle(b); free_battle(b);
itype->mask_deny = 0; itype->mask_deny = 0;
@ -128,9 +129,8 @@ static void test_select_weapon_restricted(CuTest *tc) {
b = make_battle(au->region); b = make_battle(au->region);
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
CuAssertPtrNotNull(tc, af->weapons); CuAssertPtrNotNull(tc, af->weapons);
CuAssertIntEquals(tc, 1, af->weapons[0].count); CuAssertPtrEquals(tc, wtype, (void *)af->weapons[0].type);
CuAssertPtrEquals(tc, itype->rtype->wtype, (void *)af->weapons[0].type); CuAssertPtrEquals(tc, NULL, (void *)af->weapons[1].type);
CuAssertIntEquals(tc, 0, af->weapons[1].count);
free_battle(b); free_battle(b);
itype->mask_deny = 0; itype->mask_deny = 0;
@ -138,7 +138,7 @@ static void test_select_weapon_restricted(CuTest *tc) {
b = make_battle(au->region); b = make_battle(au->region);
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
CuAssertPtrNotNull(tc, af->weapons); CuAssertPtrNotNull(tc, af->weapons);
CuAssertIntEquals(tc, 0, af->weapons[0].count); CuAssertPtrEquals(tc, NULL, (void *)af->weapons[0].type);
free_battle(b); free_battle(b);
itype->mask_deny = 0; itype->mask_deny = 0;
@ -146,8 +146,8 @@ static void test_select_weapon_restricted(CuTest *tc) {
b = make_battle(au->region); b = make_battle(au->region);
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
CuAssertPtrNotNull(tc, af->weapons); CuAssertPtrNotNull(tc, af->weapons);
CuAssertIntEquals(tc, 1, af->weapons[0].count); CuAssertPtrEquals(tc, wtype, (void *)af->weapons[0].type);
CuAssertIntEquals(tc, 0, af->weapons[1].count); CuAssertPtrEquals(tc, NULL, (void *)af->weapons[1].type);
free_battle(b); free_battle(b);
test_teardown(); test_teardown();

View File

@ -298,35 +298,35 @@ int sp_combatrosthauch(struct castorder * co)
for (w = 0; df->weapons[w].type != NULL; ++w) { for (w = 0; df->weapons[w].type != NULL; ++w) {
weapon *wp = df->weapons; weapon *wp = df->weapons;
int n = force; if (df->unit->items && force > 0) {
if (n > wp->used) n = wp->used; item ** itp = i_find(&df->unit->items, wp->type->itype);
if (n) { if (*itp) {
requirement *mat = wp->type->itype->construction->materials; item *it = *itp;
bool iron = false; requirement *mat = wp->type->itype->construction->materials;
while (mat && mat->number > 0) { int n = force;
if (mat->rtype == get_resourcetype(R_IRON)) { if (it->number < n) n = it->number;
iron = true;
break; while (mat && mat->number > 0) {
} if (mat->rtype == get_resourcetype(R_IRON)) {
mat++; int p;
} force -= n;
if (iron) { k += n;
int p; i_change(itp, wp->type->itype, -n);
force -= n; for (p = 0; n && p != df->unit->number; ++p) {
wp->used -= n; if (df->person[p].melee == wp) {
k += n; df->person[p].melee = NULL;
i_change(&df->unit->items, wp->type->itype, -n); --n;
for (p = 0; n && p != df->unit->number; ++p) { }
if (df->person[p].missile == wp) { }
df->person[p].missile = NULL; for (p = 0; n && p != df->unit->number; ++p) {
--n; if (df->person[p].missile == wp) {
} df->person[p].missile = NULL;
} --n;
for (p = 0; n && p != df->unit->number; ++p) { }
if (df->person[p].melee == wp) { }
df->person[p].melee = NULL; break;
--n;
} }
mat++;
} }
} }
} }