1
/* $Id: ai_group.hpp 21890 2011-01-22 14:52:20Z rubidium $ */
4
* This file is part of OpenTTD.
5
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10
/** @file ai_group.hpp Everything to put vehicles into groups. */
15
#include "ai_vehicle.hpp"
18
* Class that handles all group related functions.
20
class AIGroup : public AIObject {
22
/** Get the name of this class to identify it towards squirrel. */
23
static const char *GetClassName() { return "AIGroup"; }
26
* The group IDs of some special groups.
29
/* Values are important, as they represent the internal state of the game (see group_type.h). */
30
GROUP_ALL = 0xFFFD, ///< All vehicles are in this group.
31
GROUP_DEFAULT = 0xFFFE, ///< Vehicles not put in any other group are in this one.
32
GROUP_INVALID = 0xFFFF, ///< An invalid group id.
36
* Checks whether the given group is valid.
37
* @param group_id The group to check.
38
* @pre group_id != GROUP_DEFAULT && group_id != GROUP_ALL.
39
* @return True if and only if the group is valid.
41
static bool IsValidGroup(GroupID group_id);
45
* @param vehicle_type The type of vehicle to create a group for.
46
* @return The GroupID of the new group, or an invalid GroupID when
47
* it failed. Check the return value using IsValidGroup(). In test-mode
48
* 0 is returned if it was successful; any other value indicates failure.
50
static GroupID CreateGroup(AIVehicle::VehicleType vehicle_type);
53
* Delete the given group. When the deletion succeeds all vehicles in the
54
* given group will move to the GROUP_DEFAULT.
55
* @param group_id The group to delete.
56
* @pre IsValidGroup(group_id).
57
* @return True if and only if the group was successfully deleted.
59
static bool DeleteGroup(GroupID group_id);
62
* Get the vehicle type of a group.
63
* @param group_id The group to get the type from.
64
* @pre IsValidGroup(group_id).
65
* @return The vehicletype of the given group.
67
static AIVehicle::VehicleType GetVehicleType(GroupID group_id);
70
* Set the name of a group.
71
* @param group_id The group to set the name for.
72
* @param name The name for the group.
73
* @pre IsValidGroup(group_id).
74
* @pre 'name' must have at least one character.
75
* @pre 'name' must have at most 30 characters.
76
* @exception AIError::ERR_NAME_IS_NOT_UNIQUE
77
* @return True if and only if the name was changed.
79
static bool SetName(GroupID group_id, const char *name);
82
* Get the name of a group.
83
* @param group_id The group to get the name of.
84
* @pre IsValidGroup(group_id).
85
* @return The name the group has.
87
static char *GetName(GroupID group_id);
90
* Enable or disable autoreplace protected. If the protection is
91
* enabled, global autoreplace won't affect vehicles in this group.
92
* @param group_id The group to change the protection for.
93
* @param enable True if protection should be enabled.
94
* @pre IsValidGroup(group_id).
95
* @return True if and only if the protection was successfully changed.
97
static bool EnableAutoReplaceProtection(GroupID group_id, bool enable);
100
* Get the autoreplace protection status.
101
* @param group_id The group to get the protection status for.
102
* @pre IsValidGroup(group_id).
103
* @return The autoreplace protection status for the given group.
105
static bool GetAutoReplaceProtection(GroupID group_id);
108
* Get the number of engines in a given group.
109
* @param group_id The group to get the number of engines in.
110
* @param engine_id The engine id to count.
111
* @pre IsValidGroup(group_id) || group_id == GROUP_ALL || group_id == GROUP_DEFAULT.
112
* @return The number of engines with id engine_id in the group with id group_id.
114
static int32 GetNumEngines(GroupID group_id, EngineID engine_id);
117
* Move a vehicle to a group.
118
* @param group_id The group to move the vehicel to.
119
* @param vehicle_id The vehicle to move to the group.
120
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT.
121
* @pre AIVehicle::IsValidVehicle(vehicle_id).
122
* @return True if and only if the vehicle was successfully moved to the group.
123
* @note A vehicle can be in only one group at the same time. To remove it from
124
* a group, move it to another or to GROUP_DEFAULT. Moving the vehicle to the
125
* given group means removing it from another group.
127
static bool MoveVehicle(GroupID group_id, VehicleID vehicle_id);
130
* Enable or disable the removal of wagons when a (part of a) vehicle is
131
* (auto)replaced with a longer variant (longer wagons or longer engines)
132
* If enabled, wagons are removed from the end of the vehicle until it
133
* fits in the same number of tiles as it did before.
134
* @param keep_length If true, wagons will be removed if the a new engine is longer.
135
* @return True if and only if the value was successfully changed.
137
static bool EnableWagonRemoval(bool keep_length);
140
* Get the current status of wagon removal.
141
* @return Whether or not wagon removal is enabled.
143
static bool HasWagonRemoval();
146
* Start replacing all vehicles with a specified engine with another engine.
147
* @param group_id The group to replace vehicles from. Use ALL_GROUP to replace
148
* vehicles from all groups that haven't set autoreplace protection.
149
* @param engine_id_old The engine id to start replacing.
150
* @param engine_id_new The engine id to replace with.
151
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
152
* @pre AIEngine.IsBuildable(engine_id_new).
153
* @return True if and if the replacing was successfully started.
154
* @note To stop autoreplacing engine_id_old, call StopAutoReplace(group_id, engine_id_old).
156
static bool SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new);
159
* Get the EngineID the given EngineID is replaced with.
160
* @param group_id The group to get the replacement from.
161
* @param engine_id The engine that is being replaced.
162
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
163
* @return The EngineID that is replacing engine_id or an invalid EngineID
164
* in case engine_id is not begin replaced.
166
static EngineID GetEngineReplacement(GroupID group_id, EngineID engine_id);
169
* Stop replacing a certain engine in the specified group.
170
* @param group_id The group to stop replacing the engine in.
171
* @param engine_id The engine id to stop replacing with another engine.
172
* @pre IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL.
173
* @return True if and if the replacing was successfully stopped.
175
static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
178
#endif /* AI_GROUP_HPP */