diff --git a/conf/e2/rules.xml b/conf/e2/rules.xml index 7bde2205f..45b9030d3 100644 --- a/conf/e2/rules.xml +++ b/conf/e2/rules.xml @@ -20,6 +20,11 @@ + + + + + diff --git a/src/economy.c b/src/economy.c index 6fc1fea60..1cae19b1c 100644 --- a/src/economy.c +++ b/src/economy.c @@ -69,6 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include /* libs includes */ #include @@ -2653,14 +2654,10 @@ expandwork(region * r, request * work_begin, request * work_end, int maxwork) jobs = rpeasants(r); } earnings = jobs * p_wage; - if (r->attribs && rule_blessed_harvest() == HARVEST_TAXES) { + if (jobs > 0 && r->attribs && rule_blessed_harvest() == HARVEST_TAXES) { /* E3 rules */ - const curse_type *blessedharvest_ct = ct_find("blessedharvest"); - if (blessedharvest_ct) { - int happy = - (int)(jobs * curse_geteffect(get_curse(r->attribs, blessedharvest_ct))); - earnings += happy; - } + int happy = harvest_effect(r); + earnings += happy * jobs; } rsetmoney(r, money + earnings); } diff --git a/src/gmtool.c b/src/gmtool.c index 674e139f7..6db857ad9 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -1,4 +1,4 @@ -/* +/* * +-------------------+ Christian Schlittchen * | | Enno Rehling * | Eressea PBEM host | Katja Zedel @@ -81,7 +81,7 @@ int gm_codepage = -1; static void unicode_remove_diacritics(const char *rp, char *wp) { while (*rp) { - if (gm_codepage >=0 && *rp & 0x80) { + if (gm_codepage >= 0 && *rp & 0x80) { size_t sz = 0; unsigned char ch; switch (gm_codepage) { @@ -115,7 +115,7 @@ int umvwprintw(WINDOW *win, int y, int x, const char *format, ...) { va_start(args, format); memset(buffer, 0, sizeof(buffer)); - vsnprintf(buffer, sizeof(buffer)-1, format, args); + vsnprintf(buffer, sizeof(buffer) - 1, format, args); va_end(args); simplify(buffer, buffer); @@ -344,7 +344,7 @@ map_region *cursor_region(const view * v, const coordinate * c) static void draw_cursor(WINDOW * win, selection * s, const view * v, const coordinate * c, -int show) + int show) { int lines = getmaxy(win) / THEIGHT; int xp, yp, nx, ny; @@ -814,7 +814,7 @@ static void select_regions(state * st, int selectmode) st->wnd_map->update |= 3; } -void loaddata(state *st) { +static void loaddata(state *st) { char datafile[MAX_PATH]; askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); @@ -824,7 +824,7 @@ void loaddata(state *st) { } } -void savedata(state *st) { +static void savedata(state *st) { char datafile[MAX_PATH]; askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); @@ -835,6 +835,20 @@ void savedata(state *st) { } } +static void seed_player(state *st, const newfaction *player) { + if (player) { + region *r; + int nx = st->cursor.x; + int ny = st->cursor.y; + + pnormalize(&nx, &ny, st->cursor.pl); + r = findregion(nx, ny); + if (r) { + addplayer(r, addfaction(player->email, player->password, player->race, + player->lang, player->subscription)); + } + } +} static void handlekey(state * st, int c) { window *wnd; @@ -897,10 +911,6 @@ static void handlekey(state * st, int c) loaddata(st); break; case 'B': - if (!new_players) { - join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer)); - new_players = read_newfactions(sbuffer); - } cnormalize(&st->cursor, &nx, &ny); minpop = config_get_int("editor.population.min", 8); maxpop = config_get_int("editor.population.max", minpop); @@ -1111,13 +1121,15 @@ static void handlekey(state * st, int c) else tag_region(st->selected, nx, ny); break; - case 'A': - if (!new_players) { - join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer)); - new_players = read_newfactions(sbuffer); + case 's': /* seed */ + if (new_players) { + newfaction * next = new_players->next; + seed_player(st, new_players); + free(new_players->email); + free(new_players->password); + free(new_players); + new_players = next; } - seed_players(&new_players, false); - st->wnd_map->update |= 1; break; case '/': statusline(st->wnd_status->handle, "find-"); @@ -1289,13 +1301,15 @@ void run_mapper(void) int split = 20; state *st; point tl; -/* FIXME: dsiable logging - int old_flags = log_flags; - log_flags &= ~(LOG_CPERROR | LOG_CPWARNING); -*/ + char sbuffer[512]; + + if (!new_players) { + join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer)); + new_players = read_newfactions(sbuffer); + } + init_curses(); curs_set(1); - set_readline(curses_readline); assert(stdscr); getbegyx(stdscr, x, y); @@ -1384,15 +1398,15 @@ void run_mapper(void) set_readline(NULL); curs_set(1); endwin(); -/* FIXME: reset logging - log_flags = old_flags; -*/ + /* FIXME: reset logging + log_flags = old_flags; + */ state_close(st); } int curses_readline(struct lua_State *L, char *buffer, size_t size, -const char *prompt) + const char *prompt) { UNUSED_ARG(L); askstring(hstatus, prompt, buffer, size); diff --git a/src/gmtool.h b/src/gmtool.h index 3a682f453..04f062f4b 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -22,7 +22,6 @@ extern "C" { struct terrain_type; struct newfaction; - int gmmain(int argc, char *argv[]); int curses_readline(struct lua_State *L, char *buffer, size_t size, const char *prompt); diff --git a/src/kernel/building.c b/src/kernel/building.c index 14e4a3e07..520807933 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -55,6 +55,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include /* attributes includes */ +#include #include typedef struct building_typelist { @@ -710,7 +711,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) } if (r->attribs && rule_blessed_harvest() == HARVEST_WORK) { /* E1 rules */ - wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest"))); + wage += harvest_effect(r); } } diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 4a3e1c045..336316159 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -596,28 +596,23 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct, if (ct->mergeflags & M_DURATION) { c->duration = MAX(c->duration, duration); } - if (ct->mergeflags & M_SUMDURATION) { + else if (ct->mergeflags & M_SUMDURATION) { c->duration += duration; } - if (ct->mergeflags & M_SUMEFFECT) { - c->effect += effect; - } if (ct->mergeflags & M_MAXEFFECT) { c->effect = MAX(c->effect, effect); } + else if (ct->mergeflags & M_SUMEFFECT) { + c->effect += effect; + } if (ct->mergeflags & M_VIGOUR) { c->vigour = MAX(vigour, c->vigour); } - if (ct->mergeflags & M_VIGOUR_ADD) { + else if (ct->mergeflags & M_VIGOUR_ADD) { c->vigour = vigour + c->vigour; } - if (ct->mergeflags & M_MEN) { - switch (ct->typ) { - case CURSETYP_UNIT: - { - c->data.i += men; - } - } + if (ct->mergeflags & M_MEN && ct->typ == CURSETYP_UNIT) { + c->data.i += men; } set_curseingmagician(magician, *ap, ct); } diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 80faba3c1..7901cd96f 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -223,6 +224,21 @@ static void test_valid_race(CuTest *tc) { test_cleanup(); } +static void test_set_email(CuTest *tc) { + char * email = NULL; + test_setup(); + CuAssertIntEquals(tc, 0, set_email(&email, "enno@eressea.de")); + CuAssertStrEquals(tc, "enno@eressea.de", email); + CuAssertIntEquals(tc, 0, set_email(&email, "bugs@eressea.de")); + CuAssertStrEquals(tc, "bugs@eressea.de", email); + CuAssertIntEquals(tc, -1, set_email(&email, "bad@@eressea.de")); + CuAssertIntEquals(tc, -1, set_email(&email, "eressea.de")); + CuAssertIntEquals(tc, -1, set_email(&email, "eressea@")); + CuAssertStrEquals(tc, "bugs@eressea.de", email); + free(email); + test_cleanup(); +} + CuSuite *get_faction_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -237,5 +253,6 @@ CuSuite *get_faction_suite(void) SUITE_ADD_TEST(suite, test_set_origin_bug); SUITE_ADD_TEST(suite, test_check_passwd); SUITE_ADD_TEST(suite, test_valid_race); + SUITE_ADD_TEST(suite, test_set_email); return suite; } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index ffab4ca46..6e2599763 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -161,6 +161,8 @@ newfaction *read_newfactions(const char *filename) break; if (email[0] == '\0') break; + if (email[0] == '#') + break; if (password[0] == '\0') { size_t sz; sz = strlcpy(password, itoa36(rng_int()), sizeof(password)); diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index b10f3046f..dc9256538 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -24,6 +24,7 @@ #include /* util includes */ +#include #include #include #include @@ -33,10 +34,6 @@ #include #include -/* --------------------------------------------------------------------- */ -/* CurseInfo mit Spezialabfragen - */ - /* * godcursezone */ @@ -206,6 +203,22 @@ static struct curse_type ct_blessedharvest = { cinfo_simple }; +int harvest_effect(const struct region *r) { + if (r->attribs) { + curse *c = get_curse(r->attribs, &ct_blessedharvest); + if (c) { + int happy = curse_geteffect_int(c); + if (happy != 1) { + /* https://bugs.eressea.de/view.php?id=2353 detect and fix bad harvest */ + log_error("blessedharvest curse %d has effect=%d, duration=%d", c->no, happy, c->duration); + c->effect = 1.0; + } + return happy; + } + } + return 0; +} + static struct curse_type ct_drought = { "drought", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), diff --git a/src/spells/regioncurse.h b/src/spells/regioncurse.h index c261ade41..a1ee182c1 100644 --- a/src/spells/regioncurse.h +++ b/src/spells/regioncurse.h @@ -17,10 +17,10 @@ extern "C" { #endif - struct curse; - struct locale; + struct region; - extern void register_regioncurse(void); + int harvest_effect(const struct region *r); + void register_regioncurse(void); #ifdef __cplusplus } diff --git a/src/study.c b/src/study.c index ddded23cc..85ff0b436 100644 --- a/src/study.c +++ b/src/study.c @@ -483,7 +483,7 @@ int teach_cmd(unit * teacher, struct order *ord) free_order(new_order); /* parse_order & set_order have each increased the refcount */ } if (academy && sk_academy!=NOSKILL) { - assert(academy % STUDYDAYS == 0); + /* assert(academy % STUDYDAYS == 0); bug 2355: why? */ academy_teaching_bonus(teacher, sk_academy, academy); } return 0; diff --git a/src/util/goodies.c b/src/util/goodies.c index c478bcf83..0794240d5 100644 --- a/src/util/goodies.c +++ b/src/util/goodies.c @@ -82,12 +82,18 @@ static int spc_email_isvalid(const char *address) if (strchr(rfc822_specials, *c)) return 0; } + if (*c!='@') { + /* no @ symbol */ + return -1; + } + domain = ++c; + if (!*c) { + return -1; + } if (c == address || *(c - 1) == '.') return 0; /* next we validate the domain portion (name@domain) */ - if (!*(domain = ++c)) - return 0; do { if (*c == '.') { if (c == domain || *(c - 1) == '.')