summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-24 19:56:43 +0000
committerrubidium <rubidium@openttd.org>2007-07-24 19:56:43 +0000
commitfe8e2979954ed2e129af7a23ec76c6aea73c36da (patch)
treec3eb0b717ba232c1a35aae37f75f9c5c10ed767e
parent5d3f058b65c97b61709061b721d1ad6922dbc9ef (diff)
downloadopenttd-fe8e2979954ed2e129af7a23ec76c6aea73c36da.tar.xz
(svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
-rw-r--r--src/industry.h44
-rw-r--r--src/industry_cmd.cpp4
-rw-r--r--src/industry_gui.cpp4
-rw-r--r--src/station_cmd.cpp108
-rw-r--r--src/table/build_industry.h41
5 files changed, 125 insertions, 76 deletions
diff --git a/src/industry.h b/src/industry.h
index e6f17492d..12dbb5f8f 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -105,7 +105,7 @@ struct Industry {
uint16 last_month_transported[2]; ///< total units transported per cargo in the last full month
uint16 counter; ///< used for animation and/or production (if available cargo)
- IndustryType type; ///< type of industry. see IT_COAL_MINE and others
+ IndustryType type; ///< type of industry.
OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
byte random_color; ///< randomized colour of the industry, for display purpose
Year last_prod_year; ///< last year of production
@@ -332,46 +332,6 @@ static inline void DeleteIndustry(Industry *i)
extern const Industry **_industry_sort;
extern bool _industry_sort_dirty;
-enum {
- IT_COAL_MINE = 0,
- IT_POWER_STATION = 1,
- IT_SAWMILL = 2,
- IT_FOREST = 3,
- IT_OIL_REFINERY = 4,
- IT_OIL_RIG = 5,
- IT_FACTORY = 6,
- IT_PRINTING_WORKS = 7,
- IT_STEEL_MILL = 8,
- IT_FARM = 9,
- IT_COPPER_MINE = 10,
- IT_OIL_WELL = 11,
- IT_BANK_TEMP = 12,
- IT_FOOD_PROCESS = 13,
- IT_PAPER_MILL = 14,
- IT_GOLD_MINE = 15,
- IT_BANK_TROPIC_ARCTIC = 16,
- IT_DIAMOND_MINE = 17,
- IT_IRON_MINE = 18,
- IT_FRUIT_PLANTATION = 19,
- IT_RUBBER_PLANTATION = 20,
- IT_WATER_SUPPLY = 21,
- IT_WATER_TOWER = 22,
- IT_FACTORY_2 = 23,
- IT_FARM_2 = 24,
- IT_LUMBER_MILL = 25,
- IT_COTTON_CANDY = 26,
- IT_CANDY_FACTORY = 27,
- IT_BATTERY_FARM = 28,
- IT_COLA_WELLS = 29,
- IT_TOY_SHOP = 30,
- IT_TOY_FACTORY = 31,
- IT_PLASTIC_FOUNTAINS = 32,
- IT_FIZZY_DRINK_FACTORY = 33,
- IT_BUBBLE_GENERATOR = 34,
- IT_TOFFEE_QUARRY = 35,
- IT_SUGAR_MINE = 36,
- IT_END,
- IT_INVALID = 255,
-};
+static const uint8 IT_INVALID = 255;
#endif /* INDUSTRY_H */
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index a6ef9c2a5..958f1a013 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1669,7 +1669,7 @@ void GenerateIndustries()
/* Find the total amount of industries */
if (_opt.diff.number_industries > 0) {
- for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
+ for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
ind_spc = GetIndustrySpec(it);
@@ -1694,7 +1694,7 @@ void GenerateIndustries()
SetGeneratingWorldProgress(GWP_INDUSTRY, i);
if (_opt.diff.number_industries > 0) {
- for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
+ for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
/* Once the number of industries has been determined, let's really create them.
* The test for chance allows us to try create industries that are available only
* for this landscape.
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 600878eae..7b98af0be 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -114,7 +114,7 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
/* We'll perform two distinct loops, one for secondary industries, and the other one for
* primary ones. Each loop will fill the _fund_gui structure. */
- for (ind = IT_COAL_MINE; ind < NUM_INDUSTRYTYPES; ind++) {
+ for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
indsp = GetIndustrySpec(ind);
if (indsp->enabled && (!indsp->IsRawIndustry() || _game_mode == GM_EDITOR)) {
_fund_gui.index[_fund_gui.count] = ind;
@@ -124,7 +124,7 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
}
if (_patches.raw_industry_construction != 0 && _game_mode != GM_EDITOR) {
- for (ind = IT_COAL_MINE; ind < NUM_INDUSTRYTYPES; ind++) {
+ for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
indsp = GetIndustrySpec(ind);
if (indsp->enabled && indsp->IsRawIndustry()) {
_fund_gui.index[_fund_gui.count] = ind;
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index a5c8df484..df788d997 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -137,6 +137,12 @@ static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest
return (closest_station == INVALID_STATION) ? NULL : GetStation(closest_station);
}
+/**
+ * Function to check whether the given tile matches some criterion.
+ * @param tile the tile to check
+ * @return true if it matches, false otherwise
+ */
+typedef bool (*CMSAMatcher)(TileIndex tile);
/**
* Counts the numbers of tiles matching a specific type in the area around
@@ -146,39 +152,85 @@ static Station* GetStationAround(TileIndex tile, int w, int h, StationID closest
* in all other cases this parameter is ignored
* @return the result the noumber of matching tiles around
*/
-static int CountMapSquareAround(TileIndex tile, TileType type, IndustryType industry)
+static int CountMapSquareAround(TileIndex tile, CMSAMatcher cmp)
{
int num = 0;
for (int dx = -3; dx <= 3; dx++) {
for (int dy = -3; dy <= 3; dy++) {
- TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(dx, dy));
-
- if (IsTileType(cur_tile, type)) {
- switch (type) {
- case MP_INDUSTRY:
- if (GetIndustryType(cur_tile) == industry)
- num++;
- break;
-
- case MP_WATER:
- if (!IsWater(cur_tile))
- break;
- /* FALL THROUGH WHEN WATER TILE */
- case MP_TREES:
- num++;
- break;
-
- default:
- break;
- }
- }
+ if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++;
}
}
return num;
}
+/**
+ * Check whether the tile is a mine.
+ * @param tile the tile to investigate.
+ * @return true if and only if the tile is a mine
+ */
+static bool CMSAMine(TileIndex tile)
+{
+ /* No industry */
+ if (!IsTileType(tile, MP_INDUSTRY)) return false;
+
+ const IndustrySpec *indsp = GetIndustrySpec(GetIndustryByTile(tile)->type);
+
+ /* No extractive industry */
+ if ((indsp->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
+
+ for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) {
+ /* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */
+ if (indsp->produced_cargo[i] != CT_INVALID && (GetCargo(indsp->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
+ }
+
+ return false;
+}
+
+/**
+ * Check whether the tile is water.
+ * @param tile the tile to investigate.
+ * @return true if and only if the tile is a mine
+ */
+static bool CMSAWater(TileIndex tile)
+{
+ return IsTileType(tile, MP_WATER) && IsWater(tile);
+}
+
+/**
+ * Check whether the tile is a tree.
+ * @param tile the tile to investigate.
+ * @return true if and only if the tile is a mine
+ */
+static bool CMSATree(TileIndex tile)
+{
+ return IsTileType(tile, MP_TREES);
+}
+
+/**
+ * Check whether the tile is a forest.
+ * @param tile the tile to investigate.
+ * @return true if and only if the tile is a mine
+ */
+static bool CMSAForest(TileIndex tile)
+{
+ /* No industry */
+ if (!IsTileType(tile, MP_INDUSTRY)) return false;
+
+ const IndustrySpec *indsp = GetIndustrySpec(GetIndustryByTile(tile)->type);
+
+ /* No extractive industry */
+ if ((indsp->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
+
+ for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) {
+ /* The industry produces wood. */
+ if (indsp->produced_cargo[i] != CT_INVALID && GetCargo(indsp->produced_cargo[i])->label == 'WOOD') return true;
+ }
+
+ return false;
+}
+
#define M(x) ((x) - STR_SV_STNAME)
static bool GenerateStationName(Station *st, TileIndex tile, int flag)
@@ -221,11 +273,7 @@ static bool GenerateStationName(Station *st, TileIndex tile, int flag)
/* check mine? */
if (HASBIT(free_names, M(STR_SV_STNAME_MINES))) {
- if (CountMapSquareAround(tile, MP_INDUSTRY, IT_COAL_MINE) >= 2 ||
- CountMapSquareAround(tile, MP_INDUSTRY, IT_IRON_MINE) >= 2 ||
- CountMapSquareAround(tile, MP_INDUSTRY, IT_COPPER_MINE) >= 2 ||
- CountMapSquareAround(tile, MP_INDUSTRY, IT_GOLD_MINE) >= 2 ||
- CountMapSquareAround(tile, MP_INDUSTRY, IT_DIAMOND_MINE) >= 2) {
+ if (CountMapSquareAround(tile, CMSAMine) >= 2) {
found = M(STR_SV_STNAME_MINES);
goto done;
}
@@ -243,15 +291,15 @@ static bool GenerateStationName(Station *st, TileIndex tile, int flag)
/* Check lakeside */
if (HASBIT(free_names, M(STR_SV_STNAME_LAKESIDE)) &&
DistanceFromEdge(tile) < 20 &&
- CountMapSquareAround(tile, MP_WATER, 0) >= 5) {
+ CountMapSquareAround(tile, CMSAWater) >= 5) {
found = M(STR_SV_STNAME_LAKESIDE);
goto done;
}
/* Check woods */
if (HASBIT(free_names, M(STR_SV_STNAME_WOODS)) && (
- CountMapSquareAround(tile, MP_TREES, 0) >= 8 ||
- CountMapSquareAround(tile, MP_INDUSTRY, IT_FOREST) >= 2)
+ CountMapSquareAround(tile, CMSATree) >= 8 ||
+ CountMapSquareAround(tile, CMSAForest) >= 2)
) {
found = _opt.landscape == LT_TROPIC ?
M(STR_SV_STNAME_FOREST) : M(STR_SV_STNAME_WOODS);
diff --git a/src/table/build_industry.h b/src/table/build_industry.h
index c0f9b7141..dc342a68a 100644
--- a/src/table/build_industry.h
+++ b/src/table/build_industry.h
@@ -1091,6 +1091,47 @@ static const uint8 _farm_sounds[] = { SND_24_SHEEP, SND_25_COW, SND_26_HORSE };
/** Array with... hem... a sound of toyland */
static const uint8 _plastic_mine_sounds[] = { SND_33_PLASTIC_MINE };
+enum {
+ IT_COAL_MINE = 0,
+ IT_POWER_STATION = 1,
+ IT_SAWMILL = 2,
+ IT_FOREST = 3,
+ IT_OIL_REFINERY = 4,
+ IT_OIL_RIG = 5,
+ IT_FACTORY = 6,
+ IT_PRINTING_WORKS = 7,
+ IT_STEEL_MILL = 8,
+ IT_FARM = 9,
+ IT_COPPER_MINE = 10,
+ IT_OIL_WELL = 11,
+ IT_BANK_TEMP = 12,
+ IT_FOOD_PROCESS = 13,
+ IT_PAPER_MILL = 14,
+ IT_GOLD_MINE = 15,
+ IT_BANK_TROPIC_ARCTIC = 16,
+ IT_DIAMOND_MINE = 17,
+ IT_IRON_MINE = 18,
+ IT_FRUIT_PLANTATION = 19,
+ IT_RUBBER_PLANTATION = 20,
+ IT_WATER_SUPPLY = 21,
+ IT_WATER_TOWER = 22,
+ IT_FACTORY_2 = 23,
+ IT_FARM_2 = 24,
+ IT_LUMBER_MILL = 25,
+ IT_COTTON_CANDY = 26,
+ IT_CANDY_FACTORY = 27,
+ IT_BATTERY_FARM = 28,
+ IT_COLA_WELLS = 29,
+ IT_TOY_SHOP = 30,
+ IT_TOY_FACTORY = 31,
+ IT_PLASTIC_FOUNTAINS = 32,
+ IT_FIZZY_DRINK_FACTORY = 33,
+ IT_BUBBLE_GENERATOR = 34,
+ IT_TOFFEE_QUARRY = 35,
+ IT_SUGAR_MINE = 36,
+ IT_END,
+};
+
/**
* Writes the properties of an industry into the IndustrySpec struct.
* @param tbl tile table