|
|
/* $Id$ */
|
|
|
|
|
|
/*
|
|
|
* This file is part of OpenTTD.
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
/** @file newgrf_industries.cpp Handling of NewGRF industries. */
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "debug.h"
|
|
|
#include "tile_type.h"
|
|
|
#include "strings_type.h"
|
|
|
#include "company_type.h"
|
|
|
#include "industry_map.h"
|
|
|
#include "industry.h"
|
|
|
#include "newgrf.h"
|
|
|
#include "newgrf_industries.h"
|
|
|
#include "newgrf_commons.h"
|
|
|
#include "newgrf_text.h"
|
|
|
#include "newgrf_town.h"
|
|
|
#include "window_func.h"
|
|
|
#include "town.h"
|
|
|
#include "company_base.h"
|
|
|
#include "command_func.h"
|
|
|
#include "gui.h"
|
|
|
#include "strings_func.h"
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
|
static uint32 _industry_creation_random_bits;
|
|
|
|
|
|
/* Since the industry IDs defined by the GRF file don't necessarily correlate
|
|
|
* to those used by the game, the IDs used for overriding old industries must be
|
|
|
* translated when the idustry spec is set. */
|
|
|
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
|
|
|
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
|
|
|
|
|
|
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
|
|
|
{
|
|
@@ -221,57 +221,57 @@ uint32 IndustryGetVariable(const Resolve
|
|
|
byte colours;
|
|
|
bool is_ai = false;
|
|
|
|
|
|
const Company *c = Company::GetIfValid(industry->founder);
|
|
|
if (c != NULL) {
|
|
|
const Livery *l = &c->livery[LS_DEFAULT];
|
|
|
|
|
|
is_ai = c->is_ai;
|
|
|
colours = l->colour1 + l->colour2 * 16;
|
|
|
} else {
|
|
|
colours = GB(Random(), 0, 8);
|
|
|
}
|
|
|
|
|
|
return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
|
|
|
}
|
|
|
|
|
|
case 0x46: return industry->construction_date; // Date when built - long format - (in days)
|
|
|
|
|
|
/* Get industry ID at offset param */
|
|
|
case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), industry);
|
|
|
|
|
|
/* Get random tile bits at offset param */
|
|
|
case 0x61:
|
|
|
tile = GetNearbyTile(parameter, tile);
|
|
|
return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
|
|
|
return (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
|
|
|
|
|
|
/* Land info of nearby tiles */
|
|
|
case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY);
|
|
|
|
|
|
/* Animation stage of nearby tiles */
|
|
|
case 0x63:
|
|
|
tile = GetNearbyTile(parameter, tile);
|
|
|
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) {
|
|
|
if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile) == industry) {
|
|
|
return GetIndustryAnimationState(tile);
|
|
|
}
|
|
|
return 0xFFFFFFFF;
|
|
|
|
|
|
/* Distance of nearest industry of given type */
|
|
|
case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
|
|
|
/* Get town zone and Manhattan distance of closest town */
|
|
|
case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
|
|
|
/* Get square of Euclidian distance of closes town */
|
|
|
case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF);
|
|
|
|
|
|
/* Count of industry, distance of closest instance
|
|
|
* 68 is the same as 67, but with a filtering on selected layout */
|
|
|
case 0x67:
|
|
|
case 0x68: return GetCountAndDistanceOfClosestInstance(parameter, variable == 0x68 ? GB(GetRegister(0x101), 0, 8) : 0, industry);
|
|
|
|
|
|
/* Get a variable from the persistent storage */
|
|
|
case 0x7C: return industry->psa.Get(parameter);
|
|
|
|
|
|
/* Industry structure access*/
|
|
|
case 0x80: return industry->xy;
|
|
|
case 0x81: return GB(industry->xy, 8, 8);
|
|
|
/* Pointer to the town the industry is associated with */
|
|
|
case 0x82: return industry->town->index;
|