1 /* 2 * Copyright (c) 1997 - 2002 Hansj�rg Malthaner 3 * 4 * This file is part of the Simutrans project under the artistic licence. 5 * (see licence.txt) 6 */ 7 8 #ifndef HAUSBAUER_H 9 #define HAUSBAUER_H 10 11 #include "../descriptor/building_desc.h" 12 #include "../dataobj/koord3d.h" 13 #include "../simtypes.h" 14 #include "../tpl/vector_tpl.h" 15 16 class gebaeude_t; 17 class karte_ptr_t; 18 class player_t; 19 class tool_selector_t; 20 21 /** 22 * This class deals with building single- and multi-tile buildings. It knows the descriptions 23 * of (nearly) all buildings as regards type, height, size, images and animations. 24 * To be able to build a new house the house description must be registered by register_desc(). 25 * 26 * To ensure all monuments are only present once per map, there is a list 27 * which monuments have been built and which not. 28 * There's no need to construct an instance since everything is static here. 29 */ 30 class hausbauer_t 31 { 32 private: 33 static sint16 largest_city_building_area; 34 35 static vector_tpl<const building_desc_t*> attractions_land; ///< Sights outside of cities 36 static vector_tpl<const building_desc_t*> attractions_city; ///< Sights within cities 37 static vector_tpl<const building_desc_t*> townhalls; ///< Town halls 38 static vector_tpl<const building_desc_t*> monuments; ///< All monuments 39 static vector_tpl<const building_desc_t*> unbuilt_monuments; ///< All unbuilt monuments 40 static vector_tpl<const building_desc_t*> headquarters; ///< Company headquarters 41 static vector_tpl<const building_desc_t*> station_building; ///< All station buildings 42 43 /// @returns a random entry from @p list 44 static const building_desc_t* get_random_desc(vector_tpl<const building_desc_t*>& list, uint16 time, bool ignore_retire, climate cl); 45 46 /// our game world 47 static karte_ptr_t welt; 48 49 public: get_largest_city_building_area()50 static sint16 get_largest_city_building_area() { return largest_city_building_area; } 51 52 /// description for elevated monorail (mandatory description) 53 static const building_desc_t* elevated_foundation_desc; 54 55 /** 56 * Finds a station building enabling pax/mail/goods for the AI. 57 * If @p time == 0 the timeline will be ignored. 58 * @param enables station enabled flags (see haltestelle_t::station_flags) 59 * @returns a random station that can be built above ground. 60 */ 61 static const building_desc_t* get_random_station(const building_desc_t::btype utype, const waytype_t wt, const uint16 time, const uint8 enables); 62 63 /// Finds and returns the tile at position @p idx 64 static const building_tile_desc_t* find_tile(const char* name, int idx); 65 66 /// @returns the house description with name @p name 67 static const building_desc_t* get_desc(const char *name); 68 69 /** 70 * Registers the house description so the house can be built in-game. 71 * @returns true 72 */ 73 static bool register_desc(building_desc_t *desc); 74 75 /// Sorts all house descriptions into their respective lists. 76 static bool successfully_loaded(); 77 78 /** 79 * Fills menu with icons of buildings of a given waytype. 80 * This is needed for station extensions and headquarters. 81 */ 82 static void fill_menu(tool_selector_t* tool_selector, building_desc_t::btype, waytype_t wt, sint16 sound_ok); 83 84 /// @returns a random commercial building matching the requirements. 85 static const building_desc_t* get_commercial(int level, uint16 time, climate c, uint32 clusters, koord minsize, koord maxsize ); 86 87 /// @returns a random industrial building matching the requirements. 88 static const building_desc_t* get_industrial(int level, uint16 time, climate cl, uint32 clusters, koord minsize, koord maxsize ); 89 90 /// @returns a random residential building matching the requirements. 91 static const building_desc_t* get_residential(int level, uint16 time, climate cl, uint32 clusters, koord minsize, koord maxsize ); 92 93 /// @returns headquarters with level @p level (takes the first matching one) 94 static const building_desc_t* get_headquarters(int level, uint16 time); 95 96 /// @returns a random tourist attraction matching the requirements. get_random_attraction(uint16 time,bool ignore_retire,climate cl)97 static const building_desc_t* get_random_attraction(uint16 time, bool ignore_retire, climate cl) 98 { 99 return get_random_desc(attractions_land, time, ignore_retire, cl); 100 } 101 102 /// @returns a random unbuilt monument. 103 static const building_desc_t* get_random_monument(uint16 time = 0) 104 { 105 return get_random_desc(unbuilt_monuments, time, false, MAX_CLIMATES); 106 } 107 108 /** 109 * Tells the house builder a new map is being loaded or generated. 110 * In this case the list of unbuilt monuments must be refilled 111 * to ensure each monument is only present once per map. 112 */ 113 static void new_world(); 114 115 /// @returns true if this monument has not yet been built. is_valid_monument(const building_desc_t * desc)116 static bool is_valid_monument(const building_desc_t* desc) { return unbuilt_monuments.is_contained(desc); } 117 118 /// Tells the house builder a monument has been built. monument_erected(const building_desc_t * desc)119 static void monument_erected(const building_desc_t* desc) { unbuilt_monuments.remove(desc); } 120 121 /// Called for a city attraction or a town hall with a certain number of inhabitants (bev). 122 static const building_desc_t* get_special(uint32 bev, building_desc_t::btype utype, uint16 time, bool ignore_retire, climate cl); 123 124 /** 125 * Removes an arbitrary building. 126 * It will also take care of factories and foundations. 127 * @param sp the player wanting to remove the building. 128 */ 129 static void remove(player_t *player, gebaeude_t *gb); 130 131 /** 132 * Main function to build all non-traffic buildings, including factories. 133 * Building size can be larger than 1x1. 134 * Also the underlying ground will be changed to foundation. 135 * @param param if building a factory, pointer to the factory, 136 * if building a stop, pointer to the halt handle. 137 * 138 * @return The first built part of the building. Usually at @p pos, if this 139 * building tile is not empty. 140 */ 141 static gebaeude_t* build(player_t* player, koord3d pos, int layout, const building_desc_t* desc, void* param = NULL); 142 143 /** 144 * Build all kind of stops and depots. The building size must be 1x1. 145 * Stations with layout>4 may change the layout of neighbouring buildings. (->end of rail platforms) 146 * @param param if building a stop, pointer to the halt handle 147 */ 148 static gebaeude_t* build_station_extension_depot(player_t* player, koord3d pos, int layout, const building_desc_t* desc, void* param = NULL); 149 150 /// @returns house list of type @p typ 151 static const vector_tpl<const building_desc_t *> *get_list(building_desc_t::btype typ); 152 153 /// @returns city building list of type @p typ (res/com/ind) 154 static const vector_tpl<const building_desc_t *> *get_citybuilding_list(building_desc_t::btype typ); 155 }; 156 157 #endif 158