Public Member Functions | Private Attributes

ScriptAccounting Class Reference

Class that keeps track of the costs, so you can request how much a block of commands did cost in total. More...

#include <script_accounting.hpp>

Inheritance diagram for ScriptAccounting:
ScriptObject SimpleCountedObject

Public Member Functions

 ScriptAccounting ()
 Creating instance of this class starts counting the costs of commands from zero.
 ~ScriptAccounting ()
 Restore the ScriptAccounting that was on top when we created this instance.
Money GetCosts ()
 Get the current value of the costs.
void ResetCosts ()
 Reset the costs to zero.

Private Attributes

Money last_costs
 The last cost we did return.

Detailed Description

Class that keeps track of the costs, so you can request how much a block of commands did cost in total.

Works in both Execute as in Test mode. ai game Example:

   {
     local costs = ScriptAccounting();
     BuildRoad(from_here, to_here);
     BuildRoad(from_there, to_there);
     print("Costs for route is: " + costs.GetCosts());
   }
 

Definition at line 31 of file script_accounting.hpp.


Constructor & Destructor Documentation

ScriptAccounting::ScriptAccounting (  ) 

Creating instance of this class starts counting the costs of commands from zero.

Saves the current value of GetCosts so we can return to the old value when the instance gets deleted.

Definition at line 25 of file script_accounting.cpp.

References ScriptObject::GetDoCommandCosts(), last_costs, and ScriptObject::SetDoCommandCosts().

ScriptAccounting::~ScriptAccounting (  ) 

Restore the ScriptAccounting that was on top when we created this instance.

So basically restore the value of GetCosts to what it was before we created this instance.

Definition at line 31 of file script_accounting.cpp.

References last_costs, and ScriptObject::SetDoCommandCosts().


Member Function Documentation

Money ScriptAccounting::GetCosts (  ) 

Get the current value of the costs.

Returns:
The current costs.
Note:
when nesting ScriptAccounting instances all instances' GetCosts will always return the value of the 'top' instance.

Definition at line 15 of file script_accounting.cpp.

References ScriptObject::GetDoCommandCosts().

void ScriptAccounting::ResetCosts (  ) 

Reset the costs to zero.

Note:
when nesting ScriptAccounting instances all instances' ResetCosts will always effect on the 'top' instance.

Definition at line 20 of file script_accounting.cpp.

References ScriptObject::SetDoCommandCosts().


The documentation for this class was generated from the following files: