src/ai/api/ai_transactionmode.cpp
author rubidium
Sat, 14 Apr 2007 20:38:10 +0000
branchnoai
changeset 9594 5009a30f320a
parent 9560 ff2dde050a4c
child 9629 66dde6412125
permissions -rw-r--r--
(svn r9627) [NoAI] -Fix: let the squirrel export script export all needed (and a few more) types of references to structs and classes.
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
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     3
/** @file ai_transactionmode.cpp class to switch the AI to Transaction mode */
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"
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
     7
#include "../../command.h"
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
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9474
diff changeset
    11
bool AITransactionMode::ModeProc(TileIndex tile, uint32 p1, uint32 p2, uint procc, int32 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);
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    25
	instance->costs += costs;
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
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    33
	this->costs         = 0;
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
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    42
	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
    43
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    44
	/* 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
    45
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    46
	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
    47
		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
    48
		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
    49
		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
    50
	}
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
	/* 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
    53
	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
    54
		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
    55
		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
    56
		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
    57
	}
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
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
    61
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    62
	/* 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
    63
	this->Stop();
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    64
9560
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    65
	/* 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
    66
	 *  '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
    67
	 *  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
    68
	this->IncreaseDoCommandCosts(-this->GetCosts());
ff2dde050a4c (svn r9498) [NoAI] -Add: added regression for AITransactionMode()
truelight
parents: 9486
diff changeset
    69
9474
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    70
	/* 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
    71
	AIExecMode exec;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    72
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    73
	/* 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
    74
	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
    75
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    76
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    77
	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
    78
		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
    79
		_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
    80
		/* 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
    81
		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
    82
		/* 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
    83
		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
    84
		/* 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
    85
		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
    86
	}
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
	/* 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
    89
	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
    90
		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
    91
		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
    92
		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
    93
	}
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
	/* 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
    96
	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
    97
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    98
	return true;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
    99
}
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
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
   102
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   103
	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
   104
}
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
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
   107
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   108
	AITransactionModeCommand command;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   109
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   110
	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
   111
	return;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   112
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   113
	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
   114
		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
   115
		_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
   116
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   117
		/* 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
   118
		/* 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
   119
		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
   120
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   121
		/* 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
   122
		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
   123
	}
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
int32 AITransactionMode::GetCosts()
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   127
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   128
	return this->costs;
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   129
}
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
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
   132
{
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   133
	/* 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
   134
	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
   135
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   136
	/* 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
   137
	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
   138
		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
   139
		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
   140
	}
2b53e154a8d5 (svn r9319) [NoAI] -Add: added AITransactionMode, which allows you to record commands and execute it later on.
truelight
parents:
diff changeset
   141
}