summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-06-26 13:44:14 +0000
committersmatz <smatz@openttd.org>2009-06-26 13:44:14 +0000
commite6a165881cba611a4475db21068d64caa67796ea (patch)
tree2954a4e0bee44f0c00864e32211ceb6d4d87d122
parent2987f021447d47a2678a8fdce81547e3d66a7217 (diff)
downloadopenttd-e6a165881cba611a4475db21068d64caa67796ea.tar.xz
(svn r16664) -Codechange: move house-related stuff from town.h and town_type.h to separate files
-rw-r--r--projects/openttd_vs80.vcproj8
-rw-r--r--projects/openttd_vs90.vcproj8
-rw-r--r--source.list2
-rw-r--r--src/house.h135
-rw-r--r--src/house_type.h13
-rw-r--r--src/newgrf.h1
-rw-r--r--src/newgrf_house.cpp1
-rw-r--r--src/newgrf_house.h1
-rw-r--r--src/newgrf_spritegroup.h1
-rw-r--r--src/rail_cmd.cpp1
-rw-r--r--src/road_cmd.cpp1
-rw-r--r--src/saveload/afterload.cpp1
-rw-r--r--src/saveload/town_sl.cpp2
-rw-r--r--src/town.h129
-rw-r--r--src/town_cmd.cpp1
-rw-r--r--src/town_map.h13
-rw-r--r--src/town_type.h4
17 files changed, 184 insertions, 138 deletions
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index 836191ed4..02cca66b6 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -1064,6 +1064,14 @@
>
</File>
<File
+ RelativePath=".\..\src\house.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\house_type.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\industry.h"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index 90789aaca..edf15f0b4 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -1061,6 +1061,14 @@
>
</File>
<File
+ RelativePath=".\..\src\house.h"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\house_type.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\industry.h"
>
</File>
diff --git a/source.list b/source.list
index 038ba93a9..47cf503f9 100644
--- a/source.list
+++ b/source.list
@@ -194,6 +194,8 @@ group_type.h
gui.h
heightmap.h
highscore.h
+house.h
+house_type.h
industry.h
industry_type.h
ini_type.h
diff --git a/src/house.h b/src/house.h
new file mode 100644
index 000000000..bbe98845e
--- /dev/null
+++ b/src/house.h
@@ -0,0 +1,135 @@
+/* $Id$ */
+
+/** @file house.h definition of HouseSpec and accessors */
+
+#ifndef HOUSE_H
+#define HOUSE_H
+
+#include "strings_type.h"
+#include "cargo_type.h"
+#include "economy_type.h"
+#include "date_type.h"
+#include "house_type.h"
+
+/** Simple value that indicates the house has reached the final stage of
+ * construction. */
+static const byte TOWN_HOUSE_COMPLETED = 3;
+
+enum {
+ HOUSE_NO_CLASS = 0,
+ NEW_HOUSE_OFFSET = 110,
+ HOUSE_MAX = 512,
+ INVALID_HOUSE_ID = 0xFFFF,
+
+ /* There can only be as many classes as there are new houses, plus one for
+ * NO_CLASS, as the original houses don't have classes. */
+ HOUSE_CLASS_MAX = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
+};
+
+enum BuildingFlags {
+ TILE_NO_FLAG = 0,
+ TILE_SIZE_1x1 = 1U << 0,
+ TILE_NOT_SLOPED = 1U << 1,
+ TILE_SIZE_2x1 = 1U << 2,
+ TILE_SIZE_1x2 = 1U << 3,
+ TILE_SIZE_2x2 = 1U << 4,
+ BUILDING_IS_ANIMATED = 1U << 5,
+ BUILDING_IS_CHURCH = 1U << 6,
+ BUILDING_IS_STADIUM = 1U << 7,
+ BUILDING_HAS_1_TILE = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
+ BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
+ BUILDING_2_TILES_X = TILE_SIZE_2x1 | TILE_SIZE_2x2,
+ BUILDING_2_TILES_Y = TILE_SIZE_1x2 | TILE_SIZE_2x2,
+ BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
+};
+DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
+
+enum HouseZonesBits {
+ HZB_BEGIN = 0,
+ HZB_TOWN_EDGE = 0,
+ HZB_TOWN_OUTSKIRT,
+ HZB_TOWN_OUTER_SUBURB,
+ HZB_TOWN_INNER_SUBURB,
+ HZB_TOWN_CENTRE,
+ HZB_END,
+};
+assert_compile(HZB_END == 5);
+
+DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
+
+enum HouseZones { ///< Bit Value Meaning
+ HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none
+ HZ_ZON1 = 1U << HZB_TOWN_EDGE, ///< 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb
+ HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT,
+ HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB,
+ HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB,
+ HZ_ZON5 = 1U << HZB_TOWN_CENTRE, ///< center of town
+ HZ_ZONALL = 0x001F, ///< 1F This is just to englobe all above types at once
+ HZ_SUBARTC_ABOVE = 0x0800, ///< 11 800 can appear in sub-arctic climate above the snow line
+ HZ_TEMP = 0x1000, ///< 12 1000 can appear in temperate climate
+ HZ_SUBARTC_BELOW = 0x2000, ///< 13 2000 can appear in sub-arctic climate below the snow line
+ HZ_SUBTROPIC = 0x4000, ///< 14 4000 can appear in subtropical climate
+ HZ_TOYLND = 0x8000 ///< 15 8000 can appear in toyland climate
+};
+DECLARE_ENUM_AS_BIT_SET(HouseZones)
+
+enum HouseExtraFlags {
+ NO_EXTRA_FLAG = 0,
+ BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical
+ BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
+ SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses
+ CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits
+};
+
+DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
+
+struct HouseSpec {
+ /* Standard properties */
+ Year min_year; ///< introduction year of the house
+ Year max_year; ///< last year it can be built
+ byte population; ///< population (Zero on other tiles in multi tile house.)
+ byte removal_cost; ///< cost multiplier for removing it
+ StringID building_name; ///< building name
+ uint16 remove_rating_decrease; ///< rating decrease if removed
+ byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
+ byte cargo_acceptance[3]; ///< acceptance level for the cargo slots
+ CargoID accepts_cargo[3]; ///< 3 input cargo slots
+ BuildingFlags building_flags; ///< some flags that describe the house (size, stadium etc...)
+ HouseZones building_availability; ///< where can it be built (climates, zones)
+ bool enabled; ///< the house is available to build (true by default, but can be disabled by newgrf)
+
+ /* NewHouses properties */
+ HouseID substitute_id; ///< which original house this one is based on
+ struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the house
+ HouseID override; ///< which house this one replaces
+ uint16 callback_mask; ///< House callback flags
+ byte random_colour[4]; ///< 4 "random" colours
+ byte probability; ///< Relative probability of appearing (16 is the standard value)
+ HouseExtraFlags extra_flags; ///< some more flags
+ HouseClassID class_id; ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44
+ byte animation_frames; ///< number of animation frames
+ byte animation_speed; ///< amount of time between each of those frames
+ byte processing_time; ///< Periodic refresh multiplier
+ byte minimum_life; ///< The minimum number of years this house will survive before the town rebuilds it
+
+ /* grf file related properties*/
+ uint8 local_id; ///< id defined by the grf file for this house
+ const struct GRFFile *grffile; ///< grf file that introduced this house
+
+ /**
+ * Get the cost for removing this house
+ * @return the cost (inflation corrected etc)
+ */
+ Money GetRemovalCost() const;
+
+};
+
+extern HouseSpec _house_specs[];
+
+static inline HouseSpec *GetHouseSpecs(HouseID house_id)
+{
+ assert(house_id < HOUSE_MAX);
+ return &_house_specs[house_id];
+}
+
+#endif /* HOUSE_H */
diff --git a/src/house_type.h b/src/house_type.h
new file mode 100644
index 000000000..da9ebe7c7
--- /dev/null
+++ b/src/house_type.h
@@ -0,0 +1,13 @@
+/* $Id$ */
+
+/** @file house_type.h declaration of basic house types and enums */
+
+#ifndef HOUSE_TYPE_H
+#define HOUSE_TYPE_H
+
+typedef uint16 HouseID;
+typedef uint16 HouseClassID;
+
+struct HouseSpec;
+
+#endif /* HOUSE_TYPE_H */
diff --git a/src/newgrf.h b/src/newgrf.h
index e05ef89fe..23122e780 100644
--- a/src/newgrf.h
+++ b/src/newgrf.h
@@ -11,6 +11,7 @@
#include "industry_type.h"
#include "station_type.h"
#include "rail_type.h"
+#include "house_type.h"
enum GrfLoadingStage {
GLS_FILESCAN,
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index b1e5c64fc..214734af1 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -21,6 +21,7 @@
#include "company_func.h"
#include "animated_tile_func.h"
#include "company_base.h"
+#include "town.h"
static BuildingCounts<uint32> _building_counts;
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
diff --git a/src/newgrf_house.h b/src/newgrf_house.h
index ce08e1213..a67718486 100644
--- a/src/newgrf_house.h
+++ b/src/newgrf_house.h
@@ -8,6 +8,7 @@
#include "town_type.h"
#include "newgrf_callbacks.h"
#include "tile_cmd.h"
+#include "house_type.h"
/**
* Makes class IDs unique to each GRF file.
diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h
index bb5683518..20ad65ead 100644
--- a/src/newgrf_spritegroup.h
+++ b/src/newgrf_spritegroup.h
@@ -12,6 +12,7 @@
#include "engine_type.h"
#include "tile_type.h"
#include "core/pool_type.hpp"
+#include "house_type.h"
#include "newgrf_cargo.h"
#include "newgrf_callbacks.h"
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index b279b164b..16e29a3d2 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -28,6 +28,7 @@
#include "station_map.h"
#include "functions.h"
#include "elrail_func.h"
+#include "town.h"
#include "table/strings.h"
#include "table/railtypes.h"
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index caa365766..81d8b36b5 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -27,6 +27,7 @@
#include "effectvehicle_func.h"
#include "elrail_func.h"
#include "roadveh.h"
+#include "town.h"
#include "table/sprites.h"
#include "table/strings.h"
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 2b1bd15e6..78c86bb43 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -28,6 +28,7 @@
#include "../company_func.h"
#include "../road_cmd.h"
#include "../ai/ai.hpp"
+#include "../town.h"
#include "table/strings.h"
diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
index 1c621aab6..2667997f0 100644
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -6,7 +6,7 @@
#include "../newgrf_house.h"
#include "../newgrf_commons.h"
#include "../variables.h"
-#include "../town_map.h"
+#include "../town.h"
#include "saveload.h"
diff --git a/src/town.h b/src/town.h
index 0f34d1fd3..a55d45e3d 100644
--- a/src/town.h
+++ b/src/town.h
@@ -19,77 +19,7 @@
#include "economy_type.h"
#include "map_type.h"
#include "command_type.h"
-
-enum {
- HOUSE_NO_CLASS = 0,
- NEW_HOUSE_OFFSET = 110,
- HOUSE_MAX = 512,
- INVALID_TOWN = 0xFFFF,
- INVALID_HOUSE_ID = 0xFFFF,
-
- /* There can only be as many classes as there are new houses, plus one for
- * NO_CLASS, as the original houses don't have classes. */
- HOUSE_CLASS_MAX = HOUSE_MAX - NEW_HOUSE_OFFSET + 1,
-};
-
-enum BuildingFlags {
- TILE_NO_FLAG = 0,
- TILE_SIZE_1x1 = 1U << 0,
- TILE_NOT_SLOPED = 1U << 1,
- TILE_SIZE_2x1 = 1U << 2,
- TILE_SIZE_1x2 = 1U << 3,
- TILE_SIZE_2x2 = 1U << 4,
- BUILDING_IS_ANIMATED = 1U << 5,
- BUILDING_IS_CHURCH = 1U << 6,
- BUILDING_IS_STADIUM = 1U << 7,
- BUILDING_HAS_1_TILE = TILE_SIZE_1x1 | TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
- BUILDING_HAS_2_TILES = TILE_SIZE_2x1 | TILE_SIZE_1x2 | TILE_SIZE_2x2,
- BUILDING_2_TILES_X = TILE_SIZE_2x1 | TILE_SIZE_2x2,
- BUILDING_2_TILES_Y = TILE_SIZE_1x2 | TILE_SIZE_2x2,
- BUILDING_HAS_4_TILES = TILE_SIZE_2x2,
-};
-
-DECLARE_ENUM_AS_BIT_SET(BuildingFlags)
-
-enum HouseZonesBits {
- HZB_BEGIN = 0,
- HZB_TOWN_EDGE = 0,
- HZB_TOWN_OUTSKIRT,
- HZB_TOWN_OUTER_SUBURB,
- HZB_TOWN_INNER_SUBURB,
- HZB_TOWN_CENTRE,
- HZB_END,
-};
-assert_compile(HZB_END == 5);
-
-DECLARE_POSTFIX_INCREMENT(HouseZonesBits)
-
-enum HouseZones { ///< Bit Value Meaning
- HZ_NOZNS = 0x0000, ///< 0 This is just to get rid of zeros, meaning none
- HZ_ZON1 = 1U << HZB_TOWN_EDGE, ///< 0..4 1,2,4,8,10 which town zones the building can be built in, Zone1 been the further suburb
- HZ_ZON2 = 1U << HZB_TOWN_OUTSKIRT,
- HZ_ZON3 = 1U << HZB_TOWN_OUTER_SUBURB,
- HZ_ZON4 = 1U << HZB_TOWN_INNER_SUBURB,
- HZ_ZON5 = 1U << HZB_TOWN_CENTRE, ///< center of town
- HZ_ZONALL = 0x001F, ///< 1F This is just to englobe all above types at once
- HZ_SUBARTC_ABOVE = 0x0800, ///< 11 800 can appear in sub-arctic climate above the snow line
- HZ_TEMP = 0x1000, ///< 12 1000 can appear in temperate climate
- HZ_SUBARTC_BELOW = 0x2000, ///< 13 2000 can appear in sub-arctic climate below the snow line
- HZ_SUBTROPIC = 0x4000, ///< 14 4000 can appear in subtropical climate
- HZ_TOYLND = 0x8000 ///< 15 8000 can appear in toyland climate
-};
-
-DECLARE_ENUM_AS_BIT_SET(HouseZones)
-
-enum HouseExtraFlags {
- NO_EXTRA_FLAG = 0,
- BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical
- BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
- SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses
- CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits
-};
-
-DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
+#include "town_map.h"
template <typename T>
struct BuildingCounts {
@@ -100,6 +30,8 @@ struct BuildingCounts {
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4; ///< value for custom town number in difficulty settings
static const uint CUSTOM_TOWN_MAX_NUMBER = 5000; ///< this is the maximum number of towns a user can specify in customisation
+static const uint INVALID_TOWN = 0xFFFF;
+
typedef Pool<Town, TownID, 64, 64000> TownPool;
extern TownPool _town_pool;
@@ -205,48 +137,10 @@ struct Town : TownPool::PoolItem<&_town_pool> {
}
};
-struct HouseSpec {
- /* Standard properties */
- Year min_year; ///< introduction year of the house
- Year max_year; ///< last year it can be built
- byte population; ///< population (Zero on other tiles in multi tile house.)
- byte removal_cost; ///< cost multiplier for removing it
- StringID building_name; ///< building name
- uint16 remove_rating_decrease; ///< rating decrease if removed
- byte mail_generation; ///< mail generation multiplier (tile based, as the acceptances below)
- byte cargo_acceptance[3]; ///< acceptance level for the cargo slots
- CargoID accepts_cargo[3]; ///< 3 input cargo slots
- BuildingFlags building_flags; ///< some flags that describe the house (size, stadium etc...)
- HouseZones building_availability; ///< where can it be built (climates, zones)
- bool enabled; ///< the house is available to build (true by default, but can be disabled by newgrf)
-
- /* NewHouses properties */
- HouseID substitute_id; ///< which original house this one is based on
- struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the house
- HouseID override; ///< which house this one replaces
- uint16 callback_mask; ///< House callback flags
- byte random_colour[4]; ///< 4 "random" colours
- byte probability; ///< Relative probability of appearing (16 is the standard value)
- HouseExtraFlags extra_flags; ///< some more flags
- HouseClassID class_id; ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44
- byte animation_frames; ///< number of animation frames
- byte animation_speed; ///< amount of time between each of those frames
- byte processing_time; ///< Periodic refresh multiplier
- byte minimum_life; ///< The minimum number of years this house will survive before the town rebuilds it
-
- /* grf file related properties*/
- uint8 local_id; ///< id defined by the grf file for this house
- const struct GRFFile *grffile; ///< grf file that introduced this house
-
- /**
- * Get the cost for removing this house
- * @return the cost (inflation corrected etc)
- */
- Money GetRemovalCost() const;
-
-};
-
-extern HouseSpec _house_specs[HOUSE_MAX];
+static inline Town *GetTownByTile(TileIndex tile)
+{
+ return Town::Get(GetTownIndex(tile));
+}
uint32 GetWorldPopulation();
@@ -268,10 +162,6 @@ enum TownRatingCheckType {
* in TTD. */
static const byte TOWN_GROWTH_FREQUENCY = 70;
-/** Simple value that indicates the house has reached the final stage of
- * construction. */
-static const byte TOWN_HOUSE_COMPLETED = 3;
-
/** This enum is used in conjonction with town->flags.
* IT simply states what bit is used for.
* It is pretty unrealistic (IMHO) to only have one church/stadium
@@ -286,11 +176,6 @@ enum {
bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type);
-static inline HouseSpec *GetHouseSpecs(HouseID house_id)
-{
- assert(house_id < HOUSE_MAX);
- return &_house_specs[house_id];
-}
TileIndexDiff GetHouseNorthPart(HouseID &house);
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 085d6f250..a14c1330d 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -43,6 +43,7 @@
#include "subsidy_func.h"
#include "core/smallmap_type.hpp"
#include "core/pool_func.hpp"
+#include "town.h"
#include "table/strings.h"
#include "table/town_land.h"
diff --git a/src/town_map.h b/src/town_map.h
index e1007a030..66ff29cd0 100644
--- a/src/town_map.h
+++ b/src/town_map.h
@@ -5,8 +5,9 @@
#ifndef TOWN_MAP_H
#define TOWN_MAP_H
-#include "town.h"
#include "tile_map.h"
+#include "town_type.h"
+#include "house.h"
/**
* Get the index of which town this house/street is attached to.
@@ -34,16 +35,6 @@ static inline void SetTownIndex(TileIndex t, TownID index)
}
/**
- * Gets the town associated with the house or road tile
- * @param t the tile to get the town of
- * @return the town
- */
-static inline Town *GetTownByTile(TileIndex t)
-{
- return Town::Get(GetTownIndex(t));
-}
-
-/**
* Get the type of this house, which is an index into the house spec array
* Since m4 is only a byte and we want to support 512 houses, we use the bit 6
* of m3 as an additional bit to house type.
diff --git a/src/town_type.h b/src/town_type.h
index d56b934df..9c4a4b6e6 100644
--- a/src/town_type.h
+++ b/src/town_type.h
@@ -8,11 +8,7 @@
#include "core/enum_type.hpp"
typedef uint16 TownID;
-typedef uint16 HouseID;
-typedef uint16 HouseClassID;
-
struct Town;
-struct HouseSpec;
/** Supported initial town sizes */
enum TownSize {