Merge branch 'develop' of github.com:ennorehling/eressea into develop

This commit is contained in:
Enno Rehling 2016-11-17 22:09:51 +01:00
commit aef475f663
20 changed files with 162 additions and 57 deletions

View File

@ -1216,7 +1216,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
while (chance(kritchance)) {
if (bdebug) {
fprintf(bdebug, "%s/%d lands a critical hit\n", unitid(au), at.index);
fprintf(bdebug, "%s/%d lands a critical hit\n", itoa36(au->no), at.index);
}
da += dice_rand(damage);
}
@ -1980,10 +1980,10 @@ debug_hit(troop at, const weapon * awp, troop dt, const weapon * dwp,
int skdiff, int dist, bool success)
{
fprintf(bdebug, "%.4s/%d [%6s/%d] %s %.4s/%d [%6s/%d] with %d, distance %d\n",
unitid(at.fighter->unit), at.index,
itoa36(at.fighter->unit->no), at.index,
LOC(default_locale, awp ? resourcename(awp->type->itype->rtype,
0) : "unarmed"), weapon_effskill(at, dt, awp, true, dist > 1),
success ? "hits" : "misses", unitid(dt.fighter->unit), dt.index,
success ? "hits" : "misses", itoa36(dt.fighter->unit->no), dt.index,
LOC(default_locale, dwp ? resourcename(dwp->type->itype->rtype,
0) : "unarmed"), weapon_effskill(dt, at, dwp, false, dist > 1), skdiff,
dist);
@ -2194,7 +2194,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack)
if (reload && wp && wp->type->reload && !getreload(ta)) {
int i = setreload(ta);
if (bdebug) {
fprintf(bdebug, "%s/%d reloading %d turns\n", unitid(au),
fprintf(bdebug, "%s/%d reloading %d turns\n", itoa36(au->no),
ta.index, i);
}
}
@ -3130,7 +3130,7 @@ static void print_stats(battle * b)
static int weapon_weight(const weapon * w, bool missile)
{
if (missile == i2b(fval(w->type, WTF_MISSILE))) {
if (missile == !!(fval(w->type, WTF_MISSILE))) {
return w->attackskill + w->defenseskill;
}
return 0;

View File

@ -782,7 +782,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
if (sf != u->faction)
stream_printf(out, "%d;Verkleidung\n", sf->no);
if (fval(u, UFL_ANON_FACTION))
stream_printf(out, "%d;Parteitarnung\n", i2b(fval(u, UFL_ANON_FACTION)));
stream_printf(out, "%d;Parteitarnung\n", (u->flags & UFL_ANON_FACTION)!=0);
if (otherfaction && otherfaction != u->faction) {
stream_printf(out, "%d;Anderepartei\n", otherfaction->no);
}
@ -794,7 +794,7 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
else {
if (fval(u, UFL_ANON_FACTION)) {
/* faction info is hidden */
stream_printf(out, "%d;Parteitarnung\n", i2b(fval(u, UFL_ANON_FACTION)));
stream_printf(out, "%d;Parteitarnung\n", (u->flags & UFL_ANON_FACTION) != 0);
}
else {
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);

View File

@ -426,7 +426,7 @@ building *new_building(const struct building_type * btype, region * r,
bname = parameters[P_GEBAEUDE];
}
assert(bname);
slprintf(buffer, sizeof(buffer), "%s %s", bname, buildingid(b));
slprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
b->name = _strdup(bname);
return b;
}

View File

@ -101,7 +101,6 @@ struct settings global = {
};
bool lomem = false;
FILE *logfile;
int turn = -1;
const char *parameters[MAXPARAMS] = {

View File

@ -34,8 +34,6 @@ struct param;
#define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. L<>nge der Strings, die
* von struct unitname, etc. zur<EFBFBD>ckgegeben werden. ohne die 0 */
#define i2b(i) ((bool)((i)?(true):(false)))
#define fval(u, i) ((u)->flags & (i))
#define fset(u, i) ((u)->flags |= (i))
#define freset(u, i) ((u)->flags &= ~(i))
@ -47,13 +45,6 @@ struct param;
bool isparam(const char *s, const struct locale * lang, param_t param);
param_t getparam(const struct locale *lang);
#define unitid(x) itoa36((x)->no)
#define buildingid(x) itoa36((x)->no)
#define shipid(x) itoa36((x)->no)
#define factionid(x) itoa36((x)->no)
#define curseid(x) itoa36((x)->no)
const char * game_name(void);
int game_id(void);
/* returns a value between [0..xpct_2], generated with two dice */
@ -166,10 +157,8 @@ struct param;
extern const char *localenames[];
extern settings global;
extern bool sqlpatch;
extern bool lomem; /* save memory */
extern int turn;
extern bool getunitpeasants;
#ifdef __cplusplus
}

View File

@ -273,11 +273,11 @@ faction *addfaction(const char *email, const char *password,
addlist(&factions, f);
fhash(f);
slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), factionid(f));
slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no));
f->name = _strdup(buf);
if (!f->race) {
log_warning("creating a faction that has no race", factionid(f));
log_warning("creating a faction that has no race", itoa36(f->no));
}
return f;
@ -828,7 +828,7 @@ int writepasswd(void)
for (f = factions; f; f = f->next) {
fprintf(F, "%s:%s:%s:%u\n",
factionid(f), f->email, f->_password, f->subscription);
itoa36(f->no), f->email, f->_password, f->subscription);
}
fclose(F);
return 0;

