forked from github/server
giving ownerships over buildings was broken by a recent refactoring
This commit is contained in:
parent
36ad727394
commit
131840054c
|
@ -92,6 +92,7 @@
|
|||
<ClCompile Include="gamecode\creport.c" />
|
||||
<ClCompile Include="gamecode\economy.c" />
|
||||
<ClCompile Include="eressea.c" />
|
||||
<ClCompile Include="gamecode\economy_test.c" />
|
||||
<ClCompile Include="gamecode\give.c" />
|
||||
<ClCompile Include="gamecode\xmlreport.c" />
|
||||
<ClCompile Include="gmtool.c" />
|
||||
|
|
|
@ -68,6 +68,9 @@
|
|||
<ClCompile Include="gamecode\xmlreport.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="gamecode\economy_test.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="gamecode\archetype.h">
|
||||
|
|
|
@ -626,17 +626,19 @@ static void friendly_takeover(region * r, faction * f)
|
|||
}
|
||||
}
|
||||
|
||||
static void give_control(unit * u, unit * u2)
|
||||
void give_control(unit * u, unit * u2)
|
||||
{
|
||||
if (u->building && u->faction != u2->faction && rule_region_owners()) {
|
||||
region *r = u->region;
|
||||
faction *f = region_get_owner(r);
|
||||
if (u->building) {
|
||||
if (u->faction != u2->faction && rule_region_owners()) {
|
||||
region *r = u->region;
|
||||
faction *f = region_get_owner(r);
|
||||
|
||||
assert(u->building==u2->building);
|
||||
if (f == u->faction) {
|
||||
building *b = largestbuilding(r, &cmp_current_owner, false);
|
||||
if (b == u->building) {
|
||||
friendly_takeover(r, u2->faction);
|
||||
assert(u->building==u2->building);
|
||||
if (f == u->faction) {
|
||||
building *b = largestbuilding(r, &cmp_current_owner, false);
|
||||
if (b == u->building) {
|
||||
friendly_takeover(r, u2->faction);
|
||||
}
|
||||
}
|
||||
}
|
||||
building_set_owner(u2);
|
||||
|
|
|
@ -55,6 +55,7 @@ extern "C" {
|
|||
extern void split_allocations(struct region *r);
|
||||
extern int recruit_archetypes(void);
|
||||
extern int give_control_cmd(struct unit *u, struct order *ord);
|
||||
extern void give_control(struct unit * u, struct unit * u2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#include "platform.h"
|
||||
#include "economy.h"
|
||||
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/ship.h>
|
||||
|
||||
#include <cutest/CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
static void test_give_control_building(CuTest * tc)
|
||||
{
|
||||
unit *u1, *u2;
|
||||
building *b;
|
||||
struct faction *f;
|
||||
region *r;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
f = test_create_faction(0);
|
||||
r = findregion(0, 0);
|
||||
b = test_create_building(r, 0);
|
||||
u1 = test_create_unit(f, r);
|
||||
u_set_building(u1, b);
|
||||
u2 = test_create_unit(f, r);
|
||||
u_set_building(u2, b);
|
||||
CuAssertPtrEquals(tc, u1, building_owner(b));
|
||||
give_control(u1, u2);
|
||||
CuAssertPtrEquals(tc, u2, building_owner(b));
|
||||
}
|
||||
|
||||
static void test_give_control_ship(CuTest * tc)
|
||||
{
|
||||
unit *u1, *u2;
|
||||
ship *sh;
|
||||
struct faction *f;
|
||||
region *r;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
f = test_create_faction(0);
|
||||
r = findregion(0, 0);
|
||||
sh = test_create_ship(r, 0);
|
||||
u1 = test_create_unit(f, r);
|
||||
u_set_ship(u1, sh);
|
||||
u2 = test_create_unit(f, r);
|
||||
u_set_ship(u2, sh);
|
||||
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
||||
give_control(u1, u2);
|
||||
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
||||
}
|
||||
|
||||
CuSuite *get_economy_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_give_control_building);
|
||||
SUITE_ADD_TEST(suite, test_give_control_ship);
|
||||
return suite;
|
||||
}
|
10
src/tests.c
10
src/tests.c
|
@ -21,6 +21,7 @@
|
|||
#include <kernel/equipment_test.c>
|
||||
#include <kernel/reports_test.c>
|
||||
#include <kernel/spellbook_test.c>
|
||||
#include <gamecode/economy_test.c>
|
||||
#include <gamecode/laws_test.c>
|
||||
#include <gamecode/market_test.c>
|
||||
|
||||
|
@ -67,6 +68,7 @@ int RunAllTests(void)
|
|||
/* gamecode */
|
||||
CuSuiteAddSuite(suite, get_market_suite());
|
||||
CuSuiteAddSuite(suite, get_laws_suite());
|
||||
CuSuiteAddSuite(suite, get_economy_suite());
|
||||
|
||||
CuSuiteRun(suite);
|
||||
CuSuiteSummary(suite, output);
|
||||
|
@ -137,15 +139,15 @@ test_create_terrain(const char * name, unsigned int flags)
|
|||
|
||||
building * test_create_building(region * r, const building_type * btype)
|
||||
{
|
||||
building * b = new_building(btype, r, default_locale);
|
||||
b->size = btype->maxsize>0?btype->maxsize:1;
|
||||
building * b = new_building(btype?btype:bt_find("castle"), r, default_locale);
|
||||
b->size = b->type->maxsize>0?b->type->maxsize:1;
|
||||
return b;
|
||||
}
|
||||
|
||||
ship * test_create_ship(region * r, const ship_type * stype)
|
||||
{
|
||||
ship * s = new_ship(stype, r, default_locale);
|
||||
s->size = stype->construction?stype->construction->maxsize:1;
|
||||
ship * s = new_ship(stype?stype:st_find("boat"), r, default_locale);
|
||||
s->size = s->type->construction?s->type->construction->maxsize:1;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue