2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file waypoint.cpp Handling of waypoints. */
|
2007-04-06 05:10:19 +01:00
|
|
|
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2009-03-13 23:48:07 +00:00
|
|
|
#include "strings_type.h"
|
2007-12-25 23:42:52 +00:00
|
|
|
#include "rail.h"
|
2008-03-31 01:06:17 +01:00
|
|
|
#include "station_base.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "town.h"
|
|
|
|
#include "waypoint.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-03-31 07:42:26 +01:00
|
|
|
#include "newgrf_station.h"
|
2009-03-13 23:48:07 +00:00
|
|
|
#include "order_func.h"
|
2009-05-22 16:13:50 +01:00
|
|
|
#include "core/pool_func.hpp"
|
2005-03-24 17:03:37 +00:00
|
|
|
|
2009-05-22 16:13:50 +01:00
|
|
|
WaypointPool _waypoint_pool("Waypoint");
|
|
|
|
INSTANTIATE_POOL_METHODS(Waypoint)
|
2005-03-24 17:03:37 +00:00
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/**
|
|
|
|
* Daily loop for waypoints
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void WaypointsDailyLoop()
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
/* Check if we need to delete a waypoint */
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2009-07-16 21:15:28 +01:00
|
|
|
if (wp->delete_ctr != 0 && --wp->delete_ctr == 0) delete wp;
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-06 05:10:19 +01:00
|
|
|
/**
|
|
|
|
* Draw a waypoint
|
|
|
|
* @param x coordinate
|
|
|
|
* @param y coordinate
|
|
|
|
* @param stat_id station id
|
|
|
|
* @param railtype RailType to use for
|
|
|
|
*/
|
2005-10-16 10:13:04 +01:00
|
|
|
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
2006-05-06 21:48:40 +01:00
|
|
|
if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
|
2009-07-18 11:01:31 +01:00
|
|
|
StationPickerDrawSprite(x, y, STATION_WAYPOINT, railtype, INVALID_ROADTYPE, AXIS_X);
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-02 13:22:40 +01:00
|
|
|
Waypoint::~Waypoint()
|
|
|
|
{
|
2007-08-05 22:20:55 +01:00
|
|
|
if (CleaningPool()) return;
|
2008-08-21 03:19:31 +01:00
|
|
|
DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
|
2007-08-02 13:22:40 +01:00
|
|
|
RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);
|
|
|
|
|
2009-07-08 09:30:35 +01:00
|
|
|
this->sign.MarkDirty();
|
2007-08-02 13:22:40 +01:00
|
|
|
}
|
|
|
|
|
2009-07-17 21:21:24 +01:00
|
|
|
/**
|
|
|
|
* Assign a station spec to this waypoint.
|
|
|
|
* @param index the index of the spec from the waypoint specs
|
|
|
|
*/
|
|
|
|
void Waypoint::AssignStationSpec(uint index)
|
|
|
|
{
|
2009-07-17 21:40:29 +01:00
|
|
|
free(this->speclist);
|
|
|
|
|
2009-07-17 21:21:24 +01:00
|
|
|
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, index);
|
|
|
|
|
|
|
|
if (statspec != NULL) {
|
2009-07-17 21:40:29 +01:00
|
|
|
this->speclist = MallocT<StationSpecList>(1);
|
|
|
|
this->speclist->spec = statspec;
|
|
|
|
this->speclist->grfid = statspec->grffile->grfid;
|
|
|
|
this->speclist->localidx = statspec->localidx;
|
|
|
|
this->num_specs = 1;
|
2009-07-17 21:21:24 +01:00
|
|
|
} else {
|
2009-07-17 21:40:29 +01:00
|
|
|
this->speclist = NULL;
|
|
|
|
this->num_specs = 0;
|
2009-07-17 21:21:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeWaypoints()
|
2005-03-24 17:03:37 +00:00
|
|
|
{
|
2009-05-22 16:13:50 +01:00
|
|
|
_waypoint_pool.CleanPool();
|
2005-03-24 17:03:37 +00:00
|
|
|
}
|