forked from github/server
some static analysis warnings (cppcheck and msvc).
This commit is contained in:
parent
83556f8010
commit
45c44a03fb
6 changed files with 67 additions and 51 deletions
|
@ -110,7 +110,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
||||||
/* invariant: unit ti can still teach i students */
|
/* invariant: unit ti can still teach i students */
|
||||||
int s, i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
int s, i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
||||||
/* invariant: unit si has n students that can still be taught */
|
/* invariant: unit si has n students that can still be taught */
|
||||||
int n = scholars[si].u->number;
|
int s, n = scholars[si].u->number;
|
||||||
for (t = ti, s = si; t != si && s != se; ) {
|
for (t = ti, s = si; t != si && s != se; ) {
|
||||||
if (i >= n) {
|
if (i >= n) {
|
||||||
/* t has more than enough teaching capacity for s */
|
/* t has more than enough teaching capacity for s */
|
||||||
|
|
64
src/battle.c
64
src/battle.c
|
@ -697,23 +697,20 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effektiver Waffenskill waehrend des Kampfes.
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking,
|
weapon_effskill(troop t, troop enemy, const weapon * w,
|
||||||
bool missile)
|
bool attacking, bool missile)
|
||||||
/* effektiver Waffenskill w<>hrend des Kampfes */
|
|
||||||
{
|
{
|
||||||
/* In dieser Runde alle die Modifier berechnen, die fig durch die
|
|
||||||
* Waffen bekommt. */
|
|
||||||
fighter *tf = t.fighter;
|
fighter *tf = t.fighter;
|
||||||
unit *tu = t.fighter->unit;
|
unit *tu = t.fighter->unit;
|
||||||
int skill;
|
/* Alle Modifier berechnen, die fig durch die Waffen bekommt. */
|
||||||
const weapon_type *wtype = w ? w->type : NULL;
|
if (w) {
|
||||||
|
int skill = 0;
|
||||||
|
const weapon_type *wtype = w->type;
|
||||||
|
|
||||||
if (wtype == NULL) {
|
|
||||||
/* Ohne Waffe: Waffenlose Angriffe */
|
|
||||||
skill = weapon_skill(NULL, tu, attacking);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (attacking) {
|
if (attacking) {
|
||||||
skill = w->attackskill;
|
skill = w->attackskill;
|
||||||
}
|
}
|
||||||
|
@ -745,30 +742,31 @@ bool missile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
/* Burgenbonus, Pferdebonus */
|
||||||
|
if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
|
||||||
|
&& !fval(wtype, WTF_MISSILE)))) {
|
||||||
|
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Burgenbonus, Pferdebonus */
|
if (t.index < tf->elvenhorses) {
|
||||||
if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
|
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
||||||
&& !fval(wtype, WTF_MISSILE)))) {
|
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
||||||
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
|
* WMF_ELVENHORSE einbauen. */
|
||||||
}
|
skill += 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (t.index < tf->elvenhorses) {
|
if (skill > 0 && !attacking && missile) {
|
||||||
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
/*
|
||||||
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
* Wenn ich verteidige, und nicht direkt meinem Feind gegen<EFBFBD>berstehe,
|
||||||
* WMF_ELVENHORSE einbauen. */
|
* halbiert sich mein Skill: (z.B. gegen Fernk<EFBFBD>mpfer. Nahk<EFBFBD>mpfer
|
||||||
skill += 2;
|
* k<EFBFBD>nnen mich eh nicht treffen)
|
||||||
|
*/
|
||||||
|
skill /= 2;
|
||||||
|
}
|
||||||
|
return skill;
|
||||||
}
|
}
|
||||||
|
/* no weapon: fight weaponless */
|
||||||
if (skill > 0 && !attacking && missile) {
|
return weapon_skill(NULL, tu, attacking);
|
||||||
/*
|
|
||||||
* Wenn ich verteidige, und nicht direkt meinem Feind gegen<EFBFBD>berstehe,
|
|
||||||
* halbiert sich mein Skill: (z.B. gegen Fernk<EFBFBD>mpfer. Nahk<EFBFBD>mpfer
|
|
||||||
* k<EFBFBD>nnen mich eh nicht treffen)
|
|
||||||
*/
|
|
||||||
skill /= 2;
|
|
||||||
}
|
|
||||||
return skill;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const armor_type *select_armor(troop t, bool shield)
|
const armor_type *select_armor(troop t, bool shield)
|
||||||
|
|
|
@ -123,6 +123,16 @@ static void test_select_weapon_restricted(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 0, af->weapons[0].count);
|
CuAssertIntEquals(tc, 0, af->weapons[0].count);
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
itype->mask_deny = 0;
|
||||||
|
itype->mask_allow = rc_mask(au->_race);
|
||||||
|
b = make_battle(au->region);
|
||||||
|
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
|
||||||
|
CuAssertPtrNotNull(tc, af->weapons);
|
||||||
|
CuAssertIntEquals(tc, 1, af->weapons[0].count);
|
||||||
|
CuAssertPtrEquals(tc, itype->rtype->wtype, (void *)af->weapons[0].type);
|
||||||
|
CuAssertIntEquals(tc, 0, af->weapons[1].count);
|
||||||
|
free_battle(b);
|
||||||
|
|
||||||
itype->mask_deny = 0;
|
itype->mask_deny = 0;
|
||||||
itype->mask_allow = rc_mask(rc);
|
itype->mask_allow = rc_mask(rc);
|
||||||
b = make_battle(au->region);
|
b = make_battle(au->region);
|
||||||
|
|
|
@ -106,27 +106,31 @@ int findoption(const char *s, const struct locale *lang)
|
||||||
|
|
||||||
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
||||||
|
|
||||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
|
||||||
static int *forbidden_ids;
|
static int *forbidden_ids;
|
||||||
|
|
||||||
int 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) {
|
||||||
return 1;
|
return true;
|
||||||
|
}
|
||||||
if (!forbidden_ids) {
|
if (!forbidden_ids) {
|
||||||
while (forbidden[len])
|
while (forbidden[len])
|
||||||
++len;
|
++len;
|
||||||
forbidden_ids = calloc(len, sizeof(int));
|
forbidden_ids = malloc(len * sizeof(int));
|
||||||
|
if (!forbidden_ids) abort();
|
||||||
for (i = 0; i != len; ++i) {
|
for (i = 0; i != len; ++i) {
|
||||||
forbidden_ids[i] = atoi36(forbidden[i]);
|
forbidden_ids[i] = atoi36(forbidden[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i != len; ++i)
|
for (i = 0; i != len; ++i) {
|
||||||
if (id == forbidden_ids[i])
|
if (id == forbidden_ids[i]) {
|
||||||
return 1;
|
return true;
|
||||||
return 0;
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newcontainerid(void)
|
int newcontainerid(void)
|
||||||
|
@ -274,6 +278,7 @@ void set_param(struct param **p, const char *key, const char *value)
|
||||||
par = *p;
|
par = *p;
|
||||||
if (!par && value) {
|
if (!par && value) {
|
||||||
*p = par = calloc(1, sizeof(param));
|
*p = par = calloc(1, sizeof(param));
|
||||||
|
if (!par) abort();
|
||||||
}
|
}
|
||||||
if (par) {
|
if (par) {
|
||||||
void *match;
|
void *match;
|
||||||
|
@ -509,7 +514,6 @@ order *default_order(const struct locale *lang)
|
||||||
int i = locale_index(lang);
|
int i = locale_index(lang);
|
||||||
keyword_t kwd;
|
keyword_t kwd;
|
||||||
const char * str;
|
const char * str;
|
||||||
order *result = 0;
|
|
||||||
|
|
||||||
assert(i < MAXLOCALES);
|
assert(i < MAXLOCALES);
|
||||||
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
||||||
|
@ -518,7 +522,8 @@ order *default_order(const struct locale *lang)
|
||||||
kwd = findkeyword(str);
|
kwd = findkeyword(str);
|
||||||
}
|
}
|
||||||
if (kwd != NOKEYWORD) {
|
if (kwd != NOKEYWORD) {
|
||||||
result = create_order(kwd, lang, NULL);
|
/* TODO: why is there a copy_order made here? */
|
||||||
|
order *result = create_order(kwd, lang, NULL);
|
||||||
return copy_order(result);
|
return copy_order(result);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -52,7 +52,7 @@ extern "C" {
|
||||||
void init_locale(struct locale *lang);
|
void init_locale(struct locale *lang);
|
||||||
void init_races(struct locale *lang);
|
void init_races(struct locale *lang);
|
||||||
|
|
||||||
int forbiddenid(int id);
|
bool forbiddenid(int id);
|
||||||
int newcontainerid(void);
|
int newcontainerid(void);
|
||||||
|
|
||||||
bool rule_region_owners(void);
|
bool rule_region_owners(void);
|
||||||
|
|
|
@ -194,12 +194,10 @@ resource_type *rt_get_or_create(const char *name) {
|
||||||
if (!rtype) {
|
if (!rtype) {
|
||||||
rtype = calloc(1, sizeof(resource_type));
|
rtype = calloc(1, sizeof(resource_type));
|
||||||
if (!rtype) {
|
if (!rtype) {
|
||||||
perror("resource_type allocation failed");
|
abort();
|
||||||
}
|
|
||||||
else {
|
|
||||||
rtype->_name = str_strdup(name);
|
|
||||||
rt_register(rtype);
|
|
||||||
}
|
}
|
||||||
|
rtype->_name = str_strdup(name);
|
||||||
|
rt_register(rtype);
|
||||||
}
|
}
|
||||||
return rtype;
|
return rtype;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +245,7 @@ item_type *it_get_or_create(resource_type *rtype) {
|
||||||
if (!rtype->itype) {
|
if (!rtype->itype) {
|
||||||
item_type * itype;
|
item_type * itype;
|
||||||
itype = (item_type *)calloc(sizeof(item_type), 1);
|
itype = (item_type *)calloc(sizeof(item_type), 1);
|
||||||
|
if (!itype) abort();
|
||||||
itype->rtype = rtype;
|
itype->rtype = rtype;
|
||||||
rtype->uchange = res_changeitem;
|
rtype->uchange = res_changeitem;
|
||||||
rtype->itype = itype;
|
rtype->itype = itype;
|
||||||
|
@ -269,6 +268,7 @@ luxury_type *new_luxurytype(item_type * itype, int price)
|
||||||
assert(resource2luxury(itype->rtype) == NULL);
|
assert(resource2luxury(itype->rtype) == NULL);
|
||||||
|
|
||||||
ltype = calloc(sizeof(luxury_type), 1);
|
ltype = calloc(sizeof(luxury_type), 1);
|
||||||
|
if (!ltype) abort();
|
||||||
ltype->itype = itype;
|
ltype->itype = itype;
|
||||||
ltype->price = price;
|
ltype->price = price;
|
||||||
lt_register(ltype);
|
lt_register(ltype);
|
||||||
|
@ -285,6 +285,7 @@ weapon_type *new_weapontype(item_type * itype,
|
||||||
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
||||||
|
|
||||||
wtype = calloc(sizeof(weapon_type), 1);
|
wtype = calloc(sizeof(weapon_type), 1);
|
||||||
|
if (!wtype) abort();
|
||||||
if (damage) {
|
if (damage) {
|
||||||
wtype->damage[0] = str_strdup(damage[0]);
|
wtype->damage[0] = str_strdup(damage[0]);
|
||||||
wtype->damage[1] = str_strdup(damage[1]);
|
wtype->damage[1] = str_strdup(damage[1]);
|
||||||
|
@ -309,6 +310,7 @@ armor_type *new_armortype(item_type * itype, double penalty, variant magres,
|
||||||
assert(itype->rtype->atype == NULL);
|
assert(itype->rtype->atype == NULL);
|
||||||
|
|
||||||
atype = calloc(sizeof(armor_type), 1);
|
atype = calloc(sizeof(armor_type), 1);
|
||||||
|
if (!atype) abort();
|
||||||
|
|
||||||
atype->itype = itype;
|
atype->itype = itype;
|
||||||
atype->penalty = penalty;
|
atype->penalty = penalty;
|
||||||
|
@ -530,6 +532,7 @@ item *i_new(const item_type * itype, int size)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i = malloc(sizeof(item));
|
i = malloc(sizeof(item));
|
||||||
|
if (!i) abort();
|
||||||
}
|
}
|
||||||
assert(itype);
|
assert(itype);
|
||||||
i->next = NULL;
|
i->next = NULL;
|
||||||
|
|
Loading…
Reference in a new issue