2005-07-24 14:12:37 +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 industry.h Base of all industries. */
|
2007-03-03 04:04:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef INDUSTRY_H
|
|
|
|
#define INDUSTRY_H
|
|
|
|
|
2009-05-22 15:39:22 +00:00
|
|
|
#include "core/pool_type.hpp"
|
2007-09-22 13:56:38 +00:00
|
|
|
#include "newgrf_storage.h"
|
2009-08-08 16:42:55 +00:00
|
|
|
#include "subsidy_type.h"
|
2009-08-30 11:47:41 +00:00
|
|
|
#include "industry_map.h"
|
2010-01-04 18:21:07 +00:00
|
|
|
#include "tilearea_type.h"
|
2006-04-28 21:58:16 +00:00
|
|
|
|
2007-03-28 20:06:28 +00:00
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
|
|
|
|
extern IndustryPool _industry_pool;
|
2007-08-02 23:21:52 +00:00
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/**
|
|
|
|
* Defines the internal data of a functionnal industry
|
|
|
|
*/
|
2009-05-22 15:13:50 +00:00
|
|
|
struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
2007-09-22 13:56:38 +00:00
|
|
|
typedef PersistentStorageArray<uint32, 16> PersistentStorage;
|
|
|
|
|
2010-01-04 18:21:07 +00:00
|
|
|
TileArea location; ///< Location of the industry
|
2007-06-07 14:38:45 +00:00
|
|
|
const Town *town; ///< Nearest town
|
2007-09-27 21:39:13 +00:00
|
|
|
CargoID produced_cargo[2]; ///< 2 production cargo slots
|
2007-07-04 18:27:21 +00:00
|
|
|
uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo
|
|
|
|
uint16 incoming_cargo_waiting[3]; ///< incoming cargo waiting to be processed
|
2007-06-07 14:38:45 +00:00
|
|
|
byte production_rate[2]; ///< production rate for each cargo
|
|
|
|
byte prod_level; ///< general production level
|
2007-09-27 21:39:13 +00:00
|
|
|
CargoID accepts_cargo[3]; ///< 3 input cargo slots
|
2007-06-07 14:38:45 +00:00
|
|
|
uint16 this_month_production[2]; ///< stats of this month's production per cargo
|
|
|
|
uint16 this_month_transported[2]; ///< stats of this month's transport per cargo
|
|
|
|
byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
|
|
|
|
uint16 last_month_production[2]; ///< total units produced per cargo in the last full month
|
|
|
|
uint16 last_month_transported[2]; ///< total units transported per cargo in the last full month
|
|
|
|
uint16 counter; ///< used for animation and/or production (if available cargo)
|
|
|
|
|
2007-07-24 19:56:43 +00:00
|
|
|
IndustryType type; ///< type of industry.
|
2007-06-07 14:38:45 +00:00
|
|
|
OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
|
2009-02-09 02:57:15 +00:00
|
|
|
byte random_colour; ///< randomized colour of the industry, for display purpose
|
2007-06-07 14:38:45 +00:00
|
|
|
Year last_prod_year; ///< last year of production
|
|
|
|
byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
|
|
|
|
|
2009-08-08 16:42:55 +00:00
|
|
|
PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
|
|
|
|
|
2007-07-07 08:53:19 +00:00
|
|
|
OwnerByte founder; ///< Founder of the industry
|
|
|
|
Date construction_date; ///< Date of the construction of the industry
|
|
|
|
uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType)
|
|
|
|
Date last_cargo_accepted_at; ///< Last day cargo was accepted by this industry
|
2007-08-15 00:49:34 +00:00
|
|
|
byte selected_layout; ///< Which tile layout was used when creating the industry
|
2007-08-02 23:21:52 +00:00
|
|
|
|
2007-11-11 17:56:37 +00:00
|
|
|
byte random_triggers; ///< Triggers for the random
|
|
|
|
uint16 random; ///< Random value used for randomisation of all kinds of things
|
|
|
|
|
2007-09-22 13:56:38 +00:00
|
|
|
PersistentStorage psa; ///< Persistent storage for NewGRF industries.
|
|
|
|
|
2010-01-04 18:21:07 +00:00
|
|
|
Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
|
2007-08-02 23:21:52 +00:00
|
|
|
~Industry();
|
2009-06-26 15:08:54 +00:00
|
|
|
|
2009-08-30 11:47:41 +00:00
|
|
|
/**
|
|
|
|
* Get the industry of the given tile
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param tile the tile to get the industry from
|
2009-08-30 11:47:41 +00:00
|
|
|
* @pre IsTileType(t, MP_INDUSTRY)
|
|
|
|
* @return the industry
|
|
|
|
*/
|
|
|
|
static FORCEINLINE Industry *GetByTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
return Industry::Get(GetIndustryIndex(tile));
|
|
|
|
}
|
|
|
|
|
2009-06-26 15:08:54 +00:00
|
|
|
static Industry *GetRandom();
|
2009-09-08 12:22:28 +00:00
|
|
|
static void PostDestructor(size_t index);
|
2010-03-20 14:30:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment the count of industries for this type.
|
|
|
|
* @param type IndustryType to increment
|
|
|
|
* @pre type < NUM_INDUSTRYTYPES
|
|
|
|
*/
|
|
|
|
static inline void IncIndustryTypeCount(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < NUM_INDUSTRYTYPES);
|
|
|
|
counts[type]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement the count of industries for this type.
|
|
|
|
* @param type IndustryType to decrement
|
|
|
|
* @pre type < NUM_INDUSTRYTYPES
|
|
|
|
*/
|
|
|
|
static inline void DecIndustryTypeCount(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < NUM_INDUSTRYTYPES);
|
|
|
|
counts[type]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the count of industries for this type.
|
|
|
|
* @param type IndustryType to query
|
|
|
|
* @pre type < NUM_INDUSTRYTYPES
|
|
|
|
*/
|
|
|
|
static inline uint16 GetIndustryTypeCount(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < NUM_INDUSTRYTYPES);
|
|
|
|
return counts[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Resets industry counts. */
|
|
|
|
static inline void ResetIndustryCounts()
|
|
|
|
{
|
|
|
|
memset(&counts, 0, sizeof(counts));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static uint16 counts[NUM_INDUSTRYTYPES]; ///< Number of industries per type ingame
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-05-18 14:34:15 +00:00
|
|
|
void PlantRandomFarmField(const Industry *i);
|
2006-04-28 21:58:16 +00:00
|
|
|
|
2008-12-26 19:37:50 +00:00
|
|
|
void ReleaseDisastersTargetingIndustry(IndustryID);
|
|
|
|
|
2008-09-15 17:18:22 +00:00
|
|
|
/* industry_cmd.cpp */
|
|
|
|
void SetIndustryDailyChanges();
|
2007-04-26 20:20:12 +00:00
|
|
|
|
2009-05-22 14:23:36 +00:00
|
|
|
#define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
|
|
|
|
#define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* INDUSTRY_H */
|