forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsimware.h
169 lines (134 loc) · 4.39 KB
/
simware.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* This file is part of the Simutrans-Extended project under the Artistic License.
* (see LICENSE.txt)
*/
#ifndef SIMWARE_H
#define SIMWARE_H
#include "halthandle_t.h"
#include "dataobj/koord.h"
#include "descriptor/goods_desc.h"
class goods_manager_t;
class karte_t;
class player_t;
/** Class to handle goods packets (and their destinations) */
class ware_t
{
friend class goods_manager_t;
private:
/// private lookup table to speedup
static const goods_desc_t *index_to_desc[256];
public:
/// amount of goods
uint32 menge;
/// type of good, used as index into index_to_desc
uint32 index: 8;
// Necessary to determine whether to book
// jobs taken on arrival.
bool is_commuting_trip : 1;
/// The class of mail/passengers. Not used for goods.
uint8 g_class;
/// The percentage of the maximum tolerable journey time for
/// any given level of comfort that this packet of passengers
/// (if passengers) will travel in a lower class of accommodation
/// than available on a convoy.
uint16 comfort_preference_percentage = 500;
private:
/**
* Handle of target station.
*/
halthandle_t ziel;
/**
* Handle of station, where the packet has to leave convoy.
*/
halthandle_t zwischenziel;
/**
* A handle to the ultimate origin.
* @author: jamespetts
*/
halthandle_t origin;
/**
* A handle to the previous transfer
* for the purposes of distance calculation
* @author: jamespetts, November 2011
*/
halthandle_t last_transfer;
/**
* Target position (factory, etc)
*/
koord zielpos;
public:
// The time at which this packet arrived at the current station
// @author: jamespetts
sint64 arrival_time;
private:
/**
* Update target (zielpos) for factory-going goods (after loading or rotating)
*/
void update_factory_target();
public:
inline const halthandle_t &get_ziel() const { return ziel; }
void set_ziel(const halthandle_t &ziel) { this->ziel = ziel; }
inline const halthandle_t &get_zwischenziel() const { return zwischenziel; }
inline halthandle_t &access_zwischenziel() { return zwischenziel; }
void set_zwischenziel(const halthandle_t &zwischenziel) { this->zwischenziel = zwischenziel; }
koord get_zielpos() const { return zielpos; }
void set_zielpos(const koord zielpos) { this->zielpos = zielpos; }
void reset() { menge = 0; ziel = zwischenziel = origin = last_transfer = halthandle_t(); zielpos = koord::invalid; }
ware_t();
ware_t(const goods_desc_t *typ);
ware_t(const goods_desc_t *typ, halthandle_t origin);
ware_t(loadsave_t *file);
/// @returns the non-translated name of the ware.
inline const char *get_name() const { return get_desc()->get_name(); }
inline const char *get_mass() const { return get_desc()->get_mass(); }
inline uint8 get_catg() const { return get_desc()->get_catg(); }
inline uint8 get_index() const { return index; }
inline uint8 get_class() const { return g_class; }
inline void set_class(uint8 value) { g_class = value; }
//@author: jamespetts
inline halthandle_t get_origin() const { return origin; }
void set_origin(halthandle_t value) { origin = value; }
inline halthandle_t get_last_transfer() const { return last_transfer; }
void set_last_transfer(halthandle_t value) { last_transfer = value; }
inline const goods_desc_t* get_desc() const { return index_to_desc[index]; }
void set_desc(const goods_desc_t* type);
void rdwr(loadsave_t *file);
void finish_rd(karte_t *welt);
// find out the category ...
inline bool is_passenger() const { return index == 0; }
inline bool is_mail() const { return index == 1; }
inline bool is_freight() const { return index > 2; }
int operator==(const ware_t &w) {
return menge == w.menge &&
zwischenziel == w.zwischenziel &&
arrival_time == w.arrival_time &&
index == w.index &&
ziel == w.ziel &&
zielpos == w.zielpos &&
origin == w.origin &&
last_transfer == w.last_transfer &&
g_class == w.g_class;
}
bool can_merge_with(const ware_t &w)
{
return zwischenziel == w.zwischenziel &&
index == w.index &&
ziel == w.ziel &&
zielpos == w.zielpos &&
origin == w.origin &&
last_transfer == w.last_transfer &&
g_class == w.g_class;
}
bool operator <= (const ware_t &w)
{
// Used only for the binary heap
return arrival_time <= w.arrival_time;
}
int operator!=(const ware_t &w) { return !(*this == w); }
/**
* Adjust target coordinates.
* Must be called after factories have been rotated!
*/
void rotate90( sint16 y_size );
};
#endif