messy merge of cppcheck fixes into develop

This commit is contained in:
Enno Rehling 2018-02-25 20:41:53 +01:00
commit 432a8d432d
83 changed files with 363 additions and 576 deletions

View File

@ -38,6 +38,8 @@ else (MSVC)
find_package (Curses)
endif (MSVC)
find_package (Readline)
if (ERESSEA_DB STREQUAL "db")
find_package (BerkeleyDB REQUIRED QUIET)
else()

View File

@ -0,0 +1,47 @@
# - Try to find readline include dirs and libraries
#
# Usage of this module as follows:
#
# find_package(Readline)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# READLINE_ROOT_DIR Set this variable to the root installation of
# readline if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# READLINE_FOUND System has readline, include and lib dirs found
# READLINE_INCLUDE_DIR The readline include directories.
# READLINE_LIBRARY The readline library.
find_path(READLINE_ROOT_DIR
NAMES include/readline/readline.h
)
find_path(READLINE_INCLUDE_DIR
NAMES readline/readline.h
HINTS ${READLINE_ROOT_DIR}/include
)
find_library(READLINE_LIBRARY
NAMES readline
HINTS ${READLINE_ROOT_DIR}/lib
)
if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY)
set(READLINE_FOUND TRUE)
else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY)
FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND Ncurses_LIBRARY)
mark_as_advanced(
READLINE_ROOT_DIR
READLINE_INCLUDE_DIR
READLINE_LIBRARY
)

View File

@ -1,3 +1,8 @@
#!/bin/sh
cppcheck -U_MSC_VER --enable=all -IcJSON -Isrc -Iclibs -Istorage src
IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }')
cppcheck $IGNORE \
--quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \
-UERESSEA_BUILDNO -UERESSEA_VERSION \
-IcJSON -Isrc -Iclibs -Istorage src

View File

@ -293,6 +293,12 @@ target_link_libraries(test_eressea ${DB_LIBRARIES})
add_definitions(-DUSE_DB)
endif(SQLITE3_FOUND)
if (READLINE_FOUND)
include_directories (${READLINE_INCLUDE_DIR})
target_link_libraries(eressea ${READLINE_LIBRARY})
add_definitions(-DUSE_READLINE)
endif (READLINE_FOUND)
if (CURSES_FOUND)
include_directories (${CURSES_INCLUDE_DIR})
target_link_libraries(eressea ${CURSES_LIBRARIES})

View File

@ -52,13 +52,7 @@ typedef struct dict_data {
char *name;
union {
int i;
char *str;
double real;
struct unit *u;
struct region *r;
struct building *b;
struct ship *sh;
struct faction *f;
} data;
} dict_data;

View File

