diff --git a/res/races/dragon.xml b/res/races/dragon.xml index 907ff90a7..e4a1a7fec 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -1,7 +1,8 @@ +income="1000" walk="yes" teach="no" getitem="yes" resistbash="yes" +dragon="yes"> diff --git a/res/races/wyrm.xml b/res/races/wyrm.xml index b5d3bd7a2..b9f95d9ef 100644 --- a/res/races/wyrm.xml +++ b/res/races/wyrm.xml @@ -1,4 +1,8 @@ - + diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml index d1b3a4752..71bc4214b 100644 --- a/res/races/youngdragon.xml +++ b/res/races/youngdragon.xml @@ -1,4 +1,8 @@ - + diff --git a/src/economy.c b/src/economy.c index 099e9786d..8f6a1afa1 100644 --- a/src/economy.c +++ b/src/economy.c @@ -114,20 +114,8 @@ static void recruit_init(void) int income(const unit * u) { - // TODO: make this a property, like race.income, no hard-coding of values - if (fval(u_race(u), RCF_DRAGON)) { - switch (old_race(u_race(u))) { - case RC_FIREDRAGON: - return 150 * u->number; - case RC_DRAGON: - return 1000 * u->number; - case RC_WYRM: - return 5000 * u->number; - default: - break; - } - } - return 20 * u->number; + const race *rc = u_race(u); + return rc->income * u->number; } static void scramble(void *data, unsigned int n, size_t width) diff --git a/src/economy.test.c b/src/economy.test.c index 7f48df289..3c4a5f257 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -328,11 +328,25 @@ static void test_recruit(CuTest *tc) { test_cleanup(); } +static void test_income(CuTest *tc) +{ + race *rc; + unit *u; + test_setup(); + rc = test_create_race("nerd"); + u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0)); + CuAssertIntEquals(tc, 20, income(u)); + u->number = 5; + CuAssertIntEquals(tc, 100, income(u)); + test_cleanup(); +} + CuSuite *get_economy_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_give_control_building); SUITE_ADD_TEST(suite, test_give_control_ship); + SUITE_ADD_TEST(suite, test_income); SUITE_ADD_TEST(suite, test_steal_okay); SUITE_ADD_TEST(suite, test_steal_ocean); SUITE_ADD_TEST(suite, test_steal_nosteal); diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 9e6001f8d..6e60fc90c 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -481,6 +481,9 @@ static void json_race(cJSON *json, race *rc) { else if (strcmp(child->string, "capacity") == 0) { rc->capacity = child->valueint; } + else if (strcmp(child->string, "income") == 0) { + rc->income = child->valueint; + } else if (strcmp(child->string, "hp") == 0) { rc->hitpoints = child->valueint; } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 3fac3478a..76784ed56 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -141,6 +141,7 @@ static void test_races(CuTest * tc) "\"maintenance\" : 2," "\"weight\" : 3," "\"capacity\" : 4," + "\"income\" : 30," "\"hp\" : 5," "\"ac\" : 6," "\"flags\" : [ \"npc\", \"walk\", \"undead\" ]" @@ -167,6 +168,7 @@ static void test_races(CuTest * tc) CuAssertIntEquals(tc, 2, rc->maintenance); CuAssertIntEquals(tc, 3, rc->weight); CuAssertIntEquals(tc, 4, rc->capacity); + CuAssertIntEquals(tc, 30, rc->income); CuAssertIntEquals(tc, 5, rc->hitpoints); CuAssertIntEquals(tc, 6, rc->armor); cJSON_Delete(json); diff --git a/src/kernel/race.c b/src/kernel/race.c index 4003c701e..57ebe972a 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -173,6 +173,7 @@ race *rc_create(const char *zName) rc->hitpoints = 1; rc->weight = PERSON_WEIGHT; rc->capacity = 540; + rc->income = 20; rc->recruit_multi = 1.0F; rc->regaura = 1.0F; rc->speed = 1.0F; diff --git a/src/kernel/race.h b/src/kernel/race.h index 17c2bc61f..214f2738d 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -124,6 +124,7 @@ extern "C" { int splitsize; int weight; int capacity; + int income; float speed; float aggression; /* chance that a monster will attack */ int hitpoints; diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index ec4b40f92..7bccdbba8 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -32,6 +32,7 @@ static void test_rc_defaults(CuTest *tc) { CuAssertIntEquals(tc, 0, rc->recruitcost); CuAssertIntEquals(tc, 0, rc->maintenance); CuAssertIntEquals(tc, 540, rc->capacity); + CuAssertIntEquals(tc, 20, rc->income); CuAssertIntEquals(tc, 1, rc->hitpoints); CuAssertIntEquals(tc, 0, rc->armor); CuAssertIntEquals(tc, 0, rc->at_bonus); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 06363de48..894647f89 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1656,6 +1656,7 @@ static int parse_races(xmlDocPtr doc) rc->maintenance = xml_ivalue(node, "maintenance", rc->maintenance); rc->weight = xml_ivalue(node, "weight", rc->weight); rc->capacity = xml_ivalue(node, "capacity", rc->capacity); + rc->income = xml_ivalue(node, "income", rc->income); rc->speed = (float)xml_fvalue(node, "speed", rc->speed); rc->hitpoints = xml_ivalue(node, "hp", rc->hitpoints); rc->armor = (char)xml_ivalue(node, "ac", rc->armor);