summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-06 22:33:16 +0000
committerrubidium <rubidium@openttd.org>2007-07-06 22:33:16 +0000
commitc86015203aa7e85cd4e5d6044896a203028ca16a (patch)
tree1de87f9b435b1ab9b67128267575da1d07cd652e
parent472bfba5f8273ae5aff61a4a2c514b6b57d1ed49 (diff)
downloadopenttd-c86015203aa7e85cd4e5d6044896a203028ca16a.tar.xz
(svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
-rw-r--r--src/industry.h12
-rw-r--r--src/industry_cmd.cpp29
-rw-r--r--src/industry_gui.cpp2
3 files changed, 34 insertions, 9 deletions
diff --git a/src/industry.h b/src/industry.h
index 505c14096..d8fea7356 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -147,6 +147,18 @@ struct IndustrySpec {
uint8 cleanup_flag; ///< flags indicating which data should be freed upon cleaning up
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
struct GRFFileProps grf_prop; ///< properties related the the grf file
+
+ /**
+ * Is an industry with the spec a raw industry?
+ * @return true if it should be handled as a raw industry
+ */
+ bool IsRawIndustry() const;
+
+ /**
+ * Get the cost for constructing this industry
+ * @return the cost (inflation corrected etc)
+ */
+ Money GetConstructionCost() const;
};
/**
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index cf6572dac..3deb5c673 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1505,17 +1505,13 @@ CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
return CMD_ERROR;
}
- bool raw_industry = indspec->accepts_cargo[0] == CT_INVALID && indspec->accepts_cargo[1] == CT_INVALID &&
- indspec->accepts_cargo[2] == CT_INVALID && !(indspec->behaviour & INDUSTRYBEH_CUT_TREES);
-
/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
- * Raw material industries are industries that do not accept cargo (at least for now)
- * Exclude the lumber mill (only "raw" industry that can be built) */
- if (raw_industry && _patches.raw_industry_construction == 0) {
+ * Raw material industries are industries that do not accept cargo (at least for now) */
+ if (_patches.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
return CMD_ERROR;
}
- if (raw_industry && _patches.raw_industry_construction == 2) {
+ if (_patches.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
if (flags & DC_EXEC) {
/* Prospecting has a chance to fail, however we cannot guarantee that something can
* be built on the map, so the chance gets lower when the map is fuller, but there
@@ -1539,7 +1535,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR;
}
- return CommandCost((_price.build_industry >> 8) * ((_patches.raw_industry_construction == 1) ? indspec->raw_industry_cost_multiplier : indspec->cost_multiplier));
+ return CommandCost(indspec->GetConstructionCost());
}
@@ -1895,6 +1891,23 @@ void InitializeIndustries()
_industry_sound_tile = 0;
}
+bool IndustrySpec::IsRawIndustry() const
+{
+ /* Lumber mills are extractive/organic, but can always be built like a non-raw industry */
+ return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0 &&
+ (this->behaviour & INDUSTRYBEH_CUT_TREES) == 0;
+}
+
+Money IndustrySpec::GetConstructionCost() const
+{
+ return (_price.build_industry *
+ (_patches.raw_industry_construction == 1 && this->IsRawIndustry() ?
+ this->raw_industry_cost_multiplier :
+ this->cost_multiplier
+ )) >> 8;
+}
+
+
extern const TileTypeProcs _tile_type_industry_procs = {
DrawTile_Industry, /* draw_tile_proc */
GetSlopeZ_Industry, /* get_slope_z_proc */
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index fa0b9746d..fb1481145 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -39,7 +39,7 @@ static void BuildIndustryWndProc(Window *w, WindowEvent *e)
if (_thd.place_mode == 1 && _thd.window_class == WC_BUILD_INDUSTRY) {
int ind_type = _build_industry_types[_opt_ptr->landscape][WP(w, def_d).data_1];
- SetDParam(0, (_price.build_industry >> 8) * (_patches.raw_industry_construction == 1 ? GetIndustrySpec(ind_type)->raw_industry_cost_multiplier : GetIndustrySpec(ind_type)->cost_multiplier));
+ SetDParam(0, GetIndustrySpec(ind_type)->GetConstructionCost());
DrawStringCentered(85, w->height - 21, STR_482F_COST, 0);
}
break;