src/ai/api/ai_accounting.hpp
branchnoai
changeset 9452 4c5eedbc3ba9
child 9462 a4f49aab1367
equal deleted inserted replaced
9451:7629656423cc 9452:4c5eedbc3ba9
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file ai_accounting.hpp everything to handle AI accounting things */
       
     4 
       
     5 #ifndef AI_ACCOUNTING_HPP
       
     6 #define AI_ACCOUNTING_HPP
       
     7 
       
     8 #include "ai_object.hpp"
       
     9 
       
    10 /**
       
    11  * Class that handles all AI accounting related functions.
       
    12  * Example:
       
    13  *   {
       
    14  *     local costs = AIAccounting();
       
    15  *     BuildRoad(from_here, to_here);
       
    16  *     BuildRoad(from_there, to_there);
       
    17  *     print("Costs for route is: " + costs.GetCosts());
       
    18  *   }
       
    19  */
       
    20 class AIAccounting : public AIObject {
       
    21 private:
       
    22 	int32 last_costs;
       
    23 public:
       
    24 	/**
       
    25 	 * Creating instance of this class starts counting the costs of commands
       
    26 	 *   from zero.
       
    27 	 * @note when the instance is destroyed, he restores the costs that was
       
    28 	 *   current when the instance was created!
       
    29 	 */
       
    30 	AIAccounting();
       
    31 
       
    32 	/**
       
    33 	 * Destroying this instance reset the costs to the value it was
       
    34 	 *   in when the instance was created.
       
    35 	 */
       
    36 	~AIAccounting();
       
    37 
       
    38 	/**
       
    39 	 * Get the current value of the costs.
       
    40 	 */
       
    41 	int32 GetCosts();
       
    42 
       
    43 	/**
       
    44 	 * Reset the costs to zero.
       
    45 	 */
       
    46 	void ResetCosts();
       
    47 };
       
    48 
       
    49 #ifdef DEFINE_SQUIRREL_CLASS
       
    50 void SQAIAccountingRegister(Squirrel *engine) {
       
    51 	DefSQClass <AIAccounting> SQAIAccounting("AIAccounting");
       
    52 	SQAIAccounting.PreRegister(engine);
       
    53 	SQAIAccounting.AddConstructor(engine);
       
    54 	SQAIAccounting.DefSQFunction(engine, &AIAccounting::GetCosts, "GetCosts");
       
    55 	SQAIAccounting.DefSQFunction(engine, &AIAccounting::ResetCosts, "ResetCosts");
       
    56 	SQAIAccounting.PostRegister(engine);
       
    57 }
       
    58 #endif /* SQUIRREL_CLASS */
       
    59 
       
    60 #endif /* AI_ACCOUNTING_HPP */