diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index ebbc978f6..60f2b6f63 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -142,6 +142,7 @@ function process(rules, orders) callbacks(rules, 'update') write_files(config.locales) + dbupdate() file = '' .. get_turn() .. '.dat' if eressea.write_game(file)~=0 then @@ -161,9 +162,6 @@ function run_turn(rules) orderfile = orderfile or config.basepath .. '/orders.' .. turn eressea.log.debug("executing turn " .. get_turn() .. " with " .. orderfile .. " with rules=" .. config.rules) local result = process(rules, orderfile) - if result==0 then - dbupdate() - end return result end diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 49542ce4a..9fa861bc6 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -287,7 +287,6 @@ void syntax_error(const struct unit *u, struct order *ord) message * result; result = msg_error(u, ord, 10); ADDMSG(&u->faction->msgs, result); - msg_release(result); } extern unsigned int new_hashstring(const char *s); @@ -306,6 +305,7 @@ void free_messagelist(message_list * msgs) message *add_message(message_list ** pm, message * m) { + assert(m->type); if (!lomem && m != NULL) { struct mlist *mnew = malloc(sizeof(struct mlist)); if (*pm == NULL) { diff --git a/src/kernel/region.c b/src/kernel/region.c index b227394a8..852a6f0cb 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -42,7 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include -#include +#include #include #include #include diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 2e95de30c..8a23afd4a 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include -#include +#include #include #include #include diff --git a/src/kernel/unit.c b/src/kernel/unit.c index ea2bbd950..6a0e22f08 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -48,7 +48,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/laws.c b/src/laws.c index ed9bc2108..abab90a12 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2894,7 +2894,7 @@ void restack_units(void) cmistake(u, ord, 260, MSG_EVENT); } else if (v == u) { - cmistake(u, ord, 10, MSG_EVENT); + syntax_error(u, ord); } else { switch (p) { @@ -4381,17 +4381,17 @@ void init_processor(void) add_proc_order(p, K_GROUP, group_cmd, 0, NULL); p += 10; - add_proc_order(p, K_QUIT, &quit_cmd, 0, NULL); -// add_proc_order(p, K_URSPRUNG, &origin_cmd, 0, NULL); - add_proc_order(p, K_ALLY, &ally_cmd, 0, NULL); - add_proc_order(p, K_PREFIX, &prefix_cmd, 0, NULL); - add_proc_order(p, K_SETSTEALTH, &setstealth_cmd, 0, NULL); - add_proc_order(p, K_STATUS, &status_cmd, 0, NULL); - add_proc_order(p, K_COMBATSPELL, &combatspell_cmd, 0, NULL); - add_proc_order(p, K_DISPLAY, &display_cmd, 0, NULL); - add_proc_order(p, K_NAME, &name_cmd, 0, NULL); - add_proc_order(p, K_GUARD, &guard_off_cmd, 0, NULL); - add_proc_order(p, K_RESHOW, &reshow_cmd, 0, NULL); + add_proc_order(p, K_QUIT, quit_cmd, 0, NULL); +// add_proc_order(p, K_URSPRUNG, origin_cmd, 0, NULL); + add_proc_order(p, K_ALLY, ally_cmd, 0, NULL); + add_proc_order(p, K_PREFIX, prefix_cmd, 0, NULL); + add_proc_order(p, K_SETSTEALTH, setstealth_cmd, 0, NULL); + add_proc_order(p, K_STATUS, status_cmd, 0, NULL); + add_proc_order(p, K_COMBATSPELL, combatspell_cmd, 0, NULL); + add_proc_order(p, K_DISPLAY, display_cmd, 0, NULL); + add_proc_order(p, K_NAME, name_cmd, 0, NULL); + add_proc_order(p, K_GUARD, guard_off_cmd, 0, NULL); + add_proc_order(p, K_RESHOW, reshow_cmd, 0, NULL); if (get_param_int(global.parameters, "rules.alliances", 0) == 1) { p += 10; @@ -4403,7 +4403,7 @@ void init_processor(void) add_proc_order(p, K_MAIL, mail_cmd, 0, "Botschaften"); p += 10; /* all claims must be done before we can USE */ - add_proc_region(p, &enter_1, "Betreten (1. Versuch)"); /* for GIVE CONTROL */ + add_proc_region(p, enter_1, "Betreten (1. Versuch)"); /* for GIVE CONTROL */ add_proc_order(p, K_USE, use_cmd, 0, "Benutzen"); p += 10; /* in case it has any effects on alliance victories */ @@ -4426,11 +4426,11 @@ void init_processor(void) p += 10; /* can't allow reserve before siege (weapons) */ add_proc_region(p, enter_1, "Betreten (3. Versuch)"); /* to claim a castle after a victory and to be able to DESTROY it in the same turn */ if (get_param_int(global.parameters, "rules.reserve.twophase", 0)) { - add_proc_order(p, K_RESERVE, &reserve_self, 0, "RESERVE (self)"); + add_proc_order(p, K_RESERVE, reserve_self, 0, "RESERVE (self)"); p += 10; } - add_proc_order(p, K_RESERVE, &reserve_cmd, 0, "RESERVE (all)"); - add_proc_order(p, K_CLAIM, &claim_cmd, 0, NULL); + add_proc_order(p, K_RESERVE, reserve_cmd, 0, "RESERVE (all)"); + add_proc_order(p, K_CLAIM, claim_cmd, 0, NULL); add_proc_unit(p, follow_unit, "Folge auf Einheiten setzen"); p += 10; /* rest rng again before economics */ @@ -4438,13 +4438,13 @@ void init_processor(void) add_proc_region(p, force_leave, "kick non-allies out of buildings/ships"); } add_proc_region(p, economics, "Zerstoeren, Geben, Rekrutieren, Vergessen"); - add_proc_order(p, K_PROMOTION, &promotion_cmd, 0, "Heldenbefoerderung"); + add_proc_order(p, K_PROMOTION, promotion_cmd, 0, "Heldenbefoerderung"); p += 10; if (!keyword_disabled(K_PAY)) { - add_proc_order(p, K_PAY, &pay_cmd, 0, "Gebaeudeunterhalt (disable)"); + add_proc_order(p, K_PAY, pay_cmd, 0, "Gebaeudeunterhalt (disable)"); } - add_proc_postregion(p, &maintain_buildings_1, + add_proc_postregion(p, maintain_buildings_1, "Gebaeudeunterhalt (1. Versuch)"); p += 10; /* QUIT fuer sich alleine */ @@ -4452,68 +4452,68 @@ void init_processor(void) if (!keyword_disabled(K_CAST)) { p += 10; - add_proc_global(p, &magic, "Zaubern"); + add_proc_global(p, magic, "Zaubern"); } p += 10; - add_proc_order(p, K_TEACH, &teach_cmd, PROC_THISORDER | PROC_LONGORDER, + add_proc_order(p, K_TEACH, teach_cmd, PROC_THISORDER | PROC_LONGORDER, "Lehren"); p += 10; - add_proc_order(p, K_STUDY, &learn_cmd, PROC_THISORDER | PROC_LONGORDER, + add_proc_order(p, K_STUDY, learn_cmd, PROC_THISORDER | PROC_LONGORDER, "Lernen"); p += 10; - add_proc_order(p, K_MAKE, &make_cmd, PROC_THISORDER | PROC_LONGORDER, + add_proc_order(p, K_MAKE, make_cmd, PROC_THISORDER | PROC_LONGORDER, "Produktion"); - add_proc_postregion(p, &produce, "Arbeiten, Handel, Rekruten"); - add_proc_postregion(p, &split_allocations, "Produktion II"); + add_proc_postregion(p, produce, "Arbeiten, Handel, Rekruten"); + add_proc_postregion(p, split_allocations, "Produktion II"); p += 10; - add_proc_region(p, &enter_2, "Betreten (4. Versuch)"); /* Once again after QUIT */ + add_proc_region(p, enter_2, "Betreten (4. Versuch)"); /* Once again after QUIT */ p += 10; - add_proc_region(p, &sinkships, "Schiffe sinken"); + add_proc_region(p, sinkships, "Schiffe sinken"); p += 10; - add_proc_global(p, &movement, "Bewegungen"); + add_proc_global(p, movement, "Bewegungen"); if (get_param_int(global.parameters, "work.auto", 0)) { p += 10; - add_proc_region(p, &auto_work, "Arbeiten (auto)"); + add_proc_region(p, auto_work, "Arbeiten (auto)"); } p += 10; - add_proc_order(p, K_GUARD, &guard_on_cmd, 0, "Bewache (an)"); + add_proc_order(p, K_GUARD, guard_on_cmd, 0, "Bewache (an)"); if (get_param_int(global.parameters, "rules.encounters", 0)) { p += 10; - add_proc_global(p, &encounters, "Zufallsbegegnungen"); + add_proc_global(p, encounters, "Zufallsbegegnungen"); } p += 10; - add_proc_unit(p, &monster_kills_peasants, + add_proc_unit(p, monster_kills_peasants, "Monster fressen und vertreiben Bauern"); p += 10; - add_proc_global(p, &randomevents, "Zufallsereignisse"); + add_proc_global(p, randomevents, "Zufallsereignisse"); p += 10; - add_proc_global(p, &monthly_healing, "Regeneration (HP)"); - add_proc_global(p, ®enerate_aura, "Regeneration (Aura)"); + add_proc_global(p, monthly_healing, "Regeneration (HP)"); + add_proc_global(p, regenerate_aura, "Regeneration (Aura)"); if (!keyword_disabled(K_DEFAULT)) { - add_proc_global(p, &defaultorders, "Defaults setzen"); + add_proc_global(p, defaultorders, "Defaults setzen"); } - add_proc_global(p, &demographics, "Nahrung, Seuchen, Wachstum, Wanderung"); + add_proc_global(p, demographics, "Nahrung, Seuchen, Wachstum, Wanderung"); if (!keyword_disabled(K_SORT)) { p += 10; add_proc_global(p, restack_units, "Einheiten sortieren"); } if (!keyword_disabled(K_NUMBER)) { - add_proc_order(p, K_NUMBER, &renumber_cmd, 0, "Neue Nummern (Einheiten)"); + add_proc_order(p, K_NUMBER, renumber_cmd, 0, "Neue Nummern (Einheiten)"); p += 10; - add_proc_global(p, &renumber_factions, "Neue Nummern"); + add_proc_global(p, renumber_factions, "Neue Nummern"); } } diff --git a/src/magic.c b/src/magic.c index e50393d40..d91bd9658 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2527,7 +2527,7 @@ static castorder *cast_cmd(unit * u, order * ord) level = _min(p, level); if (level < 1) { /* Fehler "Das macht wenig Sinn" */ - cmistake(u, ord, 10, MSG_MAGIC); + syntax_error(u, ord); return 0; } s = gettoken(token, sizeof(token)); @@ -2557,7 +2557,7 @@ static castorder *cast_cmd(unit * u, order * ord) level = _min(p, level); if (level < 1) { /* Fehler "Das macht wenig Sinn" */ - cmistake(u, ord, 10, MSG_MAGIC); + syntax_error(u, ord); return 0; } s = gettoken(token, sizeof(token)); diff --git a/src/modules/arena.c b/src/modules/arena.c index fa08d74ac..fea4743de 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -49,7 +49,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/modules/museum.c b/src/modules/museum.c index 27722f0f3..4914e11bd 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -43,7 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include diff --git a/src/report.c b/src/report.c index aab6f6691..e62adb7e8 100644 --- a/src/report.c +++ b/src/report.c @@ -120,7 +120,14 @@ void newline(stream *out) { sputs("", out); } -static const char *spaces = " "; +void write_spaces(stream *out, size_t num) { + static const char spaces[REPORTWIDTH] = " "; + while (num > 0) { + size_t bytes = (num > REPORTWIDTH) ? REPORTWIDTH : num; + swrite(spaces, sizeof(char), bytes, out); + num -= bytes; + } +} static void centre(stream *out, const char *s, bool breaking) { @@ -140,9 +147,8 @@ static void centre(stream *out, const char *s, bool breaking) freestrlist(T); } else { - swrite(spaces, sizeof(char), (REPORTWIDTH - strlen(s) + 1) / 2, out); + write_spaces(out, (REPORTWIDTH - strlen(s) + 1) / 2); sputs(s, out); - newline(out); } } @@ -176,16 +182,16 @@ char marker) const char *last_space = begin; if (mark && indent >= 2) { - swrite(spaces, sizeof(char), indent - 2, out); + write_spaces(out, indent - 2); swrite(mark, sizeof(char), 1, out); - swrite(spaces, sizeof(char), 1, out); + write_spaces(out, 1); mark = 0; } else if (begin == str) { - swrite(spaces, sizeof(char), indent, out); + write_spaces(out, indent); } else { - swrite(spaces, sizeof(char), indent + hanging_indent, out); + write_spaces(out, indent + hanging_indent); } while (*end && end <= begin + length - indent) { if (*end == ' ') { @@ -518,7 +524,7 @@ void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark) width = REPORTWIDTH - indent; firstline = 1; - for (;;) { + while (s[0]) { unsigned int j = 0, i; for (i=0; s[j]; j=i) { @@ -535,7 +541,7 @@ void sparagraph(strlist ** SP, const char *s, unsigned int indent, char mark) break; } i = j + 1; - } while (s[j]); + } for (j = 0; j != indent; j++) buf[j] = ' '; diff --git a/src/report.h b/src/report.h index 5f4da17a9..189a38f0f 100644 --- a/src/report.h +++ b/src/report.h @@ -15,8 +15,10 @@ extern "C" { #endif + struct stream; void register_nr(void); void report_cleanup(void); + void write_spaces(struct stream *out, size_t num); #ifdef __cplusplus } diff --git a/src/reports.test.c b/src/reports.test.c index eb772782f..29f7ae5aa 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -1,6 +1,7 @@ #include #include #include "reports.h" +#include "report.h" #include #include @@ -10,6 +11,8 @@ #include #include +#include +#include #include #include @@ -98,11 +101,43 @@ static void test_seen_faction(CuTest *tc) { CuAssertTrue(tc, f1->no < f2->no); } +static void test_write_spaces(CuTest *tc) { + stream out = { 0 }; + char buf[1024]; + size_t len; + + mstream_init(&out); + write_spaces(&out, 4); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertStrEquals(tc, " ", buf); + CuAssertIntEquals(tc, ' ', buf[3]); + mstream_done(&out); +} + +static void test_write_many_spaces(CuTest *tc) { + stream out = { 0 }; + char buf[1024]; + size_t len; + + mstream_init(&out); + write_spaces(&out, 100); + out.api->rewind(out.handle); + len = out.api->read(out.handle, buf, sizeof(buf)); + buf[len] = '\0'; + CuAssertIntEquals(tc, 100, (int)len); + CuAssertIntEquals(tc, ' ', buf[99]); + mstream_done(&out); +} + CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_reorder_units); SUITE_ADD_TEST(suite, test_seen_faction); SUITE_ADD_TEST(suite, test_regionid); + SUITE_ADD_TEST(suite, test_write_spaces); + SUITE_ADD_TEST(suite, test_write_many_spaces); return suite; } diff --git a/src/util/crmessage.c b/src/util/crmessage.c index 517adfd6e..942ba2610 100644 --- a/src/util/crmessage.c +++ b/src/util/crmessage.c @@ -15,7 +15,7 @@ #include "crmessage.h" #include "message.h" -#include "goodies.h" +#include "strings.h" #include "log.h" #include diff --git a/src/util/goodies.c b/src/util/goodies.c index b46f9cb7a..2444d0f47 100644 --- a/src/util/goodies.c +++ b/src/util/goodies.c @@ -19,10 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "goodies.h" -#include "unicode.h" - /* libc includes */ -#include #include #include @@ -53,23 +50,6 @@ int *intlist_find(int *i_p, int fi) return NULL; } -char *set_string(char **s, const char *neu) -{ - if (neu == NULL) { - free(*s); - *s = NULL; - } - else if (*s == NULL) { - *s = malloc(strlen(neu) + 1); - strcpy(*s, neu); - } - else { - *s = realloc(*s, strlen(neu) + 1); - strcpy(*s, neu); - } - return *s; -} - static int spc_email_isvalid(const char *address) { int count = 0; diff --git a/src/util/goodies.h b/src/util/goodies.h index da18b2b36..c619c4958 100644 --- a/src/util/goodies.h +++ b/src/util/goodies.h @@ -19,18 +19,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef GOODIES_H #define GOODIES_H -#include "strings.h" - #ifdef __cplusplus extern "C" { #endif - extern char *set_string(char **s, const char *neu); - extern int set_email(char **pemail, const char *newmail); + int set_email(char **pemail, const char *newmail); - extern int *intlist_init(void); - extern int *intlist_add(int *i_p, int i); - extern int *intlist_find(int *i_p, int i); + int *intlist_init(void); + int *intlist_add(int *i_p, int i); + int *intlist_find(int *i_p, int i); #ifdef __cplusplus } diff --git a/src/util/language.c b/src/util/language.c index 677832636..79697f95f 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "language_struct.h" #include "log.h" -#include "goodies.h" +#include "strings.h" #include "umlaut.h" #include diff --git a/src/util/message.c b/src/util/message.c index 302e8d57c..b082d9d98 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -14,7 +14,7 @@ #include #include "message.h" -#include "goodies.h" +#include "strings.h" #include "log.h" #include "quicklist.h" diff --git a/src/util/nrmessage.c b/src/util/nrmessage.c index 5543b87ef..640cb81e6 100644 --- a/src/util/nrmessage.c +++ b/src/util/nrmessage.c @@ -21,7 +21,7 @@ #include "message.h" #include "language.h" #include "translation.h" -#include "goodies.h" +#include "strings.h" /* libc includes */ #include diff --git a/src/util/strings.c b/src/util/strings.c index 7a3660ed5..3f3d7dc36 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -21,6 +21,24 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include +#include + +char *set_string(char **s, const char *neu) +{ + if (neu == NULL) { + free(*s); + *s = NULL; + } + else if (*s == NULL) { + *s = malloc(strlen(neu) + 1); + strcpy(*s, neu); + } + else { + *s = realloc(*s, strlen(neu) + 1); + strcpy(*s, neu); + } + return *s; +} unsigned int hashstring(const char *s) { diff --git a/src/util/strings.h b/src/util/strings.h index 4157fc853..7178cf179 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -22,11 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - extern unsigned int hashstring(const char *s); - extern const char *escape_string(const char *str, char *buffer, - size_t len); - extern unsigned int jenkins_hash(unsigned int a); - extern unsigned int wang_hash(unsigned int a); + char *set_string(char **s, const char *neu); + unsigned int hashstring(const char *s); + const char *escape_string(const char *str, char *buffer, size_t len); + unsigned int jenkins_hash(unsigned int a); + unsigned int wang_hash(unsigned int a); /* benchmark for units: * JENKINS_HASH: 5.25 misses/hit (with good cache behavior)