src/ai/api/ai_object.cpp
author truebrain
Mon, 16 Jun 2008 00:07:49 +0000
branchnoai
changeset 10977 6c1a6657c7db
parent 10668 495789401303
child 10978 13fd0364b2c6
permissions -rw-r--r--
(svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
-Note: if the road pieces failed to build, but building the bridge/tunnel succeeded, the function still returns true (for the obvious reasons)
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     1
/* $Id$ */
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     2
9833
89a64246458f (svn r12496) [NoAI] -Documentation: give the .cpp files a nice uniform format too
truebrain
parents: 9760
diff changeset
     3
/** @file ai_object.cpp Implementation of AIObject. */
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     4
9430
9e0a193b2bec (svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents: 9427
diff changeset
     5
#include "ai_object.hpp"
9851
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
     6
#include "ai_log.hpp"
9863
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9862
diff changeset
     7
#include "ai_error.hpp"
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
     8
#include "table/strings.h"
10339
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
     9
#include "../../openttd.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9703
diff changeset
    10
#include "../../command_func.h"
10977
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
    11
#include "../../map_func.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9703
diff changeset
    12
#include "../../network/network.h"
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    13
#include "../../player_func.h"
9837
c9ec4f82e0d0 (svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents: 9833
diff changeset
    14
#include "../../signs_func.h"
10977
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
    15
#include "../../tunnelbridge.h"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9703
diff changeset
    16
#include "../../vehicle_func.h"
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
    17
#include "../ai.h"
9444
fd27df7ca2a0 (svn r9260) [NoAI] -Codechange: do the AI threading properly using a mutex and condition signalling.
rubidium
parents: 9441
diff changeset
    18
#include "../ai_threads.h"
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    19
10339
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    20
struct AIObject::AIDoCommandStruct {
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    21
	AIModeProc *mode;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    22
	AIObject *mode_instance;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    23
	uint delay;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    24
	CommandCost costs;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    25
	uint last_error;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    26
	bool last_command_res;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    27
	VehicleID new_vehicle_id;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    28
	SignID new_sign_id;
10977
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
    29
	TileIndex new_tunnel_endtile;
10668
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    30
	RoadType road_type;
10339
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    31
	void *event_data;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    32
	void *log_data;
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    33
};
ce6cd68d9eb8 (svn r12880) [NoAI] -Add: introduces ai_types.hpp, which has all NNNId like VehicleID. This simplifies the include-mess, and avoids including tons of _type.h for just a single typedef.
truebrain
parents: 9864
diff changeset
    34
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    35
void AIObject::SetDoCommandDelay(uint ticks)
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    36
{
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    37
	assert(ticks > 0);
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    38
	GetDoCommandStruct(_current_player)->delay = ticks;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    39
}
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    40
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    41
uint AIObject::GetDoCommandDelay()
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    42
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    43
	return GetDoCommandStruct(_current_player)->delay;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    44
}
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    45
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    46
void AIObject::SetDoCommandMode(AIModeProc *proc, AIObject *instance)
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    47
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    48
	GetDoCommandStruct(_current_player)->mode = proc;
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    49
	GetDoCommandStruct(_current_player)->mode_instance = instance;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    50
}
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    51
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    52
AIModeProc *AIObject::GetDoCommandMode()
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    53
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    54
	return GetDoCommandStruct(_current_player)->mode;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    55
}
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
    56
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    57
AIObject *AIObject::GetDoCommandModeInstance()
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    58
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    59
	return GetDoCommandStruct(_current_player)->mode_instance;
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    60
}
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    61
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9511
diff changeset
    62
void AIObject::SetDoCommandCosts(Money value)
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9406
diff changeset
    63
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    64
	GetDoCommandStruct(_current_player)->costs = CommandCost(value);
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9406
diff changeset
    65
}
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9406
diff changeset
    66
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9511
diff changeset
    67
void AIObject::IncreaseDoCommandCosts(Money value)
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9406
diff changeset
    68
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    69
	GetDoCommandStruct(_current_player)->costs.AddCost(value);
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    70
}
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    71
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9511
diff changeset
    72
