forked from github/server
owner update fix and test cases
This commit is contained in:
parent
de4604fdcc
commit
8ffafd2815
|
@ -3068,9 +3068,10 @@ static double rc_popularity(const struct race * rc)
|
|||
|
||||
void update_owners(region * r)
|
||||
{
|
||||
building * blargest = NULL;
|
||||
blargest = largestbuilding(r, &is_tax_building, false);
|
||||
building * bowner = largestbuilding(r, &is_owner_building, false);
|
||||
building * blargest = largestbuilding(r, &is_tax_building, false);
|
||||
if (blargest) {
|
||||
if (!bowner || bowner->size<blargest->size) {
|
||||
/* region owners update? */
|
||||
faction * f = region_get_owner(r);
|
||||
unit * u = buildingowner(r, blargest);
|
||||
|
@ -3081,6 +3082,7 @@ void update_owners(region * r)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void age_region(region * r)
|
||||
{
|
||||
|
|
|
@ -118,6 +118,29 @@ tolua_region_get_terrainname(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_owner(lua_State* L)
|
||||
{
|
||||
region* r = (region*) tolua_tousertype(L, 1, 0);
|
||||
struct faction* f = (struct faction*) tolua_tousertype(L, 2, 0);
|
||||
if (r) {
|
||||
region_set_owner(r, f, turn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_owner(lua_State* L)
|
||||
{
|
||||
region* r = (region*) tolua_tousertype(L, 1, 0);
|
||||
if (r) {
|
||||
struct faction * f = region_get_owner(r);
|
||||
tolua_pushusertype(L, f, "faction");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_terrainname(lua_State* L)
|
||||
{
|
||||
|
@ -553,6 +576,7 @@ tolua_region_open(lua_State* L)
|
|||
tolua_function(L, TOLUA_CAST "next", tolua_region_get_adj);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "terrain_name", &tolua_region_get_terrainname, &tolua_region_set_terrainname);
|
||||
tolua_variable(L, TOLUA_CAST "owner", &tolua_region_get_owner, &tolua_region_set_owner);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "get_key", tolua_region_getkey);
|
||||
tolua_function(L, TOLUA_CAST "set_key", tolua_region_setkey);
|
||||
|
|
|
@ -244,6 +244,36 @@ local function test_recruit2()
|
|||
print(u.number)
|
||||
end
|
||||
|
||||
local function test_owners()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("enno@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local f2 = faction.create("enno@eressea.de", "human", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
local u3 = unit.create(f2, r, 1)
|
||||
|
||||
local b3 = building.create(r, "castle")
|
||||
b3.size = 2
|
||||
u3.building = b3
|
||||
local b1 = building.create(r, "castle")
|
||||
b1.size = 1
|
||||
u1.building = b1
|
||||
local b2 = building.create(r, "castle")
|
||||
b2.size = 2
|
||||
u2.building = b2
|
||||
|
||||
update_owners()
|
||||
assert(r.owner==u3.faction)
|
||||
b1.size=3
|
||||
b2.size=3
|
||||
update_owners()
|
||||
assert(r.owner==u2.faction)
|
||||
b1.size=4
|
||||
update_owners()
|
||||
assert(r.owner==u1.faction)
|
||||
end
|
||||
|
||||
local function test_recruit()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
|
@ -587,9 +617,11 @@ tests = {
|
|||
["upkeep"] = test_upkeep,
|
||||
["id"] = test_id,
|
||||
["work"] = test_work,
|
||||
["owners"] = test_owners,
|
||||
["market"] = test_market
|
||||
}
|
||||
mytests = {
|
||||
["owners"] = test_owners,
|
||||
["mallorn"] = test_mallorn,
|
||||
["recruit2"] = test_recruit2
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue