forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimhalt.h
682 lines (495 loc) · 15.5 KB
/
simhalt.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/*
* simhalt.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 simhalt_h
#define simhalt_h
#ifndef simdebug_h
#include "simdebug.h"
#endif
#ifndef tpl_slist_tpl_h
#include "tpl/slist_tpl.h"
#endif
#ifndef ptrhashtable_tpl_h
#include "tpl/ptrhashtable_tpl.h"
#endif
#ifndef simware_h
#include "simware.h"
#endif
#ifndef dataobj_warenziel_h
#include "dataobj/warenziel.h"
#endif
#ifndef koord3d_h
#include "dataobj/koord3d.h"
#endif
#ifndef simtypes_h
#include "simtypes.h"
#endif
#define MAX_HALT_COST 7 // Total number of cost items
#define MAX_MONTHS 12 // Max history
#define MAX_HALT_NON_MONEY_TYPES 7 // number of non money types in HALT's financial statistic
#define HALT_ARRIVED 0 // the amount of ware that arrived here
#define HALT_DEPARTED 1 // the amount of ware that has departed from here
#define HALT_WAITING 2 // the amount of ware waiting
#define HALT_HAPPY 3 // number of happy passangers
#define HALT_UNHAPPY 4 // number of unhappy passangers
#define HALT_NOROUTE 5 // number of no-route passangers
#define HALT_CONVOIS_ARRIVED 6 // number of convois arrived this month
class spieler_t;
class fabrik_t;
class karte_t;
#ifdef LAGER_NOT_IN_USE
class lagerhaus_t;
#endif
class grund_t;
class fahrplan_t;
class koord;
class halt_info_t;
struct event_t;
class simline_t;
class cbuffer_t;
#include "halthandle_t.h"
/*
* struct hold travel details for wares that travel
* @author hsiegeln
*/
struct travel_details {
ware_t ware;
halthandle_t destination;
halthandle_t via_destination;
};
// -------------------------- Haltestelle ----------------------------
/**
* Haltestellen in Simutrans. Diese Klasse managed das Routing und Verladen
* von Waren. Eine Haltestelle ist somit auch ein Warenumschlagplatz.
*
* @author Hj. Malthaner
* @see stadt_t
* @see fabrik_t
* @see convoi_t
*/
class haltestelle_t
{
public:
/**
* Sets max number of hops in route calculation
* @author Hj. Malthaner
*/
static void set_max_hops(int hops);
/**
* Sets max number of transfers in route calculation
* @author Hj. Malthaner
*/
static void set_max_transfers(int transfers);
private:
/**
* Manche Methoden müssen auf alle Haltestellen angewandt werden
* deshalb verwaltet die Klasse eine Liste aller Haltestellen
* @author Hj. Malthaner
*/
static slist_tpl<halthandle_t> alle_haltestellen;
static int erzeuge_fussgaenger_an(karte_t *welt, koord3d k, int anzahl);
/*
* declare compare function
* @author hsiegeln
*/
static int compare_ware(const void *td1, const void *td2);
/*
* struct holds new financial history for line
* @author hsiegeln
*/
sint64 financial_history[MAX_MONTHS][MAX_HALT_COST];
/**
* initialize the financial history
* @author hsiegeln
*/
void init_financial_history();
public:
/**
* Tries to generate some pedestrians on the sqaure and the
* adjacent sqaures. Return actual number of generated
* pedestrians.
*
* @author Hj. Malthaner
*/
static int erzeuge_fussgaenger(karte_t *welt, koord3d pos, int anzahl);
//13-Jan-02 Markus Weber Added
enum stationtyp {invalid=-1, loadingbay = 1 ,
railstation = 2, dock = 4, busstop = 8}; //could be combined with or!
// @author hsiegeln added
enum sort_mode_t { by_name=0, by_via=1, by_amount=2};
/**
* sucht Haltestelle an Koordinate pos.
*
* @param pos die Position an der gesucht werden soll
* @return NULL, wenn nichts gefunden, sonst Zeiger auf Haltestelle
* @author Hj. Malthaner
*/
static halthandle_t gib_halt(const karte_t *welt, const koord pos);
// Hajo: for future compatibility, migrate to this call!
static halthandle_t gib_halt(const karte_t *welt, const koord3d pos);
/**
* sucht Haltestelle an Koordinate pos.
*
* @param pos Zeiger auf die Position an der gesucht werden soll
* @return NULL, wenn nichts gefunden, sonst Zeiger auf Haltestelle
* @author Hj. Malthaner
*/
static halthandle_t gib_halt(const karte_t *welt, const koord * const pos);
/**
* Prueft, ob halt auf eine Haltestelle zeigt
* @param halt der zu prüfende Zeiger
* @author Hj. Malthaner
*/
static bool pruefe_zeiger(halthandle_t halt) {return alle_haltestellen.contains( halt );};
static const slist_tpl<halthandle_t> & gib_alle_haltestellen() {return alle_haltestellen;};
/**
* @return die Anzahl der Haltestellen
* @author Hj. Malthaner
*/
static int gib_anzahl() {return alle_haltestellen.count();};
/**
* Station factory method. Returns handles instead of pointers.
* @author Hj. Malthaner
*/
static halthandle_t create(karte_t *welt, koord pos, spieler_t *sp);
/**
* Station factory method. Returns handles instead of pointers.
* @author Hj. Malthaner
*/
static halthandle_t create(karte_t *welt, loadsave_t *file);
/**
* Station destruction method.
* @author Hj. Malthaner
*/
static void destroy(halthandle_t &halt);
/**
* destroys all stations
* @author Hj. Malthaner
*/
static void destroy_all();
private:
/**
* Handle for ourselves. Can be used like the 'this' pointer
* @author Hj. Malthaner
*/
halthandle_t self;
char name[128];
const char * name_from_ground() const;
/**
* The name is saved with the first ground square. After creating and/
* or loading a station the name must be copied into the name array.
* This flag tells wether the name s has been copied yet or not.
* Set to true in all constructors. Setto flase in gib_name() after
* copying the name.
* @author Hj. Malthaner
*/
bool need_name;
/**
* Liste aller felder (Grund-Objekte) die zu dieser Haltestelle gehören
* @author Hj. Malthaner
*/
slist_tpl<grund_t *> grund;
// fuer die zielverwaltung
slist_tpl<warenziel_t> warenziele;
// loest warte_menge ab
ptrhashtable_tpl<const ware_besch_t *, slist_tpl<ware_t> *> waren;
/**
* Liste der angeschlossenen Fabriken
* @author Hj. Malthaner
*/
slist_tpl<fabrik_t *> fab_list;
spieler_t *besitzer_p;
karte_t *welt;
#ifdef LAGER_NOT_IN_USE
lagerhaus_t *lager; // unser lager, falls vorhanden
#endif
koord pos;
bool pax_enabled;
bool post_enabled;
bool ware_enabled;
/**
* Found route and station uncrowded
* @author Hj. Malthaner
*/
int pax_happy;
/**
* Found no route
* @author Hj. Malthaner
*/
int pax_no_route;
/**
* Station crowded
* @author Hj. Malthaner
*/
int pax_unhappy;
/**
* Haltestellen werden beim warenrouting markiert. Jeder durchgang
* hat eine eindeutige marke
* @author Hj. Malthaner
*/
unsigned int marke;
const char * quote_bezeichnung(int quote) const;
halt_info_t *halt_info;
/**
* Initialisiert das gui für diese Haltestelle.
* Muss aus jedem Konstruktor aufgerufen werden.
* @author Hj. Malthaner
*/
void init_gui();
/**
* prüft ob das zwischenziel der Ware im Fahrplan enthalten ist
* @author Hj. Malthaner
*/
bool pruefe_ziel(const ware_t &ware, const fahrplan_t *fpl) const;
/**
* versucht die ware mit beriets wartender ware zusammenzufassen
* @author Hj. Malthaner
*/
bool vereinige_waren(const ware_t &ware);
/**
* liefert wartende ware an eine Fabrik
* @author Hj. Malthaner
*/
void liefere_an_fabrik(ware_t ware);
haltestelle_t(karte_t *welt, loadsave_t *file);
haltestelle_t(karte_t *welt, koord pos, spieler_t *sp);
~haltestelle_t();
/*
* parameter to ease sorting
* sortby is static and set during rendering of halt_info frame
* @author hsiegeln
*/
static sort_mode_t sortby;
/*
* parameter to ease sorting
* sortierung is local and stores the sortorder for the individual station
* @author hsiegeln
*/
sort_mode_t sortierung;
public:
/**
* getter/setter for sortby
* @author hsiegeln
*/
haltestelle_t::sort_mode_t get_sortby() { return sortierung; }
void set_sortby(sort_mode_t sm) { sortby = sm; sortierung = sm; }
/**
* Calculates a status color for status bars
* @author Hj. Malthaner
*/
int gib_status_farbe() const;
/**
* Draws some nice colored bars giving some status information
* @author Hj. Malthaner
*/
void display_status(int xpos, int ypos) const;
/**
* sucht umliegende, erreichbare fabriken und baut daraus die
* Fabrikliste auf.
* @author Hj. Malthaner
*/
void verbinde_fabriken();
/**
* Rebuilds the list of reachable destinations
*
* @author Hj. Malthaner
*/
void rebuild_destinations();
spieler_t *gib_besitzer() const {return besitzer_p;};
const slist_tpl<warenziel_t> * gib_warenziele() const {return &warenziele;};
const slist_tpl<fabrik_t*> & gib_fab_list() const {return fab_list;};
/**
* Haltestellen messen regelmaessig die Fahrplaene pruefen
* @author Hj. Malthaner
*/
void step();
/**
* Called every month/every 24 game hours
* @author Hj. Malthaner
*/
void neuer_monat();
/**
* liefert zu einer Zielkoordinate die Haltestelle
* an der Zielkoordinate
* @author Hj. Malthaner
* @see haltestelle_t::gib_halt
*/
halthandle_t gib_halt(const koord ziel) const;
/**
* gibt true zurück, wenn die Ware nicht mehr reisen muss
* weil sie schon nahe genug am ziel ist.
*
* false kann bedeuten: die Ware ist noch nicht am Ziel. Dabei gibt es zwei
* Fälle: keine Route oder Route zum Ziel. ware->ziel() und Zwischenziel()
* geben Auskunft, sind NULL, wenn keine Route existiert.
*
* Kann die Ware nicht zum Ziel geroutet werden (keine Route), dann werden
* Ziel und Zwischenziel auf koord::invalid gesetzt.
*
* @param ware die zu routende Ware
* @param start die Starthaltestelle
* @author Hj. Malthaner
*/
bool suche_route(ware_t &ware, halthandle_t start);
void set_pax_enabled(bool yesno) {pax_enabled = yesno;};
void set_post_enabled(bool yesno){post_enabled = yesno;};
void set_ware_enabled(bool yesno){ware_enabled = yesno;};
bool get_pax_enabled() const { return pax_enabled;};
bool get_post_enabled() const { return post_enabled;};
/**
* Found route and station uncrowded
* @author Hj. Malthaner
*/
void add_pax_happy(int n);
/**
* Found no route
* @author Hj. Malthaner
*/
void add_pax_no_route(int n);
/**
* Station crowded
* @author Hj. Malthaner
*/
void add_pax_unhappy(int n);
int get_pax_happy() const {return pax_happy;};
int get_pax_no_route() const {return pax_no_route;};
int get_pax_unhappy() const {return pax_unhappy;};
#ifdef LAGER_NOT_IN_USE
void setze_lager(lagerhaus_t *l) {lager = l;};
#endif
bool add_grund(grund_t *gb);
void rem_grund(grund_t *gb);
int gib_grund_count() const {return grund.count();};
bool existiert_in_welt();
bool ist_da(koord pos) const;
koord gib_basis_pos() const;
/**
* gibt Gesamtmenge derware vom typ typ zurück
* @author Hj. Malthaner
*/
int gib_ware_summe(const ware_besch_t *warentyp) const;
/**
* gibt Gesamtmenge derware vom typ typ fuer ziel zurück
* @author Hj. Malthaner
*/
int gib_ware_fuer_ziel(const ware_besch_t *warentyp,
const koord ziel) const;
bool nimmt_an(const ware_besch_t *warentyp);
bool gibt_ab(const ware_besch_t *warentyp) const;
/**
* holt ware ab
* @return abgeholte menge
* @author Hj. Malthaner
*/
ware_t hole_ab(const ware_besch_t *warentyp, int menge, fahrplan_t *fpl);
/**
* liefert ware an. Falls die Ware zu wartender Ware dazugenommen
* werden kann, kann ware_t gelöscht werden! D.h. man darf ware nach
* aufruf dieser Methode nicht mehr referenzieren!
* @return angenommene menge
* @author Hj. Malthaner
*/
int liefere_an(ware_t ware);
/**
* wird von Fahrzeug aufgerufen, wenn dieses an der Haltestelle
* gehalten hat.
* @param wertung Verbesserungswert der Haltestellenquote in 1/256
* @param typ der beförderte warentyp
* @author Hj. Malthaner
*/
void hat_gehalten(int wertung,
const ware_besch_t *warentyp,
const fahrplan_t *fpl);
void info(cbuffer_t & buf) const;
/**
* @param buf the buffer to fill
* @return Goods description text (buf)
* @author Hj. Malthaner
*/
void get_freight_info(cbuffer_t & buf);
/**
* @param buf the buffer to fill
* @return short list of the waiting goods (i.e. 110 Wood, 15 Coal)
* @author Hj. Malthaner
*/
void get_short_freight_info(cbuffer_t & buf);
/**
* Opens an information window for this station.
* @author Hj. Malthaner
*/
void zeige_info();
/**
* Opens the details window for this station.
* @author Hj. Malthaner
*/
void open_detail_window();
/**
* @returns station number
* @author Markus Weber
*/
int index_of() const {return alle_haltestellen.index_of(self);} //13-Feb-02 Markus Added
/**
* @returns the sum of all waiting goods (100t coal + 10
* passengers + 2000 liter oil = 2110)
* @author Markus Weber
*/
int sum_all_waiting_goods() const;
/**
* @returns true, if goods or passengers are waiting
* @author Markus Weber
*/
bool is_something_waiting() const; //12-Jan-2002 Markus Weber Added
/**
* @returns the type of a station
* (combination of: railstation, loading bay, dock)
* @author Markus Weber
*/
int get_station_type() const; //13-Jan-2002 Markus Weber Added
/**
* fragt den namen der Haltestelle ab.
* Der Name ist der text des ersten Untergrundes der Haltestelle
* @return der Name der Haltestelle.
* @author Hj. Malthaner
*/
const char * gib_name() const;
char * access_name();
void setze_name(const char *name);
void rdwr(loadsave_t *file);
void laden_abschliessen();
/*
* called, if a line serves this stop
* @author hsiegeln
*/
void add_line(simline_t * line) { if (!registered_lines.contains(line)) registered_lines.append(line); rebuild_destinations(); };
/*
* called, if a line removes this stop from it's schedule
* @author hsiegeln
*/
void remove_line(simline_t * line) { registered_lines.remove(line); rebuild_destinations(); };
/*
* list of line ids that serve this stop
* @author hsiegeln
*/
slist_tpl<simline_t *> registered_lines;
/**
* book a certain amount into the halt's financial history
* @author hsiegeln
*/
void book(sint64 amount, int cost_type);
/**
* return a pointer to the financial history
* @author hsiegeln
*/
sint64* get_finance_history() { return *financial_history; };
/**
* return a specified element from the financial history
* @author hsiegeln
*/
sint64 get_finance_history(int month, int cost_type) { return financial_history[month][cost_type]; };
};
#endif