forked from github/server
FAST_CONNECT is always on.
fix more cppcheck messages.
This commit is contained in:
parent
120b03d2f5
commit
4181e23d15
16 changed files with 17 additions and 228 deletions
|
@ -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
|
||||
|
@ -472,12 +471,12 @@ static int count_materials(unit *u, const construction *type, int n, int complet
|
|||
int c;
|
||||
for (c = 0; n > 0 && type->materials[c].number; c++) {
|
||||
const struct resource_type *rtype = type->materials[c].rtype;
|
||||
int need, prebuilt;
|
||||
int canuse = get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
|
||||
canuse = matmod(u, rtype, canuse);
|
||||
|
||||
assert(canuse >= 0);
|
||||
if (type->reqsize > 1) {
|
||||
int need, prebuilt;
|
||||
prebuilt =
|
||||
required(completed, type->reqsize, type->materials[c].number);
|
||||
for (; n;) {
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -346,14 +346,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)
|
||||
|
@ -670,11 +663,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;
|
||||
|
@ -685,6 +673,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();
|
||||
}
|
||||
|
|
|
@ -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,10 +242,10 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
|||
va_start(marker, params);
|
||||
sbs_init(&sbs, zBuffer, sizeof(zBuffer));
|
||||
while (*params) {
|
||||
int i;
|
||||
const char *s;
|
||||
tok = strchr(params, '%');
|
||||
if (tok) {
|
||||
const char *s;
|
||||
int i;
|
||||
if (tok != params) {
|
||||
sbs_strncat(&sbs, params, tok - params);
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -319,8 +319,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];
|
||||
|
@ -331,7 +329,6 @@ void runhash(region * r)
|
|||
r->connect[d] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
while (regionhash[key] != NULL && regionhash[key] != r) {
|
||||
key = (key + gk) % RMAXHASH;
|
||||
}
|
||||
|
@ -343,23 +340,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;
|
||||
}
|
||||
|
||||
|
@ -973,7 +966,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",
|
||||
|
@ -989,6 +982,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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -4211,12 +4211,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 */
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -2356,14 +2356,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) {
|
||||
|
|
91
src/names.c
91
src/names.c
|
@ -369,97 +369,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
|
||||
|
|
23
src/report.c
23
src/report.c
|
@ -2395,29 +2395,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)
|
||||
|
|
|
@ -54,11 +54,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(attrib * a, void *owner, struct gamedata *data)
|
||||
|
@ -518,24 +514,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, 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);
|
||||
|
|
|
@ -81,8 +81,6 @@ extern "C" {
|
|||
int a_age(attrib ** attribs, void *owner);
|
||||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue