move atoip out of config (small helper) and test it.

remove some unnecessary variables from laws.c
This commit is contained in:
Enno Rehling 2014-12-23 09:23:37 +01:00
parent 5ebf05f625
commit b27491eccd
6 changed files with 24 additions and 26 deletions

View File

@ -587,19 +587,6 @@ int change_hitpoints(unit * u, int value)
return hp;
}
unsigned int atoip(const char *s)
{
int n;
assert(s);
n = atoi(s);
if (n < 0)
n = 0;
return n;
}
bool unit_has_cursed_item(const unit * u)
{
item *itm = u->items;

View File

@ -108,8 +108,6 @@ extern "C" {
/* special units */
void make_undead_unit(struct unit *);
unsigned int atoip(const char *s);
param_t findparam(const char *s, const struct locale *lang);
param_t findparam_ex(const char *s, const struct locale * lang);
bool isparam(const char *s, const struct locale * lang, param_t param);

View File

@ -2017,19 +2017,15 @@ int mail_cmd(unit * u, struct order *ord)
}
case P_FACTION:
{
bool see = false;
n = getfactionid();
for (u2 = r->units; u2; u2 = u2->next) {
if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) {
see = true;
break;
}
}
if (!see) {
if (!u2) {
cmistake(u, ord, 66, MSG_MESSAGE);
break;
}
@ -2041,21 +2037,17 @@ int mail_cmd(unit * u, struct order *ord)
}
mailfaction(u, n, ord, s);
return 0;
}
case P_UNIT:
{
bool see = false;
n = getid();
for (u2 = r->units; u2; u2 = u2->next) {
if (u2->no == n && cansee(u->faction, r, u2, 0)) {
see = true;
break;
}
}
if (!see) {
if (!u2) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"feedback_unit_not_found", ""));
return 0;
@ -2081,7 +2073,6 @@ int mail_cmd(unit * u, struct order *ord)
mailunit(r, u, n, ord, s);
}
return 0;
}
case P_BUILDING:
case P_GEBAEUDE:

View File

@ -240,3 +240,16 @@ int getid(void)
}
return i;
}
unsigned int atoip(const char *s)
{
int n;
assert(s);
n = atoi(s);
if (n < 0)
n = 0;
return n;
}

View File

@ -26,6 +26,8 @@ extern "C" {
unsigned int getuint(void);
int getint(void);
int getid(void);
unsigned int atoip(const char *s);
#define getshipid() getid()
#define getfactionid() getid()

View File

@ -41,9 +41,16 @@ static void test_getstrtoken(CuTest *tc) {
CuAssertPtrEquals(tc, NULL, (void *)getstrtoken());
}
static void test_atoip(CuTest *tc) {
CuAssertIntEquals(tc, 42, atoip("42"));
CuAssertIntEquals(tc, 0, atoip("-42"));
CuAssertIntEquals(tc, 0, atoip("NOPE"));
}
CuSuite *get_parser_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_atoip);
SUITE_ADD_TEST(suite, test_skip_token);
SUITE_ADD_TEST(suite, test_gettoken);
SUITE_ADD_TEST(suite, test_getintegers);