Chunnel patch 28392: Add: Basic tunnel pool. (no save)
https://www.tt-forums.net/viewtopic.php?p=1183416#p1183416
This commit is contained in:

committed by
Jonathan G Rennison

parent
54494a0a7c
commit
ad070b91ea
@@ -404,6 +404,7 @@ transparency.h
|
|||||||
transparency_gui.h
|
transparency_gui.h
|
||||||
transport_type.h
|
transport_type.h
|
||||||
tunnelbridge.h
|
tunnelbridge.h
|
||||||
|
tunnel_base.h
|
||||||
vehicle_base.h
|
vehicle_base.h
|
||||||
vehicle_func.h
|
vehicle_func.h
|
||||||
vehicle_gui.h
|
vehicle_gui.h
|
||||||
|
40
src/tunnel_base.h
Normal file
40
src/tunnel_base.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file tunnel_base.h Base for all tunnels */
|
||||||
|
|
||||||
|
#ifndef TUNNEL_BASE_H
|
||||||
|
#define TUNNEL_BASE_H
|
||||||
|
|
||||||
|
#include "tunnel_map.h"
|
||||||
|
#include "core/pool_type.hpp"
|
||||||
|
|
||||||
|
struct Tunnel;
|
||||||
|
|
||||||
|
typedef Pool<Tunnel, TunnelID, 64, 64000> TunnelPool;
|
||||||
|
extern TunnelPool _tunnel_pool;
|
||||||
|
|
||||||
|
struct Tunnel : TunnelPool::PoolItem<&_tunnel_pool> {
|
||||||
|
|
||||||
|
TileIndex tile_n; // North tile of tunnel.
|
||||||
|
TileIndex tile_s; // South tile of tunnel.
|
||||||
|
|
||||||
|
Tunnel(TileIndex tile_n = INVALID_TILE) : tile_n(tile_n) {}
|
||||||
|
~Tunnel();
|
||||||
|
|
||||||
|
static inline Tunnel *GetByTile(TileIndex tile)
|
||||||
|
{
|
||||||
|
return Tunnel::Get(GetTunnelIndex(tile));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FOR_ALL_TUNNELS_FROM(var, start) FOR_ALL_ITEMS_FROM(Tunnel, tunnel_index, var, start)
|
||||||
|
#define FOR_ALL_TUNNELS(var) FOR_ALL_TUNNELS_FROM(var, 0)
|
||||||
|
|
||||||
|
#endif /* TUNNEL_BASE_H */
|
@@ -12,8 +12,21 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "tunnelbridge_map.h"
|
#include "tunnelbridge_map.h"
|
||||||
|
|
||||||
|
#include "core/pool_func.hpp"
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
/** All tunnel portals tucked away in a pool. */
|
||||||
|
TunnelPool _tunnel_pool("Tunnel");
|
||||||
|
INSTANTIATE_POOL_METHODS(Tunnel)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up a tunnel tile
|
||||||
|
*/
|
||||||
|
Tunnel::~Tunnel()
|
||||||
|
{
|
||||||
|
if (CleaningPool()) return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the other end of the tunnel. Where a vehicle would reappear when it
|
* Gets the other end of the tunnel. Where a vehicle would reappear when it
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "road_map.h"
|
#include "road_map.h"
|
||||||
|
|
||||||
|
typedef uint16 TunnelID; ///< Type for the unique identifier of tunnels.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this a tunnel (entrance)?
|
* Is this a tunnel (entrance)?
|
||||||
@@ -37,6 +38,18 @@ static inline bool IsTunnelTile(TileIndex t)
|
|||||||
return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
|
return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the index of tunnel tile.
|
||||||
|
* @param t the tile
|
||||||
|
* @pre IsTunnelTile(t)
|
||||||
|
* @return TunnelID
|
||||||
|
*/
|
||||||
|
static inline TunnelID GetTunnelIndex(TileIndex t)
|
||||||
|
{
|
||||||
|
assert(IsTunnelTile(t));
|
||||||
|
return _m[t].m2;
|
||||||
|
}
|
||||||
|
|
||||||
TileIndex GetOtherTunnelEnd(TileIndex);
|
TileIndex GetOtherTunnelEnd(TileIndex);
|
||||||
bool IsTunnelInWay(TileIndex, int z);
|
bool IsTunnelInWay(TileIndex, int z);
|
||||||
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
|
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
|
||||||
@@ -48,11 +61,11 @@ bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
|
|||||||
* @param d the direction facing out of the tunnel
|
* @param d the direction facing out of the tunnel
|
||||||
* @param r the road type used in the tunnel
|
* @param r the road type used in the tunnel
|
||||||
*/
|
*/
|
||||||
static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadTypes r)
|
static inline void MakeRoadTunnel(TileIndex t, Owner o, TunnelID id, DiagDirection d, RoadTypes r)
|
||||||
{
|
{
|
||||||
SetTileType(t, MP_TUNNELBRIDGE);
|
SetTileType(t, MP_TUNNELBRIDGE);
|
||||||
SetTileOwner(t, o);
|
SetTileOwner(t, o);
|
||||||
_m[t].m2 = 0;
|
_m[t].m2 = id;
|
||||||
_m[t].m3 = 0;
|
_m[t].m3 = 0;
|
||||||
_m[t].m4 = 0;
|
_m[t].m4 = 0;
|
||||||
_m[t].m5 = TRANSPORT_ROAD << 2 | d;
|
_m[t].m5 = TRANSPORT_ROAD << 2 | d;
|
||||||
@@ -70,11 +83,11 @@ static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadTyp
|
|||||||
* @param d the direction facing out of the tunnel
|
* @param d the direction facing out of the tunnel
|
||||||
* @param r the rail type used in the tunnel
|
* @param r the rail type used in the tunnel
|
||||||
*/
|
*/
|
||||||
static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
|
static inline void MakeRailTunnel(TileIndex t, Owner o,TunnelID id, DiagDirection d, RailType r)
|
||||||
{
|
{
|
||||||
SetTileType(t, MP_TUNNELBRIDGE);
|
SetTileType(t, MP_TUNNELBRIDGE);
|
||||||
SetTileOwner(t, o);
|
SetTileOwner(t, o);
|
||||||
_m[t].m2 = 0;
|
_m[t].m2 = id;
|
||||||
SB(_m[t].m1, 7, 1, GB(r, 4, 1));
|
SB(_m[t].m1, 7, 1, GB(r, 4, 1));
|
||||||
SB(_m[t].m3, 0, 4, GB(r, 0, 4));
|
SB(_m[t].m3, 0, 4, GB(r, 0, 4));
|
||||||
SB(_m[t].m3, 4, 4, 0);
|
SB(_m[t].m3, 4, 4, 0);
|
||||||
@@ -84,4 +97,6 @@ static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailTyp
|
|||||||
_me[t].m7 = 0;
|
_me[t].m7 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* TUNNEL_MAP_H */
|
#endif /* TUNNEL_MAP_H */
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "autoslope.h"
|
#include "autoslope.h"
|
||||||
#include "tunnelbridge_map.h"
|
#include "tunnelbridge_map.h"
|
||||||
#include "bridge_signal_map.h"
|
#include "bridge_signal_map.h"
|
||||||
|
#include "tunnel_base.h"
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
#include "date_func.h"
|
#include "date_func.h"
|
||||||
#include "clear_func.h"
|
#include "clear_func.h"
|
||||||
@@ -49,6 +50,7 @@
|
|||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
|
||||||
BridgeSpec _bridge[MAX_BRIDGES]; ///< The specification of all bridges.
|
BridgeSpec _bridge[MAX_BRIDGES]; ///< The specification of all bridges.
|
||||||
TileIndex _build_tunnel_endtile; ///< The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
|
TileIndex _build_tunnel_endtile; ///< The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
|
||||||
|
|
||||||
@@ -747,10 +749,20 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
|||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
Company *c = Company::GetIfValid(company);
|
Company *c = Company::GetIfValid(company);
|
||||||
uint num_pieces = (tiles + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
uint num_pieces = (tiles + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||||
|
|
||||||
|
/* The most northern tile first. */
|
||||||
|
TileIndex tn = start_tile;
|
||||||
|
TileIndex ts = end_tile;
|
||||||
|
if(start_tile > end_tile) Swap(tn, ts);
|
||||||
|
|
||||||
|
if (!Tunnel::CanAllocateItem()) return CMD_ERROR;
|
||||||
|
Tunnel *t = new Tunnel(tn);
|
||||||
|
t->tile_s = ts;
|
||||||
|
|
||||||
if (transport_type == TRANSPORT_RAIL) {
|
if (transport_type == TRANSPORT_RAIL) {
|
||||||
if (!IsTunnelTile(start_tile) && c != NULL) c->infrastructure.rail[railtype] += num_pieces;
|
if (!IsTunnelTile(start_tile) && c != NULL) c->infrastructure.rail[railtype] += num_pieces;
|
||||||
MakeRailTunnel(start_tile, company, direction, railtype);
|
MakeRailTunnel(start_tile, company, t->index, direction, railtype);
|
||||||
MakeRailTunnel(end_tile, company, ReverseDiagDir(direction), railtype);
|
MakeRailTunnel(end_tile, company, t->index, ReverseDiagDir(direction), railtype);
|
||||||
AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, company);
|
AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, company);
|
||||||
YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
|
YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
|
||||||
} else {
|
} else {
|
||||||
@@ -760,8 +772,8 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
|||||||
c->infrastructure.road[rt] += num_pieces * 2; // A full diagonal road has two road bits.
|
c->infrastructure.road[rt] += num_pieces * 2; // A full diagonal road has two road bits.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MakeRoadTunnel(start_tile, company, direction, rts);
|
MakeRoadTunnel(start_tile, company, t->index, direction, rts);
|
||||||
MakeRoadTunnel(end_tile, company, ReverseDiagDir(direction), rts);
|
MakeRoadTunnel(end_tile, company, t->index, ReverseDiagDir(direction), rts);
|
||||||
}
|
}
|
||||||
DirtyCompanyInfrastructureWindows(company);
|
DirtyCompanyInfrastructureWindows(company);
|
||||||
}
|
}
|
||||||
@@ -873,6 +885,8 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
|||||||
DirtyCompanyInfrastructureWindows(owner);
|
DirtyCompanyInfrastructureWindows(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete Tunnel::GetByTile(tile);
|
||||||
|
|
||||||
DoClearSquare(tile);
|
DoClearSquare(tile);
|
||||||
DoClearSquare(endtile);
|
DoClearSquare(endtile);
|
||||||
|
|
||||||
@@ -895,6 +909,8 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete Tunnel::GetByTile(tile);
|
||||||
|
|
||||||
DoClearSquare(tile);
|
DoClearSquare(tile);
|
||||||
DoClearSquare(endtile);
|
DoClearSquare(endtile);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
#define TUNNELBRIDGE_MAP_H
|
#define TUNNELBRIDGE_MAP_H
|
||||||
|
|
||||||
#include "bridge_map.h"
|
#include "bridge_map.h"
|
||||||
#include "tunnel_map.h"
|
#include "tunnel_base.h"
|
||||||
#include "cmd_helper.h"
|
#include "cmd_helper.h"
|
||||||
#include "signal_type.h"
|
#include "signal_type.h"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user