forked from github/server
cppcheck: variable scopes, etc.
This commit is contained in:
parent
f67a4943e4
commit
398a258658
|
@ -333,7 +333,7 @@ static int do_recruiting(recruitment * recruits, int available)
|
|||
for (req = rec->requests; req; req = req->next) {
|
||||
unit *u = req->unit;
|
||||
const race *rc = u_race(u); /* race is set in recruit() */
|
||||
int number, dec;
|
||||
int number;
|
||||
double multi = 2.0 * rc->recruit_multi;
|
||||
|
||||
number = (int)(get / multi);
|
||||
|
@ -359,7 +359,7 @@ static int do_recruiting(recruitment * recruits, int available)
|
|||
}
|
||||
add_recruits(u, number, req->qty);
|
||||
if (number > 0) {
|
||||
dec = (int)(number * multi);
|
||||
int dec = (int)(number * multi);
|
||||
if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) {
|
||||
recruited += dec;
|
||||
}
|
||||
|
@ -1006,7 +1006,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
|
|||
}
|
||||
}
|
||||
|
||||
assert(sk != NOSKILL || "limited resource needs a required skill for making it");
|
||||
assert(sk != NOSKILL || !"limited resource needs a required skill for making it");
|
||||
skill = effskill(u, sk, 0);
|
||||
if (skill == 0) {
|
||||
add_message(&u->faction->msgs,
|
||||
|
@ -1075,13 +1075,12 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|||
{
|
||||
const item_type *itype = resource2item(rtype);
|
||||
rawmaterial *rm = rm_get(r, rtype);
|
||||
int need;
|
||||
bool first = true;
|
||||
|
||||
if (rm != NULL) {
|
||||
int need;
|
||||
do {
|
||||
int avail = rm->amount;
|
||||
int nreq = 0;
|
||||
int avail = rm->amount, nreq = 0;
|
||||
allocation *al;
|
||||
|
||||
if (avail <= 0) {
|
||||
|
@ -1093,7 +1092,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|||
|
||||
assert(avail > 0);
|
||||
|
||||
for (al = alist; al; al = al->next)
|
||||
for (al = alist; al; al = al->next) {
|
||||
if (!fval(al, AFL_DONE)) {
|
||||
int req = required(al->want - al->get, al->save);
|
||||
assert(al->get <= al->want && al->get >= 0);
|
||||
|
@ -1112,6 +1111,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|||
fset(al, AFL_LOWSKILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
need = nreq;
|
||||
|
||||
if (avail > nreq) avail = nreq;
|
||||
|
|
10
src/give.c
10
src/give.c
|
@ -158,18 +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);
|
||||
int divisor = config_get_int("rules.items.give_divisor", 1);
|
||||
assert(divisor <= 0 || divisor >= 1);
|
||||
if (divisor >= 1) {
|
||||
/* predictable > correct: */
|
||||
int x = (int)(n / divisor);
|
||||
return x;
|
||||
return n / divisor;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
@ -306,7 +303,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 +387,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. */
|
||||
|
|
13
src/gmtool.c
13
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;
|
||||
|
@ -336,9 +336,9 @@ 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;
|
||||
relpos.x = c->x - v->topleft.x;
|
||||
relpos.y = c->y - v->topleft.y;
|
||||
cy = relpos.y;
|
||||
|
@ -426,13 +426,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);
|
||||
|
@ -708,10 +709,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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2720,10 +2720,10 @@ static void age_stonecircle(building *b) {
|
|||
curse *c = get_curse(rt->attribs, &ct_astralblock);
|
||||
if (!c) {
|
||||
int sk = effskill(mage, SK_MAGIC, 0);
|
||||
float effect = 100;
|
||||
if (sk > 0) {
|
||||
int vig = sk;
|
||||
int dur = (sk + 1) / 2;
|
||||
float effect = 100;
|
||||
/* the mage reactivates the circle */
|
||||
c = create_curse(mage, &rt->attribs, &ct_astralblock,
|
||||
vig, dur, effect, 0);
|
||||
|
|
|
@ -499,13 +499,13 @@ void unset_combatspell(unit * u, spell * sp)
|
|||
{
|
||||
sc_mage *m;
|
||||
int nr = 0;
|
||||
int i;
|
||||
|
||||
m = get_mage_depr(u);
|
||||
if (!m)
|
||||
return;
|
||||
|
||||
if (!sp) {
|
||||
int i;
|
||||
for (i = 0; i < MAXCOMBATSPELLS; i++) {
|
||||
m->combatspells[i].sp = NULL;
|
||||
}
|
||||
|
@ -1589,13 +1589,13 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
|
|||
const spell *sp = co->sp;
|
||||
region *target_r = co_get_region(co);
|
||||
spellparameter *sa = co->par;
|
||||
int i;
|
||||
|
||||
*invalid = 0;
|
||||
*resist = 0;
|
||||
*success = 0;
|
||||
|
||||
if (sa && sa->length) {
|
||||
int i;
|
||||
/* zuerst versuchen wir vorher nicht gefundene Objekte zu finden.
|
||||
* Wurde ein Objekt durch globalsuche gefunden, obwohl der Zauber
|
||||
* gar nicht global hätte suchen dürften, setzen wir das Objekt
|
||||
|
|
|
@ -284,7 +284,7 @@ static int ridingcapacity(const unit * u)
|
|||
int walkingcapacity(const struct unit *u)
|
||||
{
|
||||
int n, people, pferde_fuer_wagen, horses;
|
||||
int wagen_ohne_pferde, wagen_mit_pferden, wagen_mit_trollen;
|
||||
int wagen_mit_pferden;
|
||||
int vehicles = 0, vcap = 0;
|
||||
int animals = 0, acap = 0;
|
||||
const struct resource_type *rhorse = rt_find("horse");
|
||||
|
@ -312,6 +312,7 @@ int walkingcapacity(const struct unit *u)
|
|||
n = wagen_mit_pferden * vcap;
|
||||
|
||||
if (u_race(u) == get_race(RC_TROLL)) {
|
||||
int wagen_ohne_pferde, wagen_mit_trollen;
|
||||
/* 4 Trolle ziehen einen Wagen. */
|
||||
/* Unbesetzte Wagen feststellen */
|
||||
wagen_ohne_pferde = vehicles - wagen_mit_pferden;
|
||||
|
@ -682,7 +683,6 @@ static bool is_freezing(const unit * u)
|
|||
|
||||
int check_ship_allowed(struct ship *sh, const region * r)
|
||||
{
|
||||
int c = 0;
|
||||
const building_type *bt_harbour = bt_find("harbour");
|
||||
|
||||
if (sh->region && r_insectstalled(r)) {
|
||||
|
@ -708,6 +708,7 @@ int check_ship_allowed(struct ship *sh, const region * r)
|
|||
return SA_COAST;
|
||||
}
|
||||
if (sh->type->coasts) {
|
||||
int c;
|
||||
for (c = 0; sh->type->coasts[c] != NULL; ++c) {
|
||||
if (sh->type->coasts[c] == r->terrain) {
|
||||
return SA_COAST;
|
||||
|
|
21
src/names.c
21
src/names.c
|
@ -350,7 +350,6 @@ static void dracoid_name(unit * u)
|
|||
{
|
||||
static char name[NAMESIZE + 1];
|
||||
int mid_syllabels;
|
||||
size_t sz;
|
||||
|
||||
/* ignore u */
|
||||
UNUSED_ARG(u);
|
||||
|
@ -358,14 +357,14 @@ static void dracoid_name(unit * u)
|
|||
|
||||
mid_syllabels = rng_int() % 4;
|
||||
|
||||
sz = str_strlcpy(name, drac_pre[rng_int() % DRAC_PRE], sizeof(name));
|
||||
str_strlcpy(name, drac_pre[rng_int() % DRAC_PRE], sizeof(name));
|
||||
while (mid_syllabels > 0) {
|
||||
mid_syllabels--;
|
||||
if (rng_int() % 10 < 4)
|
||||
str_strlcat(name, "'", sizeof(name));
|
||||
sz += str_strlcat(name, drac_mid[rng_int() % DRAC_MID], sizeof(name));
|
||||
str_strlcat(name, drac_mid[rng_int() % DRAC_MID], sizeof(name));
|
||||
}
|
||||
sz += str_strlcat(name, drac_suf[rng_int() % DRAC_SUF], sizeof(name));
|
||||
str_strlcat(name, drac_suf[rng_int() % DRAC_SUF], sizeof(name));
|
||||
unit_setname(u, name);
|
||||
}
|
||||
|
||||
|
@ -392,13 +391,13 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
while (*p != 0) {
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
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!");
|
||||
assert(result == 0 || !"damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* Counter erh<72>hen */
|
||||
|
@ -409,7 +408,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
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!");
|
||||
assert(result == 0 || !"damnit, we're not handling invalid input here!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -423,7 +422,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
bufp = buf;
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
assert(result == 0 || !"damnit, we're not handling invalid input here!");
|
||||
|
||||
while (*p != 0 && c < maxchars) {
|
||||
/* Leerzeichen <20>berspringen */
|
||||
|
@ -431,7 +430,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
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!");
|
||||
assert(result == 0 || !"damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* alnums <20>bertragen */
|
||||
|
@ -443,7 +442,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
++c;
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
assert(result == 0 || !"damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* Bis zum n<>chsten Leerzeichen */
|
||||
|
@ -451,7 +450,7 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
|||
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!");
|
||||
assert(result == 0 || !"damnit, we're not handling invalid input here!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ void piracy_cmd(unit * u)
|
|||
const faction *target;
|
||||
int value;
|
||||
} aff[MAXDIRECTIONS];
|
||||
int saff = 0;
|
||||
int *il;
|
||||
|
||||
assert(u->thisorder);
|
||||
|
@ -139,6 +138,7 @@ void piracy_cmd(unit * u)
|
|||
/* Wenn nicht, sehen wir, ob wir ein Ziel finden. */
|
||||
|
||||
if (target_dir == NODIRECTION) {
|
||||
int saff = 0;
|
||||
direction_t dir;
|
||||
/* Einheit ist also Kapitän. Jetzt gucken, in wievielen
|
||||
* Nachbarregionen potentielle Opfer sind. */
|
||||
|
|
|
@ -37,8 +37,8 @@ int add_raceprefix(const char *prefix)
|
|||
}
|
||||
|
||||
void free_prefixes(void) {
|
||||
int i;
|
||||
if (race_prefixes) {
|
||||
int i;
|
||||
for (i = 0; race_prefixes[i]; ++i) {
|
||||
free(race_prefixes[i]);
|
||||
}
|
||||
|
|
|
@ -537,7 +537,6 @@ static int sp_summon_familiar(castorder * co)
|
|||
unit *mage = co->magician.u;
|
||||
int cast_level = co->level;
|
||||
const race *rc;
|
||||
int dh;
|
||||
message *msg;
|
||||
char zText[2048];
|
||||
|
||||
|
@ -553,7 +552,8 @@ static int sp_summon_familiar(castorder * co)
|
|||
|
||||
if (fval(rc, RCF_SWIM) && !fval(rc, RCF_WALK)) {
|
||||
int coasts = is_coastregion(r);
|
||||
int dir;
|
||||
int dir, dh;
|
||||
|
||||
if (coasts == 0) {
|
||||
cmistake(mage, co->order, 229, MSG_MAGIC);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue