forked from github/server
some static analysis warnings (cppcheck and msvc).
This commit is contained in:
parent
ba3c63160d
commit
2ac6a6826d
|
@ -110,7 +110,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
/* invariant: unit ti can still teach i students */
|
||||
int s, i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
||||
/* 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; ) {
|
||||
if (i >= n) {
|
||||
/* t has more than enough teaching capacity for s */
|
||||
|
|
66
src/battle.c
66
src/battle.c
|
@ -697,23 +697,20 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effektiver Waffenskill waehrend des Kampfes.
|
||||
*/
|
||||
static int
|
||||
weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking,
|
||||
bool missile)
|
||||
/* effektiver Waffenskill w<>hrend des Kampfes */
|
||||
weapon_effskill(troop t, troop enemy, const weapon * w,
|
||||
bool attacking, bool missile)
|
||||
{
|
||||
/* In dieser Runde alle die Modifier berechnen, die fig durch die
|
||||
* Waffen bekommt. */
|
||||
fighter *tf = t.fighter;
|
||||
unit *tu = t.fighter->unit;
|
||||
int skill;
|
||||
const weapon_type *wtype = w ? w->type : NULL;
|
||||
/* Alle Modifier berechnen, die fig durch die Waffen bekommt. */
|
||||
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) {
|
||||
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 (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
|
||||
&& !fval(wtype, WTF_MISSILE)))) {
|
||||
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
|
||||
}
|
||||
if (t.index < tf->elvenhorses) {
|
||||
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
||||
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
||||
* WMF_ELVENHORSE einbauen. */
|
||||
skill += 2;
|
||||
}
|
||||
|
||||
if (t.index < tf->elvenhorses) {
|
||||
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
||||
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
||||
* WMF_ELVENHORSE einbauen. */
|
||||
skill += 2;
|
||||
if (skill > 0 && !attacking && missile) {
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
if (skill > 0 && !attacking && missile) {
|
||||
/*
|
||||
* 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;
|
||||
/* no weapon: fight weaponless */
|
||||
return weapon_skill(NULL, tu, attacking);
|
||||
}
|
||||
|
||||
const armor_type *select_armor(troop t, bool shield)
|
||||
|
@ -1318,7 +1316,7 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile
|
|||
++at.fighter->hits;
|
||||
|
||||
calculate_attack_type(at, dt, type, missile, &awtype, &attskill, &magic);
|
||||
calculate_defense_type(at, dt, type, missile, &awtype, &attskill);
|
||||
calculate_defense_type(at, dt, type, missile, &dwtype, &defskill);
|
||||
|
||||
if (is_riding(at) && (awtype == NULL || (fval(awtype, WTF_HORSEBONUS)
|
||||
&& !fval(awtype, WTF_MISSILE)))) {
|
||||
|
|
|
@ -123,6 +123,16 @@ static void test_select_weapon_restricted(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, 0, af->weapons[0].count);
|
||||
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_allow = rc_mask(rc);
|
||||
b = make_battle(au->region);
|
||||
|
|
|
@ -106,27 +106,31 @@ int findoption(const char *s, const struct locale *lang)
|
|||
|
||||
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
||||
|
||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
||||
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;
|
||||
size_t i;
|
||||
if (id <= 0)
|
||||
return 1;
|
||||
if (id <= 0) {
|
||||
return true;
|
||||
}
|
||||
if (!forbidden_ids) {
|
||||
while (forbidden[len])
|
||||
++len;
|
||||
forbidden_ids = calloc(len, sizeof(int));
|
||||
forbidden_ids = malloc(len * sizeof(int));
|
||||
if (!forbidden_ids) abort();
|
||||
for (i = 0; i != len; ++i) {
|
||||
forbidden_ids[i] = atoi36(forbidden[i]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i != len; ++i)
|
||||
if (id == forbidden_ids[i])
|
||||
return 1;
|
||||
return 0;
|
||||
for (i = 0; i != len; ++i) {
|
||||
if (id == forbidden_ids[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int newcontainerid(void)
|
||||
|
@ -274,6 +278,7 @@ void set_param(struct param **p, const char *key, const char *value)
|
|||
par = *p;
|
||||
if (!par && value) {
|
||||
*p = par = calloc(1, sizeof(param));
|
||||
if (!par) abort();
|
||||
}
|
||||
if (par) {
|
||||
void *match;
|
||||
|
@ -509,7 +514,6 @@ order *default_order(const struct locale *lang)
|
|||
int i = locale_index(lang);
|
||||
keyword_t kwd;
|
||||
const char * str;
|
||||
order *result = 0;
|
||||
|
||||
assert(i < MAXLOCALES);
|
||||
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
||||
|
@ -518,7 +522,8 @@ order *default_order(const struct locale *lang)
|
|||
kwd = findkeyword(str);
|
||||
}
|
||||
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 NULL;
|
||||
|
|
|
@ -52,7 +52,7 @@ extern "C" {
|
|||
void init_locale(struct locale *lang);
|
||||
void init_races(struct locale *lang);
|
||||
|
||||
int forbiddenid(int id);
|
||||
bool forbiddenid(int id);
|
||||
int newcontainerid(void);
|
||||
|
||||
bool rule_region_owners(void);
|
||||
|
|
|
@ -194,12 +194,10 @@ resource_type *rt_get_or_create(const char *name) {
|
|||
if (!rtype) {
|
||||
rtype = calloc(1, sizeof(resource_type));
|
||||
if (!rtype) {
|
||||
perror("resource_type allocation failed");
|
||||
}
|
||||
else {
|
||||
rtype->_name = str_strdup(name);
|
||||
rt_register(rtype);
|
||||
abort();
|
||||
}
|
||||
rtype->_name = str_strdup(name);
|
||||
rt_register(rtype);
|
||||
}
|
||||
return rtype;
|
||||
}
|
||||
|
@ -247,6 +245,7 @@ item_type *it_get_or_create(resource_type *rtype) {
|
|||
if (!rtype->itype) {
|
||||
item_type * itype;
|
||||
itype = (item_type *)calloc(sizeof(item_type), 1);
|
||||
if (!itype) abort();
|
||||
itype->rtype = rtype;
|
||||
rtype->uchange = res_changeitem;
|
||||
rtype->itype = itype;
|
||||
|
@ -269,6 +268,7 @@ luxury_type *new_luxurytype(item_type * itype, int price)
|
|||
assert(resource2luxury(itype->rtype) == NULL);
|
||||
|
||||
ltype = calloc(sizeof(luxury_type), 1);
|
||||
if (!ltype) abort();
|
||||
ltype->itype = itype;
|
||||
ltype->price = price;
|
||||
lt_register(ltype);
|
||||
|
@ -285,6 +285,7 @@ weapon_type *new_weapontype(item_type * itype,
|
|||
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
||||
|
||||
wtype = calloc(sizeof(weapon_type), 1);
|
||||
if (!wtype) abort();
|
||||
if (damage) {
|
||||
wtype->damage[0] = str_strdup(damage[0]);
|
||||
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);
|
||||
|
||||
atype = calloc(sizeof(armor_type), 1);
|
||||
if (!atype) abort();
|
||||
|
||||
atype->itype = itype;
|
||||
atype->penalty = penalty;
|
||||
|
@ -530,6 +532,7 @@ item *i_new(const item_type * itype, int size)
|
|||
}
|
||||
else {
|
||||
i = malloc(sizeof(item));
|
||||
if (!i) abort();
|
||||
}
|
||||
assert(itype);
|
||||
i->next = NULL;
|
||||
|
|
Loading…
Reference in New Issue