2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
/** @file road_func.h Functions related to roads. */
|
|
|
|
|
|
|
|
#ifndef ROAD_FUNC_H
|
|
|
|
#define ROAD_FUNC_H
|
|
|
|
|
2007-12-21 19:21:21 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2019-04-06 06:46:15 +00:00
|
|
|
#include "road.h"
|
2011-12-03 23:40:46 +00:00
|
|
|
#include "economy_func.h"
|
2019-04-06 06:46:15 +00:00
|
|
|
#include "transparency.h"
|
2020-07-02 16:47:26 +00:00
|
|
|
#include "settings_type.h"
|
2007-12-18 20:38:16 +00:00
|
|
|
|
2013-11-25 13:16:06 +00:00
|
|
|
/**
|
|
|
|
* Whether the given roadtype is valid.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param r the roadtype to check for validness
|
2013-11-25 13:16:06 +00:00
|
|
|
* @return true if and only if valid
|
|
|
|
*/
|
|
|
|
static inline bool IsValidRoadBits(RoadBits r)
|
|
|
|
{
|
|
|
|
return r < ROAD_END;
|
|
|
|
}
|
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
/**
|
|
|
|
* Calculate the complement of a RoadBits value
|
|
|
|
*
|
|
|
|
* Simply flips all bits in the RoadBits value to get the complement
|
|
|
|
* of the RoadBits.
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @return the complement
|
|
|
|
*/
|
|
|
|
static inline RoadBits ComplementRoadBits(RoadBits r)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(IsValidRoadBits(r));
|
2007-12-18 20:38:16 +00:00
|
|
|
return (RoadBits)(ROAD_ALL ^ r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the mirrored RoadBits
|
|
|
|
*
|
|
|
|
* Simply move the bits to their new position.
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @return the mirrored
|
|
|
|
*/
|
|
|
|
static inline RoadBits MirrorRoadBits(RoadBits r)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(IsValidRoadBits(r));
|
2007-12-18 20:38:16 +00:00
|
|
|
return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate rotated RoadBits
|
|
|
|
*
|
2013-01-08 22:46:42 +00:00
|
|
|
* Move the Roadbits clockwise until they are in their final position.
|
2007-12-18 20:38:16 +00:00
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @param rot The given Rotation angle
|
|
|
|
* @return the rotated
|
|
|
|
*/
|
|
|
|
static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(IsValidRoadBits(r));
|
2009-08-14 17:11:59 +00:00
|
|
|
for (; rot > (DiagDirDiff)0; rot--) {
|
2007-12-18 20:38:16 +00:00
|
|
|
r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
/**
|
|
|
|
* Check if we've got a straight road
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits
|
|
|
|
* @return true if we've got a straight road
|
|
|
|
*/
|
|
|
|
static inline bool IsStraightRoad(RoadBits r)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(IsValidRoadBits(r));
|
2008-03-25 18:59:25 +00:00
|
|
|
return (r == ROAD_X || r == ROAD_Y);
|
|
|
|
}
|
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
/**
|
|
|
|
* Create the road-part which belongs to the given DiagDirection
|
|
|
|
*
|
|
|
|
* This function returns a RoadBits value which belongs to
|
|
|
|
* the given DiagDirection.
|
|
|
|
*
|
|
|
|
* @param d The DiagDirection
|
|
|
|
* @return The result RoadBits which the selected road-part set
|
|
|
|
*/
|
|
|
|
static inline RoadBits DiagDirToRoadBits(DiagDirection d)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(IsValidDiagDirection(d));
|
2007-12-18 20:38:16 +00:00
|
|
|
return (RoadBits)(ROAD_NW << (3 ^ d));
|
|
|
|
}
|
|
|
|
|
2008-03-22 10:56:08 +00:00
|
|
|
/**
|
|
|
|
* Create the road-part which belongs to the given Axis
|
|
|
|
*
|
|
|
|
* This function returns a RoadBits value which belongs to
|
|
|
|
* the given Axis.
|
|
|
|
*
|
|
|
|
* @param a The Axis
|
|
|
|
* @return The result RoadBits which the selected road-part set
|
|
|
|
*/
|
|
|
|
static inline RoadBits AxisToRoadBits(Axis a)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(IsValidAxis(a));
|
2008-03-22 10:56:08 +00:00
|
|
|
return a == AXIS_X ? ROAD_X : ROAD_Y;
|
|
|
|
}
|
|
|
|
|
2011-12-03 23:40:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the maintenance cost of a number of road bits.
|
|
|
|
* @param roadtype Road type to get the cost for.
|
|
|
|
* @param num Number of road bits.
|
2019-04-06 06:46:15 +00:00
|
|
|
* @param total_num Total number of road bits of all road/tram-types.
|
2011-12-03 23:40:46 +00:00
|
|
|
* @return Total cost.
|
|
|
|
*/
|
2019-04-06 06:46:15 +00:00
|
|
|
static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num, uint32 total_num)
|
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(roadtype < ROADTYPE_END);
|
2019-04-06 06:46:15 +00:00
|
|
|
return (_price[PR_INFRASTRUCTURE_ROAD] * GetRoadTypeInfo(roadtype)->maintenance_multiplier * num * (1 + IntSqrt(total_num))) >> 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if a road type has catenary
|
|
|
|
* @param roadtype Road type to test
|
|
|
|
*/
|
|
|
|
static inline bool HasRoadCatenary(RoadType roadtype)
|
2011-12-03 23:40:46 +00:00
|
|
|
{
|
2022-10-22 11:34:54 +00:00
|
|
|
dbg_assert(roadtype < ROADTYPE_END);
|
2019-04-06 06:46:15 +00:00
|
|
|
return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY);
|
2011-12-03 23:40:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 06:46:15 +00:00
|
|
|
/**
|
|
|
|
* Test if we should draw road catenary
|
|
|
|
* @param roadtype Road type to test
|
|
|
|
*/
|
|
|
|
static inline bool HasRoadCatenaryDrawn(RoadType roadtype)
|
|
|
|
{
|
|
|
|
return HasRoadCatenary(roadtype) && !IsInvisibilitySet(TO_CATENARY);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasRoadTypeAvail(CompanyID company, RoadType roadtype);
|
|
|
|
bool ValParamRoadType(RoadType roadtype);
|
|
|
|
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces = true);
|
|
|
|
RoadTypes GetRoadTypes(bool introduces);
|
|
|
|
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date);
|
2008-01-09 21:05:03 +00:00
|
|
|
|
2017-07-20 00:07:02 +00:00
|
|
|
void UpdateLevelCrossing(TileIndex tile, bool sound = true, bool force_close = false);
|
2021-11-20 01:42:18 +00:00
|
|
|
void MarkDirtyAdjacentLevelCrossingTilesOnAddRemove(TileIndex tile, Axis road_axis);
|
2017-05-07 18:33:59 +00:00
|
|
|
bool IsCrossingOccupiedByRoadVehicle(TileIndex t);
|
2020-10-26 22:17:25 +00:00
|
|
|
|
|
|
|
void UpdateRoadCachedOneWayStatesAroundTile(TileIndex tile);
|
2019-04-06 06:46:15 +00:00
|
|
|
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
|
|
|
|
|
|
|
|
struct TileInfo;
|
2022-12-17 14:01:47 +00:00
|
|
|
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset, bool draw_underlay = true);
|
2008-01-17 19:49:06 +00:00
|
|
|
|
2020-07-02 16:47:26 +00:00
|
|
|
inline bool RoadLayoutChangeNotificationEnabled(bool added)
|
|
|
|
{
|
|
|
|
return _settings_game.pf.reroute_rv_on_layout_change >= (added ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
2019-05-24 17:51:30 +00:00
|
|
|
inline void NotifyRoadLayoutChanged()
|
|
|
|
{
|
|
|
|
_road_layout_change_counter++;
|
|
|
|
}
|
|
|
|
|
2020-07-02 16:47:26 +00:00
|
|
|
inline void NotifyRoadLayoutChanged(bool added)
|
|
|
|
{
|
|
|
|
if (RoadLayoutChangeNotificationEnabled(added)) NotifyRoadLayoutChanged();
|
|
|
|
}
|
|
|
|
|
2019-07-11 18:45:56 +00:00
|
|
|
void NotifyRoadLayoutChangedIfTileNonLeaf(TileIndex tile, RoadTramType rtt, RoadBits present_bits);
|
|
|
|
void NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(TileIndex start, TileIndex end, DiagDirection start_dir, RoadTramType rtt);
|
2019-05-24 17:51:30 +00:00
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
#endif /* ROAD_FUNC_H */
|