Merge pull request #664 from ennorehling/master

last-minute Bugfixes für 3.11
This commit is contained in:
Enno Rehling 2017-03-03 22:18:23 +01:00 committed by GitHub
commit 040485504d
28 changed files with 388 additions and 95 deletions

2
clibs

@ -1 +1 @@
Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11 Subproject commit d286006a28c8aa7cd70ed7fd4cd172b50ade9727

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<calendar name="secondage" newyear="month_1" start="0"> <calendar name="secondage" newyear="month_1">
<season name="winter"> <season name="winter">
<month name="month_4" storm="50" /> <month name="month_4" storm="50" />
<month name="month_5" storm="30" /> <month name="month_5" storm="30" />

View File

@ -10,6 +10,11 @@ function setup()
eressea.settings.set("rules.encounters", "0") eressea.settings.set("rules.encounters", "0")
end end
function test_calendar()
assert_equal(get_season(1011), "calendar::winter")
assert_equal(get_season(1012), "calendar::spring")
end
function test_herbalism() function test_herbalism()
-- OBS: herbalism is currently an E2-only skill -- OBS: herbalism is currently an E2-only skill
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")

View File

@ -1,5 +1,3 @@
require 'tests.economy'
require 'tests.e2.undead' require 'tests.e2.undead'
require 'tests.e2.shiplanding' require 'tests.e2.shiplanding'
require 'tests.e2.e2features' require 'tests.e2.e2features'
@ -8,6 +6,7 @@ require 'tests.e2.destroy'
require 'tests.e2.guard' require 'tests.e2.guard'
require 'tests.e2.spells' require 'tests.e2.spells'
require 'tests.e2.stealth' require 'tests.e2.stealth'
require 'tests.economy'
require 'tests.orders' require 'tests.orders'
require 'tests.common' require 'tests.common'
require 'tests.report' require 'tests.report'

View File

@ -4,6 +4,7 @@ require 'tests.e3.spells'
require 'tests.e3.rules' require 'tests.e3.rules'
require 'tests.e3.parser' require 'tests.e3.parser'
require 'tests.e3.morale' require 'tests.e3.morale'
require 'tests.economy'
require 'tests.orders' require 'tests.orders'
require 'tests.common' require 'tests.common'
-- require 'tests.report' -- require 'tests.report'

View File

@ -37,6 +37,10 @@ function teardown()
set_rule("rules.ship.storms") set_rule("rules.ship.storms")
end end
function test_calendar()
assert_equal(get_season(396), "calendar::winter")
end
function disable_test_bug_1738_build_castle_e3() function disable_test_bug_1738_build_castle_e3()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("bug_1738@eressea.de", "human", "de") local f = faction.create("bug_1738@eressea.de", "human", "de")
@ -990,4 +994,4 @@ function test_bug2187()
-- write_report(f) -- write_report(f)
set_rule("rules.food.flags", "4") set_rule("rules.food.flags", "4")
end end

View File

@ -127,6 +127,20 @@ function test_ironkeeper_guards_iron()
assert_equal(level, u:get_item("iron")) assert_equal(level, u:get_item("iron"))
end end
function test_sawmill()
local r = region.create(0, 0, "plain")
r:set_resource("tree", 100)
local u = unit.create(faction.create("human"), r)
u:add_item("money", 250) -- sawmill maintenance
u:set_skill("forestry", 6)
u.building = building.create(r, "sawmill")
u.building.size = 1
u:add_order("MACHE 6 HOLZ")
process_orders()
assert_equal(6, u:get_item("log"))
assert_equal(97, r:get_resource("tree"))
end
function test_ent_guards_trees() function test_ent_guards_trees()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
r:set_resource("tree", 100) r:set_resource("tree", 100)

View File

