diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index eb778653a..6bde6ee0a 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -419,43 +419,35 @@ live(region * r) * - movement because of low loyalty relating to present parties. */ -/* Arbeitsversion */ +#define MAX_EMIGRATION(p) ((p)/MAXDIRECTIONS) +#define MAX_IMMIGRATION(p) ((p)*2/3) + static void calculate_emigration(region *r) { - direction_t i; - int overpopulation = rpeasants(r) - maxworkingpeasants(r); - int weight[MAXDIRECTIONS], weightall; + int i; + int maxp = maxworkingpeasants(r); + int rp = rpeasants(r); + int max_immigrants = MAX_IMMIGRATION(maxp-rp); - /* Bauern wandern nur bei Überbevölkerung, sonst gar nicht */ - if(overpopulation <= 0) return; - - weightall = 0; - - for (i = 0; i != MAXDIRECTIONS; i++) { - region *rc = rconnect(r,i); - int w; - - if (rc == NULL || !fval(rc->terrain, LAND_REGION)) { - w = 0; - } else { - w = rpeasants(rc) - maxworkingpeasants(rc); - w = max(0,w); - if (rterrain(rc) == T_VOLCANO || rterrain(rc) == T_VOLCANO_SMOKING) { - w = w/10; - } - } - weight[i] = w; - weightall += w; + if (rterrain(r) == T_VOLCANO || rterrain(r) == T_VOLCANO_SMOKING) { + max_immigrants = max_immigrants/10; } - if (weightall !=0 ) for (i = 0; i != MAXDIRECTIONS; i++) { - region *rc = rconnect(r, i); - if (rc != NULL) { - int wandering_peasants = (overpopulation * weight[i])/weightall; - if (wandering_peasants > 0) { - r->land->newpeasants -= wandering_peasants; - rc->land->newpeasants += wandering_peasants; + for (i = 0; max_immigrants>0 && i != MAXDIRECTIONS; i++) { + int dir = (turn+i) % MAXDIRECTIONS; + region *rc = rconnect(r, (direction_t)dir); + + if (rc != NULL && fval(rc->terrain, LAND_REGION)) { + int rp2 = rpeasants(rc); + int maxp2 = maxworkingpeasants(rc); + int max_emigration = MAX_EMIGRATION(rp2-maxp2); + + if (max_emigration>0) { + max_emigration = min(max_emigration, max_immigrants); + r->land->newpeasants += max_emigration; + rc->land->newpeasants -= max_emigration; + max_immigrants -= max_emigration; } } } @@ -817,26 +809,28 @@ demographics(void) if (!fval(r->terrain, SEA_REGION)) { /* die Nachfrage nach Produkten steigt. */ struct demand * dmd; - if (r->land) for (dmd=r->land->demands;dmd;dmd=dmd->next) { - if (dmd->value>0 && dmd->value < MAXDEMAND) { - float rise = DMRISE; - if (buildingtype_exists(r, bt_find("harbour"))) rise = DMRISEHAFEN; - if (rng_double()value; + if (r->land) { + for (dmd=r->land->demands;dmd;dmd=dmd->next) { + if (dmd->value>0 && dmd->value < MAXDEMAND) { + float rise = DMRISE; + if (buildingtype_exists(r, bt_find("harbour"))) rise = DMRISEHAFEN; + if (rng_double()value; + } + } + /* Seuchen erst nachdem die Bauern sich vermehrt haben + * und gewandert sind */ + + calculate_emigration(r); + peasants(r); + plagues(r, false); + horses(r); + if (current_season != SEASON_WINTER) { + trees(r, current_season, last_weeks_season); } } - /* Seuchen erst nachdem die Bauern sich vermehrt haben - * und gewandert sind */ - calculate_emigration(r); - peasants(r); - plagues(r, false); - - horses(r); - if(current_season != SEASON_WINTER) { - trees(r, current_season, last_weeks_season); - } update_resources(r); - migrate(r); + if (r->land) migrate(r); } } while (free_migrants) { @@ -850,7 +844,7 @@ demographics(void) puts(" - Einwanderung..."); for (r = regions; r; r = r->next) { - if (fval(r->terrain, LAND_REGION)) { + if (r->land && r->land->newpeasants) { int rp = rpeasants(r) + r->land->newpeasants; rsetpeasants(r, max(0, rp)); } diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 2c9d675db..5070bf9b3 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -92,7 +92,7 @@ typedef enum combatmagic { } combatmagic_t; /* external variables */ -boolean nobattledebug = false; +boolean battledebug = true; /* globals */ static int obs_count = 0; @@ -224,7 +224,7 @@ armedmen(const unit * u) } static void -battledebug(const char *s) +battle_log(const char *s) { #if SHOW_DEBUG puts(s); @@ -1053,9 +1053,10 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) kritchance = min(0.9, kritchance); while (chance(kritchance)) { - sprintf(debugbuf, - "%s/%d landet einen kritischen Treffer", unitid(au), at.index); - battledebug(debugbuf); + if (battledebug) { + sprintf(debugbuf, "%s/%d landet einen kritischen Treffer", unitid(au), at.index); + battle_log(debugbuf); + } da += dice_rand(damage); } @@ -1134,8 +1135,10 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) } } - sprintf(debugbuf, "Verursacht %dTP, Rüstung %d: %d -> %d HP", - da, ar, df->person[dt.index].hp, df->person[dt.index].hp - rda); + if (battledebug) { + sprintf(debugbuf, "Verursacht %dTP, Rüstung %d: %d -> %d HP", + da, ar, df->person[dt.index].hp, df->person[dt.index].hp - rda); + } #ifdef SMALL_BATTLE_MESSAGES if (b->small) { @@ -1152,7 +1155,9 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) df->person[dt.index].hp -= rda; if (df->person[dt.index].hp > 0) { /* Hat überlebt */ - battledebug(debugbuf); + if (battledebug) { + battle_log(debugbuf); + } if (au->race == new_race[RC_DAEMON]) { #ifdef TODO_RUNESWORD if (select_weapon(dt, 0, -1) == WP_RUNESWORD) continue; @@ -1220,8 +1225,10 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) return false; } - strcat(debugbuf, ", tot"); - battledebug(debugbuf); + if (battledebug) { + strcat(debugbuf, ", tot"); + battle_log(debugbuf); + } #ifdef SMALL_BATTLE_MESSAGES if (b->small) { strcat(smallbuf, "."); @@ -1897,8 +1904,10 @@ hits(troop at, troop dt, weapon * awp) } #endif if (contest(skdiff, armor, shield)) { - strcat(debugbuf, " und trifft."); - battledebug(debugbuf); + if (battledebug) { + strcat(debugbuf, " und trifft."); + battle_log(debugbuf); + } #ifdef SMALL_BATTLE_MESSAGES if (b->small) { strcat(smallbuf, " und trifft."); @@ -1907,8 +1916,10 @@ hits(troop at, troop dt, weapon * awp) #endif return 1; } - strcat(debugbuf, "."); - battledebug(debugbuf); + if (battledebug) { + strcat(debugbuf, "."); + battle_log(debugbuf); + } #ifdef SMALL_BATTLE_MESSAGES if (b->small) { strcat(smallbuf, "."); @@ -2102,8 +2113,10 @@ attack(battle *b, troop ta, const att *a, int numattack) } if (reload && wp && wp->type->reload && !getreload(ta)) { int i = setreload(ta); - sprintf(buf, " Nachladen gesetzt: %d", i); - battledebug(buf); + if (battledebug) { + sprintf(buf, " Nachladen gesetzt: %d", i); + battle_log(buf); + } } } } @@ -2738,11 +2751,13 @@ aftermath(battle * b) free(trollsave); #endif - sprintf(buf, "The battle lasted %d turns, %s and %s.\n", - b->turn, - b->has_tactics_turn==true?"had a tactic turn":"had no tactic turn", - battle_was_relevant==true?"was relevant":"was not relevant."); - battledebug(buf); + if (battledebug) { + sprintf(buf, "The battle lasted %d turns, %s and %s.\n", + b->turn, + b->has_tactics_turn==true?"had a tactic turn":"had no tactic turn", + battle_was_relevant==true?"was relevant":"was not relevant."); + battle_log(buf); + } } static void @@ -2758,8 +2773,9 @@ battle_punit(unit * u, battle * b) spunit(&S, f, u, 4, see_battle); for (x = S; x; x = x->next) { fbattlerecord(b, f, x->s); - if (u->faction == f) - battledebug(x->s); + if (battledebug && u->faction == f) { + battle_log(x->s); + } } if (S) freestrlist(S); @@ -2926,14 +2942,14 @@ print_stats(battle * b) buf[77] = (char)0; for (k = buf; *k; ++k) *k = '-'; battlerecord(b, buf); - if (s->bf->faction) { + if (battledebug && s->bf->faction) { if (s->bf->faction->alliance) { slprintf(buf, sizeof(buf), "##### %s (%s/%d)", s->bf->faction->name, itoa36(s->bf->faction->no), s->bf->faction->alliance?s->bf->faction->alliance->id:0); } else { slprintf(buf, sizeof(buf), "##### %s (%s)", s->bf->faction->name, itoa36(s->bf->faction->no)); } - battledebug(buf); + battle_log(buf); } print_fighters(b, s); } @@ -3354,7 +3370,7 @@ make_battle(region * r) bfaction * bf; static int max_fac_no = 0; /* need this only once */ - if (!nobattledebug) { + if (battledebug) { char zText[MAX_PATH]; char zFilename[MAX_PATH]; sprintf(zText, "%s/battles", basepath()); @@ -3884,10 +3900,10 @@ init_battle(region * r, battle **bp) c1->side->bf->attacker = true; set_enemy(c1->side, c2->side, true); - if (!enemy(c1->side, c2->side)) { + if (battledebug && !enemy(c1->side, c2->side)) { sprintf(buf, "%s attackiert %s", sidename(c1->side, false), sidename(c2->side, false)); - battledebug(buf); + battle_log(buf); } fighting = true; } @@ -4081,10 +4097,10 @@ battle_flee(battle * b) #endif } } - if (runners > 0) { + if (battledebug && runners > 0) { char lbuf[256]; sprintf(lbuf, "Flucht: %d aus %s", runners, itoa36(fig->unit->no)); - battledebug(lbuf); + battle_log(lbuf); } } } @@ -4155,11 +4171,11 @@ do_battle(region * r) #endif for (;battle_report(b) && b->turn<=COMBAT_TURNS;++b->turn) { - char lbuf[256]; - - sprintf(lbuf, "*** Runde: %d", b->turn); - battledebug(lbuf); - + if (battledebug) { + char lbuf[256]; + sprintf(lbuf, "*** Runde: %d", b->turn); + battle_log(lbuf); + } battle_flee(b); battle_update(b); battle_attacks(b); diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index f3a4f29d6..b3b4d3bfa 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -231,9 +231,6 @@ extern void read_laen(struct region * r, int laen); /* Vermehrung trotz 90% Auslastung */ #define PEASANTFORCE 0.75 -#define PEASANTSWANDER_WEIGHT 5 -#define PEASANTSGREED_WEIGHT 5 - #define TREESIZE (MAXPEASANTS_PER_AREA-2) /* Eisen in Bergregionen bei Erschaffung */ diff --git a/src/eressea/main.c b/src/eressea/main.c index ac4f707ed..4a7a23e8f 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -115,7 +115,7 @@ extern boolean noreports; extern boolean nomer; extern boolean nobattle; extern boolean nomonsters; -extern boolean nobattledebug; +extern boolean battledebug; extern boolean dirtyload; extern int loadplane; @@ -420,7 +420,7 @@ read_args(int argc, char **argv) else if (strcmp(argv[i]+2, "lomem")==0) lomem = true; else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true; else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true; - else if (strcmp(argv[i]+2, "nodebug")==0) nobattledebug = true; + else if (strcmp(argv[i]+2, "nodebug")==0) battledebug = false; else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true; else if (strcmp(argv[i]+2, "help")==0) return usage(argv[0], NULL); diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 392bb7dba..de13be108 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -136,7 +136,7 @@ extern "C" { extern boolean nomer; extern boolean nobattle; extern boolean nomonsters; - extern boolean nobattledebug; + extern boolean battledebug; extern boolean dirtyload; extern int loadplane; @@ -451,7 +451,7 @@ read_args(int argc, char **argv, lua_State * luaState) else if (strcmp(argv[i]+2, "lomem")==0) lomem = true; else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true; else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true; - else if (strcmp(argv[i]+2, "nodebug")==0) nobattledebug = true; + else if (strcmp(argv[i]+2, "nodebug")==0) battledebug = false; else if (strcmp(argv[i]+2, "console")==0) luafile=NULL; else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true; else if (strcmp(argv[i]+2, "help")==0) @@ -584,6 +584,8 @@ load_inifile(const char * filename) lomem = iniparser_getint(d, "common:lomem", lomem)?1:0; quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1; + battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0; + str = iniparser_getstr(d, "eressea:run"); if (str) luafile = str; str = iniparser_getstr(d, "eressea:report");