Merge pull request #715 from ennorehling/develop

BUG 2353, 2354, 2355
This commit is contained in:
Enno Rehling 2017-08-06 21:32:25 +02:00 committed by GitHub
commit 292117f2b1
12 changed files with 105 additions and 56 deletions

View File

@ -20,6 +20,11 @@
<xi:include href="config://game/spells.xml"/>
<xi:include href="config://default/adamantium.xml"/>
<equipment>
<set name="first_unit">
<item name="money" amount="2500"/>
<item name="log" amount="10"/>
<item name="stone" amount="4"/>
</set>
<set name="autoseed_unit">
<item name="log" amount="50"/>
<item name="stone" amount="50"/>

View File

@ -69,6 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/reduceproduction.h>
#include <attributes/racename.h>
#include <spells/regioncurse.h>
/* libs includes */
#include <math.h>
@ -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);
}

View File

@ -1,4 +1,4 @@
/*
/*
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
* | | Enno Rehling <enno@eressea.de>
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -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);

View File

@ -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);

View File

@ -55,6 +55,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <limits.h>
/* attributes includes */
#include <spells/regioncurse.h>
#include <attributes/reduceproduction.h>
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);
}
}

View File

@ -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);
}

View File

@ -8,6 +8,7 @@
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/config.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/password.h>
@ -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;
}

View File

@ -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));

View File

@ -24,6 +24,7 @@
#include <kernel/unit.h>
/* util includes */
#include <util/log.h>
#include <util/nrmessage.h>
#include <util/message.h>
#include <util/functions.h>
@ -33,10 +34,6 @@
#include <stdlib.h>
#include <assert.h>
/* --------------------------------------------------------------------- */
/* 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),

View File

@ -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
}

View File

@ -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;

View File

@ -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) == '.')