Skip to content

Commit

Permalink
fix and test terraforming effects of great drought
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Jul 24, 2023
1 parent 4197c12 commit d0be981
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 132 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Thumbs.db
tmp/
tests/orders.txt
tests/config.lua
tests/reports/
tests/data/185.dat
/quicklist/
/cutest/
/critbit/
/tests/reports
/tests/data
/quicklist
/cutest
/critbit
*.mo
/.vs
/.idea/
Expand Down
8 changes: 4 additions & 4 deletions res/core/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5739,28 +5739,28 @@
</type>
</message>

<message name="drought_effect_1" section="magic">
<message name="drought_glacier_to_swamp" section="magic">
<type>
<arg name="mage" type="unit"/>
<arg name="region" type="region"/>
</type>
</message>

<message name="drought_effect_2" section="magic">
<message name="drought_no_terraform" section="magic">
<type>
<arg name="mage" type="unit"/>
<arg name="region" type="region"/>
</type>
</message>

<message name="drought_effect_3" section="magic">
<message name="drought_glacier_to_ocean" section="magic">
<type>
<arg name="mage" type="unit"/>
<arg name="region" type="region"/>
</type>
</message>

<message name="drought_effect_4" section="magic">
<message name="drought_to_ocean_global" section="magic">
<type>
<arg name="mage" type="unit"/>
<arg name="region" type="region"/>
Expand Down
8 changes: 4 additions & 4 deletions res/translations/messages.de.po
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ msgstr "\"$unit($unit) in $region($region): $int($number) $race($race,$number) $
msgid "fleescared"
msgstr "\"$int($amount) Bauern flohen aus Furcht vor $unit($unit).\""

msgid "drought_effect_3"
msgid "drought_glacier_to_ocean"
msgstr "\"$unit($mage) ruft das Feuer der Sonne auf $region($region) hinab. Die Felder verdorren und Pferde verdursten. Die Hungersnot kostet vielen Bauern das Leben. Vertrocknete Bäume recken ihre kahlen Zweige in den blauen Himmel, von dem erbarmungslos die sengende Sonne brennt. Die Dürre verändert die Region für immer.\""

msgid "spellfail_pump"
Expand Down Expand Up @@ -1155,7 +1155,7 @@ msgstr "\"$unit($unit) wird durchscheinend und verschwindet.\""
msgid "error127"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - So viele Fremde kann Deine Partei nicht aufnehmen.\""

msgid "drought_effect_2"
msgid "drought_no_terraform"
msgstr "\"$unit($mage) ruft das Feuer der Sonne auf $region($region) hinab. Die Felder verdorren und Pferde verdursten. Die Hungersnot kostet vielen Bauern das Leben. Vertrocknete Bäume recken ihre kahlen Zweige in den blauen Himmel, von dem erbarmungslos die sengende Sonne brennt.\""

msgid "usepotion"
Expand Down Expand Up @@ -2022,7 +2022,7 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Gebäude ka
msgid "teach_asgood"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - $unit($unit) muß mindestens 2 Stufen besser sein als $unit($student).\""

msgid "drought_effect_1"
msgid "drought_glacier_to_swamp"
msgstr "\"$unit($mage) ruft das Feuer der Sonne auf $region($region) hinab. Eis schmilzt und verwandelt sich in Morast. Reißende Ströme spülen die mageren Felder weg und ersäufen Mensch und Tier. Was an Bauten nicht den Fluten zum Opfer fiel, verschlingt der Morast. Die sengende Hitze verändert die Region für immer.\""

msgid "error204"
Expand Down Expand Up @@ -2298,7 +2298,7 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - $unit($target)
msgid "error79"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Ein Schiff oder eine Burg muß angegeben werden.\""

msgid "drought_effect_4"
msgid "drought_to_ocean_global"
msgstr "\"$unit($mage) ruft das Feuer der Sonne auf $region($region) hinab. Das Eis zerbricht und eine gewaltige Flutwelle verschlingt die Region.\""

msgctxt "curseinfo"
Expand Down
8 changes: 4 additions & 4 deletions res/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ msgstr "\"$unit($unit) in $region($region): $int($number) $race($race,$number) d
msgid "fleescared"
msgstr "\"$int($amount) peasants fled in fear of $unit($unit).\""

msgid "drought_effect_3"
msgid "drought_glacier_to_ocean"
msgstr "\"$unit($mage) calls the torching power of the sun upon $region($region). The crops wither, horses die of thirst. A famine claims the lives of many peasants. The trees die and their bald branches cannot protect from the torrid sun that mercilessly burns the grounds. The drought permanently alters the region.\""

msgid "spellfail_pump"
Expand Down Expand Up @@ -1155,7 +1155,7 @@ msgstr "\"$unit($unit) disappears.\""
msgid "error127"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Your faction cannot hire so many strangers.\""

