forked from github/server
extract rc_mask, add it to exparse code.
This commit is contained in:
parent
3cb1d1a071
commit
ac786e034c
4 changed files with 35 additions and 12 deletions
|
@ -574,3 +574,20 @@ struct race * read_race_reference(struct storage *store)
|
||||||
void register_race_function(race_func func, const char *name) {
|
void register_race_function(race_func func, const char *name) {
|
||||||
register_function((pf_generic)func, name);
|
register_function((pf_generic)func, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int race_mask = 1;
|
||||||
|
|
||||||
|
int rc_mask(char *list) {
|
||||||
|
int mask = 0;
|
||||||
|
char * tok = strtok(list, " ,");
|
||||||
|
while (tok) {
|
||||||
|
race * rc = rc_get_or_create(tok);
|
||||||
|
if (!rc->mask_item) {
|
||||||
|
rc->mask_item = race_mask;
|
||||||
|
race_mask = race_mask << 1;
|
||||||
|
}
|
||||||
|
mask |= rc->mask_item;
|
||||||
|
tok = strtok(NULL, " ,");
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
|
@ -198,6 +198,8 @@ extern "C" {
|
||||||
#define MIGRANTS_LOG10 1
|
#define MIGRANTS_LOG10 1
|
||||||
int rc_migrants_formula(const race *rc);
|
int rc_migrants_formula(const race *rc);
|
||||||
|
|
||||||
|
int rc_mask(char *list);
|
||||||
|
|
||||||
/* Flags. Do not reorder these without changing json_race() in jsonconf.c */
|
/* Flags. Do not reorder these without changing json_race() in jsonconf.c */
|
||||||
#define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */
|
#define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */
|
||||||
#define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */
|
#define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
@ -172,6 +173,19 @@ static void test_racename(CuTest *tc) {
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_rc_mask(CuTest *tc) {
|
||||||
|
int mask;
|
||||||
|
char list[64];
|
||||||
|
test_setup();
|
||||||
|
strcpy(list, "goblin dwarf");
|
||||||
|
mask = rc_mask(list);
|
||||||
|
CuAssertIntEquals(tc, 3, mask);
|
||||||
|
CuAssertStrEquals(tc, "goblin", list);
|
||||||
|
mask = rc_mask(list);
|
||||||
|
CuAssertIntEquals(tc, 1, mask);
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_race_suite(void)
|
CuSuite *get_race_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -180,6 +194,7 @@ CuSuite *get_race_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_rc_name);
|
SUITE_ADD_TEST(suite, test_rc_name);
|
||||||
SUITE_ADD_TEST(suite, test_rc_defaults);
|
SUITE_ADD_TEST(suite, test_rc_defaults);
|
||||||
SUITE_ADD_TEST(suite, test_rc_find);
|
SUITE_ADD_TEST(suite, test_rc_find);
|
||||||
|
SUITE_ADD_TEST(suite, test_rc_mask);
|
||||||
SUITE_ADD_TEST(suite, test_rc_set_param);
|
SUITE_ADD_TEST(suite, test_rc_set_param);
|
||||||
SUITE_ADD_TEST(suite, test_rc_can_use);
|
SUITE_ADD_TEST(suite, test_rc_can_use);
|
||||||
SUITE_ADD_TEST(suite, test_racename);
|
SUITE_ADD_TEST(suite, test_racename);
|
||||||
|
|
|
@ -656,23 +656,12 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
||||||
return wtype;
|
return wtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int race_mask = 1;
|
|
||||||
|
|
||||||
static void mask_races(xmlNodePtr node, const char *key, int *maskp) {
|
static void mask_races(xmlNodePtr node, const char *key, int *maskp) {
|
||||||
xmlChar *propValue = xmlGetProp(node, BAD_CAST key);
|
xmlChar *propValue = xmlGetProp(node, BAD_CAST key);
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
assert(maskp);
|
assert(maskp);
|
||||||
if (propValue) {
|
if (propValue) {
|
||||||
char * tok = strtok((char *)propValue, " ,");
|
mask = rc_mask((char *)propValue);
|
||||||
while (tok) {
|
|
||||||
race * rc = rc_get_or_create(tok);
|
|
||||||
if (!rc->mask_item) {
|
|
||||||
rc->mask_item = race_mask;
|
|
||||||
race_mask = race_mask << 1;
|
|
||||||
}
|
|
||||||
mask |= rc->mask_item;
|
|
||||||
tok = strtok(NULL, " ,");
|
|
||||||
}
|
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
}
|
}
|
||||||
*maskp = mask;
|
*maskp = mask;
|
||||||
|
|
Loading…
Reference in a new issue