2007-06-09 02:05:51 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file newgrf_industries.h Functions for NewGRF industries. */
|
2007-06-09 02:05:51 +00:00
|
|
|
|
|
|
|
#ifndef NEWGRF_INDUSTRIES_H
|
|
|
|
#define NEWGRF_INDUSTRIES_H
|
|
|
|
|
2012-11-10 20:44:10 +00:00
|
|
|
#include "newgrf_town.h"
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Resolver for industry scopes. */
|
2012-11-10 20:44:10 +00:00
|
|
|
struct IndustriesScopeResolver : public ScopeResolver {
|
2012-11-10 20:46:39 +00:00
|
|
|
TileIndex tile; ///< Tile owned by the industry.
|
|
|
|
Industry *industry; ///< %Industry being resolved.
|
|
|
|
IndustryType type; ///< Type of the industry.
|
|
|
|
uint32 random_bits; ///< Random bits of the new industry.
|
2012-11-10 20:44:10 +00:00
|
|
|
|
2018-03-11 13:19:41 +00:00
|
|
|
/**
|
|
|
|
* Scope resolver for industries.
|
|
|
|
* @param ro Surrounding resolver.
|
|
|
|
* @param tile %Tile owned by the industry.
|
|
|
|
* @param industry %Industry being resolved.
|
|
|
|
* @param type Type of the industry.
|
|
|
|
* @param random_bits Random bits of the new industry.
|
|
|
|
*/
|
|
|
|
IndustriesScopeResolver(ResolverObject &ro, TileIndex tile, Industry *industry, IndustryType type, uint32 random_bits = 0)
|
|
|
|
: ScopeResolver(ro), tile(tile), industry(industry), type(type), random_bits(random_bits)
|
|
|
|
{
|
|
|
|
}
|
2012-11-10 20:44:10 +00:00
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
uint32 GetRandomBits() const override;
|
|
|
|
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
|
|
|
|
uint32 GetTriggers() const override;
|
|
|
|
void StorePSA(uint pos, int32 value) override;
|
2012-11-10 20:44:10 +00:00
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Resolver for industries. */
|
2012-11-10 20:44:10 +00:00
|
|
|
struct IndustriesResolverObject : public ResolverObject {
|
2012-11-10 20:46:39 +00:00
|
|
|
IndustriesScopeResolver industries_scope; ///< Scope resolver for the industry.
|
2019-04-10 21:07:06 +00:00
|
|
|
TownScopeResolver *town_scope; ///< Scope resolver for the associated town (if needed and available, else \c nullptr).
|
2012-11-10 20:44:10 +00:00
|
|
|
|
|
|
|
IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32 random_bits = 0,
|
|
|
|
CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
|
|
|
|
~IndustriesResolverObject();
|
|
|
|
|
|
|
|
TownScopeResolver *GetTown();
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override
|
2012-11-10 20:44:10 +00:00
|
|
|
{
|
|
|
|
switch (scope) {
|
|
|
|
case VSG_SCOPE_SELF: return &industries_scope;
|
|
|
|
case VSG_SCOPE_PARENT: {
|
|
|
|
TownScopeResolver *tsr = this->GetTown();
|
2019-04-10 21:07:06 +00:00
|
|
|
if (tsr != nullptr) return tsr;
|
2012-11-10 20:44:10 +00:00
|
|
|
}
|
2017-08-13 18:38:42 +00:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ResolverObject::GetScope(scope, relative);
|
2012-11-10 20:44:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-09-23 19:27:35 +00:00
|
|
|
/** When should the industry(tile) be triggered for random bits? */
|
|
|
|
enum IndustryTrigger {
|
|
|
|
/** Triggered each tile loop */
|
|
|
|
INDUSTRY_TRIGGER_TILELOOP_PROCESS = 1,
|
|
|
|
/** Triggered (whole industry) each 256 ticks */
|
|
|
|
INDUSTRY_TRIGGER_256_TICKS = 2,
|
|
|
|
/** Triggered on cargo delivery */
|
|
|
|
INDUSTRY_TRIGGER_CARGO_DELIVERY = 4,
|
|
|
|
};
|
|
|
|
|
2012-09-21 09:47:21 +00:00
|
|
|
/** From where has callback #CBID_INDUSTRY_PROBABILITY been called */
|
2008-01-07 14:02:26 +00:00
|
|
|
enum IndustryAvailabilityCallType {
|
2010-10-16 13:15:54 +00:00
|
|
|
IACT_MAPGENERATION, ///< during random map generation
|
|
|
|
IACT_RANDOMCREATION, ///< during creation of random ingame industry
|
|
|
|
IACT_USERCREATION, ///< from the Fund/build window
|
|
|
|
IACT_PROSPECTCREATION, ///< from the Fund/build using prospecting
|
2008-01-07 14:02:26 +00:00
|
|
|
};
|
|
|
|
|
2007-06-13 02:29:08 +00:00
|
|
|
/* in newgrf_industry.cpp */
|
2007-07-25 19:06:29 +00:00
|
|
|
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
|
2010-01-21 18:32:44 +00:00
|
|
|
uint32 GetIndustryIDAtOffset(TileIndex new_tile, const Industry *i, uint32 cur_grfid);
|
2007-07-05 05:41:56 +00:00
|
|
|
void IndustryProductionCallback(Industry *ind, int reason);
|
2010-10-16 13:15:54 +00:00
|
|
|
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type);
|
2011-11-08 17:26:13 +00:00
|
|
|
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob);
|
2010-08-07 20:11:27 +00:00
|
|
|
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type);
|
2007-06-09 02:05:51 +00:00
|
|
|
|
2007-07-11 22:57:47 +00:00
|
|
|
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);
|
|
|
|
|
2007-06-13 02:29:08 +00:00
|
|
|
/* in newgrf_industrytiles.cpp*/
|
2011-11-08 17:29:01 +00:00
|
|
|
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8);
|
2007-07-11 23:10:22 +00:00
|
|
|
|
2007-06-09 02:05:51 +00:00
|
|
|
#endif /* NEWGRF_INDUSTRIES_H */
|