src/newgrf_station.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
--- a/src/newgrf_station.cpp	Mon Dec 03 23:39:38 2007 +0000
+++ b/src/newgrf_station.cpp	Tue Jan 22 21:00:30 2008 +0000
@@ -5,12 +5,10 @@
 #include "stdafx.h"
 #include "openttd.h"
 #include "variables.h"
-#include "functions.h"
+#include "tile_cmd.h"
 #include "landscape.h"
 #include "debug.h"
 #include "sprite.h"
-#include "table/sprites.h"
-#include "table/strings.h"
 #include "station.h"
 #include "station_map.h"
 #include "newgrf.h"
@@ -18,13 +16,17 @@
 #include "newgrf_commons.h"
 #include "newgrf_station.h"
 #include "newgrf_spritegroup.h"
-#include "date.h"
-#include "helpers.hpp"
 #include "cargotype.h"
 #include "town_map.h"
 #include "newgrf_town.h"
+#include "gfx_func.h"
+#include "date_func.h"
+#include "player_func.h"
 
-static StationClass station_classes[STAT_CLASS_MAX];
+#include "table/sprites.h"
+#include "table/strings.h"
+
+static StationClass _station_classes[STAT_CLASS_MAX];
 
 enum {
 	MAX_SPECLIST = 255,
@@ -38,42 +40,42 @@
 void ResetStationClasses()
 {
 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
-		station_classes[i].id = 0;
-		station_classes[i].name = STR_EMPTY;
-		station_classes[i].stations = 0;
+		_station_classes[i].id = 0;
+		_station_classes[i].name = STR_EMPTY;
+		_station_classes[i].stations = 0;
 
-		free(station_classes[i].spec);
-		station_classes[i].spec = NULL;
+		free(_station_classes[i].spec);
+		_station_classes[i].spec = NULL;
 	}
 
 	/* Set up initial data */
-	station_classes[0].id = 'DFLT';
-	station_classes[0].name = STR_STAT_CLASS_DFLT;
-	station_classes[0].stations = 1;
-	station_classes[0].spec = MallocT<StationSpec*>(1);
-	station_classes[0].spec[0] = NULL;
+	_station_classes[0].id = 'DFLT';
+	_station_classes[0].name = STR_STAT_CLASS_DFLT;
+	_station_classes[0].stations = 1;
+	_station_classes[0].spec = MallocT<StationSpec*>(1);
+	_station_classes[0].spec[0] = NULL;
 
-	station_classes[1].id = 'WAYP';
-	station_classes[1].name = STR_STAT_CLASS_WAYP;
-	station_classes[1].stations = 1;
-	station_classes[1].spec = MallocT<StationSpec*>(1);
-	station_classes[1].spec[0] = NULL;
+	_station_classes[1].id = 'WAYP';
+	_station_classes[1].name = STR_STAT_CLASS_WAYP;
+	_station_classes[1].stations = 1;
+	_station_classes[1].spec = MallocT<StationSpec*>(1);
+	_station_classes[1].spec[0] = NULL;
 }
 
 /**
  * Allocate a station class for the given class id.
  * @param cls A 32 bit value identifying the class.
- * @return Index into station_classes of allocated class.
+ * @return Index into _station_classes of allocated class.
  */
 StationClassID AllocateStationClass(uint32 cls)
 {
 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
-		if (station_classes[i].id == cls) {
+		if (_station_classes[i].id == cls) {
 			/* ClassID is already allocated, so reuse it. */
 			return i;
-		} else if (station_classes[i].id == 0) {
+		} else if (_station_classes[i].id == 0) {
 			/* This class is empty, so allocate it to the ClassID. */
-			station_classes[i].id = cls;
+			_station_classes[i].id = cls;
 			return i;
 		}
 	}
@@ -86,33 +88,14 @@
 void SetStationClassName(StationClassID sclass, StringID name)
 {
 	assert(sclass < STAT_CLASS_MAX);
-	station_classes[sclass].name = name;
+	_station_classes[sclass].name = name;
 }
 
 /** Retrieve the name of a custom station class */
 StringID GetStationClassName(StationClassID sclass)
 {
 	assert(sclass < STAT_CLASS_MAX);
-	return station_classes[sclass].name;
-}
-
-/** Build a list of station class name StringIDs to use in a dropdown list
- * @return Pointer to a (static) array of StringIDs
- */
-StringID *BuildStationClassDropdown()
-{
-	/* Allow room for all station classes, plus a terminator entry */
-	static StringID names[STAT_CLASS_MAX + 1];
-	uint i;
-
-	/* Add each name */
-	for (i = 0; i < STAT_CLASS_MAX && station_classes[i].id != 0; i++) {
-		names[i] = station_classes[i].name;
-	}
-	/* Terminate the list */
-	names[i] = INVALID_STRING_ID;
-
-	return names;
+	return _station_classes[sclass].name;
 }
 
 /**
@@ -122,7 +105,7 @@
 uint GetNumStationClasses()
 {
 	uint i;
-	for (i = 0; i < STAT_CLASS_MAX && station_classes[i].id != 0; i++);
+	for (i = 0; i < STAT_CLASS_MAX && _station_classes[i].id != 0; i++);
 	return i;
 }
 
@@ -134,7 +117,7 @@
 uint GetNumCustomStations(StationClassID sclass)
 {
 	assert(sclass < STAT_CLASS_MAX);
-	return station_classes[sclass].stations;
+	return _station_classes[sclass].stations;
 }
 
 /**
@@ -150,7 +133,7 @@
 	if (statspec->allocated) return;
 
 	assert(statspec->sclass < STAT_CLASS_MAX);
-	station_class = &station_classes[statspec->sclass];
+	station_class = &_station_classes[statspec->sclass];
 
 	i = station_class->stations++;
 	station_class->spec = ReallocT(station_class->spec, station_class->stations);
@@ -168,8 +151,8 @@
 const StationSpec *GetCustomStationSpec(StationClassID sclass, uint station)
 {
 	assert(sclass < STAT_CLASS_MAX);
-	if (station < station_classes[sclass].stations)
-		return station_classes[sclass].spec[station];
+	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. */
@@ -182,8 +165,8 @@
 	uint j;
 
 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
-		for (j = 0; j < station_classes[i].stations; j++) {
-			const StationSpec *statspec = station_classes[i].spec[j];
+		for (j = 0; j < _station_classes[i].stations; j++) {
+			const StationSpec *statspec = _station_classes[i].spec[j];
 			if (statspec == NULL) continue;
 			if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) return statspec;
 		}
@@ -439,6 +422,34 @@
 
 		/* Variables which use the parameter */
 		/* Variables 0x60 to 0x65 are handled separately below */
+		case 0x67: { // Land info of nearby tiles
+			Axis axis = GetRailStationAxis(tile);
+
+			if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
+			byte tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1;
+
+			uint z;
+			Slope tileh = GetTileSlope(tile, &z);
+			bool swap = (axis == AXIS_Y && HasBit(tileh, 0) != HasBit(tileh, 2));
+			return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | (tileh ^ (swap ? 5 : 0));
+		}
+
+		case 0x68: { // Station info of nearby tiles
+			TileIndex nearby_tile = GetNearbyTile(parameter, tile);
+
+			if (!IsRailwayStationTile(nearby_tile)) return 0xFFFFFFFF;
+
+			uint32 grfid = st->speclist[GetCustomStationSpecIndex(tile)].grfid;
+			bool perpendicular = GetRailStationAxis(tile) != GetRailStationAxis(nearby_tile);
+			bool same_station = st->TileBelongsToRailStation(nearby_tile);
+			uint32 res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10;
+
+			if (IsCustomStationSpecIndex(nearby_tile)) {
+				const StationSpecList ssl = GetStationByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
+				res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx;
+			}
+			return res;
+		}
 
 		/* General station properties */
 		case 0x82: return 50;