summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/openttd_vs80.vcproj12
-rw-r--r--projects/openttd_vs90.vcproj12
-rw-r--r--source.list3
-rw-r--r--src/autoreplace.cpp150
-rw-r--r--src/autoreplace_base.h2
-rw-r--r--src/engine.cpp142
-rw-r--r--src/engine_type.h1
-rw-r--r--src/misc.cpp4
-rw-r--r--src/saveload.cpp2
9 files changed, 184 insertions, 144 deletions
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index 65879058d..88044a818 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -456,6 +456,10 @@
>
</File>
<File
+ RelativePath=".\..\src\autoreplace.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\aystar.cpp"
>
</File>
@@ -1576,6 +1580,10 @@
>
</File>
<File
+ RelativePath=".\..\src\vehicle_gui_base.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\vehicle_type.h"
>
</File>
@@ -2044,6 +2052,10 @@
>
</File>
<File
+ RelativePath=".\..\src\table\palette_convert.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\table\railtypes.h"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index 248efa350..9c8b73d73 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -453,6 +453,10 @@
>
</File>
<File
+ RelativePath=".\..\src\autoreplace.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\aystar.cpp"
>
</File>
@@ -1573,6 +1577,10 @@
>
</File>
<File
+ RelativePath=".\..\src\vehicle_gui_base.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\vehicle_type.h"
>
</File>
@@ -2041,6 +2049,10 @@
>
</File>
<File
+ RelativePath=".\..\src\table\palette_convert.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\table\railtypes.h"
>
</File>
diff --git a/source.list b/source.list
index ce747750b..5b78893d7 100644
--- a/source.list
+++ b/source.list
@@ -2,6 +2,7 @@
airport.cpp
animated_tile.cpp
articulated_vehicles.cpp
+autoreplace.cpp
aystar.cpp
bmp.cpp
callback_table.cpp
@@ -321,6 +322,7 @@ variables.h
vehicle_base.h
vehicle_func.h
vehicle_gui.h
+vehicle_gui_base.h
vehicle_type.h
vehiclelist.h
viewport_func.h
@@ -456,6 +458,7 @@ table/industry_land.h
table/landscape_sprite.h
table/namegen.h
table/palettes.h
+table/palette_convert.h
table/railtypes.h
table/road_land.h
table/roadveh_movement.h
diff --git a/src/autoreplace.cpp b/src/autoreplace.cpp
new file mode 100644
index 000000000..a2da94776
--- /dev/null
+++ b/src/autoreplace.cpp
@@ -0,0 +1,150 @@
+/* $Id$ */
+
+/** @file autoreplace.cpp Management of replacement lists. */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "debug.h"
+#include "command_func.h"
+#include "saveload.h"
+#include "group.h"
+#include "autoreplace_base.h"
+#include "oldpool_func.h"
+
+DEFINE_OLD_POOL_GENERIC(EngineRenew, EngineRenew)
+
+/**
+ * Retrieves the EngineRenew that specifies the replacement of the given
+ * engine type from the given renewlist */
+static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
+{
+ EngineRenew *er = (EngineRenew *)erl;
+
+ while (er) {
+ if (er->from == engine && er->group_id == group) return er;
+ er = er->next;
+ }
+ return NULL;
+}
+
+void RemoveAllEngineReplacement(EngineRenewList *erl)
+{
+ EngineRenew *er = (EngineRenew *)(*erl);
+ EngineRenew *next;
+
+ while (er != NULL) {
+ next = er->next;
+ delete er;
+ er = next;
+ }
+ *erl = NULL; // Empty list
+}
+
+EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
+{
+ const EngineRenew *er = GetEngineReplacement(erl, engine, group);
+ if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !GetGroup(group)->replace_protection))) {
+ /* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
+ er = GetEngineReplacement(erl, engine, ALL_GROUP);
+ }
+ return er == NULL ? INVALID_ENGINE : er->to;
+}
+
+CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
+{
+ EngineRenew *er;
+
+ /* Check if the old vehicle is already in the list */
+ er = GetEngineReplacement(*erl, old_engine, group);
+ if (er != NULL) {
+ if (flags & DC_EXEC) er->to = new_engine;
+ return CommandCost();
+ }
+
+ if (!EngineRenew::CanAllocateItem()) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ er = new EngineRenew(old_engine, new_engine);
+ er->group_id = group;
+
+ /* Insert before the first element */
+ er->next = (EngineRenew *)(*erl);
+ *erl = (EngineRenewList)er;
+ }
+
+ return CommandCost();
+}
+
+CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
+{
+ EngineRenew *er = (EngineRenew *)(*erl);
+ EngineRenew *prev = NULL;
+
+ while (er)
+ {
+ if (er->from == engine && er->group_id == group) {
+ if (flags & DC_EXEC) {
+ if (prev == NULL) { // First element
+ /* The second becomes the new first element */
+ *erl = (EngineRenewList)er->next;
+ } else {
+ /* Cut this element out */
+ prev->next = er->next;
+ }
+ delete er;
+ }
+ return CommandCost();
+ }
+ prev = er;
+ er = er->next;
+ }
+
+ return CMD_ERROR;
+}
+
+static const SaveLoad _engine_renew_desc[] = {
+ SLE_VAR(EngineRenew, from, SLE_UINT16),
+ SLE_VAR(EngineRenew, to, SLE_UINT16),
+
+ SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
+ SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),
+ SLE_END()
+};
+
+static void Save_ERNW()
+{
+ EngineRenew *er;
+
+ FOR_ALL_ENGINE_RENEWS(er) {
+ SlSetArrayIndex(er->index);
+ SlObject(er, _engine_renew_desc);
+ }
+}
+
+static void Load_ERNW()
+{
+ int index;
+
+ while ((index = SlIterateArray()) != -1) {
+ EngineRenew *er = new (index) EngineRenew();
+ SlObject(er, _engine_renew_desc);
+
+ /* Advanced vehicle lists, ungrouped vehicles got added */
+ if (CheckSavegameVersion(60)) {
+ er->group_id = ALL_GROUP;
+ } else if (CheckSavegameVersion(71)) {
+ if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
+ }
+ }
+}
+
+extern const ChunkHandler _autoreplace_chunk_handlers[] = {
+ { 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST},
+};
+
+void InitializeEngineRenews()
+{
+ /* Clean the engine renew pool and create 1 block in it */
+ _EngineRenew_pool.CleanPool();
+ _EngineRenew_pool.AddBlockToPool();
+}
diff --git a/src/autoreplace_base.h b/src/autoreplace_base.h
index 065cc5661..ca5533e47 100644
--- a/src/autoreplace_base.h
+++ b/src/autoreplace_base.h
@@ -8,6 +8,8 @@
#include "oldpool.h"
#include "autoreplace_type.h"
+typedef uint16 EngineRenewID;
+
/**
* Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is
* placed here so the only exception to this rule, the saveload code, can use
diff --git a/src/engine.cpp b/src/engine.cpp
index ffc6c0176..60000ac5b 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -21,7 +21,6 @@
#include "functions.h"
#include "window_func.h"
#include "date_func.h"
-#include "autoreplace_base.h"
#include "autoreplace_gui.h"
#include "string_func.h"
#include "settings_type.h"
@@ -569,137 +568,6 @@ CargoID GetEngineCargoType(EngineID engine)
}
}
-/************************************************************************
- * Engine Replacement stuff
- ************************************************************************/
-
-DEFINE_OLD_POOL_GENERIC(EngineRenew, EngineRenew)
-
-/**
- * Retrieves the EngineRenew that specifies the replacement of the given
- * engine type from the given renewlist */
-static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
-{
- EngineRenew *er = (EngineRenew *)erl;
-
- while (er) {
- if (er->from == engine && er->group_id == group) return er;
- er = er->next;
- }
- return NULL;
-}
-
-void RemoveAllEngineReplacement(EngineRenewList *erl)
-{
- EngineRenew *er = (EngineRenew *)(*erl);
- EngineRenew *next;
-
- while (er != NULL) {
- next = er->next;
- delete er;
- er = next;
- }
- *erl = NULL; // Empty list
-}
-
-EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
-{
- const EngineRenew *er = GetEngineReplacement(erl, engine, group);
- if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !GetGroup(group)->replace_protection))) {
- /* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
- er = GetEngineReplacement(erl, engine, ALL_GROUP);
- }
- return er == NULL ? INVALID_ENGINE : er->to;
-}
-
-CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
-{
- EngineRenew *er;
-
- /* Check if the old vehicle is already in the list */
- er = GetEngineReplacement(*erl, old_engine, group);
- if (er != NULL) {
- if (flags & DC_EXEC) er->to = new_engine;
- return CommandCost();
- }
-
- if (!EngineRenew::CanAllocateItem()) return CMD_ERROR;
-
- if (flags & DC_EXEC) {
- er = new EngineRenew(old_engine, new_engine);
- er->group_id = group;
-
- /* Insert before the first element */
- er->next = (EngineRenew *)(*erl);
- *erl = (EngineRenewList)er;
- }
-
- return CommandCost();
-}
-
-CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
-{
- EngineRenew *er = (EngineRenew *)(*erl);
- EngineRenew *prev = NULL;
-
- while (er)
- {
- if (er->from == engine && er->group_id == group) {
- if (flags & DC_EXEC) {
- if (prev == NULL) { // First element
- /* The second becomes the new first element */
- *erl = (EngineRenewList)er->next;
- } else {
- /* Cut this element out */
- prev->next = er->next;
- }
- delete er;
- }
- return CommandCost();
- }
- prev = er;
- er = er->next;
- }
-
- return CMD_ERROR;
-}
-
-static const SaveLoad _engine_renew_desc[] = {
- SLE_VAR(EngineRenew, from, SLE_UINT16),
- SLE_VAR(EngineRenew, to, SLE_UINT16),
-
- SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
- SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),
- SLE_END()
-};
-
-static void Save_ERNW()
-{
- EngineRenew *er;
-
- FOR_ALL_ENGINE_RENEWS(er) {
- SlSetArrayIndex(er->index);
- SlObject(er, _engine_renew_desc);
- }
-}
-
-static void Load_ERNW()
-{
- int index;
-
- while ((index = SlIterateArray()) != -1) {
- EngineRenew *er = new (index) EngineRenew();
- SlObject(er, _engine_renew_desc);
-
- /* Advanced vehicle lists, ungrouped vehicles got added */
- if (CheckSavegameVersion(60)) {
- er->group_id = ALL_GROUP;
- } else if (CheckSavegameVersion(71)) {
- if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
- }
- }
-}
-
static const SaveLoad _engine_desc[] = {
SLE_CONDVAR(Engine, intro_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
SLE_CONDVAR(Engine, intro_date, SLE_INT32, 31, SL_MAX_VERSION),
@@ -805,13 +673,5 @@ static void Load_ENGS()
extern const ChunkHandler _engine_chunk_handlers[] = {
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY },
- { 'ENGS', NULL, Load_ENGS, CH_RIFF },
- { 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST},
+ { 'ENGS', NULL, Load_ENGS, CH_RIFF | CH_LAST },
};
-
-void InitializeEngines()
-{
- /* Clean the engine renew pool and create 1 block in it */
- _EngineRenew_pool.CleanPool();
- _EngineRenew_pool.AddBlockToPool();
-}
diff --git a/src/engine_type.h b/src/engine_type.h
index c9eb56a5e..5760d3ac6 100644
--- a/src/engine_type.h
+++ b/src/engine_type.h
@@ -15,7 +15,6 @@
#include "strings_type.h"
typedef uint16 EngineID;
-typedef uint16 EngineRenewID;
struct Engine;
diff --git a/src/misc.cpp b/src/misc.cpp
index 463b05707..6e2b5d976 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -39,7 +39,7 @@ extern TileIndex _cur_tileloop_tile;
void InitializeVehicles();
void InitializeWaypoints();
void InitializeDepots();
-void InitializeEngines();
+void InitializeEngineRenews();
void InitializeOrders();
void InitializeClearLand();
void InitializeRailGui();
@@ -76,7 +76,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date)
InitializeOldNames();
}
- InitializeEngines();
+ InitializeEngineRenews();
InitializeVehicles();
InitializeWaypoints();
InitializeDepots();
diff --git a/src/saveload.cpp b/src/saveload.cpp
index cee5257a3..b4bc4b919 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -1315,6 +1315,7 @@ extern const ChunkHandler _animated_tile_chunk_handlers[];
extern const ChunkHandler _newgrf_chunk_handlers[];
extern const ChunkHandler _group_chunk_handlers[];
extern const ChunkHandler _cargopacket_chunk_handlers[];
+extern const ChunkHandler _autoreplace_chunk_handlers[];
static const ChunkHandler * const _chunk_handlers[] = {
_gamelog_chunk_handlers,
@@ -1337,6 +1338,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_newgrf_chunk_handlers,
_group_chunk_handlers,
_cargopacket_chunk_handlers,
+ _autoreplace_chunk_handlers,
NULL,
};