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
|
/*
* 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_ptr_t;
class grund_t;
class obj_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
{
static karte_ptr_t welt;
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;
// stores climate related settings
uint8 climate_data;
union DATA {
grund_t ** some; // valid if capacity > 1
grund_t * one; // valid if capacity == 1
} data;
public:
/**
* Constructs a planquadrat (tile) with initial capacity of one ground
* @author Hansjrg Malthaner
*/
planquadrat_t() { ground_size = 0; climate_data = 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, bool startup = false);
/**
* 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 (tile)
* @return grund_t * with thing or NULL
* @author V. Meyer
*/
grund_t *get_boden_von_obj(obj_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; }
/**
* returns climate of plan (lowest 3 bits of climate byte)
* @author Kieron Green
*/
inline climate get_climate() const { return (climate)(climate_data & 7); }
/**
* sets plan climate
* @author Kieron Green
*/
void set_climate(climate cl) {
climate_data = (climate_data & 0xf8) + (cl & 7);
}
/**
* returns whether this is a transition to next climate (which will then use calculated image rather than overlay)
* @author Kieron Green
*/
inline bool get_climate_transition_flag() const { return (climate_data >> 3) & 1; }
/**
* set whether this is a transition to next climate (which will then use calculated image rather than overlay)
* @author Kieron Green
*/
void set_climate_transition_flag(bool flag) {
climate_data = flag ? (climate_data | 0x08) : (climate_data & 0xf7);
}
/**
* returns corners which transition to another climate
* this has no meaning if tile is a slope with transition to next climate as these corners are fixed
* therefore for this case to allow double heights 0 = first level transition, 1 = second level transition
* @author Kieron Green
*/
inline uint8 get_climate_corners() const { return (climate_data >> 4) & 15; }
/**
* sets climate transition corners
* this has no meaning if tile is a slope with transition to next climate as these corners are fixed
* therefore for this case to allow double heights 0 = first level transition, 1 = second level transition
* @author Kieron Green
*/
void set_climate_corners(uint8 corners) {
climate_data = (climate_data & 0x0f) + (corners << 4);
}
/**
* converts boden to correct type, land or water
* @author Kieron Green
*/
void correct_water();
/**
* konvertiert Land zu Water wenn unter Grundwasserniveau abgesenkt
* @author Hj. Malthaner
*/
void abgesenkt();
/**
* Converts water to land when raised above the ground water level
* @author Hj. Malthaner
*/
void angehoben();
/**
* returns halthandle belonging to player if present
* @return NULL if no halt present
* @author Kieron Green
*/
halthandle_t get_halt(player_t *player) const;
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
* @param unsorted if true then halt list will be sorted later by call to sort_haltlist, see karte_t::plans_finish_rd.
*/
void add_to_haltlist(halthandle_t halt, bool unsorted = false);
/**
* removes the halt from a ground
* however this function check, whether there is really no other part still reachable
* @author prissi
*/
void remove_from_haltlist(halthandle_t halt);
/**
* sort list of connected halts, ascending wrt distance to this tile
*/
void sort_haltlist();
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(loadsave_t *file, koord pos );
/**
* Updates season and/or snowline dependent graphics
*/
void check_season_snowline(const bool season_change, const bool snowline_change);
void display_obj(const sint16 xpos, const sint16 ypos, const sint16 raster_tile_width, const bool is_global, const sint8 hmin, const sint8 hmax CLIP_NUM_DEF) const;
void display_overlay(sint16 xpos, sint16 ypos) const;
static void toggle_horizontal_clip(CLIP_NUM_DEF0);
/**
* @brief Update this square for underground view.
*
* Updates this square for underground view. This includes calculating
* calculating new back will images as well as water depth texture.
*
* This method does not modify this square object, but does modify the
* grounds it references.
*/
void update_underground() const;
};
#endif
|