summaryrefslogtreecommitdiff
path: root/src/waypoint.cpp
blob: acfda8334102bb1160bcffe096ba35ff167648bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* $Id$ */

/** @file waypoint.cpp Handling of waypoints. */

#include "stdafx.h"

#include "strings_type.h"
#include "rail.h"
#include "station_base.h"
#include "town.h"
#include "waypoint.h"
#include "window_func.h"
#include "newgrf_station.h"
#include "order_func.h"
#include "core/pool_func.hpp"

WaypointPool _waypoint_pool("Waypoint");
INSTANTIATE_POOL_METHODS(Waypoint)

/**
 * Update all signs
 */
void UpdateAllWaypointVirtCoords()
{
	Waypoint *wp;

	FOR_ALL_WAYPOINTS(wp) {
		wp->UpdateVirtCoord();
	}
}

/**
 * Daily loop for waypoints
 */
void WaypointsDailyLoop()
{
	Waypoint *wp;

	/* Check if we need to delete a waypoint */
	FOR_ALL_WAYPOINTS(wp) {
		if (wp->delete_ctr != 0 && --wp->delete_ctr == 0) delete wp;
	}
}

/**
 * Draw a waypoint
 * @param x coordinate
 * @param y coordinate
 * @param stat_id station id
 * @param railtype RailType to use for
 */
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
{
	x += 33;
	y += 17;

	if (!DrawStationTile(x, y, railtype, AXIS_X, STAT_CLASS_WAYP, stat_id)) {
		DrawDefaultWaypointSprite(x, y, railtype);
	}
}

Waypoint::~Waypoint()
{
	if (CleaningPool()) return;
	DeleteWindowById(WC_WAYPOINT_VIEW, this->index);
	RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, this->index);

	this->sign.MarkDirty();
}

/**
 * Assign a station spec to this waypoint.
 * @param index the index of the spec from the waypoint specs
 */
void Waypoint::AssignStationSpec(uint index)
{
	free(this->speclist);

	const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, index);

	if (statspec != NULL) {
		this->speclist = MallocT<StationSpecList>(1);
		this->speclist->spec = statspec;
		this->speclist->grfid = statspec->grffile->grfid;
		this->speclist->localidx = statspec->localidx;
		this->num_specs = 1;
	} else {
		this->speclist = NULL;
		this->num_specs = 0;
	}
}

void InitializeWaypoints()
{
	_waypoint_pool.CleanPool();
}