From 1d8163e3f2d14d3815adb250df88d9b418678002 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 18 Mar 2016 17:18:33 +0100 Subject: [PATCH] Producers: Unit tests for fuel objects --- planet/Tests.ocf/Producers.ocs/Script.c | 83 +++++++++++++++---- .../System.ocg/ProductionTimes.c | 4 + 2 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 planet/Tests.ocf/Producers.ocs/System.ocg/ProductionTimes.c diff --git a/planet/Tests.ocf/Producers.ocs/Script.c b/planet/Tests.ocf/Producers.ocs/Script.c index 2ced1162e..8e71ad380 100644 --- a/planet/Tests.ocf/Producers.ocs/Script.c +++ b/planet/Tests.ocf/Producers.ocs/Script.c @@ -48,18 +48,6 @@ protected func InitializePlayer(int plr) return; } -protected func RemovePlayer(int plr) -{ - // Remove script player. - if (GetPlayerType(plr) == C4PT_Script) - { - if (plr == script_plr) - script_plr = nil; - return; - } - return; -} - /*-- Test Control --*/ @@ -187,8 +175,7 @@ global func Test2_OnStart(int plr) var barrel = CreateObject(Barrel); barrel->PutLiquid("Water", 300); // contains 300 water producer->AddToQueue(Loam, 5); // needs 300 water - //barrel->Enter(producer); - producer->Collect(barrel); + producer->Collect(barrel, true); // Log what the test is about. Log("Objects with liquid need (loam), can be produced with liquid containers (barrel). The liquid container must not be removed."); @@ -211,7 +198,6 @@ global func Test2_OnFinished() } - // Producer with liquid need and liquid object. global func Test3_OnStart(int plr) { @@ -242,6 +228,73 @@ global func Test3_OnFinished() return; } + +// Producer with fuel need, fuel object +global func Test4_OnStart(int plr) +{ + // Producer: Foundry + var producer = CreateObjectAbove(Foundry, 75, 160, plr); + producer->CreateContents(Wood, 10); + producer->CreateContents(Ore, 5); + producer->AddToQueue(Metal, 5); + + // Log what the test is about. + Log("Objects with fuel need (metal), can be produced with fuel objects (wood). The fuel is used up."); + return true; +} + +global func Test4_Completed() +{ + if (ObjectCount(Find_ID(Metal)) >= 5 && ObjectCount(Find_ID(Wood)) <= 0) + return true; + return false; +} + +global func Test4_OnFinished() +{ + RemoveAll(Find_Or(Find_ID(Foundry), Find_ID(Metal))); + return; +} + + +// Producer with fuel need, liquid container +global func Test5_OnStart(int plr) +{ + // Producer: Foundry + var producer = CreateObjectAbove(Foundry, 75, 160, plr); + producer->CreateContents(Ore, 5); + producer->AddToQueue(Metal, 5); + + var barrelA = CreateObject(Barrel); + var barrelB = CreateObject(Barrel); + barrelA->PutLiquid("Oil", 300); + barrelB->PutLiquid("Oil", 300); + + producer->Collect(barrelA, true); + producer->Collect(barrelB, true); + + // Log what the test is about. + Log("Objects with fuel need (metal), can be produced with fuel from a liquid container (barrel with oil). The fuel is used up."); + return true; +} + +global func Test5_Completed() +{ + if (ObjectCount(Find_ID(Metal)) >= 5 // metal is produced + && ObjectCount(Find_ID(Barrel)) == 2 // barrels stay + && FindObject(Find_ID(Liquid_Oil)) // oil remains + && FindObject(Find_ID(Liquid_Oil))->GetLiquidAmount() == 100) // the correct amount was used + return true; + return false; +} + +global func Test5_OnFinished() +{ + RemoveAll(Find_Or(Find_ID(Foundry), Find_ID(Metal), Find_ID(Barrel), Find_ID(Liquid_Oil))); + return; +} + + /*-- Helper Functions --*/ global func SetWindFixed(int strength) diff --git a/planet/Tests.ocf/Producers.ocs/System.ocg/ProductionTimes.c b/planet/Tests.ocf/Producers.ocs/System.ocg/ProductionTimes.c new file mode 100644 index 000000000..f85708a6c --- /dev/null +++ b/planet/Tests.ocf/Producers.ocs/System.ocg/ProductionTimes.c @@ -0,0 +1,4 @@ +#appendto Foundry + +// Objects should be produced faster +private func ProductionTime(id toProduce) { return 10; }