Money AIObject::GetDoCommandCosts()
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    73
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    74
	return GetDoCommandStruct(_current_player)->costs.GetCost();
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9406
diff changeset
    75
}
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9406
diff changeset
    76
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
    77
void AIObject::SetLastError(AIErrorType last_error)
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
    78
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    79
	GetDoCommandStruct(_current_player)->last_error = last_error;
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
    80
}
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
    81
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
    82
AIErrorType AIObject::GetLastError()
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
    83
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    84
	return GetDoCommandStruct(_current_player)->last_error;
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
    85
}
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
    86
10668
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    87
void AIObject::SetRoadType(RoadType road_type)
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    88
{
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    89
	GetDoCommandStruct(_current_player)->road_type = road_type;
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    90
}
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    91
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    92
RoadType AIObject::GetRoadType()
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    93
{
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    94
	return GetDoCommandStruct(_current_player)->road_type;
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    95
}
495789401303 (svn r13212) [NoAI] -Add: introducing the ability to build trams. Use AIRoad.SetCurrentRoadType to switch to Trams, than all AIRoad functions will produce tram-objects.
truebrain
parents: 10339
diff changeset
    96
9760
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
    97
void AIObject::SetLastCommandRes(bool res)
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
    98
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
    99
	GetDoCommandStruct(_current_player)->last_command_res = res;
9760
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
   100
}
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
   101
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
   102
bool AIObject::GetLastCommandRes()
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
   103
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   104
	return GetDoCommandStruct(_current_player)->last_command_res;
9760
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
   105
}
265fdd2130c3 (svn r12248) [NoAI] -Codechange: last_command_res was in AIThread, while it should be in AIObject, like all other variables like it
truebrain
parents: 9748
diff changeset
   106
9841
f931a10242c9 (svn r12507) [NoAI] -Fix: enable Doxyfile warning about missing params and fix 3 missing params in AIObject
truebrain
parents: 9837
diff changeset
   107
void AIObject::SetNewVehicleID(VehicleID vehicle_id)
9496
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   108
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   109
	GetDoCommandStruct(_current_player)->new_vehicle_id = vehicle_id;
9496
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   110
}
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   111
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   112
VehicleID AIObject::GetNewVehicleID()
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   113
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   114
	return GetDoCommandStruct(_current_player)->new_vehicle_id;
9496
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   115
}
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   116
9841
f931a10242c9 (svn r12507) [NoAI] -Fix: enable Doxyfile warning about missing params and fix 3 missing params in AIObject
truebrain
parents: 9837
diff changeset
   117
void AIObject::SetNewSignID(SignID sign_id)
9511
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   118
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   119
	GetDoCommandStruct(_current_player)->new_sign_id = sign_id;
9511
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   120
}
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   121
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   122
SignID AIObject::GetNewSignID()
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   123
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   124
	return GetDoCommandStruct(_current_player)->new_sign_id;
9511
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   125
}
f767ad06e86b (svn r9407) [NoAI] -Add: placing of signs.
rubidium
parents: 9508
diff changeset
   126
10977
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   127
void AIObject::SetNewTunnelEndtile(TileIndex tile)
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   128
{
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   129
	GetDoCommandStruct(_current_player)->new_tunnel_endtile = tile;
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   130
}
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   131
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   132
TileIndex AIObject::GetNewTunnelEndtile()
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   133
{
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   134
	return GetDoCommandStruct(_current_player)->new_tunnel_endtile;
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   135
}
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   136
9682
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   137
void *&AIObject::GetEventPointer()
9680
5ed7bbfd51c7 (svn r10629) [NoAI] -Fix: on returning a class instance which is NULL, do not make a wrapper SQ, but return a NULL pointer too
truelight
parents: 9629
diff changeset
   138
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   139
	return GetDoCommandStruct(_current_player)->event_data;
9680
5ed7bbfd51c7 (svn r10629) [NoAI] -Fix: on returning a class instance which is NULL, do not make a wrapper SQ, but return a NULL pointer too
truelight
parents: 9629
diff changeset
   140
}
5ed7bbfd51c7 (svn r10629) [NoAI] -Fix: on returning a class instance which is NULL, do not make a wrapper SQ, but return a NULL pointer too
truelight
parents: 9629
diff changeset
   141
