(svn r4079) Add GetSation{Index,ByTile}() to get the station index resp. the station from a tile
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
				
			|||||||
#include "../../map.h"
 | 
					#include "../../map.h"
 | 
				
			||||||
#include "../../rail_map.h"
 | 
					#include "../../rail_map.h"
 | 
				
			||||||
#include "../../road_map.h"
 | 
					#include "../../road_map.h"
 | 
				
			||||||
 | 
					#include "../../station_map.h"
 | 
				
			||||||
#include "../../tile.h"
 | 
					#include "../../tile.h"
 | 
				
			||||||
#include "../../player.h"
 | 
					#include "../../player.h"
 | 
				
			||||||
#include "../../tunnel_map.h"
 | 
					#include "../../tunnel_map.h"
 | 
				
			||||||
@@ -2313,11 +2314,11 @@ static void AiStateBuildRail(Player *p)
 | 
				
			|||||||
	p->ai.banned_tile_count = 0;
 | 
						p->ai.banned_tile_count = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int AiGetStationIdByDef(TileIndex tile, int id)
 | 
					static StationID AiGetStationIdByDef(TileIndex tile, int id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const AiDefaultBlockData *p = _default_rail_track_data[id]->data;
 | 
						const AiDefaultBlockData *p = _default_rail_track_data[id]->data;
 | 
				
			||||||
	while (p->mode != 1) p++;
 | 
						while (p->mode != 1) p++;
 | 
				
			||||||
	return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2;
 | 
						return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void AiStateBuildRailVeh(Player *p)
 | 
					static void AiStateBuildRailVeh(Player *p)
 | 
				
			||||||
@@ -3096,11 +3097,11 @@ static void AiStateBuildRoad(Player *p)
 | 
				
			|||||||
	p->ai.banned_tile_count = 0;
 | 
						p->ai.banned_tile_count = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int AiGetStationIdFromRoadBlock(TileIndex tile, int id)
 | 
					static StationID AiGetStationIdFromRoadBlock(TileIndex tile, int id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const AiDefaultBlockData *p = _road_default_block_data[id]->data;
 | 
						const AiDefaultBlockData *p = _road_default_block_data[id]->data;
 | 
				
			||||||
	while (p->mode != 1) p++;
 | 
						while (p->mode != 1) p++;
 | 
				
			||||||
	return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2;
 | 
						return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void AiStateBuildRoadVehicles(Player *p)
 | 
					static void AiStateBuildRoadVehicles(Player *p)
 | 
				
			||||||
@@ -3406,11 +3407,11 @@ static void AiStateBuildDefaultAirportBlocks(Player *p)
 | 
				
			|||||||
	p->ai.state = AIS_BUILD_AIRCRAFT_VEHICLES;
 | 
						p->ai.state = AIS_BUILD_AIRCRAFT_VEHICLES;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int AiGetStationIdFromAircraftBlock(TileIndex tile, int id)
 | 
					static StationID AiGetStationIdFromAircraftBlock(TileIndex tile, int id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const AiDefaultBlockData *p = _airport_default_block_data[id];
 | 
						const AiDefaultBlockData *p = _airport_default_block_data[id];
 | 
				
			||||||
	while (p->mode != 1) p++;
 | 
						while (p->mode != 1) p++;
 | 
				
			||||||
	return _m[TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))].m2;
 | 
						return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void AiStateBuildAircraftVehicles(Player *p)
 | 
					static void AiStateBuildAircraftVehicles(Player *p)
 | 
				
			||||||
@@ -3431,7 +3432,7 @@ static void AiStateBuildAircraftVehicles(Player *p)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/* XXX - Have the AI pick the hangar terminal in an airport. Eg get airport-type
 | 
						/* XXX - Have the AI pick the hangar terminal in an airport. Eg get airport-type
 | 
				
			||||||
	 * and offset to the FIRST depot because the AI picks the st->xy tile */
 | 
						 * and offset to the FIRST depot because the AI picks the st->xy tile */
 | 
				
			||||||
	tile += ToTileIndexDiff(GetAirport(GetStation(_m[tile].m2)->airport_type)->airport_depots[0]);
 | 
						tile += ToTileIndexDiff(GetAirport(GetStationByTile(tile)->airport_type)->airport_depots[0]);
 | 
				
			||||||
	if (CmdFailed(DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) return;
 | 
						if (CmdFailed(DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_AIRCRAFT))) return;
 | 
				
			||||||
	loco_id = _new_aircraft_id;
 | 
						loco_id = _new_aircraft_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@
 | 
				
			|||||||
#include "../../debug.h"
 | 
					#include "../../debug.h"
 | 
				
			||||||
#include "../../functions.h"
 | 
					#include "../../functions.h"
 | 
				
			||||||
#include "../../road_map.h"
 | 
					#include "../../road_map.h"
 | 
				
			||||||
 | 
					#include "../../station_map.h"
 | 
				
			||||||
#include "../../table/strings.h"
 | 
					#include "../../table/strings.h"
 | 
				
			||||||
#include "../../map.h"
 | 
					#include "../../map.h"
 | 
				
			||||||
#include "../../tile.h"
 | 
					#include "../../tile.h"
 | 
				
			||||||
@@ -1202,7 +1203,7 @@ static void AiNew_State_GiveOrders(Player *p)
 | 
				
			|||||||
	idx = 0;
 | 
						idx = 0;
 | 
				
			||||||
	order.type = OT_GOTO_STATION;
 | 
						order.type = OT_GOTO_STATION;
 | 
				
			||||||
	order.flags = 0;
 | 
						order.flags = 0;
 | 
				
			||||||
	order.station = _m[p->ainew.to_tile].m2;
 | 
						order.station = GetStationIndex(p->ainew.to_tile);
 | 
				
			||||||
	if (p->ainew.tbt == AI_TRUCK && p->ainew.to_deliver)
 | 
						if (p->ainew.tbt == AI_TRUCK && p->ainew.to_deliver)
 | 
				
			||||||
		order.flags |= OF_FULL_LOAD;
 | 
							order.flags |= OF_FULL_LOAD;
 | 
				
			||||||
	AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 | 
						AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 | 
				
			||||||
@@ -1210,7 +1211,7 @@ static void AiNew_State_GiveOrders(Player *p)
 | 
				
			|||||||
	idx = 0;
 | 
						idx = 0;
 | 
				
			||||||
	order.type = OT_GOTO_STATION;
 | 
						order.type = OT_GOTO_STATION;
 | 
				
			||||||
	order.flags = 0;
 | 
						order.flags = 0;
 | 
				
			||||||
	order.station = _m[p->ainew.from_tile].m2;
 | 
						order.station = GetStationIndex(p->ainew.from_tile);
 | 
				
			||||||
	if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver)
 | 
						if (p->ainew.tbt == AI_TRUCK && p->ainew.from_deliver)
 | 
				
			||||||
		order.flags |= OF_FULL_LOAD;
 | 
							order.flags |= OF_FULL_LOAD;
 | 
				
			||||||
	AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 | 
						AI_DoCommand(0, p->ainew.veh_id + (idx << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
#include "openttd.h"
 | 
					#include "openttd.h"
 | 
				
			||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
@@ -239,7 +240,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
		 * layout for #th position of depot. Since layout must start with a listing
 | 
							 * layout for #th position of depot. Since layout must start with a listing
 | 
				
			||||||
		 * of all depots, it is simple */
 | 
							 * of all depots, it is simple */
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			const Station* st = GetStation(_m[tile].m2);
 | 
								const Station* st = GetStationByTile(tile);
 | 
				
			||||||
			const AirportFTAClass* apc = GetAirport(st->airport_type);
 | 
								const AirportFTAClass* apc = GetAirport(st->airport_type);
 | 
				
			||||||
			uint i;
 | 
								uint i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -256,7 +257,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		v->u.air.state = HANGAR;
 | 
							v->u.air.state = HANGAR;
 | 
				
			||||||
		v->u.air.previous_pos = v->u.air.pos;
 | 
							v->u.air.previous_pos = v->u.air.pos;
 | 
				
			||||||
		v->u.air.targetairport = _m[tile].m2;
 | 
							v->u.air.targetairport = GetStationIndex(tile);
 | 
				
			||||||
		v->next = u;
 | 
							v->next = u;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		v->service_interval = _patches.servint_aircraft;
 | 
							v->service_interval = _patches.servint_aircraft;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
#include "openttd.h"
 | 
					#include "openttd.h"
 | 
				
			||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/sprites.h"
 | 
					#include "table/sprites.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
@@ -650,7 +651,7 @@ static void DrawAircraftDepotWindow(Window *w)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
 | 
						SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SetDParam(0, _m[tile].m2);
 | 
						SetDParam(0, GetStationIndex(tile));
 | 
				
			||||||
	DrawWindowWidgets(w);
 | 
						DrawWindowWidgets(w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	x = 2;
 | 
						x = 2;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
#include "stdafx.h"
 | 
					#include "stdafx.h"
 | 
				
			||||||
#include "openttd.h"
 | 
					#include "openttd.h"
 | 
				
			||||||
#include "industry_map.h"
 | 
					#include "industry_map.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
@@ -183,7 +184,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
 | 
				
			|||||||
				v->current_order.station = 1;
 | 
									v->current_order.station = 1;
 | 
				
			||||||
				v->age = 0;
 | 
									v->age = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				SetDParam(0, _m[tile].m2);
 | 
									SetDParam(0, GetStationIndex(tile));
 | 
				
			||||||
				AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
 | 
									AddNewsItem(STR_B000_ZEPPELIN_DISASTER_AT,
 | 
				
			||||||
					NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
 | 
										NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
 | 
				
			||||||
					v->index,
 | 
										v->index,
 | 
				
			||||||
@@ -205,7 +206,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
 | 
				
			|||||||
				IsTileType(tile, MP_STATION) &&
 | 
									IsTileType(tile, MP_STATION) &&
 | 
				
			||||||
				IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 | 
									IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 | 
				
			||||||
				IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 | 
									IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 | 
				
			||||||
			st = GetStation(_m[tile].m2);
 | 
								st = GetStationByTile(tile);
 | 
				
			||||||
			CLRBITS(st->airport_flags, RUNWAY_IN_block);
 | 
								CLRBITS(st->airport_flags, RUNWAY_IN_block);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -247,7 +248,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
 | 
				
			|||||||
			IsTileType(tile, MP_STATION) &&
 | 
								IsTileType(tile, MP_STATION) &&
 | 
				
			||||||
			IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 | 
								IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
 | 
				
			||||||
			IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 | 
								IS_HUMAN_PLAYER(GetTileOwner(tile))) {
 | 
				
			||||||
		st = GetStation(_m[tile].m2);
 | 
							st = GetStationByTile(tile);
 | 
				
			||||||
		SETBITS(st->airport_flags, RUNWAY_IN_block);
 | 
							SETBITS(st->airport_flags, RUNWAY_IN_block);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								npf.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								npf.c
									
									
									
									
									
								
							@@ -10,6 +10,7 @@
 | 
				
			|||||||
#include "macros.h"
 | 
					#include "macros.h"
 | 
				
			||||||
#include "pathfind.h"
 | 
					#include "pathfind.h"
 | 
				
			||||||
#include "station.h"
 | 
					#include "station.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
#include "depot.h"
 | 
					#include "depot.h"
 | 
				
			||||||
#include "tunnel_map.h"
 | 
					#include "tunnel_map.h"
 | 
				
			||||||
@@ -423,7 +424,7 @@ static int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current)
 | 
				
			|||||||
	 * is correct */
 | 
						 * is correct */
 | 
				
			||||||
	if (
 | 
						if (
 | 
				
			||||||
		(fstd->station_index == INVALID_STATION && tile == fstd->dest_coords) || /* We've found the tile, or */
 | 
							(fstd->station_index == INVALID_STATION && tile == fstd->dest_coords) || /* We've found the tile, or */
 | 
				
			||||||
		(IsTileType(tile, MP_STATION) && _m[tile].m2 == fstd->station_index) /* the station */
 | 
							(IsTileType(tile, MP_STATION) && GetStationIndex(tile) == fstd->station_index) /* the station */
 | 
				
			||||||
	) {
 | 
						) {
 | 
				
			||||||
		return AYSTAR_FOUND_END_NODE;
 | 
							return AYSTAR_FOUND_END_NODE;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
#include "stdafx.h"
 | 
					#include "stdafx.h"
 | 
				
			||||||
#include "openttd.h"
 | 
					#include "openttd.h"
 | 
				
			||||||
#include "road_map.h"
 | 
					#include "road_map.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/sprites.h"
 | 
					#include "table/sprites.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
@@ -190,7 +191,6 @@ static void DrawOrdersWindow(Window *w)
 | 
				
			|||||||
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
 | 
					static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Order order;
 | 
						Order order;
 | 
				
			||||||
	int st_index;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// check depot first
 | 
						// check depot first
 | 
				
			||||||
	if (_patches.gotodepot) {
 | 
						if (_patches.gotodepot) {
 | 
				
			||||||
@@ -221,7 +221,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
 | 
				
			|||||||
			if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
 | 
								if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
 | 
				
			||||||
				order.type = OT_GOTO_DEPOT;
 | 
									order.type = OT_GOTO_DEPOT;
 | 
				
			||||||
				order.flags = OF_PART_OF_ORDERS;
 | 
									order.flags = OF_PART_OF_ORDERS;
 | 
				
			||||||
				order.station = _m[tile].m2;
 | 
									order.station = GetStationIndex(tile);
 | 
				
			||||||
				return order;
 | 
									return order;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
@@ -257,7 +257,8 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (IsTileType(tile, MP_STATION)) {
 | 
						if (IsTileType(tile, MP_STATION)) {
 | 
				
			||||||
		const Station* st = GetStation(st_index = _m[tile].m2);
 | 
							StationID st_index = GetStationIndex(tile);
 | 
				
			||||||
 | 
							const Station* st = GetStation(st_index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (st->owner == _current_player || st->owner == OWNER_NONE) {
 | 
							if (st->owner == _current_player || st->owner == OWNER_NONE) {
 | 
				
			||||||
			byte facil;
 | 
								byte facil;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@
 | 
				
			|||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
#include "road_map.h"
 | 
					#include "road_map.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
@@ -1415,7 +1416,7 @@ again:
 | 
				
			|||||||
	if (v->u.road.state >= 0x20 &&
 | 
						if (v->u.road.state >= 0x20 &&
 | 
				
			||||||
			_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) {
 | 
								_road_veh_data_1[v->u.road.state - 0x20 + (_opt.road_side<<4)] == v->u.road.frame) {
 | 
				
			||||||
		RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 | 
							RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
 | 
				
			||||||
		Station* st = GetStation(_m[v->tile].m2);
 | 
							Station* st = GetStationByTile(v->tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (v->current_order.type != OT_LEAVESTATION &&
 | 
							if (v->current_order.type != OT_LEAVESTATION &&
 | 
				
			||||||
				v->current_order.type != OT_GOTO_DEPOT) {
 | 
									v->current_order.type != OT_GOTO_DEPOT) {
 | 
				
			||||||
@@ -1423,7 +1424,7 @@ again:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			CLRBIT(rs->status, 7);
 | 
								CLRBIT(rs->status, 7);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			v->last_station_visited = _m[v->tile].m2;
 | 
								v->last_station_visited = GetStationIndex(v->tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			RoadVehArrivesAt(v, st);
 | 
								RoadVehArrivesAt(v, st);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@
 | 
				
			|||||||
#include "openttd.h"
 | 
					#include "openttd.h"
 | 
				
			||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/sprites.h"
 | 
					#include "table/sprites.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
@@ -110,7 +111,7 @@ RoadStop* GetPrimaryRoadStop(const Station* st, RoadStopType type)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
 | 
					RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const Station* st = GetStation(_m[tile].m2);
 | 
						const Station* st = GetStationByTile(tile);
 | 
				
			||||||
	RoadStop* rs;
 | 
						RoadStop* rs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) {
 | 
						for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) {
 | 
				
			||||||
@@ -184,7 +185,7 @@ static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest
 | 
				
			|||||||
	// check around to see if there's any stations there
 | 
						// check around to see if there's any stations there
 | 
				
			||||||
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 | 
						BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 | 
				
			||||||
		if (IsTileType(tile_cur, MP_STATION)) {
 | 
							if (IsTileType(tile_cur, MP_STATION)) {
 | 
				
			||||||
			StationID t = _m[tile_cur].m2;
 | 
								StationID t = GetStationIndex(tile_cur);
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Station *st = GetStation(t);
 | 
									Station *st = GetStation(t);
 | 
				
			||||||
				// you cannot take control of an oilrig!!
 | 
									// you cannot take control of an oilrig!!
 | 
				
			||||||
@@ -232,7 +233,7 @@ static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h)
 | 
				
			|||||||
	uint t;
 | 
						uint t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i != MapSize(); i++) {
 | 
						for (i = 0; i != MapSize(); i++) {
 | 
				
			||||||
		if (IsTileType(i, MP_STATION) && _m[i].m2 == station_index) {
 | 
							if (IsTileType(i, MP_STATION) && GetStationIndex(i) == station_index) {
 | 
				
			||||||
			t = TileX(i);
 | 
								t = TileX(i);
 | 
				
			||||||
			if (t < x1) x1 = t;
 | 
								if (t < x1) x1 = t;
 | 
				
			||||||
			if (t > x2) x2 = t;
 | 
								if (t > x2) x2 = t;
 | 
				
			||||||
@@ -797,7 +798,7 @@ int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invali
 | 
				
			|||||||
			if (_m[tile_cur].m5 >= 8) {
 | 
								if (_m[tile_cur].m5 >= 8) {
 | 
				
			||||||
				return ClearTile_Station(tile_cur, DC_AUTO); // get error message
 | 
									return ClearTile_Station(tile_cur, DC_AUTO); // get error message
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				StationID st = _m[tile_cur].m2;
 | 
									StationID st = GetStationIndex(tile_cur);
 | 
				
			||||||
				if (*station == INVALID_STATION) {
 | 
									if (*station == INVALID_STATION) {
 | 
				
			||||||
					*station = st;
 | 
										*station = st;
 | 
				
			||||||
				} else if (*station != st) {
 | 
									} else if (*station != st) {
 | 
				
			||||||
@@ -1069,7 +1070,7 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static bool TileBelongsToRailStation(const Station *st, TileIndex tile)
 | 
					static bool TileBelongsToRailStation(const Station *st, TileIndex tile)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return IsTileType(tile, MP_STATION) && _m[tile].m2 == st->index && _m[tile].m5 < 8;
 | 
						return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st->index && _m[tile].m5 < 8;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void MakeRailwayStationAreaSmaller(Station *st)
 | 
					static void MakeRailwayStationAreaSmaller(Station *st)
 | 
				
			||||||
@@ -1144,7 +1145,7 @@ int32 CmdRemoveFromRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// make sure the specified tile belongs to the current player, and that it is a railroad station.
 | 
						// make sure the specified tile belongs to the current player, and that it is a railroad station.
 | 
				
			||||||
	if (!IsTileType(tile, MP_STATION) || _m[tile].m5 >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
 | 
						if (!IsTileType(tile, MP_STATION) || _m[tile].m5 >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
 | 
				
			||||||
	st = GetStation(_m[tile].m2);
 | 
						st = GetStationByTile(tile);
 | 
				
			||||||
	if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR;
 | 
						if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// if we reached here, it means we can actually delete it. do that.
 | 
						// if we reached here, it means we can actually delete it. do that.
 | 
				
			||||||
@@ -1252,7 +1253,8 @@ static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
 | 
					int32 DoConvertStationRail(TileIndex tile, uint totype, bool exec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const Station *st = GetStation(_m[tile].m2);
 | 
						const Station* st = GetStationByTile(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 | 
						if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// tile is not a railroad station?
 | 
						// tile is not a railroad station?
 | 
				
			||||||
@@ -1971,7 +1973,7 @@ static void DrawTile_Station(TileInfo *ti)
 | 
				
			|||||||
		//debug("Cust-o-mized %p", statspec);
 | 
							//debug("Cust-o-mized %p", statspec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (statspec != NULL) {
 | 
							if (statspec != NULL) {
 | 
				
			||||||
			const Station* st = GetStation(_m[ti->tile].m2);
 | 
								const Station* st = GetStationByTile(ti->tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			relocation = GetCustomStationRelocation(statspec, st, 0);
 | 
								relocation = GetCustomStationRelocation(statspec, st, 0);
 | 
				
			||||||
			//debug("Relocation %d", relocation);
 | 
								//debug("Relocation %d", relocation);
 | 
				
			||||||
@@ -2051,7 +2053,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
 | 
				
			|||||||
	StringID str;
 | 
						StringID str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	td->owner = GetTileOwner(tile);
 | 
						td->owner = GetTileOwner(tile);
 | 
				
			||||||
	td->build_date = GetStation(_m[tile].m2)->build_date;
 | 
						td->build_date = GetStationByTile(tile)->build_date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m5 = _m[tile].m5;
 | 
						m5 = _m[tile].m5;
 | 
				
			||||||
	(str=STR_305E_RAILROAD_STATION, m5 < 8) ||
 | 
						(str=STR_305E_RAILROAD_STATION, m5 < 8) ||
 | 
				
			||||||
@@ -2166,7 +2168,7 @@ static void ClickTile_Station(TileIndex tile)
 | 
				
			|||||||
	if (_m[tile].m5 == 32 || _m[tile].m5 == 65) {
 | 
						if (_m[tile].m5 == 32 || _m[tile].m5 == 65) {
 | 
				
			||||||
		ShowAircraftDepotWindow(tile);
 | 
							ShowAircraftDepotWindow(tile);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		ShowStationViewWindow(_m[tile].m2);
 | 
							ShowStationViewWindow(GetStationIndex(tile));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2179,7 +2181,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
 | 
				
			|||||||
	if (v->type == VEH_Train) {
 | 
						if (v->type == VEH_Train) {
 | 
				
			||||||
		if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) &&
 | 
							if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) &&
 | 
				
			||||||
				!IsCompatibleTrainStationTile(tile + TileOffsByDir(DirToDiagDir(v->direction)), tile)) {
 | 
									!IsCompatibleTrainStationTile(tile + TileOffsByDir(DirToDiagDir(v->direction)), tile)) {
 | 
				
			||||||
			StationID station_id = _m[tile].m2;
 | 
								StationID station_id = GetStationIndex(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
 | 
								if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
 | 
				
			||||||
					(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
 | 
										(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
 | 
				
			||||||
@@ -2563,7 +2565,7 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount)
 | 
				
			|||||||
		cur_tile = TILE_MASK(cur_tile);
 | 
							cur_tile = TILE_MASK(cur_tile);
 | 
				
			||||||
		if (!IsTileType(cur_tile, MP_STATION)) continue;
 | 
							if (!IsTileType(cur_tile, MP_STATION)) continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		st = GetStation(_m[cur_tile].m2);
 | 
							st = GetStationByTile(cur_tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (i = 0; i != lengthof(around); i++) {
 | 
							for (i = 0; i != lengthof(around); i++) {
 | 
				
			||||||
			if (around[i] == NULL) {
 | 
								if (around[i] == NULL) {
 | 
				
			||||||
@@ -2721,7 +2723,7 @@ void BuildOilRig(TileIndex tile)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void DeleteOilRig(TileIndex tile)
 | 
					void DeleteOilRig(TileIndex tile)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Station *st = GetStation(_m[tile].m2);
 | 
						Station* st = GetStationByTile(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DoClearSquare(tile);
 | 
						DoClearSquare(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2738,7 +2740,8 @@ static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerI
 | 
				
			|||||||
	if (!IsTileOwner(tile, old_player)) return;
 | 
						if (!IsTileOwner(tile, old_player)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (new_player != OWNER_SPECTATOR) {
 | 
						if (new_player != OWNER_SPECTATOR) {
 | 
				
			||||||
		Station *st = GetStation(_m[tile].m2);
 | 
							Station* st = GetStationByTile(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		SetTileOwner(tile, new_player);
 | 
							SetTileOwner(tile, new_player);
 | 
				
			||||||
		st->owner = new_player;
 | 
							st->owner = new_player;
 | 
				
			||||||
		_global_station_sort_dirty = true; // transfer ownership of station to another player
 | 
							_global_station_sort_dirty = true; // transfer ownership of station to another player
 | 
				
			||||||
@@ -2764,7 +2767,7 @@ static int32 ClearTile_Station(TileIndex tile, byte flags)
 | 
				
			|||||||
		return_cmd_error(STR_4800_IN_THE_WAY);
 | 
							return_cmd_error(STR_4800_IN_THE_WAY);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	st = GetStation(_m[tile].m2);
 | 
						st = GetStationByTile(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (m5 < 8) return RemoveRailroadStation(st, tile, flags);
 | 
						if (m5 < 8) return RemoveRailroadStation(st, tile, flags);
 | 
				
			||||||
	// original airports < 67, new airports between 83 - 114
 | 
						// original airports < 67, new airports between 83 - 114
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								station_map.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								station_map.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					/* $Id$ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "station.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline StationID GetStationIndex(TileIndex t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return (StationID)_m[t].m2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline Station* GetStationByTile(TileIndex t)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return GetStation(GetStationIndex(t));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										23
									
								
								train_cmd.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								train_cmd.c
									
									
									
									
									
								
							@@ -6,6 +6,7 @@
 | 
				
			|||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
#include "functions.h"
 | 
					#include "functions.h"
 | 
				
			||||||
#include "gui.h"
 | 
					#include "gui.h"
 | 
				
			||||||
 | 
					#include "station_map.h"
 | 
				
			||||||
#include "table/strings.h"
 | 
					#include "table/strings.h"
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
#include "tile.h"
 | 
					#include "tile.h"
 | 
				
			||||||
@@ -196,21 +197,20 @@ enum AccelType {
 | 
				
			|||||||
static bool TrainShouldStop(const Vehicle* v, TileIndex tile)
 | 
					static bool TrainShouldStop(const Vehicle* v, TileIndex tile)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const Order* o = &v->current_order;
 | 
						const Order* o = &v->current_order;
 | 
				
			||||||
 | 
						StationID sid = GetStationIndex(tile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assert(v->type == VEH_Train);
 | 
						assert(v->type == VEH_Train);
 | 
				
			||||||
	assert(IsTileType(v->tile, MP_STATION));
 | 
					 | 
				
			||||||
	//When does a train drive through a station
 | 
						//When does a train drive through a station
 | 
				
			||||||
	//first we deal with the "new nonstop handling"
 | 
						//first we deal with the "new nonstop handling"
 | 
				
			||||||
	if (_patches.new_nonstop && o->flags & OF_NON_STOP &&
 | 
						if (_patches.new_nonstop && o->flags & OF_NON_STOP && sid == o->station) {
 | 
				
			||||||
			_m[tile].m2 == o->station )
 | 
					 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (v->last_station_visited == _m[tile].m2)
 | 
						if (v->last_station_visited == sid) return false;
 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_m[tile].m2 != o->station &&
 | 
						if (sid != o->station && (o->flags & OF_NON_STOP || _patches.new_nonstop)) {
 | 
				
			||||||
			(o->flags & OF_NON_STOP || _patches.new_nonstop))
 | 
					 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -2027,8 +2027,11 @@ static bool NtpCallbFindStation(TileIndex tile, TrainTrackFollowerData *ttfd, in
 | 
				
			|||||||
	if (ttfd->dest_coords == 0) return false;
 | 
						if (ttfd->dest_coords == 0) return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// did we reach the final station?
 | 
						// did we reach the final station?
 | 
				
			||||||
	if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) ||
 | 
						if ((ttfd->station_index == INVALID_STATION && tile == ttfd->dest_coords) || (
 | 
				
			||||||
			(IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && _m[tile].m2 == ttfd->station_index)) {
 | 
									IsTileType(tile, MP_STATION) &&
 | 
				
			||||||
 | 
									IS_BYTE_INSIDE(_m[tile].m5, 0, 8) &&
 | 
				
			||||||
 | 
									GetStationIndex(tile) == ttfd->station_index
 | 
				
			||||||
 | 
								)) {
 | 
				
			||||||
		/* We do not check for dest_coords if we have a station_index,
 | 
							/* We do not check for dest_coords if we have a station_index,
 | 
				
			||||||
		 * because in that case the dest_coords are just an
 | 
							 * because in that case the dest_coords are just an
 | 
				
			||||||
		 * approximation of where the station is */
 | 
							 * approximation of where the station is */
 | 
				
			||||||
@@ -2301,7 +2304,7 @@ static bool ProcessTrainOrder(Vehicle *v)
 | 
				
			|||||||
	if (_patches.new_nonstop &&
 | 
						if (_patches.new_nonstop &&
 | 
				
			||||||
			v->current_order.flags & OF_NON_STOP &&
 | 
								v->current_order.flags & OF_NON_STOP &&
 | 
				
			||||||
			IsTileType(v->tile, MP_STATION) &&
 | 
								IsTileType(v->tile, MP_STATION) &&
 | 
				
			||||||
			v->current_order.station == _m[v->tile].m2) {
 | 
								v->current_order.station == GetStationIndex(v->tile)) {
 | 
				
			||||||
		v->cur_order_index++;
 | 
							v->cur_order_index++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user