Handling of trafficlights. More...
#include "stdafx.h"
#include "openttd.h"
#include "landscape.h"
#include "sprite.h"
#include "viewport_func.h"
#include "road_map.h"
#include "command_func.h"
#include "cheat_func.h"
#include "animated_tile_func.h"
#include "economy_func.h"
#include "road_cmd.h"
#include "company_func.h"
#include "company_base.h"
#include "settings_type.h"
#include "trafficlight.h"
#include "trafficlight_type.h"
#include "date_func.h"
#include "table/sprites.h"
#include "table/strings.h"
#include <set>
Go to the source code of this file.
Typedefs | |
typedef std::set< TileIndex > | TLC |
Functions | |
TLC * | GetTrafficLightConsist (TileIndex tile, bool checkroadworks) |
Gets the traffic light consist (a set of adjacent tiles with traffic lights). | |
TileIndex | GetTLCLowestTileIndexOrRoadWorks (TileIndex tile) |
Gets the lowest TileIndex of the traffic light consist or 0 if roadworks are found in the consist. | |
TrafficLightState | GetTLState (TileIndex tile) |
Returns the state of the trafficlights on a tile. | |
TrackdirBits | GetIntraTLCAllowedDirections (TileIndex tile) |
Which directions in tile are allowed to be taken due to adjacent traffic lights (traffic light consist). | |
TrackdirBits | GetTrafficLightDisallowedDirections (TileIndex tile) |
Get a bitmask of the directions forbidden to drive on due to traffic light(s). | |
bool | CheckTLCSize (TileIndex tile) |
Checks if the size of a traffic light consist is within the allowed range. | |
CommandCost | CmdBuildTrafficLights (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Build traffic lights on a crossing. | |
CommandCost | CmdRemoveTrafficLights (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Removes traffic lights from a tile. | |
void | ClearAllTrafficLights () |
Clear all traffic lights from the map. | |
void | DrawTrafficLights (TileInfo *ti) |
Draws traffic lights on a tile. | |
Variables | |
static const TrackdirBits | _tls_to_trackdir [7] |
Which directions are disallowed due to the TLState (red lights..). |
Handling of trafficlights.
Definition in file trafficlight.cpp.
bool CheckTLCSize | ( | TileIndex | tile | ) |
Checks if the size of a traffic light consist is within the allowed range.
tile | Tile to check (can also be a new tile to be added to the TLC). |
Definition at line 172 of file trafficlight.cpp.
References _settings_game, GameSettings::construction, GetTrafficLightConsist(), and ConstructionSettings::max_tlc_size.
Referenced by CmdBuildTrafficLights().
CommandCost CmdBuildTrafficLights | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Build traffic lights on a crossing.
tile | Tile where to place the traffic lights. | |
flags | Operation to perform. | |
p1 | Unused. | |
p2 | Unused. |
Definition at line 189 of file trafficlight.cpp.
References _current_company, _settings_game, AddAnimatedTile(), ConstructionSettings::allow_building_tls_in_towns, CheckTLCSize(), CMD_ERROR, GameSettings::construction, CountBits(), DC_EXEC, EXPENSES_CONSTRUCTION, GetAllRoadBits(), GetRoadTileType(), GetTileOwner(), HasTrafficLights(), IsTileOwner(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MarkTileDirtyByTile(), MP_ROAD, OWNER_NONE, OWNER_TOWN, return_cmd_error, ROAD_TILE_NORMAL, and ConstructionSettings::traffic_lights.
CommandCost CmdRemoveTrafficLights | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Removes traffic lights from a tile.
tile | Tile where to remove the traffic lights. | |
flags | Operation to perform. | |
p1 | Unused. | |
p2 | Unused. |
Definition at line 230 of file trafficlight.cpp.
References _cheats, _current_company, _settings_game, ConstructionSettings::allow_building_tls_in_towns, CMD_ERROR, GameSettings::construction, DC_EXEC, DeleteAnimatedTile(), EXPENSES_CONSTRUCTION, GetRoadTileType(), GetTileOwner(), HasTrafficLights(), IsTileOwner(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Cheats::magic_bulldozer, MarkTileDirtyByTile(), MP_ROAD, OWNER_NONE, OWNER_TOWN, return_cmd_error, ROAD_TILE_NORMAL, and Cheat::value.
void DrawTrafficLights | ( | TileInfo * | ti | ) |
Draws traffic lights on a tile.
ti | TileInfo of the tile to draw on. |
Definition at line 270 of file trafficlight.cpp.
References _settings_game, _tl_offsets, _tls_to_sprites, DrawRoadDetail(), DRD_BOTH, DRD_NORTHBOUND, DRD_SOUTHBOUND, GetAllRoadBits(), GetDisallowedRoadDirections(), GetTLState(), HasTrafficLights(), IsNormalRoad(), IsTileType(), MP_ROAD, ROAD_NE, VehicleSettings::road_side, TileInfo::tile, TileDiffXY(), and GameSettings::vehicle.
Referenced by DrawRoadBits().
TrackdirBits GetIntraTLCAllowedDirections | ( | TileIndex | tile | ) |
Which directions in tile are allowed to be taken due to adjacent traffic lights (traffic light consist).
tile | Tile to search on. |
Definition at line 141 of file trafficlight.cpp.
References HasTrafficLights(), TileDiffXY(), TRACKDIR_BIT_LOWER_E, TRACKDIR_BIT_LOWER_W, TRACKDIR_BIT_UPPER_E, TRACKDIR_BIT_UPPER_W, TRACKDIR_BIT_X_NE, TRACKDIR_BIT_X_SW, TRACKDIR_BIT_Y_NW, and TRACKDIR_BIT_Y_SE.
Referenced by GetTrafficLightDisallowedDirections().
Gets the lowest TileIndex of the traffic light consist or 0 if roadworks are found in the consist.
tile | Tile of the traffic light consist. |
Definition at line 82 of file trafficlight.cpp.
References GetTrafficLightConsist().
Referenced by GetTLState().
TrafficLightState GetTLState | ( | TileIndex | tile | ) |
Returns the state of the trafficlights on a tile.
tile | This tile. |
< All lights are off in scenario editor.
< All lights are off when roadworks are in the consist.
< SW and NE are green, NW and SE are red.
< SW and NE are yellow, NW and SE are red.
< SW and NE are red, NW and SE are red-yellow.
< SW and NE are red, NW and SE are green.
< SW and NE are red, NW and SE are yellow.
< SW and NE are red-yellow, NW and SE are red.
Definition at line 98 of file trafficlight.cpp.
References _settings_game, _tick_counter, GameSettings::construction, GetTLCLowestTileIndexOrRoadWorks(), HasTrafficLights(), TileX(), TileY(), TLS_X_GREEN_Y_RED, TLS_X_RED_Y_GREEN, TLS_X_RED_Y_REDYELLOW, TLS_X_RED_Y_YELLOW, TLS_X_YELLOW_Y_RED, and ConstructionSettings::traffic_lights_green_phase.
Referenced by DrawTrafficLights(), and GetTrafficLightDisallowedDirections().
TLC* GetTrafficLightConsist | ( | TileIndex | tile, | |
bool | checkroadworks | |||
) |
Gets the traffic light consist (a set of adjacent tiles with traffic lights).
If specified by the checkroadworks parameter, it returns 0 instead if road works are found within the consist.
tile | Tile of the traffic light consist. | |
checkroadworks | Should we check for roadworks in the consist (and return 0 if found). |
Definition at line 48 of file trafficlight.cpp.
References _settings_game, _tlc_distance, GameSettings::construction, HasRoadWorks(), HasTrafficLights(), ConstructionSettings::max_tlc_distance, and ToTileIndexDiff().
Referenced by CheckTLCSize(), and GetTLCLowestTileIndexOrRoadWorks().
TrackdirBits GetTrafficLightDisallowedDirections | ( | TileIndex | tile | ) |
Get a bitmask of the directions forbidden to drive on due to traffic light(s).
tile | Tile to check. |
Definition at line 162 of file trafficlight.cpp.
References _tls_to_trackdir, GetIntraTLCAllowedDirections(), and GetTLState().
const TrackdirBits _tls_to_trackdir[7] [static] |
{ TRACKDIR_BIT_MASK, TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_RIGHT_N, TRACKDIR_BIT_MASK, TRACKDIR_BIT_MASK, TRACKDIR_BIT_X_SW | TRACKDIR_BIT_X_NE | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_RIGHT_S, TRACKDIR_BIT_MASK, TRACKDIR_BIT_MASK, }
Which directions are disallowed due to the TLState (red lights..).
Definition at line 122 of file trafficlight.cpp.
Referenced by GetTrafficLightDisallowedDirections().