summaryrefslogtreecommitdiff
path: root/src/departures_type.h
blob: cb06b144ffb83f3cb7b5b70474cba65907b0eaf3 (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
97
98
99
100
101
/* $Id: departures_type.h $ */

/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file departures_type.h Types related to departures. */

#ifndef DEPARTURES_TYPE_H
#define DEPARTURES_TYPE_H

#include "station_base.h"
#include "order_base.h"
#include "vehicle_base.h"

/** Whether or not a vehicle has arrived for a departure. */
typedef enum {
	D_TRAVELLING = 0,
	D_ARRIVED = 1,
	D_CANCELLED = 2,
} DepartureStatus;

/** The type of departures. */
typedef enum {
	D_DEPARTURE = 0,
	D_ARRIVAL = 1,
} DepartureType;

typedef struct CallAt {
	StationID station;
	DateTicks scheduled_date;

	CallAt(const StationID& s) : station(s), scheduled_date(0) { }
	CallAt(const StationID& s, const DateTicks& t) : station(s), scheduled_date(t) { }
	CallAt(const CallAt& c) : station(c.station), scheduled_date(c.scheduled_date) { }

	inline bool operator==(const CallAt& c) const {
		return this->station == c.station;
	}

	inline bool operator!=(const CallAt& c) const {
		return this->station != c.station;
	}

	inline bool operator>=(const CallAt& c) const {
		return this->station == c.station &&
				this->scheduled_date != 0 &&
				c.scheduled_date != 0 &&
				this->scheduled_date >= c.scheduled_date;
	}

	CallAt& operator=(const CallAt& c) {
		this->station = c.station;
		this->scheduled_date = c.scheduled_date;
		return *this;
	}

	inline bool operator==(StationID s) const {
		return this->station == s;
	}
} CallAt;

/** A scheduled departure. */
typedef struct Departure {
	DateTicks scheduled_date;              ///< The date this departure is scheduled to finish on (i.e. when the vehicle leaves the station)
	DateTicks lateness;                    ///< How delayed the departure is expected to be
	CallAt terminus;                    ///< The station at which the vehicle will terminate following this departure
	StationID via;                         ///< The station the departure should list as going via
	SmallVector<CallAt, 32> calling_at; ///< The stations both called at and unloaded at by the vehicle after this departure before it terminates
	DepartureStatus status;                ///< Whether the vehicle has arrived yet for this departure
	DepartureType type;                    ///< The type of the departure (departure or arrival)
	const Vehicle *vehicle;                ///< The vehicle performing this departure
	const Order *order;                    ///< The order corresponding to this departure
	Departure() : terminus(INVALID_STATION), via(INVALID_STATION), calling_at(), vehicle(NULL) { }
	~Departure()
	{
		calling_at.Reset();
	}

    inline bool operator==(const Departure& d) const {
        if (this->calling_at.Length() != d.calling_at.Length()) return false;

        for (uint i = 0; i < this->calling_at.Length(); ++i) {
            if (*(this->calling_at.Get(i)) != *(d.calling_at.Get(i))) return false;
        }

        return
            (this->scheduled_date / DATE_UNIT_SIZE) == (d.scheduled_date / DATE_UNIT_SIZE) &&
            this->vehicle->type == d.vehicle->type &&
            this->via == d.via &&
            this->type == d.type
            ;
    }
} Departure;

typedef SmallVector<Departure*, 32> DepartureList;

#endif /* DEPARTURES_TYPE_H */