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"
|
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)
|
|
|
|
{
|
2013-11-25 13:16:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-11-25 13:16:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-11-25 13:16:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-11-25 13:16:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-11-25 13:16:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-11-25 13:16:06 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
static inline bool HasRoadCatenary(RoadType roadtype)
|
2011-12-03 23:40:46 +00:00
|
|
|
{
|
2019-04-06 06:46:15 +00:00
|
|
|
assert(roadtype < ROADTYPE_END);
|
|
|
|
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
|
|
|
|
2008-01-17 20:41:33 +00:00
|
|
|
void UpdateLevelCrossing(TileIndex tile, bool sound = true);
|
2019-04-06 06:46:15 +00:00
|
|
|
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
|
|
|
|
|
|
|
|
struct TileInfo;
|
|
|
|
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset);
|
2008-01-17 19:49:06 +00:00
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
#endif /* ROAD_FUNC_H */
|