NMR-Zaehlung auch fuer LUA

This commit is contained in:
Enno Rehling 2006-08-20 13:32:03 +00:00
parent 7590fa50ef
commit c3e4e828a8
7 changed files with 73 additions and 38 deletions

View File

@ -2646,10 +2646,8 @@ report_summary(summary * s, summary * o, boolean full)
FILE * F = NULL; FILE * F = NULL;
int i, newplayers = 0; int i, newplayers = 0;
faction * f; faction * f;
int * nmrs = malloc(sizeof(int)*(NMRTimeout()+1));
{
char zText[MAX_PATH]; char zText[MAX_PATH];
if (full) { if (full) {
sprintf(zText, "%s/parteien.full", basepath()); sprintf(zText, "%s/parteien.full", basepath());
} else { } else {
@ -2657,7 +2655,6 @@ report_summary(summary * s, summary * o, boolean full)
} }
F = cfopen(zText, "w"); F = cfopen(zText, "w");
if (!F) return; if (!F) return;
}
printf("Schreibe Zusammenfassung (parteien)...\n"); printf("Schreibe Zusammenfassung (parteien)...\n");
fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale)); fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale));
fprintf(F, "Auswertung Nr: %d\n\n", turn); fprintf(F, "Auswertung Nr: %d\n\n", turn);
@ -2751,23 +2748,7 @@ report_summary(summary * s, summary * o, boolean full)
fprintf(F, "\n\n"); fprintf(F, "\n\n");
for (i = 0; i <= NMRTimeout(); ++i) { newplayers = update_nmrs();
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]++;
}
}
for (i = 0; i <= NMRTimeout(); ++i) { for (i = 0; i <= NMRTimeout(); ++i) {
if (i == NMRTimeout()) { if (i == NMRTimeout()) {
@ -2827,6 +2808,7 @@ report_summary(summary * s, summary * o, boolean full)
writemonument(); writemonument();
} }
free(nmrs); free(nmrs);
nmrs = NULL;
} }
/******* end summary ******/ /******* end summary ******/

View File

@ -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 #define ORDERS_IN_NR 1
static size_t static size_t
buforder(char * bufp, size_t size, const order * ord, int mode) buforder(char * bufp, size_t size, const order * ord, int mode)

View File

@ -105,6 +105,9 @@ extern const char * trailinto(const struct region * r, const struct locale * lan
extern void reports_init(void); extern void reports_init(void);
extern int update_nmrs(void);
extern int * nmrs;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -563,9 +563,9 @@ factionorders(void)
* incrementiert wird. */ * incrementiert wird. */
f->lastorders = global.data_turn+1; f->lastorders = global.data_turn+1;
} else } else {
log_warning(("Befehle für die ungültige Partei %s\n", fid)); log_warning(("Befehle für die ungültige Partei %s\n", fid));
}
return f; return f;
} }

View File

@ -51,6 +51,16 @@ get_turn(void)
return turn; return turn;
} }
static int
get_nmrs(int n)
{
if (n<=NMRTimeout()) {
if (nmrs==NULL) update_nmrs();
return nmrs[n];
}
return 0;
}
static int static int
find_plane_id(const char * name) find_plane_id(const char * name)
{ {
@ -229,6 +239,7 @@ bind_eressea(lua_State * L)
def("dice_roll", &dice_rand), def("dice_roll", &dice_rand),
def("equipment_setitem", &lua_addequipment), def("equipment_setitem", &lua_addequipment),
def("get_turn", &get_turn), def("get_turn", &get_turn),
def("get_nmrs", &get_nmrs),
def("remove_empty_units", &remove_empty_units), def("remove_empty_units", &remove_empty_units),
def("update_subscriptions", &update_subscriptions), def("update_subscriptions", &update_subscriptions),

View File

@ -62,6 +62,12 @@ function process(orders)
print("could not read " .. orders) print("could not read " .. orders)
return -1 return -1
end 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() run_scripts()
-- create new monsters: -- create new monsters:

View File

@ -1,5 +1,9 @@
local function kill_multis() 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 for k, v in multis do
local f = get_faction(atoi36(k)) local f = get_faction(atoi36(k))
if f~=nil then if f~=nil then