From 9f0cd81086804143c40d92e056332a7660580f41 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 22 Mar 2010 00:36:49 -0700 Subject: [PATCH] crazy shit can happen when the unit dies but lua still has a pointer to it :-( also fixing a test for ocean-spells that was intermittent when storms happened --- scripts/tests/e3a.lua | 5 ++++- scripts/tests/morale.lua | 36 +++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/scripts/tests/e3a.lua b/scripts/tests/e3a.lua index 216847715..e82f20f3d 100644 --- a/scripts/tests/e3a.lua +++ b/scripts/tests/e3a.lua @@ -50,6 +50,10 @@ end function test_seecast() local r = region.create(0,0, "plain") + for i = 1,10 do + -- this prevents storms (only high seas have storms) + region.create(i, 1, "plain") + end for i = 1,10 do region.create(i, 0, "ocean") end @@ -218,7 +222,6 @@ function test_owners() end function test_taxes() - set_key("test", 42) local r = region.create(0, 0, "plain") r:set_resource("peasant", 1000) r:set_resource("money", 5000) diff --git a/scripts/tests/morale.lua b/scripts/tests/morale.lua index 9a84b9455..ed651992e 100644 --- a/scripts/tests/morale.lua +++ b/scripts/tests/morale.lua @@ -14,17 +14,20 @@ function test_when_owner_returns_morale_drops_only_2() u1:add_item("money", 10000) local b = building.create(r, "castle") b.size = 50 - + set_turn(get_turn()+10) + f1.lastturn=get_turn() u1.building = b update_owners() r.morale = 6 u1.building = nil - update_owners() - assert_equal(6, r.morale) + process_orders() + assert_equal(5, r.morale) -- no owner, fall by 1 u1.building = b update_owners() - assert_equal(4, r.morale) + set_key("test", 42) + process_orders() + assert_equal(3, r.morale) -- new owner, fall by 2 end function test_morale_alliance() @@ -36,6 +39,9 @@ function test_morale_alliance() local f2 = faction.create("noreply@eressea.de", "human", "de") local u2 = unit.create(f2, r, 1) u2:add_item("money", 10000) + local f3 = faction.create("noreply@eressea.de", "human", "de") + local u3 = unit.create(f3, r, 1) + u3:add_item("money", 10000) local al = alliance.create(42, "Die Antwoord") f1.alliance = al; @@ -45,6 +51,7 @@ function test_morale_alliance() b.size = 50 u1.building = b u2.building = b + u3.building = b update_owners() r.morale = 6 @@ -52,27 +59,22 @@ function test_morale_alliance() process_orders() f1.lastturn=get_turn() f2.lastturn=get_turn() + f3.lastturn=get_turn() end -- just checking everything's okay after setup. run_a_turn() assert_equal(6, r.morale) - -- change owner, same alliance as before, but has new owner hasn't been 10 weeks in the alliance yet. + -- change owner, new owner is in the same alliance u1.building = nil - update_owners() - assert_equal(0, r.morale) - - -- change owner, this time the alliance is 10 weeks old - r.morale = 6 - u1.building = b - for i=1,10 do - run_a_turn() - end - assert_equal(6, r.morale) - u2.building = nil - update_owners() + run_a_turn() assert_equal(4, r.morale) + + -- change owner, new owner is not in the same alliance + u2.building = nil + run_a_turn() + assert_equal(0, r.morale) end function test_morale_change()