View File

@ -1291,7 +1291,7 @@ faction *read_faction(struct gamedata * data)
};
f->banner = _strdup(name);
log_debug(" - Lese Partei %s (%s)", f->name, factionid(f));
log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no));
READ_STR(data->store, name, sizeof(name));
if (set_email(&f->email, name) != 0) {

View File

@ -201,7 +201,7 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
sname = parameters[P_SHIP];
}
assert(sname);
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
slprintf(buffer, sizeof(buffer), "%s %s", sname, itoa36(sh->no));
sh->name = _strdup(buffer);
shash(sh);
if (r) {

View File

@ -494,6 +494,10 @@ attrib_type at_alias = {
NO_READ
};
/** remember old unit.no (for the creport, mostly)
* if alias is positive, then this unit was a TEMP
* if alias is negative, then this unit has been RENUMBERed
*/
int ualias(const unit * u)
{
attrib *a = a_find(u->attribs, &at_alias);
@ -1716,7 +1720,7 @@ void renumber_unit(unit *u, int no) {
uunhash(u);
if (!ualias(u)) {
attrib *a = a_add(&u->attribs, a_new(&at_alias));
a->data.i = -u->no; // TODO: why is the alias negative? confusing!
a->data.i = -u->no;
}
u->no = no;
uhash(u);

View File

@ -997,7 +997,7 @@ int quit_cmd(unit * u, struct order *ord)
char buffer[64];
write_order(ord, buffer, sizeof(buffer));
cmistake(u, ord, 86, MSG_EVENT);
log_warning("QUIT with illegal password for faction %s: %s\n", factionid(f), buffer);
log_warning("QUIT with illegal password for faction %s: %s\n", itoa36(f->no), buffer);
}
return 0;
}

View File

@ -347,7 +347,7 @@ attrib_type at_mage = {
bool is_mage(const unit * u)
{
return i2b(get_mage(u) != NULL);
return get_mage(u) != NULL;
}
sc_mage *get_mage(const unit * u)
@ -2167,7 +2167,7 @@ typedef struct familiar_data {
bool is_familiar(const unit * u)
{
attrib *a = a_find(u->attribs, &at_familiarmage);
return i2b(a != NULL);
return a != NULL;
}
static void

View File

@ -169,7 +169,7 @@ void score(void)
fprintf(scoreFP, "%30.30s (%3.3s) %5s (%3d)\n",
f->name,
f->race->_name,
factionid(f),
itoa36(f->no),
f->age);
}
fclose(scoreFP);

View File

@ -36,7 +36,6 @@ void renumber_factions(void)
attrib *a = a_find(f->attribs, &at_number);
int want;
struct renum **rn;
faction *old;
if (!a)
continue;
@ -45,12 +44,6 @@ void renumber_factions(void)
ADDMSG(&f->msgs, msg_message("renumber_twice", "id", want));
continue;
}
old = findfaction(want);
if (old) {
a_remove(&f->attribs, a);
ADDMSG(&f->msgs, msg_message("renumber_inuse", "id", want));
continue;
}
if (!faction_id_is_unused(want)) {
a_remove(&f->attribs, a);
ADDMSG(&f->msgs, msg_message("renumber_inuse", "id", want));
@ -151,7 +144,7 @@ int renumber_cmd(unit * u, order * ord)
cmistake(u, ord, 114, MSG_EVENT);
break;
}
if (findship(i) || findbuilding(i)) {
if (findship(i)) {
cmistake(u, ord, 115, MSG_EVENT);
break;
}
@ -180,7 +173,7 @@ int renumber_cmd(unit * u, order * ord)
cmistake(u, ord, 114, MSG_EVENT);
break;
}
if (findship(i) || findbuilding(i)) {
if (findbuilding(i)) {
cmistake(u, ord, 115, MSG_EVENT);
break;
}

View File

@ -29,6 +29,25 @@ static void test_renumber_faction(CuTest *tc) {
test_cleanup();
}
static void test_renumber_faction_duplicate(CuTest *tc) {
unit *u;
faction *f, *f2;
int no;
const struct locale *lang;
test_setup_ex(tc);
f2 = test_create_faction(0);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
no = f->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_FACTION]), itoa36(f2->no));
renumber_cmd(u, u->thisorder);
renumber_factions();
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "renumber_inuse"));
CuAssertIntEquals(tc, no, u->faction->no);
test_cleanup();
}
static void test_renumber_building(CuTest *tc) {
unit *u;
int uno, no;
@ -46,6 +65,26 @@ static void test_renumber_building(CuTest *tc) {
test_cleanup();
}
static void test_renumber_building_duplicate(CuTest *tc) {
unit *u;
faction *f;
int uno, no;
const struct locale *lang;
test_setup_ex(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
u->building = test_create_building(u->region, 0);
uno = u->building->no;
u->building = test_create_building(u->region, 0);
no = u->building->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_BUILDING]), itoa36(uno));
renumber_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115"));
CuAssertIntEquals(tc, no, u->building->no);
test_cleanup();
}
static void test_renumber_ship(CuTest *tc) {
unit *u;
int uno, no;
@ -63,6 +102,26 @@ static void test_renumber_ship(CuTest *tc) {
test_cleanup();
}
static void test_renumber_ship_duplicate(CuTest *tc) {
unit *u;
faction *f;
int uno, no;
const struct locale *lang;
test_setup_ex(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
u->ship = test_create_ship(u->region, 0);
uno = u->ship->no;
u->ship = test_create_ship(u->region, 0);
no = u->ship->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_SHIP]), itoa36(uno));
renumber_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115"));
CuAssertIntEquals(tc, no, u->ship->no);
test_cleanup();
}
static void test_renumber_unit(CuTest *tc) {
unit *u;
int uno, no;
@ -76,7 +135,62 @@ static void test_renumber_unit(CuTest *tc) {
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_UNIT]), itoa36(uno));
renumber_cmd(u, u->thisorder);
CuAssertIntEquals(tc, uno, u->no);
CuAssertIntEquals(tc, -no, ualias(u)); // TODO: why is ualias negative?
CuAssertIntEquals(tc, -no, ualias(u));
test_cleanup();
}
static void test_renumber_unit_duplicate(CuTest *tc) {
unit *u, *u2;
faction *f;
int no;
const struct locale *lang;
test_setup_ex(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
no = u->no;
u2 = test_create_unit(f, u->region);
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s %s", LOC(lang, parameters[P_UNIT]), itoa36(u2->no));
renumber_cmd(u, u->thisorder);
CuAssertIntEquals(tc, no, u->no);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error115"));
CuAssertIntEquals(tc, 0, ualias(u));
test_cleanup();
}
static void test_renumber_unit_limit(CuTest *tc) {
unit *u;
faction *f;
int no;
const struct locale *lang;
test_setup_ex(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
no = u->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s 10000", LOC(lang, parameters[P_UNIT]));
renumber_cmd(u, u->thisorder);
CuAssertIntEquals(tc, no, u->no);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error114"));
CuAssertIntEquals(tc, 0, ualias(u));
test_cleanup();
}
static void test_renumber_unit_invalid(CuTest *tc) {
unit *u;
faction *f;
int no;
const struct locale *lang;
test_setup_ex(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
no = u->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s TEMP", LOC(lang, parameters[P_UNIT]));
renumber_cmd(u, u->thisorder);
CuAssertIntEquals(tc, no, u->no);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error116"));
CuAssertIntEquals(tc, 0, ualias(u));
test_cleanup();
}
@ -84,8 +198,14 @@ CuSuite *get_renumber_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_renumber_unit);
SUITE_ADD_TEST(suite, test_renumber_unit_limit);
SUITE_ADD_TEST(suite, test_renumber_unit_duplicate);
SUITE_ADD_TEST(suite, test_renumber_unit_invalid);
SUITE_ADD_TEST(suite, test_renumber_building);
SUITE_ADD_TEST(suite, test_renumber_building_duplicate);
SUITE_ADD_TEST(suite, test_renumber_ship);
SUITE_ADD_TEST(suite, test_renumber_ship_duplicate);
SUITE_ADD_TEST(suite, test_renumber_faction);
SUITE_ADD_TEST(suite, test_renumber_faction_duplicate);
return suite;
}

View File

@ -1406,7 +1406,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
newline(out);
newline(out);
sprintf(buf, "%s %s \"password\"", LOC(f->locale, "ERESSEA"), factionid(f));
sprintf(buf, "%s %s \"password\"", LOC(f->locale, "ERESSEA"), itoa36(f->no));
rps_nowrap(out, buf);
newline(out);
newline(out);
@ -1453,7 +1453,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
size = sizeof(buf) - 1;
bytes = _snprintf(bufp, size, "%s %s; %s [%d,%d$",
LOC(u->faction->locale, parameters[P_UNIT]),
unitid(u), unit_getname(u), u->number, get_money(u));
itoa36(u->no), unit_getname(u), u->number, get_money(u));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (u->building && building_owner(u->building) == u) {
@ -1479,7 +1479,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)strlcpy(bufp, shipid(u->ship), size);
bytes = (int)strlcpy(bufp, itoa36(u->ship->no), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}

