Changeset - r9732:9f7ac9c243a2
[Not reviewed]
master
0 1 0
belugas - 16 years ago 2008-07-28 23:37:19
belugas@openttd.org
(svn r13864) -Feature(FS #2164): All industry creations are now generating a news event, even those funded by a real player.
1 file changed with 15 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1625,75 +1625,79 @@ static Industry *CreateNewIndustryHelper
 
/** Build/Fund an industry
 
 * @param tile tile where industry is built
 
 * @param flags of operations to conduct
 
 * @param p1 various bitstuffed elements
 
 * - p1 = (bit  0 - 15) - industry type see build_industry.h and see industry.h
 
 * - p1 = (bit 16 - 31) - first layout to try
 
 * @param p2 seed to use for variable 8F
 
 * @return index of the newly create industry, or CMD_ERROR if it failed
 
 */
 
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16));
 
	const Industry *ind = NULL;
 

	
 
	/* Check if the to-be built/founded industry is available for this climate. */
 
	if (!indspec->enabled) {
 
		return CMD_ERROR;
 
	}
 

	
 
	/* 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) */
 
	if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (_game_mode != GM_EDITOR && _settings_game.construction.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++) {
 
					/* We should not have more than one Random() in a function call
 
					 * because parameter evaluation order is not guaranteed in the c++ standard
 
					 */
 
					tile = RandomTile();
 
					const Industry *ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2);
 
					ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2);
 
					if (ind != NULL) {
 
						SetDParam(0, indspec->name);
 
						if (indspec->new_industry_text > STR_LAST_STRINGID) {
 
							SetDParam(1, STR_TOWN);
 
							SetDParam(2, ind->town->index);
 
						} else {
 
							SetDParam(1, ind->town->index);
 
						}
 
						AddNewsItem(indspec->new_industry_text,
 
								NS_OPENCLOSE, ind->xy, 0);
 
						break;
 
					}
 
				}
 
			}
 
		}
 
	} else {
 
		int count = indspec->num_table;
 
		const IndustryTileTable * const *itt = indspec->table;
 
		int num = Clamp(GB(p1, 16, 16), 0, count - 1);
 

	
 
		_error_message = STR_0239_SITE_UNSUITABLE;
 
		do {
 
			if (--count < 0) return CMD_ERROR;
 
			if (--num < 0) num = indspec->num_table - 1;
 
		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
 

	
 
		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2) == NULL) return CMD_ERROR;
 
		ind = CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2);
 
		if (ind == NULL) return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC && _game_mode != GM_EDITOR && ind != NULL) {
 
		SetDParam(0, indspec->name);
 
		if (indspec->new_industry_text > STR_LAST_STRINGID) {
 
			SetDParam(1, STR_TOWN);
 
			SetDParam(2, ind->town->index);
 
		} else {
 
			SetDParam(1, ind->town->index);
 
		}
 
		AddNewsItem(indspec->new_industry_text, NS_OPENCLOSE, ind->xy, 0);
 
	}
 

	
 
	return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
 
}
 

	
 

	
 
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 

	
 
	uint32 seed = Random();
 
	return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed);
0 comments (0 inline, 0 general)