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
|
/*
* Copyright (c) 1997 - 2001 Hansjrg Malthaner
*
* This file is part of the Simutrans project under the artistic license.
* (see license.txt)
*/
#ifndef simplan_h
#define simplan_h
#include "halthandle_t.h"
#include "boden/grund.h"
class karte_t;
class grund_t;
class ding_t;
class planquadrat_t;
void swap(planquadrat_t& a, planquadrat_t& b);
/**
* Die Karte ist aus Planquadraten zusammengesetzt.
* Planquadrate speichern Untergrnde (Bden) der Karte.
* @author Hj. Malthaner
*/
class planquadrat_t
{
private:
/* list of stations that are reaching to this tile (saves lots of time for lookup) */
halthandle_t *halt_list;
uint8 ground_size, halt_list_count;
/* only one station per ground xy tile */
halthandle_t this_halt;
union DATA {
grund_t ** some; // valid if capacity > 1
grund_t * one; // valid if capacity == 1
} data;
public:
/**
* Constructs a planquadrat with initial capacity of one ground
* @author Hansjrg Malthaner
*/
planquadrat_t() { ground_size=0; data.one = NULL; halt_list_count=0; halt_list=NULL; }
~planquadrat_t();
private:
planquadrat_t(planquadrat_t const&);
planquadrat_t& operator=(planquadrat_t const&);
friend void swap(planquadrat_t& a, planquadrat_t& b);
public:
/**
* Setzen des "normalen" Bodens auf Kartenniveau
* @author V. Meyer
*/
void kartenboden_setzen(grund_t *bd);
/**
* Ersetzt Boden alt durch neu, lscht Boden alt.
* @author Hansjrg Malthaner
*/
void boden_ersetzen(grund_t *alt, grund_t *neu);
/**
* Setzen einen Brcken- oder Tunnelbodens
* @author V. Meyer
*/
void boden_hinzufuegen(grund_t *bd);
/**
* Lschen eines Brcken- oder Tunnelbodens
* @author V. Meyer
*/
bool boden_entfernen(grund_t *bd);
/**
* Return either ground tile in this height or NULL if not existing
* Inline, since called from karte_t::lookup() and thus extremely often
* @return NULL if not ground in this height
* @author Hj. Malthaner
*/
inline grund_t *get_boden_in_hoehe(const sint16 z) const {
if(ground_size==1) {
// must be valid ground at this point!
if( data.one->get_hoehe() == z ) {
return data.one;
}
}
else {
for( uint8 i = 0; i < ground_size; i++ ) {
if( data.some[i]->get_hoehe() == z ) {
return data.some[i];
}
}
}
return NULL;
}
/**
* returns normal ground (always first index)
* @return not defined if no ground (must not happen!)
* @author Hansjrg Malthaner
*/
inline grund_t *get_kartenboden() const { return (ground_size<=1) ? data.one : data.some[0]; }
/**
* find ground if thing is on this planquadrat
* @return grund_t * with thing or NULL
* @author V. Meyer
*/
grund_t *get_boden_von_obj(ding_t *obj) const;
/**
* ground saved at index position idx (zero would be normal ground)
* Since it is always called from loops or with other checks, no
* range check is done => if only one ground, range is ignored!
* @return ground at idx, undefined if ground_size==NULL
* @author Hj. Malthaner
*/
inline grund_t *get_boden_bei(const unsigned idx) const { return (ground_size<=1 ? data.one : data.some[idx]); }
/**
* @return Anzahl der Bden dieses Planquadrats
* @author Hj. Malthaner
*/
unsigned int get_boden_count() const { return ground_size; }
/**
* konvertiert Land zu Wasser wenn unter Grundwasserniveau abgesenkt
* @author Hj. Malthaner
*/
void abgesenkt(karte_t *welt);
/**
* konvertiert Wasser zu Land wenn ber Grundwasserniveau angehoben
* @author Hj. Malthaner
*/
void angehoben(karte_t *welt);
/**
* since stops may be multilevel, but waren uses pos, we mirror here any halt that is on this square
* @author Hj. Malthaner
*/
void set_halt(halthandle_t halt);
/**
* returns a halthandle, if some ground here has a stop
* @return NULL wenn keine Haltestelle, sonst Zeiger auf Haltestelle
* @author Hj. Malthaner
*/
const halthandle_t get_halt() const {return this_halt;}
private:
// these functions are private helper functions for halt_list corrections
void halt_list_remove( halthandle_t halt );
void halt_list_insert_at( halthandle_t halt, uint8 pos );
public:
/*
* The following three functions takes about 4 bytes of memory per tile but speed up passenger generation
* @author prissi
*/
void add_to_haltlist(halthandle_t halt);
/**
* removes the halt from a ground
* however this funtion check, whether there is really no other part still reachable
* @author prissi
*/
void remove_from_haltlist(karte_t *welt, halthandle_t halt);
bool is_connected(halthandle_t halt) const;
/**
* returns the internal array of halts
* @author prissi
*/
const halthandle_t *get_haltlist() const { return halt_list; }
uint8 get_haltlist_count() const { return halt_list_count; }
void rdwr(karte_t *welt, loadsave_t *file, koord pos );
// will toggle the seasons ...
void check_season(const long month);
void display_dinge(const sint16 xpos, const sint16 ypos, const sint16 raster_tile_width, const bool is_global, const sint8 hmin, const sint8 hmax) const;
void display_overlay(sint16 xpos, sint16 ypos, const sint8 hmin, const sint8 hmax) const;
};
#endif
|