msgid "drought_effect_2"
msgid "drought_no_terraform"
msgstr "\"$unit($mage) calls the torching power of the sun upon $region($region). The crops wither, horses die of thirst. A famine claims the lives of many peasants. The trees die and their bald branches cannot protect from the torrid sun that mercilessly burns the grounds.\""

msgid "usepotion"
Expand Down Expand Up @@ -2022,7 +2022,7 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - The building ca
msgid "teach_asgood"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - $unit($unit) needs to be at least 2 levels better than $unit($student).\""

msgid "drought_effect_1"
msgid "drought_glacier_to_swamp"
msgstr "\"$unit($mage) calls the torching power of the sun upon $region($region). Ice melts and turns the lands into swamps. Powerful rivers wash away the fertile soil and drown people and animals alike. What buildings have not succumbed to the floods sink into the mire. The torrid sun changes the region forever.\""

msgid "error204"
Expand Down Expand Up @@ -2298,7 +2298,7 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - $unit($target)
msgid "error79"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - A ship or a castle must be supplied.\""

msgid "drought_effect_4"
msgid "drought_to_ocean_global"
msgstr "\"$unit($mage) calls the torching power of the sun upon $region($region). The ice melts and and the region is consumed by a tidal wave.\""

msgctxt "curseinfo"
Expand Down
11 changes: 11 additions & 0 deletions src/kernel/region.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
#include "resources.h"
#include "unit.h"
#include "terrain.h"
#include "terrainid.h"
#include "item.h"


#include <CuTest.h>
#include <tests.h>
#include <stdlib.h>

void test_newterrain(CuTest *tc) {
terrain_type *t_plain;

test_setup();
init_terrains();
t_plain = get_or_create_terrain("plain");
CuAssertPtrEquals(tc, t_plain, (void *)newterrain(T_PLAIN));
}

