forked from github/server
Merge branch 'develop' of github.com:eressea/server
This commit is contained in:
commit
6953ad4403
|
@ -111,6 +111,10 @@ building_type *bt_get_or_create(const char *name)
|
||||||
if (btype == NULL) {
|
if (btype == NULL) {
|
||||||
btype = calloc(sizeof(building_type), 1);
|
btype = calloc(sizeof(building_type), 1);
|
||||||
btype->_name = _strdup(name);
|
btype->_name = _strdup(name);
|
||||||
|
btype->auraregen = 1.0;
|
||||||
|
btype->maxsize = -1;
|
||||||
|
btype->capacity = -1;
|
||||||
|
btype->maxcapacity = -1;
|
||||||
bt_register(btype);
|
bt_register(btype);
|
||||||
}
|
}
|
||||||
return btype;
|
return btype;
|
||||||
|
|
|
@ -357,10 +357,36 @@ void test_buildingowner_goes_to_empty_unit_after_leave(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_btype_defaults(CuTest *tc) {
|
||||||
|
building_type * btype;
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
btype = bt_get_or_create("hodor");
|
||||||
|
CuAssertPtrNotNull(tc, btype);
|
||||||
|
CuAssertStrEquals(tc, "hodor", btype->_name);
|
||||||
|
CuAssertPtrEquals(tc, 0, btype->maintenance);
|
||||||
|
CuAssertPtrEquals(tc, 0, btype->construction);
|
||||||
|
CuAssertTrue(tc, !btype->name);
|
||||||
|
CuAssertTrue(tc, !btype->init);
|
||||||
|
CuAssertTrue(tc, !btype->age);
|
||||||
|
CuAssertTrue(tc, !btype->protection);
|
||||||
|
CuAssertTrue(tc, !btype->taxes);
|
||||||
|
CuAssertDblEquals(tc, 1.0, btype->auraregen, 0.0);
|
||||||
|
CuAssertIntEquals(tc, -1, btype->maxsize);
|
||||||
|
CuAssertIntEquals(tc, -1, btype->capacity);
|
||||||
|
CuAssertIntEquals(tc, -1, btype->maxcapacity);
|
||||||
|
CuAssertIntEquals(tc, 0, btype->magres);
|
||||||
|
CuAssertIntEquals(tc, 0, btype->magresbonus);
|
||||||
|
CuAssertIntEquals(tc, 0, btype->fumblebonus);
|
||||||
|
CuAssertIntEquals(tc, 0, btype->flags);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_building_suite(void)
|
CuSuite *get_building_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_register_building);
|
SUITE_ADD_TEST(suite, test_register_building);
|
||||||
|
SUITE_ADD_TEST(suite, test_btype_defaults);
|
||||||
SUITE_ADD_TEST(suite, test_building_set_owner);
|
SUITE_ADD_TEST(suite, test_building_set_owner);
|
||||||
SUITE_ADD_TEST(suite, test_buildingowner_resets_when_empty);
|
SUITE_ADD_TEST(suite, test_buildingowner_resets_when_empty);
|
||||||
SUITE_ADD_TEST(suite, test_buildingowner_goes_to_next_when_empty);
|
SUITE_ADD_TEST(suite, test_buildingowner_goes_to_next_when_empty);
|
||||||
|
|
|
@ -296,6 +296,54 @@ static void test_buildings(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char * building_defaults_data = "{\"buildings\": { "
|
||||||
|
"\"house\" : { }"
|
||||||
|
"}}";
|
||||||
|
|
||||||
|
static void test_buildings_default(CuTest * tc)
|
||||||
|
{
|
||||||
|
cJSON *json = cJSON_Parse(building_defaults_data);
|
||||||
|
const building_type *bt;
|
||||||
|
building_type clone;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
bt = bt_get_or_create("house");
|
||||||
|
clone = *bt;
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(bt, &clone, sizeof(building_type)));
|
||||||
|
CuAssertPtrNotNull(tc, json);
|
||||||
|
json_config(json);
|
||||||
|
|
||||||
|
CuAssertPtrEquals(tc, (void *)bt, (void *)bt_find("house"));
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(bt, &clone, sizeof(building_type)));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * ship_defaults_data = "{\"ships\": { "
|
||||||
|
"\"hodor\" : { }"
|
||||||
|
"}}";
|
||||||
|
|
||||||
|
static void test_ships_default(CuTest * tc)
|
||||||
|
{
|
||||||
|
cJSON *json = cJSON_Parse(ship_defaults_data);
|
||||||
|
const ship_type *st;
|
||||||
|
ship_type clone;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
st = st_get_or_create("hodor");
|
||||||
|
clone = *st;
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(st, &clone, sizeof(ship_type)));
|
||||||
|
CuAssertPtrNotNull(tc, json);
|
||||||
|
json_config(json);
|
||||||
|
|
||||||
|
CuAssertPtrEquals(tc, (void *)st, (void *)st_find("hodor"));
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(st, &clone, sizeof(ship_type)));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_configs(CuTest * tc)
|
static void test_configs(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"include\": [ \"test.json\" ] }";
|
const char * data = "{\"include\": [ \"test.json\" ] }";
|
||||||
|
@ -446,8 +494,10 @@ CuSuite *get_jsonconf_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_skills);
|
SUITE_ADD_TEST(suite, test_skills);
|
||||||
SUITE_ADD_TEST(suite, test_directions);
|
SUITE_ADD_TEST(suite, test_directions);
|
||||||
SUITE_ADD_TEST(suite, test_items);
|
SUITE_ADD_TEST(suite, test_items);
|
||||||
|
SUITE_ADD_TEST(suite, test_ships_default);
|
||||||
SUITE_ADD_TEST(suite, test_ships);
|
SUITE_ADD_TEST(suite, test_ships);
|
||||||
SUITE_ADD_TEST(suite, test_buildings);
|
SUITE_ADD_TEST(suite, test_buildings);
|
||||||
|
SUITE_ADD_TEST(suite, test_buildings_default);
|
||||||
SUITE_ADD_TEST(suite, test_configs);
|
SUITE_ADD_TEST(suite, test_configs);
|
||||||
SUITE_ADD_TEST(suite, test_castles);
|
SUITE_ADD_TEST(suite, test_castles);
|
||||||
SUITE_ADD_TEST(suite, test_terrains);
|
SUITE_ADD_TEST(suite, test_terrains);
|
||||||
|
|
|
@ -110,6 +110,7 @@ ship_type *st_get_or_create(const char * name) {
|
||||||
if (!st) {
|
if (!st) {
|
||||||
st = (ship_type *)calloc(sizeof(ship_type), 1);
|
st = (ship_type *)calloc(sizeof(ship_type), 1);
|
||||||
st->_name = _strdup(name);
|
st->_name = _strdup(name);
|
||||||
|
st->storm = 1.0;
|
||||||
ql_push(&shiptypes, (void *)st);
|
ql_push(&shiptypes, (void *)st);
|
||||||
}
|
}
|
||||||
return st;
|
return st;
|
||||||
|
|
|
@ -38,6 +38,7 @@ extern "C" {
|
||||||
int range; /* range in regions */
|
int range; /* range in regions */
|
||||||
int flags; /* flags */
|
int flags; /* flags */
|
||||||
int combat; /* modifier for combat */
|
int combat; /* modifier for combat */
|
||||||
|
int fishing; /* weekly income from fishing */
|
||||||
|
|
||||||
double storm; /* multiplier for chance to drift in storm */
|
double storm; /* multiplier for chance to drift in storm */
|
||||||
double damage; /* multiplier for damage taken by the ship */
|
double damage; /* multiplier for damage taken by the ship */
|
||||||
|
@ -49,8 +50,6 @@ extern "C" {
|
||||||
int minskill; /* min. skill to sail this (crew) */
|
int minskill; /* min. skill to sail this (crew) */
|
||||||
int sumskill; /* min. sum of crew+captain */
|
int sumskill; /* min. sum of crew+captain */
|
||||||
|
|
||||||
int fishing; /* weekly income from fishing */
|
|
||||||
|
|
||||||
int at_bonus; /* Verändert den Angriffsskill (default: 0) */
|
int at_bonus; /* Verändert den Angriffsskill (default: 0) */
|
||||||
int df_bonus; /* Verändert den Verteidigungskill (default: 0) */
|
int df_bonus; /* Verändert den Verteidigungskill (default: 0) */
|
||||||
float tac_bonus;
|
float tac_bonus;
|
||||||
|
|
|
@ -342,10 +342,36 @@ void test_shipowner_goes_to_empty_unit_after_leave(CuTest * tc)
|
||||||
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_stype_defaults(CuTest *tc) {
|
||||||
|
ship_type *stype;
|
||||||
|
test_cleanup();
|
||||||
|
stype = st_get_or_create("hodor");
|
||||||
|
CuAssertPtrNotNull(tc, stype);
|
||||||
|
CuAssertStrEquals(tc, "hodor", stype->_name);
|
||||||
|
CuAssertPtrEquals(tc, 0, stype->construction);
|
||||||
|
CuAssertPtrEquals(tc, 0, stype->coasts);
|
||||||
|
CuAssertDblEquals(tc, 0.0, stype->damage, 0.0);
|
||||||
|
CuAssertDblEquals(tc, 1.0, stype->storm, 0.0);
|
||||||
|
CuAssertDblEquals(tc, 0.0, stype->tac_bonus, 0.0);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->cabins);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->cargo);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->combat);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->fishing);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->range);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->cptskill);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->minskill);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->sumskill);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->at_bonus);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->df_bonus);
|
||||||
|
CuAssertIntEquals(tc, 0, stype->flags);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_ship_suite(void)
|
CuSuite *get_ship_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_register_ship);
|
SUITE_ADD_TEST(suite, test_register_ship);
|
||||||
|
SUITE_ADD_TEST(suite, test_stype_defaults);
|
||||||
SUITE_ADD_TEST(suite, test_ship_set_owner);
|
SUITE_ADD_TEST(suite, test_ship_set_owner);
|
||||||
SUITE_ADD_TEST(suite, test_shipowner_resets_when_empty);
|
SUITE_ADD_TEST(suite, test_shipowner_resets_when_empty);
|
||||||
SUITE_ADD_TEST(suite, test_shipowner_goes_to_next_when_empty);
|
SUITE_ADD_TEST(suite, test_shipowner_goes_to_next_when_empty);
|
||||||
|
|
|
@ -244,14 +244,14 @@ static int parse_buildings(xmlDocPtr doc)
|
||||||
btype = bt_get_or_create((const char *)propValue);
|
btype = bt_get_or_create((const char *)propValue);
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
|
|
||||||
btype->capacity = xml_ivalue(node, "capacity", -1);
|
btype->capacity = xml_ivalue(node, "capacity", btype->capacity);
|
||||||
btype->maxcapacity = xml_ivalue(node, "maxcapacity", -1);
|
btype->maxcapacity = xml_ivalue(node, "maxcapacity", btype->maxcapacity);
|
||||||
btype->maxsize = xml_ivalue(node, "maxsize", -1);
|
btype->maxsize = xml_ivalue(node, "maxsize", btype->maxsize);
|
||||||
|
|
||||||
btype->magres = xml_ivalue(node, "magres", 0);
|
btype->magres = xml_ivalue(node, "magres", btype->magres);
|
||||||
btype->magresbonus = xml_ivalue(node, "magresbonus", 0);
|
btype->magresbonus = xml_ivalue(node, "magresbonus", btype->magresbonus);
|
||||||
btype->fumblebonus = xml_ivalue(node, "fumblebonus", 0);
|
btype->fumblebonus = xml_ivalue(node, "fumblebonus", btype->fumblebonus);
|
||||||
btype->auraregen = xml_fvalue(node, "auraregen", 1.0);
|
btype->auraregen = xml_fvalue(node, "auraregen", btype->auraregen);
|
||||||
|
|
||||||
if (xml_bvalue(node, "nodestroy", false))
|
if (xml_bvalue(node, "nodestroy", false))
|
||||||
btype->flags |= BTF_INDESTRUCTIBLE;
|
btype->flags |= BTF_INDESTRUCTIBLE;
|
||||||
|
@ -305,9 +305,6 @@ static int parse_buildings(xmlDocPtr doc)
|
||||||
else if (strcmp((const char *)propValue, "taxes") == 0) {
|
else if (strcmp((const char *)propValue, "taxes") == 0) {
|
||||||
btype->taxes = (double(*)(const struct building *, int))fun;
|
btype->taxes = (double(*)(const struct building *, int))fun;
|
||||||
}
|
}
|
||||||
else if (strcmp((const char *)propValue, "age") == 0) {
|
|
||||||
btype->age = (void(*)(struct building *))fun;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
log_error("unknown function type '%s' for building %s\n", (const char *)propValue, btype->_name);
|
log_error("unknown function type '%s' for building %s\n", (const char *)propValue, btype->_name);
|
||||||
}
|
}
|
||||||
|
@ -494,21 +491,21 @@ static int parse_ships(xmlDocPtr doc)
|
||||||
xmlFree(propValue);
|
xmlFree(propValue);
|
||||||
|
|
||||||
st->cabins = xml_ivalue(node, "cabins", 0) * PERSON_WEIGHT;
|
st->cabins = xml_ivalue(node, "cabins", 0) * PERSON_WEIGHT;
|
||||||
st->cargo = xml_ivalue(node, "cargo", 0);
|
st->cargo = xml_ivalue(node, "cargo", st->cargo);
|
||||||
st->combat = xml_ivalue(node, "combat", 0);
|
st->combat = xml_ivalue(node, "combat", st->combat);
|
||||||
st->cptskill = xml_ivalue(node, "cptskill", 0);
|
st->damage = xml_fvalue(node, "damage", st->damage);
|
||||||
st->damage = xml_fvalue(node, "damage", 0.0);
|
|
||||||
if (xml_bvalue(node, "nocoast", false))
|
if (xml_bvalue(node, "nocoast", false))
|
||||||
st->flags |= SFL_NOCOAST;
|
st->flags |= SFL_NOCOAST;
|
||||||
if (xml_bvalue(node, "fly", false))
|
if (xml_bvalue(node, "fly", false))
|
||||||
st->flags |= SFL_FLY;
|
st->flags |= SFL_FLY;
|
||||||
if (xml_bvalue(node, "opensea", false))
|
if (xml_bvalue(node, "opensea", false))
|
||||||
st->flags |= SFL_OPENSEA;
|
st->flags |= SFL_OPENSEA;
|
||||||
st->fishing = xml_ivalue(node, "fishing", 0);
|
st->fishing = xml_ivalue(node, "fishing", st->fishing);
|
||||||
st->minskill = xml_ivalue(node, "minskill", 0);
|
st->cptskill = xml_ivalue(node, "cptskill", st->cptskill);
|
||||||
st->range = xml_ivalue(node, "range", 0);
|
st->minskill = xml_ivalue(node, "minskill", st->minskill);
|
||||||
st->storm = xml_fvalue(node, "storm", 1.0);
|
st->sumskill = xml_ivalue(node, "sumskill", st->sumskill);
|
||||||
st->sumskill = xml_ivalue(node, "sumskill", 0);
|
st->range = xml_ivalue(node, "range", st->range);
|
||||||
|
st->storm = xml_fvalue(node, "storm", st->storm);
|
||||||
|
|
||||||
/* reading eressea/ships/ship/construction */
|
/* reading eressea/ships/ship/construction */
|
||||||
xpath->node = node;
|
xpath->node = node;
|
||||||
|
|
|
@ -240,13 +240,12 @@ const message_type *register_msg(const char *type, int n_param, ...) {
|
||||||
void assert_messages(struct CuTest * tc, struct mlist *msglist, const message_type **types,
|
void assert_messages(struct CuTest * tc, struct mlist *msglist, const message_type **types,
|
||||||
int num_msgs, bool exact_match, ...) {
|
int num_msgs, bool exact_match, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
int found, argc;
|
int found = 0, argc = 0;
|
||||||
struct message *msg;
|
struct message *msg;
|
||||||
bool match = true;
|
bool match = true;
|
||||||
|
|
||||||
va_start(args, exact_match);
|
va_start(args, exact_match);
|
||||||
|
|
||||||
found = 0;
|
|
||||||
while (msglist) {
|
while (msglist) {
|
||||||
if (found >= num_msgs) {
|
if (found >= num_msgs) {
|
||||||
if (exact_match) {
|
if (exact_match) {
|
||||||
|
|
Loading…
Reference in New Issue