Refactoring: Stackable: Use InitialStackCount() where it makes sense

liquid_container
Mark 2016-03-08 06:57:20 +01:00
parent d8a68f5655
commit 350088525c
2 changed files with 9 additions and 6 deletions

View File

@ -181,7 +181,7 @@ private func UpdateName()
private func UpdateMass()
{
SetMass(GetID()->GetMass() * Max(GetStackCount(), 1) / MaxStackCount());
SetMass(GetID()->GetMass() * Max(GetStackCount(), 1) / InitialStackCount());
}
/*
@ -206,7 +206,7 @@ protected func RejectEntrance(object into)
public func CalcValue(object in_base, int for_plr)
{
return GetID()->GetValue() * Max(GetStackCount(), 1) / MaxStackCount();
return GetID()->GetValue() * Max(GetStackCount(), 1) / InitialStackCount();
}
/* Tries to add this object to another stack. Returns true if successful.
@ -294,7 +294,7 @@ public func SaveScenarioObject(props)
props->Remove("Name");
if (IsInfiniteStackCount())
props->AddCall("Stack", this, "SetInfiniteStackCount");
else if (GetStackCount() != MaxStackCount())
else if (GetStackCount() != InitialStackCount())
props->AddCall("Stack", this, "SetStackCount", GetStackCount());
return true;
}

View File

@ -218,7 +218,7 @@ global func Test3_OnStart(int plr){ return true;}
global func Test3_OnFinished(){ return; }
global func Test3_Execute()
{
Log("Test the behaviour of CalcValue()");
Log("Test the behaviour of CalcValue() and UpdateMass()");
var stackable = CreateObject(Arrow);
var passed = true;
@ -227,8 +227,11 @@ global func Test3_Execute()
{
stackable->SetStackCount(i);
var comparison = "Got %d, expected %d.";
var description = Format("A stack with %d object(s) should have %d times the value of the definition. %s", i, i, comparison);
var passed = doTest(description, stackable->CalcValue(), (Arrow->GetValue() * i) / Arrow->MaxStackCount());
var description = Format("A stack with %d object(s) should have value proportional to the value of the definition. %s", i, comparison);
passed &= doTest(description, stackable->CalcValue(), (Arrow->GetValue() * i) / Arrow->InitialStackCount());
description = Format("A stack with %d object(s) should have mass proportional to that of the definition. %s", i, comparison);
passed &= doTest(description, stackable->GetMass(), Max(1, (Arrow->GetMass() * i) / Arrow->InitialStackCount()));
}
stackable->RemoveObject();