summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2008-02-05 05:21:02 +0000
committerbelugas <belugas@openttd.org>2008-02-05 05:21:02 +0000
commit7f5f48281c301344a3f007037f49c2d12b5ebf10 (patch)
tree9c2717a65edae3fd296acdab60dde15fb2ba163c
parent23c8664593b6e7a4f2b1c0058d5f4491935c3682 (diff)
downloadopenttd-7f5f48281c301344a3f007037f49c2d12b5ebf10.tar.xz
(svn r12066) -Codechange: Rename GetBridge for the more common GetBridgeSpec
-Codechange: Remove direct access to the _bridge table in favor of the above mentioned GetBridgeSpec -Codechange: Rationalize the use of Bridge type pointer
-rw-r--r--src/bridge.h2
-rw-r--r--src/bridge_gui.cpp4
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/tunnelbridge_cmd.cpp20
-rw-r--r--src/yapf/follow_track.hpp2
6 files changed, 14 insertions, 18 deletions
diff --git a/src/bridge.h b/src/bridge.h
index 9088e96c1..29afd06b1 100644
--- a/src/bridge.h
+++ b/src/bridge.h
@@ -35,7 +35,7 @@ extern Bridge _bridge[MAX_BRIDGES];
Foundation GetBridgeFoundation(Slope tileh, Axis axis);
bool HasBridgeFlatRamp(Slope tileh, Axis axis);
-static inline const Bridge *GetBridge(uint i)
+static inline const Bridge *GetBridgeSpec(uint i)
{
assert(i < lengthof(_bridge));
return &_bridge[i];
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index 5b74e0cde..11d8ee074 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -79,7 +79,7 @@ static void BuildBridgeWndProc(Window *w, WindowEvent *e)
uint y = 15;
for (uint i = 0; (i < w->vscroll.cap) && ((i + w->vscroll.pos) < _bridgedata.count); i++) {
- const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
+ const Bridge *b = GetBridgeSpec(_bridgedata.indexes[i + w->vscroll.pos]);
SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
SetDParam(1, b->speed * 10 / 16);
@@ -191,7 +191,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) {
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
/* bridge is accepted, add to list */
- const Bridge *b = &_bridge[bridge_type];
+ const Bridge *b = GetBridgeSpec(bridge_type);
/* Add to terraforming & bulldozing costs the cost of the
* bridge itself (not computed with DC_QUERY_COST) */
_bridgedata.costs[j] = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * b->price) >> 8);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index f374197a3..7098797a9 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -956,7 +956,7 @@ static bool RoadVehAccelerate(Vehicle *v)
/* Clamp */
spd = min(spd, v->max_speed);
if (v->u.road.state == RVSB_WORMHOLE && !(v->vehstatus & VS_HIDDEN)) {
- spd = min(spd, GetBridge(GetBridgeType(v->tile))->speed * 2);
+ spd = min(spd, GetBridgeSpec(GetBridgeType(v->tile))->speed * 2);
}
/* updates statusbar only if speed have changed to save CPU time */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index def649ccd..a4c730939 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3132,7 +3132,7 @@ static void TrainController(Vehicle *v, bool update_image)
* - for bridges, only the middle part - without the bridge heads */
if (!(v->vehstatus & VS_HIDDEN)) {
v->cur_speed =
- min(v->cur_speed, GetBridge(GetBridgeType(v->tile))->speed);
+ min(v->cur_speed, GetBridgeSpec(GetBridgeType(v->tile))->speed);
}
if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 6b1cdd60a..0ea62d5ea 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -99,7 +99,7 @@ bool HasBridgeFlatRamp(Slope tileh, Axis axis)
static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
{
- const Bridge *bridge = &_bridge[index];
+ const Bridge *bridge = GetBridgeSpec(index);
assert(table < 7);
if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
return _bridge_sprite_table[index][table];
@@ -108,8 +108,6 @@ static inline const PalSpriteID *GetBridgeSpriteTable(int index, byte table)
}
}
-static inline byte GetBridgeFlags(int index) { return _bridge[index].flags;}
-
/**
* Determines the foundation for the north bridge head, and tests if the resulting slope is valid.
@@ -155,7 +153,7 @@ static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, uint *z)
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len)
{
- const Bridge *b = &_bridge[bridge_type];
+ const Bridge *b = GetBridgeSpec(bridge_type);
uint max; // max possible length of a bridge (with patch 100)
if (bridge_type >= MAX_BRIDGES) return false;
@@ -266,7 +264,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p
/* Do not replace town bridges with lower speed bridges. */
if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
- _bridge[bridge_type].speed < _bridge[GetBridgeType(tile_start)].speed) {
+ GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed) {
Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
if (t == NULL) {
@@ -416,14 +414,12 @@ not_valid_below:;
* and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
*/
if (!(flags & DC_QUERY_COST)) {
- const Bridge *b = &_bridge[bridge_type];
-
bridge_len += 2; // begin and end tiles/ramps
if (IsValidPlayer(_current_player) && !_is_old_ai_player)
bridge_len = CalcBridgeLenCostFactor(bridge_len);
- cost.AddCost((int64)bridge_len * _price.build_bridge * b->price >> 8);
+ cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8);
}
return cost;
@@ -700,7 +696,7 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo* ti, Axis
{
SpriteID image = psid->sprite;
if (image != 0) {
- bool drawfarpillar = !HasBit(GetBridgeFlags(type), 0);
+ bool drawfarpillar = !HasBit(GetBridgeSpec(type)->flags, 0);
/* "side" specifies the side the pillars stand on.
* The length of the pillars is then set to the height of the bridge over the corners of this edge.
@@ -1130,8 +1126,8 @@ static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
td->str = (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) ?
STR_5017_RAILROAD_TUNNEL : STR_5018_ROAD_TUNNEL;
} else { //so it must be a bridge
- int brtype = GetBridgeType(tile);
- td->str = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL ? _bridge[brtype].name_rail : _bridge[brtype].name_road;
+ const Bridge *brspc = GetBridgeSpec(GetBridgeType(tile));
+ td->str = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL ? brspc->name_rail : brspc->name_road;
}
td->owner = GetTileOwner(tile);
}
@@ -1289,7 +1285,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
if (v->IsPrimaryVehicle()) {
/* modify speed of vehicle */
- uint16 spd = _bridge[GetBridgeType(tile)].speed;
+ uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
if (v->type == VEH_ROAD) spd *= 2;
if (v->cur_speed > spd) v->cur_speed = spd;
diff --git a/src/yapf/follow_track.hpp b/src/yapf/follow_track.hpp
index cf7d98671..09bc98b76 100644
--- a/src/yapf/follow_track.hpp
+++ b/src/yapf/follow_track.hpp
@@ -342,7 +342,7 @@ public:
// for now we handle only on-bridge speed limit
if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
- int spd = _bridge[GetBridgeType(m_old_tile)].speed;
+ int spd = GetBridgeSpec(GetBridgeType(m_old_tile))->speed;
if (IsRoadTT()) spd *= 2;
if (max_speed > spd) max_speed = spd;
}