AIAccounting 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 <ai_accounting.hpp>

Inheritance diagram for AIAccounting:
AIObject SimpleCountedObject

Public Member Functions

 AIAccounting ()
 Creating instance of this class starts counting the costs of commands from zero.
 ~AIAccounting ()
 Restore the AIAccounting 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.

Static Public Member Functions

static const char * GetClassName ()
 Get the name of this class to identify it towards squirrel.

Private Attributes

Money last_costs

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. Example:

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

Definition at line 30 of file ai_accounting.hpp.


Constructor & Destructor Documentation

AIAccounting::AIAccounting (  ) 

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 ai_accounting.cpp.

References AIObject::GetDoCommandCosts(), and AIObject::SetDoCommandCosts().

AIAccounting::~AIAccounting (  ) 

Restore the AIAccounting 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 ai_accounting.cpp.

References AIObject::SetDoCommandCosts().


Member Function Documentation

static const char* AIAccounting::GetClassName (  )  [inline, static]

Get the name of this class to identify it towards squirrel.

Definition at line 33 of file ai_accounting.hpp.

Money AIAccounting::GetCosts (  ) 

Get the current value of the costs.

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

Definition at line 15 of file ai_accounting.cpp.

References AIObject::GetDoCommandCosts().

void AIAccounting::ResetCosts (  ) 

Reset the costs to zero.

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

Definition at line 20 of file ai_accounting.cpp.

References AIObject::SetDoCommandCosts().


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

Generated on Sun Jan 23 01:49:45 2011 for OpenTTD by  doxygen 1.6.1