~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/ai/api/ai_group.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: ai_group.hpp 15520 2009-02-19 09:01:34Z yexo $ */
 
2
 
 
3
/** @file ai_group.hpp Everything to put vehicles into groups. */
 
4
 
 
5
#ifndef AI_GROUP_HPP
 
6
#define AI_GROUP_HPP
 
7
 
 
8
#include "ai_object.hpp"
 
9
#include "ai_vehicle.hpp"
 
10
 
 
11
/**
 
12
 * Class that handles all group related functions.
 
13
 */
 
14
class AIGroup : public AIObject {
 
15
public:
 
16
        static const char *GetClassName() { return "AIGroup"; }
 
17
 
 
18
        /**
 
19
         * The group IDs of some special groups.
 
20
         */
 
21
        enum GroupID {
 
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.
 
26
        };
 
27
 
 
28
        /**
 
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.
 
33
         */
 
34
        static bool IsValidGroup(GroupID group_id);
 
35
 
 
36
        /**
 
37
         * Create a new group.
 
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.
 
42
         */
 
43
        static GroupID CreateGroup(AIVehicle::VehicleType vehicle_type);
 
44
 
 
45
        /**
 
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.
 
51
         */
 
52
        static bool DeleteGroup(GroupID group_id);
 
53
 
 
54
        /**
 
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.
 
59
         */
 
60
        static AIVehicle::VehicleType GetVehicleType(GroupID group_id);
 
61
 
 
62
        /**
 
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.
 
71
         */
 
72
        static bool SetName(GroupID group_id, const char *name);
 
73
 
 
74
        /**
 
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.
 
79
         */
 
80
        static char *GetName(GroupID group_id);
 
81
 
 
82
        /**
 
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.
 
89
         */
 
90
        static bool EnableAutoReplaceProtection(GroupID group_id, bool enable);
 
91
 
 
92
        /**
 
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.
 
97
         */
 
98
        static bool GetAutoReplaceProtection(GroupID group_id);
 
99
 
 
100
        /**
 
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.
 
106
         */
 
107
        static int32 GetNumEngines(GroupID group_id, EngineID engine_id);
 
108
 
 
109
        /**
 
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.
 
119
         */
 
120
        static bool MoveVehicle(GroupID group_id, VehicleID vehicle_id);
 
121
 
 
122
        /**
 
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.
 
129
         */
 
130
        static bool EnableWagonRemoval(bool keep_length);
 
131
 
 
132
        /**
 
133
         * Get the current status of wagon removal.
 
134
         * @return Whether or not wagon removal is enabled.
 
135
         */
 
136
        static bool HasWagonRemoval();
 
137
 
 
138
        /**
 
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).
 
147
         */
 
148
        static bool SetAutoReplace(GroupID group_id, EngineID engine_id_old, EngineID engine_id_new);
 
149
 
 
150
        /**
 
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.
 
157
         */
 
158
        static EngineID GetEngineReplacement(GroupID group_id, EngineID engine_id);
 
159
 
 
160
        /**
 
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.
 
166
         */
 
167
        static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
 
168
};
 
169
 
 
170
#endif /* AI_GROUP_HPP */