- trying another peasant migration algorithm

also:
- battle log optional (debug = 0 in the .ini file)
This commit is contained in:
Enno Rehling 2007-05-27 21:20:06 +00:00
parent 1ca7075c09
commit 27110e7e26
5 changed files with 99 additions and 90 deletions

View file

@ -419,43 +419,35 @@ live(region * r)
* - movement because of low loyalty relating to present parties. * - 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 static void
calculate_emigration(region *r) calculate_emigration(region *r)
{ {
direction_t i; int i;
int overpopulation = rpeasants(r) - maxworkingpeasants(r); int maxp = maxworkingpeasants(r);
int weight[MAXDIRECTIONS], weightall; int rp = rpeasants(r);
int max_immigrants = MAX_IMMIGRATION(maxp-rp);
/* Bauern wandern nur bei Überbevölkerung, sonst gar nicht */ if (rterrain(r) == T_VOLCANO || rterrain(r) == T_VOLCANO_SMOKING) {
if(overpopulation <= 0) return; max_immigrants = max_immigrants/10;
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 (weightall !=0 ) for (i = 0; i != MAXDIRECTIONS; i++) { for (i = 0; max_immigrants>0 && i != MAXDIRECTIONS; i++) {
region *rc = rconnect(r, i); int dir = (turn+i) % MAXDIRECTIONS;
if (rc != NULL) { region *rc = rconnect(r, (direction_t)dir);
int wandering_peasants = (overpopulation * weight[i])/weightall;
if (wandering_peasants > 0) { if (rc != NULL && fval(rc->terrain, LAND_REGION)) {
r->land->newpeasants -= wandering_peasants; int rp2 = rpeasants(rc);
rc->land->newpeasants += wandering_peasants; 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)) { if (!fval(r->terrain, SEA_REGION)) {
/* die Nachfrage nach Produkten steigt. */ /* die Nachfrage nach Produkten steigt. */
struct demand * dmd; struct demand * dmd;
if (r->land) for (dmd=r->land->demands;dmd;dmd=dmd->next) { if (r->land) {
if (dmd->value>0 && dmd->value < MAXDEMAND) { for (dmd=r->land->demands;dmd;dmd=dmd->next) {
float rise = DMRISE; if (dmd->value>0 && dmd->value < MAXDEMAND) {
if (buildingtype_exists(r, bt_find("harbour"))) rise = DMRISEHAFEN; float rise = DMRISE;
if (rng_double()<rise) ++dmd->value; if (buildingtype_exists(r, bt_find("harbour"))) rise = DMRISEHAFEN;
if (rng_double()<rise) ++dmd->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); update_resources(r);
migrate(r); if (r->land) migrate(r);
} }
} }
while (free_migrants) { while (free_migrants) {
@ -850,7 +844,7 @@ demographics(void)
puts(" - Einwanderung..."); puts(" - Einwanderung...");
for (r = regions; r; r = r->next) { 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; int rp = rpeasants(r) + r->land->newpeasants;
rsetpeasants(r, max(0, rp)); rsetpeasants(r, max(0, rp));
} }

View file

@ -92,7 +92,7 @@ typedef enum combatmagic {
} combatmagic_t; } combatmagic_t;
/* external variables */ /* external variables */
boolean nobattledebug = false; boolean battledebug = true;
/* globals */ /* globals */
static int obs_count = 0; static int obs_count = 0;
@ -224,7 +224,7 @@ armedmen(const unit * u)
} }
static void static void
battledebug(const char *s) battle_log(const char *s)
{ {
#if SHOW_DEBUG #if SHOW_DEBUG
puts(s); puts(s);
@ -1053,9 +1053,10 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
kritchance = min(0.9, kritchance); kritchance = min(0.9, kritchance);
while (chance(kritchance)) { while (chance(kritchance)) {
sprintf(debugbuf, if (battledebug) {
"%s/%d landet einen kritischen Treffer", unitid(au), at.index); sprintf(debugbuf, "%s/%d landet einen kritischen Treffer", unitid(au), at.index);
battledebug(debugbuf); battle_log(debugbuf);
}
da += dice_rand(damage); 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", if (battledebug) {
da, ar, df->person[dt.index].hp, df->person[dt.index].hp - rda); 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 #ifdef SMALL_BATTLE_MESSAGES
if (b->small) { 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; df->person[dt.index].hp -= rda;
if (df->person[dt.index].hp > 0) { /* Hat überlebt */ if (df->person[dt.index].hp > 0) { /* Hat überlebt */
battledebug(debugbuf); if (battledebug) {
battle_log(debugbuf);
}
if (au->race == new_race[RC_DAEMON]) { if (au->race == new_race[RC_DAEMON]) {
#ifdef TODO_RUNESWORD #ifdef TODO_RUNESWORD
if (select_weapon(dt, 0, -1) == WP_RUNESWORD) continue; 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; return false;
} }
strcat(debugbuf, ", tot"); if (battledebug) {
battledebug(debugbuf); strcat(debugbuf, ", tot");
battle_log(debugbuf);
}
#ifdef SMALL_BATTLE_MESSAGES #ifdef SMALL_BATTLE_MESSAGES
if (b->small) { if (b->small) {
strcat(smallbuf, "."); strcat(smallbuf, ".");
@ -1897,8 +1904,10 @@ hits(troop at, troop dt, weapon * awp)
} }
#endif #endif
if (contest(skdiff, armor, shield)) { if (contest(skdiff, armor, shield)) {
strcat(debugbuf, " und trifft."); if (battledebug) {
battledebug(debugbuf); strcat(debugbuf, " und trifft.");
battle_log(debugbuf);
}
#ifdef SMALL_BATTLE_MESSAGES #ifdef SMALL_BATTLE_MESSAGES
if (b->small) { if (b->small) {
strcat(smallbuf, " und trifft."); strcat(smallbuf, " und trifft.");
@ -1907,8 +1916,10 @@ hits(troop at, troop dt, weapon * awp)
#endif #endif
return 1; return 1;
} }
strcat(debugbuf, "."); if (battledebug) {
battledebug(debugbuf); strcat(debugbuf, ".");
battle_log(debugbuf);
}
#ifdef SMALL_BATTLE_MESSAGES #ifdef SMALL_BATTLE_MESSAGES
if (b->small) { if (b->small) {
strcat(smallbuf, "."); strcat(smallbuf, ".");
@ -2102,8 +2113,10 @@ attack(battle *b, troop ta, const att *a, int numattack)
} }
if (reload && wp && wp->type->reload && !getreload(ta)) { if (reload && wp && wp->type->reload && !getreload(ta)) {
int i = setreload(ta); int i = setreload(ta);
sprintf(buf, " Nachladen gesetzt: %d", i); if (battledebug) {
battledebug(buf); sprintf(buf, " Nachladen gesetzt: %d", i);
battle_log(buf);
}
} }
} }
} }
@ -2738,11 +2751,13 @@ aftermath(battle * b)
free(trollsave); free(trollsave);
#endif #endif
sprintf(buf, "The battle lasted %d turns, %s and %s.\n", if (battledebug) {
b->turn, sprintf(buf, "The battle lasted %d turns, %s and %s.\n",
b->has_tactics_turn==true?"had a tactic turn":"had no tactic turn", b->turn,
battle_was_relevant==true?"was relevant":"was not relevant."); b->has_tactics_turn==true?"had a tactic turn":"had no tactic turn",
battledebug(buf); battle_was_relevant==true?"was relevant":"was not relevant.");
battle_log(buf);
}
} }
static void static void
@ -2758,8 +2773,9 @@ battle_punit(unit * u, battle * b)
spunit(&S, f, u, 4, see_battle); spunit(&S, f, u, 4, see_battle);
for (x = S; x; x = x->next) { for (x = S; x; x = x->next) {
fbattlerecord(b, f, x->s); fbattlerecord(b, f, x->s);
if (u->faction == f) if (battledebug && u->faction == f) {
battledebug(x->s); battle_log(x->s);
}
} }
if (S) if (S)
freestrlist(S); freestrlist(S);
@ -2926,14 +2942,14 @@ print_stats(battle * b)
buf[77] = (char)0; buf[77] = (char)0;
for (k = buf; *k; ++k) *k = '-'; for (k = buf; *k; ++k) *k = '-';
battlerecord(b, buf); battlerecord(b, buf);
if (s->bf->faction) { if (battledebug && s->bf->faction) {
if (s->bf->faction->alliance) { if (s->bf->faction->alliance) {
slprintf(buf, sizeof(buf), "##### %s (%s/%d)", s->bf->faction->name, itoa36(s->bf->faction->no), 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); s->bf->faction->alliance?s->bf->faction->alliance->id:0);
} else { } else {
slprintf(buf, sizeof(buf), "##### %s (%s)", s->bf->faction->name, itoa36(s->bf->faction->no)); slprintf(buf, sizeof(buf), "##### %s (%s)", s->bf->faction->name, itoa36(s->bf->faction->no));
} }
battledebug(buf); battle_log(buf);
} }
print_fighters(b, s); print_fighters(b, s);
} }
@ -3354,7 +3370,7 @@ make_battle(region * r)
bfaction * bf; bfaction * bf;
static int max_fac_no = 0; /* need this only once */ static int max_fac_no = 0; /* need this only once */
if (!nobattledebug) { if (battledebug) {
char zText[MAX_PATH]; char zText[MAX_PATH];
char zFilename[MAX_PATH]; char zFilename[MAX_PATH];
sprintf(zText, "%s/battles", basepath()); sprintf(zText, "%s/battles", basepath());
@ -3884,10 +3900,10 @@ init_battle(region * r, battle **bp)
c1->side->bf->attacker = true; c1->side->bf->attacker = true;
set_enemy(c1->side, c2->side, 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), sprintf(buf, "%s attackiert %s", sidename(c1->side, false),
sidename(c2->side, false)); sidename(c2->side, false));
battledebug(buf); battle_log(buf);
} }
fighting = true; fighting = true;
} }
@ -4081,10 +4097,10 @@ battle_flee(battle * b)
#endif #endif
} }
} }
if (runners > 0) { if (battledebug && runners > 0) {
char lbuf[256]; char lbuf[256];
sprintf(lbuf, "Flucht: %d aus %s", runners, itoa36(fig->unit->no)); 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 #endif
for (;battle_report(b) && b->turn<=COMBAT_TURNS;++b->turn) { for (;battle_report(b) && b->turn<=COMBAT_TURNS;++b->turn) {
char lbuf[256]; if (battledebug) {
char lbuf[256];
sprintf(lbuf, "*** Runde: %d", b->turn); sprintf(lbuf, "*** Runde: %d", b->turn);
battledebug(lbuf); battle_log(lbuf);
}
battle_flee(b); battle_flee(b);
battle_update(b); battle_update(b);
battle_attacks(b); battle_attacks(b);

View file

@ -231,9 +231,6 @@ extern void read_laen(struct region * r, int laen);
/* Vermehrung trotz 90% Auslastung */ /* Vermehrung trotz 90% Auslastung */
#define PEASANTFORCE 0.75 #define PEASANTFORCE 0.75
#define PEASANTSWANDER_WEIGHT 5
#define PEASANTSGREED_WEIGHT 5
#define TREESIZE (MAXPEASANTS_PER_AREA-2) #define TREESIZE (MAXPEASANTS_PER_AREA-2)
/* Eisen in Bergregionen bei Erschaffung */ /* Eisen in Bergregionen bei Erschaffung */

View file

@ -115,7 +115,7 @@ extern boolean noreports;
extern boolean nomer; extern boolean nomer;
extern boolean nobattle; extern boolean nobattle;
extern boolean nomonsters; extern boolean nomonsters;
extern boolean nobattledebug; extern boolean battledebug;
extern boolean dirtyload; extern boolean dirtyload;
extern int loadplane; 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, "lomem")==0) lomem = true;
else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = 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, "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, "crabsolute")==0) opt_cr_absolute_coords = true;
else if (strcmp(argv[i]+2, "help")==0) else if (strcmp(argv[i]+2, "help")==0)
return usage(argv[0], NULL); return usage(argv[0], NULL);

View file

@ -136,7 +136,7 @@ extern "C" {
extern boolean nomer; extern boolean nomer;
extern boolean nobattle; extern boolean nobattle;
extern boolean nomonsters; extern boolean nomonsters;
extern boolean nobattledebug; extern boolean battledebug;
extern boolean dirtyload; extern boolean dirtyload;
extern int loadplane; 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, "lomem")==0) lomem = true;
else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = 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, "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, "console")==0) luafile=NULL;
else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true; else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true;
else if (strcmp(argv[i]+2, "help")==0) 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; lomem = iniparser_getint(d, "common:lomem", lomem)?1:0;
quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1; quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1;
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
str = iniparser_getstr(d, "eressea:run"); str = iniparser_getstr(d, "eressea:run");
if (str) luafile = str; if (str) luafile = str;
str = iniparser_getstr(d, "eressea:report"); str = iniparser_getstr(d, "eressea:report");