forked from github/server
MORALE -1 when giving command of building
This commit is contained in:
parent
3b6a4fd3ba
commit
1ad2f4a264
6 changed files with 67 additions and 17 deletions
|
@ -634,6 +634,27 @@ recruit(unit * u, struct order * ord, request ** recruitorders)
|
|||
addlist(recruitorders, o);
|
||||
}
|
||||
|
||||
static void
|
||||
give_control(unit * u, unit * u2)
|
||||
{
|
||||
if (u->building && u->faction!=u2->faction) {
|
||||
region * r = u->region;
|
||||
faction * f = region_get_owner(r);
|
||||
if (f==u->faction) {
|
||||
building * b = largestbuilding(r, &is_owner_building, false);
|
||||
if (b==u->building) {
|
||||
int morale = region_get_morale(r);
|
||||
region_set_owner(r, u2->faction, turn);
|
||||
if (morale>0) {
|
||||
region_set_morale(r, morale-1, turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
freset(u, UFL_OWNER);
|
||||
fset(u2, UFL_OWNER);
|
||||
}
|
||||
|
||||
static void
|
||||
give_cmd(unit * u, order * ord)
|
||||
{
|
||||
|
@ -704,12 +725,7 @@ give_cmd(unit * u, order * ord)
|
|||
cmistake(u, ord, 49, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
if (!alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) {
|
||||
cmistake(u, ord, 40, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
freset(u, UFL_OWNER);
|
||||
fset(u2, UFL_OWNER);
|
||||
give_control(u, u2);
|
||||
|
||||
msg = msg_message("givecommand", "unit recipient", u, u2);
|
||||
add_message(&u->faction->msgs, msg);
|
||||
|
|
|
@ -3098,12 +3098,14 @@ static void age_region(region * r)
|
|||
ch *= 1.2; /* 20% improvement */
|
||||
}
|
||||
if (chance(ch)) {
|
||||
++r->land->morale;
|
||||
r->land->ownership->morale_turn = turn;
|
||||
region_set_morale(r, r->land->morale+1, turn);
|
||||
}
|
||||
}
|
||||
if (!r->land->ownership->owner && r->land->morale<MORALE_DEFAULT) {
|
||||
r->land->morale = (short)MIN(r->land->morale, MORALE_DEFAULT);
|
||||
short m = (short)MIN(r->land->morale, MORALE_DEFAULT);
|
||||
if (m!=r->land->morale) {
|
||||
region_set_morale(r, m, turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1246,8 +1246,8 @@ terraform_region(region * r, const terrain_type * terrain)
|
|||
int mnr = 0;
|
||||
|
||||
r->land = calloc(1, sizeof(land_region));
|
||||
r->land->morale = MORALE_DEFAULT;
|
||||
r->land->ownership = NULL;
|
||||
region_set_morale(r, MORALE_DEFAULT, -1);
|
||||
region_setname(r, makename());
|
||||
for (d=0;d!=MAXDIRECTIONS;++d) {
|
||||
region * nr = rconnect(r, d);
|
||||
|
@ -1456,13 +1456,12 @@ region_set_owner(struct region * r, struct faction * owner, int turn)
|
|||
if (r->land) {
|
||||
if (!r->land->ownership) {
|
||||
r->land->ownership = malloc(sizeof(region_owner));
|
||||
r->land->morale = MORALE_DEFAULT;
|
||||
region_set_morale(r, MORALE_DEFAULT, turn);
|
||||
} else if (r->land->ownership->owner) {
|
||||
r->land->morale = MORALE_TAKEOVER;
|
||||
region_set_morale(r, MORALE_TAKEOVER, turn);
|
||||
}
|
||||
r->land->ownership->owner = owner;
|
||||
r->land->ownership->since_turn = turn;
|
||||
r->land->ownership->morale_turn = turn;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1500,10 +1499,13 @@ int region_get_morale(const region * r)
|
|||
return r->land?r->land->morale:-1;
|
||||
}
|
||||
|
||||
void region_set_morale(region * r, int morale)
|
||||
void region_set_morale(region * r, int morale, int turn)
|
||||
{
|
||||
if (r->land) {
|
||||
r->land->morale = (short)morale;
|
||||
if (turn>=0 && r->land->ownership) {
|
||||
r->land->ownership->morale_turn = turn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ struct region * r_connect(const struct region *, direction_t dir);
|
|||
void free_regions(void);
|
||||
|
||||
int region_get_morale(const region * r);
|
||||
void region_set_morale(region * r, int morale);
|
||||
void region_set_morale(region * r, int morale, int turn);
|
||||
|
||||
void write_region_reference(const struct region * r, struct storage * store);
|
||||
variant read_region_reference(struct storage * store);
|
||||
|
|
|
@ -194,7 +194,7 @@ static int tolua_region_get_morale(lua_State* L)
|
|||
static int tolua_region_set_morale(lua_State* L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
region_set_morale(r, (int)tolua_tonumber(L, 2, 0));
|
||||
region_set_morale(r, (int)tolua_tonumber(L, 2, 0), turn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -302,6 +302,34 @@ local function test_owners()
|
|||
assert(r.owner==u1.faction)
|
||||
end
|
||||
|
||||
local function test_morale()
|
||||
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 b = building.create(r, "castle")
|
||||
b.size = 10
|
||||
u1.building = b
|
||||
u2.building = b
|
||||
update_owners()
|
||||
assert(r.morale==2)
|
||||
r.morale = 5
|
||||
assert(r.owner==u1.faction)
|
||||
u1:clear_orders()
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " KOMMANDO")
|
||||
process_orders()
|
||||
u1:clear_orders()
|
||||
assert(r.owner==u2.faction)
|
||||
assert(r.morale==4)
|
||||
u2.building = nil
|
||||
update_owners()
|
||||
assert(r.owner==u1.faction)
|
||||
assert(r.morale==0)
|
||||
end
|
||||
|
||||
local function test_recruit()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
|
@ -645,14 +673,16 @@ tests = {
|
|||
["upkeep"] = test_upkeep,
|
||||
["id"] = test_id,
|
||||
["work"] = test_work,
|
||||
["morale"] = test_morale,
|
||||
["owners"] = test_owners,
|
||||
["market"] = test_market
|
||||
}
|
||||
mytests = {
|
||||
-- ["blessed"] = test_blessed -- foiled by peasantgrowth
|
||||
["morale"] = test_morale
|
||||
}
|
||||
fail = 0
|
||||
for k, v in pairs(tests) do
|
||||
for k, v in pairs(mytests) do
|
||||
local status, err = pcall(v)
|
||||
if not status then
|
||||
fail = fail + 1
|
||||
|
|
Loading…
Reference in a new issue