@ -21,7 +21,7 @@ COMPILE_DEFINITIONS ERESSEA_BUILDNO="${ERESSEA_BUILDNO}")
ENDIF() ENDIF()
IF (CMAKE_COMPILER_IS_GNUCC) IF (CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
ENDIF() ENDIF()
IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion")

View File

@ -18,7 +18,7 @@ int seasons = 0;
int first_turn(void) int first_turn(void)
{ {
return config_get_int("game.start", 1); return config_get_int("game.start", 0);
} }
const gamedate *get_gamedate(int turn, gamedate * gd) const gamedate *get_gamedate(int turn, gamedate * gd)

View File

@ -763,12 +763,8 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
stream_printf(out, "\"%s\";Beschr\n", str); stream_printf(out, "\"%s\";Beschr\n", str);
} }
/* print faction information */ /* print faction information */
sf = visible_faction(f, u); sf = visible_faction(NULL, u);
prefix = raceprefix(u);
if (u->faction == f || omniscient(f)) { if (u->faction == f || omniscient(f)) {
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
const faction *otherfaction =
a_otherfaction ? get_otherfaction(a_otherfaction) : NULL;
/* my own faction, full info */ /* my own faction, full info */
const attrib *a = NULL; const attrib *a = NULL;
unit *mage; unit *mage;
@ -780,12 +776,12 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
stream_printf(out, "%d;gruppe\n", g->gid); stream_printf(out, "%d;gruppe\n", g->gid);
} }
stream_printf(out, "%d;Partei\n", u->faction->no); stream_printf(out, "%d;Partei\n", u->faction->no);
if (sf != u->faction) if (sf && sf != u->faction) {
stream_printf(out, "%d;Verkleidung\n", sf->no); stream_printf(out, "%d;Verkleidung\n", sf->no);
if (fval(u, UFL_ANON_FACTION)) stream_printf(out, "%d;Anderepartei\n", sf->no);
stream_printf(out, "%d;Parteitarnung\n", (u->flags & UFL_ANON_FACTION)!=0); }
if (otherfaction && otherfaction != u->faction) { if (fval(u, UFL_ANON_FACTION)) {
stream_printf(out, "%d;Anderepartei\n", otherfaction->no); stream_printf(out, "%d;Parteitarnung\n", (u->flags & UFL_ANON_FACTION) != 0);
} }
mage = get_familiar_mage(u); mage = get_familiar_mage(u);
if (mage) { if (mage) {
@ -798,21 +794,19 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
stream_printf(out, "%d;Parteitarnung\n", (u->flags & UFL_ANON_FACTION) != 0); stream_printf(out, "%d;Parteitarnung\n", (u->flags & UFL_ANON_FACTION) != 0);
} }
else { else {
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
const faction *otherfaction =
a_otherfaction ? get_otherfaction(a_otherfaction) : NULL;
/* other unit. show visible faction, not u->faction */ /* other unit. show visible faction, not u->faction */
stream_printf(out, "%d;Partei\n", sf->no); stream_printf(out, "%d;Partei\n", sf ? sf->no : f->no);
if (sf == f) { if (sf == f) {
stream_printf(out, "1;Verraeter\n"); stream_printf(out, "1;Verraeter\n");
} }
if (otherfaction && otherfaction != u->faction) { if (sf && sf != u->faction) {
if (alliedunit(u, f, HELP_FSTEALTH)) { if (alliedunit(u, f, HELP_FSTEALTH)) {
stream_printf(out, "%d;Anderepartei\n", otherfaction->no); stream_printf(out, "%d;Anderepartei\n", sf->no);
} }
} }
} }
} }
prefix = raceprefix(u);
if (prefix) { if (prefix) {
prefix = mkname("prefix", prefix); prefix = mkname("prefix", prefix);
stream_printf(out, "\"%s\";typprefix\n", translate(prefix, LOC(f->locale, stream_printf(out, "\"%s\";typprefix\n", translate(prefix, LOC(f->locale,

View File

@ -1,9 +1,11 @@
#include <platform.h> #include <platform.h>
#include "creport.h" #include "creport.h"
#include "move.h" #include "move.h"
#include "spy.h"
#include "travelthru.h" #include "travelthru.h"
#include "keyword.h" #include "keyword.h"
#include <kernel/ally.h>
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/item.h> #include <kernel/item.h>
@ -48,9 +50,67 @@ static void test_cr_unit(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static int cr_get_int(stream *strm, const char *match, int def)
{
char line[1024];
strm->api->rewind(strm->handle);
while (strm->api->readln(strm->handle, line, sizeof(line))==0) {
if (strstr(line, match)) {
return atoi(line);
}
}
return def;
}
static void test_cr_factionstealth(CuTest *tc) {
stream strm;
faction *f1, *f2;
region *r;
unit *u;
ally *al;
test_setup();
mstream_init(&strm);
f1 = test_create_faction(0);
f2 = test_create_faction(0);
r = test_create_region(0, 0, 0);
u = test_create_unit(f1, r);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
set_factionstealth(u, f2);
CuAssertPtrNotNull(tc, u->attribs);
cr_output_unit(&strm, u->region, f1, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, -1, cr_get_int(&strm, ";Verraeter", -1));
cr_output_unit(&strm, u->region, f2, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Verraeter", -1));
al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH;
cr_output_unit(&strm, u->region, f2, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));
CuAssertIntEquals(tc, f2->no, cr_get_int(&strm, ";Anderepartei", -1));
CuAssertIntEquals(tc, 1, cr_get_int(&strm, ";Verraeter", -1));
mstream_done(&strm);
test_cleanup();
}
CuSuite *get_creport_suite(void) CuSuite *get_creport_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_cr_unit); SUITE_ADD_TEST(suite, test_cr_unit);
SUITE_ADD_TEST(suite, test_cr_factionstealth);
return suite; return suite;
} }

View File

@ -1123,7 +1123,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
allocation *al; allocation *al;
int nreq = 0; int nreq = 0;
resource_limit *rdata = get_resourcelimit(rtype); resource_limit *rdata = get_resourcelimit(rtype);
int avail = 0; int avail = INT_MAX;
for (al = alist; al; al = al->next) { for (al = alist; al; al = al->next) {
nreq += required(al->want, al->save); nreq += required(al->want, al->save);
@ -1145,7 +1145,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
if (rx>0 && rng_int() % nreq < rx) ++x; if (rx>0 && rng_int() % nreq < rx) ++x;
avail -= x; avail -= x;
nreq -= want; nreq -= want;
al->get = x * al->save.sa[0] / al->save.sa[1]; al->get = x * al->save.sa[1] / al->save.sa[0];
al->get = MIN(al->want, al->get); al->get = MIN(al->want, al->get);
if (rdata->produce) { if (rdata->produce) {
int use = required(al->get, al->save); int use = required(al->get, al->save);

View File

@ -407,6 +407,12 @@ static void test_make_item(CuTest *tc) {
CuAssertIntEquals(tc, 22, get_item(u, itype)); CuAssertIntEquals(tc, 22, get_item(u, itype));
CuAssertIntEquals(tc, 283, u->region->resources->amount); /* no free lunches */ CuAssertIntEquals(tc, 283, u->region->resources->amount); /* no free lunches */
rdata->modifiers[0].value = frac_make(1, 2);
make_item(u, itype, 6);
split_allocations(u->region);
CuAssertIntEquals(tc, 28, get_item(u, itype));
CuAssertIntEquals(tc, 280, u->region->resources->amount); /* 50% saving = 3 stones make 6 stones */
rdata->modifiers[0].flags = RMF_REQUIREDBUILDING; rdata->modifiers[0].flags = RMF_REQUIREDBUILDING;
rdata->modifiers[0].race = NULL; rdata->modifiers[0].race = NULL;
rdata->modifiers[0].btype = bt_get_or_create("mine"); rdata->modifiers[0].btype = bt_get_or_create("mine");

View File

@ -24,16 +24,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "monsters.h" #include "monsters.h"
#include <kernel/ally.h> #include <kernel/ally.h>
#include <kernel/unit.h> #include <kernel/building.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/building.h> #include <kernel/terrain.h>
#include <kernel/unit.h>
#include <assert.h> #include <assert.h>
guard_t can_start_guarding(const unit * u) guard_t can_start_guarding(const unit * u)
{ {
if (u->region->terrain->flags & SEA_REGION) {
return E_GUARD_TERRAIN;
}
if (u->status >= ST_FLEE || fval(u, UFL_FLEEING)) if (u->status >= ST_FLEE || fval(u, UFL_FLEEING))
return E_GUARD_FLEEING; return E_GUARD_FLEEING;
/* Monster der Monsterpartei duerfen immer bewachen */ /* Monster der Monsterpartei duerfen immer bewachen */

View File

@ -12,7 +12,7 @@ extern "C" {
struct unit; struct unit;
struct region; struct region;
typedef enum { E_GUARD_OK, E_GUARD_UNARMED, E_GUARD_NEWBIE, E_GUARD_FLEEING } guard_t; typedef enum { E_GUARD_OK, E_GUARD_UNARMED, E_GUARD_NEWBIE, E_GUARD_FLEEING, E_GUARD_TERRAIN } guard_t;
guard_t can_start_guarding(const struct unit * u); guard_t can_start_guarding(const struct unit * u);
void update_guards(void); void update_guards(void);

View File

@ -7,7 +7,9 @@
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/order.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/terrain.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/region.h> #include <kernel/region.h>
@ -128,14 +130,117 @@ static void test_guard_monsters(CuTest * tc)
test_cleanup(); test_cleanup();
} }
static void test_update_guard(CuTest * tc)
/* https://bugs.eressea.de/view.php?id=2292 */
{
unit *ug;
region *r;
item_type *itype;
const struct terrain_type *t_ocean, *t_plain;
test_setup();
t_ocean = test_create_terrain("ocean", SEA_REGION);
t_plain = test_create_terrain("packice", ARCTIC_REGION);
itype = it_get_or_create(rt_get_or_create("sword"));
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
r = test_create_region(0, 0, t_plain);
ug = test_create_unit(test_create_faction(0), r);
i_change(&ug->items, itype, 1);
set_level(ug, SK_MELEE, 2);
setguard(ug, true);
CuAssertIntEquals(tc, 1, armedmen(ug, false));
CuAssertTrue(tc, is_guard(ug));
terraform_region(r, t_ocean);
update_guards();
CuAssertTrue(tc, ! is_guard(ug));
test_cleanup();
}
static void test_guard_on(CuTest * tc)
{
unit *ug;
region *r;
item_type *itype;
terrain_type *t_ocean, *t_plain;
test_setup();
t_ocean = test_create_terrain("ocean", SEA_REGION);
t_plain = test_create_terrain("plain", LAND_REGION);
itype = it_get_or_create(rt_get_or_create("sword"));
new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2);
r = test_create_region(0, 0, t_plain);
ug = test_create_unit(test_create_faction(0), r);
i_change(&ug->items, itype, 1);
set_level(ug, SK_MELEE, 2);
ug->thisorder = create_order(K_GUARD, ug->faction->locale, NULL);
setguard(ug, false);
CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, is_guard(ug));
terraform_region(r, test_create_terrain("packice", ARCTIC_REGION));
setguard(ug, false);
CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, is_guard(ug));
terraform_region(r, t_ocean);
setguard(ug, false);
CuAssertIntEquals(tc, E_GUARD_TERRAIN, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, !is_guard(ug));
CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "error2"));
terraform_region(r, t_plain);
i_change(&ug->items, itype, -1);
CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, !is_guard(ug));
CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "unit_unarmed"));
i_change(&ug->items, itype, 1);
test_clear_messages(ug->faction);
set_level(ug, SK_MELEE, 0);
CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, !is_guard(ug));
CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "unit_unarmed"));
set_level(ug, SK_MELEE, 2);
ug->status = ST_FLEE;
CuAssertIntEquals(tc, E_GUARD_FLEEING, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, !is_guard(ug));
CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "error320"));
ug->status = ST_FIGHT;
config_set("NewbieImmunity", "5");
CuAssertIntEquals(tc, E_GUARD_NEWBIE, can_start_guarding(ug));
guard_on_cmd(ug, ug->thisorder);
CuAssertTrue(tc, !is_guard(ug));
CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "error304"));
config_set("NewbieImmunity", NULL);
test_clear_messages(ug->faction);
test_cleanup();
}
CuSuite *get_guard_suite(void) CuSuite *get_guard_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_is_guarded); SUITE_ADD_TEST(suite, test_is_guarded);
SUITE_ADD_TEST(suite, test_is_guard); SUITE_ADD_TEST(suite, test_is_guard);
SUITE_ADD_TEST(suite, test_guard_unskilled); SUITE_ADD_TEST(suite, test_guard_unskilled);
SUITE_ADD_TEST(suite, test_guard_on);
SUITE_ADD_TEST(suite, test_guard_armed); SUITE_ADD_TEST(suite, test_guard_armed);
SUITE_ADD_TEST(suite, test_guard_unarmed); SUITE_ADD_TEST(suite, test_guard_unarmed);
SUITE_ADD_TEST(suite, test_guard_monsters); SUITE_ADD_TEST(suite, test_guard_monsters);
SUITE_ADD_TEST(suite, test_update_guard);
return suite; return suite;
} }

