forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimfab.h
353 lines (272 loc) · 8.07 KB
/
simfab.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
* simfab.h
*
* Copyright (c) 1997 - 2001 Hansjörg Malthaner
*
* This file is part of the Simutrans project and may not be used
* in other projects without written permission of the author.
*/
#ifndef simfab_h
#define simfab_h
#include "simware.h"
#include "dataobj/koord3d.h"
#include "dataobj/translator.h"
#include "tpl/slist_tpl.h"
#include "tpl/vector_tpl.h"
#include "tpl/array_tpl.h"
#include "besch/fabrik_besch.h"
#include "halthandle_t.h"
#include "simworld.h"
// Fabrik
class haltestelle_t;
class spieler_t;
class stadt_t;
class stringhashtable_t;
class raucher_t;
// production happens in every second
#define PRODUCTION_DELTA_T (1024)
// error of shifting
#define BASEPRODSHIFT (8)
// base production=1 is 16 => shift 4
#define MAX_PRODBASE_SHIFT (4)
// up to this distance, factories will be connected to their towns ...
#define CONNECT_TO_TOWN_SQUARE_DISTANCE 5000
/**
* Eine Klasse für Fabriken in Simutrans. Fabriken produzieren und
* verbrauchen Waren und beliefern nahe Haltestellen.
*
* Die Abfragefunktionen liefern -1 wenn eine Ware niemals
* hergestellt oder verbraucht wird, 0 wenn gerade nichts
* hergestellt oder verbraucht wird und > 0 sonst
* (entspricht Vorrat/Verbrauch).
*
* @date 1998
* @see haltestelle_t
* @author Hj. Malthaner
* @version $Revision: 1.21 $
*/
class fabrik_t
{
public:
/**
* Konstanten
* @author Hj. Malthaner
*/
enum { precision_bits = 10, old_precision_bits = 10 };
private:
/**
* Die möglichen Lieferziele
* @author Hj. Malthaner
*/
vector_tpl <koord> lieferziele;
uint32 last_lieferziel_start;
/**
* suppliers to this factry
* @author hsiegeln
*/
vector_tpl <koord> suppliers;
/**
* Die erzeugten waren auf die Haltestellen verteilen
* @author Hj. Malthaner
*/
void verteile_waren(const uint32 produkt);
/* still needed for the info dialog; otherwise useless
*/
slist_tpl<stadt_t *> arbeiterziele;
spieler_t *besitzer_p;
karte_t *welt;
const fabrik_besch_t *besch;
raucher_t *raucher;
/**
* Bauposition gedreht?
* @author V.Meyer
*/
uint8 rotate;
/**
* produktionsgrundmenge
* @author Hj. Malthaner
*/
sint32 prodbase;
/**
* multiplikator für die Produktionsgrundmenge
* @author Hj. Malthaner
*/
sint32 prodfaktor;
/**
* pointer auf das einganslagerfeld
* @author Hj. Malthaner
*/
vector_tpl<ware_t> *eingang;
/**
* pointer auf das ausgangslagerfeld
* @author Hj. Malthaner
*/
vector_tpl<ware_t> *ausgang;
/**
* bisherige abgabe in diesem monat pro ware
* @author Hj. Malthaner
*/
array_tpl<sint32> abgabe_sum;
/**
* abgabe im letzten monat pro ware
* @author Hj. Malthaner
*/
array_tpl<sint32> abgabe_letzt;
/**
* Zeitakkumulator für Produktion
* @author Hj. Malthaner
*/
sint32 delta_sum;
uint32 total_input, total_output;
uint8 status;
void recalc_factory_status();
public:
static fabrik_t * gib_fab(const karte_t *welt, const koord pos);
/**
* @return vehicle description object
* @author Hj. Malthaner
*/
const fabrik_besch_t *gib_besch() const {return besch; }
/**
* @author hsiegeln
*/
void laden_abschliessen();
/* check, if the coordinate belongs to this factory
* @author prissi
*/
bool is_fabrik( koord check );
/* check, if the coordinate belongs to this factory
* @author prissi
*/
bool is_fabrik( koord check, koord extent );
/**
* Die Koordinate (Position) der fabrik
* @author Hj. Malthaner
*/
koord3d pos;
void link_halt(halthandle_t halt);
void unlink_halt(halthandle_t halt);
const vector_tpl<koord>& gib_lieferziele() const { return lieferziele; }
const vector_tpl<koord>& get_suppliers() const { return suppliers; }
/* workers origin only used for info dialog purposes; otherwise useless ...
* @author Hj. Malthaner/prissi
*/
void add_arbeiterziel(stadt_t *stadt);
void rem_arbeiterziel(stadt_t *stadt);
const slist_tpl<stadt_t*>& gib_arbeiterziele() const { return arbeiterziele; }
/**
* Fügt ein neues Lieferziel hinzu
* @author Hj. Malthaner
*/
void add_lieferziel(koord ziel);
void rem_lieferziel(koord pos);
/**
* adds a supplier
* @author Hj. Malthaner
*/
void add_supplier(koord pos);
void rem_supplier(koord pos);
/**
* Used while loading a saved game
* @author Hj. Malthaner
*/
fabrik_t(karte_t *welt, loadsave_t *file);
fabrik_t(karte_t *welt, koord3d pos, spieler_t *sp, const fabrik_besch_t *fabesch);
~fabrik_t();
/**
* @return menge der ware typ
* -1 wenn typ nicht produziert wird
* sonst die gelagerte menge
*/
sint32 vorrat_an(const ware_besch_t *ware); // Vorrat von Warentyp
/**
* @return 1 wenn verbrauch,
* 0 wenn Produktionsstopp,
* -1 wenn Ware nicht verarbeitet wird
*/
sint32 verbraucht(const ware_besch_t *); // Nimmt fab das an ??
sint32 hole_ab(const ware_besch_t *, sint32 menge ); // jemand will waren abholen
sint32 liefere_an(const ware_besch_t *, sint32 menge);
sint32 gib_abgabe_letzt(sint32 t) { return abgabe_letzt[t]; }
void step(long delta_t); // fabrik muss auch arbeiten
void neuer_monat();
const char *gib_name() const { return besch ? translator::translate(besch->gib_name()) : "unnamed"; }
sint32 gib_kennfarbe() const { return besch ? besch->gib_kennfarbe() : 0; }
spieler_t *gib_besitzer() const { return welt->lookup(pos) ? welt->lookup(pos)->first_obj()->gib_besitzer() : NULL; }
void info(cbuffer_t & buf);
void rdwr(loadsave_t *file);
inline koord3d gib_pos() const { return pos; }
/**
* Die Menge an Produzierter Ware je Zeitspanne PRODUCTION_DELTA_T
*
* @author Hj. Malthaner
*/
uint32 produktion(uint32 produkt) const;
/**
* Die maximal produzierbare Menge je Monat
*
* @author Hj. Malthaner
*/
sint32 max_produktion() const;
/**
* gibt eine NULL-Terminierte Liste von Fabrikpointern zurück
*
* @author Hj. Malthaner
*/
static vector_tpl<fabrik_t *> & sind_da_welche(karte_t *welt, koord min, koord max);
/**
* gibt true zurueck wenn sich ein fabrik im feld befindet
*
* @author Hj. Malthaner
*/
static bool ist_da_eine(karte_t *welt, koord min, koord max);
static bool ist_bauplatz(karte_t *welt, koord pos, koord groesse, bool water, climate_bits cl);
// hier die methoden zum parametrisieren der Fabrik
/**
* Baut die Gebäude für die Fabrik
*
* @author Hj. Malthaner, V. Meyer
*/
void baue(sint32 rotate, bool clear);
/**
* setzt die Eingangswarentypen
*
* @author Hj. Malthaner
*/
void set_eingang(vector_tpl<ware_t> * typen);
const vector_tpl<ware_t>* gib_eingang() const { return eingang; }
/**
* setzt die Ausgangsswarentypen
*
* @author Hj. Malthaner
*/
void set_ausgang(vector_tpl<ware_t> * typen);
const vector_tpl<ware_t>* gib_ausgang() const { return ausgang; }
/**
* Produktionsgrundmenge
* @author Hj. Malthaner
*/
void set_prodbase(sint32 i) { prodbase = i; }
sint32 get_prodbase(void) { return prodbase; }
/**
* Produktionsmultiplikator
* @author Hj. Malthaner
*/
void set_prodfaktor(sint32 i) { prodfaktor = (i < 16 ? 16 : i); }
sint32 get_prodfaktor(void) const { return prodfaktor; }
/* prissi: returns the status of the current factory, as well as output */
enum { bad, medium, good, inactive, nothing };
static unsigned status_to_color[5];
unsigned calc_factory_status(unsigned long* input, unsigned long* output) const
{
if (input != NULL) *input = total_input;
if (output != NULL) *output = total_output;
return status;
}
/**
* Crossconnects all factories
* @author Hj. Malthaner
*/
void add_all_suppliers();
};
#endif