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_cmd.cpp Handling of industry tiles. */
2007-03-03 04:04:22 +00:00
2004-08-09 17:04:08 +00:00
# include "stdafx.h"
2005-06-02 19:30:21 +00:00
# include "openttd.h"
2006-03-05 10:19:33 +00:00
# include "clear_map.h"
2009-08-30 11:47:41 +00:00
# include "industry.h"
2009-06-24 17:39:54 +00:00
# include "station_base.h"
2007-11-15 22:20:33 +00:00
# include "train.h"
2007-03-20 13:47:00 +00:00
# include "landscape.h"
2008-01-09 09:57:48 +00:00
# include "viewport_func.h"
2007-12-21 21:50:46 +00:00
# include "command_func.h"
2004-08-09 17:04:08 +00:00
# include "town.h"
2008-03-28 08:53:36 +00:00
# include "news_func.h"
2005-07-21 22:15:02 +00:00
# include "variables.h"
2009-01-31 20:16:06 +00:00
# include "cheat_type.h"
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
# include "genworld.h"
2007-02-02 15:14:28 +00:00
# include "tree_map.h"
2007-09-22 23:40:35 +00:00
# include "newgrf.h"
2007-07-20 17:32:27 +00:00
# include "newgrf_commons.h"
2007-07-05 05:41:56 +00:00
# include "newgrf_industries.h"
2007-06-19 17:33:12 +00:00
# include "newgrf_industrytiles.h"
2007-09-14 22:27:40 +00:00
# include "autoslope.h"
2007-11-10 01:17:15 +00:00
# include "transparency.h"
2007-11-24 08:45:04 +00:00
# include "water.h"
2007-12-21 19:49:27 +00:00
# include "strings_func.h"
2007-12-25 11:26:07 +00:00
# include "functions.h"
# include "window_func.h"
2007-12-26 13:50:40 +00:00
# include "date_func.h"
2007-12-27 13:35:39 +00:00
# include "vehicle_func.h"
2007-12-29 09:24:26 +00:00
# include "sound_func.h"
2008-04-20 08:22:59 +00:00
# include "animated_tile_func.h"
2008-04-20 11:12:07 +00:00
# include "effectvehicle_func.h"
2009-01-12 17:11:45 +00:00
# include "ai/ai.hpp"
2009-05-22 15:13:50 +00:00
# include "core/pool_func.hpp"
2009-05-23 15:46:00 +00:00
# include "subsidy_func.h"
2004-08-09 17:04:08 +00:00
2008-01-13 01:21:35 +00:00
# include "table/strings.h"
# include "table/industry_land.h"
# include "table/build_industry.h"
2009-05-22 15:13:50 +00:00
IndustryPool _industry_pool ( " Industry " ) ;
INSTANTIATE_POOL_METHODS ( Industry )
2006-08-26 19:51:49 +00:00
void ShowIndustryViewWindow ( int industry ) ;
void BuildOilRig ( TileIndex tile ) ;
static byte _industry_sound_ctr ;
static TileIndex _industry_sound_tile ;
2009-01-04 11:32:26 +00:00
uint16 _industry_counts [ NUM_INDUSTRYTYPES ] ; ///< Number of industries per type ingame
2007-06-08 15:48:48 +00:00
2007-05-29 17:41:59 +00:00
IndustrySpec _industry_specs [ NUM_INDUSTRYTYPES ] ;
IndustryTileSpec _industry_tile_specs [ NUM_INDUSTRYTILES ] ;
/** This function initialize the spec arrays of both
* industry and industry tiles .
* It adjusts the enabling of the industry too , based on climate availability .
* This will allow for clearer testings */
void ResetIndustries ( )
{
memset ( & _industry_specs , 0 , sizeof ( _industry_specs ) ) ;
memcpy ( & _industry_specs , & _origin_industry_specs , sizeof ( _origin_industry_specs ) ) ;
/* once performed, enable only the current climate industries */
for ( IndustryType i = 0 ; i < NUM_INDUSTRYTYPES ; i + + ) {
2007-09-28 21:24:25 +00:00
_industry_specs [ i ] . enabled = i < NEW_INDUSTRYOFFSET & &
2008-05-29 15:13:28 +00:00
HasBit ( _origin_industry_specs [ i ] . climate_availability , _settings_game . game_creation . landscape ) ;
2007-05-29 17:41:59 +00:00
}
memset ( & _industry_tile_specs , 0 , sizeof ( _industry_tile_specs ) ) ;
memcpy ( & _industry_tile_specs , & _origin_industry_tile_specs , sizeof ( _origin_industry_tile_specs ) ) ;
2007-10-03 00:57:54 +00:00
/* Reset any overrides that have been set. */
_industile_mngr . ResetOverride ( ) ;
_industry_mngr . ResetOverride ( ) ;
2007-05-29 17:41:59 +00:00
}
2007-07-15 00:26:12 +00:00
void ResetIndustryCreationProbility ( IndustryType type )
{
assert ( type < INVALID_INDUSTRYTYPE ) ;
2008-05-29 15:13:28 +00:00
_industry_specs [ type ] . appear_creation [ _settings_game . game_creation . landscape ] = 0 ;
2007-07-15 00:26:12 +00:00
}
2006-04-10 21:00:56 +00:00
/**
* Retrieve the type for this industry . Although it is accessed by a tile ,
* it will return the general type of industry , and not the sprite index
* as would do GetIndustryGfx .
* @ param tile that is queried
* @ pre IsTileType ( tile , MP_INDUSTRY )
* @ return general type for this industry , as defined in industry . h
* */
IndustryType GetIndustryType ( TileIndex tile )
{
assert ( IsTileType ( tile , MP_INDUSTRY ) ) ;
2009-08-30 11:47:41 +00:00
const Industry * ind = Industry : : GetByTile ( tile ) ;
2009-05-22 15:13:50 +00:00
assert ( ind ! = NULL ) ;
return ind - > type ;
2006-04-10 21:00:56 +00:00
}
2004-08-09 17:04:08 +00:00
2006-04-26 14:58:06 +00:00
/**
* Accessor for array _industry_specs .
* This will ensure at once : proper access and
* not allowing modifications of it .
2006-04-26 21:10:01 +00:00
* @ param thistype of industry ( which is the index in _industry_specs )
2007-04-19 14:50:01 +00:00
* @ pre thistype < NUM_INDUSTRYTYPES
2007-03-03 04:04:22 +00:00
* @ return a pointer to the corresponding industry spec
2006-04-26 14:58:06 +00:00
* */
2006-04-28 21:58:16 +00:00
const IndustrySpec * GetIndustrySpec ( IndustryType thistype )
2006-04-26 14:58:06 +00:00
{
2007-04-19 14:50:01 +00:00
assert ( thistype < NUM_INDUSTRYTYPES ) ;
2006-04-26 14:58:06 +00:00
return & _industry_specs [ thistype ] ;
}
2007-03-03 04:04:22 +00:00
/**
* Accessor for array _industry_tile_specs .
* This will ensure at once : proper access and
* not allowing modifications of it .
2007-07-20 14:49:41 +00:00
* @ param gfx of industrytile ( which is the index in _industry_tile_specs )
2007-05-30 02:08:18 +00:00
* @ pre gfx < INVALID_INDUSTRYTILE
2007-03-03 04:04:22 +00:00
* @ return a pointer to the corresponding industrytile spec
* */
2007-08-22 01:16:08 +00:00
const IndustryTileSpec * GetIndustryTileSpec ( IndustryGfx gfx )
2007-02-21 02:22:43 +00:00
{
2007-05-30 02:08:18 +00:00
assert ( gfx < INVALID_INDUSTRYTILE ) ;
2007-08-22 01:16:08 +00:00
return & _industry_tile_specs [ gfx ] ;
2007-02-21 02:22:43 +00:00
}
2007-08-02 23:21:52 +00:00
Industry : : ~ Industry ( )
2006-08-26 19:51:49 +00:00
{
2007-08-06 14:08:25 +00:00
if ( CleaningPool ( ) ) return ;
2007-08-02 23:21:52 +00:00
/* Industry can also be destroyed when not fully initialized.
* This means that we do not have to clear tiles either . */
2009-05-22 15:13:50 +00:00
if ( this - > width = = 0 ) return ;
2007-08-02 23:21:52 +00:00
2009-07-26 21:50:30 +00:00
TILE_LOOP ( tile_cur , this - > width , this - > height , this - > xy ) {
2006-08-26 19:51:49 +00:00
if ( IsTileType ( tile_cur , MP_INDUSTRY ) ) {
2007-08-02 23:21:52 +00:00
if ( GetIndustryIndex ( tile_cur ) = = this - > index ) {
2008-07-26 16:14:10 +00:00
/* MakeWaterKeepingClass() can also handle 'land' */
MakeWaterKeepingClass ( tile_cur , OWNER_NONE ) ;
2009-07-01 14:51:05 +00:00
/* MakeWaterKeepingClass() doesn't remove animation if the tiles
* become watery , but be on the safe side an always remote it . */
DeleteAnimatedTile ( tile_cur ) ;
2006-08-26 19:51:49 +00:00
}
} else if ( IsTileType ( tile_cur , MP_STATION ) & & IsOilRig ( tile_cur ) ) {
DeleteOilRig ( tile_cur ) ;
}
2009-07-26 21:50:30 +00:00
}
2006-08-26 19:51:49 +00:00
2007-08-02 23:21:52 +00:00
if ( GetIndustrySpec ( this - > type ) - > behaviour & INDUSTRYBEH_PLANT_FIELDS ) {
2006-08-26 19:51:49 +00:00
/* Remove the farmland and convert it to regular tiles over time. */
2009-07-26 21:50:30 +00:00
TILE_LOOP ( tile_cur , 42 , 42 , this - > xy - TileDiffXY ( 21 , 21 ) ) {
2006-10-11 21:20:53 +00:00
tile_cur = TILE_MASK ( tile_cur ) ;
2006-08-26 19:51:49 +00:00
if ( IsTileType ( tile_cur , MP_CLEAR ) & & IsClearGround ( tile_cur , CLEAR_FIELDS ) & &
2007-08-02 23:21:52 +00:00
GetIndustryIndexOfField ( tile_cur ) = = this - > index ) {
2006-08-26 19:51:49 +00:00
SetIndustryIndexOfField ( tile_cur , INVALID_INDUSTRY ) ;
}
2009-07-26 21:50:30 +00:00
}
2006-08-26 19:51:49 +00:00
}
2008-12-26 19:37:50 +00:00
/* don't let any disaster vehicle target invalid industry */
ReleaseDisastersTargetingIndustry ( this - > index ) ;
2007-08-02 23:21:52 +00:00
DecIndustryTypeCount ( this - > type ) ;
2007-06-08 15:48:48 +00:00
2009-05-24 16:52:42 +00:00
DeleteIndustryNews ( this - > index ) ;
2007-08-02 23:21:52 +00:00
DeleteWindowById ( WC_INDUSTRY_VIEW , this - > index ) ;
2008-05-18 23:36:33 +00:00
InvalidateWindowData ( WC_INDUSTRY_DIRECTORY , 0 , 0 ) ;
2009-06-25 15:42:03 +00:00
2009-08-08 16:42:55 +00:00
DeleteSubsidyWith ( ST_INDUSTRY , this - > index ) ;
CargoPacket : : InvalidateAllFrom ( ST_INDUSTRY , this - > index ) ;
2009-06-25 15:42:03 +00:00
Station : : RecomputeIndustriesNearForAll ( ) ;
2006-08-26 19:51:49 +00:00
}
2009-06-26 15:08:54 +00:00
/**
* Return a random valid industry .
* @ return random industry , NULL if there are no industries
*/
/* static */ Industry * Industry : : GetRandom ( )
{
if ( Industry : : GetNumItems ( ) = = 0 ) return NULL ;
int num = RandomRange ( ( uint16 ) Industry : : GetNumItems ( ) ) ;
size_t index = MAX_UVALUE ( size_t ) ;
while ( num > = 0 ) {
num - - ;
index + + ;
/* Make sure we have a valid industry */
while ( ! Industry : : IsValidID ( index ) ) {
index + + ;
assert ( index < Industry : : GetPoolSize ( ) ) ;
}
}
return Industry : : Get ( index ) ;
}
2006-03-21 23:22:21 +00:00
static void IndustryDrawSugarMine ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
2007-04-21 02:47:33 +00:00
const DrawIndustryAnimationStruct * d ;
2004-08-09 17:04:08 +00:00
2006-03-24 13:46:45 +00:00
if ( ! IsIndustryCompleted ( ti - > tile ) ) return ;
2004-09-11 09:55:19 +00:00
2006-12-30 11:51:37 +00:00
d = & _draw_industry_spec1 [ GetIndustryAnimationState ( ti - > tile ) ] ;
2004-08-09 17:04:08 +00:00
2007-01-14 19:57:49 +00:00
AddChildSpriteScreen ( SPR_IT_SUGAR_MINE_SIEVE + d - > image_1 , PAL_NONE , d - > x , 0 ) ;
2004-08-09 17:04:08 +00:00
2007-04-21 02:47:33 +00:00
if ( d - > image_2 ! = 0 ) {
AddChildSpriteScreen ( SPR_IT_SUGAR_MINE_CLOUDS + d - > image_2 - 1 , PAL_NONE , 8 , 41 ) ;
}
2004-08-09 17:04:08 +00:00
2007-04-21 02:47:33 +00:00
if ( d - > image_3 ! = 0 ) {
AddChildSpriteScreen ( SPR_IT_SUGAR_MINE_PILE + d - > image_3 - 1 , PAL_NONE ,
_drawtile_proc1 [ d - > image_3 - 1 ] . x , _drawtile_proc1 [ d - > image_3 - 1 ] . y ) ;
2005-11-14 19:48:04 +00:00
}
2004-08-09 17:04:08 +00:00
}
2006-03-21 23:22:21 +00:00
static void IndustryDrawToffeeQuarry ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
2007-04-21 02:47:33 +00:00
uint8 x = 0 ;
2004-09-11 09:55:19 +00:00
2006-03-24 13:46:45 +00:00
if ( IsIndustryCompleted ( ti - > tile ) ) {
2007-04-21 02:47:33 +00:00
x = _industry_anim_offs_toffee [ GetIndustryAnimationState ( ti - > tile ) ] ;
if ( x = = 0xFF )
2004-08-09 17:04:08 +00:00
x = 0 ;
}
2007-01-14 19:57:49 +00:00
AddChildSpriteScreen ( SPR_IT_TOFFEE_QUARRY_SHOVEL , PAL_NONE , 22 - x , 24 + x ) ;
AddChildSpriteScreen ( SPR_IT_TOFFEE_QUARRY_TOFFEE , PAL_NONE , 6 , 14 ) ;
2004-08-09 17:04:08 +00:00
}
2006-03-21 23:22:21 +00:00
static void IndustryDrawBubbleGenerator ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
2006-03-24 13:46:45 +00:00
if ( IsIndustryCompleted ( ti - > tile ) ) {
2007-04-21 02:47:33 +00:00
AddChildSpriteScreen ( SPR_IT_BUBBLE_GENERATOR_BUBBLE , PAL_NONE , 5 , _industry_anim_offs_bubbles [ GetIndustryAnimationState ( ti - > tile ) ] ) ;
2005-11-14 19:48:04 +00:00
} else {
2007-01-14 19:57:49 +00:00
AddChildSpriteScreen ( SPR_IT_BUBBLE_GENERATOR_SPRING , PAL_NONE , 3 , 67 ) ;
2004-08-09 17:04:08 +00:00
}
}
2006-03-21 23:22:21 +00:00
static void IndustryDrawToyFactory ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
2007-04-21 02:47:33 +00:00
const DrawIndustryAnimationStruct * d ;
2004-08-09 17:04:08 +00:00
2007-04-21 02:47:33 +00:00
d = & _industry_anim_offs_toys [ GetIndustryAnimationState ( ti - > tile ) ] ;
2004-08-09 17:04:08 +00:00
if ( d - > image_1 ! = 0xFF ) {
2007-04-21 02:47:33 +00:00
AddChildSpriteScreen ( SPR_IT_TOY_FACTORY_CLAY , PAL_NONE , d - > x , 96 + d - > image_1 ) ;
2004-08-09 17:04:08 +00:00
}
if ( d - > image_2 ! = 0xFF ) {
2007-01-14 19:57:49 +00:00
AddChildSpriteScreen ( SPR_IT_TOY_FACTORY_ROBOT , PAL_NONE , 16 - d - > image_2 * 2 , 100 + d - > image_2 ) ;
2004-08-09 17:04:08 +00:00
}
2007-01-14 19:57:49 +00:00
AddChildSpriteScreen ( SPR_IT_TOY_FACTORY_STAMP , PAL_NONE , 7 , d - > image_3 ) ;
AddChildSpriteScreen ( SPR_IT_TOY_FACTORY_STAMP_HOLDER , PAL_NONE , 0 , 42 ) ;
2004-08-09 17:04:08 +00:00
}
2006-03-21 23:22:21 +00:00
static void IndustryDrawCoalPlantSparks ( const TileInfo * ti )
2004-08-09 17:04:08 +00:00
{
2006-03-24 13:46:45 +00:00
if ( IsIndustryCompleted ( ti - > tile ) ) {
2007-04-21 02:47:33 +00:00
uint8 image = GetIndustryAnimationState ( ti - > tile ) ;
2006-03-24 13:46:45 +00:00
2004-08-09 17:04:08 +00:00
if ( image ! = 0 & & image < 7 ) {
2006-03-21 23:22:21 +00:00
AddChildSpriteScreen ( image + SPR_IT_POWER_PLANT_TRANSFORMERS ,
2007-01-14 19:57:49 +00:00
PAL_NONE ,
2007-04-21 02:47:33 +00:00
_coal_plant_sparks [ image - 1 ] . x ,
_coal_plant_sparks [ image - 1 ] . y
2004-08-09 17:04:08 +00:00
) ;
}
}
}
2005-09-18 20:56:44 +00:00
typedef void IndustryDrawTileProc ( const TileInfo * ti ) ;
2004-08-09 17:04:08 +00:00
static IndustryDrawTileProc * const _industry_draw_tile_procs [ 5 ] = {
2006-03-21 23:22:21 +00:00
IndustryDrawSugarMine ,
IndustryDrawToffeeQuarry ,
IndustryDrawBubbleGenerator ,
IndustryDrawToyFactory ,
IndustryDrawCoalPlantSparks ,
2004-08-09 17:04:08 +00:00
} ;
static void DrawTile_Industry ( TileInfo * ti )
{
2007-06-19 17:33:12 +00:00
IndustryGfx gfx = GetIndustryGfx ( ti - > tile ) ;
2009-08-30 11:47:41 +00:00
Industry * ind = Industry : : GetByTile ( ti - > tile ) ;
2007-06-19 17:33:12 +00:00
const IndustryTileSpec * indts = GetIndustryTileSpec ( gfx ) ;
2006-04-24 21:10:56 +00:00
const DrawBuildingsTileStruct * dits ;
2007-01-14 19:57:49 +00:00
SpriteID image ;
SpriteID pal ;
2004-08-09 17:04:08 +00:00
/* Retrieve pointer to the draw industry tile struct */
2007-06-19 17:33:12 +00:00
if ( gfx > = NEW_INDUSTRYTILEOFFSET ) {
/* Draw the tile using the specialized method of newgrf industrytile.
* DrawNewIndustry will return false if ever the resolver could not
* find any sprite to display . So in this case , we will jump on the
* substitute gfx instead . */
if ( indts - > grf_prop . spritegroup ! = NULL & & DrawNewIndustryTile ( ti , ind , gfx , indts ) ) {
return ;
} else {
/* No sprite group (or no valid one) found, meaning no graphics associated.
* Use the substitute one instead */
2007-08-22 00:59:46 +00:00
if ( indts - > grf_prop . subst_id ! = INVALID_INDUSTRYTILE ) {
gfx = indts - > grf_prop . subst_id ;
/* And point the industrytile spec accordingly */
indts = GetIndustryTileSpec ( gfx ) ;
}
2007-06-19 17:33:12 +00:00
}
}
dits = & _industry_draw_tile_data [ gfx < < 2 | ( indts - > anim_state ?
2007-07-20 17:14:03 +00:00
GetIndustryAnimationState ( ti - > tile ) & INDUSTRY_COMPLETED :
2006-12-30 11:57:52 +00:00
GetIndustryConstructionStage ( ti - > tile ) ) ] ;
2004-08-09 17:04:08 +00:00
2007-01-14 19:57:49 +00:00
image = dits - > ground . sprite ;
2009-02-09 02:57:15 +00:00
if ( HasBit ( image , PALETTE_MODIFIER_COLOUR ) & & dits - > ground . pal = = PAL_NONE ) {
pal = GENERAL_SPRITE_COLOUR ( ind - > random_colour ) ;
2007-01-14 19:57:49 +00:00
} else {
pal = dits - > ground . pal ;
}
2004-08-09 17:04:08 +00:00
2007-07-26 16:51:10 +00:00
/* DrawFoundation() modifes ti->z and ti->tileh */
if ( ti - > tileh ! = SLOPE_FLAT ) DrawFoundation ( ti , FOUNDATION_LEVELED ) ;
2004-08-09 17:04:08 +00:00
2008-07-26 16:14:10 +00:00
/* If the ground sprite is the default flat water sprite, draw also canal/river borders.
* Do not do this if the tile ' s WaterClass is ' land ' . */
if ( image = = SPR_FLAT_WATER_TILE & & IsIndustryTileOnWater ( ti - > tile ) ) {
DrawWaterClassGround ( ti ) ;
} else {
DrawGroundSprite ( image , pal ) ;
}
2007-06-24 10:20:05 +00:00
2008-04-03 19:55:40 +00:00
/* If industries are transparent and invisible, do not draw the upper part */
if ( IsInvisibilitySet ( TO_INDUSTRIES ) ) return ;
2004-08-09 17:04:08 +00:00
/* Add industry on top of the ground? */
2007-01-14 19:57:49 +00:00
image = dits - > building . sprite ;
2005-11-14 19:48:04 +00:00
if ( image ! = 0 ) {
2007-07-26 14:07:11 +00:00
AddSortableSpriteToDraw ( image ,
2009-02-09 02:57:15 +00:00
( HasBit ( image , PALETTE_MODIFIER_COLOUR ) & & dits - > building . pal = = PAL_NONE ) ? GENERAL_SPRITE_COLOUR ( ind - > random_colour ) : dits - > building . pal ,
2005-11-16 11:55:06 +00:00
ti - > x + dits - > subtile_x ,
ti - > y + dits - > subtile_y ,
2007-09-14 21:32:21 +00:00
dits - > width ,
dits - > height ,
2004-08-09 17:04:08 +00:00
dits - > dz ,
2007-07-26 16:51:10 +00:00
ti - > z ,
2007-11-10 01:17:15 +00:00
IsTransparencySet ( TO_INDUSTRIES ) ) ;
2004-08-09 17:04:08 +00:00
2007-11-10 01:17:15 +00:00
if ( IsTransparencySet ( TO_INDUSTRIES ) ) return ;
2004-08-09 17:04:08 +00:00
}
2005-11-14 19:48:04 +00:00
{
2006-04-24 21:10:56 +00:00
int proc = dits - > draw_proc - 1 ;
2005-11-14 19:48:04 +00:00
if ( proc > = 0 ) _industry_draw_tile_procs [ proc ] ( ti ) ;
2004-08-09 17:04:08 +00:00
}
}
2006-08-06 16:32:49 +00:00
static uint GetSlopeZ_Industry ( TileIndex tile , uint x , uint y )
2005-10-19 14:49:46 +00:00
{
2006-08-06 16:32:49 +00:00
return GetTileMaxZ ( tile ) ;
2004-08-09 17:04:08 +00:00
}
2007-07-26 16:51:10 +00:00
static Foundation GetFoundation_Industry ( TileIndex tile , Slope tileh )
2005-10-22 06:39:32 +00:00
{
2008-05-31 22:43:42 +00:00
IndustryGfx gfx = GetIndustryGfx ( tile ) ;
/* For NewGRF industry tiles we might not be drawing a foundation. We need to
2008-06-12 21:36:56 +00:00
* account for this , as other structures should
2008-05-31 22:43:42 +00:00
* draw the wall of the foundation in this case .
*/
if ( gfx > = NEW_INDUSTRYTILEOFFSET ) {
const IndustryTileSpec * indts = GetIndustryTileSpec ( gfx ) ;
if ( indts - > grf_prop . spritegroup ! = NULL & & HasBit ( indts - > callback_flags , CBM_INDT_DRAW_FOUNDATIONS ) ) {
2009-08-30 11:47:41 +00:00
uint32 callback_res = GetIndustryTileCallback ( CBID_INDUSTRY_DRAW_FOUNDATIONS , 0 , 0 , gfx , Industry : : GetByTile ( tile ) , tile ) ;
2008-05-31 22:43:42 +00:00
if ( callback_res = = 0 ) return FOUNDATION_NONE ;
}
}
2007-07-26 16:51:10 +00:00
return FlatteningFoundation ( tileh ) ;
2004-08-13 18:27:33 +00:00
}
2009-09-07 07:39:08 +00:00
static void AddAcceptedCargo_Industry ( TileIndex tile , CargoArray & acceptance , uint32 * town_acc )
2004-08-09 17:04:08 +00:00
{
2007-07-08 17:40:04 +00:00
IndustryGfx gfx = GetIndustryGfx ( tile ) ;
const IndustryTileSpec * itspec = GetIndustryTileSpec ( gfx ) ;
/* When we have to use a callback, we put our data in the next two variables */
CargoID raw_accepts_cargo [ lengthof ( itspec - > accepts_cargo ) ] ;
2009-06-27 18:26:50 +00:00
uint8 raw_cargo_acceptance [ lengthof ( itspec - > acceptance ) ] ;
2007-07-08 17:40:04 +00:00
/* And then these will always point to a same sized array with the required data */
const CargoID * accepts_cargo = itspec - > accepts_cargo ;
2009-06-27 18:26:50 +00:00
const uint8 * cargo_acceptance = itspec - > acceptance ;
2007-07-08 17:40:04 +00:00
2007-11-19 21:02:30 +00:00
if ( HasBit ( itspec - > callback_flags , CBM_INDT_ACCEPT_CARGO ) ) {
2009-08-30 11:47:41 +00:00
uint16 res = GetIndustryTileCallback ( CBID_INDTILE_ACCEPT_CARGO , 0 , 0 , gfx , Industry : : GetByTile ( tile ) , tile ) ;
2007-07-08 17:40:04 +00:00
if ( res ! = CALLBACK_FAILED ) {
accepts_cargo = raw_accepts_cargo ;
for ( uint i = 0 ; i < lengthof ( itspec - > accepts_cargo ) ; i + + ) raw_accepts_cargo [ i ] = GetCargoTranslation ( GB ( res , i * 5 , 5 ) , itspec - > grf_prop . grffile ) ;
}
}
2007-11-19 21:02:30 +00:00
if ( HasBit ( itspec - > callback_flags , CBM_INDT_CARGO_ACCEPTANCE ) ) {
2009-08-30 11:47:41 +00:00
uint16 res = GetIndustryTileCallback ( CBID_INDTILE_CARGO_ACCEPTANCE , 0 , 0 , gfx , Industry : : GetByTile ( tile ) , tile ) ;
2007-07-08 17:40:04 +00:00
if ( res ! = CALLBACK_FAILED ) {
2009-06-27 18:26:50 +00:00
cargo_acceptance = raw_cargo_acceptance ;
for ( uint i = 0 ; i < lengthof ( itspec - > accepts_cargo ) ; i + + ) raw_cargo_acceptance [ i ] = GB ( res , i * 4 , 4 ) ;
2007-07-08 17:40:04 +00:00
}
}
2004-08-09 17:04:08 +00:00
2007-05-29 00:15:34 +00:00
for ( byte i = 0 ; i < lengthof ( itspec - > accepts_cargo ) ; i + + ) {
2007-07-08 17:40:04 +00:00
CargoID a = accepts_cargo [ i ] ;
2009-06-27 18:26:50 +00:00
if ( a ! = CT_INVALID ) acceptance [ a ] + = cargo_acceptance [ i ] ;
2007-05-29 00:15:34 +00:00
}
2004-08-09 17:04:08 +00:00
}
2005-06-24 12:38:35 +00:00
static void GetTileDesc_Industry ( TileIndex tile , TileDesc * td )
2004-08-09 17:04:08 +00:00
{
2009-08-30 11:47:41 +00:00
const Industry * i = Industry : : GetByTile ( tile ) ;
2008-07-25 22:37:34 +00:00
const IndustrySpec * is = GetIndustrySpec ( i - > type ) ;
2004-08-09 17:04:08 +00:00
2008-05-21 22:15:39 +00:00
td - > owner [ 0 ] = i - > owner ;
2008-07-25 22:37:34 +00:00
td - > str = is - > name ;
2006-03-24 13:46:45 +00:00
if ( ! IsIndustryCompleted ( tile ) ) {
2004-12-02 22:53:07 +00:00
SetDParamX ( td - > dparam , 0 , td - > str ) ;
2009-08-05 17:59:21 +00:00
td - > str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION ;
2004-08-09 17:04:08 +00:00
}
2008-07-25 22:37:34 +00:00
if ( is - > grf_prop . grffile ! = NULL ) {
td - > grf = GetGRFConfig ( is - > grf_prop . grffile - > grfid ) - > name ;
}
2004-08-09 17:04:08 +00:00
}
2009-02-09 21:20:05 +00:00
static CommandCost ClearTile_Industry ( TileIndex tile , DoCommandFlag flags )
2004-08-09 17:04:08 +00:00
{
2009-08-30 11:47:41 +00:00
Industry * i = Industry : : GetByTile ( tile ) ;
2007-03-28 20:06:28 +00:00
const IndustrySpec * indspec = GetIndustrySpec ( i - > type ) ;
2004-08-09 17:04:08 +00:00
2006-08-28 18:53:03 +00:00
/* water can destroy industries
* in editor you can bulldoze industries
* with magic_bulldozer cheat you can destroy industries
* ( area around OILRIG is water , so water shouldn ' t flood it
*/
2008-09-30 20:39:50 +00:00
if ( ( _current_company ! = OWNER_WATER & & _game_mode ! = GM_EDITOR & &
2004-09-03 17:57:27 +00:00
! _cheats . magic_bulldozer . value ) | |
2007-09-26 14:14:51 +00:00
( ( flags & DC_AUTO ) ! = 0 ) | |
2008-09-30 20:39:50 +00:00
( _current_company = = OWNER_WATER & &
2008-08-17 13:56:11 +00:00
( ( indspec - > behaviour & INDUSTRYBEH_BUILT_ONWATER ) | |
HasBit ( GetIndustryTileSpec ( GetIndustryGfx ( tile ) ) - > slopes_refused , 5 ) ) ) ) {
2007-03-28 20:06:28 +00:00
SetDParam ( 0 , indspec - > name ) ;
2009-08-05 17:59:21 +00:00
return_cmd_error ( flags & DC_AUTO ? STR_ERROR_UNMOVABLE_OBJECT_IN_THE_WAY : INVALID_STRING_ID ) ;
2004-08-09 17:04:08 +00:00
}
2009-01-12 17:11:45 +00:00
if ( flags & DC_EXEC ) {
AI : : BroadcastNewEvent ( new AIEventIndustryClose ( i - > index ) ) ;
delete i ;
}
2008-01-09 16:55:48 +00:00
return CommandCost ( EXPENSES_CONSTRUCTION , indspec - > GetRemovalCost ( ) ) ;
2004-08-09 17:04:08 +00:00
}
2005-06-24 12:38:35 +00:00
static void TransportIndustryGoods ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2009-08-30 11:47:41 +00:00
Industry * i = Industry : : GetByTile ( tile ) ;
2006-04-26 21:10:01 +00:00
const IndustrySpec * indspec = GetIndustrySpec ( i - > type ) ;
2007-10-27 11:20:47 +00:00
bool moved_cargo = false ;
2004-09-11 09:55:19 +00:00
2007-10-27 11:20:47 +00:00
for ( uint j = 0 ; j < lengthof ( i - > produced_cargo_waiting ) ; j + + ) {
uint cw = min ( i - > produced_cargo_waiting [ j ] , 255 ) ;
if ( cw > indspec - > minimal_cargo & & i - > produced_cargo [ j ] ! = CT_INVALID ) {
i - > produced_cargo_waiting [ j ] - = cw ;
2004-08-09 17:04:08 +00:00
2007-10-27 11:20:47 +00:00
/* fluctuating economy? */
if ( _economy . fluct < = 0 ) cw = ( cw + 1 ) / 2 ;
2004-08-09 17:04:08 +00:00
2007-10-27 11:20:47 +00:00
i - > this_month_production [ j ] + = cw ;
2004-08-09 17:04:08 +00:00
2009-08-08 16:42:55 +00:00
uint am = MoveGoodsToStation ( i - > xy , i - > width , i - > height , i - > produced_cargo [ j ] , cw , ST_INDUSTRY , i - > index ) ;
2007-10-27 11:20:47 +00:00
i - > this_month_transported [ j ] + = am ;
2006-03-25 10:38:28 +00:00
2007-10-27 11:20:47 +00:00
moved_cargo | = ( am ! = 0 ) ;
2004-08-09 17:04:08 +00:00
}
}
2007-10-27 11:20:47 +00:00
if ( moved_cargo & & ! StartStopIndustryTileAnimation ( i , IAT_INDUSTRY_DISTRIBUTES_CARGO ) ) {
uint newgfx = GetIndustryTileSpec ( GetIndustryGfx ( tile ) ) - > anim_production ;
2004-09-11 09:55:19 +00:00
2007-10-27 11:20:47 +00:00
if ( newgfx ! = INDUSTRYTILE_NOANIM ) {
ResetIndustryConstructionStage ( tile ) ;
SetIndustryCompleted ( tile , true ) ;
SetIndustryGfx ( tile , newgfx ) ;
MarkTileDirtyByTile ( tile ) ;
}
2004-08-09 17:04:08 +00:00
}
}
2005-06-24 12:38:35 +00:00
static void AnimateTile_Industry ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-03-25 10:38:28 +00:00
byte m ;
2007-07-11 15:03:29 +00:00
IndustryGfx gfx = GetIndustryGfx ( tile ) ;
if ( GetIndustryTileSpec ( gfx ) - > animation_info ! = 0xFFFF ) {
AnimateNewIndustryTile ( tile ) ;
return ;
}
2004-08-09 17:04:08 +00:00
2007-07-11 15:03:29 +00:00
switch ( gfx ) {
2006-04-14 01:54:07 +00:00
case GFX_SUGAR_MINE_SIEVE :
2004-08-09 17:04:08 +00:00
if ( ( _tick_counter & 1 ) = = 0 ) {
2006-12-30 11:51:37 +00:00
m = GetIndustryAnimationState ( tile ) + 1 ;
2004-09-11 09:55:19 +00:00
2006-02-01 07:36:15 +00:00
switch ( m & 7 ) {
2006-08-28 18:53:03 +00:00
case 2 : SndPlayTileFx ( SND_2D_RIP_2 , tile ) ; break ;
2004-12-04 09:26:39 +00:00
case 6 : SndPlayTileFx ( SND_29_RIP , tile ) ; break ;
2004-08-09 17:04:08 +00:00
}
if ( m > = 96 ) {
m = 0 ;
DeleteAnimatedTile ( tile ) ;
}
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
break ;
2006-04-14 01:54:07 +00:00
case GFX_TOFFEE_QUARY :
2004-08-09 17:04:08 +00:00
if ( ( _tick_counter & 3 ) = = 0 ) {
2006-12-30 11:51:37 +00:00
m = GetIndustryAnimationState ( tile ) ;
2004-09-11 09:55:19 +00:00
2007-04-21 02:47:33 +00:00
if ( _industry_anim_offs_toffee [ m ] = = 0xFF ) {
2004-12-04 09:26:39 +00:00
SndPlayTileFx ( SND_30_CARTOON_SOUND , tile ) ;
2004-08-09 17:04:08 +00:00
}
if ( + + m > = 70 ) {
m = 0 ;
DeleteAnimatedTile ( tile ) ;
}
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
break ;
2006-04-14 01:54:07 +00:00
case GFX_BUBBLE_CATCHER :
2006-12-30 11:51:37 +00:00
if ( ( _tick_counter & 1 ) = = 0 ) {
m = GetIndustryAnimationState ( tile ) ;
2004-08-09 17:04:08 +00:00
if ( + + m > = 40 ) {
m = 0 ;
DeleteAnimatedTile ( tile ) ;
}
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
break ;
2007-03-03 04:04:22 +00:00
/* Sparks on a coal plant */
2006-04-14 01:54:07 +00:00
case GFX_POWERPLANT_SPARKS :
2004-08-09 17:04:08 +00:00
if ( ( _tick_counter & 3 ) = = 0 ) {
2006-12-30 11:51:37 +00:00
m = GetIndustryAnimationState ( tile ) ;
if ( m = = 6 ) {
SetIndustryAnimationState ( tile , 0 ) ;
2004-08-09 17:04:08 +00:00
DeleteAnimatedTile ( tile ) ;
} else {
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m + 1 ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
}
break ;
2006-04-14 01:54:07 +00:00
case GFX_TOY_FACTORY :
2004-08-09 17:04:08 +00:00
if ( ( _tick_counter & 1 ) = = 0 ) {
2006-12-30 11:51:37 +00:00
m = GetIndustryAnimationState ( tile ) + 1 ;
2004-08-09 17:04:08 +00:00
2007-04-16 02:56:48 +00:00
switch ( m ) {
case 1 : SndPlayTileFx ( SND_2C_MACHINERY , tile ) ; break ;
case 23 : SndPlayTileFx ( SND_2B_COMEDY_HIT , tile ) ; break ;
case 28 : SndPlayTileFx ( SND_2A_EXTRACT_AND_POP , tile ) ; break ;
default :
if ( m > = 50 ) {
int n = GetIndustryAnimationLoop ( tile ) + 1 ;
m = 0 ;
if ( n > = 8 ) {
n = 0 ;
DeleteAnimatedTile ( tile ) ;
}
SetIndustryAnimationLoop ( tile , n ) ;
}
2004-08-09 17:04:08 +00:00
}
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
break ;
2006-12-30 11:41:54 +00:00
case GFX_PLASTIC_FOUNTAIN_ANIMATED_1 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_2 :
case GFX_PLASTIC_FOUNTAIN_ANIMATED_3 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_4 :
case GFX_PLASTIC_FOUNTAIN_ANIMATED_5 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_6 :
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_8 :
2004-08-09 17:04:08 +00:00
if ( ( _tick_counter & 3 ) = = 0 ) {
2006-04-10 21:00:56 +00:00
IndustryGfx gfx = GetIndustryGfx ( tile ) ;
2004-08-09 17:04:08 +00:00
2006-03-25 10:38:28 +00:00
gfx = ( gfx < 155 ) ? gfx + 1 : 148 ;
SetIndustryGfx ( tile , gfx ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
break ;
2006-09-08 22:12:57 +00:00
case GFX_OILWELL_ANIMATED_1 :
case GFX_OILWELL_ANIMATED_2 :
case GFX_OILWELL_ANIMATED_3 :
2004-08-09 17:04:08 +00:00
if ( ( _tick_counter & 7 ) = = 0 ) {
2007-11-25 15:35:25 +00:00
bool b = Chance16 ( 1 , 7 ) ;
2006-04-10 21:00:56 +00:00
IndustryGfx gfx = GetIndustryGfx ( tile ) ;
2006-03-25 10:38:28 +00:00
2006-12-30 11:51:37 +00:00
m = GetIndustryAnimationState ( tile ) + 1 ;
2006-09-08 22:12:57 +00:00
if ( m = = 4 & & ( m = 0 , + + gfx ) = = GFX_OILWELL_ANIMATED_3 + 1 & & ( gfx = GFX_OILWELL_ANIMATED_1 , b ) ) {
SetIndustryGfx ( tile , GFX_OILWELL_NOT_ANIMATED ) ;
2006-12-30 11:51:37 +00:00
SetIndustryConstructionStage ( tile , 3 ) ;
2004-09-11 09:55:19 +00:00
DeleteAnimatedTile ( tile ) ;
2004-08-09 17:04:08 +00:00
} else {
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2006-03-25 10:38:28 +00:00
SetIndustryGfx ( tile , gfx ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
}
break ;
2006-09-08 22:12:57 +00:00
case GFX_COAL_MINE_TOWER_ANIMATED :
case GFX_COPPER_MINE_TOWER_ANIMATED :
case GFX_GOLD_MINE_TOWER_ANIMATED : {
2004-08-09 17:04:08 +00:00
int state = _tick_counter & 0x7FF ;
if ( ( state - = 0x400 ) < 0 )
return ;
if ( state < 0x1A0 ) {
if ( state < 0x20 | | state > = 0x180 ) {
2006-12-30 11:51:37 +00:00
m = GetIndustryAnimationState ( tile ) ;
if ( ! ( m & 0x40 ) ) {
2006-12-30 11:57:52 +00:00
SetIndustryAnimationState ( tile , m | 0x40 ) ;
2004-12-04 09:26:39 +00:00
SndPlayTileFx ( SND_0B_MINING_MACHINERY , tile ) ;
2004-08-09 17:04:08 +00:00
}
if ( state & 7 )
return ;
} else {
if ( state & 3 )
return ;
}
2006-12-30 11:51:37 +00:00
m = ( GetIndustryAnimationState ( tile ) + 1 ) | 0x40 ;
2004-08-09 17:04:08 +00:00
if ( m > 0xC2 ) m = 0xC0 ;
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
} else if ( state > = 0x200 & & state < 0x3A0 ) {
int i ;
i = ( state < 0x220 | | state > = 0x380 ) ? 7 : 3 ;
if ( state & i )
return ;
2006-12-30 11:51:37 +00:00
m = ( GetIndustryAnimationState ( tile ) & 0xBF ) - 1 ;
2004-08-09 17:04:08 +00:00
if ( m < 0x80 ) m = 0x82 ;
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , m ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
}
} break ;
}
}
2008-04-20 11:12:07 +00:00
static void CreateChimneySmoke ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-05-07 07:55:05 +00:00
uint x = TileX ( tile ) * TILE_SIZE ;
uint y = TileY ( tile ) * TILE_SIZE ;
uint z = GetTileMaxZ ( tile ) ;
CreateEffectVehicle ( x + 15 , y + 14 , z + 59 , EV_CHIMNEY_SMOKE ) ;
2004-08-09 17:04:08 +00:00
}
2006-04-10 15:09:56 +00:00
static void MakeIndustryTileBigger ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-04-10 15:09:56 +00:00
byte cnt = GetIndustryConstructionCounter ( tile ) + 1 ;
byte stage ;
2004-08-09 17:04:08 +00:00
2006-04-10 15:09:56 +00:00
if ( cnt ! = 4 ) {
SetIndustryConstructionCounter ( tile , cnt ) ;
2004-08-09 17:04:08 +00:00
return ;
}
2006-04-10 15:09:56 +00:00
stage = GetIndustryConstructionStage ( tile ) + 1 ;
SetIndustryConstructionCounter ( tile , 0 ) ;
SetIndustryConstructionStage ( tile , stage ) ;
2007-07-11 15:03:29 +00:00
StartStopIndustryTileAnimation ( tile , IAT_CONSTRUCTION_STATE_CHANGE ) ;
2007-07-20 17:14:03 +00:00
if ( stage = = INDUSTRY_COMPLETED ) SetIndustryCompleted ( tile , true ) ;
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
2006-03-24 13:46:45 +00:00
if ( ! IsIndustryCompleted ( tile ) ) return ;
2004-08-09 17:04:08 +00:00
2007-07-11 15:03:29 +00:00
IndustryGfx gfx = GetIndustryGfx ( tile ) ;
if ( gfx > = NEW_INDUSTRYTILEOFFSET ) {
2007-11-11 00:53:59 +00:00
/* New industries are already animated on construction. */
2007-07-11 15:03:29 +00:00
return ;
}
switch ( gfx ) {
2006-09-08 22:12:57 +00:00
case GFX_POWERPLANT_CHIMNEY :
2008-04-20 11:12:07 +00:00
CreateChimneySmoke ( tile ) ;
2004-08-09 17:04:08 +00:00
break ;
2006-09-15 21:44:55 +00:00
case GFX_OILRIG_1 :
if ( GetIndustryGfx ( tile + TileDiffXY ( 0 , 1 ) ) = = GFX_OILRIG_1 ) BuildOilRig ( tile ) ;
2004-08-09 17:04:08 +00:00
break ;
2006-04-14 01:54:07 +00:00
case GFX_TOY_FACTORY :
case GFX_BUBBLE_CATCHER :
case GFX_TOFFEE_QUARY :
2006-12-30 11:51:37 +00:00
SetIndustryAnimationState ( tile , 0 ) ;
2006-04-12 18:10:54 +00:00
SetIndustryAnimationLoop ( tile , 0 ) ;
2004-08-09 17:04:08 +00:00
break ;
2006-12-30 11:41:54 +00:00
case GFX_PLASTIC_FOUNTAIN_ANIMATED_1 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_2 :
case GFX_PLASTIC_FOUNTAIN_ANIMATED_3 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_4 :
case GFX_PLASTIC_FOUNTAIN_ANIMATED_5 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_6 :
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7 : case GFX_PLASTIC_FOUNTAIN_ANIMATED_8 :
2004-08-09 17:04:08 +00:00
AddAnimatedTile ( tile ) ;
break ;
}
}
2006-03-21 23:22:21 +00:00
static void TileLoopIndustry_BubbleGenerator ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2008-04-20 11:12:07 +00:00
static const int8 _bubble_spawn_location [ 3 ] [ 4 ] = {
{ 11 , 0 , - 4 , - 14 } ,
{ - 4 , - 10 , - 4 , 1 } ,
{ 49 , 59 , 60 , 65 } ,
2004-08-09 17:04:08 +00:00
} ;
2004-12-04 09:26:39 +00:00
SndPlayTileFx ( SND_2E_EXTRACT_AND_POP , tile ) ;
2004-09-11 09:55:19 +00:00
2009-05-22 18:56:25 +00:00
int dir = Random ( ) & 3 ;
2004-08-09 17:04:08 +00:00
2009-05-22 18:56:25 +00:00
EffectVehicle * v = CreateEffectVehicleAbove (
2008-04-20 11:12:07 +00:00
TileX ( tile ) * TILE_SIZE + _bubble_spawn_location [ 0 ] [ dir ] ,
TileY ( tile ) * TILE_SIZE + _bubble_spawn_location [ 1 ] [ dir ] ,
_bubble_spawn_location [ 2 ] [ dir ] ,
2005-02-12 15:53:32 +00:00
EV_BUBBLE
2004-08-09 17:04:08 +00:00
) ;
2009-05-22 18:56:25 +00:00
if ( v ! = NULL ) v - > animation_substate = dir ;
2004-08-09 17:04:08 +00:00
}
2005-06-24 12:38:35 +00:00
static void TileLoop_Industry ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-04-10 21:00:56 +00:00
IndustryGfx newgfx ;
2006-12-30 11:51:37 +00:00
IndustryGfx gfx ;
2004-08-09 17:04:08 +00:00
2008-07-26 16:14:10 +00:00
if ( IsIndustryTileOnWater ( tile ) ) TileLoop_Water ( tile ) ;
2007-11-11 17:56:37 +00:00
TriggerIndustryTile ( tile , INDTILE_TRIGGER_TILE_LOOP ) ;
2006-03-24 13:46:45 +00:00
if ( ! IsIndustryCompleted ( tile ) ) {
2006-04-10 15:09:56 +00:00
MakeIndustryTileBigger ( tile ) ;
2004-08-09 17:04:08 +00:00
return ;
}
2005-11-14 19:48:04 +00:00
if ( _game_mode = = GM_EDITOR ) return ;
2004-08-09 17:04:08 +00:00
TransportIndustryGoods ( tile ) ;
2007-07-11 15:03:29 +00:00
if ( StartStopIndustryTileAnimation ( tile , IAT_TILELOOP ) ) return ;
2007-03-14 02:52:50 +00:00
newgfx = GetIndustryTileSpec ( GetIndustryGfx ( tile ) ) - > anim_next ;
2007-05-29 17:41:59 +00:00
if ( newgfx ! = INDUSTRYTILE_NOANIM ) {
2006-04-10 15:09:56 +00:00
ResetIndustryConstructionStage ( tile ) ;
2006-03-25 10:38:28 +00:00
SetIndustryGfx ( tile , newgfx ) ;
2004-08-09 17:04:08 +00:00
MarkTileDirtyByTile ( tile ) ;
return ;
}
2006-12-30 11:51:37 +00:00
gfx = GetIndustryGfx ( tile ) ;
2004-08-09 17:04:08 +00:00
2006-12-30 11:51:37 +00:00
switch ( gfx ) {
2006-09-08 22:12:57 +00:00
case GFX_COAL_MINE_TOWER_NOT_ANIMATED :
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED :
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED :
2007-11-25 15:35:25 +00:00
if ( ! ( _tick_counter & 0x400 ) & & Chance16 ( 1 , 2 ) ) {
2006-12-30 11:51:37 +00:00
switch ( gfx ) {
case GFX_COAL_MINE_TOWER_NOT_ANIMATED : gfx = GFX_COAL_MINE_TOWER_ANIMATED ; break ;
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED : gfx = GFX_COPPER_MINE_TOWER_ANIMATED ; break ;
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED : gfx = GFX_GOLD_MINE_TOWER_ANIMATED ; break ;
}
SetIndustryGfx ( tile , gfx ) ;
SetIndustryAnimationState ( tile , 0x80 ) ;
AddAnimatedTile ( tile ) ;
}
2004-08-09 17:04:08 +00:00
break ;
2006-09-08 22:12:57 +00:00
case GFX_OILWELL_NOT_ANIMATED :
2007-11-25 15:35:25 +00:00
if ( Chance16 ( 1 , 6 ) ) {
2006-12-30 11:51:37 +00:00
SetIndustryGfx ( tile , GFX_OILWELL_ANIMATED_1 ) ;
SetIndustryAnimationState ( tile , 0 ) ;
AddAnimatedTile ( tile ) ;
}
2004-08-09 17:04:08 +00:00
break ;
2006-09-08 22:12:57 +00:00
case GFX_COAL_MINE_TOWER_ANIMATED :
case GFX_COPPER_MINE_TOWER_ANIMATED :
case GFX_GOLD_MINE_TOWER_ANIMATED :
2006-12-30 11:51:37 +00:00
if ( ! ( _tick_counter & 0x400 ) ) {
switch ( gfx ) {
case GFX_COAL_MINE_TOWER_ANIMATED : gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED ; break ;
case GFX_COPPER_MINE_TOWER_ANIMATED : gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED ; break ;
case GFX_GOLD_MINE_TOWER_ANIMATED : gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED ; break ;
}
SetIndustryGfx ( tile , gfx ) ;
SetIndustryCompleted ( tile , true ) ;
SetIndustryConstructionStage ( tile , 3 ) ;
DeleteAnimatedTile ( tile ) ;
}
2004-08-09 17:04:08 +00:00
break ;
2006-09-08 22:12:57 +00:00
case GFX_POWERPLANT_SPARKS :
2007-11-25 15:35:25 +00:00
if ( Chance16 ( 1 , 3 ) ) {
2004-12-04 09:26:39 +00:00
SndPlayTileFx ( SND_0C_ELECTRIC_SPARK , tile ) ;
2004-08-09 17:04:08 +00:00
AddAnimatedTile ( tile ) ;
}
break ;
2006-09-08 22:12:57 +00:00
case GFX_COPPER_MINE_CHIMNEY :
2006-04-03 05:32:11 +00:00
CreateEffectVehicleAbove ( TileX ( tile ) * TILE_SIZE + 6 , TileY ( tile ) * TILE_SIZE + 6 , 43 , EV_SMOKE ) ;
2005-11-14 19:48:04 +00:00
break ;
2004-08-09 17:04:08 +00:00
2006-09-08 22:12:57 +00:00
case GFX_TOY_FACTORY : {
2009-08-30 11:47:41 +00:00
Industry * i = Industry : : GetByTile ( tile ) ;
2004-08-09 17:04:08 +00:00
if ( i - > was_cargo_delivered ) {
i - > was_cargo_delivered = false ;
2006-04-12 18:10:54 +00:00
SetIndustryAnimationLoop ( tile , 0 ) ;
2004-08-09 17:04:08 +00:00
AddAnimatedTile ( tile ) ;
}
}
break ;
2006-09-08 22:12:57 +00:00
case GFX_BUBBLE_GENERATOR :
2006-03-21 23:22:21 +00:00
TileLoopIndustry_BubbleGenerator ( tile ) ;
2004-09-11 09:55:19 +00:00
break ;
2006-09-08 22:12:57 +00:00
case GFX_TOFFEE_QUARY :
2004-08-09 17:04:08 +00:00
AddAnimatedTile ( tile ) ;
break ;
2006-09-08 22:12:57 +00:00
case GFX_SUGAR_MINE_SIEVE :
2007-11-25 15:35:25 +00:00
if ( Chance16 ( 1 , 3 ) ) AddAnimatedTile ( tile ) ;
2004-08-09 17:04:08 +00:00
break ;
}
}
2009-01-02 22:42:05 +00:00
static bool ClickTile_Industry ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-03-24 08:00:45 +00:00
ShowIndustryViewWindow ( GetIndustryIndex ( tile ) ) ;
2009-01-02 22:42:05 +00:00
return true ;
2004-08-09 17:04:08 +00:00
}
2008-02-20 17:49:50 +00:00
static TrackStatus GetTileTrackStatus_Industry ( TileIndex tile , TransportType mode , uint sub_mode , DiagDirection side )
2004-08-09 17:04:08 +00:00
{
return 0 ;
}
2009-06-27 21:06:58 +00:00
static void AddProducedCargo_Industry ( TileIndex tile , CargoArray & produced )
2004-08-09 17:04:08 +00:00
{
2009-08-30 11:47:41 +00:00
const Industry * i = Industry : : GetByTile ( tile ) ;
2005-11-13 13:43:55 +00:00
2009-06-27 17:05:20 +00:00
for ( uint j = 0 ; j < lengthof ( i - > produced_cargo ) ; j + + ) {
CargoID cargo = i - > produced_cargo [ j ] ;
2009-06-27 18:26:50 +00:00
if ( cargo ! = CT_INVALID ) produced [ cargo ] + + ;
2009-06-27 17:05:20 +00:00
}
2004-08-09 17:04:08 +00:00
}
2008-09-30 20:39:50 +00:00
static void ChangeTileOwner_Industry ( TileIndex tile , Owner old_owner , Owner new_owner )
2004-08-09 17:04:08 +00:00
{
2007-07-07 08:53:19 +00:00
/* If the founder merges, the industry was created by the merged company */
2009-08-30 11:47:41 +00:00
Industry * i = Industry : : GetByTile ( tile ) ;
2008-09-30 20:39:50 +00:00
if ( i - > founder = = old_owner ) i - > founder = ( new_owner = = INVALID_OWNER ) ? OWNER_NONE : new_owner ;
2004-08-09 17:04:08 +00:00
}
static const byte _plantfarmfield_type [ ] = { 1 , 1 , 1 , 1 , 1 , 3 , 3 , 4 , 4 , 4 , 5 , 5 , 5 , 6 , 6 , 6 } ;
2005-01-17 09:41:46 +00:00
static bool IsBadFarmFieldTile ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2005-01-29 15:12:40 +00:00
switch ( GetTileType ( tile ) ) {
2007-01-15 16:31:46 +00:00
case MP_CLEAR : return IsClearGround ( tile , CLEAR_FIELDS ) | | IsClearGround ( tile , CLEAR_SNOW ) | | IsClearGround ( tile , CLEAR_DESERT ) ;
2008-01-31 17:54:13 +00:00
case MP_TREES : return ( GetTreeGround ( tile ) = = TREE_GROUND_SHORE ) ;
2006-02-01 15:31:21 +00:00
default : return true ;
2004-08-09 17:04:08 +00:00
}
}
2005-01-17 09:41:46 +00:00
static bool IsBadFarmFieldTile2 ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2005-01-29 15:12:40 +00:00
switch ( GetTileType ( tile ) ) {
2007-01-15 16:31:46 +00:00
case MP_CLEAR : return IsClearGround ( tile , CLEAR_SNOW ) | | IsClearGround ( tile , CLEAR_DESERT ) ;
2008-01-31 17:54:13 +00:00
case MP_TREES : return ( GetTreeGround ( tile ) = = TREE_GROUND_SHORE ) ;
2006-02-01 15:31:21 +00:00
default : return true ;
2004-08-09 17:04:08 +00:00
}
}
2006-03-08 06:55:33 +00:00
static void SetupFarmFieldFence ( TileIndex tile , int size , byte type , Axis direction )
2004-08-09 17:04:08 +00:00
{
do {
tile = TILE_MASK ( tile ) ;
2004-09-11 09:55:19 +00:00
2005-01-16 11:24:58 +00:00
if ( IsTileType ( tile , MP_CLEAR ) | | IsTileType ( tile , MP_TREES ) ) {
2007-01-10 18:56:51 +00:00
byte or_ = type ;
2004-09-11 09:55:19 +00:00
2007-11-25 15:35:25 +00:00
if ( or_ = = 1 & & Chance16 ( 1 , 7 ) ) or_ = 2 ;
2004-08-09 17:04:08 +00:00
2006-03-08 06:55:33 +00:00
if ( direction = = AXIS_X ) {
2007-01-10 18:56:51 +00:00
SetFenceSE ( tile , or_ ) ;
2006-03-08 06:55:33 +00:00
} else {
2007-01-10 18:56:51 +00:00
SetFenceSW ( tile , or_ ) ;
2004-08-09 17:04:08 +00:00
}
}
2004-09-11 09:55:19 +00:00
2006-03-08 06:55:33 +00:00
tile + = ( direction = = AXIS_X ? TileDiffXY ( 1 , 0 ) : TileDiffXY ( 0 , 1 ) ) ;
2004-08-09 17:04:08 +00:00
} while ( - - size ) ;
}
2006-08-20 19:31:58 +00:00
static void PlantFarmField ( TileIndex tile , IndustryID industry )
2004-08-09 17:04:08 +00:00
{
uint size_x , size_y ;
uint32 r ;
2005-07-19 21:49:35 +00:00
uint count ;
2006-02-05 11:54:25 +00:00
uint counter ;
uint field_type ;
int type ;
2004-08-09 17:04:08 +00:00
2008-05-29 15:13:28 +00:00
if ( _settings_game . game_creation . landscape = = LT_ARCTIC ) {
2007-03-20 13:47:00 +00:00
if ( GetTileZ ( tile ) + TILE_HEIGHT * 2 > = GetSnowLine ( ) )
2004-08-09 17:04:08 +00:00
return ;
}
/* determine field size */
r = ( Random ( ) & 0x303 ) + 0x404 ;
2008-05-29 15:13:28 +00:00
if ( _settings_game . game_creation . landscape = = LT_ARCTIC ) r + = 0x404 ;
2005-07-21 06:31:02 +00:00
size_x = GB ( r , 0 , 8 ) ;
size_y = GB ( r , 8 , 8 ) ;
2004-08-09 17:04:08 +00:00
/* offset tile to match size */
2005-06-25 16:44:57 +00:00
tile - = TileDiffXY ( size_x / 2 , size_y / 2 ) ;
2004-09-11 09:55:19 +00:00
2009-01-21 02:31:55 +00:00
if ( TileX ( tile ) + size_x > = MapSizeX ( ) | | TileY ( tile ) + size_y > = MapSizeY ( ) ) return ;
2004-08-09 17:04:08 +00:00
/* check the amount of bad tiles */
count = 0 ;
2009-07-26 21:50:30 +00:00
TILE_LOOP ( cur_tile , size_x , size_y , tile ) {
2009-02-25 21:50:54 +00:00
assert ( cur_tile < MapSize ( ) ) ;
2004-08-09 17:04:08 +00:00
count + = IsBadFarmFieldTile ( cur_tile ) ;
2009-07-26 21:50:30 +00:00
}
2005-07-19 21:49:35 +00:00
if ( count * 2 > = size_x * size_y ) return ;
2004-08-09 17:04:08 +00:00
/* determine type of field */
r = Random ( ) ;
2006-02-05 11:54:25 +00:00
counter = GB ( r , 5 , 3 ) ;
field_type = GB ( r , 8 , 8 ) * 9 > > 8 ;
2004-08-09 17:04:08 +00:00
/* make field */
2009-07-26 21:50:30 +00:00
TILE_LOOP ( cur_tile , size_x , size_y , tile ) {
2009-02-25 21:50:54 +00:00
assert ( cur_tile < MapSize ( ) ) ;
2004-08-09 17:04:08 +00:00
if ( ! IsBadFarmFieldTile2 ( cur_tile ) ) {
2006-08-20 18:44:26 +00:00
MakeField ( cur_tile , field_type , industry ) ;
2006-02-05 11:54:25 +00:00
SetClearCounter ( cur_tile , counter ) ;
MarkTileDirtyByTile ( cur_tile ) ;
2004-08-09 17:04:08 +00:00
}
2009-07-26 21:50:30 +00:00
}
2004-09-11 09:55:19 +00:00
2004-08-09 17:04:08 +00:00
type = 3 ;
2008-05-29 15:13:28 +00:00
if ( _settings_game . game_creation . landscape ! = LT_ARCTIC & & _settings_game . game_creation . landscape ! = LT_TROPIC ) {
2004-08-09 17:04:08 +00:00
type = _plantfarmfield_type [ Random ( ) & 0xF ] ;
}
2006-03-08 06:55:33 +00:00
SetupFarmFieldFence ( tile - TileDiffXY ( 1 , 0 ) , size_y , type , AXIS_Y ) ;
SetupFarmFieldFence ( tile - TileDiffXY ( 0 , 1 ) , size_x , type , AXIS_X ) ;
SetupFarmFieldFence ( tile + TileDiffXY ( size_x - 1 , 0 ) , size_y , type , AXIS_Y ) ;
SetupFarmFieldFence ( tile + TileDiffXY ( 0 , size_y - 1 ) , size_x , type , AXIS_X ) ;
2004-08-09 17:04:08 +00:00
}
2006-08-20 18:44:26 +00:00
void PlantRandomFarmField ( const Industry * i )
{
int x = i - > width / 2 + Random ( ) % 31 - 16 ;
int y = i - > height / 2 + Random ( ) % 31 - 16 ;
TileIndex tile = TileAddWrap ( i - > xy , x , y ) ;
if ( tile ! = INVALID_TILE ) PlantFarmField ( tile , i - > index ) ;
}
2006-11-17 23:01:58 +00:00
/**
* Search callback function for ChopLumberMillTrees
* @ param tile to test
2008-06-25 18:46:05 +00:00
* @ param user_data that is passed by the caller . In this case , nothing
2007-03-03 04:04:22 +00:00
* @ return the result of the test
2006-11-17 23:01:58 +00:00
*/
2008-06-25 18:46:05 +00:00
static bool SearchLumberMillTrees ( TileIndex tile , void * user_data )
2004-08-09 17:04:08 +00:00
{
2007-02-02 15:14:28 +00:00
if ( IsTileType ( tile , MP_TREES ) & & GetTreeGrowth ( tile ) > 2 ) { ///< 3 and up means all fully grown trees
2008-09-30 20:39:50 +00:00
CompanyID old_company = _current_company ;
2006-11-17 23:01:58 +00:00
/* found a tree */
2004-08-09 17:04:08 +00:00
2008-09-30 20:39:50 +00:00
_current_company = OWNER_NONE ;
2006-11-17 23:01:58 +00:00
_industry_sound_ctr = 1 ;
_industry_sound_tile = tile ;
SndPlayTileFx ( SND_38_CHAINSAW , tile ) ;
2005-11-14 19:48:04 +00:00
2006-11-17 23:01:58 +00:00
DoCommand ( tile , 0 , 0 , DC_EXEC , CMD_LANDSCAPE_CLEAR ) ;
2005-11-14 19:48:04 +00:00
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
2006-11-17 23:01:58 +00:00
return true ;
}
return false ;
}
2004-08-09 17:04:08 +00:00
2006-11-17 23:01:58 +00:00
/**
* Perform a circular search around the Lumber Mill in order to find trees to cut
* @ param i industry
*/
static void ChopLumberMillTrees ( Industry * i )
{
TileIndex tile = i - > xy ;
2004-08-09 17:04:08 +00:00
2006-11-17 23:01:58 +00:00
if ( ! IsIndustryCompleted ( tile ) ) return ; ///< Can't proceed if not completed
2004-09-25 17:37:32 +00:00
2008-06-25 18:46:05 +00:00
if ( CircularTileSearch ( & tile , 40 , SearchLumberMillTrees , NULL ) ) ///< 40x40 tiles to search
2007-07-04 18:27:21 +00:00
i - > produced_cargo_waiting [ 0 ] = min ( 0xffff , i - > produced_cargo_waiting [ 0 ] + 45 ) ; ///< Found a tree, add according value to waiting cargo
2004-08-09 17:04:08 +00:00
}
static void ProduceIndustryGoods ( Industry * i )
{
uint32 r ;
uint num ;
2007-05-20 00:50:06 +00:00
const IndustrySpec * indsp = GetIndustrySpec ( i - > type ) ;
2004-08-09 17:04:08 +00:00
/* play a sound? */
if ( ( i - > counter & 0x3F ) = = 0 ) {
2007-11-25 15:35:25 +00:00
if ( Chance16R ( 1 , 14 , r ) & & ( num = indsp - > number_of_sounds ) ! = 0 ) {
2004-08-09 17:04:08 +00:00
SndPlayTileFx (
2007-05-20 00:50:06 +00:00
( SoundFx ) ( indsp - > random_sounds [ ( ( r > > 16 ) * num ) > > 16 ] ) ,
2004-08-09 17:04:08 +00:00
i - > xy ) ;
}
}
i - > counter - - ;
/* produce some cargo */
if ( ( i - > counter & 0xFF ) = = 0 ) {
2007-11-19 21:02:30 +00:00
if ( HasBit ( indsp - > callback_flags , CBM_IND_PRODUCTION_256_TICKS ) ) IndustryProductionCallback ( i , 1 ) ;
2007-07-05 05:41:56 +00:00
2007-10-19 21:14:38 +00:00
IndustryBehaviour indbehav = indsp - > behaviour ;
2007-07-04 18:27:21 +00:00
i - > produced_cargo_waiting [ 0 ] = min ( 0xffff , i - > produced_cargo_waiting [ 0 ] + i - > production_rate [ 0 ] ) ;
i - > produced_cargo_waiting [ 1 ] = min ( 0xffff , i - > produced_cargo_waiting [ 1 ] + i - > production_rate [ 1 ] ) ;
2004-08-09 17:04:08 +00:00
2007-07-08 19:54:51 +00:00
if ( ( indbehav & INDUSTRYBEH_PLANT_FIELDS ) ! = 0 ) {
bool plant ;
2007-11-19 21:02:30 +00:00
if ( HasBit ( indsp - > callback_flags , CBM_IND_SPECIAL_EFFECT ) ) {
2007-07-08 19:54:51 +00:00
plant = ( GetIndustryCallback ( CBID_INDUSTRY_SPECIAL_EFFECT , Random ( ) , 0 , i , i - > type , i - > xy ) ! = 0 ) ;
} else {
2007-11-25 15:35:25 +00:00
plant = Chance16 ( 1 , 8 ) ;
2007-07-08 19:54:51 +00:00
}
if ( plant ) PlantRandomFarmField ( i ) ;
}
if ( ( indbehav & INDUSTRYBEH_CUT_TREES ) ! = 0 ) {
bool cut = ( ( i - > counter & 0x1FF ) = = 0 ) ;
2007-11-19 21:02:30 +00:00
if ( HasBit ( indsp - > callback_flags , CBM_IND_SPECIAL_EFFECT ) ) {
2007-07-08 19:54:51 +00:00
cut = ( GetIndustryCallback ( CBID_INDUSTRY_SPECIAL_EFFECT , 0 , 1 , i , i - > type , i - > xy ) ! = 0 ) ;
}
if ( cut ) ChopLumberMillTrees ( i ) ;
2005-11-14 19:48:04 +00:00
}
2008-04-23 00:14:49 +00:00
TriggerIndustry ( i , INDUSTRY_TRIGGER_INDUSTRY_TICK ) ;
StartStopIndustryTileAnimation ( i , IAT_INDUSTRY_TICK ) ;
2004-08-09 17:04:08 +00:00
}
}
2007-03-07 11:47:46 +00:00
void OnTick_Industry ( )
2004-08-09 17:04:08 +00:00
{
Industry * i ;
if ( _industry_sound_ctr ! = 0 ) {
_industry_sound_ctr + + ;
if ( _industry_sound_ctr = = 75 ) {
2004-12-04 09:26:39 +00:00
SndPlayTileFx ( SND_37_BALLOON_SQUEAK , _industry_sound_tile ) ;
2004-08-09 17:04:08 +00:00
} else if ( _industry_sound_ctr = = 160 ) {
2004-09-11 09:55:19 +00:00
_industry_sound_ctr = 0 ;
2004-12-04 09:26:39 +00:00
SndPlayTileFx ( SND_36_CARTOON_CRASH , _industry_sound_tile ) ;
2004-08-09 17:04:08 +00:00
}
}
2005-11-14 19:48:04 +00:00
if ( _game_mode = = GM_EDITOR ) return ;
2004-08-09 17:04:08 +00:00
2004-12-30 10:03:35 +00:00
FOR_ALL_INDUSTRIES ( i ) {
2006-08-22 15:33:35 +00:00
ProduceIndustryGoods ( i ) ;
2004-08-09 17:04:08 +00:00
}
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_NULL ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
return true ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_Forest ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2008-05-29 15:13:28 +00:00
if ( _settings_game . game_creation . landscape = = LT_ARCTIC ) {
2007-03-20 13:47:00 +00:00
if ( GetTileZ ( tile ) < HighestSnowLine ( ) + TILE_HEIGHT * 2U ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED ;
2004-08-09 17:04:08 +00:00
return false ;
}
}
return true ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_OilRefinery ( TileIndex tile )
{
if ( _game_mode = = GM_EDITOR ) return true ;
2008-05-29 15:13:28 +00:00
if ( DistanceFromEdge ( TILE_ADDXY ( tile , 1 , 1 ) ) < _settings_game . game_creation . oil_refinery_limit ) return true ;
2006-05-20 16:46:37 +00:00
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_CAN_ONLY_BE_POSITIONED ;
2006-05-20 16:46:37 +00:00
return false ;
}
2004-08-10 16:12:40 +00:00
extern bool _ignore_restrictions ;
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_OilRig ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2005-11-14 19:48:04 +00:00
if ( _game_mode = = GM_EDITOR & & _ignore_restrictions ) return true ;
2006-05-20 16:46:37 +00:00
if ( TileHeight ( tile ) = = 0 & &
2008-05-29 15:13:28 +00:00
DistanceFromEdge ( TILE_ADDXY ( tile , 1 , 1 ) ) < _settings_game . game_creation . oil_refinery_limit ) return true ;
2004-08-09 17:04:08 +00:00
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_CAN_ONLY_BE_POSITIONED ;
2004-08-09 17:04:08 +00:00
return false ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_Farm ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2008-05-29 15:13:28 +00:00
if ( _settings_game . game_creation . landscape = = LT_ARCTIC ) {
2007-03-20 13:47:00 +00:00
if ( GetTileZ ( tile ) + TILE_HEIGHT * 2 > = HighestSnowLine ( ) ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_SITE_UNSUITABLE ;
2004-08-09 17:04:08 +00:00
return false ;
}
}
return true ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_Plantation ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-03-30 19:16:44 +00:00
if ( GetTropicZone ( tile ) = = TROPICZONE_DESERT ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_SITE_UNSUITABLE ;
2004-08-09 17:04:08 +00:00
return false ;
}
return true ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_Water ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-03-30 19:16:44 +00:00
if ( GetTropicZone ( tile ) ! = TROPICZONE_DESERT ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT ;
2004-08-09 17:04:08 +00:00
return false ;
}
return true ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_Lumbermill ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-03-30 19:16:44 +00:00
if ( GetTropicZone ( tile ) ! = TROPICZONE_RAINFOREST ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST ;
2004-08-09 17:04:08 +00:00
return false ;
}
return true ;
}
2006-05-20 16:46:37 +00:00
static bool CheckNewIndustry_BubbleGen ( TileIndex tile )
2004-08-09 17:04:08 +00:00
{
2006-04-23 19:35:36 +00:00
return GetTileZ ( tile ) < = TILE_HEIGHT * 4 ;
2004-08-09 17:04:08 +00:00
}
2006-05-20 16:46:37 +00:00
typedef bool CheckNewIndustryProc ( TileIndex tile ) ;
2006-04-26 17:01:27 +00:00
static CheckNewIndustryProc * const _check_new_industry_procs [ CHECK_END ] = {
2004-08-09 17:04:08 +00:00
CheckNewIndustry_NULL ,
CheckNewIndustry_Forest ,
2006-05-20 16:46:37 +00:00
CheckNewIndustry_OilRefinery ,
2004-08-09 17:04:08 +00:00
CheckNewIndustry_Farm ,
CheckNewIndustry_Plantation ,
CheckNewIndustry_Water ,
CheckNewIndustry_Lumbermill ,
CheckNewIndustry_BubbleGen ,
2006-05-20 16:46:37 +00:00
CheckNewIndustry_OilRig
2004-08-09 17:04:08 +00:00
} ;
2006-04-26 14:58:06 +00:00
static const Town * CheckMultipleIndustryInTown ( TileIndex tile , int type )
2004-08-09 17:04:08 +00:00
{
2006-04-26 14:58:06 +00:00
const Town * t ;
const Industry * i ;
2004-08-09 17:04:08 +00:00
2008-10-14 18:38:51 +00:00
t = ClosestTownFromTile ( tile , UINT_MAX ) ;
2004-09-11 09:55:19 +00:00
2008-05-29 15:13:28 +00:00
if ( _settings_game . economy . multiple_industry_per_town ) return t ;
2004-08-09 17:04:08 +00:00
2004-12-30 10:03:35 +00:00
FOR_ALL_INDUSTRIES ( i ) {
2006-08-22 15:33:35 +00:00
if ( i - > type = = ( byte ) type & &
2004-08-09 17:04:08 +00:00
i - > town = = t ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN ;
2004-08-09 17:04:08 +00:00
return NULL ;
}
}
return t ;
}
2007-10-02 16:56:45 +00:00
bool IsSlopeRefused ( Slope current , Slope refused )
{
2007-10-15 18:36:20 +00:00
if ( IsSteepSlope ( current ) ) return true ;
2007-10-02 16:56:45 +00:00
if ( current ! = SLOPE_FLAT ) {
2007-12-07 21:16:38 +00:00
if ( IsSteepSlope ( refused ) ) return true ;
2007-10-02 16:56:45 +00:00
Slope t = ComplementSlope ( current ) ;
2009-06-01 11:43:36 +00:00
if ( ( refused & SLOPE_W ) & & ( t & SLOPE_NW ) ) return true ;
if ( ( refused & SLOPE_S ) & & ( t & SLOPE_NE ) ) return true ;
if ( ( refused & SLOPE_E ) & & ( t & SLOPE_SW ) ) return true ;
if ( ( refused & SLOPE_N ) & & ( t & SLOPE_SE ) ) return true ;
2007-10-02 16:56:45 +00:00
}
return false ;
}
static bool CheckIfIndustryTilesAreFree ( TileIndex tile , const IndustryTileTable * it , uint itspec_index , int type , bool * custom_shape_check = NULL )
2004-08-09 17:04:08 +00:00
{
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_SITE_UNSUITABLE ;
2007-10-02 17:48:17 +00:00
bool refused_slope = false ;
bool custom_shape = false ;
2004-08-09 17:04:08 +00:00
do {
2007-08-24 00:23:35 +00:00
IndustryGfx gfx = GetTranslatedIndustryTileID ( it - > gfx ) ;
2009-01-21 02:31:55 +00:00
if ( TileX ( tile ) + it - > ti . x > = MapSizeX ( ) ) return false ;
if ( TileY ( tile ) + it - > ti . y > = MapSizeY ( ) ) return false ;
2005-06-24 12:38:35 +00:00
TileIndex cur_tile = tile + ToTileIndexDiff ( it - > ti ) ;
2004-08-09 17:04:08 +00:00
if ( ! IsValidTile ( cur_tile ) ) {
2007-08-26 00:23:32 +00:00
if ( gfx = = GFX_WATERTILE_SPECIALCHECK ) continue ;
2004-08-09 17:04:08 +00:00
return false ;
}
2004-09-11 09:55:19 +00:00
2007-08-26 00:23:32 +00:00
if ( gfx = = GFX_WATERTILE_SPECIALCHECK ) {
2006-03-22 19:04:04 +00:00
if ( ! IsTileType ( cur_tile , MP_WATER ) | |
2006-04-23 13:48:16 +00:00
GetTileSlope ( cur_tile , NULL ) ! = SLOPE_FLAT ) {
2006-03-22 19:04:04 +00:00
return false ;
}
2004-08-09 17:04:08 +00:00
} else {
2007-10-19 22:46:55 +00:00
if ( ! EnsureNoVehicleOnGround ( cur_tile ) ) return false ;
2007-06-13 15:22:28 +00:00
if ( MayHaveBridgeAbove ( cur_tile ) & & IsBridgeAbove ( cur_tile ) ) return false ;
2007-09-06 03:02:38 +00:00
const IndustryTileSpec * its = GetIndustryTileSpec ( gfx ) ;
2007-10-19 21:14:38 +00:00
IndustryBehaviour ind_behav = GetIndustrySpec ( type ) - > behaviour ;
2004-08-09 17:04:08 +00:00
2007-10-19 21:05:25 +00:00
/* Perform land/water check if not disabled */
2008-02-02 09:28:43 +00:00
if ( ! HasBit ( its - > slopes_refused , 5 ) & & ( IsWaterTile ( cur_tile ) = = ! ( ind_behav & INDUSTRYBEH_BUILT_ONWATER ) ) ) return false ;
2007-10-19 21:05:25 +00:00
2007-11-19 21:02:30 +00:00
if ( HasBit ( its - > callback_flags , CBM_INDT_SHAPE_CHECK ) ) {
2007-10-02 17:48:17 +00:00
custom_shape = true ;
2007-10-02 16:56:45 +00:00
if ( ! PerformIndustryTileSlopeCheck ( tile , cur_tile , its , type , gfx , itspec_index ) ) return false ;
2004-08-09 17:04:08 +00:00
} else {
2007-10-19 21:05:25 +00:00
Slope tileh = GetTileSlope ( cur_tile , NULL ) ;
refused_slope | = IsSlopeRefused ( tileh , its - > slopes_refused ) ;
2007-07-09 18:53:43 +00:00
}
2004-08-09 17:04:08 +00:00
2009-01-09 15:11:35 +00:00
if ( ( ind_behav & ( INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE ) ) | | // Tile must be a house
( ( ind_behav & INDUSTRYBEH_ONLY_NEARTOWN ) & & IsTileType ( cur_tile , MP_HOUSE ) ) ) { // Tile is allowed to be a house (and it is a house)
2007-07-09 18:53:43 +00:00
if ( ! IsTileType ( cur_tile , MP_HOUSE ) ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS ;
2007-07-09 18:53:43 +00:00
return false ;
2004-08-09 17:04:08 +00:00
}
2008-11-23 16:34:27 +00:00
/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
CompanyID old_company = _current_company ;
_current_company = OWNER_TOWN ;
2009-02-09 21:20:05 +00:00
bool not_clearable = CmdFailed ( DoCommand ( cur_tile , 0 , 0 , DC_NONE , CMD_LANDSCAPE_CLEAR ) ) ;
2008-11-23 16:34:27 +00:00
_current_company = old_company ;
if ( not_clearable ) return false ;
2009-01-09 15:11:35 +00:00
} else {
2009-02-11 20:09:29 +00:00
/* Clear the tiles, but do not affect town ratings */
bool not_clearable = CmdFailed ( DoCommand ( cur_tile , 0 , 0 , DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING , CMD_LANDSCAPE_CLEAR ) ) ;
2008-11-23 16:34:27 +00:00
if ( not_clearable ) return false ;
2007-07-09 18:53:43 +00:00
}
2004-08-09 17:04:08 +00:00
}
2005-01-06 11:39:00 +00:00
} while ( ( + + it ) - > ti . x ! = - 0x80 ) ;
2004-08-09 17:04:08 +00:00
2007-10-02 17:48:17 +00:00
if ( custom_shape_check ! = NULL ) * custom_shape_check = custom_shape ;
/* It is almost impossible to have a fully flat land in TG, so what we
* do is that we check if we can make the land flat later on . See
* CheckIfCanLevelIndustryPlatform ( ) . */
2008-05-29 15:13:28 +00:00
return ! refused_slope | | ( _settings_game . game_creation . land_generator = = LG_TERRAGENESIS & & _generating_world & & ! custom_shape & & ! _ignore_restrictions ) ;
2004-08-09 17:04:08 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
static bool CheckIfIndustryIsAllowed ( TileIndex tile , int type , const Town * t )
{
2007-03-28 20:06:28 +00:00
if ( ( GetIndustrySpec ( type ) - > behaviour & INDUSTRYBEH_TOWN1200_MORE ) & & t - > population < 1200 ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200 ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
return false ;
}
2007-03-28 20:06:28 +00:00
if ( ( GetIndustrySpec ( type ) - > behaviour & INDUSTRYBEH_ONLY_NEARTOWN ) & & DistanceMax ( t - > xy , tile ) > 9 ) {
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_SITE_UNSUITABLE ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
return false ;
}
return true ;
}
static bool CheckCanTerraformSurroundingTiles ( TileIndex tile , uint height , int internal )
{
int size_x , size_y ;
uint curh ;
size_x = 2 ;
size_y = 2 ;
/* Check if we don't leave the map */
if ( TileX ( tile ) = = 0 | | TileY ( tile ) = = 0 | | GetTileType ( tile ) = = MP_VOID ) return false ;
tile + = TileDiffXY ( - 1 , - 1 ) ;
2009-07-26 21:50:30 +00:00
TILE_LOOP ( tile_walk , size_x , size_y , tile ) {
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
curh = TileHeight ( tile_walk ) ;
/* Is the tile clear? */
if ( ( GetTileType ( tile_walk ) ! = MP_CLEAR ) & & ( GetTileType ( tile_walk ) ! = MP_TREES ) )
return false ;
/* Don't allow too big of a change if this is the sub-tile check */
2007-11-26 16:01:29 +00:00
if ( internal ! = 0 & & Delta ( curh , height ) > 1 ) return false ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
/* Different height, so the surrounding tiles of this tile
* has to be correct too ( in level , or almost in level )
* else you get a chain - reaction of terraforming . */
if ( internal = = 0 & & curh ! = height ) {
2009-01-21 02:31:55 +00:00
if ( TileX ( tile_walk ) = = 0 | | TileY ( tile_walk ) = = 0 | | ! CheckCanTerraformSurroundingTiles ( tile_walk + TileDiffXY ( - 1 , - 1 ) , height , internal + 1 ) )
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
return false ;
}
2009-07-26 21:50:30 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
return true ;
}
/**
* This function tries to flatten out the land below an industry , without
* damaging the surroundings too much .
*/
2009-02-09 21:20:05 +00:00
static bool CheckIfCanLevelIndustryPlatform ( TileIndex tile , DoCommandFlag flags , const IndustryTileTable * it , int type )
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
{
const int MKEND = - 0x80 ; // used for last element in an IndustryTileTable (see build_industry.h)
int max_x = 0 ;
int max_y = 0 ;
TileIndex cur_tile ;
uint size_x , size_y ;
uint h , curh ;
/* Finds dimensions of largest variant of this industry */
do {
2007-09-26 01:24:12 +00:00
if ( it - > gfx = = 0xFF ) continue ; // FF been a marquer for a check on clear water, skip it
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
if ( it - > ti . x > max_x ) max_x = it - > ti . x ;
if ( it - > ti . y > max_y ) max_y = it - > ti . y ;
} while ( ( + + it ) - > ti . x ! = MKEND ) ;
/* Remember level height */
h = TileHeight ( tile ) ;
2009-01-21 02:31:55 +00:00
if ( TileX ( tile ) < = 1 | | TileY ( tile ) < = 1 ) return false ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
/* Check that all tiles in area and surrounding are clear
* this determines that there are no obstructing items */
cur_tile = tile + TileDiffXY ( - 1 , - 1 ) ;
size_x = max_x + 4 ;
size_y = max_y + 4 ;
/* Check if we don't leave the map */
2009-01-21 02:31:55 +00:00
if ( TileX ( cur_tile ) + size_x > = MapMaxX ( ) | | TileY ( cur_tile ) + size_y > = MapMaxY ( ) ) return false ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
2008-09-30 20:39:50 +00:00
/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
2009-02-11 20:09:29 +00:00
* Perform terraforming as OWNER_TOWN to disable autoslope and town ratings . */
2008-09-30 20:39:50 +00:00
CompanyID old_company = _current_company ;
_current_company = OWNER_TOWN ;
2007-09-26 14:32:06 +00:00
2009-07-26 21:50:30 +00:00
TILE_LOOP ( tile_walk , size_x , size_y , cur_tile ) {
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
curh = TileHeight ( tile_walk ) ;
if ( curh ! = h ) {
/* This tile needs terraforming. Check if we can do that without
* damaging the surroundings too much . */
2007-09-26 14:32:06 +00:00
if ( ! CheckCanTerraformSurroundingTiles ( tile_walk , h , 0 ) ) {
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
2007-09-26 14:32:06 +00:00
return false ;
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
/* This is not 100% correct check, but the best we can do without modifying the map.
* What is missing , is if the difference in height is more than 1. . */
2007-09-26 14:32:06 +00:00
if ( CmdFailed ( DoCommand ( tile_walk , SLOPE_N , ( curh > h ) ? 0 : 1 , flags & ~ DC_EXEC , CMD_TERRAFORM_LAND ) ) ) {
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
2007-09-26 14:32:06 +00:00
return false ;
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
}
2009-07-26 21:50:30 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
if ( flags & DC_EXEC ) {
/* Terraform the land under the industry */
2009-07-26 21:50:30 +00:00
TILE_LOOP ( tile_walk , size_x , size_y , cur_tile ) {
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
curh = TileHeight ( tile_walk ) ;
while ( curh ! = h ) {
/* We give the terraforming for free here, because we can't calculate
* exact cost in the test - round , and as we all know , that will cause
* a nice assert if they don ' t match ; ) */
2007-08-27 21:18:04 +00:00
DoCommand ( tile_walk , SLOPE_N , ( curh > h ) ? 0 : 1 , flags , CMD_TERRAFORM_LAND ) ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
curh + = ( curh > h ) ? - 1 : 1 ;
}
2009-07-26 21:50:30 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
}
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
return true ;
}
2008-01-09 18:35:18 +00:00
static bool CheckIfFarEnoughFromIndustry ( TileIndex tile , int type )
2004-08-09 17:04:08 +00:00
{
2006-04-26 21:10:01 +00:00
const IndustrySpec * indspec = GetIndustrySpec ( type ) ;
2006-04-26 14:58:06 +00:00
const Industry * i ;
2004-08-09 17:04:08 +00:00
2008-05-29 15:13:28 +00:00
if ( _settings_game . economy . same_industry_close & & indspec - > IsRawIndustry ( ) )
2008-01-09 18:35:18 +00:00
/* Allow primary industries to be placed close to any other industry */
2004-08-09 17:04:08 +00:00
return true ;
2004-09-11 09:55:19 +00:00
2004-12-30 10:03:35 +00:00
FOR_ALL_INDUSTRIES ( i ) {
2008-01-09 18:35:18 +00:00
/* Within 14 tiles from another industry is considered close */
bool in_low_distance = DistanceMax ( tile , i - > xy ) < = 14 ;
2007-03-03 04:04:22 +00:00
/* check if an industry that accepts the same goods is nearby */
2008-01-09 18:35:18 +00:00
if ( in_low_distance & &
2008-05-01 22:51:53 +00:00
! indspec - > IsRawIndustry ( ) & & // not a primary industry?
2007-09-27 21:39:13 +00:00
indspec - > accepts_cargo [ 0 ] = = i - > accepts_cargo [ 0 ] & & (
2008-01-09 18:35:18 +00:00
/* at least one of those options must be true */
_game_mode ! = GM_EDITOR | | // editor must not be stopped
2008-05-29 15:13:28 +00:00
! _settings_game . economy . same_industry_close | |
! _settings_game . economy . multiple_industry_per_town ) ) {
2009-08-05 17:59:21 +00:00
_error_message = STR_ERROR_INDUSTRY_TOO_CLOSE ;
2005-11-14 19:48:04 +00:00
return false ;
}
2004-08-09 17:04:08 +00:00
2008-01-09 18:35:18 +00:00
/* check if there are any conflicting industry types around */
if ( ( i - > type = = indspec - > conflicting [ 0 ] | |
i - > type = = indspec - > conflicting [ 1 ] | |
i - > type = = indspec - > conflicting [ 2 ] ) & &
in_low_distance ) {
2009-08-05 17:59:21 +00:00
_error_message = STR_ERROR_INDUSTRY_TOO_CLOSE ;
2004-08-09 17:04:08 +00:00
return false ;
}
}
return true ;
}
2008-02-09 03:03:09 +00:00
/** Production level maximum, minimum and default values.
* It is not a value been really used in order to change , but rather an indicator
* of how the industry is behaving . */
enum ProductionLevels {
PRODLEVEL_CLOSURE = 0x00 , ///< signal set to actually close the industry
PRODLEVEL_MINIMUM = 0x04 , ///< below this level, the industry is set to be closing
PRODLEVEL_DEFAULT = 0x10 , ///< default level set when the industry is created
PRODLEVEL_MAXIMUM = 0x80 , ///< the industry is running at full speed
} ;
2009-02-11 20:09:29 +00:00
static void DoCreateNewIndustry ( Industry * i , TileIndex tile , int type , const IndustryTileTable * it , byte layout , const Town * t , Owner owner , Owner founder )
2004-08-09 17:04:08 +00:00
{
2006-04-26 21:10:01 +00:00
const IndustrySpec * indspec = GetIndustrySpec ( type ) ;
2004-08-09 17:04:08 +00:00
uint32 r ;
2007-09-27 21:47:38 +00:00
uint j ;
2004-08-09 17:04:08 +00:00
i - > xy = tile ;
i - > width = i - > height = 0 ;
i - > type = type ;
2007-06-08 15:48:48 +00:00
IncIndustryTypeCount ( type ) ;
2004-08-09 17:04:08 +00:00
2007-09-27 21:39:13 +00:00
i - > produced_cargo [ 0 ] = indspec - > produced_cargo [ 0 ] ;
i - > produced_cargo [ 1 ] = indspec - > produced_cargo [ 1 ] ;
i - > accepts_cargo [ 0 ] = indspec - > accepts_cargo [ 0 ] ;
i - > accepts_cargo [ 1 ] = indspec - > accepts_cargo [ 1 ] ;
i - > accepts_cargo [ 2 ] = indspec - > accepts_cargo [ 2 ] ;
2006-04-26 21:10:01 +00:00
i - > production_rate [ 0 ] = indspec - > production_rate [ 0 ] ;
i - > production_rate [ 1 ] = indspec - > production_rate [ 1 ] ;
2004-08-09 17:04:08 +00:00
2007-11-23 16:50:54 +00:00
/* don't use smooth economy for industries using production related callbacks */
2008-05-29 15:13:28 +00:00
if ( _settings_game . economy . smooth_economy & &
2007-11-23 16:50:54 +00:00
! ( HasBit ( indspec - > callback_flags , CBM_IND_PRODUCTION_256_TICKS ) | | HasBit ( indspec - > callback_flags , CBM_IND_PRODUCTION_CARGO_ARRIVAL ) ) & & // production callbacks
! ( HasBit ( indspec - > callback_flags , CBM_IND_MONTHLYPROD_CHANGE ) | | HasBit ( indspec - > callback_flags , CBM_IND_PRODUCTION_CHANGE ) ) // production change callbacks
) {
2004-08-09 17:04:08 +00:00
i - > production_rate [ 0 ] = min ( ( RandomRange ( 256 ) + 128 ) * i - > production_rate [ 0 ] > > 8 , 255 ) ;
i - > production_rate [ 1 ] = min ( ( RandomRange ( 256 ) + 128 ) * i - > production_rate [ 1 ] > > 8 , 255 ) ;
}
i - > town = t ;
i - > owner = owner ;
2005-10-03 21:20:01 +00:00
r = Random ( ) ;
2009-02-09 02:57:15 +00:00
i - > random_colour = GB ( r , 0 , 4 ) ;
2007-11-11 18:22:06 +00:00
i - > counter = GB ( r , 4 , 12 ) ;
i - > random = GB ( r , 16 , 16 ) ;
2007-07-04 18:27:21 +00:00
i - > produced_cargo_waiting [ 0 ] = 0 ;
i - > produced_cargo_waiting [ 1 ] = 0 ;
i - > incoming_cargo_waiting [ 0 ] = 0 ;
i - > incoming_cargo_waiting [ 1 ] = 0 ;
i - > incoming_cargo_waiting [ 2 ] = 0 ;
2007-06-07 14:38:45 +00:00
i - > this_month_production [ 0 ] = 0 ;
i - > this_month_production [ 1 ] = 0 ;
i - > this_month_transported [ 0 ] = 0 ;
i - > this_month_transported [ 1 ] = 0 ;
i - > last_month_pct_transported [ 0 ] = 0 ;
i - > last_month_pct_transported [ 1 ] = 0 ;
i - > last_month_transported [ 0 ] = 0 ;
i - > last_month_transported [ 1 ] = 0 ;
2004-08-09 17:04:08 +00:00
i - > was_cargo_delivered = false ;
2006-08-20 19:05:28 +00:00
i - > last_prod_year = _cur_year ;
2007-06-07 14:38:45 +00:00
i - > last_month_production [ 0 ] = i - > production_rate [ 0 ] * 8 ;
i - > last_month_production [ 1 ] = i - > production_rate [ 1 ] * 8 ;
2009-02-11 20:09:29 +00:00
i - > founder = founder ;
2007-09-27 21:47:38 +00:00
2007-11-19 21:02:30 +00:00
if ( HasBit ( indspec - > callback_flags , CBM_IND_DECIDE_COLOUR ) ) {
2007-09-28 17:09:50 +00:00
uint16 res = GetIndustryCallback ( CBID_INDUSTRY_DECIDE_COLOUR , 0 , 0 , i , type , INVALID_TILE ) ;
2009-02-09 02:57:15 +00:00
if ( res ! = CALLBACK_FAILED ) i - > random_colour = GB ( res , 0 , 4 ) ;
2007-09-28 17:09:50 +00:00
}
2007-11-19 21:02:30 +00:00
if ( HasBit ( indspec - > callback_flags , CBM_IND_INPUT_CARGO_TYPES ) ) {
2007-09-27 21:47:38 +00:00
for ( j = 0 ; j < lengthof ( i - > accepts_cargo ) ; j + + ) i - > accepts_cargo [ j ] = CT_INVALID ;
for ( j = 0 ; j < lengthof ( i - > accepts_cargo ) ; j + + ) {
uint16 res = GetIndustryCallback ( CBID_INDUSTRY_INPUT_CARGO_TYPES , j , 0 , i , type , INVALID_TILE ) ;
if ( res = = CALLBACK_FAILED | | GB ( res , 0 , 8 ) = = CT_INVALID ) break ;
i - > accepts_cargo [ j ] = GetCargoTranslation ( GB ( res , 0 , 8 ) , indspec - > grf_prop . grffile ) ;
}
}
2007-11-19 21:02:30 +00:00
if ( HasBit ( indspec - > callback_flags , CBM_IND_OUTPUT_CARGO_TYPES ) ) {
2007-09-27 21:47:38 +00:00
for ( j = 0 ; j < lengthof ( i - > produced_cargo ) ; j + + ) i - > produced_cargo [ j ] = CT_INVALID ;
for ( j = 0 ; j < lengthof ( i - > produced_cargo ) ; j + + ) {
uint16 res = GetIndustryCallback ( CBID_INDUSTRY_OUTPUT_CARGO_TYPES , j , 0 , i , type , INVALID_TILE ) ;
if ( res = = CALLBACK_FAILED | | GB ( res , 0 , 8 ) = = CT_INVALID ) break ;
i - > produced_cargo [ j ] = GetCargoTranslation ( GB ( res , 0 , 8 ) , indspec - > grf_prop . grffile ) ;
}
}
2007-07-07 08:53:19 +00:00
i - > construction_date = _date ;
i - > construction_type = ( _game_mode = = GM_EDITOR ) ? ICT_SCENARIO_EDITOR :
( _generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY ) ;
2004-08-09 17:04:08 +00:00
2007-08-15 00:49:34 +00:00
/* Adding 1 here makes it conform to specs of var44 of varaction2 for industries
* 0 = created prior of newindustries
* else , chosen layout + 1 */
i - > selected_layout = layout + 1 ;
2007-06-07 14:38:45 +00:00
if ( ! _generating_world ) i - > last_month_production [ 0 ] = i - > last_month_production [ 1 ] = 0 ;
2004-09-11 09:55:19 +00:00
2008-02-09 03:03:09 +00:00
i - > prod_level = PRODLEVEL_DEFAULT ;
2004-08-09 17:04:08 +00:00
do {
2005-06-24 12:38:35 +00:00
TileIndex cur_tile = tile + ToTileIndexDiff ( it - > ti ) ;
2004-08-09 17:04:08 +00:00
2007-08-26 00:23:32 +00:00
if ( it - > gfx ! = GFX_WATERTILE_SPECIALCHECK ) {
2004-08-09 17:04:08 +00:00
byte size ;
2005-01-06 11:39:00 +00:00
size = it - > ti . x ;
2004-08-09 17:04:08 +00:00
if ( size > i - > width ) i - > width = size ;
2005-01-06 11:39:00 +00:00
size = it - > ti . y ;
2004-08-09 17:04:08 +00:00
if ( size > i - > height ) i - > height = size ;
2008-07-26 16:14:10 +00:00
WaterClass wc = ( IsWaterTile ( cur_tile ) ? GetWaterClass ( cur_tile ) : WATER_CLASS_INVALID ) ;
2009-02-11 20:09:29 +00:00
DoCommand ( cur_tile , 0 , 0 , DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING , CMD_LANDSCAPE_CLEAR ) ;
2004-08-09 17:04:08 +00:00
2008-07-26 16:14:10 +00:00
MakeIndustry ( cur_tile , i - > index , it - > gfx , Random ( ) , wc ) ;
2007-11-11 00:53:59 +00:00
2006-12-30 11:51:37 +00:00
if ( _generating_world ) {
SetIndustryConstructionCounter ( cur_tile , 3 ) ;
SetIndustryConstructionStage ( cur_tile , 2 ) ;
2007-11-11 18:22:06 +00:00
}
2008-01-16 15:06:48 +00:00
/* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */
IndustryGfx cur_gfx = GetTranslatedIndustryTileID ( it - > gfx ) ;
const IndustryTileSpec * its = GetIndustryTileSpec ( cur_gfx ) ;
if ( its - > animation_info ! = 0xFFFF ) AddAnimatedTile ( cur_tile ) ;
2004-08-09 17:04:08 +00:00
}
2005-01-06 11:39:00 +00:00
} while ( ( + + it ) - > ti . x ! = - 0x80 ) ;
2004-08-09 17:04:08 +00:00
i - > width + + ;
i - > height + + ;
2007-03-28 20:06:28 +00:00
if ( GetIndustrySpec ( i - > type ) - > behaviour & INDUSTRYBEH_PLANT_ON_BUILT ) {
2006-08-20 18:44:26 +00:00
for ( j = 0 ; j ! = 50 ; j + + ) PlantRandomFarmField ( i ) ;
2004-08-09 17:04:08 +00:00
}
2008-05-18 23:36:33 +00:00
InvalidateWindowData ( WC_INDUSTRY_DIRECTORY , 0 , 0 ) ;
2009-06-25 15:42:03 +00:00
Station : : RecomputeIndustriesNearForAll ( ) ;
2004-08-09 17:04:08 +00:00
}
2007-03-03 04:04:22 +00:00
/** Helper function for Build/Fund an industry
* @ param tile tile where industry is built
* @ param type of industry to build
* @ param flags of operations to conduct
* @ param indspec pointer to industry specifications
2007-07-09 13:21:49 +00:00
* @ param itspec_index the index of the itsepc to build / fund
2008-01-29 00:36:55 +00:00
* @ param seed random seed ( possibly ) used by industries
2009-02-11 20:09:29 +00:00
* @ param founder Founder of the industry
2007-03-03 04:04:22 +00:00
* @ return the pointer of the newly created industry , or NULL if it failed
*/
2009-02-11 20:09:29 +00:00
static Industry * CreateNewIndustryHelper ( TileIndex tile , IndustryType type , DoCommandFlag flags , const IndustrySpec * indspec , uint itspec_index , uint32 seed , Owner founder )
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
{
2007-07-09 13:21:49 +00:00
const IndustryTileTable * it = indspec - > table [ itspec_index ] ;
2007-07-09 18:53:43 +00:00
bool custom_shape_check = false ;
2007-10-02 16:56:45 +00:00
if ( ! CheckIfIndustryTilesAreFree ( tile , it , itspec_index , type , & custom_shape_check ) ) return NULL ;
2007-07-09 18:53:43 +00:00
2007-11-19 21:02:30 +00:00
if ( HasBit ( GetIndustrySpec ( type ) - > callback_flags , CBM_IND_LOCATION ) ) {
2008-01-29 00:36:55 +00:00
if ( ! CheckIfCallBackAllowsCreation ( tile , type , itspec_index , seed ) ) return NULL ;
2007-07-09 18:53:43 +00:00
} else {
if ( ! _check_new_industry_procs [ indspec - > check_proc ] ( tile ) ) return NULL ;
2007-07-09 13:21:49 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
2009-02-09 21:20:05 +00:00
if ( ! custom_shape_check & & _settings_game . game_creation . land_generator = = LG_TERRAGENESIS & & _generating_world & & ! _ignore_restrictions & & ! CheckIfCanLevelIndustryPlatform ( tile , DC_NONE , it , type ) ) return NULL ;
2008-01-09 18:35:18 +00:00
if ( ! CheckIfFarEnoughFromIndustry ( tile , type ) ) return NULL ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
2007-07-09 13:21:49 +00:00
const Town * t = CheckMultipleIndustryInTown ( tile , type ) ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
if ( t = = NULL ) return NULL ;
if ( ! CheckIfIndustryIsAllowed ( tile , type , t ) ) return NULL ;
2008-04-23 20:56:08 +00:00
if ( ! Industry : : CanAllocateItem ( ) ) return NULL ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
if ( flags & DC_EXEC ) {
2008-04-23 20:56:08 +00:00
Industry * i = new Industry ( tile ) ;
2007-07-09 18:53:43 +00:00
if ( ! custom_shape_check ) CheckIfCanLevelIndustryPlatform ( tile , DC_EXEC , it , type ) ;
2009-02-11 20:09:29 +00:00
DoCreateNewIndustry ( i , tile , type , it , itspec_index , t , OWNER_NONE , founder ) ;
2008-04-23 20:56:08 +00:00
return i ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
}
2008-04-23 20:56:08 +00:00
/* We need to return a non-NULL pointer to tell we have created an industry.
* However , we haven ' t created a real one ( no DC_EXEC ) , so return a fake one . */
2009-05-22 15:13:50 +00:00
return ( Industry * ) - 1 ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
}
2005-05-11 00:00:27 +00:00
/** Build/Fund an industry
2006-04-10 07:15:58 +00:00
* @ param tile tile where industry is built
2007-03-03 04:04:22 +00:00
* @ param flags of operations to conduct
2008-01-29 00:36:55 +00:00
* @ param p1 various bitstuffed elements
2009-09-04 20:04:54 +00:00
* - p1 = ( bit 0 - 7 ) - industry type see build_industry . h and see industry . h
* - p1 = ( bit 8 - 15 ) - first layout to try
2008-01-29 00:36:55 +00:00
* @ param p2 seed to use for variable 8F
2007-03-03 04:04:22 +00:00
* @ return index of the newly create industry , or CMD_ERROR if it failed
2005-05-11 00:00:27 +00:00
*/
2009-02-09 21:20:05 +00:00
CommandCost CmdBuildIndustry ( TileIndex tile , DoCommandFlag flags , uint32 p1 , uint32 p2 , const char * text )
2004-08-09 17:04:08 +00:00
{
2009-09-04 20:04:54 +00:00
IndustryType it = GB ( p1 , 0 , 8 ) ;
2009-09-04 20:02:35 +00:00
if ( it > = NUM_INDUSTRYTYPES ) return CMD_ERROR ;
const IndustrySpec * indspec = GetIndustrySpec ( it ) ;
2005-11-14 19:48:04 +00:00
2006-10-27 15:54:24 +00:00
/* Check if the to-be built/founded industry is available for this climate. */
2009-09-04 20:04:54 +00:00
if ( ! indspec - > enabled ) return CMD_ERROR ;
2004-08-09 17:04:08 +00:00
2009-02-08 12:25:13 +00:00
/* If the setting for raw-material industries is not on, you cannot build raw-material industries.
2007-07-06 22:33:16 +00:00
* Raw material industries are industries that do not accept cargo ( at least for now ) */
2008-05-29 15:13:28 +00:00
if ( _game_mode ! = GM_EDITOR & & _settings_game . construction . raw_industry_construction = = 0 & & indspec - > IsRawIndustry ( ) ) {
2005-11-14 15:22:12 +00:00
return CMD_ERROR ;
}
2004-08-09 17:04:08 +00:00
2009-09-04 20:04:54 +00:00
const Industry * ind = NULL ;
2008-05-29 15:13:28 +00:00
if ( _game_mode ! = GM_EDITOR & & _settings_game . construction . raw_industry_construction = = 2 & & indspec - > IsRawIndustry ( ) ) {
2007-07-06 07:24:10 +00:00
if ( flags & DC_EXEC ) {
2009-02-11 20:09:29 +00:00
/* 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 ;
2007-07-06 07:24:10 +00:00
/* 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 + + ) {
2007-12-28 16:21:29 +00:00
/* 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 ( ) ;
2009-09-04 20:04:54 +00:00
ind = CreateNewIndustryHelper ( tile , it , flags , indspec , RandomRange ( indspec - > num_table ) , p2 , founder ) ;
2007-07-08 18:41:34 +00:00
if ( ind ! = NULL ) {
break ;
}
2007-07-06 07:24:10 +00:00
}
}
2009-02-11 20:09:29 +00:00
_current_company = founder ;
2007-07-06 07:24:10 +00:00
}
} else {
2007-10-20 00:20:23 +00:00
int count = indspec - > num_table ;
const IndustryTileTable * const * itt = indspec - > table ;
2009-09-04 20:04:54 +00:00
int num = GB ( p1 , 8 , 8 ) ;
2009-09-04 20:02:35 +00:00
if ( num > = count ) return CMD_ERROR ;
2007-07-06 07:24:10 +00:00
2009-04-21 23:40:56 +00:00
_error_message = STR_ERROR_SITE_UNSUITABLE ;
2007-07-06 07:24:10 +00:00
do {
2007-10-20 00:20:23 +00:00
if ( - - count < 0 ) return CMD_ERROR ;
if ( - - num < 0 ) num = indspec - > num_table - 1 ;
2009-09-04 20:04:54 +00:00
} while ( ! CheckIfIndustryTilesAreFree ( tile , itt [ num ] , num , it ) ) ;
2004-08-09 17:04:08 +00:00
2009-09-04 20:04:54 +00:00
ind = CreateNewIndustryHelper ( tile , it , flags , indspec , num , p2 , _current_company ) ;
2008-07-28 23:37:19 +00:00
if ( ind = = NULL ) return CMD_ERROR ;
}
2009-06-01 11:43:36 +00:00
if ( ( flags & DC_EXEC ) & & _game_mode ! = GM_EDITOR & & ind ! = NULL ) {
2008-07-28 23:37:19 +00:00
SetDParam ( 0 , indspec - > name ) ;
if ( indspec - > new_industry_text > STR_LAST_STRINGID ) {
2009-07-20 11:21:57 +00:00
SetDParam ( 1 , STR_TOWN_NAME ) ;
2008-07-28 23:37:19 +00:00
SetDParam ( 2 , ind - > town - > index ) ;
} else {
SetDParam ( 1 , ind - > town - > index ) ;
}
2009-05-24 16:52:42 +00:00
AddIndustryNewsItem ( indspec - > new_industry_text , NS_INDUSTRY_OPEN , ind - > index ) ;
2009-01-12 17:11:45 +00:00
AI : : BroadcastNewEvent ( new AIEventIndustryOpen ( ind - > index ) ) ;
2007-07-06 07:24:10 +00:00
}
2004-09-11 09:55:19 +00:00
2008-01-09 16:55:48 +00:00
return CommandCost ( EXPENSES_OTHER , indspec - > GetConstructionCost ( ) ) ;
2004-08-09 17:04:08 +00:00
}
2009-02-12 18:08:47 +00:00
static Industry * CreateNewIndustry ( TileIndex tile , IndustryType type )
2004-08-09 17:04:08 +00:00
{
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
const IndustrySpec * indspec = GetIndustrySpec ( type ) ;
2004-09-11 09:55:19 +00:00
2008-01-29 00:36:55 +00:00
uint32 seed = Random ( ) ;
2009-02-11 20:09:29 +00:00
return CreateNewIndustryHelper ( tile , type , DC_EXEC , indspec , RandomRange ( indspec - > num_table ) , seed , OWNER_NONE ) ;
2004-08-09 17:04:08 +00:00
}
2007-07-27 03:07:05 +00:00
enum {
NB_NUMOFINDUSTRY = 11 ,
NB_DIFFICULTY_LEVEL = 5 ,
} ;
static const byte _numof_industry_table [ NB_DIFFICULTY_LEVEL ] [ NB_NUMOFINDUSTRY ] = {
2007-03-03 04:04:22 +00:00
/* difficulty settings for number of industries */
2009-03-15 00:32:18 +00:00
{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , // none
{ 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } , // very low
{ 0 , 1 , 1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 } , // low
{ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } , // normal
{ 0 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 , 10 , 10 } , // high
2004-08-09 17:04:08 +00:00
} ;
2007-04-09 01:43:29 +00:00
/** This function is the one who really do the creation work
* of random industries during game creation
* @ param type IndustryType of the desired industry
* @ param amount of industries that need to be built */
2006-04-26 21:10:01 +00:00
static void PlaceInitialIndustry ( IndustryType type , int amount )
2004-08-09 17:04:08 +00:00
{
2007-07-27 03:07:05 +00:00
/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
* _numof_industry_table . newgrf can specify a big amount */
2008-05-29 15:13:28 +00:00
int num = ( amount > NB_NUMOFINDUSTRY ) ? amount : _numof_industry_table [ _settings_game . difficulty . number_industries ] [ amount ] ;
2007-05-30 20:20:58 +00:00
const IndustrySpec * ind_spc = GetIndustrySpec ( type ) ;
2005-07-15 19:51:54 +00:00
2007-04-09 01:43:29 +00:00
/* These are always placed next to the coastline, so we scale by the perimeter instead. */
2007-05-30 20:20:58 +00:00
num = ( ind_spc - > check_proc = = CHECK_REFINERY | | ind_spc - > check_proc = = CHECK_OIL_RIG ) ? ScaleByMapSize1D ( num ) : ScaleByMapSize ( num ) ;
2004-08-22 15:56:56 +00:00
2008-05-29 15:13:28 +00:00
if ( _settings_game . difficulty . number_industries ! = 0 ) {
2008-09-30 20:39:50 +00:00
CompanyID old_company = _current_company ;
_current_company = OWNER_NONE ;
2004-08-15 22:17:46 +00:00
assert ( num > 0 ) ;
2004-08-09 17:04:08 +00:00
do {
2005-11-14 19:48:04 +00:00
uint i ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
IncreaseGeneratingWorldProgress ( GWP_INDUSTRY ) ;
2005-11-14 19:48:04 +00:00
for ( i = 0 ; i < 2000 ; i + + ) {
if ( CreateNewIndustry ( RandomTile ( ) , type ) ! = NULL ) break ;
}
2004-08-22 15:56:56 +00:00
} while ( - - num ) ;
2004-09-16 15:15:04 +00:00
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
2004-08-15 22:17:46 +00:00
}
2004-08-09 17:04:08 +00:00
}
2007-04-09 01:43:29 +00:00
/** This function will create ramdon industries during game creation.
* It will scale the amount of industries by map size as well as difficulty level */
2007-03-07 11:47:46 +00:00
void GenerateIndustries ( )
2004-08-09 17:04:08 +00:00
{
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
uint i = 0 ;
2007-04-09 01:43:29 +00:00
uint8 chance ;
IndustryType it ;
const IndustrySpec * ind_spc ;
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
/* Find the total amount of industries */
2008-05-29 15:13:28 +00:00
if ( _settings_game . difficulty . number_industries > 0 ) {
2007-07-24 19:56:43 +00:00
for ( it = 0 ; it < NUM_INDUSTRYTYPES ; it + + ) {
2007-07-15 00:26:12 +00:00
ind_spc = GetIndustrySpec ( it ) ;
if ( ! CheckIfCallBackAllowsAvailability ( it , IACT_MAPGENERATION ) ) {
ResetIndustryCreationProbility ( it ) ;
}
2007-04-09 01:43:29 +00:00
2008-05-29 15:13:28 +00:00
chance = ind_spc - > appear_creation [ _settings_game . game_creation . landscape ] ;
2007-07-15 00:45:02 +00:00
if ( ind_spc - > enabled & & chance > 0 ) {
2007-05-30 01:55:11 +00:00
/* once the chance of appearance is determind, it have to be scaled by
* the difficulty level . The " chance " in question is more an index into
* the _numof_industry_table , in fact */
2008-05-29 15:13:28 +00:00
int num = ( chance > NB_NUMOFINDUSTRY ) ? chance : _numof_industry_table [ _settings_game . difficulty . number_industries ] [ chance ] ;
2007-05-30 01:55:11 +00:00
/* These are always placed next to the coastline, so we scale by the perimeter instead. */
2007-05-30 20:20:58 +00:00
num = ( ind_spc - > check_proc = = CHECK_REFINERY | | ind_spc - > check_proc = = CHECK_OIL_RIG ) ? ScaleByMapSize1D ( num ) : ScaleByMapSize ( num ) ;
2007-05-30 01:55:11 +00:00
i + = num ;
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
}
2007-04-09 01:43:29 +00:00
}
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
SetGeneratingWorldProgress ( GWP_INDUSTRY , i ) ;
2004-08-09 17:04:08 +00:00
2008-05-29 15:13:28 +00:00
if ( _settings_game . difficulty . number_industries > 0 ) {
2007-07-24 19:56:43 +00:00
for ( it = 0 ; it < NUM_INDUSTRYTYPES ; it + + ) {
2007-07-15 00:26:12 +00:00
/* Once the number of industries has been determined, let's really create them.
* The test for chance allows us to try create industries that are available only
* for this landscape .
* @ todo : Do we really have to pass chance as un - scaled value , since we ' ve already
* processed that scaling above ? No , don ' t think so . Will find a way . */
ind_spc = GetIndustrySpec ( it ) ;
if ( ind_spc - > enabled ) {
2008-05-29 15:13:28 +00:00
chance = ind_spc - > appear_creation [ _settings_game . game_creation . landscape ] ;
2007-07-15 00:26:12 +00:00
if ( chance > 0 ) PlaceInitialIndustry ( it , chance ) ;
}
2007-05-30 01:55:11 +00:00
}
2007-07-15 00:26:12 +00:00
}
2004-08-09 17:04:08 +00:00
}
static void UpdateIndustryStatistics ( Industry * i )
{
byte pct ;
2007-04-16 02:53:55 +00:00
bool refresh = false ;
2007-05-18 00:33:47 +00:00
2007-09-27 21:39:13 +00:00
for ( byte j = 0 ; j < lengthof ( i - > produced_cargo ) ; j + + ) {
if ( i - > produced_cargo [ j ] ! = CT_INVALID ) {
2007-05-18 00:33:47 +00:00
pct = 0 ;
2007-06-07 14:38:45 +00:00
if ( i - > this_month_production [ j ] ! = 0 ) {
2007-05-18 00:33:47 +00:00
i - > last_prod_year = _cur_year ;
2007-06-07 14:38:45 +00:00
pct = min ( i - > this_month_transported [ j ] * 256 / i - > this_month_production [ j ] , 255 ) ;
2007-05-18 00:33:47 +00:00
}
2007-06-07 14:38:45 +00:00
i - > last_month_pct_transported [ j ] = pct ;
2004-08-09 17:04:08 +00:00
2007-06-07 14:38:45 +00:00
i - > last_month_production [ j ] = i - > this_month_production [ j ] ;
i - > this_month_production [ j ] = 0 ;
2004-08-09 17:04:08 +00:00
2007-06-07 14:38:45 +00:00
i - > last_month_transported [ j ] = i - > this_month_transported [ j ] ;
i - > this_month_transported [ j ] = 0 ;
2007-05-18 00:33:47 +00:00
refresh = true ;
2004-09-11 09:55:19 +00:00
}
2004-08-09 17:04:08 +00:00
}
2007-09-22 21:59:02 +00:00
if ( refresh ) InvalidateWindow ( WC_INDUSTRY_VIEW , i - > index ) ;
2004-08-09 17:04:08 +00:00
}
2007-04-06 02:12:15 +00:00
/** Simple helper that will collect data for the generation of industries */
struct ProbabilityHelper {
uint16 prob ; ///< probability
IndustryType ind ; ///< industry id correcponding
} ;
2007-04-04 00:32:40 +00:00
/**
* Try to create a random industry , during gameplay
*/
2009-05-21 22:43:25 +00:00
static void MaybeNewIndustry ( )
2007-04-04 00:32:40 +00:00
{
2009-03-15 00:32:18 +00:00
Industry * ind ; // will receive the industry's creation pointer
2007-04-04 00:32:40 +00:00
IndustryType rndtype , j ; // Loop controlers
const IndustrySpec * ind_spc ;
uint num = 0 ;
2007-04-19 14:50:01 +00:00
ProbabilityHelper cumulative_probs [ NUM_INDUSTRYTYPES ] ; // probability collector
2007-04-04 00:32:40 +00:00
uint16 probability_max = 0 ;
/* Generate a list of all possible industries that can be built. */
2007-04-19 14:50:01 +00:00
for ( j = 0 ; j < NUM_INDUSTRYTYPES ; j + + ) {
2007-11-03 23:34:12 +00:00
ind_spc = GetIndustrySpec ( j ) ;
2008-05-29 15:13:28 +00:00
byte chance = ind_spc - > appear_ingame [ _settings_game . game_creation . landscape ] ;
2007-11-03 23:34:12 +00:00
if ( ! ind_spc - > enabled | | chance = = 0 ) continue ;
2007-04-04 00:32:40 +00:00
2007-07-15 00:26:12 +00:00
/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
* and if appearing chance for this landscape is above 0 , this industry can be chosen */
2007-11-03 23:34:12 +00:00
if ( CheckIfCallBackAllowsAvailability ( j , IACT_RANDOMCREATION ) ) {
2007-04-04 00:32:40 +00:00
probability_max + = chance ;
2007-04-06 02:12:15 +00:00
/* adds the result for this industry */
cumulative_probs [ num ] . ind = j ;
cumulative_probs [ num + + ] . prob = probability_max ;
2007-04-04 00:32:40 +00:00
}
}
2004-08-09 17:04:08 +00:00
2009-04-11 14:54:03 +00:00
/* Abort if there is no industry buildable */
if ( probability_max = = 0 ) return ;
2007-04-06 02:12:15 +00:00
/* Find a random type, with maximum being what has been evaluate above*/
2007-04-04 00:32:40 +00:00
rndtype = RandomRange ( probability_max ) ;
2007-04-19 14:50:01 +00:00
for ( j = 0 ; j < NUM_INDUSTRYTYPES ; j + + ) {
2007-04-06 02:12:15 +00:00
/* and choose the index of the industry that matches as close as possible this random type */
if ( cumulative_probs [ j ] . prob > = rndtype ) break ;
2007-04-04 00:32:40 +00:00
}
2004-08-09 17:04:08 +00:00
2007-04-06 02:12:15 +00:00
ind_spc = GetIndustrySpec ( cumulative_probs [ j ] . ind ) ;
2007-04-04 00:32:40 +00:00
/* Check if it is allowed */
2007-03-28 20:06:28 +00:00
if ( ( ind_spc - > behaviour & INDUSTRYBEH_BEFORE_1950 ) & & _cur_year > 1950 ) return ;
if ( ( ind_spc - > behaviour & INDUSTRYBEH_AFTER_1960 ) & & _cur_year < 1960 ) return ;
2004-08-09 17:04:08 +00:00
2007-04-06 02:12:15 +00:00
/* try to create 2000 times this industry */
2007-04-04 00:32:40 +00:00
num = 2000 ;
2005-11-14 19:48:04 +00:00
for ( ; ; ) {
2007-04-06 02:12:15 +00:00
ind = CreateNewIndustry ( RandomTile ( ) , cumulative_probs [ j ] . ind ) ;
2007-04-04 00:32:40 +00:00
if ( ind ! = NULL ) break ;
if ( - - num = = 0 ) return ;
2004-08-09 17:04:08 +00:00
}
2007-03-09 02:04:07 +00:00
SetDParam ( 0 , ind_spc - > name ) ;
2007-10-18 20:35:59 +00:00
if ( ind_spc - > new_industry_text > STR_LAST_STRINGID ) {
2009-07-20 11:21:57 +00:00
SetDParam ( 1 , STR_TOWN_NAME ) ;
2007-10-18 20:35:59 +00:00
SetDParam ( 2 , ind - > town - > index ) ;
} else {
SetDParam ( 1 , ind - > town - > index ) ;
}
2009-05-24 16:52:42 +00:00
AddIndustryNewsItem ( ind_spc - > new_industry_text , NS_INDUSTRY_OPEN , ind - > index ) ;
2009-01-12 17:11:45 +00:00
AI : : BroadcastNewEvent ( new AIEventIndustryOpen ( ind - > index ) ) ;
2004-08-09 17:04:08 +00:00
}
2007-09-22 21:59:02 +00:00
/**
* Protects an industry from closure if the appropriate flags and conditions are met
* INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set ( which , by default , it is not ) and the
* count of industries of this type must one ( or lower ) in order to be protected
* against closure .
* @ param type IndustryType been queried
* @ result true if protection is on , false otherwise ( except for oil wells )
*/
static bool CheckIndustryCloseDownProtection ( IndustryType type )
2004-08-09 17:04:08 +00:00
{
2006-04-26 21:10:01 +00:00
const IndustrySpec * indspec = GetIndustrySpec ( type ) ;
2004-09-11 09:55:19 +00:00
2007-09-22 21:59:02 +00:00
/* oil wells (or the industries with that flag set) are always allowed to closedown */
2009-06-01 11:43:36 +00:00
if ( ( indspec - > behaviour & INDUSTRYBEH_DONT_INCR_PROD ) & & _settings_game . game_creation . landscape = = LT_TEMPERATE ) return false ;
2007-11-03 15:21:26 +00:00
return ( indspec - > behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE ) = = 0 & & GetIndustryTypeCount ( type ) < = 1 ;
2007-09-22 21:59:02 +00:00
}
2007-11-15 22:20:33 +00:00
/**
2009-03-14 18:16:29 +00:00
* Can given cargo type be accepted or produced by the industry ?
* @ param cargo : Cargo type
* @ param ind : Industry
* @ param * c_accepts : Pointer to boolean for acceptance of cargo
* @ param * c_produces : Pointer to boolean for production of cargo
* @ return : \ c * c_accepts is set when industry accepts the cargo type ,
* \ c * c_produces is set when the industry produces the cargo type
*/
2007-11-15 22:20:33 +00:00
static void CanCargoServiceIndustry ( CargoID cargo , Industry * ind , bool * c_accepts , bool * c_produces )
{
const IndustrySpec * indspec = GetIndustrySpec ( ind - > type ) ;
/* Check for acceptance of cargo */
2008-05-01 22:51:53 +00:00
for ( byte j = 0 ; j < lengthof ( ind - > accepts_cargo ) ; j + + ) {
if ( ind - > accepts_cargo [ j ] = = CT_INVALID ) continue ;
2007-11-15 22:20:33 +00:00
if ( cargo = = ind - > accepts_cargo [ j ] ) {
2007-11-19 21:02:30 +00:00
if ( HasBit ( indspec - > callback_flags , CBM_IND_REFUSE_CARGO ) ) {
2007-11-15 22:20:33 +00:00
uint16 res = GetIndustryCallback ( CBID_INDUSTRY_REFUSE_CARGO ,
0 , GetReverseCargoTranslation ( cargo , indspec - > grf_prop . grffile ) ,
ind , ind - > type , ind - > xy ) ;
if ( res = = 0 ) continue ;
}
* c_accepts = true ;
break ;
}
}
/* Check for produced cargo */
2008-05-01 22:51:53 +00:00
for ( byte j = 0 ; j < lengthof ( ind - > produced_cargo ) ; j + + ) {
if ( ind - > produced_cargo [ j ] = = CT_INVALID ) continue ;
2007-11-15 22:20:33 +00:00
if ( cargo = = ind - > produced_cargo [ j ] ) {
* c_produces = true ;
break ;
}
}
}
/**
2009-03-14 18:16:29 +00:00
* Compute who can service the industry .
*
* Here , ' can service ' means that he / she has trains and stations close enough
* to the industry with the right cargo type and the right orders ( ie has the
* technical means ) .
*
* @ param ind : Industry being investigated .
*
* @ return : 0 if nobody can service the industry , 2 if the local company can
* service the industry , and 1 otherwise ( only competitors can service the
* industry )
*/
2009-01-10 00:31:47 +00:00
int WhoCanServiceIndustry ( Industry * ind )
2007-11-15 22:20:33 +00:00
{
/* Find all stations within reach of the industry */
2009-01-13 20:43:53 +00:00
StationList stations ;
FindStationsAroundTiles ( ind - > xy , ind - > width , ind - > height , & stations ) ;
2007-11-15 22:20:33 +00:00
2009-01-13 18:18:53 +00:00
if ( stations . Length ( ) = = 0 ) return 0 ; // No stations found at all => nobody services
2007-11-15 22:20:33 +00:00
const Vehicle * v ;
int result = 0 ;
FOR_ALL_VEHICLES ( v ) {
/* Is it worthwhile to try this vehicle? */
2008-09-30 20:39:50 +00:00
if ( v - > owner ! = _local_company & & result ! = 0 ) continue ;
2007-11-15 22:20:33 +00:00
/* Check whether it accepts the right kind of cargo */
bool c_accepts = false ;
bool c_produces = false ;
2009-07-01 22:22:01 +00:00
if ( v - > type = = VEH_TRAIN & & Train : : From ( v ) - > IsFrontEngine ( ) ) {
2008-05-21 12:06:05 +00:00
for ( const Vehicle * u = v ; u ! = NULL ; u = u - > Next ( ) ) {
2007-11-15 22:20:33 +00:00
CanCargoServiceIndustry ( u - > cargo_type , ind , & c_accepts , & c_produces ) ;
2008-05-21 12:06:05 +00:00
}
2007-11-15 22:20:33 +00:00
} else if ( v - > type = = VEH_ROAD | | v - > type = = VEH_SHIP | | v - > type = = VEH_AIRCRAFT ) {
CanCargoServiceIndustry ( v - > cargo_type , ind , & c_accepts , & c_produces ) ;
} else {
continue ;
}
if ( ! c_accepts & & ! c_produces ) continue ; // Wrong cargo
/* Check orders of the vehicle.
* We cannot check the first of shared orders only , since the first vehicle in such a chain
* may have a different cargo type .
*/
const Order * o ;
FOR_VEHICLE_ORDERS ( v , o ) {
2008-04-07 20:03:46 +00:00
if ( o - > IsType ( OT_GOTO_STATION ) & & ! ( o - > GetUnloadType ( ) & OUFB_TRANSFER ) ) {
2007-11-15 22:20:33 +00:00
/* Vehicle visits a station to load or unload */
2009-05-16 23:34:14 +00:00
Station * st = Station : : Get ( o - > GetDestination ( ) ) ;
2009-05-22 15:13:50 +00:00
assert ( st ! = NULL ) ;
2007-11-15 22:20:33 +00:00
/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
2008-04-07 20:03:46 +00:00
if ( ( o - > GetUnloadType ( ) & OUFB_UNLOAD ) & & ! c_accepts ) break ;
2007-11-15 22:20:33 +00:00
2009-01-13 18:18:53 +00:00
if ( stations . Contains ( st ) ) {
2008-09-30 20:39:50 +00:00
if ( v - > owner = = _local_company ) return 2 ; // Company services industry
2007-11-15 22:20:33 +00:00
result = 1 ; // Competitor services industry
}
}
}
}
return result ;
}
/**
2009-03-14 18:16:29 +00:00
* Report news that industry production has changed significantly
*
* @ param ind : Industry with changed production
* @ param type : Cargo type that has changed
* @ param percent : Percentage of change ( > 0 means increase , < 0 means decrease )
*/
2007-11-15 22:20:33 +00:00
static void ReportNewsProductionChangeIndustry ( Industry * ind , CargoID type , int percent )
{
2008-05-15 13:39:36 +00:00
NewsSubtype ns ;
2007-11-15 22:20:33 +00:00
switch ( WhoCanServiceIndustry ( ind ) ) {
2008-09-30 20:39:50 +00:00
case 0 : ns = NS_INDUSTRY_NOBODY ; break ;
case 1 : ns = NS_INDUSTRY_OTHER ; break ;
case 2 : ns = NS_INDUSTRY_COMPANY ; break ;
2009-05-26 15:46:24 +00:00
default : NOT_REACHED ( ) ;
2007-11-15 22:20:33 +00:00
}
SetDParam ( 2 , abs ( percent ) ) ;
2009-07-16 19:00:13 +00:00
SetDParam ( 0 , CargoSpec : : Get ( type ) - > name ) ;
2007-11-15 22:20:33 +00:00
SetDParam ( 1 , ind - > index ) ;
2009-05-24 16:52:42 +00:00
AddIndustryNewsItem (
2009-04-21 23:40:56 +00:00
percent > = 0 ? STR_NEWS_INDUSTRY_PRODUCTION_INCREASE_SMOOTH : STR_NEWS_INDUSTRY_PRODUCTION_DECREASE_SMOOTH ,
2008-05-15 13:39:36 +00:00
ns ,
2009-05-24 16:52:42 +00:00
ind - > index
2007-11-15 22:20:33 +00:00
) ;
}
2007-11-23 12:12:07 +00:00
enum {
PERCENT_TRANSPORTED_60 = 153 ,
2008-01-06 01:06:12 +00:00
PERCENT_TRANSPORTED_80 = 204 ,
2007-11-23 12:12:07 +00:00
} ;
2007-09-22 21:59:02 +00:00
/** Change industry production or do closure
* @ param i Industry for which changes are performed
* @ param monthly true if it ' s the monthly call , false if it ' s the random call
*/
static void ChangeIndustryProduction ( Industry * i , bool monthly )
{
StringID str = STR_NULL ;
bool closeit = false ;
const IndustrySpec * indspec = GetIndustrySpec ( i - > type ) ;
2009-01-17 14:49:31 +00:00
bool standard = false ;
2007-09-22 23:40:35 +00:00
bool suppress_message = false ;
2009-01-16 11:32:35 +00:00
bool recalculate_multipliers = false ; ///< reinitialize production_rate to match prod_level
2007-11-23 16:50:54 +00:00
/* don't use smooth economy for industries using production related callbacks */
2008-05-29 15:13:28 +00:00
bool smooth_economy = _settings_game . economy . smooth_economy & &
2007-11-23 16:50:54 +00:00
! ( HasBit ( indspec - > callback_flags , CBM_IND_PRODUCTION_256_TICKS ) | | HasBit ( indspec - > callback_flags , CBM_IND_PRODUCTION_CARGO_ARRIVAL ) ) & & // production callbacks
! ( HasBit ( indspec - > callback_flags , CBM_IND_MONTHLYPROD_CHANGE ) | | HasBit ( indspec - > callback_flags , CBM_IND_PRODUCTION_CHANGE ) ) ; // production change callbacks
2007-09-22 23:40:35 +00:00
byte div = 0 ;
byte mul = 0 ;
2007-11-27 04:16:08 +00:00
int8 increment = 0 ;
2007-09-22 23:40:35 +00:00
2009-01-17 14:49:31 +00:00
bool callback_enabled = HasBit ( indspec - > callback_flags , monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE ) ;
if ( callback_enabled ) {
2007-09-22 23:40:35 +00:00
uint16 res = GetIndustryCallback ( monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE , 0 , Random ( ) , i , i - > type , i - > xy ) ;
2009-01-17 14:49:31 +00:00
if ( res ! = CALLBACK_FAILED ) { // failed callback means "do nothing"
2007-11-19 21:02:30 +00:00
suppress_message = HasBit ( res , 7 ) ;
2007-09-22 23:40:35 +00:00
/* Get the custom message if any */
2007-11-19 21:02:30 +00:00
if ( HasBit ( res , 8 ) ) str = MapGRFStringID ( indspec - > grf_prop . grffile - > grfid , GB ( GetRegister ( 0x100 ) , 0 , 16 ) ) ;
2007-09-22 23:40:35 +00:00
res = GB ( res , 0 , 4 ) ;
2009-08-09 14:40:34 +00:00
switch ( res ) {
2007-09-22 23:40:35 +00:00
default : NOT_REACHED ( ) ;
case 0x0 : break ; // Do nothing, but show the custom message if any
case 0x1 : div = 1 ; break ; // Halve industry production. If production reaches the quarter of the default, the industry is closed instead.
case 0x2 : mul = 1 ; break ; // Double industry production if it hasn't reached eight times of the original yet.
case 0x3 : closeit = true ; break ; // The industry announces imminent closure, and is physically removed from the map next month.
case 0x4 : standard = true ; break ; // Do the standard random production change as if this industry was a primary one.
case 0x5 : case 0x6 : case 0x7 : // Divide production by 4, 8, 16
2007-11-23 04:17:41 +00:00
case 0x8 : div = res - 0x3 ; break ; // Divide production by 32
2007-09-22 23:40:35 +00:00
case 0x9 : case 0xA : case 0xB : // Multiply production by 4, 8, 16
2007-11-23 04:17:41 +00:00
case 0xC : mul = res - 0x7 ; break ; // Multiply production by 32
2007-11-27 04:16:08 +00:00
case 0xD : // decrement production
case 0xE : // increment production
increment = res = = 0x0D ? - 1 : 1 ;
break ;
2008-11-03 20:23:51 +00:00
case 0xF : // Set production to third byte of register 0x100
i - > prod_level = Clamp ( GB ( GetRegister ( 0x100 ) , 16 , 8 ) , PRODLEVEL_MINIMUM , PRODLEVEL_MAXIMUM ) ;
2009-01-16 11:32:35 +00:00
recalculate_multipliers = true ;
2008-11-03 19:25:52 +00:00
break ;
2007-09-22 23:40:35 +00:00
}
}
2009-01-17 14:49:31 +00:00
} else {
if ( monthly ! = smooth_economy ) return ;
if ( indspec - > life_type = = INDUSTRYLIFE_BLACK_HOLE ) return ;
2007-09-22 23:40:35 +00:00
}
2007-09-22 21:59:02 +00:00
2009-01-17 14:49:31 +00:00
if ( standard | | ( ! callback_enabled & & ( indspec - > life_type & ( INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE ) ) ! = 0 ) ) {
2007-07-03 19:16:34 +00:00
/* decrease or increase */
2008-05-29 15:13:28 +00:00
bool only_decrease = ( indspec - > behaviour & INDUSTRYBEH_DONT_INCR_PROD ) & & _settings_game . game_creation . landscape = = LT_TEMPERATE ;
2004-08-09 17:04:08 +00:00
2007-10-05 17:53:45 +00:00
if ( smooth_economy ) {
2007-09-22 21:59:02 +00:00
closeit = true ;
2008-05-01 22:51:53 +00:00
for ( byte j = 0 ; j < lengthof ( i - > produced_cargo ) ; j + + ) {
if ( i - > produced_cargo [ j ] = = CT_INVALID ) continue ;
2008-01-06 01:06:12 +00:00
uint32 r = Random ( ) ;
2007-09-22 21:59:02 +00:00
int old_prod , new_prod , percent ;
2008-01-06 01:06:12 +00:00
/* If over 60% is transported, mult is 1, else mult is -1. */
2007-11-23 12:12:07 +00:00
int mult = ( i - > last_month_pct_transported [ j ] > PERCENT_TRANSPORTED_60 ) ? 1 : - 1 ;
2004-09-11 09:55:19 +00:00
2007-09-22 21:59:02 +00:00
new_prod = old_prod = i - > production_rate [ j ] ;
2004-09-11 09:55:19 +00:00
2008-01-06 01:06:12 +00:00
/* For industries with only_decrease flags (temperate terrain Oil Wells),
* the multiplier will always be - 1 so they will only decrease . */
2007-11-26 19:23:53 +00:00
if ( only_decrease ) {
mult = - 1 ;
2008-01-06 01:06:12 +00:00
/* For normal industries, if over 60% is transported, 33% chance for decrease.
* Bonus for very high station ratings ( over 80 % ) : 16 % chance for decrease . */
} else if ( Chance16I ( 1 , ( ( i - > last_month_pct_transported [ j ] > PERCENT_TRANSPORTED_80 ) ? 6 : 3 ) , r ) ) {
2007-11-26 19:23:53 +00:00
mult * = - 1 ;
}
2007-11-23 12:12:07 +00:00
2008-01-06 01:06:12 +00:00
/* 4.5% chance for 3-23% (or 1 unit for very low productions) production change,
* determined by mult value . If mult = 1 prod . increases , else ( - 1 ) it decreases . */
if ( Chance16I ( 1 , 22 , r > > 16 ) ) {
2007-11-23 12:12:07 +00:00
new_prod + = mult * ( max ( ( ( RandomRange ( 50 ) + 10 ) * old_prod ) > > 8 , 1U ) ) ;
2007-09-22 21:59:02 +00:00
}
2004-08-09 17:04:08 +00:00
2007-11-23 12:12:07 +00:00
/* Prevent production to overflow or Oil Rig passengers to be over-"produced" */
2007-11-19 18:38:10 +00:00
new_prod = Clamp ( new_prod , 1 , 255 ) ;
2007-11-23 12:12:07 +00:00
if ( ( ( indspec - > behaviour & INDUSTRYBEH_BUILT_ONWATER ) ! = 0 ) & & j = = 1 )
new_prod = Clamp ( new_prod , 0 , 16 ) ;
2007-09-22 21:59:02 +00:00
/* Do not stop closing the industry when it has the lowest possible production rate */
if ( new_prod = = old_prod & & old_prod > 1 ) {
closeit = false ;
continue ;
}
2004-08-09 17:04:08 +00:00
2007-09-22 21:59:02 +00:00
percent = ( old_prod = = 0 ) ? 100 : ( new_prod * 100 / old_prod - 100 ) ;
i - > production_rate [ j ] = new_prod ;
/* Close the industry when it has the lowest possible production rate */
if ( new_prod > 1 ) closeit = false ;
2007-11-15 22:20:33 +00:00
if ( abs ( percent ) > = 10 ) {
ReportNewsProductionChangeIndustry ( i , i - > produced_cargo [ j ] , percent ) ;
2007-07-03 19:16:34 +00:00
}
2007-09-22 21:59:02 +00:00
}
} else {
2007-11-25 15:35:25 +00:00
if ( only_decrease | | Chance16 ( 1 , 3 ) ) {
2008-01-06 01:06:12 +00:00
/* If more than 60% transported, 66% chance of increase, else 33% chance of increase */
2007-11-25 15:35:25 +00:00
if ( ! only_decrease & & ( i - > last_month_pct_transported [ 0 ] > PERCENT_TRANSPORTED_60 ) ! = Chance16 ( 1 , 3 ) ) {
2007-09-22 23:40:35 +00:00
mul = 1 ; // Increase production
2005-02-06 15:07:29 +00:00
} else {
2007-09-22 23:40:35 +00:00
div = 1 ; // Decrease production
2005-02-06 15:07:29 +00:00
}
2004-08-09 17:04:08 +00:00
}
2007-07-03 19:16:34 +00:00
}
}
2007-09-22 21:59:02 +00:00
2009-06-01 11:43:36 +00:00
if ( ! callback_enabled & & ( indspec - > life_type & INDUSTRYLIFE_PROCESSING ) ) {
2007-11-25 15:35:25 +00:00
if ( ( byte ) ( _cur_year - i - > last_prod_year ) > = 5 & & Chance16 ( 1 , smooth_economy ? 180 : 2 ) ) {
2007-09-22 21:59:02 +00:00
closeit = true ;
2007-07-03 19:16:34 +00:00
}
2005-02-06 15:07:29 +00:00
}
2007-09-22 23:40:35 +00:00
/* Increase if needed */
2008-02-09 03:03:09 +00:00
while ( mul - - ! = 0 & & i - > prod_level < PRODLEVEL_MAXIMUM ) {
2008-02-09 03:12:05 +00:00
i - > prod_level = min ( i - > prod_level * 2 , PRODLEVEL_MAXIMUM ) ;
2009-01-16 11:32:35 +00:00
recalculate_multipliers = true ;
2007-09-22 23:40:35 +00:00
if ( str = = STR_NULL ) str = indspec - > production_up_text ;
}
/* Decrease if needed */
while ( div - - ! = 0 & & ! closeit ) {
2008-02-09 03:03:09 +00:00
if ( i - > prod_level = = PRODLEVEL_MINIMUM ) {
2007-09-22 23:40:35 +00:00
closeit = true ;
} else {
2008-02-09 03:12:05 +00:00
i - > prod_level = max ( i - > prod_level / 2 , ( int ) PRODLEVEL_MINIMUM ) ; // typecast to int required to please MSVC
2009-01-16 11:32:35 +00:00
recalculate_multipliers = true ;
2007-09-22 23:40:35 +00:00
if ( str = = STR_NULL ) str = indspec - > production_down_text ;
}
}
2008-01-24 18:16:04 +00:00
/* Increase or Decreasing the production level if needed */
2007-11-27 04:16:08 +00:00
if ( increment ! = 0 ) {
2008-02-09 03:03:09 +00:00
if ( increment < 0 & & i - > prod_level = = PRODLEVEL_MINIMUM ) {
2008-01-24 18:16:04 +00:00
closeit = true ;
} else {
2008-02-09 03:03:09 +00:00
i - > prod_level = ClampU ( i - > prod_level + increment , PRODLEVEL_MINIMUM , PRODLEVEL_MAXIMUM ) ;
2009-01-16 11:32:35 +00:00
recalculate_multipliers = true ;
2008-01-24 18:16:04 +00:00
}
2007-11-27 04:16:08 +00:00
}
2009-01-16 11:32:35 +00:00
/* Recalculate production_rate
* For non - smooth economy these should always be synchronized with prod_level */
if ( recalculate_multipliers ) {
2009-03-29 11:41:42 +00:00
/* Rates are rounded up, so e.g. oilrig always produces some passengers */
i - > production_rate [ 0 ] = min ( ( indspec - > production_rate [ 0 ] * i - > prod_level + PRODLEVEL_DEFAULT - 1 ) / PRODLEVEL_DEFAULT , 0xFF ) ;
i - > production_rate [ 1 ] = min ( ( indspec - > production_rate [ 1 ] * i - > prod_level + PRODLEVEL_DEFAULT - 1 ) / PRODLEVEL_DEFAULT , 0xFF ) ;
2009-01-16 11:32:35 +00:00
}
2007-09-22 21:59:02 +00:00
/* Close if needed and allowed */
if ( closeit & & ! CheckIndustryCloseDownProtection ( i - > type ) ) {
2008-02-09 03:03:09 +00:00
i - > prod_level = PRODLEVEL_CLOSURE ;
2007-09-22 21:59:02 +00:00
str = indspec - > closure_text ;
}
2007-09-22 23:40:35 +00:00
if ( ! suppress_message & & str ! = STR_NULL ) {
2008-05-15 13:39:36 +00:00
NewsSubtype ns ;
2007-11-15 22:20:33 +00:00
/* Compute news category */
if ( closeit ) {
2008-07-30 01:53:03 +00:00
ns = NS_INDUSTRY_CLOSE ;
2009-01-12 17:11:45 +00:00
AI : : BroadcastNewEvent ( new AIEventIndustryClose ( i - > index ) ) ;
2007-11-15 22:20:33 +00:00
} else {
switch ( WhoCanServiceIndustry ( i ) ) {
2008-09-30 20:39:50 +00:00
case 0 : ns = NS_INDUSTRY_NOBODY ; break ;
case 1 : ns = NS_INDUSTRY_OTHER ; break ;
case 2 : ns = NS_INDUSTRY_COMPANY ; break ;
2009-05-26 15:46:24 +00:00
default : NOT_REACHED ( ) ;
2007-11-15 22:20:33 +00:00
}
}
/* Set parameters of news string */
2007-10-18 20:35:59 +00:00
if ( str > STR_LAST_STRINGID ) {
2009-07-20 11:21:57 +00:00
SetDParam ( 0 , STR_TOWN_NAME ) ;
2007-10-18 20:35:59 +00:00
SetDParam ( 1 , i - > town - > index ) ;
SetDParam ( 2 , indspec - > name ) ;
2007-11-12 18:32:04 +00:00
} else if ( closeit ) {
2009-07-20 11:21:57 +00:00
SetDParam ( 0 , STR_FORMAT_INDUSTRY_NAME ) ;
2007-11-12 18:32:04 +00:00
SetDParam ( 1 , i - > town - > index ) ;
SetDParam ( 2 , indspec - > name ) ;
2007-10-18 20:35:59 +00:00
} else {
SetDParam ( 0 , i - > index ) ;
}
2007-11-15 22:20:33 +00:00
/* and report the news to the user */
2007-09-22 21:59:02 +00:00
AddNewsItem ( str ,
2008-05-15 13:39:36 +00:00
ns ,
2009-05-24 16:52:42 +00:00
closeit ? NR_TILE : NR_INDUSTRY ,
closeit ? i - > xy + TileDiffXY ( 1 , 1 ) : i - > index ) ;
2004-08-09 17:04:08 +00:00
}
}
2008-09-15 17:18:22 +00:00
/** Daily handler for the industry changes
* Taking the original map size of 256 * 256 , the number of random changes was always of just one unit .
* But it cannot be the same on smaller or bigger maps . That number has to be scaled up or down .
* For small maps , it implies that less than one change per month is required , while on bigger maps ,
* it would be way more . The daily loop handles those changes . */
void IndustryDailyLoop ( )
{
_economy . industry_daily_change_counter + = _economy . industry_daily_increment ;
/* Bits 16-31 of industry_construction_counter contain the number of industries to change/create today,
* the lower 16 bit are a fractional part that might accumulate over several days until it
* is sufficient for an industry . */
uint16 change_loop = _economy . industry_daily_change_counter > > 16 ;
/* Reset the active part of the counter, just keeping the "factional part" */
_economy . industry_daily_change_counter & = 0xFFFF ;
if ( change_loop = = 0 ) {
return ; // Nothing to do? get out
}
2008-09-30 20:39:50 +00:00
CompanyID old_company = _current_company ;
_current_company = OWNER_NONE ;
2008-09-15 17:18:22 +00:00
/* perform the required industry changes for the day */
for ( uint16 j = 0 ; j < change_loop ; j + + ) {
/* 3% chance that we start a new industry */
if ( Chance16 ( 3 , 100 ) ) {
MaybeNewIndustry ( ) ;
} else {
2009-06-26 15:08:54 +00:00
Industry * i = Industry : : GetRandom ( ) ;
2008-09-15 17:18:22 +00:00
if ( i ! = NULL ) ChangeIndustryProduction ( i , false ) ;
}
}
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
2008-09-15 17:18:22 +00:00
/* production-change */
InvalidateWindowData ( WC_INDUSTRY_DIRECTORY , 0 , 1 ) ;
}
2007-03-07 11:47:46 +00:00
void IndustryMonthlyLoop ( )
2004-08-09 17:04:08 +00:00
{
Industry * i ;
2008-09-30 20:39:50 +00:00
CompanyID old_company = _current_company ;
_current_company = OWNER_NONE ;
2004-08-09 17:04:08 +00:00
2004-12-30 10:03:35 +00:00
FOR_ALL_INDUSTRIES ( i ) {
2006-08-22 15:33:35 +00:00
UpdateIndustryStatistics ( i ) ;
2008-02-09 03:03:09 +00:00
if ( i - > prod_level = = PRODLEVEL_CLOSURE ) {
2007-09-22 21:59:02 +00:00
delete i ;
} else {
ChangeIndustryProduction ( i , true ) ;
}
2004-08-09 17:04:08 +00:00
}
2008-09-30 20:39:50 +00:00
_current_company = old_company ;
2004-09-16 15:15:04 +00:00
2007-03-03 04:04:22 +00:00
/* production-change */
2008-05-18 23:36:33 +00:00
InvalidateWindowData ( WC_INDUSTRY_DIRECTORY , 0 , 1 ) ;
2004-08-09 17:04:08 +00:00
}
2007-03-07 11:47:46 +00:00
void InitializeIndustries ( )
2004-08-09 17:04:08 +00:00
{
2009-05-22 15:13:50 +00:00
_industry_pool . CleanPool ( ) ;
2005-01-06 22:31:58 +00:00
2007-06-10 01:25:21 +00:00
ResetIndustryCounts ( ) ;
2006-09-10 08:28:32 +00:00
_industry_sound_tile = 0 ;
2004-08-09 17:04:08 +00:00
}
2007-07-06 22:33:16 +00:00
bool IndustrySpec : : IsRawIndustry ( ) const
{
/* Lumber mills are extractive/organic, but can always be built like a non-raw industry */
return ( this - > life_type & ( INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC ) ) ! = 0 & &
( this - > behaviour & INDUSTRYBEH_CUT_TREES ) = = 0 ;
}
Money IndustrySpec : : GetConstructionCost ( ) const
{
return ( _price . build_industry *
2008-05-29 15:13:28 +00:00
( _settings_game . construction . raw_industry_construction = = 1 & & this - > IsRawIndustry ( ) ?
2007-07-06 22:33:16 +00:00
this - > raw_industry_cost_multiplier :
this - > cost_multiplier
) ) > > 8 ;
}
2007-11-27 17:13:49 +00:00
Money IndustrySpec : : GetRemovalCost ( ) const
{
return ( _price . remove_house * this - > removal_cost_multiplier ) > > 8 ;
}
2007-07-06 22:33:16 +00:00
2009-02-09 21:20:05 +00:00
static CommandCost TerraformTile_Industry ( TileIndex tile , DoCommandFlag flags , uint z_new , Slope tileh_new )
2007-08-30 17:17:04 +00:00
{
2007-09-14 22:27:40 +00:00
if ( AutoslopeEnabled ( ) ) {
/* We imitate here TTDP's behaviour:
* - Both new and old slope must not be steep .
* - TileMaxZ must not be changed .
* - Allow autoslope by default .
* - Disallow autoslope if callback succeeds and returns non - zero .
*/
Slope tileh_old = GetTileSlope ( tile , NULL ) ;
/* TileMaxZ must not be changed. Slopes must not be steep. */
if ( ! IsSteepSlope ( tileh_old ) & & ! IsSteepSlope ( tileh_new ) & & ( GetTileMaxZ ( tile ) = = z_new + GetSlopeMaxZ ( tileh_new ) ) ) {
const IndustryGfx gfx = GetIndustryGfx ( tile ) ;
const IndustryTileSpec * itspec = GetIndustryTileSpec ( gfx ) ;
/* Call callback 3C 'disable autosloping for industry tiles'. */
2007-11-19 21:02:30 +00:00
if ( HasBit ( itspec - > callback_flags , CBM_INDT_AUTOSLOPE ) ) {
2007-09-14 22:27:40 +00:00
/* If the callback fails, allow autoslope. */
2009-08-30 11:47:41 +00:00
uint16 res = GetIndustryTileCallback ( CBID_INDUSTRY_AUTOSLOPE , 0 , 0 , gfx , Industry : : GetByTile ( tile ) , tile ) ;
2008-01-09 16:55:48 +00:00
if ( ( res = = 0 ) | | ( res = = CALLBACK_FAILED ) ) return CommandCost ( EXPENSES_CONSTRUCTION , _price . terraform ) ;
2007-09-14 22:27:40 +00:00
} else {
2007-11-15 22:20:33 +00:00
/* allow autoslope */
2008-01-09 16:55:48 +00:00
return CommandCost ( EXPENSES_CONSTRUCTION , _price . terraform ) ;
2007-09-14 22:27:40 +00:00
}
}
}
2007-09-26 14:14:51 +00:00
return DoCommand ( tile , 0 , 0 , flags , CMD_LANDSCAPE_CLEAR ) ;
2007-08-30 17:17:04 +00:00
}
2007-07-06 22:33:16 +00:00
2007-01-10 18:56:51 +00:00
extern const TileTypeProcs _tile_type_industry_procs = {
2009-03-15 00:32:18 +00:00
DrawTile_Industry , // draw_tile_proc
GetSlopeZ_Industry , // get_slope_z_proc
ClearTile_Industry , // clear_tile_proc
2009-06-25 19:23:09 +00:00
AddAcceptedCargo_Industry , // add_accepted_cargo_proc
2009-03-15 00:32:18 +00:00
GetTileDesc_Industry , // get_tile_desc_proc
GetTileTrackStatus_Industry , // get_tile_track_status_proc
ClickTile_Industry , // click_tile_proc
AnimateTile_Industry , // animate_tile_proc
TileLoop_Industry , // tile_loop_proc
ChangeTileOwner_Industry , // change_tile_owner_proc
2009-06-27 17:05:20 +00:00
AddProducedCargo_Industry , // add_produced_cargo_proc
2009-03-15 00:32:18 +00:00
NULL , // vehicle_enter_tile_proc
GetFoundation_Industry , // get_foundation_proc
TerraformTile_Industry , // terraform_tile_proc
2004-08-09 17:04:08 +00:00
} ;