forked from github/server
reduce variables scope (cppcheck warnings).
This commit is contained in:
parent
6d5ab44411
commit
264822a354
8 changed files with 25 additions and 32 deletions
|
@ -107,10 +107,10 @@ int findoption(const char *s, const struct locale *lang)
|
||||||
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
||||||
|
|
||||||
static int *forbidden_ids;
|
static int *forbidden_ids;
|
||||||
|
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
||||||
|
|
||||||
bool forbiddenid(int id)
|
bool forbiddenid(int id)
|
||||||
{
|
{
|
||||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
|
||||||
static size_t len;
|
static size_t len;
|
||||||
size_t i;
|
size_t i;
|
||||||
if (id <= 0) {
|
if (id <= 0) {
|
||||||
|
|
|
@ -982,9 +982,8 @@ void set_number(unit * u, int count)
|
||||||
void remove_skill(unit * u, skill_t sk)
|
void remove_skill(unit * u, skill_t sk)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
skill *sv;
|
|
||||||
for (i = 0; i != u->skill_size; ++i) {
|
for (i = 0; i != u->skill_size; ++i) {
|
||||||
sv = u->skills + i;
|
skill *sv = u->skills + i;
|
||||||
if (sv->id == sk) {
|
if (sv->id == sk) {
|
||||||
if (u->skill_size - i - 1 > 0) {
|
if (u->skill_size - i - 1 > 0) {
|
||||||
memmove(sv, sv + 1, (u->skill_size - i - 1) * sizeof(skill));
|
memmove(sv, sv + 1, (u->skill_size - i - 1) * sizeof(skill));
|
||||||
|
|
|
@ -2090,7 +2090,7 @@ castorder *create_castorder(castorder * co, unit *caster, unit * familiar, const
|
||||||
co->sp = sp;
|
co->sp = sp;
|
||||||
co->level = lev;
|
co->level = lev;
|
||||||
co->force = MagicPower(force);
|
co->force = MagicPower(force);
|
||||||
co->_rtarget = r ? r : (familiar ? familiar->region : (caster ? caster->region : 0));
|
co->_rtarget = r ? r : (familiar ? familiar->region : (caster ? caster->region : NULL));
|
||||||
co->distance = range;
|
co->distance = range;
|
||||||
co->order = copy_order(ord);
|
co->order = copy_order(ord);
|
||||||
co->par = p;
|
co->par = p;
|
||||||
|
|
|
@ -637,6 +637,7 @@ void move_ship(ship * sh, region * from, region * to, region_list * route)
|
||||||
unit **iunit = &from->units;
|
unit **iunit = &from->units;
|
||||||
unit **ulist = &to->units;
|
unit **ulist = &to->units;
|
||||||
|
|
||||||
|
assert(sh);
|
||||||
if (from != to) {
|
if (from != to) {
|
||||||
translist(&from->ships, &to->ships, sh);
|
translist(&from->ships, &to->ships, sh);
|
||||||
sh->region = to;
|
sh->region = to;
|
||||||
|
@ -1676,10 +1677,9 @@ static bool ship_ready(const region * r, unit * u, order * ord)
|
||||||
unit *owner_buildingtyp(const region * r, const building_type * bt)
|
unit *owner_buildingtyp(const region * r, const building_type * bt)
|
||||||
{
|
{
|
||||||
building *b;
|
building *b;
|
||||||
unit *owner;
|
|
||||||
|
|
||||||
for (b = rbuildings(r); b; b = b->next) {
|
for (b = rbuildings(r); b; b = b->next) {
|
||||||
owner = building_owner(b);
|
unit *owner = building_owner(b);
|
||||||
if (b->type == bt && owner != NULL) {
|
if (b->type == bt && owner != NULL) {
|
||||||
if (building_finished(b)) {
|
if (building_finished(b)) {
|
||||||
return owner;
|
return owner;
|
||||||
|
@ -1971,7 +1971,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
|
||||||
/* Hafengebühren ? */
|
/* Hafengebühren ? */
|
||||||
|
|
||||||
harbourmaster = owner_buildingtyp(current_point, bt_find("harbour"));
|
harbourmaster = owner_buildingtyp(current_point, bt_find("harbour"));
|
||||||
if (sh && harbourmaster != NULL) {
|
if (harbourmaster != NULL) {
|
||||||
item *itm;
|
item *itm;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
item *trans = NULL;
|
item *trans = NULL;
|
||||||
|
|
22
src/report.c
22
src/report.c
|
@ -432,7 +432,7 @@ void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct
|
||||||
|
|
||||||
void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
|
void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
|
||||||
{
|
{
|
||||||
int k, itemanz, costtyp;
|
int k;
|
||||||
bool cont;
|
bool cont;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
const spell *sp = spellref_get(&sbe->spref);
|
const spell *sp = spellref_get(&sbe->spref);
|
||||||
|
@ -471,8 +471,8 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la
|
||||||
paragraph(out, LOC(lang, "nr_spell_components"), 0, 0, 0);
|
paragraph(out, LOC(lang, "nr_spell_components"), 0, 0, 0);
|
||||||
for (k = 0; sp->components[k].type; ++k) {
|
for (k = 0; sp->components[k].type; ++k) {
|
||||||
const resource_type *rtype = sp->components[k].type;
|
const resource_type *rtype = sp->components[k].type;
|
||||||
itemanz = sp->components[k].amount;
|
int itemanz = sp->components[k].amount;
|
||||||
costtyp = sp->components[k].cost;
|
int costtyp = sp->components[k].cost;
|
||||||
if (itemanz > 0) {
|
if (itemanz > 0) {
|
||||||
sbs_init(&sbs, buf, sizeof(buf));
|
sbs_init(&sbs, buf, sizeof(buf));
|
||||||
if (sp->sptyp & SPELLLEVEL) {
|
if (sp->sptyp & SPELLLEVEL) {
|
||||||
|
@ -519,7 +519,6 @@ static void
|
||||||
nr_curses_i(struct stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self)
|
nr_curses_i(struct stream *out, int indent, const faction *viewer, objtype_t typ, const void *obj, attrib *a, int self)
|
||||||
{
|
{
|
||||||
for (; a; a = a->next) {
|
for (; a; a = a->next) {
|
||||||
char buf[4096];
|
|
||||||
message *msg = 0;
|
message *msg = 0;
|
||||||
|
|
||||||
if (a->type == &at_curse) {
|
if (a->type == &at_curse) {
|
||||||
|
@ -536,6 +535,7 @@ nr_curses_i(struct stream *out, int indent, const faction *viewer, objtype_t typ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg) {
|
if (msg) {
|
||||||
|
char buf[4096];
|
||||||
newline(out);
|
newline(out);
|
||||||
nr_render(msg, viewer->locale, buf, sizeof(buf), viewer);
|
nr_render(msg, viewer->locale, buf, sizeof(buf), viewer);
|
||||||
paragraph(out, buf, indent, 2, 0);
|
paragraph(out, buf, indent, 2, 0);
|
||||||
|
@ -847,7 +847,6 @@ static void report_region_resource(sbstring *sbp, const struct locale *lang, con
|
||||||
static void report_region_description(struct stream *out, const region * r, faction * f, const bool see[])
|
static void report_region_description(struct stream *out, const region * r, faction * f, const bool see[])
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
bool dh;
|
|
||||||
int trees;
|
int trees;
|
||||||
int saplings;
|
int saplings;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
|
@ -986,6 +985,7 @@ static void report_region_description(struct stream *out, const region * r, fact
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int d, nrd = 0;
|
int d, nrd = 0;
|
||||||
|
bool dh = false;
|
||||||
|
|
||||||
/* Nachbarregionen, die gesehen werden, ermitteln */
|
/* Nachbarregionen, die gesehen werden, ermitteln */
|
||||||
for (d = 0; d != MAXDIRECTIONS; d++) {
|
for (d = 0; d != MAXDIRECTIONS; d++) {
|
||||||
|
@ -994,7 +994,6 @@ static void report_region_description(struct stream *out, const region * r, fact
|
||||||
}
|
}
|
||||||
|
|
||||||
/* list directions */
|
/* list directions */
|
||||||
dh = false;
|
|
||||||
for (d = 0; d != MAXDIRECTIONS; d++) {
|
for (d = 0; d != MAXDIRECTIONS; d++) {
|
||||||
if (see[d]) {
|
if (see[d]) {
|
||||||
region *r2 = rconnect(r, d);
|
region *r2 = rconnect(r, d);
|
||||||
|
@ -1037,7 +1036,6 @@ static void report_region_description(struct stream *out, const region * r, fact
|
||||||
sbs_strcat(&sbs, " (\"");
|
sbs_strcat(&sbs, " (\"");
|
||||||
sbs_strcat(&sbs, LOC(f->locale, spd->keyword));
|
sbs_strcat(&sbs, LOC(f->locale, spd->keyword));
|
||||||
sbs_strcat(&sbs, "\").");
|
sbs_strcat(&sbs, "\").");
|
||||||
dh = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pump_paragraph(&sbs, out, REPORTWIDTH, true);
|
pump_paragraph(&sbs, out, REPORTWIDTH, true);
|
||||||
|
@ -1889,7 +1887,6 @@ static void cb_write_travelthru(region *r, unit *u, void *cbdata) {
|
||||||
void report_travelthru(struct stream *out, region *r, const faction *f)
|
void report_travelthru(struct stream *out, region *r, const faction *f)
|
||||||
{
|
{
|
||||||
int maxtravel;
|
int maxtravel;
|
||||||
char buf[8192];
|
|
||||||
|
|
||||||
assert(r);
|
assert(r);
|
||||||
assert(f);
|
assert(f);
|
||||||
|
@ -1901,6 +1898,7 @@ void report_travelthru(struct stream *out, region *r, const faction *f)
|
||||||
maxtravel = count_travelthru(r, f);
|
maxtravel = count_travelthru(r, f);
|
||||||
if (maxtravel > 0) {
|
if (maxtravel > 0) {
|
||||||
cb_data cbdata;
|
cb_data cbdata;
|
||||||
|
char buf[8192];
|
||||||
|
|
||||||
init_cb(&cbdata, out, buf, sizeof(buf), f);
|
init_cb(&cbdata, out, buf, sizeof(buf), f);
|
||||||
cbdata.maxtravel = maxtravel;
|
cbdata.maxtravel = maxtravel;
|
||||||
|
@ -1960,12 +1958,11 @@ report_plaintext(const char *filename, report_context * ctx,
|
||||||
|
|
||||||
if (f->age <= 2) {
|
if (f->age <= 2) {
|
||||||
const char *email;
|
const char *email;
|
||||||
const char *subject;
|
|
||||||
email = config_get("game.email");
|
email = config_get("game.email");
|
||||||
if (!email)
|
if (!email)
|
||||||
log_error("game.email not set");
|
log_error("game.email not set");
|
||||||
else {
|
else {
|
||||||
subject = get_mailcmd(f->locale);
|
const char *subject = get_mailcmd(f->locale);
|
||||||
|
|
||||||
m = msg_message("newbie_info_game", "email subject", email, subject);
|
m = msg_message("newbie_info_game", "email subject", email, subject);
|
||||||
if (m) {
|
if (m) {
|
||||||
|
@ -2068,9 +2065,9 @@ report_plaintext(const char *filename, report_context * ctx,
|
||||||
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
|
for (a = a_find(f->attribs, &at_showitem); a && a->type == &at_showitem;
|
||||||
a = a->next) {
|
a = a->next) {
|
||||||
const item_type *itype = (const item_type *)a->data.v;
|
const item_type *itype = (const item_type *)a->data.v;
|
||||||
const char *description = NULL;
|
|
||||||
if (itype) {
|
if (itype) {
|
||||||
const char *pname = resourcename(itype->rtype, 0);
|
const char *pname = resourcename(itype->rtype, 0);
|
||||||
|
const char *description;
|
||||||
|
|
||||||
if (ch == 0) {
|
if (ch == 0) {
|
||||||
newline(out);
|
newline(out);
|
||||||
|
@ -2102,8 +2099,7 @@ report_plaintext(const char *filename, report_context * ctx,
|
||||||
}
|
}
|
||||||
centre(out, buf, true);
|
centre(out, buf, true);
|
||||||
newline(out);
|
newline(out);
|
||||||
description = mkname("describe", pname);
|
description = LOC(f->locale, mkname("describe", pname));
|
||||||
description = LOC(f->locale, description);
|
|
||||||
centre(out, description, true);
|
centre(out, description, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,11 +319,11 @@ report_items(const unit *u, item * result, int size, const unit * owner,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (itm = items; itm; itm = itm->next) {
|
for (itm = items; itm; itm = itm->next) {
|
||||||
item *ishow;
|
|
||||||
const char *ic;
|
const char *ic;
|
||||||
|
|
||||||
report_item(owner, itm, viewer, NULL, &ic, NULL, false);
|
report_item(owner, itm, viewer, NULL, &ic, NULL, false);
|
||||||
if (ic && *ic) {
|
if (ic && *ic) {
|
||||||
|
item *ishow;
|
||||||
for (ishow = result; ishow != result + n; ++ishow) {
|
for (ishow = result; ishow != result + n; ++ishow) {
|
||||||
const char *sc;
|
const char *sc;
|
||||||
|
|
||||||
|
@ -1783,9 +1783,9 @@ static void var_free_regions(variant x) /*-V524 */
|
||||||
|
|
||||||
const char *trailinto(const region * r, const struct locale *lang)
|
const char *trailinto(const region * r, const struct locale *lang)
|
||||||
{
|
{
|
||||||
static char ref[32];
|
|
||||||
const char *s;
|
|
||||||
if (r) {
|
if (r) {
|
||||||
|
static char ref[32];
|
||||||
|
const char *s;
|
||||||
const char *tname = terrain_name(r);
|
const char *tname = terrain_name(r);
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
|
|
|
@ -601,14 +601,14 @@ static void test_prepare_lighthouse_owners(CuTest *tc)
|
||||||
f = test_create_faction(NULL);
|
f = test_create_faction(NULL);
|
||||||
r1 = test_create_region(0, 0, t_plain);
|
r1 = test_create_region(0, 0, t_plain);
|
||||||
r2 = test_create_region(1, 0, t_ocean);
|
r2 = test_create_region(1, 0, t_ocean);
|
||||||
r3 = test_create_region(2, 0, t_ocean);
|
test_create_region(2, 0, t_ocean);
|
||||||
r3 = test_create_region(3, 0, t_ocean);
|
r3 = test_create_region(3, 0, t_ocean);
|
||||||
btype = test_create_buildingtype("lighthouse");
|
btype = test_create_buildingtype("lighthouse");
|
||||||
b = test_create_building(r1, btype);
|
b = test_create_building(r1, btype);
|
||||||
b->flags |= BLD_MAINTAINED;
|
b->flags |= BLD_MAINTAINED;
|
||||||
b->size = 10;
|
b->size = 10;
|
||||||
update_lighthouse(b);
|
update_lighthouse(b);
|
||||||
u = test_create_unit(f, r1);
|
test_create_unit(f, r1);
|
||||||
u = test_create_unit(test_create_faction(NULL), r1);
|
u = test_create_unit(test_create_faction(NULL), r1);
|
||||||
u->building = b;
|
u->building = b;
|
||||||
region_set_owner(b->region, f, 0);
|
region_set_owner(b->region, f, 0);
|
||||||
|
|
12
src/spells.c
12
src/spells.c
|
@ -2346,7 +2346,6 @@ static int sp_earthquake(castorder * co)
|
||||||
static void patzer_peasantmob(const castorder * co)
|
static void patzer_peasantmob(const castorder * co)
|
||||||
{
|
{
|
||||||
unit *u;
|
unit *u;
|
||||||
attrib *a;
|
|
||||||
region *r;
|
region *r;
|
||||||
unit *mage = co_get_magician(co);
|
unit *mage = co_get_magician(co);
|
||||||
r = mage->region->land ? mage->region : co_get_region(co);
|
r = mage->region->land ? mage->region : co_get_region(co);
|
||||||
|
@ -2355,6 +2354,7 @@ static void patzer_peasantmob(const castorder * co)
|
||||||
faction *f = get_monsters();
|
faction *f = get_monsters();
|
||||||
const struct locale *lang = f->locale;
|
const struct locale *lang = f->locale;
|
||||||
message *msg;
|
message *msg;
|
||||||
|
attrib *a;
|
||||||
int anteil, n;
|
int anteil, n;
|
||||||
|
|
||||||
anteil = 6 + rng_int() % 4;
|
anteil = 6 + rng_int() % 4;
|
||||||
|
@ -2410,7 +2410,6 @@ static void patzer_peasantmob(const castorder * co)
|
||||||
static int sp_forest_fire(castorder * co)
|
static int sp_forest_fire(castorder * co)
|
||||||
{
|
{
|
||||||
unit *u;
|
unit *u;
|
||||||
region *nr;
|
|
||||||
direction_t i;
|
direction_t i;
|
||||||
region *r = co_get_region(co);
|
region *r = co_get_region(co);
|
||||||
unit *caster = co_get_caster(co);
|
unit *caster = co_get_caster(co);
|
||||||
|
@ -2442,7 +2441,7 @@ static int sp_forest_fire(castorder * co)
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
|
||||||
for (i = 0; i < MAXDIRECTIONS; i++) {
|
for (i = 0; i < MAXDIRECTIONS; i++) {
|
||||||
nr = rconnect(r, i);
|
region *nr = rconnect(r, i);
|
||||||
assert(nr);
|
assert(nr);
|
||||||
destroyed = 0;
|
destroyed = 0;
|
||||||
vernichtet_schoesslinge = 0;
|
vernichtet_schoesslinge = 0;
|
||||||
|
@ -5629,7 +5628,6 @@ int sp_disruptastral(castorder * co)
|
||||||
attrib *a;
|
attrib *a;
|
||||||
double effect;
|
double effect;
|
||||||
region *r2 = rl2->data;
|
region *r2 = rl2->data;
|
||||||
spec_direction *sd;
|
|
||||||
int inhab_regions = 0;
|
int inhab_regions = 0;
|
||||||
region_list *trl = NULL;
|
region_list *trl = NULL;
|
||||||
|
|
||||||
|
@ -5649,7 +5647,7 @@ int sp_disruptastral(castorder * co)
|
||||||
|
|
||||||
while (a != NULL && a->type == &at_direction) {
|
while (a != NULL && a->type == &at_direction) {
|
||||||
attrib *a2 = a->next;
|
attrib *a2 = a->next;
|
||||||
sd = (spec_direction *)(a->data.v);
|
spec_direction *sd = (spec_direction *)(a->data.v);
|
||||||
if (sd->duration != -1)
|
if (sd->duration != -1)
|
||||||
a_remove(&r->attribs, a);
|
a_remove(&r->attribs, a);
|
||||||
a = a2;
|
a = a2;
|
||||||
|
@ -6161,7 +6159,6 @@ int sp_speed2(castorder * co)
|
||||||
*/
|
*/
|
||||||
int sp_break_curse(castorder * co)
|
int sp_break_curse(castorder * co)
|
||||||
{
|
{
|
||||||
attrib **ap;
|
|
||||||
int obj;
|
int obj;
|
||||||
curse *c;
|
curse *c;
|
||||||
region *r = co_get_region(co);
|
region *r = co_get_region(co);
|
||||||
|
@ -6169,7 +6166,6 @@ int sp_break_curse(castorder * co)
|
||||||
int cast_level = co->level;
|
int cast_level = co->level;
|
||||||
double force = co->force;
|
double force = co->force;
|
||||||
spellparameter *pa = co->par;
|
spellparameter *pa = co->par;
|
||||||
const char *ts = NULL;
|
|
||||||
|
|
||||||
if (pa->length < 2) {
|
if (pa->length < 2) {
|
||||||
/* Das Zielobjekt wurde vergessen */
|
/* Das Zielobjekt wurde vergessen */
|
||||||
|
@ -6186,6 +6182,8 @@ int sp_break_curse(castorder * co)
|
||||||
"unit region command", mage, mage->region, co->order));
|
"unit region command", mage, mage->region, co->order));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
const char *ts = NULL;
|
||||||
|
attrib **ap;
|
||||||
switch (obj) {
|
switch (obj) {
|
||||||
case SPP_REGION:
|
case SPP_REGION:
|
||||||
ap = &r->attribs;
|
ap = &r->attribs;
|
||||||
|
|
Loading…
Reference in a new issue