forked from github/server
cppcheck warnings for battle
This commit is contained in:
parent
b67db4faf9
commit
e4aa8f505e
6 changed files with 14 additions and 26 deletions
|
@ -52,13 +52,7 @@ typedef struct dict_data {
|
||||||
char *name;
|
char *name;
|
||||||
union {
|
union {
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
|
||||||
double real;
|
double real;
|
||||||
struct unit *u;
|
|
||||||
struct region *r;
|
|
||||||
struct building *b;
|
|
||||||
struct ship *sh;
|
|
||||||
struct faction *f;
|
|
||||||
} data;
|
} data;
|
||||||
} dict_data;
|
} dict_data;
|
||||||
|
|
||||||
|
|
16
src/battle.c
16
src/battle.c
|
@ -393,7 +393,6 @@ static int get_row(const side * s, int row, const side * vs)
|
||||||
int line, result;
|
int line, result;
|
||||||
int retreat = 0;
|
int retreat = 0;
|
||||||
int size[NUMROWS];
|
int size[NUMROWS];
|
||||||
int front = 0;
|
|
||||||
battle *b = s->battle;
|
battle *b = s->battle;
|
||||||
|
|
||||||
memset(counted, 0, sizeof(counted));
|
memset(counted, 0, sizeof(counted));
|
||||||
|
@ -426,6 +425,7 @@ static int get_row(const side * s, int row, const side * vs)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (enemyfront) {
|
if (enemyfront) {
|
||||||
|
int front = 0;
|
||||||
for (line = FIRST_ROW; line != NUMROWS; ++line) {
|
for (line = FIRST_ROW; line != NUMROWS; ++line) {
|
||||||
front += size[line];
|
front += size[line];
|
||||||
if (!front || front < enemyfront / ROW_FACTOR)
|
if (!front || front < enemyfront / ROW_FACTOR)
|
||||||
|
@ -1142,7 +1142,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
|
||||||
|
|
||||||
/* Schild */
|
/* Schild */
|
||||||
side *ds = df->side;
|
side *ds = df->side;
|
||||||
int hp, ar;
|
int ar;
|
||||||
|
|
||||||
const weapon_type *dwtype = NULL;
|
const weapon_type *dwtype = NULL;
|
||||||
const weapon_type *awtype = NULL;
|
const weapon_type *awtype = NULL;
|
||||||
|
@ -1257,7 +1257,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
|
||||||
/* jeder Schaden wird um effect% reduziert bis der Schild duration
|
/* jeder Schaden wird um effect% reduziert bis der Schild duration
|
||||||
* Trefferpunkte aufgefangen hat */
|
* Trefferpunkte aufgefangen hat */
|
||||||
if (me->typ == SHIELD_REDUCE) {
|
if (me->typ == SHIELD_REDUCE) {
|
||||||
hp = rda * (me->effect / 100);
|
int hp = rda * (me->effect / 100);
|
||||||
rda -= hp;
|
rda -= hp;
|
||||||
me->duration -= hp;
|
me->duration -= hp;
|
||||||
}
|
}
|
||||||
|
@ -2875,12 +2875,9 @@ static void print_stats(battle * b)
|
||||||
{
|
{
|
||||||
side *s2;
|
side *s2;
|
||||||
side *s;
|
side *s;
|
||||||
int i = 0;
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
bfaction *bf;
|
bfaction *bf;
|
||||||
|
|
||||||
++i;
|
|
||||||
|
|
||||||
for (bf = b->factions; bf; bf = bf->next) {
|
for (bf = b->factions; bf; bf = bf->next) {
|
||||||
faction *f = bf->faction;
|
faction *f = bf->faction;
|
||||||
const char *loc_army = LOC(f->locale, "battle_army");
|
const char *loc_army = LOC(f->locale, "battle_army");
|
||||||
|
@ -3046,8 +3043,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
{
|
{
|
||||||
#define WMAX 20
|
#define WMAX 20
|
||||||
weapon weapons[WMAX];
|
weapon weapons[WMAX];
|
||||||
int owp[WMAX];
|
|
||||||
int dwp[WMAX];
|
|
||||||
region *r = b->region;
|
region *r = b->region;
|
||||||
item *itm;
|
item *itm;
|
||||||
fighter *fig = NULL;
|
fighter *fig = NULL;
|
||||||
|
@ -3160,6 +3155,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
/* F<>r alle Waffengattungen wird bestimmt, wie viele der Personen mit
|
/* F<>r alle Waffengattungen wird bestimmt, wie viele der Personen mit
|
||||||
* ihr k<EFBFBD>mpfen k<EFBFBD>nnten, und was ihr Wert darin ist. */
|
* ihr k<EFBFBD>mpfen k<EFBFBD>nnten, und was ihr Wert darin ist. */
|
||||||
if (u_race(u)->battle_flags & BF_EQUIPMENT) {
|
if (u_race(u)->battle_flags & BF_EQUIPMENT) {
|
||||||
|
int owp[WMAX];
|
||||||
|
int dwp[WMAX];
|
||||||
int oi = 0, di = 0, w = 0;
|
int oi = 0, di = 0, w = 0;
|
||||||
for (itm = u->items; itm && w != WMAX; itm = itm->next) {
|
for (itm = u->items; itm && w != WMAX; itm = itm->next) {
|
||||||
const weapon_type *wtype = resource2weapon(itm->type->rtype);
|
const weapon_type *wtype = resource2weapon(itm->type->rtype);
|
||||||
|
@ -3480,7 +3477,6 @@ static int battle_report(battle * b)
|
||||||
{
|
{
|
||||||
side *s, *s2;
|
side *s, *s2;
|
||||||
bool cont = false;
|
bool cont = false;
|
||||||
bool komma;
|
|
||||||
bfaction *bf;
|
bfaction *bf;
|
||||||
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
|
@ -3503,6 +3499,7 @@ static int battle_report(battle * b)
|
||||||
char buf[32 * MAXSIDES];
|
char buf[32 * MAXSIDES];
|
||||||
message *m;
|
message *m;
|
||||||
sbstring sbs;
|
sbstring sbs;
|
||||||
|
bool komma = false;
|
||||||
|
|
||||||
sbs_init(&sbs, buf, sizeof(buf));
|
sbs_init(&sbs, buf, sizeof(buf));
|
||||||
battle_message_faction(b, fac, msg_separator);
|
battle_message_faction(b, fac, msg_separator);
|
||||||
|
@ -3514,7 +3511,6 @@ static int battle_report(battle * b)
|
||||||
battle_message_faction(b, fac, m);
|
battle_message_faction(b, fac, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
|
|
||||||
komma = false;
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
if (s->alive) {
|
if (s->alive) {
|
||||||
int r, k = 0, *alive = get_alive(s);
|
int r, k = 0, *alive = get_alive(s);
|
||||||
|
|
|
@ -446,7 +446,6 @@ static void test_battle_skilldiff(CuTest *tc)
|
||||||
td.index = 0;
|
td.index = 0;
|
||||||
ta.fighter = setup_fighter(&b, ua);
|
ta.fighter = setup_fighter(&b, ua);
|
||||||
ta.index = 0;
|
ta.index = 0;
|
||||||
ua = test_create_unit(test_create_faction(NULL), r);
|
|
||||||
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
||||||
|
|
||||||
ta.fighter->person[0].attack = 2;
|
ta.fighter->person[0].attack = 2;
|
||||||
|
@ -483,7 +482,6 @@ static void test_battle_skilldiff_building(CuTest *tc)
|
||||||
td.index = 0;
|
td.index = 0;
|
||||||
ta.fighter = setup_fighter(&b, ua);
|
ta.fighter = setup_fighter(&b, ua);
|
||||||
ta.index = 0;
|
ta.index = 0;
|
||||||
ua = test_create_unit(test_create_faction(NULL), r);
|
|
||||||
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
||||||
|
|
||||||
ud->building->size = 10;
|
ud->building->size = 10;
|
||||||
|
@ -502,8 +500,8 @@ static void test_battle_skilldiff_building(CuTest *tc)
|
||||||
static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax)
|
static void assert_skill(CuTest *tc, const char *msg, unit *u, skill_t sk, int level, int week, int weekmax)
|
||||||
{
|
{
|
||||||
skill *sv = unit_skill(u, sk);
|
skill *sv = unit_skill(u, sk);
|
||||||
char buf[256];
|
|
||||||
if (sv) {
|
if (sv) {
|
||||||
|
char buf[256];
|
||||||
sprintf(buf, "%s level %d != %d", msg, sv->level, level);
|
sprintf(buf, "%s level %d != %d", msg, sv->level, level);
|
||||||
CuAssertIntEquals_Msg(tc, buf, level, sv->level);
|
CuAssertIntEquals_Msg(tc, buf, level, sv->level);
|
||||||
sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax);
|
sprintf(buf, "%s week %d !<= %d !<= %d", msg, week, sv->weeks, weekmax);
|
||||||
|
|
|
@ -63,11 +63,11 @@ int config_parse(const char *json)
|
||||||
|
|
||||||
int config_read(const char *filename, const char * relpath)
|
int config_read(const char *filename, const char * relpath)
|
||||||
{
|
{
|
||||||
char name[PATH_MAX];
|
|
||||||
FILE *F;
|
FILE *F;
|
||||||
|
|
||||||
json_relpath = relpath;
|
json_relpath = relpath;
|
||||||
if (relpath) {
|
if (relpath) {
|
||||||
|
char name[PATH_MAX];
|
||||||
path_join(relpath, filename, name, sizeof(name));
|
path_join(relpath, filename, name, sizeof(name));
|
||||||
F = fopen(name, "r");
|
F = fopen(name, "r");
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define PATH_DELIM '\\'
|
||||||
|
#else
|
||||||
|
#define PATH_DELIM '/'
|
||||||
|
#endif
|
||||||
|
|
||||||
char * path_join(const char *p1, const char *p2, char *dst, size_t len) {
|
char * path_join(const char *p1, const char *p2, char *dst, size_t len) {
|
||||||
size_t sz;
|
size_t sz;
|
||||||
assert(p1 && p2);
|
assert(p1 && p2);
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define PATH_DELIM '\\'
|
|
||||||
#else
|
|
||||||
#define PATH_DELIM '/'
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char * path_join(const char *p1, const char *p2, char *dst, size_t len);
|
char * path_join(const char *p1, const char *p2, char *dst, size_t len);
|
||||||
|
|
Loading…
Reference in a new issue