Changeset - r12912:a127fd7ac355
[Not reviewed]
master
0 3 0
rubidium - 15 years ago 2009-09-04 20:04:54
rubidium@openttd.org
(svn r17414) -Codechange: only send/read the number of bits that can be actually useful when building industries
3 files changed with 12 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_industrytype.cpp
Show inline comments
 
@@ -105,13 +105,13 @@
 
/* static */ bool AIIndustryType::BuildIndustry(IndustryType industry_type, TileIndex tile)
 
{
 
	EnforcePrecondition(false, CanBuildIndustry(industry_type));
 
	EnforcePrecondition(false, AIMap::IsValidTile(tile));
 

	
 
	uint32 seed = ::InteractiveRandom();
 
	return AIObject::DoCommand(tile, (::InteractiveRandomRange(::GetIndustrySpec(industry_type)->num_table) << 16) | industry_type, seed, CMD_BUILD_INDUSTRY);
 
	return AIObject::DoCommand(tile, (::InteractiveRandomRange(::GetIndustrySpec(industry_type)->num_table) << 8) | industry_type, seed, CMD_BUILD_INDUSTRY);
 
}
 

	
 
/* static */ bool AIIndustryType::ProspectIndustry(IndustryType industry_type)
 
{
 
	EnforcePrecondition(false, CanProspectIndustry(industry_type));
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -1668,36 +1668,34 @@ 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
 
 * - p1 = (bit  0 -  7) - industry type see build_industry.h and see industry.h
 
 * - p1 = (bit  8 - 15) - 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, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	IndustryType it = GB(p1, 0, 16);
 
	IndustryType it = GB(p1, 0, 8);
 
	if (it >= NUM_INDUSTRYTYPES) return CMD_ERROR;
 

	
 
	const IndustrySpec *indspec = GetIndustrySpec(it);
 
	const Industry *ind = NULL;
 

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

	
 
	/* If the setting 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;
 
	}
 

	
 
	const Industry *ind = NULL;
 
	if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
 
		if (flags & DC_EXEC) {
 
			/* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */
 
			CompanyID founder = _current_company;
 
			_current_company = OWNER_TOWN;
 
			/* Prospecting has a chance to fail, however we cannot guarantee that something can
 
@@ -1706,33 +1704,33 @@ CommandCost CmdBuildIndustry(TileIndex t
 
			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();
 
					ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2, founder);
 
					ind = CreateNewIndustryHelper(tile, it, flags, indspec, RandomRange(indspec->num_table), p2, founder);
 
					if (ind != NULL) {
 
						break;
 
					}
 
				}
 
			}
 
			_current_company = founder;
 
		}
 
	} else {
 
		int count = indspec->num_table;
 
		const IndustryTileTable * const *itt = indspec->table;
 
		int num = GB(p1, 16, 16);
 
		int num = GB(p1, 8, 8);
 
		if (num >= count) return CMD_ERROR;
 

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

	
 
		ind = CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2, _current_company);
 
		ind = CreateNewIndustryHelper(tile, it, flags, indspec, num, p2, _current_company);
 
		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) {
src/industry_gui.cpp
Show inline comments
 
@@ -382,22 +382,22 @@ public:
 
				return;
 
			}
 

	
 
			_current_company = OWNER_NONE;
 
			_generating_world = true;
 
			_ignore_restrictions = true;
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
			if (!success) {
 
				SetDParam(0, indsp->name);
 
				ShowErrorMessage(_error_message, STR_ERROR_CAN_T_BUILD_HERE, pt.x, pt.y);
 
			}
 

	
 
			_ignore_restrictions = false;
 
			_generating_world = false;
 
		} else {
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
			success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
 
		}
 

	
 
		/* If an industry has been built, just reset the cursor and the system */
 
		if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 

	
0 comments (0 inline, 0 general)