src/ai/api/ai_transactionmode.cpp
author truebrain
Fri, 18 Jul 2008 00:15:14 +0000
branchnoai
changeset 11165 a725845fcc01
parent 11007 d57c2e53679b
permissions -rw-r--r--
(svn r13723) [NoAI] -Add: added AIIndustry::GetStockpiledCargo() (Yexo)
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     1
/* $Id$ */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     2
9833
89a64246458f (svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents: 9723
diff changeset
     3
/** @file ai_transactionmode.cpp Implementation of AITransactionMode. */
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     4
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     5
#include "ai_transactionmode.hpp"
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     6
#include "ai_execmode.hpp"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9629
diff changeset
     7
#include "../../command_func.h"
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     8
#include "../../debug.h"
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     9
#include <stack>
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    10
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9560
diff changeset
    11
bool AITransactionMode::ModeProc(TileIndex tile, uint32 p1, uint32 p2, uint procc, CommandCost costs)
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    12
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    13
	AITransactionMode *instance = (AITransactionMode *)AIObject::GetDoCommandModeInstance();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    14
	/* Don't record if we are stopped */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    15
	if (instance->stopped) return false;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    16
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    17
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    18
	/* Store all params in a nice list, so we can execute them later */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    19
	command.tile  = tile;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    20
	command.p1    = p1;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    21
	command.p2    = p2;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    22
	command.procc = procc;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    23
	command.text  = (_cmd_text == NULL) ? NULL : strdup(_cmd_text);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    24
	instance->command_stack.push(command);
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9560
diff changeset
    25
	instance->costs.AddCost(costs);
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    26
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    27
	/* Now we return 'false', as we don't want to execute the commands just yet */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    28
	return false;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    29
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    30
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    31
AITransactionMode::AITransactionMode()
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    32
{
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9560
diff changeset
    33
	this->costs         = CommandCost();
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    34
	this->stopped       = false;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    35
	this->last_mode     = this->GetDoCommandMode();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    36
	this->last_instance = this->GetDoCommandModeInstance();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    37
	this->SetDoCommandMode(&AITransactionMode::ModeProc, this);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    38
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    39
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    40
AITransactionMode::~AITransactionMode()
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    41
{
11007
d57c2e53679b (svn r13563) [NoAI] -Fix: added some asserts to ensure sanity of AI*Modes.
truebrain
parents: 9833
diff changeset
    42
	assert(this->GetDoCommandModeInstance() == this);
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    43
	this->SetDoCommandMode(this->last_mode, this->last_instance);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    44
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    45
	/* Clean up the command_stack nicely (as in: free the cmd_text) */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    46
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    47
	while (!this->command_stack.empty()) {
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    48
		command = this->command_stack.front();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    49
		free(command.text);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    50
		this->command_stack.pop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    51
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    52
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    53
	/* Clean up the reverse_stack too */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    54
	while (!this->reverse_stack.empty()) {
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    55
		command = this->reverse_stack.front();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    56
		free(command.text);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    57
		this->reverse_stack.pop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    58
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    59
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    60
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    61
bool AITransactionMode::Execute()
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    62
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    63
	/* Make sure we are stopped */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    64
	this->Stop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    65
9560
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    66
	/* Remove the costs this transaction costs from the total costs, so any
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    67
	 *  'accounting' running on the background will get the real costs for
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    68
	 *  executing, and not the double value of both testing and executing */
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    69
	this->IncreaseDoCommandCosts(-this->GetCosts());
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    70
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    71
	/* Switch to a forced execute mode */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    72
	AIExecMode exec;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    73
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    74
	/* Reverse stack should be empty */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    75
	assert(this->reverse_stack.empty());
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    76
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    77
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    78
	while (!this->command_stack.empty()) {
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    79
		command = this->command_stack.front();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    80
		_cmd_text = command.text;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    81
		/* Make sure we return 'false' if the command fails to execute. This allows rollback of failed builds. */
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9474
diff changeset
    82
		if (!this->DoCommand(command.tile, command.p1, command.p2, command.procc)) return false;
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    83
		/* Add the command to the reverse stack */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    84
		this->reverse_stack.push(command);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    85
		/* Remove the item from the list */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    86
		this->command_stack.pop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    87
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    88
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    89
	/* Everything went okay, clean the reverse stack */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    90
	while (!this->reverse_stack.empty()) {
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    91
		command = this->reverse_stack.front();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    92
		free(command.text);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    93
		this->reverse_stack.pop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    94
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    95
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    96
	/* Reverse stack should be empty again */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    97
	assert(this->reverse_stack.empty());
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    98
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    99
	return true;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   100
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   101
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   102
void AITransactionMode::Stop()
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   103
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   104
	this->stopped = true;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   105
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   106
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   107
void AITransactionMode::Rollback()
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   108
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   109
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   110
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   111
	DEBUG(ai, 0, "AITransactionMode::Rollback is not yet implemented");
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   112
	return;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   113
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   114
	while (!this->reverse_stack.empty()) {
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   115
		command = this->reverse_stack.front();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   116
		_cmd_text = command.text;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   117
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   118
		/* Find the reverse, and issue it */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   119
		/* TODO -- Make a table which reverses every command.procc */
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9474
diff changeset
   120
		this->DoCommand(command.tile, command.p1, command.p2, command.procc);
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   121
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   122
		/* Remove the item from the list */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   123
		this->reverse_stack.pop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   124
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   125
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   126
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9560
diff changeset
   127
Money AITransactionMode::GetCosts()
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   128
{
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9560
diff changeset
   129
	return this->costs.GetCost();
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   130
}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   131
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   132
void AITransactionMode::Append(AITransactionMode *transaction)
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   133
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   134
	/* Can't append to myself! */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   135
	if (transaction == this) return;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   136
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   137
	/* Simply move the queue from transaction to ourself */
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   138
	while (!transaction->command_stack.empty()) {
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   139
		this->command_stack.push(transaction->command_stack.front());
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   140
		transaction->command_stack.pop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   141
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   142
}