From 50ff85428b1ca4c5c84753d49919a1e3317a88e2 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Fri, 3 Feb 2006 15:51:00 +0000 Subject: (svn r3525) - Rename station_newgrf.[ch] to newgrf_station.[ch], and update project files. --- Makefile | 2 +- newgrf_station.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ newgrf_station.h | 77 +++++++++++++++++++++++++++++++++++++ openttd.dsp | 16 ++++---- openttd.vcproj | 12 +++--- station.h | 2 +- station_newgrf.c | 115 ------------------------------------------------------- station_newgrf.h | 77 ------------------------------------- 8 files changed, 208 insertions(+), 208 deletions(-) create mode 100644 newgrf_station.c create mode 100644 newgrf_station.h delete mode 100644 station_newgrf.c delete mode 100644 station_newgrf.h diff --git a/Makefile b/Makefile index 016258796..827363e55 100644 --- a/Makefile +++ b/Makefile @@ -654,6 +654,7 @@ SRCS += network_server.c SRCS += network_udp.c SRCS += newgrf.c SRCS += newgrf_engine.c +SRCS += newgrf_station.c SRCS += news_gui.c SRCS += npf.c SRCS += oldloader.c @@ -686,7 +687,6 @@ SRCS += sprite.c SRCS += spritecache.c SRCS += station_cmd.c SRCS += station_gui.c -SRCS += station_newgrf.c SRCS += string.c SRCS += strings.c SRCS += subsidy_gui.c diff --git a/newgrf_station.c b/newgrf_station.c new file mode 100644 index 000000000..81ce3249a --- /dev/null +++ b/newgrf_station.c @@ -0,0 +1,115 @@ +/* $Id$ */ + +/** @file newgrf_station.c Functions for dealing with station classes and custom stations. */ + +#include "stdafx.h" +#include "openttd.h" +#include "debug.h" +#include "sprite.h" +#include "newgrf_station.h" + +static StationClass station_classes[STAT_CLASS_MAX]; + +/** + * Reset station classes to their default state. + * This includes initialising the Default and Waypoint classes with an empty + * entry, for standard stations and waypoints. + */ +void ResetStationClasses(void) +{ + StationClassID i; + for (i = 0; i < STAT_CLASS_MAX; i++) { + station_classes[i].id = 0; + + free(station_classes[i].name); + station_classes[i].name = NULL; + + station_classes[i].stations = 0; + + free(station_classes[i].spec); + station_classes[i].spec = NULL; + } + + // Set up initial data + station_classes[0].id = 'DFLT'; + station_classes[0].name = strdup("Default"); + station_classes[0].stations = 1; + station_classes[0].spec = malloc(sizeof(*station_classes[0].spec)); + station_classes[0].spec[0] = NULL; + + station_classes[1].id = 'WAYP'; + station_classes[1].name = strdup("Waypoints"); + station_classes[1].stations = 1; + station_classes[1].spec = malloc(sizeof(*station_classes[1].spec)); + station_classes[1].spec[0] = NULL; +} + +/** + * Allocate a station class for the given class id. + * @param classid A 32 bit value identifying the class. + * @return Index into station_classes of allocated class. + */ +StationClassID AllocateStationClass(uint32 class) +{ + StationClassID i; + + for (i = 0; i < STAT_CLASS_MAX; i++) { + if (station_classes[i].id == class) { + // ClassID is already allocated, so reuse it. + return i; + } else if (station_classes[i].id == 0) { + // This class is empty, so allocate it to the ClassID. + station_classes[i].id = class; + return i; + } + } + + DEBUG(grf, 2)("StationClassAllocate: Already allocated %d classes, using default.", STAT_CLASS_MAX); + return STAT_CLASS_DFLT; +} + +/** + * Return the number of stations for the given station class. + * @param sclass Index of the station class. + * @return Number of stations in the class. + */ +uint GetNumCustomStations(StationClassID sclass) +{ + assert(sclass < STAT_CLASS_MAX); + return station_classes[sclass].stations; +} + +/** + * Tie a station spec to its station class. + * @param spec The station spec. + */ +void SetCustomStation(StationSpec *spec) +{ + StationClass *station_class; + int i; + + assert(spec->sclass < STAT_CLASS_MAX); + station_class = &station_classes[spec->sclass]; + + i = station_class->stations++; + station_class->spec = realloc(station_class->spec, station_class->stations * sizeof(*station_class->spec)); + + station_class->spec[i] = spec; +} + +/** + * Retrieve a station spec from a class. + * @param sclass Index of the station class. + * @param station The station index with the class. + * @return The station spec. + */ +const StationSpec *GetCustomStation(StationClassID sclass, uint station) +{ + assert(sclass < STAT_CLASS_MAX); + if (station < station_classes[sclass].stations) + return station_classes[sclass].spec[station]; + + // If the custom station isn't defined any more, then the GRF file + // probably was not loaded. + return NULL; +} diff --git a/newgrf_station.h b/newgrf_station.h new file mode 100644 index 000000000..60033de77 --- /dev/null +++ b/newgrf_station.h @@ -0,0 +1,77 @@ +/* $Id$ */ + +/** @file newgrf_station.h Header file for NewGRF stations */ + +#ifndef NEWGRF_STATION_H +#define NEWGRF_STATION_H + +#include "engine.h" + +typedef enum { + STAT_CLASS_DFLT, ///< Default station class. + STAT_CLASS_WAYP, ///< Waypoint class. + STAT_CLASS_MAX = 16, ///< Maximum number of classes. +} StationClassID; + +/* Station layout for given dimensions - it is a two-dimensional array + * where index is computed as (x * platforms) + platform. */ +typedef byte *StationLayout; + +typedef struct stationspec { + uint32 grfid; ///< ID of GRF file station belongs to. + int localidx; ///< Index within GRF file of station. + + StationClassID sclass; ///< The class to which this spec belongs. + + /** + * Bitmask of number of platforms available for the station. + * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 platforms. + */ + byte allowed_platforms; + /** + * Bitmask of platform lengths available for the station. + * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 tiles long. + */ + byte allowed_lengths; + + /** Number of tile layouts. + * A minimum of 8 is required is required for stations. + * 0-1 = plain platform + * 2-3 = platform with building + * 4-5 = platform with roof, left side + * 6-7 = platform with roof, right side + */ + int tiles; + DrawTileSprites *renderdata; ///< Array of tile layouts. + + byte lengths; + byte *platforms; + StationLayout **layouts; + + /** + * NUM_GLOBAL_CID sprite groups. + * Used for obtaining the sprite offset of custom sprites, and for + * evaluating callbacks. + */ + SpriteGroup *spritegroup[NUM_GLOBAL_CID]; +} StationSpec; + +/** + * Struct containing information relating to station classes. + */ +typedef struct stationclass { + uint32 id; ///< ID of this class, e.g. 'DFLT', 'WAYP', etc. + char *name; ///< Name of this class. + uint stations; ///< Number of stations in this class. + StationSpec **spec; ///< Array of station specifications. +} StationClass; + +void ResetStationClasses(void); +StationClassID AllocateStationClass(uint32 class); +void SetStationClassName(StationClassID sclass, const char *name); +uint GetNumCustomStations(StationClassID sclass); + +void SetCustomStation(StationSpec *spec); +const StationSpec *GetCustomStation(StationClassID sclass, uint station); + +#endif /* NEWGRF_STATION_H */ diff --git a/openttd.dsp b/openttd.dsp index 4c0f9aebe..f9d4f677d 100644 --- a/openttd.dsp +++ b/openttd.dsp @@ -280,6 +280,10 @@ SOURCE=.\newgrf_engine.c # End Source File # Begin Source File +SOURCE=.\newgrf_station.c +# End Source File +# Begin Source File + SOURCE=.\npf.c # End Source File # Begin Source File @@ -413,10 +417,6 @@ SOURCE=.\spritecache.c # End Source File # Begin Source File -SOURCE=.\station_newgrf.c -# End Source File -# Begin Source File - SOURCE=.\StdAfx.c !IF "$(CFG)" == "openttd - Win32 Release" @@ -630,6 +630,10 @@ SOURCE=.\newgrf_engine.h # End Source File # Begin Source File +SOURCE=.\newgrf_station.h +# End Source File +# Begin Source File + SOURCE=.\news.h # End Source File # Begin Source File @@ -698,10 +702,6 @@ SOURCE=.\station.h # End Source File # Begin Source File -SOURCE=.\station_newgrf.h -# End Source File -# Begin Source File - SOURCE=.\StdAfx.h # End Source File # Begin Source File diff --git a/openttd.vcproj b/openttd.vcproj index 35fffbd73..133a050b8 100644 --- a/openttd.vcproj +++ b/openttd.vcproj @@ -275,6 +275,9 @@ + + @@ -341,9 +344,6 @@ - - @@ -492,6 +492,9 @@ + + @@ -552,9 +555,6 @@ - - diff --git a/station.h b/station.h index 0f2393913..669ee3cd7 100644 --- a/station.h +++ b/station.h @@ -8,7 +8,7 @@ #include "sprite.h" #include "tile.h" #include "vehicle.h" -#include "station_newgrf.h" +#include "newgrf_station.h" typedef struct GoodsEntry { uint16 waiting_acceptance; diff --git a/station_newgrf.c b/station_newgrf.c deleted file mode 100644 index 1150a2376..000000000 --- a/station_newgrf.c +++ /dev/null @@ -1,115 +0,0 @@ -/* $Id$ */ - -/** @file station_newgrf.c Functions for dealing with station classes and custom stations. */ - -#include "stdafx.h" -#include "openttd.h" -#include "debug.h" -#include "sprite.h" -#include "station_newgrf.h" - -static StationClass station_classes[STAT_CLASS_MAX]; - -/** - * Reset station classes to their default state. - * This includes initialising the Default and Waypoint classes with an empty - * entry, for standard stations and waypoints. - */ -void ResetStationClasses(void) -{ - StationClassID i; - for (i = 0; i < STAT_CLASS_MAX; i++) { - station_classes[i].id = 0; - - free(station_classes[i].name); - station_classes[i].name = NULL; - - station_classes[i].stations = 0; - - free(station_classes[i].spec); - station_classes[i].spec = NULL; - } - - // Set up initial data - station_classes[0].id = 'DFLT'; - station_classes[0].name = strdup("Default"); - station_classes[0].stations = 1; - station_classes[0].spec = malloc(sizeof(*station_classes[0].spec)); - station_classes[0].spec[0] = NULL; - - station_classes[1].id = 'WAYP'; - station_classes[1].name = strdup("Waypoints"); - station_classes[1].stations = 1; - station_classes[1].spec = malloc(sizeof(*station_classes[1].spec)); - station_classes[1].spec[0] = NULL; -} - -/** - * Allocate a station class for the given class id. - * @param classid A 32 bit value identifying the class. - * @return Index into station_classes of allocated class. - */ -StationClassID AllocateStationClass(uint32 class) -{ - StationClassID i; - - for (i = 0; i < STAT_CLASS_MAX; i++) { - if (station_classes[i].id == class) { - // ClassID is already allocated, so reuse it. - return i; - } else if (station_classes[i].id == 0) { - // This class is empty, so allocate it to the ClassID. - station_classes[i].id = class; - return i; - } - } - - DEBUG(grf, 2)("StationClassAllocate: Already allocated %d classes, using default.", STAT_CLASS_MAX); - return STAT_CLASS_DFLT; -} - -/** - * Return the number of stations for the given station class. - * @param sclass Index of the station class. - * @return Number of stations in the class. - */ -uint GetNumCustomStations(StationClassID sclass) -{ - assert(sclass < STAT_CLASS_MAX); - return station_classes[sclass].stations; -} - -/** - * Tie a station spec to its station class. - * @param spec The station spec. - */ -void SetCustomStation(StationSpec *spec) -{ - StationClass *station_class; - int i; - - assert(spec->sclass < STAT_CLASS_MAX); - station_class = &station_classes[spec->sclass]; - - i = station_class->stations++; - station_class->spec = realloc(station_class->spec, station_class->stations * sizeof(*station_class->spec)); - - station_class->spec[i] = spec; -} - -/** - * Retrieve a station spec from a class. - * @param sclass Index of the station class. - * @param station The station index with the class. - * @return The station spec. - */ -const StationSpec *GetCustomStation(StationClassID sclass, uint station) -{ - assert(sclass < STAT_CLASS_MAX); - if (station < station_classes[sclass].stations) - return station_classes[sclass].spec[station]; - - // If the custom station isn't defined any more, then the GRF file - // probably was not loaded. - return NULL; -} diff --git a/station_newgrf.h b/station_newgrf.h deleted file mode 100644 index b4bca4b46..000000000 --- a/station_newgrf.h +++ /dev/null @@ -1,77 +0,0 @@ -/* $Id$ */ - -/** @file station_newgrf.h Header file for NewGRF stations */ - -#ifndef STATION_NEWGRF_H -#define STATION_NEWGRF_H - -#include "engine.h" - -typedef enum { - STAT_CLASS_DFLT, ///< Default station class. - STAT_CLASS_WAYP, ///< Waypoint class. - STAT_CLASS_MAX = 16, ///< Maximum number of classes. -} StationClassID; - -/* Station layout for given dimensions - it is a two-dimensional array - * where index is computed as (x * platforms) + platform. */ -typedef byte *StationLayout; - -typedef struct stationspec { - uint32 grfid; ///< ID of GRF file station belongs to. - int localidx; ///< Index within GRF file of station. - - StationClassID sclass; ///< The class to which this spec belongs. - - /** - * Bitmask of number of platforms available for the station. - * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 platforms. - */ - byte allowed_platforms; - /** - * Bitmask of platform lengths available for the station. - * 0..6 correpsond to 1..7, while bit 7 corresponds to >7 tiles long. - */ - byte allowed_lengths; - - /** Number of tile layouts. - * A minimum of 8 is required is required for stations. - * 0-1 = plain platform - * 2-3 = platform with building - * 4-5 = platform with roof, left side - * 6-7 = platform with roof, right side - */ - int tiles; - DrawTileSprites *renderdata; ///< Array of tile layouts. - - byte lengths; - byte *platforms; - StationLayout **layouts; - - /** - * NUM_GLOBAL_CID sprite groups. - * Used for obtaining the sprite offset of custom sprites, and for - * evaluating callbacks. - */ - SpriteGroup *spritegroup[NUM_GLOBAL_CID]; -} StationSpec; - -/** - * Struct containing information relating to station classes. - */ -typedef struct stationclass { - uint32 id; ///< ID of this class, e.g. 'DFLT', 'WAYP', etc. - char *name; ///< Name of this class. - uint stations; ///< Number of stations in this class. - StationSpec **spec; ///< Array of station specifications. -} StationClass; - -void ResetStationClasses(void); -StationClassID AllocateStationClass(uint32 class); -void SetStationClassName(StationClassID sclass, const char *name); -uint GetNumCustomStations(StationClassID sclass); - -void SetCustomStation(StationSpec *spec); -const StationSpec *GetCustomStation(StationClassID sclass, uint station); - -#endif /* STATION_NEWGRF_H */ -- cgit v1.2.3-70-g09d2