# house.h

Go to the documentation of this file.

    00001 /* $Id: house.h 18736 2010-01-05 21:36:05Z yexo $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef HOUSE_H
    00013 #define HOUSE_H
    00014
    00015 #include "strings_type.h"
    00016 #include "cargo_type.h"
    00017 #include "economy_type.h"
    00018 #include "date_type.h"
    00019 #include "house_type.h"
    00020
    00023 static const byte TOWN_HOUSE_COMPLETED = 3;
    00024
    00025 enum {
    00026   HOUSE_NO_CLASS   = 0,
    00027   NEW_HOUSE_OFFSET = 110,
    00028   HOUSE_MAX        = 512,
    00029   INVALID_HOUSE_ID = 0xFFFF,
    00030
    00031   /* There can only be as many classes as there are new houses, plus one for
    00032    * NO_CLASS, as the original houses don't have classes. */
    00033   HOUSE_CLASS_MAX  = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
    00034 };
    00035
    00036 enum BuildingFlags {
    00037   TILE_NO_FLAG         =       0,
    00038   TILE_SIZE_1x1        = 1U << 0,
    00039   TILE_NOT_SLOPED      = 1U << 1,
    00040   TILE_SIZE_2x1        = 1U << 2,
    00041   TILE_SIZE_1x2        = 1U << 3,
    00042   TILE_SIZE_2x2        = 1U << 4,
    00043   BUILDING_IS_ANIMATED = 1U << 5,
    00044   BUILDING_IS_CHURCH   = 1U << 6,
    00045   BUILDING_IS_STADIUM  = 1U << 7,
    00046   BUILDING_HAS_1_TILE  = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
    00047   BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
    00048   BUILDING_2_TILES_X   = TILE_SIZE_2x1 | TILE_SIZE_2x2,
    00049   BUILDING_2_TILES_Y   = TILE_SIZE_1x2 | TILE_SIZE_2x2,
    00050   BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
    00051 };
    00052 DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
    00053
    00054 enum HouseZonesBits {
    00055   HZB_BEGIN     = 0,
    00056   HZB_TOWN_EDGE = 0,
    00057   HZB_TOWN_OUTSKIRT,
    00058   HZB_TOWN_OUTER_SUBURB,
    00059   HZB_TOWN_INNER_SUBURB,
    00060   HZB_TOWN_CENTRE,
    00061   HZB_END,
    00062 };
    00063 assert_compile(HZB_END == 5);
    00064
    00065 DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
    00066
    00067 enum HouseZones {
    00068   HZ_NOZNS             = 0x0000,
    00069   HZ_ZON1              = 1U << HZB_TOWN_EDGE,
    00070   HZ_ZON2              = 1U << HZB_TOWN_OUTSKIRT,
    00071   HZ_ZON3              = 1U << HZB_TOWN_OUTER_SUBURB,
    00072   HZ_ZON4              = 1U << HZB_TOWN_INNER_SUBURB,
    00073   HZ_ZON5              = 1U << HZB_TOWN_CENTRE,
    00074   HZ_ZONALL            = 0x001F,
    00075   HZ_SUBARTC_ABOVE     = 0x0800,
    00076   HZ_TEMP              = 0x1000,
    00077   HZ_SUBARTC_BELOW     = 0x2000,
    00078   HZ_SUBTROPIC         = 0x4000,
    00079   HZ_TOYLND            = 0x8000
    00080 };
    00081 DECLARE_ENUM_AS_BIT_SET(HouseZones)
    00082
    00083 enum HouseExtraFlags {
    00084   NO_EXTRA_FLAG            =       0,
    00085   BUILDING_IS_HISTORICAL   = 1U << 0,
    00086   BUILDING_IS_PROTECTED    = 1U << 1,
    00087   SYNCHRONISED_CALLBACK_1B = 1U << 2,
    00088   CALLBACK_1A_RANDOM_BITS  = 1U << 3,
    00089 };
    00090
    00091 DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
    00092
    00093 struct HouseSpec {
    00094   /* Standard properties */
    00095   Year min_year;
    00096   Year max_year;
    00097   byte population;
    00098   byte removal_cost;
    00099   StringID building_name;
    00100   uint16 remove_rating_decrease;
    00101   byte mail_generation;
    00102   byte cargo_acceptance[3];
    00103   CargoID accepts_cargo[3];
    00104   BuildingFlags building_flags;
    00105   HouseZones building_availability;
    00106   bool enabled;
    00107
    00108   /* NewHouses properties */
    00109   HouseID substitute_id;
    00110   struct SpriteGroup *spritegroup;
    00111   HouseID override;
    00112   uint16 callback_mask;
    00113   byte random_colour[4];
    00114   byte probability;
    00115   HouseExtraFlags extra_flags;
    00116   HouseClassID class_id;
    00117   byte animation_frames;
    00118   byte animation_speed;
    00119   byte processing_time;
    00120   byte minimum_life;
    00121
    00122   /* grf file related properties*/
    00123   uint8 local_id;
    00124   const struct GRFFile *grffile;
    00125
    00130   Money GetRemovalCost() const;
    00131
    00132   static FORCEINLINE HouseSpec *Get(size_t house_id)
    00133   {
    00134     assert(house_id < HOUSE_MAX);
    00135     extern HouseSpec _house_specs[];
    00136     return &_house_specs[house_id];
    00137   }
    00138 };
    00139
    00145 static inline HouseID GetTranslatedHouseID(HouseID hid)
    00146 {
    00147   const HouseSpec *hs = HouseSpec::Get(hid);
    00148   return hs->override == INVALID_HOUSE_ID ? hid : hs->override;
    00149 }
    00150
    00151 #endif /* HOUSE_H */