View File

@ -833,17 +833,21 @@ const char * game_name(void)
return param ? param : global.gamename; return param ? param : global.gamename;
} }
const char * game_name_upper(void) const char * game_mailcmd(void)
{ {
static char result[32]; /* FIXME: static result */ const char *param = config_get("game.mailcmd");
char *r = result; if (!param) {
const char *param = game_name(); static char result[32]; /* FIXME: static result */
const char *c = param; char *r = result;
while (*c && (result+sizeof(result))>r) { const char *c;
*r++ = (char)toupper(*c++); param = game_name();
for (c = param; *c && (result + sizeof(result)) > r; ++c) {
*r++ = (char)toupper(*c);
}
*r = '\0';
return result;
} }
*r = '\0'; return param;
return result;
} }
int game_id(void) { int game_id(void) {

View File

@ -51,7 +51,7 @@ extern "C" {
param_t getparam(const struct locale *lang); param_t getparam(const struct locale *lang);
const char * game_name(void); const char * game_name(void);
const char * game_name_upper(void); const char * game_mailcmd(void);
int game_id(void); int game_id(void);
/* returns a value between [0..xpct_2], generated with two dice */ /* returns a value between [0..xpct_2], generated with two dice */

View File

@ -245,7 +245,6 @@ static void test_config_inifile(CuTest *tc) {
config_set_from(ini); config_set_from(ini);
CuAssertStrEquals(tc, "Eressea", config_get("game.name")); CuAssertStrEquals(tc, "Eressea", config_get("game.name"));
CuAssertStrEquals(tc, "Eressea", game_name()); CuAssertStrEquals(tc, "Eressea", game_name());
CuAssertStrEquals(tc, "ERESSEA", game_name_upper());
CuAssertIntEquals(tc, 42, game_id()); CuAssertIntEquals(tc, 42, game_id());
iniparser_freedict(ini); iniparser_freedict(ini);
test_cleanup(); test_cleanup();
@ -274,6 +273,18 @@ static void test_findparam(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_game_mailcmd(CuTest *tc) {
test_setup();
CuAssertStrEquals(tc, "Eressea", game_name());
CuAssertStrEquals(tc, "ERESSEA", game_mailcmd());
config_set("game.name", "Hodor");
CuAssertStrEquals(tc, "Hodor", game_name());
CuAssertStrEquals(tc, "HODOR", game_mailcmd());
config_set("game.mailcmd", "ERESSEA");
CuAssertStrEquals(tc, "ERESSEA", game_mailcmd());
test_cleanup();
}
CuSuite *get_config_suite(void) CuSuite *get_config_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -287,6 +298,7 @@ CuSuite *get_config_suite(void)
SUITE_ADD_TEST(suite, test_getunit); SUITE_ADD_TEST(suite, test_getunit);
SUITE_ADD_TEST(suite, test_read_unitid); SUITE_ADD_TEST(suite, test_read_unitid);
SUITE_ADD_TEST(suite, test_default_order); SUITE_ADD_TEST(suite, test_default_order);
SUITE_ADD_TEST(suite, test_game_mailcmd);
SUITE_ADD_TEST(suite, test_rules); SUITE_ADD_TEST(suite, test_rules);
return suite; return suite;
} }

View File

@ -797,18 +797,18 @@ static void json_settings(cJSON *json) {
return; return;
} }
for (child = json->child; child; child = child->next) { for (child = json->child; child; child = child->next) {
if (child->valuestring) { if (config_get(child->string) == NULL) {
config_set(child->string, child->valuestring); if (child->valuestring) {
} config_set(child->string, child->valuestring);
else {
char value[32];
if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) {
sprintf(value, "%f", child->valuedouble);
} }
else { else {
sprintf(value, "%d", child->valueint); char value[32];
} if (child->type == cJSON_Number && child->valuedouble && child->valueint < child->valuedouble) {
if (config_get(child->string) == NULL) { sprintf(value, "%f", child->valuedouble);
}
else {
sprintf(value, "%d", child->valueint);
}
config_set(child->string, value); config_set(child->string, value);
} }
} }

View File

@ -70,14 +70,17 @@ static void test_settings(CuTest * tc)
"\"integer\" : 14," "\"integer\" : 14,"
"\"true\": true," "\"true\": true,"
"\"game.id\": 4," "\"game.id\": 4,"
"\"game.name\": \"E3\","
"\"false\": false," "\"false\": false,"
"\"float\" : 1.5 }}"; "\"float\" : 1.5 }}";
cJSON *json = cJSON_Parse(data); cJSON *json = cJSON_Parse(data);
test_cleanup(); test_cleanup();
config_set("game.id", "42"); /* should not be replaced */ config_set("game.id", "42"); /* should not be replaced */
config_set("game.name", "Eressea"); /* should not be replaced */
json_config(json); json_config(json);
CuAssertStrEquals(tc, "42", config_get("game.id")); CuAssertStrEquals(tc, "42", config_get("game.id"));
CuAssertStrEquals(tc, "Eressea", config_get("game.name"));
CuAssertStrEquals(tc, "1", config_get("true")); CuAssertStrEquals(tc, "1", config_get("true"));
CuAssertStrEquals(tc, "0", config_get("false")); CuAssertStrEquals(tc, "0", config_get("false"));
CuAssertStrEquals(tc, "1d4", config_get("string")); CuAssertStrEquals(tc, "1d4", config_get("string"));

View File

@ -2686,31 +2686,29 @@ int guard_on_cmd(unit * u, struct order *ord)
return 0; return 0;
} }
if (fval(u->region->terrain, SEA_REGION)) { if (fval(u, UFL_MOVED)) {
cmistake(u, ord, 2, MSG_EVENT); cmistake(u, ord, 187, MSG_EVENT);
}
else if (fval(u_race(u), RCF_ILLUSIONARY)
|| u_race(u) == get_race(RC_SPELL)) {
cmistake(u, ord, 95, MSG_EVENT);
} }
else { else {
if (fval(u, UFL_MOVED)) { int err = can_start_guarding(u);
cmistake(u, ord, 187, MSG_EVENT); if (err == E_GUARD_OK) {
setguard(u, true);
} }
else if (fval(u_race(u), RCF_ILLUSIONARY) else if (err == E_GUARD_TERRAIN) {
|| u_race(u) == get_race(RC_SPELL)) { cmistake(u, ord, 2, MSG_EVENT);
cmistake(u, ord, 95, MSG_EVENT);
} }
else { else if (err == E_GUARD_UNARMED) {
int err = can_start_guarding(u); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", ""));
if (err == E_GUARD_OK) { }
setguard(u, true); else if (err == E_GUARD_FLEEING) {
} cmistake(u, ord, 320, MSG_EVENT);
else if (err == E_GUARD_UNARMED) { }
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", "")); else if (err == E_GUARD_NEWBIE) {
} cmistake(u, ord, 304, MSG_EVENT);
else if (err == E_GUARD_FLEEING) {
cmistake(u, ord, 320, MSG_EVENT);
}
else if (err == E_GUARD_NEWBIE) {
cmistake(u, ord, 304, MSG_EVENT);
}
} }
} }
return 0; return 0;

