forked from github/server
cppcheck niggles.
This commit is contained in:
parent
26dc593ddb
commit
3cd51fe384
9 changed files with 25 additions and 84 deletions
16
src/battle.c
16
src/battle.c
|
@ -948,22 +948,6 @@ void drain_exp(struct unit *u, int n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *rel_dam(int dam, int hp)
|
|
||||||
{
|
|
||||||
double q = (double)dam / (double)hp;
|
|
||||||
|
|
||||||
if (q > 0.75) {
|
|
||||||
return "eine klaffende Wunde";
|
|
||||||
}
|
|
||||||
else if (q > 0.5) {
|
|
||||||
return "eine schwere Wunde";
|
|
||||||
}
|
|
||||||
else if (q > 0.25) {
|
|
||||||
return "eine Wunde";
|
|
||||||
}
|
|
||||||
return "eine kleine Wunde";
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vampirism(troop at, int damage)
|
static void vampirism(troop at, int damage)
|
||||||
{
|
{
|
||||||
if (rule_vampire > 0) {
|
if (rule_vampire > 0) {
|
||||||
|
|
|
@ -250,7 +250,7 @@ static void test_trade_insect(CuTest *tc) {
|
||||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s",
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s",
|
||||||
LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
||||||
|
|
||||||
set_item(u, it_silver, 10);
|
test_set_item(u, it_silver, 10);
|
||||||
CuAssertPtrEquals(tc, r, u->region);
|
CuAssertPtrEquals(tc, r, u->region);
|
||||||
CuAssertPtrEquals(tc, (void *)it_luxury, (void *)r_luxury(u->region));
|
CuAssertPtrEquals(tc, (void *)it_luxury, (void *)r_luxury(u->region));
|
||||||
produce(u->region);
|
produce(u->region);
|
||||||
|
@ -283,7 +283,7 @@ static void test_buy_cmd(CuTest *tc) {
|
||||||
|
|
||||||
u = test_create_unit(test_create_faction(NULL), r);
|
u = test_create_unit(test_create_faction(NULL), r);
|
||||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s", LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
unit_addorder(u, create_order(K_BUY, u->faction->locale, "1 %s", LOC(u->faction->locale, resourcename(it_luxury->rtype, 0))));
|
||||||
set_item(u, rt_silver->itype, 1000);
|
test_set_item(u, rt_silver->itype, 1000);
|
||||||
|
|
||||||
produce(r);
|
produce(r);
|
||||||
CuAssertPtrNotNullMsg(tc, "trading requires a castle", test_find_messagetype(u->faction->msgs, "error119"));
|
CuAssertPtrNotNullMsg(tc, "trading requires a castle", test_find_messagetype(u->faction->msgs, "error119"));
|
||||||
|
@ -525,13 +525,13 @@ static void test_modify_material(CuTest *tc) {
|
||||||
itype->construction->materials[0].rtype = rtype;
|
itype->construction->materials[0].rtype = rtype;
|
||||||
itype->construction->materials[0].number = 2;
|
itype->construction->materials[0].number = 2;
|
||||||
|
|
||||||
set_item(u, rtype->itype, 1); /* 1 iron should get us 1 sword */
|
test_set_item(u, rtype->itype, 1); /* 1 iron should get us 1 sword */
|
||||||
make_item(u, itype, 1);
|
make_item(u, itype, 1);
|
||||||
CuAssertIntEquals(tc, 1, get_item(u, itype));
|
CuAssertIntEquals(tc, 1, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
||||||
|
|
||||||
u_setrace(u, test_create_race("smurf"));
|
u_setrace(u, test_create_race("smurf"));
|
||||||
set_item(u, rtype->itype, 2); /* 2 iron should be required now */
|
test_set_item(u, rtype->itype, 2); /* 2 iron should be required now */
|
||||||
make_item(u, itype, 1);
|
make_item(u, itype, 1);
|
||||||
CuAssertIntEquals(tc, 2, get_item(u, itype));
|
CuAssertIntEquals(tc, 2, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
||||||
|
@ -576,20 +576,20 @@ static void test_modify_skill(CuTest *tc) {
|
||||||
mod[0].value.sa[1] = 1;
|
mod[0].value.sa[1] = 1;
|
||||||
mod[0].race_mask = rc_mask(u_race(u));
|
mod[0].race_mask = rc_mask(u_race(u));
|
||||||
|
|
||||||
set_item(u, rtype->itype, 2); /* 2 iron should get us 2 swords */
|
test_set_item(u, rtype->itype, 2); /* 2 iron should get us 2 swords */
|
||||||
make_item(u, itype, 2);
|
make_item(u, itype, 2);
|
||||||
CuAssertIntEquals(tc, 2, get_item(u, itype));
|
CuAssertIntEquals(tc, 2, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
||||||
|
|
||||||
mod[0].value.sa[0] = NOSKILL; /* match any skill */
|
mod[0].value.sa[0] = NOSKILL; /* match any skill */
|
||||||
set_item(u, rtype->itype, 2);
|
test_set_item(u, rtype->itype, 2);
|
||||||
make_item(u, itype, 2);
|
make_item(u, itype, 2);
|
||||||
CuAssertIntEquals(tc, 4, get_item(u, itype));
|
CuAssertIntEquals(tc, 4, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
CuAssertIntEquals(tc, 0, get_item(u, rtype->itype));
|
||||||
|
|
||||||
|
|
||||||
u_setrace(u, test_create_race("smurf"));
|
u_setrace(u, test_create_race("smurf"));
|
||||||
set_item(u, rtype->itype, 2);
|
test_set_item(u, rtype->itype, 2);
|
||||||
make_item(u, itype, 1); /* only enough skill to make 1 now */
|
make_item(u, itype, 1); /* only enough skill to make 1 now */
|
||||||
CuAssertIntEquals(tc, 5, get_item(u, itype));
|
CuAssertIntEquals(tc, 5, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 1, get_item(u, rtype->itype));
|
CuAssertIntEquals(tc, 1, get_item(u, rtype->itype));
|
||||||
|
@ -626,7 +626,7 @@ static void test_modify_production(CuTest *tc) {
|
||||||
itype->construction->materials[0].rtype = rt_silver;
|
itype->construction->materials[0].rtype = rt_silver;
|
||||||
itype->construction->materials[0].number = 1;
|
itype->construction->materials[0].number = 1;
|
||||||
set_level(u, SK_ALCHEMY, 1);
|
set_level(u, SK_ALCHEMY, 1);
|
||||||
set_item(u, rt_silver->itype, 1);
|
test_set_item(u, rt_silver->itype, 1);
|
||||||
make_item(u, itype, 1);
|
make_item(u, itype, 1);
|
||||||
CuAssertIntEquals(tc, 1, get_item(u, itype));
|
CuAssertIntEquals(tc, 1, get_item(u, itype));
|
||||||
CuAssertIntEquals(tc, 0, get_item(u, rt_silver->itype));
|
CuAssertIntEquals(tc, 0, get_item(u, rt_silver->itype));
|
||||||
|
|
|
@ -73,36 +73,6 @@ void free_borders(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection *find_border(int id)
|
|
||||||
{
|
|
||||||
int key;
|
|
||||||
for (key = 0; key != BORDER_MAXHASH; key++) {
|
|
||||||
connection *bhash;
|
|
||||||
for (bhash = borders[key]; bhash != NULL; bhash = bhash->nexthash) {
|
|
||||||
connection *b;
|
|
||||||
for (b = bhash; b; b = b->next) {
|
|
||||||
if (b->id == id)
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int resolve_borderid(variant id, void *addr)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
connection *b = NULL;
|
|
||||||
if (id.i != 0) {
|
|
||||||
b = find_border(id.i);
|
|
||||||
if (b == NULL) {
|
|
||||||
result = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*(connection **)addr = b;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void walk_i(region *r, connection *b, void(*cb)(connection *, void *), void *data) {
|
static void walk_i(region *r, connection *b, void(*cb)(connection *, void *), void *data) {
|
||||||
for (; b; b = b->nexthash) {
|
for (; b; b = b->nexthash) {
|
||||||
if (b->from == r || b->to == r) {
|
if (b->from == r || b->to == r) {
|
||||||
|
|
|
@ -97,8 +97,6 @@ extern "C" {
|
||||||
struct border_type *next; /* for internal use only */
|
struct border_type *next; /* for internal use only */
|
||||||
} border_type;
|
} border_type;
|
||||||
|
|
||||||
connection *find_border(int id);
|
|
||||||
int resolve_borderid(variant data, void *addr);
|
|
||||||
void free_borders(void);
|
void free_borders(void);
|
||||||
|
|
||||||
void walk_connections(struct region *r, void(*cb)(struct connection *, void *), void *data);
|
void walk_connections(struct region *r, void(*cb)(struct connection *, void *), void *data);
|
||||||
|
|
|
@ -582,22 +582,6 @@ int get_item(const unit * u, const item_type *itype)
|
||||||
return i ? i->number : 0;
|
return i ? i->number : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_item(unit * u, const item_type *itype, int value)
|
|
||||||
{
|
|
||||||
item *i;
|
|
||||||
|
|
||||||
assert(itype);
|
|
||||||
i = *i_find(&u->items, itype);
|
|
||||||
if (!i) {
|
|
||||||
i = i_add(&u->items, i_new(itype, value));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
i->number = value;
|
|
||||||
assert(i->number >= 0);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -284,7 +284,6 @@ extern "C" {
|
||||||
struct item *item_spoil(const struct race *rc, int size);
|
struct item *item_spoil(const struct race *rc, int size);
|
||||||
|
|
||||||
int get_item(const struct unit * u, const struct item_type *itype);
|
int get_item(const struct unit * u, const struct item_type *itype);
|
||||||
int set_item(struct unit * u, const struct item_type *itype, int value);
|
|
||||||
int get_money(const struct unit *);
|
int get_money(const struct unit *);
|
||||||
int set_money(struct unit *, int);
|
int set_money(struct unit *, int);
|
||||||
int change_money(struct unit *, int);
|
int change_money(struct unit *, int);
|
||||||
|
|
11
src/move.c
11
src/move.c
|
@ -2022,17 +2022,6 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
|
||||||
* the token parser needs to be initialized before calling this function!
|
* the token parser needs to be initialized before calling this function!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** fleeing units use this function
|
|
||||||
*/
|
|
||||||
void run_to(unit * u, region * to)
|
|
||||||
{
|
|
||||||
region_list *route = NULL;
|
|
||||||
add_regionlist(&route, to);
|
|
||||||
travel_route(u, route, NULL, NULL, TRAVEL_RUNNING);
|
|
||||||
free_regionlist(route);
|
|
||||||
/* weder transport noch follow */
|
|
||||||
}
|
|
||||||
|
|
||||||
static const region_list *travel_i(unit * u, const region_list * route_begin,
|
static const region_list *travel_i(unit * u, const region_list * route_begin,
|
||||||
const region_list * route_end, order * ord, int mode, follower ** followers)
|
const region_list * route_end, order * ord, int mode, follower ** followers)
|
||||||
{
|
{
|
||||||
|
|
16
src/tests.c
16
src/tests.c
|
@ -37,6 +37,22 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
int test_set_item(unit * u, const item_type *itype, int value)
|
||||||
|
{
|
||||||
|
item *i;
|
||||||
|
|
||||||
|
assert(itype);
|
||||||
|
i = *i_find(&u->items, itype);
|
||||||
|
if (!i) {
|
||||||
|
i = i_add(&u->items, i_new(itype, value));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i->number = value;
|
||||||
|
assert(i->number >= 0);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
struct race *test_create_race(const char *name)
|
struct race *test_create_race(const char *name)
|
||||||
{
|
{
|
||||||
race *rc = rc_get_or_create(name ? name : "smurf");
|
race *rc = rc_get_or_create(name ? name : "smurf");
|
||||||
|
|
|
@ -58,6 +58,7 @@ extern "C" {
|
||||||
struct building_type *test_create_buildingtype(const char *name);
|
struct building_type *test_create_buildingtype(const char *name);
|
||||||
void test_create_castorder(struct castorder *co, struct unit *u, int level, float force, int range, struct spellparameter *par);
|
void test_create_castorder(struct castorder *co, struct unit *u, int level, float force, int range, struct spellparameter *par);
|
||||||
struct spell * test_create_spell(void);
|
struct spell * test_create_spell(void);
|
||||||
|
int test_set_item(struct unit * u, const struct item_type *itype, int value);
|
||||||
|
|
||||||
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
||||||
const char * test_get_messagetype(const struct message *msg);
|
const char * test_get_messagetype(const struct message *msg);
|
||||||
|
|
Loading…
Reference in a new issue