forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabrik_besch.h
298 lines (248 loc) · 8.27 KB
/
fabrik_besch.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
* Copyright (c) 1997 - 2002 by Volker Meyer & Hansjörg Malthaner
*
* This file is part of the Simutrans project under the artistic licence.
*/
#ifndef __FABRIK_BESCH_H
#define __FABRIK_BESCH_H
#include "obj_besch.h"
#include "haus_besch.h"
#include "skin_besch.h"
#include "ware_besch.h"
#include "../dataobj/koord.h"
#include "../tpl/weighted_vector_tpl.h"
class checksum_t;
/* Knightly : this besch will store data specific to each class of fields
* Fields are xref'ed from skin_besch_t
*/
class field_class_besch_t : public obj_besch_t {
friend class factory_field_class_reader_t;
friend class factory_field_group_reader_t; // Knightly : this is a special case due to besch restructuring
private:
uint8 snow_image; // 0 or 1 for snow
uint16 production_per_field;
uint16 storage_capacity;
uint16 spawn_weight;
public:
skin_besch_t const* get_bilder() const { return get_child<skin_besch_t>(0); }
const char *get_name() const { return get_bilder()->get_name(); }
const char *get_copyright() const { return get_bilder()->get_copyright(); }
uint8 has_snow_image() const { return snow_image; }
uint16 get_field_production() const { return production_per_field; }
uint16 get_storage_capacity() const { return storage_capacity; }
uint16 get_spawn_weight() const { return spawn_weight; }
void calc_checksum(checksum_t *chk) const;
};
// Knightly : this besch now only contains common, shared data regarding fields
class field_group_besch_t : public obj_besch_t {
friend class factory_field_group_reader_t;
private:
uint16 probability; // between 0 ...10000
uint16 max_fields; // maximum number of fields around a single factory
uint16 min_fields; // number of fields to start with
uint16 start_fields; // spawn between min and start_fields fields
uint16 field_classes; // number of field classes
weighted_vector_tpl<uint16> field_class_indices;
public:
// fills the array, is only called once during alles_geladen() after resolve xrefs
void init_field_class_indices()
{
if( field_classes>0 ) {
field_class_indices.clear();
field_class_indices.resize( field_classes );
for( uint16 i=0 ; i<field_classes ; ++i ) {
field_class_indices.append( i, get_field_class(i)->get_spawn_weight() );
}
}
}
uint16 get_probability() const { return probability; }
uint16 get_max_fields() const { return max_fields; }
uint16 get_min_fields() const { return min_fields; }
uint16 get_start_fields() const { return start_fields; }
uint16 get_field_class_count() const { return field_classes; }
field_class_besch_t const* get_field_class(uint16 const idx) const { return idx < field_classes ? get_child<field_class_besch_t>(idx) : 0; }
const weighted_vector_tpl<uint16> &get_field_class_indices() const { return field_class_indices; }
void calc_checksum(checksum_t *chk) const;
};
/*
* Autor:
* Volker Meyer
*
* Beschreibung:
* Der Rauch einer Fabrik verweist auf eine allgemeine Rauchbeschreibung
*
* Kindknoten:
* 0 SKin
*/
class rauch_besch_t : public obj_besch_t {
friend class factory_smoke_reader_t;
private:
koord pos_off;
koord xy_off;
sint16 zeitmaske;
public:
const char *get_name() const { return get_bilder()->get_name(); }
const char *get_copyright() const { return get_bilder()->get_copyright(); }
skin_besch_t const* get_bilder() const { return get_child<skin_besch_t>(0); }
// get the tile with the smoke
koord get_pos_off( koord size, uint8 rotation) const {
switch( rotation%4 ) {
case 1: return koord( size.y-pos_off.y, pos_off.x );
case 2: return koord( size.x-pos_off.x, size.y-pos_off.y );
case 3: return koord( pos_off.y, size.x-pos_off.x );
}
return pos_off;
}
// offset in pixel (depends on OBJECT_OFFSET_STEPS==16)
koord get_xy_off(uint8 rotation) const {
switch( rotation%4 ) {
case 1: return koord( 0, xy_off.y+xy_off.x/2 );
case 2: return koord( -xy_off.x, xy_off.y );
case 3: return koord( 0, xy_off.y-xy_off.x/2 );
}
return xy_off;
}
sint16 get_zeitmaske() const { return zeitmaske; }
};
/*
* Autor:
* Volker Meyer
*
* Beschreibung:
* Ein Verbrauchsgut einer Fabriktyps
*
* Kindknoten:
* 0 Ware
*/
class fabrik_lieferant_besch_t : public obj_besch_t {
friend class factory_supplier_reader_t;
private:
uint16 kapazitaet;
uint16 anzahl;
uint16 verbrauch;
public:
ware_besch_t const* get_ware() const { return get_child<ware_besch_t>(0); }
int get_kapazitaet() const { return kapazitaet; }
int get_anzahl() const { return anzahl; }
int get_verbrauch() const { return verbrauch; }
void calc_checksum(checksum_t *chk) const;
};
/*
* Autor:
* Volker Meyer
*
* Beschreibung:
* Eine Produktion eines Fabriktyps
*
* Kindknoten:
* 0 Ware
*/
class fabrik_produkt_besch_t : public obj_besch_t {
friend class factory_product_reader_t;
private:
uint16 kapazitaet;
/**
* How much of this product is derived from one unit of factory
* production? 256 means 1.0
* @author Hj. Malthaner
*/
uint16 faktor;
public:
ware_besch_t const* get_ware() const { return get_child<ware_besch_t>(0); }
uint32 get_kapazitaet() const { return kapazitaet; }
uint32 get_faktor() const { return faktor; }
void calc_checksum(checksum_t *chk) const;
};
/*
* Autor:
* Volker Meyer
*
* Beschreibung:
* Jetzt endlich die Ganze Fabrik
*
* Kindknoten:
* 0 Haus
* 1 Rauch
* 2 Lieferant 1
* 3 Lieferant 2
* ... ...
* n+1 Lieferant n
* n+2 Produkt 1
* n+3 Produkt 2
* ... ...
*/
class fabrik_besch_t : public obj_besch_t {
friend class factory_reader_t;
public:
enum site_t { Land, Wasser, Stadt };
private:
site_t platzierung;
uint16 produktivitaet;
uint16 bereich;
uint16 gewichtung; // Wie wahrscheinlich soll der Bau sein?
uint8 kennfarbe;
uint16 lieferanten;
uint16 produkte;
uint8 fields; // only if there are any ...
uint16 pax_level;
bool electricity_producer;
uint16 expand_probability;
uint16 expand_minimum;
uint16 expand_range;
uint16 expand_times;
uint16 electric_boost;
uint16 pax_boost;
uint16 mail_boost;
uint16 electric_amount;
uint16 pax_demand;
uint16 mail_demand;
public:
/*
* Name und Copyright sind beim Gebäude gespeichert!
*/
const char *get_name() const { return get_haus()->get_name(); }
const char *get_copyright() const { return get_haus()->get_copyright(); }
haus_besch_t const* get_haus() const { return get_child<haus_besch_t>(0); }
rauch_besch_t const* get_rauch() const { return get_child<rauch_besch_t>(1); }
// we must take care, for the case of no producer/consumer
const fabrik_lieferant_besch_t *get_lieferant(int i) const
{
return 0 <= i && i < lieferanten ? get_child<fabrik_lieferant_besch_t>(2 + i) : 0;
}
const fabrik_produkt_besch_t *get_produkt(int i) const
{
return 0 <= i && i < produkte ? get_child<fabrik_produkt_besch_t>(2 + lieferanten + i) : 0;
}
const field_group_besch_t *get_field_group() const {
if(!fields) {
return NULL;
}
return get_child<field_group_besch_t>(2 + lieferanten + produkte);
}
bool is_consumer_only() const { return produkte == 0; }
bool is_producer_only() const { return lieferanten == 0; }
int get_lieferanten() const { return lieferanten; }
uint get_produkte() const { return produkte; }
/* where to built */
site_t get_platzierung() const { return platzierung; }
int get_gewichtung() const { return gewichtung; }
uint8 get_kennfarbe() const { return kennfarbe; }
void set_produktivitaet(int p) { produktivitaet=p; }
int get_produktivitaet() const { return produktivitaet; }
int get_bereich() const { return bereich; }
/* level for post and passenger generation */
int get_pax_level() const { return pax_level; }
int is_electricity_producer() const { return electricity_producer; }
uint16 get_expand_probability() const { return expand_probability; }
uint16 get_expand_minumum() const { return expand_minimum; }
uint16 get_expand_range() const { return expand_range; }
uint16 get_expand_times() const { return expand_times; }
uint16 get_electric_boost() const { return electric_boost; }
uint16 get_pax_boost() const { return pax_boost; }
uint16 get_mail_boost() const { return mail_boost; }
uint16 get_electric_amount() const { return electric_amount; }
uint16 get_pax_demand() const { return pax_demand; }
uint16 get_mail_demand() const { return mail_demand; }
void calc_checksum(checksum_t *chk) const;
};
#endif