Typedefs | Functions | Variables

trafficlight.cpp File Reference

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< TileIndexTLC

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..).

Detailed Description

Handling of trafficlights.

Definition in file trafficlight.cpp.


Function Documentation

bool CheckTLCSize ( TileIndex  tile  ) 

Checks if the size of a traffic light consist is within the allowed range.

Parameters:
tile Tile to check (can also be a new tile to be added to the TLC).
Returns:
result True if the TLC size is within the allowed range, else false.

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 
)
CommandCost CmdRemoveTrafficLights ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
void DrawTrafficLights ( TileInfo ti  ) 
TrackdirBits GetIntraTLCAllowedDirections ( TileIndex  tile  ) 

Which directions in tile are allowed to be taken due to adjacent traffic lights (traffic light consist).

Parameters:
tile Tile to search on.
Returns:
trackdirbits Bitmask of allowed directions.

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().

TileIndex GetTLCLowestTileIndexOrRoadWorks ( TileIndex  tile  ) 

Gets the lowest TileIndex of the traffic light consist or 0 if roadworks are found in the consist.

Parameters:
tile Tile of the traffic light consist.
Returns:
lowest TileIndex in the consist or 0 if roadworks were found.

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.

Note:
In the scenario editor trafficlights are disabled.
Parameters:
tile This tile.
Precondition:
The tile must have trafficlights.
Returns:
Trafficlights state or disabled state.

< 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.

Parameters:
tile Tile of the traffic light consist.
checkroadworks Should we check for roadworks in the consist (and return 0 if found).
Returns:
visited The traffic light consist (TLC); if checkroadworks == true and roadworks were found, return 0 instead.

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).

Parameters:
tile Tile to check.
Returns:
Bitmask of forbidden directions.

Definition at line 162 of file trafficlight.cpp.

References _tls_to_trackdir, GetIntraTLCAllowedDirections(), and GetTLState().


Variable Documentation

const TrackdirBits _tls_to_trackdir[7] [static]
Initial value:
 {
  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().