blnak line conflict?

This commit is contained in:
Enno Rehling 2019-04-03 18:24:42 +02:00
commit 6351f04916
19 changed files with 2928 additions and 2870 deletions

View file

@ -31,9 +31,15 @@ function test_undead_reserve_other()
u1.name = 'Xolgrim' u1.name = 'Xolgrim'
process_orders() process_orders()
-- Intermittent Failure: expected 0 but was 2 if 0 ~= u1:get_item("log") then
-- try to catch that intermittent bug:
print(u1:show())
end
assert_equal(0, u1:get_item("log")) assert_equal(0, u1:get_item("log"))
if 2 ~= u2:get_item("log") then
-- try to catch that intermittent bug:
print(u2:show())
end
assert_equal(2, u2:get_item("log")) assert_equal(2, u2:get_item("log"))
end end

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

@ -383,7 +383,8 @@ static int tolua_faction_set_password(lua_State * L)
{ {
faction *self = (faction *)tolua_tousertype(L, 1, NULL); faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char * passw = tolua_tostring(L, 2, NULL); const char * passw = tolua_tostring(L, 2, NULL);
faction_setpassword(self, password_hash(passw, PASSWORD_DEFAULT)); faction_setpassword(self,
passw ? password_hash(passw, PASSWORD_DEFAULT) : NULL);
return 0; return 0;
} }

View file

@ -58,6 +58,7 @@ static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, r
int err; int err;
region *r; region *r;
cJSON *json, *attr, *result, *regs; cJSON *json, *attr, *result, *regs;
size_t sz;
r = test_create_region(0, 0, terrain); r = test_create_region(0, 0, terrain);
@ -65,7 +66,8 @@ static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, r
err = json_export(&out, EXPORT_REGIONS); err = json_export(&out, EXPORT_REGIONS);
CuAssertIntEquals(tc, 0, err); CuAssertIntEquals(tc, 0, err);
out.api->rewind(out.handle); out.api->rewind(out.handle);
out.api->read(out.handle, buf, sizeof(buf)); sz = out.api->read(out.handle, buf, sizeof(buf));
buf[sz] = '\0';
mstream_done(&out); mstream_done(&out);
json = cJSON_Parse(buf); json = cJSON_Parse(buf);

View file

@ -28,6 +28,7 @@ typedef struct allies {
static void block_insert(allies *al, struct faction *f, int status) { static void block_insert(allies *al, struct faction *f, int status) {
int i = al->num++; int i = al->num++;
assert(status > 0);
al->status[i] = status; al->status[i] = status;
al->factions[i] = f; al->factions[i] = f;
/* TODO: heapify */ /* TODO: heapify */
@ -94,13 +95,17 @@ void ally_set(allies **p_al, struct faction *f, int status)
return; return;
} }
if (al->num < BLOCKSIZE) { if (al->num < BLOCKSIZE) {
if (status > 0) {
block_insert(al, f, status); block_insert(al, f, status);
}
return; return;
} }
p_al = &al->next; p_al = &al->next;
} }
if (status > 0) {
*p_al = calloc(1, sizeof(allies)); *p_al = calloc(1, sizeof(allies));
block_insert(*p_al, f, status); block_insert(*p_al, f, status);
}
} }
void write_allies(gamedata * data, const allies *alist) void write_allies(gamedata * data, const allies *alist)
@ -112,6 +117,7 @@ void write_allies(gamedata * data, const allies *alist)
const faction * f = al->factions[i]; const faction * f = al->factions[i];
if (f && f->_alive) { if (f && f->_alive) {
write_faction_reference(f, data->store); write_faction_reference(f, data->store);
assert(al->status[i] > 0);
WRITE_INT(data->store, al->status[i]); WRITE_INT(data->store, al->status[i]);
} }
} }
@ -132,8 +138,11 @@ void read_allies(gamedata * data, allies **p_al)
f = findfaction(aid); f = findfaction(aid);
if (!f) f = faction_create(aid); if (!f) f = faction_create(aid);
READ_INT(data->store, &status); READ_INT(data->store, &status);
/* NB: some data files have allies with status=0 */
if (status > 0) {
ally_set(p_al, f, status); ally_set(p_al, f, status);
} }
}
} }
void allies_free(allies *al) void allies_free(allies *al)

View file

