Merge pull request #68 from badgerman/remove-dungeons

Remove the obsolete dungeons module
This commit is contained in:
Enno Rehling 2014-12-13 13:26:04 +01:00
commit 0e7d0cc91d
29 changed files with 200 additions and 506 deletions

View File

@ -5,4 +5,7 @@ compiler:
script: s/travis-build script: s/travis-build
before_install: before_install:
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -qq libtolua-dev liblua5.1-dev libncurses5-dev libsqlite3-dev libxml2-dev - sudo apt-get install -qq libtolua-dev liblua5.1-dev libncurses5-dev libsqlite3-dev libxml2-dev
os:
- linux
- osx

View File

@ -1,5 +1,8 @@
{ {
"keywords": { "keywords": {
"en" : {
"combat": [ "COMBAT", "FIGHT" ]
},
"de": { "de": {
"//" : "//", "//" : "//",
"banner": "BANNER", "banner": "BANNER",
@ -14,7 +17,7 @@
"guard": ["BEWACHE", "BEWACHEN"], "guard": ["BEWACHE", "BEWACHEN"],
"message": "BOTSCHAFT", "message": "BOTSCHAFT",
"end": "ENDE", "end": "ENDE",
"ride": ["REITE", "REITEN"], "ride": ["FAHRE", "FAHREN"],
"number": "NUMMER", "number": "NUMMER",
"follow": ["FOLGE","FOLGEN"], "follow": ["FOLGE","FOLGEN"],
"research": ["FORSCHE", "FORSCHEN"], "research": ["FORSCHE", "FORSCHEN"],
@ -29,7 +32,7 @@
"make": ["MACHE", "MACHEN"], "make": ["MACHE", "MACHEN"],
"maketemp": ["MACHE TEMP", "MACHETEMP"], "maketemp": ["MACHE TEMP", "MACHETEMP"],
"move" : "NACH", "move" : "NACH",
"password" : "PASSWORD", "password" : "PASSWORT",
"loot" : ["PLÜNDERE", "PLÜNDERN"], "loot" : ["PLÜNDERE", "PLÜNDERN"],
"recruit": ["REKRUTIERE", "REKRUTIEREN"], "recruit": ["REKRUTIERE", "REKRUTIEREN"],
"reserve": ["RESERVIERE", "RESERVIEREN"], "reserve": ["RESERVIERE", "RESERVIEREN"],

@ -1 +1 @@
Subproject commit 2a7af5e2347217ea4efcf7fb3f0bc9c2681d1a17 Subproject commit 61989d93368022602a2a7ac4218c83f254701f0f

View File

@ -685,13 +685,16 @@ static void
fwriteorder(FILE * F, const struct order *ord, const struct locale *lang, fwriteorder(FILE * F, const struct order *ord, const struct locale *lang,
bool escape) bool escape)
{ {
char ebuf[1024]; char ebuf[1025];
char obuf[1024]; char obuf[1024];
const char *str = obuf; const char *str = obuf;
fputc('"', F); fputc('"', F);
write_order(ord, obuf, sizeof(obuf)); write_order(ord, obuf, sizeof(obuf));
if (escape) { if (escape) {
str = escape_string(obuf, ebuf, sizeof(ebuf)); str = escape_string(obuf, ebuf, sizeof(ebuf));
if (str == ebuf) {
ebuf[1024] = 0;
}
} }
if (str[0]) if (str[0])
fputs(str, F); fputs(str, F);

View File

@ -58,9 +58,6 @@ void game_init(void)
register_resources(); register_resources();
register_buildings(); register_buildings();
register_itemfunctions(); register_itemfunctions();
#if DUNGEON_MODULE
register_dungeon();
#endif
#if MUSEUM_MODULE #if MUSEUM_MODULE
register_museum(); register_museum();
#endif #endif

View File

@ -165,7 +165,7 @@ struct order *ord)
return -1; return -1;
} }
else if (n == 0) { else if (n == 0) {
int reserve = get_reservation(src, itype->rtype); int reserve = get_reservation(src, itype);
if (reserve) { if (reserve) {
msg_feedback(src, ord, "nogive_reserved", "resource reservation", msg_feedback(src, ord, "nogive_reserved", "resource reservation",
itype->rtype, reserve); itype->rtype, reserve);
@ -187,7 +187,7 @@ struct order *ord)
i_change(&dest->items, itype, r); i_change(&dest->items, itype, r);
#ifdef RESERVE_GIVE #ifdef RESERVE_GIVE
#ifdef RESERVE_DONATIONS #ifdef RESERVE_DONATIONS
change_reservation(dest, item2resource(itype), r); change_reservation(dest, itype, r);
#else #else
if (src->faction == dest->faction) { if (src->faction == dest->faction) {
change_reservation(dest, item2resource(itype), r); change_reservation(dest, item2resource(itype), r);
@ -426,7 +426,6 @@ void give_unit(unit * u, unit * u2, order * ord)
if (u2 == NULL) { if (u2 == NULL) {
message *msg; message *msg;
if (fval(r->terrain, SEA_REGION)) { if (fval(r->terrain, SEA_REGION)) {
/* TODO: why is this here, but the unit does not actually seem to lose any men? */
msg = disband_men(u->number, u, ord); msg = disband_men(u->number, u, ord);
if (msg) { if (msg) {
ADDMSG(&u->faction->msgs, msg); ADDMSG(&u->faction->msgs, msg);
@ -516,7 +515,7 @@ void give_unit(unit * u, unit * u2, order * ord)
cmistake(u, ord, 156, MSG_COMMERCE); cmistake(u, ord, 156, MSG_COMMERCE);
return; return;
} }
add_give(u, u2, 1, 1, get_resourcetype(R_UNIT), ord, 0); add_give(u, u2, n, n, get_resourcetype(R_PERSON), ord, 0);
u_setfaction(u, u2->faction); u_setfaction(u, u2->faction);
u2->faction->newbies += n; u2->faction->newbies += n;
} }
@ -680,8 +679,8 @@ void give_cmd(unit * u, order * ord)
item *itm = *itmp; item *itm = *itmp;
const item_type *itype = itm->type; const item_type *itype = itm->type;
if (itm->number > 0 if (itm->number > 0
&& itm->number - get_reservation(u, itype->rtype) > 0) { && itm->number - get_reservation(u, itype) > 0) {
n = itm->number - get_reservation(u, itype->rtype); n = itm->number - get_reservation(u, itype);
if (give_item(n, itype, u, u2, ord) == 0) { if (give_item(n, itype, u, u2, ord) == 0) {
if (*itmp != itm) if (*itmp != itm)
continue; continue;
@ -719,7 +718,7 @@ void give_cmd(unit * u, order * ord)
item *i = *i_find(&u->items, itype); item *i = *i_find(&u->items, itype);
if (i != NULL) { if (i != NULL) {
if (can_give(u, u2, itype, 0)) { if (can_give(u, u2, itype, 0)) {
n = i->number - get_reservation(u, itype->rtype); n = i->number - get_reservation(u, itype);
give_item(n, itype, u, u2, ord); give_item(n, itype, u, u2, ord);
} }
else { else {
@ -755,7 +754,7 @@ void give_cmd(unit * u, order * ord)
msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));
return; return;
} }
msg = u2 ? give_men(u->number, u, u2, ord) : disband_men(u->number, u, ord); msg = u2 ? give_men(n, u, u2, ord) : disband_men(n, u, ord);
if (msg) { if (msg) {
ADDMSG(&u->faction->msgs, msg); ADDMSG(&u->faction->msgs, msg);
} }

View File

@ -28,9 +28,6 @@
#include <modules/arena.h> #include <modules/arena.h>
#endif #endif
#include <modules/autoseed.h> #include <modules/autoseed.h>
#if DUNGEON_MODULE
#include <modules/dungeon.h>
#endif
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/calendar.h> #include <kernel/calendar.h>

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2014, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>

View File

@ -604,7 +604,7 @@ static const char *resourcenames[MAX_RESOURCES] = {
"aurafocus", "sphereofinv", "magicbag", "aurafocus", "sphereofinv", "magicbag",
"magicherbbag", "dreameye", "p2", "seed", "mallornseed", "magicherbbag", "dreameye", "p2", "seed", "mallornseed",
"money", "aura", "permaura", "money", "aura", "permaura",
"hp", "unit", "peasant" "hp", "peasant", "person"
}; };
const resource_type *get_resourcetype(resource_t type) { const resource_type *get_resourcetype(resource_t type) {
@ -949,6 +949,8 @@ void init_resources(void)
{ {
resource_type *rtype; resource_type *rtype;
rtype = rt_get_or_create(resourcenames[R_PERSON]); // lousy hack
rtype = rt_get_or_create(resourcenames[R_PEASANT]); rtype = rt_get_or_create(resourcenames[R_PEASANT]);
rtype->uchange = res_changepeasants; rtype->uchange = res_changepeasants;
@ -971,10 +973,6 @@ void init_resources(void)
rtype = rt_get_or_create(resourcenames[R_AURA]); rtype = rt_get_or_create(resourcenames[R_AURA]);
rtype->uchange = res_changeaura; rtype->uchange = res_changeaura;
// R_UNIT
rtype = rt_get_or_create(resourcenames[R_UNIT]);
rtype->uchange = res_changeperson;
/* alte typen registrieren: */ /* alte typen registrieren: */
init_oldpotions(); init_oldpotions();
} }

View File

@ -297,8 +297,8 @@ extern "C" {
R_AURA, /* Aura */ R_AURA, /* Aura */
R_PERMAURA, /* Permanente Aura */ R_PERMAURA, /* Permanente Aura */
R_LIFE, R_LIFE,
R_UNIT,
R_PEASANT, R_PEASANT,
R_PERSON,
MAX_RESOURCES, /* do not use outside item.c ! */ MAX_RESOURCES, /* do not use outside item.c ! */
NORESOURCE = -1 NORESOURCE = -1

View File

@ -64,20 +64,6 @@ void test_change_item(CuTest * tc)
test_uchange(tc, u, get_resourcetype(R_IRON)); test_uchange(tc, u, get_resourcetype(R_IRON));
} }
void test_change_person(CuTest * tc)
{
unit * u;
test_cleanup();
register_resources();
init_resources();
test_create_world();
u = test_create_unit(0, 0);
test_uchange(tc, u, get_resourcetype(R_UNIT));
}
void test_resource_type(CuTest * tc) void test_resource_type(CuTest * tc)
{ {
struct item_type *itype; struct item_type *itype;
@ -136,7 +122,6 @@ CuSuite *get_item_suite(void)
SUITE_ADD_TEST(suite, test_resourcename_no_appearance); SUITE_ADD_TEST(suite, test_resourcename_no_appearance);
SUITE_ADD_TEST(suite, test_resourcename_with_appearance); SUITE_ADD_TEST(suite, test_resourcename_with_appearance);
SUITE_ADD_TEST(suite, test_change_item); SUITE_ADD_TEST(suite, test_change_item);
SUITE_ADD_TEST(suite, test_change_person);
SUITE_ADD_TEST(suite, test_resource_type); SUITE_ADD_TEST(suite, test_resource_type);
SUITE_ADD_TEST(suite, test_finditemtype); SUITE_ADD_TEST(suite, test_finditemtype);
SUITE_ADD_TEST(suite, test_findresourcetype); SUITE_ADD_TEST(suite, test_findresourcetype);

View File

@ -84,34 +84,34 @@ int change_resource(unit * u, const resource_type * rtype, int change)
return i; return i;
} }
int get_reservation(const unit * u, const resource_type * rtype) int get_reservation(const unit * u, const item_type * itype)
{ {
reservation *res = u->reservations; reservation *res = u->reservations;
if (rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM)) if (itype->rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM))
return (u->number * GOLEM_STONE); return (u->number * GOLEM_STONE);
if (rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM)) if (itype->rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM))
return (u->number * GOLEM_IRON); return (u->number * GOLEM_IRON);
while (res && res->type != rtype) while (res && res->type != itype)
res = res->next; res = res->next;
if (res) if (res)
return res->value; return res->value;
return 0; return 0;
} }
int change_reservation(unit * u, const resource_type * rtype, int value) int change_reservation(unit * u, const item_type * itype, int value)
{ {
reservation *res, **rp = &u->reservations; reservation *res, **rp = &u->reservations;
if (!value) if (!value)
return 0; return 0;
while (*rp && (*rp)->type != rtype) while (*rp && (*rp)->type != itype)
rp = &(*rp)->next; rp = &(*rp)->next;
res = *rp; res = *rp;
if (!res) { if (!res) {
*rp = res = calloc(sizeof(reservation), 1); *rp = res = calloc(sizeof(reservation), 1);
res->type = rtype; res->type = itype;
res->value = value; res->value = value;
} }
else if (res && res->value + value <= 0) { else if (res && res->value + value <= 0) {
@ -125,18 +125,18 @@ int change_reservation(unit * u, const resource_type * rtype, int value)
return res->value; return res->value;
} }
int set_resvalue(unit * u, const resource_type * rtype, int value) int set_resvalue(unit * u, const item_type * itype, int value)
{ {
reservation *res, **rp = &u->reservations; reservation *res, **rp = &u->reservations;
while (*rp && (*rp)->type != rtype) while (*rp && (*rp)->type != itype)
rp = &(*rp)->next; rp = &(*rp)->next;
res = *rp; res = *rp;
if (!res) { if (!res) {
if (!value) if (!value)
return 0; return 0;
*rp = res = calloc(sizeof(reservation), 1); *rp = res = calloc(sizeof(reservation), 1);
res->type = rtype; res->type = itype;
res->value = value; res->value = value;
} }
else if (res && value <= 0) { else if (res && value <= 0) {
@ -166,8 +166,8 @@ int count)
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) if ((mode & GET_SLACK) && (mode & GET_RESERVE))
use = have; use = have;
else if (mode & (GET_SLACK|GET_RESERVE)) { else if (rtype->itype && mode & (GET_SLACK | GET_RESERVE)) {
int reserve = get_reservation(u, rtype); int reserve = get_reservation(u, rtype->itype);
int slack = _max(0, have - reserve); int slack = _max(0, have - reserve);
if (mode & GET_RESERVE) if (mode & GET_RESERVE)
use = have - slack; use = have - slack;
@ -211,13 +211,13 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) { if ((mode & GET_SLACK) && (mode & GET_RESERVE)) {
n = _min(use, have); n = _min(use, have);
} }
else { else if (rtype->itype) {
int reserve = get_reservation(u, rtype); int reserve = get_reservation(u, rtype->itype);
int slack = _max(0, have - reserve); int slack = _max(0, have - reserve);
if (mode & GET_RESERVE) { if (mode & GET_RESERVE) {
n = have - slack; n = have - slack;
n = _min(use, n); n = _min(use, n);
change_reservation(u, rtype, -n); change_reservation(u, rtype->itype, -n);
} }
else if (mode & GET_SLACK) { else if (mode & GET_SLACK) {
n = _min(use, slack); n = _min(use, slack);
@ -229,23 +229,24 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
} }
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) { if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
for (v = r->units; use > 0 && v != NULL; v = v->next) for (v = r->units; use > 0 && v != NULL; v = v->next) {
if (u != v) { if (u != v) {
int mask; int mask;
if ((urace(v)->ec_flags & GIVEITEM) == 0) if ((urace(v)->ec_flags & GIVEITEM) == 0)
continue; continue;
if (v->items == NULL && rtype->uget == NULL) if (v->items == NULL && rtype->uget == NULL)
continue; continue;
if (v->faction == f) { if (v->faction == f) {
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE); mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
} }
else if (alliedunit(v, f, HELP_MONEY)) else if (alliedunit(v, f, HELP_MONEY))
mask = (mode >> 6) & (GET_SLACK | GET_RESERVE); mask = (mode >> 6) & (GET_SLACK | GET_RESERVE);
else else
continue; continue;
use -= use_pooled(v, rtype, mask, use); use -= use_pooled(v, rtype, mask, use);
} }
}
} }
return count - use; return count - use;
} }

View File

@ -24,6 +24,7 @@ extern "C" {
struct unit; struct unit;
struct resource_type; struct resource_type;
struct item_type;
struct region; struct region;
/* bitfield values for get/use/change operations */ /* bitfield values for get/use/change operations */
@ -54,11 +55,11 @@ extern "C" {
int change_resource(struct unit *u, const struct resource_type *res, int change_resource(struct unit *u, const struct resource_type *res,
int change); int change);
int get_reservation(const struct unit *u, const struct resource_type *res); int get_reservation(const struct unit *u, const struct item_type *res);
int change_reservation(struct unit *u, const struct resource_type *res, int change_reservation(struct unit *u, const struct item_type *res,
int value); int value);
int set_resvalue(struct unit * u, const struct resource_type * rtype, int value); int set_resvalue(struct unit * u, const struct item_type * rtype, int value);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -30,10 +30,10 @@ void test_reservation(CuTest *tc) {
assert(u); assert(u);
i_change(&u->items, rtype->itype, 100); i_change(&u->items, rtype->itype, 100);
CuAssertIntEquals(tc, 100, get_resource(u, rtype)); CuAssertIntEquals(tc, 100, get_resource(u, rtype));
CuAssertIntEquals(tc, 0, get_reservation(u, rtype)); CuAssertIntEquals(tc, 0, get_reservation(u, rtype->itype));
CuAssertIntEquals(tc, 50, change_reservation(u, rtype, 50)); CuAssertIntEquals(tc, 50, change_reservation(u, rtype->itype, 50));
CuAssertIntEquals(tc, 100, change_reservation(u, rtype, 50)); CuAssertIntEquals(tc, 100, change_reservation(u, rtype->itype, 50));
CuAssertIntEquals(tc, 50, set_resvalue(u, rtype, 50)); CuAssertIntEquals(tc, 50, set_resvalue(u, rtype->itype, 50));
CuAssertIntEquals(tc, 100, get_resource(u, rtype)); CuAssertIntEquals(tc, 100, get_resource(u, rtype));
CuAssertIntEquals(tc, 200, change_resource(u, rtype, 100)); CuAssertIntEquals(tc, 200, change_resource(u, rtype, 100));
CuAssertIntEquals(tc, 200, get_resource(u, rtype)); CuAssertIntEquals(tc, 200, get_resource(u, rtype));
@ -61,11 +61,11 @@ void test_pool(CuTest *tc) {
u3 = test_create_unit(test_create_faction(0), r); u3 = test_create_unit(test_create_faction(0), r);
assert(u1 && u2); assert(u1 && u2);
i_change(&u1->items, rtype->itype, 100); i_change(&u1->items, rtype->itype, 100);
set_resvalue(u1, rtype, 50); set_resvalue(u1, rtype->itype, 50);
i_change(&u2->items, rtype->itype, 200); i_change(&u2->items, rtype->itype, 200);
set_resvalue(u2, rtype, 100); set_resvalue(u2, rtype->itype, 100);
i_change(&u3->items, rtype->itype, 400); i_change(&u3->items, rtype->itype, 400);
set_resvalue(u3, rtype, 200); set_resvalue(u3, rtype->itype, 200);
CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, 40)); CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, 40));
CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, INT_MAX)); CuAssertIntEquals(tc, 50, get_pooled(u1, rtype, GET_SLACK, INT_MAX));
@ -112,46 +112,45 @@ void test_pool_use(CuTest *tc) {
unit *u1, *u2, *u3; unit *u1, *u2, *u3;
faction *f; faction *f;
region *r; region *r;
struct resource_type *rtype; struct item_type *itype;
ally *al; ally *al;
test_cleanup(); test_cleanup();
test_create_world(); test_create_world();
rtype = rt_get_or_create("money"); itype = it_get_or_create(rt_get_or_create("money"));
it_get_or_create(rtype);
f = test_create_faction(0); f = test_create_faction(0);
r = findregion(0, 0); r = findregion(0, 0);
assert(r && f && rtype && rtype->itype); assert(r && f && itype);
u1 = test_create_unit(f, r); u1 = test_create_unit(f, r);
u2 = test_create_unit(f, r); u2 = test_create_unit(f, r);
u3 = test_create_unit(test_create_faction(0), r); u3 = test_create_unit(test_create_faction(0), r);
assert(u1 && u2); assert(u1 && u2);
i_change(&u1->items, rtype->itype, 100); i_change(&u1->items, itype, 100);
set_resvalue(u1, rtype, 50); set_resvalue(u1, itype, 50);
i_change(&u2->items, rtype->itype, 200); i_change(&u2->items, itype, 200);
set_resvalue(u2, rtype, 100); set_resvalue(u2, itype, 100);
i_change(&u3->items, rtype->itype, 400); i_change(&u3->items, itype, 400);
set_resvalue(u3, rtype, 200); set_resvalue(u3, itype, 200);
al = ally_add(&u3->faction->allies, f); al = ally_add(&u3->faction->allies, f);
al->status = HELP_MONEY; al->status = HELP_MONEY;
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_SLACK, 10)); CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_SLACK, 10));
CuAssertIntEquals(tc, 40, use_pooled(u1, rtype, GET_SLACK, 50)); CuAssertIntEquals(tc, 40, use_pooled(u1, itype->rtype, GET_SLACK, 50));
CuAssertIntEquals(tc, 50, i_get(u1->items, rtype->itype)); CuAssertIntEquals(tc, 50, i_get(u1->items, itype));
CuAssertIntEquals(tc, 50, get_reservation(u1, rtype)); CuAssertIntEquals(tc, 50, get_reservation(u1, itype));
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_RESERVE, 10)); CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_RESERVE, 10));
CuAssertIntEquals(tc, 40, i_get(u1->items, rtype->itype)); CuAssertIntEquals(tc, 40, i_get(u1->items, itype));
CuAssertIntEquals(tc, 40, get_reservation(u1, rtype)); CuAssertIntEquals(tc, 40, get_reservation(u1, itype));
CuAssertIntEquals(tc, 40, use_pooled(u1, rtype, GET_RESERVE, 50)); CuAssertIntEquals(tc, 40, use_pooled(u1, itype->rtype, GET_RESERVE, 50));
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_POOLED_SLACK, 10)); CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_POOLED_SLACK, 10));
CuAssertIntEquals(tc, 90, use_pooled(u1, rtype, GET_POOLED_SLACK, 100)); CuAssertIntEquals(tc, 90, use_pooled(u1, itype->rtype, GET_POOLED_SLACK, 100));
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype)); CuAssertIntEquals(tc, 100, i_get(u2->items, itype));
CuAssertIntEquals(tc, 10, use_pooled(u1, rtype, GET_POOLED_RESERVE, 10)); CuAssertIntEquals(tc, 10, use_pooled(u1, itype->rtype, GET_POOLED_RESERVE, 10));
CuAssertIntEquals(tc, 90, get_reservation(u2, rtype)); CuAssertIntEquals(tc, 90, get_reservation(u2, itype));
CuAssertIntEquals(tc, 90, use_pooled(u1, rtype, GET_POOLED_RESERVE, 100)); CuAssertIntEquals(tc, 90, use_pooled(u1, itype->rtype, GET_POOLED_RESERVE, 100));
CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype)); CuAssertIntEquals(tc, 0, i_get(u2->items, itype));
} }
void test_change_resource(CuTest * tc) void test_change_resource(CuTest * tc)