9851
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
   142
void *&AIObject::GetLogPointer()
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
   143
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   144
	return GetDoCommandStruct(_current_player)->log_data;
9851
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
   145
}
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
   146
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   147
AIObject::AIDoCommandStruct *AIObject::GetDoCommandStruct(PlayerID player)
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   148
{
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   149
	/* Storage for data on per-AI level */
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   150
	static AIDoCommandStruct command_struct[MAX_PLAYERS];
9682
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   151
	static bool initialized = false;
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   152
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   153
	/* Make sure all memory is NULL when we start */
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   154
	if (!initialized) {
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   155
		initialized = true;
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   156
		memset(&command_struct, 0, sizeof(command_struct));
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   157
	}
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   158
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   159
	return &command_struct[player];
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   160
}
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   161
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   162
void AIObject::ResetInternalPlayerData()
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   163
{
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   164
	AIDoCommandStruct *command_struct = GetDoCommandStruct(_current_player);
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   165
	command_struct->mode = NULL;
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   166
	command_struct->delay = 1;
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9511
diff changeset
   167
	command_struct->costs = CommandCost();
9682
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   168
	if (command_struct->event_data != NULL) AIEventController::FreeEventPointer();
d031eb183733 (svn r10631) [NoAI] -Add: AIEvent, to take care of events; for now it only reports when vehicles are crashed
truelight
parents: 9680
diff changeset
   169
	command_struct->event_data = NULL;
9851
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
   170
	if (command_struct->log_data != NULL) AILog::FreeLogPointer();
a5f5a7cf2b61 (svn r12519) [NoAI] -Add: added AILog with Info(), Warning(), and Error()
truebrain
parents: 9847
diff changeset
   171
	command_struct->log_data = NULL;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   172
}
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   173
9695
708f1e3cc4c4 (svn r10936) [NoAI] -Fix: allow water_protection for non-water-building in DoCommand
truelight
parents: 9688
diff changeset
   174
bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc, bool water_protection)
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   175
{
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9473
diff changeset
   176
	uint32 flags = 0;
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   177
	PlayerID old_lp;
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 9511
diff changeset
   178
	CommandCost res;
9748
4584f8cd00e8 (svn r12228) [NoAI] -Fix: very minor coding style error (VERY minor)
truebrain
parents: 9724
diff changeset
   179
	const char *tmp_cmdtext;
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   180
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   181
	/* Make sure the last error is reset, so we don't give faulty warnings */
9863
73647fe2e301 (svn r12552) [NoAI] -Change: do not force the use of StringIDs when setting errors.
rubidium
parents: 9862
diff changeset
   182
	SetLastError(AIError::ERR_NONE);
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   183
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9473
diff changeset
   184
	if (procc != CMD_LANDSCAPE_CLEAR) flags |= DC_AUTO;
9695
708f1e3cc4c4 (svn r10936) [NoAI] -Fix: allow water_protection for non-water-building in DoCommand
truelight
parents: 9688
diff changeset
   185
	if (water_protection) flags |= DC_NO_WATER;
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9473
diff changeset
   186
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   187
	/* The test already resets _cmd_text, so backup the pointer */
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   188
	tmp_cmdtext = _cmd_text;
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   189
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   190
	/* First, do a test-run to see if we can do this */
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9473
diff changeset
   191
	res = ::DoCommand(tile, p1, p2, flags, procc);
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   192
	/* The command failed, so return */
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   193
	if (::CmdFailed(res)) {
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
   194
		SetLastError(AIError::StringToError(_error_message));
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   195
		return false;
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   196
	}
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   197
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
   198
	/* Restore _cmd_text */
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
   199
	_cmd_text = tmp_cmdtext;
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
   200
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9444
diff changeset
   201
	/* Check what the callback wants us to do */
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   202
	if (GetDoCommandMode() != NULL && !GetDoCommandMode()(tile, p1, p2, procc, res)) {
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   203
		IncreaseDoCommandCosts(res.GetCost());
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
   204
		return true;
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
   205
	}
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   206
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   207
	/* If we did a DC_EXEC, and the command did not return an error, execute it
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   208
	 * over the network */
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   209
	if (flags & DC_NO_WATER) procc |= CMD_NO_WATER;
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   210
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   211
#ifdef ENABLE_NETWORK
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   212
	/* Send the command */
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   213
	if (_networking) {
9406
3500f836dc21 (svn r9203) [NoAI] -Fix: in SP do not switch _local_player, only in MP
truelight
parents: 9370
diff changeset
   214
		/* NetworkSend_Command needs _local_player to be set correctly, so
3500f836dc21 (svn r9203) [NoAI] -Fix: in SP do not switch _local_player, only in MP
truelight
parents: 9370
diff changeset
   215
		 * adjust it, and put it back right after the function */
3500f836dc21 (svn r9203) [NoAI] -Fix: in SP do not switch _local_player, only in MP
truelight
parents: 9370
diff changeset
   216
		old_lp = _local_player;
3500f836dc21 (svn r9203) [NoAI] -Fix: in SP do not switch _local_player, only in MP
truelight
parents: 9370
diff changeset
   217
		_local_player = _current_player;
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
   218
		::NetworkSend_Command(tile, p1, p2, procc, CcAI);
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
   219
		_local_player = old_lp;
9406
3500f836dc21 (svn r9203) [NoAI] -Fix: in SP do not switch _local_player, only in MP
truelight
parents: 9370
diff changeset
   220
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
   221
		/* Suspend the AI till the command is really executed */
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   222
		::AI_SuspendPlayer(_current_player, -(int)GetDoCommandDelay());
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
   223
		/* Check if the callback still agrees with us, else return error */
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   224
		if (!GetLastCommandRes()) res = CMD_ERROR;
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   225
	} else {
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   226
#else
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   227
	{
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   228
#endif
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   229
		/* For SinglePlayer we execute the command immediatly */
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
   230
		::DoCommandP(tile, p1, p2, NULL, procc);
9496
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   231
		/* Store some values inside the AIObject static memory */
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   232
		SetNewVehicleID(_new_vehicle_id);
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   233
		SetNewSignID(_new_sign_id);
10977
6c1a6657c7db (svn r13531) [NoAI] -Add [API CHANGE]: when building a bridge/tunnel for road/tram, the BuildBridge/BuildTunnel function will now also make two half-road/half-tram pieces on both ends of the bridge/tunnel, so it is easier for you to connect them to your network. This give a more consistant behavior for road.
truebrain
parents: 10668
diff changeset
   234
		SetNewTunnelEndtile(_build_tunnel_endtile);
9496
05ebee9884b3 (svn r9368) [NoAI] -Fix: store _new_vehicle_id directly after successful handling the command in a per-AI-player-safe piece of memory, so we can restore the value when ever we want later in the process
truelight
parents: 9486
diff changeset
   235
9441
03da911c8d5f (svn r9255) [NoAI] -Add: each AI now runs in a seperate thread. The main thread is suspended if any AI thread is running, only one AI thread runs at the time.
truelight
parents: 9430
diff changeset
   236
		/* Suspend the AI player for 1 tick, so it simulates MultiPlayer */
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   237
		::AI_SuspendPlayer(_current_player, GetDoCommandDelay());
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   238
	}
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   239
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   240
	if (::CmdFailed(res)) {
9864
4a9b7b610b13 (svn r12554) [NoAI] -Codechange: add more typing information.
rubidium
parents: 9863
diff changeset
   241
		SetLastError(AIError::StringToError(_error_message));
9844
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   242
		return false;
738b8f69675f (svn r12510) [NoAI] -Add: added AIError, which allows you to catch errors triggered by commands (Morloth)
truebrain
parents: 9841
diff changeset
   243
	}
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
   244
9862
26f6a061eae6 (svn r12551) [NoAI] -Fix: remove unneeded AIObject:: (don't use AIObject:: inside the AIObject class ;))
truebrain
parents: 9851
diff changeset
   245
	IncreaseDoCommandCosts(res.GetCost());
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
   246
	return true;
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   247
}