From 118230a73706a6556197c9f6f7bb455588cf2ad5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 3 Sep 2005 08:54:19 +0000 Subject: [PATCH] implemented global warming (glacier belts with age > 200 can melt) --- src/common/gamecode/randenc.c | 72 ++++++++++++++++++-------------- src/eressea/korrektur.c | 77 +++++++++++++++++++++++++++-------- 2 files changed, 100 insertions(+), 49 deletions(-) diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index f48231d92..b5327e9df 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -909,8 +909,7 @@ melt_iceberg(region *r) for (u=r->units; u; u=u->next) freset(u->faction, FL_DH); for (u=r->units; u; u=u->next) if (!fval(u->faction, FL_DH)) { fset(u->faction, FL_DH); - ADDMSG(&u->faction->msgs, new_message(u->faction, - "iceberg_melt%r:region", r)); + ADDMSG(&u->faction->msgs, msg_message("iceberg_melt", "region", r)); } /* driftrichtung löschen */ @@ -1049,13 +1048,18 @@ move_icebergs(void) { region *r; - for (r=regions; r; r=r->next) if (rterrain(r) == T_ICEBERG && !fval(r, RF_DH)) { - if (rand()%100 < 60) { - fset(r, RF_DH); - move_iceberg(r); - } else if (rand()%100 < 10){ - fset(r, RF_DH); - melt_iceberg(r); + for (r=regions; r; r=r->next) { + if (rterrain(r) == T_ICEBERG && !fval(r, RF_DH)) { + int select = rand() % 10; + if (select < 4) { + /* 4% chance */ + fset(r, RF_DH); + melt_iceberg(r); + } else if (select<64) { + /* 60% chance */ + fset(r, RF_DH); + move_iceberg(r); + } } } } @@ -1065,32 +1069,38 @@ create_icebergs(void) { region *r; - for (r=regions; r; r=r->next) if (rterrain(r) == T_ICEBERG_SLEEP && rand()%100 < 5) { - boolean has_ocean_neighbour = false; - direction_t dir; - region *rc; - unit *u; + for (r=regions; r; r=r->next) { + if (rterrain(r) == T_ICEBERG_SLEEP && chance(0.05)) { + boolean has_ocean_neighbour = false; + direction_t dir; + region *rc; + unit *u; - freset(r, RF_DH); - for (dir=0; dir < MAXDIRECTIONS; dir++) { - rc = rconnect(r, dir); - if (rc && rterrain(rc) == T_OCEAN) { - has_ocean_neighbour = true; - break; - } - } - if (!has_ocean_neighbour) continue; + freset(r, RF_DH); + for (dir=0; dir < MAXDIRECTIONS; dir++) { + rc = rconnect(r, dir); + if (rc && rterrain(rc) == T_OCEAN) { + has_ocean_neighbour = true; + break; + } + } + if (!has_ocean_neighbour) continue; - rsetterrain(r, T_ICEBERG); + rsetterrain(r, T_ICEBERG); - fset(r, RF_DH); - move_iceberg(r); + fset(r, RF_DH); + move_iceberg(r); - for (u=r->units; u; u=u->next) freset(u->faction, FL_DH); - for (u=r->units; u; u=u->next) if (!fval(u->faction, FL_DH)) { - fset(u->faction, FL_DH); - ADDMSG(&u->faction->msgs, msg_message("iceberg_create", "region", r)); - } + for (u=r->units; u; u=u->next) { + freset(u->faction, FL_DH); + } + for (u=r->units; u; u=u->next) { + if (!fval(u->faction, FL_DH)) { + fset(u->faction, FL_DH); + ADDMSG(&u->faction->msgs, msg_message("iceberg_create", "region", r)); + } + } + } } } diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 041d77e33..e05c02780 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -24,8 +24,9 @@ /* misc includes */ #include #include -#include +#include #include +#include /* gamecode includes */ #include @@ -57,16 +58,17 @@ #include /* util includes */ -#include -#include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include /* libc includes */ #include @@ -74,10 +76,6 @@ #include #include -/* attributes includes */ -#include -#include - #undef XMAS1999 #undef XMAS2000 #undef XMAS2001 @@ -749,7 +747,7 @@ fix_gates(void) static void frame_regions(void) { - unsigned short ocean_age = turn; + unsigned short ocean_age = (unsigned short)turn; region * r = regions; for (r=regions;r;r=r->next) { direction_t d; @@ -785,6 +783,46 @@ frame_regions(void) } } +#define GLOBAL_WARMING 200 + +#ifdef GLOBAL_WARMING +static void +global_warming(void) +{ + region * r; + for (r=regions;r;r=r->next) { + if (r->ageterrain==T_GLACIER) { + /* 1% chance that an existing glacier gets unstable */ + if (chance(0.01)) { + direction_t d; + for (d=0;d!=MAXDIRECTIONS;++d) { + region * rn = rconnect(r, d); + if (rn!=NULL) { + terrain_t rt = rn->terrain; + if (rt!=T_ICEBERG && rt!=T_ICEBERG_SLEEP && rt!=T_GLACIER && rt!=T_OCEAN) { + break; + } + } + } + if (d==MAXDIRECTIONS) { + terraform(r, T_ICEBERG_SLEEP); + } + } + } else if (r->terrain==T_ICEBERG || r->terrain==T_ICEBERG_SLEEP) { + direction_t d; + for (d=0;d!=MAXDIRECTIONS;++d) { + region * rn = rconnect(r, d); + if (rn && rn->terrain==T_GLACIER && chance(0.10)) { + /* 10% chance that a glacier next to an iceberg gets unstable */ + terraform(rn, T_ICEBERG_SLEEP); + } + } + } + } +} +#endif + static int fix_astralplane(void) { @@ -949,10 +987,10 @@ check_phoenix(void) return; } } - } + } - f = findfaction(MONSTER_FACTION); - if (f==NULL) return; + f = findfaction(MONSTER_FACTION); + if (f==NULL) return; /* it is not, so we create it */ r = random_land_region(); @@ -1131,6 +1169,9 @@ korrektur(void) do_once("atrx", fix_attribflags()); do_once("asfi", fix_astral_firewalls()); frame_regions(); +#ifdef GLOBAL_WARMING + global_warming(); +#endif fix_astralplane(); fix_firewalls(); fix_gates();