@ -1,6 +1,7 @@
#include <platform.h> #include <platform.h>
#include "types.h" #include "types.h"
#include "ally.h" #include "ally.h"
#include "faction.h"
#include <CuTest.h> #include <CuTest.h>
#include <tests.h> #include <tests.h>
@ -41,11 +42,36 @@ static void test_allies(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void test_allies_set(CuTest *tc) {
struct faction *f1, *f2;
struct allies * al = NULL;
test_setup();
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
CuAssertPtrEquals(tc, NULL, al);
ally_set(&al, f1, HELP_ALL);
CuAssertPtrNotNull(tc, al);
ally_set(&al, f1, DONT_HELP);
CuAssertPtrEquals(tc, NULL, f1->allies);
ally_set(&al, f1, DONT_HELP);
CuAssertPtrEquals(tc, NULL, al);
ally_set(&al, f1, HELP_ALL);
ally_set(&al, f2, DONT_HELP);
ally_set(&al, f1, DONT_HELP);
CuAssertPtrEquals(tc, NULL, al);
test_teardown();
}
CuSuite *get_ally_suite(void) CuSuite *get_ally_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_allies); SUITE_ADD_TEST(suite, test_allies);
SUITE_ADD_TEST(suite, test_allies_clone); SUITE_ADD_TEST(suite, test_allies_clone);
SUITE_ADD_TEST(suite, test_allies_set);
return suite; return suite;
} }

View file

@ -299,7 +299,7 @@ unit *addplayer(region * r, faction * f)
} while (rc == NULL || urc == RC_DAEMON || !playerrace(rc)); } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc));
u->irace = rc; u->irace = rc;
} }
f->lastorders = 0;
return u; return u;
} }
@ -564,8 +564,12 @@ const char *faction_getpassword(const faction *f) {
void faction_setpassword(faction * f, const char *pwhash) void faction_setpassword(faction * f, const char *pwhash)
{ {
assert(pwhash); if (pwhash) {
f->password_id = dbstring_save(pwhash); f->password_id = dbstring_save(pwhash);
}
else {
f->password_id = 0;
}
} }
bool valid_race(const struct faction *f, const struct race *rc) bool valid_race(const struct faction *f, const struct race *rc)

View file

@ -41,8 +41,9 @@
#define CRYPT_VERSION 363 /* passwords are encrypted */ #define CRYPT_VERSION 363 /* passwords are encrypted */
#define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */ #define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */
#define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */ #define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */
#define FIX_STARTLEVEL_VERSION 366 /* fixing resource startlevels */
#define RELEASE_VERSION FAMILIAR_FIXSPELLBOOK_VERSION /* current datafile */ #define RELEASE_VERSION FIX_STARTLEVEL_VERSION /* current datafile */
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */ #define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */

View file

@ -630,6 +630,7 @@ static void fix_baselevel(region *r) {
} }
} }
} }
} }
} }
@ -801,6 +802,11 @@ static region *readregion(gamedata *data, int x, int y)
} }
} }
read_attribs(data, &r->attribs, r); read_attribs(data, &r->attribs, r);
if (r->resources && data->version < FIX_STARTLEVEL_VERSION) {
/* we had some badly made rawmaterials before this */
fix_baselevel(r);
}
return r; return r;
} }

View file

@ -8,7 +8,7 @@
#ifndef ERESSEA_VERSION #ifndef ERESSEA_VERSION
/* the version number, if it was not passed to make with -D */ /* the version number, if it was not passed to make with -D */
#define ERESSEA_VERSION "3.19.0" #define ERESSEA_VERSION "3.20.0"
#endif #endif
const char *eressea_version(void) { const char *eressea_version(void) {

View file

@ -3205,7 +3205,7 @@ static int faction_getmages(faction * f, unit ** results, int numresults)
for (u = f->units; u; u = u->nextF) { for (u = f->units; u; u = u->nextF) {
if (u->number > 0) { if (u->number > 0) {
struct sc_mage * mage = get_mage(u); struct sc_mage * mage = get_mage(u);
if (mage && mage_get_spellbook(mage)) { if (mage) {
int level = effskill(u, SK_MAGIC, NULL); int level = effskill(u, SK_MAGIC, NULL);
if (level > maxlevel) { if (level > maxlevel) {
maxlevel = level; maxlevel = level;

View file

@ -30,23 +30,23 @@ static int age_chance(int a, int b, int p) {
#define DRAGONAGE 27 #define DRAGONAGE 27
#define WYRMAGE 68 #define WYRMAGE 68
static void evolve_dragon(unit * u, const struct race *rc) {
scale_number(u, 1);
u_setrace(u, rc);
u->irace = NULL;
u->hp = unit_max_hp(u);
}
void age_firedragon(unit * u) void age_firedragon(unit * u)
{ {
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) { if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); evolve_dragon(u, get_race(RC_DRAGON));
u_setrace(u, get_race(RC_DRAGON));
u->irace = NULL;
scale_number(u, 1);
u->hp = (int)(unit_max_hp(u) * u->number * q);
} }
} }
void age_dragon(unit * u) void age_dragon(unit * u)
{ {
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) { if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); evolve_dragon(u, get_race(RC_WYRM));
u_setrace(u, get_race(RC_WYRM));
u->irace = NULL;
u->hp = (int)(unit_max_hp(u) * u->number * q);
} }
} }

View file

@ -1509,7 +1509,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda
if ((mode & HELP_ALL) == HELP_ALL) { if ((mode & HELP_ALL) == HELP_ALL) {
sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY])); sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY]));
} }
else { else if (mode > 0) {
int h, hh = 0; int h, hh = 0;
for (h = 1; h <= HELP_TRAVEL; h *= 2) { for (h = 1; h <= HELP_TRAVEL; h *= 2) {
int p = MAXPARAMS; int p = MAXPARAMS;
@ -2173,8 +2173,8 @@ report_plaintext(const char *filename, report_context * ctx,
if (wants_stats && r->seen.mode >= seen_travel) { if (wants_stats && r->seen.mode >= seen_travel) {
if (r->land || r->seen.mode >= seen_unit) { if (r->land || r->seen.mode >= seen_unit) {
newline(out);
statistics(out, r, f); statistics(out, r, f);
newline(out);
} }
} }

View file

@ -144,8 +144,6 @@ bool omniscient(const faction *f)
return (f->race == rc_template); return (f->race == rc_template);
} }
static char *groupid(const struct group *g, const struct faction *f) static char *groupid(const struct group *g, const struct faction *f)
{ {
typedef char name[OBJECTIDSIZE + 1]; typedef char name[OBJECTIDSIZE + 1];
@ -1603,7 +1601,9 @@ int write_reports(faction * f)
if (noreports) { if (noreports) {
return false; return false;
} }
if (f->lastorders == 0) { if (f->lastorders == 0 || f->age <= 1) {
/* neue Parteien, oder solche die noch NIE einen Zug gemacht haben,
* kriegen ein neues Passwort: */
password = faction_genpassword(f, buffer); password = faction_genpassword(f, buffer);
} }
prepare_report(&ctx, f, password); prepare_report(&ctx, f, password);

View file

@ -963,6 +963,7 @@ static void test_reports_genpassword(CuTest *tc) {
CuAssertTrue(tc, f->password_id != 0); CuAssertTrue(tc, f->password_id != 0);
test_clear_messagelist(&f->msgs); test_clear_messagelist(&f->msgs);
f->lastorders = 1; f->lastorders = 1;
f->age = 2;
pwid = f->password_id; pwid = f->password_id;
write_reports(f); write_reports(f);
CuAssertIntEquals(tc, pwid, f->password_id); CuAssertIntEquals(tc, pwid, f->password_id);

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) {
item *it = *itp;
requirement *mat = wp->type->itype->construction->materials; requirement *mat = wp->type->itype->construction->materials;
bool iron = false; int n = force;
if (it->number < n) n = it->number;
while (mat && mat->number > 0) { while (mat && mat->number > 0) {
if (mat->rtype == get_resourcetype(R_IRON)) { if (mat->rtype == get_resourcetype(R_IRON)) {
iron = true;
break;
}
mat++;
}
if (iron) {
int p; int p;
force -= n; force -= n;
wp->used -= n;
k += n; k += n;
i_change(&df->unit->items, wp->type->itype, -n); i_change(itp, wp->type->itype, -n);
for (p = 0; n && p != df->unit->number; ++p) {
if (df->person[p].melee == wp) {
df->person[p].melee = NULL;
--n;
}
}
for (p = 0; n && p != df->unit->number; ++p) { for (p = 0; n && p != df->unit->number; ++p) {
if (df->person[p].missile == wp) { if (df->person[p].missile == wp) {
df->person[p].missile = NULL; df->person[p].missile = NULL;
--n; --n;
} }
} }
for (p = 0; n && p != df->unit->number; ++p) { break;
if (df->person[p].melee == wp) {
df->person[p].melee = NULL;
--n;
} }
mat++;
} }
} }
} }

View file

@ -88,7 +88,7 @@ const char *itoab_r(int i, int base, char *s, size_t len)
} }
} }
else { else {
log_error("static buffer exhauset, itoab(%d, %d)", i, base); log_error("static buffer exhausted, itoab(%d, %d)", i, base);
assert(i == 0 || !"itoab: static buffer exhausted"); assert(i == 0 || !"itoab: static buffer exhausted");
} }
} }