forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathway_reader.cc
186 lines (164 loc) · 5.07 KB
/
way_reader.cc
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* This file is part of the Simutrans project under the Artistic License.
* (see LICENSE.txt)
*/
#include <stdio.h>
#include "../../simdebug.h"
#include "../../utils/simstring.h"
#include "../way_desc.h"
#include "../intro_dates.h"
#include "../../bauer/wegbauer.h"
#include "way_reader.h"
#include "../obj_node_info.h"
#include "../../network/pakset_info.h"
void way_reader_t::register_obj(obj_desc_t *&data)
{
way_desc_t *desc = static_cast<way_desc_t *>(data);
way_builder_t::register_desc(desc);
// printf("...Weg %s geladen\n", desc->get_name());
obj_for_xref(get_type(), desc->get_name(), data);
checksum_t *chk = new checksum_t();
desc->calc_checksum(chk);
pakset_info_t::append(desc->get_name(), get_type(), chk);
}
bool way_reader_t::successfully_loaded() const
{
return way_builder_t::successfully_loaded();
}
obj_desc_t * way_reader_t::read_node(FILE *fp, obj_node_info_t &node)
{
ALLOCA(char, desc_buf, node.size);
way_desc_t *desc = new way_desc_t();
// Read data
fread(desc_buf, node.size, 1, fp);
char * p = desc_buf;
// old versions of PAK files have no version stamp.
// But we know, the higher most bit was always cleared.
int version = 0;
if(node.size == 0) {
// old node, version 0, compatibility code
desc->price = 10000;
desc->maintenance = 800;
desc->topspeed = 999;
desc->max_weight = 999;
desc->intro_date = DEFAULT_INTRO_DATE*12;
desc->retire_date = DEFAULT_RETIRE_DATE*12;
desc->wtyp = road_wt;
desc->styp = type_flat;
desc->draw_as_obj = false;
desc->number_of_seasons = 0;
}
else {
const uint16 v = decode_uint16(p);
version = v & 0x7FFF;
if(version==6) {
// version 6, now with axle load
desc->price = decode_uint32(p);
desc->maintenance = decode_uint32(p);
desc->topspeed = decode_uint32(p);
desc->max_weight = decode_uint32(p);
desc->intro_date = decode_uint16(p);
desc->retire_date = decode_uint16(p);
desc->axle_load = decode_uint16(p); // new
desc->wtyp = decode_uint8(p);
desc->styp = decode_uint8(p);
desc->draw_as_obj = decode_uint8(p);
desc->number_of_seasons = decode_sint8(p);
}
else if(version==4 || version==5) {
// Versioned node, version 4+5
desc->price = decode_uint32(p);
desc->maintenance = decode_uint32(p);
desc->topspeed = decode_uint32(p);
desc->max_weight = decode_uint32(p);
desc->intro_date = decode_uint16(p);
desc->retire_date = decode_uint16(p);
desc->wtyp = decode_uint8(p);
desc->styp = decode_uint8(p);
desc->draw_as_obj = decode_uint8(p);
desc->number_of_seasons = decode_sint8(p);
}
else if(version==3) {
// Versioned node, version 3
desc->price = decode_uint32(p);
desc->maintenance = decode_uint32(p);
desc->topspeed = decode_uint32(p);
desc->max_weight = decode_uint32(p);
desc->intro_date = decode_uint16(p);
desc->retire_date = decode_uint16(p);
desc->wtyp = decode_uint8(p);
desc->styp = decode_uint8(p);
desc->draw_as_obj = decode_uint8(p);
desc->number_of_seasons = 0;
}
else if(version==2) {
// Versioned node, version 2
desc->price = decode_uint32(p);
desc->maintenance = decode_uint32(p);
desc->topspeed = decode_uint32(p);
desc->max_weight = decode_uint32(p);
desc->intro_date = decode_uint16(p);
desc->retire_date = decode_uint16(p);
desc->wtyp = decode_uint8(p);
desc->styp = decode_uint8(p);
desc->draw_as_obj = false;
desc->number_of_seasons = 0;
}
else if(version == 1) {
// Versioned node, version 1
desc->price = decode_uint32(p);
desc->maintenance = decode_uint32(p);
desc->topspeed = decode_uint32(p);
desc->max_weight = decode_uint32(p);
uint32 intro_date= decode_uint32(p);
desc->intro_date = (intro_date/16)*12 + (intro_date%16);
desc->wtyp = decode_uint8(p);
desc->styp = decode_uint8(p);
desc->retire_date = DEFAULT_RETIRE_DATE*12;
desc->draw_as_obj = false;
desc->number_of_seasons = 0;
}
else {
dbg->fatal( "way_reader_t::read_node()", "Cannot handle too new node version %i", version );
}
}
// some internal corrections to pay for previous confusion with two waytypes
if(desc->wtyp==tram_wt) {
desc->styp = type_tram;
desc->wtyp = track_wt;
}
else if(desc->styp==5 && desc->wtyp==track_wt) {
desc->wtyp = monorail_wt;
desc->styp = type_flat;
}
else if(desc->wtyp==128) {
desc->wtyp = powerline_wt;
}
if(version<=2 && desc->wtyp==air_wt && desc->topspeed>=250) {
// runway!
desc->styp = type_runway;
}
if( version < 6 ) {
desc->axle_load = 9999;
}
// front images from version 5 on
desc->front_images = version > 4;
DBG_DEBUG("way_reader_t::read_node()",
"version=%d, price=%d, maintenance=%d, topspeed=%d, max_weight=%d, "
"wtype=%d, styp=%d, intro=%i/%i, retire=%i/%i, axle_load=%d, ding=%i, seasons=%i",
version,
desc->price,
desc->maintenance,
desc->topspeed,
desc->max_weight,
desc->wtyp,
desc->styp,
(desc->intro_date%12)+1,
desc->intro_date/12,
(desc->retire_date%12)+1,
desc->retire_date/12,
desc->axle_load,
desc->draw_as_obj,
desc->number_of_seasons);
return desc;
}