From 090c6665f07ce1967c900889659115d60f594d76 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 17 Oct 2009 10:12:58 +0000 Subject: [PATCH] small fixes (morale < 0) --- src/common/gamecode/economy.c | 3 ++- src/common/kernel/region.c | 7 ++++++- src/common/kernel/save.c | 1 + src/scripts/e3a/multi.lua | 2 +- src/scripts/run-e3a.lua | 10 ++++++---- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 5651adb40..c46b77fb2 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -646,7 +646,8 @@ give_control(unit * u, unit * u2) int morale = region_get_morale(r); region_set_owner(r, u2->faction, turn); if (morale>0) { - region_set_morale(r, morale-MORALE_TRANSFER, turn); + morale = MAX(0, morale-MORALE_TRANSFER); + region_set_morale(r, morale, turn); } } } diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index ef2bdcc99..9dd939cc2 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -1532,7 +1532,11 @@ region_getname(const region * r) { int region_get_morale(const region * r) { - return r->land?r->land->morale:-1; + if (r->land) { + assert(r->land->morale>=0 && r->land->morale<=MORALE_MAX); + return r->land->morale; + } + return -1; } void region_set_morale(region * r, int morale, int turn) @@ -1542,6 +1546,7 @@ void region_set_morale(region * r, int morale, int turn) if (turn>=0 && r->land->ownership) { r->land->ownership->morale_turn = turn; } + assert(r->land->morale>=0 && r->land->morale<=MORALE_MAX); } } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 6e93b952a..f49b47fee 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1062,6 +1062,7 @@ readregion(struct storage * store, int x, int y) } if (store->version>=REGIONOWNER_VERSION) { r->land->morale = (short)store->r_int(store); + if (r->land->morale<0) r->land->morale = 0; read_owner(store, &r->land->ownership); if (r->land->ownership && r->land->ownership->owner) { faction * owner = r->land->ownership->owner; diff --git a/src/scripts/e3a/multi.lua b/src/scripts/e3a/multi.lua index fddfa055c..6f2da87cc 100644 --- a/src/scripts/e3a/multi.lua +++ b/src/scripts/e3a/multi.lua @@ -7,7 +7,7 @@ function mark_multi(f) if u.building~=nil then local found = False for u2 in u.region.units do - if u2.faction~=u.faction then + if u2.faction.id~=u.faction.id then found = true break end diff --git a/src/scripts/run-e3a.lua b/src/scripts/run-e3a.lua index b0cec5f33..222632faf 100644 --- a/src/scripts/run-e3a.lua +++ b/src/scripts/run-e3a.lua @@ -3,6 +3,7 @@ local locales = { "de", "en" } local confirmed_multis = { } local suspected_multis = { +"odin" } function num_oceans(r) @@ -72,10 +73,11 @@ function kill_multis(multis) end function mark_multis(multis) - if multi~=nil and multis~=nil then + if multis~=nil then for idx, fno in ipairs(multis) do local f = get_faction(fno) if f~=nil and f.email~="doppelspieler@eressea.de" then + print("* multi-player " .. tostring(f)) mark_multi(f) end end @@ -147,7 +149,7 @@ end function process(orders) -- initialize starting equipment for new players - + print(orders) if open_game(get_turn())~=0 then print("could not read game") return -1 @@ -156,6 +158,8 @@ function process(orders) -- kill multi-players (external script) -- loadscript("eressea/multis.lua") + kill_multis(confirmed_multis) + mark_multis(suspected_multis) -- run the turn: if read_orders(orders) ~= 0 then @@ -163,7 +167,6 @@ function process(orders) return -1 end - kill_multis(confirmed_multis) -- plan_monsters() local mon = get_faction(666) if mon ~= nil then @@ -192,7 +195,6 @@ function process(orders) -- spawn_ents() kill_nonstarters() - mark_multis(suspected_multis) -- post-turn updates: update_guards() update_scores()