View File

@ -140,7 +140,7 @@ static char *groupid(const struct group *g, const struct faction *f)
static name idbuf[8];
static int nextbuf = 0;
char *buf = idbuf[(++nextbuf) % 8];
sprintf(buf, "%s (%s)", g->name, factionid(f));
sprintf(buf, "%s (%s)", g->name, itoa36(f->no));
return buf;
}
@ -1418,7 +1418,7 @@ int write_reports(faction * f, time_t ltime)
do {
char filename[32];
char path[MAX_PATH];
sprintf(filename, "%d-%s.%s", turn, factionid(f),
sprintf(filename, "%d-%s.%s", turn, itoa36(f->no),
rtype->extension);
join_path(reportpath(), filename, path, sizeof(path));
errno = 0;
@ -1441,7 +1441,7 @@ int write_reports(faction * f, time_t ltime)
}
}
if (!gotit) {
log_warning("No report for faction %s!", factionid(f));
log_warning("No report for faction %s!", itoa36(f->no));
}
finish_reports(&ctx);
return 0;
@ -1452,7 +1452,7 @@ static void write_script(FILE * F, const faction * f)
report_type *rtype;
char buf[1024];
fprintf(F, "faction=%s:email=%s:lang=%s", factionid(f), f->email,
fprintf(F, "faction=%s:email=%s:lang=%s", itoa36(f->no), f->email,
locale_name(f->locale));
if (f->options & (1 << O_BZIP2))
fputs(":compression=bz2", F);

View File

@ -6291,21 +6291,21 @@ int sp_q_antimagie(castorder * co)
{
unit *u = pa->param[0]->data.u;
ap = &u->attribs;
ts = unitid(u);
ts = itoa36(u->no);
break;
}
case SPP_BUILDING:
{
building *b = pa->param[0]->data.b;
ap = &b->attribs;
ts = buildingid(b);
ts = itoa36(b->no);
break;
}
case SPP_SHIP:
{
ship *sh = pa->param[0]->data.sh;
ap = &sh->attribs;
ts = shipid(sh);
ts = itoa36(sh->no);
break;
}
default:
@ -6384,21 +6384,21 @@ int sp_break_curse(castorder * co)
{
unit *u = pa->param[0]->data.u;
ap = &u->attribs;
ts = unitid(u);
ts = itoa36(u->no);
break;
}
case SPP_BUILDING:
{
building *b = pa->param[0]->data.b;
ap = &b->attribs;
ts = buildingid(b);
ts = itoa36(b->no);
break;
}
case SPP_SHIP:
{
ship *sh = pa->param[0]->data.sh;
ap = &sh->attribs;
ts = shipid(sh);
ts = itoa36(sh->no);
break;
}
default:

View File

@ -439,7 +439,7 @@ int teach_cmd(unit * u, struct order *ord)
strncat(zOrder, " ", sz - 1);
--sz;
}
sz -= strlcpy(zOrder + 4096 - sz, unitid(u2), sz);
sz -= strlcpy(zOrder + 4096 - sz, itoa36(u2->no), sz);
if (getkeyword(u2->thisorder) != K_STUDY) {
ADDMSG(&u->faction->msgs,

View File

@ -96,12 +96,12 @@ int update_nmrs(void)
int nmr = turn - f->lastorders + 1;
if (timeout>0) {
if (nmr < 0 || nmr > timeout) {
log_error("faction %s has %d NMR", factionid(f), nmr);
log_error("faction %s has %d NMR", itoa36(f->no), nmr);
nmr = _max(0, nmr);
nmr = _min(nmr, timeout);
}
if (nmr > 0) {
log_debug("faction %s has %d NMR", factionid(f), nmr);
log_debug("faction %s has %d NMR", itoa36(f->no), nmr);
}
++nmrs[nmr];
}

View File

@ -118,7 +118,7 @@ static void shock_write(const trigger * t, struct storage *store)
next = next->next;
}
if (next && u) {
log_error("more than one shock-attribut for %s on a unit. FIXED.\n", unitid(u));
log_error("more than one shock-attribut for %s on a unit. FIXED.\n", itoa36(u->no));
write_unit_reference(NULL, store);
}
else {