Public Types | Public Member Functions | Data Fields | Private Member Functions | Private Attributes

CopyPaste Class Reference

Public Types

enum  CopyPasteTileType {
  CP_TILE_CLEAR, CP_TILE_RAIL, CP_TILE_ROAD, CP_TILE_TUNNELBRIDGE,
  CP_TILE_STATION
}

Public Member Functions

SaveOrLoadResult SaveLoadTemplate (const char *filename, int mode)
 SaveLoad function for templates TODO: Compression TODO: Better error handling (use goto for block error handling).
const char * GetErrorString ()
 Get the string representation of the error message.
bool IsSomethingCopied ()
 Returns if something is in our copy buffer.
void AllocateMapArray (uint32 max_tiles)
 allocate a map array
void ClearCopyArrays ()
 Clears content of copy buffers for current width/height, but does NOT reset width/height.
void CopyArea (TileIndex end, TileIndex start)
 Copies given area into copy buffer.
void PasteArea (TileIndex tile)
 Paste copied content onto map, taking care of multiplayer/singleplayer environment.
void RotateSelectionCCW ()
 Rotates the copied content CounterClockWise This is done by first rotating the array indices, then rotating the field contents.
void RotateSelectionCW ()
 Rotates the copied content ClockWise This is done by first rotating the array indices, then rotating the field contents.
void MirrorSelectionHorizontal ()
void MirrorSelectionVertical ()
uint GetHeight (uint baseh, uint index)
Slope GetSlope (uint index)
CopyPasteTileType GetCPTileType (uint index)
 Get the major tiletype of a tile.
uint GetCPMinorTileType (uint index)
 Get the minor tiletype of a tile.
TrackBits GetCPTrackBits (uint index)
FORCEINLINE uint32 GetWidth ()
FORCEINLINE uint32 GetHeight ()
 Used by the GUI.

Data Fields

bool m_copy_with_rail
 If rail should be copied.
bool m_copy_with_road
 If road should be copied.
bool m_copy_with_other
 If stuff owned by other players should be copied.
uint8 m_paste_vacant_terrain
 If empty terrain should be recreated. 0 = no terraform, 1 = terraform only needed, 2 = terraform all terrain.
bool m_convert_rail
 If rails should be converted to currently selected railtype.
bool m_clear_before_build
 If terrain should be bulldozed before we try to paste it.
bool m_toggle_signal_direction
 If signal direction should be toggled when pasting.

Private Member Functions

void SetError (StringID message, StringID extra=INVALID_STRING_ID)
 Set the error string & an extra message.
void internal_PasteArea (TileIndex tile)
 internal PasteArea method
void CP_DoCommand (TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd)
 Special DoCommand for CopyPaste.
void CP_RaiseLowerLand (TileIndex tile, int mode)
void CP_PlaceRail (TileIndex tile, int cmd, uint32 railtype)
void CP_PlaceSignals (TileIndex tile, Track track, SignalType type, uint direction, bool semaphore)
void CP_PlaceRoad (TileIndex tile, uint8 road_bits)
void CP_PlaceRoadStop (TileIndex tile, uint8 direction, uint8 roadtype, bool truck_stop, bool drive_through)
void CP_PlaceRail_Tunnel (TileIndex tile, uint32 railtype)
void CP_PlaceRoad_Tunnel (TileIndex tile, uint8 roadtype)
void CP_Build_Bridge (TileIndex start, TileIndex end, uint8 bridgetype, uint8 transport_type, uint8 rail_road_type)
void CP_PlaceRail_Depot (TileIndex tile, uint8 railtype, uint8 direction)
void CP_PlaceRoad_Depot (TileIndex tile, uint8 direction_type)
void CP_PlaceWaypoint (TileIndex tile, uint8 waypoint_type)
void CP_ClearTile (TileIndex start_tile, TileIndex end_tile)
uint8 MirrorSignalDirection (uint8 direction)
DisallowedRoadDirections MirrorOneWayRoadDirection (DisallowedRoadDirections drd)
void SwapSignalInfo (uint index)
void PasteSignals (uint index, TileIndex tile)
 This function pastes signals for a given index.
void PasteLandscape (TileIndex tile)
 This function pastes landscape.
void TerrainNeededAroundTile (TileIndex tindex, TileIndex bindex)
 Indicates this tile needs to be terraformed, in order to restore some building.
int8 ClampToRight (TileIndex index, int8 baseh, int8 h_tile)
 This function calculates the height, the given tile will have, after the neighbour(right) tile is restored.
int8 ClampToUp (TileIndex index, int8 baseh, int8 h_tile, int32 size_x)
 This function calculates the height, the given tile will have, after the neighbour(upper) tile is restored.
FORCEINLINE void SetWidth (uint32 width)
FORCEINLINE void SetHeight (uint32 height)