@ -86,7 +86,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TACTICS_MODIFIER 1 /* modifier for generals in the front/rear */
#define CATAPULT_INITIAL_RELOAD 4 /* erster schuss in runde 1 + rng_int() % INITIAL */
#define CATAPULT_STRUCTURAL_DAMAGE
#define BASE_CHANCE 70 /* 70% Basis-<2D>berlebenschance */
#define TDIFF_CHANGE 5 /* 5% h<>her pro Stufe */
@ -393,7 +392,6 @@ static int get_row(const side * s, int row, const side * vs)
int line, result;
int retreat = 0;
int size[NUMROWS];
int front = 0;
battle *b = s->battle;
memset(counted, 0, sizeof(counted));
@ -426,6 +424,7 @@ static int get_row(const side * s, int row, const side * vs)
break;
}
if (enemyfront) {
int front = 0;
for (line = FIRST_ROW; line != NUMROWS; ++line) {
front += size[line];
if (!front || front < enemyfront / ROW_FACTOR)
@ -1157,7 +1156,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
/* Schild */
side *ds = df->side;
int hp, ar;
int ar;
const weapon_type *dwtype = NULL;
const weapon_type *awtype = NULL;
@ -1272,7 +1271,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
/* jeder Schaden wird um effect% reduziert bis der Schild duration
* Trefferpunkte aufgefangen hat */
if (me->typ == SHIELD_REDUCE) {
hp = rda * (me->effect / 100);
int hp = rda * (me->effect / 100);
rda -= hp;
me->duration -= hp;
}
@ -2886,12 +2885,9 @@ static void print_stats(battle * b)
{
side *s2;
side *s;
int i = 0;
for (s = b->sides; s != b->sides + b->nsides; ++s) {
bfaction *bf;
++i;
for (bf = b->factions; bf; bf = bf->next) {
faction *f = bf->faction;
const char *loc_army = LOC(f->locale, "battle_army");
@ -3057,8 +3053,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
{
#define WMAX 20
weapon weapons[WMAX];
int owp[WMAX];
int dwp[WMAX];
region *r = b->region;
item *itm;
fighter *fig = NULL;
@ -3171,6 +3165,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
/* F<>r alle Waffengattungen wird bestimmt, wie viele der Personen mit
* ihr k<EFBFBD>mpfen k<EFBFBD>nnten, und was ihr Wert darin ist. */
if (u_race(u)->battle_flags & BF_EQUIPMENT) {
int owp[WMAX];
int dwp[WMAX];
int oi = 0, di = 0, w = 0;
for (itm = u->items; itm && w != WMAX; itm = itm->next) {
const weapon_type *wtype = resource2weapon(itm->type->rtype);
@ -3491,7 +3487,6 @@ static int battle_report(battle * b)
{
side *s, *s2;
bool cont = false;
bool komma;
bfaction *bf;
for (s = b->sides; s != b->sides + b->nsides; ++s) {
@ -3514,6 +3509,7 @@ static int battle_report(battle * b)
char buf[32 * MAXSIDES];
message *m;
sbstring sbs;
bool komma = false;
sbs_init(&sbs, buf, sizeof(buf));
battle_message_faction(b, fac, msg_separator);
@ -3525,7 +3521,6 @@ static int battle_report(battle * b)
battle_message_faction(b, fac, m);
msg_release(m);
komma = false;
for (s = b->sides; s != b->sides + b->nsides; ++s) {
if (s->alive) {
int r, k = 0, *alive = get_alive(s);

View File

@ -116,10 +116,12 @@ static void test_defenders_get_building_bonus(CuTest * tc)
at.index = 0;
bld->size = 10; /* stage 1 building */
CuAssertIntEquals(tc, 1, buildingeffsize(bld, false));
CuAssertIntEquals(tc, -1, skilldiff(at, dt, 0));
CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0));
bld->size = 1; /* stage 0 building */
CuAssertIntEquals(tc, 0, buildingeffsize(bld, false));
CuAssertIntEquals(tc, 0, skilldiff(at, dt, 0));
CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0));
@ -281,8 +283,10 @@ static void test_calculate_armor(CuTest * tc)
b = NULL;
i_change(&du->items, ibelt, 1);
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "without natural armor", 0, natural_armor(du));
CuAssertIntEquals_Msg(tc, "magical armor", 1, calculate_armor(dt, 0, 0, 0));
rc->armor = 2;
CuAssertIntEquals_Msg(tc, "with natural armor", 2, natural_armor(du));
CuAssertIntEquals_Msg(tc, "natural armor", 3, calculate_armor(dt, 0, 0, 0));
rc->armor = 0;
free_battle(b);
@ -446,7 +450,6 @@ static void test_battle_skilldiff(CuTest *tc)
td.index = 0;
ta.fighter = setup_fighter(&b, ua);
ta.index = 0;
ua = test_create_unit(test_create_faction(NULL), r);
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
ta.fighter->person[0].attack = 2;
@ -483,7 +486,6 @@ static void test_battle_skilldiff_building(CuTest *tc)
td.index = 0;
ta.fighter = setup_fighter(&b, ua);
ta.index = 0;
ua = test_create_unit(test_create_faction(NULL), r);
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
ud->building->size = 10;
@ -502,8 +504,8 @@ static void test_battle_skilldiff_building(CuTest *tc)
static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax)
{
skill *sv = unit_skill(u, sk);
char buf[256];
if (sv) {
char buf[256];
sprintf(buf, "%s level %d != %d", msg, sv->level, level);
CuAssertIntEquals_Msg(tc, buf, level, sv->level);
sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax);

View File

@ -63,11 +63,11 @@ int config_parse(const char *json)
int config_read(const char *filename, const char * relpath)
{
char name[PATH_MAX];
FILE *F;
json_relpath = relpath;
if (relpath) {
char name[PATH_MAX];
path_join(relpath, filename, name, sizeof(name));
F = fopen(name, "r");
}

View File

@ -29,7 +29,7 @@
#define lua_strlen(L, idx) lua_rawlen(L, idx)
#endif
#if defined(LUA_USE_READLINE)
#ifdef LUA_USE_READLINE
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
@ -58,7 +58,7 @@ static int lua_readline(lua_State * l, char *b, const char *prompt)
}
}
void set_readline(readline foo)
void set_readline(readline_fun foo)
{
my_readline = foo;
}
@ -190,7 +190,6 @@ static int pushline(lua_State * L, int firstline)
lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */
else
lua_pushstring(L, b);
lua_freeline(L, b);
return 1;
}

View File

@ -30,8 +30,8 @@ extern "C" {
extern int lua_console(struct lua_State *L);
extern int lua_do(struct lua_State *L);
typedef int (*readline) (struct lua_State *, char *, size_t, const char *);
extern void set_readline(readline foo);
typedef int (*readline_fun) (struct lua_State *, char *, size_t, const char *);
extern void set_readline(readline_fun foo);
#ifdef __cplusplus
}

View File

@ -1511,6 +1511,31 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
}
}
static void report_itemtype(FILE *F, faction *f, const item_type *itype) {
const char *ch;
const char *description = NULL;
const char *pname = resourcename(itype->rtype, 0);
const char *potiontext = mkname("potion", pname);
ch = resourcename(itype->rtype, 0);
fprintf(F, "TRANK %d\n", str_hash(ch));
fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch)));
fprintf(F, "%d;Stufe\n", potion_level(itype));
description = LOC(f->locale, potiontext);
fprintf(F, "\"%s\";Beschr\n", description);
if (itype->construction) {
requirement *m = itype->construction->materials;
fprintf(F, "ZUTATEN\n");
while (m->number) {
ch = resourcename(m->rtype, 0);
fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch)));
m++;
}
}
}
/* main function of the creport. creates the header and traverses all regions */
static int
report_computer(const char *filename, report_context * ctx, const char *bom)
@ -1655,33 +1680,9 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
a = a->next) {
const item_type *itype = (const item_type *)a->data.v;
const char *ch;
const char *description = NULL;
if (itype == NULL)
continue;
ch = resourcename(itype->rtype, 0);
fprintf(F, "TRANK %d\n", str_hash(ch));
fprintf(F, "\"%s\";Name\n", translate(ch, LOC(f->locale, ch)));
fprintf(F, "%d;Stufe\n", potion_level(itype));
if (description == NULL) {
const char *pname = resourcename(itype->rtype, 0);
const char *potiontext = mkname("potion", pname);
description = LOC(f->locale, potiontext);
}
fprintf(F, "\"%s\";Beschr\n", description);
if (itype->construction) {
requirement *m = itype->construction->materials;
fprintf(F, "ZUTATEN\n");
while (m->number) {
ch = resourcename(m->rtype, 0);
fprintf(F, "\"%s\"\n", translate(ch, LOC(f->locale, ch)));
m++;
}
if (itype) {
report_itemtype(F, f, itype);
}
}

View File

@ -13,7 +13,7 @@ static void test_add_donation(CuTest *tc) {
region *r;
test_setup();
mt_register(mt_new_va("donation", "from:faction", "to:faction", "amount:int", NULL));
mt_register(mt_new_va("donation", "from:faction", "to:faction", "amount:int", MT_NEW_END));
r = test_create_region(0, 0, NULL);
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);

View File

@ -141,11 +141,11 @@ static void scramble(void *data, unsigned int n, size_t width)
}
}
unsigned int expand_production(region * r, econ_request * requests, econ_request ***results)
int expand_production(region * r, econ_request * requests, econ_request ***results)
{
unit *u;
econ_request *o;
unsigned int norders = 0;
int norders = 0;
/* Alle Units ohne production haben ein -1, alle units mit orders haben ein
* 0 hier stehen */
@ -190,7 +190,7 @@ static void free_requests(econ_request *requests) {
}
}
static unsigned int expandorders(region * r, econ_request * requests) {
static int expandorders(region * r, econ_request * requests) {
return expand_production(r, requests, &g_requests);
}
@ -388,8 +388,7 @@ void free_recruitments(recruitment * recruits)
/* Rekrutierung */
static void expandrecruit(region * r, econ_request * recruitorders)
{
recruitment *recruits = NULL;
recruitment *recruits;
int orc_total = 0;
/* peasant limited: */
@ -430,12 +429,10 @@ static int recruit_cost(const faction * f, const race * rc)
static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
{
region *r = u->region;
plane *pl;
econ_request *o;
int recruitcost = -1;
const faction *f = u->faction;
const struct race *rc = u_race(u);
const char *str;
int n;
init_order_depr(ord);
@ -447,6 +444,8 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
if (u->number == 0) {
char token[128];
const char *str;
str = gettoken(token, sizeof(token));
if (str && str[0]) {
/* Monsters can RECRUIT 15 DRACOID
@ -506,7 +505,7 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
}
if (recruitcost) {
pl = getplane(r);
plane *pl = getplane(r);
if (pl && fval(pl, PFL_NORECRUITS)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_pflnorecruit", ""));
return;
@ -1075,10 +1074,10 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
{
const item_type *itype = resource2item(rtype);
rawmaterial *rm = rm_get(r, rtype);
bool first = true;
if (rm != NULL) {
int need;
bool first = true;
do {
int avail = rm->amount, nreq = 0;
allocation *al;
@ -1299,7 +1298,6 @@ int make_cmd(unit * u, struct order *ord)
int m = INT_MAX;
const char *s;
const struct locale *lang = u->faction->locale;
char ibuf[16];
keyword_t kwd;
kwd = init_order_depr(ord);
@ -1307,6 +1305,7 @@ int make_cmd(unit * u, struct order *ord)
s = gettoken(token, sizeof(token));
if (s) {
char ibuf[16];
m = atoip(s);
sprintf(ibuf, "%d", m);
if (!strcmp(ibuf, (const char *)s)) {
@ -1673,8 +1672,8 @@ static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 };
static void expandselling(region * r, econ_request * sellorders, int limit)
{
int money, price, max_products;
unsigned int j, norders;
int money, max_products;
int norders;
/* int m, n = 0; */
int maxsize = 0, maxeffsize = 0;
int taxcollected = 0;
@ -1751,11 +1750,12 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
norders = expandorders(r, sellorders);
if (norders > 0) {
int j;
for (j = 0; j != norders; j++) {
const luxury_type *search = NULL;
const luxury_type *ltype = g_requests[j]->type.trade.ltype;
int multi = r_demand(r, ltype);
int i;
int i, price;
int use = 0;
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
/* TODO: this is slow and lame! */
@ -2336,13 +2336,13 @@ static void research_cmd(unit * u, struct order *ord)
static void expandentertainment(region * r)
{
unit *u;
int m = entertainmoney(r);
econ_request *o;
for (o = &entertainers[0]; o != nextentertainer; ++o) {
double part = m / (double)entertaining;
u = o->unit;
unit *u = o->unit;
if (entertaining <= m)
u->n = o->qty;
else

View File

@ -75,7 +75,7 @@ extern "C" {
void produce(struct region *r);
void auto_work(struct region *r);
unsigned int expand_production(struct region * r, struct econ_request * requests, struct econ_request ***results);
int expand_production(struct region * r, struct econ_request * requests, struct econ_request ***results);
typedef enum income_t { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT } income_t;
void add_income(struct unit * u, income_t type, int want, int qty);

View File

@ -143,10 +143,10 @@ static struct unit *create_recruiter(void) {
static void setup_production(void) {
init_resources();
mt_register(mt_new_va("produce", "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", NULL));
mt_register(mt_new_va("income", "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", NULL));
mt_register(mt_new_va("buy", "unit:unit", "money:int", NULL));
mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", NULL));
mt_register(mt_new_va("produce", "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", MT_NEW_END));
mt_register(mt_new_va("income", "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", MT_NEW_END));
mt_register(mt_new_va("buy", "unit:unit", "money:int", MT_NEW_END));
mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", MT_NEW_END));
}
static void test_heroes_dont_recruit(CuTest * tc) {
@ -377,11 +377,11 @@ static void test_tax_cmd(CuTest *tc) {
}
static void setup_economy(void) {
mt_register(mt_new_va("recruit", "unit:unit", "region:region", "amount:int", "want:int", NULL));
mt_register(mt_new_va("maintenance", "unit:unit", "building:building", NULL));
mt_register(mt_new_va("maintenancefail", "unit:unit", "building:building", NULL));
mt_register(mt_new_va("maintenance_nowork", "building:building", NULL));
mt_register(mt_new_va("maintenance_noowner", "building:building", NULL));
mt_register(mt_new_va("recruit", "unit:unit", "region:region", "amount:int", "want:int", MT_NEW_END));
mt_register(mt_new_va("maintenance", "unit:unit", "building:building", MT_NEW_END));
mt_register(mt_new_va("maintenancefail", "unit:unit", "building:building", MT_NEW_END));
mt_register(mt_new_va("maintenance_nowork", "building:building", MT_NEW_END));
mt_register(mt_new_va("maintenance_noowner", "building:building", MT_NEW_END));
}
/**

View File

@ -49,6 +49,8 @@ void game_done(void)
free_gamedata();
creport_cleanup();
report_cleanup();
#endif
#endif
calendar_cleanup();
free_functions();
free_config();

View File

@ -162,7 +162,11 @@ int give_quota(const unit * src, const unit * dst, const item_type * type,
return n;
}
if (dst && src && src->faction != dst->faction) {
int divisor = config_get_int("rules.items.give_divisor", 1);
static int config;
static double divisor = 1.0;
if (config_changed(&config)) {
divisor = config_get_flt("rules.items.give_divisor", divisor);
}
assert(divisor <= 0 || divisor >= 1);
if (divisor >= 1) {
/* predictable > correct: */
@ -302,7 +306,6 @@ static bool rule_transfermen(void)
message * give_men(int n, unit * u, unit * u2, struct order *ord)
{
ship *sh;
int error = 0;
message * msg;
int maxt = max_transfers();
@ -410,6 +413,14 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord)
}
if (error == 0) {
ship *sh = leftship(u);
/* Einheiten von Schiffen können nicht NACH in von
* Nicht-alliierten bewachten Regionen ausführen */
if (sh) {
set_leftship(u2, sh);
}
if (u2->number == 0) {
set_racename(&u2->attribs, get_racename(u->attribs));
u_setrace(u2, u_race(u));
@ -422,12 +433,6 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord)
}
}
/* Einheiten von Schiffen können nicht NACH in von
* Nicht-alliierten bewachten Regionen ausführen */
sh = leftship(u);
if (sh) {
set_leftship(u2, sh);
}
transfermen(u, u2, n);
if (maxt >= 0 && u->faction != u2->faction) {
u2->faction->newbies += n;

View File

@ -54,24 +54,24 @@ static void setup_give(struct give *env) {
}
/* success messages: */
mt_register(mt_new_va("receive_person", "unit:unit", "target:unit", "amount:int", NULL));
mt_register(mt_new_va("give_person", "unit:unit", "target:unit", "amount:int", NULL));
mt_register(mt_new_va("give_person_peasants", "unit:unit", "amount:int", NULL));
mt_register(mt_new_va("give_person_ocean", "unit:unit", "amount:int", NULL));
mt_register(mt_new_va("receive", "unit:unit", "target:unit", "resource:resource", "amount:int", NULL));
mt_register(mt_new_va("give", "unit:unit", "target:unit", "resource:resource", "amount:int", NULL));
mt_register(mt_new_va("give_peasants", "unit:unit", "resource:resource", "amount:int", NULL));
mt_register(mt_new_va("receive_person", "unit:unit", "target:unit", "amount:int", MT_NEW_END));
mt_register(mt_new_va("give_person", "unit:unit", "target:unit", "amount:int", MT_NEW_END));
mt_register(mt_new_va("give_person_peasants", "unit:unit", "amount:int", MT_NEW_END));
mt_register(mt_new_va("give_person_ocean", "unit:unit", "amount:int", MT_NEW_END));
mt_register(mt_new_va("receive", "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END));
mt_register(mt_new_va("give", "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END));
mt_register(mt_new_va("give_peasants", "unit:unit", "resource:resource", "amount:int", MT_NEW_END));
/* error messages: */
mt_register(mt_new_va("too_many_units_in_faction", "unit:unit", "region:region", "command:order", "allowed:int", NULL));
mt_register(mt_new_va("too_many_units_in_alliance", "unit:unit", "region:region", "command:order", "allowed:int", NULL));
mt_register(mt_new_va("feedback_no_contact", "unit:unit", "region:region", "command:order", "target:unit", NULL));
mt_register(mt_new_va("feedback_give_forbidden", "unit:unit", "region:region", "command:order", NULL));
mt_register(mt_new_va("peasants_give_invalid", "unit:unit", "region:region", "command:order", NULL));
mt_register(mt_new_va("giverestriction", "unit:unit", "region:region", "command:order", "turns:int", NULL));
mt_register(mt_new_va("error_unit_size", "unit:unit", "region:region", "command:order", "maxsize:int", NULL));
mt_register(mt_new_va("nogive_reserved", "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", NULL));
mt_register(mt_new_va("race_notake", "unit:unit", "region:region", "command:order", "race:race", NULL));
mt_register(mt_new_va("race_noregroup", "unit:unit", "region:region", "command:order", "race:race", NULL));
mt_register(mt_new_va("too_many_units_in_faction", "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END));
mt_register(mt_new_va("too_many_units_in_alliance", "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END));
mt_register(mt_new_va("feedback_no_contact", "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END));
mt_register(mt_new_va("feedback_give_forbidden", "unit:unit", "region:region", "command:order", MT_NEW_END));
mt_register(mt_new_va("peasants_give_invalid", "unit:unit", "region:region", "command:order", MT_NEW_END));
mt_register(mt_new_va("giverestriction", "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END));
mt_register(mt_new_va("error_unit_size", "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END));
mt_register(mt_new_va("nogive_reserved", "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END));
mt_register(mt_new_va("race_notake", "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END));
mt_register(mt_new_va("race_noregroup", "unit:unit", "region:region", "command:order", "race:race", MT_NEW_END));
}
static void test_give_unit(CuTest * tc) {

View File

@ -144,7 +144,7 @@ static void init_curses(void)
short bcol = COLOR_BLACK;
short hcol = COLOR_MAGENTA;
start_color();
#ifdef WIN32
#ifdef __PDCURSES__
/* looks crap on putty with TERM=linux */
if (can_change_color()) {
init_color(COLOR_YELLOW, 1000, 1000, 0);
@ -335,10 +335,10 @@ static void paint_map(window * wnd, const state * st)
map_region *cursor_region(const view * v, const coordinate * c)
{
coordinate relpos;
if (c) {
int cx, cy;
coordinate relpos;
relpos.x = c->x - v->topleft.x;
relpos.y = c->y - v->topleft.y;
cy = relpos.y;
@ -422,6 +422,15 @@ static bool handle_info_region(window * wnd, state * st, int c)
return false;
}
int wxborder(WINDOW *win)
{
#ifdef __PDCURSES__
return wborder(win, 0, 0, 0, 0, 0, 0, 0, 0);
#else
return wborder(win, '|', '|', '-', '-', '+', '+', '+', '+');
#endif
}
static void paint_info_region(window * wnd, const state * st)
{
WINDOW *win = wnd->handle;
@ -937,7 +946,7 @@ static void handlekey(state * st, int c)
static int findmode = 0;
region *r;
char sbuffer[80];
static char kbuffer[80];
const char *loc = locate;
int n, nx, ny, minpop, maxpop;
switch (c) {
@ -1239,7 +1248,7 @@ static void handlekey(state * st, int c)
else if (findmode == 'F') {
faction *f = select_faction(st);
if (f != NULL) {
itoab_r(f->no, 36, locate, sizeof(locate));
loc = itoa36_r(f->no, locate, sizeof(locate));
findmode = 'f';
}
else {
@ -1252,8 +1261,9 @@ static void handlekey(state * st, int c)
break;
}
/* achtung: fall-through ist absicht: */
if (!strlen(locate))
if (!strlen(loc)) {
break;
}
case 'n':
if (findmode == 'u') {
unit *u = findunit(atoi36(locate));
@ -1265,9 +1275,9 @@ static void handlekey(state * st, int c)
region *first = (mr && mr->r && mr->r->next) ? mr->r->next : regions;
if (findmode == 'f') {
snprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", locate);
snprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", loc);
statusline(st->wnd_status->handle, sbuffer);
f = findfaction(atoi36(locate));
f = findfaction(atoi36(loc));
if (f == NULL) {
statusline(st->wnd_status->handle, "faction not found.");
beep();
@ -1320,6 +1330,7 @@ static void handlekey(state * st, int c)
}
}
if (wnd == NULL) {
static char kbuffer[80];
if (kbuffer[0] == 0) {
strcpy(kbuffer, "getch:");
}
@ -1391,9 +1402,9 @@ void run_mapper(void)
int split = 20;
state *st;
point tl;
char sbuffer[512];
if (!new_players) {
char sbuffer[512];
path_join(basepath(), "newfactions", sbuffer, sizeof(sbuffer));
new_players = read_newfactions(sbuffer);
}
@ -1435,8 +1446,6 @@ void run_mapper(void)
view *vi = &st->display;
getbegyx(hwinmap, x, y);
width = getmaxx(hwinmap) - x;
height = getmaxy(hwinmap) - y;
coor2point(&st->cursor, &p);
if (st->cursor.pl != vi->pl) {

View File

@ -90,11 +90,7 @@ extern "C" {
#define TWIDTH 2 /* width of tile */
#define THEIGHT 1 /* height of tile */
#ifdef WIN32
#define wxborder(win) wborder(win, 0, 0, 0, 0, 0, 0, 0, 0)
#else
#define wxborder(win) wborder(win, '|', '|', '-', '-', '+', '+', '+', '+')
#endif
int wxborder(WINDOW *win);
#ifdef __cplusplus
}

View File

@ -252,6 +252,9 @@ static int
lua_use_item(unit *u, const item_type *itype, const char * fname, int amount, struct order *ord)
{
lua_State *L = (lua_State *)global.vm_state;
int len, result = 0;
char fname[64];
int (*callout)(unit *, const item_type *, int, struct order *);
lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) {
@ -278,11 +281,11 @@ use_item_callback(unit *u, const item_type *itype, int amount, struct order *ord
{
int len;
char fname[64];
int(*callout)(unit *, const item_type *, int, struct order *);
len = snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name);
if (len > 0 && (size_t)len < sizeof(fname)) {
int result;
int(*callout)(unit *, const item_type *, int, struct order *);
/* check if we have a register_item_use function */
callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname);

View File

@ -122,14 +122,14 @@ use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
struct order *ord)
{
region *r = u->region;
const resource_type *rt_crystal = NULL;
const resource_type *rt_crystal;
int i;
rt_crystal = rt_find("antimagic");
assert(rt_crystal != NULL);
for (i = 0; i != amount; ++i) {
int effect, duration = 2;
int effect;
double force;
spell *sp = find_spell("antimagiczone");
attrib **ap = &r->attribs;
@ -173,6 +173,7 @@ struct order *ord)
}
if (force > 0) {
int duration = 2;
create_curse(u, &r->attribs, &ct_antimagiczone, force, duration,
effect, 0);
}

View File

@ -138,16 +138,16 @@ int *casualties)
/* If battle succeeds */
if (hits(*at, dt, wp)) {
d += terminate(dt, *at, AT_STANDARD, wp->type->damage[0], true);
#ifdef CATAPULT_STRUCTURAL_DAMAGE
/* CATAPULT_STRUCTURAL_DAMAGE
if (dt.fighter->unit->building && rng_int() % 100 < 5) {
double dmg = config_get_flt("rules.building.damage.catapult", 1);
damage_building(b, dt.fighter->unit->building, dmg);
}
else if (dt.fighter->unit->ship && rng_int() % 100 < 5) {
double dmg = config_get_flt("rules.ship.damage.catapult", 0.01);
damage_ship(dt.fighter->unit->ship, dmg)
damage_ship(dt.fighter->unit->ship, dmg);
}
#endif
*/
}
}

View File

@ -43,7 +43,7 @@ static void test_manacrystal(CuTest *tc) {
static void test_skillpotion(CuTest *tc) {
unit *u;
const struct item_type *itype;
skill* pSkill = NULL;
skill* pSkill;
int initialWeeks_Entertainment = 0;
int initialWeeks_Stamina = 0;
int initialWeeks_Magic = 0;

View File

@ -27,7 +27,7 @@ static int report_json(const char *filename, report_context * ctx, const char *c
if (config_get_int("jsreport.enabled", 0) != 0) {
FILE * F = fopen(filename, "w");
if (F) {
int x, y, minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;
int minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;
seen_region *sr;
region *r;
/* traverse all regions */
@ -44,12 +44,13 @@ static int report_json(const char *filename, report_context * ctx, const char *c
else if (tx > maxx) maxx = tx;
}
if (maxx >= minx && maxy >= miny) {
int w = maxx - minx + 1, h = maxy - miny + 1;
int y, w = maxx - minx + 1, h = maxy - miny + 1;
fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F);
fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w);
fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w);
fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F);
for (y = miny; y <= maxy; ++y) {
int x;
for (x = minx; x <= maxx; ++x) {
int data = 0;
int tx = x, ty = y;

View File

@ -233,7 +233,6 @@ alliedfaction(const struct plane *pl, const struct faction *f,
/* Die Gruppe von Einheit u hat helfe zu f2 gesetzt. */
int alliedunit(const unit * u, const faction * f2, int mode)
{
ally *sf;
int automode;
assert(u);
@ -242,6 +241,7 @@ int alliedunit(const unit * u, const faction * f2, int mode)
if (u->faction == f2)
return mode;
if (u->faction != NULL && f2 != NULL) {
ally *sf;
plane *pl;
if (mode & HELP_FIGHT) {

View File

@ -449,8 +449,7 @@ static int use_materials(unit *u, const construction *type, int n, int completed
required(completed, type->reqsize, type->materials[c].number);
int need =
required(completed + n, type->reqsize, type->materials[c].number);
int multi = 1;
int canuse = 100; /* normalization */
int multi, canuse = 100; /* normalization */
canuse = matmod(u, rtype, canuse);
assert(canuse >= 0);
assert(canuse % 100 == 0
@ -477,13 +476,14 @@ static int count_materials(unit *u, const construction *type, int n, int complet
assert(canuse >= 0);
if (type->reqsize > 1) {
int prebuilt =
required(completed, type->reqsize, type->materials[c].number);
for (; n;) {
int prebuilt = required(completed, type->reqsize,
type->materials[c].number);
while (n > 0) {
int need =
required(completed + n, type->reqsize, type->materials[c].number);
if (need - prebuilt <= canuse)
if (need - prebuilt <= canuse) {
break;
}
--n; /* TODO: optimieren? */
}
}
@ -704,7 +704,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
* gefunden wurde, dann wird nicht einfach eine neue erbaut. Ansonsten
* baut man an der eigenen burg weiter. */
/* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */
/* Wenn die angegebene Nummer falsch ist, KEINE Burg bauen! */
if (id > 0) { /* eine Nummer angegeben, keine neue Burg bauen */
b = findbuilding(id);
if (!b || b->region != u->region) { /* eine Burg mit dieser Nummer gibt es hier nicht */
@ -893,12 +893,12 @@ static void build_ship(unit * u, ship * sh, int want)
if (n)
ADDMSG(&u->faction->msgs,
msg_message("buildship", "ship unit size", sh, u, n));
msg_message("buildship", "ship unit size", sh, u, n));
}
void
create_ship(unit * u, const struct ship_type *newtype, int want,
order * ord)
order * ord)
{
ship *sh;
int msize;
@ -940,7 +940,7 @@ order * ord)
}
new_order =
create_order(K_MAKE, u->faction->locale, "%s %i", LOC(u->faction->locale,
parameters[P_SHIP]), sh->no);
parameters[P_SHIP]), sh->no);
replace_order(&u->orders, ord, new_order);
free_order(new_order);

View File

@ -256,7 +256,7 @@ static void test_build_destroy_road(CuTest *tc)
message *m;
test_setup();
mt_register(mt_new_va("destroy_road", "unit:unit", "from:region", "to:region", NULL));
mt_register(mt_new_va("destroy_road", "unit:unit", "from:region", "to:region", MT_NEW_END));
r2 = test_create_region(1, 0, 0);
r = test_create_region(0, 0, NULL);
rsetroad(r, D_EAST, 100);

View File

@ -359,7 +359,7 @@ building *new_building(const struct building_type * btype, region * r,
{
building **bptr = &r->buildings;
building *b = (building *)calloc(1, sizeof(building));
const char *bname = 0;
const char *bname;
char buffer[32];
b->no = newcontainerid();
@ -372,14 +372,12 @@ building *new_building(const struct building_type * btype, region * r,
*bptr = b;
update_lighthouse(b);
if (!bname) {
bname = LOC(lang, btype->_name);
}
bname = LOC(lang, btype->_name);
if (!bname) {
bname = LOC(lang, parameters[P_GEBAEUDE]);
}
if (!bname) {
bname = parameters[P_GEBAEUDE];
if (!bname) {
bname = parameters[P_GEBAEUDE];
}
}
assert(bname);
snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));

View File

@ -248,7 +248,7 @@ static void test_buildingowner_resets_when_empty(CuTest * tc)
u_set_building(u, bld);
CuAssertPtrEquals(tc, u, building_owner(bld));
u->number = 0;
CuAssertPtrEquals(tc, 0, building_owner(bld));
CuAssertPtrEquals(tc, NULL, building_owner(bld));
u->number = 1;
CuAssertPtrEquals(tc, u, building_owner(bld));
test_teardown();

View File

@ -156,9 +156,10 @@ connection *get_borders(const region * r1, const region * r2)
connection *new_border(border_type * type, region * from, region * to)
{
connection *b, **bp = get_borders_i(from, to);
connection *b, **bp;
assert(from && to);
bp = get_borders_i(from, to);
while (*bp) {
bp = &(*bp)->next;
}
@ -241,6 +242,7 @@ void b_read(connection * b, gamedata * data)
default:
assert(!"invalid variant type in connection");
}
assert(result >= 0 || !"EOF encountered?");
}
void b_write(const connection * b, storage * store)
@ -557,8 +559,7 @@ static bool b_validroad(const connection * b)
static bool b_rvisibleroad(const connection * b, const region * r)
{
int x = b->data.i;
x = (r == b->from) ? b->data.sa[0] : b->data.sa[1];
int x = (r == b->from) ? b->data.sa[0] : b->data.sa[1];
if (x == 0) {
return false;
}

View File

@ -291,25 +291,6 @@ void ct_register(const curse_type * ct)
selist_set_insert(ctlp, (void *)ct, NULL);
}
void ct_remove(const char *c)
{
unsigned int hash = tolower(c[0]);
selist *ctl = cursetypes[hash];
if (ctl) {
int qi;
for (qi = 0; ctl; selist_advance(&ctl, &qi, 1)) {
curse_type *type = (curse_type *)selist_get(ctl, qi);
if (strcmp(c, type->cname) == 0) {
selist_delete(&ctl, qi);
break;
}
}
}
}
const curse_type *ct_find(const char *c)
{
unsigned int hash = tolower(c[0]);
@ -609,7 +590,6 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct,
static void do_transfer_curse(curse * c, const unit * u, unit * u2, int n)
{
int cursedmen = 0;
int men = get_cursedmen(u, c);
bool dogive = false;
const curse_type *ct = c->type;
@ -622,6 +602,7 @@ static void do_transfer_curse(curse * c, const unit * u, unit * u2, int n)
case CURSE_SPREADMODULO:
{
int cursedmen = 0;
int i;
int u_number = u->number;
for (i = 0; i < n + 1 && u_number > 0; i++) {

View File

@ -60,8 +60,8 @@ static void test_get_equipment(CuTest * tc)
eq = get_equipment("catapult");
CuAssertPtrEquals(tc, NULL, eq);
eq = create_equipment("catapult");
eq = get_equipment("catapult");
CuAssertPtrNotNull(tc, eq);
CuAssertPtrEquals(tc, eq, get_equipment("catapult"));
CuAssertStrEquals(tc, "catapult", equipment_name(eq));
eq = get_equipment("catapultammo123");
CuAssertPtrNotNull(tc, eq);

View File

@ -897,17 +897,6 @@ void log_dead_factions(void)
}
void free_factions(void) {
#ifdef DMAXHASH
int i;
for (i = 0; i != DMAXHASH; ++i) {
while (deadhash[i]) {
dead *d = deadhash[i];
deadhash[i] = d->nexthash;
free(d);
}
}
#endif
free_flist(&factions);
free_flist(&dead_factions);
}

View File

@ -243,7 +243,7 @@ static void test_set_email(CuTest *tc) {
sprintf(email, "enno");
faction_setemail(f, email);
email[0] = 0;
CuAssertTrue(tc, email != f->email);
CuAssertStrEquals(tc, "enno", f->email);
CuAssertStrEquals(tc, "enno", faction_getemail(f));
faction_setemail(f, "bugs@eressea.de");

View File

@ -53,7 +53,7 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
gamedata_init(&data, &store, RELEASE_VERSION);
write_game(&data);
free_gamedata();
f = f2 = NULL;
f = NULL;
data.strm.api->rewind(data.strm.handle);
read_game(&data);
mstream_done(&data.strm);

View File

@ -353,14 +353,7 @@ const weapon_type *resource2weapon(const resource_type * rtype)
const luxury_type *resource2luxury(const resource_type * rtype)
{
#ifdef AT_LTYPE
attrib *a = a_find(rtype->attribs, &at_ltype);
if (a)
return (const luxury_type *)a->data.v;
return NULL;
#else
return rtype->ltype;
#endif
}
resource_type *rt_find(const char *name)
@ -677,11 +670,6 @@ void init_resources(void)
rtype->itype = it_get_or_create(rtype);
rtype->itype->flags |= ITF_ANIMAL | ITF_BIG;
rtype = rt_get_or_create(resourcenames[R_SAPLING]);
rtype = rt_get_or_create(resourcenames[R_TREE]);
rtype = rt_get_or_create(resourcenames[R_MALLORN_SAPLING]);
rtype = rt_get_or_create(resourcenames[R_MALLORN_TREE]);
/* "special" spell components */
rtype = rt_get_or_create(resourcenames[R_AURA]);
rtype->uchange = res_changeaura;
@ -692,6 +680,12 @@ void init_resources(void)
rtype = rt_get_or_create(resourcenames[R_PEASANT]);
rtype->uchange = res_changepeasants;
/* trees are important, too: */
rt_get_or_create(resourcenames[R_SAPLING]);
rt_get_or_create(resourcenames[R_TREE]);
rt_get_or_create(resourcenames[R_MALLORN_SAPLING]);
rt_get_or_create(resourcenames[R_MALLORN_TREE]);
/* alte typen registrieren: */
init_oldpotions();
}

View File

@ -46,16 +46,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <ctype.h>
#include <assert.h>
typedef struct msg_setting {
struct msg_setting *next;
const struct message_type *type;
int level;
} msg_setting;
/************ Compatibility function *************/
#define MAXSTRLEN (4*DISPLAYSIZE+3)
#include "region.h"
#include <kernel/config.h>
static void
arg_set(variant args[], const message_type * mtype, const char *buffer,
@ -92,7 +83,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
log_warning("trying to create message of unknown type \"%s\"\n", name);
if (!mt_find("missing_feedback")) {
mt_register(mt_new_va("missing_feedback", "unit:unit",
"region:region", "command:order", "name:string", NULL));
"region:region", "command:order", "name:string", MT_NEW_END));
}
return msg_message("missing_feedback", "name unit region command",
name, u, u->region, ord);
@ -162,7 +153,7 @@ static message *missing_message(const char *name) {
log_warning("trying to create undefined message of type \"%s\"\n", name);
if (strcmp(name, "missing_message") != 0) {
if (!mt_find("missing_message")) {
mt_register(mt_new_va("missing_message", "name:string", NULL));
mt_register(mt_new_va("missing_message", "name:string", MT_NEW_END));
}
return msg_message("missing_message", "name", name);
}
@ -267,7 +258,7 @@ void addmessage(region * r, faction * f, const char *s, msg_t mtype, int level)
message * msg_error(const unit * u, struct order *ord, int mno) {
static char msgname[20];
if (fval(u->faction, FFL_NPC)) {
if (u->faction->flags & FFL_NPC) {
return NULL;
}
sprintf(msgname, "error%d", mno);

View File

@ -12,7 +12,7 @@ void test_missing_message(CuTest *tc) {
test_setup();
message_handle_missing(MESSAGE_MISSING_REPLACE);
msg = msg_message("unknown", "unit", NULL);
msg = msg_message("unknown", "unit", (unit *)NULL);
CuAssertPtrNotNull(tc, msg);
CuAssertPtrNotNull(tc, msg->type);
CuAssertStrEquals(tc, msg->type->name, "missing_message");

View File

@ -107,7 +107,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape)
{
const char *str, *text;
const char *text;
order_data *od = NULL;
keyword_t kwd = ORD_KEYWORD(ord);
@ -128,7 +128,7 @@ int stream_order(struct stream *out, const struct order *ord, const struct local
text = OD_STRING(od);
}
if (kwd != NOKEYWORD) {
str = (const char *)LOC(lang, keyword(kwd));
const char *str = (const char *)LOC(lang, keyword(kwd));
assert(str);
swrite(str, 1, strlen(str), out);
}
@ -242,9 +242,9 @@ order *create_order(keyword_t kwd, const struct locale * lang,
va_start(marker, params);
sbs_init(&sbs, zBuffer, sizeof(zBuffer));
while (*params) {
const char *s;
tok = strchr(params, '%');
if (tok) {
const char *s;
int i;
if (tok != params) {
sbs_strncat(&sbs, params, tok - params);

View File

@ -30,13 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define MAXDEPTH 1024
bool allowed_swim(const region * src, const region * r)
{
if (fval(r->terrain, SWIM_INTO))
return true;
return false;
}
bool allowed_walk(const region * src, const region * r)
{
if (fval(r->terrain, WALK_INTO))

View File

@ -98,7 +98,6 @@ enum {
static void rc_setoption(race *rc, int k, const char *value) {
unsigned char key = (unsigned char)k;
int i;
variant *v = NULL;
if (!rc->options) {
rc->options = malloc(sizeof(rcoption));
@ -106,6 +105,7 @@ static void rc_setoption(race *rc, int k, const char *value) {
rc->options->key[1] = RCO_NONE;
v = rc->options->value;
} else {
int i;
for (i=0;!v && i < MAXOPTIONS;++i) {
if (rc->options->key[i]==key) {
v = rc->options->value+i;
@ -196,9 +196,10 @@ static rc_xref *xrefs;
race_t old_race(const struct race * rc)
{
static int cache;
int i, l, r;
int l, r;
if (rc_changed(&cache)) {
int i;
if (!xrefs) {
xrefs = malloc(sizeof(rc_xref) * MAXRACES);
}

View File

@ -320,8 +320,6 @@ void runhash(region * r)
{
unsigned int rid = coor_hashkey(r->x, r->y);
int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH);
#ifdef FAST_CONNECT
int d, di;
for (d = 0, di = MAXDIRECTIONS / 2; d != MAXDIRECTIONS; ++d, ++di) {
region *rc = r->connect[d];
@ -332,7 +330,6 @@ void runhash(region * r)
r->connect[d] = NULL;
}
}
#endif
while (regionhash[key] != NULL && regionhash[key] != r) {
key = (key + gk) % RMAXHASH;
}
@ -344,23 +341,19 @@ region *r_connect(const region * r, direction_t dir)
{
region *result;
int x, y;
#ifdef FAST_CONNECT
region *rmodify = (region *)r;
assert(dir >= 0 && dir < MAXDIRECTIONS);
if (r->connect[dir])
return r->connect[dir];
#endif
assert(dir < MAXDIRECTIONS);
x = r->x + delta_x[dir];
y = r->y + delta_y[dir];
pnormalize(&x, &y, rplane(r));
result = rfindhash(x, y);
#ifdef FAST_CONNECT
if (result) {
rmodify->connect[dir] = result;
result->connect[back[dir]] = rmodify;
}
#endif
return result;
}
@ -974,7 +967,7 @@ void free_regions(void)
*/
static char *makename(void)
{
int s, v, k, e, p = 0, x = 0;
int s, k, e, p = 0, x = 0;
size_t nk, ne, nv, ns;
static char name[16];
const char *kons = "bcdfghklmnprstvwz",
@ -990,6 +983,7 @@ static char *makename(void)
ns = strlen(start);
for (s = rng_int() % 3 + 2; s > 0; s--) {
int v;
if (x > 0) {
k = rng_int() % (int)nk;
name[p] = kons[k];

View File

@ -31,10 +31,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define MAXREGIONS 524287 /* must be prime for hashing. 262139 was a little small */
#define MAXTREES 100 * 1000 * 1000 /* bug 2360: some players are crazy */
/* FAST_CONNECT: regions are directly connected to neighbours, saves doing
a hash-access each time a neighbour is needed, 6 extra pointers per hex */
#define FAST_CONNECT
#define RF_CHAOTIC (1<<0) /* persistent */
#define RF_MALLORN (1<<1) /* persistent */
#define RF_BLOCKED (1<<2) /* persistent */
@ -136,9 +132,7 @@ extern "C" {
struct attrib *attribs;
const struct terrain_type *terrain;
struct rawmaterial *resources;
#ifdef FAST_CONNECT
struct region *connect[MAXDIRECTIONS]; /* use rconnect(r, dir) to access */
#endif
struct {
seen_mode mode;
} seen;
@ -247,11 +241,7 @@ extern "C" {
struct alliance *region_get_alliance(const struct region *r);
struct region *r_connect(const struct region *, direction_t dir);
#ifdef FAST_CONNECT
# define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, (direction_t)dir))
#else
# define rconnect(r, dir) r_connect(r, (direction_t)dir)
#endif
#define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, (direction_t)dir))
void free_regions(void);
void free_land(struct land_region * lr);

View File

@ -172,19 +172,6 @@ struct ship *findship(int i)
return sfindhash(i);
}
struct ship *findshipr(const region * r, int n)
{
ship *sh;
for (sh = r->ships; sh; sh = sh->next) {
if (sh->no == n) {
assert(sh->region == r);
return sh;
}
}
return 0;
}
void damage_ship(ship * sh, double percent)
{
double damage =

View File

@ -76,8 +76,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <math.h>
#define FIND_FOREIGN_TEMP
int weight(const unit * u)
{
int w = 0, n = 0, in_bag = 0;
@ -125,19 +123,6 @@ unit *findunitr(const region * r, int n)
return (u && u->region == r) ? u : 0;
}
/* TODO: deprecated, replace with findunit(n) */
unit *findunitg(int n, const region * hint)
{
UNUSED_ARG(hint);
/* Abfangen von Syntaxfehlern. */
if (n <= 0)
return NULL;
/* findunit global! */
hint = 0;
return ufindhash(n);
}
#define UMAXHASH MAXUNITS
static unit *unithash[UMAXHASH];
static unit *delmarker = (unit *)unithash; /* a funny hack */
@ -359,42 +344,6 @@ int gift_items(unit * u, int flags)
static unit *deleted_units = NULL;
#define DMAXHASH 7919
#undef DMAXHASH /* TODO: makes dfindhash slow! */
#ifdef DMAXHASH
typedef struct dead {
struct dead *nexthash;
faction *f;
int no;
} dead;
static dead *deadhash[DMAXHASH];
static void dhash(int no, faction * f)
{
dead *hash = (dead *)calloc(1, sizeof(dead));
dead *old = deadhash[no % DMAXHASH];
hash->no = no;
hash->f = f;
deadhash[no % DMAXHASH] = hash;
hash->nexthash = old;
}
faction *dfindhash(int no)
{
dead *old;
if (no < 0)
return 0;
for (old = deadhash[no % DMAXHASH]; old; old = old->nexthash) {
if (old->no == no) {
return old->f;
}
}
return 0;
}
#else
struct faction *dfindhash(int no) {
unit *u;
@ -405,7 +354,6 @@ struct faction *dfindhash(int no) {
}
return NULL;
}
#endif
int remove_unit(unit ** ulist, unit * u)
{
@ -454,9 +402,6 @@ int remove_unit(unit ** ulist, unit * u)
u->next = deleted_units;
deleted_units = u;
#ifdef DMAXHASH
dhash(u->no, u->faction);
#endif
u->region = NULL;
@ -473,11 +418,11 @@ unit *findnewunit(const region * r, const faction * f, int n)
for (u2 = r->units; u2; u2 = u2->next)
if (u2->faction == f && ualias(u2) == n)
return u2;
#ifdef FIND_FOREIGN_TEMP
for (u2 = r->units; u2; u2 = u2->next)
if (ualias(u2) == n)
return u2;
#endif
return 0;
}

View File

@ -245,9 +245,7 @@ extern "C" {
void remove_empty_units_in_region(struct region * r);
void remove_empty_units(void);
struct unit *findunitg(int n, const struct region *hint);
struct unit *findunit(int n);
struct unit *findunitr(const struct region *r, int n);
void default_name(const unit *u, char name[], int len);

View File

@ -4226,12 +4226,6 @@ cansee(const faction * f, const region * r, const unit * u, int modifier)
return (rings <= 0 && stealth <= 0);
}
bool cansee_ex(const faction * f, const region * r, const unit * u, int modifier, seen_mode mode)
{
UNUSED_ARG(mode);
return cansee(f, r, u, modifier);
}
bool cansee_unit(const unit * u, const unit * target, int modifier)
/* target->region kann != u->region sein, wenn es um durchreisen geht */
{

View File

@ -98,8 +98,6 @@ extern "C" {
void nmr_warnings(void);
bool cansee_ex(const struct faction * f, const struct region * r,
const struct unit * u, int modifier, seen_mode mode);
bool cansee(const struct faction * f, const struct region * r,
const struct unit *u, int modifier);
bool cansee_durchgezogen(const struct faction *f, const struct region *r,

View File

@ -258,7 +258,7 @@ static void test_force_leave_buildings(CuTest *tc) {
building * b;
test_setup();
mt_register(mt_new_va("force_leave_building", "unit:unit", "owner:unit", "building:building", NULL));
mt_register(mt_new_va("force_leave_building", "unit:unit", "owner:unit", "building:building", MT_NEW_END));
r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION));
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(u1->faction, r);
@ -288,7 +288,7 @@ static void test_force_leave_ships(CuTest *tc) {
ship *sh;
test_setup();
mt_register(mt_new_va("force_leave_ship", "unit:unit", "owner:unit", "ship:ship", NULL));
mt_register(mt_new_va("force_leave_ship", "unit:unit", "owner:unit", "ship:ship", MT_NEW_END));
r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION));
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
@ -876,7 +876,7 @@ static void test_luck_message(CuTest *tc) {
attrib *a;
test_setup();
mt_register(mt_new_va("peasantluck_success", "births:int", NULL));
mt_register(mt_new_va("peasantluck_success", "births:int", MT_NEW_END));
setup_terrains(tc);
r = test_create_region(0, 0, NULL);
rsetpeasants(r, 1);
@ -901,8 +901,8 @@ static unit * setup_name_cmd(void) {
faction *f;
test_setup();
mt_register(mt_new_va("renamed_building_seen", "renamer:unit", "region:region", "building:building", NULL));
mt_register(mt_new_va("renamed_building_notseen", "region:region", "building:building", NULL));
mt_register(mt_new_va("renamed_building_seen", "renamer:unit", "region:region", "building:building", MT_NEW_END));
mt_register(mt_new_va("renamed_building_notseen", "region:region", "building:building", MT_NEW_END));
f = test_create_faction(NULL);
return test_create_unit(f, test_create_region(0, 0, NULL));
}
@ -1301,9 +1301,9 @@ static void test_ally_cmd(CuTest *tc) {
static void test_nmr_warnings(CuTest *tc) {
faction *f1, *f2;
test_setup();
mt_register(mt_new_va("nmr_warning", NULL));
mt_register(mt_new_va("nmr_warning_final", NULL));
mt_register(mt_new_va("warn_dropout", "faction:faction", "turn:int", NULL));
mt_register(mt_new_va("nmr_warning", MT_NEW_END));
mt_register(mt_new_va("nmr_warning_final", MT_NEW_END));
mt_register(mt_new_va("warn_dropout", "faction:faction", "turn:int", MT_NEW_END));
config_set("nmr.timeout", "3");
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
@ -1325,9 +1325,9 @@ static unit * setup_mail_cmd(void) {
faction *f;
test_setup();
mt_register(mt_new_va("regionmessage", "region:region", "sender:unit", "string:string", NULL));
mt_register(mt_new_va("unitmessage", "region:region", "sender:unit", "string:string", "unit:unit", NULL));
mt_register(mt_new_va("mail_result", "message:string", "unit:unit", NULL));
mt_register(mt_new_va("regionmessage", "region:region", "sender:unit", "string:string", MT_NEW_END));
mt_register(mt_new_va("unitmessage", "region:region", "sender:unit", "string:string", "unit:unit", MT_NEW_END));
mt_register(mt_new_va("mail_result", "message:string", "unit:unit", MT_NEW_END));
f = test_create_faction(NULL);
return test_create_unit(f, test_create_region(0, 0, NULL));
}
@ -1444,7 +1444,7 @@ static void test_show_without_item(CuTest *tc)
struct locale *loc;
test_setup();
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", NULL));
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", MT_NEW_END));
loc = get_or_create_locale("de");
locale_setstring(loc, parameters[P_ANY], "ALLE");
@ -1489,7 +1489,7 @@ static void test_show_race(CuTest *tc) {
test_setup();
mt_register(mt_new_va("msg_event", "string:string", NULL));
mt_register(mt_new_va("msg_event", "string:string", MT_NEW_END));
test_create_race("human");
rc = test_create_race("elf");
@ -1529,8 +1529,8 @@ static void test_show_both(CuTest *tc) {
message * msg;
test_setup();
mt_register(mt_new_va("msg_event", "string:string", NULL));
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", NULL));
mt_register(mt_new_va("msg_event", "string:string", MT_NEW_END));
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", MT_NEW_END));
rc = test_create_race("elf");
test_create_itemtype("elvenhorse");

View File

@ -2263,14 +2263,6 @@ static void set_clone(unit * mage, unit * clone)
assert(!a->data.v || a->data.v == mage);
}
unit *has_clone(unit * mage)
{
attrib *a = a_find(mage->attribs, &at_clone);
if (a)
return (unit *)a->data.v;
return NULL;
}
static void * resolve_clone(int id, void *data) {
UNUSED_ARG(id);
if (data) {

View File

@ -33,7 +33,7 @@ static void test_market_curse(CuTest * tc)
building_type *btype;
test_setup();
mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", NULL));
mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", MT_NEW_END));
htype = test_create_itemtype("herb");
htype->flags |= ITF_HERB;

View File

@ -780,7 +780,7 @@ void plan_monsters(faction * f)
}
}
else if (tu) {
tu = findunitg(ta->data.i, NULL);
tu = findunit(ta->data.i);
if (tu != NULL) {
long_order = make_movement_order(u, tu->region, 2, allowed_walk);
}

View File

@ -48,7 +48,7 @@ static void create_monsters(unit **up, unit **um) {
region *r;
faction *fp, *fm;
mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", NULL));
mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", MT_NEW_END));
test_create_horse();
default_locale = test_create_locale();
fp = test_create_faction(NULL);
@ -216,7 +216,7 @@ static void test_dragon_moves(CuTest * tc)
plan_monsters(m->faction);
CuAssertPtrNotNull(tc, find_order("move east", m));
mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", NULL));
mt_register(mt_new_va("dragon_growl", "dragon:unit", "number:int", "target:region", "growl:string", MT_NEW_END));
random_growl(m, findregion(1, 0), 3);

View File

@ -28,8 +28,8 @@
#include <assert.h>
static void setup_move(void) {
mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", NULL));
mt_register(mt_new_va("moveblocked", "unit:unit", "direction:int", NULL));
mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END));
mt_register(mt_new_va("moveblocked", "unit:unit", "direction:int", MT_NEW_END));
}
static void test_ship_not_allowed_in_coast(CuTest * tc)
@ -285,9 +285,9 @@ void setup_drift (struct drift_fixture *fix) {
u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat));
assert(fix->sh);
mt_register(mt_new_va("ship_drift", "ship:ship", "dir:int", NULL));
mt_register(mt_new_va("shipsink", "ship:ship", NULL));
mt_register(mt_new_va("massive_overload", "ship:ship", NULL));
mt_register(mt_new_va("ship_drift", "ship:ship", "dir:int", MT_NEW_END));
mt_register(mt_new_va("shipsink", "ship:ship", MT_NEW_END));
mt_register(mt_new_va("massive_overload", "ship:ship", MT_NEW_END));
}
static void test_ship_no_overload(CuTest *tc) {
@ -482,7 +482,7 @@ static void test_follow_ship_msg(CuTest * tc) {
td->dir = D_NORTHWEST;
td->age = 2;
mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order", NULL));
mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order", MT_NEW_END));
init_order_depr(ord);
getstrtoken();

View File

@ -368,97 +368,6 @@ static void dracoid_name(unit * u)
unit_setname(u, name);
}
/** returns an abbreviation of a string.
* TODO: buflen is being ignored */
const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
{
const char *p = s;
char *bufp;
unsigned int c = 0;
size_t bpt, i;
ucs4_t ucs;
size_t size;
int result;
UNUSED_ARG(buflen);
/* Pr<50>fen, ob Kurz genug */
if (strlen(s) <= maxchars) {
return s;
}
/* Anzahl der W<>rter feststellen */
while (*p != 0) {
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
/* Leerzeichen <20>berspringen */
while (*p != 0 && !iswalnum((wint_t)ucs)) {
p += size;
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
}
/* Counter erh<72>hen */
if (*p != 0)
++c;
/* alnums <20>berspringen */
while (*p != 0 && iswalnum((wint_t)ucs)) {
p += size;
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
}
}
/* Buchstaben pro Teilk<6C>rzel = MAX(1,max/AnzWort) */
bpt = (c > 0) ? MAX(1, maxchars / c) : 1;
/* Einzelne W<>rter anspringen und jeweils die ersten BpT kopieren */
p = s;
c = 0;
bufp = buf;
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
while (*p != 0 && c < maxchars) {
/* Leerzeichen <20>berspringen */
while (*p != 0 && !iswalnum((wint_t)ucs)) {
p += size;
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
}
/* alnums <20>bertragen */
for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) {
memcpy(bufp, p, size);
p += size;
bufp += size;
++c;
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
}
/* Bis zum n<>chsten Leerzeichen */
while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) {
p += size;
result = unicode_utf8_to_ucs4(&ucs, p, &size);
assert(result == 0 || !"damnit, we're not handling invalid input here!");
}
}
*bufp = 0;
return buf;
}
void register_names(void)
{
/* function name

View File

@ -28,7 +28,7 @@ static unit *unitorders(input *in, faction *f)
return NULL;
i = getid();
u = findunitg(i, NULL);
u = findunit(i);
if (u && u->faction == f) {
order **ordp;
@ -122,10 +122,8 @@ static unit *unitorders(input *in, faction *f)
static faction *factionorders(void)
{
faction *f = NULL;
int fid = getid();
f = findfaction(fid);
faction *f = findfaction(fid);
if (f != NULL && !fval(f, FFL_NPC)) {
char token[128];
@ -232,9 +230,8 @@ int readorders(const char *filename)
{
input in;
int result;
FILE *F = fopen(filename, "r");
FILE *F = NULL;
F = fopen(filename, "r");
if (!F) {
perror(filename);
return -1;

View File

@ -64,7 +64,7 @@ static void test_faction_password_bad(CuTest *tc) {
const char *orders[] = { "ERESSEA 1 password", NULL };
test_setup();
mt_register(mt_new_va("wrongpasswd", "password:string", NULL));
mt_register(mt_new_va("wrongpasswd", "password:string", MT_NEW_END));
f = test_create_faction(NULL);
renumber_faction(f, 1);

View File

@ -30,12 +30,12 @@ static void setup_piracy(void) {
st_boat = test_create_shiptype("boat");
st_boat->cargo = 1000;
mt_register(mt_new_va("piratenovictim", "ship:ship", "unit:unit", "region:region", NULL));
mt_register(mt_new_va("piratesawvictim", "ship:ship", "unit:unit", "region:region", "dir:int", NULL));
mt_register(mt_new_va("shipsail", "ship:ship", "from:region", "to:region", NULL));
mt_register(mt_new_va("shipfly", "ship:ship", "from:region", "to:region", NULL));
mt_register(mt_new_va("shipnoshore", "ship:ship", "region:region", NULL));
mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", NULL));
mt_register(mt_new_va("piratenovictim", "ship:ship", "unit:unit", "region:region", MT_NEW_END));
mt_register(mt_new_va("piratesawvictim", "ship:ship", "unit:unit", "region:region", "dir:int", MT_NEW_END));
mt_register(mt_new_va("shipsail", "ship:ship", "from:region", "to:region", MT_NEW_END));
mt_register(mt_new_va("shipfly", "ship:ship", "from:region", "to:region", MT_NEW_END));
mt_register(mt_new_va("shipnoshore", "ship:ship", "region:region", MT_NEW_END));
mt_register(mt_new_va("travel", "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END));
}
static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const char *p_shiptype,

View File

@ -113,7 +113,7 @@ int renumber_cmd(unit * u, order * ord)
break;
}
if (findunitg(i, u->region)) {
if (findunit(i)) {
cmistake(u, ord, 115, MSG_EVENT);
break;
}

View File

@ -38,7 +38,7 @@ static void test_renumber_faction_duplicate(CuTest *tc) {
const struct locale *lang;
test_setup_ex(tc);
mt_register(mt_new_va("renumber_inuse", "id:int", NULL));
mt_register(mt_new_va("renumber_inuse", "id:int", MT_NEW_END));
f2 = test_create_faction(NULL);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
no = f->no;

View File

@ -2396,29 +2396,6 @@ struct fsee {
#define REPORT_ZIP (1 << O_COMPRESS)
#define REPORT_BZIP2 (1 << O_BZIP2)
unit *can_find(faction * f, faction * f2)
{
int key = f->no % FMAXHASH;
struct fsee *fs = fsee[key];
struct see *ss;
if (f == f2)
return f->units;
while (fs && fs->f != f)
fs = fs->nexthash;
if (!fs)
return NULL;
ss = fs->see;
while (ss && ss->seen != f2)
ss = ss->next;
if (ss) {
/* bei TARNE PARTEI yxz muss die Partei von unit proof nicht
* wirklich Partei f2 sein! */
/* assert(ss->proof->faction==f2); */
return ss->proof;
}
return NULL;
}
void register_nr(void)
{
if (!nocr)

View File

@ -838,7 +838,7 @@ static int sp_magicstreet(castorder * co)
/* melden, 1x pro Partei */
{
message *seen = msg_message("path_effect", "mage region", mage, r);
message *unseen = msg_message("path_effect", "mage region", NULL, r);
message *unseen = msg_message("path_effect", "mage region", (unit *)NULL, r);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -895,7 +895,7 @@ static int sp_summonent(castorder * co)
/* melden, 1x pro Partei */
{
message *seen = msg_message("ent_effect", "mage amount", mage, ents);
message *unseen = msg_message("ent_effect", "mage amount", NULL, ents);
message *unseen = msg_message("ent_effect", "mage amount", (unit *)NULL, ents);
report_effect(r, mage, seen, unseen);
msg_release(unseen);
msg_release(seen);
@ -989,7 +989,7 @@ static int sp_maelstrom(castorder * co)
/* melden, 1x pro Partei */
if (c) {
message *seen = msg_message("maelstrom_effect", "mage", mage);
message *unseen = msg_message("maelstrom_effect", "mage", NULL);
message *unseen = msg_message("maelstrom_effect", "mage", (unit *)NULL);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -1033,7 +1033,7 @@ static int sp_mallorn(castorder * co)
/* melden, 1x pro Partei */
{
message *seen = msg_message("mallorn_effect", "mage", mage);
message *unseen = msg_message("mallorn_effect", "mage", NULL);
message *unseen = msg_message("mallorn_effect", "mage", (unit *)NULL);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -1068,7 +1068,7 @@ static int sp_blessedharvest(castorder * co)
duration, 1.0, 0)) {
const char * effect = co->sp->sname[0]=='b' ? "harvest_effect" : "raindance_effect";
message *seen = msg_message(effect, "mage", mage);
message *unseen = msg_message(effect, "mage", NULL);
message *unseen = msg_message(effect, "mage", (unit *)NULL);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -1114,7 +1114,7 @@ static int sp_hain(castorder * co)
{
message *seen = msg_message("growtree_effect", "mage amount", mage, trees);
message *unseen =
msg_message("growtree_effect", "mage amount", NULL, trees);
msg_message("growtree_effect", "mage amount", (unit *)NULL, trees);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -1160,7 +1160,7 @@ static int sp_mallornhain(castorder * co)
{
message *seen = msg_message("growtree_effect", "mage amount", mage, trees);
message *unseen =
msg_message("growtree_effect", "mage amount", NULL, trees);
msg_message("growtree_effect", "mage amount", (unit *)NULL, trees);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -2675,7 +2675,7 @@ static int sp_firewall(castorder * co)
/* melden, 1x pro Partei */
{
message *seen = msg_message("firewall_effect", "mage region", mage, r);
message *unseen = msg_message("firewall_effect", "mage region", NULL, r);
message *unseen = msg_message("firewall_effect", "mage region", (unit *)NULL, r);
report_effect(r, mage, seen, unseen);
msg_release(seen);
msg_release(unseen);
@ -4368,7 +4368,7 @@ int sp_puttorest(castorder * co)
int dead = deathcount(r);
int laid_to_rest = dice((int)(co->force * 2), 100);
message *seen = msg_message("puttorest", "mage", mage);
message *unseen = msg_message("puttorest", "mage", NULL);
message *unseen = msg_message("puttorest", "mage", (unit *)NULL);
if (laid_to_rest < dead) laid_to_rest = dead;

View File

@ -130,8 +130,8 @@ static void test_view_reality(CuTest *tc) {
test_setup();
setup_spells();
mt_register(mt_new_va("spell_astral_only", "unit:unit", "region:region", "command:order", NULL));
mt_register(mt_new_va("viewreality_effect", "unit:unit", NULL));
mt_register(mt_new_va("spell_astral_only", "unit:unit", "region:region", "command:order", MT_NEW_END));
mt_register(mt_new_va("viewreality_effect", "unit:unit", MT_NEW_END));
r = test_create_region(0, 0, NULL);
ra = test_create_region(real2tp(r->x), real2tp(r->y), NULL);
ra->_plane = get_astralplane();

View File

@ -29,7 +29,7 @@ static void test_flyingship(CuTest * tc)
ship *sh1, *sh2;
test_setup();
mt_register(mt_new_va("flying_ship_result", "mage:unit", "ship:ship", NULL));
mt_register(mt_new_va("flying_ship_result", "mage:unit", "ship:ship", MT_NEW_END));
par.param = &par_data_ptr;
par_data.typ = SPP_SHIP;

View File

@ -29,7 +29,7 @@ static void test_magicresistance_unit(CuTest *tc) {
curse *c;
test_setup();
mt_register(mt_new_va("magicresistance_unit", "unit:unit", "id:int", NULL));
mt_register(mt_new_va("magicresistance_unit", "unit:unit", "id:int", MT_NEW_END));
r = test_create_plain(0, 0);
f1 = test_create_faction(NULL);
u1 = test_create_unit(f1, r);
@ -57,7 +57,7 @@ static void test_magicresistance_building(CuTest *tc) {
curse *c;
test_setup();
mt_register(mt_new_va("magicresistance_building", "building:building", "id:int", NULL));
mt_register(mt_new_va("magicresistance_building", "building:building", "id:int", MT_NEW_END));
r = test_create_plain(0, 0);
f1 = test_create_faction(NULL);
u1 = test_create_unit(f1, r);

View File

@ -466,7 +466,7 @@ static void sink_ship(region * r, ship * sh, unit * saboteur)
move_unit(u, safety, NULL);
}
else {
msg = msg_message("sink_lost_msg", "dead region unit", dead, NULL, u);
msg = msg_message("sink_lost_msg", "dead region unit", dead, (region *)NULL, u);
}
add_message(&u->faction->msgs, msg);
msg_release(msg);

View File

@ -33,19 +33,19 @@ typedef struct {
} spy_fixture;
static void setup_spy(spy_fixture *fix) {
mt_register(mt_new_va("spyreport", "spy:unit", "target:unit", "status:int", NULL));
mt_register(mt_new_va("spyreport_mage", "spy:unit", "target:unit", "type:int", NULL));
mt_register(mt_new_va("spyreport_faction", "spy:unit", "target:unit", "faction:faction", NULL));
mt_register(mt_new_va("spyreport_skills", "spy:unit", "target:unit", "skills:string", NULL));
mt_register(mt_new_va("spyreport_items", "spy:unit", "target:unit", "items:items", NULL));
mt_register(mt_new_va("destroy_ship_0", "unit:unit", "ship:ship", NULL));
mt_register(mt_new_va("destroy_ship_1", "unit:unit", "ship:ship", NULL));
mt_register(mt_new_va("destroy_ship_2", "unit:unit", "ship:ship", NULL));
mt_register(mt_new_va("destroy_ship_3", "ship:ship", NULL));
mt_register(mt_new_va("destroy_ship_4", "ship:ship", NULL));
mt_register(mt_new_va("sink_msg", "ship:ship", "region:region", NULL));
mt_register(mt_new_va("sink_lost_msg", "unit:unit", "region:region", "dead:int", NULL));
mt_register(mt_new_va("sink_saved_msg", "unit:unit", "region:region", NULL));
mt_register(mt_new_va("spyreport", "spy:unit", "target:unit", "status:int", MT_NEW_END));
mt_register(mt_new_va("spyreport_mage", "spy:unit", "target:unit", "type:int", MT_NEW_END));
mt_register(mt_new_va("spyreport_faction", "spy:unit", "target:unit", "faction:faction", MT_NEW_END));
mt_register(mt_new_va("spyreport_skills", "spy:unit", "target:unit", "skills:string", MT_NEW_END));
mt_register(mt_new_va("spyreport_items", "spy:unit", "target:unit", "items:items", MT_NEW_END));
mt_register(mt_new_va("destroy_ship_0", "unit:unit", "ship:ship", MT_NEW_END));
mt_register(mt_new_va("destroy_ship_1", "unit:unit", "ship:ship", MT_NEW_END));
mt_register(mt_new_va("destroy_ship_2", "unit:unit", "ship:ship", MT_NEW_END));
mt_register(mt_new_va("destroy_ship_3", "ship:ship", MT_NEW_END));
mt_register(mt_new_va("destroy_ship_4", "ship:ship", MT_NEW_END));
mt_register(mt_new_va("sink_msg", "ship:ship", "region:region", MT_NEW_END));
mt_register(mt_new_va("sink_lost_msg", "unit:unit", "region:region", "dead:int", MT_NEW_END));
mt_register(mt_new_va("sink_saved_msg", "unit:unit", "region:region", MT_NEW_END));
if (fix) {
fix->r = test_create_region(0, 0, NULL);

View File

@ -49,8 +49,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
void expandstealing(region * r, econ_request * stealorders)
{
const resource_type *rsilver = get_resourcetype(R_SILVER);
unsigned int j;
unsigned int norders;
int norders, j;
econ_request **requests;
assert(rsilver);
@ -72,7 +71,7 @@ void expandstealing(region * r, econ_request * stealorders)
break;
}
u = findunitg(requests[j]->type.steal.no, r);
u = findunit(requests[j]->type.steal.no);
if (u && u->region == r) {
n = get_pooled(u, rsilver, GET_ALL, INT_MAX);

View File

@ -58,9 +58,9 @@ typedef struct {
} study_fixture;
static void setup_study(void) {
mt_register(mt_new_va("studycost", "unit:unit", "region:region", "cost:int", "skill:int", NULL));
mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", NULL));
mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", NULL));
mt_register(mt_new_va("studycost", "unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END));
mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END));
mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", MT_NEW_END));
}
static void setup_locale(struct locale *lang) {
@ -218,7 +218,7 @@ static void test_academy_building(CuTest *tc) {
message * msg;
test_setup();
mt_register(mt_new_va("teach_asgood", "unit:unit", "region:region", "command:order", "student:unit", NULL));
mt_register(mt_new_va("teach_asgood", "unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END));
random_source_inject_constant(0.0);
init_resources();
@ -636,8 +636,8 @@ static void test_teach_message(CuTest *tc) {
teaching_info *teach;
test_setup();
mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", NULL));
mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", NULL));
mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END));
mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", MT_NEW_END));
init_resources();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
scale_number(u, 20);

View File

@ -231,9 +231,9 @@ static void test_reset(void) {
}
random_source_reset();
mt_register(mt_new_va("changepasswd", "value:string", NULL));
mt_register(mt_new_va("starvation", "unit:unit", "region:region", "dead:int", "live:int", NULL));
mt_register(mt_new_va("malnourish", "unit:unit", "region:region", NULL));
mt_register(mt_new_va("changepasswd", "value:string", MT_NEW_END));
mt_register(mt_new_va("starvation", "unit:unit", "region:region", "dead:int", "live:int", MT_NEW_END));
mt_register(mt_new_va("malnourish", "unit:unit", "region:region", MT_NEW_END));
if (errno) {
int error = errno;

View File

@ -12,7 +12,7 @@
#include <CuTest.h>
static void shock_setup(void) {
mt_register(mt_new_va("shock", "mage:unit", "reason:string", NULL));
mt_register(mt_new_va("shock", "mage:unit", "reason:string", MT_NEW_END));
}
static void test_shock(CuTest *tc) {

View File

@ -56,11 +56,7 @@ int read_attribs(gamedata *data, attrib **alist, void *owner) {
void write_attribs(storage *store, attrib *alist, const void *owner)
{
#if RELEASE_VERSION < ATHASH_VERSION
a_write_orig(store, alist, owner);
#else
a_write(store, alist, owner);
#endif
}
int a_readint(variant * var, void *owner, struct gamedata *data)
@ -531,24 +527,6 @@ void a_write(struct storage *store, const attrib * attribs, const void *owner) {
WRITE_INT(store, 0);
}
void a_write_orig(struct storage *store, const attrib * attribs, const void *owner)
{
const attrib *na = attribs;
while (na) {
if (na->type->write) {
assert(na->type->hashkey || !"attribute not registered");
WRITE_TOK(store, na->type->name);
na->type->write(&na->data, owner, store);
na = na->next;
}
else {
na = na->nexttype;
}
}
WRITE_TOK(store, "end");
}
void attrib_done(void) {
cb_clear(&cb_deprecated);
memset(at_hash, 0, sizeof(at_hash[0]) * MAXATHASH);

View File

@ -74,8 +74,6 @@ extern "C" {
void a_free_voidptr(union variant *v);
int a_read_orig(struct gamedata *data, attrib ** attribs, void *owner);
void a_write_orig(struct storage *store, const attrib * attribs, const void *owner);
int a_read(struct gamedata *data, attrib ** attribs, void *owner);
void a_write(struct storage *store, const attrib * attribs, const void *owner);

View File

@ -58,7 +58,7 @@ const char *itoab_r(int i, int base, char *s, size_t len)
assert(len > 2);
dst = s + len - 2;
*dst = 0;
dst[1] = 0;
if (i != 0) {
int neg = 0;
@ -92,12 +92,18 @@ const char *itoab_r(int i, int base, char *s, size_t len)
assert(i == 0 || !"itoab: static buffer exhausted");
}
}
else
*dst = '0';
else {
dst[0] = '0';
}
return dst;
}
const char *itoa36_r(int i, char *result, size_t len)
{
return itoab_r(i, 36, result, len);
}
const char *itoab(int i, int base)
{
static char sstr[80];

View File

@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
const char *itoa36_r(int i, char *result, size_t len);
const char *itoab_r(int i, int base, char *result, size_t len);
const char *itoab(int i, int base);
const char *itoa36(int i);

View File

@ -5,6 +5,7 @@
#include <CuTest.h>
#include "base36.h"
#include <stdlib.h>
#include <string.h>
#include <limits.h>
static void test_atoi36(CuTest * tc)
@ -19,14 +20,20 @@ static void test_atoi36(CuTest * tc)
static void test_itoa36(CuTest * tc)
{
CuAssertStrEquals(tc, itoa36(0), "0");
CuAssertStrEquals(tc, itoa10(INT_MAX), "2147483647");
CuAssertStrEquals(tc, itoab(INT_MAX, 8), "17777777777");
CuAssertStrEquals(tc, itoab(INT_MAX, 4), "1333333333333333");
CuAssertStrEquals(tc, itoab(-1, 5), "-1");
CuAssertStrEquals(tc, itoa36(-1), "-1");
CuAssertStrEquals(tc, itoa36(-10), "-a");
CuAssertStrEquals(tc, itoa36(666), "ii");
char buf[10];
CuAssertStrEquals(tc, itoa36(0), "0");
CuAssertStrEquals(tc, itoa10(INT_MAX), "2147483647");
CuAssertStrEquals(tc, itoab(INT_MAX, 8), "17777777777");
CuAssertStrEquals(tc, itoab(INT_MAX, 4), "1333333333333333");
CuAssertStrEquals(tc, itoab(-1, 5), "-1");
CuAssertStrEquals(tc, itoa36(-1), "-1");
CuAssertStrEquals(tc, itoa36(-10), "-a");
CuAssertStrEquals(tc, itoa36(666), "ii");
memset(buf, 255, sizeof(buf));
CuAssertStrEquals(tc, itoa36_r(-10, buf, sizeof(buf)), "-a");
memset(buf, 255, sizeof(buf));
CuAssertStrEquals(tc, itoab_r(666, 36, buf, sizeof(buf)), "ii");
}
CuSuite *get_base36_suite(void)

View File

@ -45,8 +45,9 @@ extern "C" {
void mt_clear(void);
struct message_type *mt_new(const char *name, const char *args[]);
struct message_type *mt_new_va(const char *name, ...);
#define MT_NEW_END ((const char *)0)
/* mt_new("simple_sentence", "subject:string", "predicate:string",
* "object:string", "lang:locale", NULL); */
* "object:string", "lang:locale", MT_NEW_END); */
struct message *msg_create(const struct message_type *type,
variant args[]);

View File

@ -8,7 +8,7 @@ static void test_mt_new(CuTest *tc)
{
message_type *mt;
test_setup();
mt = mt_new_va("test", "name:string", "number:int", NULL);
mt = mt_new_va("test", "name:string", "number:int", MT_NEW_END);
mt_register(mt);
CuAssertPtrNotNull(tc, mt);
CuAssertStrEquals(tc, "test", mt->name);

View File

@ -8,6 +8,12 @@
#include <assert.h>
#include <string.h>
#ifdef WIN32
#define PATH_DELIM '\\'
#else
#define PATH_DELIM '/'
#endif
char * path_join(const char *p1, const char *p2, char *dst, size_t len) {
size_t sz;
assert(p1 && p2);

View File

@ -1,10 +1,4 @@
#include <stddef.h>
#ifdef WIN32
#define PATH_DELIM '\\'
#else
#define PATH_DELIM '/'
#endif
char * path_join(const char *p1, const char *p2, char *dst, size_t len);

View File

@ -20,7 +20,7 @@ static void test_volcano_update(CuTest *tc) {
const struct terrain_type *t_volcano, *t_active;
test_setup();
mt_register(mt_new_va("volcanostopsmoke", "region:region", NULL));
mt_register(mt_new_va("volcanostopsmoke", "region:region", MT_NEW_END));
t_volcano = test_create_terrain("volcano", LAND_REGION);
t_active = test_create_terrain("activevolcano", LAND_REGION);
r = test_create_region(0, 0, t_active);
@ -42,9 +42,9 @@ static void test_volcano_outbreak(CuTest *tc) {
const struct terrain_type *t_volcano, *t_active;
test_setup();
mt_register(mt_new_va("volcanooutbreak", "regionv:region", "regionn:region", NULL));
mt_register(mt_new_va("volcanooutbreaknn", "region:region", NULL));
mt_register(mt_new_va("volcano_dead", "unit:unit", "region:region", "dead:int", NULL));
mt_register(mt_new_va("volcanooutbreak", "regionv:region", "regionn:region", MT_NEW_END));
mt_register(mt_new_va("volcanooutbreaknn", "region:region", MT_NEW_END));
mt_register(mt_new_va("volcano_dead", "unit:unit", "region:region", "dead:int", MT_NEW_END));
t_volcano = test_create_terrain("volcano", LAND_REGION);
t_active = test_create_terrain("activevolcano", LAND_REGION);
r = test_create_region(0, 0, t_active);

View File

@ -19,10 +19,10 @@ void sort_wormhole_regions(selist *rlist, region **match, int count);
void make_wormholes(region **match, int count, const building_type *bt_wormhole);
static void setup_wormholes(void) {
mt_register(mt_new_va("wormhole_appear", "region:region", NULL));
mt_register(mt_new_va("wormhole_dissolve", "region:region", NULL));
mt_register(mt_new_va("wormhole_exit", "unit:unit", "region:region", NULL));
mt_register(mt_new_va("wormhole_requirements", "unit:unit", "region:region", NULL));
mt_register(mt_new_va("wormhole_appear", "region:region", MT_NEW_END));
mt_register(mt_new_va("wormhole_dissolve", "region:region", MT_NEW_END));
mt_register(mt_new_va("wormhole_exit", "unit:unit", "region:region", MT_NEW_END));
mt_register(mt_new_va("wormhole_requirements", "unit:unit", "region:region", MT_NEW_END));
}
static void test_make_wormholes(CuTest *tc) {