2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file waypoint.cpp Handling of waypoints. */
|
2007-04-06 06:10:19 +02:00
|
|
|
|
2005-03-24 18:03:37 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2009-03-14 00:48:07 +01:00
|
|
|
#include "strings_type.h"
|
2007-12-26 00:42:52 +01:00
|
|
|
#include "rail.h"
|
2008-03-31 02:06:17 +02:00
|
|
|
#include "station_base.h"
|
2005-03-24 18:03:37 +01:00
|
|
|
#include "town.h"
|
|
|
|
#include "waypoint.h"
|
2007-12-25 12:26:07 +01:00
|
|
|
#include "window_func.h"
|
2008-03-31 08:42:26 +02:00
|
|
|
#include "newgrf_station.h"
|
2008-04-07 01:49:45 +02:00
|
|
|
#include "oldpool_func.h"
|
2009-03-14 00:48:07 +01:00
|
|
|
#include "order_func.h"
|
2005-03-24 18:03:37 +01:00
|
|
|
|
2007-08-02 14:22:40 +02:00
|
|
|
DEFINE_OLD_POOL_GENERIC(Waypoint, Waypoint)
|
2005-03-24 18:03:37 +01:00
|
|
|
|
2007-04-06 06:10:19 +02:00
|
|
|
/**
|
|
|
|
* Update all signs
|
|
|
|
*/
|
2007-03-07 12:47:46 +01:00
|
|
|
void UpdateAllWaypointSigns()
|
2005-03-24 18:03:37 +01:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2006-08-22 17:33:35 +02:00
|
|
|
UpdateWaypointSign(wp);
|
2005-03-24 18:03:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-06 06:10:19 +02:00
|
|
|
/**
|
|
|
|
* Daily loop for waypoints
|
|
|
|
*/
|
2007-03-07 12:47:46 +01:00
|
|
|
void WaypointsDailyLoop()
|
2005-03-24 18:03:37 +01:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
/* Check if we need to delete a waypoint */
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2008-09-07 20:21:57 +02:00
|
|
|
if (wp->deleted != 0 && --wp->deleted == 0) delete wp;
|
2005-03-24 18:03:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-06 06:10:19 +02:00
|
|
|
/**
|
|
|
|
* This hacks together some dummy one-shot Station structure for a waypoint.
|
|
|
|
* @param tile on which to work
|
|
|
|
* @return pointer to a Station
|
|
|
|
*/
|
2005-06-24 14:38:35 +02:00
|
|
|
Station *ComposeWaypointStation(TileIndex tile)
|
2005-03-24 18:03:37 +01:00
|
|
|
{
|
|
|
|
Waypoint *wp = GetWaypointByTile(tile);
|
2007-01-19 17:01:43 +01:00
|
|
|
|
|
|
|
/* instead of 'static Station stat' use byte array to avoid Station's destructor call upon exit. As
|
|
|
|
* a side effect, the station is not constructed now. */
|
2007-01-19 23:41:50 +01:00
|
|
|
static byte stat_raw[sizeof(Station)];
|
2007-01-19 17:01:43 +01:00
|
|
|
static Station &stat = *(Station*)stat_raw;
|
2005-03-24 18:03:37 +01:00
|
|
|
|
|
|
|
stat.train_tile = stat.xy = wp->xy;
|
|
|
|
stat.town = GetTown(wp->town_index);
|
|
|
|
stat.build_date = wp->build_date;
|
|
|
|
|
|
|
|
return &stat;
|
|
|
|
}
|
|
|
|
|
2007-04-06 06:10:19 +02:00
|
|
|
/**
|
|
|
|
* Draw a waypoint
|
|
|
|
* @param x coordinate
|
|
|
|
* @param y coordinate
|
|
|
|
* @param stat_id station id
|
|
|
|
* @param railtype RailType to use for
|
|
|
|
*/
|
2005-10-16 11:13:04 +02:00
|
|
|
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
|
2005-03-24 18:03:37 +01:00
|
|
|
{
|
|
|
|
x += 33;
|
|
|
|
y += 17;
|
|
|
|
|
2006-05-06 22:48:40 +02:00
|
|
|
if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
|
2005-08-01 18:31:19 +02:00
|
|
|
DrawDefaultWaypointSprite(x, y, railtype);
|
2005-03-24 18:03:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-02 14:22:40 +02:00
|
|
|
Waypoint::Waypoint(TileIndex tile)
|
|
|
|
{
|
|
|
|
this->xy = tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
Waypoint::~Waypoint()
|
|
|
|
{
|
2008-01-12 20:58:06 +01:00
|
|
|
free(this->name);
|
2007-08-05 23:20:55 +02:00
|
|
|
|
|
|
|
if (CleaningPool()) return;
|
2008-08-21 04:19:31 +02:00
|
|
|
DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
|
2007-08-02 14:22:40 +02:00
|
|
|
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
|
|
|
|
|
|
|
|
RedrawWaypointSign(this);
|
2009-01-03 17:06:58 +01:00
|
|
|
this->xy = INVALID_TILE;
|
2007-08-02 14:22:40 +02:00
|
|
|
}
|
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void InitializeWaypoints()
|
2005-03-24 18:03:37 +01:00
|
|
|
{
|
2007-08-02 14:22:40 +02:00
|
|
|
_Waypoint_pool.CleanPool();
|
|
|
|
_Waypoint_pool.AddBlockToPool();
|
2005-03-24 18:03:37 +01:00
|
|
|
}
|