View File

@ -154,6 +154,9 @@ static race *rc_find_i(const char *name)
while (rc && !strcmp(rname, rc->_name) == 0) { while (rc && !strcmp(rname, rc->_name) == 0) {
rc = rc->next; rc = rc->next;
} }
if (!rc && strcmp(name, "uruk") == 0) {
rc = rc_find_i("orc");
}
return rc; return rc;
} }

View File

@ -401,25 +401,25 @@ void read_items(struct storage *store, item ** ilist)
{ {
for (;;) { for (;;) {
char ibuf[32]; char ibuf[32];
const resource_type *rtype; const item_type *itype;
int i; int i;
READ_STR(store, ibuf, sizeof(ibuf)); READ_STR(store, ibuf, sizeof(ibuf));
if (!strcmp("end", ibuf)) { if (!strcmp("end", ibuf)) {
break; break;
} }
rtype = rt_find(ibuf); itype = it_find(ibuf);
READ_INT(store, &i); READ_INT(store, &i);
if (i <= 0) { if (i <= 0) {
log_error("data contains an entry with %d %s\n", i, resourcename(rtype, NMF_PLURAL)); log_error("data contains an entry with %d %s\n", i, resourcename(itype->rtype, NMF_PLURAL));
} }
else { else {
if (rtype && rtype->itype) { if (itype && itype->rtype) {
i_change(ilist, rtype->itype, i); i_change(ilist, itype, i);
} }
else { else {
log_error("data contains unknown item type %s.\n", ibuf); log_error("data contains unknown item type %s.\n", ibuf);
} }
assert(rtype && rtype->itype); assert(itype && itype->rtype);
} }
} }
} }

