forked from github/server
cppcheck: DMAXHASH was unused.
cppcheck: remove warnings, reduce variable scopes.
This commit is contained in:
parent
d802f6ea67
commit
fc2506ee83
16 changed files with 77 additions and 122 deletions
26
src/give.c
26
src/give.c
|
@ -158,13 +158,15 @@ static bool limited_give(const item_type * type)
|
|||
int give_quota(const unit * src, const unit * dst, const item_type * type,
|
||||
int n)
|
||||
{
|
||||
double divisor;
|
||||
|
||||
if (!limited_give(type)) {
|
||||
return n;
|
||||
}
|
||||
if (dst && src && src->faction != dst->faction) {
|
||||
divisor = config_get_flt("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: */
|
||||
|
@ -305,8 +307,6 @@ static bool rule_transfermen(void)
|
|||
|
||||
message * give_men(int n, unit * u, unit * u2, struct order *ord)
|
||||
{
|
||||
ship *sh;
|
||||
int k = 0;
|
||||
int error = 0;
|
||||
message * msg;
|
||||
int maxt = max_transfers();
|
||||
|
@ -391,7 +391,7 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord)
|
|||
}
|
||||
|
||||
if (has_skill(u, SK_ALCHEMY) || has_skill(u2, SK_ALCHEMY)) {
|
||||
k = count_skill(u2->faction, SK_ALCHEMY);
|
||||
int k = count_skill(u2->faction, SK_ALCHEMY);
|
||||
|
||||
/* Falls die Zieleinheit keine Alchemisten sind, werden sie nun
|
||||
* welche. */
|
||||
|
@ -414,6 +414,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));
|
||||
|
@ -426,12 +434,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;
|
||||
|
|
23
src/gmtool.c
23
src/gmtool.c
|
@ -137,10 +137,10 @@ int umvwaddnstr(WINDOW *w, int y, int x, const char * str, int len) {
|
|||
|
||||
static void init_curses(void)
|
||||
{
|
||||
int fg, bg;
|
||||
initscr();
|
||||
|
||||
if (has_colors() || force_color) {
|
||||
int fg, bg;
|
||||
short bcol = COLOR_BLACK;
|
||||
short hcol = COLOR_MAGENTA;
|
||||
start_color();
|
||||
|
@ -316,11 +316,11 @@ static void paint_map(window * wnd, const state * st)
|
|||
int yp = (lines - vy - 1) * THEIGHT;
|
||||
for (vx = 0; vx != cols; ++vx) {
|
||||
map_region *mr = mr_get(&st->display, vx, vy);
|
||||
int attr = 0;
|
||||
int hl = 0;
|
||||
int xp = vx * TWIDTH + (vy & 1) * TWIDTH / 2;
|
||||
int nx, ny;
|
||||
if (mr) {
|
||||
int attr = 0;
|
||||
int hl = 0;
|
||||
cnormalize(&mr->coord, &nx, &ny);
|
||||
if (tagged_region(st->selected, nx, ny)) {
|
||||
attr |= A_REVERSE;
|
||||
|
@ -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;
|
||||
int cx, cy;
|
||||
|
||||
if (c) {
|
||||
int cx, cy;
|
||||
coordinate relpos;
|
||||
|
||||
relpos.x = c->x - v->topleft.x;
|
||||
relpos.y = c->y - v->topleft.y;
|
||||
cy = relpos.y;
|
||||
|
@ -435,13 +435,14 @@ static void paint_info_region(window * wnd, const state * st)
|
|||
{
|
||||
WINDOW *win = wnd->handle;
|
||||
int size = getmaxx(win) - 2;
|
||||
int line = 0, maxline = getmaxy(win) - 2;
|
||||
int maxline = getmaxy(win) - 2;
|
||||
map_region *mr = cursor_region(&st->display, &st->cursor);
|
||||
|
||||
UNUSED_ARG(st);
|
||||
werase(win);
|
||||
wxborder(win);
|
||||
if (mr && mr->r) {
|
||||
int line = 0;
|
||||
const region *r = mr->r;
|
||||
if (r->land) {
|
||||
umvwaddnstr(win, line++, 1, (char *)r->land->name, size);
|
||||
|
@ -717,10 +718,10 @@ static void select_regions(state * st, int selectmode)
|
|||
doupdate();
|
||||
findmode = getch();
|
||||
if (findmode == 'n') { /* none */
|
||||
int i;
|
||||
sprintf(sbuffer, "%snone", status);
|
||||
statusline(st->wnd_status->handle, sbuffer);
|
||||
if (selectmode & MODE_SELECT) {
|
||||
int i;
|
||||
for (i = 0; i != MAXTHASH; ++i) {
|
||||
tag **tp = &st->selected->tags[i];
|
||||
while (*tp) {
|
||||
|
@ -945,7 +946,6 @@ static void handlekey(state * st, int c)
|
|||
static int findmode = 0;
|
||||
region *r;
|
||||
char sbuffer[80];
|
||||
static char kbuffer[80];
|
||||
int n, nx, ny, minpop, maxpop;
|
||||
|
||||
switch (c) {
|
||||
|
@ -1328,6 +1328,7 @@ static void handlekey(state * st, int c)
|
|||
}
|
||||
}
|
||||
if (wnd == NULL) {
|
||||
static char kbuffer[80];
|
||||
if (kbuffer[0] == 0) {
|
||||
strcpy(kbuffer, "getch:");
|
||||
}
|
||||
|
@ -1399,9 +1400,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);
|
||||
}
|
||||
|
@ -1443,8 +1444,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) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
@ -228,7 +228,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
|
|||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
lua_pushinteger(L, delta);
|
||||
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("change(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
|
@ -254,39 +254,40 @@ use_item_lua(unit *u, const item_type *itype, 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 *);
|
||||
|
||||
len = snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name);
|
||||
if (len > 0 && (size_t)len < sizeof(fname)) {
|
||||
callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname);
|
||||
if (callout) {
|
||||
return callout(u, itype, amount, ord);
|
||||
}
|
||||
int(*callout)(unit *, const item_type *, int, struct order *);
|
||||
callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname);
|
||||
if (callout) {
|
||||
return callout(u, itype, amount, ord);
|
||||
}
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
lua_pushinteger(L, amount);
|
||||
lua_pushstring(L, getstrtoken());
|
||||
tolua_pushusertype(L, (void *)ord, TOLUA_CAST "order");
|
||||
if (lua_pcall(L, 4, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
lua_pushinteger(L, amount);
|
||||
lua_pushstring(L, getstrtoken());
|
||||
tolua_pushusertype(L, (void *)ord, TOLUA_CAST "order");
|
||||
if (lua_pcall(L, 4, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
if (itype->flags & ITF_POTION) {
|
||||
return use_potion(u, itype, amount, ord);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
log_error("no such callout: %s", fname);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
if (itype->flags & ITF_POTION) {
|
||||
return use_potion(u, itype, amount, ord);
|
||||
} else {
|
||||
log_error("no such callout: %s", fname);
|
||||
}
|
||||
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -121,14 +121,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;
|
||||
|
@ -172,6 +172,7 @@ struct order *ord)
|
|||
}
|
||||
|
||||
if (force > 0) {
|
||||
int duration = 2;
|
||||
create_curse(u, &r->attribs, &ct_antimagiczone, force, duration,
|
||||
effect, 0);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -124,7 +124,7 @@ static void json_maintenance_i(cJSON *json, maintenance *mt) {
|
|||
static void json_maintenance(cJSON *json, maintenance **mtp) {
|
||||
cJSON *child;
|
||||
maintenance *mt;
|
||||
int i, size = 1;
|
||||
int size = 1;
|
||||
|
||||
if (json->type == cJSON_Array) {
|
||||
size = cJSON_GetArraySize(json);
|
||||
|
@ -135,6 +135,7 @@ static void json_maintenance(cJSON *json, maintenance **mtp) {
|
|||
}
|
||||
*mtp = mt = (struct maintenance *) calloc(sizeof(struct maintenance), size + 1);
|
||||
if (json->type == cJSON_Array) {
|
||||
int i;
|
||||
for (i = 0, child = json->child; child; child = child->next, ++i) {
|
||||
if (child->type == cJSON_Object) {
|
||||
json_maintenance_i(child, mt + i);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -350,7 +350,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();
|
||||
|
@ -363,14 +363,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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -242,7 +243,7 @@ void b_read(connection * b, gamedata * data)
|
|||
assert(!"invalid variant type in connection");
|
||||
result = 0;
|
||||
}
|
||||
assert(result >= 0 || "EOF encountered?");
|
||||
assert(result >= 0 || !"EOF encountered?");
|
||||
}
|
||||
|
||||
void b_write(const connection * b, storage * store)
|
||||
|
@ -559,8 +560,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;
|
||||
}
|
||||
|
|
|
@ -609,7 +609,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 +621,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++) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -874,17 +874,6 @@ int writepasswd(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -358,42 +358,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;
|
||||
|
||||
|
@ -404,7 +368,6 @@ struct faction *dfindhash(int no) {
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int remove_unit(unit ** ulist, unit * u)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue