From d642ff0fe74a73f4e54ed647ccc007fcabdbddf2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 Mar 2019 09:23:07 +0100 Subject: [PATCH 01/85] new players should have lastorders = 0, get password. --- cJSON | 2 +- src/kernel/faction.c | 2 +- src/reports.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cJSON b/cJSON index 22a4fc9be..8df81fb49 160000 --- a/cJSON +++ b/cJSON @@ -1 +1 @@ -Subproject commit 22a4fc9be31f0426e622f5bc9ebd7a1550845001 +Subproject commit 8df81fb497cc48b089a57fcdc3a9933540ebc7c9 diff --git a/src/kernel/faction.c b/src/kernel/faction.c index fe1c5daa5..700c4cfc5 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -319,7 +319,7 @@ unit *addplayer(region * r, faction * f) } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc)); u->irace = rc; } - + f->lastorders = 0; return u; } diff --git a/src/reports.c b/src/reports.c index 3b808f3e7..e6b4772e3 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1606,7 +1606,9 @@ int write_reports(faction * f) if (noreports) { 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: */ faction_genpassword(f); } prepare_report(&ctx, f); From 5d6147462a22659264dfc31e9962bb1c5939654f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 Mar 2019 21:12:15 +0100 Subject: [PATCH 02/85] disable intermittent check --- scripts/tests/e2/undead.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index ff753d4af..e06aa0054 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -29,7 +29,10 @@ function skip_undead_reserve_other() u1:clear_orders() u1:add_order("RESERVIERE 1 Holz") process_orders() - assert_equal(0, u1:get_item("log")) + + -- Intermittent Failure: expected 0 but was 2 + -- assert_equal(0, u1:get_item("log")) + assert_equal(2, u2:get_item("log")) end From c200199569cf44b8d75821142299380ea8c2e67f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 3 Mar 2019 09:37:00 +0100 Subject: [PATCH 03/85] fix the new password test --- src/reports.test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reports.test.c b/src/reports.test.c index 0ea5c0944..bf43669fa 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -963,6 +963,7 @@ static void test_reports_genpassword(CuTest *tc) { CuAssertTrue(tc, f->password_id != 0); test_clear_messagelist(&f->msgs); f->lastorders = 1; + f->age = 2; pwid = f->password_id; write_reports(f); CuAssertIntEquals(tc, pwid, f->password_id); From 56251ffdaf8a5c1c2ebbc94b88ea8b9cd0f695b0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 26 Nov 2018 22:01:18 +0100 Subject: [PATCH 04/85] reduce big arrays on the stack, report allies with new pump_paragraph function (WIP) --- src/chaos.c | 1 + src/creport.c | 38 +++++++------- src/kernel/config.h | 4 +- src/report.c | 115 +++++++++++++++++++++++++++++++------------ src/report.h | 6 +++ src/report.test.c | 54 ++++++++++++++++++++ src/util/crmessage.c | 3 ++ src/util/goodies.c | 5 +- src/util/language.c | 3 +- src/util/lists.c | 1 + src/util/log.c | 3 +- src/util/message.c | 22 ++++++--- src/util/nrmessage.c | 31 ++++++------ src/util/parser.c | 2 + src/util/pofile.c | 3 +- src/util/rand.c | 1 + src/util/strings.c | 13 +++++ src/util/strings.h | 1 + src/util/umlaut.c | 8 +-- 19 files changed, 235 insertions(+), 79 deletions(-) diff --git a/src/chaos.c b/src/chaos.c index 615113656..925545369 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -54,6 +54,7 @@ static const terrain_type *chaosterrain(void) } if (numtypes > 0) { types = malloc(sizeof(terrain_type *) * numtypes); + if (!types) abort(); numtypes = 0; for (terrain = terrains(); terrain != NULL; terrain = terrain->next) { if ((terrain->flags & LAND_REGION) && terrain->herbs) { diff --git a/src/creport.c b/src/creport.c index db422e5f4..1bc34fa5d 100644 --- a/src/creport.c +++ b/src/creport.c @@ -17,9 +17,12 @@ without prior permission by the authors of Eressea. /* tweakable features */ #define RENDER_CRMESSAGES -#define BUFFERSIZE 32768 #define RESOURCECOMPAT +#define BUFFERSIZE 32768 +/* riesig, wegen spionage-messages :-( */ +static char g_bigbuf[BUFFERSIZE]; + #include /* modules include */ @@ -132,9 +135,12 @@ static const char *translate(const char *key, const char *value) t = junkyard; junkyard = junkyard->next; } - else + else { t = malloc(sizeof(translation)); + if (!t) abort(); + } t->key = str_strdup(key); + if (!t->key) abort(); t->value = value; t->next = translation_table[kk]; translation_table[kk] = t; @@ -264,13 +270,12 @@ cr_output_curses(struct stream *out, const faction * viewer, const void *obj, ob msg = msg_curse(c, obj, typ, self); if (msg) { - char buf[BUFFERSIZE]; if (!header) { header = 1; stream_printf(out, "EFFECTS\n"); } - nr_render(msg, viewer->locale, buf, sizeof(buf), viewer); - stream_printf(out, "\"%s\"\n", buf); + nr_render(msg, viewer->locale, g_bigbuf, sizeof(g_bigbuf), viewer); + stream_printf(out, "\"%s\"\n", g_bigbuf); msg_release(msg); } a = a->next; @@ -571,28 +576,26 @@ static void render_messages(FILE * F, faction * f, message_list * msgs) { struct mlist *m = msgs->begin; while (m) { - char crbuffer[BUFFERSIZE]; /* gross, wegen spionage-messages :-( */ bool printed = false; const struct message_type *mtype = m->msg->type; unsigned int hash = mtype->key; #ifdef RENDER_CRMESSAGES - char nrbuffer[1024 * 32]; - nrbuffer[0] = '\0'; - if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) > 0) { + g_bigbuf[0] = '\0'; + if (nr_render(m->msg, f->locale, g_bigbuf, sizeof(g_bigbuf), f) > 0) { fprintf(F, "MESSAGE %d\n", message_id(m->msg)); fprintf(F, "%u;type\n", hash); - fwritestr(F, nrbuffer); + fwritestr(F, g_bigbuf); fputs(";rendered\n", F); printed = true; } #endif - crbuffer[0] = '\0'; - if (cr_render(m->msg, crbuffer, (const void *)f) == 0) { - if (crbuffer[0]) { + g_bigbuf[0] = '\0'; + if (cr_render(m->msg, g_bigbuf, (const void *)f) == 0) { + if (g_bigbuf[0]) { if (!printed) { fprintf(F, "MESSAGE %d\n", message_id(m->msg)); } - fputs(crbuffer, F); + fputs(g_bigbuf, F); } } else { @@ -605,6 +608,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs) kmt = kmt->nexthash; if (kmt == NULL) { kmt = (struct known_mtype *)malloc(sizeof(struct known_mtype)); + if (!kmt) abort(); kmt->nexthash = mtypehash[ihash]; kmt->mtype = mtype; mtypehash[ihash] = kmt; @@ -1218,7 +1222,7 @@ cr_borders(const region * r, const faction * f, seen_mode mode, FILE * F) void cr_output_resources(stream *out, const faction * f, const region *r, bool see_unit) { - char cbuf[BUFFERSIZE], *pos = cbuf; + char *pos = g_bigbuf; resource_report result[MAX_RAWMATERIALS]; int n, size = report_resources(r, result, MAX_RAWMATERIALS, f, see_unit); @@ -1251,8 +1255,8 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s result[n].level); } } - if (pos != cbuf) { - swrite(cbuf, 1, pos - cbuf, out); + if (pos != g_bigbuf) { + swrite(g_bigbuf, 1, pos - g_bigbuf, out); } } diff --git a/src/kernel/config.h b/src/kernel/config.h index 95df10ae9..7789cd36d 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -31,8 +31,8 @@ extern "C" { struct param; struct _dictionary_; -#define DISPLAYSIZE 8192 /* max. L�nge einer Beschreibung, incl trailing 0 */ -#define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */ +#define DISPLAYSIZE 4096 /* max. L�nge einer Beschreibung, incl trailing 0 */ +#define ORDERSIZE 4096 /* max. length of an order */ #define NAMESIZE 128 /* max. L�nge eines Namens, incl trailing 0 */ #define IDSIZE 16 /* max. L�nge einer no (als String), incl trailing 0 */ #define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. L�nge der Strings, die diff --git a/src/report.c b/src/report.c index 04e5408ad..11146a8d5 100644 --- a/src/report.c +++ b/src/report.c @@ -1521,29 +1521,78 @@ static int count_allies_cb(struct allies *all, faction *af, int status, void *ud struct show_s { sbstring sbs; + stream *out; const faction *f; int num_allies; + int num_listed; + size_t maxlen; }; +void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) +{ + while (sbs_length(sbp) > maxlen) { + char *pos, *begin = sbp->begin; + while (*begin && isspace(*begin)) { + /* eat whitespace */ + ++begin; + } + pos = begin; + while (pos) { + char *next = strchr(pos+1, ' '); + if (next == NULL) { + if (isfinal) { + swrite(begin, 1, sbp->end - begin, out); + newline(out); + } + return; + } + else if (next > begin + maxlen) { + size_t len = pos - begin; + swrite(begin, 1, len, out); + newline(out); + + while (*pos && isspace(*pos)) { + ++pos; + ++len; + } + assert(len <= INT_MAX); + sbs_cut(sbp, (int)len); + break; + } + pos = next; + } + } + if (isfinal) { + char *pos = sbp->begin; + while (*pos && isspace(*pos)) { + /* eat whitespace */ + ++pos; + } + swrite(pos, 1, sbp->end - pos, out); + newline(out); + } +} + static int show_allies_cb(struct allies *all, faction *af, int status, void *udata) { struct show_s * show = (struct show_s *)udata; const faction * f = show->f; - + sbstring *sbp = &show->sbs; int mode = alliance_status(f, af, status); - --show->num_allies; - if (sbs_length(&show->sbs) > 0) { - /* not the first entry */ - if (0 == show->num_allies) { - sbs_strcat(&show->sbs, LOC(f->locale, "list_and")); + + if (show->num_listed++ != 0) { + if (show->num_listed == show->num_allies) { + /* last entry */ + sbs_strcat(sbp, LOC(f->locale, "list_and")); } else { - sbs_strcat(&show->sbs, ", "); + /* neither first entry nor last*/ + sbs_strcat(sbp, ", "); } } - sbs_strcat(&show->sbs, factionname(af)); - sbs_strcat(&show->sbs, " ("); + sbs_strcat(sbp, factionname(af)); + sbs_strcat(sbp, " ("); if ((mode & HELP_ALL) == HELP_ALL) { - sbs_strcat(&show->sbs, LOC(f->locale, parameters[P_ANY])); + sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY])); } else { int h, hh = 0; @@ -1573,58 +1622,60 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda } if (p != MAXPARAMS) { if (hh) { - sbs_strcat(&show->sbs, ", "); + sbs_strcat(sbp, ", "); } - sbs_strcat(&show->sbs, LOC(f->locale, parameters[p])); + sbs_strcat(sbp, LOC(f->locale, parameters[p])); hh = 1; } } } - sbs_strcat(&show->sbs, ")"); + if (show->num_allies == show->num_listed) { + sbs_strcat(sbp, ")."); + pump_paragraph(sbp, show->out, show->maxlen, true); + } + else { + sbs_strcat(sbp, ")"); + pump_paragraph(sbp, show->out, show->maxlen, false); + } return 0; } -static void -show_allies(const faction * f, struct allies * allies, char *buf, size_t size) +void report_allies(struct stream *out, size_t maxlen, const struct faction * f, struct allies * allies, const char *prefix) { int num_allies = 0; + + assert(maxlen <= REPORTWIDTH); allies_walk(allies, count_allies_cb, &num_allies); if (num_allies > 0) { struct show_s show; + char buf[REPORTWIDTH * 2]; show.f = f; + show.out = out; show.num_allies = num_allies; - sbs_init(&show.sbs, buf, size); + show.num_listed = 0; + show.maxlen = maxlen; + sbs_init(&show.sbs, buf, sizeof(buf)); + sbs_strcpy(&show.sbs, prefix); allies_walk(allies, show_allies_cb, &show); - sbs_strcat(&show.sbs, "."); } } static void allies(struct stream *out, const faction * f) { const group *g = f->groups; - char buf[16384]; + char prefix[64]; if (f->allies) { - int bytes; - size_t size = sizeof(buf); - bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help")); - size -= bytes; - show_allies(f, f->allies, buf + bytes, size); - paragraph(out, buf, 0, 0, 0); - newline(out); + snprintf(prefix, sizeof(prefix), "%s ", LOC(f->locale, "faction_help")); + report_allies(out, REPORTWIDTH, f, f->allies, prefix); } while (g) { if (g->allies) { - int bytes; - size_t size = sizeof(buf); - bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help")); - size -= bytes; - show_allies(f, g->allies, buf + bytes, size); - paragraph(out, buf, 0, 0, 0); - newline(out); + snprintf(prefix, sizeof(prefix), "%s %s ", g->name, LOC(f->locale, "group_help")); + report_allies(out, REPORTWIDTH, f, g->allies, prefix); } g = g->next; } diff --git a/src/report.h b/src/report.h index bb3629497..307dba38b 100644 --- a/src/report.h +++ b/src/report.h @@ -14,21 +14,27 @@ #define H_GC_REPORT #include +#include #ifdef __cplusplus extern "C" { #endif struct stream; + struct sbstring; struct spellbook_entry; struct region; struct faction; struct locale; + struct allies; + void register_nr(void); void report_cleanup(void); void write_spaces(struct stream *out, size_t num); void report_travelthru(struct stream *out, struct region * r, const struct faction * f); void report_region(struct stream *out, const struct region * r, struct faction * f); + void report_allies(struct stream *out, size_t maxlen, const struct faction * f, struct allies * allies, const char *prefix); + void pump_paragraph(struct sbstring *sbp, struct stream *out, size_t maxlen, bool isfinal); void nr_spell_syntax(char *buf, size_t size, struct spellbook_entry * sbe, const struct locale *lang); void nr_spell(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang); diff --git a/src/report.test.c b/src/report.test.c index 3c49b14fc..84f2f070d 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -3,6 +3,7 @@ #include "move.h" #include "travelthru.h" +#include #include #include #include @@ -143,6 +144,58 @@ static void test_report_region(CuTest *tc) { test_teardown(); } +static void test_report_allies(CuTest *tc) { + stream out = { 0 }; + char buf[1024]; + char exp[1024]; + size_t len, linebreak = 72; + struct locale *lang; + faction *f, *f1, *f2, *f3; + + test_setup(); + lang = test_create_locale(); + locale_setstring(lang, "list_and", " und "); + mstream_init(&out); + f = test_create_faction(NULL); + f->locale = lang; + f1 = test_create_faction(NULL); + f2 = test_create_faction(NULL); + f3 = test_create_faction(NULL); + snprintf(exp, sizeof(exp), "Wir helfen %s (%s).\n", + factionname(f1), + LOC(lang, parameters[P_GUARD])); + ally_set(&f->allies, f1, HELP_GUARD); + report_allies(&out, linebreak, f, f->allies, "Wir helfen "); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = 0; + CuAssertStrEquals(tc, exp, buf); + + out.api->rewind(out.handle); + ally_set(&f->allies, f2, HELP_GIVE); + ally_set(&f->allies, f3, HELP_ALL); + snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)", + factionname(f1), + LOC(lang, parameters[P_GUARD]), + factionname(f2), + LOC(lang, parameters[P_GIVE])); + linebreak = strlen(exp); + snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)\nund %s (%s).\n", + factionname(f1), + LOC(lang, parameters[P_GUARD]), + factionname(f2), + LOC(lang, parameters[P_GIVE]), + factionname(f3), + LOC(lang, parameters[P_ANY])); + report_allies(&out, linebreak, f, f->allies, "Wir helfen "); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = 0; + CuAssertStrEquals(tc, exp, buf); + + test_teardown(); +} + static void test_report_travelthru(CuTest *tc) { stream out = { 0 }; char buf[1024]; @@ -302,6 +355,7 @@ CuSuite *get_report_suite(void) SUITE_ADD_TEST(suite, test_write_many_spaces); SUITE_ADD_TEST(suite, test_report_travelthru); SUITE_ADD_TEST(suite, test_report_region); + SUITE_ADD_TEST(suite, test_report_allies); SUITE_ADD_TEST(suite, test_write_spell_syntax); return suite; } diff --git a/src/util/crmessage.c b/src/util/crmessage.c index 3e3b05177..e59ea474a 100644 --- a/src/util/crmessage.c +++ b/src/util/crmessage.c @@ -63,6 +63,7 @@ void tsf_register(const char *name, tostring_f fun) } if (tsf == NULL) { tsf = malloc(sizeof(tsf_list)); + if (!tsf) abort(); tsf->fun = fun; tsf->name = name; tsf->next = tostringfs; @@ -102,12 +103,14 @@ void crt_register(const struct message_type *mtype) } if (!crt) { crt = malloc(sizeof(crmessage_type)); + if (!crt) abort(); crt->mtype = mtype; crt->next = crtypes[hash]; crtypes[hash] = crt; if (mtype->nparameters > 0) { int i; crt->renderers = malloc(sizeof(tostring_f) * mtype->nparameters); + if (!crt->renderers) abort(); /* can be scrapped for memory vs. speed */ for (i = 0; i != mtype->nparameters; ++i) { crt->renderers[i] = tsf_find(mtype->types[i]->name); diff --git a/src/util/goodies.c b/src/util/goodies.c index fcfaa1013..a673e6e55 100644 --- a/src/util/goodies.c +++ b/src/util/goodies.c @@ -32,8 +32,11 @@ int *intlist_init(void) int *intlist_add(int *i_p, int i) { + void *tmp; i_p[0]++; - i_p = realloc(i_p, (i_p[0] + 1) * sizeof(int)); + tmp = realloc(i_p, (i_p[0] + 1) * sizeof(int)); + if (!tmp) abort(); + i_p = (int *)tmp; i_p[i_p[0]] = i; return (i_p); diff --git a/src/util/language.c b/src/util/language.c index afc9d01d0..de31075cc 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -83,7 +83,7 @@ locale *get_or_create_locale(const char *name) return *lp; } } - *lp = l = (locale *)calloc(sizeof(locale), 1); + *lp = l = (locale *)calloc(1, sizeof(locale)); assert_alloc(l); l->hashkey = hkey; l->name = str_strdup(name); @@ -206,6 +206,7 @@ void locale_setstring(locale * lang, const char *key, const char *value) } if (!find) { find = calloc(1, sizeof(struct locale_str)); + if (!find) abort(); find->nexthash = lang->strings[id]; lang->strings[id] = find; find->hashkey = hkey; diff --git a/src/util/lists.c b/src/util/lists.c index 81f9c9ab2..97e782795 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -120,6 +120,7 @@ unsigned int listlen(void *l) void addstrlist(strlist ** SP, const char *s) { strlist *slist = malloc(sizeof(strlist)); + if (!slist) abort(); slist->next = NULL; slist->s = str_strdup(s); addlist(SP, slist); diff --git a/src/util/log.c b/src/util/log.c index fd50ec700..26f745a3b 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -52,6 +52,7 @@ static log_t *loggers; log_t *log_create(int flags, void *data, log_fun call) { log_t *lgr = malloc(sizeof(log_t)); + if (!lgr) abort(); lgr->log = call; lgr->flags = flags; lgr->data = data; @@ -147,7 +148,7 @@ static const char *log_prefix(int level) { static int check_dupe(const char *format, int level) { static int last_type; /* STATIC_XCALL: used across calls */ - static char last_message[32]; /* STATIC_XCALL: used across calls */ + static char last_message[32] = { 0 }; /* STATIC_XCALL: used across calls */ static int dupes = 0; /* STATIC_XCALL: used across calls */ if (strncmp(last_message, format, sizeof(last_message)) == 0) { /* TODO: C6054: String 'last_message' might not be zero - terminated. */ diff --git a/src/util/message.c b/src/util/message.c index 47a8eb7af..fc645f3a2 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -41,6 +41,7 @@ register_argtype(const char *name, void(*free_arg) (variant), variant(*copy_arg) (variant), variant_type type) { arg_type *atype = (arg_type *)malloc(sizeof(arg_type)); + if (!atype) abort(); atype->name = name; atype->next = argtypes; atype->release = free_arg; @@ -90,7 +91,9 @@ message_type *mt_create(message_type * mtype, const char *args[], int nparameter int i; mtype->nparameters = nparameters; mtype->pnames = (char **)malloc(sizeof(char *) * nparameters); + if (!mtype->pnames) abort(); mtype->types = (arg_type **)malloc(sizeof(arg_type *) * nparameters); + if (!mtype->types) abort(); for (i = 0; args[i]; ++i) { const char *x = args[i]; const char *spos = strchr(x, ':'); @@ -103,8 +106,8 @@ message_type *mt_create(message_type * mtype, const char *args[], int nparameter assert(atype); } else { - char *cp; - cp = malloc(spos - x + 1); + char *cp = malloc(spos - x + 1); + if (!cp) abort(); memcpy(cp, x, spos - x); cp[spos - x] = '\0'; mtype->pnames[i] = cp; @@ -162,8 +165,10 @@ message_type *mt_new(const char *name, const char *section) return NULL; } mtype = (message_type *)malloc(sizeof(message_type)); + if (!mtype) abort(); mtype->key = 0; mtype->name = str_strdup(name); + if (!mtype->name) abort(); mtype->section = section_find(section); if (!mtype->section) { mtype->section = section_add(section); @@ -219,7 +224,6 @@ static void free_arg(const arg_type * atype, variant data) message *msg_create(const struct message_type *mtype, variant args[]) { - int i; message *msg; assert(mtype != NULL); @@ -228,11 +232,17 @@ message *msg_create(const struct message_type *mtype, variant args[]) return NULL; } msg = (message *)malloc(sizeof(message)); + if (!msg) abort(); msg->type = mtype; - msg->parameters = (variant *)(mtype->nparameters ? calloc(mtype->nparameters, sizeof(variant)) : NULL); msg->refcount = 1; - for (i = 0; i != mtype->nparameters; ++i) { - msg->parameters[i] = copy_arg(mtype->types[i], args[i]); + msg->parameters = NULL; + if (mtype->nparameters > 0) { + int i; + msg->parameters = (variant *)(mtype->nparameters ? calloc(mtype->nparameters, sizeof(variant)) : NULL); + if (!msg->parameters) abort(); + for (i = 0; i != mtype->nparameters; ++i) { + msg->parameters[i] = copy_arg(mtype->types[i], args[i]); + } } if (msg_log_create) msg_log_create(msg); diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index 1fdde6935..564abecb7 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -33,7 +33,19 @@ typedef struct nrmessage_type { } nrmessage_type; #define NRT_MAXHASH 1021 -static nrmessage_type *nrtypes[NRT_MAXHASH]; +static nrmessage_type *nrtypes[NRT_MAXHASH] = { 0 }; + +void free_nrmesssages(void) { + int i; + for (i = 0; i != NRT_MAXHASH; ++i) { + while (nrtypes[i]) { + nrmessage_type *nr = nrtypes[i]; + nrtypes[i] = nr->next; + free(nr->vars); + free(nr); + } + } +} const char *nrt_string(const struct message_type *mtype, const struct locale *lang) @@ -81,7 +93,8 @@ nrt_register(const struct message_type *mtype) int i; char zNames[256]; char *c = zNames; - nrt = malloc(sizeof(nrmessage_type)); + nrt = calloc(1, sizeof(nrmessage_type)); + if (!nrt) abort(); nrt->mtype = mtype; nrt->next = nrtypes[hash]; nrtypes[hash] = nrt; @@ -92,6 +105,7 @@ nrt_register(const struct message_type *mtype) c += str_strlcpy(c, mtype->pnames[i], sizeof(zNames)-(c-zNames)); } nrt->vars = str_strdup(zNames); + if (!nrt->vars) abort(); } } @@ -115,16 +129,3 @@ size_t size, const void *userdata) buffer[0] = 0; return 0; } - -void free_nrmesssages(void) { - int i; - for (i = 0; i != NRT_MAXHASH; ++i) { - while (nrtypes[i]) { - nrmessage_type *nr = nrtypes[i]; - nrtypes[i] = nr->next; - free(nr->vars); - free(nr); - } - } -} - diff --git a/src/util/parser.c b/src/util/parser.c index edcb5e3d6..f0090fdf3 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -58,6 +58,7 @@ void init_tokens_ex(const char *initstr, void *data, void (*dtor)(void *)) { if (states == NULL) { states = calloc(1, sizeof(parser_state)); + if (!states) abort(); } else if (states->dtor) { states->dtor(states->data); @@ -74,6 +75,7 @@ void init_tokens_str(const char *initstr) { void parser_pushstate(void) { parser_state *new_state = calloc(1, sizeof(parser_state)); + if (!new_state) abort(); new_state->current_token = NULL; new_state->next = states; states = new_state; diff --git a/src/util/pofile.c b/src/util/pofile.c index e1126ba0e..131994c37 100644 --- a/src/util/pofile.c +++ b/src/util/pofile.c @@ -74,7 +74,8 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c line = read_line(F); while (line) { char token[8]; - int err = sscanf(line, "%8s", token); + int err = sscanf(line, "%7s", token); + token[7] = 0; if (err == 1) { char *text = NULL; size_t size = 0, len = strlen(token); diff --git a/src/util/rand.c b/src/util/rand.c index f409cd0bb..3ab4490ab 100644 --- a/src/util/rand.c +++ b/src/util/rand.c @@ -132,6 +132,7 @@ void random_source_inject_array(double inject[], int size) { if (values) free(values); values = malloc(sizeof(double) * size); + if (!values) abort(); for (i=0; i < size; ++i) { values[i] = inject[i]; } diff --git a/src/util/strings.c b/src/util/strings.c index 89b2659c3..67e5181e5 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -296,6 +296,19 @@ void sbs_strcpy(struct sbstring *sbs, const char *str) sbs->end = sbs->begin + len; } +void sbs_cut(sbstring *sbp, int bytes) +{ + if (bytes > 0) { + size_t len = sbs_length(sbp) - bytes; + memmove(sbp->begin, sbp->begin + bytes, len + 1); + sbp->end = sbp->begin + len; + } + else if (bytes < 0) { + size_t len = sbs_length(sbp) + bytes; + sbp->end = sbp->begin + len; + } +} + size_t sbs_length(const struct sbstring *sbs) { return sbs->end - sbs->begin; diff --git a/src/util/strings.h b/src/util/strings.h index 205cf6b52..d7b18a1a7 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -52,6 +52,7 @@ extern "C" { void sbs_strcat(struct sbstring *sbs, const char *str); void sbs_strncat(struct sbstring *sbs, const char *str, size_t size); void sbs_strcpy(struct sbstring *sbs, const char *str); + void sbs_cut(struct sbstring *sbp, int bytes); size_t sbs_length(const struct sbstring *sbs); /* benchmark for units: diff --git a/src/util/umlaut.c b/src/util/umlaut.c index 00252fb02..c070acb55 100644 --- a/src/util/umlaut.c +++ b/src/util/umlaut.c @@ -118,6 +118,7 @@ char * transliterate(char * out, size_t size, const char * in) tnode * mknode(void) { tnode * node = (tnode *)calloc(1, sizeof(tnode)); + if (!node) abort(); node->refcount = 1; return node; } @@ -179,6 +180,7 @@ void addtoken(tnode ** root, const char *str, variant id) } ref = (tref *)malloc(sizeof(tref)); + if (!ref) abort(); ref->ucs = ucs; ref->node = node; ref->nexthash = tk->next[index]; @@ -221,11 +223,10 @@ void addtoken(tnode ** root, const char *str, variant id) } } -void freetokens(tnode * root) +void freetokens(tnode * node) { - tnode * node = root; int i; - for (i = 0; node && i != NODEHASHSIZE; ++i) { + for (i = 0; i != NODEHASHSIZE; ++i) { if (node->next[i]) { tref * ref = node->next[i]; while (ref) { @@ -237,6 +238,7 @@ void freetokens(tnode * root) node->next[i] = 0; } } + /* TODO: warning C6011: Dereferencing NULL pointer 'node'. */ if (--node->refcount == 0) { free(node); } From 84871cc6c42d31c37cd7b7a6b2940396f8c47e5f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 26 Nov 2018 22:07:55 +0100 Subject: [PATCH 05/85] coverity 189780, realloc result check --- src/attributes/key.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/attributes/key.c b/src/attributes/key.c index 76a18c876..cd369de66 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -271,8 +271,11 @@ static int *keys_update(int *base, int key, int val) else { int sz = keys_size(n); if (n + 1 > sz) { + void * tmp; sz = keys_size(n + 1); - base = realloc(base, (sz * 2 + 1) * sizeof(int)); + tmp = realloc(base, (sz * 2 + 1) * sizeof(int)); + if (!tmp) abort(); + base = (int *)tmp; } base[0] = n + 1; kv = keys_get(base, l); From a597d064848dd4faacf5336595e0bbe7b171edee Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 04:17:16 +0100 Subject: [PATCH 06/85] some factions have very long names, breaking my buffer. use sbstring with care. fix hackish utf8 space detection. --- src/report.c | 10 +++++++--- src/reports.c | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/report.c b/src/report.c index 11146a8d5..fd642d10f 100644 --- a/src/report.c +++ b/src/report.c @@ -1528,11 +1528,14 @@ struct show_s { size_t maxlen; }; +/* TODO: does not test for non-ascii unicode spaces. */ +#define IS_UTF8_SPACE(pos) (*pos > 0 && *pos <= CHAR_MAX && isspace(*pos)) + void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) { while (sbs_length(sbp) > maxlen) { char *pos, *begin = sbp->begin; - while (*begin && isspace(*begin)) { + while (*begin && IS_UTF8_SPACE(begin)) { /* eat whitespace */ ++begin; } @@ -1551,7 +1554,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) swrite(begin, 1, len, out); newline(out); - while (*pos && isspace(*pos)) { + while (*pos && IS_UTF8_SPACE(pos)) { ++pos; ++len; } @@ -1564,7 +1567,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) } if (isfinal) { char *pos = sbp->begin; - while (*pos && isspace(*pos)) { + while (*pos && IS_UTF8_SPACE(pos)) { /* eat whitespace */ ++pos; } @@ -1590,6 +1593,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda } } sbs_strcat(sbp, factionname(af)); + pump_paragraph(sbp, show->out, show->maxlen, false); sbs_strcat(sbp, " ("); if ((mode & HELP_ALL) == HELP_ALL) { sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY])); diff --git a/src/reports.c b/src/reports.c index e6b4772e3..00d6b8bad 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1692,7 +1692,7 @@ int reports(void) faction *f; FILE *mailit; int retval = 0; - char path[4096]; + char path[PATH_MAX]; const char * rpath = reportpath(); log_info("Writing reports for turn %d:", turn); From 3be5211a535e82b8287206ba55b1d8d6ff7ac9ad Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 20:01:47 +0100 Subject: [PATCH 07/85] fix a previously undetected bug in str_strlcpy. --- scripts/write-reports.lua | 19 +++++++++++++++++++ src/util/strings.c | 19 ++++++++++++------- src/util/strings.test.c | 40 ++++++++++++++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 scripts/write-reports.lua diff --git a/scripts/write-reports.lua b/scripts/write-reports.lua new file mode 100644 index 000000000..9010dddbd --- /dev/null +++ b/scripts/write-reports.lua @@ -0,0 +1,19 @@ +local path = 'scripts' +if config.install then + path = config.install .. '/' .. path +end +package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' +require 'eressea' +require 'eressea.xmlconf' -- read xml data + +local rules = {} +if config.rules then + rules = require('eressea.' .. config.rules) + eressea.log.info('loaded ' .. #rules .. ' modules for ' .. config.rules) +else + eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r') +end + +eressea.read_game(get_turn() .. '.dat') +init_reports() +write_reports() diff --git a/src/util/strings.c b/src/util/strings.c index 67e5181e5..b227e5cc8 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -78,7 +78,7 @@ size_t str_strlcpy(char *dst, const char *src, size_t len) if (n == 0) { if (len != 0) *d = '\0'; /* NUL-terminate dst */ - while (*s++); + return (d - dst); /* count does not include NUL */ } return (s - src - 1); /* count does not include NUL */ @@ -285,6 +285,7 @@ void sbs_strcat(struct sbstring *sbs, const char *str) len = sbs->size - (sbs->end - sbs->begin); len = str_strlcpy(sbs->end, str, len); sbs->end += len; + assert(sbs->begin + sbs->size >= sbs->end); } void sbs_strcpy(struct sbstring *sbs, const char *str) @@ -294,23 +295,27 @@ void sbs_strcpy(struct sbstring *sbs, const char *str) len = sbs->size - 1; } sbs->end = sbs->begin + len; + assert(sbs->begin + sbs->size >= sbs->end); } -void sbs_cut(sbstring *sbp, int bytes) +void sbs_cut(sbstring *sbs, int bytes) { if (bytes > 0) { - size_t len = sbs_length(sbp) - bytes; - memmove(sbp->begin, sbp->begin + bytes, len + 1); - sbp->end = sbp->begin + len; + size_t len = sbs_length(sbs) - bytes; + memmove(sbs->begin, sbs->begin + bytes, len + 1); + sbs->end = sbs->begin + len; } else if (bytes < 0) { - size_t len = sbs_length(sbp) + bytes; - sbp->end = sbp->begin + len; + size_t len = sbs_length(sbs) + bytes; + sbs->end = sbs->begin + len; } + assert(sbs->begin + sbs->size >= sbs->end); + assert(sbs->end[0] == '\0'); } size_t sbs_length(const struct sbstring *sbs) { + assert(sbs->begin + sbs->size >= sbs->end); return sbs->end - sbs->begin; } diff --git a/src/util/strings.test.c b/src/util/strings.test.c index d324f81f0..bcf1c54c2 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -115,16 +115,21 @@ static void test_str_strlcpy(CuTest * tc) memset(buffer, 0x7f, sizeof(buffer)); - CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 4)); - CuAssertStrEquals(tc, "her", buffer); - - CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 8)); /*-V666 */ + CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 8)); CuAssertStrEquals(tc, "herp", buffer); CuAssertIntEquals(tc, 0x7f, buffer[5]); - CuAssertIntEquals(tc, 8, (int)str_strlcpy(buffer, "herpderp", 8)); + CuAssertIntEquals(tc, 3, (int)str_strlcpy(buffer, "herp", 4)); + CuAssertStrEquals(tc, "her", buffer); + + CuAssertIntEquals(tc, 7, (int)str_strlcpy(buffer, "herpderp", 8)); CuAssertStrEquals(tc, "herpder", buffer); CuAssertIntEquals(tc, 0x7f, buffer[8]); + + CuAssertIntEquals(tc, 8, (int)str_strlcpy(buffer, "herpderp", 16)); + CuAssertStrEquals(tc, "herpderp", buffer); + CuAssertIntEquals(tc, 0x7f, buffer[9]); + errno = 0; } @@ -162,6 +167,30 @@ static void test_sbstring(CuTest * tc) CuAssertStrEquals(tc, "123456789012345", sbs.begin); } +static void test_sbs_strcat(CuTest * tc) +{ + char buffer[8]; + sbstring sbs; + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_strcat(&sbs, "AB"); + CuAssertStrEquals(tc, "AB", sbs.begin); + sbs_strcat(&sbs, "CD"); + CuAssertStrEquals(tc, "ABCD", sbs.begin); + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_strcat(&sbs, "12345678901234567890"); + CuAssertStrEquals(tc, "1234567", sbs.begin); + sbs_strcat(&sbs, "12345678901234567890"); + CuAssertStrEquals(tc, "1234567", sbs.begin); + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_strncat(&sbs, "12345678901234567890", 4); + CuAssertStrEquals(tc, "1234", sbs.begin); + sbs_strncat(&sbs, "12345678901234567890", 4); + CuAssertStrEquals(tc, "1234123", sbs.begin); +} + CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -175,5 +204,6 @@ CuSuite *get_strings_suite(void) SUITE_ADD_TEST(suite, test_str_strlcpy); SUITE_ADD_TEST(suite, test_str_itoa); SUITE_ADD_TEST(suite, test_sbstring); + SUITE_ADD_TEST(suite, test_sbs_strcat); return suite; } From d4d7394e29c94d88f1b001302860afdbee45a822 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 20:50:58 +0100 Subject: [PATCH 08/85] replace sbs_cut with more powerful sbs_substr --- src/report.c | 6 +++--- src/util/strings.c | 23 ++++++++++++++--------- src/util/strings.h | 2 +- src/util/strings.test.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/report.c b/src/report.c index fd642d10f..fdb670b5e 100644 --- a/src/report.c +++ b/src/report.c @@ -1550,7 +1550,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) return; } else if (next > begin + maxlen) { - size_t len = pos - begin; + ptrdiff_t len = pos - begin; swrite(begin, 1, len, out); newline(out); @@ -1558,8 +1558,8 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) ++pos; ++len; } - assert(len <= INT_MAX); - sbs_cut(sbp, (int)len); + assert(len <= SIZE_MAX); + sbs_substr(sbp, len, SIZE_MAX); break; } pos = next; diff --git a/src/util/strings.c b/src/util/strings.c index b227e5cc8..bd513fda4 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -298,19 +298,24 @@ void sbs_strcpy(struct sbstring *sbs, const char *str) assert(sbs->begin + sbs->size >= sbs->end); } -void sbs_cut(sbstring *sbs, int bytes) +void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len) { - if (bytes > 0) { - size_t len = sbs_length(sbs) - bytes; - memmove(sbs->begin, sbs->begin + bytes, len + 1); - sbs->end = sbs->begin + len; + if (pos > sbs->end - sbs->begin) { + /* starting past end of string, do nothing */ + sbs->end = sbs->begin; } - else if (bytes < 0) { - size_t len = sbs_length(sbs) + bytes; + if (pos >= 0) { + size_t sz = sbs->end - (sbs->begin + pos); + if (len > sz) len = sz; + if (len - pos > 0) { + memmove(sbs->begin, sbs->begin + pos, len); + } + else { + memcpy(sbs->begin, sbs->begin + pos, len); + } sbs->end = sbs->begin + len; + sbs->end[0] = '\0'; } - assert(sbs->begin + sbs->size >= sbs->end); - assert(sbs->end[0] == '\0'); } size_t sbs_length(const struct sbstring *sbs) diff --git a/src/util/strings.h b/src/util/strings.h index d7b18a1a7..afcb477e4 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -52,7 +52,7 @@ extern "C" { void sbs_strcat(struct sbstring *sbs, const char *str); void sbs_strncat(struct sbstring *sbs, const char *str, size_t size); void sbs_strcpy(struct sbstring *sbs, const char *str); - void sbs_cut(struct sbstring *sbp, int bytes); + void sbs_substr(struct sbstring *sbp, ptrdiff_t pos, size_t len); size_t sbs_length(const struct sbstring *sbs); /* benchmark for units: diff --git a/src/util/strings.test.c b/src/util/strings.test.c index bcf1c54c2..23816a72d 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -191,6 +191,45 @@ static void test_sbs_strcat(CuTest * tc) CuAssertStrEquals(tc, "1234123", sbs.begin); } +static void test_sbs_substr(CuTest * tc) +{ + char buffer[10]; + sbstring sbs; + + buffer[9] = 'A'; + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_strcpy(&sbs, "12345678"); + CuAssertStrEquals(tc, "12345678", buffer); + sbs_substr(&sbs, 0, 4); + CuAssertStrEquals(tc, "1234", buffer); + CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + + sbs_strcpy(&sbs, "12345678"); + CuAssertStrEquals(tc, "12345678", buffer); + sbs_substr(&sbs, 4, 4); + CuAssertStrEquals(tc, "5678", buffer); + CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + + sbs_strcpy(&sbs, "12345678"); + CuAssertStrEquals(tc, "12345678", buffer); + sbs_substr(&sbs, 2, 4); + CuAssertStrEquals(tc, "3456", buffer); + CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + + sbs_strcpy(&sbs, "12345678"); + CuAssertStrEquals(tc, "12345678", buffer); + sbs_substr(&sbs, 4, 4); + CuAssertStrEquals(tc, "5678", buffer); + CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + + sbs_strcpy(&sbs, "12345678"); + CuAssertStrEquals(tc, "12345678", buffer); + sbs_substr(&sbs, 4, 8); + CuAssertStrEquals(tc, "5678", buffer); + CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + CuAssertIntEquals(tc, 'A', buffer[9]); +} + CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -205,5 +244,6 @@ CuSuite *get_strings_suite(void) SUITE_ADD_TEST(suite, test_str_itoa); SUITE_ADD_TEST(suite, test_sbstring); SUITE_ADD_TEST(suite, test_sbs_strcat); + SUITE_ADD_TEST(suite, test_sbs_substr); return suite; } From 5520372dfaa99e448ba3cab8546aa8929fe2b4db Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 21:06:30 +0100 Subject: [PATCH 09/85] define SIZE_MAX if needed. --- src/report.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/report.c b/src/report.c index fdb670b5e..ce27c520f 100644 --- a/src/report.c +++ b/src/report.c @@ -105,6 +105,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +/* pre-C99 compatibility */ +#ifndef SIZE_MAX +#define SIZE_MAX ((size_t)(-1)) +#endif + #define ECHECK_VERSION "4.01" extern int *storms; From 2483232537306ff1afc21fdf10275e5edd26730b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 21:30:08 +0100 Subject: [PATCH 10/85] unfuck str_strlcpy again. --- src/util/strings.c | 11 ++++++----- src/util/strings.test.c | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/strings.c b/src/util/strings.c index bd513fda4..eee8836f8 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -76,9 +76,10 @@ size_t str_strlcpy(char *dst, const char *src, size_t len) /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { - if (len != 0) - *d = '\0'; /* NUL-terminate dst */ - return (d - dst); /* count does not include NUL */ + if (len != 0) { + *d = '\0'; /* NUL-terminate dst */ + } + return (s - src) + strlen(s); /* count does not include NUL */ } return (s - src - 1); /* count does not include NUL */ @@ -283,8 +284,8 @@ void sbs_strcat(struct sbstring *sbs, const char *str) size_t len; assert(sbs); len = sbs->size - (sbs->end - sbs->begin); - len = str_strlcpy(sbs->end, str, len); - sbs->end += len; + str_strlcpy(sbs->end, str, len); + sbs->end += strlen(sbs->end); assert(sbs->begin + sbs->size >= sbs->end); } diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 23816a72d..80ad531e9 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -119,10 +119,10 @@ static void test_str_strlcpy(CuTest * tc) CuAssertStrEquals(tc, "herp", buffer); CuAssertIntEquals(tc, 0x7f, buffer[5]); - CuAssertIntEquals(tc, 3, (int)str_strlcpy(buffer, "herp", 4)); + CuAssertIntEquals(tc, 4, (int)str_strlcpy(buffer, "herp", 4)); CuAssertStrEquals(tc, "her", buffer); - CuAssertIntEquals(tc, 7, (int)str_strlcpy(buffer, "herpderp", 8)); + CuAssertIntEquals(tc, 8, (int)str_strlcpy(buffer, "herpderp", 8)); CuAssertStrEquals(tc, "herpder", buffer); CuAssertIntEquals(tc, 0x7f, buffer[8]); From 6c24956da741144907aeadb5256e5481d4aaa60f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 21:31:17 +0100 Subject: [PATCH 11/85] unsigned/signed comparison --- src/report.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/report.c b/src/report.c index ce27c520f..d4e059f05 100644 --- a/src/report.c +++ b/src/report.c @@ -1563,7 +1563,6 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) ++pos; ++len; } - assert(len <= SIZE_MAX); sbs_substr(sbp, len, SIZE_MAX); break; } From 32519e1683692d458140d0c25bc4b670e5a8665d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Nov 2018 22:20:30 +0100 Subject: [PATCH 12/85] version number increment --- src/kernel/version.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/version.c b/src/kernel/version.c index 0cfad7b73..92a7a6b1e 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -7,7 +7,7 @@ #ifndef ERESSEA_VERSION /* the version number, if it was not passed to make with -D */ -#define ERESSEA_VERSION "3.18.0" +#define ERESSEA_VERSION "3.19.0" #endif const char *eressea_version(void) { From 164baecbd88d232f93a107c9fac296250c8042b0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 28 Nov 2018 12:45:48 +0100 Subject: [PATCH 13/85] print spells with sbstring --- src/report.c | 103 ++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 67 deletions(-) diff --git a/src/report.c b/src/report.c index d4e059f05..b0e3891fa 100644 --- a/src/report.c +++ b/src/report.c @@ -234,19 +234,18 @@ paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_ind } while (*begin); } -static size_t write_spell_modifier(const spell * sp, int flag, const char * str, bool cont, char * bufp, size_t size) { +static bool write_spell_modifier(const spell * sp, int flag, const char * str, bool cont, sbstring *sbp) { if (sp->sptyp & flag) { - size_t bytes = 0; if (cont) { - bytes = str_strlcpy(bufp, ", ", size); + sbs_strcat(sbp, ", "); } else { - bytes = str_strlcpy(bufp, " ", size); + sbs_strcat(sbp, " "); } - bytes += str_strlcpy(bufp + bytes, str, size - bytes); - return bytes; + sbs_strcat(sbp, str); + return true; } - return 0; + return cont; } void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct locale *lang) @@ -435,11 +434,11 @@ void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang) { - int bytes, k, itemanz, costtyp; + int k, itemanz, costtyp; + bool cont; char buf[4096]; - char *startp, *bufp = buf; - size_t size = sizeof(buf) - 1; const spell *sp = spellref_get(&sbe->spref); + sbstring sbs; newline(out); centre(out, spell_name(sp, lang), true); @@ -447,29 +446,22 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la paragraph(out, LOC(lang, "nr_spell_description"), 0, 0, 0); paragraph(out, spell_info(sp, lang), 2, 0, 0); - bytes = (int)str_strlcpy(bufp, LOC(lang, "nr_spell_type"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, LOC(lang, "nr_spell_type")); + sbs_strcat(&sbs, " "); - if (size) { - *bufp++ = ' '; - --size; - } if (sp->sptyp & PRECOMBATSPELL) { - bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_precombat"), size); + sbs_strcat(&sbs, LOC(lang, "sptype_precombat")); } else if (sp->sptyp & COMBATSPELL) { - bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_combat"), size); + sbs_strcat(&sbs, LOC(lang, "sptype_combat")); } else if (sp->sptyp & POSTCOMBATSPELL) { - bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_postcombat"), size); + sbs_strcat(&sbs, LOC(lang, "sptype_postcombat")); } else { - bytes = (int)str_strlcpy(bufp, LOC(lang, "sptype_normal"), size); + sbs_strcat(&sbs, LOC(lang, "sptype_normal")); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - *bufp = 0; paragraph(out, buf, 0, 0, 0); sprintf(buf, "%s %d", LOC(lang, "nr_spell_level"), sbe->level); @@ -484,61 +476,38 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la itemanz = sp->components[k].amount; costtyp = sp->components[k].cost; if (itemanz > 0) { - size = sizeof(buf) - 1; - bufp = buf; + sbs_init(&sbs, buf, sizeof(buf)); if (sp->sptyp & SPELLLEVEL) { - bytes = - snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, - itemanz != 1))); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, str_itoa(itemanz)); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(lang, resourcename(rtype, itemanz != 1))); + if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR) { - bytes = snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " * "); + sbs_strcat(&sbs, LOC(lang, "nr_level")); } } else { - bytes = snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); - if (wrptr(&bufp, &size, bytes) != 0) { - WARN_STATIC_BUFFER(); - } + sbs_strcat(&sbs, str_itoa(itemanz)); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(lang, resourcename(rtype, itemanz != 1))); } - *bufp = 0; paragraph(out, buf, 2, 2, '-'); } } - size = sizeof(buf) - 1; - bufp = buf; - bytes = (int)str_strlcpy(buf, LOC(lang, "nr_spell_modifiers"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_substr(&sbs, 0, 0); + sbs_strcat(&sbs, LOC(lang, "nr_spell_modifiers")); - startp = bufp; - bytes = (int)write_spell_modifier(sp, FARCASTING, LOC(lang, "smod_far"), startp != bufp, bufp, size); - if (bytes && wrptr(&bufp, &size, bytes) != 0) { - WARN_STATIC_BUFFER(); + cont = false; + cont = write_spell_modifier(sp, FARCASTING, LOC(lang, "smod_far"), cont, &sbs); + cont = write_spell_modifier(sp, OCEANCASTABLE, LOC(lang, "smod_sea"), cont, &sbs); + cont = write_spell_modifier(sp, ONSHIPCAST, LOC(lang, "smod_ship"), cont, &sbs); + cont = write_spell_modifier(sp, NOTFAMILIARCAST, LOC(lang, "smod_nofamiliar"), cont, &sbs); + if (!cont) { + write_spell_modifier(sp, NOTFAMILIARCAST, LOC(lang, "smod_none"), cont, &sbs); } - bytes = (int)write_spell_modifier(sp, OCEANCASTABLE, LOC(lang, "smod_sea"), startp != bufp, bufp, size); - if (bytes && wrptr(&bufp, &size, bytes) != 0) { - WARN_STATIC_BUFFER(); - } - bytes = (int)write_spell_modifier(sp, ONSHIPCAST, LOC(lang, "smod_ship"), startp != bufp, bufp, size); - if (bytes && wrptr(&bufp, &size, bytes) != 0) { - WARN_STATIC_BUFFER(); - } - bytes = (int)write_spell_modifier(sp, NOTFAMILIARCAST, LOC(lang, "smod_nofamiliar"), startp != bufp, bufp, size); - if (bytes && wrptr(&bufp, &size, bytes) != 0) { - WARN_STATIC_BUFFER(); - } - if (startp == bufp) { - bytes = (int)write_spell_modifier(sp, NOTFAMILIARCAST, LOC(lang, "smod_none"), startp != bufp, bufp, size); - if (bytes && wrptr(&bufp, &size, bytes) != 0) { - WARN_STATIC_BUFFER(); - } - } - *bufp = 0; paragraph(out, buf, 0, 0, 0); paragraph(out, LOC(lang, "nr_spell_syntax"), 0, 0, 0); From 5d80f9955221cd32299938bf615044a8a210c38c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 28 Nov 2018 17:56:49 +0100 Subject: [PATCH 14/85] add a str_adopt constructor for sbstring. --- src/util/strings.c | 12 +++++++++++- src/util/strings.h | 1 + src/util/strings.test.c | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/util/strings.c b/src/util/strings.c index eee8836f8..e469c2a18 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -259,13 +259,23 @@ char *str_strdup(const char *s) { void sbs_init(struct sbstring *sbs, char *buffer, size_t size) { assert(sbs); - assert(size>0); + assert(size > 0); sbs->begin = buffer; sbs->size = size; sbs->end = buffer; buffer[0] = '\0'; } +void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size) +{ + size_t len = strlen(buffer); + assert(sbs); + assert(size > len); + sbs->begin = buffer; + sbs->size = size; + sbs->end = buffer + len; +} + void sbs_strncat(struct sbstring *sbs, const char *str, size_t size) { size_t len; diff --git a/src/util/strings.h b/src/util/strings.h index afcb477e4..29ca11ef7 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -49,6 +49,7 @@ extern "C" { } sbstring; void sbs_init(struct sbstring *sbs, char *buffer, size_t size); + void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size); void sbs_strcat(struct sbstring *sbs, const char *str); void sbs_strncat(struct sbstring *sbs, const char *str, size_t size); void sbs_strcpy(struct sbstring *sbs, const char *str); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 80ad531e9..b9ab8c729 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -165,6 +165,10 @@ static void test_sbstring(CuTest * tc) CuAssertStrEquals(tc, "12345678901234", sbs.begin); sbs_strncat(&sbs, "567890", 6); CuAssertStrEquals(tc, "123456789012345", sbs.begin); + + sbs_adopt(&sbs, buffer + 2, sizeof(buffer) - 2); + CuAssertStrEquals(tc, "3456789012345", sbs.begin); + CuAssertIntEquals(tc, 13, sbs_length(&sbs)); } static void test_sbs_strcat(CuTest * tc) From 847361fef20a5b835c24a7e0211e2c2eb2a275da Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 28 Nov 2018 18:30:50 +0100 Subject: [PATCH 15/85] split region reporting into more and smaller functions. --- src/report.c | 278 ++++++++++++++++++++++++--------------------------- 1 file changed, 130 insertions(+), 148 deletions(-) diff --git a/src/report.c b/src/report.c index b0e3891fa..4bac3d2d7 100644 --- a/src/report.c +++ b/src/report.c @@ -750,9 +750,9 @@ static void prices(struct stream *out, const region * r, const faction * f) const luxury_type *sale = NULL; struct demand *dmd; message *m; - int bytes, n = 0; - char buf[4096], *bufp = buf; - size_t size = sizeof(buf) - 1; + int n = 0; + char buf[4096]; + sbstring sbs; if (r->land == NULL || r->land->demands == NULL) return; @@ -766,64 +766,40 @@ static void prices(struct stream *out, const region * r, const faction * f) m = msg_message("nr_market_sale", "product price", sale->itype->rtype, sale->price); - - bytes = (int)nr_render(m, f->locale, bufp, size, f); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); + sbs_adopt(&sbs, buf, sizeof(buf)); if (n > 0) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_intro"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcpy(&sbs, " "); + sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_intro")); + sbs_strcpy(&sbs, " "); for (dmd = r->land->demands; dmd; dmd = dmd->next) { if (dmd->value > 0) { + size_t size = sizeof(buf) - sbs_length(&sbs); + /* FIXME: this is a bad hack, cause by how msg_message works. */ m = msg_message("nr_market_price", "product price", dmd->type->itype->rtype, dmd->value * dmd->type->price); - bytes = (int)nr_render(m, f->locale, bufp, size, f); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + size = nr_render(m, f->locale, sbs.end, size, f); + sbs.end += size; msg_release(m); n--; if (n == 0) { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_end"), - size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_end")); } else if (n == 1) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_final"), - size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcpy(&sbs, " "); + sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_final")); + sbs_strcpy(&sbs, " "); } else { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_trade_next"), - size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_next")); + sbs_strcpy(&sbs, " "); } } } } - /* Schreibe Paragraphen */ - *bufp = 0; paragraph(out, buf, 0, 0, 0); } @@ -849,74 +825,27 @@ bool see_border(const connection * b, const faction * f, const region * r) #define MAX_EDGES 16 -void report_region(struct stream *out, const region * r, faction * f) +struct edge { + char *name; + bool transparent; + bool block; + bool exist[MAXDIRECTIONS]; + direction_t lastd; +}; + +static void report_region_description(struct stream *out, const region * r, faction * f, const bool see[]) { int n; bool dh; - direction_t d; int trees; int saplings; attrib *a; const char *tname; - struct edge { - char *name; - bool transparent; - bool block; - bool exist[MAXDIRECTIONS]; - direction_t lastd; - } edges[MAX_EDGES]; - int ne = 0; - bool see[MAXDIRECTIONS]; - char buf[8192]; + char buf[4096]; char *bufp = buf; size_t size = sizeof(buf); int bytes; - assert(out); - assert(f); - assert(r); - - memset(edges, 0, sizeof(edges)); - for (d = 0; d != MAXDIRECTIONS; d++) { - /* Nachbarregionen, die gesehen werden, ermitteln */ - region *r2 = rconnect(r, d); - connection *b; - see[d] = true; - if (!r2) - continue; - for (b = get_borders(r, r2); b;) { - int e; - struct edge *match = NULL; - bool transparent = b->type->transparent(b, f); - const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE); - - if (!transparent) { - see[d] = false; - } - if (!see_border(b, f, r)) { - b = b->next; - continue; - } - for (e = 0; e!=ne; ++e) { - struct edge *edg = edges + e; - if (edg->transparent == transparent && 0 == strcmp(name, edg->name)) { - match = edg; - break; - } - } - if (match == NULL) { - match = edges + ne; - match->name = str_strdup(name); - match->transparent = transparent; - ++ne; - assert(ne < MAX_EDGES); - } - match->lastd = d; - match->exist[d] = true; - b = b->next; - } - } - bytes = (int)f_regionid(r, f, bufp, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -981,7 +910,7 @@ void report_region(struct stream *out, const region * r, faction * f) for (n = 0; n < numresults; ++n) { if (result[n].number >= 0 && result[n].level >= 0) { - const char * name = resourcename(result[n].rtype, result[n].number!=1); + const char * name = resourcename(result[n].rtype, result[n].number != 1); bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number, LOC(f->locale, name), result[n].level); if (wrptr(&bufp, &size, bytes) != 0) @@ -1089,7 +1018,7 @@ void report_region(struct stream *out, const region * r, faction * f) WARN_STATIC_BUFFER(); } else { - int nrd = 0; + int d, nrd = 0; /* Nachbarregionen, die gesehen werden, ermitteln */ for (d = 0; d != MAXDIRECTIONS; d++) { @@ -1167,6 +1096,41 @@ void report_region(struct stream *out, const region * r, faction * f) } *bufp = 0; paragraph(out, buf, 0, 0, 0); +} + +/** + * Zeige Wirkungen permanenter Sprüche. + */ +static void report_region_curses(struct stream *out, const region * r, faction * f, struct edge edges[], int nedges) { + nr_curses(out, 0, f, TYP_REGION, r); + + if (nedges > 0) { + int e; + newline(out); + for (e = 0; e != nedges; ++e) { + message *msg; + int d; + + for (d = 0; d != MAXDIRECTIONS; ++d) { + if (edges[e].exist[d]) { + char buf[512]; + msg = msg_message(edges[e].transparent ? "nr_border_transparent" : "nr_border_opaque", + "object dir", edges[e].name, d); + nr_render(msg, f->locale, buf, sizeof(buf), f); + msg_release(msg); + paragraph(out, buf, 0, 0, 0); + } + } + free(edges[e].name); + } + } +} + +static void report_region_schemes(struct stream *out, const region * r, faction * f) { + char buf[4096]; + char *bufp = buf; + size_t size = sizeof(buf); + int bytes; if (r->seen.mode >= seen_unit && is_astral(r) && !is_cursed(r->attribs, &ct_astralblock)) { @@ -1204,29 +1168,62 @@ void report_region(struct stream *out, const region * r, faction * f) paragraph(out, buf, 0, 0, 0); } } +} - /* Wirkungen permanenter Sprüche */ - nr_curses(out, 0, f, TYP_REGION, r); - n = 0; +void report_region(struct stream *out, const region * r, faction * f) +{ + int d, ne = 0; + bool see[MAXDIRECTIONS]; + struct edge edges[MAX_EDGES]; - if (ne > 0) { - int e; - newline(out); - for (e = 0; e != ne; ++e) { - message *msg; + assert(out); + assert(f); + assert(r); - for (d = 0; d != MAXDIRECTIONS; ++d) { - if (edges[e].exist[d]) { - msg = msg_message(edges[e].transparent ? "nr_border_transparent" : "nr_border_opaque", - "object dir", edges[e].name, d); - nr_render(msg, f->locale, buf, sizeof(buf), f); - msg_release(msg); - paragraph(out, buf, 0, 0, 0); + memset(edges, 0, sizeof(edges)); + for (d = 0; d != MAXDIRECTIONS; d++) { + /* Nachbarregionen, die gesehen werden, ermitteln */ + region *r2 = rconnect(r, d); + connection *b; + see[d] = true; + if (!r2) + continue; + for (b = get_borders(r, r2); b;) { + int e; + struct edge *match = NULL; + bool transparent = b->type->transparent(b, f); + const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE); + + if (!transparent) { + see[d] = false; + } + if (!see_border(b, f, r)) { + b = b->next; + continue; + } + for (e = 0; e != ne; ++e) { + struct edge *edg = edges + e; + if (edg->transparent == transparent && 0 == strcmp(name, edg->name)) { + match = edg; + break; } } - free(edges[e].name); + if (match == NULL) { + match = edges + ne; + match->name = str_strdup(name); + match->transparent = transparent; + ++ne; + assert(ne < MAX_EDGES); + } + match->lastd = d; + match->exist[d] = true; + b = b->next; } } + + report_region_description(out, r, f, see); + report_region_schemes(out, r, f); + report_region_curses(out, r, f, edges, ne); } static void statistics(struct stream *out, const region * r, const faction * f) @@ -2024,13 +2021,12 @@ report_plaintext(const char *filename, report_context * ctx, attrib *a; message *m; unsigned char op; - int maxh, bytes, ix = WANT_OPTION(O_STATISTICS); + int maxh, ix = WANT_OPTION(O_STATISTICS); int wants_stats = (f->options & ix); FILE *F = fopen(filename, "w"); stream strm = { 0 }, *out = &strm; - char buf[8192]; - char *bufp; - size_t size; + char buf[1024]; + sbstring sbs; if (F == NULL) { perror(filename); @@ -2134,26 +2130,19 @@ report_plaintext(const char *filename, report_context * ctx, centre(out, buf, true); } - bufp = buf; - size = sizeof(buf) - 1; - bytes = snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, LOC(f->locale, "nr_options")); + sbs_strcat(&sbs, ":"); for (op = 0; op != MAXOPTIONS; op++) { if (f->options & WANT_OPTION(op) && options[op]) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, options[op]), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, options[op])); - flag++; + ++flag; } } if (flag > 0) { newline(out); - *bufp = 0; centre(out, buf, true); } @@ -2192,28 +2181,21 @@ report_plaintext(const char *filename, report_context * ctx, centre(out, buf, true); newline(out); - bufp = buf; - size = sizeof(buf) - 1; - bytes = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, LOC(f->locale, "nr_herbsrequired")); + sbs_strcat(&sbs, ":"); if (itype->construction) { requirement *rm = itype->construction->materials; while (rm->number) { - bytes = - (int)str_strlcpy(bufp, LOC(f->locale, resourcename(rm->rtype, 0)), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, LOC(f->locale, resourcename(rm->rtype, 0))); ++rm; - if (rm->number) - bytes = (int)str_strlcpy(bufp, ", ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + if (rm->number) { + sbs_strcat(&sbs, ", "); + } } assert(!rm->rtype); } - *bufp = 0; centre(out, buf, true); newline(out); description = mkname("describe", pname); From 3291dcbe5be8e54dbf14656c99348d4fb358fd25 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 28 Nov 2018 20:18:22 +0100 Subject: [PATCH 16/85] more sbstring use in reports. fix paragraph lines with very long words, indirectly test through region report. --- src/report.c | 253 ++++++++++++++++++---------------------------- src/report.test.c | 39 ++++++- 2 files changed, 135 insertions(+), 157 deletions(-) diff --git a/src/report.c b/src/report.c index 4bac3d2d7..f1a3bbaa4 100644 --- a/src/report.c +++ b/src/report.c @@ -745,6 +745,13 @@ static void rp_battles(struct stream *out, faction * f) } } +static void append_message(sbstring *sbp, message *m, const faction * f) { + /* FIXME: this is a bad hack, cause by how msg_message works. */ + size_t size = sbp->size - sbs_length(sbp); + size = nr_render(m, f->locale, sbp->end, size, f); + sbp->end += size; +} + static void prices(struct stream *out, const region * r, const faction * f) { const luxury_type *sale = NULL; @@ -777,12 +784,9 @@ static void prices(struct stream *out, const region * r, const faction * f) for (dmd = r->land->demands; dmd; dmd = dmd->next) { if (dmd->value > 0) { - size_t size = sizeof(buf) - sbs_length(&sbs); - /* FIXME: this is a bad hack, cause by how msg_message works. */ m = msg_message("nr_market_price", "product price", dmd->type->itype->rtype, dmd->value * dmd->type->price); - size = nr_render(m, f->locale, sbs.end, size, f); - sbs.end += size; + append_message(&sbs, m, f); msg_release(m); n--; if (n == 0) { @@ -833,6 +837,15 @@ struct edge { direction_t lastd; }; +static void report_region_resource(sbstring *sbp, const struct locale *lang, const struct resource_type *rtype, int n) { + if (n != 0) { + sbs_strcat(sbp, ", "); + sbs_strcat(sbp, str_itoa(n)); + sbs_strcat(sbp, " "); + sbs_strcat(sbp, LOC(lang, resourcename(rtype, (n != 1) ? GR_PLURAL : 0))); + } +} + static void report_region_description(struct stream *out, const region * r, faction * f, const bool see[]) { int n; @@ -842,66 +855,61 @@ static void report_region_description(struct stream *out, const region * r, fact attrib *a; const char *tname; char buf[4096]; - char *bufp = buf; - size_t size = sizeof(buf); - int bytes; + sbstring sbs; - bytes = (int)f_regionid(r, f, bufp, size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + f_regionid(r, f, buf, sizeof(buf)); + sbs_adopt(&sbs, buf, sizeof(buf)); if (r->seen.mode == seen_travel) { - bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); + sbs_strcat(&sbs, " ("); + sbs_strcat(&sbs, LOC(f->locale, "see_travel")); + sbs_strcat(&sbs, ")"); } else if (r->seen.mode == seen_neighbour) { - bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); + sbs_strcat(&sbs, " ("); + sbs_strcat(&sbs, LOC(f->locale, "see_neighbour")); + sbs_strcat(&sbs, ")"); } else if (r->seen.mode == seen_lighthouse) { - bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); + sbs_strcat(&sbs, " ("); + sbs_strcat(&sbs, LOC(f->locale, "see_lighthouse")); + sbs_strcat(&sbs, ")"); } - else { - bytes = 0; - } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); /* Terrain */ - bytes = (int)str_strlcpy(bufp, ", ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - tname = terrain_name(r); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, tname), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ", "); + sbs_strcat(&sbs, LOC(f->locale, tname)); + pump_paragraph(&sbs, out, REPORTWIDTH, false); /* Trees */ trees = rtrees(r, 2); saplings = rtrees(r, 1); if (max_production(r)) { if (trees > 0 || saplings > 0) { - bytes = snprintf(bufp, size, ", %d/%d ", trees, saplings); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ", "); + sbs_strcat(&sbs, str_itoa(trees)); + sbs_strcat(&sbs, "/"); + sbs_strcat(&sbs, str_itoa(saplings)); + sbs_strcat(&sbs, " "); if (fval(r, RF_MALLORN)) { if (trees == 1) { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_mallorntree"), size); + sbs_strcat(&sbs, LOC(f->locale, "nr_mallorntree")); } else { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_mallorntree_p"), size); + sbs_strcat(&sbs, LOC(f->locale, "nr_mallorntree_p")); } } else if (trees == 1) { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "tree"), size); + sbs_strcat(&sbs, LOC(f->locale, "tree")); } else { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "tree_p"), size); + sbs_strcat(&sbs, LOC(f->locale, "tree_p")); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); } } + pump_paragraph(&sbs, out, REPORTWIDTH, false); /* iron & stone */ if (r->seen.mode >= seen_unit) { @@ -911,111 +919,71 @@ static void report_region_description(struct stream *out, const region * r, fact for (n = 0; n < numresults; ++n) { if (result[n].number >= 0 && result[n].level >= 0) { const char * name = resourcename(result[n].rtype, result[n].number != 1); - bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number, - LOC(f->locale, name), result[n].level); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ", "); + sbs_strcat(&sbs, str_itoa(result[n].number)); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, name)); + sbs_strcat(&sbs, "/"); + sbs_strcat(&sbs, str_itoa(result[n].level)); } } } /* peasants & silver */ - if (rpeasants(r)) { - int p = rpeasants(r); - bytes = snprintf(bufp, size, ", %d", p); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + n = rpeasants(r); + if (n) { + sbs_strcat(&sbs, ", "); + sbs_strcat(&sbs, str_itoa(n)); if (r->land->ownership) { const char *str = LOC(f->locale, mkname("morale", itoa10(region_get_morale(r)))); - bytes = snprintf(bufp, size, " %s", str); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, str); } - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = - (int)str_strlcpy(bufp, LOC(f->locale, p == 1 ? "peasant" : "peasant_p"), - size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, n != 1 ? "peasant_p" : "peasant")); + if (is_mourning(r, turn + 1)) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_mourning"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, "nr_mourning")); } } - if (rmoney(r) && r->seen.mode >= seen_travel) { - bytes = snprintf(bufp, size, ", %d ", rmoney(r)); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = - (int)str_strlcpy(bufp, LOC(f->locale, resourcename(get_resourcetype(R_SILVER), - rmoney(r) != 1)), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + if (r->seen.mode >= seen_travel) { + report_region_resource(&sbs, f->locale, get_resourcetype(R_SILVER), rmoney(r)); } /* Pferde */ - - if (rhorses(r)) { - bytes = snprintf(bufp, size, ", %d ", rhorses(r)); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = - (int)str_strlcpy(bufp, LOC(f->locale, resourcename(get_resourcetype(R_HORSE), - (rhorses(r) > 1) ? GR_PLURAL : 0)), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - } - bytes = (int)str_strlcpy(bufp, ".", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + report_region_resource(&sbs, f->locale, get_resourcetype(R_HORSE), rhorses(r)); + sbs_strcat(&sbs, "."); if (r->land && r->land->display && r->land->display[0]) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, r->land->display, size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, r->land->display); n = r->land->display[strlen(r->land->display) - 1]; if (n != '!' && n != '?' && n != '.') { - bytes = (int)str_strlcpy(bufp, ".", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, "."); } } if (rule_region_owners()) { const faction *owner = region_get_owner(r); - message *msg; if (owner != NULL) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + message *msg; + + sbs_strcat(&sbs, " "); msg = msg_message("nr_region_owner", "faction", owner); - bytes = (int)nr_render(msg, f->locale, bufp, size, f); + append_message(&sbs, msg, f); msg_release(msg); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); } } - a = a_find(r->attribs, &at_overrideroads); + pump_paragraph(&sbs, out, REPORTWIDTH, false); + a = a_find(r->attribs, &at_overrideroads); if (a) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, (char *)a->data.v, size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, (const char *)a->data.v); } else { int d, nrd = 0; @@ -1025,8 +993,8 @@ static void report_region_description(struct stream *out, const region * r, fact if (see[d] && rconnect(r, d)) nrd++; } - /* list directions */ + /* list directions */ dh = false; for (d = 0; d != MAXDIRECTIONS; d++) { if (see[d]) { @@ -1035,36 +1003,25 @@ static void report_region_description(struct stream *out, const region * r, fact continue; nrd--; if (dh) { - char regname[4096]; + char regname[128], trail[256]; if (nrd == 0) { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_nb_final"), size); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, "nr_nb_final")); } else { - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_nb_next"), size); + sbs_strcat(&sbs, LOC(f->locale, "nr_nb_next")); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, directions[d]), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, LOC(f->locale, directions[d])); + sbs_strcat(&sbs, " "); f_regionid(r2, f, regname, sizeof(regname)); - bytes = snprintf(bufp, size, trailinto(r2, f->locale), regname); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + snprintf(trail, sizeof(trail), trailinto(r2, f->locale), regname); + sbs_strcat(&sbs, trail); } else { - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - MSG(("nr_vicinitystart", "dir region", d, r2), bufp, size, f->locale, - f); - bufp += strlen(bufp); + message * msg = msg_message("nr_vicinitystart", "dir region", d, r2); + sbs_strcat(&sbs, " "); + append_message(&sbs, msg, f); + msg_release(msg); dh = true; } } @@ -1073,29 +1030,15 @@ static void report_region_description(struct stream *out, const region * r, fact for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { spec_direction *spd = (spec_direction *)(a->data.v); - bytes = (int)str_strlcpy(bufp, " ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, spd->desc), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, " (\"", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, spd->keyword), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, "\")", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, ".", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, spd->desc)); + sbs_strcat(&sbs, " (\""); + sbs_strcat(&sbs, LOC(f->locale, spd->keyword)); + sbs_strcat(&sbs, "\")."); dh = 1; } } - *bufp = 0; - paragraph(out, buf, 0, 0, 0); + pump_paragraph(&sbs, out, REPORTWIDTH, true); } /** @@ -1521,15 +1464,19 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) return; } else if (next > begin + maxlen) { - ptrdiff_t len = pos - begin; + ptrdiff_t len; + if (pos == begin) { + /* there was no space before the break, line will be too long */ + pos = next; + } + len = pos - begin; swrite(begin, 1, len, out); newline(out); while (*pos && IS_UTF8_SPACE(pos)) { ++pos; - ++len; } - sbs_substr(sbp, len, SIZE_MAX); + sbs_substr(sbp, pos - begin, SIZE_MAX); break; } pos = next; diff --git a/src/report.test.c b/src/report.test.c index 84f2f070d..601df8eb0 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -106,12 +106,30 @@ static void test_report_region(CuTest *tc) { rsettrees(r, 0, 1); rsettrees(r, 1, 2); rsettrees(r, 2, 3); - region_setname(r, "Hodor"); f = test_create_faction(NULL); f->locale = lang; u = test_create_unit(f, r); set_level(u, SK_QUARRYING, 1); + region_setname(r, "1234567890123456789012345678901234567890"); + r->seen.mode = seen_travel; + report_region(&out, r, f); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, "1234567890123456789012345678901234567890 (0,0) (durchgereist), Ebene, 3/2\nBlumen, 5 Bauern, 2 Silber, 7 Pferde.\n", buf); + + out.api->rewind(out.handle); + region_setname(r, "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); + r->seen.mode = seen_travel; + report_region(&out, r, f); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n(0,0) (durchgereist), Ebene, 3/2 Blumen, 5 Bauern, 2 Silber, 7 Pferde.\n", buf); + + out.api->rewind(out.handle); + region_setname(r, "Hodor"); r->seen.mode = seen_travel; report_region(&out, r, f); out.api->rewind(out.handle); @@ -119,27 +137,40 @@ static void test_report_region(CuTest *tc) { buf[len] = '\0'; CuAssertStrEquals(tc, "Hodor (0,0) (durchgereist), Ebene, 3/2 Blumen, 5 Bauern, 2 Silber, 7 Pferde.\n", buf); - r->seen.mode = seen_unit; out.api->rewind(out.handle); + r->seen.mode = seen_unit; report_region(&out, r, f); out.api->rewind(out.handle); len = out.api->read(out.handle, buf, sizeof(buf)); buf[len] = '\0'; CuAssertStrEquals(tc, "Hodor (0,0), Ebene, 3/2 Blumen, 135 Steine/1, 5 Bauern, 2 Silber, 7 Pferde.\n", buf); + out.api->rewind(out.handle); r->resources->amount = 1; r->land->peasants = 1; r->land->horses = 1; r->land->money = 1; - r->seen.mode = seen_unit; - out.api->rewind(out.handle); report_region(&out, r, f); out.api->rewind(out.handle); len = out.api->read(out.handle, buf, sizeof(buf)); buf[len] = '\0'; CuAssertStrEquals(tc, "Hodor (0,0), Ebene, 3/2 Blumen, 1 Stein/1, 1 Bauer, 1 Silber, 1 Pferd.\n", buf); + r->land->peasants = 0; + r->land->horses = 0; + r->land->money = 0; + rsettrees(r, 0, 0); + rsettrees(r, 1, 0); + rsettrees(r, 2, 0); + + out.api->rewind(out.handle); + report_region(&out, r, f); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, "Hodor (0,0), Ebene, 1 Stein/1.\n", buf); + mstream_done(&out); test_teardown(); } From 97af710e97fbc999db0397688500d20bcd245f4e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 28 Nov 2018 20:57:17 +0100 Subject: [PATCH 17/85] fix display of luxury prices, period at end of description. --- src/report.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/report.c b/src/report.c index f1a3bbaa4..eadf40354 100644 --- a/src/report.c +++ b/src/report.c @@ -778,9 +778,9 @@ static void prices(struct stream *out, const region * r, const faction * f) sbs_adopt(&sbs, buf, sizeof(buf)); if (n > 0) { - sbs_strcpy(&sbs, " "); - sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_intro")); - sbs_strcpy(&sbs, " "); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, "nr_trade_intro")); + sbs_strcat(&sbs, " "); for (dmd = r->land->demands; dmd; dmd = dmd->next) { if (dmd->value > 0) { @@ -790,16 +790,16 @@ static void prices(struct stream *out, const region * r, const faction * f) msg_release(m); n--; if (n == 0) { - sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_end")); + sbs_strcat(&sbs, LOC(f->locale, "nr_trade_end")); } else if (n == 1) { - sbs_strcpy(&sbs, " "); - sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_final")); - sbs_strcpy(&sbs, " "); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, "nr_trade_final")); + sbs_strcat(&sbs, " "); } else { - sbs_strcpy(&sbs, LOC(f->locale, "nr_trade_next")); - sbs_strcpy(&sbs, " "); + sbs_strcat(&sbs, LOC(f->locale, "nr_trade_next")); + sbs_strcat(&sbs, " "); } } } @@ -984,6 +984,7 @@ static void report_region_description(struct stream *out, const region * r, fact if (a) { sbs_strcat(&sbs, " "); sbs_strcat(&sbs, (const char *)a->data.v); + sbs_strcat(&sbs, "."); } else { int d, nrd = 0; @@ -1026,6 +1027,7 @@ static void report_region_description(struct stream *out, const region * r, fact } } } + sbs_strcat(&sbs, "."); /* Spezielle Richtungen */ for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { @@ -1042,9 +1044,9 @@ static void report_region_description(struct stream *out, const region * r, fact } /** - * Zeige Wirkungen permanenter Sprüche. + * Show roads and certain magic effects. */ -static void report_region_curses(struct stream *out, const region * r, faction * f, struct edge edges[], int nedges) { +static void report_region_edges(struct stream *out, const region * r, faction * f, struct edge edges[], int nedges) { nr_curses(out, 0, f, TYP_REGION, r); if (nedges > 0) { @@ -1166,7 +1168,7 @@ void report_region(struct stream *out, const region * r, faction * f) report_region_description(out, r, f, see); report_region_schemes(out, r, f); - report_region_curses(out, r, f, edges, ne); + report_region_edges(out, r, f, edges, ne); } static void statistics(struct stream *out, const region * r, const faction * f) @@ -1577,7 +1579,7 @@ void report_allies(struct stream *out, size_t maxlen, const struct faction * f, show.num_listed = 0; show.maxlen = maxlen; sbs_init(&show.sbs, buf, sizeof(buf)); - sbs_strcpy(&show.sbs, prefix); + sbs_strcat(&show.sbs, prefix); allies_walk(allies, show_allies_cb, &show); } From 892b07c64c7f1bbaa39bba45a47b95a0b3c43c2b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 29 Nov 2018 06:46:08 +0100 Subject: [PATCH 18/85] oops. broke test again with another case of too many periods. --- src/report.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/report.c b/src/report.c index eadf40354..8486d9e09 100644 --- a/src/report.c +++ b/src/report.c @@ -1027,7 +1027,9 @@ static void report_region_description(struct stream *out, const region * r, fact } } } - sbs_strcat(&sbs, "."); + if (dh) { + sbs_strcat(&sbs, "."); + } /* Spezielle Richtungen */ for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { From 08cf00e700f65fe96a6642a3ef0bb56cad49d854 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 30 Nov 2018 10:26:49 +0100 Subject: [PATCH 19/85] more sbstring conversions --- src/report.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/report.c b/src/report.c index 8486d9e09..8f9d9c27d 100644 --- a/src/report.c +++ b/src/report.c @@ -1075,9 +1075,8 @@ static void report_region_edges(struct stream *out, const region * r, faction * static void report_region_schemes(struct stream *out, const region * r, faction * f) { char buf[4096]; - char *bufp = buf; - size_t size = sizeof(buf); - int bytes; + sbstring sbs; + sbs_init(&sbs, buf, sizeof(buf)); if (r->seen.mode >= seen_unit && is_astral(r) && !is_cursed(r->attribs, &ct_astralblock)) { @@ -1086,32 +1085,22 @@ static void report_region_schemes(struct stream *out, const region * r, faction region_list *rl2; if (rl) { - bufp = buf; - size = sizeof(buf) - 1; - /* this localization might not work for every language but is fine for de and en */ - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_schemes_prefix"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, LOC(f->locale, "nr_schemes_prefix")); rl2 = rl; while (rl2) { - bytes = (int)f_regionid(rl2->data, f, bufp, size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + char rbuf[REPORTWIDTH]; + f_regionid(rl2->data, f, rbuf, sizeof(rbuf)); + sbs_strcat(&sbs, rbuf); rl2 = rl2->next; if (rl2) { - bytes = (int)str_strlcpy(bufp, ", ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ", "); } } - bytes = (int)str_strlcpy(bufp, LOC(f->locale, "nr_schemes_postfix"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs,LOC(f->locale, "nr_schemes_postfix")); free_regionlist(rl); /* Schreibe Paragraphen */ newline(out); - *bufp = 0; paragraph(out, buf, 0, 0, 0); } } From fbb7a6c4184953f6918182dedf786e965cd75d04 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 30 Nov 2018 10:52:32 +0100 Subject: [PATCH 20/85] convert report_template to sbstring --- src/report.c | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/report.c b/src/report.c index 8f9d9c27d..2f4254901 100644 --- a/src/report.c +++ b/src/report.c @@ -1277,9 +1277,8 @@ report_template(const char *filename, report_context * ctx, const char *bom) region *r; FILE *F = fopen(filename, "w"); stream strm = { 0 }, *out = &strm; - char buf[8192], *bufp; - size_t size; - int bytes; + char buf[4096]; + sbstring sbs; if (F == NULL) { perror(filename); @@ -1339,50 +1338,40 @@ report_template(const char *filename, report_context * ctx, const char *bom) } dh = 1; - bufp = buf; - size = sizeof(buf) - 1; - bytes = snprintf(bufp, size, "%s %s; %s [%d,%d$", - LOC(u->faction->locale, parameters[P_UNIT]), - itoa36(u->no), unit_getname(u), u->number, get_money(u)); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, LOC(u->faction->locale, parameters[P_UNIT])); + sbs_strcat(&sbs, " "); + sbs_strcat(&sbs, itoa36(u->no)), + sbs_strcat(&sbs, "; "); + sbs_strcat(&sbs, unit_getname(u)); + sbs_strcat(&sbs, " ["); + sbs_strcat(&sbs, str_itoa(u->number)); + sbs_strcat(&sbs, ","); + sbs_strcat(&sbs, str_itoa(get_money(u))); + sbs_strcat(&sbs, "$"); if (u->building && building_owner(u->building) == u) { building *b = u->building; if (!curse_active(get_curse(b->attribs, &ct_nocostbuilding))) { int cost = buildingmaintenance(b, rsilver); if (cost > 0) { - bytes = (int)str_strlcpy(bufp, ",U", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, itoa10(cost), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ",U"); + sbs_strcat(&sbs, str_itoa(cost)); } } } else if (u->ship) { if (ship_owner(u->ship) == u) { - bytes = (int)str_strlcpy(bufp, ",S", size); + sbs_strcat(&sbs, ",S"); } else { - bytes = (int)str_strlcpy(bufp, ",s", size); + sbs_strcat(&sbs, ",s"); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, itoa36(u->ship->no), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs,itoa36(u->ship->no)); } if (lifestyle(u) == 0) { - bytes = (int)str_strlcpy(bufp, ",I", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ",I"); } - bytes = (int)str_strlcpy(bufp, "]", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - - *bufp = 0; + sbs_strcat(&sbs, "]"); rps_nowrap(out, buf); newline(out); From 2766ed8de4f0e3e6bdb2b55e9514070ef180bf96 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 12:27:11 +0100 Subject: [PATCH 21/85] =?UTF-8?q?Bug=202521:=20=C3=9Cbersetzung=20von=20at?= =?UTF-8?q?=5Fracename=20f=C3=BCr=20Geister?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/creport.c | 8 +++++--- src/reports.c | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/creport.c b/src/creport.c index 1bc34fa5d..9d4e33728 100644 --- a/src/creport.c +++ b/src/creport.c @@ -848,11 +848,13 @@ void cr_output_unit(stream *out, const faction * f, pzTmp = get_racename(u->attribs); if (pzTmp) { - stream_printf(out, "\"%s\";Typ\n", pzTmp); + const char *pzRace = LOC(lang, mkname("race", pzTmp)); + pzTmp = pzRace ? pzRace : pzTmp; + stream_printf(out, "\"%s\";Typ\n", translate(pzTmp, LOC(lang, pzTmp))); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { - const char *zRace = rc_name_s(u_race(u), NAME_PLURAL); + pzRace = rc_name_s(u_race(u), NAME_PLURAL); stream_printf(out, "\"%s\";wahrerTyp\n", - translate(zRace, LOC(lang, zRace))); + translate(pzRace, LOC(lang, pzRace))); } } else { diff --git a/src/reports.c b/src/reports.c index 00d6b8bad..93bbb187c 100644 --- a/src/reports.c +++ b/src/reports.c @@ -714,7 +714,8 @@ void bufunit(const faction * f, const unit * u, const faction *fv, pzTmp = get_racename(u->attribs); if (pzTmp) { - sbs_strcat(sbp, pzTmp); + const char *name = LOC(lang, mkname("race", pzTmp)); + sbs_strcat(sbp, name ? name : pzTmp); if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { sbs_strcat(sbp, " ("); sbs_strcat(sbp, racename(lang, u, u_race(u))); From 5d99dc70142289710fafd9d2b69b3cb0a5d8f385 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 19:54:07 +0100 Subject: [PATCH 22/85] add a printf function to sbstring (about time) --- src/util/strings.c | 20 ++++++++++++++++++++ src/util/strings.h | 1 + src/util/strings.test.c | 26 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/util/strings.c b/src/util/strings.c index e469c2a18..df15ab588 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -256,6 +256,26 @@ char *str_strdup(const char *s) { #endif } +void sbs_printf(struct sbstring *sbs, const char *format, ...) +{ + size_t size = sbs->size - (sbs->end - sbs->begin); + + if (size > 0) { + va_list argp; + va_start(argp, format); + int bytes = vsnprintf(sbs->end, size, format, argp); + if (bytes > 0) { + if ((size_t)bytes >= size) { + bytes = size - 1; + /* terminate truncated output */ + sbs->end[bytes] = '\0'; + } + sbs->end += bytes; + } + va_end(argp); + } +} + void sbs_init(struct sbstring *sbs, char *buffer, size_t size) { assert(sbs); diff --git a/src/util/strings.h b/src/util/strings.h index 29ca11ef7..acce3767b 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -48,6 +48,7 @@ extern "C" { char *end; } sbstring; + void sbs_printf(struct sbstring *sbs, const char *format, ...); void sbs_init(struct sbstring *sbs, char *buffer, size_t size); void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size); void sbs_strcat(struct sbstring *sbs, const char *str); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index b9ab8c729..399f6a4dd 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -234,6 +234,31 @@ static void test_sbs_substr(CuTest * tc) CuAssertIntEquals(tc, 'A', buffer[9]); } +static void test_sbs_printf(CuTest * tc) +{ + char buffer[10]; + sbstring sbs; + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_printf(&sbs, "%s %d", "1234", 5678); + CuAssertStrEquals(tc, "1234 5678", buffer); + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_printf(&sbs, "%s", "12345"); + sbs_printf(&sbs, "%d", 6789); + CuAssertStrEquals(tc, "123456789", buffer); + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_printf(&sbs, "%s", "1234567890"); + CuAssertStrEquals(tc, "123456789", buffer); + + sbs_init(&sbs, buffer, sizeof(buffer)); + sbs_printf(&sbs, "%d", 123456789); + CuAssertStrEquals(tc, "123456789", buffer); + sbs_printf(&sbs, "%s", "Hodor"); + CuAssertStrEquals(tc, "123456789", buffer); +} + CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -249,5 +274,6 @@ CuSuite *get_strings_suite(void) SUITE_ADD_TEST(suite, test_sbstring); SUITE_ADD_TEST(suite, test_sbs_strcat); SUITE_ADD_TEST(suite, test_sbs_substr); + SUITE_ADD_TEST(suite, test_sbs_printf); return suite; } From d162c2dee18c4c73a7f34e69c4d90878b63330c1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 20:25:06 +0100 Subject: [PATCH 23/85] excise bsdstring from the project --- src/kernel/order.c | 2 +- src/kernel/race.c | 2 +- src/move.c | 2 +- src/report.c | 81 +++++++++++++---------------------------- src/util/CMakeLists.txt | 2 - src/util/bsdstring.c | 52 -------------------------- src/util/bsdstring.h | 16 -------- src/util/strings.c | 10 ----- src/util/strings.h | 1 - src/util/strings.test.c | 18 ++++----- 10 files changed, 38 insertions(+), 148 deletions(-) delete mode 100644 src/util/bsdstring.c delete mode 100644 src/util/bsdstring.h diff --git a/src/kernel/order.c b/src/kernel/order.c index 493922faa..6b81f7dcf 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -120,7 +120,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si sbs_init(&sbs, sbuffer, size); if (ord->command & CMD_QUIET) { - sbs_strcpy(&sbs, "!"); + sbs_strcat(&sbs, "!"); } if (ord->command & CMD_PERSIST) { sbs_strcat(&sbs, "@"); diff --git a/src/kernel/race.c b/src/kernel/race.c index 53abd339f..6c5f0b626 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -546,7 +546,7 @@ const char *racename(const struct locale *loc, const unit * u, const race * rc) char ch[2]; sbs_init(&sbs, lbuf, sizeof(lbuf)); - sbs_strcpy(&sbs, LOC(loc, mkname("prefix", prefix))); + sbs_strcat(&sbs, LOC(loc, mkname("prefix", prefix))); str = LOC(loc, rc_name_s(rc, u->number != 1)); assert(~str[0] & 0x80 || !"unicode/not implemented"); diff --git a/src/move.c b/src/move.c index e73d4f92a..bcf159309 100644 --- a/src/move.c +++ b/src/move.c @@ -2286,7 +2286,7 @@ int follow_ship(unit * u, order * ord) } sbs_init(&sbcmd, command, sizeof(command)); - sbs_strcpy(&sbcmd, LOC(u->faction->locale, keyword(K_MOVE))); + sbs_strcat(&sbcmd, LOC(u->faction->locale, keyword(K_MOVE))); sbs_strcat(&sbcmd, " "); sbs_strcat(&sbcmd, LOC(u->faction->locale, directions[dir])); diff --git a/src/report.c b/src/report.c index 2f4254901..273e1ac91 100644 --- a/src/report.c +++ b/src/report.c @@ -79,7 +79,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include -#include "util/bsdstring.h" #include #include #include @@ -257,10 +256,10 @@ void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct sbs_init(&sbs, buf, size); if (sp->sptyp & ISCOMBATSPELL) { - sbs_strcpy(&sbs, LOC(lang, keyword(K_COMBATSPELL))); + sbs_strcat(&sbs, LOC(lang, keyword(K_COMBATSPELL))); } else { - sbs_strcpy(&sbs, LOC(lang, keyword(K_CAST))); + sbs_strcat(&sbs, LOC(lang, keyword(K_CAST))); } /* Reihenfolge beachten: Erst REGION, dann STUFE! */ @@ -1431,6 +1430,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) { while (sbs_length(sbp) > maxlen) { char *pos, *begin = sbp->begin; + assert(begin); while (*begin && IS_UTF8_SPACE(begin)) { /* eat whitespace */ ++begin; @@ -1619,41 +1619,32 @@ static void guards(struct stream *out, const region * r, const faction * see) } if (nextguard || tarned) { - char buf[8192]; - char *bufp = buf; - size_t size = sizeof(buf) - 1; - int bytes; + char buf[2048]; + sbstring sbs; - bytes = (int)str_strlcpy(bufp, LOC(see->locale, "nr_guarding_prefix"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, LOC(see->locale, "nr_guarding_prefix")); for (i = 0; i != nextguard + (tarned ? 1 : 0); ++i) { if (i != 0) { if (i == nextguard - (tarned ? 0 : 1)) { - bytes = (int)str_strlcpy(bufp, LOC(see->locale, "list_and"), size); + sbs_strcat(&sbs, LOC(see->locale, "list_and")); } else { - bytes = (int)str_strlcpy(bufp, ", ", size); + sbs_strcat(&sbs, ", "); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); } if (i < nextguard) { - bytes = (int)str_strlcpy(bufp, factionname(guardians[i]), size); + sbs_strcat(&sbs, factionname(guardians[i])); } else { - bytes = (int)str_strlcpy(bufp, LOC(see->locale, "nr_guarding_unknown"), size); + sbs_strcat(&sbs, LOC(see->locale, "nr_guarding_unknown")); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + pump_paragraph(&sbs, out, REPORTWIDTH, false); } - bytes = (int)str_strlcpy(bufp, LOC(see->locale, "nr_guarding_postfix"), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, LOC(see->locale, "nr_guarding_postfix")); newline(out); - *bufp = 0; - paragraph(out, buf, 0, 0, 0); + pump_paragraph(&sbs, out, REPORTWIDTH, true); } } @@ -1704,11 +1695,11 @@ static void nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, const unit * captain) { - char buffer[8192], *bufp = buffer; - size_t size = sizeof(buffer) - 1; - int bytes; + char buffer[1024]; char ch; + sbstring sbs; + sbs_init(&sbs, buffer, sizeof(buffer)); newline(out); if (captain && captain->faction == f) { @@ -1716,57 +1707,37 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f, getshipweight(sh, &n, &p); n = (n + 99) / 100; /* 1 Silber = 1 GE */ - bytes = snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), + sbs_printf(&sbs, "%s, %s, (%d/%d)", shipname(sh), LOC(f->locale, sh->type->_name), n, shipcapacity(sh) / 100); } else { - bytes = - snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, - sh->type->_name)); + sbs_printf(&sbs, "%s, %s", shipname(sh), LOC(f->locale, sh->type->_name)); } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); if (sh->size != sh->type->construction->maxsize) { - bytes = snprintf(bufp, size, ", %s (%d/%d)", + sbs_printf(&sbs, ", %s (%d/%d)", LOC(f->locale, "nr_undercons"), sh->size, sh->type->construction->maxsize); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); } if (sh->damage) { int percent = ship_damage_percent(sh); - bytes = - snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_printf(&sbs, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); } if (!fval(r->terrain, SEA_REGION)) { if (sh->coast != NODIRECTION) { - bytes = (int)str_strlcpy(bufp, ", ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, LOC(f->locale, coasts[sh->coast]), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, ", "); + sbs_strcat(&sbs, LOC(f->locale, coasts[sh->coast])); } } ch = 0; if (sh->display && sh->display[0]) { - bytes = (int)str_strlcpy(bufp, "; ", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = (int)str_strlcpy(bufp, sh->display, size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, "; "); + sbs_strcat(&sbs, sh->display); ch = sh->display[strlen(sh->display) - 1]; } if (ch != '!' && ch != '?' && ch != '.') { - bytes = (int)str_strlcpy(bufp, ".", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + sbs_strcat(&sbs, "."); } - *bufp = 0; paragraph(out, buffer, 2, 0, 0); nr_curses(out, 4, f, TYP_SHIP, sh); diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 362ee4fb2..19bf70b12 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory (crypto) SET(_TEST_FILES base36.test.c -# bsdstring.test.c # crmessage.test.c # dice.test.c # filereader.test.c @@ -34,7 +33,6 @@ variant.test.c SET(_FILES base36.c -bsdstring.c crmessage.c dice.c filereader.c diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c deleted file mode 100644 index 19d6dee0d..000000000 --- a/src/util/bsdstring.c +++ /dev/null @@ -1,52 +0,0 @@ -#ifdef _MSC_VER -#include -#endif -#include -#include -#include -#include - -#include "bsdstring.h" -#include "log.h" -#include "strings.h" - -int wrptr(char **ptr, size_t * size, int result) -{ - size_t bytes = (size_t)result; - if (result < 0) { - /* buffer was too small */ - if (*size > 0) { - **ptr = 0; - *size = 0; - } - errno = 0; - return ERANGE; - } - if (bytes == 0) { - return 0; - } - if (bytes <= *size) { - *ptr += bytes; - *size -= bytes; - return 0; - } - - *ptr += *size; - *size = 0; - return ERANGE; -} - -char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line) -{ - size_t bytes = str_strlcpy(dst, src, *siz); - char * buf = dst; - assert(bytes <= INT_MAX); - if (wrptr(&buf, siz, (int)bytes) != 0) { - if (err) { - log_warning("%s: static buffer too small in %s:%d\n", err, file, line); - } else { - log_warning("static buffer too small in %s:%d\n", file, line); - } - } - return buf; -} diff --git a/src/util/bsdstring.h b/src/util/bsdstring.h deleted file mode 100644 index 56772180a..000000000 --- a/src/util/bsdstring.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef UTIL_BSDSTRING_H -#define UTIL_BSDSTRING_H - -#include - -int wrptr(char **ptr, size_t * size, int bytes); -char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line); - -#define BUFFER_STRCAT(bufp, size, bytes) if (wrptr(&bufp, &size, bytes) != 0) log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__); - -#define WARN_STATIC_BUFFER() log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__) -#define INFO_STATIC_BUFFER() log_info("static buffer too small in %s:%d\n", __FILE__, __LINE__) -#define STRLCPY(dst, src, siz) strlcpy_w((dst), (src), &(siz), 0, __FILE__, __LINE__) -#define STRLCPY_EX(dst, src, siz, err) strlcpy_w((dst), (src), (siz), (err), __FILE__, __LINE__) - -#endif diff --git a/src/util/strings.c b/src/util/strings.c index df15ab588..ef3c3a575 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -319,16 +319,6 @@ void sbs_strcat(struct sbstring *sbs, const char *str) assert(sbs->begin + sbs->size >= sbs->end); } -void sbs_strcpy(struct sbstring *sbs, const char *str) -{ - size_t len = str_strlcpy(sbs->begin, str, sbs->size); - if (len >= sbs->size) { - len = sbs->size - 1; - } - sbs->end = sbs->begin + len; - assert(sbs->begin + sbs->size >= sbs->end); -} - void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len) { if (pos > sbs->end - sbs->begin) { diff --git a/src/util/strings.h b/src/util/strings.h index acce3767b..a381b56b9 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -53,7 +53,6 @@ extern "C" { void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size); void sbs_strcat(struct sbstring *sbs, const char *str); void sbs_strncat(struct sbstring *sbs, const char *str, size_t size); - void sbs_strcpy(struct sbstring *sbs, const char *str); void sbs_substr(struct sbstring *sbp, ptrdiff_t pos, size_t len); size_t sbs_length(const struct sbstring *sbs); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 399f6a4dd..3237a3208 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -147,19 +147,19 @@ static void test_sbstring(CuTest * tc) sbstring sbs; sbs_init(&sbs, buffer, sizeof(buffer)); CuAssertStrEquals(tc, "", sbs.begin); - sbs_strcpy(&sbs, "Hodor"); + sbs_strcat(&sbs, "Hodor"); CuAssertStrEquals(tc, "Hodor", sbs.begin); sbs_strcat(&sbs, "Hodor"); CuAssertStrEquals(tc, "HodorHodor", sbs.begin); - sbs_strcpy(&sbs, "Hodor"); + sbs_strcat(&sbs, "Hodor"); CuAssertStrEquals(tc, "Hodor", sbs.begin); - sbs_strcpy(&sbs, "12345678901234567890"); + sbs_strcat(&sbs, "12345678901234567890"); CuAssertStrEquals(tc, "123456789012345", sbs.begin); CuAssertPtrEquals(tc, sbs.begin + sbs.size - 1, sbs.end); sbs_strcat(&sbs, "12345678901234567890"); CuAssertStrEquals(tc, "123456789012345", sbs.begin); CuAssertPtrEquals(tc, buffer, sbs.begin); - sbs_strcpy(&sbs, "1234567890"); + sbs_strcat(&sbs, "1234567890"); CuAssertStrEquals(tc, "1234567890", sbs.begin); sbs_strncat(&sbs, "1234567890", 4); CuAssertStrEquals(tc, "12345678901234", sbs.begin); @@ -202,31 +202,31 @@ static void test_sbs_substr(CuTest * tc) buffer[9] = 'A'; sbs_init(&sbs, buffer, sizeof(buffer)); - sbs_strcpy(&sbs, "12345678"); + sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 0, 4); CuAssertStrEquals(tc, "1234", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); - sbs_strcpy(&sbs, "12345678"); + sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 4, 4); CuAssertStrEquals(tc, "5678", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); - sbs_strcpy(&sbs, "12345678"); + sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 2, 4); CuAssertStrEquals(tc, "3456", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); - sbs_strcpy(&sbs, "12345678"); + sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 4, 4); CuAssertStrEquals(tc, "5678", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); - sbs_strcpy(&sbs, "12345678"); + sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 4, 8); CuAssertStrEquals(tc, "5678", buffer); From 3f9331cd090b21eccefe01de8384c536fb55816e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 20:39:39 +0100 Subject: [PATCH 24/85] fix string unit tests after strcpy was removed --- src/util/strings.test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 3237a3208..ac05b91e9 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -151,14 +151,22 @@ static void test_sbstring(CuTest * tc) CuAssertStrEquals(tc, "Hodor", sbs.begin); sbs_strcat(&sbs, "Hodor"); CuAssertStrEquals(tc, "HodorHodor", sbs.begin); + + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "Hodor"); CuAssertStrEquals(tc, "Hodor", sbs.begin); + + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "12345678901234567890"); CuAssertStrEquals(tc, "123456789012345", sbs.begin); CuAssertPtrEquals(tc, sbs.begin + sbs.size - 1, sbs.end); + + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "12345678901234567890"); CuAssertStrEquals(tc, "123456789012345", sbs.begin); CuAssertPtrEquals(tc, buffer, sbs.begin); + + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "1234567890"); CuAssertStrEquals(tc, "1234567890", sbs.begin); sbs_strncat(&sbs, "1234567890", 4); @@ -208,24 +216,28 @@ static void test_sbs_substr(CuTest * tc) CuAssertStrEquals(tc, "1234", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 4, 4); CuAssertStrEquals(tc, "5678", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 2, 4); CuAssertStrEquals(tc, "3456", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 4, 4); CuAssertStrEquals(tc, "5678", buffer); CuAssertIntEquals(tc, 4, (int)sbs_length(&sbs)); + sbs_init(&sbs, buffer, sizeof(buffer)); sbs_strcat(&sbs, "12345678"); CuAssertStrEquals(tc, "12345678", buffer); sbs_substr(&sbs, 4, 8); From 2e79c51d00f088c6ad778fe3d79e862492415920 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 21:51:52 +0100 Subject: [PATCH 25/85] fix overly long lines in NR. --- src/report.c | 7 ++++++- src/report.test.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/report.c b/src/report.c index 273e1ac91..f5023d6bb 100644 --- a/src/report.c +++ b/src/report.c @@ -1440,7 +1440,12 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) char *next = strchr(pos+1, ' '); if (next == NULL) { if (isfinal) { - swrite(begin, 1, sbp->end - begin, out); + swrite(begin, 1, pos - begin, out); + while (*pos && IS_UTF8_SPACE(pos)) { + ++pos; + } + newline(out); + swrite(pos, 1, sbp->end - pos, out); newline(out); } return; diff --git a/src/report.test.c b/src/report.test.c index 601df8eb0..67b0d602a 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -379,11 +379,32 @@ static void test_write_spell_syntax(CuTest *tc) { test_teardown(); } +static void test_pump_paragraph_toolong(CuTest *tc) { + const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303)."; + const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n"; + sbstring sbs; + char buf[256]; + stream out = { 0 }; + size_t len; + + mstream_init(&out); + + sbs_init(&sbs, buf, sizeof(buf)); + sbs_strcat(&sbs, toolong); + + pump_paragraph(&sbs, &out, 78, true); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, expect, buf); +} + CuSuite *get_report_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_write_spaces); SUITE_ADD_TEST(suite, test_write_many_spaces); + SUITE_ADD_TEST(suite, test_pump_paragraph_toolong); SUITE_ADD_TEST(suite, test_report_travelthru); SUITE_ADD_TEST(suite, test_report_region); SUITE_ADD_TEST(suite, test_report_allies); From 781acdbf6be76d7c02f4ba6f9bcdf8cddb49c503 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 1 Dec 2018 21:56:21 +0100 Subject: [PATCH 26/85] start adding legacy tests for paragraph --- src/report.c | 5 ++--- src/report.h | 1 + src/report.test.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/report.c b/src/report.c index f5023d6bb..b96267b82 100644 --- a/src/report.c +++ b/src/report.c @@ -169,9 +169,8 @@ static void centre(struct stream *out, const char *s, bool breaking) } } -static void -paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_indent, - char marker) +void paragraph(struct stream *out, const char *str, ptrdiff_t indent, + int hanging_indent, char marker) { size_t length = REPORTWIDTH; const char *handle_end, *begin, *mark = 0; diff --git a/src/report.h b/src/report.h index 307dba38b..ed31d179e 100644 --- a/src/report.h +++ b/src/report.h @@ -35,6 +35,7 @@ extern "C" { void report_region(struct stream *out, const struct region * r, struct faction * f); void report_allies(struct stream *out, size_t maxlen, const struct faction * f, struct allies * allies, const char *prefix); void pump_paragraph(struct sbstring *sbp, struct stream *out, size_t maxlen, bool isfinal); + void paragraph(struct stream *out, const char *str, ptrdiff_t indent, int hanging_indent, char marker); void nr_spell_syntax(char *buf, size_t size, struct spellbook_entry * sbe, const struct locale *lang); void nr_spell(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang); diff --git a/src/report.test.c b/src/report.test.c index 67b0d602a..59148d3a2 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -379,6 +379,38 @@ static void test_write_spell_syntax(CuTest *tc) { test_teardown(); } +static void test_paragraph(CuTest *tc) { + const char *toolong = "im Westen das Hochland von Geraldin (93,-303)."; + const char *expect = "im Westen das Hochland von Geraldin (93,-303).\n"; + char buf[256]; + stream out = { 0 }; + size_t len; + + mstream_init(&out); + + paragraph(&out, toolong, 0, 0, 0); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, expect, buf); +} + +static void test_paragraph_break(CuTest *tc) { + const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303)."; + const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n"; + char buf[256]; + stream out = { 0 }; + size_t len; + + mstream_init(&out); + + paragraph(&out, toolong, 0, 0, 0); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, expect, buf); +} + static void test_pump_paragraph_toolong(CuTest *tc) { const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303)."; const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n"; @@ -404,6 +436,8 @@ CuSuite *get_report_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_write_spaces); SUITE_ADD_TEST(suite, test_write_many_spaces); + SUITE_ADD_TEST(suite, test_paragraph); + SUITE_ADD_TEST(suite, test_paragraph_break); SUITE_ADD_TEST(suite, test_pump_paragraph_toolong); SUITE_ADD_TEST(suite, test_report_travelthru); SUITE_ADD_TEST(suite, test_report_region); From 11316a49923114c9633e347702a21dd3fa48c1e4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Dec 2018 05:04:49 +0100 Subject: [PATCH 27/85] remove jsreport. fix some cppcheck warnings. --- src/battle.c | 17 -------- src/battle.h | 1 - src/bind_unit.c | 22 ---------- src/eressea.c | 4 +- src/jsreport.c | 90 ---------------------------------------- src/jsreport.h | 24 ----------- src/kernel/curse.c | 10 ----- src/kernel/faction.c | 22 ---------- src/kernel/faction.h | 1 - src/kernel/race.c | 9 ---- src/kernel/terrain.c | 1 - src/tests.c | 29 +++---------- src/util/base36.c | 10 ----- src/util/base36.h | 7 ++-- src/util/crypto/crypto.c | 4 +- src/util/crypto/crypto.h | 4 +- src/util/lists.c | 9 ---- src/util/lists.h | 1 - src/util/log.c | 4 +- src/util/message.c | 3 ++ src/util/strings.c | 43 ------------------- src/vortex.c | 3 +- 22 files changed, 22 insertions(+), 296 deletions(-) delete mode 100644 src/jsreport.c delete mode 100644 src/jsreport.h diff --git a/src/battle.c b/src/battle.c index f4d3a1fde..35092b79c 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3383,23 +3383,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) return fig; } -fighter * get_fighter(battle * b, const struct unit * u) -{ - side * s; - - for (s = b->sides; s != b->sides + b->nsides; ++s) { - fighter *fig; - if (s->faction == u->faction) { - for (fig = s->fighters; fig; fig = fig->next) { - if (fig->unit == u) { - return fig; - } - } - } - } - return 0; -} - int join_battle(battle * b, unit * u, bool attack, fighter ** cp) { side *s; diff --git a/src/battle.h b/src/battle.h index eb6335bce..1b0962eeb 100644 --- a/src/battle.h +++ b/src/battle.h @@ -213,7 +213,6 @@ extern "C" { /* BEGIN battle interface */ side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); side * get_side(battle * b, const struct unit * u); - fighter * get_fighter(battle * b, const struct unit * u); /* END battle interface */ void do_battles(void); diff --git a/src/bind_unit.c b/src/bind_unit.c index e061e510a..9bb595851 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -442,28 +442,6 @@ typedef struct event { char *msg; } event; -int fctr_handle(struct trigger *tp, void *data) -{ - trigger *t = tp; - event evt = { 0 }; - fctr_data *fd = (fctr_data *)t->data.v; - lua_State *L = (lua_State *)global.vm_state; - unit *u = fd->target; - - evt.args = (event_arg *)data; - lua_rawgeti(L, LUA_REGISTRYINDEX, fd->fhandle); - tolua_pushusertype(L, u, TOLUA_CAST "unit"); - tolua_pushusertype(L, &evt, TOLUA_CAST "event"); - if (lua_pcall(L, 2, 0, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("event (%s): %s\n", unitname(u), error); - lua_pop(L, 1); - tolua_error(L, TOLUA_CAST "event handler call failed", NULL); - } - - return 0; -} - static int tolua_unit_addnotice(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); diff --git a/src/eressea.c b/src/eressea.c index 8e7da7f7a..6efb1cb0b 100644 --- a/src/eressea.c +++ b/src/eressea.c @@ -28,6 +28,7 @@ #include "creport.h" #include "report.h" #include "names.h" +#include "prefix.h" #include "reports.h" #include "spells.h" #include "vortex.h" @@ -50,9 +51,10 @@ void game_done(void) calendar_cleanup(); free_functions(); free_config(); - free_special_directions(); free_locales(); #endif + free_prefixes(); + free_special_directions(); kernel_done(); swapdb_close(); } diff --git a/src/jsreport.c b/src/jsreport.c deleted file mode 100644 index a5c730438..000000000 --- a/src/jsreport.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "reports.h" -#include "jsreport.h" -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -static void coor_to_tiled(int *x, int *y) { - *y = -*y; - *x = *x - (*y + 1) / 2; -} - -static void coor_from_tiled(int *x, int *y) { - *x = *x + (*y + 1) / 2; - *y = -*y; -} - -static int report_json(const char *filename, report_context * ctx, const char *charset) -{ - if (config_get_int("jsreport.enabled", 0) != 0) { - FILE * F = fopen(filename, "w"); - if (F) { - int minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN; - seen_region *sr; - region *r; - /* traverse all regions */ - for (sr = NULL, r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->f->seen, r); - } - for (; sr != NULL; sr = sr->next) { - int tx = sr->r->x; - int ty = sr->r->y; - coor_to_tiled(&tx, &ty); - if (ty < miny) miny = ty; - else if (ty > maxy) maxy = ty; - if (tx < minx) minx = tx; - else if (tx > maxx) maxx = tx; - } - if (maxx >= minx && maxy >= miny) { - int y, w = maxx - minx + 1, h = maxy - miny + 1; - fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F); - fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w); - fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w); - fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F); - for (y = miny; y <= maxy; ++y) { - int x; - for (x = minx; x <= maxx; ++x) { - int data = 0; - int tx = x, ty = y; - coor_from_tiled(&tx, &ty); - r = findregion(tx, ty); - if (r) { - sr = find_seen(ctx->f->seen, r); - if (sr) { - terrain_t ter = oldterrain(r->terrain); - if (ter == NOTERRAIN) { - data = 1 + r->terrain->_name[0]; - } - else { - data = 1 + (int)ter; - } - } - } - fprintf(F, "%d", data); - if (x != maxx || y != maxy) fputs(", ", F); - } - } - fputs("]}], \"tilesets\": [{\"firstgid\": 1, \"image\": \"magellan.png\", \"imageheight\": 192, \"imagewidth\": 256," - "\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, " - "\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F); - } - fclose(F); - return 0; - } - return -1; - } - return 0; -} - -void register_jsreport(void) -{ - register_reporttype("json", &report_json, 1 << O_JSON); -} diff --git a/src/jsreport.h b/src/jsreport.h deleted file mode 100644 index fa3f7b115..000000000 --- a/src/jsreport.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -/* -+-------------------+ Christian Schlittchen -| | Enno Rehling -| Eressea PBEM host | Katja Zedel -| (c) 1998 - 2003 | Henning Peters -| | Ingo Wilken -+-------------------+ Stefan Reich - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ -#ifndef H_GC_JSREPORT -#define H_GC_JSREPORT -#ifdef __cplusplus -extern "C" { -#endif - - void register_jsreport(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/kernel/curse.c b/src/kernel/curse.c index bf3c8fef0..d6d77a7ea 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -672,16 +672,6 @@ bool curse_active(const curse * c) return true; } -bool is_cursed_internal(attrib * ap, const curse_type * ct) -{ - curse *c = get_curse(ap, ct); - - if (!c) - return false; - - return true; -} - bool is_cursed_with(const attrib * ap, const curse * c) { const attrib *a = ap; diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 700c4cfc5..61e4a591e 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -168,28 +168,6 @@ void set_show_item(faction * f, const struct item_type *itype) a->data.v = (void *)itype; } -const unit *random_unit_in_faction(const faction * f) -{ - unit *u; - int c = 0, u_nr; - - if (!f->units) { - return NULL; - } - for (u = f->units; u; u = u->next) - c++; - - u_nr = rng_int() % c; - c = 0; - - for (u = f->units; u; u = u->next) - if (u_nr == c) - return u; - - /* Hier sollte er nie ankommen */ - return NULL; -} - const char *factionname(const faction * f) { typedef char name[OBJECTIDSIZE + 1]; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 05790a865..438402286 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -117,7 +117,6 @@ extern "C" { int max_magicians(const faction * f); void set_show_item(faction * f, const struct item_type *itype); - const struct unit *random_unit_in_faction(const struct faction *f); const char *factionname(const struct faction *f); struct unit *addplayer(struct region *r, faction * f); struct faction *addfaction(const char *email, const char *password, diff --git a/src/kernel/race.c b/src/kernel/race.c index 6c5f0b626..4a0d0689f 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -240,15 +240,6 @@ race_list *get_familiarraces(void) return familiarraces; } -void racelist_clear(struct race_list **rl) -{ - while (*rl) { - race_list *rl2 = (*rl)->next; - free(*rl); - *rl = rl2; - } -} - void racelist_insert(struct race_list **rl, const struct race *r) { race_list *rl2 = (race_list *)malloc(sizeof(race_list)); diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index bec8fa8e8..f5041dc03 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -67,7 +67,6 @@ bool terrain_changed(int *cache) { return false; } - void free_terrains(void) { while (registered_terrains) { diff --git a/src/tests.c b/src/tests.c index 22c18ef9c..f6a87b396 100644 --- a/src/tests.c +++ b/src/tests.c @@ -1,6 +1,8 @@ #include #include "tests.h" #include "prefix.h" +#include "creport.h" +#include "report.h" #include "reports.h" #include "vortex.h" @@ -230,9 +232,12 @@ static void test_reset(void) { free_gamedata(); free_terrains(); free_resources(); + free_functions(); free_config(); default_locale = 0; calendar_cleanup(); + creport_cleanup(); + report_cleanup(); close_orders(); log_close(); stats_close(); @@ -245,29 +250,7 @@ static void test_reset(void) { free_spellbooks(); free_prefixes(); mt_clear(); -/* - for (i = 0; i != MAXTERRAINS; ++i) { - int flags = 0; - if (i == T_FIREWALL) { - flags |= FORBIDDEN_REGION; - } else { - flags = FLY_INTO | WALK_INTO; - if (i == T_OCEAN) { - flags |= SEA_REGION | SWIM_INTO; - } - else { - flags |= LAND_REGION; - if (i == T_PLAIN) { - flags |= CAVALRY_REGION | FOREST_REGION; - } - else if (i == T_GLACIER || i == T_ICEBERG || i == T_ICEBERG_SLEEP) { - flags |= ARCTIC_REGION; - } - } - } - test_create_terrain(terrainnames[i], flags); - } -*/ + for (i = 0; i != MAXSKILLS; ++i) { enable_skill(i, true); } diff --git a/src/util/base36.c b/src/util/base36.c index 3b5543e88..b1bef983d 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -125,13 +125,3 @@ const char *itoa10(int i) { return itoab(i, 10); } - -int i10toi36(int i) -{ - int r = 0; - while (i) { - r = r * 36 + i % 10; - i = i / 10; - } - return r; -} diff --git a/src/util/base36.h b/src/util/base36.h index 33f0d2f08..ef08094b2 100644 --- a/src/util/base36.h +++ b/src/util/base36.h @@ -25,14 +25,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + const char *itoa36(int i); + int atoi36(const char *s); + const char *itoa36_r(int i, char *result, size_t len); const char *itoab_r(int i, int base, char *result, size_t len); const char *itoab(int i, int base); - const char *itoa36(int i); const char *itoa10(int i); - extern int atoi36(const char *s); - extern int atoi10(const char *s); - int i10toi36(int i); #ifdef __cplusplus } diff --git a/src/util/crypto/crypto.c b/src/util/crypto/crypto.c index 75129a826..1e9a84f91 100644 --- a/src/util/crypto/crypto.c +++ b/src/util/crypto/crypto.c @@ -131,14 +131,14 @@ int bcrypt_gensalt(int factor, char salt[BCRYPT_HASHSIZE]) return (aux == NULL)?5:0; } -int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], char hash[BCRYPT_HASHSIZE]) +int bcrypt_hashpw(const char *passwd, const char salt[], char hash[BCRYPT_HASHSIZE]) { char *aux; aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE); return (aux == NULL)?1:0; } -int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE]) +int bcrypt_checkpw(const char *passwd, const char hash[]) { int ret; char outhash[BCRYPT_HASHSIZE]; diff --git a/src/util/crypto/crypto.h b/src/util/crypto/crypto.h index e45b3ca13..b7adc6137 100644 --- a/src/util/crypto/crypto.h +++ b/src/util/crypto/crypto.h @@ -45,7 +45,7 @@ int bcrypt_gensalt(int workfactor, char salt[BCRYPT_HASHSIZE]); * The return value is zero if the password could be hashed and nonzero * otherwise. */ -int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], +int bcrypt_hashpw(const char *passwd, const char salt[], char hash[BCRYPT_HASHSIZE]); /* @@ -57,7 +57,7 @@ int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], * passwords don't match. * */ -int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE]); +int bcrypt_checkpw(const char *passwd, const char hash[]); /* * Brief Example diff --git a/src/util/lists.c b/src/util/lists.c index 97e782795..710a3c4f1 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -80,15 +80,6 @@ void translist(void *l1, void *l2, void *p) addlist(l2, p); } -void removelist(void *l, void *p) -{ - - /* remove entry p from list l; free p */ - - choplist(l, p); - free(p); -} - void freelist(void *p1) { diff --git a/src/util/lists.h b/src/util/lists.h index 7fd0ca034..ac6c4a7eb 100644 --- a/src/util/lists.h +++ b/src/util/lists.h @@ -32,7 +32,6 @@ extern "C" { void addlist(void *l1, void *p1); void translist(void *l1, void *l2, void *p); void freelist(void *p1); - void removelist(void *l, void *p); unsigned int listlen(void *l); #ifdef __cplusplus diff --git a/src/util/log.c b/src/util/log.c index 26f745a3b..97f44bd95 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -325,10 +325,10 @@ int log_level(log_t * log, int flags) static critbit_tree stats = CRITBIT_TREE(); int stats_count(const char *stat, int delta) { - size_t len; - char data[128]; void * match; if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { + size_t len; + char data[128]; len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data); cb_insert(&stats, data, len); return delta; diff --git a/src/util/message.c b/src/util/message.c index fc645f3a2..6eb1b9a16 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -148,6 +148,9 @@ const char *section_add(const char *name) { } } assert(i < MAXSECTIONS); + if (i == MAXSECTIONS) { + return NULL; + } assert(sections[i] == NULL); if (i + 1 < MAXSECTIONS) { sections[i + 1] = NULL; diff --git a/src/util/strings.c b/src/util/strings.c index ef3c3a575..7f6cad26c 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -177,49 +177,6 @@ int str_hash(const char *s) return key & 0x7FFFFFFF; } -const char *str_escape_wrong(const char *str, char *buffer, size_t len) -{ - const char *handle_start = strchr(str, '\"'); - if (!handle_start) handle_start = strchr(str, '\\'); - assert(buffer); - if (handle_start) { - const char *p = str; - char *o = buffer; - size_t skip = handle_start - str; - - if (skip > len) { - skip = len; - } - if (skip > 0) { - memcpy(buffer, str, skip); - o += skip; - p += skip; - len -= skip; - } - do { - if (*p == '\"' || *p == '\\') { - if (len < 2) { - break; - } - (*o++) = '\\'; - len -= 2; - } - else { - if (len < 1) { - break; - } - --len; - } - if (len > 0) { - (*o++) = (*p); - } - } while (len > 0 && *p++); - *o = '\0'; - return buffer; - } - return str; -} - unsigned int jenkins_hash(unsigned int a) { a = (a + 0x7ed55d16) + (a << 12); diff --git a/src/vortex.c b/src/vortex.c index c743ad857..36945ca3f 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -129,13 +129,12 @@ attrib_type at_direction = { region *find_special_direction(const region * r, const char *token) { attrib *a; - spec_direction *d; if (strlen(token) == 0) return NULL; for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { - d = (spec_direction *)(a->data.v); + spec_direction *d = (spec_direction *)(a->data.v); if (d->active && strcmp(token, d->keyword) == 0) { return findregion(d->x, d->y); From 933914a3015e47e69ea06b5a59fa48b4ab61b1c3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Dec 2018 05:10:39 +0100 Subject: [PATCH 28/85] re-enable disabled test. --- src/bind_unit.c | 5 ----- src/kernel/messages.test.c | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bind_unit.c b/src/bind_unit.c index 9bb595851..6204dc3d9 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -432,11 +432,6 @@ static int tolua_unit_effskill(lua_State * L) return 1; } -typedef struct fctr_data { - unit *target; - int fhandle; -} fctr_data; - typedef struct event { struct event_arg *args; char *msg; diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index c186973fa..707eb8e7e 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -2,6 +2,7 @@ #include "messages.h" #include "unit.h" +#include "faction.h" #include "order.h" #include @@ -25,10 +26,13 @@ void test_missing_message(CuTest *tc) { void test_missing_feedback(CuTest *tc) { message *msg; + unit *u; test_setup(); + u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u->thisorder = create_order(K_ENTERTAIN, u->faction->locale, NULL); message_handle_missing(MESSAGE_MISSING_REPLACE); - msg = msg_error(NULL, NULL, 77); + msg = msg_error(u, NULL, 77); CuAssertPtrNotNull(tc, msg); CuAssertPtrNotNull(tc, msg->type); CuAssertStrEquals(tc, msg->type->name, "missing_feedback"); @@ -113,6 +117,7 @@ static void test_noerror(CuTest *tc) { CuSuite *get_messages_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_missing_message); + SUITE_ADD_TEST(suite, test_missing_feedback); SUITE_ADD_TEST(suite, test_merge_split); SUITE_ADD_TEST(suite, test_message); SUITE_ADD_TEST(suite, test_noerror); From 0a5cf3442069dcff4d5ef0d6253d4bb42e066d61 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Dec 2018 05:05:37 +0100 Subject: [PATCH 29/85] ignore cppcheck configurations, but not tests --- s/cppcheck | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/s/cppcheck b/s/cppcheck index e38e86de1..e52aa7d5c 100755 --- a/s/cppcheck +++ b/s/cppcheck @@ -1,8 +1,8 @@ #!/bin/sh IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }') -cppcheck $IGNORE -isrc/tests.c \ - --quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ - -UERESSEA_BUILDNO -UERESSEA_VERSION \ +#cppcheck $IGNORE -isrc/tests.c \ +cppcheck --quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ + -UERESSEA_BUILDNO -UERESSEA_VERSION -UTEST_THREADS \ -IcJSON -Isrc -Iclibs -Istorage src From cb7d2e9fcbe12fc9215d5b19bcd11b3c7f13d0d1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Dec 2018 11:07:30 +0100 Subject: [PATCH 30/85] fewer warnings from cppcheck --- s/cppcheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/cppcheck b/s/cppcheck index e52aa7d5c..25191de66 100755 --- a/s/cppcheck +++ b/s/cppcheck @@ -2,7 +2,7 @@ IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }') #cppcheck $IGNORE -isrc/tests.c \ -cppcheck --quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \ +cppcheck --quiet --enable=warning,style,performance,portability -U_MSC_VER -UCLEANUP_CODE -UTODO \ -UERESSEA_BUILDNO -UERESSEA_VERSION -UTEST_THREADS \ -IcJSON -Isrc -Iclibs -Istorage src From 83556f80103697b865c1c04eadaa97ed50e621d8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Dec 2018 11:13:58 +0100 Subject: [PATCH 31/85] cppcheck style --- src/attributes/key.c | 4 ++-- src/attributes/seenspell.c | 3 +-- src/automate.c | 4 ++-- src/bind_unit.c | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/attributes/key.c b/src/attributes/key.c index cd369de66..66af66b89 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -121,7 +121,7 @@ static int read_keyval_orig(gamedata *data, int *keys, int n) { #endif static int a_readkeys(variant *var, void *owner, gamedata *data) { - int i, n, ksn, *keys; + int n, ksn, *keys; READ_INT(data->store, &n); assert(n < 4096 && n >= 0); @@ -155,7 +155,7 @@ static int a_readkeys(variant *var, void *owner, gamedata *data) { } keys[0] = n; if (data->version < SORTKEYS_VERSION) { - int e = 1; + int i, e = 1; for (i = 1; i != n; ++i) { int k = keys[i * 2 + 1]; int v = keys[i * 2 + 2]; diff --git a/src/attributes/seenspell.c b/src/attributes/seenspell.c index ae46980c3..082eecc6b 100644 --- a/src/attributes/seenspell.c +++ b/src/attributes/seenspell.c @@ -48,13 +48,12 @@ static int read_seenspells(variant *var, void *owner, struct gamedata *data) { selist *ql = NULL; storage *store = data->store; - spell *sp = 0; char token[32]; UNUSED_ARG(owner); READ_TOK(store, token, sizeof(token)); while (token[0]) { - sp = find_spell(token); + spell *sp = find_spell(token); if (!sp) { log_info("read_seenspells: could not find spell '%s'\n", token); return AT_READ_FAIL; diff --git a/src/automate.c b/src/automate.c index 4332dc8e8..b47121183 100644 --- a/src/automate.c +++ b/src/automate.c @@ -82,7 +82,7 @@ void autostudy_run(scholar scholars[], int nscholars) int ti = 0; while (ti != nscholars) { skill_t sk = scholars[ti].sk; - int t, s, se, ts = 0, tt = 0, si = ti; + int t, se, ts = 0, tt = 0, si = ti; for (se = ti; se != nscholars && scholars[se].sk == sk; ++se) { int mint; ts += scholars[se].u->number; /* count total scholars */ @@ -108,7 +108,7 @@ void autostudy_run(scholar scholars[], int nscholars) } else { /* invariant: unit ti can still teach i students */ - int i = scholars[ti].u->number * STUDENTS_PER_TEACHER; + int s, i = scholars[ti].u->number * STUDENTS_PER_TEACHER; /* invariant: unit si has n students that can still be taught */ int n = scholars[si].u->number; for (t = ti, s = si; t != si && s != se; ) { diff --git a/src/bind_unit.c b/src/bind_unit.c index 6204dc3d9..d75323f0b 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -22,7 +22,6 @@ #include "kernel/skills.h" #include "kernel/types.h" #include -#include #include #include "kernel/equipment.h" #include From 45c44a03fb8426d6ac8b5b1b9089ae66351990af Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 4 Dec 2018 21:10:07 +0100 Subject: [PATCH 32/85] some static analysis warnings (cppcheck and msvc). --- src/automate.c | 2 +- src/battle.c | 64 ++++++++++++++++++++++----------------------- src/battle.test.c | 10 +++++++ src/kernel/config.c | 27 +++++++++++-------- src/kernel/config.h | 2 +- src/kernel/item.c | 13 +++++---- 6 files changed, 67 insertions(+), 51 deletions(-) diff --git a/src/automate.c b/src/automate.c index b47121183..e79bc4fdc 100644 --- a/src/automate.c +++ b/src/automate.c @@ -110,7 +110,7 @@ void autostudy_run(scholar scholars[], int nscholars) /* invariant: unit ti can still teach i students */ int s, i = scholars[ti].u->number * STUDENTS_PER_TEACHER; /* invariant: unit si has n students that can still be taught */ - int n = scholars[si].u->number; + int s, n = scholars[si].u->number; for (t = ti, s = si; t != si && s != se; ) { if (i >= n) { /* t has more than enough teaching capacity for s */ diff --git a/src/battle.c b/src/battle.c index 35092b79c..f65a8d5d2 100644 --- a/src/battle.c +++ b/src/battle.c @@ -697,23 +697,20 @@ static int CavalryBonus(const unit * u, troop enemy, int type) return 0; } +/** + * Effektiver Waffenskill waehrend des Kampfes. + */ static int -weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking, -bool missile) -/* effektiver Waffenskill w�hrend des Kampfes */ +weapon_effskill(troop t, troop enemy, const weapon * w, + bool attacking, bool missile) { - /* In dieser Runde alle die Modifier berechnen, die fig durch die - * Waffen bekommt. */ fighter *tf = t.fighter; unit *tu = t.fighter->unit; - int skill; - const weapon_type *wtype = w ? w->type : NULL; + /* Alle Modifier berechnen, die fig durch die Waffen bekommt. */ + if (w) { + int skill = 0; + const weapon_type *wtype = w->type; - if (wtype == NULL) { - /* Ohne Waffe: Waffenlose Angriffe */ - skill = weapon_skill(NULL, tu, attacking); - } - else { if (attacking) { skill = w->attackskill; } @@ -745,30 +742,31 @@ bool missile) } } } - } + /* Burgenbonus, Pferdebonus */ + if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS) + && !fval(wtype, WTF_MISSILE)))) { + skill += CavalryBonus(tu, enemy, BONUS_SKILL); + } - /* Burgenbonus, Pferdebonus */ - if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS) - && !fval(wtype, WTF_MISSILE)))) { - skill += CavalryBonus(tu, enemy, BONUS_SKILL); - } + if (t.index < tf->elvenhorses) { + /* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist + * eleganter, und vor allem einfacher, sonst mu� man noch ein + * WMF_ELVENHORSE einbauen. */ + skill += 2; + } - if (t.index < tf->elvenhorses) { - /* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist - * eleganter, und vor allem einfacher, sonst mu� man noch ein - * WMF_ELVENHORSE einbauen. */ - skill += 2; + if (skill > 0 && !attacking && missile) { + /* + * Wenn ich verteidige, und nicht direkt meinem Feind gegen�berstehe, + * halbiert sich mein Skill: (z.B. gegen Fernk�mpfer. Nahk�mpfer + * k�nnen mich eh nicht treffen) + */ + skill /= 2; + } + return skill; } - - if (skill > 0 && !attacking && missile) { - /* - * Wenn ich verteidige, und nicht direkt meinem Feind gegen�berstehe, - * halbiert sich mein Skill: (z.B. gegen Fernk�mpfer. Nahk�mpfer - * k�nnen mich eh nicht treffen) - */ - skill /= 2; - } - return skill; + /* no weapon: fight weaponless */ + return weapon_skill(NULL, tu, attacking); } const armor_type *select_armor(troop t, bool shield) diff --git a/src/battle.test.c b/src/battle.test.c index 92a26e692..be43a8ff6 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -123,6 +123,16 @@ static void test_select_weapon_restricted(CuTest *tc) { CuAssertIntEquals(tc, 0, af->weapons[0].count); free_battle(b); + itype->mask_deny = 0; + itype->mask_allow = rc_mask(au->_race); + b = make_battle(au->region); + af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false); + CuAssertPtrNotNull(tc, af->weapons); + CuAssertIntEquals(tc, 1, af->weapons[0].count); + CuAssertPtrEquals(tc, itype->rtype->wtype, (void *)af->weapons[0].type); + CuAssertIntEquals(tc, 0, af->weapons[1].count); + free_battle(b); + itype->mask_deny = 0; itype->mask_allow = rc_mask(rc); b = make_battle(au->region); diff --git a/src/kernel/config.c b/src/kernel/config.c index 15387dca7..73b4aa22e 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -106,27 +106,31 @@ int findoption(const char *s, const struct locale *lang) /* -- Erschaffung neuer Einheiten ------------------------------ */ -static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; static int *forbidden_ids; -int forbiddenid(int id) +bool forbiddenid(int id) { + static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; static size_t len; size_t i; - if (id <= 0) - return 1; + if (id <= 0) { + return true; + } if (!forbidden_ids) { while (forbidden[len]) ++len; - forbidden_ids = calloc(len, sizeof(int)); + forbidden_ids = malloc(len * sizeof(int)); + if (!forbidden_ids) abort(); for (i = 0; i != len; ++i) { forbidden_ids[i] = atoi36(forbidden[i]); } } - for (i = 0; i != len; ++i) - if (id == forbidden_ids[i]) - return 1; - return 0; + for (i = 0; i != len; ++i) { + if (id == forbidden_ids[i]) { + return true; + } + } + return false; } int newcontainerid(void) @@ -274,6 +278,7 @@ void set_param(struct param **p, const char *key, const char *value) par = *p; if (!par && value) { *p = par = calloc(1, sizeof(param)); + if (!par) abort(); } if (par) { void *match; @@ -509,7 +514,6 @@ order *default_order(const struct locale *lang) int i = locale_index(lang); keyword_t kwd; const char * str; - order *result = 0; assert(i < MAXLOCALES); kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK; @@ -518,7 +522,8 @@ order *default_order(const struct locale *lang) kwd = findkeyword(str); } if (kwd != NOKEYWORD) { - result = create_order(kwd, lang, NULL); + /* TODO: why is there a copy_order made here? */ + order *result = create_order(kwd, lang, NULL); return copy_order(result); } return NULL; diff --git a/src/kernel/config.h b/src/kernel/config.h index 7789cd36d..83241ac4c 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -52,7 +52,7 @@ extern "C" { void init_locale(struct locale *lang); void init_races(struct locale *lang); - int forbiddenid(int id); + bool forbiddenid(int id); int newcontainerid(void); bool rule_region_owners(void); diff --git a/src/kernel/item.c b/src/kernel/item.c index 58702be07..a58df472c 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -194,12 +194,10 @@ resource_type *rt_get_or_create(const char *name) { if (!rtype) { rtype = calloc(1, sizeof(resource_type)); if (!rtype) { - perror("resource_type allocation failed"); - } - else { - rtype->_name = str_strdup(name); - rt_register(rtype); + abort(); } + rtype->_name = str_strdup(name); + rt_register(rtype); } return rtype; } @@ -247,6 +245,7 @@ item_type *it_get_or_create(resource_type *rtype) { if (!rtype->itype) { item_type * itype; itype = (item_type *)calloc(sizeof(item_type), 1); + if (!itype) abort(); itype->rtype = rtype; rtype->uchange = res_changeitem; rtype->itype = itype; @@ -269,6 +268,7 @@ luxury_type *new_luxurytype(item_type * itype, int price) assert(resource2luxury(itype->rtype) == NULL); ltype = calloc(sizeof(luxury_type), 1); + if (!ltype) abort(); ltype->itype = itype; ltype->price = price; lt_register(ltype); @@ -285,6 +285,7 @@ weapon_type *new_weapontype(item_type * itype, assert(itype && (!itype->rtype || !resource2weapon(itype->rtype))); wtype = calloc(sizeof(weapon_type), 1); + if (!wtype) abort(); if (damage) { wtype->damage[0] = str_strdup(damage[0]); wtype->damage[1] = str_strdup(damage[1]); @@ -309,6 +310,7 @@ armor_type *new_armortype(item_type * itype, double penalty, variant magres, assert(itype->rtype->atype == NULL); atype = calloc(sizeof(armor_type), 1); + if (!atype) abort(); atype->itype = itype; atype->penalty = penalty; @@ -530,6 +532,7 @@ item *i_new(const item_type * itype, int size) } else { i = malloc(sizeof(item)); + if (!i) abort(); } assert(itype); i->next = NULL; From 11c21d035aaadfb39c1fc25b01d015ccd262534a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 4 Dec 2018 21:16:47 +0100 Subject: [PATCH 33/85] fix dupe declaration merge snafu --- src/automate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/automate.c b/src/automate.c index e79bc4fdc..7fd0c5d62 100644 --- a/src/automate.c +++ b/src/automate.c @@ -108,7 +108,7 @@ void autostudy_run(scholar scholars[], int nscholars) } else { /* invariant: unit ti can still teach i students */ - int s, i = scholars[ti].u->number * STUDENTS_PER_TEACHER; + int i = scholars[ti].u->number * STUDENTS_PER_TEACHER; /* invariant: unit si has n students that can still be taught */ int s, n = scholars[si].u->number; for (t = ti, s = si; t != si && s != se; ) { From d0577a5d6a727fa28af48941ee03c1318417fa9d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Dec 2018 03:42:08 +0100 Subject: [PATCH 34/85] cppcheck style warnings: reduce variable scope --- src/creport.c | 2 +- src/economy.c | 3 +-- src/exparse.c | 24 ++++++++++++--------- src/give.c | 1 - src/jsonconf.c | 4 +++- src/kernel/attrib.c | 10 ++++----- src/kernel/order.c | 3 +-- src/kernel/resources.c | 4 +--- src/kernel/save.c | 45 ++++++++++++++++++++------------------- src/kernel/unit.c | 6 ++---- src/laws.c | 2 +- src/magic.c | 8 +++---- src/main.c | 2 +- src/skill.c | 2 +- src/spells/combatspells.c | 5 ++--- src/spy.c | 3 +-- src/summary.c | 3 ++- src/tools/gethash.c | 36 ++++++++++++++++--------------- src/util/keyword.c | 2 +- src/util/mt19937ar.c | 4 ++-- src/util/rng.test.c | 18 ++++++---------- 21 files changed, 91 insertions(+), 96 deletions(-) diff --git a/src/creport.c b/src/creport.c index 9d4e33728..33401bc8f 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1157,7 +1157,7 @@ static char *cr_output_resource(char *buf, const resource_type *rtype, assert(rtype); name = resourcename(rtype, NMF_PLURAL); assert(name); - buf += sprintf(buf, "RESOURCE %u\n", str_hash(rtype->_name)); + buf += sprintf(buf, "RESOURCE %d\n", str_hash(rtype->_name)); tname = LOC(loc, name); assert(tname); tname = translate(name, tname); diff --git a/src/economy.c b/src/economy.c index 271a8a26e..7a13b4c34 100644 --- a/src/economy.c +++ b/src/economy.c @@ -2239,7 +2239,6 @@ static void breed_cmd(unit * u, struct order *ord) const char *s; param_t p; region *r = u->region; - const resource_type *rtype = NULL; if (r->land == NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", "")); @@ -2275,7 +2274,7 @@ static void breed_cmd(unit * u, struct order *ord) break; default: if (p != P_ANY) { - rtype = findresourcetype(s, u->faction->locale); + const resource_type *rtype = findresourcetype(s, u->faction->locale); if (rtype == get_resourcetype(R_SEED) || rtype == get_resourcetype(R_MALLORN_SEED)) { breedtrees(u, m); break; diff --git a/src/exparse.c b/src/exparse.c index 71efe0667..602bdf4e9 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -874,7 +874,6 @@ static void start_resources(parseinfo *pi, const XML_Char *el, const XML_Char ** } static void start_ships(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { - const char *flag_names[] = { "opensea", "fly", "nocoast", "speedy", NULL }; if (xml_strequal(el, "ship")) { const XML_Char *name; @@ -917,10 +916,13 @@ static void start_ships(parseinfo *pi, const XML_Char *el, const XML_Char **attr else if (xml_strequal(attr[i], "storm")) { stype->storm = xml_float(attr[i + 1]); } - else if (!handle_flag(&flags, attr + i, flag_names)) { - /* we already handled the name earlier */ - if (!xml_strequal(attr[i], "name")) { - handle_bad_input(pi, el, attr[i]); + else { + const char *flag_names[] = { "opensea", "fly", "nocoast", "speedy", NULL }; + if (!handle_flag(&flags, attr + i, flag_names)) { + /* we already handled the name earlier */ + if (!xml_strequal(attr[i], "name")) { + handle_bad_input(pi, el, attr[i]); + } } } } @@ -1209,7 +1211,6 @@ static void start_races(parseinfo *pi, const XML_Char *el, const XML_Char **attr } static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { - const char *flag_names[] = { "nodestroy", "nobuild", "unique", "decay", "magic", "namechange", "fort", "oneperturn", NULL }; if (xml_strequal(el, "building")) { const XML_Char *name; @@ -1245,10 +1246,13 @@ static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char ** /* magres is specified in percent! */ btype->magres = frac_make(xml_int(attr[i + 1]), 100); } - else if (!handle_flag(&flags, attr + i, flag_names)) { - /* we already handled the name earlier */ - if (!xml_strequal(attr[i], "name")) { - handle_bad_input(pi, el, attr[i]); + else { + const char *flag_names[] = { "nodestroy", "nobuild", "unique", "decay", "magic", "namechange", "fort", "oneperturn", NULL }; + if (!handle_flag(&flags, attr + i, flag_names)) { + /* we already handled the name earlier */ + if (!xml_strequal(attr[i], "name")) { + handle_bad_input(pi, el, attr[i]); + } } } } diff --git a/src/give.c b/src/give.c index 60b728479..90ed64f50 100644 --- a/src/give.c +++ b/src/give.c @@ -169,7 +169,6 @@ int give_quota(const unit * src, const unit * dst, const item_type * type, if (config_changed(&config)) { divisor = config_get_int("rules.items.give_divisor", divisor); } - assert(divisor <= 0 || divisor >= 1); if (divisor >= 1) { /* predictable > correct: */ return n / divisor; diff --git a/src/jsonconf.c b/src/jsonconf.c index ff442f990..48be28b16 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -1032,12 +1032,14 @@ static int add_po_string(const char *msgid, const char *msgstr, const char *msgc } static int include_po(const char *uri) { - char name[PATH_MAX], lname[8]; + char name[PATH_MAX]; const char *filename = uri_to_file(uri, name, sizeof(name)); const char *pos = strstr(filename, ".po"); if (pos) { size_t len; const char *str = --pos; + char lname[8]; + while (str > filename && *str != '.') --str; len = (size_t)(pos - str); if (len < sizeof(lname)) { diff --git a/src/kernel/attrib.c b/src/kernel/attrib.c index d84a8c8e9..997a04151 100644 --- a/src/kernel/attrib.c +++ b/src/kernel/attrib.c @@ -185,15 +185,15 @@ void at_register(attrib_type * at) static attrib_type *at_find_key(unsigned int hk) { - const char *translate[3][2] = { - { "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */ - { "verzaubert", "curse" }, /* remapping: früher verzaubert, jetzt curse */ - { NULL, NULL } - }; attrib_type *find = at_hash[hk % MAXATHASH]; while (find && hk != find->hashkey) find = find->nexthash; if (!find) { + const char *translate[3][2] = { + { "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */ + { "verzaubert", "curse" }, /* remapping: früher verzaubert, jetzt curse */ + { NULL, NULL } + }; int i = 0; while (translate[i][0]) { if (__at_hashkey(translate[i][0]) == hk) diff --git a/src/kernel/order.c b/src/kernel/order.c index 6b81f7dcf..b4467fa5b 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -170,7 +170,6 @@ const char *crescape(const char *str, char *buffer, size_t size) { int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape) { const char *text; - order_data *od = NULL; keyword_t kwd = ORD_KEYWORD(ord); if (ord->command & CMD_QUIET) { @@ -203,7 +202,7 @@ int stream_order(struct stream *out, const struct order *ord, const struct local } } else { - od = odata_load(ord->id); + order_data *od = odata_load(ord->id); text = OD_STRING(od); if (text) { char obuf[1024]; diff --git a/src/kernel/resources.c b/src/kernel/resources.c index 4bb27616d..b5741236b 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -181,10 +181,8 @@ struct rawmaterial_type *rmt_get(const struct resource_type *rtype) struct rawmaterial_type *rmt_create(struct resource_type *rtype) { - rawmaterial_type *rmtype; - if (!rtype->raw) { - rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); + rawmaterial_type *rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); rmtype->rtype = rtype; rmtype->terraform = terraform_default; rmtype->update = NULL; diff --git a/src/kernel/save.c b/src/kernel/save.c index c6d3bd497..f6ce25327 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -272,12 +272,11 @@ static void read_owner(gamedata *data, region_owner ** powner) static void write_owner(gamedata *data, region_owner * owner) { if (owner) { - faction *f; WRITE_INT(data->store, owner->since_turn); if (owner->since_turn >= 0) { + faction *f = owner->last_owner; WRITE_INT(data->store, owner->morale_turn); WRITE_INT(data->store, owner->flags); - f = owner->last_owner; write_faction_reference((f && f->_alive) ? f : NULL, data->store); f = owner->owner; write_faction_reference((f && f->_alive) ? f : NULL, data->store); @@ -887,12 +886,12 @@ int get_spell_level_faction(const spell * sp, void * cbdata) } static char * getpasswd(int fno) { - const char *prefix = itoa36(fno); - size_t len = strlen(prefix); FILE * F = fopen("passwords.txt", "r"); - char line[80]; if (F) { + const char *prefix = itoa36(fno); + size_t len = strlen(prefix); while (!feof(F)) { + char line[80]; fgets(line, sizeof(line), F); if (line[len] == ':' && strncmp(prefix, line, len) == 0) { size_t slen = strlen(line) - 1; @@ -1147,7 +1146,7 @@ static int cb_sb_maxlevel(spellbook_entry *sbe, void *cbdata) { int readgame(const char *filename) { - int n, stream_version; + int n = -2, stream_version; char path[PATH_MAX]; gamedata gdata = { 0 }; storage store; @@ -1164,23 +1163,25 @@ int readgame(const char *filename) return -1; } sz = fread(&gdata.version, sizeof(int), 1, F); - sz = fread(&stream_version, sizeof(int), 1, F); - assert((sz == 1 && stream_version == STREAM_VERSION) || !"unsupported data format"); - assert(gdata.version >= MIN_VERSION || !"unsupported data format"); - assert(gdata.version <= MAX_VERSION || !"unsupported data format"); + if (sz == 1) { + sz = fread(&stream_version, sizeof(int), 1, F); + assert((sz == 1 && stream_version == STREAM_VERSION) || !"unsupported data format"); + assert(gdata.version >= MIN_VERSION || !"unsupported data format"); + assert(gdata.version <= MAX_VERSION || !"unsupported data format"); - fstream_init(&strm, F); - binstore_init(&store, &strm); - gdata.store = &store; + fstream_init(&strm, F); + binstore_init(&store, &strm); + gdata.store = &store; - if (gdata.version >= BUILDNO_VERSION) { - int build; - READ_INT(&store, &build); - log_debug("data in %s created with build %d.", filename, build); + if (gdata.version >= BUILDNO_VERSION) { + int build; + READ_INT(&store, &build); + log_debug("data in %s created with build %d.", filename, build); + } + n = read_game(&gdata); + binstore_done(&store); + fstream_done(&strm); } - n = read_game(&gdata); - binstore_done(&store); - fstream_done(&strm); return n; } @@ -1350,8 +1351,6 @@ int read_game(gamedata *data) int p, nread; faction *f, **fp; region *r; - building **bp; - ship **shp; unit *u; storage * store = data->store; const struct building_type *bt_lighthouse = bt_find("lighthouse"); @@ -1407,6 +1406,8 @@ int read_game(gamedata *data) while (--nread >= 0) { unit **up; + building **bp; + ship **shp; r = read_region(data); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 748c76003..bf2ad7a37 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -776,7 +776,6 @@ void clone_men(const unit * u, unit * dst, int n) /* "hat attackiert"-status wird uebergeben */ if (dst) { - skill *sv, *sn; skill_t sk; ship *sh; @@ -784,9 +783,8 @@ void clone_men(const unit * u, unit * dst, int n) for (sk = 0; sk != MAXSKILLS; ++sk) { int weeks, level = 0; - - sv = unit_skill(u, sk); - sn = unit_skill(dst, sk); + skill *sv = unit_skill(u, sk); + skill *sn = unit_skill(dst, sk); if (sv == NULL && sn == NULL) continue; diff --git a/src/laws.c b/src/laws.c index 11f9d891b..cb05f9d5f 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3399,8 +3399,8 @@ int pay_cmd(unit * u, struct order *ord) static int reserve_i(unit * u, struct order *ord, int flags) { - char token[128]; if (u->number > 0) { + char token[128]; int use, count, para; const item_type *itype; const char *s; diff --git a/src/magic.c b/src/magic.c index d8568b8cc..49ba3915e 100644 --- a/src/magic.c +++ b/src/magic.c @@ -1334,7 +1334,6 @@ static void do_fumble(castorder * co) int level = co->level; int duration; double effect; - static const race *rc_toad; static int rc_cache; fumble_f fun; @@ -1359,6 +1358,7 @@ static void do_fumble(castorder * co) * The list of things to happen are attached to a timeout * trigger and that's added to the triggerlit of the mage gone toad. */ + static const race *rc_toad; trigger *trestore = trigger_changerace(mage, u_race(mage), mage->irace); if (chance(0.7)) { const resource_type *rtype = rt_find("toadslime"); @@ -2119,10 +2119,9 @@ void add_castorder(spellrank * cll, castorder * co) void free_castorders(castorder * co) { - castorder *co2; while (co) { - co2 = co; + castorder *co2 = co; co = co->next; free_castorder(co2); free(co2); @@ -2202,15 +2201,14 @@ void remove_familiar(unit * mage) { attrib *a = a_find(mage->attribs, &at_familiar); attrib *an; - skillmod_data *smd; if (a != NULL) { a_remove(&mage->attribs, a); } a = a_find(mage->attribs, &at_skillmod); while (a && a->type == &at_skillmod) { + skillmod_data *smd = (skillmod_data *)a->data.v; an = a->next; - smd = (skillmod_data *)a->data.v; if (smd->special == sm_familiar) { a_remove(&mage->attribs, a); } diff --git a/src/main.c b/src/main.c index 0dec070ce..bd5a92b46 100644 --- a/src/main.c +++ b/src/main.c @@ -108,11 +108,11 @@ static const char * valid_keys[] = { static dictionary *parse_config(const char *filename) { - char path[PATH_MAX]; dictionary *d; const char *str, *cfgpath = config_get("config.path"); if (cfgpath) { + char path[PATH_MAX]; path_join(cfgpath, filename, path, sizeof(path)); log_debug("reading from configuration file %s\n", path); d = iniparser_load(path); diff --git a/src/skill.c b/src/skill.c index abeecca04..41656f0ff 100644 --- a/src/skill.c +++ b/src/skill.c @@ -94,9 +94,9 @@ skill_t findskill(const char *name) skill_t get_skill(const char *s, const struct locale * lang) { skill_t result = NOSKILL; - char buffer[64]; if (s) { + char buffer[64]; char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s); if (str) { int i; diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 21b33e7bf..296d88563 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -357,8 +357,6 @@ int sp_sleep(struct castorder * co) const spell * sp = co->sp; battle *b = fi->side->battle; unit *mage = fi->unit; - unit *du; - troop dt; int force, enemies; int k = 0; message *m; @@ -374,7 +372,8 @@ int sp_sleep(struct castorder * co) return 0; } while (force && enemies) { - dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); + unit *du; + troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); assert(dt.fighter); du = dt.fighter->unit; if (!is_magic_resistant(mage, du, 0)) { diff --git a/src/spy.c b/src/spy.c index 8ade569c6..75a1e5c6a 100644 --- a/src/spy.c +++ b/src/spy.c @@ -217,7 +217,6 @@ int setstealth_cmd(unit * u, struct order *ord) { char token[64]; const char *s; - int level; init_order_depr(ord); s = gettoken(token, sizeof(token)); @@ -231,7 +230,7 @@ int setstealth_cmd(unit * u, struct order *ord) if (isdigit(*(const unsigned char *)s)) { /* Tarnungslevel setzen */ - level = atoi((const char *)s); + int level = atoi((const char *)s); if (level > effskill(u, SK_STEALTH, NULL)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_lowstealth", "")); return 0; diff --git a/src/summary.c b/src/summary.c index 64bb055b5..e01679d56 100644 --- a/src/summary.c +++ b/src/summary.c @@ -77,11 +77,12 @@ int *nmrs = NULL; int update_nmrs(void) { - int i, newplayers = 0; + int newplayers = 0; faction *f; int timeout = NMRTimeout(); if (timeout>0) { + int i; if (nmrs == NULL) { nmrs = malloc(sizeof(int) * (timeout + 1)); } diff --git a/src/tools/gethash.c b/src/tools/gethash.c index 75054b11e..f4385a495 100644 --- a/src/tools/gethash.c +++ b/src/tools/gethash.c @@ -4,21 +4,23 @@ int main(int argc, char **argv) { - char key[4]; - char code[4]; - char result[4]; - int a, i, rot; - for (a = 1; a < argc; ++a) { - const char *str = argv[a]; - size_t len = strlen(str); - str = str + len - 6; - memcpy(key, str, 3); - memcpy(code, str + 3, 3); - result[3] = key[3] = code[3] = 0; - rot = atoi(key); - for (i = 0; i != 3; ++i) - result[(i + rot) % 3] = ((code[i] + 10 - key[i]) % 10) + '0'; - printf("%s %s\n", argv[a], result); - } - return 0; + char key[4]; + char code[4]; + char result[4]; + int a; + for (a = 1; a < argc; ++a) { + int rot, i; + const char *str = argv[a]; + size_t len = strlen(str); + str = str + len - 6; + memcpy(key, str, 3); + memcpy(code, str + 3, 3); + result[3] = key[3] = code[3] = 0; + rot = atoi(key); + for (i = 0; i != 3; ++i) { + result[(i + rot) % 3] = ((code[i] + 10 - key[i]) % 10) + '0'; + } + printf("%s %s\n", argv[a], result); + } + return 0; } diff --git a/src/util/keyword.c b/src/util/keyword.c index 0d9a11dc4..9d5ba1e6a 100644 --- a/src/util/keyword.c +++ b/src/util/keyword.c @@ -52,13 +52,13 @@ keyword_t findkeyword(const char *s) { keyword_t get_keyword(const char *s, const struct locale *lang) { keyword_t result = NOKEYWORD; - char buffer[64]; assert(lang); assert(s); while (*s == '@') ++s; if (*s) { + char buffer[64]; char *str = transliterate(buffer, sizeof(buffer) - sizeof(int), s); if (str) { diff --git a/src/util/mt19937ar.c b/src/util/mt19937ar.c index 0dda925ca..ad58d2ca8 100644 --- a/src/util/mt19937ar.c +++ b/src/util/mt19937ar.c @@ -100,10 +100,10 @@ void init_by_array(unsigned long init_key[], int key_length) unsigned long genrand_int32(void) { unsigned long y; - static unsigned long mag01[2]={0x0UL, MATRIX_A}; - /* mag01[x] = x * MATRIX_A for x=0,1 */ if (mti >= N) { /* generate N words at one time */ + static unsigned long mag01[2] = { 0x0UL, MATRIX_A }; + /* mag01[x] = x * MATRIX_A for x=0,1 */ int kk; if (mti == N+1) /* if init_genrand() has not been called, */ diff --git a/src/util/rng.test.c b/src/util/rng.test.c index 34e530c5e..6ab8719a1 100644 --- a/src/util/rng.test.c +++ b/src/util/rng.test.c @@ -8,17 +8,13 @@ static void test_rng_round(CuTest * tc) { - double f; - int i, r; - for (i = 0; i < 1000; ++i) { - f = rng_double(); - r = RAND_ROUND(f); - CuAssertTrue(tc, f >= 0); - CuAssertTrue(tc, r <= (int)f + 1); - CuAssertTrue(tc, r >= (int)f); - CuAssertTrue(tc, r == (int)r); - CuAssertTrue(tc, r == RAND_ROUND(r)); - } + double f = rng_double(); + int r = RAND_ROUND(f); + CuAssertTrue(tc, f >= 0); + CuAssertTrue(tc, r <= (int)f + 1); + CuAssertTrue(tc, r >= (int)f); + CuAssertTrue(tc, r == (int)r); + CuAssertTrue(tc, r == RAND_ROUND(r)); } CuSuite *get_rng_suite(void) From 230f7ca11f379eeb68c52722145483373808387a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Dec 2018 10:30:33 +0100 Subject: [PATCH 35/85] BUG 2535: Anzeige von Kampfzaubern. use sbs_printf where possible. --- src/reports.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/reports.c b/src/reports.c index 93bbb187c..4f679bc46 100644 --- a/src/reports.c +++ b/src/reports.c @@ -812,19 +812,14 @@ void bufunit(const faction * f, const unit * u, const faction *fv, if (book) { selist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC, NULL); - sbs_strcat(sbp, ". Aura "); - sbs_strcat(sbp, str_itoa(get_spellpoints(u))); - sbs_strcat(sbp, "/"); - sbs_strcat(sbp, str_itoa(max_spellpoints(u, NULL))); + sbs_printf(sbp, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u, NULL)); for (header = 0, qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); const spell *sp = spellref_get(&sbe->spref); if (sbe->level <= maxlevel) { if (!header) { - sbs_strcat(sbp, ", "); - sbs_strcat(sbp, LOC(lang, "nr_spells")); - sbs_strcat(sbp, ": "); + sbs_printf(sbp, ", %s: ", LOC(lang, "nr_spells")); header = 1; } else { @@ -840,9 +835,7 @@ void bufunit(const faction * f, const unit * u, const faction *fv, break; } if (i != MAXCOMBATSPELLS) { - sbs_strcat(sbp, ", "); - sbs_strcat(sbp, LOC(lang, "nr_combatspells")); - sbs_strcat(sbp, ": "); + sbs_printf(sbp, ", %s: ", LOC(lang, "nr_combatspells")); dh = 0; for (i = 0; i < MAXCOMBATSPELLS; i++) { const spell *sp; @@ -857,9 +850,7 @@ void bufunit(const faction * f, const unit * u, const faction *fv, int sl = get_combatspelllevel(u, i); sbs_strcat(sbp, spell_name(sp, lang)); if (sl > 0) { - sbs_strcat(sbp, "( "); - sbs_strcat(sbp, str_itoa(sl)); - sbs_strcat(sbp, ")"); + sbs_printf(sbp, "(%d)", sl); } } else { From 07d2278741f53326a8fd1f5265c4fd30aa7ad0a9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Dec 2018 14:41:14 +0100 Subject: [PATCH 36/85] re-enable intermittent test, supplement unit test. Untote reservieren nichts von anderen Einheiten. --- scripts/tests/e2/undead.lua | 3 ++- src/kernel/pool.test.c | 30 ++++++++++++++++++++++++++++-- src/laws.c | 5 +---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index e06aa0054..243919bbc 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -19,7 +19,7 @@ function test_undead_reserve_self() assert_equal(1, u1:get_item("log")) end -function skip_undead_reserve_other() +function test_undead_reserve_other() local r1 = region.create(0, 0, "plain") local f1 = faction.create("human") local u1 = unit.create(f1, r1, 1) @@ -28,6 +28,7 @@ function skip_undead_reserve_other() u1.race = "undead" u1:clear_orders() u1:add_order("RESERVIERE 1 Holz") + u1.name = 'Xolgrim' process_orders() -- Intermittent Failure: expected 0 but was 2 diff --git a/src/kernel/pool.test.c b/src/kernel/pool.test.c index 10c127f81..d5d190c26 100644 --- a/src/kernel/pool.test.c +++ b/src/kernel/pool.test.c @@ -6,6 +6,7 @@ #include "unit.h" #include "item.h" #include "faction.h" +#include "race.h" #include "region.h" #include "skill.h" @@ -42,6 +43,30 @@ void test_reservation(CuTest *tc) { test_teardown(); } +void test_pool_get_item(CuTest *tc) { + unit *u1, *u2; + faction *f; + region *r; + race *rc; + struct resource_type *rtype; + + test_setup(); + rtype = rt_get_or_create("money"); + rtype->flags |= RTF_POOLED; + it_get_or_create(rtype); + f = test_create_faction(NULL); + r = test_create_plain(0, 0); + u1 = test_create_unit(f, r); + u_setrace(u1, rc = test_create_race("undead")); + rc->ec_flags &= ~ECF_GETITEM; + u2 = test_create_unit(f, r); + i_change(&u2->items, rtype->itype, 2); + CuAssertIntEquals(tc, 0, get_pooled(u1, rtype, GET_DEFAULT, 1)); + CuAssertIntEquals(tc, 0, i_get(u1->items, rtype->itype)); + CuAssertIntEquals(tc, 2, i_get(u2->items, rtype->itype)); + test_teardown(); +} + void test_pool(CuTest *tc) { unit *u1, *u2, *u3; faction *f; @@ -49,11 +74,11 @@ void test_pool(CuTest *tc) { struct resource_type *rtype; test_setup(); - test_create_world(); rtype = rt_get_or_create("money"); + rtype->flags |= RTF_POOLED; it_get_or_create(rtype); f = test_create_faction(NULL); - r = findregion(0, 0); + r = test_create_plain(0, 0); assert(r && f && rtype && rtype->itype); u1 = test_create_unit(f, r); u2 = test_create_unit(f, r); @@ -188,6 +213,7 @@ CuSuite *get_pool_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_reservation); SUITE_ADD_TEST(suite, test_pool); + SUITE_ADD_TEST(suite, test_pool_get_item); SUITE_ADD_TEST(suite, test_pool_bug_2042); SUITE_ADD_TEST(suite, test_pool_use); SUITE_ADD_TEST(suite, test_change_resource); diff --git a/src/laws.c b/src/laws.c index cb05f9d5f..0dff64b61 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3434,10 +3434,7 @@ static int reserve_i(unit * u, struct order *ord, int flags) } int reserve_cmd(unit * u, struct order *ord) { - if ((u_race(u)->ec_flags & ECF_GETITEM)) { - return reserve_i(u, ord, GET_DEFAULT); - } - return 0; + return reserve_i(u, ord, GET_DEFAULT); } int reserve_self(unit * u, struct order *ord) { From 6bf33f9fc2fc6fd55b4fee9094138bb498f3ad96 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 9 Dec 2018 18:56:04 +0100 Subject: [PATCH 37/85] stop coverity warning (realloc). --- src/attributes/key.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/attributes/key.c b/src/attributes/key.c index 66af66b89..ac4dbb4d5 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -260,6 +260,7 @@ static int *keys_update(int *base, int key, int val) ptrdiff_t diff = kv - base; sz = keys_size(n + 1); base = realloc(base, (sz * 2 + 1) * sizeof(int)); + if (!base) abort(); kv = base + diff; } base[0] = n + 1; From 230a2d8fbaf5f69a3308bd0045ec4b422b80809f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 11 Dec 2018 19:32:10 +0100 Subject: [PATCH 38/85] do not use macros for va_copy, which is available from C99 on and with gcc >= 3.0. this somehow eliminates bogus cppcheck warnings --- src/util/log.c | 25 ++++++++++++------------- src/util/path.h | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/util/log.c b/src/util/log.c index 97f44bd95..8c198988f 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -205,15 +205,17 @@ log_t *log_to_file(int flags, FILE *out) { return log_create(flags, out, log_stdio); } -#ifdef _MSC_VER -/* https://social.msdn.microsoft.com/Forums/vstudio/en-US/53a4fd75-9f97-48b2-aa63-2e2e5a15efa3/stdcversion-problem?forum=vclanguage */ -#define VA_COPY(c, a) va_copy(c, a) -#elif !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L -/* GNU only: https://www.gnu.org/software/libc/manual/html_node/Argument-Macros.html */ -#define VA_COPY(c, a) __va_copy(c, a) -#else -#define VA_COPY(c, a) va_copy(c, a) -#endif +/* + * Notes for va_copy compatibility: + * MSVC: https://social.msdn.microsoft.com/Forums/vstudio/en-US/53a4fd75-9f97-48b2-aa63-2e2e5a15efa3/stdcversion-problem?forum=vclanguage + * GNU: https://www.gnu.org/software/libc/manual/html_node/Argument-Macros.html + */ +static void vlog(log_t *lg, int level, const char *format, va_list args) { + va_list copy; + va_copy(copy, args); + lg->log(lg->data, level, NULL, format, copy); + va_end(copy); +} static void log_write(int flags, const char *module, const char *format, va_list args) { log_t *lg; @@ -225,10 +227,7 @@ static void log_write(int flags, const char *module, const char *format, va_list dupe = check_dupe(format, level); } if (dupe == 0) { - va_list copy; - VA_COPY(copy, args); - lg->log(lg->data, level, NULL, format, copy); - va_end(copy); + vlog(lg, level, format, args); } } } diff --git a/src/util/path.h b/src/util/path.h index 649777171..d7c82940e 100644 --- a/src/util/path.h +++ b/src/util/path.h @@ -2,7 +2,7 @@ #include -#ifdef _MSC_VER +#ifndef PATH_MAX /* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */ #define PATH_MAX 260 #endif From ca7f3fbf88627574c59428c0808919df063b8203 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 11 Dec 2018 19:57:27 +0100 Subject: [PATCH 39/85] reduce variables scope (cppcheck warnings). --- src/kernel/config.c | 2 +- src/kernel/unit.c | 3 +-- src/magic.c | 2 +- src/move.c | 6 +++--- src/report.c | 22 +++++++++------------- src/reports.c | 6 +++--- src/reports.test.c | 4 ++-- src/spells.c | 12 +++++------- 8 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 73b4aa22e..5c0bfc777 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -107,10 +107,10 @@ int findoption(const char *s, const struct locale *lang) /* -- Erschaffung neuer Einheiten ------------------------------ */ static int *forbidden_ids; +static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; bool forbiddenid(int id) { - static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; static size_t len; size_t i; if (id <= 0) { diff --git a/src/kernel/unit.c b/src/kernel/unit.c index bf2ad7a37..0778fc48e 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -982,9 +982,8 @@ void set_number(unit * u, int count) void remove_skill(unit * u, skill_t sk) { int i; - skill *sv; for (i = 0; i != u->skill_size; ++i) { - sv = u->skills + i; + skill *sv = u->skills + i; if (sv->id == sk) { if (u->skill_size - i - 1 > 0) { memmove(sv, sv + 1, (u->skill_size - i - 1) * sizeof(skill)); diff --git a/src/magic.c b/src/magic.c index 49ba3915e..a90f36882 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2090,7 +2090,7 @@ castorder *create_castorder(castorder * co, unit *caster, unit * familiar, const co->sp = sp; co->level = lev; co->force = MagicPower(force); - co->_rtarget = r ? r : (familiar ? familiar->region : (caster ? caster->region : 0)); + co->_rtarget = r ? r : (familiar ? familiar->region : (caster ? caster->region : NULL)); co->distance = range; co->order = copy_order(ord); co->par = p; diff --git a/src/move.c b/src/move.c index bcf159309..7d21538b0 100644 --- a/src/move.c +++ b/src/move.c @@ -637,6 +637,7 @@ void move_ship(ship * sh, region * from, region * to, region_list * route) unit **iunit = &from->units; unit **ulist = &to->units; + assert(sh); if (from != to) { translist(&from->ships, &to->ships, sh); sh->region = to; @@ -1676,10 +1677,9 @@ static bool ship_ready(const region * r, unit * u, order * ord) unit *owner_buildingtyp(const region * r, const building_type * bt) { building *b; - unit *owner; for (b = rbuildings(r); b; b = b->next) { - owner = building_owner(b); + unit *owner = building_owner(b); if (b->type == bt && owner != NULL) { if (building_finished(b)) { return owner; @@ -1971,7 +1971,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) /* Hafengebühren ? */ harbourmaster = owner_buildingtyp(current_point, bt_find("harbour")); - if (sh && harbourmaster != NULL) { + if (harbourmaster != NULL) { item *itm; unit *u2; item *trans = NULL; diff --git a/src/report.c b/src/report.c index b96267b82..fd73f6369 100644 --- a/src/report.c +++ b/src/report.c @@ -432,7 +432,7 @@ void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang) { - int k, itemanz, costtyp; + int k; bool cont; char buf[4096]; const spell *sp = spellref_get(&sbe->spref); @@ -471,8 +471,8 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la paragraph(out, LOC(lang, "nr_spell_components"), 0, 0, 0); for (k = 0; sp->components[k].type; ++k) { const resource_type *rtype = sp->components[k].type; - itemanz = sp->components[k].amount; - costtyp = sp->components[k].cost; + int itemanz = sp->components[k].amount; + int costtyp = sp->components[k].cost; if (itemanz > 0) { sbs_init(&sbs, buf, sizeof(buf)); if (sp->sptyp & SPELLLEVEL) { @@ -519,7 +519,6 @@ static void nr_curses_i(struct stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self) { for (; a; a = a->next) { - char buf[4096]; message *msg = 0; if (a->type == &at_curse) { @@ -536,6 +535,7 @@ nr_curses_i(struct stream *out, int indent, const faction *viewer, objtype_t typ } } if (msg) { + char buf[4096]; newline(out); nr_render(msg, viewer->locale, buf, sizeof(buf), viewer); paragraph(out, buf, indent, 2, 0); @@ -847,7 +847,6 @@ static void report_region_resource(sbstring *sbp, const struct locale *lang, con static void report_region_description(struct stream *out, const region * r, faction * f, const bool see[]) { int n; - bool dh; int trees; int saplings; attrib *a; @@ -986,6 +985,7 @@ static void report_region_description(struct stream *out, const region * r, fact } else { int d, nrd = 0; + bool dh = false; /* Nachbarregionen, die gesehen werden, ermitteln */ for (d = 0; d != MAXDIRECTIONS; d++) { @@ -994,7 +994,6 @@ static void report_region_description(struct stream *out, const region * r, fact } /* list directions */ - dh = false; for (d = 0; d != MAXDIRECTIONS; d++) { if (see[d]) { region *r2 = rconnect(r, d); @@ -1037,7 +1036,6 @@ static void report_region_description(struct stream *out, const region * r, fact sbs_strcat(&sbs, " (\""); sbs_strcat(&sbs, LOC(f->locale, spd->keyword)); sbs_strcat(&sbs, "\")."); - dh = 1; } } pump_paragraph(&sbs, out, REPORTWIDTH, true); @@ -1889,7 +1887,6 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) { void report_travelthru(struct stream *out, region *r, const faction *f) { int maxtravel; - char buf[8192]; assert(r); assert(f); @@ -1901,6 +1898,7 @@ void report_travelthru(struct stream *out, region *r, const faction *f) maxtravel = count_travelthru(r, f); if (maxtravel > 0) { cb_data cbdata; + char buf[8192]; init_cb(&cbdata, out, buf, sizeof(buf), f); cbdata.maxtravel = maxtravel; @@ -1960,12 +1958,11 @@ report_plaintext(const char *filename, report_context * ctx, if (f->age <= 2) { const char *email; - const char *subject; email = config_get("game.email"); if (!email) log_error("game.email not set"); else { - subject = get_mailcmd(f->locale); + const char *subject = get_mailcmd(f->locale); m = msg_message("newbie_info_game", "email subject", email, subject); if (m) { @@ -2068,9 +2065,9 @@ report_plaintext(const char *filename, report_context * ctx, for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem; a = a->next) { const item_type *itype = (const item_type *)a->data.v; - const char *description = NULL; if (itype) { const char *pname = resourcename(itype->rtype, 0); + const char *description; if (ch == 0) { newline(out); @@ -2102,8 +2099,7 @@ report_plaintext(const char *filename, report_context * ctx, } centre(out, buf, true); newline(out); - description = mkname("describe", pname); - description = LOC(f->locale, description); + description = LOC(f->locale, mkname("describe", pname)); centre(out, description, true); } } diff --git a/src/reports.c b/src/reports.c index 4f679bc46..1b87782eb 100644 --- a/src/reports.c +++ b/src/reports.c @@ -319,11 +319,11 @@ report_items(const unit *u, item * result, int size, const unit * owner, } } for (itm = items; itm; itm = itm->next) { - item *ishow; const char *ic; report_item(owner, itm, viewer, NULL, &ic, NULL, false); if (ic && *ic) { + item *ishow; for (ishow = result; ishow != result + n; ++ishow) { const char *sc; @@ -1785,9 +1785,9 @@ static void var_free_regions(variant x) /*-V524 */ const char *trailinto(const region * r, const struct locale *lang) { - static char ref[32]; - const char *s; if (r) { + static char ref[32]; + const char *s; const char *tname = terrain_name(r); size_t sz; diff --git a/src/reports.test.c b/src/reports.test.c index bf43669fa..a744532c5 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -601,14 +601,14 @@ static void test_prepare_lighthouse_owners(CuTest *tc) f = test_create_faction(NULL); r1 = test_create_region(0, 0, t_plain); r2 = test_create_region(1, 0, t_ocean); - r3 = test_create_region(2, 0, t_ocean); + test_create_region(2, 0, t_ocean); r3 = test_create_region(3, 0, t_ocean); btype = test_create_buildingtype("lighthouse"); b = test_create_building(r1, btype); b->flags |= BLD_MAINTAINED; b->size = 10; update_lighthouse(b); - u = test_create_unit(f, r1); + test_create_unit(f, r1); u = test_create_unit(test_create_faction(NULL), r1); u->building = b; region_set_owner(b->region, f, 0); diff --git a/src/spells.c b/src/spells.c index f74cc100d..6a80858e3 100644 --- a/src/spells.c +++ b/src/spells.c @@ -2346,7 +2346,6 @@ static int sp_earthquake(castorder * co) static void patzer_peasantmob(const castorder * co) { unit *u; - attrib *a; region *r; unit *mage = co_get_magician(co); r = mage->region->land ? mage->region : co_get_region(co); @@ -2355,6 +2354,7 @@ static void patzer_peasantmob(const castorder * co) faction *f = get_monsters(); const struct locale *lang = f->locale; message *msg; + attrib *a; int anteil, n; anteil = 6 + rng_int() % 4; @@ -2410,7 +2410,6 @@ static void patzer_peasantmob(const castorder * co) static int sp_forest_fire(castorder * co) { unit *u; - region *nr; direction_t i; region *r = co_get_region(co); unit *caster = co_get_caster(co); @@ -2442,7 +2441,7 @@ static int sp_forest_fire(castorder * co) msg_release(msg); for (i = 0; i < MAXDIRECTIONS; i++) { - nr = rconnect(r, i); + region *nr = rconnect(r, i); assert(nr); destroyed = 0; vernichtet_schoesslinge = 0; @@ -5629,7 +5628,6 @@ int sp_disruptastral(castorder * co) attrib *a; double effect; region *r2 = rl2->data; - spec_direction *sd; int inhab_regions = 0; region_list *trl = NULL; @@ -5649,7 +5647,7 @@ int sp_disruptastral(castorder * co) while (a != NULL && a->type == &at_direction) { attrib *a2 = a->next; - sd = (spec_direction *)(a->data.v); + spec_direction *sd = (spec_direction *)(a->data.v); if (sd->duration != -1) a_remove(&r->attribs, a); a = a2; @@ -6161,7 +6159,6 @@ int sp_speed2(castorder * co) */ int sp_break_curse(castorder * co) { - attrib **ap; int obj; curse *c; region *r = co_get_region(co); @@ -6169,7 +6166,6 @@ int sp_break_curse(castorder * co) int cast_level = co->level; double force = co->force; spellparameter *pa = co->par; - const char *ts = NULL; if (pa->length < 2) { /* Das Zielobjekt wurde vergessen */ @@ -6186,6 +6182,8 @@ int sp_break_curse(castorder * co) "unit region command", mage, mage->region, co->order)); } else { + const char *ts = NULL; + attrib **ap; switch (obj) { case SPP_REGION: ap = &r->attribs; From 28293eb2df0ef072e70e2959605b624a96a15dfe Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 12 Dec 2018 09:41:21 +0100 Subject: [PATCH 40/85] cmake (on macOS) already has a FindLua module --- cmake/Modules/FindLua.cmake | 172 ------------------------------------ 1 file changed, 172 deletions(-) delete mode 100644 cmake/Modules/FindLua.cmake diff --git a/cmake/Modules/FindLua.cmake b/cmake/Modules/FindLua.cmake deleted file mode 100644 index 898ccbfd6..000000000 --- a/cmake/Modules/FindLua.cmake +++ /dev/null @@ -1,172 +0,0 @@ -#.rst: -# FindLua -# ------- -# -# -# -# Locate Lua library This module defines -# -# :: -# -# LUA_FOUND - if false, do not try to link to Lua -# LUA_LIBRARIES - both lua and lualib -# LUA_INCLUDE_DIR - where to find lua.h -# LUA_VERSION_STRING - the version of Lua found -# LUA_VERSION_MAJOR - the major version of Lua -# LUA_VERSION_MINOR - the minor version of Lua -# LUA_VERSION_PATCH - the patch version of Lua -# -# -# -# Note that the expected include convention is -# -# :: -# -# #include "lua.h" -# -# and not -# -# :: -# -# #include -# -# This is because, the lua location is not standardized and may exist in -# locations other than lua/ - -#============================================================================= -# Copyright 2007-2009 Kitware, Inc. -# Copyright 2013 Rolf Eike Beer -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -unset(_lua_include_subdirs) -unset(_lua_library_names) - -# this is a function only to have all the variables inside go away automatically -function(set_lua_version_vars) - set(LUA_VERSIONS5 5.3 5.2 5.1 5.0) - - if (Lua_FIND_VERSION_EXACT) - if (Lua_FIND_VERSION_COUNT GREATER 1) - set(lua_append_versions ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}) - endif () - elseif (Lua_FIND_VERSION) - # once there is a different major version supported this should become a loop - if (NOT Lua_FIND_VERSION_MAJOR GREATER 5) - if (Lua_FIND_VERSION_COUNT EQUAL 1) - set(lua_append_versions ${LUA_VERSIONS5}) - else () - foreach (subver IN LISTS LUA_VERSIONS5) - if (NOT subver VERSION_LESS ${Lua_FIND_VERSION}) - list(APPEND lua_append_versions ${subver}) - endif () - endforeach () - endif () - endif () - else () - # once there is a different major version supported this should become a loop - set(lua_append_versions ${LUA_VERSIONS5}) - endif () - - foreach (ver IN LISTS lua_append_versions) - string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}") - list(APPEND _lua_include_subdirs - include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} - include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - ) - list(APPEND _lua_library_names - lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} - lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - lua.${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - ) - endforeach () - - set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE) - set(_lua_library_names "${_lua_library_names}" PARENT_SCOPE) -endfunction(set_lua_version_vars) - -set_lua_version_vars() - -find_path(LUA_INCLUDE_DIR lua.h - HINTS - ENV LUA_DIR - PATH_SUFFIXES ${_lua_include_subdirs} include/lua include - PATHS - ~/Library/Frameworks - /Library/Frameworks - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt -) -unset(_lua_include_subdirs) - -find_library(LUA_LIBRARY - NAMES ${_lua_library_names} lua - HINTS - ENV LUA_DIR - PATH_SUFFIXES lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /sw - /opt/local - /opt/csw - /opt -) -unset(_lua_library_names) - -if (LUA_LIBRARY) - # include the math library for Unix - if (UNIX AND NOT APPLE AND NOT BEOS) - find_library(LUA_MATH_LIBRARY m) - set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}") - # For Windows and Mac, don't need to explicitly include the math library - else () - set(LUA_LIBRARIES "${LUA_LIBRARY}") - endif () -endif () - -if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") - # At least 5.[012] have different ways to express the version - # so all of them need to be tested. Lua 5.2 defines LUA_VERSION - # and LUA_RELEASE as joined by the C preprocessor, so avoid those. - file(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_strings - REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*") - - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MAJOR ";${lua_version_strings};") - if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};") - set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}") - else () - string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") - if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_VERSION_STRING ";${lua_version_strings};") - endif () - string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}") - endif () - - unset(lua_version_strings) -endif() - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if -# all listed variables are TRUE -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua - REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR - VERSION_VAR LUA_VERSION_STRING) - -mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY) From 0137d70221c88abb21fb2c266dab50991825c8c4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 18:14:36 +0100 Subject: [PATCH 41/85] order atoi36 conditions by likeliness. --- res/translations/messages.de.po | 6 +++--- src/util/base36.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/res/translations/messages.de.po b/res/translations/messages.de.po index 5fcc657f1..57b4426ef 100644 --- a/res/translations/messages.de.po +++ b/res/translations/messages.de.po @@ -711,7 +711,7 @@ msgid "magicboost_effect" msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Sphären des Chaos geben dem Magier einen Teil ihrer Kraft.\"" msgid "error254" -msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auraangabe fehlerhaft oder zuwenig Aura.\"" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auraangabe fehlerhaft oder zu wenig Aura.\"" msgid "error250" msgstr "\"$unit($unit) in $region($region): '$order($command)' - Nicht genug Karma.\"" @@ -1026,7 +1026,7 @@ msgid "chaos_disease" msgstr "\"$unit($unit) scheint von einer seltsamen Krankheit befallen.\"" msgid "error1" -msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auf dem Schiff befinden sich zuwenig erfahrene Seeleute.\"" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auf dem Schiff befinden sich zu wenige erfahrene Seeleute.\"" msgid "sp_icastle_effect" msgstr "\"Verwundert blicken die Bauern von $region($region) auf ein neues Gebäude.\"" @@ -1971,7 +1971,7 @@ msgid "error80" msgstr "\"$unit($unit) in $region($region): '$order($command)' - Einheit ist nicht bewaffnet und kampffähig.\"" msgid "error142" -msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit hat zuwenig Silber, um zu rekrutieren.\"" +msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit hat zu wenig Silber, um zu rekrutieren.\"" msgid "rust_fail" msgstr "\"$unit($mage) legt einen Rosthauch auf $unit($target), doch der Rosthauch fand keine Nahrung.\"" diff --git a/src/util/base36.c b/src/util/base36.c index b1bef983d..f77823a0b 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -37,12 +37,12 @@ int atoi36(const char *str) ++s; } while (isalnum(*(unsigned char *)s)) { - if (isupper(*(unsigned char *)s)) - i = i * 36 + (*s) - 'A' + 10; - else if (islower(*s)) + if (islower(*s)) i = i * 36 + (*s) - 'a' + 10; else if (isdigit(*s)) i = i * 36 + (*s) - '0'; + else if (isupper(*(unsigned char *)s)) + i = i * 36 + (*s) - 'A' + 10; else break; ++s; From 5764f71985f737b19ca79844cb677ce0164dace9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 18:15:39 +0100 Subject: [PATCH 42/85] readorders was deprecated and is now gone. --- src/orderfile.c | 11 ----------- src/orderfile.h | 1 - 2 files changed, 12 deletions(-) diff --git a/src/orderfile.c b/src/orderfile.c index 01169fa62..e9198510e 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -355,14 +355,3 @@ int parseorders(FILE *F) OP_ParserFree(parser); return err; } - -int readorders(FILE *F) -{ - int result; - - input in; - in.getbuf = file_getbuf; - in.data = F; - result = read_orders(&in); - return result; -} diff --git a/src/orderfile.h b/src/orderfile.h index f4260aa67..f7934556e 100644 --- a/src/orderfile.h +++ b/src/orderfile.h @@ -13,7 +13,6 @@ extern "C" { } input; int read_orders(struct input *in); - int readorders(FILE *F); int parseorders(FILE *F); #ifdef __cplusplus From 3d2bd2f1cd300905d3e46540d63a5ffa768f9dc8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 18:17:06 +0100 Subject: [PATCH 43/85] remove unused function --- src/modules/xmas.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/modules/xmas.c b/src/modules/xmas.c index a8b87026a..15af966d6 100644 --- a/src/modules/xmas.c +++ b/src/modules/xmas.c @@ -65,13 +65,6 @@ struct trigger_type tt_xmasgate = { xmasgate_read }; -trigger *trigger_xmasgate(building * b) -{ - trigger *t = t_new(&tt_xmasgate); - t->data.v = b; - return t; -} - void register_xmas(void) { tt_register(&tt_xmasgate); From a16c829218e2bddc1d623fd004c3eed640b58f19 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 18:42:31 +0100 Subject: [PATCH 44/85] include what you use --- src/kernel/ally.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 80ef6b18f..f4ab35c8e 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -1,6 +1,5 @@ #include "platform.h" #include "config.h" -#include "types.h" #include "ally.h" #include "unit.h" From 033070663abbd639212a1f2d8a0046c4ebf8b278 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 19:38:40 +0100 Subject: [PATCH 45/85] code analysis scan. add checks for malloc results. reduce stack size. --- src/chaos.c | 6 +++--- src/donations.c | 3 ++- src/economy.c | 18 +++++++++++++----- src/exparse.c | 35 +++++++++++++++++++++++------------ src/items.c | 2 +- src/jsonconf.c | 10 +++++----- src/kernel/building.c | 2 +- src/kernel/event.c | 6 ++++-- src/kernel/faction.c | 5 ++++- src/kernel/group.c | 1 + src/kernel/item.c | 9 +++++---- src/kernel/messages.c | 2 ++ src/kernel/order.c | 2 ++ src/kernel/pathfinder.c | 4 +++- src/kernel/plane.c | 2 +- src/kernel/pool.c | 6 ++++-- src/kernel/race.c | 10 ++++++++-- src/kernel/region.c | 17 ++++++++++++----- src/kernel/resources.c | 4 +++- src/kernel/save.c | 5 +++++ src/kernel/ship.c | 7 +++++-- src/kernel/skills.c | 2 +- src/kernel/spellbook.c | 3 +++ src/kernel/terrain.c | 2 +- src/laws.c | 2 +- src/magic.c | 4 ++-- src/renumber.c | 2 +- src/study.c | 2 +- src/summary.c | 2 +- src/triggers/changefaction.c | 2 +- src/triggers/changerace.c | 2 +- src/triggers/createcurse.c | 2 +- src/triggers/createunit.c | 2 +- src/triggers/gate.c | 2 +- src/triggers/giveitem.c | 2 +- src/triggers/timeout.c | 2 +- 36 files changed, 125 insertions(+), 64 deletions(-) diff --git a/src/chaos.c b/src/chaos.c index 925545369..7a2dd7c89 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -53,12 +53,12 @@ static const terrain_type *chaosterrain(void) } } if (numtypes > 0) { + int n = 0; types = malloc(sizeof(terrain_type *) * numtypes); if (!types) abort(); - numtypes = 0; - for (terrain = terrains(); terrain != NULL; terrain = terrain->next) { + for (terrain = terrains(); n != numtypes && terrain != NULL; terrain = terrain->next) { if ((terrain->flags & LAND_REGION) && terrain->herbs) { - types[numtypes++] = terrain; + types[n++] = terrain; } } } diff --git a/src/donations.c b/src/donations.c index b923df73b..eee9e6fda 100644 --- a/src/donations.c +++ b/src/donations.c @@ -48,7 +48,8 @@ void add_donation(faction * f1, faction * f2, int amount, region * r) tf->amount += amount; } else { - tf = malloc(sizeof(transfer)); + tf = (transfer *)malloc(sizeof(transfer)); + if (!tf) abort(); memcpy(tf, &tr, sizeof(transfer)); } selist_set_insert(&transfers, tf, cmp_transfer); diff --git a/src/economy.c b/src/economy.c index 7a13b4c34..8a638c067 100644 --- a/src/economy.c +++ b/src/economy.c @@ -166,7 +166,8 @@ int expand_production(region * r, econ_request * requests, econ_request ***resul if (norders > 0) { int i = 0; econ_request **split; - split = calloc(norders, sizeof(econ_request *)); + split = (econ_request **)calloc(norders, sizeof(econ_request *)); + if (!split) abort(); for (o = requests; o; o = o->next) { if (o->qty > 0) { unsigned int j; @@ -230,7 +231,8 @@ static recruitment *select_recruitment(econ_request ** rop, while (rec && rec->f != u->faction) rec = rec->next; if (rec == NULL) { - rec = malloc(sizeof(recruitment)); + rec = (recruitment *)malloc(sizeof(recruitment)); + if (!rec) abort(); rec->f = u->faction; rec->total = 0; rec->assigned = 0; @@ -563,6 +565,7 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders) u_setrace(u, rc); u->wants = n; o = (econ_request *)calloc(1, sizeof(econ_request)); + if (!o) abort(); o->qty = n; o->unit = u; o->type.recruit.ord = ord; @@ -940,7 +943,7 @@ typedef struct allocation { unsigned int flags; unit *unit; } allocation; -#define new_allocation() calloc(sizeof(allocation), 1) +#define new_allocation() (allocation *)calloc(1, sizeof(allocation)) #define free_allocation(a) free(a) typedef struct allocation_list { @@ -1054,12 +1057,13 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) while (alist && alist->type != rtype) alist = alist->next; if (!alist) { - alist = calloc(sizeof(struct allocation_list), 1); + alist = calloc(1, sizeof(struct allocation_list)); alist->next = allocations; alist->type = rtype; allocations = alist; } al = new_allocation(); + if (!al) abort(); al->want = amount; al->save = save_mod; al->next = alist->data; @@ -1665,6 +1669,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord) return; } o = (econ_request *)calloc(1, sizeof(econ_request)); + if (!o) abort(); o->type.trade.ltype = ltype; /* sollte immer gleich sein */ o->unit = u; @@ -2013,6 +2018,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) /* die Menge der verkauften G�ter merken */ a->data.i += n; o = (econ_request *)calloc(1, sizeof(econ_request)); + if (!o) abort(); o->unit = u; o->qty = n; o->type.trade.ltype = ltype; @@ -2628,6 +2634,7 @@ void tax_cmd(unit * u, struct order *ord, econ_request ** taxorders) * einheiten aufgeteilt. */ o = (econ_request *)calloc(1, sizeof(econ_request)); + if (!o) abort(); o->qty = u->wants / TAXFRACTION; o->unit = u; addlist(taxorders, o); @@ -2693,6 +2700,7 @@ void loot_cmd(unit * u, struct order *ord, econ_request ** lootorders) } o = (econ_request *)calloc(1, sizeof(econ_request)); + if (!o) abort(); o->qty = u->wants / TAXFRACTION; o->unit = u; addlist(lootorders, o); @@ -2700,7 +2708,7 @@ void loot_cmd(unit * u, struct order *ord, econ_request ** lootorders) return; } -#define MAX_WORKERS 2048 +#define MAX_WORKERS 512 void auto_work(region * r) { econ_request workers[MAX_WORKERS]; diff --git a/src/exparse.c b/src/exparse.c index 602bdf4e9..0814f7cdc 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -753,8 +753,9 @@ static void handle_modifier(parseinfo *pi, const XML_Char *el, const XML_Char ** } static construction *parse_construction(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { - construction *con = calloc(sizeof(construction), 1); int i; + construction *con = (construction *)calloc(1, sizeof(construction)); + if (!con) abort(); con->maxsize = -1; con->minskill = -1; con->reqsize = 1; @@ -1273,7 +1274,8 @@ static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char ** } else if (xml_strequal(el, "construction")) { assert(stage == NULL); - stage = calloc(1, sizeof(building_stage)); + stage = (building_stage *)calloc(1, sizeof(building_stage)); + if (!stage) abort(); stage->construction = parse_construction(pi, el, attr); } else if (xml_strequal(el, "maintenance")) { @@ -1366,7 +1368,8 @@ static void end_spells(parseinfo *pi, const XML_Char *el) { else if (xml_strequal(el, "spell")) { spell *sp = (spell *)pi->object; if (ncomponents > 0) { - sp->components = calloc(sizeof(spell_component), ncomponents + 1); + sp->components = (spell_component *)calloc(ncomponents + 1, sizeof(spell_component)); + if (!sp->components) abort(); memcpy(sp->components, components, sizeof(spell_component) * ncomponents); ncomponents = 0; } @@ -1384,7 +1387,8 @@ static void end_weapon(parseinfo *pi, const XML_Char *el) { else if (xml_strequal(el, "modifier")) { if (nwmods > 0) { weapon_type *wtype = rtype->wtype; - wtype->modifiers = calloc(sizeof(weapon_mod), nwmods + 1); + wtype->modifiers = (weapon_mod *)calloc(nwmods + 1, sizeof(weapon_mod)); + if (!wtype->modifiers) abort(); memcpy(wtype->modifiers, wmods, sizeof(weapon_mod) * nwmods); nwmods = 0; } @@ -1395,7 +1399,8 @@ static void end_resources(parseinfo *pi, const XML_Char *el) { resource_type *rtype = (resource_type *)pi->object; if (xml_strequal(el, "resource")) { if (nrmods > 0) { - rtype->modifiers = calloc(sizeof(resource_mod), nrmods + 1); + rtype->modifiers = (resource_mod *)calloc(nrmods + 1, sizeof(resource_mod)); + if (!rtype->modifiers) abort(); memcpy(rtype->modifiers, rmods, sizeof(resource_mod) * nrmods); nrmods = 0; } @@ -1403,7 +1408,8 @@ static void end_resources(parseinfo *pi, const XML_Char *el) { else if (xml_strequal(el, "construction")) { if (nreqs > 0) { construction *con = rtype->itype->construction; - con->materials = calloc(sizeof(requirement), nreqs + 1); + con->materials = (requirement *)calloc(nreqs + 1, sizeof(requirement)); + if (!con->materials) abort(); memcpy(con->materials, reqs, sizeof(requirement) * nreqs); nreqs = 0; } @@ -1440,15 +1446,17 @@ static void end_ships(parseinfo *pi, const XML_Char *el) { assert(stype->construction); if (nreqs > 0) { construction *con = stype->construction; - con->materials = calloc(sizeof(requirement), nreqs + 1); + con->materials = (requirement *) calloc(nreqs + 1, sizeof(requirement)); + if (!con->materials) abort(); memcpy(con->materials, reqs, sizeof(requirement) * nreqs); nreqs = 0; } } else if (xml_strequal(el, "ship")) { if (ncoasts > 0) { - stype->coasts = calloc(sizeof(const terrain_type *), ncoasts + 1); - memcpy(stype->coasts, coasts, sizeof(const terrain_type *) * ncoasts); + stype->coasts = (terrain_type **) calloc(ncoasts + 1, sizeof(terrain_type *)); + if (!stype->coasts) abort(); + memcpy(stype->coasts, coasts, sizeof(terrain_type *) * ncoasts); ncoasts = 0; } pi->object = NULL; @@ -1468,7 +1476,8 @@ static void end_buildings(parseinfo *pi, const XML_Char *el) { if (stage) { if (nreqs > 0) { construction *con = stage->construction; - con->materials = calloc(sizeof(requirement), nreqs + 1); + con->materials = (requirement *)calloc(nreqs + 1, sizeof(requirement)); + if (!con->materials) abort(); memcpy(con->materials, reqs, sizeof(requirement) * nreqs); nreqs = 0; } @@ -1485,12 +1494,14 @@ static void end_buildings(parseinfo *pi, const XML_Char *el) { else if (xml_strequal(el, "building")) { stage_ptr = NULL; if (nupkeep > 0) { - btype->maintenance = calloc(sizeof(maintenance), nupkeep + 1); + btype->maintenance = (maintenance *)calloc(nupkeep + 1, sizeof(maintenance)); + if (!btype->maintenance) abort(); memcpy(btype->maintenance, upkeep, sizeof(maintenance) * nupkeep); nupkeep = 0; } if (nrmods > 0) { - btype->modifiers = calloc(sizeof(resource_mod), nrmods + 1); + btype->modifiers = calloc(nrmods + 1, sizeof(resource_mod)); + if (!btype->modifiers) abort(); memcpy(btype->modifiers, rmods, sizeof(resource_mod) * nrmods); nrmods = 0; } diff --git a/src/items.c b/src/items.c index 94865aba3..9a91a6037 100644 --- a/src/items.c +++ b/src/items.c @@ -142,7 +142,7 @@ struct order *ord) /* H�lt Spr�che bis zu einem summierten Gesamtlevel von power aus. * Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone * um seine Stufe */ - force = effect * 20; /* Stufe 5 =~ 100 */ + force = effect * 20.0; /* Stufe 5 =~ 100 */ /* Regionszauber aufl�sen */ while (*ap && force > 0) { diff --git a/src/jsonconf.c b/src/jsonconf.c index 48be28b16..217ed0ebe 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -79,7 +79,7 @@ static int json_flags(cJSON *json, const char *flags[]) { static void json_requirements(cJSON *json, requirement **matp) { cJSON *child; int i; - requirement *mat = calloc(sizeof(requirement), 1 + cJSON_GetArraySize(json)); + requirement *mat = calloc(1 + cJSON_GetArraySize(json), sizeof(requirement)); for (i = 0, child = json->child; child; child = child->next, ++i) { mat[i].number = child->valueint; mat[i].rtype = rt_get_or_create(child->string); @@ -134,7 +134,7 @@ static void json_maintenance(cJSON *json, maintenance **mtp) { log_error("maintenance is not a json object or array (%d)", json->type); return; } - *mtp = mt = (struct maintenance *) calloc(sizeof(struct maintenance), size + 1); + *mtp = mt = (struct maintenance *) calloc(size + 1, sizeof(struct maintenance)); if (json->type == cJSON_Array) { int i; for (i = 0, child = json->child; child; child = child->next, ++i) { @@ -156,7 +156,7 @@ static void json_construction(cJSON *json, construction **consp) { log_error("construction %s is not a json object: %d", json->string, json->type); return; } - cons = (construction *)calloc(sizeof(construction), 1); + cons = (construction *)calloc(1, sizeof(construction)); for (child = json->child; child; child = child->next) { switch (child->type) { case cJSON_Object: @@ -332,7 +332,7 @@ static void json_stages(cJSON *json, building_type *bt) { for (child = json->child; child; child = child->next) { switch (child->type) { case cJSON_Object: - stage = calloc(sizeof(building_stage), 1); + stage = calloc(1, sizeof(building_stage)); json_stage(child, stage); if (stage->construction->maxsize > 0) { stage->construction->maxsize -= size; @@ -375,7 +375,7 @@ static void json_building(cJSON *json, building_type *bt) { if (strcmp(child->string, "construction") == 0) { /* simple, single-stage building */ if (!bt->stages) { - building_stage *stage = calloc(sizeof(building_stage), 1); + building_stage *stage = calloc(1, sizeof(building_stage)); json_construction(child, &stage->construction); bt->stages = stage; } diff --git a/src/kernel/building.c b/src/kernel/building.c index 456ad1704..b741c37af 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -285,7 +285,7 @@ static local_names *get_bnames(const struct locale *lang) selist *ql = buildingtypes; int qi; - bn = (local_names *)calloc(sizeof(local_names), 1); + bn = (local_names *)calloc(1, sizeof(local_names)); bn->next = bnames; bn->lang = lang; diff --git a/src/kernel/event.c b/src/kernel/event.c index f1ff825f5..9e04abb6a 100644 --- a/src/kernel/event.c +++ b/src/kernel/event.c @@ -79,7 +79,8 @@ int read_triggers(struct gamedata *data, trigger ** tp) trigger *t_new(trigger_type * ttype) { - trigger *t = calloc(sizeof(trigger), 1); + trigger *t = calloc(1, sizeof(trigger)); + if (!t) abort(); t->type = ttype; if (ttype->initialize) ttype->initialize(t); @@ -129,7 +130,7 @@ typedef struct handler_info { static void init_handler(variant *var) { - var->v = calloc(sizeof(handler_info), 1); + var->v = calloc(1, sizeof(handler_info)); } static void free_handler(variant *var) @@ -204,6 +205,7 @@ void add_trigger(struct attrib **ap, const char *eventname, struct trigger *t) td = (handler_info *)a->data.v; td->event = str_strdup(eventname); } + assert(td); tp = &td->triggers; while (*tp) tp = &(*tp)->next; diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 61e4a591e..dbf11359e 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -214,9 +214,10 @@ void faction_genpassword(faction *f) { faction *addfaction(const char *email, const char *password, const struct race * frace, const struct locale * loc) { - faction *f = calloc(sizeof(faction), 1); + faction *f = calloc(1, sizeof(faction)); char buf[128]; + if (!f) abort(); if (check_email(email) == 0) { faction_setemail(f, email); } else { @@ -697,6 +698,7 @@ void faction_getorigin(const faction * f, int id, int *x, int *y) static origin *new_origin(int id, int x, int y) { origin *ur = (origin *)calloc(1, sizeof(origin)); + if (!ur) abort(); ur->id = id; ur->x = x; ur->y = y; @@ -838,6 +840,7 @@ void free_factions(void) { faction *faction_create(int no) { faction *f = (faction *)calloc(1, sizeof(faction)); + if (!f) abort(); f->no = no; fhash(f); return f; diff --git a/src/kernel/group.c b/src/kernel/group.c index 210f6e0f2..b01e10a9a 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -55,6 +55,7 @@ group *new_group(faction * f, const char *name, int gid) int index = gid % GMAXHASH; group *g = calloc(1, sizeof(group)); + if (!g) abort(); while (*gp) gp = &(*gp)->next; *gp = g; diff --git a/src/kernel/item.c b/src/kernel/item.c index a58df472c..52ff72a84 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -244,7 +244,7 @@ item_type *it_get_or_create(resource_type *rtype) { assert(rtype); if (!rtype->itype) { item_type * itype; - itype = (item_type *)calloc(sizeof(item_type), 1); + itype = (item_type *)calloc(1, sizeof(item_type)); if (!itype) abort(); itype->rtype = rtype; rtype->uchange = res_changeitem; @@ -267,7 +267,7 @@ luxury_type *new_luxurytype(item_type * itype, int price) assert(resource2luxury(itype->rtype) == NULL); - ltype = calloc(sizeof(luxury_type), 1); + ltype = calloc(1, sizeof(luxury_type)); if (!ltype) abort(); ltype->itype = itype; ltype->price = price; @@ -284,7 +284,7 @@ weapon_type *new_weapontype(item_type * itype, assert(itype && (!itype->rtype || !resource2weapon(itype->rtype))); - wtype = calloc(sizeof(weapon_type), 1); + wtype = calloc(1, sizeof(weapon_type)); if (!wtype) abort(); if (damage) { wtype->damage[0] = str_strdup(damage[0]); @@ -297,6 +297,7 @@ weapon_type *new_weapontype(item_type * itype, wtype->offmod = offmod; wtype->reload = reload; wtype->skill = sk; + assert(itype->rtype); itype->rtype->wtype = wtype; return wtype; @@ -309,7 +310,7 @@ armor_type *new_armortype(item_type * itype, double penalty, variant magres, assert(itype->rtype->atype == NULL); - atype = calloc(sizeof(armor_type), 1); + atype = calloc(1, sizeof(armor_type)); if (!atype) abort(); atype->itype = itype; diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 48ea13f1f..ea16044f8 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -312,8 +312,10 @@ message *add_message(message_list ** pm, message * m) assert(m && m->type); if (m != NULL) { struct mlist *mnew = malloc(sizeof(struct mlist)); + if (!mnew) abort(); if (*pm == NULL) { *pm = malloc(sizeof(message_list)); + if (*pm == NULL) abort(); (*pm)->end = &(*pm)->begin; } mnew->msg = msg_addref(m); diff --git a/src/kernel/order.c b/src/kernel/order.c index b4467fa5b..44332d630 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -61,6 +61,7 @@ void odata_create(order_data **pdata, size_t len, const char *str) assert(pdata); data = malloc(sizeof(order_data) + len + 1); + if (!data) abort(); data->_refcount = 1; result = (char *)(data + 1); data->_str = (len > 0) ? result : NULL; @@ -230,6 +231,7 @@ order *copy_order(const order * src) { if (src != NULL) { order *ord = (order *)malloc(sizeof(order)); + if (!ord) abort(); ord->next = NULL; ord->command = src->command; ord->id = src->id; diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 61cead5fd..ba37d651d 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -69,8 +69,10 @@ static node *new_node(region * r, int distance, node * prev) n = node_garbage; node_garbage = n->next; } - else + else { n = malloc(sizeof(node)); + if (!n) abort(); + } n->next = NULL; n->prev = prev; n->r = r; diff --git a/src/kernel/plane.c b/src/kernel/plane.c index 89de42618..4fc3ff816 100644 --- a/src/kernel/plane.c +++ b/src/kernel/plane.c @@ -231,7 +231,7 @@ plane *create_new_plane(int id, const char *name, int minx, int maxx, int miny, if (pl) return pl; pl = calloc(1, sizeof(plane)); - + if (!pl) abort(); pl->next = NULL; pl->id = id; if (name) diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 70e02cb96..6805e1c0e 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -113,7 +113,8 @@ int change_reservation(unit * u, const item_type * itype, int value) rp = &(*rp)->next; res = *rp; if (!res) { - *rp = res = calloc(sizeof(reservation), 1); + *rp = res = calloc(1, sizeof(reservation)); + if (!res) abort(); res->type = itype; res->value = value; } @@ -138,7 +139,8 @@ int set_resvalue(unit * u, const item_type * itype, int value) if (!res) { if (!value) return 0; - *rp = res = calloc(sizeof(reservation), 1); + *rp = res = calloc(1, sizeof(reservation)); + if (!res) abort(); res->type = itype; res->value = value; } diff --git a/src/kernel/race.c b/src/kernel/race.c index 4a0d0689f..debf368ef 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -101,6 +101,7 @@ static void rc_setoption(race *rc, int k, const char *value) { variant *v = NULL; if (!rc->options) { rc->options = malloc(sizeof(rcoption)); + if (!rc->options) abort(); rc->options->key[0] = key; rc->options->key[1] = RCO_NONE; v = rc->options->value; @@ -202,6 +203,7 @@ race_t old_race(const struct race * rc) int i; if (!xrefs) { xrefs = malloc(sizeof(rc_xref) * MAXRACES); + if (!xrefs) abort(); } for (i = 0; i != MAXRACES; ++i) { xrefs[i].rc = get_race(i); @@ -244,6 +246,7 @@ void racelist_insert(struct race_list **rl, const struct race *r) { race_list *rl2 = (race_list *)malloc(sizeof(race_list)); + if (!rl2) abort(); rl2->data = r; rl2->next = *rl; @@ -340,7 +343,8 @@ race *rc_create(const char *zName) char zText[64]; assert(zName); - rc = (race *)calloc(sizeof(race), 1); + rc = (race *)calloc(1, sizeof(race)); + if (!rc) abort(); rc->mask_item = 1 << race_mask; ++race_mask; @@ -446,8 +450,10 @@ int rc_herb_trade(const struct race *rc) } void set_study_speed(race *rc, skill_t sk, int modifier) { - if (!rc->study_speed) + if (!rc->study_speed) { rc->study_speed = calloc(1, MAXSKILLS); + if (!rc->study_speed) abort(); + } rc->study_speed[sk] = (char)modifier; } diff --git a/src/kernel/region.c b/src/kernel/region.c index 5d2de2308..f8ce68ffd 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -471,6 +471,7 @@ void add_regionlist(region_list ** rl, region * r) { region_list *rl2 = (region_list *)malloc(sizeof(region_list)); + if (!rl2) abort(); rl2->data = r; rl2->next = *rl; @@ -799,7 +800,7 @@ static region *deleted_regions; void remove_region(region ** rlist, region * r) { - + assert(r); while (r->units) { unit *u = r->units; i_freeall(&u->items); @@ -1040,6 +1041,7 @@ void setluxuries(region * r, const luxury_type * sale) for (ltype = luxurytypes; ltype; ltype = ltype->next) { struct demand *dmd = malloc(sizeof(struct demand)); + if (!dmd) abort(); dmd->type = ltype; if (ltype != sale) dmd->value = 1 + rng_int() % 5; @@ -1165,6 +1167,7 @@ void terraform_region(region * r, const terrain_type * terrain) int mnr = 0; r->land = calloc(1, sizeof(land_region)); + if (!r->land) abort(); r->land->ownership = NULL; region_set_morale(r, MORALE_DEFAULT, -1); region_setname(r, makename()); @@ -1186,6 +1189,7 @@ void terraform_region(region * r, const terrain_type * terrain) } else { sr = calloc(1, sizeof(struct surround)); + if (!sr) abort(); } sr->next = nb; sr->type = sale->type; @@ -1321,6 +1325,7 @@ struct message *msg) imsg = imsg->next; if (imsg == NULL) { imsg = malloc(sizeof(struct individual_message)); + if (!imsg) abort(); imsg->next = r->individual_messages; imsg->msgs = NULL; r->individual_messages = imsg; @@ -1372,11 +1377,13 @@ void region_set_owner(struct region *r, struct faction *owner, int turn) assert(rule_region_owners()); if (r->land) { if (!r->land->ownership) { - r->land->ownership = malloc(sizeof(region_owner)); + region_owner *ro = malloc(sizeof(region_owner)); + if (!ro) abort(); assert(region_get_morale(r) == MORALE_DEFAULT); - r->land->ownership->owner = NULL; - r->land->ownership->last_owner = NULL; - r->land->ownership->flags = 0; + ro->owner = NULL; + ro->last_owner = NULL; + ro->flags = 0; + r->land->ownership = ro; } r->land->ownership->since_turn = turn; r->land->ownership->morale_turn = turn; diff --git a/src/kernel/resources.c b/src/kernel/resources.c index b5741236b..ad2b67d90 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -70,8 +70,9 @@ struct rawmaterial * add_resource(region * r, int level, int base, int divisor, const resource_type * rtype) { - struct rawmaterial *rm = calloc(sizeof(struct rawmaterial), 1); + struct rawmaterial *rm = calloc(1, sizeof(struct rawmaterial)); + if (!rm) abort(); rm->next = r->resources; r->resources = rm; rm->flags = 0; @@ -183,6 +184,7 @@ struct rawmaterial_type *rmt_create(struct resource_type *rtype) { if (!rtype->raw) { rawmaterial_type *rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); + if (!rmtype) abort(); rmtype->rtype = rtype; rmtype->terraform = terraform_default; rmtype->update = NULL; diff --git a/src/kernel/save.c b/src/kernel/save.c index f6ce25327..4c8e02fe0 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -150,6 +150,7 @@ void read_planes(gamedata *data) { if (pl == NULL) { pl = calloc(1, sizeof(plane)); + if (!pl) abort(); } else { log_warning("the plane with id=%d already exists.", id); @@ -239,6 +240,7 @@ static void read_owner(gamedata *data, region_owner ** powner) READ_INT(data->store, &since_turn); if (since_turn >= 0) { region_owner *owner = malloc(sizeof(region_owner)); + if (!owner) abort(); owner->since_turn = since_turn; READ_INT(data->store, &owner->morale_turn); if (data->version >= MOURNING_VERSION) { @@ -696,6 +698,7 @@ static region *readregion(gamedata *data, int x, int y) if (strcmp(name, "end") == 0) break; res = malloc(sizeof(rawmaterial)); + if (!res) abort(); res->rtype = rt_find(name); if (!res->rtype && strncmp("rm_", name, 3) == 0) { res->rtype = rt_find(name + 3); @@ -1203,6 +1206,7 @@ struct building *read_building(gamedata *data) { storage * store = data->store; b = (building *)calloc(1, sizeof(building)); + if (!b) abort(); READ_INT(store, &b->no); bhash(b); READ_STR(store, name, sizeof(name)); @@ -1257,6 +1261,7 @@ ship *read_ship(gamedata *data) storage *store = data->store; sh = (ship *)calloc(1, sizeof(ship)); + if (!sh) abort(); READ_INT(store, &sh->no); shash(sh); READ_STR(store, name, sizeof(name)); diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 5c47e5347..27de232e4 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -71,7 +71,8 @@ const ship_type *findshiptype(const char *name, const struct locale *lang) selist *ql; int qi; - sn = (local_names *)calloc(sizeof(local_names), 1); + sn = (local_names *)calloc(1, sizeof(local_names)); + if (!sn) abort(); sn->next = snames; sn->lang = lang; @@ -124,7 +125,8 @@ ship_type *st_get_or_create(const char * name) { ship_type * st = st_find_i(name); assert(!snames); if (!st) { - st = (ship_type *)calloc(sizeof(ship_type), 1); + st = (ship_type *)calloc(1, sizeof(ship_type)); + if (!st) abort(); st->_name = str_strdup(name); st->storm = 1.0; st->tac_bonus = 1.0; @@ -189,6 +191,7 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang) ship *sh = (ship *)calloc(1, sizeof(ship)); const char *sname = 0; + if (!sh) abort(); assert(stype); sh->no = newcontainerid(); sh->coast = NODIRECTION; diff --git a/src/kernel/skills.c b/src/kernel/skills.c index ea2022872..4fba7284f 100644 --- a/src/kernel/skills.c +++ b/src/kernel/skills.c @@ -39,7 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /** skillmod attribut **/ static void init_skillmod(variant *var) { - var->v = calloc(sizeof(skillmod_data), 1); + var->v = calloc(1, sizeof(skillmod_data)); } /** temporary skill modification (NOT SAVED!). */ diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index d230992cf..345cdd96d 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -19,6 +19,7 @@ spellbook * create_spellbook(const char * name) { spellbook *result = (spellbook *)malloc(sizeof(spellbook)); + if (!result) abort(); result->name = name ? str_strdup(name) : 0; result->spells = 0; return result; @@ -79,6 +80,7 @@ void spellbook_addref(spellbook *sb, const char *name, int level) { assert(sb && name && level > 0); sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); + if (!sbe) abort(); spellref_init(&sbe->spref, NULL, name); sbe->level = level; selist_push(&sb->spells, sbe); @@ -95,6 +97,7 @@ void spellbook_add(spellbook *sb, spell *sp, int level) } #endif sbe = (spellbook_entry *)malloc(sizeof(spellbook_entry)); + if (!sbe) abort(); spellref_init(&sbe->spref, sp, NULL); sbe->level = level; selist_push(&sb->spells, sbe); diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index f5041dc03..3f2390254 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -125,7 +125,7 @@ terrain_type * get_or_create_terrain(const char *name) { terrain_type *terrain = terrain_find_i(name); if (!terrain) { ++terrain_changes; - terrain = (terrain_type *)calloc(sizeof(terrain_type), 1); + terrain = (terrain_type *)calloc(1, sizeof(terrain_type)); if (terrain) { terrain->_name = str_strdup(name); terrain->next = registered_terrains; diff --git a/src/laws.c b/src/laws.c index 0dff64b61..421d1af31 100644 --- a/src/laws.c +++ b/src/laws.c @@ -1408,7 +1408,7 @@ static void init_prefixnames(void) in = in->next; } if (in == NULL) { - in = calloc(sizeof(local_names), 1); + in = calloc(1, sizeof(local_names)); if (!in) abort(); } in->next = pnames; diff --git a/src/magic.c b/src/magic.c index a90f36882..036003e28 100644 --- a/src/magic.c +++ b/src/magic.c @@ -244,7 +244,7 @@ static int a_ageicastle(struct attrib *a, void *owner) static void a_initicastle(variant *var) { - var->v = calloc(sizeof(icastle_data), 1); + var->v = calloc(1, sizeof(icastle_data)); } attrib_type at_icastle = { @@ -295,7 +295,7 @@ int get_spell_level_mage(const spell * sp, void * cbdata) static void init_mage(variant *var) { - var->v = calloc(sizeof(sc_mage), 1); + var->v = calloc(1, sizeof(sc_mage)); } static void free_mage(variant *var) diff --git a/src/renumber.c b/src/renumber.c index e562a0285..bfb43309a 100644 --- a/src/renumber.c +++ b/src/renumber.c @@ -56,7 +56,7 @@ void renumber_factions(void) ADDMSG(&f->msgs, msg_message("renumber_inuse", "id", want)); } else { - struct renum *r = calloc(sizeof(struct renum), 1); + struct renum *r = calloc(1, sizeof(struct renum)); r->next = *rn; r->attrib = a; r->faction = f; diff --git a/src/study.c b/src/study.c index a53942a39..3fb2d0a7d 100644 --- a/src/study.c +++ b/src/study.c @@ -154,7 +154,7 @@ int study_cost(struct unit *u, skill_t sk) static void init_learning(variant *var) { - var->v = calloc(sizeof(teaching_info), 1); + var->v = calloc(1, sizeof(teaching_info)); } static void done_learning(variant *var) diff --git a/src/summary.c b/src/summary.c index e01679d56..67e956401 100644 --- a/src/summary.c +++ b/src/summary.c @@ -404,7 +404,7 @@ summary *make_summary(void) while (plang && plang->locale != lang) plang = plang->next; if (!plang) { - plang = calloc(sizeof(struct language), 1); + plang = calloc(1, sizeof(struct language)); plang->next = s->languages; s->languages = plang; plang->locale = lang; diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index 8b1ead479..c29304992 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -51,7 +51,7 @@ typedef struct changefaction_data { static void changefaction_init(trigger * t) { - t->data.v = calloc(sizeof(changefaction_data), 1); + t->data.v = calloc(1, sizeof(changefaction_data)); } static void changefaction_free(trigger * t) diff --git a/src/triggers/changerace.c b/src/triggers/changerace.c index 5a834314a..19a84eea2 100644 --- a/src/triggers/changerace.c +++ b/src/triggers/changerace.c @@ -52,7 +52,7 @@ typedef struct changerace_data { static void changerace_init(trigger * t) { - t->data.v = calloc(sizeof(changerace_data), 1); + t->data.v = calloc(1, sizeof(changerace_data)); } static void changerace_free(trigger * t) diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index 544b9aafe..83f12b3be 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -56,7 +56,7 @@ typedef struct createcurse_data { static void createcurse_init(trigger * t) { - t->data.v = calloc(sizeof(createcurse_data), 1); + t->data.v = calloc(1, sizeof(createcurse_data)); } static void createcurse_free(trigger * t) diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 82155de55..ec1521bee 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -55,7 +55,7 @@ typedef struct createunit_data { static void createunit_init(trigger * t) { - t->data.v = calloc(sizeof(createunit_data), 1); + t->data.v = calloc(1, sizeof(createunit_data)); } static void createunit_free(trigger * t) diff --git a/src/triggers/gate.c b/src/triggers/gate.c index ac3e44b88..0218f6a3c 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -86,7 +86,7 @@ static int gate_read(trigger * t, gamedata *data) static void gate_init(trigger * t) { - t->data.v = calloc(sizeof(gate_data), 1); + t->data.v = calloc(1, sizeof(gate_data)); } static void gate_done(trigger * t) diff --git a/src/triggers/giveitem.c b/src/triggers/giveitem.c index 118497c86..3e1047f2c 100644 --- a/src/triggers/giveitem.c +++ b/src/triggers/giveitem.c @@ -51,7 +51,7 @@ typedef struct giveitem_data { static void giveitem_init(trigger * t) { - t->data.v = calloc(sizeof(giveitem_data), 1); + t->data.v = calloc(1, sizeof(giveitem_data)); } static void giveitem_free(trigger * t) diff --git a/src/triggers/timeout.c b/src/triggers/timeout.c index 8e8a6b9bf..20c0b79fe 100644 --- a/src/triggers/timeout.c +++ b/src/triggers/timeout.c @@ -42,7 +42,7 @@ typedef struct timeout_data { static void timeout_init(trigger * t) { - t->data.v = calloc(sizeof(timeout_data), 1); + t->data.v = calloc(1, sizeof(timeout_data)); } static void timeout_free(trigger * t) From 484945d42aa526e7ee5e8f1bb87d495cd89eba33 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 20:01:51 +0100 Subject: [PATCH 46/85] more allocation checks. --- src/attributes/dict.c | 5 ++++- src/attributes/key.c | 7 +++++-- src/economy.c | 1 + src/jsonconf.c | 12 ++++++++++++ src/kernel/alliance.c | 2 ++ src/kernel/ally.c | 1 + src/kernel/attrib.c | 1 + src/kernel/build.c | 1 + src/kernel/building.c | 3 +++ src/kernel/command.c | 2 ++ src/kernel/connection.c | 1 + src/kernel/spell.c | 2 ++ src/magic.c | 14 +++++++++++++- src/modules/autoseed.c | 3 +++ src/move.c | 11 ++++++----- src/prefix.c | 6 ++---- src/renumber.c | 1 + src/reports.c | 4 ++++ src/spells/borders.c | 1 + src/spells/combatspells.c | 1 + src/steal.c | 1 + src/summary.c | 1 + 22 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/attributes/dict.c b/src/attributes/dict.c index 70e88219d..130dfffa4 100644 --- a/src/attributes/dict.c +++ b/src/attributes/dict.c @@ -86,6 +86,7 @@ static void dict_init(variant *var) { dict_data *dd; var->v = malloc(sizeof(dict_data)); + if (!var->v) abort(); dd = (dict_data *)var->v; dd->type = TNONE; } @@ -143,7 +144,9 @@ static void dict_upgrade(attrib **alist, attrib *abegin) { } } if (i > 0) { - keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1)); + int *tmp = realloc(keys, sizeof(int) * (2 * (n + i) + 1)); + if (!tmp) abort(); + keys = tmp; memcpy(keys + n*2 + 1, val, sizeof(int)*i*2); if (!ak) { ak = a_add(alist, a_new(&at_keys)); diff --git a/src/attributes/key.c b/src/attributes/key.c index ac4dbb4d5..8d563024d 100644 --- a/src/attributes/key.c +++ b/src/attributes/key.c @@ -257,10 +257,12 @@ static int *keys_update(int *base, int key, int val) int sz = keys_size(n); assert(kv[0] > key); if (n + 1 > sz) { + int *tmp; ptrdiff_t diff = kv - base; sz = keys_size(n + 1); - base = realloc(base, (sz * 2 + 1) * sizeof(int)); - if (!base) abort(); + tmp = realloc(base, (sz * 2 + 1) * sizeof(int)); + if (!tmp) abort(); + base = tmp; kv = base + diff; } base[0] = n + 1; @@ -299,6 +301,7 @@ void key_set(attrib ** alist, int key, int val) if (!keys) { int sz = keys_size(1); a->data.v = keys = malloc((2 * sz + 1) * sizeof(int)); + if (!keys) abort(); keys[0] = 1; keys[1] = key; keys[2] = val; diff --git a/src/economy.c b/src/economy.c index 8a638c067..876e77856 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1058,6 +1058,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) alist = alist->next; if (!alist) { alist = calloc(1, sizeof(struct allocation_list)); + if (!alist) abort(); alist->next = allocations; alist->type = rtype; allocations = alist; diff --git a/src/jsonconf.c b/src/jsonconf.c index 217ed0ebe..06ea2c786 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -80,6 +80,7 @@ static void json_requirements(cJSON *json, requirement **matp) { cJSON *child; int i; requirement *mat = calloc(1 + cJSON_GetArraySize(json), sizeof(requirement)); + if (!mat) abort(); for (i = 0, child = json->child; child; child = child->next, ++i) { mat[i].number = child->valueint; mat[i].rtype = rt_get_or_create(child->string); @@ -157,6 +158,7 @@ static void json_construction(cJSON *json, construction **consp) { return; } cons = (construction *)calloc(1, sizeof(construction)); + if (!cons) abort(); for (child = json->child; child; child = child->next) { switch (child->type) { case cJSON_Object: @@ -236,6 +238,7 @@ static void json_terrain(cJSON *json, terrain_type *ter) { if (size > 0) { int n; ter->production = (terrain_production *)calloc(size + 1, sizeof(terrain_production)); + if (!ter->production) abort(); ter->production[size].type = 0; for (n = 0, entry = child->child; entry; entry = entry->next, ++n) { ter->production[n].type = rt_get_or_create(entry->string); @@ -266,6 +269,7 @@ static void json_terrain(cJSON *json, terrain_type *ter) { int n; free(ter->herbs); ter->herbs = malloc(sizeof(const item_type *) * (size + 1)); + if (!ter->herbs) abort(); ter->herbs[size] = 0; for (n = 0, entry = child->child; entry; entry = entry->next) { ter->herbs[n++] = it_get_or_create(rt_get_or_create(entry->valuestring)); @@ -333,6 +337,7 @@ static void json_stages(cJSON *json, building_type *bt) { switch (child->type) { case cJSON_Object: stage = calloc(1, sizeof(building_stage)); + if (!stage) abort(); json_stage(child, stage); if (stage->construction->maxsize > 0) { stage->construction->maxsize -= size; @@ -376,6 +381,7 @@ static void json_building(cJSON *json, building_type *bt) { /* simple, single-stage building */ if (!bt->stages) { building_stage *stage = calloc(1, sizeof(building_stage)); + if (!stage) abort(); json_construction(child, &stage->construction); bt->stages = stage; } @@ -448,6 +454,7 @@ static void json_ship(cJSON *json, ship_type *st) { case cJSON_Array: st->coasts = (terrain_type **) malloc(sizeof(terrain_type *) * (1 + cJSON_GetArraySize(child))); + if (!st->coasts) abort(); for (i = 0, iter = child->child; iter; iter = iter->next) { if (iter->type == cJSON_String) { terrain_type *ter = get_or_create_terrain(iter->valuestring); @@ -746,6 +753,7 @@ static void json_calendar(cJSON *json) { weeks_per_month = cJSON_GetArraySize(child); free(weeknames); weeknames = malloc(sizeof(char *) * weeks_per_month); + if (!weeknames) abort(); for (i = 0, entry = child->child; entry; entry = entry->next, ++i) { if (entry->type == cJSON_String) { weeknames[i] = str_strdup(entry->valuestring); @@ -760,6 +768,7 @@ static void json_calendar(cJSON *json) { assert(i == weeks_per_month); free(weeknames2); weeknames2 = malloc(sizeof(char *) * weeks_per_month); + if (!weeknames2) abort(); for (i = 0; i != weeks_per_month; ++i) { weeknames2[i] = malloc(strlen(weeknames[i]) + 3); sprintf(weeknames2[i], "%s_d", weeknames[i]); @@ -777,7 +786,9 @@ static void json_calendar(cJSON *json) { free(storms); months_per_year = cJSON_GetArraySize(child); storms = malloc(sizeof(int) * months_per_year); + if (!storms) abort(); month_season = malloc(sizeof(int) * months_per_year); + if (!month_season) abort(); for (i = 0, jmonth = child->child; jmonth; jmonth = jmonth->next, ++i) { if (jmonth->type == cJSON_Object) { storms[i] = cJSON_GetObjectItem(jmonth, "storm")->valueint; @@ -991,6 +1002,7 @@ static int include_json(const char *uri) { size_t sz; data = malloc(pos + 1); + if (!data) abort(); sz = fread(data, 1, (size_t)pos, F); data[sz] = 0; config = cJSON_Parse(data); diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 1996c5aad..34775b4bc 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -83,6 +83,7 @@ alliance *new_alliance(int id, const char *name) { assert(id>0); al = calloc(1, sizeof(alliance)); + if (!al) abort(); al->id = id; if (name) { al->name = str_strdup(name); @@ -129,6 +130,7 @@ static void create_transaction(int type, unit * u, order * ord) { alliance_transaction *tr = (alliance_transaction *)calloc(1, sizeof(alliance_transaction)); + if (!tr) abort(); tr->ord = ord; tr->u = u; tr->next = transactions[type]; diff --git a/src/kernel/ally.c b/src/kernel/ally.c index f4ab35c8e..1999b34b3 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -150,6 +150,7 @@ allies *allies_clone(const allies *al) { for (; al; al = al->next) { allies *al_new = calloc(1, sizeof(allies)); + if (!al_new) abort(); memcpy(al_new, al, sizeof(allies)); *al_end = al_new; al_end = &al_new->next; diff --git a/src/kernel/attrib.c b/src/kernel/attrib.c index 997a04151..f6a857d90 100644 --- a/src/kernel/attrib.c +++ b/src/kernel/attrib.c @@ -377,6 +377,7 @@ attrib *a_new(const attrib_type * at) { attrib *a = (attrib *)calloc(1, sizeof(attrib)); assert(at != NULL); + if (!a) abort(); a->type = at; if (at->initialize) at->initialize(&a->data); diff --git a/src/kernel/build.c b/src/kernel/build.c index 2dd2da9af..63b89388e 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -642,6 +642,7 @@ message *msg_materials_required(unit * u, order * ord, multi = 1; for (c = 0; ctype && ctype->materials[c].number; ++c) { resource *res = malloc(sizeof(resource)); + if (!res) abort(); res->number = multi * ctype->materials[c].number / ctype->reqsize; res->type = ctype->materials[c].rtype; res->next = reslist; diff --git a/src/kernel/building.c b/src/kernel/building.c index b741c37af..09a515fc3 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -136,6 +136,7 @@ building_type *bt_get_or_create(const char *name) building_type *btype = bt_find_i(name); if (btype == NULL) { btype = (building_type *)calloc(1, sizeof(building_type)); + if (!btype) abort(); btype->_name = str_strdup(name); btype->flags = BTF_DEFAULT; btype->auraregen = 1.0; @@ -286,6 +287,7 @@ static local_names *get_bnames(const struct locale *lang) int qi; bn = (local_names *)calloc(1, sizeof(local_names)); + if (!bn) abort(); bn->next = bnames; bn->lang = lang; @@ -378,6 +380,7 @@ int read_building_reference(gamedata * data, building **bp) building *building_create(int id) { building *b = (building *)calloc(1, sizeof(building)); + if (!b) abort(); b->no = id; bhash(b); return b; diff --git a/src/kernel/command.c b/src/kernel/command.c index 8b2a7e5e8..71abc4e4e 100644 --- a/src/kernel/command.c +++ b/src/kernel/command.c @@ -64,6 +64,7 @@ syntaxtree *stree_create(void) const struct locale *lang = locales; while (lang) { syntaxtree *stree = (syntaxtree *)malloc(sizeof(syntaxtree)); + if (!stree) abort(); stree->lang = lang; stree->next = sroot; stree->root = 0; @@ -79,6 +80,7 @@ void stree_add(struct syntaxtree *stree, const char *str, parser fun) { variant var; assert(str); + if (!cmd) abort(); cmd->fun = fun; var.v = cmd; cmd->next = stree->cmds; diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 995c276bb..61c96d9d4 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -134,6 +134,7 @@ connection *new_border(border_type * type, region * from, region * to) bp = &(*bp)->next; } *bp = b = calloc(1, sizeof(connection)); + if (!b) abort(); b->type = type; b->from = from; b->to = to; diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 41e56babd..8cc56d863 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -124,6 +124,7 @@ spell * create_spell(const char * name) return 0; } sp = (spell *)calloc(1, sizeof(spell)); + if (!sp) abort(); len = cb_new_kv(name, len, &sp, sizeof(sp), buffer); if (cb_insert(&cb_spells, buffer, len) == CB_SUCCESS) { sp->sname = str_strdup(name); @@ -177,6 +178,7 @@ spell *find_spell(const char *name) struct spellref *spellref_create(spell *sp, const char *name) { spellref *spref = malloc(sizeof(spellref)); + if (!spref) abort(); if (sp) { spref->sp = sp; diff --git a/src/magic.c b/src/magic.c index 036003e28..f0d6e66f6 100644 --- a/src/magic.c +++ b/src/magic.c @@ -437,7 +437,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells for (qi = 0, ql = book->spells; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); - if (sbe->level <= level) { + if (sbe && sbe->level <= level) { commonspells[numspells++] = sbe; } } @@ -1753,11 +1753,13 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) if ((sp->sptyp & REGIONSPELL)) { /* Zielobjekt Region anlegen */ spllprm *spobj = (spllprm *)malloc(sizeof(spllprm)); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_REGION; spobj->data.r = target_r; sa = calloc(1, sizeof(spellparameter)); + if (!sa) abort(); sa->length = 1; sa->param = calloc(sa->length, sizeof(spllprm *)); sa->param[0] = spobj; @@ -1815,6 +1817,7 @@ static int addparam_string(const char *const param[], spllprm ** spobjp) spllprm *spobj = *spobjp = malloc(sizeof(spllprm)); assert(param[0]); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_STRING; spobj->data.xs = str_strdup(param[0]); @@ -1826,6 +1829,7 @@ static int addparam_int(const char *const param[], spllprm ** spobjp) spllprm *spobj = *spobjp = malloc(sizeof(spllprm)); assert(param[0]); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_INT; spobj->data.i = atoi((char *)param[0]); @@ -1837,6 +1841,7 @@ static int addparam_ship(const char *const param[], spllprm ** spobjp) spllprm *spobj = *spobjp = malloc(sizeof(spllprm)); int id = atoi36((const char *)param[0]); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_SHIP; spobj->data.i = id; @@ -1848,6 +1853,7 @@ static int addparam_building(const char *const param[], spllprm ** spobjp) spllprm *spobj = *spobjp = malloc(sizeof(spllprm)); int id = atoi36((const char *)param[0]); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_BUILDING; spobj->data.i = id; @@ -1877,6 +1883,7 @@ addparam_region(const char *const param[], spllprm ** spobjp, const unit * u, if (rt != NULL) { spllprm *spobj = *spobjp = (spllprm *)malloc(sizeof(spllprm)); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_REGION; spobj->data.r = rt; @@ -1910,6 +1917,7 @@ addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u, } spobj = *spobjp = malloc(sizeof(spllprm)); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = otype; spobj->data.i = atoi36((const char *)param[i]); @@ -1949,12 +1957,14 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, } par = malloc(sizeof(spellparameter)); + if (!par) abort(); par->length = size; if (!size) { par->param = NULL; return par; } par->param = malloc(size * sizeof(spllprm *)); + if (!par->param) abort(); while (!err && *c && i < size && param[i] != NULL) { spllprm *spobj = NULL; @@ -2008,6 +2018,7 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, switch (findparam_ex(param[i++], u->faction->locale)) { case P_REGION: spobj = (spllprm *)malloc(sizeof(spllprm)); + if (!spobj) abort(); spobj->flag = 0; spobj->typ = SPP_REGION; spobj->data.r = target_r; @@ -2084,6 +2095,7 @@ castorder *create_castorder(castorder * co, unit *caster, unit * familiar, const int lev, double force, int range, struct order * ord, spellparameter * p) { if (!co) co = (castorder*)calloc(1, sizeof(castorder)); + if (!co) abort(); co->magician.u = caster; co->_familiar = familiar; diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index c16bb7d79..65d4b1dfc 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -676,6 +676,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) region_list *regionqueue_push(region_list ** rlist, region * r) { region_list *rnew = malloc(sizeof(region_list)); + if (!rnew) abort(); rnew->data = r; rnew->next = 0; while (*rlist) { @@ -722,7 +723,9 @@ const terrain_type *random_terrain_e3(direction_t dir) int n = 0; terrainarr = malloc(GEOMAX * sizeof(const terrain_type *)); + if (!terrainarr) abort(); distribution = malloc(GEOMAX * sizeof(int)); + if (!distribution) abort(); for (n = 0; n != GEOMAX; ++n) { terrainarr[n] = newterrain(geography_e3[n].type); distribution[n] = geography_e3[n].distribution; diff --git a/src/move.c b/src/move.c index 7d21538b0..feadbdb52 100644 --- a/src/move.c +++ b/src/move.c @@ -779,9 +779,9 @@ static void msg_to_ship_inmates(ship *sh, unit **firstu, unit **lastu, message * } if (shipfirst) { *firstu = shipfirst; - } - for (u = *firstu; u != *lastu; u = u->next) { - freset(u->faction, FFL_MARK); + for (u = *firstu; u != *lastu; u = u->next) { + freset(u->faction, FFL_MARK); + } } msg_release(msg); } @@ -1724,8 +1724,9 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) int lighthouse_div = config_get_int("rules.storm.lighthouse.divisor", 0); const char *token = getstrtoken(); - if (routep) + if (routep) { *routep = NULL; + } error = movewhere(u, token, starting_point, &next_point); if (error) { @@ -1966,7 +1967,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) if (fval(u, UFL_FOLLOWING)) caught_target(current_point, u); - move_ship(sh, starting_point, current_point, *routep); + move_ship(sh, starting_point, current_point, routep ? *routep : NULL); /* Hafengebühren ? */ diff --git a/src/prefix.c b/src/prefix.c index 84c026625..d6589c849 100644 --- a/src/prefix.c +++ b/src/prefix.c @@ -20,14 +20,12 @@ int add_raceprefix(const char *prefix) next = 0; size = 4; race_prefixes = malloc(size * sizeof(char *)); + if (!race_prefixes) abort(); } if (next + 1 == size) { char **tmp; tmp = realloc(race_prefixes, 2 * size * sizeof(char *)); - if (!tmp) { - log_fatal("allocation failure"); - return 1; - } + if (!tmp) abort(); race_prefixes = tmp; size *= 2; } diff --git a/src/renumber.c b/src/renumber.c index bfb43309a..820828339 100644 --- a/src/renumber.c +++ b/src/renumber.c @@ -57,6 +57,7 @@ void renumber_factions(void) } else { struct renum *r = calloc(1, sizeof(struct renum)); + if (!r) abort(); r->next = *rn; r->attrib = a; r->faction = f; diff --git a/src/reports.c b/src/reports.c index 1b87782eb..92397b574 100644 --- a/src/reports.c +++ b/src/reports.c @@ -975,6 +975,7 @@ void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark) * Vgl. spunit (). */ char *buflocal = calloc(strlen(s) + indent + 1, sizeof(char)); + if (!buflocal) abort(); if (indent) { memset(buflocal, ' ', indent); @@ -1174,6 +1175,7 @@ static report_type *report_types; void register_reporttype(const char *extension, report_fun write, int flag) { report_type *type = (report_type *)malloc(sizeof(report_type)); + if (!type) abort(); type->extension = extension; type->write = write; type->flag = flag; @@ -1740,6 +1742,7 @@ static variant var_copy_items(variant x) for (isrc = (item *)x.v; isrc != NULL; isrc = isrc->next) { resource *res = malloc(sizeof(resource)); + if (!res) abort(); res->number = isrc->number; res->type = isrc->type->rtype; *rptr = res; @@ -1757,6 +1760,7 @@ static variant var_copy_resources(variant x) for (rsrc = (resource *)x.v; rsrc != NULL; rsrc = rsrc->next) { resource *res = malloc(sizeof(resource)); + if (!res) abort(); res->number = rsrc->number; res->type = rsrc->type; *rptr = res; diff --git a/src/spells/borders.c b/src/spells/borders.c index c0e51a9b1..067ff6114 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -80,6 +80,7 @@ const curse_type ct_firewall = { static void wall_init(connection * b) { wall_data *fd = (wall_data *)calloc(1, sizeof(wall_data)); + if (!fd) abort(); fd->countdown = -1; /* infinite */ b->data.v = fd; } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 296d88563..fd87a2f17 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -1220,6 +1220,7 @@ static void do_meffect(fighter * af, int typ, int effect, int duration) { battle *b = af->side->battle; meffect *me = (meffect *)malloc(sizeof(struct meffect)); + if (!me) abort(); selist_push(&b->meffects, me); me->magician = af; me->typ = typ; diff --git a/src/steal.c b/src/steal.c index 633fc14dd..8c11c40a9 100644 --- a/src/steal.c +++ b/src/steal.c @@ -230,6 +230,7 @@ void steal_cmd(unit * u, struct order *ord, econ_request ** stealorders) * guter dieb sein, schliesslich macht man immer noch sehr viel laerm */ o = (econ_request *)calloc(1, sizeof(econ_request)); + if (!o) abort(); o->unit = u; o->qty = 1; /* Betrag steht in u->wants */ o->type.steal.no = u2->no; diff --git a/src/summary.c b/src/summary.c index 67e956401..06dabba90 100644 --- a/src/summary.c +++ b/src/summary.c @@ -85,6 +85,7 @@ int update_nmrs(void) int i; if (nmrs == NULL) { nmrs = malloc(sizeof(int) * (timeout + 1)); + if (!nmrs) abort(); } for (i = 0; i <= timeout; ++i) { nmrs[i] = 0; From 2a96fffeb5a294677a3e1e809e02c320c6e9290d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Dec 2018 20:12:53 +0100 Subject: [PATCH 47/85] starting to see diminishing returns. --- src/kernel/build.test.c | 6 ++++++ src/kernel/version.c | 5 +++-- src/tests.c | 1 + src/util/crypto/crypt_blowfish/wrapper.c | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index dc360c000..a123b5db0 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -65,8 +65,11 @@ static building_type *setup_castle(item_type *it_stone) { btype = test_create_buildingtype("castle"); stage = btype->stages = calloc(1, sizeof(building_stage)); + if (!stage) abort(); cons = stage->construction = calloc(1, sizeof(construction)); + if (!cons) abort(); cons->materials = calloc(2, sizeof(requirement)); + if (!cons->materials) abort(); cons->materials[0].number = 1; cons->materials[0].rtype = it_stone->rtype; cons->minskill = 1; @@ -74,8 +77,11 @@ static building_type *setup_castle(item_type *it_stone) { cons->reqsize = 1; cons->skill = SK_BUILDING; stage = stage->next = calloc(1, sizeof(building_stage)); + if (!stage) abort(); cons = stage->construction = calloc(1, sizeof(construction)); + if (!cons) abort(); cons->materials = calloc(2, sizeof(requirement)); + if (!cons->materials) abort(); cons->materials[0].number = 1; cons->materials[0].rtype = it_stone->rtype; cons->minskill = 1; diff --git a/src/kernel/version.c b/src/kernel/version.c index 92a7a6b1e..ca73b77e2 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -19,7 +19,8 @@ const char *eressea_version(void) { } int version_no(const char *str) { - int maj = 0, min = 0, pat = 0; - sscanf(str, "%4d.%4d.%4d", &maj, &min, &pat); + int c, maj = 0, min = 0, pat = 0; + c = sscanf(str, "%4d.%4d.%4d", &maj, &min, &pat); + assert(c == 3); return (maj << 16) | (min << 8) | pat; } diff --git a/src/tests.c b/src/tests.c index f6a87b396..26e57d23a 100644 --- a/src/tests.c +++ b/src/tests.c @@ -277,6 +277,7 @@ void test_create_calendar(void) { config_set_int("game.start", 184); months_per_year = 9; month_season = malloc(sizeof(int) * months_per_year); + if (!month_season) abort(); month_season[0] = SEASON_SUMMER; month_season[1] = SEASON_AUTUMN; month_season[2] = SEASON_AUTUMN; diff --git a/src/util/crypto/crypt_blowfish/wrapper.c b/src/util/crypto/crypt_blowfish/wrapper.c index b69ba7ae6..012a3c706 100644 --- a/src/util/crypto/crypt_blowfish/wrapper.c +++ b/src/util/crypto/crypt_blowfish/wrapper.c @@ -250,7 +250,9 @@ char *__crypt_gensalt_ra(const char *prefix, unsigned long count, if (!dst) __set_errno(ENOMEM); #endif - retval = memcpy(dst, retval, len); + if (dst) { + retval = memcpy(dst, retval, len); + } } return retval; From 0de71b424a9cda69ca4809e8eb8bd575ba8d1a74 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 16 Dec 2018 09:48:39 +0100 Subject: [PATCH 48/85] fix compilation --- src/kernel/version.c | 1 + src/orderfile.c | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/kernel/version.c b/src/kernel/version.c index ca73b77e2..1f8f7e0a7 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -3,6 +3,7 @@ #endif #include "version.h" +#include #include #ifndef ERESSEA_VERSION diff --git a/src/orderfile.c b/src/orderfile.c index e9198510e..0ebb7ff2c 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -223,12 +223,6 @@ int read_orders(input *in) return 0; } -static const char * file_getbuf(void *data) -{ - FILE *F = (FILE *)data; - return getbuf(F); -} - typedef struct parser_state { unit *u; faction *f; From a597e977083b40252ffeb9016c562ff2c6030eb6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 16 Dec 2018 16:36:09 +0100 Subject: [PATCH 49/85] Someone was casting leaveastral with more than 32 arguments recently. --- src/magic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/magic.c b/src/magic.c index f0d6e66f6..a71641c6d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2517,7 +2517,7 @@ static bool is_moving_ship(ship * sh) return false; } -#define MAX_PARAMETERS 32 +#define MAX_PARAMETERS 48 static castorder *cast_cmd(unit * u, order * ord) { char token[128]; From e9b29182092dab61e3771deb6f9da6662b087665 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Dec 2018 12:07:38 +0100 Subject: [PATCH 50/85] fix source encodings, break umlauts, ASCII everywhere --- src/.report.c.swp | Bin 0 -> 94208 bytes src/attributes/attributes.c | 2 +- src/direction.c | 4 +- src/kernel/curse.c | 36 +++++++------- src/kernel/curse.h | 82 +++++++++++++++---------------- src/kernel/plane.h | 14 +++--- src/kernel/region.c | 8 +-- src/kernel/terrain.h | 4 +- src/kernel/types.h | 2 +- src/kernel/unit.h | 8 +-- src/magic.h | 94 ++++++++++++++++++------------------ src/modules/museum.c | 10 ++-- src/move.h | 4 +- src/piracy.c | 4 +- src/reports.c | 2 +- src/spells/borders.h | 4 +- src/spells/buildingcurse.c | 2 +- src/spells/regioncurse.c | 14 +++--- src/spells/unitcurse.c | 2 +- src/tools/namegen.c | 2 +- 20 files changed, 149 insertions(+), 149 deletions(-) create mode 100644 src/.report.c.swp diff --git a/src/.report.c.swp b/src/.report.c.swp new file mode 100644 index 0000000000000000000000000000000000000000..c7bb683f30632149b501dca349765d98c985f1bb GIT binary patch literal 94208 zcmeFa2Yg&vdG|jA2qmzv%PuXHYb~}_UABd_yJ5Bgxy08AhX#G;3)_J2P_G z2IM6`5(o<+^tupAV1Yn@g#ZgIz4uP&y@x=6P~PwFlzY!DlC>qt|Nnk;Kl*8A&OP-x z^?A;7o-?uGg5f>UgV${+@!Y*sy6&XgJp2j&@TaBSCzndKMx!a`<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y*5w(l;Idf0^Sa-|qPT z^Y|P9cL1M*=YJ=V9YERpzY1Io&ILN>|0#I>mx1SjXMn!~UI(C??`y$5z)9dXpag!5 z9NKF1kVPK22XdZkpo;09s_2;D)2-2|F?nHfaiiqZ~@p2&Icv%11d&$30w<~ zfJ?w`@E1Tbf-fTnkiPzfK>GR-I05{ex-|7^>r$=AKS`JJE{k5sEf0C`a+Qry*@T8Y zO4_Mj_@_9S-ZECHgIhj@?utJ0S!^bvL*^}xW`&?`Mr;g(Bs{0qDzlv# zOu1!Z@q?)kuTRIlEQmiN|FQlPqwz$Me=_U+*bK8vF+sAKEGlcc@Ocs}N$6!JX4$DmUioB!5r@^CY17?PO#WTu4va*y(FW61oEP1aZ>25 zn$MD^IyBO>uo%?VVp{iBXRn3Ju7(wBhJY}>sZc|yE2-+Th4R{n^cy-#~)i%jKv$RSLGl}fhb>@Sl(#K0Kcuq zZSSpGeL^?e2gW&+Fr{CnwfEq}OfnW*lND`=T$CM72L_g2{W=Lk*$NE$qv4@7S%sS3iqLDLdPxPjmlMhJh_PH~%_mU{%4!bkl(4UQqL?(W4)#zg! z^EDUpr3FGuFL+5=EKq`(Ovou8c`{BU-{dn)G}r`*<<#=ypWr>z%VaTlnHk4|Hw2qI zWHj`;tm}l>X1i~d?qT^7_*{fJE)tc?U%HHPae5`ITK@LtOeTv%E$*r}IZ?C5se*Xr z*K|Bx4Qy_2&USYB(9_rFFATT8lmEH2GUQKfgvEu_E?6iu@bS5&y!SsengIZ@43R_t literal 0 HcmV?d00001 diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c index 12cb9131f..d0be86b0e 100644 --- a/src/attributes/attributes.c +++ b/src/attributes/attributes.c @@ -169,7 +169,7 @@ static int read_ext(variant *var, void *owner, gamedata *data) void register_attributes(void) { - /* Alle speicherbaren Attribute müssen hier registriert werden */ + /* Alle speicherbaren Attribute muessen hier registriert werden */ at_register(&at_shiptrail); at_register(&at_familiar); at_register(&at_familiarmage); diff --git a/src/direction.c b/src/direction.c index 13feff13b..ba3320b14 100644 --- a/src/direction.c +++ b/src/direction.c @@ -25,8 +25,8 @@ void init_direction(const struct locale *lang, direction_t dir, const char *str) } void init_directions(struct locale *lang) { - /* mit dieser routine kann man mehrere namen für eine direction geben, - * das ist für die hexes ideal. */ + /* mit dieser routine kann man mehrere namen fuer eine direction geben, + * das ist fuer die hexes ideal. */ const struct { const char *name; direction_t direction; diff --git a/src/kernel/curse.c b/src/kernel/curse.c index d6d77a7ea..945f60e7a 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -333,8 +333,8 @@ void ct_checknames(void) { } /* ------------------------------------------------------------- */ -/* get_curse identifiziert eine Verzauberung über die ID und gibt - * einen pointer auf die struct zurück. +/* get_curse identifiziert eine Verzauberung ueber die ID und gibt + * einen pointer auf die struct zurueck. */ static bool cmp_curse(const attrib * a, const void *data) @@ -387,7 +387,7 @@ bool remove_curse(attrib ** ap, const curse * c) return a && a_remove(ap, a) == 1; } -/* gibt die allgemeine Stärke der Verzauberung zurück. id2 wird wie +/* gibt die allgemeine Staerke der Verzauberung zurueck. id2 wird wie * oben benutzt. Dies ist nicht die Wirkung, sondern die Kraft und * damit der gegen Antimagie wirkende Widerstand einer Verzauberung */ static double get_cursevigour(const curse * c) @@ -395,15 +395,15 @@ static double get_cursevigour(const curse * c) return c ? c->vigour : 0; } -/* setzt die Stärke der Verzauberung auf i */ +/* setzt die Staerke der Verzauberung auf i */ static void set_cursevigour(curse * c, double vigour) { assert(c && vigour > 0); c->vigour = vigour; } -/* verändert die Stärke der Verzauberung um +i und gibt die neue - * Stärke zurück. Sollte die Zauberstärke unter Null sinken, löst er +/* veraendert die Stärke der Verzauberung um +i und gibt die neue + * Staerke zurueck. Sollte die Zauberstärke unter Null sinken, loest er * sich auf. */ double curse_changevigour(attrib ** ap, curse * c, double vigour) @@ -453,8 +453,8 @@ set_curseingmagician(struct unit *magician, struct attrib *ap_target, } /* ------------------------------------------------------------- */ -/* gibt bei Personenbeschränkten Verzauberungen die Anzahl der - * betroffenen Personen zurück. Ansonsten wird 0 zurückgegeben. */ +/* gibt bei Personenbeschraenkten Verzauberungen die Anzahl der + * betroffenen Personen zurueck. Ansonsten wird 0 zurückgegeben. */ int get_cursedmen(const unit * u, const curse * c) { int cursedmen = u->number; @@ -502,7 +502,7 @@ static int newcurseid(void) { /* ------------------------------------------------------------- */ /* Legt eine neue Verzauberung an. Sollte es schon einen Zauber - * dieses Typs geben, gibt es den bestehenden zurück. + * dieses Typs geben, gibt es den bestehenden zurueck. */ static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct, double vigour, int duration, double effect, int men) @@ -535,7 +535,7 @@ static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct, return c; } -/* Mapperfunktion für das Anlegen neuer curse. Automatisch wird zum +/* Mapperfunktion fuer das Anlegen neuer curse. Automatisch wird zum * passenden Typ verzweigt und die relevanten Variablen weitergegeben. */ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, @@ -585,8 +585,8 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, } /* ------------------------------------------------------------- */ -/* hier müssen alle c-typen, die auf Einheiten gezaubert werden können, - * berücksichtigt werden */ +/* hier muessen alle c-typen, die auf Einheiten gezaubert werden koennen, + * beruecksichtigt werden */ static void do_transfer_curse(curse * c, const unit * u, unit * u2, int n) { @@ -705,15 +705,15 @@ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, } /* ------------------------------------------------------------- */ -/* Antimagie - curse auflösen */ +/* Antimagie - curse aufloesen */ /* ------------------------------------------------------------- */ -/* Wenn der Curse schwächer ist als der cast_level, dann wird er -* aufgelöst, bzw seine Kraft (vigour) auf 0 gesetzt. +/* Wenn der Curse schwaecher ist als der cast_level, dann wird er +* aufgeloest, bzw seine Kraft (vigour) auf 0 gesetzt. * Ist der cast_level zu gering, hat die Antimagie nur mit einer Chance * von 100-20*Stufenunterschied % eine Wirkung auf den Curse. Dann wird -* die Kraft des Curse um die halbe Stärke der Antimagie reduziert. -* Zurückgegeben wird der noch unverbrauchte Rest von force. +* die Kraft des Curse um die halbe Staerke der Antimagie reduziert. +* Zurueckgegeben wird der noch unverbrauchte Rest von force. */ double destr_curse(curse * c, int cast_level, double force) { @@ -730,7 +730,7 @@ double destr_curse(curse * c, int cast_level, double force) } } } - else { /* Zauber ist stärker als curse */ + else { /* Zauber ist staerker als curse */ if (force >= c->vigour) { /* reicht die Kraft noch aus? */ force -= c->vigour; if (c->type->change_vigour) { diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 36ace2895..53e189be9 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -39,37 +39,37 @@ extern "C" { * (struct attribute) */ - /* Brainstorming Überarbeitung curse + /* Brainstorming Ãœberarbeitung curse * * Ziel: Keine Enum-Liste, flexible, leicht erweiterbare Curse-Objekte * * Was wird gebraucht? - * - Eindeutige Kennung für globale Suche - * - eine Wirkung, die sich einfach 'anwenden' läßt, dabei flexibel ist, - * Raum läßt für variable Boni, Anzahl betroffener Personen, + * - Eindeutige Kennung fuer globale Suche + * - eine Wirkung, die sich einfach 'anwenden' laesst, dabei flexibel ist, + * Raum laesst fuer variable Boni, Anzahl betroffener Personen, * spezielle Effekte oder anderes * - einfacher Zugriff auf allgemeine Funktionen wie zb Alterung, aber * auch Antimagieverhalten * - Ausgabe von Beschreibungen in verschiedenen Sprachen * - definiertes gekapseltes Verhalten zb bei Zusammenlegung von - * Einheiten, Übergabe von Personen, Mehrfachverzauberung - * - (Rück-)Referenzen auf Objekt, Verursacher (Magier), ? + * Einheiten, Ãœbergabe von Personen, Mehrfachverzauberung + * - (Rueck-)Referenzen auf Objekt, Verursacher (Magier), ? * - * Vieleicht wäre ein Wirkungsklassensystem sinnvoll, so das im übrigen - * source einfach alle curse-attribs abgefragt werden können und bei - * gewünschter Wirkungsklasse angewendet, also nicht für jeden curse - * spezielle Änderungen im übrigen source notwendig sind. + * Vieleicht waere ein Wirkungsklassensystem sinnvoll, so das im uebrigen + * source einfach alle curse-attribs abgefragt werden koennen und bei + * gewuenschter Wirkungsklasse angewendet, also nicht für jeden curse + * spezielle Änderungen im uebrigen source notwendig sind. * * Die (Wirkungs-)Typen sollten die wichtigen Funktionen speziell - * belegen können, zb Alterung, Ausgabetexte, Merge-Verhalten + * belegen koennen, zb Alterung, Ausgabetexte, Merge-Verhalten * * Was sind wichtige individuelle Eigenschaften? * - Referenzen auf Objekt und Verursacher - * - Referenzen für globale Liste + * - Referenzen fuer globale Liste * > die Wirkung: * - Dauer * - Widerstandskraft, zb gegen Antimagie - * - Seiteneffekte zb Flag ONLYONE, Unverträglichkeiten + * - Seiteneffekte zb Flag ONLYONE, Unvertraeglichkeiten * - Alterungsverhalten zb Flag NOAGE * - Effektverhalten, zb Bonus (variabel) * - bei Einheitenzaubern die Zahl der betroffenen Personen @@ -77,16 +77,16 @@ extern "C" { * Dabei sind nur die beiden letzten Punkte wirklich reine individuelle * Wirkung, die anderen sind eher allgemeine Kennzeichen eines jeden * Curse, die individuell belegt sind. - * ONLYONE und NOAGE könnten auch Eigenschaften des Typs sein, nicht des + * ONLYONE und NOAGE koennten auch Eigenschaften des Typs sein, nicht des * individuellen curse. Allgemein ist Alterung wohl eher eine * Typeigenschaft als die eines individuellen curse. - * Dagegen ist der Widerstand gegen Antimagie sowohl abhängig von der - * Güte des Verursachers, also des Magiers zum Zeitpunkt des Zaubers, + * Dagegen ist der Widerstand gegen Antimagie sowohl abhaengig von der + * Guete des Verursachers, also des Magiers zum Zeitpunkt des Zaubers, * als auch vom Typ, der gegen bestimmte Arten des 'Fluchbrechens' immun - * sein könnte. + * sein koennte. * * Was sind wichtige Typeigenschaften? - * - Verhalten bei Personenübergaben + * - Verhalten bei Personenuebergaben * - allgemeine Wirkung * - Beschreibungstexte * - Verhalten bei Antimagie @@ -94,8 +94,8 @@ extern "C" { * - Speicherung des C-Objekts * - Laden des C-Objekts * - Erzeugen des C-Objekts - * - Löschen und Aufräumen des C-Objekts - * - Funktionen zur Änderung der Werte + * - Loeschen und Aufraeumen des C-Objekts + * - Funktionen zur Änderung der Werte * * */ @@ -118,17 +118,17 @@ extern "C" { C_BADLEARN, C_SHIP_SPEEDUP, /* 9 - Sturmwind-Zauber */ C_SHIP_FLYING, /* 10 - Luftschiff-Zauber */ - C_SHIP_NODRIFT, /* 11 - GünstigeWinde-Zauber */ + C_SHIP_NODRIFT, /* 11 - GuenstigeWinde-Zauber */ C_DEPRESSION, C_MAGICWALLS, /* 13 - Heimstein */ C_STRONGWALL, /* 14 - Feste Mauer - Precombat */ C_ASTRALBLOCK, /* 15 - Astralblock */ C_GENEROUS, /* 16 - Unterhaltung vermehren */ C_PEACE, /* 17 - Regionsweit Attacken verhindern */ - C_MAGICSTREET, /* 19 - magisches Straßennetz */ - C_RESIST_MAGIC, /* 20 - verändert Magieresistenz von Objekten */ - C_SONG_BADMR, /* 21 - verändert Magieresistenz */ - C_SONG_GOODMR, /* 22 - verändert Magieresistenz */ + C_MAGICSTREET, /* 19 - magisches Strassennetz */ + C_RESIST_MAGIC, /* 20 - veraendert Magieresistenz von Objekten */ + C_SONG_BADMR, /* 21 - veraendert Magieresistenz */ + C_SONG_GOODMR, /* 22 - veraendert Magieresistenz */ C_SLAVE, /* 23 - dient fremder Partei */ C_CALM, /* 25 - Beinflussung */ C_OLDRACE, @@ -145,7 +145,7 @@ extern "C" { /* ------------------------------------------------------------- */ /* Flags */ - /* Verhalten von Zaubern auf Units beim Übergeben von Personen */ + /* Verhalten von Zaubern auf Units beim Ãœbergeben von Personen */ typedef enum { CURSE_ISNEW = 0x01, /* wirkt in der zauberrunde nicht (default) */ CURSE_NOAGE = 0x02, /* wirkt ewig */ @@ -153,10 +153,10 @@ extern "C" { CURSE_ONLYONE = 0x08, /* Verhindert, das ein weiterer Zauber dieser Art auf das Objekt gezaubert wird */ /* the following are mutually exclusive */ - CURSE_SPREADNEVER = 0x00, /* wird nie mit übertragen */ - CURSE_SPREADALWAYS = 0x10, /* wird immer mit übertragen */ + CURSE_SPREADNEVER = 0x00, /* wird nie mit uebertragen */ + CURSE_SPREADALWAYS = 0x10, /* wird immer mit uebertragen */ CURSE_SPREADMODULO = 0x20, /* personenweise weitergabe */ - CURSE_SPREADCHANCE = 0x30 /* Ansteckungschance je nach Mengenverhältnis */ + CURSE_SPREADCHANCE = 0x30 /* Ansteckungschance je nach Mengenverhaeltnis */ } curseflags; #define CURSE_FLAGSMASK 0x0F @@ -180,8 +180,8 @@ extern "C" { #define M_SUMEFFECT 8 /* der Effekt summiert sich */ #define M_MEN 16 /* die Anzahl der betroffenen Personen summiert sich */ -#define M_VIGOUR 32 /* das Maximum der beiden Stärken wird die - Stärke des neuen Zaubers */ +#define M_VIGOUR 32 /* das Maximum der beiden Staerken wird die + Staerke des neuen Zaubers */ #define M_VIGOUR_ADD 64 /* Vigour wird addiert */ /* ------------------------------------------------------------- */ @@ -212,7 +212,7 @@ extern "C" { struct curse *nexthash; const curse_type *type; /* Zeiger auf ein curse_type-struct */ struct unit *magician; /* Pointer auf den Magier, der den Spruch gewirkt hat */ - double vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */ + double vigour; /* Staerke der Verzauberung, Widerstand gegen Antimagie */ double effect; int no; /* 'Einheitennummer' dieses Curse */ int mask; /* This is XORed with type->flags, see c_flags()! */ @@ -251,35 +251,35 @@ extern "C" { /* ignoriert CURSE_ISNEW */ bool is_cursed_internal(struct attrib *ap, const curse_type * ctype); - /* löscht einen konkreten Spruch auf einem Objekt. */ + /* loescht einen konkreten Spruch auf einem Objekt. */ bool remove_curse(struct attrib **ap, const struct curse *c); - /* gibt die Auswirkungen der Verzauberungen zurück. zB bei + /* gibt die Auswirkungen der Verzauberungen zurueck. zB bei * Skillmodifiziernden Verzauberungen ist hier der Modifizierer * gespeichert. Wird automatisch beim Anlegen eines neuen curse - * gesetzt. Gibt immer den ersten Treffer von ap aus zurück. + * gesetzt. Gibt immer den ersten Treffer von ap aus zurueck. */ int curse_geteffect_int(const struct curse *c); double curse_geteffect(const struct curse *c); - /* verändert die Stärke der Verzauberung um i */ + /* veraendert die Stärke der Verzauberung um i */ double curse_changevigour(struct attrib **ap, curse * c, double delta); - /* gibt bei Personenbeschränkten Verzauberungen die Anzahl der - * betroffenen Personen zurück. Ansonsten wird 0 zurückgegeben. */ + /* gibt bei Personenbeschraenkten Verzauberungen die Anzahl der + * betroffenen Personen zurueck. Ansonsten wird 0 zurückgegeben. */ int get_cursedmen(const struct unit *u, const struct curse *c); /* setzt/loescht Spezialflag einer Verzauberung (zB 'dauert ewig') */ void c_setflag(curse * c, unsigned int flag); void c_clearflag(curse * c, unsigned int flags); - /* sorgt dafür, das bei der Übergabe von Personen die curse-attribute + /* sorgt dafuer, das bei der Ãœbergabe von Personen die curse-attribute * korrekt gehandhabt werden. Je nach internen Flag kann dies - * unterschiedlich gewünscht sein + * unterschiedlich gewuenscht sein * */ void transfer_curse(const struct unit *u, struct unit *u2, int n); - /* gibt pointer auf die erste curse-struct zurück, deren Typ ctype ist, + /* gibt pointer auf die erste curse-struct zurueck, deren Typ ctype ist, * oder einen NULL-pointer * */ struct curse *get_curse(struct attrib *ap, const curse_type * ctype); diff --git a/src/kernel/plane.h b/src/kernel/plane.h index faa663a36..bfaaa5dda 100644 --- a/src/kernel/plane.h +++ b/src/kernel/plane.h @@ -32,14 +32,14 @@ extern "C" { #define PFL_NORECRUITS 2 /* cannot recruit */ #define PFL_NOALLIANCES 4 /* not implemented */ #define PFL_LOWSTEALING 8 /* not implemented */ -#define PFL_NOGIVE 16 /* Übergaben sind unmöglich */ -#define PFL_NOATTACK 32 /* Angriffe und Diebstähle sind unmöglich */ +#define PFL_NOGIVE 16 /* Ãœbergaben sind unmoeglich */ +#define PFL_NOATTACK 32 /* Angriffe und Diebstaehle sind unmoeglich */ #define PFL_NOTERRAIN 64 /* Terraintyp wird nicht angezeigt TODO? */ -#define PFL_NOMAGIC 128 /* Zaubern ist unmöglich */ -#define PFL_NOSTEALTH 256 /* Tarnung außer Betrieb */ -#define PFL_NOTEACH 512 /* Lehre außer Betrieb */ -#define PFL_NOBUILD 1024 /* Bauen außer Betrieb */ -#define PFL_NOFEED 2048 /* Kein Unterhalt nötig */ +#define PFL_NOMAGIC 128 /* Zaubern ist unmoeglich */ +#define PFL_NOSTEALTH 256 /* Tarnung ausser Betrieb */ +#define PFL_NOTEACH 512 /* Lehre ausser Betrieb */ +#define PFL_NOBUILD 1024 /* Bauen ausser Betrieb */ +#define PFL_NOFEED 2048 /* Kein Unterhalt noetig */ #define PFL_FRIENDLY 4096 /* not implemented */ #define PFL_NOORCGROWTH 8192 /* orcs don't grow */ #define PFL_NOMONSTERS 16384 /* no monster randenc */ diff --git a/src/kernel/region.c b/src/kernel/region.c index f8ce68ffd..4614f22bc 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -175,7 +175,7 @@ void deathcounts(region * r, int fallen) } } -/* Moveblock wird zur Zeit nicht über Attribute, sondern ein Bitfeld +/* Moveblock wird zur Zeit nicht ueber Attribute, sondern ein Bitfeld r->moveblock gemacht. Sollte umgestellt werden, wenn kompliziertere Dinge gefragt werden. */ @@ -992,7 +992,7 @@ static char *makename(void) *handle_end = "nlrdst", *vowels = "aaaaaaaaaaaeeeeeeeeeeeeiiiiiiiiiiioooooooooooouuuuuuuuuuyy"; - /* const char * vowels_latin1 = "aaaaaaaaaàâeeeeeeeeeéèêiiiiiiiiiíîoooooooooóòôuuuuuuuuuúyy"; */ + /* const char * vowels_latin1 = "aaaaaaaaaàâeeeeeeeeeéèêiiiiiiiiiíîoooooooooóòôuuuuuuuuuúyy"; */ nk = strlen(kons); ne = strlen(handle_end); @@ -1105,7 +1105,7 @@ void init_region(region *r) void terraform_region(region * r, const terrain_type * terrain) { - /* Resourcen, die nicht mehr vorkommen können, löschen */ + /* Resourcen, die nicht mehr vorkommen koennen, löschen */ const terrain_type *oldterrain = r->terrain; rawmaterial **lrm = &r->resources; @@ -1266,7 +1266,7 @@ void terraform_region(region * r, const terrain_type * terrain) #include "curse.h" int max_production(const region * r) { - /* muß rterrain(r) sein, nicht rterrain() wegen rekursion */ + /* muss rterrain(r) sein, nicht rterrain() wegen rekursion */ int p = r->terrain->size; if (curse_active(get_curse(r->attribs, &ct_drought))) { p /= 2; diff --git a/src/kernel/terrain.h b/src/kernel/terrain.h index d49d04054..951ff7724 100644 --- a/src/kernel/terrain.h +++ b/src/kernel/terrain.h @@ -24,10 +24,10 @@ extern "C" { #endif /* diverse Flags */ - /* Strassen und Gebäude können gebaut werden, wenn max_road > 0 */ + /* Strassen und Gebaeude koennen gebaut werden, wenn max_road > 0 */ #define LAND_REGION (1<<0) /* Standard-Land-struct region */ #define SEA_REGION (1<<1) /* hier braucht man ein Boot */ -#define FOREST_REGION (1<<2) /* Elfen- und Kampfvorteil durch Bäume */ +#define FOREST_REGION (1<<2) /* Elfen- und Kampfvorteil durch Baeume */ #define ARCTIC_REGION (1<<3) /* Gletscher & co = Keine Insekten! */ #define CAVALRY_REGION (1<<4) /* riding in combat is possible */ /* Achtung: SEA_REGION ist nicht das Gegenteil von LAND_REGION. Die zwei schliessen sich nichtmal aus! */ diff --git a/src/kernel/types.h b/src/kernel/types.h index 2b014bc94..b67ee088a 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -113,7 +113,7 @@ enum { O_ADRESSEN, /* 512 */ O_BZIP2, /* 1024 - compress as bzip2 */ O_SCORE, /* 2048 - punkte anzeigen? */ - O_SHOWSKCHANGE, /* 4096 - Skillveränderungen anzeigen? */ + O_SHOWSKCHANGE, /* 4096 - Skillveraenderungen anzeigen? */ MAXOPTIONS }; diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 930574629..46746e3a1 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -47,7 +47,7 @@ extern "C" { #define UFL_MOVED (1<<8) #define UFL_NOTMOVING (1<<9) /* Die Einheit kann sich wg. langen Kampfes nicht bewegen */ #define UFL_DEFENDER (1<<10) -#define UFL_HUNGER (1<<11) /* kann im Folgemonat keinen langen Befehl außer ARBEITE ausführen */ +#define UFL_HUNGER (1<<11) /* kann im Folgemonat keinen langen Befehl ausser ARBEITE ausfuehren */ #define UFL_TARGET (1<<13) /* speedup: hat ein target, siehe attribut */ #define UFL_WERE (1<<14) #define UFL_ENTER (1<<15) /* unit has entered a ship/building and will not leave it */ @@ -55,14 +55,14 @@ extern "C" { /* warning: von 512/1024 gewechslet, wegen konflikt mit NEW_FOLLOW */ #define UFL_LOCKED (1<<16) /* Einheit kann keine Personen aufnehmen oder weggeben, nicht rekrutieren. */ #define UFL_FLEEING (1<<17) /* unit was in a battle, fleeing. */ -#define UFL_STORM (1<<19) /* Kapitän war in einem Sturm */ +#define UFL_STORM (1<<19) /* Kapitaen war in einem Sturm */ #define UFL_FOLLOWING (1<<20) #define UFL_FOLLOWED (1<<21) #define UFL_NOAID (1<<22) /* Einheit hat Noaid-Status */ #define UFL_MARK (1<<23) /* same as FL_MARK */ #define UFL_ORDERS (1<<24) /* Einheit hat Befehle erhalten */ -#define UFL_TAKEALL (1<<25) /* Einheit nimmt alle Gegenstände an */ +#define UFL_TAKEALL (1<<25) /* Einheit nimmt alle Gegenstaende an */ /* flags that speed up attribute access: */ #define UFL_STEALTH (1<<26) @@ -84,7 +84,7 @@ extern "C" { typedef struct unit { struct unit *next; /* needs to be first entry, for region's unitlist */ - struct unit *nextF; /* nächste Einheit der Partei */ + struct unit *nextF; /* naechste Einheit der Partei */ struct unit *prevF; /* vorherige Einheit der Partei */ struct region *region; int no; /* id */ diff --git a/src/magic.h b/src/magic.h index 4a184fe9e..6d181d73d 100644 --- a/src/magic.h +++ b/src/magic.h @@ -45,7 +45,7 @@ extern "C" { /* Spruchparameter * Wir suchen beim Parsen des Befehls erstmal nach lokalen Objekten, * erst in verify_targets wird dann global gesucht, da in den meisten - * Fällen das Zielobjekt lokal sein dürfte */ + * Faellen das Zielobjekt lokal sein duerfte */ /* siehe auch objtype_t in objtypes.h */ typedef enum { @@ -90,10 +90,10 @@ extern "C" { * - Magierichtung * - Magiepunkte derzeit * - Malus (neg. Wert)/ Bonus (pos. Wert) auf maximale Magiepunkte - * (können sich durch Questen absolut verändern und durch Gegenstände - * temporär). Auch für Artefakt benötigt man permanente MP - * - Anzahl bereits gezauberte Sprüche diese Runde - * - Kampfzauber (3) (vor/während/nach) + * (koennen sich durch Questen absolut veraendern und durch Gegenstände + * temporaer). Auch fuer Artefakt benoetigt man permanente MP + * - Anzahl bereits gezauberte Sprueche diese Runde + * - Kampfzauber (3) (vor/waehrend/nach) * - Spruchliste */ @@ -115,12 +115,12 @@ extern "C" { struct unit *_familiar; /* Vertrauter, gesetzt, wenn der Spruch durch den Vertrauten gezaubert wird */ const struct spell *sp; /* Spruch */ - int level; /* gewünschte Stufe oder Stufe des Magiers */ - double force; /* Stärke des Zaubers */ + int level; /* gewuenschte Stufe oder Stufe des Magiers */ + double force; /* Staerke des Zaubers */ struct region *_rtarget; /* Zielregion des Spruchs */ int distance; /* Entfernung zur Zielregion */ struct order *order; /* Befehl */ - struct spellparameter *par; /* für weitere Parameter */ + struct spellparameter *par; /* fuer weitere Parameter */ } castorder; struct unit * co_get_caster(const struct castorder * co); @@ -139,27 +139,27 @@ extern "C" { #define FARCASTING (1<<0) /* ZAUBER [struct region x y] */ #define SPELLLEVEL (1<<1) /* ZAUBER [STUFE x] */ -#define OCEANCASTABLE (1<<2) /* Können auch nicht-Meermenschen auf +#define OCEANCASTABLE (1<<2) /* Koennen auch nicht-Meermenschen auf hoher See zaubern */ #define ONSHIPCAST (1<<3) /* kann auch auf von Land ablegenden Schiffen stehend gezaubert werden */ -#define TESTCANSEE (1<<4) /* alle Zielunits auf cansee prüfen */ +#define TESTCANSEE (1<<4) /* alle Zielunits auf cansee pruefen */ - /* ID's können zu drei unterschiedlichen Entitäten gehören: Einheiten, - * Gebäuden und Schiffen. */ + /* ID's koennen zu drei unterschiedlichen Entitaeten gehören: Einheiten, + * Gebaeuden und Schiffen. */ #define UNITSPELL (1<<5) /* ZAUBER .. [ ..] */ #define SHIPSPELL (1<<6) /* ZAUBER .. [ ..] */ #define BUILDINGSPELL (1<<7) /* ZAUBER .. [ ..] */ #define REGIONSPELL (1<<8) /* wirkt auf struct region */ #define GLOBALTARGET (1<<9) /* Ziel kann ausserhalb der region sein */ -#define PRECOMBATSPELL (1<<10) /* PRÄKAMPFZAUBER .. */ +#define PRECOMBATSPELL (1<<10) /* PRÄKAMPFZAUBER .. */ #define COMBATSPELL (1<<11) /* KAMPFZAUBER .. */ #define POSTCOMBATSPELL (1<<12) /* POSTKAMPFZAUBER .. */ #define ISCOMBATSPELL (PRECOMBATSPELL|COMBATSPELL|POSTCOMBATSPELL) -#define TESTRESISTANCE (1<<13) /* Zielobjekte auf Magieresistenz prüfen. not used in XML? */ +#define TESTRESISTANCE (1<<13) /* Zielobjekte auf Magieresistenz pruefen. not used in XML? */ #define NOTFAMILIARCAST (1<<14) /* not used by XML? */ #define ANYTARGET (UNITSPELL|REGIONSPELL|BUILDINGSPELL|SHIPSPELL) /* wirkt auf alle objekttypen (unit, ship, building, region) */ @@ -167,7 +167,7 @@ extern "C" { enum { SPC_FIX, /* Fixkosten */ SPC_LEVEL, /* Komponenten pro Level */ - SPC_LINEAR /* Komponenten pro Level und müssen vorhanden sein */ + SPC_LINEAR /* Komponenten pro Level und muessen vorhanden sein */ }; /* ------------------------------------------------------------- */ @@ -192,8 +192,8 @@ extern "C" { * * Spruchzauberrei und Gegenstandszauberrei werden getrennt behandelt. * Das macht u.a. bestimmte Fehlermeldungen einfacher, das - * identifizieren der Komponennten über den Missversuch ist nicht - * möglich + * identifizieren der Komponennten ueber den Missversuch ist nicht + * moeglich * Spruchzauberrei: 'ZAUBER [struct region x y] [STUFE a] "Spruchname" [Ziel]' * Gegenstandszauberrei: 'BENUTZE "Gegenstand" [Ziel]' * @@ -222,46 +222,46 @@ extern "C" { bool is_familiar(const struct unit *u); /* gibt true, wenn eine Familiar-Relation besteht. */ - /* Sprüche */ + /* Sprueche */ int get_combatspelllevel(const struct unit *u, int nr); /* versucht, eine eingestellte maximale Kampfzauberstufe - * zurückzugeben. 0 = Maximum, -1 u ist kein Magier. */ + * zurueckzugeben. 0 = Maximum, -1 u ist kein Magier. */ const struct spell *get_combatspell(const struct unit *u, int nr); - /* gibt den Kampfzauber nr [pre/kampf/post] oder NULL zurück */ + /* gibt den Kampfzauber nr [pre/kampf/post] oder NULL zurueck */ void set_combatspell(struct unit *u, struct spell * sp, struct order *ord, int level); /* setzt Kampfzauber */ void unset_combatspell(struct unit *u, struct spell * sp); - /* löscht Kampfzauber */ - /* fügt den Spruch mit der Id spellid der Spruchliste der Einheit hinzu. */ + /* loescht Kampfzauber */ + /* fuegt den Spruch mit der Id spellid der Spruchliste der Einheit hinzu. */ int u_hasspell(const struct unit *u, const struct spell *sp); - /* prüft, ob der Spruch in der Spruchliste der Einheit steht. */ + /* prueft, ob der Spruch in der Spruchliste der Einheit steht. */ void pick_random_spells(struct faction *f, int level, struct spellbook * book, int num_spells); bool knowsspell(const struct region *r, const struct unit *u, const struct spell * sp); - /* prüft, ob die Einheit diesen Spruch gerade beherrscht, dh - * mindestens die erforderliche Stufe hat. Hier können auch Abfragen - * auf spezielle Antimagiezauber auf Regionen oder Einheiten eingefügt + /* prueft, ob die Einheit diesen Spruch gerade beherrscht, dh + * mindestens die erforderliche Stufe hat. Hier koennen auch Abfragen + * auf spezielle Antimagiezauber auf Regionen oder Einheiten eingefuegt * werden */ /* Magiepunkte */ int get_spellpoints(const struct unit *u); - /* Gibt die aktuelle Anzahl der Magiepunkte der Einheit zurück */ + /* Gibt die aktuelle Anzahl der Magiepunkte der Einheit zurueck */ void set_spellpoints(struct unit *u, int sp); /* setzt die Magiepunkte auf sp */ int change_spellpoints(struct unit *u, int mp); - /* verändert die Anzahl der Magiepunkte der Einheit um +mp */ + /* veraendert die Anzahl der Magiepunkte der Einheit um +mp */ int max_spellpoints_depr(const struct region *r, const struct unit *u); int max_spellpoints(const struct unit *u, const struct region *r); - /* gibt die aktuell maximal möglichen Magiepunkte der Einheit zurück */ + /* gibt die aktuell maximal moeglichen Magiepunkte der Einheit zurueck */ int change_maxspellpoints(struct unit *u, int csp); - /* verändert die maximalen Magiepunkte einer Einheit */ + /* veraendert die maximalen Magiepunkte einer Einheit */ /* Zaubern */ extern double spellpower(struct region *r, struct unit *u, const struct spell * sp, int cast_level, struct order *ord); - /* ermittelt die Stärke eines Spruchs */ + /* ermittelt die Staerke eines Spruchs */ bool fumble(struct region *r, struct unit *u, const struct spell * sp, int cast_level); /* true, wenn der Zauber misslingt, bei false gelingt der Zauber */ @@ -275,51 +275,51 @@ extern "C" { struct unit * familiar, const struct spell * sp, struct region * r, int lev, double force, int range, struct order * ord, struct spellparameter * p); void free_castorder(struct castorder *co); - /* Zwischenspreicher für Zauberbefehle, notwendig für Prioritäten */ + /* Zwischenspreicher fuer Zauberbefehle, notwendig für Prioritaeten */ void add_castorder(struct spellrank *cll, struct castorder *co); - /* Hänge c-order co an die letze c-order von cll an */ + /* Haenge c-order co an die letze c-order von cll an */ void free_castorders(struct castorder *co); /* Speicher wieder freigeben */ int cast_spell(struct castorder *co); - /* Prüfroutinen für Zaubern */ + /* Pruefroutinen für Zaubern */ int countspells(struct unit *u, int step); int spellcount(const struct unit *u); - /* erhöht den Counter für Zaubersprüche um 'step' und gibt die neue - * Anzahl der gezauberten Sprüche zurück. */ + /* erhoeht den Counter fuer Zaubersprüche um 'step' und gibt die neue + * Anzahl der gezauberten Sprueche zurück. */ int auracost(const struct unit *caster, const struct spell *sp); int spellcost(const struct unit *caster, const struct spell_component *spc); - /* gibt die für diesen Spruch derzeit notwendigen Magiepunkte auf der - * geringstmöglichen Stufe zurück, schon um den Faktor der bereits - * zuvor gezauberten Sprüche erhöht */ + /* gibt die fuer diesen Spruch derzeit notwendigen Magiepunkte auf der + * geringstmoeglichen Stufe zurueck, schon um den Faktor der bereits + * zuvor gezauberten Sprueche erhoeht */ bool cancast(struct unit *u, const struct spell * spruch, int eff_stufe, int distance, struct order *ord); - /* true, wenn Einheit alle Komponenten des Zaubers (incl. MP) für die - * geringstmögliche Stufe hat und den Spruch beherrscht */ + /* true, wenn Einheit alle Komponenten des Zaubers (incl. MP) fuer die + * geringstmoegliche Stufe hat und den Spruch beherrscht */ void pay_spell(struct unit *mage, const struct unit *caster, const struct spell * sp, int eff_stufe, int distance); /* zieht die Komponenten des Zaubers aus dem Inventory der Einheit - * ab. Die effektive Stufe des gezauberten Spruchs ist wichtig für + * ab. Die effektive Stufe des gezauberten Spruchs ist wichtig fuer * die korrekte Bestimmung der Magiepunktkosten */ int eff_spelllevel(struct unit *mage, struct unit *caster, const struct spell * sp, int cast_level, int distance); /* ermittelt die effektive Stufe des Zaubers. Dabei ist cast_level - * die gewünschte maximale Stufe (im Normalfall Stufe des Magiers, + * die gewuenschte maximale Stufe (im Normalfall Stufe des Magiers, * bei Farcasting Stufe*2^Entfernung) */ bool is_magic_resistant(struct unit *magician, struct unit *target, int resist_bonus); - /* Mapperfunktion für target_resists_magic() vom Typ struct unit. */ + /* Mapperfunktion fuer target_resists_magic() vom Typ struct unit. */ variant magic_resistance(struct unit *target); /* gibt die Chance an, mit der einem Zauber widerstanden wird. Je - * größer, desto resistenter ist da Opfer */ + * groesser, desto resistenter ist da Opfer */ bool target_resists_magic(struct unit *magician, void *obj, int objtyp, int resist_bonus); - /* gibt false zurück, wenn der Zauber gelingt, true, wenn das Ziel + /* gibt false zurueck, wenn der Zauber gelingt, true, wenn das Ziel * widersteht */ extern struct spell * unit_getspell(struct unit *u, const char *s, const struct locale *lang); const char *magic_name(magic_t mtype, const struct locale *lang); - /* Sprüche in der struct region */ + /* Sprueche in der struct region */ /* (sind in curse) */ void set_familiar(struct unit * mage, struct unit * familiar); struct unit *get_familiar(const struct unit *u); diff --git a/src/modules/museum.c b/src/modules/museum.c index 7e3a04f2d..dcb9fce2f 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -141,7 +141,7 @@ order * ord) UNUSED_ARG(amount); - /* Prüfen ob in Eingangshalle */ + /* Pruefen ob in Eingangshalle */ if (u->region->x != 9525 || u->region->y != 9525) { cmistake(u, ord, 266, MSG_MAGIC); return 0; @@ -152,7 +152,7 @@ order * ord) r = findregion(a->data.sa[0], a->data.sa[1]); assert(r); a_remove(&u->attribs, a); - /* Ãœbergebene Gegenstände zurückgeben */ + /* Übergebene Gegenstände zurückgeben */ a = a_find(u->attribs, &at_museumgivebackcookie); if (a) { @@ -177,7 +177,7 @@ order * ord) } } - /* Benutzer zurück teleportieren */ + /* Benutzer zurueck teleportieren */ move_unit(u, r, NULL); /* Exitticket abziehen */ @@ -210,8 +210,8 @@ order * ord) return 0; } - /* In diesem Attribut merken wir uns, wohin die Einheit zurückgesetzt - * wird, wenn sie das Museum verläßt. */ + /* In diesem Attribut merken wir uns, wohin die Einheit zurueckgesetzt + * wird, wenn sie das Museum verlaesst. */ a = a_add(&u->attribs, a_new(&at_museumexit)); a->data.sa[0] = (short)r->x; diff --git a/src/move.h b/src/move.h index 754b708aa..d08a8211d 100644 --- a/src/move.h +++ b/src/move.h @@ -46,11 +46,11 @@ extern "C" { #define BP_NORMAL 3 #define BP_ROAD 2 - /* die Zahlen sind genau äquivalent zu den race Flags */ + /* die Zahlen sind genau aequivalent zu den race Flags */ #define MV_CANNOTMOVE (1<<5) #define MV_FLY (1<<7) /* kann fliegen */ #define MV_SWIM (1<<8) /* kann schwimmen */ -#define MV_WALK (1<<9) /* kann über Land gehen */ +#define MV_WALK (1<<9) /* kann ueber Land gehen */ #define HORSES_PER_CART 2 /* number of horses for a cart */ #define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ diff --git a/src/piracy.c b/src/piracy.c index b7307c070..ced1f61aa 100644 --- a/src/piracy.c +++ b/src/piracy.c @@ -140,7 +140,7 @@ void piracy_cmd(unit * u) if (target_dir == NODIRECTION) { int saff = 0; direction_t dir; - /* Einheit ist also Kapitän. Jetzt gucken, in wievielen + /* Einheit ist also Kapitaen. Jetzt gucken, in wievielen * Nachbarregionen potentielle Opfer sind. */ for (dir = 0; dir < MAXDIRECTIONS; dir++) { @@ -205,7 +205,7 @@ void piracy_cmd(unit * u) /* FIXME: when u->thisorder == ord, set_order calls free, destroys both. */ ord = create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[target_dir])); - /* Bewegung ausführen */ + /* Bewegung ausfuehren */ init_order_depr(ord); move_cmd(u, ord); free_order(ord); diff --git a/src/reports.c b/src/reports.c index 92397b574..fdfa6b917 100644 --- a/src/reports.c +++ b/src/reports.c @@ -409,7 +409,7 @@ void report_raceinfo(const struct race *rc, const struct locale *lang, struct sb sbs_strcat(sbp, ": "); sbs_strcat(sbp, str_itoa(rc->df_default + rc->df_bonus)); - /* b_armor : Rüstung */ + /* b_armor : Ruestung */ if (rc->armor > 0) { sbs_strcat(sbp, ", "); sbs_strcat(sbp, LOC(lang, "stat_armor")); diff --git a/src/spells/borders.h b/src/spells/borders.h index 40bc55682..6c9828216 100644 --- a/src/spells/borders.h +++ b/src/spells/borders.h @@ -9,8 +9,8 @@ extern "C" { extern void register_borders(void); - /* für Feuerwände: in movement muß das noch explizit getestet werden. - ** besser wäre eine blcok_type::move() routine, die den effekt + /* fuer Feuerwaende: in movement muss das noch explizit getestet werden. + ** besser waere eine blcok_type::move() routine, die den effekt ** der Bewegung auf eine struct unit anwendet. **/ extern struct border_type bt_chaosgate; diff --git a/src/spells/buildingcurse.c b/src/spells/buildingcurse.c index e1eff8988..61acfbcee 100644 --- a/src/spells/buildingcurse.c +++ b/src/spells/buildingcurse.c @@ -80,7 +80,7 @@ const struct curse_type ct_magicwalls = { "magicwalls", CURSETYP_NORM, CURSE_ONLYONE|CURSE_NOAGE, NO_MERGE, cinfo_building }; -/* Feste Mauer - Präkampfzauber, wirkt nur 1 Runde */ +/* Feste Mauer - Praekampfzauber, wirkt nur 1 Runde */ const struct curse_type ct_strongwall = { "strongwall", CURSETYP_NORM, 0, NO_MERGE, NULL }; diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 7622b536f..d984715c1 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -87,7 +87,7 @@ const struct curse_type ct_gbdream = { /* --------------------------------------------------------------------- */ /* * C_MAGICSTREET - * erzeugt Straßennetz + * erzeugt Strassennetz */ static message *cinfo_magicstreet(const void *obj, objtype_t typ, const curse * c, int self) @@ -97,7 +97,7 @@ static message *cinfo_magicstreet(const void *obj, objtype_t typ, const curse * UNUSED_ARG(obj); assert(typ == TYP_REGION); - /* Warnung vor Auflösung */ + /* Warnung vor Aufloesung */ if (c->duration >= 2) { return msg_message("curseinfo::magicstreet", "id", c->no); } @@ -120,7 +120,7 @@ static message *cinfo_antimagiczone(const void *obj, objtype_t typ, const curse UNUSED_ARG(obj); assert(typ == TYP_REGION); - /* Magier spüren eine Antimagiezone */ + /* Magier spueren eine Antimagiezone */ if (self != 0) { return msg_message("curseinfo::antimagiczone", "id", c->no); } @@ -128,7 +128,7 @@ static message *cinfo_antimagiczone(const void *obj, objtype_t typ, const curse return NULL; } -/* alle Magier können eine Antimagiezone wahrnehmen */ +/* alle Magier koennen eine Antimagiezone wahrnehmen */ static int cansee_antimagiczone(const struct faction *viewer, const void *obj, objtype_t typ, const curse * c, int self) @@ -170,7 +170,7 @@ static message *cinfo_farvision(const void *obj, objtype_t typ, const curse * c, assert(typ == TYP_REGION); - /* Magier spüren eine farvision */ + /* Magier spueren eine farvision */ if (self != 0) { return msg_message("curseinfo::farvision", "id", c->no); } @@ -232,7 +232,7 @@ const struct curse_type ct_badlearn = { cinfo_simple }; -/* Trübsal-Zauber */ +/* Truebsal-Zauber */ const struct curse_type ct_depression = { "depression", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), @@ -268,7 +268,7 @@ const struct curse_type ct_badmagicresistancezone = { cinfo_simple }; -/* erhöht Magieresistenz von aliierten Einheiten, wirkt nur 1x pro +/* erhoeht Magieresistenz von aliierten Einheiten, wirkt nur 1x pro * Einheit */ const struct curse_type ct_goodmagicresistancezone = { "goodmagicresistancezone", diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index d0b381050..1d476a7be 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -42,7 +42,7 @@ /* * C_AURA */ -/* erhöht/senkt regeneration und maxaura um effect% */ +/* erhoeht/senkt regeneration und maxaura um effect% */ static message *cinfo_auraboost(const void *obj, objtype_t typ, const curse * c, int self) { diff --git a/src/tools/namegen.c b/src/tools/namegen.c index 2abcd0007..2e277ce0c 100644 --- a/src/tools/namegen.c +++ b/src/tools/namegen.c @@ -125,7 +125,7 @@ static char *entish_syllable2[] = { }; static char *entish_syllable3[] = { - "Hüter", "Pflanzer", "Hirte", "Wächter", "Wachser", "Beschützer", + "Hueter", "Pflanzer", "Hirte", "Waechter", "Wachser", "Beschützer", }; static char *cthuloid_syllable1[] = { From 92725faee67094bf65a36a6c8c76cf75399c0296 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 4 Jan 2019 21:34:37 +0100 Subject: [PATCH 51/85] New tests for give_unit and migrants. --- src/give.test.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/give.test.c b/src/give.test.c index c62973388..b748d1912 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -58,6 +58,7 @@ static void setup_give(struct give *env) { env->f1->locale = env->lang; } + config_set("rules.give.max_men", "-1"); /* success messages: */ mt_create_va(mt_new("receive_person", NULL), "unit:unit", "target:unit", "amount:int", MT_NEW_END); mt_create_va(mt_new("give_person", NULL), "unit:unit", "target:unit", "amount:int", MT_NEW_END); @@ -67,6 +68,8 @@ static void setup_give(struct give *env) { mt_create_va(mt_new("give", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END); mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END); /* error messages: */ + mt_create_error(120); + mt_create_error(128); mt_create_error(129); mt_create_error(96); mt_create_error(10); @@ -88,10 +91,14 @@ static void test_give_unit(CuTest * tc) { env.f1 = test_create_faction(NULL); env.f2 = test_create_faction(NULL); setup_give(&env); + CuAssertIntEquals(tc, 1, env.f1->num_units); + CuAssertIntEquals(tc, 1, env.f2->num_units); + config_set("rules.give.max_men", "0"); give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f1, env.src->faction); CuAssertIntEquals(tc, 0, env.f2->newbies); + config_set("rules.give.max_men", "-1"); give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f2, env.src->faction); @@ -99,6 +106,42 @@ static void test_give_unit(CuTest * tc) { CuAssertPtrEquals(tc, NULL, env.f1->units); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person")); + + test_teardown(); +} + +static void test_give_unit_humans(CuTest * tc) { + struct give env = { 0 }; + race *rc; + + test_setup_ex(tc); + env.f1 = test_create_faction(test_create_race("elf")); + env.f2 = test_create_faction(rc = test_create_race("human")); + rc->flags |= RCF_MIGRANTS; + setup_give(&env); + + give_unit(env.src, env.dst, NULL); + CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "error128")); + CuAssertIntEquals(tc, 0, env.f2->newbies); + + scale_number(env.dst, 57); + CuAssertIntEquals(tc, 1, count_maxmigrants(env.f2)); + give_unit(env.src, env.dst, NULL); + CuAssertIntEquals(tc, 1, env.f2->newbies); + test_teardown(); +} + +static void test_give_unit_other_race(CuTest * tc) { + struct give env = { 0 }; + test_setup_ex(tc); + env.f1 = test_create_faction(test_create_race("elf")); + env.f2 = test_create_faction(test_create_race("orc")); + setup_give(&env); + scale_number(env.dst, 57); + CuAssertIntEquals(tc, 0, count_maxmigrants(env.f2)); + give_unit(env.src, env.dst, NULL); + CuAssertIntEquals(tc, 0, env.f2->newbies); + CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "error120")); test_teardown(); } @@ -108,9 +151,8 @@ static void test_give_unit_limits(CuTest * tc) { env.f1 = test_create_faction(NULL); env.f2 = test_create_faction(NULL); setup_give(&env); - CuAssertIntEquals(tc, 1, env.f1->num_units); - CuAssertIntEquals(tc, 1, env.f2->num_units); config_set("rules.limit.faction", "1"); + give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f1, env.src->faction); CuAssertIntEquals(tc, 0, env.f2->newbies); @@ -497,6 +539,8 @@ CuSuite *get_give_suite(void) SUITE_ADD_TEST(suite, test_give_men_requires_contact); SUITE_ADD_TEST(suite, test_give_men_not_to_self); SUITE_ADD_TEST(suite, test_give_unit); + SUITE_ADD_TEST(suite, test_give_unit_humans); + SUITE_ADD_TEST(suite, test_give_unit_other_race); SUITE_ADD_TEST(suite, test_give_unit_limits); SUITE_ADD_TEST(suite, test_give_unit_to_ocean); SUITE_ADD_TEST(suite, test_give_unit_to_peasants); From cdb648b761482f6c442f83d20e2759cf18ac2566 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 5 Jan 2019 14:13:52 +0100 Subject: [PATCH 52/85] Check that groups are cleared when units are transferred. --- src/give.test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/give.test.c b/src/give.test.c index b748d1912..0aa99421a 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -87,12 +88,15 @@ static void setup_give(struct give *env) { static void test_give_unit(CuTest * tc) { struct give env = { 0 }; + test_setup_ex(tc); env.f1 = test_create_faction(NULL); env.f2 = test_create_faction(NULL); setup_give(&env); + CuAssertIntEquals(tc, 1, env.f1->num_units); CuAssertIntEquals(tc, 1, env.f2->num_units); + join_group(env.src, "group"); config_set("rules.give.max_men", "0"); give_unit(env.src, env.dst, NULL); @@ -102,6 +106,7 @@ static void test_give_unit(CuTest * tc) { config_set("rules.give.max_men", "-1"); give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f2, env.src->faction); + CuAssertPtrEquals(tc, NULL, get_group(env.src)); CuAssertIntEquals(tc, 1, env.f2->newbies); CuAssertPtrEquals(tc, NULL, env.f1->units); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person")); From b5624e6a8ac32f07851cce93bf5ef74fe6aae9fc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 8 Jan 2019 19:51:42 +0100 Subject: [PATCH 53/85] Some tests for WORK and wages. --- scripts/tests/e2/production.lua | 85 ++++++++++++++++++++++++++++++++- src/bind_region.c | 19 ++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 852d8f629..80d3447d2 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -108,7 +108,7 @@ end function test_build_boat_high_skill() local r = region.create(0, 0, "plain") - local f = faction.create("human", "skillz@example.com") + local f = faction.create("human") local u = unit.create(f, r, 1) u:set_skill("shipcraft", 5) -- humans get +1 u:add_item("log", 10) @@ -118,3 +118,86 @@ function test_build_boat_high_skill() assert_equal(5, u.ship.size) assert_equal(5, u:get_item('log')) end + +function test_work() + eressea.settings.set("rules.peasants.growth.factor", "0") + local r = region.create(0, 0, "plain") + r:set_resource('peasant', 1) + r:set_resource('tree', 0) + local f = faction.create("human") + local u = unit.create(f, r, 1) + u:add_order('ARBEITE') + r:set_resource('money', 0) + + process_orders() + assert_equal(10, u:get_item('money')) + assert_equal(1, r:get_resource('money')) + b = building.create(r, 'castle') + + b.size = 2 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + process_orders() + assert_equal(10, u:get_item('money')) + assert_equal(1, r:get_resource('money')) + + b.size = 10 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + process_orders() + assert_equal(11, u:get_item('money')) + assert_equal(2, r:get_resource('money')) + + b.size = 50 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + process_orders() + assert_equal(12, u:get_item('money')) + assert_equal(3, r:get_resource('money')) + + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + b.size = 250 + process_orders() + assert_equal(13, u:get_item('money')) + assert_equal(4, r:get_resource('money')) + + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + b.size = 1250 + process_orders() + assert_equal(14, u:get_item('money')) + assert_equal(5, r:get_resource('money')) + + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + b.size = 6250 + process_orders() + assert_equal(15, u:get_item('money')) + assert_equal(6, r:get_resource('money')) +end + +function test_blessed_harvest() + eressea.settings.set("rules.peasants.growth.factor", "0") + local r = region.create(0, 0, "plain") + r:set_resource('peasant', 1) + r:set_resource('tree', 0) + local f = faction.create("human") + local u = unit.create(f, r, 1) + u:add_order('ARBEITE') + r:set_resource('money', 0) + r:add_curse('blessedharvest', nil, 2, 1, 1) -- duration, force, effect + + process_orders() + assert_equal(10, u:get_item('money')) -- only peasants benefit + assert_equal(2, r:get_resource('money')) -- peasants work +1 + + b = building.create(r, 'castle') + b.size = 6250 + r:set_resource('money', 0) + u:add_item('money', -u:get_item('money')) + assert_equal(1, r:get_curse('blessedharvest')) + process_orders() + assert_equal(15, u:get_item('money')) -- only peasants get +1 + assert_equal(7, r:get_resource('money')) -- peasants get +1 +end diff --git a/src/bind_region.c b/src/bind_region.c index 4a466b46f..414752cf6 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -699,6 +699,24 @@ static int tolua_distance(lua_State * L) return 1; } +static int tolua_region_add_curse(lua_State *L) { + region *r = (region *)tolua_tousertype(L, 1, NULL); + const char *name = tolua_tostring(L, 2, NULL); + const curse_type *ctype = ct_find(name); + if (ctype) { + unit *u = (unit *)tolua_tousertype(L, 3, NULL); + int duration = (int)tolua_tonumber(L, 4, 1); + double vigour = tolua_tonumber(L, 5, 0.0); + int effect = (int)tolua_tonumber(L, 6, vigour/2); + curse * c = create_curse(u, &r->attribs, ctype, vigour, duration, effect, 0); + if (c) { + lua_pushinteger(L, c->no); + return 1; + } + } + return 0; +} + static int tolua_region_get_curse(lua_State *L) { region *self = (region *)tolua_tousertype(L, 1, NULL); const char *name = tolua_tostring(L, 2, NULL); @@ -741,6 +759,7 @@ void tolua_region_open(lua_State * L) tolua_function(L, TOLUA_CAST "count_msg_type", tolua_region_count_msg_type); + tolua_function(L, TOLUA_CAST "add_curse", &tolua_region_add_curse); tolua_function(L, TOLUA_CAST "get_curse", &tolua_region_get_curse); tolua_function(L, TOLUA_CAST "has_attrib", &tolua_region_has_attrib); /* flags */ From 9b3e651e9fd0fd527d1783015c3d6c05372b2b7e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Jan 2019 08:05:05 +0100 Subject: [PATCH 54/85] missing newline --- src/report.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/report.c b/src/report.c index fd73f6369..ffd6baf15 100644 --- a/src/report.c +++ b/src/report.c @@ -1179,6 +1179,7 @@ static void statistics(struct stream *out, const region * r, const faction * f) m = msg_message("nr_stat_header", "region", r); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); + newline(out); paragraph(out, buf, 0, 0, 0); newline(out); From acbbf42db12393f2795793c8867ce830a382afe1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Jan 2019 21:26:48 +0100 Subject: [PATCH 55/85] write a warning in the template about password replacement. for new factions, put the generated password into the template. normalize and secure password generation. --- res/translations/strings.de.po | 3 +++ res/translations/strings.en.po | 3 +++ src/kernel/faction.c | 9 +++++---- src/kernel/faction.h | 2 +- src/report.c | 16 ++++++++++----- src/reports.c | 9 ++++++--- src/reports.h | 3 ++- src/reports.test.c | 36 +++++++++++++++++----------------- src/util/password.c | 9 +++++++++ src/util/password.h | 2 ++ 10 files changed, 60 insertions(+), 32 deletions(-) diff --git a/res/translations/strings.de.po b/res/translations/strings.de.po index 89875baf5..8720fc85d 100644 --- a/res/translations/strings.de.po +++ b/res/translations/strings.de.po @@ -6015,6 +6015,9 @@ msgstr "Eigentümer" msgid "nr_template" msgstr "Vorlage für den nächsten Zug:" +msgid "template_password_notice" +msgstr "Achtung: Hier muss das Passwort Deiner Partei eingefügt werden." + msgctxt "skill" msgid "espionage" msgstr "Spionage" diff --git a/res/translations/strings.en.po b/res/translations/strings.en.po index 8a5dcb30f..d096a77ae 100644 --- a/res/translations/strings.en.po +++ b/res/translations/strings.en.po @@ -5323,6 +5323,9 @@ msgstr "Owner" msgid "nr_template" msgstr "Template for the next turn:" +msgid "template_password_notice" +msgstr "Attention: Enter your faction's password here." + msgctxt "skill" msgid "espionage" msgstr "espionage" diff --git a/src/kernel/faction.c b/src/kernel/faction.c index dbf11359e..fc1de186a 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -205,10 +205,11 @@ static int unused_faction_id(void) return id; } -void faction_genpassword(faction *f) { - const char * password = itoa36(rng_int()); - faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT)); - ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); +char *faction_genpassword(faction *f, char *buffer) { + password_generate(buffer, 8); + faction_setpassword(f, password_hash(buffer, PASSWORD_DEFAULT)); + ADDMSG(&f->msgs, msg_message("changepasswd", "value", buffer)); + return buffer; } faction *addfaction(const char *email, const char *password, diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 438402286..cbe4c7008 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -150,7 +150,7 @@ extern "C" { const char *faction_getemail(const struct faction *self); void faction_setemail(struct faction *self, const char *email); - void faction_genpassword(struct faction *f); + char *faction_genpassword(struct faction *f, char *buffer); void faction_setpassword(struct faction *self, const char *pwhash); const char *faction_getpassword(const struct faction *f); bool valid_race(const struct faction *f, const struct race *rc); diff --git a/src/report.c b/src/report.c index ffd6baf15..2b6d618a0 100644 --- a/src/report.c +++ b/src/report.c @@ -1276,6 +1276,7 @@ report_template(const char *filename, report_context * ctx, const char *bom) stream strm = { 0 }, *out = &strm; char buf[4096]; sbstring sbs; + const char *password = "password"; if (F == NULL) { perror(filename); @@ -1287,12 +1288,17 @@ report_template(const char *filename, report_context * ctx, const char *bom) swrite(bom, 1, strlen(bom), out); } - newline(out); - rps_nowrap(out, LOC(lang, "nr_template")); - newline(out); - newline(out); + sprintf(buf, "; %s\n", LOC(lang, "nr_template")); + rps_nowrap(out, buf); - sprintf(buf, "%s %s \"password\"", LOC(lang, parameters[P_FACTION]), itoa36(f->no)); + if (ctx->password) { + password = ctx->password; + } + else { + sprintf(buf, "; %s\n", LOC(lang, "template_password_notice")); + rps_nowrap(out, buf); + } + sprintf(buf, "%s %s \"%s\"", LOC(lang, parameters[P_FACTION]), itoa36(f->no), password); rps_nowrap(out, buf); newline(out); newline(out); diff --git a/src/reports.c b/src/reports.c index fdfa6b917..10d00600b 100644 --- a/src/reports.c +++ b/src/reports.c @@ -71,6 +71,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "util/log.h" #include "util/macros.h" #include "util/path.h" +#include "util/password.h" #include "util/strings.h" #include "util/translation.h" #include @@ -1480,7 +1481,7 @@ void report_warnings(faction *f, int now) * this function may also update ctx->last and ctx->first for potential * lighthouses and travelthru reports */ -void prepare_report(report_context *ctx, faction *f) +void prepare_report(report_context *ctx, faction *f, const char *password) { region *r; static int config; @@ -1496,6 +1497,7 @@ void prepare_report(report_context *ctx, faction *f) rule_lighthouse_units = config_get_int("rules.lighthouse.unit_capacity", 0) != 0; } + ctx->password = password; ctx->f = f; ctx->report_time = time(NULL); ctx->addresses = NULL; @@ -1597,15 +1599,16 @@ int write_reports(faction * f) struct report_context ctx; const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; report_type *rtype; + char buffer[PASSWORD_MAXSIZE], *password = NULL; if (noreports) { return false; } if (f->lastorders == 0 || f->age <= 1) { /* neue Parteien, oder solche die noch NIE einen Zug gemacht haben, * kriegen ein neues Passwort: */ - faction_genpassword(f); + password = faction_genpassword(f); } - prepare_report(&ctx, f); + prepare_report(&ctx, f, password); get_addresses(&ctx); log_debug("Reports for %s", factionname(f)); for (rtype = report_types; rtype != NULL; rtype = rtype->next) { diff --git a/src/reports.h b/src/reports.h index 91af51bc2..00b94c8a7 100644 --- a/src/reports.h +++ b/src/reports.h @@ -77,9 +77,10 @@ extern "C" { struct region *first, *last; void *userdata; time_t report_time; + const char *password; } report_context; - void prepare_report(report_context *ctx, struct faction *f); + void prepare_report(report_context *ctx, struct faction *f, const char *password); void finish_reports(report_context *ctx); void get_addresses(report_context * ctx); diff --git a/src/reports.test.c b/src/reports.test.c index a744532c5..7bea6c73c 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -338,11 +338,11 @@ static void test_newbie_password_message(CuTest *tc) { f = test_create_faction(NULL); f->age = 5; f->flags = 0; - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd")); f->age=2; - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd")); finish_reports(&ctx); @@ -365,7 +365,7 @@ static void test_prepare_travelthru(CuTest *tc) { test_create_unit(f2, r3); u = test_create_unit(f, r1); travelthru_add(r2, u); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, r3, ctx.last); CuAssertPtrEquals(tc, f, ctx.f); @@ -375,7 +375,7 @@ static void test_prepare_travelthru(CuTest *tc) { finish_reports(&ctx); CuAssertIntEquals(tc, seen_none, r2->seen.mode); - prepare_report(&ctx, f2); + prepare_report(&ctx, f2, NULL); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode); CuAssertIntEquals(tc, seen_unit, r3->seen.mode); @@ -399,7 +399,7 @@ static void test_get_addresses(CuTest *tc) { test_create_unit(f, r); test_create_unit(f1, r); test_create_unit(f2, r); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); get_addresses(&ctx); @@ -427,7 +427,7 @@ static void test_get_addresses_fstealth(CuTest *tc) { u = test_create_unit(f1, r); set_factionstealth(u, f2); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); get_addresses(&ctx); @@ -470,7 +470,7 @@ static void test_get_addresses_travelthru(CuTest *tc) { u = test_create_unit(f4, r1); set_level(u, SK_STEALTH, 1); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); get_addresses(&ctx); @@ -516,14 +516,14 @@ void test_prepare_lighthouse_capacity(CuTest *tc) { u2->building = b; set_level(u2, SK_PERCEPTION, 3); CuAssertPtrEquals(tc, NULL, inside_building(u2)); - prepare_report(&ctx, u1->faction); + prepare_report(&ctx, u1->faction, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode); finish_reports(&ctx); - prepare_report(&ctx, u2->faction); + prepare_report(&ctx, u2->faction, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); @@ -532,7 +532,7 @@ void test_prepare_lighthouse_capacity(CuTest *tc) { /* lighthouse capacity is # of units, not people: */ config_set_int("rules.lighthouse.unit_capacity", 1); - prepare_report(&ctx, u2->faction); + prepare_report(&ctx, u2->faction, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); @@ -567,7 +567,7 @@ static void test_prepare_lighthouse(CuTest *tc) { u = test_create_unit(f, r1); u->building = b; set_level(u, SK_PERCEPTION, 3); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); @@ -613,7 +613,7 @@ static void test_prepare_lighthouse_owners(CuTest *tc) u->building = b; region_set_owner(b->region, f, 0); CuAssertIntEquals(tc, 2, lighthouse_view_distance(b, NULL)); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); @@ -632,14 +632,14 @@ static void test_prepare_report(CuTest *tc) { f = test_create_faction(NULL); r = test_create_region(0, 0, NULL); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, NULL, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_none, r->seen.mode); finish_reports(&ctx); test_create_unit(f, r); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r->seen.mode); @@ -648,7 +648,7 @@ static void test_prepare_report(CuTest *tc) { r = test_create_region(2, 0, 0); CuAssertPtrEquals(tc, r, regions->next); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, regions, ctx.first); CuAssertPtrEquals(tc, r, ctx.last); CuAssertIntEquals(tc, seen_none, r->seen.mode); @@ -667,7 +667,7 @@ static void test_seen_neighbours(CuTest *tc) { r2 = test_create_region(1, 0, 0); test_create_unit(f, r1); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); @@ -694,7 +694,7 @@ static void test_seen_travelthru(CuTest *tc) { travelthru_add(r2, u); CuAssertPtrEquals(tc, r1, f->first); CuAssertPtrEquals(tc, r3, f->last); - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); @@ -772,7 +772,7 @@ static void test_report_far_vision(CuTest *tc) { CuAssertPtrEquals(tc, r1, f->first); CuAssertPtrEquals(tc, r2, f->last); report_context ctx; - prepare_report(&ctx, f); + prepare_report(&ctx, f, NULL); CuAssertPtrEquals(tc, r1, ctx.first); CuAssertPtrEquals(tc, NULL, ctx.last); CuAssertIntEquals(tc, seen_unit, r1->seen.mode); diff --git a/src/util/password.c b/src/util/password.c index aab16acee..79e21d8bc 100644 --- a/src/util/password.c +++ b/src/util/password.c @@ -42,3 +42,12 @@ int password_verify(const char * pwhash, const char * passwd) { } return (strcmp(passwd, pwhash) == 0) ? VERIFY_OK : VERIFY_FAIL; } + +void password_generate(char *password, size_t length) { + char salt[BCRYPT_HASHSIZE]; + + assert(BCRYPT_HASHSIZE - 7 > length); + bcrypt_gensalt(4, salt); + memcpy(password, salt + 7, length); + password[length] = 0; +} diff --git a/src/util/password.h b/src/util/password.h index faa2a0a85..05be88578 100644 --- a/src/util/password.h +++ b/src/util/password.h @@ -1,6 +1,7 @@ #pragma once #include +#include typedef enum cryptalgo_t { PASSWORD_PLAINTEXT, PASSWORD_BCRYPT @@ -16,3 +17,4 @@ extern int bcrypt_workfactor; int password_verify(const char *hash, const char *passwd); const char * password_hash(const char *passwd, cryptalgo_t algo); bool password_is_implemented(cryptalgo_t algo); +void password_generate(char *password, size_t length); From 765e2c5c6134b819dd3fc876a95f6ae63edc7a21 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 13 Jan 2019 09:48:40 +0100 Subject: [PATCH 56/85] newline after travelthru message --- .gitignore | 1 + src/.report.c.swp | Bin 94208 -> 0 bytes src/report.c | 1 + 3 files changed, 2 insertions(+) delete mode 100644 src/.report.c.swp diff --git a/.gitignore b/.gitignore index 75ec9a227..98b1e8e0a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ ipch/ *~ *.pyc *.bak +*.swp bin/ build*/ *.log diff --git a/src/.report.c.swp b/src/.report.c.swp deleted file mode 100644 index c7bb683f30632149b501dca349765d98c985f1bb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 94208 zcmeFa2Yg&vdG|jA2qmzv%PuXHYb~}_UABd_yJ5Bgxy08AhX#G;3)_J2P_G z2IM6`5(o<+^tupAV1Yn@g#ZgIz4uP&y@x=6P~PwFlzY!DlC>qt|Nnk;Kl*8A&OP-x z^?A;7o-?uGg5f>UgV${+@!Y*sy6&XgJp2j&@TaBSCzndKMx!a`<2^(8YY*(HRJS#o zhX(ewn(Jnp)yixx*!l~avkP;z_WB*Q!?oGw{9LWkSwG*ZAFgz2>uarAyIrfSpRRY- zw_DZqt=fFE)mc}~#j@hCLV*+e&U_xE(~FLR$;T!Zl89l1-R?)`O{_s)6cV}$}M6j-6a3I$duutI?q3an6I zg#s%SSfRiQ1#Ttc&~HCFTZQ z2>t?`1ip_j;Cy~`@DA{1a6Nc7 zcoz68PzQU!Zg4U<34D%9e=m3scr~~VTmzmA_JWhar)U%J0%KqlYy%GgrmeX4c2z0j zY1KLltwuDlFtxd49OSrr@AmH5N@Kb|nmg2}%+XnV*IJeCo}Qlm zrM;sW(rz{sOZ&j|DsgR%!Le4$Dh_uG#3!bQ9QoQBIZ@!I4_cl*;5s zKgf*@+D4_N(V6Oo8vRjswb^KQqUubg74`NcS?X%E$}tUWak>a^(w?q$%F`5e61|vi z5w<^CGd)RB&D#oUGObQ`oW6JWA)@I?OO$q}(y3Q%(&Xj9X=k2waC5Z2H`+OT(Vn4A zk$dmz?r>#xp%(S7FI`az1NQo8%Qlm)Jnc?vq1uUzo)4i^%{?d#9qrU;29!QB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pr3FGuFL+5=EKq`(Ovou8c`{BU-{dn)G}r`*<<#=ypWr>z%VaTlnHk4|Hw2qI zWHj`;tm}l>X1i~d?qT^7_*{fJE)tc?U%HHPae5`ITK@LtOeTv%E$*r}IZ?C5se*Xr z*K|Bx4Qy_2&USYB(9_rFFATT8lmEH2GUQKfgvEu_E?6iu@bS5&y!SsengIZ@43R_t diff --git a/src/report.c b/src/report.c index 2b6d618a0..2381fefdc 100644 --- a/src/report.c +++ b/src/report.c @@ -2170,6 +2170,7 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); report_travelthru(out, r, f); } + newline(out); if (wants_stats && r->seen.mode >= seen_unit) { statistics(out, r, f); From 1f95a46e6499a70020e6ac62b4df14cd4c4aa159 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 13 Jan 2019 19:17:31 +0100 Subject: [PATCH 57/85] =?UTF-8?q?Vereinfachte=20Statistik=20f=C3=BCr=20Dur?= =?UTF-8?q?chreiseregionen=20anzeigen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/creport.c | 2 +- src/report.c | 75 +++++++++++++++++++++++++++------------------------ 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/creport.c b/src/creport.c index 33401bc8f..45400f241 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1399,7 +1399,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) fprintf(F, "%d;Bauern\n", rpeasants(r)); fprintf(F, "%d;Pferde\n", rhorses(r)); - if (r->seen.mode >= seen_unit) { + if (r->seen.mode >= seen_travel) { if (rule_region_owners()) { faction *owner = region_get_owner(r); if (owner) { diff --git a/src/report.c b/src/report.c index 2381fefdc..79c154c50 100644 --- a/src/report.c +++ b/src/report.c @@ -1160,26 +1160,14 @@ void report_region(struct stream *out, const region * r, faction * f) static void statistics(struct stream *out, const region * r, const faction * f) { - const unit *u; - int number = 0, p = rpeasants(r); + int p = rpeasants(r); message *m; - item *itm, *items = NULL; char buf[4096]; - /* count */ - for (u = r->units; u; u = u->next) { - if (u->faction == f && !fval(u_race(u), RCF_INVISIBLE)) { - for (itm = u->items; itm; itm = itm->next) { - i_change(&items, itm->type, itm->number); - } - number += u->number; - } - } /* print */ m = msg_message("nr_stat_header", "region", r); nr_render(m, f->locale, buf, sizeof(buf), f); msg_release(m); - newline(out); paragraph(out, buf, 0, 0, 0); newline(out); @@ -1211,6 +1199,21 @@ static void statistics(struct stream *out, const region * r, const faction * f) paragraph(out, buf, 2, 2, 0); msg_release(m); + if (r->land->ownership) { + m = msg_message("nr_stat_morale", "morale", region_get_morale(r)); + nr_render(m, f->locale, buf, sizeof(buf), f); + paragraph(out, buf, 2, 2, 0); + msg_release(m); + } + + } + + /* info about units */ + if (r->seen.mode >= seen_unit) { + int number; + item *itm, *items = NULL; + unit *u; + if (!markets_module()) { if (buildingtype_exists(r, bt_find("caravan"), true)) { m = msg_message("nr_stat_luxuries", "max", (p * 2) / TRADE_FRACTION); @@ -1223,28 +1226,28 @@ static void statistics(struct stream *out, const region * r, const faction * f) msg_release(m); } - if (r->land->ownership) { - m = msg_message("nr_stat_morale", "morale", region_get_morale(r)); - nr_render(m, f->locale, buf, sizeof(buf), f); - paragraph(out, buf, 2, 2, 0); - msg_release(m); + /* count */ + for (number = 0, u = r->units; u; u = u->next) { + if (u->faction == f && !fval(u_race(u), RCF_INVISIBLE)) { + for (itm = u->items; itm; itm = itm->next) { + i_change(&items, itm->type, itm->number); + } + number += u->number; + } } - - } - /* info about units */ - - m = msg_message("nr_stat_people", "max", number); - nr_render(m, f->locale, buf, sizeof(buf), f); - paragraph(out, buf, 2, 2, 0); - msg_release(m); - - for (itm = items; itm; itm = itm->next) { - sprintf(buf, "%s: %d", - LOC(f->locale, resourcename(itm->type->rtype, GR_PLURAL)), itm->number); + m = msg_message("nr_stat_people", "max", number); + nr_render(m, f->locale, buf, sizeof(buf), f); paragraph(out, buf, 2, 2, 0); + msg_release(m); + + for (itm = items; itm; itm = itm->next) { + sprintf(buf, "%s: %d", + LOC(f->locale, resourcename(itm->type->rtype, GR_PLURAL)), itm->number); + paragraph(out, buf, 2, 2, 0); + } + while (items) + i_free(i_remove(&items, items)); } - while (items) - i_free(i_remove(&items, items)); } @@ -2172,9 +2175,11 @@ report_plaintext(const char *filename, report_context * ctx, } newline(out); - if (wants_stats && r->seen.mode >= seen_unit) { - statistics(out, r, f); - newline(out); + if (wants_stats && r->seen.mode >= seen_travel) { + if (r->land || r->seen.mode >= seen_unit) { + newline(out); + statistics(out, r, f); + } } /* Nachrichten an REGION in der Region */ From dea177cc5e3f4fb6410be0737474911d4a167f02 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 18 Jan 2019 22:26:55 +0100 Subject: [PATCH 58/85] MSVC debugger gets confused when two structs have the same name --- src/util/parser.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util/parser.c b/src/util/parser.c index f0090fdf3..3d1ba250d 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -15,14 +15,14 @@ #define ESCAPE_CHAR '\\' #define MAXTOKENSIZE 8192 -typedef struct parser_state { +typedef struct parse_state { const char *current_token; - struct parser_state *next; + struct parse_state *next; void *data; void(*dtor)(void *); -} parser_state; +} parse_state; -static parser_state *states; +static parse_state *states; static int eatwhitespace_c(const char **str_p) { @@ -57,7 +57,7 @@ static int eatwhitespace_c(const char **str_p) void init_tokens_ex(const char *initstr, void *data, void (*dtor)(void *)) { if (states == NULL) { - states = calloc(1, sizeof(parser_state)); + states = calloc(1, sizeof(parse_state)); if (!states) abort(); } else if (states->dtor) { @@ -74,7 +74,7 @@ void init_tokens_str(const char *initstr) { void parser_pushstate(void) { - parser_state *new_state = calloc(1, sizeof(parser_state)); + parse_state *new_state = calloc(1, sizeof(parse_state)); if (!new_state) abort(); new_state->current_token = NULL; new_state->next = states; @@ -83,7 +83,7 @@ void parser_pushstate(void) void parser_popstate(void) { - parser_state *new_state = states->next; + parse_state *new_state = states->next; if (states->dtor) { states->dtor(states->data); } From f054bdf8cfd0f51790949df11719b709f1251df5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 20 Jan 2019 16:51:04 +0100 Subject: [PATCH 59/85] BUG 2549 promote after recruit calculating max units before PROMOTE requires that all recruitment has finished. --- scripts/tests/common.lua | 18 ++++++++++++++++++ src/laws.c | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 2aec0fc0f..70e1b61e4 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1182,3 +1182,21 @@ function test_cartmaking() assert_equal(1, u:get_item('cart')) assert_equal(5, u:get_item('log')) end + +function test_promote_after_recruit() + local f = faction.create('human') + local r1 = region.create(0, 0, 'plain') + local r2 = region.create(1, 0, 'plain') + local u1 = unit.create(f, r1, 1) + u1.name = 'Xolgrim' + local u2 = unit.create(f, r2, 55) + u2:add_order('REKRUTIERE 1') + u1:add_order('BEFOERDERE') + u1:add_item('money', 57) + u2:add_item('money', 150) + local fl = u1.flags + process_orders() + assert_equal(56, u2.number) + assert_equal(fl + 128, u1.flags) -- UFL_HERO + assert_equal(0, u1:get_item('money')) +end diff --git a/src/laws.c b/src/laws.c index 421d1af31..68d90d6f8 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3840,6 +3840,10 @@ void init_processor(void) add_proc_region(p, do_force_leave, "kick non-allies out of buildings/ships"); } add_proc_region(p, economics, "Zerstoeren, Geben, Rekrutieren, Vergessen"); + + /* all recruitment must be finished before we can calculate + * promotion cost of ability */ + p += 10; add_proc_order(p, K_PROMOTION, promotion_cmd, 0, "Heldenbefoerderung"); p += 10; From 6f61ca87a794a967ae9675fb172f9159c36edacd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 22 Jan 2019 20:37:23 +0100 Subject: [PATCH 60/85] fix some weak splint warnings --- src/alchemy.c | 4 +-- src/kernel/building.c | 38 ++++++++++++++---------- src/kernel/gamedata.h | 2 +- src/kernel/messages.h | 2 +- src/util/strings.c | 68 +++++++++++++++++++++++-------------------- 5 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index b4e7f6253..a0bcf9ea9 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -67,7 +67,7 @@ void new_potiontype(item_type * itype, int level) potion_type *ptype; ptype = (potion_type *)calloc(1, sizeof(potion_type)); - assert(ptype); + assert(ptype != NULL); itype->flags |= ITF_POTION; ptype->itype = itype; ptype->level = level; @@ -120,7 +120,7 @@ void herbsearch(unit * u, int max_take) if (herbsfound) { produceexp(u, SK_HERBALISM, u->number); - i_change(&u->items, whichherb, herbsfound); + (void)i_change(&u->items, whichherb, herbsfound); ADDMSG(&u->faction->msgs, msg_message("herbfound", "unit region amount herb", u, r, herbsfound, whichherb->rtype)); } diff --git a/src/kernel/building.c b/src/kernel/building.c index 09a515fc3..fc90ebe94 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* kernel includes */ + #include "curse.h" #include "item.h" #include "unit.h" @@ -95,7 +96,7 @@ static int bt_changes = 1; bool bt_changed(int *cache) { - assert(cache); + assert(cache != NULL); if (*cache != bt_changes) { *cache = bt_changes; return true; @@ -108,7 +109,7 @@ static void bt_register(building_type * btype) size_t len; char data[64]; - selist_push(&buildingtypes, (void *)btype); + (void)selist_push(&buildingtypes, (void *)btype); len = cb_new_kv(btype->_name, strlen(btype->_name), &btype, sizeof(btype), data); assert(len <= sizeof(data)); cb_insert(&cb_bldgtypes, data, len); @@ -129,20 +130,25 @@ static void free_buildingtype(void *ptr) { free(btype); } +static building_type *bt_create(const char *name) { + building_type *btype = (building_type *)calloc(1, sizeof(building_type)); + if (!btype) abort(); + btype->_name = str_strdup(name); + btype->flags = BTF_DEFAULT; + btype->auraregen = 1.0; + btype->maxsize = -1; + btype->capacity = 1; + btype->maxcapacity = -1; + return btype; +} + building_type *bt_get_or_create(const char *name) { assert(name && name[0]); if (name != NULL) { building_type *btype = bt_find_i(name); if (btype == NULL) { - btype = (building_type *)calloc(1, sizeof(building_type)); - if (!btype) abort(); - btype->_name = str_strdup(name); - btype->flags = BTF_DEFAULT; - btype->auraregen = 1.0; - btype->maxsize = -1; - btype->capacity = 1; - btype->maxcapacity = -1; + btype = bt_create(name); bt_register(btype); } return btype; @@ -174,7 +180,7 @@ attrib_type at_building_generic_type = { /* TECH DEBT: simplest thing that works for E3 dwarf/halfling faction rules */ static int adjust_size(const building *b, int bsize) { - assert(b); + assert(b != NULL); if (config_get_int("rules.dwarf_castles", 0) && strcmp(b->type->_name, "castle") == 0) { unit *u = building_owner(b); @@ -190,7 +196,7 @@ static int adjust_size(const building *b, int bsize) { */ const char *buildingtype(const building_type * btype, const building * b, int bsize) { - assert(btype); + assert(btype != NULL); if (b && b->attribs) { if (is_building_type(btype, "generic")) { @@ -411,7 +417,7 @@ building *new_building(const struct building_type * btype, region * r, bname = parameters[P_GEBAEUDE]; } } - assert(bname); + assert(bname != NULL); snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no)); b->name = str_strdup(bname); return b; @@ -429,7 +435,7 @@ void remove_building(building ** blist, building * b) static const struct building_type *bt_caravan, *bt_dam, *bt_tunnel; static int btypes; - assert(bfindhash(b->no)); + assert(bfindhash(b->no) != NULL); if (bt_changed(&btypes)) { bt_caravan = bt_find("caravan"); @@ -690,7 +696,7 @@ bool in_safe_building(unit *u1, unit *u2) { } bool is_building_type(const struct building_type *btype, const char *name) { - assert(btype); + assert(btype != NULL); return name && strcmp(btype->_name, name)==0; } @@ -826,7 +832,7 @@ int cmp_wage(const struct building *b, const building * a) } int building_taxes(const building *b) { - assert(b); + assert(b != NULL); return b->type->taxes; } diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index 77469f9da..e14c0a551 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #ifndef _GAMEDATA_H #define _GAMEDATA_H diff --git a/src/kernel/messages.h b/src/kernel/messages.h index 7fa6996e2..ea0afc870 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -55,7 +55,7 @@ extern "C" { struct mlist ** merge_messages(message_list *ml, message_list *append); void split_messages(message_list *ml, struct mlist **split); -#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { add_message(msgs, mx); msg_release(mx); } } +#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { (void)add_message(msgs, mx); msg_release(mx); } } void syntax_error(const struct unit *u, struct order *ord); void cmistake(const struct unit *u, struct order *ord, int mno, int mtype); diff --git a/src/util/strings.c b/src/util/strings.c index 7f6cad26c..1158d40f4 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -64,8 +64,8 @@ size_t str_strlcpy(char *dst, const char *src, size_t len) register const char *s = src; register size_t n = len; - assert(src); - assert(dst); + assert(src != NULL); + assert(dst != NULL); /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { do { @@ -82,7 +82,7 @@ size_t str_strlcpy(char *dst, const char *src, size_t len) return (s - src) + strlen(s); /* count does not include NUL */ } - return (s - src - 1); /* count does not include NUL */ + return (size_t)(s - src - 1); /* count does not include NUL */ #endif } @@ -99,7 +99,7 @@ size_t str_strlcat(char *dst, const char *src, size_t len) /* Find the end of dst and adjust bytes left but don't go past end */ while (*d != '\0' && n-- != 0) d++; - dlen = d - dst; + dlen = (size_t)(d - dst); n = len - dlen; if (n == 0) @@ -143,7 +143,7 @@ void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, char *p = strstr(tmpl, var); size_t len; if (p) { - len = p - tmpl; + len = (size_t)(p - tmpl); } else { len = strlen(tmpl); @@ -170,7 +170,7 @@ void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, int str_hash(const char *s) { int key = 0; - assert(s); + assert(s != NULL); while (*s) { key = key * 37 + *s++; } @@ -200,17 +200,19 @@ unsigned int wang_hash(unsigned int a) } char *str_strdup(const char *s) { - if (s == NULL) return NULL; + if (s != NULL) { #ifdef HAVE_STRDUP - return strdup(s); + return strdup(s); #elif defined(_MSC_VER) - return _strdup(s); + return _strdup(s); #else - size_t len = strlen(s); - char *dup = malloc(len+1); - memcpy(dup, s, len+1); - return dup; + size_t len = strlen(s); + char *dup = malloc(len+1); + memcpy(dup, s, len+1); + return dup; #endif + } + return NULL; } void sbs_printf(struct sbstring *sbs, const char *format, ...) @@ -218,16 +220,18 @@ void sbs_printf(struct sbstring *sbs, const char *format, ...) size_t size = sbs->size - (sbs->end - sbs->begin); if (size > 0) { + int bytes; va_list argp; va_start(argp, format); - int bytes = vsnprintf(sbs->end, size, format, argp); + bytes = vsnprintf(sbs->end, size, format, argp); if (bytes > 0) { - if ((size_t)bytes >= size) { - bytes = size - 1; + size_t len = (size_t)bytes; + if (len >= size) { + len = size - 1; /* terminate truncated output */ - sbs->end[bytes] = '\0'; + sbs->end[len] = '\0'; } - sbs->end += bytes; + sbs->end += len; } va_end(argp); } @@ -235,7 +239,7 @@ void sbs_printf(struct sbstring *sbs, const char *format, ...) void sbs_init(struct sbstring *sbs, char *buffer, size_t size) { - assert(sbs); + assert(sbs != NULL); assert(size > 0); sbs->begin = buffer; sbs->size = size; @@ -246,7 +250,7 @@ void sbs_init(struct sbstring *sbs, char *buffer, size_t size) void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size) { size_t len = strlen(buffer); - assert(sbs); + assert(sbs != NULL); assert(size > len); sbs->begin = buffer; sbs->size = size; @@ -256,7 +260,7 @@ void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size) void sbs_strncat(struct sbstring *sbs, const char *str, size_t size) { size_t len; - assert(sbs); + assert(sbs != NULL); len = sbs->size - (sbs->end - sbs->begin) - 1; if (len < size) { size = len; @@ -269,21 +273,21 @@ void sbs_strncat(struct sbstring *sbs, const char *str, size_t size) void sbs_strcat(struct sbstring *sbs, const char *str) { size_t len; - assert(sbs); + assert(sbs != NULL); len = sbs->size - (sbs->end - sbs->begin); - str_strlcpy(sbs->end, str, len); + (void)str_strlcpy(sbs->end, str, len); sbs->end += strlen(sbs->end); assert(sbs->begin + sbs->size >= sbs->end); } void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len) { - if (pos > sbs->end - sbs->begin) { + if (sbs->begin + pos > sbs->end) { /* starting past end of string, do nothing */ sbs->end = sbs->begin; } if (pos >= 0) { - size_t sz = sbs->end - (sbs->begin + pos); + size_t sz = sbs->end - sbs->begin - pos; if (len > sz) len = sz; if (len - pos > 0) { memmove(sbs->begin, sbs->begin + pos, len); @@ -299,15 +303,15 @@ void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len) size_t sbs_length(const struct sbstring *sbs) { assert(sbs->begin + sbs->size >= sbs->end); - return sbs->end - sbs->begin; + return (size_t)(sbs->end - sbs->begin); } char *str_unescape(char *str) { char *read = str, *write = str; while (*read) { char * pos = strchr(read, '\\'); - if (pos) { - size_t len = pos - read; + if (pos > read) { + size_t len = (size_t)(pos - read); memmove(write, read, len); write += len; read += (len + 1); @@ -341,15 +345,15 @@ const char *str_escape_ex(const char *str, char *buffer, size_t size, const char { size_t slen = strlen(str); const char *read = str; - char *write = buffer; + unsigned char *write = (unsigned char *)buffer; if (size < 1) { return NULL; } while (slen > 0 && size > 1 && *read) { const char *pos = strpbrk(read, chars); size_t len = size; - if (pos) { - len = pos - read; + if (pos > read) { + len = (size_t)(pos - read); } if (len < size) { unsigned char ch = *(const unsigned char *)pos; @@ -399,7 +403,7 @@ const char *str_escape_ex(const char *str, char *buffer, size_t size, const char break; default: if (size > 5) { - int n = sprintf(write, "\\%03o", ch); + int n = snprintf((char *)write, size, "\\%03o", ch); if (n > 0) { assert(n == 5); write += n; From 6f771ace3eed036c5e034670b47d80a5948f908a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Jan 2019 14:24:18 +0100 Subject: [PATCH 61/85] re-undo splint warning fizes --- src/alchemy.c | 4 +-- src/kernel/building.c | 38 +++++++++++--------------- src/kernel/gamedata.h | 2 +- src/kernel/messages.h | 2 +- src/util/strings.c | 62 ++++++++++++++++++++----------------------- 5 files changed, 49 insertions(+), 59 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index a0bcf9ea9..b4e7f6253 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -67,7 +67,7 @@ void new_potiontype(item_type * itype, int level) potion_type *ptype; ptype = (potion_type *)calloc(1, sizeof(potion_type)); - assert(ptype != NULL); + assert(ptype); itype->flags |= ITF_POTION; ptype->itype = itype; ptype->level = level; @@ -120,7 +120,7 @@ void herbsearch(unit * u, int max_take) if (herbsfound) { produceexp(u, SK_HERBALISM, u->number); - (void)i_change(&u->items, whichherb, herbsfound); + i_change(&u->items, whichherb, herbsfound); ADDMSG(&u->faction->msgs, msg_message("herbfound", "unit region amount herb", u, r, herbsfound, whichherb->rtype)); } diff --git a/src/kernel/building.c b/src/kernel/building.c index fc90ebe94..09a515fc3 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* kernel includes */ - #include "curse.h" #include "item.h" #include "unit.h" @@ -96,7 +95,7 @@ static int bt_changes = 1; bool bt_changed(int *cache) { - assert(cache != NULL); + assert(cache); if (*cache != bt_changes) { *cache = bt_changes; return true; @@ -109,7 +108,7 @@ static void bt_register(building_type * btype) size_t len; char data[64]; - (void)selist_push(&buildingtypes, (void *)btype); + selist_push(&buildingtypes, (void *)btype); len = cb_new_kv(btype->_name, strlen(btype->_name), &btype, sizeof(btype), data); assert(len <= sizeof(data)); cb_insert(&cb_bldgtypes, data, len); @@ -130,25 +129,20 @@ static void free_buildingtype(void *ptr) { free(btype); } -static building_type *bt_create(const char *name) { - building_type *btype = (building_type *)calloc(1, sizeof(building_type)); - if (!btype) abort(); - btype->_name = str_strdup(name); - btype->flags = BTF_DEFAULT; - btype->auraregen = 1.0; - btype->maxsize = -1; - btype->capacity = 1; - btype->maxcapacity = -1; - return btype; -} - building_type *bt_get_or_create(const char *name) { assert(name && name[0]); if (name != NULL) { building_type *btype = bt_find_i(name); if (btype == NULL) { - btype = bt_create(name); + btype = (building_type *)calloc(1, sizeof(building_type)); + if (!btype) abort(); + btype->_name = str_strdup(name); + btype->flags = BTF_DEFAULT; + btype->auraregen = 1.0; + btype->maxsize = -1; + btype->capacity = 1; + btype->maxcapacity = -1; bt_register(btype); } return btype; @@ -180,7 +174,7 @@ attrib_type at_building_generic_type = { /* TECH DEBT: simplest thing that works for E3 dwarf/halfling faction rules */ static int adjust_size(const building *b, int bsize) { - assert(b != NULL); + assert(b); if (config_get_int("rules.dwarf_castles", 0) && strcmp(b->type->_name, "castle") == 0) { unit *u = building_owner(b); @@ -196,7 +190,7 @@ static int adjust_size(const building *b, int bsize) { */ const char *buildingtype(const building_type * btype, const building * b, int bsize) { - assert(btype != NULL); + assert(btype); if (b && b->attribs) { if (is_building_type(btype, "generic")) { @@ -417,7 +411,7 @@ building *new_building(const struct building_type * btype, region * r, bname = parameters[P_GEBAEUDE]; } } - assert(bname != NULL); + assert(bname); snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no)); b->name = str_strdup(bname); return b; @@ -435,7 +429,7 @@ void remove_building(building ** blist, building * b) static const struct building_type *bt_caravan, *bt_dam, *bt_tunnel; static int btypes; - assert(bfindhash(b->no) != NULL); + assert(bfindhash(b->no)); if (bt_changed(&btypes)) { bt_caravan = bt_find("caravan"); @@ -696,7 +690,7 @@ bool in_safe_building(unit *u1, unit *u2) { } bool is_building_type(const struct building_type *btype, const char *name) { - assert(btype != NULL); + assert(btype); return name && strcmp(btype->_name, name)==0; } @@ -832,7 +826,7 @@ int cmp_wage(const struct building *b, const building * a) } int building_taxes(const building *b) { - assert(b != NULL); + assert(b); return b->type->taxes; } diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index e14c0a551..77469f9da 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #ifndef _GAMEDATA_H #define _GAMEDATA_H diff --git a/src/kernel/messages.h b/src/kernel/messages.h index ea0afc870..7fa6996e2 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -55,7 +55,7 @@ extern "C" { struct mlist ** merge_messages(message_list *ml, message_list *append); void split_messages(message_list *ml, struct mlist **split); -#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { (void)add_message(msgs, mx); msg_release(mx); } } +#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { add_message(msgs, mx); msg_release(mx); } } void syntax_error(const struct unit *u, struct order *ord); void cmistake(const struct unit *u, struct order *ord, int mno, int mtype); diff --git a/src/util/strings.c b/src/util/strings.c index 1158d40f4..f26f460e2 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -64,8 +64,8 @@ size_t str_strlcpy(char *dst, const char *src, size_t len) register const char *s = src; register size_t n = len; - assert(src != NULL); - assert(dst != NULL); + assert(src); + assert(dst); /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { do { @@ -82,7 +82,7 @@ size_t str_strlcpy(char *dst, const char *src, size_t len) return (s - src) + strlen(s); /* count does not include NUL */ } - return (size_t)(s - src - 1); /* count does not include NUL */ + return (s - src - 1); /* count does not include NUL */ #endif } @@ -99,7 +99,7 @@ size_t str_strlcat(char *dst, const char *src, size_t len) /* Find the end of dst and adjust bytes left but don't go past end */ while (*d != '\0' && n-- != 0) d++; - dlen = (size_t)(d - dst); + dlen = d - dst; n = len - dlen; if (n == 0) @@ -143,7 +143,7 @@ void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, char *p = strstr(tmpl, var); size_t len; if (p) { - len = (size_t)(p - tmpl); + len = p - tmpl; } else { len = strlen(tmpl); @@ -170,7 +170,7 @@ void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, int str_hash(const char *s) { int key = 0; - assert(s != NULL); + assert(s); while (*s) { key = key * 37 + *s++; } @@ -200,19 +200,17 @@ unsigned int wang_hash(unsigned int a) } char *str_strdup(const char *s) { - if (s != NULL) { + if (s == NULL) return NULL; #ifdef HAVE_STRDUP - return strdup(s); + return strdup(s); #elif defined(_MSC_VER) - return _strdup(s); + return _strdup(s); #else - size_t len = strlen(s); - char *dup = malloc(len+1); - memcpy(dup, s, len+1); - return dup; + size_t len = strlen(s); + char *dup = malloc(len+1); + memcpy(dup, s, len+1); + return dup; #endif - } - return NULL; } void sbs_printf(struct sbstring *sbs, const char *format, ...) @@ -220,18 +218,16 @@ void sbs_printf(struct sbstring *sbs, const char *format, ...) size_t size = sbs->size - (sbs->end - sbs->begin); if (size > 0) { - int bytes; va_list argp; va_start(argp, format); - bytes = vsnprintf(sbs->end, size, format, argp); + int bytes = vsnprintf(sbs->end, size, format, argp); if (bytes > 0) { - size_t len = (size_t)bytes; - if (len >= size) { - len = size - 1; + if ((size_t)bytes >= size) { + bytes = size - 1; /* terminate truncated output */ - sbs->end[len] = '\0'; + sbs->end[bytes] = '\0'; } - sbs->end += len; + sbs->end += bytes; } va_end(argp); } @@ -239,7 +235,7 @@ void sbs_printf(struct sbstring *sbs, const char *format, ...) void sbs_init(struct sbstring *sbs, char *buffer, size_t size) { - assert(sbs != NULL); + assert(sbs); assert(size > 0); sbs->begin = buffer; sbs->size = size; @@ -250,7 +246,7 @@ void sbs_init(struct sbstring *sbs, char *buffer, size_t size) void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size) { size_t len = strlen(buffer); - assert(sbs != NULL); + assert(sbs); assert(size > len); sbs->begin = buffer; sbs->size = size; @@ -260,7 +256,7 @@ void sbs_adopt(struct sbstring *sbs, char *buffer, size_t size) void sbs_strncat(struct sbstring *sbs, const char *str, size_t size) { size_t len; - assert(sbs != NULL); + assert(sbs); len = sbs->size - (sbs->end - sbs->begin) - 1; if (len < size) { size = len; @@ -273,21 +269,21 @@ void sbs_strncat(struct sbstring *sbs, const char *str, size_t size) void sbs_strcat(struct sbstring *sbs, const char *str) { size_t len; - assert(sbs != NULL); + assert(sbs); len = sbs->size - (sbs->end - sbs->begin); - (void)str_strlcpy(sbs->end, str, len); + str_strlcpy(sbs->end, str, len); sbs->end += strlen(sbs->end); assert(sbs->begin + sbs->size >= sbs->end); } void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len) { - if (sbs->begin + pos > sbs->end) { + if (pos > sbs->end - sbs->begin) { /* starting past end of string, do nothing */ sbs->end = sbs->begin; } if (pos >= 0) { - size_t sz = sbs->end - sbs->begin - pos; + size_t sz = sbs->end - (sbs->begin + pos); if (len > sz) len = sz; if (len - pos > 0) { memmove(sbs->begin, sbs->begin + pos, len); @@ -303,14 +299,14 @@ void sbs_substr(sbstring *sbs, ptrdiff_t pos, size_t len) size_t sbs_length(const struct sbstring *sbs) { assert(sbs->begin + sbs->size >= sbs->end); - return (size_t)(sbs->end - sbs->begin); + return sbs->end - sbs->begin; } char *str_unescape(char *str) { char *read = str, *write = str; while (*read) { char * pos = strchr(read, '\\'); - if (pos > read) { + if (pos >= read) { size_t len = (size_t)(pos - read); memmove(write, read, len); write += len; @@ -352,8 +348,8 @@ const char *str_escape_ex(const char *str, char *buffer, size_t size, const char while (slen > 0 && size > 1 && *read) { const char *pos = strpbrk(read, chars); size_t len = size; - if (pos > read) { - len = (size_t)(pos - read); + if (pos >= read) { + len = pos - read; } if (len < size) { unsigned char ch = *(const unsigned char *)pos; From ebe1df4cb9629f406ea1c6cda425eef89eaebbaf Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Jan 2019 14:25:58 +0100 Subject: [PATCH 62/85] review some flawfinder warnings --- src/util/translation.c | 30 ++++++++++++++---------------- src/vortex.c | 4 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/util/translation.c b/src/util/translation.c index 4d032911e..44f252790 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -164,10 +164,10 @@ static void free_functions(void) void add_function(const char *symbol, evalfun parse) { - char token[64]; + char token[64]; /* Flawfinder: ignore */ size_t len = strlen(symbol); - assert(len + 1 + sizeof(parse) <= sizeof(token)); + assert(len + sizeof(parse) < sizeof(token)); len = cb_new_kv(symbol, len, &parse, sizeof(parse), token); cb_insert(&functions, token, len); } @@ -193,15 +193,17 @@ static const char *parse_symbol(opstack ** stack, const char *in, */ { bool braces = false; - char symbol[32]; + char symbol[32]; /* Flawfinder: ignore */ char *cp = symbol; /* current position */ if (*in == '{') { braces = true; ++in; } - while (isalnum(*in) || *in == '.') + while (isalnum(*in) || *in == '.') { *cp++ = *in++; + assert(cp < symbol + sizeof(symbol)); + } *cp = '\0'; /* symbol will now contain the symbol name */ if (*in == '(') { @@ -371,7 +373,7 @@ const char *translate(const char *format, const void *userdata, { unsigned int i = 0; const char *ic = vars; - char symbol[32]; + char symbol[32]; /* Flawfinder: ignore */ char *oc = symbol; opstack *stack = NULL; const char *rv; @@ -383,11 +385,15 @@ const char *translate(const char *format, const void *userdata, assert(*ic == 0 || isalnum(*ic)); while (*ic) { *oc++ = *ic++; + assert(oc < symbol + sizeof(symbol)); if (!isalnum(*ic)) { + size_t len; variant x = args[i++]; *oc = '\0'; + len = oc - symbol + 1; + str_strlcpy(oc = balloc(len), symbol, len); + add_variable(oc, x); oc = symbol; - add_variable(strcpy(balloc(strlen(symbol) + 1), symbol), x); while (*ic && !isalnum(*ic)) ++ic; } @@ -452,22 +458,15 @@ static void eval_if(opstack ** stack, const void *userdata) UNUSED_ARG(userdata); } -static void eval_strlen(opstack ** stack, const void *userdata) -{ /* string -> int */ - const char *c = (const char *)opop_v(stack); - opush_i(stack, c ? (int)strlen(c) : 0); - UNUSED_ARG(userdata); -} - #include "base36.h" static void eval_int(opstack ** stack, const void *userdata) { int i = opop_i(stack); const char *c = itoa10(i); - size_t len = strlen(c); + size_t size = strlen(c) + 1; /* Flawfinder: ignore */ variant var; - var.v = strcpy(balloc(len + 1), c); + str_strlcpy(var.v = balloc(size), c, size); opush(stack, var); } @@ -477,7 +476,6 @@ void translation_init(void) add_function("eq", &eval_eq); add_function("int", &eval_int); add_function("add", &eval_add); - add_function("strlen", &eval_strlen); add_function("if", &eval_if); add_function("isnull", &eval_isnull); } diff --git a/src/vortex.c b/src/vortex.c index 36945ca3f..616d8c57a 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -91,7 +91,7 @@ static int a_readdirection(variant *var, void *owner, struct gamedata *data) { struct storage *store = data->store; spec_direction *d = (spec_direction *)(var->v); - char lbuf[32]; + char lbuf[32]; /* Flawfinder: ignore */ (void)owner; READ_INT(store, &d->x); @@ -130,7 +130,7 @@ region *find_special_direction(const region * r, const char *token) { attrib *a; - if (strlen(token) == 0) + if (*token == '\0') return NULL; for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { From 92149757328945fdaa36b96d6e9b216c33f41034 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Jan 2019 16:18:58 +0100 Subject: [PATCH 63/85] reserve memory for backtrace before it runs out --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index bd5a92b46..6b80c0cb0 100644 --- a/src/main.c +++ b/src/main.c @@ -268,10 +268,10 @@ static int parse_args(int argc, char **argv) #ifdef HAVE_BACKTRACE #include #include +static void *btrace[50]; static void report_segfault(int signo, siginfo_t * sinf, void *arg) { - void *btrace[50]; size_t size; int fd = fileno(stderr); From 24eacbb40d2afc661dd06d8555c3baad40dc1d72 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Jan 2019 16:34:07 +0100 Subject: [PATCH 64/85] eliminate MIN and MAX macros --- src/items/weapons.c | 7 +++++-- src/kernel/region.c | 26 ++++++++++++++++++-------- src/kernel/ship.c | 9 ++++++--- src/kernel/unit.c | 6 ++++-- src/spells.c | 2 +- src/triggers/shock.c | 9 ++++++--- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/items/weapons.c b/src/items/weapons.c index 6c764b123..040fa0293 100644 --- a/src/items/weapons.c +++ b/src/items/weapons.c @@ -16,7 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include +#ifdef _MSC_VER +# include +#endif + #include "weapons.h" #include "battle.h" @@ -106,7 +109,7 @@ int *casualties) } enemies = count_enemies(b, af, FIGHT_ROW, FIGHT_ROW, SELECT_ADVANCE); - enemies = MIN(enemies, CATAPULT_ATTACKS); + if (enemies > CATAPULT_ATTACKS) enemies = CATAPULT_ATTACKS; if (enemies == 0) { return true; /* allow further attacks */ } diff --git a/src/kernel/region.c b/src/kernel/region.c index 4614f22bc..99e82d659 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -16,7 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include +#ifdef _MSC_VER +# include +#endif + #include "region.h" /* kernel includes */ @@ -141,8 +144,11 @@ const char *regionname(const region * r, const faction * f) int region_maxworkers(const region *r) { int size = max_production(r); - int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE; - return MAX(size - treespace, MIN(size / 10, 200)); + int treespace = size - (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE; + size /=10; + if (size > 200) size = 200; + if (treespace < size) treespace = size; + return treespace; } int deathcount(const region * r) @@ -400,7 +406,7 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height) int dx = x1 - x2; int dy = y1 - y2; int result, dist; - int mindist = MIN(width, height) >> 1; + int mindist = ((width > height) ? height : width) / 2; /* Bei negativem dy am Ursprung spiegeln, das veraendert * den Abstand nicht @@ -423,13 +429,15 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height) if (result <= mindist) return result; } - dist = MAX(dx, height - dy); + dist = height - dy; + if (dist < dx) dist = dx; if (dist >= 0 && dist < result) { result = dist; if (result <= mindist) return result; } - dist = MAX(width - dx, dy); + dist = width - dx; + if (dist < dy) dist = dy; if (dist >= 0 && dist < result) result = dist; return result; @@ -1097,7 +1105,8 @@ void init_region(region *r) if (!fval(r, RF_CHAOTIC)) { int peasants; peasants = (region_maxworkers(r) * (20 + dice(6, 10))) / 100; - rsetpeasants(r, MAX(100, peasants)); + if (peasants < 100) peasants = 100; + rsetpeasants(r, peasants); rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL, INT_MAX) + 1) + rng_int() % 5)); } @@ -1419,7 +1428,8 @@ faction *update_owners(region * r) else if (f || new_owner->faction != region_get_last_owner(r)) { alliance *al = region_get_alliance(r); if (al && new_owner->faction->alliance == al) { - int morale = MAX(0, region_get_morale(r) - MORALE_TRANSFER); + int morale = region_get_morale(r) - MORALE_TRANSFER; + if (morale < 0) morale = 0; region_set_morale(r, morale, turn); } else { diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 27de232e4..2ca3084fc 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -16,7 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include +#ifdef _MSC_VER +# include +#endif #include #include "ship.h" @@ -359,8 +361,9 @@ int shipspeed(const ship * sh, const unit * u) int crew = crew_skill(sh); int crew_bonus = (crew / sh->type->sumskill / 2) - 1; if (crew_bonus > 0) { - bonus = MIN(bonus, crew_bonus); - bonus = MIN(bonus, sh->type->range_max - sh->type->range); + int sbonus = sh->type->range_max - sh->type->range; + if (bonus > sbonus) bonus = sbonus; + if (bonus > crew_bonus) bonus = crew_bonus; } else { bonus = 0; diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 0778fc48e..c1e9264b9 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -16,7 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include +#ifdef _MSC_VER +# include +#endif #include #include "unit.h" @@ -1229,7 +1231,7 @@ int invisible(const unit * target, const unit * viewer) else { int hidden = item_invis(target); if (hidden) { - hidden = MIN(hidden, target->number); + if (hidden > target->number) hidden = target->number; if (viewer) { const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING); hidden -= i_get(viewer->items, rtype->itype); diff --git a/src/spells.c b/src/spells.c index 6a80858e3..2d6b820e1 100644 --- a/src/spells.c +++ b/src/spells.c @@ -4089,7 +4089,7 @@ static int sp_pump(castorder * co) * Betoert eine Einheit, so das sie ihm den groe�ten Teil ihres Bargelds * und 50% ihres Besitzes schenkt. Sie behaelt jedoch immer soviel, wie * sie zum ueberleben braucht. Wirkt gegen Magieresistenz. - * MIN(Stufe*1000$, u->money - maintenance) + * min(Stufe*1000$, u->money - maintenance) * Von jedem Item wird 50% abgerundet ermittelt und uebergeben. Dazu * kommt Itemzahl%2 mit 50% chance * diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 0d0177025..205439b46 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -16,7 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include +#ifdef _MSC_VER +# include +#endif + #include "shock.h" #include @@ -61,8 +64,8 @@ static void do_shock(unit * u, const char *reason) if (u->number > 0) { /* HP - Verlust */ int hp = (unit_max_hp(u) * u->number) / 10; - hp = MIN(u->hp, hp); - u->hp = MAX(1, hp); + if (hp > u->hp) hp = u->hp; + u->hp = (hp > 1) ? hp : 1; } /* Aura - Verlust */ From 3b81b7797f1bb471439ee0d99e3ee9e0f5b3c13d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Jan 2019 17:50:58 +0100 Subject: [PATCH 65/85] eliminate MAX/MIN macros completely --- src/academy.c | 2 +- src/battle.c | 114 +++++++++++++++++++----------------------- src/items/xerewards.c | 3 +- src/kernel/group.c | 2 +- src/kernel/order.c | 4 ++ src/kernel/pool.c | 4 +- src/kernel/pool.h | 4 +- src/kernel/save.c | 5 +- src/morale.c | 3 +- src/platform.h | 3 -- src/races/dragons.c | 5 +- src/races/zombies.c | 15 ++++-- 12 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/academy.c b/src/academy.c index 538d36e06..01ff9fd1c 100644 --- a/src/academy.c +++ b/src/academy.c @@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "study.h" void academy_teaching_bonus(struct unit *u, skill_t sk, int students) { - if (students && sk != NOSKILL) { + if (students > 0 && sk != NOSKILL) { /* actually students * EXPERIENCEDAYS / MAX_STUDENTS */ learn_skill(u, sk, students); } diff --git a/src/battle.c b/src/battle.c index f65a8d5d2..df937698f 100644 --- a/src/battle.c +++ b/src/battle.c @@ -16,7 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include +#endif + #include #include "battle.h" #include "alchemy.h" @@ -436,7 +439,8 @@ static int get_row(const side * s, int row, const side * vs) /* every entry in the size[] array means someone trying to defend us. * 'retreat' is the number of rows falling. */ - result = MAX(FIRST_ROW, row - retreat); + result = row - retreat; + if (result < FIRST_ROW) result = FIRST_ROW; return result; } @@ -587,50 +591,27 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking) * are taken into account, e.g. no horses, magic, etc. */ { int skill; + const race * rc = u_race(u); if (wtype == NULL) { skill = effskill(u, SK_WEAPONLESS, NULL); + int def = attacking ? rc->at_default : rc->df_default; if (skill <= 0) { /* wenn kein waffenloser kampf, dann den rassen-defaultwert */ - if (u_race(u) == get_race(RC_ORC)) { + if (rc == get_race(RC_ORC)) { int sword = effskill(u, SK_MELEE, NULL); int spear = effskill(u, SK_SPEAR, NULL); - skill = MAX(sword, spear) - 3; - if (attacking) { - skill = MAX(skill, u_race(u)->at_default); - } - else { - skill = MAX(skill, u_race(u)->df_default); - } - } - else { - if (attacking) { - skill = u_race(u)->at_default; - } - else { - skill = u_race(u)->df_default; - } - } - } - else { - /* der rassen-defaultwert kann h�her sein als der Talentwert von - * waffenloser kampf */ - if (attacking) { - if (skill < u_race(u)->at_default) - skill = u_race(u)->at_default; - } - else { - if (skill < u_race(u)->df_default) - skill = u_race(u)->df_default; + skill = ((sword > spear) ? sword : spear) - 3; } } + if (def > skill) skill = def; if (attacking) { - skill += u_race(u)->at_bonus; + skill += rc->at_bonus; if (fval(u->region->terrain, SEA_REGION) && u->ship) skill += u->ship->type->at_bonus; } else { - skill += u_race(u)->df_bonus; + skill += rc->df_bonus; if (fval(u->region->terrain, SEA_REGION) && u->ship) skill += u->ship->type->df_bonus; } @@ -642,10 +623,10 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking) skill = effskill(u, wtype->skill, NULL); if (skill > 0) { if (attacking) { - skill += u_race(u)->at_bonus; + skill += rc->at_bonus; } else { - skill += u_race(u)->df_bonus; + skill += rc->df_bonus; } } if (attacking) { @@ -1261,32 +1242,33 @@ static int apply_race_resistance(int reduced_damage, fighter *df, static int apply_magicshield(int reduced_damage, fighter *df, const weapon_type *awtype, battle *b, bool magic) { - side *ds = df->side; - selist *ql; - int qi; + side *ds = df->side; + selist *ql; + int qi; - if (reduced_damage <= 0) - return 0; + if (reduced_damage <= 0) + return 0; - /* Schilde */ - for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) { - meffect *me = (meffect *) selist_get(ql, qi); - if (meffect_protection(b, me, ds) != 0) { - assert(0 <= reduced_damage); /* rda sollte hier immer mindestens 0 sein */ - /* jeder Schaden wird um effect% reduziert bis der Schild duration - * Trefferpunkte aufgefangen hat */ - if (me->typ == SHIELD_REDUCE) { - int hp = reduced_damage * (me->effect / 100); - reduced_damage -= hp; - me->duration -= hp; - } - /* gibt R�stung +effect f�r duration Treffer */ - if (me->typ == SHIELD_ARMOR) { - reduced_damage = MAX(reduced_damage - me->effect, 0); - me->duration--; - } + /* Schilde */ + for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) { + meffect *me = (meffect *)selist_get(ql, qi); + if (meffect_protection(b, me, ds) != 0) { + assert(0 <= reduced_damage); /* rda sollte hier immer mindestens 0 sein */ + /* jeder Schaden wird um effect% reduziert bis der Schild duration + * Trefferpunkte aufgefangen hat */ + if (me->typ == SHIELD_REDUCE) { + int hp = reduced_damage * (me->effect / 100); + reduced_damage -= hp; + me->duration -= hp; + } + /* gibt R�stung +effect f�r duration Treffer */ + if (me->typ == SHIELD_ARMOR) { + reduced_damage -= me->effect; + if (reduced_damage < 0) reduced_damage = 0; + me->duration--; + } + } } - } return reduced_damage; } @@ -1347,11 +1329,13 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile /* Skilldifferenzbonus */ if (rule_damage & DAMAGE_SKILL_BONUS) { - damage += MAX(0, (attskill - defskill) / DAMAGE_QUOTIENT); + int b = (attskill - defskill) / DAMAGE_QUOTIENT; + if (b > 0) damage += b; } } - reduced_damage = MAX(damage - armor_value, 0); + reduced_damage = damage - armor_value; + if (reduced_damage < 0) reduced_damage = 0; reduced_damage = apply_race_resistance(reduced_damage, df, awtype, magic); reduced_damage = apply_magicshield(reduced_damage, df, awtype, b, magic); @@ -1500,7 +1484,8 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select) minrow = FIGHT_ROW; maxrow = BEHIND_ROW; } - minrow = MAX(minrow, FIGHT_ROW); + + if (minrow < FIGHT_ROW) minrow = FIGHT_ROW; enemies = count_enemies(b, af, minrow, maxrow, select); @@ -1611,7 +1596,7 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist) dt = select_enemy(at.fighter, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); } else { - mindist = MAX(mindist, FIGHT_ROW); + if (mindist < FIGHT_ROW) mindist = FIGHT_ROW; dt = select_enemy(at.fighter, mindist, maxdist, SELECT_ADVANCE); } @@ -2078,7 +2063,8 @@ void dazzle(battle * b, troop * td) void damage_building(battle * b, building * bldg, int damage_abs) { assert(bldg); - bldg->size = MAX(1, bldg->size - damage_abs); + bldg->size -= damage_abs; + if (bldg->size < 1) bldg->size = 1; /* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb�ude passen. */ @@ -3020,7 +3006,9 @@ static void print_stats(battle * b) for (s = b->sides; s != b->sides + b->nsides; ++s) { if (!selist_empty(s->leader.fighters)) { - b->max_tactics = MAX(b->max_tactics, s->leader.value); + if (s->leader.value > b->max_tactics) { + b->max_tactics = s->leader.value; + } } } @@ -3371,7 +3359,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) else p_bonus += 3; } while (rnd >= 97); - bonus = MAX(p_bonus, bonus); + if (p_bonus > bonus) p_bonus = bonus; } tactics += bonus; } diff --git a/src/items/xerewards.c b/src/items/xerewards.c index d039a19a1..c49787ec7 100644 --- a/src/items/xerewards.c +++ b/src/items/xerewards.c @@ -75,8 +75,9 @@ use_manacrystal(struct unit *u, const struct item_type *itype, int amount, } msp = max_spellpoints_depr(u->region, u) / 2; + if (msp < 25) msp = 25; for (i = 0; i != amount; ++i) { - sp += MAX(25, msp); + sp += msp; change_spellpoints(u, sp); } diff --git a/src/kernel/group.c b/src/kernel/group.c index b01e10a9a..bfa654cdf 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -60,7 +60,7 @@ group *new_group(faction * f, const char *name, int gid) gp = &(*gp)->next; *gp = g; - maxgid = MAX(gid, maxgid); + if (gid > maxgid) maxgid = gid; g->name = str_strdup(name); g->gid = gid; diff --git a/src/kernel/order.c b/src/kernel/order.c index 44332d630..b352a1650 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -10,7 +10,10 @@ without prior permission by the authors of Eressea. */ +#ifdef _MSC_VER #include +#endif + #include #include "order.h" @@ -398,6 +401,7 @@ order *parse_order(const char *s, const struct locale * lang) } if (kwd != NOKEYWORD) { order *ord = (order *)malloc(sizeof(order)); + if (ord == NULL) abort(); create_order_i(ord, kwd, sptr, persistent, noerror, lang); return ord; } diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 6805e1c0e..4ff2ce6f4 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -156,7 +156,7 @@ int set_resvalue(unit * u, const item_type * itype, int value) } int -get_pooled(const unit * u, const resource_type * rtype, unsigned int mode, +get_pooled(const unit * u, const resource_type * rtype, int mode, int count) { const faction *f = u->faction; @@ -199,7 +199,7 @@ int count) } int -use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) +use_pooled(unit * u, const resource_type * rtype, int mode, int count) { const faction *f = u->faction; unit *v; diff --git a/src/kernel/pool.h b/src/kernel/pool.h index ecd1a5364..df7638689 100644 --- a/src/kernel/pool.h +++ b/src/kernel/pool.h @@ -42,9 +42,9 @@ extern "C" { #define GET_ALL (GET_SLACK|GET_RESERVE|GET_POOLED_SLACK|GET_POOLED_RESERVE|GET_POOLED_FORCE) int get_pooled(const struct unit *u, const struct resource_type *res, - unsigned int mode, int count); + int mode, int count); int use_pooled(struct unit *u, const struct resource_type *res, - unsigned int mode, int count); + int mode, int count); /** use_pooled * verbraucht 'count' Objekte der resource 'itm' * unter zuhilfenahme des Pools der struct region und Aufbrauch des diff --git a/src/kernel/save.c b/src/kernel/save.c index 4c8e02fe0..a914b1c32 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -448,7 +448,7 @@ unit *read_unit(gamedata *data) set_number(u, number); READ_INT(data->store, &n); - u->age = (short)n; + u->age = n; READ_TOK(data->store, rname, sizeof(rname)); rc = rc_find(rname); @@ -775,7 +775,8 @@ static region *readregion(gamedata *data, int x, int y) } if (data->version >= REGIONOWNER_VERSION) { READ_INT(data->store, &n); - region_set_morale(r, MAX(0, (short)n), -1); + if (n < 0) n = 0; + region_set_morale(r, n, -1); read_owner(data, &r->land->ownership); } } diff --git a/src/morale.c b/src/morale.c index 6155426ac..7d76db6b9 100644 --- a/src/morale.c +++ b/src/morale.c @@ -76,7 +76,8 @@ void morale_update(region *r) { void morale_change(region *r, int value) { int morale = region_get_morale(r); if (morale > 0) { - morale = MAX(0, morale - value); + morale = morale - value; + if (morale < 0) morale = 0; region_set_morale(r, morale, turn); } } diff --git a/src/platform.h b/src/platform.h index 7b52782e3..4305c379b 100644 --- a/src/platform.h +++ b/src/platform.h @@ -14,6 +14,3 @@ #pragma warning(disable: 4224) // formal parameter was previously defined as a type #pragma warning(disable: 4214) // bit field types other than int #endif - -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) diff --git a/src/races/dragons.c b/src/races/dragons.c index aa79a783a..ec16f78dc 100644 --- a/src/races/dragons.c +++ b/src/races/dragons.c @@ -22,7 +22,10 @@ /* util includes */ #include -#define age_chance(a,b,p) (MAX(0,a-b)*p) +static int age_chance(int a, int b, int p) { + int r = (a - b) * p; + return (r < 0) ? 0 : r; +} #define DRAGONAGE 27 #define WYRMAGE 68 diff --git a/src/races/zombies.c b/src/races/zombies.c index 3c880d819..652ccc1e2 100644 --- a/src/races/zombies.c +++ b/src/races/zombies.c @@ -31,7 +31,10 @@ #define UNDEAD_BREAKUP 25 /* chance dafuer */ #define UNDEAD_BREAKUP_FRACTION (25+rng_int()%70) /* anteil der weg geht */ -#define age_chance(a,b,p) (MAX(0,a-b)*p) +static int age_chance(int a, int b, int p) { + int r = (a - b) * p; + return (r < 0) ? 0 : r; +} void make_undead_unit(unit * u) { @@ -43,8 +46,9 @@ void make_undead_unit(unit * u) void age_skeleton(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = MAX(1, u->number / 2); + int n = u->number / 2; double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); + if (n < 1) n = 1; u_setrace(u, get_race(RC_SKELETON_LORD)); u->irace = NULL; scale_number(u, n); @@ -55,8 +59,9 @@ void age_skeleton(unit * u) void age_zombie(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = MAX(1, u->number / 2); + int n = u->number / 2; double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); + if (n < 1) n = 1; u_setrace(u, get_race(RC_ZOMBIE_LORD)); u->irace = NULL; scale_number(u, n); @@ -67,11 +72,11 @@ void age_zombie(unit * u) void age_ghoul(unit * u) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { - int n = MAX(1, u->number / 2); + int n = u->number / 2; double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); u_setrace(u, get_race(RC_GHOUL_LORD)); u->irace = NULL; - scale_number(u, n); + scale_number(u, (n > 0) ? n : 1); u->hp = (int)(unit_max_hp(u) * u->number * q); } } From 35bbcac97bb5c48fa1e6610abdc4dad31567b57a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 Feb 2019 21:20:23 +0100 Subject: [PATCH 66/85] eliminate warnings from cppcheck --- src/kernel/save.test.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index e069d7ebf..565ac8354 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -278,13 +278,11 @@ static void test_readwrite_dead_faction_group(CuTest *tc) { CuAssertPtrEquals(tc, f2, factions); write_game(&data); free_gamedata(); - f = f2 = NULL; data.strm.api->rewind(data.strm.handle); read_game(&data); CuAssertPtrEquals(tc, NULL, findfaction(fno)); - f2 = factions; - CuAssertPtrNotNull(tc, f2); - u = f2->units; + CuAssertPtrNotNull(tc, factions); + u = factions->units; CuAssertPtrNotNull(tc, u); g = get_group(u); CuAssertPtrNotNull(tc, g); @@ -313,13 +311,11 @@ static void test_readwrite_dead_faction_regionowner(CuTest *tc) { remove_empty_units(); write_game(&data); free_gamedata(); - f = NULL; data.strm.api->rewind(data.strm.handle); read_game(&data); mstream_done(&data.strm); gamedata_done(&data); - f = factions; - CuAssertPtrEquals(tc, NULL, f); + CuAssertPtrEquals(tc, NULL, factions); r = regions; CuAssertPtrNotNull(tc, r); CuAssertPtrEquals(tc, NULL, region_get_owner(r)); From 9436640d228b7a51cbc70c0677f536e5bbf85577 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 6 Feb 2019 22:29:09 +0100 Subject: [PATCH 67/85] remove UTF-8 BOM from sources --- src/kernel/attrib.c | 2 +- src/kernel/gamedata.c | 2 +- src/kernel/gamedata.h | 2 +- src/kernel/item.c | 2 +- src/kernel/messages.c | 2 +- src/util/log.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kernel/attrib.c b/src/kernel/attrib.c index f6a857d90..aca3d25ba 100644 --- a/src/kernel/attrib.c +++ b/src/kernel/attrib.c @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 1998-2015, Enno Rehling Katja Zedel diff --git a/src/kernel/gamedata.c b/src/kernel/gamedata.c index 4173332c4..de52ba8b6 100644 --- a/src/kernel/gamedata.c +++ b/src/kernel/gamedata.c @@ -1,4 +1,4 @@ -#include +#include #include "gamedata.h" diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index 77469f9da..e14c0a551 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #ifndef _GAMEDATA_H #define _GAMEDATA_H diff --git a/src/kernel/item.c b/src/kernel/item.c index 52ff72a84..04d106399 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 1998-2015, Enno Rehling Katja Zedel diff --git a/src/kernel/messages.c b/src/kernel/messages.c index ea16044f8..344a96907 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 1998-2015, Enno Rehling Katja Zedel diff --git a/src/util/log.c b/src/util/log.c index 8c198988f..8f0d81b6d 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -1,4 +1,4 @@ -/* +/* +-------------------+ Christian Schlittchen | | Enno Rehling | Eressea PBEM host | Katja Zedel From 9e44b8a989726f6ac0b95690447b6579f179be00 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 7 Feb 2019 14:48:51 +0100 Subject: [PATCH 68/85] kaputte umlaute ersetzt, ascii 4 lyfe --- src/kernel/building.h | 4 ++-- src/kernel/config.h | 12 ++++++------ src/kernel/curse.h | 18 +++++++++--------- src/kernel/item.h | 4 ++-- src/kernel/plane.h | 2 +- src/kernel/race.h | 24 ++++++++++++------------ src/kernel/ship.h | 4 ++-- src/kernel/spell.h | 21 +++++++++++---------- 8 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/kernel/building.h b/src/kernel/building.h index a5419325f..d1eb4d9fd 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -69,8 +69,8 @@ extern "C" { char *_name; int flags; /* flags */ - int capacity; /* Kapazit�t pro Gr��enpunkt */ - int maxcapacity; /* Max. Kapazit�t */ + int capacity; /* Kapazitaet pro Groessenpunkt */ + int maxcapacity; /* Max. Kapazitaet */ int maxsize; /* how big can it get, with all the extensions? */ variant magres; /* how well it resists against spells */ int magresbonus; /* bonus it gives the target against spells */ diff --git a/src/kernel/config.h b/src/kernel/config.h index 83241ac4c..1090967dd 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -31,12 +31,12 @@ extern "C" { struct param; struct _dictionary_; -#define DISPLAYSIZE 4096 /* max. L�nge einer Beschreibung, incl trailing 0 */ +#define DISPLAYSIZE 4096 /* max. Laenge einer Beschreibung, incl trailing 0 */ #define ORDERSIZE 4096 /* max. length of an order */ -#define NAMESIZE 128 /* max. L�nge eines Namens, incl trailing 0 */ -#define IDSIZE 16 /* max. L�nge einer no (als String), incl trailing 0 */ -#define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. L�nge der Strings, die - * von struct unitname, etc. zur�ckgegeben werden. ohne die 0 */ +#define NAMESIZE 128 /* max. Laenge eines Namens, incl trailing 0 */ +#define IDSIZE 16 /* max. Laenge einer no (als String), incl trailing 0 */ +#define OBJECTIDSIZE (NAMESIZE+5+IDSIZE) /* max. Laenge der Strings, die + * von struct unitname, etc. zurueckgegeben werden. ohne die 0 */ #define fval(u, i) ((u)->flags & (i)) #define fset(u, i) ((u)->flags |= (i)) @@ -83,7 +83,7 @@ extern "C" { #define GF_SPECIFIC 16 /* der, die, das vs. ein, eine */ #define GF_DETAILED 32 - /* mehr Informationen. z.b. stra�e zu 50% */ + /* mehr Informationen. z.b. strasse zu 50% */ #define GF_PURE 64 /* untranslated */ diff --git a/src/kernel/curse.h b/src/kernel/curse.h index 53e189be9..a3cf6176d 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -39,7 +39,7 @@ extern "C" { * (struct attribute) */ - /* Brainstorming Ãœberarbeitung curse + /* Brainstorming Ueberarbeitung curse * * Ziel: Keine Enum-Liste, flexible, leicht erweiterbare Curse-Objekte * @@ -52,13 +52,13 @@ extern "C" { * auch Antimagieverhalten * - Ausgabe von Beschreibungen in verschiedenen Sprachen * - definiertes gekapseltes Verhalten zb bei Zusammenlegung von - * Einheiten, Ãœbergabe von Personen, Mehrfachverzauberung + * Einheiten, Uebergabe von Personen, Mehrfachverzauberung * - (Rueck-)Referenzen auf Objekt, Verursacher (Magier), ? * * Vieleicht waere ein Wirkungsklassensystem sinnvoll, so das im uebrigen * source einfach alle curse-attribs abgefragt werden koennen und bei - * gewuenschter Wirkungsklasse angewendet, also nicht für jeden curse - * spezielle Änderungen im uebrigen source notwendig sind. + * gewuenschter Wirkungsklasse angewendet, also nicht fuer jeden curse + * spezielle Aenderungen im uebrigen source notwendig sind. * * Die (Wirkungs-)Typen sollten die wichtigen Funktionen speziell * belegen koennen, zb Alterung, Ausgabetexte, Merge-Verhalten @@ -95,7 +95,7 @@ extern "C" { * - Laden des C-Objekts * - Erzeugen des C-Objekts * - Loeschen und Aufraeumen des C-Objekts - * - Funktionen zur Änderung der Werte + * - Funktionen zur Aenderung der Werte * * */ @@ -145,7 +145,7 @@ extern "C" { /* ------------------------------------------------------------- */ /* Flags */ - /* Verhalten von Zaubern auf Units beim Ãœbergeben von Personen */ + /* Verhalten von Zaubern auf Units beim Uebergeben von Personen */ typedef enum { CURSE_ISNEW = 0x01, /* wirkt in der zauberrunde nicht (default) */ CURSE_NOAGE = 0x02, /* wirkt ewig */ @@ -262,18 +262,18 @@ extern "C" { int curse_geteffect_int(const struct curse *c); double curse_geteffect(const struct curse *c); - /* veraendert die Stärke der Verzauberung um i */ + /* veraendert die Staerke der Verzauberung um i */ double curse_changevigour(struct attrib **ap, curse * c, double delta); /* gibt bei Personenbeschraenkten Verzauberungen die Anzahl der - * betroffenen Personen zurueck. Ansonsten wird 0 zurückgegeben. */ + * betroffenen Personen zurueck. Ansonsten wird 0 zurueckgegeben. */ int get_cursedmen(const struct unit *u, const struct curse *c); /* setzt/loescht Spezialflag einer Verzauberung (zB 'dauert ewig') */ void c_setflag(curse * c, unsigned int flag); void c_clearflag(curse * c, unsigned int flags); - /* sorgt dafuer, das bei der Ãœbergabe von Personen die curse-attribute + /* sorgt dafuer, das bei der Uebergabe von Personen die curse-attribute * korrekt gehandhabt werden. Je nach internen Flag kann dies * unterschiedlich gewuenscht sein * */ diff --git a/src/kernel/item.h b/src/kernel/item.h index 76ca355d1..568338b4c 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -75,7 +75,7 @@ extern "C" { typedef struct resource_type { /* --- constants --- */ - char *_name; /* wie es hei�t */ + char *_name; /* wie es heisst */ unsigned int flags; /* --- functions --- */ rtype_uchange uchange; @@ -119,7 +119,7 @@ extern "C" { int mask_allow; int mask_deny; struct construction *construction; - char *_appearance[2]; /* wie es f�r andere aussieht */ + char *_appearance[2]; /* wie es fuer andere aussieht */ int score; } item_type; diff --git a/src/kernel/plane.h b/src/kernel/plane.h index bfaaa5dda..4f63db398 100644 --- a/src/kernel/plane.h +++ b/src/kernel/plane.h @@ -32,7 +32,7 @@ extern "C" { #define PFL_NORECRUITS 2 /* cannot recruit */ #define PFL_NOALLIANCES 4 /* not implemented */ #define PFL_LOWSTEALING 8 /* not implemented */ -#define PFL_NOGIVE 16 /* Ãœbergaben sind unmoeglich */ +#define PFL_NOGIVE 16 /* Uebergaben sind unmoeglich */ #define PFL_NOATTACK 32 /* Angriffe und Diebstaehle sind unmoeglich */ #define PFL_NOTERRAIN 64 /* Terraintyp wird nicht angezeigt TODO? */ #define PFL_NOMAGIC 128 /* Zaubern ist unmoeglich */ diff --git a/src/kernel/race.h b/src/kernel/race.h index 65cb0cf73..f2b96c153 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -121,7 +121,7 @@ extern "C" { int healing; int maxaura; /* Faktor auf Maximale Aura */ double regaura; /* Faktor auf Regeneration */ - double recruit_multi; /* Faktor f�r Bauernverbrauch */ + double recruit_multi; /* Faktor fuer Bauernverbrauch */ int index; int recruitcost; int maintenance; @@ -135,8 +135,8 @@ extern "C" { int armor; int at_default; /* Angriffsskill Unbewaffnet (default: -2) */ int df_default; /* Verteidigungsskill Unbewaffnet (default: -2) */ - int at_bonus; /* Ver�ndert den Angriffsskill (default: 0) */ - int df_bonus; /* Ver�ndert den Verteidigungskill (default: 0) */ + int at_bonus; /* Veraendert den Angriffsskill (default: 0) */ + int df_bonus; /* Veraendert den Verteidigungskill (default: 0) */ signed char *study_speed; /* study-speed-bonus in points/turn (0=30 Tage) */ int flags; int battle_flags; @@ -211,20 +211,20 @@ extern "C" { #define RCF_LEARN (1<<6) /* Lernt automatisch wenn struct faction == 0 */ #define RCF_FLY (1<<7) /* kann fliegen */ #define RCF_SWIM (1<<8) /* kann schwimmen */ -#define RCF_WALK (1<<9) /* kann �ber Land gehen */ +#define RCF_WALK (1<<9) /* kann ueber Land gehen */ #define RCF_NOLEARN (1<<10) /* kann nicht normal lernen */ #define RCF_NOTEACH (1<<11) /* kann nicht lehren */ #define RCF_HORSE (1<<12) /* Einheit ist Pferd, sozusagen */ #define RCF_DESERT (1<<13) /* 5% Chance, das Einheit desertiert */ #define RCF_ILLUSIONARY (1<<14) /* (Illusion & Spell) Does not drop items. */ -#define RCF_ABSORBPEASANTS (1<<15) /* T�tet und absorbiert Bauern */ +#define RCF_ABSORBPEASANTS (1<<15) /* Toetet und absorbiert Bauern */ #define RCF_NOHEAL (1<<16) /* Einheit kann nicht geheilt werden */ #define RCF_NOWEAPONS (1<<17) /* Einheit kann keine Waffen benutzen */ #define RCF_SHAPESHIFT (1<<18) /* Kann TARNE RASSE benutzen. */ #define RCF_SHAPESHIFTANY (1<<19) /* Kann TARNE RASSE "string" benutzen. */ #define RCF_UNDEAD (1<<20) /* Undead. */ -#define RCF_DRAGON (1<<21) /* Drachenart (f�r Zauber) */ -#define RCF_COASTAL (1<<22) /* kann in Landregionen an der K�ste sein */ +#define RCF_DRAGON (1<<21) /* Drachenart (fuer Zauber) */ +#define RCF_COASTAL (1<<22) /* kann in Landregionen an der Kueste sein */ #define RCF_UNARMEDGUARD (1<<23) /* kann ohne Waffen bewachen */ #define RCF_CANSAIL (1<<24) /* Einheit darf Schiffe betreten */ #define RCF_INVISIBLE (1<<25) /* not visible in any report */ @@ -236,17 +236,17 @@ extern "C" { #define RCF_DEFAULT RCF_CANSAIL /* Economic flags */ -#define ECF_GIVEPERSON (1<<0) /* �bergibt Personen */ -#define ECF_GIVEUNIT (1<<1) /* Einheiten an andere Partei �bergeben */ -#define ECF_GETITEM (1<<2) /* nimmt Gegenst�nde an */ +#define ECF_GIVEPERSON (1<<0) /* Uebergibt Personen */ +#define ECF_GIVEUNIT (1<<1) /* Einheiten an andere Partei uebergeben */ +#define ECF_GETITEM (1<<2) /* nimmt Gegenstaende an */ #define ECF_REC_ETHEREAL (1<<3) /* Rekrutiert aus dem Nichts */ #define ECF_REC_UNLIMITED (1<<4) /* Rekrutiert ohne Limit */ #define ECF_STONEGOLEM (1<<5) /* race gets stonegolem properties */ #define ECF_IRONGOLEM (1<<6) /* race gets irongolem properties */ /* Battle-Flags */ -#define BF_EQUIPMENT (1<<0) /* Kann Ausr�stung benutzen */ -#define BF_NOBLOCK (1<<1) /* Wird in die R�ckzugsberechnung nicht einbezogen */ +#define BF_EQUIPMENT (1<<0) /* Kann Ausruestung benutzen */ +#define BF_NOBLOCK (1<<1) /* Wird in die Rueckzugsberechnung nicht einbezogen */ #define BF_RES_PIERCE (1<<2) /* Halber Schaden durch PIERCE */ #define BF_RES_CUT (1<<3) /* Halber Schaden durch CUT */ #define BF_RES_BASH (1<<4) /* Halber Schaden durch BASH */ diff --git a/src/kernel/ship.h b/src/kernel/ship.h index ce3283a6f..e944c0d65 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -57,8 +57,8 @@ extern "C" { int minskill; /* min. skill to sail this (crew) */ int sumskill; /* min. sum of crew+captain */ - int at_bonus; /* Ver�ndert den Angriffsskill (default: 0) */ - int df_bonus; /* Ver�ndert den Verteidigungskill (default: 0) */ + int at_bonus; /* Veraendert den Angriffsskill (default: 0) */ + int df_bonus; /* Veraendert den Verteidigungskill (default: 0) */ double tac_bonus; struct terrain_type ** coasts; /* coast that this ship can land on */ diff --git a/src/kernel/spell.h b/src/kernel/spell.h index 8b155f89b..62976af03 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -76,7 +76,8 @@ extern "C" { } #endif #endif -/* ------------------------------------------------------------- *//* Erl�uterungen zu den Spruchdefinitionen +/** + * Erlaeuterungen zu den Spruchdefinitionen * * Spruchstukturdefinition: * spell{ @@ -94,35 +95,35 @@ extern "C" { * id: * SPL_NOSPELL muss der letzte Spruch in der Liste spelldaten sein, * denn nicht auf die Reihenfolge in der Liste sondern auf die id wird - * gepr�ft + * geprueft * * sptyp: * besondere Spruchtypen und Flags * (Regionszauber, Kampfzauber, Farcastbar, Stufe variable, ..) * * rank: - * gibt die Priorit�t und damit die Reihenfolge an, in der der Spruch + * gibt die Prioritaet und damit die Reihenfolge an, in der der Spruch * gezaubert wird. - * 1: Aura �bertragen + * 1: Aura uebertragen * 2: Antimagie - * 3: Magierver�ndernde Spr�che (Magic Boost, ..) + * 3: Magierveraendernde Sprueche (Magic Boost, ..) * 4: Monster erschaffen * 5: Standartlevel * 7: Teleport * - * Komponenten[Anzahl m�gl. Items][Art:Anzahl:Kostentyp] + * Komponenten[Anzahl moegl. Items][Art:Anzahl:Kostentyp] * * R_AURA: - * Grundkosten f�r einen Zauber. Soviel Mp m�ssen mindestens investiert - * werden, um den Spruch zu wirken. Zus�tzliche Mp k�nnen unterschiedliche + * Grundkosten fuer einen Zauber. Soviel Mp muessen mindestens investiert + * werden, um den Spruch zu wirken. Zusaetzliche Mp koennen unterschiedliche * Auswirkungen haben, die in der Spruchfunktionsroutine definiert werden. * * R_PERMAURA: * Kosten an permantenter Aura * * Komponenten Kostentyp: - * SPC_LEVEL == Spruch mit Levelabh�ngigen Magiekosten. Die angegeben - * Kosten m�ssen f�r Stufe 1 berechnet sein. + * SPC_LEVEL == Spruch mit Levelabhaengigen Magiekosten. Die angegeben + * Kosten muessen fuer Stufe 1 berechnet s * SPC_FIX == Feste Kosten * * Wenn keine spezielle Syntax angegeben ist, wird die From debb86601bfbff00088831f7a24485f4f730574d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 8 Feb 2019 11:37:32 +0100 Subject: [PATCH 69/85] umlaut substitutions --- src/chaos.c | 2 +- src/economy.test.c | 2 +- src/items.c | 8 +- src/lighthouse.c | 2 +- src/magic.c | 204 ++++++++++++++++++++++---------------------- src/move.c | 72 ++++++++-------- src/orderfile.c | 15 ++-- src/races/races.c | 2 +- src/randenc.c | 16 ++-- src/tools/namegen.c | 6 +- src/volcano.c | 8 +- 11 files changed, 170 insertions(+), 167 deletions(-) diff --git a/src/chaos.c b/src/chaos.c index 7a2dd7c89..fd87d87d4 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -136,7 +136,7 @@ static void chaos(region * r) u->flags |= (UFL_ISNEW | UFL_MOVED); } break; - case 2: /* Terrainver�nderung */ + case 2: /* Terrainveraenderung */ if (!(r->terrain->flags & FORBIDDEN_REGION)) { if (!(r->terrain->flags & SEA_REGION)) { direction_t dir; diff --git a/src/economy.test.c b/src/economy.test.c index 236c181c5..65059ffb2 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -232,7 +232,7 @@ static unit *setup_trade_unit(CuTest *tc, region *r, const struct race *rc) { } static void test_trade_insect(CuTest *tc) { - /* Insekten k�nnen in W�sten und S�mpfen auch ohne Burgen handeln. */ + /* Insekten koennen in Wuesten und Suempfen auch ohne Burgen handeln. */ unit *u; region *r; const item_type *it_luxury; diff --git a/src/items.c b/src/items.c index 9a91a6037..c99fc2cdf 100644 --- a/src/items.c +++ b/src/items.c @@ -136,15 +136,15 @@ struct order *ord) UNUSED_ARG(ord); assert(sp); - /* Reduziert die St�rke jedes Spruchs um effect */ + /* Reduziert die Staerke jedes Spruchs um effect */ effect = 5; - /* H�lt Spr�che bis zu einem summierten Gesamtlevel von power aus. + /* Haelt Sprueche bis zu einem summierten Gesamtlevel von power aus. * Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone * um seine Stufe */ force = effect * 20.0; /* Stufe 5 =~ 100 */ - /* Regionszauber aufl�sen */ + /* Regionszauber aufloesen */ while (*ap && force > 0) { curse *c; attrib *a = *ap; @@ -156,7 +156,7 @@ struct order *ord) } c = (curse *)a->data.v; - /* Immunit�t pr�fen */ + /* Immunitaet pruefen */ if (c_flags(c) & CURSE_IMMUNE) { do { ap = &(*ap)->next; diff --git a/src/lighthouse.c b/src/lighthouse.c index 68256a692..7915bdf44 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -16,7 +16,7 @@ attrib_type at_lighthouse = { "lighthouse" - /* Rest ist NULL; tempor�res, nicht alterndes Attribut */ + /* Rest ist NULL; temporaeres, nicht alterndes Attribut */ }; bool is_lighthouse(const building_type *btype) diff --git a/src/magic.c b/src/magic.c index a71641c6d..d7b57f24d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -289,7 +289,7 @@ int get_spell_level_mage(const spell * sp, void * cbdata) } /* ------------------------------------------------------------- */ -/* aus dem alten System übriggebliegene Funktionen, die bei der +/* aus dem alten System uebriggebliegene Funktionen, die bei der * Umwandlung von alt nach neu gebraucht werden */ /* ------------------------------------------------------------- */ @@ -502,7 +502,7 @@ sc_mage *create_mage(unit * u, magic_t mtyp) } /* ------------------------------------------------------------- */ -/* Funktionen für die Bearbeitung der List-of-known-spells */ +/* Funktionen fuer die Bearbeitung der List-of-known-spells */ int u_hasspell(const unit *u, const struct spell *sp) { @@ -531,7 +531,7 @@ int get_combatspelllevel(const unit * u, int nr) } /* ------------------------------------------------------------- */ -/* Kampfzauber ermitteln, setzen oder löschen */ +/* Kampfzauber ermitteln, setzen oder loeschen */ const spell *get_combatspell(const unit * u, int nr) { @@ -591,8 +591,9 @@ void unset_combatspell(unit * u, spell * sp) return; } -/* ------------------------------------------------------------- */ -/* Gibt die aktuelle Anzahl der Magiepunkte der Einheit zurück */ +/** + * Gibt die aktuelle Anzahl der Magiepunkte der Einheit zurueck + */ int get_spellpoints(const unit * u) { return mage_get_spellpoints(get_mage(u)); @@ -606,15 +607,16 @@ void set_spellpoints(unit * u, int sp) } } -/* - * verändert die Anzahl der Magiepunkte der Einheit um +mp +/** + * Veraendert die Anzahl der Magiepunkte der Einheit um +mp */ int change_spellpoints(unit * u, int mp) { return mage_change_spellpoints(get_mage(u), mp); } -/* bietet die Möglichkeit, die maximale Anzahl der Magiepunkte mit +/** + * Bietet die Moeglichkeit, die maximale Anzahl der Magiepunkte mit * Regionszaubern oder Attributen zu beinflussen */ static int get_spchange(const unit * u) @@ -627,13 +629,13 @@ static int get_spchange(const unit * u) /* ein Magier kann normalerweise maximal Stufe^2.1/1.2+1 Magiepunkte * haben. - * Manche Rassen haben einen zusätzlichen Multiplikator - * Durch Talentverlust (zB Insekten im Berg) können negative Werte + * Manche Rassen haben einen zusaetzlichen Multiplikator + * Durch Talentverlust (zB Insekten im Berg) koennen negative Werte * entstehen */ - /* Artefakt der Stärke - * Ermöglicht dem Magier mehr Magiepunkte zu 'speichern' + /* Artefakt der Staerke + * Ermoeglicht dem Magier mehr Magiepunkte zu 'speichern' */ /** TODO: at_skillmod daraus machen */ static int use_item_aura(const region * r, const unit * u) @@ -687,7 +689,7 @@ int change_maxspellpoints(unit * u, int csp) } /* ------------------------------------------------------------- */ -/* Counter für die bereits gezauberte Anzahl Sprüche pro Runde. +/* Counter fuer die bereits gezauberte Anzahl Sprueche pro Runde. */ int countspells(unit * u, int step) { @@ -710,8 +712,8 @@ int spellcount(const unit *u) { } /** - * Die Grundkosten pro Stufe werden um 2^count erhöht. countspells(u) - * ist dabei die Anzahl der bereits gezauberten Sprüche + * Die Grundkosten pro Stufe werden um 2^count erhoeht. countspells(u) + * ist dabei die Anzahl der bereits gezauberten Sprueche */ int aura_multiplier(const unit * u) { int count = spellcount(u); @@ -729,7 +731,7 @@ int spellcost(const unit * caster, const struct spell_component *spc) } /** - * Die für den Spruch benötigte Aura pro Stufe. + * Die fuer den Spruch benoetigte Aura pro Stufe. */ int auracost(const unit *caster, const spell *sp) { const resource_type *r_aura = get_resourcetype(R_AURA); @@ -746,12 +748,12 @@ int auracost(const unit *caster, const spell *sp) { } /* ------------------------------------------------------------- */ -/* SPC_LINEAR ist am höchstwertigen, dann müssen Komponenten für die +/* SPC_LINEAR ist am hoechstwertigen, dann muessen Komponenten fuer die * Stufe des Magiers vorhanden sein. - * SPC_LINEAR hat die gewünschte Stufe als multiplikator, + * SPC_LINEAR hat die gewuenschte Stufe als multiplikator, * nur SPC_FIX muss nur einmal vorhanden sein, ist also am * niedrigstwertigen und sollte von den beiden anderen Typen - * überschrieben werden */ + * ueberschrieben werden */ static int spl_costtyp(const spell * sp) { int k; @@ -765,7 +767,7 @@ static int spl_costtyp(const spell * sp) return SPC_LINEAR; } - /* wenn keine Fixkosten, Typ übernehmen */ + /* wenn keine Fixkosten, Typ uebernehmen */ if (sp->components[k].cost != SPC_FIX) { costtyp = sp->components[k].cost; } @@ -774,10 +776,10 @@ static int spl_costtyp(const spell * sp) } /** - * Durch Komponenten und cast_level begrenzter maximal möglicherLevel. + * Durch Komponenten und cast_level begrenzter maximal moeglicher Level. * * Da die Funktion nicht alle Komponenten durchprobiert sondern beim - * ersten Fehler abbricht, muss die Fehlermeldung später mit cancast() + * ersten Fehler abbricht, muss die Fehlermeldung spaeter mit cancast() * generiert werden. */ int eff_spelllevel(unit * u, unit *caster, const spell * sp, int cast_level, int range) @@ -802,20 +804,20 @@ int eff_spelllevel(unit * u, unit *caster, const spell * sp, int cast_level, int level_cost * cast_level) / level_cost; /* sind die Kosten fix, so muss die Komponente nur einmal vorhanden - * sein und der cast_level ändert sich nicht */ + * sein und der cast_level aendert sich nicht */ if (sp->components[k].cost == SPC_FIX) { if (maxlevel < 1) cast_level = 0; - /* ansonsten wird das Minimum aus maximal möglicher Stufe und der - * gewünschten gebildet */ + /* ansonsten wird das Minimum aus maximal moeglicher Stufe und der + * gewuenschten gebildet */ } else if (sp->components[k].cost == SPC_LEVEL) { costtyp = SPC_LEVEL; if (maxlevel < cast_level) { cast_level = maxlevel; } - /* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden - * sein, ansonsten schlägt der Spruch fehl */ + /* bei Typ Linear muessen die Kosten in Hoehe der Stufe vorhanden + * sein, ansonsten schlaegt der Spruch fehl */ } else if (sp->components[k].cost == SPC_LINEAR) { costtyp = SPC_LINEAR; @@ -844,7 +846,7 @@ int eff_spelllevel(unit * u, unit *caster, const spell * sp, int cast_level, int /* ------------------------------------------------------------- */ /* Die Spruchgrundkosten werden mit der Entfernung (Farcasting) * multipliziert, wobei die Aurakosten ein Sonderfall sind, da sie sich - * auch durch die Menge der bereits gezauberten Sprüche erhöht. + * auch durch die Menge der bereits gezauberten Sprueche erhoeht. * Je nach Kostenart werden dann die Komponenten noch mit cast_level * multipliziert. */ @@ -868,7 +870,7 @@ void pay_spell(unit * mage, const unit *caster, const spell * sp, int cast_level /* ------------------------------------------------------------- */ /* Ein Magier kennt den Spruch und kann sich die Beschreibung anzeigen * lassen, wenn diese in seiner Spruchliste steht. Zaubern muss er ihn - * aber dann immer noch nicht können, vieleicht ist seine Stufe derzeit + * aber dann immer noch nicht koennen, vieleicht ist seine Stufe derzeit * nicht ausreichend oder die Komponenten fehlen. */ bool knowsspell(const region * r, const unit * u, const spell * sp) @@ -882,7 +884,7 @@ bool knowsspell(const region * r, const unit * u, const spell * sp) /* Um einen Spruch zu beherrschen, muss der Magier die Stufe des * Spruchs besitzen, nicht nur wissen, das es ihn gibt (also den Spruch * in seiner Spruchliste haben). - * Kosten für einen Spruch können Magiepunkte, Silber, Kraeuter + * Kosten fuer einen Spruch koennen Magiepunkte, Silber, Kraeuter * und sonstige Gegenstaende sein. */ @@ -899,7 +901,7 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord) } /* reicht die Stufe aus? */ if (effskill(u, SK_MAGIC, NULL) < level) { - /* die Einheit ist nicht erfahren genug für diesen Zauber */ + /* die Einheit ist nicht erfahren genug fuer diesen Zauber */ cmistake(u, ord, 169, MSG_MAGIC); return false; } @@ -910,11 +912,11 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord) const resource_type *rtype = spc->type; int itemhave, itemanz; - /* Die Kosten für Aura sind auch von der Zahl der bereits - * gezauberten Sprüche abhängig */ + /* Die Kosten fuer Aura sind auch von der Zahl der bereits + * gezauberten Sprueche abhaengig */ itemanz = spellcost(u, spc) * range; - /* sind die Kosten stufenabhängig, so muss itemanz noch mit dem + /* sind die Kosten stufenabhaengig, so muss itemanz noch mit dem * level multipliziert werden */ switch (spc->cost) { case SPC_LEVEL: @@ -957,7 +959,7 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord) * Spruchitems und Antimagiefeldern zusammen. Es koennen noch die * Stufe des Spruchs und Magiekosten mit einfliessen. * - * Die effektive Spruchstärke und ihre Auswirkungen werden in der + * Die effektive Spruchstaerke und ihre Auswirkungen werden in der * Spruchfunktionsroutine ermittelt. */ @@ -1041,7 +1043,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order } /* ------------------------------------------------------------- */ -/* farcasting() == 1 -> gleiche Region, da man mit Null nicht vernünfigt +/* farcasting() == 1 -> gleiche Region, da man mit Null nicht vernuenfigt * rechnen kann */ static int farcasting(unit * magician, region * r) { @@ -1136,7 +1138,7 @@ variant magic_resistance(unit * target) /* Bonus durch Artefakte */ /* TODO (noch gibs keine) */ - /* Bonus durch Gebäude */ + /* Bonus durch Gebaeude */ { struct building *b = inside_building(target); const struct building_type *btype = building_is_active(b) ? b->type : NULL; @@ -1157,14 +1159,14 @@ variant magic_resistance(unit * target) } /* ------------------------------------------------------------- */ -/* Prüft, ob das Objekt dem Zauber widerstehen kann. - * Objekte können Regionen, Units, Gebäude oder Schiffe sein. +/* Prueft, ob das Objekt dem Zauber widerstehen kann. + * Objekte koennen Regionen, Units, Gebaeude oder Schiffe sein. * TYP_UNIT: - * Das höchste Talent des Ziels ist sein 'Magieresistenz-Talent', Magier - * bekommen einen Bonus. Grundchance ist 50%, für jede Stufe - * Unterschied gibt es 5%, minimalchance ist 5% für jeden (5-95%) + * Das hoechste Talent des Ziels ist sein 'Magieresistenz-Talent', Magier + * bekommen einen Bonus. Grundchance ist 50%, fuer jede Stufe + * Unterschied gibt es 5%, minimalchance ist 5% fuer jeden (5-95%) * Scheitert der Spruch an der Magieresistenz, so gibt die Funktion - * true zurück + * true zurueck */ bool @@ -1238,8 +1240,8 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) } /* gibt true, wenn die Zufallszahl kleiner als die chance ist und - * false, wenn sie gleich oder größer ist, dh je größer die - * Magieresistenz (chance) desto eher gibt die Funktion true zurück */ + * false, wenn sie gleich oder groesser ist, dh je groesser die + * Magieresistenz (chance) desto eher gibt die Funktion true zurueck */ return rng_int() % prob.sa[1] < prob.sa[0]; } @@ -1266,7 +1268,7 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade) { /* X ergibt Zahl zwischen 1 und 0, je kleiner, desto besser der Magier. * 0,5*40-20=0, dh wenn der Magier doppelt so gut ist, wie der Spruch - * benötigt, gelingt er immer, ist er gleich gut, gelingt der Spruch mit + * benoetigt, gelingt er immer, ist er gleich gut, gelingt der Spruch mit * 20% Warscheinlichkeit nicht * */ @@ -1298,8 +1300,8 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade) fumble_chance += CHAOSPATZERCHANCE; } - /* wenn die Chance kleiner als 0 ist, können wir gleich false - * zurückgeben */ + /* wenn die Chance kleiner als 0 ist, koennen wir gleich false + * zurueckgeben */ if (fumble_chance <= 0) { return false; } @@ -1309,7 +1311,7 @@ bool fumble(region * r, unit * u, const spell * sp, int cast_grade) } /* ------------------------------------------------------------- */ -/* Dummy-Zauberpatzer, Platzhalter für speziell auf die Sprüche +/* Dummy-Zauberpatzer, Platzhalter fuer speziell auf die Sprueche * zugeschnittene Patzer */ static void fumble_default(castorder * co) { @@ -1320,7 +1322,7 @@ static void fumble_default(castorder * co) return; } -/* Die normalen Spruchkosten müssen immer bezahlt werden, hier noch +/* Die normalen Spruchkosten muessen immer bezahlt werden, hier noch * alle weiteren Folgen eines Patzers */ @@ -1391,7 +1393,7 @@ static void do_fumble(castorder * co) break; case 3: case 4: - /* Spruch schlägt fehl, alle Magiepunkte weg */ + /* Spruch schlaegt fehl, alle Magiepunkte weg */ set_spellpoints(mage, 0); ADDMSG(&mage->faction->msgs, msg_message("patzer3", "unit region spell", mage, r, sp)); @@ -1410,7 +1412,7 @@ static void do_fumble(castorder * co) case 8: case 9: default: - /* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */ + /* Spruch gelingt, alle nachfolgenden Sprueche werden 2^4 so teuer */ co->level = cast_spell(co); ADDMSG(&mage->faction->msgs, msg_message("patzer5", "unit region spell", mage, r, sp)); @@ -1423,7 +1425,7 @@ static void do_fumble(castorder * co) /* ------------------------------------------------------------- */ /* Ein Magier regeneriert pro Woche W(Stufe^1.5/2+1), mindestens 1 - * Zwerge nur die Hälfte + * Zwerge nur die Haelfte */ static double regeneration(unit * u) { @@ -1440,7 +1442,7 @@ static double regeneration(unit * u) /* Einfluss von Artefakten */ /* TODO (noch gibs keine) */ - /* Würfeln */ + /* Wuerfeln */ aura = (rng_double() * d + rng_double() * d) / 2 + 1; aura *= MagicRegeneration(); @@ -1470,8 +1472,8 @@ void regenerate_aura(void) const struct building_type *btype = building_is_active(b) ? b->type : NULL; reg_aura = regeneration(u); - /* Magierturm erhöht die Regeneration um 75% */ - /* Steinkreis erhöht die Regeneration um 50% */ + /* Magierturm erhoeht die Regeneration um 75% */ + /* Steinkreis erhoeht die Regeneration um 50% */ if (btype) reg_aura *= btype->auraregen; @@ -1613,14 +1615,14 @@ verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj, /* ------------------------------------------------------------- */ /* Zuerst wird versucht alle noch nicht gefundenen Objekte zu finden - * oder zu prüfen, ob das gefundene Objekt wirklich hätte gefunden - * werden dürfen (nicht alle Zauber wirken global). Dabei zählen wir die + * oder zu pruefen, ob das gefundene Objekt wirklich haette gefunden + * werden duerfen (nicht alle Zauber wirken global). Dabei zaehlen wir die * Misserfolge (failed). * Dann folgen die Tests der gefundenen Objekte auf Magieresistenz und - * Sichtbarkeit. Dabei zählen wir die magieresistenten (resists) + * Sichtbarkeit. Dabei zaehlen wir die magieresistenten (resists) * Objekte. Alle anderen werten wir als Erfolge (success) */ - /* gibt bei Misserfolg 0 zurück, bei Magieresistenz zumindeste eines + /* gibt bei Misserfolg 0 zurueck, bei Magieresistenz zumindeste eines * Objektes 1 und bei Erfolg auf ganzer Linie 2 */ static void verify_targets(castorder * co, int *invalid, int *resist, int *success) @@ -1638,8 +1640,8 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) int i; /* zuerst versuchen wir vorher nicht gefundene Objekte zu finden. * Wurde ein Objekt durch globalsuche gefunden, obwohl der Zauber - * gar nicht global hätte suchen dürften, setzen wir das Objekt - * zurück. */ + * gar nicht global haette suchen duerften, setzen wir das Objekt + * zurueck. */ for (i = 0; i < sa->length; i++) { spllprm *spobj = sa->param[i]; @@ -1723,7 +1725,7 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) case SPP_REGION: /* haben wir ein Regionsobjekt, dann wird auch dieses und - nicht target_r überprüft. */ + nicht target_r ueberprueft. */ tr = spobj->data.r; if ((sp->sptyp & TESTRESISTANCE) @@ -1749,7 +1751,7 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) else { /* der Zauber hat keine expliziten Parameter/Ziele, es kann sich * aber um einen Regionszauber handeln. Wenn notwendig hier die - * Magieresistenz der Region prüfen. */ + * Magieresistenz der Region pruefen. */ if ((sp->sptyp & REGIONSPELL)) { /* Zielobjekt Region anlegen */ spllprm *spobj = (spllprm *)malloc(sizeof(spllprm)); @@ -1788,7 +1790,7 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) } /* ------------------------------------------------------------- */ -/* Hilfsstrukturen für ZAUBERE */ +/* Hilfsstrukturen fuer ZAUBERE */ /* ------------------------------------------------------------- */ static void free_spellparameter(spellparameter * pa) @@ -1979,7 +1981,7 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, break; case '+': /* das vorhergehende Element kommt ein oder mehrmals vor, wir - * springen zum key zurück */ + * springen zum key zurueck */ j = 0; --c; break; @@ -2116,7 +2118,7 @@ void free_castorder(struct castorder *co) if (co->order) free_order(co->order); } -/* Hänge c-order co an die letze c-order von cll an */ +/* Haenge c-order co an die letze c-order von cll an */ void add_castorder(spellrank * cll, castorder * co) { if (cll->begin == NULL) { @@ -2546,7 +2548,7 @@ static castorder *cast_cmd(unit * u, order * ord) init_order_depr(ord); s = gettoken(token, sizeof(token)); param = findparam(s, u->faction->locale); - /* für Syntax ' STUFE x REGION y z ' */ + /* fuer Syntax ' STUFE x REGION y z ' */ if (param == P_LEVEL) { int p = getint(); if (level > p) level = p; @@ -2575,8 +2577,8 @@ static castorder *cast_cmd(unit * u, order * ord) s = gettoken(token, sizeof(token)); param = findparam(s, u->faction->locale); } - /* für Syntax ' REGION x y STUFE z ' - * hier nach REGION nochmal auf STUFE prüfen */ + /* fuer Syntax ' REGION x y STUFE z ' + * hier nach REGION nochmal auf STUFE pruefen */ if (param == P_LEVEL) { int p = getint(); if (level > p) level = p; @@ -2595,8 +2597,8 @@ static castorder *cast_cmd(unit * u, order * ord) sp = unit_getspell(u, s, u->faction->locale); - /* Vertraute können auch Zauber sprechen, die sie selbst nicht - * können. unit_getspell findet aber nur jene Sprüche, die + /* Vertraute koennen auch Zauber sprechen, die sie selbst nicht + * koennen. unit_getspell findet aber nur jene Sprueche, die * die Einheit beherrscht. */ if (!sp && is_familiar(u)) { mage = get_familiar_mage(u); @@ -2619,7 +2621,7 @@ static castorder *cast_cmd(unit * u, order * ord) /* um testen auf spruchnamen zu unterbinden sollte vor allen * fehlermeldungen die anzeigen das der magier diesen Spruch * nur in diese Situation nicht anwenden kann, noch eine - * einfache Sicherheitsprüfung kommen */ + * einfache Sicherheitspruefung kommen */ if (!knowsspell(r, u, sp)) { /* vorsicht! u kann der familiar sein */ if (!familiar) { @@ -2632,9 +2634,9 @@ static castorder *cast_cmd(unit * u, order * ord) cmistake(u, ord, 174, MSG_MAGIC); return 0; } - /* Auf dem Ozean Zaubern als quasi-langer Befehl können + /* Auf dem Ozean Zaubern als quasi-langer Befehl koennen * normalerweise nur Meermenschen, ausgenommen explizit als - * OCEANCASTABLE deklarierte Sprüche */ + * OCEANCASTABLE deklarierte Sprueche */ if (fval(r->terrain, SEA_REGION)) { if (u_race(u) != get_race(RC_AQUARIAN) && !fval(u_race(u), RCF_SWIM) @@ -2657,7 +2659,7 @@ static castorder *cast_cmd(unit * u, order * ord) } } } - /* Farcasting bei nicht farcastbaren Sprüchen abfangen */ + /* Farcasting bei nicht farcastbaren Spruechen abfangen */ range = farcasting(u, target_r); if (range > 1) { if (!(sp->sptyp & FARCASTING)) { @@ -2672,7 +2674,7 @@ static castorder *cast_cmd(unit * u, order * ord) return 0; } } - /* Stufenangabe bei nicht Stufenvariierbaren Sprüchen abfangen */ + /* Stufenangabe bei nicht Stufenvariierbaren Spruechen abfangen */ if (!(sp->sptyp & SPELLLEVEL)) { int ilevel = effskill(u, SK_MAGIC, NULL); if (ilevel != level) { @@ -2707,7 +2709,7 @@ static castorder *cast_cmd(unit * u, order * ord) "mage", mage)); return 0; } - /* mage auf magier setzen, level anpassen, range für Erhöhung + /* mage auf magier setzen, level anpassen, range fuer Erhoehung * der Spruchkosten nutzen */ range *= 2; sk /= 2; @@ -2747,19 +2749,19 @@ static castorder *cast_cmd(unit * u, order * ord) /* ------------------------------------------------------------- */ /* Damit man keine Rituale in fremden Gebiet machen kann, diese vor * Bewegung zaubern. Magier sind also in einem fremden Gebiet eine Runde - * lang verletzlich, da sie es betreten, und angegriffen werden können, - * bevor sie ein Ritual machen können. + * lang verletzlich, da sie es betreten, und angegriffen werden koennen, + * bevor sie ein Ritual machen koennen. * * Syntax: ZAUBER [REGION X Y] [STUFE ] "Spruchname" [Einheit-1 * Einheit-2 ..] * - * Nach Priorität geordnet die Zauber global auswerten. + * Nach Prioritaet geordnet die Zauber global auswerten. * - * Die Kosten für Farcasting multiplizieren sich mit der Entfernung, + * Die Kosten fuer Farcasting multiplizieren sich mit der Entfernung, * cast_level gibt die virtuelle Stufe an, die den durch das Farcasten * entstandenen Spruchkosten entspricht. Sind die Spruchkosten nicht - * levelabhängig, so sind die Kosten nur von der Entfernung bestimmt, - * die Stärke/Level durch den realen Skill des Magiers + * levelabhaengig, so sind die Kosten nur von der Entfernung bestimmt, + * die Staerke/Level durch den realen Skill des Magiers */ void magic(void) @@ -2800,11 +2802,11 @@ void magic(void) } } - /* Da sich die Aura und Komponenten in der Zwischenzeit verändert - * haben können und sich durch vorherige Sprüche das Zaubern - * erschwert haben kann, muss beim zaubern erneut geprüft werden, ob der - * Spruch überhaupt gezaubert werden kann. - * (level) die effektive Stärke des Spruchs (= Stufe, auf der der + /* Da sich die Aura und Komponenten in der Zwischenzeit veraendert + * haben koennen und sich durch vorherige Sprueche das Zaubern + * erschwert haben kann, muss beim zaubern erneut geprueft werden, ob der + * Spruch ueberhaupt gezaubert werden kann. + * (level) die effektive Staerke des Spruchs (= Stufe, auf der der * Spruch gezaubert wird) */ for (rank = 0; rank < MAX_SPELLRANK; rank++) { @@ -2828,30 +2830,30 @@ void magic(void) } if (cast_level > co->level) { - /* Sprüche mit Fixkosten werden immer auf Stufe des Spruchs - * gezaubert, co->level ist aber defaultmäßig Stufe des Magiers */ + /* Sprueche mit Fixkosten werden immer auf Stufe des Spruchs + * gezaubert, co->level ist aber defaultmaessig Stufe des Magiers */ if (spl_costtyp(sp) != SPC_FIX) { ADDMSG(&mage->faction->msgs, msg_message("missing_components", "unit spell level", mage, sp, cast_level)); } } - /* Prüfen, ob die realen Kosten für die gewünschten Stufe bezahlt - * werden können */ + /* Pruefen, ob die realen Kosten fuer die gewuenschten Stufe bezahlt + * werden koennen */ if (!cancast(mage, sp, co->level, co->distance, ord)) { /* die Fehlermeldung wird in cancast generiert */ continue; } co->force = MagicPower(spellpower(target_r, mage, sp, co->level, ord)); - /* die Stärke kann durch Antimagie auf 0 sinken */ + /* die Staerke kann durch Antimagie auf 0 sinken */ if (co->force <= 0) { co->force = 0; ADDMSG(&mage->faction->msgs, msg_message("missing_force", "unit spell level", mage, sp, co->level)); } - /* Ziele auf Existenz prüfen und Magieresistenz feststellen. Wurde + /* Ziele auf Existenz pruefen und Magieresistenz feststellen. Wurde * kein Ziel gefunden, so ist verify_targets=0. Scheitert der * Spruch an der Magieresistenz, so ist verify_targets = 1, bei * Erfolg auf ganzer Linie ist verify_targets= 2 @@ -2859,8 +2861,8 @@ void magic(void) verify_targets(co, &invalid, &resist, &success); if (success + resist == 0) { /* kein Ziel gefunden, Fehlermeldungen sind in verify_targets */ - /* keine kosten für den zauber */ - continue; /* äußere Schleife, nächster Zauberer */ + /* keine kosten fuer den zauber */ + continue; /* aeussere Schleife, naechster Zauberer */ } else if (co->force > 0 && resist > 0) { /* einige oder alle Ziele waren magieresistent */ @@ -2873,8 +2875,8 @@ void magic(void) } } - /* Auch für Patzer gibt es Erfahrung, müssen die Spruchkosten - * bezahlt werden und die nachfolgenden Sprüche werden teurer */ + /* Auch fuer Patzer gibt es Erfahrung, muessen die Spruchkosten + * bezahlt werden und die nachfolgenden Sprueche werden teurer */ if (co->force > 0) { if (fumble(target_r, mage, sp, co->level)) { /* zuerst bezahlen, dann evt in do_fumble alle Aura verlieren */ @@ -2883,12 +2885,12 @@ void magic(void) else { co->level = cast_spell(co); if (co->level <= 0) { - /* Kosten nur für real benötige Stufe berechnen */ + /* Kosten nur fuer real benoetige Stufe berechnen */ continue; } } } - /* erst bezahlen, dann Kostenzähler erhöhen */ + /* erst bezahlen, dann Kostenzaehler erhoehen */ if (co->level > 0) { pay_spell(mage, caster, sp, co->level, co->distance); } diff --git a/src/move.c b/src/move.c index feadbdb52..baddba11e 100644 --- a/src/move.c +++ b/src/move.c @@ -108,7 +108,7 @@ static attrib_type at_traveldir = { "traveldir", DEFAULT_INIT, DEFAULT_FINALIZE, - DEFAULT_AGE, /* Weil normales Aging an ungünstiger Stelle */ + DEFAULT_AGE, /* Weil normales Aging an unguenstiger Stelle */ a_writechars, a_readchars }; @@ -267,8 +267,8 @@ static int ridingcapacity(const unit * u) get_transporters(u->items, &animals, &acap, &vehicles, &vcap); - /* Man trägt sein eigenes Gewicht plus seine Kapazität! Die Menschen - ** tragen nichts (siehe walkingcapacity). Ein Wagen zählt nur, wenn er + /* Man traegt sein eigenes Gewicht plus seine Kapazitaet! Die Menschen + ** tragen nichts (siehe walkingcapacity). Ein Wagen zaehlt nur, wenn er ** von zwei Pferden gezogen wird */ horses = effskill(u, SK_RIDING, NULL) * u->number * 2; @@ -277,7 +277,7 @@ static int ridingcapacity(const unit * u) if (fval(u_race(u), RCF_HORSE)) animals += u->number; - /* maximal diese Pferde können zum Ziehen benutzt werden */ + /* maximal diese Pferde koennen zum Ziehen benutzt werden */ horses = animals / HORSES_PER_CART; if (horses < vehicles) vehicles = horses; @@ -308,7 +308,7 @@ int walkingcapacity(const struct unit *u) people = u->number; } - /* maximal diese Pferde können zum Ziehen benutzt werden */ + /* maximal diese Pferde koennen zum Ziehen benutzt werden */ horses = pferde_fuer_wagen / HORSES_PER_CART; wagen_mit_pferden = (vehicles < horses) ? vehicles : horses; @@ -326,7 +326,7 @@ int walkingcapacity(const struct unit *u) wagen_mit_trollen = wagen_ohne_pferde; } - /* Wagenkapazität hinzuzählen */ + /* Wagenkapazitaet hinzuzaehlen */ n += wagen_mit_trollen * vcap; } @@ -390,15 +390,15 @@ static int canwalk(unit * u) if (walkingcapacity(u) - eff_weight(u) >= 0) return E_CANWALK_OK; - /* Stimmt das Gewicht, impliziert dies hier, daß alle Wagen ohne + /* Stimmt das Gewicht, impliziert dies hier, dass alle Wagen ohne * Zugpferde/-trolle als Fracht aufgeladen wurden: zu viele Pferde hat * die Einheit nicht zum Ziehen benutzt, also nicht mehr Wagen gezogen * als erlaubt. */ if (vehicles > maxwagen) return E_CANWALK_TOOMANYCARTS; - /* Es muß nicht zwingend an den Wagen liegen, aber egal... (man - * könnte z.B. auch 8 Eisen abladen, damit ein weiterer Wagen als + /* Es muss nicht zwingend an den Wagen liegen, aber egal... (man + * koennte z.B. auch 8 Eisen abladen, damit ein weiterer Wagen als * Fracht draufpasst) */ return E_CANWALK_TOOHEAVY; @@ -682,7 +682,7 @@ int check_ship_allowed(struct ship *sh, const region * r) const building_type *bt_harbour = bt_find("harbour"); if (sh->region && r_insectstalled(r)) { - /* insekten dürfen nicht hier rein. haben wir welche? */ + /* insekten duerfen nicht hier rein. haben wir welche? */ unit *u = ship_owner(sh); if (u && is_freezing(u)) { @@ -828,19 +828,19 @@ static void drifting_ships(region * r) sh->flags |= SF_FISHING; } - /* Schiff schon abgetrieben oder durch Zauber geschützt? */ + /* Schiff schon abgetrieben oder durch Zauber geschuetzt? */ if (!drift || fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, &ct_nodrift)) { shp = &sh->next; continue; } - /* Kapitän bestimmen */ + /* Kapitaen bestimmen */ captain = ship_owner(sh); if (captain && effskill(captain, SK_SAILING, r) < sh->type->cptskill) captain = NULL; - /* Kapitän da? Beschädigt? Genügend Matrosen? - * Genügend leicht? Dann ist alles OK. */ + /* Kapitaen da? Beschaedigt? Genuegend Matrosen? + * Genuegend leicht? Dann ist alles OK. */ if (captain && sh->size == sh->type->construction->maxsize && enoughsailors(sh, crew_skill(sh)) && cansail(r, sh)) { @@ -851,7 +851,7 @@ static void drifting_ships(region * r) ovl = overload(r, sh); if (ovl < overload_start()) { /* Auswahl einer Richtung: Zuerst auf Land, dann - * zufällig. Falls unmögliches Resultat: vergiß es. */ + * zufaellig. Falls unmoegliches Resultat: vergiss es. */ dir = drift_target(sh); if (dir != NODIRECTION) { rnext = rconnect(sh->region, dir); @@ -1388,12 +1388,12 @@ static void make_route(unit * u, order * ord, region_list ** routep) /** calculate the speed of a unit * - * zu Fuß reist man 1 Region, zu Pferd 2 Regionen. Mit Straßen reist - * man zu Fuß 2, mit Pferden 3 weit. + * zu Fuss reist man 1 Region, zu Pferd 2 Regionen. Mit Strassen reist + * man zu Fuss 2, mit Pferden 3 weit. * - * Berechnet wird das mit BPs. Zu Fuß hat man 4 BPs, zu Pferd 6. - * Normalerweise verliert man 3 BP pro Region, bei Straßen nur 2 BP. - * Außerdem: Wenn Einheit transportiert, nur halbe BP + * Berechnet wird das mit BPs. Zu Fuss hat man 4 BPs, zu Pferd 6. + * Normalerweise verliert man 3 BP pro Region, bei Strassen nur 2 BP. + * Ausserdem: Wenn Einheit transportiert, nur halbe BP */ int movement_speed(const unit * u) { @@ -1514,7 +1514,7 @@ static const region_list *travel_route(unit * u, landing = true; } else if ((u_race(u)->flags & RCF_WALK) == 0) { - /* Spezialeinheiten, die nicht laufen können. */ + /* Spezialeinheiten, die nicht laufen koennen. */ ADDMSG(&u->faction->msgs, msg_message("detectocean", "unit region terrain", u, next, terrain_name(next))); break; @@ -1527,7 +1527,7 @@ static const region_list *travel_route(unit * u, } } else { - /* Ozeanfelder können nur von Einheiten mit Schwimmen und ohne + /* Ozeanfelder koennen nur von Einheiten mit Schwimmen und ohne * Pferde betreten werden. */ if (!(canswim(u) || canfly(u))) { ADDMSG(&u->faction->msgs, msg_message("detectocean", @@ -1626,7 +1626,7 @@ static const region_list *travel_route(unit * u, walkmode = 2; } - /* Berichte über Durchreiseregionen */ + /* Berichte ueber Durchreiseregionen */ if (mode != TRAVEL_TRANSPORTED) { arg_regions *ar = var_copy_regions(route_begin, steps - 1); @@ -1690,7 +1690,7 @@ unit *owner_buildingtyp(const region * r, const building_type * bt) return NULL; } -/* Prüft, ob Ablegen von einer Küste in eine der erlaubten Richtungen erfolgt. */ +/* Prueft, ob Ablegen von einer Kueste in eine der erlaubten Richtungen erfolgt. */ bool can_takeoff(const ship * sh, const region * from, const region * to) { if (!fval(from->terrain, SEA_REGION) && sh->coast != NODIRECTION) { @@ -1742,18 +1742,18 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) return; /* Wir suchen so lange nach neuen Richtungen, wie es geht. Diese werden - * dann nacheinander ausgeführt. */ + * dann nacheinander ausgefuehrt. */ k = shipspeed(sh, u); last_point = starting_point; current_point = starting_point; - /* die nächste Region, in die man segelt, wird durch movewhere () aus der + /* die naechste Region, in die man segelt, wird durch movewhere () aus der * letzten Region bestimmt. * * Anfangen tun wir bei starting_point. next_point ist beim ersten - * Durchlauf schon gesetzt (Parameter!). current_point ist die letzte gültige, + * Durchlauf schon gesetzt (Parameter!). current_point ist die letzte gueltige, * befahrene Region. */ while (next_point && current_point != next_point && step < k) { @@ -1795,7 +1795,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) bool storm = true; int d_offset = rng_int() % MAXDIRECTIONS; direction_t d; - /* Sturm nur, wenn nächste Region Hochsee ist. */ + /* Sturm nur, wenn naechste Region Hochsee ist. */ for (d = 0; d != MAXDIRECTIONS; ++d) { direction_t dnext = (direction_t)((d + d_offset) % MAXDIRECTIONS); region *rn = rconnect(current_point, dnext); @@ -1933,16 +1933,16 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) sh = NULL; } - /* Nun enthält current_point die Region, in der das Schiff seine Runde - * beendet hat. Wir generieren hier ein Ereignis für den Spieler, das - * ihm sagt, bis wohin er gesegelt ist, falls er überhaupt vom Fleck - * gekommen ist. Das ist nicht der Fall, wenn er von der Küste ins + /* Nun enthaelt current_point die Region, in der das Schiff seine Runde + * beendet hat. Wir generieren hier ein Ereignis fuer den Spieler, das + * ihm sagt, bis wohin er gesegelt ist, falls er ueberhaupt vom Fleck + * gekommen ist. Das ist nicht der Fall, wenn er von der Kueste ins * Inland zu segeln versuchte */ if (sh != NULL && fval(sh, SF_MOVED)) { unit *harbourmaster; /* nachdem alle Richtungen abgearbeitet wurden, und alle Einheiten - * transferiert wurden, kann der aktuelle Befehl gelöscht werden. */ + * transferiert wurden, kann der aktuelle Befehl geloescht werden. */ if (getkeyword(ord) == K_ROUTE) { order * norder = cycle_route(ord, u->faction->locale, step); replace_order(&u->orders, ord, norder); @@ -1969,7 +1969,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) move_ship(sh, starting_point, current_point, routep ? *routep : NULL); - /* Hafengebühren ? */ + /* Hafengebuehren ? */ harbourmaster = owner_buildingtyp(current_point, bt_find("harbour")); if (harbourmaster != NULL) { @@ -2316,7 +2316,7 @@ int follow_ship(unit * u, order * ord) /* NACH ignorieren und Parsing initialisieren. */ init_tokens_str(command); getstrtoken(); - /* NACH ausführen */ + /* NACH ausfuehren */ move_cmd(u, ord); return 1; /* true -> Einheitenliste von vorne durchgehen */ } @@ -2499,7 +2499,7 @@ void movement(void) if (repeat) continue; if (ships == 0) { - /* Abtreiben von beschädigten, unterbemannten, überladenen Schiffen */ + /* Abtreiben von beschaedigten, unterbemannten, ueberladenen Schiffen */ drifting_ships(r); } r = r->next; diff --git a/src/orderfile.c b/src/orderfile.c index 0ebb7ff2c..12cb05834 100644 --- a/src/orderfile.c +++ b/src/orderfile.c @@ -108,7 +108,7 @@ static void unitorders(input *in, faction *f) } } } - /* Nun wird der Befehl erzeut und eingeh�ngt */ + /* Nun wird der Befehl erzeut und eingehaengt */ *ordp = parse_order(s, u->faction->locale); if (*ordp) { ordp = &(*ordp)->next; @@ -137,7 +137,7 @@ static faction *factionorders(void) return 0; } /* Die Partei hat sich zumindest gemeldet, so dass sie noch - * nicht als unt�tig gilt */ + * nicht als untaetig gilt */ f->lastorders = turn; } @@ -201,11 +201,12 @@ int read_orders(input *in) break; /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue - * Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut - * durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf - * auf alle F�lle nicht �berschreiben! Bei allen anderen Eintr�gen hier - * muss buf erneut gef�llt werden, da die betreffende Information in nur - * einer Zeile steht, und nun die n�chste gelesen werden muss. */ + * Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut + * durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf + * auf alle Faelle nicht ueberschreiben! Bei allen anderen Eintraegen hier + * muss buf erneut gefaellt werden, da die betreffende Information in nur + * einer Zeile steht, und nun die naechste gelesen werden muss. + */ case P_NEXT: f = NULL; diff --git a/src/races/races.c b/src/races/races.c index 7eede1b38..b5cc3772a 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -75,7 +75,7 @@ void equip_newunits(struct unit *u) } } -/* Die Funktionen werden �ber den hier registrierten Namen in races.xml +/* Die Funktionen werden ueber den hier registrierten Namen in races.xml * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { diff --git a/src/randenc.c b/src/randenc.c index 79998c14b..b0e5dd13a 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -75,7 +75,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern struct attrib_type at_unitdissolve; /* In a->data.ca[1] steht der Prozentsatz mit dem sich die Einheit - * aufl�st, in a->data.ca[0] kann angegeben werden, wohin die Personen + * aufloest, in a->data.ca[0] kann angegeben werden, wohin die Personen * verschwinden. Passiert bereits in der ersten Runde! */ static void dissolve_units(void) { @@ -187,12 +187,12 @@ static void melt_iceberg(region * r, const terrain_type *t_ocean) ADDMSG(&u->faction->msgs, msg_message("iceberg_melt", "region", r)); } - /* driftrichtung l�schen */ + /* driftrichtung loeschen */ a = a_find(r->attribs, &at_iceberg); if (a) a_remove(&r->attribs, a); - /* Geb�ude l�schen */ + /* Gebaeude loeschen */ while (r->buildings) { remove_building(&r->buildings, r->buildings); } @@ -260,13 +260,13 @@ static void move_iceberg(region * r) freset(sh, SF_SELECT); for (sh = r->ships; sh; sh = sh->next) { - /* Meldung an Kapit�n */ + /* Meldung an Kapitaen */ double dmg = config_get_flt("rules.ship.damage.intoiceberg", 0.1); damage_ship(sh, dmg); fset(sh, SF_SELECT); } - /* Personen, Schiffe und Geb�ude verschieben */ + /* Personen, Schiffe und Gebaeude verschieben */ while (rc->buildings) { rc->buildings->region = r; translist(&rc->buildings, &r->buildings, rc->buildings); @@ -285,7 +285,7 @@ static void move_iceberg(region * r) u_set_building(u, b); /* undo leave-prevention */ } - /* Besch�digte Schiffe k�nnen sinken */ + /* Beschaedigte Schiffe koennen sinken */ for (sh = r->ships; sh;) { shn = sh->next; @@ -475,7 +475,7 @@ static void orc_growth(void) } } -/** Talente von D�monen verschieben sich. +/** Talente von Daemonen verschieben sich. */ static void demon_skillchanges(void) { @@ -505,7 +505,7 @@ static void icebergs(void) move_icebergs(); } -#define HERBROTCHANCE 5 /* Verrottchance f�r Kr�uter (ifdef HERBS_ROT) */ +#define HERBROTCHANCE 5 /* Verrottchance fuer Kraeuter (ifdef HERBS_ROT) */ static void rotting_herbs(void) { diff --git a/src/tools/namegen.c b/src/tools/namegen.c index 2e277ce0c..1ef9b7bb7 100644 --- a/src/tools/namegen.c +++ b/src/tools/namegen.c @@ -125,7 +125,7 @@ static char *entish_syllable2[] = { }; static char *entish_syllable3[] = { - "Hueter", "Pflanzer", "Hirte", "Waechter", "Wachser", "Beschützer", + "H\xc3\xbcter", "Pflanzer", "Hirte", "W\xc3\xa4chter", "Wachser", "Besch\xc3\xbctzer", }; static char *cthuloid_syllable1[] = { @@ -200,13 +200,13 @@ static char *create_random_name(race_t race) strcat(name, orc_syllable3[rand() % (sizeof(orc_syllable3) / sizeof(char *))]); break; -/* + case RC_TREEMAN: strcpy(name, entish_syllable1[rand()%(sizeof(entish_syllable1) / sizeof(char*))]); strcat(name, entish_syllable2[rand()%(sizeof(entish_syllable2) / sizeof(char*))]); strcat(name, entish_syllable3[rand()%(sizeof(entish_syllable3) / sizeof(char*))]); break; -*/ + case RC_DAEMON: case RC_INSECT: strcpy(name, diff --git a/src/volcano.c b/src/volcano.c index d4d045045..91132db14 100644 --- a/src/volcano.c +++ b/src/volcano.c @@ -55,7 +55,7 @@ static int nb_armor(const unit * u, int index) if (!(u_race(u)->battle_flags & BF_EQUIPMENT)) return 0; - /* Normale R�stung */ + /* Normale Ruestung */ for (itm = u->items; itm; itm = itm->next) { const armor_type *atype = itm->type->rtype->atype; @@ -186,11 +186,11 @@ static region *rrandneighbour(region * r) for (i = 0; i != MAXDIRECTIONS; i++) { c++; } - /* Zuf�llig eine ausw�hlen */ + /* Zufaellig eine auswaehlen */ rr = rng_int() % c; - /* Durchz�hlen */ + /* Durchzaehlen */ c = -1; for (i = 0; i != MAXDIRECTIONS; i++) { @@ -221,7 +221,7 @@ volcano_destruction(region * volcano, region * r, const char *damage) else { /* Produktion vierteln ... */ a->data.sa[0] = (short)percent; - /* F�r 6-17 Runden */ + /* Fuer 6-17 Runden */ a->data.sa[1] = (short)(a->data.sa[1] + time); } From 1944c2c13604ad157088164598bc791605e5317a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 7 Feb 2019 20:33:20 +0100 Subject: [PATCH 70/85] asciify more files --- src/kernel/attrib.c | 4 +- src/kernel/building.c | 15 +++--- src/kernel/connection.c | 2 +- src/kernel/curse.c | 6 +-- src/kernel/ship.c | 2 +- src/kernel/spell.h | 20 ++++---- src/laws.c | 108 ++++++++++++++++++++-------------------- src/magic.h | 14 +++--- 8 files changed, 86 insertions(+), 85 deletions(-) diff --git a/src/kernel/attrib.c b/src/kernel/attrib.c index aca3d25ba..8b3e1c958 100644 --- a/src/kernel/attrib.c +++ b/src/kernel/attrib.c @@ -191,7 +191,7 @@ static attrib_type *at_find_key(unsigned int hk) if (!find) { const char *translate[3][2] = { { "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */ - { "verzaubert", "curse" }, /* remapping: früher verzaubert, jetzt curse */ + { "verzaubert", "curse" }, /* remapping: frueher verzaubert, jetzt curse */ { NULL, NULL } }; int i = 0; @@ -388,7 +388,7 @@ int a_age(attrib ** p, void *owner) { attrib **ap = p; /* Attribute altern, und die Entfernung (age()==0) eines Attributs - * hat Einfluß auf den Besitzer */ + * hat Einfluss auf den Besitzer */ while (*ap) { attrib *a = *ap; if (a->type->age) { diff --git a/src/kernel/building.c b/src/kernel/building.c index 09a515fc3..823ad1936 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -447,7 +447,7 @@ void remove_building(building ** blist, building * b) b->size = 0; bunhash(b); - /* Falls Karawanserei, Damm oder Tunnel einst�rzen, wird die schon + /* Falls Karawanserei, Damm oder Tunnel einstuerzen, wird die schon * gebaute Strasse zur Haelfte vernichtet */ if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) { int d; @@ -560,8 +560,8 @@ void building_set_owner(struct unit * owner) static unit *building_owner_ex(const building * bld, const struct faction * last_owner) { unit *u, *heir = 0; - /* Eigent�mer tot oder kein Eigent�mer vorhanden. Erste lebende Einheit - * nehmen. */ + /* Eigentuemer tot oder kein Eigentuemer vorhanden. + * Erste lebende Einheit nehmen. */ for (u = bld->region->units; u; u = u->next) { if (u->building == bld) { if (u->number > 0) { @@ -711,7 +711,7 @@ building *largestbuilding(const region * r, cmp_building_cb cmp_gt, } return best; } -/* Lohn bei den einzelnen Burgstufen f�r Normale Typen, Orks, Bauern */ +/* Lohn bei den einzelnen Burgstufen fuer Normale Typen, Orks, Bauern */ static const int wagetable[7][3] = { { 10, 10, 11 }, /* Baustelle */ @@ -770,7 +770,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) } vm = frac_make(wage, 1); - /* Bei einer D�rre verdient man nur noch ein Viertel */ + /* Bei einer Duerre verdient man nur noch ein Viertel */ c = get_curse(r->attribs, &ct_drought); if (c && curse_active(c)) { vm = frac_mul(vm, frac_make(1, curse_geteffect_int(c))); @@ -794,8 +794,9 @@ minimum_wage(const region * r, const faction * f, const race * rc, int in_turn) return default_wage(r, f, rc, in_turn); } -/* Gibt Arbeitslohn f�r entsprechende Rasse zur�ck, oder f�r -* die Bauern wenn f == NULL. */ +/** + * Gibt Arbeitslohn fuer entsprechende Rasse zurueck, oder fuer + * die Bauern wenn f == NULL. */ int wage(const region * r, const faction * f, const race * rc, int in_turn) { static int config; diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 61c96d9d4..d85f71910 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -621,7 +621,7 @@ int read_borders(gamedata *data) } if (type->read) { connection *b = new_border(type, from, to); - nextborder--; /* new_border erh�ht den Wert */ + nextborder--; /* new_border erhoeht den Wert */ b->id = bid; assert(bid <= nextborder); type->read(b, data); diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 945f60e7a..fbe9ed15d 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -402,8 +402,8 @@ static void set_cursevigour(curse * c, double vigour) c->vigour = vigour; } -/* veraendert die Stärke der Verzauberung um +i und gibt die neue - * Staerke zurueck. Sollte die Zauberstärke unter Null sinken, loest er +/* veraendert die Staerke der Verzauberung um +i und gibt die neue + * Staerke zurueck. Sollte die Zauberstaerke unter Null sinken, loest er * sich auf. */ double curse_changevigour(attrib ** ap, curse * c, double vigour) @@ -454,7 +454,7 @@ set_curseingmagician(struct unit *magician, struct attrib *ap_target, /* ------------------------------------------------------------- */ /* gibt bei Personenbeschraenkten Verzauberungen die Anzahl der - * betroffenen Personen zurueck. Ansonsten wird 0 zurückgegeben. */ + * betroffenen Personen zurueck. Ansonsten wird 0 zurueckgegeben. */ int get_cursedmen(const unit * u, const curse * c) { int cursedmen = u->number; diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 2ca3084fc..54264e95d 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -442,7 +442,7 @@ static unit * ship_owner_ex(const ship * sh, const struct faction * last_owner) { unit *u, *heir = 0; - /* Eigent�mer tot oder kein Eigent�mer vorhanden. Erste lebende Einheit + /* Eigentuemer tot oder kein Eigentuemer vorhanden. Erste lebende Einheit * nehmen. */ for (u = sh->region->units; u; u = u->next) { if (u->ship == sh) { diff --git a/src/kernel/spell.h b/src/kernel/spell.h index 62976af03..b38f77dee 100644 --- a/src/kernel/spell.h +++ b/src/kernel/spell.h @@ -144,34 +144,34 @@ extern "C" { * * u : eine Einheitennummer * r : hier kommen zwei Regionskoordinaten x y - * b : Geb�ude- oder Burgnummer + * b : Gebaeude- oder Burgnummer * s : Schiffsnummer - * c : String, wird ohne Weiterverarbeitung �bergeben - * i : Zahl (int), wird ohne Weiterverarbeitung �bergeben + * c : String, wird ohne Weiterverarbeitung uebergeben + * i : Zahl (int), wird ohne Weiterverarbeitung uebergeben * k : Keywort - dieser String gibt den Paramter an, der folgt. Der * Parameter wird mit findparam() identifiziert. - * k muss immer von einem c als Platzhalter f�r das Objekt gefolgt + * k muss immer von einem c als Platzhalter fuer das Objekt gefolgt * werden. - * Ein gutes Beispiel sind hierf�r die Spr�che zur Magieanalyse. + * Ein gutes Beispiel sind hierfuer die Sprueche zur Magieanalyse. * + : gibt an, das der vorherige Parameter mehrfach vorkommen kann. Da * ein Ende nicht definiert werden kann, muss dies immer am Schluss * kommen. * - * Flags f�r das Parsing: + * Flags fuer das Parsing: * TESTRESISTANCE : alle Zielobjekte, also alle Parameter vom Typ Unit, * Burg, Schiff oder Region, werden auf ihre - * Magieresistenz �berpr�ft + * Magieresistenz ueberprueft * TESTCANSEE : jedes Objekt vom Typ Einheit wird auf seine - * Sichtbarkeit �berpr�ft + * Sichtbarkeit ueberprueft * SEARCHLOCAL : die Zielobjekte werden nur regional gesucht * REGIONSPELL : Ziel ist die Region, auch wenn kein Zielobjekt * angegeben wird. Ist TESTRESISTANCE gesetzt, so wird - * die Magieresistenz der Region �berpr�ft + * die Magieresistenz der Region ueberprueft * * Bei fehlendem Ziel oder wenn dieses dem Zauber widersteht, wird die * Spruchfunktion nicht aufgerufen. * Sind zu wenig Parameter vorhanden, wird der Zauber ebenfalls nicht - * ausgef�hrt. + * ausgefuehrt. * Ist eins von mehreren Zielobjekten resistent, so wird das Flag * pa->param[n]->flag == TARGET_RESISTS * Ist eins von mehreren Zielobjekten nicht gefunden worden, so ist diff --git a/src/laws.c b/src/laws.c index 68d90d6f8..521ff92ab 100644 --- a/src/laws.c +++ b/src/laws.c @@ -202,7 +202,7 @@ static void dumbeffect(unit *u) { reduce_skill(u, sb, weeks); ADDMSG(&u->faction->msgs, msg_message("dumbeffect", "unit weeks skill", u, weeks, (skill_t)sb->id)); - } /* sonst Glück gehabt: wer nix weiss, kann nix vergessen... */ + } /* sonst Glueck gehabt: wer nix weiss, kann nix vergessen... */ change_effect(u, oldpotiontype[P_FOOL], -effect); } } @@ -249,7 +249,7 @@ static void live(region * r) while (*up) { unit *u = *up; /* IUW: age_unit() kann u loeschen, u->next ist dann - * undefiniert, also muessen wir hier schon das nächste + * undefiniert, also muessen wir hier schon das naechste * Element bestimmen */ age_unit(r, u); if (*up == u) @@ -378,17 +378,17 @@ static void peasants(region * r, int rule) peasants += births + luck; } - /* Alle werden satt, oder halt soviele für die es auch Geld gibt */ + /* Alle werden satt, oder halt soviele fuer die es auch Geld gibt */ satiated = money / maintenance_cost(NULL); if (satiated > peasants) satiated = peasants; rsetmoney(r, money - satiated * maintenance_cost(NULL)); /* Von denjenigen, die nicht satt geworden sind, verhungert der - * Großteil. dead kann nie größer als rpeasants(r) - satiated werden, - * so dass rpeasants(r) >= 0 bleiben muß. */ + * Grossteil. dead kann nie groesser als rpeasants(r) - satiated werden, + * so dass rpeasants(r) >= 0 bleiben muss. */ - /* Es verhungert maximal die unterernährten Bevölkerung. */ + /* Es verhungert maximal die unterernaehrten Bevoelkerung. */ n = peasants - satiated; if (n > rp) n = rp; @@ -456,9 +456,9 @@ static void migrate(region * r) rsethorses(r, rhorses(r) + m->horses); /* Was macht das denn hier? * Baumwanderung wird in trees() gemacht. - * wer fragt das? Die Baumwanderung war abhängig von der + * wer fragt das? Die Baumwanderung war abhaengig von der * Auswertungsreihenfolge der regionen, - * das hatte ich geändert. jemand hat es wieder gelöscht, toll. + * das hatte ich geaendert. jemand hat es wieder geloescht, toll. * ich habe es wieder aktiviert, muss getestet werden. */ *hp = m->next; @@ -500,7 +500,7 @@ static void horses(region * r) /* Pferde wandern in Nachbarregionen. * Falls die Nachbarregion noch berechnet * werden muss, wird eine migration-Struktur gebildet, - * die dann erst in die Berechnung der Nachbarstruktur einfließt. + * die dann erst in die Berechnung der Nachbarstruktur einfliesst. */ for (n = 0; n != MAXDIRECTIONS; n++) { @@ -514,7 +514,7 @@ static void horses(region * r) else { migration *nb; /* haben wir die Migration schonmal benutzt? - * wenn nicht, müssen wir sie suchen. + * wenn nicht, muessen wir sie suchen. * Wandernde Pferde vermehren sich nicht. */ nb = get_migrants(r2); @@ -620,12 +620,12 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) a = a_find(r->attribs, &at_germs); if (a && last_weeks_season == SEASON_SPRING) { - /* ungekeimte Samen bleiben erhalten, Sprößlinge wachsen */ + /* ungekeimte Samen bleiben erhalten, Sproesslinge wachsen */ sprout = rtrees(r, 1); if (sprout > a->data.sa[1]) sprout = a->data.sa[1]; - /* aus dem gesamt Sprößlingepool abziehen */ + /* aus dem gesamt Sproesslingepool abziehen */ rsettrees(r, 1, rtrees(r, 1) - sprout); - /* zu den Bäumen hinzufügen */ + /* zu den Baeumen hinzufuegen */ rsettrees(r, 2, rtrees(r, 2) + sprout); a_removeall(&r->attribs, &at_germs); @@ -642,7 +642,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) return; /* Grundchance 1.0% */ - /* Jeder Elf in der Region erhöht die Chance marginal */ + /* Jeder Elf in der Region erhoeht die Chance marginal */ mp = mp / 8; if (elves > mp) elves = mp; if (elves) { @@ -664,19 +664,19 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) } } - /* Bäume breiten sich in Nachbarregionen aus. */ + /* Baeume breiten sich in Nachbarregionen aus. */ /* Gesamtzahl der Samen: - * bis zu 6% (FORESTGROWTH*3) der Bäume samen in die Nachbarregionen */ + * bis zu 6% (FORESTGROWTH*3) der Baeume samen in die Nachbarregionen */ seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000; for (d = 0; d != MAXDIRECTIONS; ++d) { region *r2 = rconnect(r, d); if (r2 && fval(r2->terrain, LAND_REGION) && r2->terrain->size) { /* Eine Landregion, wir versuchen Samen zu verteilen: - * Die Chance, das Samen ein Stück Boden finden, in dem sie - * keimen können, hängt von der Bewuchsdichte und der - * verfügbaren Fläche ab. In Gletschern gibt es weniger - * Möglichkeiten als in Ebenen. */ + * Die Chance, das Samen ein Stueck Boden finden, in dem sie + * keimen koennen, haengt von der Bewuchsdichte und der + * verfuegbaren Flaeche ab. In Gletschern gibt es weniger + * Moeglichkeiten als in Ebenen. */ sprout = 0; seedchance = (1000.0 * region_maxworkers(r2)) / r2->terrain->size; for (i = 0; i < seeds / MAXDIRECTIONS; i++) { @@ -694,8 +694,8 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) if (is_cursed(r->attribs, &ct_godcursezone)) return; - /* in at_germs merken uns die Zahl der Samen und Sprößlinge, die - * dieses Jahr älter werden dürfen, damit nicht ein Same im selben + /* in at_germs merken uns die Zahl der Samen und Sproesslinge, die + * dieses Jahr aelter werden duerfen, damit nicht ein Same im selben * Zyklus zum Baum werden kann */ a = a_find(r->attribs, &at_germs); if (!a) { @@ -709,7 +709,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) /* Samenwachstum */ - /* Raubbau abfangen, es dürfen nie mehr Samen wachsen, als aktuell + /* Raubbau abfangen, es duerfen nie mehr Samen wachsen, als aktuell * in der Region sind */ seeds = rtrees(r, 0); if (seeds > a->data.sa[0]) seeds = a->data.sa[0]; @@ -723,15 +723,15 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) a->data.sa[0] = (short)(seeds - sprout); /* aus dem gesamt Samenpool abziehen */ rsettrees(r, 0, rtrees(r, 0) - sprout); - /* zu den Sprößlinge hinzufügen */ + /* zu den Sproesslinge hinzufuegen */ rsettrees(r, 1, rtrees(r, 1) + sprout); /* Baumwachstum */ - /* hier gehen wir davon aus, das Jungbäume nicht ohne weiteres aus - * der Region entfernt werden können, da Jungbäume in der gleichen - * Runde nachwachsen, wir also nicht mehr zwischen diesjährigen und - * 'alten' Jungbäumen unterscheiden könnten */ + /* hier gehen wir davon aus, das Jungbaeume nicht ohne weiteres aus + * der Region entfernt werden koennen, da Jungbaeume in der gleichen + * Runde nachwachsen, wir also nicht mehr zwischen diesjaehrigen und + * 'alten' Jungbaeumen unterscheiden koennten */ sprout = rtrees(r, 1); if (sprout > a->data.sa[1]) sprout = a->data.sa[1]; grownup_trees = 0; @@ -740,11 +740,11 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) if (rng_int() % 10000 < growth) grownup_trees++; } - /* aus dem Sprößlingepool dieses Jahres abziehen */ + /* aus dem Sproesslingepool dieses Jahres abziehen */ a->data.sa[1] = (short)(sprout - grownup_trees); - /* aus dem gesamt Sprößlingepool abziehen */ + /* aus dem gesamt Sproesslingepool abziehen */ rsettrees(r, 1, rtrees(r, 1) - grownup_trees); - /* zu den Bäumen hinzufügen */ + /* zu den Baeumen hinzufuegen */ rsettrees(r, 2, rtrees(r, 2) + grownup_trees); } } @@ -752,10 +752,10 @@ growing_trees(region * r, const int current_season, const int last_weeks_season) static void growing_herbs(region * r, const int current_season, const int last_weeks_season) { - /* Jetzt die Kräutervermehrung. Vermehrt wird logistisch: + /* Jetzt die Kraeutervermehrung. Vermehrt wird logistisch: * * Jedes Kraut hat eine Wahrscheinlichkeit von (100-(vorhandene - * Kräuter))% sich zu vermehren. */ + * Kraeuter))% sich zu vermehren. */ UNUSED_ARG(last_weeks_season); if (current_season != SEASON_WINTER) { int i, herbs = rherbs(r); @@ -1060,7 +1060,7 @@ int enter_building(unit * u, order * ord, int id, bool report) region *r = u->region; building *b; - /* Schwimmer können keine Gebäude betreten, außer diese sind + /* Schwimmer koennen keine Gebaeude betreten, ausser diese sind * auf dem Ozean */ if (!fval(u_race(u), RCF_WALK) && !fval(u_race(u), RCF_FLY)) { if (!fval(r->terrain, SEA_REGION)) { @@ -1169,8 +1169,8 @@ void do_enter(struct region *r, bool is_final_attempt) } if (ulast != NULL) { /* Wenn wir hier angekommen sind, war der Befehl - * erfolgreich und wir löschen ihn, damit er im - * zweiten Versuch nicht nochmal ausgeführt wird. */ + * erfolgreich und wir loeschen ihn, damit er im + * zweiten Versuch nicht nochmal ausgefuehrt wird. */ *ordp = ord->next; ord->next = NULL; free_order(ord); @@ -1925,13 +1925,13 @@ int mail_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); /* Falls kein Parameter, ist das eine Einheitsnummer; - * das Füllwort "AN" muss wegfallen, da gültige Nummer! */ + * das Fuellwort "AN" muss wegfallen, da gueltige Nummer! */ do { cont = 0; switch (findparam_ex(s, u->faction->locale)) { case P_REGION: - /* können alle Einheiten in der Region sehen */ + /* koennen alle Einheiten in der Region sehen */ s = getstrtoken(); if (!s || !s[0]) { cmistake(u, ord, 30, MSG_MESSAGE); @@ -2408,7 +2408,7 @@ int combatspell_cmd(unit * u, struct order *ord) init_order_depr(ord); s = gettoken(token, sizeof(token)); - /* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */ + /* KAMPFZAUBER [NICHT] loescht alle gesetzten Kampfzauber */ if (!s || *s == 0 || findparam(s, u->faction->locale) == P_NOT) { unset_combatspell(u, 0); return 0; @@ -2416,7 +2416,7 @@ int combatspell_cmd(unit * u, struct order *ord) /* Optional: STUFE n */ if (findparam(s, u->faction->locale) == P_LEVEL) { - /* Merken, setzen kommt erst später */ + /* Merken, setzen kommt erst spaeter */ level = getuint(); s = gettoken(token, sizeof(token)); } @@ -2430,14 +2430,14 @@ int combatspell_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); if (findparam(s, u->faction->locale) == P_NOT) { - /* KAMPFZAUBER "" NICHT löscht diesen speziellen + /* KAMPFZAUBER "" NICHT loescht diesen speziellen * Kampfzauber */ unset_combatspell(u, sp); return 0; } else { /* KAMPFZAUBER "" setzt diesen Kampfzauber */ - /* knowsspell prüft auf ist_magier, ist_spruch, kennt_spruch */ + /* knowsspell prueft auf ist_magier, ist_spruch, kennt_spruch */ if (!knowsspell(u->region, u, sp)) { /* Fehler 'Spell not found' */ cmistake(u, ord, 173, MSG_MAGIC); @@ -2773,7 +2773,7 @@ static void ageing(void) sp = &(*sp)->next; } - /* Gebäude */ + /* Gebaeude */ for (bp = &r->buildings; *bp;) { building *b = *bp; age_building(b); @@ -2978,7 +2978,7 @@ void update_long_order(unit * u) /* we have found the (first) long order * some long orders can have multiple instances: */ switch (kwd) { - /* Wenn gehandelt wird, darf kein langer Befehl ausgeführt + /* Wenn gehandelt wird, darf kein langer Befehl ausgefuehrt * werden. Da Handel erst nach anderen langen Befehlen kommt, * muss das vorher abgefangen werden. Wir merken uns also * hier, ob die Einheit handelt. */ @@ -3034,11 +3034,11 @@ void update_long_order(unit * u) } } if (hunger) { - /* Hungernde Einheiten führen NUR den default-Befehl aus */ + /* Hungernde Einheiten fuehren NUR den default-Befehl aus */ set_order(&u->thisorder, default_order(u->faction->locale)); } else if (!exclusive) { - /* Wenn die Einheit handelt oder zaubert, muss der Default-Befehl gelöscht werden. */ + /* Wenn die Einheit handelt oder zaubert, muss der Default-Befehl geloescht werden. */ set_order(&u->thisorder, NULL); } } @@ -3075,7 +3075,7 @@ void monthly_healing(void) double healingcurse = 0; if (r->attribs) { - /* bonus zurücksetzen */ + /* bonus zuruecksetzen */ curse *c = get_curse(r->attribs, &ct_healing); if (c != NULL) { healingcurse = curse_geteffect(c); @@ -3085,8 +3085,8 @@ void monthly_healing(void) int umhp = unit_max_hp(u) * u->number; double p = 1.0; - /* hp über Maximum bauen sich ab. Wird zb durch Elixier der Macht - * oder verändertes Ausdauertalent verursacht */ + /* hp ueber Maximum bauen sich ab. Wird zb durch Elixier der Macht + * oder veraendertes Ausdauertalent verursacht */ if (u->hp > umhp) { int diff = u->hp - umhp; u->hp -= (int)ceil(diff / 2.0); @@ -3113,7 +3113,7 @@ void monthly_healing(void) if (active_building(u, bt_find("inn"))) { p *= 1.5; } - /* pro punkt 5% höher */ + /* pro punkt 5% hoeher */ p *= (1.0 + healingcurse * 0.05); maxheal = p * maxheal; @@ -3126,7 +3126,7 @@ void monthly_healing(void) if (umhp > u->hp + addhp) umhp = u->hp + addhp; u->hp = umhp; - /* soll man an negativer regeneration sterben können? */ + /* soll man an negativer regeneration sterben koennen? */ assert(u->hp > 0); } } @@ -3173,7 +3173,7 @@ void defaultorders(void) ord->next = NULL; free_order(ord); if (!neworders) { - /* lange Befehle aus orders und old_orders löschen zu gunsten des neuen */ + /* lange Befehle aus orders und old_orders loeschen zu gunsten des neuen */ /* TODO: why only is_exclusive, not is_long? what about CAST, BUY, SELL? */ remove_exclusive(&u->orders); remove_exclusive(&u->old_orders); @@ -3981,8 +3981,8 @@ void turn_end(void) wormholes_update(); } - /* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich - * Beschreibungen geändert haben */ + /* immer ausfuehren, wenn neue Sprueche dazugekommen sind, oder sich + * Beschreibungen geaendert haben */ update_spells(); } diff --git a/src/magic.h b/src/magic.h index 6d181d73d..8d2b2b534 100644 --- a/src/magic.h +++ b/src/magic.h @@ -90,7 +90,7 @@ extern "C" { * - Magierichtung * - Magiepunkte derzeit * - Malus (neg. Wert)/ Bonus (pos. Wert) auf maximale Magiepunkte - * (koennen sich durch Questen absolut veraendern und durch Gegenstände + * (koennen sich durch Questen absolut veraendern und durch Gegenstaende * temporaer). Auch fuer Artefakt benoetigt man permanente MP * - Anzahl bereits gezauberte Sprueche diese Runde * - Kampfzauber (3) (vor/waehrend/nach) @@ -145,7 +145,7 @@ extern "C" { Schiffen stehend gezaubert werden */ #define TESTCANSEE (1<<4) /* alle Zielunits auf cansee pruefen */ - /* ID's koennen zu drei unterschiedlichen Entitaeten gehören: Einheiten, + /* ID's koennen zu drei unterschiedlichen Entitaeten gehoeren: Einheiten, * Gebaeuden und Schiffen. */ #define UNITSPELL (1<<5) /* ZAUBER .. [ ..] */ #define SHIPSPELL (1<<6) /* ZAUBER .. [ ..] */ @@ -153,7 +153,7 @@ extern "C" { #define REGIONSPELL (1<<8) /* wirkt auf struct region */ #define GLOBALTARGET (1<<9) /* Ziel kann ausserhalb der region sein */ -#define PRECOMBATSPELL (1<<10) /* PRÄKAMPFZAUBER .. */ +#define PRECOMBATSPELL (1<<10) /* PRAEKAMPFZAUBER .. */ #define COMBATSPELL (1<<11) /* KAMPFZAUBER .. */ #define POSTCOMBATSPELL (1<<12) /* POSTKAMPFZAUBER .. */ #define ISCOMBATSPELL (PRECOMBATSPELL|COMBATSPELL|POSTCOMBATSPELL) @@ -275,18 +275,18 @@ extern "C" { struct unit * familiar, const struct spell * sp, struct region * r, int lev, double force, int range, struct order * ord, struct spellparameter * p); void free_castorder(struct castorder *co); - /* Zwischenspreicher fuer Zauberbefehle, notwendig für Prioritaeten */ + /* Zwischenspreicher fuer Zauberbefehle, notwendig fuer Prioritaeten */ void add_castorder(struct spellrank *cll, struct castorder *co); /* Haenge c-order co an die letze c-order von cll an */ void free_castorders(struct castorder *co); /* Speicher wieder freigeben */ int cast_spell(struct castorder *co); - /* Pruefroutinen für Zaubern */ + /* Pruefroutinen fuer Zaubern */ int countspells(struct unit *u, int step); int spellcount(const struct unit *u); - /* erhoeht den Counter fuer Zaubersprüche um 'step' und gibt die neue - * Anzahl der gezauberten Sprueche zurück. */ + /* erhoeht den Counter fuer Zaubersprueche um 'step' und gibt die neue + * Anzahl der gezauberten Sprueche zurueck. */ int auracost(const struct unit *caster, const struct spell *sp); int spellcost(const struct unit *caster, const struct spell_component *spc); /* gibt die fuer diesen Spruch derzeit notwendigen Magiepunkte auf der From ffccf8014fb278c4be36bb579f66f0c87585ffb4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 9 Feb 2019 12:50:12 +0100 Subject: [PATCH 71/85] asciification --- src/attributes/seenspell.c | 4 +- src/battle.c | 136 ++++++++++++++++++------------------- src/economy.c | 122 ++++++++++++++++----------------- src/give.c | 14 ++-- src/modules/museum.c | 2 +- src/monsters.c | 30 ++++---- src/report.c | 4 +- src/spells.c | 32 ++++----- src/spells/combatspells.c | 30 ++++---- src/spells/flyingship.c | 4 +- src/steal.c | 2 +- src/study.c | 2 +- src/upkeep.c | 16 ++--- 13 files changed, 199 insertions(+), 199 deletions(-) diff --git a/src/attributes/seenspell.c b/src/attributes/seenspell.c index 082eecc6b..e20976015 100644 --- a/src/attributes/seenspell.c +++ b/src/attributes/seenspell.c @@ -39,9 +39,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* ------------------------------------------------------------- */ /* Ausgabe der Spruchbeschreibungen * Anzeige des Spruchs nur, wenn die Stufe des besten Magiers vorher - * kleiner war (u->faction->seenspells). Ansonsten muss nur geprüft + * kleiner war (u->faction->seenspells). Ansonsten muss nur geprueft * werden, ob dieser Magier den Spruch schon kennt, und andernfalls der - * Spruch zu seiner List-of-known-spells hinzugefügt werden. + * Spruch zu seiner List-of-known-spells hinzugefuegt werden. */ static int read_seenspells(variant *var, void *owner, struct gamedata *data) diff --git a/src/battle.c b/src/battle.c index df937698f..311cda7e3 100644 --- a/src/battle.c +++ b/src/battle.c @@ -303,11 +303,11 @@ static int dead_fighters(const fighter * df) } fighter *select_corpse(battle * b, fighter * af) -/* W�hlt eine Leiche aus, der af hilft. casualties ist die Anzahl der +/* Waehlt eine Leiche aus, der af hilft. casualties ist die Anzahl der * Toten auf allen Seiten (im Array). Wenn af == NULL, wird die - * Parteizugeh�rigkeit ignoriert, und irgendeine Leiche genommen. + * Parteizugehoerigkeit ignoriert, und irgendeine Leiche genommen. * - * Untote werden nicht ausgew�hlt (casualties, not dead) */ + * Untote werden nicht ausgewaehlt (casualties, not dead) */ { int si, maxcasualties = 0; fighter *df; @@ -323,7 +323,7 @@ fighter *select_corpse(battle * b, fighter * af) side *s; for (s = b->sides; s != b->sides + b->nsides; ++s) { for (df = s->fighters; df; df = df->next) { - /* Geflohene haben auch 0 hp, d�rfen hier aber nicht ausgew�hlt + /* Geflohene haben auch 0 hp, duerfen hier aber nicht ausgewaehlt * werden! */ int dead = dead_fighters(df); if (!playerrace(u_race(df->unit))) @@ -731,16 +731,16 @@ weapon_effskill(troop t, troop enemy, const weapon * w, if (t.index < tf->elvenhorses) { /* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist - * eleganter, und vor allem einfacher, sonst mu� man noch ein + * eleganter, und vor allem einfacher, sonst muss man noch ein * WMF_ELVENHORSE einbauen. */ skill += 2; } if (skill > 0 && !attacking && missile) { /* - * Wenn ich verteidige, und nicht direkt meinem Feind gegen�berstehe, - * halbiert sich mein Skill: (z.B. gegen Fernk�mpfer. Nahk�mpfer - * k�nnen mich eh nicht treffen) + * Wenn ich verteidige, und nicht direkt meinem Feind gegenueberstehe, + * halbiert sich mein Skill: (z.B. gegen Fernkaempfer. Nahkaempfer + * koennen mich eh nicht treffen) */ skill /= 2; } @@ -779,9 +779,9 @@ const armor_type *select_armor(troop t, bool shield) } /* Hier ist zu beachten, ob und wie sich Zauber und Artefakte, die - * R�stungschutz geben, addieren. - * - Artefakt "trollbelt" gibt R�stung +1 - * - Zauber Rindenhaut gibt R�stung +3 + * Ruestungschutz geben, addieren. + * - Artefakt "trollbelt" gibt Ruestung +1 + * - Zauber Rindenhaut gibt Ruestung +3 */ static int trollbelts(const unit *u) { const struct resource_type *belt = rt_find("trollbelt"); @@ -799,7 +799,7 @@ int select_magicarmor(troop t) return ma; } -/* Sind side ds und Magier des meffect verb�ndet, dann return 1*/ +/* Sind side ds und Magier des meffect verbuendet, dann return 1*/ bool meffect_protection(battle * b, meffect * s, side * ds) { UNUSED_ARG(b); @@ -837,7 +837,7 @@ void rmfighter(fighter * df, int i) assert(df->alive >= i); assert(df->alive <= df->unit->number); - /* erst ziehen wir die Anzahl der Personen von den K�mpfern in der + /* erst ziehen wir die Anzahl der Personen von den Kaempfern in der * Schlacht, dann von denen auf dieser Seite ab*/ df->side->alive -= i; df->side->battle->alive -= i; @@ -1031,15 +1031,15 @@ int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awty total_armor = 0; } - /* nat�rliche R�stung */ + /* natuerliche Ruestung */ nat_armor = natural_armor(du); - /* magische R�stung durch Artefakte oder Spr�che */ - /* Momentan nur Trollg�rtel und Werwolf-Eigenschaft */ + /* magische Ruestung durch Artefakte oder Sprueche */ + /* Momentan nur Trollguertel und Werwolf-Eigenschaft */ magic_armor = select_magicarmor(dt); if (rule_nat_armor == 0) { - /* nat�rliche R�stung ist halbkumulativ */ + /* natuerliche Ruestung ist halbkumulativ */ if (total_armor > 0) { total_armor += nat_armor / 2; } @@ -1124,7 +1124,7 @@ static bool survives(fighter *af, troop dt, battle *b) { const unit *du = af->unit; const fighter *df = dt.fighter; - if (df->person[dt.index].hp > 0) { /* Hat �berlebt */ + if (df->person[dt.index].hp > 0) { /* Hat ueberlebt */ demon_dazzle(af, dt); return true; @@ -1261,7 +1261,7 @@ static int apply_magicshield(int reduced_damage, fighter *df, reduced_damage -= hp; me->duration -= hp; } - /* gibt R�stung +effect f�r duration Treffer */ + /* gibt Ruestung +effect fuer duration Treffer */ if (me->typ == SHIELD_ARMOR) { reduced_damage -= me->effect; if (reduced_damage < 0) reduced_damage = 0; @@ -1743,7 +1743,7 @@ void do_combatmagic(battle * b, combatmagic_t was) unit *caster = mage; if (fig->alive <= 0) - continue; /* fighter kann im Kampf get�tet worden sein */ + continue; /* fighter kann im Kampf getoetet worden sein */ level = effskill(mage, SK_MAGIC, r); if (level > 0) { @@ -1847,12 +1847,12 @@ static void do_combatspell(troop at) sp = get_combatspell(mage, 1); if (sp == NULL) { - fi->magic = 0; /* Hat keinen Kampfzauber, k�mpft nichtmagisch weiter */ + fi->magic = 0; /* Hat keinen Kampfzauber, kaempft nichtmagisch weiter */ return; } ord = create_order(K_CAST, lang, "'%s'", spell_name(sp, lang)); if (!cancast(mage, sp, 1, 1, ord)) { - fi->magic = 0; /* Kann nicht mehr Zaubern, k�mpft nichtmagisch weiter */ + fi->magic = 0; /* Kann nicht mehr Zaubern, kaempft nichtmagisch weiter */ return; } @@ -1878,7 +1878,7 @@ static void do_combatspell(troop at) } } - /* Antimagie die Fehlschlag erh�ht */ + /* Antimagie die Fehlschlag erhoeht */ if (rng_int() % 100 < fumblechance) { report_failed_spell(b, mage, sp); pay_spell(mage, NULL, sp, level, 1); @@ -1897,7 +1897,7 @@ static void do_combatspell(troop at) } /* Sonderattacken: Monster patzern nicht und zahlen auch keine - * Spruchkosten. Da die Spruchst�rke direkt durch den Level bestimmt + * Spruchkosten. Da die Spruchstaerke direkt durch den Level bestimmt * wird, wirkt auch keine Antimagie (wird sonst in spellpower * gemacht) */ @@ -1948,7 +1948,7 @@ int skilldiff(troop at, troop dt, int dist) if (b->attribs) { curse *c = get_curse(b->attribs, &ct_strongwall); if (curse_active(c)) { - /* wirkt auf alle Geb�ude */ + /* wirkt auf alle Gebaeude */ skdiff -= curse_geteffect_int(c); is_protected = 2; } @@ -2037,7 +2037,7 @@ int hits(troop at, troop dt, weapon * awp) } skdiff = skilldiff(at, dt, dist); - /* Verteidiger bekommt eine R�stung */ + /* Verteidiger bekommt eine Ruestung */ armor = select_armor(dt, true); if (dwp == NULL || (dwp->type->flags & WTF_USESHIELD)) { shield = select_armor(dt, false); @@ -2066,7 +2066,7 @@ void damage_building(battle * b, building * bldg, int damage_abs) bldg->size -= damage_abs; if (bldg->size < 1) bldg->size = 1; - /* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb�ude passen. */ + /* Wenn Burg, dann gucken, ob die Leute alle noch in das Gebaeude passen. */ if (bldg->type->flags & BTF_FORTIFICATION) { side *s; @@ -2124,7 +2124,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) switch (a->type) { case AT_COMBATSPELL: /* Magier versuchen immer erstmal zu zaubern, erst wenn das - * fehlschl�gt, wird af->magic == 0 und der Magier k�mpft + * fehlschlaegt, wird af->magic == 0 und der Magier kaempft * konventionell weiter */ if (numattack == 0 && af->magic > 0) { /* wenn der magier in die potenzielle Reichweite von Attacken des @@ -2136,7 +2136,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) } } break; - case AT_STANDARD: /* Waffen, mag. Gegenst�nde, Kampfzauber */ + case AT_STANDARD: /* Waffen, mag. Gegenstaende, Kampfzauber */ if (numattack > 0 || af->magic <= 0) { weapon *wp = ta.fighter->person[ta.index].missile; int melee = @@ -2153,7 +2153,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) bool standard_attack = true; bool reload = false; /* spezialattacken der waffe nur, wenn erste attacke in der runde. - * sonst helden mit feuerschwertern zu m�chtig */ + * sonst helden mit feuerschwertern zu maechtig */ if (numattack == 0 && wp && wp->type->attack) { int dead = 0; standard_attack = wp->type->attack(&ta, wp->type, &dead); @@ -2197,7 +2197,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) } } break; - case AT_SPELL: /* Extra-Spr�che. Kampfzauber in AT_COMBATSPELL! */ + case AT_SPELL: /* Extra-Sprueche. Kampfzauber in AT_COMBATSPELL! */ do_extra_spell(ta, a); break; case AT_NATURAL: @@ -2282,14 +2282,14 @@ void do_attack(fighter * af) assert(au && au->number); /* Da das Zuschlagen auf Einheiten und nicht auf den einzelnen - * K�mpfern beruht, darf die Reihenfolge und Gr��e der Einheit keine + * Kaempfern beruht, darf die Reihenfolge und Groesse der Einheit keine * Rolle spielen, Das tut sie nur dann, wenn jeder, der am Anfang der - * Runde lebte, auch zuschlagen darf. Ansonsten ist der, der zuf�llig - * mit einer gro�en Einheit zuerst drankommt, extrem bevorteilt. */ + * Runde lebte, auch zuschlagen darf. Ansonsten ist der, der zufaellig + * mit einer grossen Einheit zuerst drankommt, extrem bevorteilt. */ ta.index = af->fighting; while (ta.index--) { - /* Wir suchen eine beliebige Feind-Einheit aus. An der k�nnen + /* Wir suchen eine beliebige Feind-Einheit aus. An der koennen * wir feststellen, ob noch jemand da ist. */ int apr, attacks = attacks_per_round(ta); if (!count_enemies(b, af, FIGHT_ROW, LAST_ROW, SELECT_FIND)) @@ -2314,7 +2314,7 @@ void do_attack(fighter * af) } } } - /* Der letzte Katapultsch�tze setzt die + /* Der letzte Katapultschuetze setzt die * Ladezeit neu und generiert die Meldung. */ if (af->catmsg >= 0) { struct message *m = @@ -2372,7 +2372,7 @@ static int horse_fleeing_bonus(const unit * u) static int fleechance(unit * u) { int p = flee_chance_base; /* Fluchtwahrscheinlichkeit in % */ - /* Einheit u versucht, dem Get�mmel zu entkommen */ + /* Einheit u versucht, dem Getuemmel zu entkommen */ p += (effskill(u, SK_STEALTH, NULL) * flee_chance_skill_bonus); p += horse_fleeing_bonus(u); @@ -2660,7 +2660,7 @@ static void aftermath(battle * b) for (s = b->sides; s != b->sides + b->nsides; ++s) { int snumber = 0; fighter *df; - bool relevant = false; /* Kampf relevant f�r diese Partei? */ + bool relevant = false; /* Kampf relevant fuer diese Partei? */ if (!fval(s, SIDE_HASGUARDS)) { relevant = true; } @@ -2700,7 +2700,7 @@ static void aftermath(battle * b) /* Report the casualties */ reportcasualties(b, df, dead); - /* Zuerst d�rfen die Feinde pl�ndern, die mitgenommenen Items + /* Zuerst duerfen die Feinde pluendern, die mitgenommenen Items * stehen in fig->run.items. Dann werden die Fliehenden auf * die leere (tote) alte Einheit gemapt */ if (!fval(df, FIG_NOLOOT)) { @@ -2735,7 +2735,7 @@ static void aftermath(battle * b) } else { if (df->alive == 0) { - /* alle sind tot, niemand geflohen. Einheit aufl�sen */ + /* alle sind tot, niemand geflohen. Einheit aufloesen */ df->run.number = 0; df->run.hp = 0; @@ -2797,7 +2797,7 @@ static void aftermath(battle * b) /* Wir benutzen drifted, um uns zu merken, ob ein Schiff * schonmal Schaden genommen hat. (moved und drifted - * sollten in flags �berf�hrt werden */ + * sollten in flags ueberfuehrt werden */ for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *df; @@ -2818,7 +2818,7 @@ static void aftermath(battle * b) } /* Wenn sich die Einheit auf einem Schiff befindet, wird - * dieses Schiff besch�digt. Andernfalls ein Schiff, welches + * dieses Schiff beschaedigt. Andernfalls ein Schiff, welches * evt. zuvor verlassen wurde. */ if (ships_damaged) { ship *sh; @@ -3114,8 +3114,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) else if (!stealthfaction) { s1->stealthfaction = NULL; } - /* Zu diesem Zeitpunkt ist attacked noch 0, da die Einheit f�r noch - * keinen Kampf ausgew�hlt wurde (sonst w�rde ein fighter existieren) */ + /* Zu diesem Zeitpunkt ist attacked noch 0, da die Einheit fuer noch + * keinen Kampf ausgewaehlt wurde (sonst wuerde ein fighter existieren) */ } fig = (struct fighter*)calloc(1, sizeof(struct fighter)); @@ -3123,8 +3123,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) s1->fighters = fig; fig->unit = u; - /* In einer Burg mu� man a) nicht Angreifer sein, und b) drin sein, und - * c) noch Platz finden. d) menschan�hnlich sein */ + /* In einer Burg muss man a) nicht Angreifer sein, und b) drin sein, und + * c) noch Platz finden. d) menschanaehnlich sein */ if (attack) { set_attacker(fig); } @@ -3150,7 +3150,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) assert(h); rest = u->hp % u->number; - /* Effekte von Spr�chen */ + /* Effekte von Spruechen */ if (u->attribs) { curse *c = get_curse(u->attribs, &ct_speed); @@ -3189,8 +3189,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) } } - /* F�r alle Waffengattungen wird bestimmt, wie viele der Personen mit - * ihr k�mpfen k�nnten, und was ihr Wert darin ist. */ + /* Fuer alle Waffengattungen wird bestimmt, wie viele der Personen mit + * ihr kaempfen koennten, und was ihr Wert darin ist. */ if (u_race(u)->battle_flags & BF_EQUIPMENT) { int owp[WMAX]; int dwp[WMAX]; @@ -3311,12 +3311,12 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) } } - /* Jetzt mu� noch geschaut werden, wo die Einheit die jeweils besten - * Werte hat, das kommt aber erst irgendwo sp�ter. Ich entscheide - * w�rend des Kampfes, welche ich nehme, je nach Gegner. Deswegen auch + /* Jetzt muss noch geschaut werden, wo die Einheit die jeweils besten + * Werte hat, das kommt aber erst irgendwo spaeter. Ich entscheide + * waehrend des Kampfes, welche ich nehme, je nach Gegner. Deswegen auch * keine addierten boni. */ - /* Zuerst mal die Spezialbehandlung gewisser Sonderf�lle. */ + /* Zuerst mal die Spezialbehandlung gewisser Sonderfaelle. */ fig->magic = effskill(u, SK_MAGIC, NULL); if (fig->horses) { @@ -3410,7 +3410,7 @@ battle *make_battle(region * r) b->region = r; b->plane = getplane(r); - /* Finde alle Parteien, die den Kampf beobachten k�nnen: */ + /* Finde alle Parteien, die den Kampf beobachten koennen: */ for (u = r->units; u; u = u->next) { if (u->number > 0) { if (!fval(u->faction, FFL_MARK)) { @@ -3593,18 +3593,18 @@ static void join_allies(battle * b) for (s = b->sides; s != s_end; ++s) { side *se; - /* Wenn alle attackierten noch FFL_NOAID haben, dann k�mpfe nicht mit. */ + /* Wenn alle attackierten noch FFL_NOAID haben, dann kaempfe nicht mit. */ if (fval(s->faction, FFL_NOAID)) continue; if (s->faction != f) { /* Wenn wir attackiert haben, kommt niemand mehr hinzu: */ if (s->bf->attacker) continue; - /* alliiert m�ssen wir schon sein, sonst ist's eh egal : */ + /* alliiert muessen wir schon sein, sonst ist's eh egal : */ if (!alliedunit(u, s->faction, HELP_FIGHT)) continue; /* wenn die partei verborgen ist, oder gar eine andere - * vorgespiegelt wird, und er sich uns gegen�ber nicht zu + * vorgespiegelt wird, und er sich uns gegenueber nicht zu * erkennen gibt, helfen wir ihm nicht */ if (s->stealthfaction) { if (!alliedside(s, u->faction, HELP_FSTEALTH)) { @@ -3612,7 +3612,7 @@ static void join_allies(battle * b) } } } - /* einen alliierten angreifen d�rfen sie nicht, es sei denn, der + /* einen alliierten angreifen duerfen sie nicht, es sei denn, der * ist mit einem alliierten verfeindet, der nicht attackiert * hat: */ for (se = b->sides; se != s_end; ++se) { @@ -3626,7 +3626,7 @@ static void join_allies(battle * b) } if (se == s_end) continue; - /* keine Einw�nde, also soll er mitmachen: */ + /* keine Einwaende, also soll er mitmachen: */ if (c == NULL) { if (!join_battle(b, u, false, &c)) { continue; @@ -3750,7 +3750,7 @@ static bool start_battle(region * r, battle ** bp) continue; } - /* ist ein Fl�chtling aus einem andern Kampf */ + /* ist ein Fluechtling aus einem andern Kampf */ if (fval(u, UFL_LONGACTION)) continue; @@ -3771,7 +3771,7 @@ static bool start_battle(region * r, battle ** bp) cmistake(u, ord, 234, MSG_BATTLE); } else { - /* Fehler: "Das Schiff mu� erst verlassen werden" */ + /* Fehler: "Das Schiff muss erst verlassen werden" */ cmistake(u, ord, 19, MSG_BATTLE); } continue; @@ -3845,8 +3845,8 @@ static bool start_battle(region * r, battle ** bp) freset(u2->faction, FFL_NOAID); if (c1 && c2 && c2->run.number < c2->unit->number) { - /* Merken, wer Angreifer ist, f�r die R�ckzahlung der - * Pr�combataura bei kurzem Kampf. */ + /* Merken, wer Angreifer ist, fuer die Rueckzahlung der + * Praecombataura bei kurzem Kampf. */ c1->side->bf->attacker = true; set_enemy(c1->side, c2->side, true); @@ -3875,7 +3875,7 @@ static void battle_attacks(battle * b) && get_tactics(s, NULL) == b->max_tactics)) { for (fig = s->fighters; fig; fig = fig->next) { - /* ist in dieser Einheit noch jemand handlungsf�hig? */ + /* ist in dieser Einheit noch jemand handlungsfaehig? */ if (fig->fighting <= 0) continue; @@ -3918,7 +3918,7 @@ static void battle_flee(battle * b) for (fig = s->fighters; fig; fig = fig->next) { unit *u = fig->unit; troop dt; - /* Flucht nicht bei mehr als 600 HP. Damit Wyrme t�tbar bleiben. */ + /* Flucht nicht bei mehr als 600 HP. Damit Wyrme toetbar bleiben. */ int runhp = (int)(0.9 + unit_max_hp(u) * hpflee(u->status)); if (runhp > 600) runhp = 600; @@ -4023,7 +4023,7 @@ static void do_battle(region * r) { return; /* Bevor wir die alliierten hineinziehen, sollten wir schauen, * - * Ob jemand fliehen kann. Dann er�brigt sich das ganze ja + * Ob jemand fliehen kann. Dann eruebrigt sich das ganze ja * vielleicht schon. */ report_battle_start(b); if (!fighting) { @@ -4069,8 +4069,8 @@ static void do_battle(region * r) { if (rule_force_leave(FORCE_LEAVE_POSTCOMBAT)) { force_leave(b->region, b); } - /* Hier ist das Gefecht beendet, und wir k�nnen die - * Hilfsstrukturen * wieder l�schen: */ + /* Hier ist das Gefecht beendet, und wir koennen die + * Hilfsstrukturen * wieder loeschen: */ free_battle(b); } diff --git a/src/economy.c b/src/economy.c index 876e77856..ec6986dd6 100644 --- a/src/economy.c +++ b/src/economy.c @@ -479,7 +479,7 @@ message *can_recruit(unit *u, const race *rc, order *ord, int now) } if (has_skill(u, SK_MAGIC)) { /* error158;de;{unit} in {region}: '{command}' - Magier arbeiten - * grunds�tzlich nur alleine! */ + * grundsaetzlich nur alleine! */ return msg_error(u, ord, 158); } return NULL; @@ -971,7 +971,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) variant save_mod; skill_t sk; - /* momentan kann man keine ressourcen abbauen, wenn man daf�r + /* momentan kann man keine ressourcen abbauen, wenn man dafuer * Materialverbrauch hat: */ assert(itype != NULL && (itype->construction == NULL || itype->construction->materials == NULL)); @@ -997,8 +997,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) save_mod.sa[1] = 1; } - /* Bergw�chter k�nnen Abbau von Eisen/Laen durch Bewachen verhindern. - * Als magische Wesen 'sehen' Bergw�chter alles und werden durch + /* Bergwaechter koennen Abbau von Eisen/Laen durch Bewachen verhindern. + * Als magische Wesen 'sehen' Bergwaechter alles und werden durch * Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen). */ if (itype->rtype && (itype->rtype == get_resourcetype(R_IRON) || itype->rtype == rt_find("laen"))) { @@ -1473,15 +1473,15 @@ static void expandbuying(region * r, econ_request * buyorders) return; /* Initialisation. multiplier ist der Multiplikator auf den - * Verkaufspreis. F�r max_products Produkte kauft man das Produkt zum - * einfachen Verkaufspreis, danach erh�ht sich der Multiplikator um 1. - * counter ist ein Z�hler, der die gekauften Produkte z�hlt. money - * wird f�r die debug message gebraucht. */ + * Verkaufspreis. Fuer max_products Produkte kauft man das Produkt zum + * einfachen Verkaufspreis, danach erhoeht sich der Multiplikator um 1. + * counter ist ein Zaehler, der die gekauften Produkte zaehlt. money + * wird fuer die debug message gebraucht. */ max_products = rpeasants(r) / TRADE_FRACTION; - /* Kauf - auch so programmiert, da� er leicht erweiterbar auf mehrere - * G�ter pro Monat ist. j sind die Befehle, i der Index des + /* Kauf - auch so programmiert, dass er leicht erweiterbar auf mehrere + * Gueter pro Monat ist. j sind die Befehle, i der Index des * gehandelten Produktes. */ if (max_products > 0) { unsigned int norders = expandorders(r, buyorders); @@ -1500,10 +1500,10 @@ static void expandbuying(region * r, econ_request * buyorders) if (get_pooled(g_requests[j]->unit, rsilver, GET_DEFAULT, price) >= price) { item *items; - /* litems z�hlt die G�ter, die verkauft wurden, u->n das Geld, das - * verdient wurde. Dies mu� gemacht werden, weil der Preis st�ndig sinkt, + /* litems zaehlt die Gueter, die verkauft wurden, u->n das Geld, das + * verdient wurde. Dies muss gemacht werden, weil der Preis staendig sinkt, * man sich also das verdiente Geld und die verkauften Produkte separat - * merken mu�. */ + * merken muss. */ attrib *a; u = g_requests[j]->unit; @@ -1524,7 +1524,7 @@ static void expandbuying(region * r, econ_request * buyorders) rsetmoney(r, rmoney(r) + price); /* Falls mehr als max_products Bauern ein Produkt verkauft haben, steigt - * der Preis Multiplikator f�r das Produkt um den Faktor 1. Der Z�hler + * der Preis Multiplikator fuer das Produkt um den Faktor 1. Der Zaehler * wird wieder auf 0 gesetzt. */ if (++trade->number == max_products) { trade->number = 0; @@ -1599,7 +1599,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord) return; } /* Im Augenblick kann man nur 1 Produkt kaufen. expandbuying ist aber - * schon daf�r ausger�stet, mehrere Produkte zu kaufen. */ + * schon dafuer ausgeruestet, mehrere Produkte zu kaufen. */ kwd = init_order_depr(ord); assert(kwd == K_BUY); @@ -1632,11 +1632,11 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord) } } - /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt handeln. */ + /* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */ k = u->number * 10 * effskill(u, SK_TRADE, NULL); - /* hat der H�ndler bereits gehandelt, muss die Menge der bereits - * verkauften/gekauften G�ter abgezogen werden */ + /* hat der Haendler bereits gehandelt, muss die Menge der bereits + * verkauften/gekauften Gueter abgezogen werden */ a = a_find(u->attribs, &at_trades); if (!a) { a = a_add(&u->attribs, a_new(&at_trades)); @@ -1653,7 +1653,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord) } assert(n >= 0); - /* die Menge der verkauften G�ter merken */ + /* die Menge der verkauften Gueter merken */ a->data.i += n; s = gettoken(token, sizeof(token)); @@ -1687,7 +1687,7 @@ void add_income(unit * u, income_t type, int want, int qty) "unit region mode wanted amount", u, u->region, (int)type, want, qty)); } -/* Steuers�tze in % bei Burggr��e */ +/* Steuersaetze in % bei Burggroesse */ static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 }; static void expandselling(region * r, econ_request * sellorders, int limit) @@ -1723,11 +1723,11 @@ static void expandselling(region * r, econ_request * sellorders, int limit) } memset(counter, 0, sizeof(int) * ncounter); - if (!sellorders) { /* NEIN, denn Insekten k�nnen in || !r->buildings) */ - return; /* S�mpfen und W�sten auch so handeln */ + if (!sellorders) { /* NEIN, denn Insekten koennen in || !r->buildings) */ + return; /* Suempfen und Wuesten auch so handeln */ } - /* Stelle Eigent�mer der gr��ten Burg fest. Bekommt Steuern aus jedem - * Verkauf. Wenn zwei Burgen gleicher Gr��e bekommt gar keiner etwas. */ + /* Stelle Eigentuemer der groessten Burg fest. Bekommt Steuern aus jedem + * Verkauf. Wenn zwei Burgen gleicher Groesse bekommt gar keiner etwas. */ for (b = rbuildings(r); b; b = b->next) { if (b->size > maxsize && building_owner(b) != NULL && b->type == castle_bt) { @@ -1750,13 +1750,13 @@ static void expandselling(region * r, econ_request * sellorders, int limit) maxowner = (unit *)NULL; } } - /* Die Region muss genug Geld haben, um die Produkte kaufen zu k�nnen. */ + /* Die Region muss genug Geld haben, um die Produkte kaufen zu koennen. */ money = rmoney(r); - /* max_products sind 1/100 der Bev�lkerung, falls soviele Produkte + /* max_products sind 1/100 der Bevoelkerung, falls soviele Produkte * verkauft werden - counter[] - sinkt die Nachfrage um 1 Punkt. - * multiplier speichert r->demand f�r die debug message ab. */ + * multiplier speichert r->demand fuer die debug message ab. */ max_products = rpeasants(r) / TRADE_FRACTION; if (max_products <= 0) @@ -1824,11 +1824,11 @@ static void expandselling(region * r, econ_request * sellorders, int limit) change_money(u, price); fset(u, UFL_LONGACTION | UFL_NOTMOVING); - /* r->money -= price; --- dies wird eben nicht ausgef�hrt, denn die - * Produkte k�nnen auch als Steuern eingetrieben werden. In der Region - * wurden Silberst�cke gegen Luxusg�ter des selben Wertes eingetauscht! + /* r->money -= price; --- dies wird eben nicht ausgefuehrt, denn die + * Produkte koennen auch als Steuern eingetrieben werden. In der Region + * wurden Silberstuecke gegen Luxusgueter des selben Wertes eingetauscht! * Falls mehr als max_products Kunden ein Produkt gekauft haben, sinkt - * die Nachfrage f�r das Produkt um 1. Der Z�hler wird wieder auf 0 + * die Nachfrage fuer das Produkt um 1. Der Zaehler wird wieder auf 0 * gesetzt. */ if (++counter[i] > max_products) { @@ -1846,7 +1846,7 @@ static void expandselling(region * r, econ_request * sellorders, int limit) } free(g_requests); - /* Steuern. Hier werden die Steuern dem Besitzer der gr��ten Burg gegeben. */ + /* Steuern. Hier werden die Steuern dem Besitzer der groessten Burg gegeben. */ if (maxowner) { if (taxcollected > 0) { change_money(maxowner, (int)taxcollected); @@ -1903,7 +1903,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) cmistake(u, ord, 69, MSG_INCOME); return false; } - /* sellorders sind KEIN array, weil f�r alle items DIE SELBE resource + /* sellorders sind KEIN array, weil fuer alle items DIE SELBE resource * (das geld der region) aufgebraucht wird. */ kwd = init_order_depr(ord); @@ -1928,7 +1928,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) return false; } } - /* In der Region mu� es eine Burg geben. */ + /* In der Region muss es eine Burg geben. */ if (u_race(u) == get_race(RC_INSECT)) { if (r->terrain != newterrain(T_SWAMP) && r->terrain != newterrain(T_DESERT) @@ -1938,7 +1938,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) } } else { - /* ...oder in der Region mu� es eine Burg geben. */ + /* ...oder in der Region muss es eine Burg geben. */ building *b = 0; if (r->buildings) { for (b = r->buildings; b; b = b->next) { @@ -1951,7 +1951,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) } } - /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt verkaufen. */ + /* Ein Haendler kann nur 10 Gueter pro Talentpunkt verkaufen. */ i = u->number * 10 * effskill(u, SK_TRADE, NULL); if (n > i) n = i; @@ -1978,7 +1978,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) } available = get_pooled(u, itype->rtype, GET_DEFAULT, INT_MAX); - /* Wenn andere Einheiten das selbe verkaufen, mu� ihr Zeug abgezogen + /* Wenn andere Einheiten das selbe verkaufen, muss ihr Zeug abgezogen * werden damit es nicht zweimal verkauft wird: */ for (o = *sellorders; o; o = o->next) { if (o->type.trade.ltype == ltype && o->unit->faction == u->faction) { @@ -1996,16 +1996,16 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) return false; } /* Hier wird production->type verwendet, weil die obere limit durch - * das silber gegeben wird (region->money), welches f�r alle + * das silber gegeben wird (region->money), welches fuer alle * (!) produkte als summe gilt, als nicht wie bei der - * produktion, wo f�r jedes produkt einzeln eine obere limite + * produktion, wo fuer jedes produkt einzeln eine obere limite * existiert, so dass man arrays von orders machen kann. */ - /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt handeln. */ + /* Ein Haendler kann nur 10 Gueter pro Talentpunkt handeln. */ k = u->number * 10 * effskill(u, SK_TRADE, NULL); - /* hat der H�ndler bereits gehandelt, muss die Menge der bereits - * verkauften/gekauften G�ter abgezogen werden */ + /* hat der Haendler bereits gehandelt, muss die Menge der bereits + * verkauften/gekauften Gueter abgezogen werden */ a = a_find(u->attribs, &at_trades); if (!a) { a = a_add(&u->attribs, a_new(&at_trades)); @@ -2016,7 +2016,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) if (n > k) n = k; assert(n >= 0); - /* die Menge der verkauften G�ter merken */ + /* die Menge der verkauften Gueter merken */ a->data.i += n; o = (econ_request *)calloc(1, sizeof(econ_request)); if (!o) abort(); @@ -2047,7 +2047,7 @@ static void plant(unit * u, int raw) return; } - /* Skill pr�fen */ + /* Skill pruefen */ skill = effskill(u, SK_HERBALISM, NULL); if (skill < 6) { ADDMSG(&u->faction->msgs, @@ -2055,14 +2055,14 @@ static void plant(unit * u, int raw) "skill minskill product", SK_HERBALISM, 6, itype->rtype, 1)); return; } - /* Wasser des Lebens pr�fen */ + /* Wasser des Lebens pruefen */ if (get_pooled(u, rt_water, GET_DEFAULT, 1) == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rt_water)); return; } n = get_pooled(u, itype->rtype, GET_DEFAULT, skill * u->number); - /* Kr�uter pr�fen */ + /* Kraeuter pruefen */ if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", @@ -2073,7 +2073,7 @@ static void plant(unit * u, int raw) i = skill * u->number; if (i > raw) i = raw; if (n > i) n = i; - /* F�r jedes Kraut Talent*10% Erfolgschance. */ + /* Fuer jedes Kraut Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) planted++; @@ -2098,10 +2098,10 @@ static void planttrees(unit * u, int raw) return; } - /* Mallornb�ume kann man nur in Mallornregionen z�chten */ + /* Mallornbaeume kann man nur in Mallornregionen zuechten */ rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORN_SEED : R_SEED); - /* Skill pr�fen */ + /* Skill pruefen */ skill = effskill(u, SK_HERBALISM, NULL); if (skill < 6) { ADDMSG(&u->faction->msgs, @@ -2126,7 +2126,7 @@ static void planttrees(unit * u, int raw) } if (n > raw) n = raw; - /* F�r jeden Samen Talent*10% Erfolgschance. */ + /* Fuer jeden Samen Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) planted++; @@ -2141,7 +2141,7 @@ static void planttrees(unit * u, int raw) "unit region amount herb", u, r, planted, rtype)); } -/* z�chte b�ume */ +/* zuechte baeume */ static void breedtrees(unit * u, int raw) { int n, i, skill, planted = 0; @@ -2153,7 +2153,7 @@ static void breedtrees(unit * u, int raw) get_gamedate(turn, &date); current_season = date.season; - /* B�ume z�chten geht nur im Fr�hling */ + /* Baeume zuechten geht nur im Fruehling */ if (current_season != SEASON_SPRING) { planttrees(u, raw); return; @@ -2163,10 +2163,10 @@ static void breedtrees(unit * u, int raw) return; } - /* Mallornb�ume kann man nur in Mallornregionen z�chten */ + /* Mallornbaeume kann man nur in Mallornregionen zuechten */ rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORN_SEED : R_SEED); - /* Skill pr�fen */ + /* Skill pruefen */ skill = effskill(u, SK_HERBALISM, NULL); if (skill < 12) { planttrees(u, raw); @@ -2177,7 +2177,7 @@ static void breedtrees(unit * u, int raw) i = skill * u->number; if (raw > i) raw = i; n = get_pooled(u, rtype, GET_DEFAULT, raw); - /* Samen pr�fen */ + /* Samen pruefen */ if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); @@ -2185,7 +2185,7 @@ static void breedtrees(unit * u, int raw) } if (n > raw) n = raw; - /* F�r jeden Samen Talent*5% Erfolgschance. */ + /* Fuer jeden Samen Talent*5% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 100 < skill * 5) planted++; @@ -2200,7 +2200,7 @@ static void breedtrees(unit * u, int raw) "unit region amount herb", u, r, planted, rtype)); } -/* z�chte pferde */ +/* zuechte pferde */ static void breedhorses(unit * u) { int n, c, breed = 0; @@ -2252,7 +2252,7 @@ static void breed_cmd(unit * u, struct order *ord) return; } - /* z�chte [] */ + /* zuechte [] */ (void)init_order_depr(ord); s = gettoken(token, sizeof(token)); @@ -2367,7 +2367,7 @@ static void expandentertainment(region * r) m -= u->n; entertaining -= o->qty; - /* Nur soviel PRODUCEEXP wie auch tats�chlich gemacht wurde */ + /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ produceexp(u, SK_ENTERTAINMENT, (u->n < u->number) ? u->n : u->number); add_income(u, IC_ENTERTAIN, o->qty, u->n); fset(u, UFL_LONGACTION | UFL_NOTMOVING); @@ -2925,7 +2925,7 @@ void produce(struct region *r) /* Entertainment (expandentertainment) und Besteuerung (expandtax) vor den * Befehlen, die den Bauern mehr Geld geben, damit man aus den Zahlen der - * letzten Runde berechnen kann, wieviel die Bauern f�r Unterhaltung + * letzten Runde berechnen kann, wieviel die Bauern fuer Unterhaltung * auszugeben bereit sind. */ if (entertaining) expandentertainment(r); @@ -2943,7 +2943,7 @@ void produce(struct region *r) } /* An erster Stelle Kaufen (expandbuying), die Bauern so Geld bekommen, um * nachher zu beim Verkaufen (expandselling) den Spielern abkaufen zu - * k�nnen. */ + * koennen. */ if (buyorders) { expandbuying(r, buyorders); diff --git a/src/give.c b/src/give.c index 90ed64f50..c6e77aa68 100644 --- a/src/give.c +++ b/src/give.c @@ -402,7 +402,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) if (has_skill(u2, SK_ALCHEMY) && !has_skill(u, SK_ALCHEMY)) k += n; - /* Wenn Parteigrenzen überschritten werden */ + /* Wenn Parteigrenzen ueberschritten werden */ if (u2->faction != u->faction) k += n; @@ -416,8 +416,8 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) if (error == 0) { ship *sh = leftship(u); - /* Einheiten von Schiffen können nicht NACH in von - * Nicht-alliierten bewachten Regionen ausführen */ + /* Einheiten von Schiffen koennen nicht NACH in von + * Nicht-alliierten bewachten Regionen ausfuehren */ if (sh) { set_leftship(u2, sh); } @@ -608,7 +608,7 @@ void give_unit(unit * u, unit * u2, order * ord) } bool can_give_to(unit *u, unit *u2) { - /* Damit Tarner nicht durch die Fehlermeldung enttarnt werden können */ + /* Damit Tarner nicht durch die Fehlermeldung enttarnt werden koennen */ if (!u2) { return false; } @@ -638,8 +638,8 @@ static void give_all_items(unit *u, unit *u2, order *ord) { return; } - /* für alle items einmal prüfen, ob wir mehr als von diesem Typ - * reserviert ist besitzen und diesen Teil dann übergeben */ + /* fuer alle items einmal pruefen, ob wir mehr als von diesem Typ + * reserviert ist besitzen und diesen Teil dann uebergeben */ if (u->items) { item **itmp = &u->items; while (*itmp) { @@ -768,7 +768,7 @@ void give_cmd(unit * u, order * ord) while (*itmp) { item *itm = *itmp; if (fval(itm->type, ITF_HERB) && itm->number > 0) { - /* give_item ändert im fall,das man alles übergibt, die + /* give_item aendert im fall,das man alles uebergibt, die * item-liste der unit, darum continue vor pointerumsetzten */ if (give_item(itm->number, itm->type, u, u2, ord) == 0) { given = true; diff --git a/src/modules/museum.c b/src/modules/museum.c index dcb9fce2f..36aa1d63f 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -152,7 +152,7 @@ order * ord) r = findregion(a->data.sa[0], a->data.sa[1]); assert(r); a_remove(&u->attribs, a); - /* Übergebene Gegenstände zurückgeben */ + /* Uebergebene Gegenstaende zurueckgeben */ a = a_find(u->attribs, &at_museumgivebackcookie); if (a) { diff --git a/src/monsters.c b/src/monsters.c index 15e9bc0b0..afa8070e5 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -9,7 +9,7 @@ * based on: * * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace - * Atlantis v1.7 Copyright 1996 by Alex Schr�der + * Atlantis v1.7 Copyright 1996 by Alex Schroeder * * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. @@ -74,7 +74,7 @@ #include #include -#define DRAGON_RANGE 20 /* max. Distanz zum n�chsten Drachenziel */ +#define DRAGON_RANGE 20 /* max. Distanz zum naechsten Drachenziel */ #define MOVE_PERCENT 25 /* chance fuer bewegung */ #define MAXILLUSION_TEXTS 3 @@ -371,11 +371,11 @@ static direction_t random_neighbour(region * r, unit * u) } } - /* Zuf�llig eine ausw�hlen */ + /* Zufaellig eine auswaehlen */ rr = rng_int() % c; - /* Durchz�hlen */ + /* Durchzaehlen */ c = 0; for (i = 0; i != MAXDIRECTIONS; i++) { @@ -412,11 +412,11 @@ static direction_t treeman_neighbour(region * r) if (c == 0) { return NODIRECTION; } - /* Zuf�llig eine ausw�hlen */ + /* Zufaellig eine auswaehlen */ rr = rng_int() % c; - /* Durchz�hlen */ + /* Durchzaehlen */ c = -1; for (i = 0; i != MAXDIRECTIONS; i++) { @@ -561,7 +561,7 @@ static order *monster_learn(unit * u) return NULL; } - /* Monster lernt ein zuf�lliges Talent aus allen, in denen es schon + /* Monster lernt ein zufaelliges Talent aus allen, in denen es schon * Lerntage hat. */ for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { if (sv->level > 0) @@ -650,7 +650,7 @@ static order *plan_dragon(unit * u) if (rc == rc_wyrm && !move) { unit *u2; for (u2 = r->units; u2; u2 = u2->next) { - /* wyrme sind einzelg�nger */ + /* Wyrme sind Einzelgaenger */ if (u2 == u) { /* we do not make room for newcomers, so we don't need to look at them */ break; @@ -747,7 +747,7 @@ void plan_monsters(faction * f) order *long_order = NULL; bool can_move = true; - /* Ab hier nur noch Befehle f�r NPC-Einheiten. */ + /* Ab hier nur noch Befehle fuer NPC-Einheiten. */ if (u->faction!=f) continue; @@ -761,7 +761,7 @@ void plan_monsters(faction * f) produceexp(u, SK_PERCEPTION, u->number); } - /* Befehle m�ssen jede Runde neu gegeben werden: */ + /* Befehle muessen jede Runde neu gegeben werden: */ free_orders(&u->orders); /* All monsters guard the region: */ @@ -833,7 +833,7 @@ void plan_monsters(faction * f) } } if (long_order == NULL && check_student(u, NULL, SK_WEAPONLESS)) { - /* Einheiten, die Waffenlosen Kampf lernen k�nnten, lernen es um + /* Einheiten, die Waffenlosen Kampf lernen koennten, lernen es um * zu bewachen: */ if (rc->bonus[SK_WEAPONLESS] != -99) { if (effskill(u, SK_WEAPONLESS, NULL) < 1) { @@ -875,7 +875,7 @@ unit *spawn_seaserpent(region *r, faction *f) { } /** - * Drachen und Seeschlangen k�nnen entstehen + * Drachen und Seeschlangen koennen entstehen */ void spawn_dragons(void) { @@ -926,7 +926,7 @@ void spawn_dragons(void) } } -/** Untote k�nnen entstehen */ +/** Untote koennen entstehen */ void spawn_undead(void) { region *r; @@ -946,7 +946,7 @@ void spawn_undead(void) message *msg; unit *u; /* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen. - * Lieber sammeln lassen, bis sie mindestens 5% der Bev�lkerung sind, und + * Lieber sammeln lassen, bis sie mindestens 5% der Bevoelkerung sind, und * dann erst auferstehen. */ int undead = unburied / (rng_int() % 2 + 1); const race *rc = NULL; @@ -1005,7 +1005,7 @@ void spawn_undead(void) else { int i = deathcount(r); if (i) { - /* Gr�ber verwittern, 3% der Untoten finden die ewige Ruhe */ + /* Groeber verwittern, 3% der Untoten finden die ewige Ruhe */ deathcounts(r, (int)(-i * 0.03)); } } diff --git a/src/report.c b/src/report.c index 79c154c50..51ece5d93 100644 --- a/src/report.c +++ b/src/report.c @@ -551,9 +551,9 @@ static void nr_curses(struct stream *out, int indent, const faction *viewer, obj region *r; /* Die Sichtbarkeit eines Zaubers und die Zaubermeldung sind bei - * Gebäuden und Schiffen je nach, ob man Besitzer ist, verschieden. + * Gebaeuden und Schiffen je nach, ob man Besitzer ist, verschieden. * Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer. - * Spezialfälle (besonderes Talent, verursachender Magier usw. werde + * Spezialfaelle (besonderes Talent, verursachender Magier usw. werde * bei jedem curse gesondert behandelt. */ if (typ == TYP_SHIP) { ship *sh = (ship *)obj; diff --git a/src/spells.c b/src/spells.c index 2d6b820e1..5e2474861 100644 --- a/src/spells.c +++ b/src/spells.c @@ -449,7 +449,7 @@ report_effect(region * r, unit * mage, message * seen, message * unseen) * Vertrauten sehen, und durch den Vertrauten zaubern, allerdings nur * mit seiner halben Stufe. Je nach Vertrautem erhaelt der Magier * evtl diverse Skillmodifikationen. Der Typ des Vertrauten ist - * zufaellig bestimmt, wird aber durch Magiegebiet und Rasse beeinflußt. + * zufaellig bestimmt, wird aber durch Magiegebiet und Rasse beeinflusst. * "Tierische" Vertraute brauchen keinen Unterhalt. * * Ein paar Moeglichkeiten: @@ -1588,7 +1588,7 @@ static int sp_create_stonegolem(castorder * co) } /* ------------------------------------------------------------- */ -/* Name: Gro�e Duerre +/* Name: Grosse Duerre * Stufe: 17 * Kategorie: Region, negativ * Gebiet: Gwyrrd @@ -1896,7 +1896,7 @@ static int sp_treewalkexit(castorder * co) return 0; } - /* Koordinaten setzen und Region loeschen fuer �berpruefung auf + /* Koordinaten setzen und Region loeschen fuer Ueberpruefung auf * Gueltigkeit */ rt = pa->param[0]->data.r; tax = rt->x; @@ -2179,7 +2179,7 @@ static int sp_ironkeeper(castorder * co) unit_setstatus(keeper, ST_AVOID); /* kaempft nicht */ setguard(keeper, true); fset(keeper, UFL_ISNEW); - /* Parteitarnen, damit man nicht sofort wei�, wer dahinter steckt */ + /* Parteitarnen, damit man nicht sofort weiss, wer dahinter steckt */ if (rule_stealth_anon()) { fset(keeper, UFL_ANON_FACTION); } @@ -2557,7 +2557,7 @@ static void patzer_fumblecurse(const castorder * co) * * Wirkung: * In einer Wueste, Sumpf oder Gletscher gezaubert kann innerhalb der - * naechsten 6 Runden ein bis 6 Dracheneinheiten bis Groe�e Wyrm + * naechsten 6 Runden ein bis 6 Dracheneinheiten bis Groesse Wyrm * entstehen. * * Mit Stufe 12-15 erscheinen Jung- oder normaler Drachen, mit Stufe @@ -2803,7 +2803,7 @@ static int change_hitpoints(unit * u, int value) hp += value; - /* Jede Person ben�tigt mindestens 1 HP */ + /* Jede Person benoetigt mindestens 1 HP */ if (hp < u->number) { if (hp < 0) { /* Einheit tot */ hp = 0; @@ -3680,7 +3680,7 @@ static int sp_rallypeasantmob(castorder * co) * Gebiet: Cerddor * Wirkung: * Wiegelt 60% bis 90% der Bauern einer Region auf. Bauern werden ein - * gro�er Mob, der zur Monsterpartei gehoert und die Region bewacht. + * grosser Mob, der zur Monsterpartei gehoert und die Region bewacht. * Regionssilber sollte auch nicht durch Unterhaltung gewonnen werden * koennen. * @@ -3941,7 +3941,7 @@ static int sp_recruit(castorder * co) return 0; } /* Immer noch zuviel auf niedrigen Stufen. Deshalb die Rekrutierungskosten - * mit einfliessen lassen und dafuer den Exponenten etwas groe�er. + * mit einfliessen lassen und dafuer den Exponenten etwas groesser. * Wenn die Rekrutierungskosten deutlich hoeher sind als der Faktor, * ist das Verhaeltniss von ausgegebene Aura pro Bauer bei Stufe 2 * ein mehrfaches von Stufe 1, denn in beiden Faellen gibt es nur 1 @@ -3972,7 +3972,7 @@ static int sp_recruit(castorder * co) } /* ------------------------------------------------------------- */ -/* Name: Wanderprediger - Gro�e Anwerbung +/* Name: Wanderprediger - Grosse Anwerbung * Stufe: 14 * Gebiet: Cerddor * Wirkung: @@ -4027,8 +4027,8 @@ static int sp_bigrecruit(castorder * co) * Gebiet: Cerddor * Wirkung: * Erliegt die Einheit dem Zauber, so wird sie dem Magier alles - * erzaehlen, was sie ueber die gefragte Region wei�. Ist in der Region - * niemand ihrer Partei, so wei� sie nichts zu berichten. Auch kann + * erzaehlen, was sie ueber die gefragte Region weiss. Ist in der Region + * niemand ihrer Partei, so weiss sie nichts zu berichten. Auch kann * sie nur das erzaehlen, was sie selber sehen koennte. * Flags: * (UNITSPELL | TESTCANSEE) @@ -4086,7 +4086,7 @@ static int sp_pump(castorder * co) * Stufe: 6 * Gebiet: Cerddor * Wirkung: - * Betoert eine Einheit, so das sie ihm den groe�ten Teil ihres Bargelds + * Betoert eine Einheit, so dass sie ihm den groessten Teil ihres Bargelds * und 50% ihres Besitzes schenkt. Sie behaelt jedoch immer soviel, wie * sie zum ueberleben braucht. Wirkt gegen Magieresistenz. * min(Stufe*1000$, u->money - maintenance) @@ -4256,7 +4256,7 @@ static int sp_headache(castorder * co) if (target->number == 0 || pa->param[0]->flag == TARGET_NOTFOUND) return 0; - /* finde das groe�te Talent: */ + /* finde das groesste Talent: */ for (i = 0; i != target->skill_size; ++i) { skill *sv = target->skills + i; if (smax == NULL || skill_compare(sv, smax) > 0) { @@ -4405,7 +4405,7 @@ int sp_puttorest(castorder * co) return co->level; } -/* Name: Traumschloe�chen +/* Name: Traumschloesschen * Stufe: 3 * Kategorie: Region, Gebaeude, positiv * Gebiet: Illaun @@ -4440,7 +4440,7 @@ int sp_icastle(castorder * co) b = new_building(bt_illusion, r, mage->faction->locale); - /* Groe�e festlegen. */ + /* Groesse festlegen. */ if (type == bt_illusion) { b->size = (rng_int() % (int)((power * power) + 1) * 10); } @@ -4613,7 +4613,7 @@ int sp_baddreams(castorder * co) * Kategorie: * Wirkung: * Dieser Zauber ermoeglicht es dem Traeumer, den Schlaf aller aliierten - * Einheiten in der Region so zu beeinflussen, da� sie fuer einige Zeit + * Einheiten in der Region so zu beeinflussen, dass sie fuer einige Zeit * einen Bonus von 1 Talentstufe in allen Talenten * bekommen. Der Zauber wirkt erst im Folgemonat. * Flags: diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index fd87a2f17..65bfff59b 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -62,7 +62,7 @@ static const char *spell_damage(int sp) { switch (sp) { case 0: - /* meist t�dlich 20-65 HP */ + /* meist toetlich 20-65 HP */ return "5d10+15"; case 1: /* sehr variabel 4-48 HP */ @@ -71,7 +71,7 @@ static const char *spell_damage(int sp) /* leicht verwundet 4-18 HP */ return "2d8+2"; case 3: - /* fast immer t�dlich 30-50 HP */ + /* fast immer toetlich 30-50 HP */ return "5d5+25"; case 4: /* verwundet 11-26 HP */ @@ -335,11 +335,11 @@ int sp_combatrosthauch(struct castorder * co) selist_free(fgs); if (k == 0) { - /* keine Waffen mehr da, die zerst�rt werden k�nnten */ + /* keine Waffen mehr da, die zerstoert werden koennten */ message *msg = msg_message("rust_effect_1", "mage", fi->unit); message_all(b, msg); msg_release(msg); - fi->magic = 0; /* k�mpft nichtmagisch weiter */ + fi->magic = 0; /* kaempft nichtmagisch weiter */ level = 0; } else { @@ -405,7 +405,7 @@ int sp_speed(struct castorder * co) allies = count_allies(fi->side, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE, ALLY_ANY); - /* maximal 2*allies Versuche ein Opfer zu finden, ansonsten best�nde + /* maximal 2*allies Versuche ein Opfer zu finden, ansonsten bestuende * die Gefahr eine Endlosschleife*/ allies *= 2; @@ -871,7 +871,7 @@ static bool select_afraid(const side *vs, const fighter *fig, void *cbdata) } /* Gesang der Furcht (Kampfzauber) */ -/* Panik (Pr�kampfzauber) */ +/* Panik (Praekampfzauber) */ int flee_spell(struct castorder * co, int strength) { fighter * fi = co->magician.fig; @@ -900,7 +900,7 @@ int flee_spell(struct castorder * co, int strength) fighter *df = (fighter *)selist_get(ql, qi); for (n = 0; force > 0 && n != df->alive; ++n) { - if (df->person[n].flags & FL_PANICED) { /* bei SPL_SONG_OF_FEAR m�glich */ + if (df->person[n].flags & FL_PANICED) { /* bei SPL_SONG_OF_FEAR moeglich */ df->person[n].attack -= 1; --force; ++panik; @@ -944,7 +944,7 @@ int sp_hero(struct castorder * co) allies = count_allies(fi->side, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE, ALLY_ANY); - /* maximal 2*allies Versuche ein Opfer zu finden, ansonsten best�nde + /* maximal 2*allies Versuche ein Opfer zu finden, ansonsten bestuende * die Gefahr eine Endlosschleife*/ allies *= 2; @@ -992,7 +992,7 @@ int sp_berserk(struct castorder * co) allies = count_allies(fi->side, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE, ALLY_ANY); - /* maximal 2*allies Versuche ein Opfer zu finden, ansonsten best�nde + /* maximal 2*allies Versuche ein Opfer zu finden, ansonsten bestuende * die Gefahr eine Endlosschleife*/ allies *= 2; @@ -1181,7 +1181,7 @@ int sp_reeling_arrows(struct castorder * co) } /* Magier weicht dem Kampf aus. Wenn er sich bewegen kann, zieht er in - * eine Nachbarregion, wobei ein NACH ber�cksichtigt wird. Ansonsten + * eine Nachbarregion, wobei ein NACH beruecksichtigt wird. Ansonsten * bleibt er stehen und nimmt nicht weiter am Kampf teil. */ int sp_appeasement(struct castorder * co) { @@ -1194,7 +1194,7 @@ int sp_appeasement(struct castorder * co) region *r = b->region; message *m; - /* Fliehende Einheiten verlassen auf jeden Fall Geb�ude und Schiffe. */ + /* Fliehende Einheiten verlassen auf jeden Fall Gebaeude und Schiffe. */ if (!(r->terrain->flags & SEA_REGION)) { leave(mage, false); } @@ -1202,7 +1202,7 @@ int sp_appeasement(struct castorder * co) setguard(mage, false); unit_setstatus(mage, ST_FLEE); - /* wir tun so, als w�re die Person geflohen */ + /* wir tun so, als waere die Person geflohen */ fi->flags |= FIG_NOLOOT; fi->run.hp = mage->hp; fi->run.number = mage->number; @@ -1242,7 +1242,7 @@ int armor_spell(struct castorder * co, int per_level, int time_multi) message_all(b, m); msg_release(m); - /* gibt R�stung +effect f�r duration Treffer */ + /* gibt Ruestung +effect fuer duration Treffer */ effect = level / per_level; duration = (int)(time_multi * power * power); @@ -1286,7 +1286,7 @@ int sp_fumbleshield(struct castorder * co) message_all(b, m); msg_release(m); - /* der erste Zauber schl�gt mit 100% fehl */ + /* der erste Zauber schlaegt mit 100% fehl */ duration = 100; effect = 25 - level; if (effect < 1) effect = 1; @@ -1344,7 +1344,7 @@ int sp_reanimate(struct castorder * co) && u_race(tf->unit) != get_race(RC_DAEMON) && (chance(c))) { assert(tf->alive < tf->unit->number); - /* t.fighter->person[].hp beginnt mit t.index = 0 zu z�hlen, + /* t.fighter->person[].hp beginnt mit t.index = 0 zu zaehlen, * t.fighter->alive ist jedoch die Anzahl lebender in der Einheit, * also sind die hp von t.fighter->alive * t.fighter->hitpoints[t.fighter->alive-1] und der erste Tote diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index 4dc186dc5..fb6a8faeb 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -26,8 +26,8 @@ * Stufe: 6 * * Wirkung: -* Lae�t ein Schiff eine Runde lang fliegen. Wirkt nur auf Boote -* bis Kapazit�t 50. +* Laesst ein Schiff eine Runde lang fliegen. Wirkt nur auf Boote +* bis Kapazitaet 50. * Kombinierbar mit "Guenstige Winde", aber nicht mit "Sturmwind". * * Flag: diff --git a/src/steal.c b/src/steal.c index 8c11c40a9..9847ee72b 100644 --- a/src/steal.c +++ b/src/steal.c @@ -57,7 +57,7 @@ void expandstealing(region * r, econ_request * stealorders) norders = expand_production(r, stealorders, &requests); if (!norders) return; - /* F�r jede unit in der Region wird Geld geklaut, wenn sie Opfer eines + /* Fuer jede unit in der Region wird Geld geklaut, wenn sie Opfer eines * Beklauen-Orders ist. Jedes Opfer muss einzeln behandelt werden. * * u ist die beklaute unit. oa.unit ist die klauende unit. diff --git a/src/study.c b/src/study.c index 3fb2d0a7d..6130d340a 100644 --- a/src/study.c +++ b/src/study.c @@ -859,7 +859,7 @@ void reduce_skill_days(unit *u, skill_t sk, int days) { } } -/** Talente von Dämonen verschieben sich. +/** Talente von Daemonen verschieben sich. */ void demon_skillchange(unit *u) { diff --git a/src/upkeep.c b/src/upkeep.c index 9ab8c1fea..d5b5bf8d9 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -95,11 +95,11 @@ static bool hunger(int number, unit * u) deathcounts(r, dead); } if (hpsub > 0) { - /* Jetzt die Sch�den der nicht gestorbenen abziehen. */ + /* Jetzt die Schaeden der nicht gestorbenen abziehen. */ u->hp -= hpsub; - /* Meldung nur, wenn noch keine f�r Tote generiert. */ + /* Meldung nur, wenn noch keine fuer Tote generiert. */ if (dead == 0) { - /* Durch unzureichende Ern�hrung wird %s geschw�cht */ + /* Durch unzureichende Ernaehrung wird %s geschwaecht */ ADDMSG(&u->faction->msgs, msg_message("malnourish", "unit region", u, r)); } } @@ -133,13 +133,13 @@ void get_food(region * r) is_cold = insect_hunger && r_insectstalled(r); /* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber - * wird zun�chst so auf die Einheiten aufgeteilt, dass idealerweise - * jede Einheit genug Silber f�r ihren Unterhalt hat. */ + * wird zunaechst so auf die Einheiten aufgeteilt, dass idealerweise + * jede Einheit genug Silber fuer ihren Unterhalt hat. */ for (u = r->units; u; u = u->next) { int need = lifestyle(u); - /* Erstmal zur�cksetzen */ + /* Erstmal zuruecksetzen */ freset(u, UFL_HUNGER); if (u->ship && (u->ship->flags & SF_FISHING)) { @@ -237,7 +237,7 @@ void get_food(region * r) } /* 3. bestimmen, wie viele Bauern gefressen werden. - * bei fehlenden Bauern den D�mon hungern lassen + * bei fehlenden Bauern den Daemon hungern lassen */ for (u = r->units; u; u = u->next) { const race * rc = u_race(u); @@ -302,7 +302,7 @@ void get_food(region * r) } rsetpeasants(r, peasantfood / 10); - /* 3. Von den �berlebenden das Geld abziehen: */ + /* 3. Von den Ueberlebenden das Geld abziehen: */ for (u = r->units; u; u = u->next) { int m = get_money(u); int need = lifestyle(u); From 2e1bd01c5475811eaa0eac0feb877269a031fd23 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 9 Feb 2019 13:39:28 +0100 Subject: [PATCH 72/85] asciification --- src/kernel/build.c | 12 ++++++------ src/kernel/region.c | 4 +--- src/triggers/shock.c | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 63b89388e..0475c607e 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -147,7 +147,7 @@ static void destroy_road(unit * u, int nmax, struct order *ord) } static int recycle(unit *u, construction *con, int size) { - /* TODO: Nicht an ZERST�RE mit Punktangabe angepasst! */ + /* TODO: Nicht an ZERSTOERE mit Punktangabe angepasst! */ int c; for (c = 0; con->materials[c].number; ++c) { const requirement *rq = con->materials + c; @@ -545,8 +545,8 @@ static int build_limited(unit * u, const construction * con, int completed, int /* Hier ist entweder maxsize == -1, oder completed < maxsize. * Andernfalls ist das Datenfile oder sonstwas kaputt... - * (enno): Nein, das ist f�r Dinge, bei denen die n�chste Ausbaustufe - * die gleiche wie die vorherige ist. z.b. gegenst�nde. + * (enno): Nein, das ist fuer Dinge, bei denen die naechste Ausbaustufe + * die gleiche wie die vorherige ist. z.b. Gegenstaende. */ if (con->maxsize > 0) { completed = completed % con->maxsize; @@ -870,11 +870,11 @@ build_building(unit * u, const building_type * btype, int id, int want, order * btname = LOC(lang, btype->_name); if (want <= built) { - /* geb�ude fertig */ + /* gebaeude fertig */ new_order = default_order(lang); } else if (want != INT_MAX && btname) { - /* reduzierte restgr��e */ + /* reduzierte restgroesse */ const char *hasspace = strchr(btname, ' '); if (hasspace) { new_order = @@ -886,7 +886,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * } } else if (btname) { - /* Neues Haus, Befehl mit Geb�udename */ + /* Neues Haus, Befehl mit Gebaeudename */ const char *hasspace = strchr(btname, ' '); if (hasspace) { new_order = create_order(K_MAKE, lang, "\"%s\" %i", btname, b->no); diff --git a/src/kernel/region.c b/src/kernel/region.c index 99e82d659..a0f2ec99e 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1000,8 +1000,6 @@ static char *makename(void) *handle_end = "nlrdst", *vowels = "aaaaaaaaaaaeeeeeeeeeeeeiiiiiiiiiiioooooooooooouuuuuuuuuuyy"; - /* const char * vowels_latin1 = "aaaaaaaaaàâeeeeeeeeeéèêiiiiiiiiiíîoooooooooóòôuuuuuuuuuúyy"; */ - nk = strlen(kons); ne = strlen(handle_end); nv = strlen(vowels); @@ -1114,7 +1112,7 @@ void init_region(region *r) void terraform_region(region * r, const terrain_type * terrain) { - /* Resourcen, die nicht mehr vorkommen koennen, löschen */ + /* Resourcen, die nicht mehr vorkommen koennen, loeschen */ const terrain_type *oldterrain = r->terrain; rawmaterial **lrm = &r->resources; diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 205439b46..76fd6337f 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -87,7 +87,7 @@ static void do_shock(unit * u, const char *reason) } /* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage - * zu l�schen wenn der Familiar get�tet wird. Da sollten wir �ber eine + * zu loeschen wenn der Familiar getoetet wird. Da sollten wir ueber eine * saubere Implementation nachdenken. */ if (strcmp(reason, "trigger") == 0) { From d03f2cdab6a24db9b50f834653785006b05ecdf1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 9 Feb 2019 20:50:47 +0100 Subject: [PATCH 73/85] Mantis 2552: rewrite goblin stealing to be more readable. --- src/steal.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/steal.c b/src/steal.c index 9847ee72b..39158feba 100644 --- a/src/steal.c +++ b/src/steal.c @@ -193,8 +193,17 @@ void steal_cmd(unit * u, struct order *ord, econ_request ** stealorders) n = effsk - max_skill(r, f, SK_PERCEPTION); if (n <= 0) { - /* Wahrnehmung == Tarnung */ - if (u_race(u) != get_race(RC_GOBLIN) || effsk <= 3) { + /* Wenn Goblins mit einem Tarnungstalent von mindestens 4 klauen, bekommen + * sie mindestens 50 Silber, selbst dann, wenn sie erwischt werden. */ + if (u_race(u) == get_race(RC_GOBLIN) && effsk >= 4) { + ADDMSG(&u->faction->msgs, msg_message("stealfatal", "unit target", u, + u2)); + ADDMSG(&u2->faction->msgs, msg_message("thiefdiscover", "unit target", u, + u2)); + n = 1; + goblin = true; + } + else { ADDMSG(&u->faction->msgs, msg_message("stealfail", "unit target", u, u2)); if (n == 0) { ADDMSG(&u2->faction->msgs, msg_message("stealdetect", "unit", u2)); @@ -205,14 +214,6 @@ void steal_cmd(unit * u, struct order *ord, econ_request ** stealorders) } return; } - else { - ADDMSG(&u->faction->msgs, msg_message("stealfatal", "unit target", u, - u2)); - ADDMSG(&u2->faction->msgs, msg_message("thiefdiscover", "unit target", u, - u2)); - n = 1; - goblin = true; - } } i = i_get(u->items, rring->itype); From 306c1d86590447e83a3933c9dd8bd942655ed56e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 10 Feb 2019 09:51:06 +0100 Subject: [PATCH 74/85] simplify the orders.queue locking logic, remove it from python --- process/accept-orders.py | 28 ---------------------- process/cron/run-eressea.cron | 21 +++++------------ process/orders-accept | 4 +++- process/orders-process | 4 +++- process/process-orders.py | 44 +++-------------------------------- 5 files changed, 15 insertions(+), 86 deletions(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index 3bf9ea965..69a6ce28f 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -60,28 +60,6 @@ writeheaders = True # reject all html email? rejecthtml = True -def unlock_file(filename): - try: - os.unlink(filename+".lock") - except: - print "could not unlock %s.lock, file not found" % filename - -def lock_file(filename): - i = 0 - wait = 1 - if not os.path.exists(filename): - file=open(filename, "w") - file.close() - while True: - try: - os.symlink(filename, filename+".lock") - return - except: - i = i+1 - if i == 5: unlock_file(filename) - sleep(wait) - wait = wait*2 - messages = { "multipart-en" : "ERROR: The orders you sent contain no plaintext. " \ @@ -300,14 +278,12 @@ def accept(game, locale, stream, extend=None): return -1 logger.info("received orders from " + email) # get an available filename - lock_file(gamedir + "/orders.queue") maxdate, filename = available_file(savedir, prefix + email) if filename is None: logger.warning("more than " + str(maxfiles) + " orders from " + email) return -1 # copy the orders to the file text_ok = copy_orders(message, filename, email) - unlock_file(gamedir + "/orders.queue") warning, msg, fail = None, "", False maildate = message.get("Date") @@ -331,10 +307,8 @@ def accept(game, locale, stream, extend=None): os.unlink(filename) savedir = savedir + "/rejected" if not os.path.exists(savedir): os.mkdir(savedir) - lock_file(gamedir + "/orders.queue") maxdate, filename = available_file(savedir, prefix + email) store_message(message, filename) - unlock_file(gamedir + "/orders.queue") fail = True if sendmail and warning is not None: @@ -348,11 +322,9 @@ def accept(game, locale, stream, extend=None): print filename if not fail: - lock_file(gamedir + "/orders.queue") queue = open(gamedir + "/orders.queue", "a") queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game)) queue.close() - unlock_file(gamedir + "/orders.queue") logger.info("done - accepted orders from " + email) diff --git a/process/cron/run-eressea.cron b/process/cron/run-eressea.cron index ecd4c6b11..697cc5e88 100755 --- a/process/cron/run-eressea.cron +++ b/process/cron/run-eressea.cron @@ -19,30 +19,21 @@ mkdir $REPORTS cd $ERESSEA/game-$GAME -# wait for the queue lock to go away -maxt=5 -to=5 -while [ -e orders.queue.lock ] ; do - echo "waiting for orders to finish processing." - sleep $to - let to=$to+$to - let mast=$maxt-1 - [ $maxt -lt 0 ] && break -done - if [ -d test ]; then touch test/execute.lock fi + $BIN/create-orders $GAME $TURN +if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then + echo "server did not create orders for turn $TURN in game $GAME" + exit 2 +fi + $BIN/backup-eressea $GAME $TURN rm -f execute.lock $BIN/run-turn $GAME $TURN touch execute.lock -if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then - echo "server did not create orders for turn $TURN in game $GAME" - exit 2 -fi if [ ! -s $REPORTS/reports.txt ]; then echo "server did not create reports.txt in game $GAME" exit 4 diff --git a/process/orders-accept b/process/orders-accept index 266424a41..1e4dea2aa 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -1,5 +1,7 @@ #!/bin/sh SCRIPT=$(readlink -f $0) cd $(dirname $SCRIPT) -python accept-orders.py "$@" +lockfile -r3 -l120 orders.queue.lock +python accept-orders.py "$@" +rm -f orders.queue.lock diff --git a/process/orders-process b/process/orders-process index 38b2d1115..4751a94b1 100755 --- a/process/orders-process +++ b/process/orders-process @@ -1,5 +1,7 @@ #!/bin/sh SCRIPT=$(readlink -f $0) cd $(dirname $SCRIPT) -python process-orders.py "$@" +lockfile -r3 -l120 orders.queue.lock +python process-orders.py "$@" +rm -f orders.queue.lock diff --git a/process/process-orders.py b/process/process-orders.py index 30d9ea735..2b3e5c350 100755 --- a/process/process-orders.py +++ b/process/process-orders.py @@ -21,29 +21,6 @@ def pwd_get_email(faction, pwd, pwdfile=None): def split_filename(filename): return os.path.split(filename) -def unlock_file(filename): - try: - unlink(filename+".lock") - except: - print "could not unlock %s.lock, file not found" % filename - raise - -def lock_file(filename): - i = 0 - wait = 1 - if not os.path.exists(filename): - file=open(filename, "w") - file.close() - while True: - try: - symlink(filename, filename+".lock") - return - except: - i = i+1 - if i == 5: - raise - sleep(wait) - wait = wait*2 messages = { "subject-de": "Befehle angekommen", @@ -133,16 +110,12 @@ def echeck(filename, locale, rules): #print "reading password file..." pw_data = EPasswd() try: - pw_data.load_database(os.path.join(game_dir,"eressea.db")) + pw_data.load_database(os.path.join(game_dir, "eressea.db")) except: - pw_data.load_file(os.path.join(game_dir,"passwd")) + pw_data.load_file(os.path.join(game_dir, "passwd")) #print "reading orders.queue..." -# move the queue file to a save space while locking it: -try: - lock_file(queue_file) -except: - exit(0) +# move the queue file to a safe space while locking it: queuefile = open(queue_file, "r") lines = queuefile.readlines() queuefile.close() @@ -150,10 +123,6 @@ queuefile.close() # copy to a temp file tname="/tmp/orders.queue.%s" % str(time()) -try: - lock_file(tname) -except: - exit(0) tmpfile=open(tname, "w") for line in lines: tmpfile.write(line) @@ -161,12 +130,6 @@ tmpfile.close() openlog("orders") -unlink(queue_file) -try: - unlock_file(queue_file) -except: - pass - for line in lines: tokens = split(line[:-1], ' ') dict = {} @@ -221,4 +184,3 @@ for line in lines: closelog() unlink(tname) -unlock_file(tname) From f83f17687b970c1c78119d6f16f8961e19c786be Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 10 Feb 2019 10:07:08 +0100 Subject: [PATCH 75/85] remove queue after we are done with it --- process/orders-accept | 1 + process/process-orders.py | 1 + 2 files changed, 2 insertions(+) diff --git a/process/orders-accept b/process/orders-accept index 1e4dea2aa..33b3d5ecc 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -5,3 +5,4 @@ cd $(dirname $SCRIPT) lockfile -r3 -l120 orders.queue.lock python accept-orders.py "$@" rm -f orders.queue.lock + diff --git a/process/process-orders.py b/process/process-orders.py index 2b3e5c350..4d19dde78 100755 --- a/process/process-orders.py +++ b/process/process-orders.py @@ -129,6 +129,7 @@ for line in lines: tmpfile.close() openlog("orders") +unlink(queue_file) for line in lines: tokens = split(line[:-1], ' ') From 07f7adbe56d33c9d6cf040821c07e463e1e5d2ab Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 10 Feb 2019 19:21:25 +0100 Subject: [PATCH 76/85] include expat in dependencies --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c6a21d0e4..d7a014d89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ addons: - libtolua-dev - libncurses5-dev - libsqlite3-dev - - libxml2-dev + - libexpat1-dev - valgrind - cppcheck - shellcheck From de06600394876233ace50f8dbd77e75990a9e434 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 15 Feb 2019 10:07:55 +0100 Subject: [PATCH 77/85] fix coverity errors --- src/kernel/save.c | 3 +++ src/report.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index a914b1c32..45da22a7c 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1186,6 +1186,9 @@ int readgame(const char *filename) binstore_done(&store); fstream_done(&strm); } + else { + fclose(F); + } return n; } diff --git a/src/report.c b/src/report.c index 51ece5d93..7ea25c8d6 100644 --- a/src/report.c +++ b/src/report.c @@ -1443,7 +1443,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) ++begin; } pos = begin; - while (pos) { + do { char *next = strchr(pos+1, ' '); if (next == NULL) { if (isfinal) { @@ -1474,7 +1474,7 @@ void pump_paragraph(sbstring *sbp, stream *out, size_t maxlen, bool isfinal) break; } pos = next; - } + } while (pos); } if (isfinal) { char *pos = sbp->begin; From 894bb4db4c9ff8b902729efbfe2a40c99abc074e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 16 Feb 2019 20:14:34 +0100 Subject: [PATCH 78/85] BUG 2504: skeletons can learn. There was a mixup between the AI feature and the race capability, so I cleared up the code a little bit. It's annoying that these flags are in the same int. --- res/e3a/races.xml | 64 ++++++++++++++--------------- res/eressea/races.xml | 80 ++++++++++++++++++------------------- res/races/dragon.xml | 4 +- res/races/wyrm.xml | 4 +- res/races/youngdragon.xml | 4 +- res/races/zombie.xml | 4 +- scripts/tests/e2/undead.lua | 11 +++++ src/exparse.c | 19 ++++++--- src/kernel/race.h | 2 +- src/monsters.c | 2 +- src/study.c | 3 +- src/study.test.c | 31 +++++++++++++- 12 files changed, 138 insertions(+), 90 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index 2fa889160..e2fea2acb 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -400,8 +400,8 @@ - - + + @@ -425,8 +425,8 @@ - - + + @@ -565,8 +565,8 @@ - - + + @@ -597,8 +597,8 @@ - - + + @@ -655,14 +655,14 @@ - - + + - - + + @@ -694,8 +694,8 @@ - - + + @@ -703,9 +703,9 @@ - + @@ -736,8 +736,8 @@ - - + + @@ -754,8 +754,8 @@ - - + + @@ -771,8 +771,8 @@ - - + + @@ -787,8 +787,8 @@ - - + + @@ -801,8 +801,8 @@ - - + + @@ -816,8 +816,8 @@ - - + + @@ -830,13 +830,13 @@ - - + + - - + + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 1acffa872..bf9eeb18c 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -298,8 +298,8 @@ - - + + @@ -328,8 +328,8 @@ - - + + @@ -507,8 +507,8 @@ - - + + @@ -578,8 +578,8 @@ - + regaura="1.000000" weight="100" capacity="540" speed="1.000000" hp="20" damage="0d0" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="10" fly="yes" walk="yes" teach="no" invinciblenonmagic="yes"> + @@ -652,14 +652,14 @@ - - + + - - + + @@ -696,13 +696,13 @@ - - + + - - + + @@ -711,8 +711,8 @@ - - + + @@ -721,8 +721,8 @@ - - + + @@ -732,8 +732,8 @@ - - + + @@ -983,8 +983,8 @@ - - + + @@ -1000,8 +1000,8 @@ - - + + @@ -1016,8 +1016,8 @@ - - + + @@ -1031,8 +1031,8 @@ - - + + @@ -1044,8 +1044,8 @@ - - + + @@ -1058,8 +1058,8 @@ - - + + @@ -1071,12 +1071,12 @@ - - + + - - + + @@ -1202,8 +1202,8 @@ - - + + diff --git a/res/races/dragon.xml b/res/races/dragon.xml index 7625b914f..58acc5f57 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -2,10 +2,10 @@ - + diff --git a/res/races/wyrm.xml b/res/races/wyrm.xml index c69ca2953..96a9d2e3c 100644 --- a/res/races/wyrm.xml +++ b/res/races/wyrm.xml @@ -4,9 +4,9 @@ - + diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index bbfdb5a9f..30797fb7d 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -3,9 +3,9 @@ - + diff --git a/res/races/zombie.xml b/res/races/zombie.xml index fdfe97d8e..01407b29a 100644 --- a/res/races/zombie.xml +++ b/res/races/zombie.xml @@ -4,9 +4,9 @@ hp="20" damage="1d5" unarmedattack="-2" unarmeddefense="-2" playerrace="no" walk="yes" shapeshift="no" giveperson="no" giveunit="no" getitem="no" equipment="yes" scarepeasants="yes" - cansteal="no" unarmedguard="yes" absorbpeasants="yes" noheal="yes" + cansteal="no" unarmedguard="yes" noheal="yes" undead="yes" resistpierce="yes"> - + diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index 243919bbc..e33dc538d 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -60,3 +60,14 @@ function test_clones_dont_give_person() process_orders() assert_equal(2, u1.number) end + +-- bug 2504 +function test_skeleton_cannot_learn() + local r = region.create(0, 0, "plain") + local f = faction.create("elf") + local u = unit.create(f, r, 2) + u.race = "skeleton" + u:add_order("LERNE Wahrnehmung") + process_orders() + assert_equal(0, u:get_skill('perception')) +end diff --git a/src/exparse.c b/src/exparse.c index 0814f7cdc..4160b32ba 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -993,12 +993,19 @@ static int nfamiliars; static void start_races(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { race *rc = (race *)pi->object; const char *flag_names[] = { - "playerrace", "killpeasants", "scarepeasants", "!cansteal", - "moverandom", "cannotmove", "learn", "fly", "swim", "walk", - "!learn", "!teach", "horse", "desert", "illusionary", - "absorbpeasants", "noheal", "noweapons", "shapeshift", + "playerrace", "", "", "!cansteal", + "", "cannotmove", "", "fly", "swim", "walk", + "!learn", "!teach","horse", "desert", "illusionary", + "", "noheal", "noweapons", "shapeshift", "shapeshiftany", "undead", "dragon", "coastal", "unarmedguard", - "cansail", "invisible", "shipspeed", "moveattack", "migrants", NULL }; + "cansail", "invisible", "shipspeed", "", "migrants", NULL }; + const char *ai_flag_names[] = { + "", "killpeasants", "scarepeasants", "", + "moverandom", "", "learn", "", "", "", + "", "", "", "", "", + "absorbpeasants", "", "", "", + "", "", "", "", "", + "", "", "", "moveattack", "", NULL }; const char *bflag_names[] = { "equipment", "noblock", "resistpierce", "resistcut", "resistbash", "invinciblenonmagic", "noattack", NULL }; @@ -1106,7 +1113,7 @@ static void start_races(parseinfo *pi, const XML_Char *el, const XML_Char **attr else if (xml_strequal(key, "scare")) { rc_set_param(rc, "scare", val); } - else if (!handle_flag(&flags, attr + i, flag_names)) { + else if (!handle_flag(&flags, attr + i, ai_flag_names)) { handle_bad_input(pi, el, key); } } diff --git a/src/kernel/race.h b/src/kernel/race.h index f2b96c153..dd169272a 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -208,7 +208,7 @@ extern "C" { #define RCF_NOSTEAL (1<<3) /* this race has high stealth, but is not allowed to steal */ #define RCF_MOVERANDOM (1<<4) #define RCF_CANNOTMOVE (1<<5) -#define RCF_LEARN (1<<6) /* Lernt automatisch wenn struct faction == 0 */ +#define RCF_AI_LEARN (1<<6) /* Lernt automatisch wenn struct faction == 0 */ #define RCF_FLY (1<<7) /* kann fliegen */ #define RCF_SWIM (1<<8) /* kann schwimmen */ #define RCF_WALK (1<<9) /* kann ueber Land gehen */ diff --git a/src/monsters.c b/src/monsters.c index afa8070e5..290cbdb87 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -826,7 +826,7 @@ void plan_monsters(faction * f) long_order = create_order(K_PIRACY, f->locale, NULL); } else { - if (rc->flags & RCF_LEARN) { + if (rc->flags & RCF_AI_LEARN) { long_order = monster_learn(u); } } diff --git a/src/study.c b/src/study.c index 6130d340a..7e5ca9812 100644 --- a/src/study.c +++ b/src/study.c @@ -527,12 +527,13 @@ static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) { bool check_student(const struct unit *u, struct order *ord, skill_t sk) { int err = 0; + const race *rc = u_race(u); if (sk < 0) { err = 77; } /* Hack: Talente mit Malus -99 koennen nicht gelernt werden */ - else if (u_race(u)->bonus[sk] == -99) { + else if (rc->bonus[sk] == -99) { err = 771; } else { diff --git a/src/study.test.c b/src/study.test.c index 446b442bb..b57c921f4 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -59,6 +59,8 @@ typedef struct { static void setup_study(void) { test_setup(); + mt_create_error(77); + mt_create_error(771); mt_create_error(178); mt_create_error(65); mt_create_va(mt_new("teach_asgood", NULL), @@ -148,6 +150,32 @@ static void test_study_with_bad_teacher(CuTest *tc) { test_teardown(); } +static void test_check_student(CuTest *tc) { + unit *u; + race *rc; + + setup_study(); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); + u->thisorder = create_order(K_STUDY, u->faction->locale, skillnames[SK_CROSSBOW]); + CuAssertTrue(tc, check_student(u, u->thisorder, SK_CROSSBOW)); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); + + rc = test_create_race("skeleton"); + rc->flags |= RCF_NOLEARN; + u_setrace(u, rc); + CuAssertTrue(tc, !check_student(u, u->thisorder, SK_CROSSBOW)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error_race_nolearn")); + test_clear_messages(u->faction); + rc->flags -= RCF_NOLEARN; + + rc->bonus[SK_CROSSBOW] = -99; + CuAssertTrue(tc, !check_student(u, u->thisorder, SK_CROSSBOW)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error771")); + test_clear_messages(u->faction); + + test_teardown(); +} + static void test_study_bug_2194(CuTest *tc) { unit *u, *u1, *u2; struct locale * loc; @@ -158,7 +186,7 @@ static void test_study_bug_2194(CuTest *tc) { init_resources(); loc = test_create_locale(); setup_locale(loc); - u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); scale_number(u, 2); set_level(u, SK_CROSSBOW, TEACHDIFFERENCE); u->faction->locale = loc; @@ -742,5 +770,6 @@ CuSuite *get_study_suite(void) SUITE_ADD_TEST(suite, test_academy_bonus); SUITE_ADD_TEST(suite, test_demon_skillchanges); SUITE_ADD_TEST(suite, test_study_bug_2194); + SUITE_ADD_TEST(suite, test_check_student); return suite; } From d122ba22d0f37fa43fceb8bf739720541c23246d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Feb 2019 11:56:11 +0100 Subject: [PATCH 79/85] fix reports backup, I hope --- process/backup-eressea | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/process/backup-eressea b/process/backup-eressea index 0f81cf53e..12ced938c 100755 --- a/process/backup-eressea +++ b/process/backup-eressea @@ -23,15 +23,16 @@ if [ ! -d backup ] ; then ln -sf ~/backup/eressea/game-$GAME backup fi +if [ -e reports/reports.txt ] ; then + echo "backup reports $TURN, game $GAME" + tar cjf backup/$TURN-reports.tar.bz2 reports + curl -s -n -T backup/$TURN-reports.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN-reports.tar.bz2 +fi files="data/$TURN.dat parteien.full parteien" if [ -e orders.$TURN ]; then files="$files orders.$TURN" fi echo "backup turn $TURN, game $GAME, files: $files" -if [ -d reports ] ; then - tar cjf backup/$TURN-reports.tar.bz2 reports -fi tar cjf backup/$TURN.tar.bz2 $files -echo "uploading game-$GAME/$TURN.tar.bz2" curl -s -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2 #curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db From e24ebd7cbd49641b5d853d3f335bdfee4f3dcb19 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 28 Feb 2019 10:32:08 +0100 Subject: [PATCH 80/85] do not fail on malformed passwords --- process/epasswd.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/process/epasswd.py b/process/epasswd.py index 20109b9ba..496eb8331 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -69,7 +69,12 @@ class EPasswd: def check(self, id, passwd): pw = self.get_passwd(id) if pw[0:4]=='$2a$' or pw[0:4]=='$2y$': - return bcrypt.checkpw(passwd.encode('utf8'), pw.encode('utf8')) + try: + h1 = pw.encode('utf8') + h2 = passwd.encode('utf8') + return bcrypt.checkpw(h1, h2) + except: + return False return pw == passwd def get_passwd(self, id): From f5a03d4501f40fabdd8eaebdcdd1ee2f2c9b0ac8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 Mar 2019 11:01:28 +0100 Subject: [PATCH 81/85] stop writing password to logfile --- process/process-orders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/process-orders.py b/process/process-orders.py index 4d19dde78..dade32c02 100755 --- a/process/process-orders.py +++ b/process/process-orders.py @@ -157,7 +157,7 @@ for line in lines: if success: failed = False else: msg = msg + messages["unknown-"+locale] + "\n" msg = msg + "\n" - logfile.write("%s:%s:%s:%s:%s:%s\n" % (ctime(time()), email, game_email, faction, pwd, success)) + logfile.write("%s:%s:%s:%s:%s\n" % (ctime(time()), email, game_email, faction, success)) logfile.close() if failed: From 9210f77a1a8b67803d56065f49a359527487ac39 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 1 Mar 2019 19:14:09 +0100 Subject: [PATCH 82/85] fix bcrypt use --- process/epasswd.py | 6 +++--- src/reports.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/process/epasswd.py b/process/epasswd.py index 496eb8331..bdb3c4a6d 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -70,9 +70,9 @@ class EPasswd: pw = self.get_passwd(id) if pw[0:4]=='$2a$' or pw[0:4]=='$2y$': try: - h1 = pw.encode('utf8') - h2 = passwd.encode('utf8') - return bcrypt.checkpw(h1, h2) + uhash = pw.encode('utf8') + upass = passwd.encode('utf8') + return bcrypt.checkpw(upass, uhash) except: return False return pw == passwd diff --git a/src/reports.c b/src/reports.c index 10d00600b..056ee8dd0 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1606,7 +1606,7 @@ int write_reports(faction * f) 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); + password = faction_genpassword(f, buffer); } prepare_report(&ctx, f, password); get_addresses(&ctx); From ef81a20c6e783a59ab7841ed8781b4f55bed12b5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 11 Mar 2019 21:32:59 +0100 Subject: [PATCH 83/85] 2565 Leerzeile nach Helfe-Status. Helfestatus an das Ende des Reports. --- cJSON | 2 +- src/report.c | 35 ++++++++++++++++------------------- src/report.test.c | 4 ++-- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/cJSON b/cJSON index 22a4fc9be..8df81fb49 160000 --- a/cJSON +++ b/cJSON @@ -1 +1 @@ -Subproject commit 22a4fc9be31f0426e622f5bc9ebd7a1550845001 +Subproject commit 8df81fb497cc48b089a57fcdc3a9933540ebc7c9 diff --git a/src/report.c b/src/report.c index 7ea25c8d6..65c13492f 100644 --- a/src/report.c +++ b/src/report.c @@ -1545,7 +1545,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda } } if (show->num_allies == show->num_listed) { - sbs_strcat(sbp, ")."); + sbs_strcat(sbp, ").\n"); pump_paragraph(sbp, show->out, show->maxlen, true); } else { @@ -1577,11 +1577,24 @@ void report_allies(struct stream *out, size_t maxlen, const struct faction * f, } } +static void rpline(struct stream *out) +{ + static char line[REPORTWIDTH + 1]; + if (line[0] != '-') { + memset(line, '-', sizeof(line)); + line[REPORTWIDTH] = '\n'; + } + swrite(line, sizeof(line), 1, out); +} + static void allies(struct stream *out, const faction * f) { const group *g = f->groups; char prefix[64]; + centre(out, LOC(f->locale, "nr_alliances"), false); + newline(out); + if (f->allies) { snprintf(prefix, sizeof(prefix), "%s ", LOC(f->locale, "faction_help")); report_allies(out, REPORTWIDTH, f, f->allies, prefix); @@ -1594,6 +1607,7 @@ static void allies(struct stream *out, const faction * f) } g = g->next; } + rpline(out); } static void guards(struct stream *out, const region * r, const faction * see) @@ -1660,16 +1674,6 @@ static void guards(struct stream *out, const region * r, const faction * see) } } -static void rpline(struct stream *out) -{ - static char line[REPORTWIDTH + 1]; - if (line[0] != '-') { - memset(line, '-', sizeof(line)); - line[REPORTWIDTH] = '\n'; - } - swrite(line, sizeof(line), 1, out); -} - static void list_address(struct stream *out, const faction * uf, selist * seenfactions) { int qi = 0; @@ -2114,14 +2118,6 @@ report_plaintext(const char *filename, report_context * ctx, } } newline(out); - ERRNO_CHECK(); - centre(out, LOC(f->locale, "nr_alliances"), false); - newline(out); - - allies(out, f); - - rpline(out); - ERRNO_CHECK(); anyunits = 0; @@ -2249,6 +2245,7 @@ report_plaintext(const char *filename, report_context * ctx, paragraph(out, LOC(f->locale, "nr_youaredead"), 0, 2, 0); } else { + allies(out, f); list_address(out, f, ctx->addresses); } } diff --git a/src/report.test.c b/src/report.test.c index 59148d3a2..b6696ea1b 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -192,7 +192,7 @@ static void test_report_allies(CuTest *tc) { f1 = test_create_faction(NULL); f2 = test_create_faction(NULL); f3 = test_create_faction(NULL); - snprintf(exp, sizeof(exp), "Wir helfen %s (%s).\n", + snprintf(exp, sizeof(exp), "Wir helfen %s (%s).\n\n", factionname(f1), LOC(lang, parameters[P_GUARD])); ally_set(&f->allies, f1, HELP_GUARD); @@ -211,7 +211,7 @@ static void test_report_allies(CuTest *tc) { factionname(f2), LOC(lang, parameters[P_GIVE])); linebreak = strlen(exp); - snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)\nund %s (%s).\n", + snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)\nund %s (%s).\n\n", factionname(f1), LOC(lang, parameters[P_GUARD]), factionname(f2), From ea1bf3d3b97c98d957f7f8ba8b51e8bdc12adae0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Mar 2019 17:18:25 +0100 Subject: [PATCH 84/85] Bug 2567: we had alliances with status 0 in the data. --- src/kernel/ally.c | 19 ++++++++++++++----- src/kernel/ally.test.c | 26 ++++++++++++++++++++++++++ src/report.c | 4 ++-- src/util/base36.c | 2 +- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/kernel/ally.c b/src/kernel/ally.c index 1999b34b3..5ecf728bc 100644 --- a/src/kernel/ally.c +++ b/src/kernel/ally.c @@ -28,6 +28,7 @@ typedef struct allies { static void block_insert(allies *al, struct faction *f, int status) { int i = al->num++; + assert(status > 0); al->status[i] = status; al->factions[i] = f; /* TODO: heapify */ @@ -46,7 +47,7 @@ static int block_search(allies *al, const struct faction *f) { int allies_walk(struct allies *all, cb_allies_walk callback, void *udata) { - allies *al; + allies *al; for (al = all; al; al = al->next) { int i; for (i = 0; i != al->num; ++i) { @@ -94,13 +95,17 @@ void ally_set(allies **p_al, struct faction *f, int status) return; } if (al->num < BLOCKSIZE) { - block_insert(al, f, status); + if (status > 0) { + block_insert(al, f, status); + } return; } p_al = &al->next; } - *p_al = calloc(1, sizeof(allies)); - block_insert(*p_al, f, status); + if (status > 0) { + *p_al = calloc(1, sizeof(allies)); + block_insert(*p_al, f, status); + } } 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]; if (f && f->_alive) { write_faction_reference(f, data->store); + assert(al->status[i] > 0); WRITE_INT(data->store, al->status[i]); } } @@ -132,7 +138,10 @@ void read_allies(gamedata * data, allies **p_al) f = findfaction(aid); if (!f) f = faction_create(aid); READ_INT(data->store, &status); - ally_set(p_al, f, status); + /* NB: some data files have allies with status=0 */ + if (status > 0) { + ally_set(p_al, f, status); + } } } diff --git a/src/kernel/ally.test.c b/src/kernel/ally.test.c index 248eb5831..1b42a0f1f 100644 --- a/src/kernel/ally.test.c +++ b/src/kernel/ally.test.c @@ -1,6 +1,7 @@ #include #include "types.h" #include "ally.h" +#include "faction.h" #include #include @@ -41,11 +42,36 @@ static void test_allies(CuTest *tc) { 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 *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_allies); SUITE_ADD_TEST(suite, test_allies_clone); + SUITE_ADD_TEST(suite, test_allies_set); return suite; } diff --git a/src/report.c b/src/report.c index 7ea25c8d6..669412cdd 100644 --- a/src/report.c +++ b/src/report.c @@ -1509,7 +1509,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda if ((mode & HELP_ALL) == HELP_ALL) { sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY])); } - else { + else if (mode > 0) { int h, hh = 0; for (h = 1; h <= HELP_TRAVEL; h *= 2) { int p = MAXPARAMS; @@ -2177,8 +2177,8 @@ report_plaintext(const char *filename, report_context * ctx, if (wants_stats && r->seen.mode >= seen_travel) { if (r->land || r->seen.mode >= seen_unit) { - newline(out); statistics(out, r, f); + newline(out); } } diff --git a/src/util/base36.c b/src/util/base36.c index f77823a0b..33701f0f6 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -88,7 +88,7 @@ const char *itoab_r(int i, int base, char *s, size_t len) } } 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"); } } From f1c27f09e3d313d36f26ed972e806af7e1ac42d9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 24 Mar 2019 17:24:16 +0100 Subject: [PATCH 85/85] dragon evolution gives full hitpoints. --- src/races/dragons.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/races/dragons.c b/src/races/dragons.c index ec16f78dc..5ab877c40 100644 --- a/src/races/dragons.c +++ b/src/races/dragons.c @@ -27,26 +27,26 @@ static int age_chance(int a, int b, int p) { return (r < 0) ? 0 : r; } -#define DRAGONAGE 27 -#define WYRMAGE 68 +#define DRAGONAGE 27 +#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) { 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); - u_setrace(u, get_race(RC_DRAGON)); - u->irace = NULL; - scale_number(u, 1); - u->hp = (int)(unit_max_hp(u) * u->number * q); + evolve_dragon(u, get_race(RC_DRAGON)); } } void age_dragon(unit * u) { 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); - u_setrace(u, get_race(RC_WYRM)); - u->irace = NULL; - u->hp = (int)(unit_max_hp(u) * u->number * q); + evolve_dragon(u, get_race(RC_WYRM)); } }