(svn r4120) Use the new station functions where appropriate

This commit is contained in:
tron 2006-03-26 19:20:15 +00:00
parent 8f60df1817
commit cda8934a55
12 changed files with 38 additions and 55 deletions

View File

@ -359,7 +359,7 @@ static void AiHandleReplaceAircraft(Player *p)
BackuppedOrders orderbak[1];
EngineID veh;
if (!IsAircraftHangarTile(v->tile) || !(v->vehstatus&VS_STOPPED)) {
if (!IsHangarTile(v->tile) || !(v->vehstatus & VS_STOPPED)) {
AiHandleGotoDepot(p, CMD_SEND_AIRCRAFT_TO_HANGAR);
return;
}
@ -3176,15 +3176,6 @@ static void AiStateDeleteRoadBlocks(Player *p)
p->ai.state = AIS_0;
}
static bool AiCheckIfHangar(Station *st)
{
TileIndex tile = st->airport_tile;
// HANGAR of airports
// 0x20 - hangar large airport (32)
// 0x41 - hangar small airport (65)
return (_m[tile].m5 == 32 || _m[tile].m5 == 65);
}
static void AiStateAirportStuff(Player *p)
{
@ -3245,7 +3236,7 @@ static void AiStateAirportStuff(Player *p)
* here for now (some of the new airport types would be
* broken because they will probably need different
* tileoff values etc), no matter that
* AiCheckIfHangar() makes no sense. --pasky */
* IsHangarTile() makes no sense. --pasky */
if (acc_planes == HELICOPTERS_ONLY) {
/* Heliports should have maybe own rulesets but
* OTOH we don't want AI to pick them up when
@ -3255,7 +3246,7 @@ static void AiStateAirportStuff(Player *p)
* because we have no such rule. */
rule = 1;
} else {
rule = AiCheckIfHangar(st);
rule = IsHangarTile(st->airport_tile);
}
aib->cur_building_rule = rule;
@ -3504,7 +3495,7 @@ static void AiStateSellVeh(Player *p)
DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
} else if (v->type == VEH_Aircraft) {
if (!IsAircraftHangarTile(v->tile) || !(v->vehstatus & VS_STOPPED)) {
if (!IsHangarTile(v->tile) || !(v->vehstatus & VS_STOPPED)) {
if (v->current_order.type != OT_GOTO_DEPOT)
DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
goto going_to_depot;

View File

@ -617,9 +617,7 @@ static void AiNew_State_FindStation(Player *p)
if (AiNew_CheckVehicleStation(p, st)) {
// We did found a station that was good enough!
new_tile = st->xy;
// Cheap way to get the direction of the station...
// Bus stations save it as 0x47 .. 0x4A, so decrease it with 0x47, and tada!
direction = _m[st->xy].m5 - 0x47;
direction = GetRoadStationDir(st->xy);
break;
}
}

View File

@ -150,7 +150,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
// to just query the cost, it is not neccessary to have a valid tile (automation/AI)
if (flags & DC_QUERY_COST) return value;
if (!IsAircraftHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
@ -305,18 +305,10 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return value;
}
bool IsAircraftHangarTile(TileIndex tile)
{
// 0x56 - hangar facing other way international airport (86)
// 0x20 - hangar large airport (32)
// 0x41 - hangar small airport (65)
return IsTileType(tile, MP_STATION) &&
(_m[tile].m5 == 32 || _m[tile].m5 == 65 || _m[tile].m5 == 86);
}
bool CheckStoppedInHangar(const Vehicle* v)
{
return v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile);
return v->vehstatus & VS_STOPPED && IsHangarTile(v->tile);
}
@ -378,7 +370,7 @@ int32 CmdStartStopAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT);
if (flags & DC_EXEC) {
if (v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile)) {
if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) {
DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN);
}

View File

