summaryrefslogtreecommitdiff
path: root/src/engine.h
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-02-06 11:11:12 +0000
committerbjarni <bjarni@openttd.org>2007-02-06 11:11:12 +0000
commitf626458af7674e508a9ec9743a699e557d1258d8 (patch)
treee35fe2197ef3aba9cb1b1902312f0f010202376b /src/engine.h
parentec301e0f8a27a3892375c46dfde4a642ce3d8169 (diff)
downloadopenttd-f626458af7674e508a9ec9743a699e557d1258d8.tar.xz
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
-The user will notice the following changes: All vehicle types behaves in the same way Adding/removing an engine (new design and so on) can no longer result in the window selecting a new engine All valid replacements will be displayed since it looks at refitting options as well (this solves the missing ships with the newships GRF) Since you can't replace an engine into itself, the engine selected in the left list will no longer appear in the right list -The code changes: Instead of looping all engines all the time, each list generates a list like the build windows This ensures consistent list generation since only one function can loop all engines Unified code for all vehicle types It now use the lists to call the drawing code in the build vehicle window Works on selected EngineIDs instead of selected index in the list
Diffstat (limited to 'src/engine.h')
-rw-r--r--src/engine.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/engine.h b/src/engine.h
index af74bcbab..df24ee8d5 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -8,6 +8,7 @@
#include "oldpool.h"
#include "rail.h"
#include "sound.h"
+#include "vehicle.h"
enum RailVehicleTypes {
RAILVEH_SINGLEHEAD,
@@ -157,8 +158,29 @@ enum {
SHIP_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES,
};
+
+static inline EngineID GetFirstEngineOfType(byte type)
+{
+ const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
+
+ return start[VehTypeToIndex(type)];
+}
+
+static inline EngineID GetLastEngineOfType(byte type)
+{
+ const EngineID end[] = {
+ NUM_TRAIN_ENGINES,
+ ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES,
+ SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
+ AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
+
+ return end[VehTypeToIndex(type)];
+}
+
VARDEF Engine _engines[TOTAL_NUM_ENGINES];
#define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
+#define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
+
static inline Engine* GetEngine(EngineID i)
{
@@ -299,6 +321,11 @@ int32 AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID n
*/
int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags);
+/** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists
+ * @param type The type of engine
+ */
+void AddRemoveEngineFromAutoreplaceAndBuildWindows(byte type);
+
/* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
void EngList_Create(EngineList *el); ///< Creates engine list
void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list