2009-08-21 22:21:05 +02: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 21:38:16 +01:00
|
|
|
/** @file road_func.h Functions related to roads. */
|
|
|
|
|
|
|
|
#ifndef ROAD_FUNC_H
|
|
|
|
#define ROAD_FUNC_H
|
|
|
|
|
2007-12-21 20:21:21 +01:00
|
|
|
#include "core/bitmath_func.hpp"
|
2019-04-06 08:46:15 +02:00
|
|
|
#include "road.h"
|
2011-12-04 00:40:46 +01:00
|
|
|
#include "economy_func.h"
|
2019-04-06 08:46:15 +02:00
|
|
|
#include "transparency.h"
|
2007-12-18 21:38:16 +01:00
|
|
|
|
2013-11-25 14:16:06 +01:00
|
|
|
/**
|
|
|
|
* Whether the given roadtype is valid.
|
2018-10-28 03:17:36 +01:00
|
|
|
* @param r the roadtype to check for validness
|
2013-11-25 14:16:06 +01:00
|
|
|
* @return true if and only if valid
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool IsValidRoadBits(RoadBits r)
|
2013-11-25 14:16:06 +01:00
|
|
|
{
|
|
|
|
return r < ROAD_END;
|
|
|
|
}
|
|
|
|
|
2007-12-18 21:38:16 +01: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
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline RoadBits ComplementRoadBits(RoadBits r)
|
2007-12-18 21:38:16 +01:00
|
|
|
{
|
2013-11-25 14:16:06 +01:00
|
|
|
assert(IsValidRoadBits(r));
|
2007-12-18 21:38:16 +01: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
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline RoadBits MirrorRoadBits(RoadBits r)
|
2007-12-18 21:38:16 +01:00
|
|
|
{
|
2013-11-25 14:16:06 +01:00
|
|
|
assert(IsValidRoadBits(r));
|
2007-12-18 21:38:16 +01:00
|
|
|
return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate rotated RoadBits
|
|
|
|
*
|
2013-01-08 23:46:42 +01:00
|
|
|
* Move the Roadbits clockwise until they are in their final position.
|
2007-12-18 21:38:16 +01:00
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @param rot The given Rotation angle
|
|
|
|
* @return the rotated
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
|
2007-12-18 21:38:16 +01:00
|
|
|
{
|
2013-11-25 14:16:06 +01:00
|
|
|
assert(IsValidRoadBits(r));
|
2009-08-14 19:11:59 +02:00
|
|
|
for (; rot > (DiagDirDiff)0; rot--) {
|
2007-12-18 21:38:16 +01:00
|
|
|
r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-25 19:59:25 +01:00
|
|
|
/**
|
|
|
|
* Check if we've got a straight road
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits
|
|
|
|
* @return true if we've got a straight road
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool IsStraightRoad(RoadBits r)
|
2008-03-25 19:59:25 +01:00
|
|
|
{
|
2013-11-25 14:16:06 +01:00
|
|
|
assert(IsValidRoadBits(r));
|
2008-03-25 19:59:25 +01:00
|
|
|
return (r == ROAD_X || r == ROAD_Y);
|
|
|
|
}
|
|
|
|
|
2007-12-18 21:38:16 +01: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
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline RoadBits DiagDirToRoadBits(DiagDirection d)
|
2007-12-18 21:38:16 +01:00
|
|
|
{
|
2013-11-25 14:16:06 +01:00
|
|
|
assert(IsValidDiagDirection(d));
|
2007-12-18 21:38:16 +01:00
|
|
|
return (RoadBits)(ROAD_NW << (3 ^ d));
|
|
|
|
}
|
|
|
|
|
2008-03-22 11:56:08 +01: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
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline RoadBits AxisToRoadBits(Axis a)
|
2008-03-22 11:56:08 +01:00
|
|
|
{
|
2013-11-25 14:16:06 +01:00
|
|
|
assert(IsValidAxis(a));
|
2008-03-22 11:56:08 +01:00
|
|
|
return a == AXIS_X ? ROAD_X : ROAD_Y;
|
|
|
|
}
|
|
|
|
|
2011-12-04 00:40:46 +01: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 08:46:15 +02:00
|
|
|
* @param total_num Total number of road bits of all road/tram-types.
|
2011-12-04 00:40:46 +01:00
|
|
|
* @return Total cost.
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline Money RoadMaintenanceCost(RoadType roadtype, uint32_t num, uint32_t total_num)
|
2019-04-06 08:46:15 +02:00
|
|
|
{
|
|
|
|
assert(roadtype < ROADTYPE_END);
|
|
|
|
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
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool HasRoadCatenary(RoadType roadtype)
|
2011-12-04 00:40:46 +01:00
|
|
|
{
|
2019-04-06 08:46:15 +02:00
|
|
|
assert(roadtype < ROADTYPE_END);
|
|
|
|
return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_CATENARY);
|
2011-12-04 00:40:46 +01:00
|
|
|
}
|
|
|
|
|
2019-04-06 08:46:15 +02:00
|
|
|
/**
|
|
|
|
* Test if we should draw road catenary
|
|
|
|
* @param roadtype Road type to test
|
|
|
|
*/
|
2024-01-06 12:19:27 +01:00
|
|
|
inline bool HasRoadCatenaryDrawn(RoadType roadtype)
|
2019-04-06 08:46:15 +02:00
|
|
|
{
|
|
|
|
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);
|
2023-04-24 20:33:18 +02:00
|
|
|
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date);
|
2008-01-09 22:05:03 +01:00
|
|
|
|
2022-11-01 21:51:23 +01:00
|
|
|
void UpdateLevelCrossing(TileIndex tile, bool sound = true, bool force_bar = false);
|
|
|
|
void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis);
|
2023-06-03 23:04:24 +02:00
|
|
|
void UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(TileIndex tile, Axis road_axis);
|
2019-04-06 08:46:15 +02:00
|
|
|
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
|
|
|
|
|
|
|
|
struct TileInfo;
|
2024-04-23 22:21:53 +02:00
|
|
|
enum Roadside : uint8_t;
|
2022-12-17 15:01:47 +01: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);
|
2024-04-23 22:21:53 +02:00
|
|
|
void DrawRoadGroundSprites(const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert);
|
2008-01-17 20:49:06 +01:00
|
|
|
|
2007-12-18 21:38:16 +01:00
|
|
|
#endif /* ROAD_FUNC_H */
|