BUG 2458: fix insect recruit warnings.

This commit is contained in:
Enno Rehling 2018-08-02 13:53:41 +02:00
parent 2697d78c07
commit 3880960acf
5 changed files with 52 additions and 30 deletions

View File

@ -1773,7 +1773,7 @@ msgid "storm"
msgstr "\"Die $ship($ship) wird in $region($region) von Stürmen abgetrieben$if($sink,\" und sinkt\",\"\").\""
msgid "nr_insectwinter"
msgstr "Es ist Winter, und Insekten können nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren."
msgstr "Insekten können wegen des Winterwetters in der kommenden Woche nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren."
msgid "spellfail_nomonsters"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Dieser Zauber kann nicht auf Monster gezaubert werden.\""
@ -2727,7 +2727,7 @@ msgid "volcanostartsmoke"
msgstr "\"Aus dem Vulkankrater von $region($region) steigt plötzlich Rauch.\""
msgid "nr_insectfall"
msgstr "Es ist Spätherbst, und diese Woche ist die letzte vor dem Winter, in der Insekten rekrutieren können."
msgstr "Es ist Spätherbst, und die kommende Woche ist die letzte vor dem Winter, in der Insekten rekrutieren können."
msgid "error296"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Hier werden niemals Bäume wachsen.\""

View File

@ -477,7 +477,7 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
if (rc == get_race(RC_INSECT)) {
gamedate date;
get_gamedate(turn, &date);
if (date.season == 0 && r->terrain != newterrain(T_DESERT)) {
if (date.season == SEASON_WINTER && r->terrain != newterrain(T_DESERT)) {
bool usepotion = false;
unit *u2;

View File

@ -1517,24 +1517,23 @@ static void cb_add_seen(region *r, unit *u, void *cbdata) {
}
}
void report_warnings(faction *f, const gamedate *date)
void report_warnings(faction *f, int now)
{
if (f->age < NewbieImmunity()) {
ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns",
NewbieImmunity() - f->age));
}
if (date) {
if (f->race == get_race(RC_INSECT)) {
if (date->season == 0) {
ADDMSG(&f->msgs, msg_message("nr_insectwinter", ""));
}
else {
gamedate next;
get_gamedate(date->turn + 1, &next);
if (next.season == 0) {
ADDMSG(&f->msgs, msg_message("nr_insectfall", ""));
}
if (f->race == get_race(RC_INSECT)) {
gamedate date;
get_gamedate(now + 1, &date);
if (date.season == SEASON_WINTER) {
ADDMSG(&f->msgs, msg_message("nr_insectwinter", ""));
}
else if (date.season == SEASON_AUTUMN) {
if (get_gamedate(now + 2 + 2, &date)->season == SEASON_WINTER) {
ADDMSG(&f->msgs, msg_message("nr_insectfall", ""));
}
}
}
@ -1552,11 +1551,9 @@ void prepare_report(report_context *ctx, faction *f)
static bool rule_region_owners;
static bool rule_lighthouse_units;
const struct building_type *bt_lighthouse = bt_find("lighthouse");
gamedate now;
/* Insekten-Winter-Warnung */
get_gamedate(turn, &now);
report_warnings(f, &now);
report_warnings(f, turn);
if (bt_lighthouse && config_changed(&config)) {
rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name);

View File

@ -115,7 +115,7 @@ extern "C" {
int size, const struct faction *viewer, bool see_unit);
int report_items(const struct unit *u, struct item *result, int size,
const struct unit *owner, const struct faction *viewer);
void report_warnings(struct faction *f, const struct gamedate *date);
void report_warnings(struct faction *f, int now);
void report_raceinfo(const struct race *rc, const struct locale *lang, char *buf, size_t length);
void report_race_skills(const struct race *rc, char *zText, size_t length, const struct locale *lang);
void report_item(const struct unit *owner, const struct item *i,

View File

@ -785,23 +785,48 @@ static void test_stealth_modifier(CuTest *tc) {
test_teardown();
}
static void setup_calendar(void) {
months_per_year = 9;
month_season = malloc(sizeof(int) * months_per_year);
month_season[0] = SEASON_SUMMER;
month_season[1] = SEASON_AUTUMN;
month_season[2] = SEASON_AUTUMN;
month_season[3] = SEASON_WINTER;
month_season[4] = SEASON_WINTER;
month_season[5] = SEASON_WINTER;
month_season[6] = SEASON_SPRING;
month_season[7] = SEASON_SPRING;
month_season[8] = SEASON_SUMMER;
}
static void test_insect_warnings(CuTest *tc) {
faction *f;
gamedate gd;
/* OBS: in unit tests, get_gamedate always returns season = 0 */
test_setup();
setup_calendar();
config_set_int("game.start", 184);
test_inject_messagetypes();
f = test_create_faction(test_create_race("insect"));
gd.turn = 0;
gd.season = 3;
report_warnings(f, &gd);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectfall"));
gd.season = 0;
report_warnings(f, &gd);
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
report_warnings(f, gd.turn);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectfall"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_clear_messages(f);
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1082, &gd)->season);
report_warnings(f, gd.turn);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectfall"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_clear_messages(f);
CuAssertIntEquals(tc, SEASON_WINTER, get_gamedate(1084, &gd)->season);
report_warnings(f, gd.turn);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectfall"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_clear_messages(f);
test_teardown();
}
@ -810,16 +835,16 @@ static void test_newbie_warning(CuTest *tc) {
test_setup();
test_inject_messagetypes();
f = test_create_faction(test_create_race("insect"));
f = test_create_faction(NULL);
config_set_int("NewbieImmunity", 3);
f->age = 2;
report_warnings(f, NULL);
report_warnings(f, 0);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "newbieimmunity"));
test_clear_messages(f);
f->age = 3;
report_warnings(f, NULL);
report_warnings(f, 0);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "newbieimmunity"));
test_clear_messages(f);