forked from jamespetts/simutrans-extended
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simfab.h
367 lines (290 loc) · 9.86 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* Copyright (c) 1997 - 2001 Hansjörg Malthaner
*
* This file is part of the Simutrans project under the artistic licence.
* (see licence.txt)
*/
#ifndef simfab_h
#define simfab_h
#include "dataobj/koord3d.h"
#include "dataobj/translator.h"
#include "tpl/slist_tpl.h"
#include "tpl/vector_tpl.h"
#include "besch/fabrik_besch.h"
#include "halthandle_t.h"
#include "simworld.h"
class spieler_t;
class stadt_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
// to prepare for 64 precision ...
class ware_production_t
{
private:
const ware_besch_t *type;
public:
const ware_besch_t* get_typ() const { return type; }
void set_typ(const ware_besch_t *t) { type=t; }
sint32 menge; // in internal untis shifted by precision (see produktion)
sint32 max;
sint32 abgabe_sum; // total this month (in units)
sint32 abgabe_letzt; // total last month (in units)
};
/**
* 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).
*
* A class of factories in Simutrans.
* Factories produce and consume goods and supplies near bus stops.
* The query functions return -1 if a product is never produced or consumed,
* 0 when nothing is manufactured or consumed and> 0 otherwise (equivalent to stocks / consumption).
* @date 1998
* @see haltestelle_t
* @author Hj. Malthaner
*/
class fabrik_t
{
public:
/**
* Konstanten
* @author Hj. Malthaner
*/
enum { precision_bits = 10, old_precision_bits = 10, precision_mask = 1023 };
private:
/**
* Die möglichen Lieferziele
*
* The possible delivery targets
* @author Hj. Malthaner
*/
vector_tpl <koord> lieferziele;
uint32 last_lieferziel_start;
/**
* suppliers to this factry
* @author hsiegeln
*/
vector_tpl <koord> suppliers;
/**
* fields of this factory (only for farms etc.)
* @author prissi
*/
vector_tpl <koord> fields;
/**
* Die erzeugten waren auf die Haltestellen verteilen
* The produced were distributed at the stops
* @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; //"possessive" (Google)
karte_t *welt;
const fabrik_besch_t *besch;
/**
* Bauposition gedreht?
* Building position turned?
* @author V.Meyer
*/
uint8 rotate;
/**
* produktionsgrundmenge
* "production fundamental set"
* @author Hj. Malthaner
*/
sint32 prodbase;
/**
* multiplikator für die Produktionsgrundmenge
* multiplier for the production of basic quantity
* @author Hj. Malthaner
*/
sint32 prodfaktor;
vector_tpl<ware_production_t> eingang; //< das einganslagerfeld ("in goose camp field" (!!) (Babelfish)
vector_tpl<ware_production_t> ausgang; //< das ausgangslagerfeld ("the output camp field") (Babelfish)
/**
* Zeitakkumulator für Produktion
* Time accumulator for production
* @author Hj. Malthaner
*/
sint32 delta_sum;
// true, if the factory did produce something in the last step
bool currently_producing;
// power that can be currently drawn from this station (or the amount delivered)
uint32 power;
uint32 total_input, total_output;
uint8 status;
/**
* Die Koordinate (Position) der fabrik
* @author Hj. Malthaner
*/
koord3d pos;
void recalc_factory_status();
// create some smoke on the map
void smoke() const;
/**
* increase the amount for a fixed time PRODUCTION_DELTA_T
* @author Hj. Malthaner
*/
uint32 produktion(uint32 produkt) const;
// This is the city within whose city limits the factory is located.
// NULL if it is outside a city. This is re-checked monthly.
//@author: jamespetts
stadt_t* city;
public:
fabrik_t(karte_t *welt, loadsave_t *file);
fabrik_t(koord3d pos, spieler_t* sp, const fabrik_besch_t* fabesch);
~fabrik_t();
static fabrik_t * get_fab(const karte_t *welt, const koord pos);
/**
* @return vehicle description object
* @author Hj. Malthaner
*/
const fabrik_besch_t *get_besch() const {return besch; }
void laden_abschliessen();
void set_pos( koord3d p ) { pos = p; }
void rotate90( const sint16 y_size );
void link_halt(halthandle_t halt);
void unlink_halt(halthandle_t halt);
const vector_tpl<koord>& get_lieferziele() const { return lieferziele; }
const vector_tpl<koord>& get_suppliers() const { return suppliers; }
/* workers origin only used for info dialog purposes and saving; otherwise useless ...
* @author Hj. Malthaner/prissi
*/
void add_arbeiterziel(stadt_t *s) { if(!arbeiterziele.is_contained(s)) arbeiterziele.insert(s); }
void remove_arbeiterziel(stadt_t *s) { arbeiterziele.remove(s); }
void clear_arbeiterziele() { arbeiterziele.clear(); }
const slist_tpl<stadt_t*>& get_arbeiterziele() const { return arbeiterziele; } //"employee goals" (Google)
/**
* Fügt ein neues Lieferziel hinzu
* Adds a new delivery goal
* @author Hj. Malthaner
*/
void add_lieferziel(koord ziel);
void rem_lieferziel(koord pos);
bool disconnect_consumer(koord pos);
bool disconnect_supplier(koord pos);
/**
* adds a supplier
* @author Hj. Malthaner
*/
void add_supplier(koord pos);
void rem_supplier(koord pos);
/**
* @return menge der ware typ ("quantity of the goods type")
* -1 wenn typ nicht produziert wird ("if not type is produced")
* sonst die gelagerte menge ("otherwise the stored quantity")
*/
sint32 input_vorrat_an(const ware_besch_t *ware); // Vorrat von Warentyp ("Inventories of product")
sint32 vorrat_an(const ware_besch_t *ware); // Vorrat von Warentyp
// returns all power and consume it
uint32 get_power() { uint32 p=power; power=0; return p; }
// give power to the factory to consume ...
void add_power(uint32 p) { power += p; }
// true, if there was production in the last step
bool is_currently_producing() const { return currently_producing; }
/**
* @return 1 wenn verbrauch,
* 0 wenn Produktionsstopp,
* -1 wenn Ware nicht verarbeitet wird
*/
sint32 verbraucht(const ware_besch_t *); // Nimmt fab das an ?? ("Notes to the fab?")
sint32 hole_ab(const ware_besch_t *, sint32 menge ); // jemand will waren abholen ("someone wants to pick up were")
sint32 liefere_an(const ware_besch_t *, sint32 menge);
sint32 get_abgabe_letzt(sint32 t) { return ausgang[t].abgabe_letzt; }
void step(long delta_t); // fabrik muss auch arbeiten ("factory must also work")
void neuer_monat();
const char *get_name() const { return besch ? translator::translate(besch->get_name()) : "unnamed"; }
sint32 get_kennfarbe() const { return besch ? besch->get_kennfarbe() : 0; }
spieler_t *get_besitzer() const { return welt->lookup(pos) ? welt->lookup(pos)->first_obj()->get_besitzer() : NULL; }
void zeige_info() const;
void info(cbuffer_t& buf) const;
void rdwr(loadsave_t *file);
inline koord3d get_pos() const { return pos; }
/*
* Fills the vector with the koords of the tiles.
*/
void get_tile_list( vector_tpl<koord> &tile_list ) const;
/**
* gibt eine NULL-Terminierte Liste von Fabrikpointern zurück
*
* a zero-scheduled list of factory pointers returns
* @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
*
* "gives true back if factory in the field is"
*
* @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
// "here the methods to parameterize the factory"
/**
* Baut die Gebäude für die Fabrik
*
* "Build the buildings for the factory"
*
* @author Hj. Malthaner, V. Meyer
*/
void baue(sint32 rotate);
sint16 get_rotate() const { return rotate; }
/* field generation code
* spawns a field for sure if probability>=1000
* @author Kieron Green
*/
bool add_random_field(uint16 probability);
void remove_field_at(koord pos);
uint32 get_field_count() const { return fields.get_count(); }
/**
* total and current procduction/storage values
* @author Hj. Malthaner
*/
const vector_tpl<ware_production_t>& get_eingang() const { return eingang; }
const vector_tpl<ware_production_t>& get_ausgang() const { return ausgang; }
/**
* Produktionsmultiplikator
* @author Hj. Malthaner
*/
void set_prodfaktor(sint32 i) { prodfaktor = (i < 16 ? 16 : i); }
sint32 get_prodfaktor(void) const { return prodfaktor; }
/* does not takes month length into account */
sint32 get_base_production() const { return prodbase; }
void set_base_production( sint32 p ) {prodbase = p; }
sint32 get_current_production() const { return (prodbase * prodfaktor * 16l)>>(26l-(long)welt->ticks_bits_per_tag); }
/* prissi: returns the status of the current factory, as well as output */
enum { bad, medium, good, inactive, nothing };
static unsigned status_to_color[5];
uint8 get_status() const { return status; }
uint32 get_total_in() const { return total_input; }
uint32 get_total_out() const { return total_output; }
/**
* Crossconnects all factories
* @author prissi
*/
void add_all_suppliers();
/* adds a new supplier to this factory
* fails if no matching goods are there
*/
bool add_supplier(fabrik_t* fab);
/* adds a new customer to this factory
* fails if no matching goods are accepted
*/
bool add_customer(fabrik_t* fab);
stadt_t* get_city() const { return city; }
void clear_city() { city = NULL; }
};
#endif