Private Attributes

uint32 m_width
uint32 m_height
StringID error_str
char * error_msg
CommandCost m_costs
 Stores the costs needed for template paste - estimate.
int8 * m_heightmap
 Storage space for copied area TODO: Convert to struct (saveload...).
uint8 * m_terrain_needed
 2Bit needed
uint8 * m_tiletype
 8Bit needed
uint8 * m_railroad
 8Bit needed
uint16 * m_signals
 15Bit needed

Detailed Description

Definition at line 14 of file copy_paste.h.


Member Function Documentation

int8 CopyPaste::ClampToRight ( TileIndex  index,
int8  baseh,
int8  h_tile 
) [private]

This function calculates the height, the given tile will have, after the neighbour(right) tile is restored.

In OTTD adjacent tiles may only differ in height by 1 level.

Definition at line 477 of file copy_paste.cpp.

References GetHeight().

Referenced by PasteLandscape().

int8 CopyPaste::ClampToUp ( TileIndex  index,
int8  baseh,
int8  h_tile,
int32  size_x 
) [private]

This function calculates the height, the given tile will have, after the neighbour(upper) tile is restored.

In OTTD adjacent tiles may only differ in height by 1 level.

Definition at line 495 of file copy_paste.cpp.

References GetHeight().

Referenced by PasteLandscape().

void CopyPaste::ClearCopyArrays (  ) 

Clears content of copy buffers for current width/height, but does NOT reset width/height.

Clears the Arrays which store the copied area.

Definition at line 87 of file copy_paste.cpp.

References m_heightmap, m_railroad, m_signals, m_terrain_needed, and m_tiletype.

Referenced by AllocateMapArray().

void CopyPaste::CopyArea ( TileIndex  end,
TileIndex  start 
)
void CopyPaste::CP_DoCommand ( TileIndex  tile,
uint32  p1,
uint32  p2,
CommandCallback callback,
uint32  cmd 
) [private]

Special DoCommand for CopyPaste.

DoCommand for Copy&Paste.

If shift is pressed, a cost-estimate is displayed instead of executing the paste.

If we are in multiplayer the pasting is redirected to the command-queue, which delays execution, to prevent overflowing the network connection.

Definition at line 234 of file copy_paste.cpp.

References _networking, _shift_pressed, CommandCost::AddCost(), CopyPasteCommandQueue::CopyPasteQueueCommand(), DC_QUERY_COST, DoCommand(), DoCommandP(), CommandCost::Failed(), and m_costs.

Referenced by CP_RaiseLowerLand().

void CopyPaste::CP_RaiseLowerLand ( TileIndex  tile,
int  mode 
) [private]
Parameters:
tile The Tile to operate on
mode true means Raise, false means Lower

Definition at line 258 of file copy_paste.cpp.

References CMD_MSG, CMD_TERRAFORM_LAND, and CP_DoCommand().

Referenced by PasteLandscape().

void CopyPaste::internal_PasteArea ( TileIndex  tile  )  [private]
bool CopyPaste::IsSomethingCopied (  ) 

Returns if something is in our copy buffer.

Returns if something is currently copied.

Definition at line 80 of file copy_paste.cpp.

References GetHeight().

Referenced by internal_PasteArea(), CopyPasteWindow::OnClick(), and CopyPasteWindow::OnPaint().

void CopyPaste::PasteArea ( TileIndex  tile  ) 

Paste copied content onto map, taking care of multiplayer/singleplayer environment.

Safe Paste Command.

Checks CopyPasteCommandQueue-Size in network games

Definition at line 724 of file copy_paste.cpp.

References _settings_client, GUISettings::cp_paste_speed, ClientSettings::gui, internal_PasteArea(), INVALID_STRING_ID, ShowErrorMessage(), TILE_SIZE, TileX(), TileY(), and WL_ERROR.

Referenced by CopyPasteWindow::OnPlaceObject().

void CopyPaste::TerrainNeededAroundTile ( TileIndex  tindex,
TileIndex  bindex 
) [private]

Indicates this tile needs to be terraformed, in order to restore some building.

Bit 0 indicates this tile is needed for terraforming, but is not directly build on. Bit 1 indicates this tile is beeing built on.

Definition at line 740 of file copy_paste.cpp.

References m_terrain_needed, and SetBit().

Referenced by CopyArea().


Field Documentation

int8* CopyPaste::m_heightmap [private]

Storage space for copied area TODO: Convert to struct (saveload...).

| Move terrain needed into this...

Definition at line 36 of file copy_paste.h.

Referenced by AllocateMapArray(), ClearCopyArrays(), CopyArea(), RotateSelectionCCW(), RotateSelectionCW(), and SaveLoadTemplate().


The documentation for this class was generated from the following files: