BUG 2396: insect recruit messages fixed, and tests added.

This commit is contained in:
Enno Rehling 2017-12-22 11:15:17 +01:00
parent 683e3c566d
commit cba452786f
11 changed files with 105 additions and 48 deletions

View File

@ -818,6 +818,10 @@
<string name="section_events">
<text locale="de">Ereignisse</text>
</string>
<string name="section_nr">
<text locale="de">Hinweise</text>
<text locale="en">Notifications</text>
</string>
<string name="section_mail">
<text locale="de">Botschaften</text>
</string>
@ -7305,16 +7309,6 @@
<text locale="en">regular spell</text>
</string>
<string name="nr_insectwinter">
<text locale="de">Es ist Winter, und Insekten können nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren.</text>
<text locale="en">It is winter, and insects can only recruit in deserts or with the aid of nestwarmth potions.</text>
</string>
<string name="nr_insectfall">
<text locale="de">Es ist Spätherbst, und diese Woche ist die letzte vor dem Winter, in der Insekten rekrutieren können.</text>
<text locale="en">It is the last week before winter in which insects can still recruit.</text>
</string>
<string name="nr_owner">
<text locale="de">Eigentümer</text>
<text locale="en">Owner</text>

View File

@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<messages>
<message name="nr_insectwinter" section="nr">
<text locale="de">Es ist Winter, und Insekten können nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren.</text>
<text locale="en">It is winter, and insects can only recruit in deserts or with the aid of nestwarmth potions.</text>
</message>
<message name="nr_insectfall" section="nr">
<text locale="de">Es ist Spätherbst, und diese Woche ist die letzte vor dem Winter, in der Insekten rekrutieren können.</text>
<text locale="en">It is the last week before winter in which insects can still recruit.</text>
</message>
<message name="newbie_info_game" section="events">
<type>
<arg name="subject" type="string"/>
@ -7049,7 +7057,7 @@
<text locale="en">"Please send in orders for the next turn if you want to continue playing."</text>
</message>
<message name="newbieimmunity" section="events">
<message name="newbieimmunity" section="nr">
<type>
<arg name="turns" type="int"/>
</type>

View File

@ -44,9 +44,10 @@ const gamedate *get_gamedate(int turn, gamedate * gd)
assert(gd);
assert(t>=0);
gd->turn = turn;
gd->week = t % weeks_per_month; /* 0 - weeks_per_month-1 */
gd->month = (t / weeks_per_month + first_month) % months_per_year; /* 0 - months_per_year-1 */
gd->year = t / (weeks_per_year)+1;
gd->year = 1 + t / weeks_per_year;
gd->season = month_season ? month_season[gd->month] : 0;
return gd;
}

View File

@ -23,6 +23,7 @@ extern "C" {
extern int weeks_per_month;
typedef struct gamedate {
int turn;
int year;
int season;
int month;

View File

@ -1297,10 +1297,6 @@ void quit(void)
}
else {
++f->age;
if (f->age + 1 < NewbieImmunity()) {
ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns",
NewbieImmunity() - f->age - 1));
}
fptr = &f->next;
}
}

View File

@ -681,7 +681,7 @@ int check_ship_allowed(struct ship *sh, const region * r)
/* insekten dürfen nicht hier rein. haben wir welche? */
unit *u = ship_owner(sh);
if (is_freezing(u)) {
if (u && is_freezing(u)) {
return SA_NO_INSECT;
}
}

View File

@ -267,7 +267,7 @@ static void dragon_name(unit * u)
str = locale_getstring(default_locale, zText);
assert(str != NULL);
if (u->number > 1) {
if (u->region->land && (u->number > 1)) {
const char *no_article = strchr((const char *)str, ' ');
assert(no_article);
/* TODO: localization */
@ -282,7 +282,7 @@ static void dragon_name(unit * u)
sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */
}
else {
if (rng_int() % 3 == 0) {
if (u->region->land && (rng_int() % 3 == 0)) {
/* TODO: localization */
snprintf(name, sizeof(name), "%s %s von %s", n, str, rname(u->region, default_locale));
}

View File

@ -42,11 +42,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* gamecode includes */
#include "alchemy.h"
#include "calendar.h"
#include "economy.h"
#include "move.h"
#include "upkeep.h"
#include "vortex.h"
#include "calendar.h"
#include "teleport.h"
/* kernel includes */
@ -744,8 +744,13 @@ rp_messages(struct stream *out, message_list * msgs, faction * viewer, int inden
newline(out);
sprintf(cat_identifier, "section_%s", section->name);
section_title = LOC(viewer->locale, cat_identifier);
centre(out, section_title, true);
newline(out);
if (section_title) {
centre(out, section_title, true);
newline(out);
}
else {
log_error("no title defined for section %s in locale %s", section->name, locale_name(viewer->locale));
}
k = 1;
}
nr_render(m->msg, viewer->locale, lbuf, sizeof(lbuf), viewer);
@ -2050,14 +2055,6 @@ report_plaintext(const char *filename, report_context * ctx,
char buf[8192];
char *bufp;
size_t size;
int thisseason;
int nextseason;
gamedate date;
get_gamedate(turn + 1, &date);
thisseason = date.season;
get_gamedate(turn + 2, &date);
nextseason = date.season;
if (F == NULL) {
perror(filename);
@ -2161,20 +2158,6 @@ report_plaintext(const char *filename, report_context * ctx,
centre(out, buf, true);
}
/* Insekten-Winter-Warnung */
if (f->race == get_race(RC_INSECT)) {
if (thisseason == 0) {
centre(out, LOC(f->locale, "nr_insectwinter"), true);
newline(out);
}
else {
if (nextseason == 0) {
centre(out, LOC(f->locale, "nr_insectfall"), true);
newline(out);
}
}
}
bufp = buf;
size = sizeof(buf) - 1;
bytes = snprintf(buf, size, "%s:", LOC(f->locale, "nr_options"));

View File

@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include <kernel/config.h>
#include "reports.h"
#include "calendar.h"
#include "guard.h"
#include "laws.h"
#include "spells.h"
@ -1396,6 +1398,29 @@ static void cb_add_seen(region *r, unit *u, void *cbdata) {
}
}
void report_warnings(faction *f, const gamedate *date)
{
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", ""));
}
}
}
}
}
/** set region.seen based on visibility by one faction.
*
* this function may also update ctx->last and ctx->first for potential
@ -1408,6 +1433,11 @@ 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);
if (bt_lighthouse && config_changed(&config)) {
rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name);

View File

@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
struct gamedate;
struct selist;
struct stream;
struct seen_region;
@ -116,6 +117,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_item(const struct unit *owner, const struct item *i,
const struct faction *viewer, const char **name, const char **basename,
int *number, bool singular);

View File

@ -1,12 +1,13 @@
#include <platform.h>
#include "reports.h"
#include "move.h"
#include "spy.h"
#include "lighthouse.h"
#include "travelthru.h"
#include "calendar.h"
#include "keyword.h"
#include "lighthouse.h"
#include "move.h"
#include "spells.h"
#include "spy.h"
#include "travelthru.h"
#include <kernel/ally.h>
#include <kernel/config.h>
@ -780,6 +781,45 @@ static void test_stealth_modifier(CuTest *tc) {
test_cleanup();
}
static void test_insect_warnings(CuTest *tc) {
faction *f;
gamedate gd;
/* OBS: in unit tests, get_gamedate always returns season = 0 */
test_setup();
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);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_cleanup();
}
static void test_newbie_warning(CuTest *tc) {
faction *f;
test_setup();
f = test_create_faction(test_create_race("insect"));
config_set_int("NewbieImmunity", 3);
f->age = 2;
report_warnings(f, NULL);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "newbieimmunity"));
test_clear_messages(f);
f->age = 3;
report_warnings(f, NULL);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "newbieimmunity"));
test_clear_messages(f);
test_cleanup();
}
CuSuite *get_reports_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -807,5 +847,7 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_bufunit);
SUITE_ADD_TEST(suite, test_bufunit_fstealth);
SUITE_ADD_TEST(suite, test_arg_resources);
SUITE_ADD_TEST(suite, test_insect_warnings);
SUITE_ADD_TEST(suite, test_newbie_warning);
return suite;
}