Bug 2606: KAUFE braucht eine Burg.

This commit is contained in:
Enno Rehling 2019-09-08 13:06:24 +02:00
parent 40a484774e
commit d2d782c761
4 changed files with 36 additions and 7 deletions

View File

@ -1174,7 +1174,8 @@ attrib_type at_trades = {
NO_READ NO_READ
}; };
static bool trade_needs_castle(const region *r, const race *rc) { bool trade_needs_castle(const terrain_type *terrain, const race *rc)
{
static int rc_change, terrain_change; static int rc_change, terrain_change;
static const race *rc_insect; static const race *rc_insect;
static const terrain_type *t_desert, *t_swamp; static const terrain_type *t_desert, *t_swamp;
@ -1185,7 +1186,7 @@ static bool trade_needs_castle(const region *r, const race *rc) {
t_swamp = newterrain(T_SWAMP); t_swamp = newterrain(T_SWAMP);
t_desert = newterrain(T_DESERT); t_desert = newterrain(T_DESERT);
} }
return rc != rc_insect && (r->terrain == t_swamp || r->terrain == t_desert); return rc != rc_insect && (terrain == t_swamp || terrain == t_desert);
} }
static void buy(unit * u, econ_request ** buyorders, struct order *ord) static void buy(unit * u, econ_request ** buyorders, struct order *ord)
@ -1221,7 +1222,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
/* Entweder man ist Insekt in Sumpf/Wueste, oder es muss /* Entweder man ist Insekt in Sumpf/Wueste, oder es muss
* einen Handelsposten in der Region geben: */ * einen Handelsposten in der Region geben: */
if (trade_needs_castle(r, u_race(u))) { if (trade_needs_castle(r->terrain, u_race(u))) {
building *b = NULL; building *b = NULL;
if (r->buildings) { if (r->buildings) {
static int cache; static int cache;

View File

@ -49,6 +49,7 @@ extern "C" {
struct faction; struct faction;
struct order; struct order;
struct message; struct message;
struct terrain_type;
struct item_type; struct item_type;
typedef struct econ_request { typedef struct econ_request {
@ -85,6 +86,8 @@ extern "C" {
void destroy(struct region *r); void destroy(struct region *r);
void produce(struct region *r); void produce(struct region *r);
void auto_work(struct region *r); void auto_work(struct region *r);
bool trade_needs_castle(const struct terrain_type *terrain, const struct race *rc);
typedef enum income_t { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT } income_t; typedef enum income_t { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT } income_t;
void add_income(struct unit * u, income_t type, int want, int qty); void add_income(struct unit * u, income_t type, int want, int qty);

View File

@ -233,10 +233,31 @@ static unit *setup_trade_unit(CuTest *tc, region *r, const struct race *rc) {
return u; return u;
} }
static void test_trade_needs_castle(CuTest *tc) {
/* Handeln ist nur in Regionen mit Burgen möglich. */
race *rc;
region *r;
const terrain_type *t_swamp;
test_setup();
setup_production();
test_create_locale();
setup_terrains(tc);
init_terrains();
t_swamp = get_terrain("swamp");
r = setup_trade_region(tc, t_swamp);
rc = test_create_race(NULL);
CuAssertTrue(tc, trade_needs_castle(t_swamp, rc));
test_teardown();
}
static void test_trade_insect(CuTest *tc) { static void test_trade_insect(CuTest *tc) {
/* Insekten koennen in Wuesten und Suempfen auch ohne Burgen handeln. */ /* Insekten koennen in Wuesten und Suempfen auch ohne Burgen handeln. */
unit *u; unit *u;
region *r; region *r;
race *rc;
const terrain_type *t_swamp;
const item_type *it_luxury; const item_type *it_luxury;
const item_type *it_silver; const item_type *it_silver;
@ -244,14 +265,17 @@ static void test_trade_insect(CuTest *tc) {
setup_production(); setup_production();
test_create_locale(); test_create_locale();
setup_terrains(tc); setup_terrains(tc);
r = setup_trade_region(tc, get_terrain("swamp"));
init_terrains(); init_terrains();
t_swamp = get_terrain("swamp");
rc = test_create_race("insect");
r = setup_trade_region(tc, t_swamp);
it_luxury = r_luxury(r); it_luxury = r_luxury(r);
CuAssertTrue(tc, !trade_needs_castle(t_swamp, rc));
CuAssertPtrNotNull(tc, it_luxury); CuAssertPtrNotNull(tc, it_luxury);
it_silver = get_resourcetype(R_SILVER)->itype; it_silver = get_resourcetype(R_SILVER)->itype;
u = setup_trade_unit(tc, r, test_create_race("insect")); u = setup_trade_unit(tc, r, rc);
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))));
@ -796,6 +820,7 @@ CuSuite *get_economy_suite(void)
SUITE_ADD_TEST(suite, test_heroes_dont_recruit); SUITE_ADD_TEST(suite, test_heroes_dont_recruit);
SUITE_ADD_TEST(suite, test_tax_cmd); SUITE_ADD_TEST(suite, test_tax_cmd);
SUITE_ADD_TEST(suite, test_buy_cmd); SUITE_ADD_TEST(suite, test_buy_cmd);
SUITE_ADD_TEST(suite, test_trade_needs_castle);
SUITE_ADD_TEST(suite, test_trade_insect); SUITE_ADD_TEST(suite, test_trade_insect);
SUITE_ADD_TEST(suite, test_maintain_buildings); SUITE_ADD_TEST(suite, test_maintain_buildings);
SUITE_ADD_TEST(suite, test_recruit); SUITE_ADD_TEST(suite, test_recruit);

View File

@ -583,7 +583,7 @@ struct message * test_find_messagetype_ex(struct message_list *msgs, const char
return ml->msg; return ml->msg;
} }
} }
return 0; return NULL;
} }
struct message * test_find_messagetype(struct message_list *msgs, const char *name) struct message * test_find_messagetype(struct message_list *msgs, const char *name)
@ -603,7 +603,7 @@ void test_clear_messages(faction *f) {
if (f->msgs) { if (f->msgs) {
free_messagelist(f->msgs->begin); free_messagelist(f->msgs->begin);
free(f->msgs); free(f->msgs);
f->msgs = 0; f->msgs = NULL;
} }
} }