void test_terraform(CuTest *tc) {
region *r;
terrain_type *t_plain, *t_ocean;
Expand Down Expand Up @@ -126,6 +136,7 @@ static void test_mourning(CuTest *tc) {
CuSuite *get_region_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_newterrain);
SUITE_ADD_TEST(suite, test_terraform);
SUITE_ADD_TEST(suite, test_trees);
SUITE_ADD_TEST(suite, test_mourning);
Expand Down
7 changes: 3 additions & 4 deletions src/kernel/terrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const char *terrainnames[MAXTERRAINS] = {
};

static terrain_type *registered_terrains;
static int terrain_changes = 1;
static int terrain_changes = 0;

bool terrain_changed(int *cache) {
assert(cache);
Expand Down Expand Up @@ -126,11 +126,10 @@ const struct terrain_type *newterrain(terrain_t t)
{
static int changed;
const struct terrain_type *result;
if (t == NOTERRAIN) {
assert(t < MAXTERRAINS);
if (t < 0 || t >= MAXTERRAINS) {
return NULL;
}
assert(t >= 0);
assert(t < MAXTERRAINS);
if (terrain_changed(&changed)) {
memset(newterrains, 0, sizeof(newterrains));
result = NULL;
Expand Down
134 changes: 51 additions & 83 deletions src/spells.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,39 @@ static int sp_create_stonegolem(castorder * co)
return cast_level;
}

static void drought(unit *u, region *r, double vigour, int duration)
{
curse *c;
message *msg;

report_spell(u, r, msg = msg_message("drought_effect", "mage region", u, r));
msg_release(msg);

/* Wenn schon Duerre herrscht, dann setzen wir nur den Power-Level
* hoch (evtl dauert dann die Duerre laenger). Ansonsten volle
* Auswirkungen.
*/
c = get_curse(r->attribs, &ct_drought);
if (c) {
if (c->vigour < vigour) {
c->vigour = vigour;
}
if (c->duration < duration) {
c->duration = duration;
}
}
else {
/* Baeume und Pferde sterben */
rsettrees(r, 2, rtrees(r, 2) / 2);
rsettrees(r, 1, rtrees(r, 1) / 2);
rsettrees(r, 0, rtrees(r, 0) / 2);
rsethorses(r, rhorses(r) / 2);

create_curse(u, &r->attribs, &ct_drought,
vigour, duration, 4.0, 0);
}
}

/* ------------------------------------------------------------- */
/* Name: Grosse Duerre
* Stufe: 17
Expand All @@ -1670,63 +1703,39 @@ static int sp_create_stonegolem(castorder * co)
* (FARCASTING | REGIONSPELL | TESTRESISTANCE)
*/

static int sp_great_drought(castorder * co)
int sp_great_drought(castorder * co)
{
unit *u;
bool terraform = false;
region *r = co_get_region(co);
unit *caster = co_get_caster(co);
int cast_level = co->level;
double force = co->force;
int duration = 2;
double effect;
const char *mtype = "drought_no_terraform";
int roll_d200 = rng_int() % 200;

if (fval(r->terrain, SEA_REGION)) {
cmistake(caster, co->order, 189, MSG_MAGIC);
/* TODO: vielleicht einen netten Patzer hier? */
return 0;
}

/* sterben */
rsetpeasants(r, rpeasants(r) / 2); /* evtl wuerfeln */
rsettrees(r, 2, rtrees(r, 2) / 2);
rsettrees(r, 1, rtrees(r, 1) / 2);
rsettrees(r, 0, rtrees(r, 0) / 2);
rsethorses(r, rhorses(r) / 2);

/* Arbeitslohn = 1/4 */
effect = 4.0; /* curses: higher is stronger */
create_curse(caster, &r->attribs, &ct_drought, force, duration, effect,
0);
drought(caster, r, co->force, 2);

/* terraforming */
if (rng_int() % 100 < 25) {
terraform = true;
/* 25% chance of terraforming */
if (roll_d200 < 50) {
terraform = false;

switch (rterrain(r)) {
case T_PLAIN:
/* rsetterrain(r, T_GRASSLAND); */
destroy_all_roads(r);
break;

case T_SWAMP:
/* rsetterrain(r, T_GRASSLAND); */
destroy_all_roads(r);
break;
/*
case T_GRASSLAND:
rsetterrain(r, T_DESERT);
destroy_all_roads(r);
break;
*/
case T_GLACIER:
if (rng_int() % 100 < 50) {
if (rterrain(r) == T_GLACIER) {
terraform = true;
/* 50% chance of becoming either ocean or swamp */
if (roll_d200 < 25) {
rsetterrain(r, T_SWAMP);
destroy_all_roads(r);
mtype = "drought_glacier_to_swamp";
}
else { /* Ozean */
destroy_all_roads(r);
rsetterrain(r, T_OCEAN);
mtype = "drought_glacier_to_ocean";
/* Einheiten duerfen hier auf keinen Fall geloescht werden! */
for (u = r->units; u; u = u->next) {
if (!u->ship) {
Expand All @@ -1737,36 +1746,23 @@ static int sp_great_drought(castorder * co)
remove_building(&r->buildings, r->buildings);
}
}
break;

default:
terraform = false;
break;
}
if (terraform) {
destroy_all_roads(r);
}
}

if (!fval(r->terrain, SEA_REGION)) {
/* not destroying the region, so it should be safe to make this a local
* message */
message *msg;
const char *mtype;
if (r->terrain == newterrain(T_SWAMP) && terraform) {
mtype = "drought_effect_1";
}
else if (!terraform) {
mtype = "drought_effect_2";
}
else {
mtype = "drought_effect_3";
}
msg = msg_message(mtype, "mage region", caster, r);
add_message(&r->msgs, msg);
msg_release(msg);
}
else {
/* possible that all units here get killed so better to inform with a global
* message */
message *msg = msg_message("drought_effect_4", "mage region", caster, r);
message *msg = msg_message("drought_to_ocean_global", "mage region", caster, r);
for (u = r->units; u; u = u->next)
freset(u->faction, FFL_SELECT);
for (u = r->units; u; u = u->next) {
Expand Down Expand Up @@ -2077,44 +2073,16 @@ static int sp_homestone(castorder * co)
*/
int sp_drought(castorder * co)
{
curse *c;
region *r = co_get_region(co);
unit *caster = co_get_caster(co);
message *msg;

if (fval(r->terrain, SEA_REGION)) {
cmistake(caster, co->order, 189, MSG_MAGIC);
/* TODO: vielleicht einen netten Patzer hier? */
return 0;
}

msg = msg_message("drought_effect", "mage region", caster, r);
report_spell(caster, r, msg);
msg_release(msg);

/* Wenn schon Duerre herrscht, dann setzen wir nur den Power-Level
* hoch (evtl dauert dann die Duerre laenger). Ansonsten volle
* Auswirkungen.
*/
c = get_curse(r->attribs, &ct_drought);
if (c) {
if (c->vigour < co->force) {
c->vigour = co->force;
}
if (c->duration < co->level) {
c->duration = co->level;
}
}
else {
/* Baeume und Pferde sterben */
rsettrees(r, 2, rtrees(r, 2) / 2);
rsettrees(r, 1, rtrees(r, 1) / 2);
rsettrees(r, 0, rtrees(r, 0) / 2);
rsethorses(r, rhorses(r) / 2);

create_curse(caster, &r->attribs, &ct_drought,
co->force, co->level, 4.0, 0);
}
drought(caster, r, co->force, co->level);
return co->level;
}

Expand Down
1 change: 1 addition & 0 deletions src/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C" {
int sp_deathcloud(struct castorder* co);
int sp_magicboost(struct castorder* co);
int sp_migranten(struct castorder* co);
int sp_great_drought(struct castorder *co);

#define ACTION_RESET 0x01 /* reset the one-time-flag FFL_SELECT (on first pass) */
#define ACTION_CANSEE 0x02 /* to people who can see the actor */
Expand Down
Loading

0 comments on commit d0be981

Please sign in to comment.