src/ai/api/ai_object.hpp
author truelight
Tue, 20 Mar 2007 11:42:07 +0000
branchnoai
changeset 9496 05ebee9884b3
parent 9486 a9b5f6b8667c
child 9511 f767ad06e86b
permissions -rw-r--r--
(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
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
9416
432e904ce0e1 (svn r9214) [NoAI] -Documentation: wrong @file flag
truelight
parents: 9414
diff changeset
     3
/** @file ai_object.hpp declaration of class for AIObject class */
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     4
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     5
#ifndef AI_OBJECT_HPP
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     6
#define AI_OBJECT_HPP
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
     7
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: 9427
diff changeset
     8
#include "../../stdafx.h"
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: 9427
diff changeset
     9
#include "../../functions.h"
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    10
9475
58c20c0e394f (svn r9320) [NoAI] -Fix: added some doxygen comments to make doxygen happy
truelight
parents: 9473
diff changeset
    11
/**
58c20c0e394f (svn r9320) [NoAI] -Fix: added some doxygen comments to make doxygen happy
truelight
parents: 9473
diff changeset
    12
 * The callback function for Mode-classes.
58c20c0e394f (svn r9320) [NoAI] -Fix: added some doxygen comments to make doxygen happy
truelight
parents: 9473
diff changeset
    13
 */
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9475
diff changeset
    14
typedef bool (AIModeProc)(TileIndex tile, uint32 p1, uint32 p2, uint procc, int32 costs);
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    15
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9441
diff changeset
    16
/**
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9441
diff changeset
    17
 * Uper-parent object of all API classes. You should never use this class in
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9441
diff changeset
    18
 *   your AI, as it doesn't publish any public functions. It is used
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9441
diff changeset
    19
 *   internally to have a common place to handle general things, like internal
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9441
diff changeset
    20
 *   command processing, and command-validation checks.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9441
diff changeset
    21
 */
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    22
class AIObject {
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    23
private:
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    24
	struct AIDoCommandStruct {
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    25
		AIModeProc *mode;
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    26
		AIObject *mode_instance;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    27
		uint delay;
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    28
		int32 costs;
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
    29
		VehicleID new_vehicle_id;
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    30
	};
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    31
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    32
	/**
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    33
	 * The current mode of the AI players.
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    34
	 */
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    35
	static AIDoCommandStruct *GetDoCommandStruct(PlayerID player);
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    36
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    37
protected:
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    38
	/**
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    39
	 * Executes a raw DoCommand for the AI.
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
    40
	 */
9486
a9b5f6b8667c (svn r9336) [NoAI] -Fix: remove 'flags' for AI DoCommand and detect its value automaticly
truelight
parents: 9475
diff changeset
    41
	static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc);
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9388
diff changeset
    42
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9388
diff changeset
    43
	/**
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    44
	 * Sets the DoCommand costs counter to a value.
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9388
diff changeset
    45
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    46
	static void SetDoCommandCosts(int32 value);
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9388
diff changeset
    47
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9388
diff changeset
    48
	/**
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    49
	 * Increase the current value of the DoCommand costs counter.
9414
a7f7bbec08da (svn r9212) [NoAI] -Add: added CmdFailed and CmdSucceeded in AIObject() and used it
truelight
parents: 9388
diff changeset
    50
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    51
	static void IncreaseDoCommandCosts(int32 value);
9452
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    52
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    53
	/**
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    54
	 * Get the current DoCommand costs counter.
4c5eedbc3ba9 (svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
truelight
parents: 9450
diff changeset
    55
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    56
	static int32 GetDoCommandCosts();
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    57
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    58
	/**
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    59
	 * Set the current mode of your AI to this proc.
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    60
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    61
	static void 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: 9448
diff changeset
    62
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    63
	/**
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    64
	 * Get the current mode your AI is currently under.
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    65
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    66
	static AIModeProc *GetDoCommandMode();
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    67
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    68
	/**
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    69
	 * Get the instance of the current mode your AI is currently under.
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    70
	 */
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    71
	static AIObject *GetDoCommandModeInstance();
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    72
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    73
	/**
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    74
	 * Set the delay of the DoCommand.
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    75
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    76
	static void SetDoCommandDelay(uint ticks);
9450
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    77
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    78
	/**
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    79
	 * Get the delay of the DoCommand.
d675836e865c (svn r9278) [NoAI] -Add: added AISettings which adds the function to control the Delay-value on DoCommands
truelight
parents: 9448
diff changeset
    80
	 */
9473
dcbcd1c4496d (svn r9318) [NoAI] -Add: added new param in ModeCallback: costs
truelight
parents: 9454
diff changeset
    81
	static uint GetDoCommandDelay();
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
    82
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
    83
	/**
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
    84
	 * Get the latest stored new_vehicle_id.
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
    85
	 */
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
    86
	static VehicleID 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
    87
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
    88
public:
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
    89
	/**
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
    90
	 * Store a new_vehicle_id per player.
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
    91
	 * @note NEVER use this yourself in your AI!
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
    92
	 */
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
    93
	static void SetNewVehicleID(VehicleID vehicle);
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
    94
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
    95
	/**
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
    96
	 * If an AI starts, some internals needs to be resetted. This function
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
    97
	 *   takes care of that.
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
    98
	 * @note NEVER use this yourself in your AI!
9454
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
    99
	 */
ee6a65b37b82 (svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
truelight
parents: 9452
diff changeset
   100
	static void ResetInternalPlayerData();
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   101
};
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   102
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
diff changeset
   103
#endif /* AI_OBJECT_HPP */