1
/* $Id: ai_group.hpp 15520 2009-02-19 09:01:34Z yexo $ */
3
/** @file ai_group.hpp Everything to put vehicles into groups. */
8
#include "ai_object.hpp"
9
#include "ai_vehicle.hpp"
12
* Class that handles all group related functions.
14
class AIGroup : public AIObject {
16
static const char *GetClassName() { return "AIGroup"; }
19
* The group IDs of some special groups.
22
/* Values are important, as they represent the internal state of the game (see group_type.h). */
23
GROUP_ALL = 0xFFFD, //!< All vehicles are in this group.
24
GROUP_DEFAULT = 0xFFFE, //!< Vehicles not put in any other group are in this one.
25
GROUP_INVALID = 0xFFFF, //!< An invalid group id.
29
* Checks whether the given group is valid.
30
* @param group_id The group to check.
31
* @pre group_id != GROUP_DEFAULT && group_id != GROUP_ALL.
32
* @return True if and only if the group is valid.
34
static bool IsValidGroup(GroupID group_id);
38
* @param vehicle_type The type of vehicle to create a group for.
39
* @return The GroupID of the new group, or an invalid GroupID when
40
* it failed. Check the return value using IsValidGroup(). In test-mode
41
* 0 is returned if it was successful; any other value indicates failure.
43
static GroupID CreateGroup(AIVehicle::VehicleType vehicle_type);
46
* Delete the given group. When the deletion succeeds all vehicles in the
47
* given group will move to the GROUP_DEFAULT.
48
* @param group_id The group to delete.
49
* @pre IsValidGroup(group_id).
50
* @return True if and only if the group was succesfully deleted.
52
static bool DeleteGroup(GroupID group_id);
55
* Get the vehicle type of a group.
56
* @param group_id The group to get the type from.
57
* @pre IsValidGroup(group_id).
58
* @return The vehicletype of the given group.
60
static AIVehicle::VehicleType GetVehicleType(GroupID group_id);
63
* Set the name of a group.
64
* @param group_id The group to set the name for.
65
* @param name The name for the group.
66
* @pre IsValidGroup(group_id).
67
* @pre 'name' must have at least one character.
68
* @pre 'name' must have at most 30 characters.
69
* @exception AIError::ERR_NAME_IS_NOT_UNIQUE
70
* @return True if and only if the name was changed.
72
static bool SetName(GroupID group_id, const char *name);
75
* Get the name of a group.
76
* @param group_id The group to get the name of.
77
* @pre IsValidGroup(group_id).
78
* @return The name the group has.
80
static char *GetName(GroupID group_id);
83
* Enable or disable autoreplace protected. If the protection is
84
* enabled, global autoreplace won't affect vehicles in this group.
85
* @param group_id The group to change the protection for.
86
* @param enable True if protection should be enabled.
87
* @pre IsValidGroup(group_id).
88
* @return True if and only if the protection was succesfully changed.
90
static bool EnableAutoReplaceProtection(GroupID group_id, bool enable);
93
* Get the autoreplace protection status.
94
* @param group_id The group to get the protection status for.
95
* @pre IsValidGroup(group_id).
96
* @return The autoreplace protection status for the given group.
98
static bool GetAutoReplaceProtection(GroupID group_id);
101
* Get the number of engines in a given group.
102
* @param group_id The group to get the number of engines in.
103
* @param engine_id The engine id to count.
104
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
105
* @return The number of engines with id engine_id in the group with id group_id.
107
static int32 GetNumEngines(GroupID group_id, EngineID engine_id);
110
* Move a vehicle to a group.
111
* @param group_id The group to move the vehicel to.
112
* @param vehicle_id The vehicle to move to the group.
113
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
114
* @pre AIVehicle::IsValidVehicle(vehicle_id).
115
* @return True if and only if the vehicle was succesfully moved to the group.
116
* @note A vehicle can be in only one group at the same time. To remove it from
117
* a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the
118
* given group means removing it from another group.
120
static bool MoveVehicle(GroupID group_id, VehicleID vehicle_id);
123
* Enable or disable the removal of wagons when a (part of a) vehicle is
124
* (auto)replaced with a longer variant (longer wagons or longer engines)
125
* If enabled, wagons are removed from the end of the vehicle until it
126
* fits in the same number of tiles as it did before.
127
* @param keep_length If true, wagons will be removed if the a new engine is longer.
128
* @return True if and only if the value was succesfully changed.
130
static bool EnableWagonRemoval(bool keep_length);
133
* Get the current status of wagon removal.
134
* @return Whether or not wagon removal is enabled.
136
static bool HasWagonRemoval();
139
* Start replacing all vehicles with a specified engine with another engine.
140
* @param group_id The group to replace vehicles from. Use ALL_GROUP to replace
141
* vehicles from all groups that haven't set autoreplace protection.
142
* @param engine_id_old The engine id to start replacing.
143
* @param engine_id_new The engine id to replace with.
144
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL.
145
* @pre AIEngine.IsValidEngine(engine_id_new).
146
* @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old).
148
static bool SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new);
151
* Get the EngineID the given EngineID is replaced with.
152
* @param group_id The group to get the replacement from.
153
* @param engine_id The engine that is being replaced.
154
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL.
155
* @return The EngineID that is replacing engine_id or an invalid EngineID
156
* in case engine_id is not begin replaced.
158
static EngineID GetEngineReplacement(GroupID group_id, EngineID engine_id);
161
* Stop replacing a certain engine in the specified group.
162
* @param group_id The group to stop replacing the engine in.
163
* @param engine_id The engine id to stop replacing with another engine.
164
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL.
165
* @return True if and if the replacing was succesfully stopped.
167
static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
170
#endif /* AI_GROUP_HPP */