summaryrefslogtreecommitdiff
path: root/src/industry.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-02 23:21:52 +0000
committerrubidium <rubidium@openttd.org>2007-08-02 23:21:52 +0000
commite4149482ec1c1d5424327983df2ebf2419ffe273 (patch)
tree492ddfe6412cdabdaaaa435390d2417c774cf096 /src/industry.h
parent549450d31a4676039e2663e66e23e2f5bae3f7f1 (diff)
downloadopenttd-e4149482ec1c1d5424327983df2ebf2419ffe273.tar.xz
(svn r10759) -Codechange: make the industry struct use the pool item class as super class.
Diffstat (limited to 'src/industry.h')
-rw-r--r--src/industry.h36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/industry.h b/src/industry.h
index 2dc562d20..408c85860 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -86,10 +86,13 @@ enum IndustyBehaviour {
DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
+struct Industry;
+DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
+
/**
* Defines the internal data of a functionnal industry
*/
-struct Industry {
+struct Industry : PoolItem<Industry, IndustryID, &_Industry_pool> {
TileIndex xy; ///< coordinates of the primary tile the industry is built one
byte width;
byte height;
@@ -111,12 +114,15 @@ struct Industry {
Year last_prod_year; ///< last year of production
byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
- IndustryID index; ///< index of the industry in the pool of industries
-
OwnerByte founder; ///< Founder of the industry
Date construction_date; ///< Date of the construction of the industry
uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType)
Date last_cargo_accepted_at; ///< Last day cargo was accepted by this industry
+
+ Industry(TileIndex tile = 0) : xy(tile) {}
+ ~Industry();
+
+ bool IsValid() const { return this->xy != 0; }
};
struct IndustryTileTable {
@@ -216,18 +222,6 @@ extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
/* smallmap_gui.cpp */
void BuildIndustriesLegend();
-DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
-
-/**
- * Check if an Industry really exists.
- * @param industry to check
- * @return true if position is a valid one
- */
-static inline bool IsValidIndustry(const Industry *industry)
-{
- return industry->xy != 0;
-}
-
/**
* Check if an Industry exists whithin the pool of industries
* @param index of the desired industry
@@ -235,7 +229,7 @@ static inline bool IsValidIndustry(const Industry *industry)
*/
static inline bool IsValidIndustryID(IndustryID index)
{
- return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
+ return index < GetIndustryPoolSize() && GetIndustry(index)->IsValid();
}
@@ -318,15 +312,7 @@ static inline Industry *GetRandomIndustry()
return GetIndustry(index);
}
-void DestroyIndustry(Industry *i);
-
-static inline void DeleteIndustry(Industry *i)
-{
- DestroyIndustry(i);
- i->xy = 0;
-}
-
-#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
+#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (i->IsValid())
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
extern const Industry **_industry_sort;