From 2f305f16d93ca28236a325d0e48faab9f1ee68b9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 21:08:35 +0100 Subject: [PATCH 1/6] additional testing for renumber. --- src/kernel/unit.c | 6 ++- src/renumber.c | 11 +--- src/renumber.test.c | 122 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 128 insertions(+), 11 deletions(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 28e95b941..95c689ded 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -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); diff --git a/src/renumber.c b/src/renumber.c index 259dfcc2b..de2b5a490 100644 --- a/src/renumber.c +++ b/src/renumber.c @@ -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; } diff --git a/src/renumber.test.c b/src/renumber.test.c index 3fabaf4c1..9ab6b1e7b 100644 --- a/src/renumber.test.c +++ b/src/renumber.test.c @@ -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; } From bc5e7443477fb7afe5dda2548975302ef4c9598d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 21:23:49 +0100 Subject: [PATCH 2/6] i2b is a bullshit macro. --- src/battle.c | 2 +- src/creport.c | 4 ++-- src/kernel/config.h | 2 -- src/magic.c | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/battle.c b/src/battle.c index 2facbb30f..34d4618a5 100644 --- a/src/battle.c +++ b/src/battle.c @@ -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; diff --git a/src/creport.c b/src/creport.c index b74c5cdef..b63a30ad4 100644 --- a/src/creport.c +++ b/src/creport.c @@ -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); diff --git a/src/kernel/config.h b/src/kernel/config.h index b9bb3f4d3..fd929e8f7 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -34,8 +34,6 @@ struct param; #define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. L�nge der Strings, die * von struct unitname, etc. zur�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)) diff --git a/src/magic.c b/src/magic.c index 803f20c78..d13be7c07 100644 --- a/src/magic.c +++ b/src/magic.c @@ -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 From 434cf8fce6371942654945f14f4c7416e29213f6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 21:27:19 +0100 Subject: [PATCH 3/6] the unitid macro is boring. --- src/battle.c | 8 ++++---- src/kernel/config.h | 2 -- src/report.c | 2 +- src/spells.c | 4 ++-- src/study.c | 2 +- src/triggers/shock.c | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/battle.c b/src/battle.c index 34d4618a5..b5d767535 100644 --- a/src/battle.c +++ b/src/battle.c @@ -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); } } diff --git a/src/kernel/config.h b/src/kernel/config.h index fd929e8f7..2f36f6bc9 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -45,8 +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) diff --git a/src/report.c b/src/report.c index 80ac85974..b3549302a 100644 --- a/src/report.c +++ b/src/report.c @@ -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) { diff --git a/src/spells.c b/src/spells.c index da2b73c5e..369dab924 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6291,7 +6291,7 @@ 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: @@ -6384,7 +6384,7 @@ 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: diff --git a/src/study.c b/src/study.c index 1cd8847be..1dd4da8b8 100644 --- a/src/study.c +++ b/src/study.c @@ -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, diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 75904e346..f44219b5f 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -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 { From 303eb863998402c308c46dcfa4bc8bc1e9433885 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 21:29:15 +0100 Subject: [PATCH 4/6] factionid and curseid are also boring. --- src/kernel/config.h | 2 -- src/kernel/faction.c | 6 +++--- src/kernel/save.c | 2 +- src/laws.c | 2 +- src/modules/score.c | 2 +- src/report.c | 2 +- src/reports.c | 8 ++++---- src/summary.c | 4 ++-- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/kernel/config.h b/src/kernel/config.h index 2f36f6bc9..a15a77ba4 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -47,8 +47,6 @@ struct param; #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); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 0172ea835..6d2430de4 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -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; diff --git a/src/kernel/save.c b/src/kernel/save.c index fa2beabc6..83fa72f76 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -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) { diff --git a/src/laws.c b/src/laws.c index 0ba3f4077..fd4f50b78 100644 --- a/src/laws.c +++ b/src/laws.c @@ -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; } diff --git a/src/modules/score.c b/src/modules/score.c index 89cf90655..8213b8985 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -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); diff --git a/src/report.c b/src/report.c index b3549302a..569674403 100644 --- a/src/report.c +++ b/src/report.c @@ -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); diff --git a/src/reports.c b/src/reports.c index 837ea1a31..fa39f0a85 100644 --- a/src/reports.c +++ b/src/reports.c @@ -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); diff --git a/src/summary.c b/src/summary.c index 8e9dea65d..b82c3a50e 100644 --- a/src/summary.c +++ b/src/summary.c @@ -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]; } From 27605f18baf4e7ed6a4451bf7f0a0e6acf08df68 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 21:31:11 +0100 Subject: [PATCH 5/6] more boring macros removed. --- src/kernel/building.c | 2 +- src/kernel/config.h | 3 --- src/kernel/ship.c | 2 +- src/report.c | 2 +- src/spells.c | 8 ++++---- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/kernel/building.c b/src/kernel/building.c index 8789e40b2..60fd420fb 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -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; } diff --git a/src/kernel/config.h b/src/kernel/config.h index a15a77ba4..6e1059092 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -45,9 +45,6 @@ struct param; bool isparam(const char *s, const struct locale * lang, param_t param); param_t getparam(const struct locale *lang); -#define buildingid(x) itoa36((x)->no) -#define shipid(x) itoa36((x)->no) - const char * game_name(void); int game_id(void); int lovar(double xpct_x2); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 02a980b68..d01d0a788 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -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) { diff --git a/src/report.c b/src/report.c index 569674403..dc52c38a3 100644 --- a/src/report.c +++ b/src/report.c @@ -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(); } diff --git a/src/spells.c b/src/spells.c index 369dab924..941b50014 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6298,14 +6298,14 @@ int sp_q_antimagie(castorder * co) { 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: @@ -6391,14 +6391,14 @@ int sp_break_curse(castorder * co) { 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: From cb6be542b9ec5d0c3a87f4372c27a0acc5ce8af0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 Nov 2016 21:32:24 +0100 Subject: [PATCH 6/6] remove unused variables. --- src/kernel/config.c | 1 - src/kernel/config.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 28147d509..7206c501f 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -101,7 +101,6 @@ struct settings global = { }; bool lomem = false; -FILE *logfile; int turn = -1; const char *parameters[MAXPARAMS] = { diff --git a/src/kernel/config.h b/src/kernel/config.h index 6e1059092..011c487b1 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -158,10 +158,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 }