Changeset - r7185:239823a9a847
[Not reviewed]
master
0 3 0
rubidium - 17 years ago 2007-07-06 22:33:16
rubidium@openttd.org
(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.
3 files changed with 34 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
@@ -138,24 +138,36 @@ struct IndustrySpec {
 
	StringID closure_text;                ///< Message appearing when the industry closes
 
	StringID production_up_text;          ///< Message appearing when the industry's production is increasing
 
	StringID production_down_text;        ///< Message appearing when the industry's production is decreasing
 
	byte appear_ingame[NUM_LANDSCAPE];    ///< Probability of appearance in game
 
	byte appear_creation[NUM_LANDSCAPE];  ///< Probability of appearance during map creation
 
	uint8 number_of_sounds;               ///< Number of sounds available in the sounds array
 
	const uint8 *random_sounds;           ///< array of random sounds.
 
	/* Newgrf data */
 
	uint16 callback_flags;                ///< Flags telling which grf callback is set
 
	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;
 
};
 

	
 
/**
 
 * Defines the data structure of each indivudual tile of an industry.
 
 */
 
struct IndustryTileSpec {
 
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
 
	uint8 acceptance[3];                  ///< Level of aceptance per cargo type
 
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
 
	byte anim_production;                 ///< Animation frame to start when goods are produced
 
	byte anim_next;                       ///< Next frame in an animation
 
	bool anim_state;                      ///< When true, the tile has to be drawn using the animation
src/industry_cmd.cpp
Show inline comments
 
@@ -1496,59 +1496,55 @@ CommandCost CmdBuildIndustry(TileIndex t
 
	const IndustryTileTable *it;
 
	const IndustrySpec *indspec;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 

	
 
	indspec = GetIndustrySpec(p1);
 

	
 
	/* Check if the to-be built/founded industry is available for this climate. */
 
	if (!indspec->enabled) {
 
		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
 
			 * is nothing we can really do about that. */
 
			if (Random() <= indspec->prospecting_chance) {
 
				for (int i = 0; i < 5000; i++) {
 
					const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)];
 
					if (CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, it) != NULL) break;
 
				}
 
			}
 
		}
 
	} else {
 
		num = indspec->num_table;
 
		itt = indspec->table;
 

	
 

	
 
		do {
 
			if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
 
		} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
 

	
 
		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());
 
}
 

	
 

	
 
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 
	const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)];
 

	
 
	return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it);
 
}
 

	
 
static const byte _numof_industry_table[5][11] = {
 
@@ -1886,24 +1882,41 @@ void IndustryMonthlyLoop()
 

	
 

	
 
void InitializeIndustries()
 
{
 
	CleanPool(&_Industry_pool);
 
	AddBlockToPool(&_Industry_pool);
 

	
 
	ResetIndustryCounts();
 
	_industry_sort_dirty = true;
 
	_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 */
 
	ClearTile_Industry,          /* clear_tile_proc */
 
	GetAcceptedCargo_Industry,   /* get_accepted_cargo_proc */
 
	GetTileDesc_Industry,        /* get_tile_desc_proc */
 
	GetTileTrackStatus_Industry, /* get_tile_track_status_proc */
 
	ClickTile_Industry,          /* click_tile_proc */
 
	AnimateTile_Industry,        /* animate_tile_proc */
 
	TileLoop_Industry,           /* tile_loop_proc */
 
	ChangeTileOwner_Industry,    /* change_tile_owner_proc */
 
	GetProducedCargo_Industry,   /* get_produced_cargo_proc */
src/industry_gui.cpp
Show inline comments
 
@@ -30,25 +30,25 @@ const byte _build_industry_types[4][12] 
 
};
 

	
 
static void UpdateIndustryProduction(Industry *i);
 

	
 
static void BuildIndustryWndProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
	case WE_PAINT:
 
		DrawWindowWidgets(w);
 
		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;
 

	
 
	case WE_CLICK: {
 
		int wid = e->we.click.widget;
 
		if (wid >= 3) {
 
			if (HandlePlacePushButton(w, wid, SPR_CURSOR_INDUSTRY, 1, NULL))
 
				WP(w, def_d).data_1 = wid - 3;
 
		}
 
	} break;
 

	
0 comments (0 inline, 0 general)