From c3e4e828a889dd9dc44de1352c7667376c082bbc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 20 Aug 2006 13:32:03 +0000 Subject: [PATCH] NMR-Zaehlung auch fuer LUA --- src/common/gamecode/report.c | 38 +++++++++------------------------- src/common/kernel/reports.c | 29 ++++++++++++++++++++++++++ src/common/kernel/reports.h | 5 ++++- src/common/kernel/save.c | 16 +++++++------- src/eressea/lua/eressea.cpp | 11 ++++++++++ src/scripts/eressea.lua | 6 ++++++ src/scripts/eressea/multis.lua | 6 +++++- 7 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 2449cda4e..12a5ddadf 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -2646,18 +2646,15 @@ report_summary(summary * s, summary * o, boolean full) FILE * F = NULL; int i, newplayers = 0; faction * f; - int * nmrs = malloc(sizeof(int)*(NMRTimeout()+1)); + char zText[MAX_PATH]; - { - char zText[MAX_PATH]; - if (full) { - sprintf(zText, "%s/parteien.full", basepath()); - } else { - sprintf(zText, "%s/parteien", basepath()); - } - F = cfopen(zText, "w"); - if (!F) return; + if (full) { + sprintf(zText, "%s/parteien.full", basepath()); + } else { + sprintf(zText, "%s/parteien", basepath()); } + F = cfopen(zText, "w"); + if (!F) return; printf("Schreibe Zusammenfassung (parteien)...\n"); fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %d\n\n", turn); @@ -2751,24 +2748,8 @@ report_summary(summary * s, summary * o, boolean full) fprintf(F, "\n\n"); - for (i = 0; i <= NMRTimeout(); ++i) { - nmrs[i] = 0; - } - - for (f = factions; f; f = f->next) { - if (fval(f, FFL_ISNEW)) { - ++newplayers; - } else if (f->no != MONSTER_FACTION) { - int nmr = turn-f->lastorders; - if (nmr<0 || nmr>NMRTimeout()) { - log_error(("faction %s has %d NMRS\n", factionid(f), nmr)); - nmr = max(0, nmr); - nmr = min(nmr, NMRTimeout()); - } - nmrs[nmr]++; - } - } - + newplayers = update_nmrs(); + for (i = 0; i <= NMRTimeout(); ++i) { if (i == NMRTimeout()) { fprintf(F, "+ NMRs:\t\t %d\n", nmrs[i]); @@ -2827,6 +2808,7 @@ report_summary(summary * s, summary * o, boolean full) writemonument(); } free(nmrs); + nmrs = NULL; } /******* end summary ******/ diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 5fec87011..8b54e8f38 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -164,6 +164,35 @@ report_item(const unit * owner, const item * i, const faction * viewer, const ch } +int * nmrs = NULL; + +int +update_nmrs(void) +{ + int i, newplayers =0; + faction *f; + + if (nmrs==NULL) nmrs = malloc(sizeof(int)*(NMRTimeout()+1)); + for (i = 0; i <= NMRTimeout(); ++i) { + nmrs[i] = 0; + } + + for (f = factions; f; f = f->next) { + if (fval(f, FFL_ISNEW)) { + ++newplayers; + } else if (f->no != MONSTER_FACTION) { + int nmr = turn-f->lastorders; + if (nmr<0 || nmr>NMRTimeout()) { + log_error(("faction %s has %d NMRS\n", factionid(f), nmr)); + nmr = max(0, nmr); + nmr = min(nmr, NMRTimeout()); + } + ++nmrs[nmr]; + } + } + return newplayers; +} + #define ORDERS_IN_NR 1 static size_t buforder(char * bufp, size_t size, const order * ord, int mode) diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index a3de80004..5787358c1 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -103,7 +103,10 @@ extern int bufunit(const struct faction * f, const struct unit * u, int indent, extern const char * reportpath(void); extern const char * trailinto(const struct region * r, const struct locale * lang); -extern void reports_init(void); + extern void reports_init(void); + + extern int update_nmrs(void); + extern int * nmrs; #ifdef __cplusplus } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index b050c0cfb..a2d2e5eb5 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -559,14 +559,14 @@ factionorders(void) /* Die Partei hat sich zumindest gemeldet, so daß sie noch * nicht als untätig gilt */ - /* TODO: +1 ist ein Workaround, weil turn erst in process_orders - * incrementiert wird. */ - f->lastorders = global.data_turn+1; - - } else - log_warning(("Befehle für die ungültige Partei %s\n", fid)); - - return f; + /* TODO: +1 ist ein Workaround, weil turn erst in process_orders + * incrementiert wird. */ + f->lastorders = global.data_turn+1; + + } else { + log_warning(("Befehle für die ungültige Partei %s\n", fid)); + } + return f; } double diff --git a/src/eressea/lua/eressea.cpp b/src/eressea/lua/eressea.cpp index 16123327b..0abf82528 100644 --- a/src/eressea/lua/eressea.cpp +++ b/src/eressea/lua/eressea.cpp @@ -51,6 +51,16 @@ get_turn(void) return turn; } +static int +get_nmrs(int n) +{ + if (n<=NMRTimeout()) { + if (nmrs==NULL) update_nmrs(); + return nmrs[n]; + } + return 0; +} + static int find_plane_id(const char * name) { @@ -229,6 +239,7 @@ bind_eressea(lua_State * L) def("dice_roll", &dice_rand), def("equipment_setitem", &lua_addequipment), def("get_turn", &get_turn), + def("get_nmrs", &get_nmrs), def("remove_empty_units", &remove_empty_units), def("update_subscriptions", &update_subscriptions), diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index d9404cdda..590673a53 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -62,6 +62,12 @@ function process(orders) print("could not read " .. orders) return -1 end + nmrs = get_nmrs(1) + if nmrs >= 60 then + print("Shit. More than 60 factions with 1 NMR (" .. nmrs .. ")") + return -1 + fi + print (nmrs .. " Factions with 1 NMR") run_scripts() -- create new monsters: diff --git a/src/scripts/eressea/multis.lua b/src/scripts/eressea/multis.lua index 882cfd827..9b25bff46 100644 --- a/src/scripts/eressea/multis.lua +++ b/src/scripts/eressea/multis.lua @@ -1,5 +1,9 @@ local function kill_multis() - local multis = { ["ms04"]="Wird wegen Parteiuebernahme geloescht" } + local multis = { +-- ["Luna"]="Wird wegen Missbrauch von Sonnensegeln geloescht", +-- ["amam"]="Wird wegen Missbrauch von Sonnensegeln geloescht", +-- ["jr81"]="Wird wegen Missbrauch von Sonnensegeln geloescht" + } for k, v in multis do local f = get_faction(atoi36(k)) if f~=nil then