@ -502,9 +502,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
uint32 disabled = 1 << 8;
StringID str;
if (v->vehstatus & VS_STOPPED && IsAircraftHangarTile(v->tile)) {
disabled = 0;
}
if (v->vehstatus & VS_STOPPED && IsHangarTile(v->tile)) disabled = 0;
if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7;
w->disabled_state = disabled;
@ -1033,7 +1031,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
DrawVehicleProfitButton(v, x, y + 13);
SetDParam(0, v->unitnumber);
if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) {
if (IsHangarTile(v->tile) && v->vehstatus & VS_HIDDEN) {
str = STR_021F;
} else {
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
@ -1096,7 +1094,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
tile = _last_built_aircraft_depot_tile;
do {
if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
if (IsHangarTile(tile) && IsTileOwner(tile, _local_player)) {
ShowAircraftDepotWindow(tile);
ShowBuildAircraftWindow(tile);
return;

View File

@ -179,7 +179,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
IsAirport(tile) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
v->current_order.station = 1;
v->age = 0;
@ -204,7 +204,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
IsAirport(tile) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
st = GetStationByTile(tile);
CLRBITS(st->airport_flags, RUNWAY_IN_block);
@ -246,7 +246,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
tile = v->tile;/**/
if (IsValidTile(tile) &&
IsTileType(tile, MP_STATION) &&
IS_BYTE_INSIDE(_m[tile].m5, 8, 0x43) &&
IsAirport(tile) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
st = GetStationByTile(tile);
SETBITS(st->airport_flags, RUNWAY_IN_block);

View File

@ -4,6 +4,7 @@
#include "openttd.h"
#include "clear_map.h"
#include "industry_map.h"
#include "station_map.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "functions.h"
@ -877,7 +878,7 @@ void DeleteIndustry(Industry *i)
if (GetIndustryIndex(tile_cur) == i->index) {
DoClearSquare(tile_cur);
}
} else if (IsTileType(tile_cur, MP_STATION) && _m[tile_cur].m5 == 0x4B) {
} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
DeleteOilRig(tile_cur);
}
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);

View File

@ -218,7 +218,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
case MP_STATION:
if (v->type != VEH_Aircraft) break;
if (IsAircraftHangarTile(tile) && IsTileOwner(tile, _local_player)) {
if (IsHangar(tile) && IsTileOwner(tile, _local_player)) {
order.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS;
order.station = GetStationIndex(tile);

View File

@ -1088,8 +1088,7 @@ static int RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection enterdir
goto do_it;
}
} else if (IsTileType(desttile, MP_STATION)) {
if (IS_BYTE_INSIDE(_m[desttile].m5, 0x43, 0x4B)) {
/* We are heading for a station */
if (IsRoadStop(desttile)) {
dir = GetRoadStationDir(desttile);
do_it:;
/* When we are heading for a depot or station, we just
@ -1321,7 +1320,7 @@ again:
v->cur_speed = 0;
return;
}
if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
if (IsRoadStop(v->tile)) {
RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
// reached a loading bay, mark it as used and clear the usage bit

View File

@ -6,6 +6,7 @@
#include "clear_map.h"
#include "functions.h"
#include "spritecache.h"
#include "station_map.h"
#include "table/strings.h"
#include "table/sprites.h"
#include "map.h"
@ -445,14 +446,15 @@ static inline uint32 GetSmallMapRoutesPixels(TileIndex tile)
uint32 bits;
if (t == MP_STATION) {
byte m5 = _m[tile].m5;
(bits = MKCOLOR(0x56565656), m5 < 8) || // 8 - railroad station (green)
(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x43) || // 67 - airport (red)
(bits = MKCOLOR(0xC2C2C2C2), m5 < 0x47) || // 71 - truck loading bay (orange)
(bits = MKCOLOR(0xBFBFBFBF), m5 < 0x4B) || // 75 - bus station (yellow)
(bits = MKCOLOR(0x98989898), m5 < 0x53) || // 83 - docks (blue)
(bits = MKCOLOR(0xB8B8B8B8), m5 < 0x73) || // 115 - airport (red) (new airports)
(bits = MKCOLOR(0xFFFFFFFF), true); // all others
switch (GetStationType(tile)) {
case STATION_RAIL: bits = MKCOLOR(0x56565656); break;
case STATION_HANGAR:
case STATION_AIRPORT: bits = MKCOLOR(0xB8B8B8B8); break;
case STATION_TRUCK: bits = MKCOLOR(0xC2C2C2C2); break;
case STATION_BUS: bits = MKCOLOR(0xBFBFBFBF); break;
case STATION_DOCK: bits = MKCOLOR(0x98989898); break;
default: bits = MKCOLOR(0xFFFFFFFF); break;
}
} else {
// ground color
bits = ApplyMask(MKCOLOR(0x54545454), &_smallmap_contours_andor[t]);

View File

@ -111,6 +111,12 @@ static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict
}
static inline bool IsHangarTile(TileIndex t)
{
return IsTileType(t, MP_STATION) && IsHangar(t);
}
static inline Axis GetRailStationAxis(TileIndex t)
{
assert(IsRailwayStation(t));

View File

@ -300,7 +300,6 @@ void VehicleEnteredDepotThisTick(Vehicle *v);
void BeginVehicleMove(Vehicle *v);
void EndVehicleMove(Vehicle *v);
bool IsAircraftHangarTile(TileIndex tile);
void ShowAircraftViewWindow(const Vehicle* v);
UnitID GetFreeUnitNumber(byte type);

View File

@ -3,6 +3,7 @@
#include "stdafx.h"
#include "openttd.h"
#include "bridge_map.h"
#include "station_map.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
@ -340,17 +341,13 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
// return true if a tile is a water tile.
static bool IsWateredTile(TileIndex tile)
{
byte m5 = _m[tile].m5;
switch (GetTileType(tile)) {
case MP_WATER:
// true, if not coast/riverbank
return m5 != 1;
return _m[tile].m5 != 1;
case MP_STATION:
// returns true if it is a dock-station
// m5 inside values is m5 < 75 all stations, 83 <= m5 <= 114 new airports
return !(m5 < 75 || (m5 >= 83 && m5 <= 114));
return IsOilRig(tile) || IsDock(tile) || IsBuoy_(tile);
case MP_TUNNELBRIDGE:
return IsBridge(tile) && IsBridgeMiddle(tile) && IsWaterUnderBridge(tile);