View File

@ -1006,7 +1006,7 @@ static void cb_add_address(region *r, unit *ut, void *cbdata) {
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
faction *sf = visible_faction(f, u); faction *sf = visible_faction(f, u);
assert(u->faction != f); /* if this is see_travel only, then I shouldn't be here. */ assert(u->faction != f); /* if this is see_travel only, then I shouldn't be here. */
if (data->lastf != sf && cansee_unit(u, ut, data->stealthmod)) { if (data->lastf != sf && cansee_unit(ut, u, data->stealthmod)) {
add_seen_faction_i(data->flist, sf); add_seen_faction_i(data->flist, sf);
data->lastf = sf; data->lastf = sf;
break; break;
@ -1024,7 +1024,7 @@ static void add_travelthru_addresses(region *r, faction *f, selist **flist, int
travelthru_map(r, cb_add_address, &cbdata); travelthru_map(r, cb_add_address, &cbdata);
} }
static void get_addresses(report_context * ctx) void get_addresses(report_context * ctx)
{ {
/* "TODO: travelthru" */ /* "TODO: travelthru" */
region *r; region *r;
@ -1945,7 +1945,7 @@ static void eval_regions(struct opstack **stack, const void *userdata)
const char *get_mailcmd(const struct locale *loc) const char *get_mailcmd(const struct locale *loc)
{ {
static char result[64]; /* FIXME: static return buffer */ static char result[64]; /* FIXME: static return buffer */
snprintf(result, sizeof(result), "%s %d %s", game_name_upper(), game_id(), LOC(loc, "mailcmd")); snprintf(result, sizeof(result), "%s %d %s", game_mailcmd(), game_id(), LOC(loc, "mailcmd"));
return result; return result;
} }

View File

@ -81,6 +81,7 @@ extern "C" {
void prepare_report(report_context *ctx, struct faction *f); void prepare_report(report_context *ctx, struct faction *f);
void finish_reports(report_context *ctx); void finish_reports(report_context *ctx);
void get_addresses(report_context * ctx);
typedef int(*report_fun) (const char *filename, report_context * ctx, typedef int(*report_fun) (const char *filename, report_context * ctx,
const char *charset); const char *charset);

View File

@ -2,6 +2,7 @@
#include "reports.h" #include "reports.h"
#include "move.h" #include "move.h"
#include "spy.h"
#include "lighthouse.h" #include "lighthouse.h"
#include "travelthru.h" #include "travelthru.h"
#include "keyword.h" #include "keyword.h"
@ -279,6 +280,88 @@ static void test_prepare_travelthru(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_get_addresses(CuTest *tc) {
report_context ctx;
faction *f, *f2, *f1;
region *r;
test_setup();
f = test_create_faction(0);
f1 = test_create_faction(0);
f2 = test_create_faction(0);
r = test_create_region(0, 0, 0);
test_create_unit(f, r);
test_create_unit(f1, r);
test_create_unit(f2, r);
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, r, ctx.first);
CuAssertPtrEquals(tc, NULL, ctx.last);
get_addresses(&ctx);
CuAssertPtrNotNull(tc, ctx.addresses);
CuAssertTrue(tc, selist_contains(ctx.addresses, f, NULL));
CuAssertTrue(tc, selist_contains(ctx.addresses, f1, NULL));
CuAssertTrue(tc, selist_contains(ctx.addresses, f2, NULL));
CuAssertIntEquals(tc, 3, selist_length(ctx.addresses));
test_cleanup();
}
static void test_get_addresses_fstealth(CuTest *tc) {
report_context ctx;
faction *f, *f2, *f1;
region *r;
unit *u;
test_setup();
f = test_create_faction(0);
f1 = test_create_faction(0);
f2 = test_create_faction(0);
r = test_create_region(0, 0, 0);
test_create_unit(f, r);
u = test_create_unit(f1, r);
set_factionstealth(u, f2);
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, r, ctx.first);
CuAssertPtrEquals(tc, NULL, ctx.last);
get_addresses(&ctx);
CuAssertPtrNotNull(tc, ctx.addresses);
CuAssertTrue(tc, selist_contains(ctx.addresses, f, NULL));
CuAssertTrue(tc, !selist_contains(ctx.addresses, f1, NULL));
CuAssertTrue(tc, selist_contains(ctx.addresses, f2, NULL));
CuAssertIntEquals(tc, 2, selist_length(ctx.addresses));
test_cleanup();
}
static void test_get_addresses_travelthru(CuTest *tc) {
report_context ctx;
faction *f, *f2, *f1;
region *r1, *r2;
unit *u;
test_setup();
f = test_create_faction(0);
f1 = test_create_faction(0);
f2 = test_create_faction(0);
r1 = test_create_region(0, 0, 0);
r2 = test_create_region(1, 0, 0);
u = test_create_unit(f, r2);
travelthru_add(r1, u);
u = test_create_unit(f1, r1);
set_factionstealth(u, f2);
u->building = test_create_building(u->region, test_create_buildingtype("tower"));
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, r1, ctx.first);
CuAssertPtrEquals(tc, NULL, ctx.last);
get_addresses(&ctx);
CuAssertPtrNotNull(tc, ctx.addresses);
CuAssertTrue(tc, selist_contains(ctx.addresses, f, NULL));
CuAssertTrue(tc, !selist_contains(ctx.addresses, f1, NULL));
CuAssertTrue(tc, selist_contains(ctx.addresses, f2, NULL));
CuAssertIntEquals(tc, 2, selist_length(ctx.addresses));
test_cleanup();
}
void test_prepare_lighthouse_capacity(CuTest *tc) { void test_prepare_lighthouse_capacity(CuTest *tc) {
building *b; building *b;
building_type *btype; building_type *btype;
@ -490,6 +573,9 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_prepare_lighthouse_owners); SUITE_ADD_TEST(suite, test_prepare_lighthouse_owners);
SUITE_ADD_TEST(suite, test_prepare_lighthouse_capacity); SUITE_ADD_TEST(suite, test_prepare_lighthouse_capacity);
SUITE_ADD_TEST(suite, test_prepare_travelthru); SUITE_ADD_TEST(suite, test_prepare_travelthru);
SUITE_ADD_TEST(suite, test_get_addresses);
SUITE_ADD_TEST(suite, test_get_addresses_fstealth);
SUITE_ADD_TEST(suite, test_get_addresses_travelthru);
SUITE_ADD_TEST(suite, test_reorder_units); SUITE_ADD_TEST(suite, test_reorder_units);
SUITE_ADD_TEST(suite, test_seen_faction); SUITE_ADD_TEST(suite, test_seen_faction);
SUITE_ADD_TEST(suite, test_regionid); SUITE_ADD_TEST(suite, test_regionid);

View File

@ -178,7 +178,7 @@ int spy_cmd(unit * u, struct order *ord)
return 0; return 0;
} }
void set_factionstealth(unit * u, faction * f) static bool can_set_factionstealth(const unit * u, const faction * f)
{ {
region *lastr = NULL; region *lastr = NULL;
/* for all units mu of our faction, check all the units in the region /* for all units mu of our faction, check all the units in the region
@ -194,7 +194,7 @@ void set_factionstealth(unit * u, faction * f)
faction *fv = visible_faction(f, ru); faction *fv = visible_faction(f, ru);
if (fv == f) { if (fv == f) {
if (cansee(f, lastr, ru, 0)) if (cansee(f, lastr, ru, 0))
break; return true;
} }
} }
ru = ru->next; ru = ru->next;
@ -204,13 +204,15 @@ void set_factionstealth(unit * u, faction * f)
} }
mu = mu->nextF; mu = mu->nextF;
} }
if (mu != NULL) { return true;
attrib *a = a_find(u->attribs, &at_otherfaction); }
if (!a)
a = a_add(&u->attribs, make_otherfaction(f)); void set_factionstealth(unit *u, faction *f) {
else attrib *a = a_find(u->attribs, &at_otherfaction);
a->data.v = f; if (!a)
} a = a_add(&u->attribs, make_otherfaction(f));
else
a->data.v = f;
} }
int setstealth_cmd(unit * u, struct order *ord) int setstealth_cmd(unit * u, struct order *ord)
@ -315,7 +317,7 @@ int setstealth_cmd(unit * u, struct order *ord)
} }
else { else {
struct faction *f = findfaction(nr); struct faction *f = findfaction(nr);
if (f == NULL) { if (f == NULL || !can_set_factionstealth(u, f)) {
cmistake(u, ord, 66, MSG_EVENT); cmistake(u, ord, 66, MSG_EVENT);
break; break;
} }

View File

@ -26,12 +26,15 @@ extern "C" {
struct region; struct region;
struct strlist; struct strlist;
struct order; struct order;
struct faction;
extern int setstealth_cmd(struct unit *u, struct order *ord); int setstealth_cmd(struct unit *u, struct order *ord);
extern int spy_cmd(struct unit *u, struct order *ord); int spy_cmd(struct unit *u, struct order *ord);
extern int sabotage_cmd(struct unit *u, struct order *ord); int sabotage_cmd(struct unit *u, struct order *ord);
extern void spy_message(int spy, const struct unit *u, void spy_message(int spy, const struct unit *u,
const struct unit *target); const struct unit *target);
void set_factionstealth(struct unit * u, struct faction * f);
#define OCEAN_SWIMMER_CHANCE 0.1 #define OCEAN_SWIMMER_CHANCE 0.1
#define CANAL_SWIMMER_CHANCE 0.9 #define CANAL_SWIMMER_CHANCE 0.9

View File

@ -50,14 +50,6 @@ static void test_simple_spy_message(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void set_factionstealth(unit *u, faction *f) {
attrib *a = a_find(u->attribs, &at_otherfaction);
if (!a)
a = a_add(&u->attribs, make_otherfaction(f));
else
a->data.v = f;
}
static void test_all_spy_message(CuTest *tc) { static void test_all_spy_message(CuTest *tc) {
spy_fixture fix; spy_fixture fix;
item_type *itype; item_type *itype;