diff --git a/src/mapper/map_partei.c b/src/mapper/map_partei.c index 5cdeaa69c..7a5f06cbd 100644 --- a/src/mapper/map_partei.c +++ b/src/mapper/map_partei.c @@ -231,54 +231,59 @@ read_newfactions(const char * filename) FILE * F = fopen(filename, "r"); if (F==NULL) return; for (;;) { - faction * f = factions; - char race[20], email[64], lang[8], password[16]; - newfaction *nf; - int bonus, subscription; - int alliance = 0; - - if (alliances!=NULL) { - /* email;race;locale;startbonus;subscription;alliance */ - if (fscanf(F, "%s %s %s %d %d %s %d", email, race, lang, &bonus, &subscription, password, &alliance)<=0) break; - } else { - /* email;race;locale;startbonus;subscription */ - if (fscanf(F, "%s %s %s %d %d %s", email, race, lang, &bonus, &subscription, password)<=0) break; - } - while (f) { - if (strcmp(f->email, email)==0 && f->subscription) { - break; - } - f = f->next; - } - if (f) continue; /* skip the ones we've already got */ - for (nf=newfactions;nf;nf=nf->next) { - if (strcmp(nf->email, email)==0) break; - } - if (nf) continue; - nf = calloc(sizeof(newfaction), 1); - if (set_email(&nf->email, email)!=0) { - log_error(("Invalid email address for subscription %s: %s\n", itoa36(subscription), email)); - } - nf->password = strdup(password); - nf->race = rc_find(race); - nf->subscription = subscription; - if (alliances!=NULL) { - struct alliance * al = findalliance(alliance); - if (al==NULL) { - char zText[64]; - sprintf(zText, "Allianz %d", alliance); - al = makealliance(alliance, zText); - } - nf->allies = al; - } else { - nf->allies = NULL; - } - if (nf->race==NULL) nf->race = findrace(race, default_locale); - nf->lang = find_locale(lang); - nf->bonus = bonus; - assert(nf->race && nf->email && nf->lang); - nf->next = newfactions; - newfactions = nf; + faction * f = factions; + char race[20], email[64], lang[8], password[16]; + newfaction *nf, **nfi; + int bonus, subscription; + int alliance = 0; + + if (alliances!=NULL) { + /* email;race;locale;startbonus;subscription;alliance */ + if (fscanf(F, "%s %s %s %d %d %s %d", email, race, lang, &bonus, &subscription, password, &alliance)<=0) break; + } else { + /* email;race;locale;startbonus;subscription */ + if (fscanf(F, "%s %s %s %d %d %s", email, race, lang, &bonus, &subscription, password)<=0) break; + } + while (f) { + if (strcmp(f->email, email)==0 && f->subscription) { + break; + } + f = f->next; + } + if (f) continue; /* skip the ones we've already got */ + for (nf=newfactions;nf;nf=nf->next) { + if (strcmp(nf->email, email)==0) break; + } + if (nf) continue; + nf = calloc(sizeof(newfaction), 1); + if (set_email(&nf->email, email)!=0) { + log_error(("Invalid email address for subscription %s: %s\n", itoa36(subscription), email)); + } + nf->password = strdup(password); + nf->race = rc_find(race); + nf->subscription = subscription; + if (alliances!=NULL) { + struct alliance * al = findalliance(alliance); + if (al==NULL) { + char zText[64]; + sprintf(zText, "Allianz %d", alliance); + al = makealliance(alliance, zText); + } + nf->allies = al; + } else { + nf->allies = NULL; + } + if (nf->race==NULL) nf->race = findrace(race, default_locale); + nf->lang = find_locale(lang); + nf->bonus = bonus; + assert(nf->race && nf->email && nf->lang); + nfi = &newfactions; + while (*nfi) { + if ((*nfi)->race==nf->race) break; + nfi=&(*nfi)->next; + } + nf->next = *nfi; + *nfi = nf; } fclose(F); } diff --git a/src/res/eressea/items-hse05.xml b/src/res/eressea/items-hse.xml similarity index 100% rename from src/res/eressea/items-hse05.xml rename to src/res/eressea/items-hse.xml diff --git a/src/res/hse4.xml b/src/res/hse4.xml new file mode 100644 index 000000000..257cfe9d0 --- /dev/null +++ b/src/res/hse4.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + Game specific + + + + + + + + + + + + + + + + + + + + + + + + hse-server@eressea.de + hse-server@eressea.de + + + ERESSEA BEFEHLE + ERESSEA ORDERS + + + diff --git a/src/scripts/hse05-buildings.lua b/src/scripts/hse-buildings.lua similarity index 100% rename from src/scripts/hse05-buildings.lua rename to src/scripts/hse-buildings.lua diff --git a/src/scripts/hse05-grails.lua b/src/scripts/hse-grails.lua similarity index 100% rename from src/scripts/hse05-grails.lua rename to src/scripts/hse-grails.lua diff --git a/src/scripts/hse05-portals.lua b/src/scripts/hse-portals.lua similarity index 100% rename from src/scripts/hse05-portals.lua rename to src/scripts/hse-portals.lua diff --git a/src/scripts/hse05-spoils.lua b/src/scripts/hse-spoils.lua similarity index 100% rename from src/scripts/hse05-spoils.lua rename to src/scripts/hse-spoils.lua diff --git a/src/scripts/hse05-stats.lua b/src/scripts/hse-stats.lua similarity index 66% rename from src/scripts/hse05-stats.lua rename to src/scripts/hse-stats.lua index 32a012628..edff5149e 100644 --- a/src/scripts/hse05-stats.lua +++ b/src/scripts/hse-stats.lua @@ -1,6 +1,6 @@ -dofile(scriptpath .. "/hse05-grails.lua") -dofile(scriptpath .. "/hse05-spoils.lua") -dofile(scriptpath .. "/hse05-buildings.lua") +dofile(scriptpath .. "/hse-grails.lua") +dofile(scriptpath .. "/hse-spoils.lua") +dofile(scriptpath .. "/hse-buildings.lua") function write_stats(filename) local file = io.open(reportpath .. "/" .. filename, "w") diff --git a/src/scripts/hse05-run.lua b/src/scripts/hse3-run.lua similarity index 96% rename from src/scripts/hse05-run.lua rename to src/scripts/hse3-run.lua index c2344fa54..b27a4ce49 100644 --- a/src/scripts/hse05-run.lua +++ b/src/scripts/hse3-run.lua @@ -1,7 +1,7 @@ function run_scripts() scripts = { - "hse05-portals.lua", - "hse05-stats.lua" + "hse-portals.lua", + "hse-stats.lua" } for index in scripts do local script = scriptpath .. "/" .. scripts[index] diff --git a/src/scripts/hse4-run.lua b/src/scripts/hse4-run.lua new file mode 100644 index 000000000..b27a4ce49 --- /dev/null +++ b/src/scripts/hse4-run.lua @@ -0,0 +1,74 @@ +function run_scripts() + scripts = { + "hse-portals.lua", + "hse-stats.lua" + } + for index in scripts do + local script = scriptpath .. "/" .. scripts[index] + print("- loading " .. script) + if pcall(dofile, script)==0 then + print("Could not load " .. script) + end + end +end + +function write_emails() + local locales = { "de", "en" } + local files = {} + local key + for key in locales do + local locale = locales[key] + files[locale] = io.open(basepath .. "/emails." .. locale, "w") + end + + local faction + for faction in factions() do + -- print(faction.id .. " - " .. faction.locale) + files[faction.locale]:write(faction.email .. "\n") + end + + for key in files do + files[key]:close() + end +end + +function process(orders) + file = "" .. get_turn() + if read_game(file)~=0 then + print("could not read game") + return -1 + end + + -- run the turn: + read_orders(orders) + run_scripts() + + plan_monsters() + process_orders() + + write_passwords() + write_reports() + + write_emails() + + file = "" .. get_turn() + if write_game(file)~=0 then + print("could not write game") + return -1 + end + + write_stats("grails.txt") +end + + +-- +-- main body of script +-- + +-- orderfile: contains the name of the orders. +if orderfile==nil then + print "you must specify an orderfile" +else + process(orderfile) +end +