View File

@ -73,7 +73,7 @@ extern "C" {
typedef struct reservation { typedef struct reservation {
struct reservation *next; struct reservation *next;
const struct resource_type *type; const struct item_type *type;
int value; int value;
} reservation; } reservation;

View File

@ -74,7 +74,7 @@
#define SAVEGAMEID_VERSION 343 /* instead of XMLNAME, save the game.id parameter from the config */ #define SAVEGAMEID_VERSION 343 /* instead of XMLNAME, save the game.id parameter from the config */
#define BUILDNO_VERSION 344 /* storing the build number in the save */ #define BUILDNO_VERSION 344 /* storing the build number in the save */
#define AUTO_RACENAME_VERSION 345 /* NPC units with name==NULL will automatically get their race for a name */ #define AUTO_RACENAME_VERSION 345 /* NPC units with name==NULL will automatically get their race for a name */
#define MIN_VERSION CURSETYPE_VERSION /* minimal datafile we support */ #define MIN_VERSION INTPAK_VERSION /* minimal datafile we support */
#define RELEASE_VERSION AUTO_RACENAME_VERSION /* current datafile */ #define RELEASE_VERSION AUTO_RACENAME_VERSION /* current datafile */
#define STREAM_VERSION 2 /* internal encoding of binary files */ #define STREAM_VERSION 2 /* internal encoding of binary files */

View File

@ -1972,7 +1972,7 @@ int mail_cmd(unit * u, struct order *ord)
case P_REGION: case P_REGION:
/* können alle Einheiten in der Region sehen */ /* können alle Einheiten in der Region sehen */
s = getstrtoken(); s = getstrtoken();
if (!s[0]) { if (!s || !s[0]) {
cmistake(u, ord, 30, MSG_MESSAGE); cmistake(u, ord, 30, MSG_MESSAGE);
break; break;
} }
@ -2141,7 +2141,7 @@ int email_cmd(unit * u, struct order *ord)
init_order(ord); init_order(ord);
s = getstrtoken(); s = getstrtoken();
if (!s[0]) { if (!s || !s[0]) {
cmistake(u, ord, 85, MSG_EVENT); cmistake(u, ord, 85, MSG_EVENT);
} }
else { else {
@ -3850,7 +3850,7 @@ static int reserve_i(unit * u, struct order *ord, int flags)
{ {
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) { if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
int use, count, para; int use, count, para;
const resource_type *rtype; const item_type *itype;
const char *s; const char *s;
init_order(ord); init_order(ord);
@ -3862,19 +3862,19 @@ static int reserve_i(unit * u, struct order *ord, int flags)
count = getint() * u->number; count = getint() * u->number;
} }
s = getstrtoken(); s = getstrtoken();
rtype = s ? findresourcetype(s, u->faction->locale) : 0; itype = s ? finditemtype(s, u->faction->locale) : 0;
if (rtype == NULL) if (itype == NULL)
return 0; return 0;
set_resvalue(u, rtype, 0); /* make sure the pool is empty */ set_resvalue(u, itype, 0); /* make sure the pool is empty */
if (count == 0 && para == P_ANY) { if (count == 0 && para == P_ANY) {
count = get_resource(u, rtype); count = get_resource(u, itype->rtype);
} }
use = use_pooled(u, rtype, flags, count); use = use_pooled(u, itype->rtype, flags, count);
if (use) { if (use) {
set_resvalue(u, rtype, use); set_resvalue(u, itype, use);
change_resource(u, rtype, use); change_resource(u, itype->rtype, use);
return use; return use;
} }
} }

View File

@ -2,7 +2,6 @@ PROJECT(modules C)
SET(_FILES SET(_FILES
arena.c arena.c
autoseed.c autoseed.c
dungeon.c
gmcmd.c gmcmd.c
museum.c museum.c
score.c score.c

View File

@ -1,273 +0,0 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <platform.h>
#include <kernel/config.h>
#if DUNGEON_MODULE
#include "dungeon.h"
#include "gmcmd.h"
#include <triggers/gate.h>
#include <triggers/unguard.h>
/* kernel includes */
#include <building.h>
#include <item.h>
#include <plane.h>
#include <race.h>
#include <region.h>
#include <skill.h>
#include <terrain.h>
#include <unit.h>
/* util includes */
#include <event.h>
#include <xml.h>
/* libc includes */
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef struct treasure {
const struct item_type *itype;
int amount;
struct treasure *next;
} treasure;
typedef struct monster {
const struct race *race;
double chance;
int maxunits;
int avgsize;
struct treasure *treasures;
struct monster *next;
struct itemtype_list *weapons;
} monster;
typedef struct skilllimit {
skill_t skill;
int minskill;
int maxskill;
struct skilllimit *next;
} skilllimit;
typedef struct dungeon {
int level;
int radius;
int size;
int maxpeople;
struct skilllimit *limits;
double connect;
struct monster *boss;
struct monster *monsters;
struct dungeon *next;
} dungeon;
dungeon *dungeonstyles;
region *make_dungeon(const dungeon * data)
{
int nb[2][3][2] = {
{{-1, 0}, {0, 1}, {1, -1}},
{{1, 0}, {-1, 1}, {0, -1}}
};
const struct race *bossrace = data->boss->race;
char name[128];
int size = data->size;
int iterations = size * size;
unsigned int flags = PFL_NORECRUITS;
int n = 0;
struct faction *fmonsters = get_monsters();
plane *p;
region *r, *center;
region *rnext;
region_list *iregion, *rlist = NULL;
const terrain_type *terrain_hell = get_terrain("hell");
assert(terrain_hell != NULL);
sprintf(name, "Die Höhlen von %s", bossrace->generate_name(NULL));
p = gm_addplane(data->radius, flags, name);
center =
findregion(p->minx + (p->maxx - p->minx) / 2,
p->miny + (p->maxy - p->miny) / 2);
assert(center);
terraform_region(center, terrain_hell);
add_regionlist(&rlist, center);
rnext = r = center;
while (size > 0 && iterations--) {
int d, o = rng_int() % 3;
for (d = 0; d != 3; ++d) {
int index = (d + o) % 3;
region *rn = findregion(r->x + nb[n][index][0], r->y + nb[n][index][1]);
assert(r->terrain == terrain_hell);
if (rn) {
if (rn->terrain == terrain_hell) {
rnext = rn;
} else if (fval(rn->terrain, SEA_REGION)) {
if (rng_int() % 100 < data->connect * 100) {
terraform_region(rn, terrain_hell);
--size;
rnext = rn;
add_regionlist(&rlist, rn);
} else
terraform(rn, T_FIREWALL);
}
if (size == 0)
break;
}
rn =
findregion(r->x + nb[(n + 1) % 2][index][0],
r->y + nb[(n + 1) % 2][index][1]);
if (rn && fval(rn->terrain, SEA_REGION)) {
terraform(rn, T_FIREWALL);
}
}
if (size == 0)
break;
if (r == rnext) {
/* error */
break;
}
r = rnext;
n = (n + 1) % 2;
}
for (iregion = rlist; iregion; iregion = iregion->next) {
monster *m = data->monsters;
region *r = iregion->data;
while (m) {
if ((rng_int() % 100) < (m->chance * 100)) {
/* TODO: check maxunits. */
treasure *loot = m->treasures;
struct itemtype_list *weapon = m->weapons;
int size = 1 + (rng_int() % m->avgsize) + (rng_int() % m->avgsize);
unit *u = createunit(r, fmonsters, size, m->race);
while (weapon) {
i_change(&u->items, weapon->type, size);
weapon = weapon->next;
}
while (loot) {
i_change(&u->items, loot->itype, loot->amount * size);
loot = loot->next;
}
}
m = m->next;
}
}
return center;
}
void make_dungeongate(region * source, region * target, const struct dungeon *d)
{
building *bsource, *btarget;
if (source == NULL || target == NULL || d == NULL)
return;
bsource = new_building(bt_find("castle"), source, default_locale);
set_string(&bsource->name, "Pforte zur Hölle");
bsource->size = 50;
add_trigger(&bsource->attribs, "timer", trigger_gate(bsource, target));
add_trigger(&bsource->attribs, "create", trigger_unguard(bsource));
fset(bsource, BLD_UNGUARDED);
btarget = new_building(bt_find("castle"), target, default_locale);
set_string(&btarget->name, "Pforte zur Außenwelt");
btarget->size = 50;
add_trigger(&btarget->attribs, "timer", trigger_gate(btarget, source));
add_trigger(&btarget->attribs, "create", trigger_unguard(btarget));
fset(btarget, BLD_UNGUARDED);
}
static int tagbegin(xml_stack * stack)
{
xml_tag *tag = stack->tag;
if (strcmp(tag->name, "dungeon") == 0) {
dungeon *d = (dungeon *) calloc(sizeof(dungeon), 1);
d->maxpeople = xml_ivalue(tag, "maxpeople");
if (d->maxpeople == 0)
d->maxpeople = INT_MAX;
d->level = xml_ivalue(tag, "level");
d->radius = xml_ivalue(tag, "radius");
d->connect = xml_fvalue(tag, "connect");
d->size = xml_ivalue(tag, "size");
stack->state = d;
} else {
dungeon *d = (dungeon *) stack->state;
if (strcmp(tag->name, "skilllimit") == 0) {
skill_t sk = findskill(xml_value(tag, "name"));
if (sk != NOSKILL) {
skilllimit *skl = calloc(sizeof(skilllimit), 1);
skl->skill = sk;
if (xml_value(tag, "max") != NULL) {
skl->maxskill = xml_ivalue(tag, "max");
} else
skl->maxskill = INT_MAX;
if (xml_value(tag, "min") != NULL) {
skl->minskill = xml_ivalue(tag, "min");
} else
skl->maxskill = INT_MIN;
skl->next = d->limits;
d->limits = skl;
}
} else if (strcmp(tag->name, "monster") == 0) {
monster *m = calloc(sizeof(monster), 1);
m->race = rc_find(xml_value(tag, "race"));
m->chance = xml_fvalue(tag, "chance");
m->avgsize = _max(1, xml_ivalue(tag, "size"));
m->maxunits = _min(1, xml_ivalue(tag, "maxunits"));
if (m->race) {
if (xml_bvalue(tag, "boss")) {
d->boss = m;
} else {
m->next = d->monsters;
d->monsters = m;
}
}
} else if (strcmp(tag->name, "weapon") == 0) {
monster *m = d->monsters;
itemtype_list *w = calloc(sizeof(itemtype_list), 1);
w->type = it_find(xml_value(tag, "type"));
if (w->type) {
w->next = m->weapons;
m->weapons = w;
}
}
}
return XML_OK;
}
static int tagend(xml_stack * stack)
{
xml_tag *tag = stack->tag;
if (strcmp(tag->name, "dungeon")) {
dungeon *d = (dungeon *) stack->state;
stack->state = NULL;
d->next = dungeonstyles;
dungeonstyles = d;
}
return XML_OK;
}
xml_callbacks xml_dungeon = {
tagbegin, tagend, NULL
};
void register_dungeon(void)
{
xml_register(&xml_dungeon, "eressea dungeon", 0);
}
#endif

View File

@ -1,37 +0,0 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef H_MOD_DUNGEON
#define H_MOD_DUNGEON
#ifdef __cplusplus
extern "C" {
#endif
#if DUNGEON_MODULE == 0
#error "must define DUNGEON_MODULE to use this module"
#endif
struct region;
struct plane;
struct building;
struct dungeon;
extern struct dungeon *dungeonstyles;
extern struct region *make_dungeon(const struct dungeon *);
extern void make_dungeongate(struct region *source, struct region *target,
const struct dungeon *);
extern void register_dungeon(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -41,7 +41,6 @@
#define SCORE_MODULE 1 #define SCORE_MODULE 1
#define MUSEUM_MODULE 1 #define MUSEUM_MODULE 1
#define ARENA_MODULE 1 #define ARENA_MODULE 1
#define DUNGEON_MODULE 0
#define CHANGED_CROSSBOWS 0 /* use the WTF_ARMORPIERCING flag */ #define CHANGED_CROSSBOWS 0 /* use the WTF_ARMORPIERCING flag */
#undef GLOBAL_WARMING /* number of turns before global warming sets in */ #undef GLOBAL_WARMING /* number of turns before global warming sets in */

View File

@ -95,13 +95,18 @@ skill_t get_skill(const char *s, const struct locale * lang)
if (s) { if (s) {
char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s); char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
int i; if (str) {
const void * match; int i;
void **tokens = get_translations(lang, UT_SKILLS); const void * match;
struct critbit_tree *cb = (critbit_tree *)*tokens; void **tokens = get_translations(lang, UT_SKILLS);
if (cb && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { struct critbit_tree *cb = (critbit_tree *)*tokens;
cb_get_kv(match, &i, sizeof(int)); if (cb && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
result = (skill_t)i; cb_get_kv(match, &i, sizeof(int));
result = (skill_t)i;
}
}
else {
log_warning("could not transliterate skill: %s", s);
} }
} }
return result; return result;

View File

@ -4736,7 +4736,7 @@ int sp_clonecopy(castorder * co)
create_newclone(mage, clone); create_newclone(mage, clone);
msg = msg_message("sp_clone_effet", "mage", mage); msg = msg_message("sp_clone_effect", "mage", mage);
r_addmessage(r, mage->faction, msg); r_addmessage(r, mage->faction, msg);
msg_release(msg); msg_release(msg);

View File

@ -5,78 +5,87 @@
#include <util/log.h> #include <util/log.h>
#pragma warning(disable: 4210) #pragma warning(disable: 4210)
#define ADD_TESTS(suite, name) \
CuSuite *get_##name##_suite(void); \ void RunTests(CuSuite * suite, const char *name) {
CuSuite *name = get_##name##_suite(); \ CuString *output = CuStringNew();
CuSuiteAddSuite(suite, name);
CuSuiteRun(suite);
CuSuiteDetails(suite, output);
if (suite->failCount) CuSuiteSummary(suite, output);
printf("%s: %s", name, output->buffer);
CuStringDelete(output);
}
#define RUN_TESTS(suite, name) \
CuSuite *get_##name##_suite(void); \
CuSuite *name = get_##name##_suite(); \
RunTests(name, #name); \
suite->failCount += name->failCount; \
suite->count += name->count; \
CuSuiteDelete(name);
int RunAllTests(void) int RunAllTests(void)
{ {
CuString *output = CuStringNew();
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
int result, flags = log_flags; int fail_count, flags = log_flags;
log_flags = LOG_FLUSH | LOG_CPERROR; log_flags = LOG_FLUSH | LOG_CPERROR;
kernel_init(); kernel_init();
/* self-test */ /* self-test */
ADD_TESTS(suite, tests); RUN_TESTS(suite, tests);
ADD_TESTS(suite, callback); RUN_TESTS(suite, callback);
ADD_TESTS(suite, json); RUN_TESTS(suite, json);
ADD_TESTS(suite, jsonconf); RUN_TESTS(suite, jsonconf);
ADD_TESTS(suite, direction); RUN_TESTS(suite, direction);
ADD_TESTS(suite, skill); RUN_TESTS(suite, skill);
ADD_TESTS(suite, keyword); RUN_TESTS(suite, keyword);
ADD_TESTS(suite, order); RUN_TESTS(suite, order);
ADD_TESTS(suite, race); RUN_TESTS(suite, race);
/* util */ /* util */
ADD_TESTS(suite, config); RUN_TESTS(suite, config);
ADD_TESTS(suite, attrib); RUN_TESTS(suite, attrib);
ADD_TESTS(suite, base36); RUN_TESTS(suite, base36);
ADD_TESTS(suite, bsdstring); RUN_TESTS(suite, bsdstring);
ADD_TESTS(suite, functions); RUN_TESTS(suite, functions);
ADD_TESTS(suite, umlaut); RUN_TESTS(suite, umlaut);
ADD_TESTS(suite, unicode); RUN_TESTS(suite, unicode);
ADD_TESTS(suite, strings); RUN_TESTS(suite, strings);
/* kernel */ /* kernel */
ADD_TESTS(suite, alliance); RUN_TESTS(suite, alliance);
ADD_TESTS(suite, unit); RUN_TESTS(suite, unit);
ADD_TESTS(suite, faction); RUN_TESTS(suite, faction);
ADD_TESTS(suite, group); RUN_TESTS(suite, group);
ADD_TESTS(suite, build); RUN_TESTS(suite, build);
ADD_TESTS(suite, pool); RUN_TESTS(suite, pool);
ADD_TESTS(suite, curse); RUN_TESTS(suite, curse);
ADD_TESTS(suite, equipment); RUN_TESTS(suite, equipment);
ADD_TESTS(suite, item); RUN_TESTS(suite, item);
ADD_TESTS(suite, magic); RUN_TESTS(suite, magic);
ADD_TESTS(suite, reports); RUN_TESTS(suite, reports);
ADD_TESTS(suite, save); RUN_TESTS(suite, save);
ADD_TESTS(suite, ship); RUN_TESTS(suite, ship);
ADD_TESTS(suite, spellbook); RUN_TESTS(suite, spellbook);
ADD_TESTS(suite, building); RUN_TESTS(suite, building);
ADD_TESTS(suite, spell); RUN_TESTS(suite, spell);
ADD_TESTS(suite, ally); RUN_TESTS(suite, ally);
/* gamecode */ /* gamecode */
ADD_TESTS(suite, battle); RUN_TESTS(suite, battle);
ADD_TESTS(suite, economy); RUN_TESTS(suite, economy);
ADD_TESTS(suite, give); RUN_TESTS(suite, give);
ADD_TESTS(suite, laws); RUN_TESTS(suite, laws);
ADD_TESTS(suite, market); RUN_TESTS(suite, market);
ADD_TESTS(suite, move); RUN_TESTS(suite, move);
ADD_TESTS(suite, stealth); RUN_TESTS(suite, stealth);
ADD_TESTS(suite, upkeep); RUN_TESTS(suite, upkeep);
ADD_TESTS(suite, vortex); RUN_TESTS(suite, vortex);
ADD_TESTS(suite, wormhole); RUN_TESTS(suite, wormhole);
CuSuiteRun(suite); printf("\ntest summary: %d tests, %d failed\n", suite->count, suite->failCount);
CuSuiteSummary(suite, output); log_flags = flags;
CuSuiteDetails(suite, output); fail_count = suite->failCount;
printf("%s\n", output->buffer); CuSuiteDelete(suite);
return fail_count;
log_flags = flags;
result = suite->failCount;
CuSuiteDelete(suite);
return result;
} }
int main(int argc, char ** argv) { int main(int argc, char ** argv) {

View File

@ -20,8 +20,6 @@ static void test_resources(CuTest *tc) {
CuAssertPtrEquals(tc, rt_find("aura"), (void *)get_resourcetype(R_AURA)); CuAssertPtrEquals(tc, rt_find("aura"), (void *)get_resourcetype(R_AURA));
CuAssertPtrNotNull(tc, rt_find("permaura")); CuAssertPtrNotNull(tc, rt_find("permaura"));
CuAssertPtrEquals(tc, rt_find("permaura"), (void *)get_resourcetype(R_PERMAURA)); CuAssertPtrEquals(tc, rt_find("permaura"), (void *)get_resourcetype(R_PERMAURA));
CuAssertPtrNotNull(tc, rt_find("unit"));
CuAssertPtrEquals(tc, rt_find("unit"), (void *)get_resourcetype(R_UNIT));
CuAssertPtrEquals(tc, 0, rt_find("stone")); CuAssertPtrEquals(tc, 0, rt_find("stone"));
rtype = rt_get_or_create("stone"); rtype = rt_get_or_create("stone");
@ -55,7 +53,6 @@ static void test_recreate_world(CuTest * tc)
CuAssertPtrNotNull(tc, get_resourcetype(R_AURA)); CuAssertPtrNotNull(tc, get_resourcetype(R_AURA));
CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA)); CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA));
CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT)); CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT));
CuAssertPtrNotNull(tc, get_resourcetype(R_UNIT));
test_cleanup(); test_cleanup();
CuAssertPtrEquals(tc, 0, get_locale("de")); CuAssertPtrEquals(tc, 0, get_locale("de"));
@ -67,7 +64,6 @@ static void test_recreate_world(CuTest * tc)
CuAssertPtrNotNull(tc, get_resourcetype(R_AURA)); CuAssertPtrNotNull(tc, get_resourcetype(R_AURA));
CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA)); CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA));
CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT)); CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT));
CuAssertPtrNotNull(tc, get_resourcetype(R_UNIT));
CuAssertPtrEquals(tc, 0, findregion(0, 0)); CuAssertPtrEquals(tc, 0, findregion(0, 0));
} }

View File

@ -42,9 +42,13 @@ const char *escape_string(const char *str, char *buffer,
char *o; char *o;
size_t skip = start - str; size_t skip = start - str;
if (skip > len) {
skip = len;
}
memcpy(buffer, str, skip); memcpy(buffer, str, skip);
o = buffer + skip; o = buffer + skip;
p = str + skip; p = str + skip;
len -= skip;
do { do {
if (*p == '\"' || *p == '\\') { if (*p == '\"' || *p == '\\') {
if (len < 2) { if (len < 2) {

View File

@ -7,6 +7,9 @@
static void test_escape_string(CuTest * tc) static void test_escape_string(CuTest * tc)
{ {
char scratch[64]; char scratch[64];
CuAssertStrEquals(tc, "12345678901234567890", escape_string("12345678901234567890", scratch, 16));
CuAssertStrEquals(tc, "123456789\\\"12345", escape_string("123456789\"1234567890", scratch, 16));
CuAssertStrEquals(tc, "1234567890123456", escape_string("1234567890123456\"890", scratch, 16));
CuAssertStrEquals(tc, "hello world", escape_string("hello world", scratch, sizeof(scratch))); CuAssertStrEquals(tc, "hello world", escape_string("hello world", scratch, sizeof(scratch)));
CuAssertStrEquals(tc, "hello \\\"world\\\"", escape_string("hello \"world\"", scratch, sizeof(scratch))); CuAssertStrEquals(tc, "hello \\\"world\\\"", escape_string("hello \"world\"", scratch, sizeof(scratch)));
CuAssertStrEquals(tc, "\\\"\\\\", escape_string("\"\\", scratch, sizeof(scratch))); CuAssertStrEquals(tc, "\\\"\\\\", escape_string("\"\\", scratch, sizeof(scratch)));