src/industry_cmd.cpp
author belugas
Sat, 22 Sep 2007 00:59:27 +0000
changeset 8104 a792a30af2c8
parent 8078 bdf94bf88568
child 8106 9f527cc360cf
permissions -rw-r--r--
(svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
     3
/** @file industry_cmd.cpp */
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3094
diff changeset
     7
#include "clear_map.h"
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
     8
#include "functions.h"
3314
b8b234d4584f (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
     9
#include "industry_map.h"
3338
2c60ed0dcce3 (svn r4120) Use the new station functions where appropriate
tron
parents: 3331
diff changeset
    10
#include "station_map.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    11
#include "table/strings.h"
7762
03721db0ac1c (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7758
diff changeset
    12
#include "strings.h"
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
    13
#include "table/sprites.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 552
diff changeset
    14
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1202
diff changeset
    15
#include "tile.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6633
diff changeset
    16
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
#include "economy.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 314
diff changeset
    25
#include "sound.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    26
#include "variables.h"
3654
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    27
#include "table/industry_land.h"
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    28
#include "table/build_industry.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    29
#include "genworld.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4231
diff changeset
    30
#include "date.h"
5056
20369e09627b (svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents: 4976
diff changeset
    31
#include "water_map.h"
6160
126831e48987 (svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents: 6135
diff changeset
    32
#include "tree_map.h"
6417
26acff62d001 (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6160
diff changeset
    33
#include "cargotype.h"
7789
bda67a697f68 (svn r10641) -Fix(r10638): Forgotten Son... err...include
belugas
parents: 7788
diff changeset
    34
#include "newgrf_commons.h"
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7661
diff changeset
    35
#include "newgrf_industries.h"
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
    36
#include "newgrf_industrytiles.h"
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
    37
#include "newgrf_callbacks.h"
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
    38
#include "misc/autoptr.hpp"
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
    39
#include "autoslope.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    41
void ShowIndustryViewWindow(int industry);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    42
void BuildOilRig(TileIndex tile);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    43
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    44
static byte _industry_sound_ctr;
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    45
static TileIndex _industry_sound_tile;
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    46
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
    47
int _total_industries;                      //general counter
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
    48
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
    49
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
    50
const Industry **_industry_sort;
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
    51
bool _industry_sort_dirty;
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
    52
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    53
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    54
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    55
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    56
/** This function initialize the spec arrays of both
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    57
 * industry and industry tiles.
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    58
 * It adjusts the enabling of the industry too, based on climate availability.
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    59
 * This will allow for clearer testings */
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    60
void ResetIndustries()
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    61
{
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    62
	memset(&_industry_specs, 0, sizeof(_industry_specs));
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    63
	memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs));
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    64
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    65
	/* once performed, enable only the current climate industries */
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    66
	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    67
		_industry_specs[i].enabled = HASBIT(_origin_industry_specs[i].climate_availability, _opt.landscape);
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    68
	}
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    69
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    70
	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    71
	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    72
}
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
    73
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
    74
void ResetIndustryCreationProbility(IndustryType type)
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
    75
{
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
    76
	assert(type < INVALID_INDUSTRYTYPE);
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
    77
	_industry_specs[type].appear_creation[_opt.landscape] = 0;
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
    78
}
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
    79
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
    80
DEFINE_OLD_POOL_GENERIC(Industry, Industry)
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    81
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    82
/**
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    83
 * Retrieve the type for this industry.  Although it is accessed by a tile,
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    84
 * it will return the general type of industry, and not the sprite index
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    85
 * as would do GetIndustryGfx.
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    86
 * @param tile that is queried
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    87
 * @pre IsTileType(tile, MP_INDUSTRY)
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    88
 * @return general type for this industry, as defined in industry.h
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    89
 **/
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    90
IndustryType GetIndustryType(TileIndex tile)
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    91
{
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    92
	assert(IsTileType(tile, MP_INDUSTRY));
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    93
7135
8078f2b614e4 (svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas
parents: 7132
diff changeset
    94
	const Industry *ind = GetIndustryByTile(tile);
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
    95
	return ind->IsValid() ? ind->type : (IndustryType)IT_INVALID;
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    96
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    98
/**
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    99
 * Accessor for array _industry_specs.
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   100
 * This will ensure at once : proper access and
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   101
 * not allowing modifications of it.
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   102
 * @param thistype of industry (which is the index in _industry_specs)
6989
43b359b4cb86 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6987
diff changeset
   103
 * @pre thistype < NUM_INDUSTRYTYPES
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   104
 * @return a pointer to the corresponding industry spec
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   105
 **/
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3669
diff changeset
   106
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   107
{
6989
43b359b4cb86 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6987
diff changeset
   108
	assert(thistype < NUM_INDUSTRYTYPES);
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   109
	return &_industry_specs[thistype];
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   110
}
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   111
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   112
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   113
 * Accessor for array _industry_tile_specs.
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   114
 * This will ensure at once : proper access and
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   115
 * not allowing modifications of it.
7784
efb98124ce51 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7762
diff changeset
   116
 * @param gfx of industrytile (which is the index in _industry_tile_specs)
7245
f868248ecf83 (svn r9984) -Codechange: Remove an obsolete structure and a now meaningless enum, in favor of the "real thing"
belugas
parents: 7244
diff changeset
   117
 * @pre gfx < INVALID_INDUSTRYTILE
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   118
 * @return a pointer to the corresponding industrytile spec
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   119
 **/
7958
86754174b58f (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7957
diff changeset
   120
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
6418
a80dba2d8243 (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 6417
diff changeset
   121
{
7245
f868248ecf83 (svn r9984) -Codechange: Remove an obsolete structure and a now meaningless enum, in favor of the "real thing"
belugas
parents: 7244
diff changeset
   122
	assert(gfx < INVALID_INDUSTRYTILE);
7958
86754174b58f (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7957
diff changeset
   123
	return &_industry_tile_specs[gfx];
6418
a80dba2d8243 (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 6417
diff changeset
   124
}
a80dba2d8243 (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 6417
diff changeset
   125
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   126
Industry::~Industry()
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   127
{
7916
8bc57ab02de6 (svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents: 7897
diff changeset
   128
	if (CleaningPool()) return;
8bc57ab02de6 (svn r10813) -Fix (r10799): some destructors were performing too much during the pool cleanups, which could cause crashes as already removed pool items could then be dereferenced by other destructors.
rubidium
parents: 7897
diff changeset
   129
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   130
	/* Industry can also be destroyed when not fully initialized.
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   131
	 * This means that we do not have to clear tiles either. */
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   132
	if (this->width == 0) {
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   133
		this->xy = 0;
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   134
		return;
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   135
	}
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   136
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   137
	BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   138
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   139
			if (GetIndustryIndex(tile_cur) == this->index) {
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   140
				DoClearSquare(tile_cur);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   141
			}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   142
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   143
			DeleteOilRig(tile_cur);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   144
		}
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   145
	END_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   146
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   147
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   148
		/* Remove the farmland and convert it to regular tiles over time. */
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   149
		BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
4815
c2a54b213fde (svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents: 4607
diff changeset
   150
			tile_cur = TILE_MASK(tile_cur);
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   151
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   152
					GetIndustryIndexOfField(tile_cur) == this->index) {
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   153
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   154
			}
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   155
		} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   156
	}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   157
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   158
	_industry_sort_dirty = true;
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   159
	DecIndustryTypeCount(this->type);
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
   160
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   161
	DeleteSubsidyWithIndustry(this->index);
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   162
	DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   163
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   164
	this->xy = 0;
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   165
}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   166
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   167
static void IndustryDrawSugarMine(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
{
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   169
	const DrawIndustryAnimationStruct *d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   171
	if (!IsIndustryCompleted(ti->tile)) return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   172
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   173
	d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   175
	AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   177
	if (d->image_2 != 0) {
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   178
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   179
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   181
	if (d->image_3 != 0) {
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   182
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   183
			_drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   184
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   187
static void IndustryDrawToffeeQuarry(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
{
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   189
	uint8 x = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   190
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   191
	if (IsIndustryCompleted(ti->tile)) {
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   192
		x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)];
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   193
		if (x == 0xFF)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   197
	AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   198
	AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, PAL_NONE, 6, 14);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   201
static void IndustryDrawBubbleGenerator( const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
{
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   203
	if (IsIndustryCompleted(ti->tile)) {
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   204
		AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   205
	} else {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   206
		AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   210
static void IndustryDrawToyFactory(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
{
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   212
	const DrawIndustryAnimationStruct *d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   214
	d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
	if (d->image_1 != 0xFF) {
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   217
		AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	if (d->image_2 != 0xFF) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   221
		AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, PAL_NONE, 16 - d->image_2 * 2, 100 + d->image_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   224
	AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   225
	AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, PAL_NONE, 0, 42);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   228
static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
{
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   230
	if (IsIndustryCompleted(ti->tile)) {
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   231
		uint8 image = GetIndustryAnimationState(ti->tile);
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   232
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
		if (image != 0 && image < 7) {
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   234
			AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   235
				PAL_NONE,
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   236
				_coal_plant_sparks[image - 1].x,
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   237
				_coal_plant_sparks[image - 1].y
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   243
typedef void IndustryDrawTileProc(const TileInfo *ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   245
	IndustryDrawSugarMine,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   246
	IndustryDrawToffeeQuarry,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   247
	IndustryDrawBubbleGenerator,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   248
	IndustryDrawToyFactory,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   249
	IndustryDrawCoalPlantSparks,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
static void DrawTile_Industry(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
{
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   254
	IndustryGfx gfx = GetIndustryGfx(ti->tile);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   255
	Industry *ind = GetIndustryByTile(ti->tile);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   256
	const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
3654
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   257
	const DrawBuildingsTileStruct *dits;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   258
	SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   259
	SpriteID pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   261
	/* Retrieve pointer to the draw industry tile struct */
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   262
	if (gfx >= NEW_INDUSTRYTILEOFFSET) {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   263
		/* Draw the tile using the specialized method of newgrf industrytile.
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   264
		 * DrawNewIndustry will return false if ever the resolver could not
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   265
		 * find any sprite to display.  So in this case, we will jump on the
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   266
		 * substitute gfx instead. */
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   267
		if (indts->grf_prop.spritegroup != NULL && DrawNewIndustryTile(ti, ind, gfx, indts)) {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   268
			return;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   269
		} else {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   270
			/* No sprite group (or no valid one) found, meaning no graphics associated.
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   271
			 * Use the substitute one instead */
7957
62dc8719052a (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7941
diff changeset
   272
			if (indts->grf_prop.subst_id != INVALID_INDUSTRYTILE) {
62dc8719052a (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7941
diff changeset
   273
				gfx = indts->grf_prop.subst_id;
62dc8719052a (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7941
diff changeset
   274
				/* And point the industrytile spec accordingly */
62dc8719052a (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7941
diff changeset
   275
				indts = GetIndustryTileSpec(gfx);
62dc8719052a (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7941
diff changeset
   276
			}
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   277
		}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   278
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7446
diff changeset
   280
	dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ?
7787
6e0b6ea38850 (svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents: 7786
diff changeset
   281
			GetIndustryAnimationState(ti->tile) & INDUSTRY_COMPLETED :
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5686
diff changeset
   282
			GetIndustryConstructionStage(ti->tile))];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   284
	image = dits->ground.sprite;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   285
	if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   286
		pal = GENERAL_SPRITE_COLOR(ind->random_color);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   287
	} else {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   288
		pal = dits->ground.pal;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   289
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7830
diff changeset
   291
	/* DrawFoundation() modifes ti->z and ti->tileh */
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7830
diff changeset
   292
	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
7531
fa6a933b71d2 (svn r10299) -Codechange [FS#931]: industry foundations should be drawn as all other foundations, i.e. with DrawFoundation, instead of writing the same functionality itself.
rubidium
parents: 7522
diff changeset
   294
	DrawGroundSprite(image, pal);
fa6a933b71d2 (svn r10299) -Codechange [FS#931]: industry foundations should be drawn as all other foundations, i.e. with DrawFoundation, instead of writing the same functionality itself.
rubidium
parents: 7522
diff changeset
   295
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
	/* Add industry on top of the ground? */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   297
	image = dits->building.sprite;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   298
	if (image != 0) {
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7815
diff changeset
   299
		AddSortableSpriteToDraw(image,
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7815
diff changeset
   300
			(HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) ? GENERAL_SPRITE_COLOR(ind->random_color) : dits->building.pal,
2653
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   301
			ti->x + dits->subtile_x,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   302
			ti->y + dits->subtile_y,
8073
42007d9c81bb (svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents: 8027
diff changeset
   303
			dits->width,
42007d9c81bb (svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents: 8027
diff changeset
   304
			dits->height,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
			dits->dz,
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7830
diff changeset
   306
			ti->z,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7815
diff changeset
   307
			HASBIT(_transparent_opt, TO_INDUSTRIES));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
6923
6913c8a82cc0 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents: 6915
diff changeset
   309
		if (HASBIT(_transparent_opt, TO_INDUSTRIES)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   312
	{
3654
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   313
		int proc = dits->draw_proc - 1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   314
		if (proc >= 0) _industry_draw_tile_procs[proc](ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   318
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y)
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   319
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   320
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7830
diff changeset
   323
static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   324
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7830
diff changeset
   325
	return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   326
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   327
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   328
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
{
7695
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   330
	IndustryGfx gfx = GetIndustryGfx(tile);
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   331
	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   332
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   333
	/* When we have to use a callback, we put our data in the next two variables */
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   334
	CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)];
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   335
	uint8 raw_acceptance[lengthof(itspec->acceptance)];
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   336
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   337
	/* And then these will always point to a same sized array with the required data */
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   338
	const CargoID *accepts_cargo = itspec->accepts_cargo;
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   339
	const uint8 *acceptance = itspec->acceptance;
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   340
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   341
	if (HASBIT(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) {
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   342
		uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile);
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   343
		if (res != CALLBACK_FAILED) {
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   344
			accepts_cargo = raw_accepts_cargo;
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   345
			for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile);
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   346
		}
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   347
	}
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   348
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   349
	if (HASBIT(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) {
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   350
		uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile);
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   351
		if (res != CALLBACK_FAILED) {
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   352
			acceptance = raw_acceptance;
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   353
			for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4);
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   354
		}
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   355
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
7232
2476045c6aed (svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents: 7179
diff changeset
   357
	for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) {
7695
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   358
		CargoID a = accepts_cargo[i];
b15538ba7152 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7682
diff changeset
   359
		if (a != CT_INVALID) ac[a] = acceptance[i];
7232
2476045c6aed (svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents: 7179
diff changeset
   360
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   363
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   365
	const Industry *i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	td->owner = i->owner;
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
   368
	td->str = GetIndustrySpec(i->type)->name;
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   369
	if (!IsIndustryCompleted(tile)) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   370
		SetDParamX(td->dparam, 0, td->str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
		td->str = STR_2058_UNDER_CONSTRUCTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7406
diff changeset
   375
static CommandCost ClearTile_Industry(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   377
	Industry *i = GetIndustryByTile(tile);
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
   378
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   380
	/* water can destroy industries
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   381
	 * in editor you can bulldoze industries
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   382
	 * with magic_bulldozer cheat you can destroy industries
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   383
	 * (area around OILRIG is water, so water shouldn't flood it
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   384
	 */
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   385
	if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   386
			!_cheats.magic_bulldozer.value) ||
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
   387
			(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
   388
		SetDParam(0, indspec->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
		return_cmd_error(STR_4800_IN_THE_WAY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
   392
	if (flags & DC_EXEC) delete i;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   393
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   396
static void TransportIndustryGoods(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   398
	Industry *i = GetIndustryByTile(tile);
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   399
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	uint cw, am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
   402
	cw = min(i->produced_cargo_waiting[0], 255);
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   403
	if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
   404
		i->produced_cargo_waiting[0] -= cw;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
		/* fluctuating economy? */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   407
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   409
		i->this_month_production[0] += cw;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
   411
		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw);
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   412
		i->this_month_transported[0] += am;
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   413
		if (am != 0 && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
6631
dc3480a670cc (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6609
diff changeset
   414
			uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   415
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
   416
			if (newgfx != INDUSTRYTILE_NOANIM) {
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   417
				ResetIndustryConstructionStage(tile);
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   418
				SetIndustryCompleted(tile, true);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   419
				SetIndustryGfx(tile, newgfx);
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   420
				MarkTileDirtyByTile(tile);
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   421
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
   425
	cw = min(i->produced_cargo_waiting[1], 255);
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   426
	if (cw > indspec->minimal_cargo) {
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
   427
		i->produced_cargo_waiting[1] -= cw;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   428
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   429
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   430
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   431
		i->this_month_production[1] += cw;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
   433
		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
   434
		i->this_month_transported[1] += am;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   439
static void AnimateTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
{
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   441
	byte m;
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   442
	IndustryGfx gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   444
	if (GetIndustryTileSpec(gfx)->animation_info != 0xFFFF) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   445
		AnimateNewIndustryTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   446
		return;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   447
	}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   448
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   449
	switch (gfx) {
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   450
	case GFX_SUGAR_MINE_SIEVE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
		if ((_tick_counter & 1) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   452
			m = GetIndustryAnimationState(tile) + 1;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   453
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2868
diff changeset
   454
			switch (m & 7) {
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   455
			case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   456
			case 6: SndPlayTileFx(SND_29_RIP, tile); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
			if (m >= 96) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
			}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   463
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   469
	case GFX_TOFFEE_QUARY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
		if ((_tick_counter & 3) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   471
			m = GetIndustryAnimationState(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   472
7015
af363e4290ab (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6989
diff changeset
   473
			if (_industry_anim_offs_toffee[m] == 0xFF) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   474
				SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
			if (++m >= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
			}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   481
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   487
	case GFX_BUBBLE_CATCHER:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   488
		if ((_tick_counter & 1) == 0) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   489
			m = GetIndustryAnimationState(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
			if (++m >= 40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
			}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   495
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   501
	/* Sparks on a coal plant */
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   502
	case GFX_POWERPLANT_SPARKS:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
		if ((_tick_counter & 3) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   504
			m = GetIndustryAnimationState(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   505
			if (m == 6) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   506
				SetIndustryAnimationState(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
			} else {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   509
				SetIndustryAnimationState(tile, m + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   515
	case GFX_TOY_FACTORY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
		if ((_tick_counter & 1) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   517
			m = GetIndustryAnimationState(tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
6964
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   519
			switch (m) {
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   520
				case  1: SndPlayTileFx(SND_2C_MACHINERY, tile); break;
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   521
				case 23: SndPlayTileFx(SND_2B_COMEDY_HIT, tile); break;
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   522
				case 28: SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); break;
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   523
				default:
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   524
					if (m >= 50) {
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   525
						int n = GetIndustryAnimationLoop(tile) + 1;
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   526
						m = 0;
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   527
						if (n >= 8) {
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   528
							n = 0;
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   529
							DeleteAnimatedTile(tile);
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   530
						}
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   531
						SetIndustryAnimationLoop(tile, n);
737c8b546ca5 (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6963
diff changeset
   532
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   535
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
5685
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   540
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   541
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   542
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   543
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		if ((_tick_counter & 3) == 0) {
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   545
			IndustryGfx gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   547
			gfx = (gfx < 155) ? gfx + 1 : 148;
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   548
			SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   553
	case GFX_OILWELL_ANIMATED_1:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   554
	case GFX_OILWELL_ANIMATED_2:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   555
	case GFX_OILWELL_ANIMATED_3:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
		if ((_tick_counter & 7) == 0) {
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6964
diff changeset
   557
			bool b = CHANCE16(1, 7);
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   558
			IndustryGfx gfx = GetIndustryGfx(tile);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   559
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   560
			m = GetIndustryAnimationState(tile) + 1;
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   561
			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   562
				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   563
				SetIndustryConstructionStage(tile, 3);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   564
				DeleteAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
			} else {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   566
				SetIndustryAnimationState(tile, m);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   567
				SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   573
	case GFX_COAL_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   574
	case GFX_COPPER_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   575
	case GFX_GOLD_MINE_TOWER_ANIMATED: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
			int state = _tick_counter & 0x7FF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
			if ((state -= 0x400) < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
			if (state < 0x1A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
				if (state < 0x20 || state >= 0x180) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   583
					m = GetIndustryAnimationState(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   584
					if (!(m & 0x40)) {
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5686
diff changeset
   585
						SetIndustryAnimationState(tile, m | 0x40);
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   586
						SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
					if (state & 7)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
					if (state & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
				}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   594
				m = (GetIndustryAnimationState(tile) + 1) | 0x40;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
				if (m > 0xC2) m = 0xC0;
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   596
				SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
			} else if (state >= 0x200 && state < 0x3A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
				int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
				i = (state < 0x220 || state >= 0x380) ? 7 : 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
				if (state & i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   604
				m = (GetIndustryAnimationState(tile) & 0xBF) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
				if (m < 0x80) m = 0x82;
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   606
				SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   613
static void CreateIndustryEffectSmoke(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
{
3773
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   615
	uint x = TileX(tile) * TILE_SIZE;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   616
	uint y = TileY(tile) * TILE_SIZE;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   617
	uint z = GetTileMaxZ(tile);
3094
5be98607b6d5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   618
3773
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   619
	CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   622
static void MakeIndustryTileBigger(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
{
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   624
	byte cnt = GetIndustryConstructionCounter(tile) + 1;
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   625
	byte stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   627
	if (cnt != 4) {
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   628
		SetIndustryConstructionCounter(tile, cnt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   632
	stage = GetIndustryConstructionStage(tile) + 1;
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   633
	SetIndustryConstructionCounter(tile, 0);
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   634
	SetIndustryConstructionStage(tile, stage);
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   635
	StartStopIndustryTileAnimation(tile, IAT_CONSTRUCTION_STATE_CHANGE);
7787
6e0b6ea38850 (svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents: 7786
diff changeset
   636
	if (stage == INDUSTRY_COMPLETED) SetIndustryCompleted(tile, true);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   637
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   640
	if (!IsIndustryCompleted(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   642
	IndustryGfx gfx = GetIndustryGfx(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   643
	if (gfx >= NEW_INDUSTRYTILEOFFSET) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   644
		/* New industry */
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   645
		const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   646
		if (its->animation_info != 0xFFFF) AddAnimatedTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   647
		return;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   648
	}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   649
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   650
	switch (gfx) {
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   651
	case GFX_POWERPLANT_CHIMNEY:
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   652
		CreateIndustryEffectSmoke(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
4607
2215d3175ad1 (svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents: 4587
diff changeset
   655
	case GFX_OILRIG_1:
2215d3175ad1 (svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents: 4587
diff changeset
   656
		if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == GFX_OILRIG_1) BuildOilRig(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   659
	case GFX_TOY_FACTORY:
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   660
	case GFX_BUBBLE_CATCHER:
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   661
	case GFX_TOFFEE_QUARY:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   662
		SetIndustryAnimationState(tile, 0);
3538
3eb71c726341 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
   663
		SetIndustryAnimationLoop(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
5685
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   666
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   667
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   668
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   669
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   675
static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	int dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	static const int8 _tileloop_ind_case_161[12] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   680
		11,   0, -4, -14,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   681
		-4, -10, -4,   1,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   682
		49,  59, 60,  65,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   685
	SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   686
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	dir = Random() & 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	v = CreateEffectVehicleAbove(
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   690
		TileX(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 0],
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   691
		TileY(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 4],
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
		_tileloop_ind_case_161[dir + 8],
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1335
diff changeset
   693
		EV_BUBBLE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
7830
210381b46ae6 (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7829
diff changeset
   696
	if (v != NULL) v->u.special.animation_substate = dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   699
static void TileLoop_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
{
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   701
	IndustryGfx newgfx;
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   702
	IndustryGfx gfx;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   704
	if (!IsIndustryCompleted(tile)) {
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   705
		MakeIndustryTileBigger(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   709
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
	TransportIndustryGoods(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   713
	if (StartStopIndustryTileAnimation(tile, IAT_TILELOOP)) return;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
   714
6631
dc3480a670cc (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6609
diff changeset
   715
	newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next;
7239
68e722150cba (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 7232
diff changeset
   716
	if (newgfx != INDUSTRYTILE_NOANIM) {
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   717
		ResetIndustryConstructionStage(tile);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   718
		SetIndustryGfx(tile, newgfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   723
	gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   725
	switch (gfx) {
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   726
	case GFX_OILRIG_1: // coast line at oilrigs
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   727
	case GFX_OILRIG_2:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   728
	case GFX_OILRIG_3:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   729
	case GFX_OILRIG_4:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   730
	case GFX_OILRIG_5:
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   731
		TileLoop_Water(tile);
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   732
		break;
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   733
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   734
	case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   735
	case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   736
	case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   737
		if (!(_tick_counter & 0x400) && CHANCE16(1, 2)) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   738
			switch (gfx) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   739
				case GFX_COAL_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   740
				case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   741
				case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   742
			}
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   743
			SetIndustryGfx(tile, gfx);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   744
			SetIndustryAnimationState(tile, 0x80);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   745
			AddAnimatedTile(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   746
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   749
	case GFX_OILWELL_NOT_ANIMATED:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   750
		if (CHANCE16(1, 6)) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   751
			SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   752
			SetIndustryAnimationState(tile, 0);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   753
			AddAnimatedTile(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   754
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   757
	case GFX_COAL_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   758
	case GFX_COPPER_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   759
	case GFX_GOLD_MINE_TOWER_ANIMATED:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   760
		if (!(_tick_counter & 0x400)) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   761
			switch (gfx) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   762
				case GFX_COAL_MINE_TOWER_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   763
				case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   764
				case GFX_GOLD_MINE_TOWER_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   765
			}
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   766
			SetIndustryGfx(tile, gfx);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   767
			SetIndustryCompleted(tile, true);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   768
			SetIndustryConstructionStage(tile, 3);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   769
			DeleteAnimatedTile(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   770
		}
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   771
		break;
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   772
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   773
	case GFX_POWERPLANT_SPARKS:
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6964
diff changeset
   774
		if (CHANCE16(1, 3)) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   775
			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
			AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   780
	case GFX_COPPER_MINE_CHIMNEY:
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   781
		CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   782
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   785
	case GFX_TOY_FACTORY: {
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   786
			Industry *i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
			if (i->was_cargo_delivered) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
				i->was_cargo_delivered = false;
3538
3eb71c726341 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
   789
				SetIndustryAnimationLoop(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
				AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   795
	case GFX_BUBBLE_GENERATOR:
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   796
		TileLoopIndustry_BubbleGenerator(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   797
		break;
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   798
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   799
	case GFX_TOFFEE_QUARY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   803
	case GFX_SUGAR_MINE_SIEVE:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   804
		if (CHANCE16(1, 3)) AddAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   809
static void ClickTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
{
3314
b8b234d4584f (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   811
	ShowIndustryViewWindow(GetIndustryIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 7152
diff changeset
   814
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
3344
d86c852715fa (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   819
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
{
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
   821
	const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type);
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
   822
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
	b[0] = i->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	b[1] = i->produced_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   827
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
{
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   829
	/* If the founder merges, the industry was created by the merged company */
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   830
	Industry *i = GetIndustryByTile(tile);
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
   831
	if (i->founder == old_player) i->founder = (new_player == PLAYER_SPECTATOR) ? OWNER_NONE : new_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   836
static bool IsBadFarmFieldTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   838
	switch (GetTileType(tile)) {
5935
6f5ae5d8d407 (svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents: 5919
diff changeset
   839
		case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   840
		case MP_TREES: return false;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   841
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   845
static bool IsBadFarmFieldTile2(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   847
	switch (GetTileType(tile)) {
5935
6f5ae5d8d407 (svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents: 5919
diff changeset
   848
		case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   849
		case MP_TREES: return false;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   850
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   854
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		tile = TILE_MASK(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   858
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
   859
		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   860
			byte or_ = type;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   861
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   862
			if (or_ == 1 && CHANCE16(1, 7)) or_ = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   864
			if (direction == AXIS_X) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   865
				SetFenceSE(tile, or_);
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   866
			} else {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   867
				SetFenceSW(tile, or_);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   870
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   871
		tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
	} while (--size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
4330
7306bda145ab (svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents: 4329
diff changeset
   875
static void PlantFarmField(TileIndex tile, IndustryID industry)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	uint size_x, size_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
	uint32 r;
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   879
	uint count;
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   880
	uint counter;
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   881
	uint field_type;
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   882
	int type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   884
	if (_opt.landscape == LT_ARCTIC) {
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6633
diff changeset
   885
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
	/* determine field size */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	r = (Random() & 0x303) + 0x404;
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   891
	if (_opt.landscape == LT_ARCTIC) r += 0x404;
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   892
	size_x = GB(r, 0, 8);
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   893
	size_y = GB(r, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	/* offset tile to match size */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   896
	tile -= TileDiffXY(size_x / 2, size_y / 2);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   897
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	/* check the amount of bad tiles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
	count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
		count += IsBadFarmFieldTile(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   904
	if (count * 2 >= size_x * size_y) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	/* determine type of field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	r = Random();
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   908
	counter = GB(r, 5, 3);
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   909
	field_type = GB(r, 8, 8) * 9 >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	/* make field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
		if (!IsBadFarmFieldTile2(cur_tile)) {
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   915
			MakeField(cur_tile, field_type, industry);
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   916
			SetClearCounter(cur_tile, counter);
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   917
			MarkTileDirtyByTile(cur_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   920
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	type = 3;
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   922
	if (_opt.landscape != LT_ARCTIC && _opt.landscape != LT_TROPIC) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
		type = _plantfarmfield_type[Random() & 0xF];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   926
	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   927
	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   928
	SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y);
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   929
	SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   932
void PlantRandomFarmField(const Industry *i)
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   933
{
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   934
	int x = i->width  / 2 + Random() % 31 - 16;
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   935
	int y = i->height / 2 + Random() % 31 - 16;
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   936
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   937
	TileIndex tile = TileAddWrap(i->xy, x, y);
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   938
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   939
	if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   940
}
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   941
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   942
/**
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   943
 * Search callback function for ChopLumberMillTrees
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   944
 * @param tile to test
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   945
 * @param data that is passed by the caller.  In this case, nothing
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
   946
 * @return the result of the test
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   947
 */
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   948
static bool SearchLumberMillTrees(TileIndex tile, uint32 data)
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   949
{
6160
126831e48987 (svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents: 6135
diff changeset
   950
	if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   951
		PlayerID old_player = _current_player;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   952
		/* found a tree */
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   953
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   954
		_current_player = OWNER_NONE;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   955
		_industry_sound_ctr = 1;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   956
		_industry_sound_tile = tile;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   957
		SndPlayTileFx(SND_38_CHAINSAW, tile);
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   958
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   959
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   960
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   961
		_current_player = old_player;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   962
		return true;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   963
	}
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   964
	return false;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   965
}
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   966
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   967
/**
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   968
 * Perform a circular search around the Lumber Mill in order to find trees to cut
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   969
 * @param i industry
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   970
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
static void ChopLumberMillTrees(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   973
	TileIndex tile = i->xy;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   974
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   975
	if (!IsIndustryCompleted(tile)) return;  ///< Can't proceed if not completed
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   977
	if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles  to search
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
   978
		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
static void ProduceIndustryGoods(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
	uint num;
7151
d811c3f808bd (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 7135
diff changeset
   985
	const IndustrySpec *indsp = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	/* play a sound? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
	if ((i->counter & 0x3F) == 0) {
7151
d811c3f808bd (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 7135
diff changeset
   989
		if (CHANCE16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
			SndPlayTileFx(
7151
d811c3f808bd (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 7135
diff changeset
   991
				(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
				i->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	i->counter--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
	/* produce some cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
	if ((i->counter & 0xFF) == 0) {
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7661
diff changeset
  1000
		if (HASBIT(indsp->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7661
diff changeset
  1001
7151
d811c3f808bd (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 7135
diff changeset
  1002
		IndustyBehaviour indbehav = indsp->behaviour;
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1003
		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]);
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1004
		i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
7701
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1006
		if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1007
			bool plant;
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1008
			if (HASBIT(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1009
				plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0);
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1010
			} else {
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1011
				plant = CHANCE16(1, 8);
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1012
			}
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1013
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1014
			if (plant) PlantRandomFarmField(i);
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1015
		}
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1016
		if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1017
			bool cut = ((i->counter & 0x1FF) == 0);
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1018
			if (HASBIT(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1019
				cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0);
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1020
			}
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1021
72d4e674ca6e (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7699
diff changeset
  1022
			if (cut) ChopLumberMillTrees(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1023
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  1027
void OnTick_Industry()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
	if (_industry_sound_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		_industry_sound_ctr++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
		if (_industry_sound_ctr == 75) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1035
			SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
		} else if (_industry_sound_ctr == 160) {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1037
			_industry_sound_ctr = 0;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1038
			SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1042
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1044
	FOR_ALL_INDUSTRIES(i) {
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7723
diff changeset
  1045
		StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK);
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1046
		ProduceIndustryGoods(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1050
static bool CheckNewIndustry_NULL(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1055
static bool CheckNewIndustry_Forest(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
{
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  1057
	if (_opt.landscape == LT_ARCTIC) {
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6633
diff changeset
  1058
		if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1066
static bool CheckNewIndustry_OilRefinery(TileIndex tile)
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1067
{
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1068
	if (_game_mode == GM_EDITOR) return true;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1069
	if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true;
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1070
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1071
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1072
	return false;
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1073
}
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1074
7
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1075
extern bool _ignore_restrictions;
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1076
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1077
static bool CheckNewIndustry_OilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1079
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1080
	if (TileHeight(tile) == 0 &&
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1081
			DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1087
static bool CheckNewIndustry_Farm(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
{
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
  1089
	if (_opt.landscape == LT_ARCTIC) {
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6633
diff changeset
  1090
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
			_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1098
static bool CheckNewIndustry_Plantation(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1100
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1108
static bool CheckNewIndustry_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1110
	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
		_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1118
static bool CheckNewIndustry_Lumbermill(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1120
	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
		_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1127
static bool CheckNewIndustry_BubbleGen(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
{
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1129
	return GetTileZ(tile) <= TILE_HEIGHT * 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1132
typedef bool CheckNewIndustryProc(TileIndex tile);
3663
50fbc1639a3f (svn r4578) CodeChange : Cleanup of industry_cmd (Step-2).
belugas
parents: 3662
diff changeset
  1133
static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
	CheckNewIndustry_NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
	CheckNewIndustry_Forest,
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1136
	CheckNewIndustry_OilRefinery,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	CheckNewIndustry_Farm,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
	CheckNewIndustry_Plantation,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
	CheckNewIndustry_Water,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	CheckNewIndustry_Lumbermill,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	CheckNewIndustry_BubbleGen,
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1142
	CheckNewIndustry_OilRig
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1145
static bool CheckSuitableIndustryPos(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
{
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1147
	uint x = TileX(tile);
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1148
	uint y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1150
	if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1158
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1160
	const Town *t;
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1161
	const Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	t = ClosestTownFromTile(tile, (uint)-1);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1164
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1165
	if (_patches.multiple_industry_per_town) return t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1167
	FOR_ALL_INDUSTRIES(i) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1168
		if (i->type == (byte)type &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
				i->town == t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
			return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
	return t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1178
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type, bool *custom_shape_check = NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
	_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
	do {
7963
e04dbb203f3e (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents: 7958
diff changeset
  1183
		IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx);
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1184
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1185
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
		if (!IsValidTile(cur_tile)) {
7969
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
  1187
			if (gfx == GFX_WATERTILE_SPECIALCHECK) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1190
7969
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
  1191
		if (gfx == GFX_WATERTILE_SPECIALCHECK) {
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1192
			if (!IsTileType(cur_tile, MP_WATER) ||
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1193
					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1194
				return false;
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1195
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
		} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1197
			if (!EnsureNoVehicle(cur_tile)) return false;
7389
d8bc6472130b (svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents: 7355
diff changeset
  1198
			if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false;
d8bc6472130b (svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents: 7355
diff changeset
  1199
8027
80ddda328596 (svn r11050) -Codechange: Use the translated gfx, not the original one.
belugas
parents: 8018
diff changeset
  1200
			const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
80ddda328596 (svn r11050) -Codechange: Use the translated gfx, not the original one.
belugas
parents: 8018
diff changeset
  1201
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
  1202
			IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1204
			if (HASBIT(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1205
				if (custom_shape_check != NULL) *custom_shape_check = true;
7963
e04dbb203f3e (svn r10972) -Codechange: Implement the counterpart(GetTranslatedIndustryTileID) of getindustileid of TTDPatch. This allows to ensure that the ID of a tile (taken out of the map or not) is still a valid one regarding the possible override it may have been flagged to.
belugas
parents: 7958
diff changeset
  1206
				if (!PerformIndustryTileSlopeCheck(cur_tile, its, type, gfx)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
			} else {
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1208
				if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1209
					/* As soon as the tile is not water, bail out.
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1210
					* But that does not mean the search is over.  You have
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1211
					* to make sure every tile of the industry will be only water*/
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1212
					if (!IsClearWaterTile(cur_tile)) return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1213
				} else {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1214
					Slope tileh;
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1215
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1216
					if (IsClearWaterTile(cur_tile)) return false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1217
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1218
					tileh = GetTileSlope(cur_tile, NULL);
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1219
					if (IsSteepSlope(tileh)) return false;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1220
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1221
					if (_patches.land_generator != LG_TERRAGENESIS || !_generating_world) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1222
						/* It is almost impossible to have a fully flat land in TG, so what we
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1223
						*  do is that we check if we can make the land flat later on. See
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1224
						*  CheckIfCanLevelIndustryPlatform(). */
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1225
						if (tileh != SLOPE_FLAT) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1226
							Slope t;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1227
							byte bits = its->slopes_refused;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1228
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1229
							if (bits & 0x10) return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1230
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1231
							t = ComplementSlope(tileh);
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1232
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1233
							if (bits & 1 && (t & SLOPE_NW)) return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1234
							if (bits & 2 && (t & SLOPE_NE)) return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1235
							if (bits & 4 && (t & SLOPE_SW)) return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1236
							if (bits & 8 && (t & SLOPE_SE)) return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1237
						}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1238
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
				}
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1240
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1242
			if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1243
				if (!IsTileType(cur_tile, MP_HOUSE)) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1244
					_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1245
					return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1246
				}
7723
e6785e8fec08 (svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents: 7712
diff changeset
  1247
				if (CmdFailed(DoCommand(cur_tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR))) return false;
e6785e8fec08 (svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents: 7712
diff changeset
  1248
			} else if ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) == 0 || !IsTileType(cur_tile, MP_HOUSE)) {
e6785e8fec08 (svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents: 7712
diff changeset
  1249
				if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
		}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1252
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1257
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1258
{
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
  1259
	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1260
		_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1261
		return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1262
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1263
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
  1264
	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1265
		_error_message = STR_0239_SITE_UNSUITABLE;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1266
		return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1267
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1268
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1269
	return true;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1270
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1271
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1272
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1273
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1274
	int size_x, size_y;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1275
	uint curh;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1276
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1277
	size_x = 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1278
	size_y = 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1279
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1280
	/* Check if we don't leave the map */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1281
	if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1282
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1283
	tile += TileDiffXY(-1, -1);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1284
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1285
		curh = TileHeight(tile_walk);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1286
		/* Is the tile clear? */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1287
		if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES))
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1288
			return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1289
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1290
		/* Don't allow too big of a change if this is the sub-tile check */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1291
		if (internal != 0 && delta(curh, height) > 1) return false;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1292
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1293
		/* Different height, so the surrounding tiles of this tile
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1294
		 *  has to be correct too (in level, or almost in level)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1295
		 *  else you get a chain-reaction of terraforming. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1296
		if (internal == 0 && curh != height) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1297
			if (!CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1))
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1298
				return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1299
		}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1300
	} END_TILE_LOOP(tile_walk, size_x, size_y, tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1301
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1302
	return true;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1303
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1304
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1305
/**
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1306
 * This function tries to flatten out the land below an industry, without
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1307
 *  damaging the surroundings too much.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1308
 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1309
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable* it, int type)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1310
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1311
	const int MKEND = -0x80;   // used for last element in an IndustryTileTable (see build_industry.h)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1312
	int max_x = 0;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1313
	int max_y = 0;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1314
	TileIndex cur_tile;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1315
	uint size_x, size_y;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1316
	uint h, curh;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1317
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1318
	/* Finds dimensions of largest variant of this industry */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1319
	do {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1320
		if (it->ti.x > max_x) max_x = it->ti.x;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1321
		if (it->ti.y > max_y) max_y = it->ti.y;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1322
	} while ((++it)->ti.x != MKEND);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1323
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1324
	/* Remember level height */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1325
	h = TileHeight(tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1326
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1327
	/* Check that all tiles in area and surrounding are clear
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1328
	 * this determines that there are no obstructing items */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1329
	cur_tile = tile + TileDiffXY(-1, -1);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1330
	size_x = max_x + 4;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1331
	size_y = max_y + 4;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1332
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1333
	/* Check if we don't leave the map */
4313
bbd84f6e21b0 (svn r5966) -Fix: prevent that the industry placement's terraforming checks can leave the map on the southern side
rubidium
parents: 4301
diff changeset
  1334
	if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1335
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1336
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1337
		curh = TileHeight(tile_walk);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1338
		if (curh != h) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1339
			/* This tile needs terraforming. Check if we can do that without
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1340
			 *  damaging the surroundings too much. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1341
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1342
			/* This is not 100% correct check, but the best we can do without modifying the map.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1343
			 *  What is missing, is if the difference in height is more than 1.. */
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7969
diff changeset
  1344
			if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) return false;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1345
		}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1346
	} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1347
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1348
	if (flags & DC_EXEC) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1349
		/* Terraform the land under the industry */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1350
		BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1351
			curh = TileHeight(tile_walk);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1352
			while (curh != h) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1353
				/* We give the terraforming for free here, because we can't calculate
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1354
				 *  exact cost in the test-round, and as we all know, that will cause
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1355
				 *  a nice assert if they don't match ;) */
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7969
diff changeset
  1356
				DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1357
				curh += (curh > h) ? -1 : 1;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1358
			}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1359
		} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1360
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1361
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1362
	return true;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1363
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1364
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1365
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1366
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
{
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1368
	const IndustrySpec *indspec = GetIndustrySpec(type);
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1369
	const Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1371
	/* accepting industries won't be close, not even with patch */
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1372
	if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
		return true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1374
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1375
	FOR_ALL_INDUSTRIES(i) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1376
		/* check if an industry that accepts the same goods is nearby */
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1377
		if (DistanceMax(tile, i->xy) <= 14 &&
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1378
				indspec->accepts_cargo[0] != CT_INVALID &&
7355
8fd37a636f6d (svn r10099) -Fix(r9867, FS860): Use the specs of the to-be-created industry instead of the scanned industry
belugas
parents: 7335
diff changeset
  1379
				indspec->accepts_cargo[0] == GetIndustrySpec(i->type)->accepts_cargo[0] && (
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1380
					_game_mode != GM_EDITOR ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1381
					!_patches.same_industry_close ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1382
					!_patches.multiple_industry_per_town
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1383
				)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1384
			_error_message = STR_INDUSTRY_TOO_CLOSE;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1385
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1386
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1388
		/* check "not close to" field. */
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1389
		if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1214
diff changeset
  1390
				DistanceMax(tile, i->xy) <= 14) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
			_error_message = STR_INDUSTRY_TOO_CLOSE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1398
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
{
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1400
	const IndustrySpec *indspec = GetIndustrySpec(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	i->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
	i->width = i->height = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
	i->type = type;
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
  1407
	IncIndustryTypeCount(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1409
	i->production_rate[0] = indspec->production_rate[0];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1410
	i->production_rate[1] = indspec->production_rate[1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	if (_patches.smooth_economy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	i->town = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
	i->owner = owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2469
diff changeset
  1420
	r = Random();
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
  1421
	i->random_color = GB(r, 8, 4);
2492
3f32f9f9fd78 (svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents: 2484
diff changeset
  1422
	i->counter = GB(r, 0, 12);
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1423
	i->produced_cargo_waiting[0] = 0;
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1424
	i->produced_cargo_waiting[1] = 0;
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1425
	i->incoming_cargo_waiting[0] = 0;
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1426
	i->incoming_cargo_waiting[1] = 0;
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  1427
	i->incoming_cargo_waiting[2] = 0;
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1428
	i->this_month_production[0] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1429
	i->this_month_production[1] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1430
	i->this_month_transported[0] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1431
	i->this_month_transported[1] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1432
	i->last_month_pct_transported[0] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1433
	i->last_month_pct_transported[1] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1434
	i->last_month_transported[0] = 0;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1435
	i->last_month_transported[1] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
	i->was_cargo_delivered = false;
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4328
diff changeset
  1437
	i->last_prod_year = _cur_year;
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1438
	i->last_month_production[0] = i->production_rate[0] * 8;
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1439
	i->last_month_production[1] = i->production_rate[1] * 8;
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  1440
	i->founder = _current_player;
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  1441
	i->construction_date = _date;
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  1442
	i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR :
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  1443
			(_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1445
	/* Adding 1 here makes it conform to specs of var44 of varaction2 for industries
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1446
	 * 0 = created prior of newindustries
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1447
	 * else, chosen layout + 1 */
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1448
	i->selected_layout = layout + 1;
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1449
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1450
	if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1451
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	i->prod_level = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
	do {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1455
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
7969
9050701304bd (svn r10980) -Fix [FS#1158] : This will hopefully fix the case of an assert that happens when an industry uses a special gfx index (tile spec 0xFF). This 0xFF is the sentinel of a special check done for oil rigs, where water need to be around, but no tile will be constructed on it.
belugas
parents: 7963
diff changeset
  1457
		if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
			byte size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1460
			size = it->ti.x;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
			if (size > i->width) i->width = size;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1462
			size = it->ti.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
			if (size > i->height)i->height = size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1465
			DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
3440
3ec61fb6c6c6 (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1467
			MakeIndustry(cur_tile, i->index, it->gfx);
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1468
			if (_generating_world) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1469
				SetIndustryConstructionCounter(cur_tile, 3);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1470
				SetIndustryConstructionStage(cur_tile, 2);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1471
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
		}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1473
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
	i->width++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
	i->height++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
  1478
	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1479
		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1485
/** Helper function for Build/Fund an industry
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1486
 * @param tile tile where industry is built
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1487
 * @param type of industry to build
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1488
 * @param flags of operations to conduct
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1489
 * @param indspec pointer to industry specifications
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1490
 * @param itspec_index the index of the itsepc to build/fund
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1491
 * @return the pointer of the newly created industry, or NULL if it failed
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1492
 */
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1493
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, uint itspec_index)
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1494
{
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1495
	const IndustryTileTable *it = indspec->table[itspec_index];
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1496
	bool custom_shape_check = false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1497
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1498
	if (!CheckIfIndustryTilesAreFree(tile, it, type, &custom_shape_check)) return NULL;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1499
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1500
	if (HASBIT(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) {
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1501
		if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index)) return NULL;
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1502
	} else {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1503
		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1504
	}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1505
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1506
	if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1507
	if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1508
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1509
	const Town *t = CheckMultipleIndustryInTown(tile, type);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1510
	if (t == NULL) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1511
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1512
	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1513
	if (!CheckSuitableIndustryPos(tile)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1514
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
  1515
	Industry *i = new Industry(tile);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1516
	if (i == NULL) return NULL;
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
  1517
	AutoPtrT<Industry> i_auto_delete = i;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1518
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1519
	if (flags & DC_EXEC) {
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7703
diff changeset
  1520
		if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  1521
		DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE);
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
  1522
		i_auto_delete.Detach();
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1523
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1524
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1525
	return i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1526
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1527
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1528
/** Build/Fund an industry
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1529
 * @param tile tile where industry is built
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1530
 * @param flags of operations to conduct
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1531
 * @param p1 industry type see build_industry.h and see industry.h
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1532
 * @param p2 unused
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1533
 * @return index of the newly create industry, or CMD_ERROR if it failed
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1534
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7406
diff changeset
  1535
CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
	const IndustryTileTable * const *itt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
	const IndustryTileTable *it;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1540
	const IndustrySpec *indspec;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
4965
9d4ad0851fde (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
  1544
	indspec = GetIndustrySpec(p1);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1545
4965
9d4ad0851fde (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
  1546
	/* Check if the to-be built/founded industry is available for this climate. */
7244
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1547
	if (!indspec->enabled) {
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1548
		return CMD_ERROR;
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1549
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1551
	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
7681
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1552
	 * Raw material industries are industries that do not accept cargo (at least for now) */
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1553
	if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1554
		return CMD_ERROR;
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1555
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1557
	if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
7673
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1558
		if (flags & DC_EXEC) {
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1559
			/* Prospecting has a chance to fail, however we cannot guarantee that something can
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1560
			 * be built on the map, so the chance gets lower when the map is fuller, but there
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1561
			 * is nothing we can really do about that. */
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1562
			if (Random() <= indspec->prospecting_chance) {
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1563
				for (int i = 0; i < 5000; i++) {
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1564
					uint tilespec_index = RandomRange(indspec->num_table);
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1565
					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, tilespec_index);
7699
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1566
					if (ind != NULL) {
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1567
						SetDParam(0, indspec->name);
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1568
						SetDParam(1, ind->town->index);
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1569
						AddNewsItem(indspec->new_industry_text,
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1570
								NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1571
						break;
c750f7b360b9 (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7695
diff changeset
  1572
					}
7673
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1573
				}
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1574
			}
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1575
		}
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1576
	} else {
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1577
		num = indspec->num_table;
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1578
		itt = indspec->table;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
7673
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1581
		do {
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1582
			if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1583
		} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1584
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1585
		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
7673
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1586
	}
3ab9344bd532 (svn r10451) -Add: support for "prospecting" raw industries, i.e. you pay an amount of money and then it might (with a given chance) build a raw industry somewhere on the map.
rubidium
parents: 7664
diff changeset
  1587
7681
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1588
	return CommandCost(indspec->GetConstructionCost());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
3538
3eb71c726341 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
  1592
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1594
	const IndustrySpec *indspec = GetIndustrySpec(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7701
diff changeset
  1596
	return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
7834
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1599
enum {
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1600
	NB_NUMOFINDUSTRY = 11,
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1601
	NB_DIFFICULTY_LEVEL = 5,
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1602
};
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1603
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1604
static const byte _numof_industry_table[NB_DIFFICULTY_LEVEL][NB_NUMOFINDUSTRY] = {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1605
	/* difficulty settings for number of industries */
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1606
	{0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0},   //none
7056
b4f146586c97 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 7015
diff changeset
  1607
	{0, 1, 1, 1, 1, 1, 1, 1,  1,  1,  1},   //very low
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1608
	{0, 1, 1, 1, 2, 2, 3, 3,  4,  4,  5},   //low
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1609
	{0, 1, 2, 3, 4, 5, 6, 7,  8,  9, 10},   //normal
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1610
	{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10},   //high
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1612
6938
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1613
/** This function is the one who really do the creation work
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1614
 * of random industries during game creation
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1615
 * @param type IndustryType of the desired industry
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1616
 * @param amount of industries that need to be built */
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1617
static void PlaceInitialIndustry(IndustryType type, int amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
{
7834
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1619
	/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1620
	 * _numof_industry_table.  newgrf can specify a big amount */
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1621
	int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_opt.diff.number_industries][amount];
7253
18dca03d0c67 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 7245
diff changeset
  1622
	const IndustrySpec *ind_spc = GetIndustrySpec(type);
2072
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1623
6938
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1624
	/* These are always placed next to the coastline, so we scale by the perimeter instead. */
7253
18dca03d0c67 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 7245
diff changeset
  1625
	num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1626
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1627
	if (_opt.diff.number_industries != 0) {
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1628
		PlayerID old_player = _current_player;
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1629
		_current_player = OWNER_NONE;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1630
		assert(num > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
		do {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1633
			uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1634
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1635
			IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1636
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1637
			for (i = 0; i < 2000; i++) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1638
				if (CreateNewIndustry(RandomTile(), type) != NULL) break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1639
			}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1640
		} while (--num);
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1641
267
dc6103ea959d (svn r273) -Fix: sorry, wrongly fixed
darkvater
parents: 266
diff changeset
  1642
		_current_player = old_player;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1643
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
6938
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1646
/** This function will create ramdon industries during game creation.
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1647
 * It will scale the amount of industries by map size as well as difficulty level */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  1648
void GenerateIndustries()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1650
	uint i = 0;
6938
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1651
	uint8 chance;
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1652
	IndustryType it;
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1653
	const IndustrySpec *ind_spc;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1654
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1655
	/* Find the total amount of industries */
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1656
	if (_opt.diff.number_industries > 0) {
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7789
diff changeset
  1657
		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1658
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1659
			ind_spc = GetIndustrySpec(it);
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1660
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1661
			if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) {
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1662
				ResetIndustryCreationProbility(it);
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1663
			}
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1664
7244
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1665
			chance = ind_spc->appear_creation[_opt.landscape];
7758
69238219f5d2 (svn r10575) -Fix r10573: misplaced )
glx
parents: 7757
diff changeset
  1666
			if (ind_spc->enabled && chance > 0) {
7244
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1667
				/* once the chance of appearance is determind, it have to be scaled by
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1668
				 * the difficulty level. The "chance" in question is more an index into
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1669
				 * the _numof_industry_table,in fact */
7834
00abd0f1ea03 (svn r10701) -Codechange: Make sure to not use an out of bound index when the index is specified by a grf file. It has a different meaning then.
belugas
parents: 7833
diff changeset
  1670
				int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_opt.diff.number_industries][chance];
6938
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1671
7244
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1672
				/* These are always placed next to the coastline, so we scale by the perimeter instead. */
7253
18dca03d0c67 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 7245
diff changeset
  1673
				num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
7244
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1674
				i += num;
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1675
			}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1676
		}
6938
37018cdc1ea3 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6934
diff changeset
  1677
	}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1678
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1679
	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1681
	if (_opt.diff.number_industries > 0) {
7815
04deaeb181ab (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7789
diff changeset
  1682
		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1683
			/* Once the number of industries has been determined, let's really create them.
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1684
			 * The test for chance allows us to try create industries that are available only
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1685
			 * for this landscape.
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1686
			 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1687
			 *          processed that scaling above? No, don't think so.  Will find a way. */
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1688
			ind_spc = GetIndustrySpec(it);
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1689
			if (ind_spc->enabled) {
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1690
				chance = ind_spc->appear_creation[_opt.landscape];
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1691
				if (chance > 0) PlaceInitialIndustry(it, chance);
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1692
			}
7244
7baac45a972c (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 7239
diff changeset
  1693
		}
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1694
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1695
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
8104
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1697
/**
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1698
 * Protects an industry from closure if the appropriate flags and conditions are met
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1699
 * INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1700
 * count of industries of this type must one (or lower) in order to be protected
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1701
 * against closure.
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1702
 * @param type IndustryType been queried
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1703
 * @result true if protection is on, false otherwise (except for oil wells)
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1704
 */
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1705
static bool CheckIndustryCloseDownProtection(IndustryType type)
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1706
{
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1707
	const IndustrySpec *indspec = GetIndustrySpec(type);
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1708
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1709
	/* oil wells (or the industries with that flag set) are always allowed to closedown */
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1710
	if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _opt.landscape == LT_TEMPERATE) return false;
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1711
	return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE && GetIndustryTypeCount(type) <= 1);
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1712
}
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1713
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1714
7784
efb98124ce51 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7762
diff changeset
  1715
/** Change industry production or do closure
efb98124ce51 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7762
diff changeset
  1716
 * @param i Industry for which changes are performed
efb98124ce51 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7762
diff changeset
  1717
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
static void ExtChangeIndustryProduction(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
{
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1720
	bool closeit = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
	int j;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1722
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1724
	if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
7578
c9aa99cf6f80 (svn r10347) -Fix [FS#948]: industries with a very low production could never recover when using smooth economy.
rubidium
parents: 7571
diff changeset
  1725
7641
6fb5fa2bab4b (svn r10419) -Fix (r10418): do not compare bitmasks with HASBIT. Thanks to Maedhros for spotting this.
rubidium
parents: 7640
diff changeset
  1726
	if ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1727
		for (j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1728
			uint32 r = Random();
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1729
			int old_prod, new_prod, percent;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1730
			int mag;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1731
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1732
			new_prod = old_prod = i->production_rate[j];
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1733
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1734
			if (CHANCE16I(20, 1024, r)) new_prod -= max(((RandomRange(50) + 10) * old_prod) >> 8, 1U);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1735
			/* Chance of increasing becomes better when more is transported */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1736
			if (CHANCE16I(20 + (i->last_month_pct_transported[j] * 20 >> 8), 1024, r >> 16) &&
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1737
					((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) == 0 || _opt.landscape != LT_TEMPERATE)) {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1738
				new_prod += max(((RandomRange(50) + 10) * old_prod) >> 8, 1U);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
			}
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1740
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1741
			new_prod = clamp(new_prod, 1, 255);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1742
			/* Do not stop closing the industry when it has the lowest possible production rate */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1743
			if (new_prod == old_prod && old_prod > 1) {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1744
				closeit = false;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1745
				continue;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1746
			}
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1747
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1748
			percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1749
			i->production_rate[j] = new_prod;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1750
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1751
			/* Close the industry when it has the lowest possible production rate */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1752
			if (new_prod > 1) closeit = false;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1753
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1754
			mag = abs(percent);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1755
			if (mag >= 10) {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1756
				SetDParam(2, mag);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1757
				SetDParam(0, GetCargo(indspec->produced_cargo[j])->name);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1758
				SetDParam(1, i->index);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1759
				AddNewsItem(
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1760
					percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1761
					NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ECONOMY, 0),
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1762
					i->xy + TileDiffXY(1, 1), 0
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1763
				);
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1764
			}
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1765
		}
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1766
	}
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1767
7641
6fb5fa2bab4b (svn r10419) -Fix (r10418): do not compare bitmasks with HASBIT. Thanks to Maedhros for spotting this.
rubidium
parents: 7640
diff changeset
  1768
	if ((indspec->life_type & INDUSTRYLIFE_PROCESSING) != 0) {
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1769
		if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180)) closeit = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1772
	/* If industry will be closed down, show this */
8104
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1773
	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
		i->prod_level = 0;
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1775
		SetDParam(0, i->index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1776
		AddNewsItem(
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1777
			indspec->closure_text,
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6964
diff changeset
  1778
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0),
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1779
			i->xy + TileDiffXY(1, 1), 0
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1780
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
static void UpdateIndustryStatistics(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1786
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
	byte pct;
6963
a1d2ec84c7bb (svn r9643) -Codechange: Simplify a test.
belugas
parents: 6938
diff changeset
  1788
	bool refresh = false;
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1789
	const IndustrySpec *indsp = GetIndustrySpec(i->type);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1790
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1791
	for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1792
		if (indsp->produced_cargo[j] != CT_INVALID) {
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1793
			pct = 0;
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1794
			if (i->this_month_production[j] != 0) {
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1795
				i->last_prod_year = _cur_year;
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1796
				pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255);
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1797
			}
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1798
			i->last_month_pct_transported[j] = pct;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1800
			i->last_month_production[j] = i->this_month_production[j];
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1801
			i->this_month_production[j] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1803
			i->last_month_transported[j] = i->this_month_transported[j];
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  1804
			i->this_month_transported[j] = 0;
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1805
			refresh = true;
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  1806
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
6963
a1d2ec84c7bb (svn r9643) -Codechange: Simplify a test.
belugas
parents: 6938
diff changeset
  1809
	if (refresh)
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1810
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1812
	if (i->prod_level == 0) {
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
  1813
		delete i;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1814
	} else if (_patches.smooth_economy) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
		ExtChangeIndustryProduction(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1816
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1819
/** Simple helper that will collect data for the generation of industries */
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1820
struct ProbabilityHelper {
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1821
	uint16 prob;      ///< probability
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1822
	IndustryType ind; ///< industry id correcponding
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1823
};
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1824
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1825
/**
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1826
 * Try to create a random industry, during gameplay
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1827
 */
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1828
static void MaybeNewIndustry(void)
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1829
{
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1830
	Industry *ind;               //will receive the industry's creation pointer
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1831
	IndustryType rndtype, j;     // Loop controlers
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1832
	const IndustrySpec *ind_spc;
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1833
	uint num = 0;
6989
43b359b4cb86 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6987
diff changeset
  1834
	ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1835
	uint16 probability_max = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1836
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1837
	/* Generate a list of all possible industries that can be built. */
6989
43b359b4cb86 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6987
diff changeset
  1838
	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1839
		byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
7757
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1841
		/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1842
		 * and if appearing chance for this landscape is above 0, this industry can be chosen */
6335bd827212 (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7725
diff changeset
  1843
		if (CheckIfCallBackAllowsAvailability(j, IACT_RANDOMCREATION) && chance != 0) {
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1844
			probability_max += chance;
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1845
			/* adds the result for this industry */
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1846
			cumulative_probs[num].ind = j;
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1847
			cumulative_probs[num++].prob = probability_max;
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1848
		}
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1849
	}
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1850
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1851
	/* Find a random type, with maximum being what has been evaluate above*/
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1852
	rndtype = RandomRange(probability_max);
6989
43b359b4cb86 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6987
diff changeset
  1853
	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1854
		/* and choose the index of the industry that matches as close as possible this random type */
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1855
		if (cumulative_probs[j].prob >= rndtype) break;
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1856
	}
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1857
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1858
	ind_spc = GetIndustrySpec(cumulative_probs[j].ind);
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1859
	/*  Check if it is allowed */
6886
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
  1860
	if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return;
742e1d75f442 (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas
parents: 6683
diff changeset
  1861
	if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1863
	/* try to create 2000 times this industry */
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1864
	num = 2000;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1865
	for (;;) {
6927
0ed416264b17 (svn r9567) -Fix(9555, FS#718): The industry ID been collected was just an index in a out of phase array. Now, ensure that the ID will really be an IndustryType
belugas
parents: 6923
diff changeset
  1866
		ind = CreateNewIndustry(RandomTile(), cumulative_probs[j].ind);
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1867
		if (ind != NULL) break;
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1868
		if (--num == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
6592
fe9298ade0a8 (svn r9075) -Codechange: Cleanup of industry_cmd (Step-7). Small step that is. The new industry messages do not need a series of tests. Only one property to use.
belugas
parents: 6573
diff changeset
  1871
	SetDParam(0, ind_spc->name);
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1872
	SetDParam(1, ind->town->index);
6592
fe9298ade0a8 (svn r9075) -Codechange: Cleanup of industry_cmd (Step-7). Small step that is. The new industry messages do not need a series of tests. Only one property to use.
belugas
parents: 6573
diff changeset
  1873
	AddNewsItem(ind_spc->new_industry_text,
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6964
diff changeset
  1874
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1877
static void ChangeIndustryProduction(Industry *i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1878
{
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1879
	StringID str = STR_NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	int type = i->type;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1881
	const IndustrySpec *indspec = GetIndustrySpec(type);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1882
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1883
	if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1884
7647
446896960367 (svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents: 7641
diff changeset
  1885
	if ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
446896960367 (svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents: 7641
diff changeset
  1886
		bool only_decrease = false;
446896960367 (svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents: 7641
diff changeset
  1887
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1888
		/* decrease or increase */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1889
		if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1890
			only_decrease = true;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1891
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1892
		if (only_decrease || CHANCE16(1, 3)) {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1893
			/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1894
			if (!only_decrease && (i->last_month_pct_transported[0] > 153) != CHANCE16(1, 3)) {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1895
				/* Increase production */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1896
				if (i->prod_level != 0x80) {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1897
					byte b;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1898
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1899
					i->prod_level <<= 1;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1900
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1901
					b = i->production_rate[0] * 2;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1902
					if (i->production_rate[0] >= 128)
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1903
						b = 0xFF;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1904
					i->production_rate[0] = b;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1905
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1906
					b = i->production_rate[1] * 2;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1907
					if (i->production_rate[1] >= 128)
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1908
						b = 0xFF;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1909
					i->production_rate[1] = b;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1910
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1911
					str = indspec->production_up_text;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1912
				}
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1913
			} else {
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1914
				/* Decrease production */
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1915
				if (i->prod_level == 4) {
8104
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1916
					/* Really set the production to 0 when the industrytype allows it,
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1917
					 * since it is equivalent to closing it. */
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1918
					if (!CheckIndustryCloseDownProtection(i->type)) {
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1919
						i->prod_level = 0;
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1920
						str = indspec->closure_text;
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1921
					}
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1922
				} else {
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1923
					i->prod_level >>= 1;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1924
					i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1925
					i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1926
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1927
					str = indspec->production_down_text;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
			}
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1930
		}
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1931
	}
7647
446896960367 (svn r10425) -Fix (r10418): do not compare bitmasks with HASBIT. Strike two. Forgotten code :)
belugas
parents: 7641
diff changeset
  1932
	if (indspec->life_type & INDUSTRYLIFE_PROCESSING) {
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1933
		/* maybe close */
8104
a792a30af2c8 (svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
belugas
parents: 8078
diff changeset
  1934
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2) && !CheckIndustryCloseDownProtection(i->type)) {
7640
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1935
			i->prod_level = 0;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1936
			str = indspec->closure_text;
81b9fe4a2631 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7628
diff changeset
  1937
		}
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1938
	}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1939
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1940
	if (str != STR_NULL) {
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1941
		SetDParam(0, i->index);
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6964
diff changeset
  1942
		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, str == indspec->closure_text ? NT_OPENCLOSE : NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  1946
void IndustryMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
	Industry *i;
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1949
	PlayerID old_player = _current_player;
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1950
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1952
	FOR_ALL_INDUSTRIES(i) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1953
		UpdateIndustryStatistics(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1955
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1956
	/* 3% chance that we start a new industry */
6929
35899001a413 (svn r9569) -Fix(r9567): testing mode leftover...
belugas
parents: 6927
diff changeset
  1957
	if (CHANCE16(3, 100)) {
6915
99e67df845fd (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6886
diff changeset
  1958
		MaybeNewIndustry();
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
  1959
	} else if (!_patches.smooth_economy) {
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
  1960
		i = GetRandomIndustry();
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
  1961
		if (i != NULL) ChangeIndustryProduction(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
	}
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1963
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1964
	_current_player = old_player;
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1965
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  1966
	/* production-change */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  1972
void InitializeIndustries()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
{
7897
222641b84fc4 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7886
diff changeset
  1974
	_Industry_pool.CleanPool();
222641b84fc4 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7886
diff changeset
  1975
	_Industry_pool.AddBlockToPool();
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1976
7335
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7320
diff changeset
  1977
	ResetIndustryCounts();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1978
	_industry_sort_dirty = true;
4587
47bdc67193da (svn r6437) -Fix: reset the location of the last sound as that location can be outside the map when you are loading another (smaller) map. Thanks to MeusH for noticing.
rubidium
parents: 4583
diff changeset
  1979
	_industry_sound_tile = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
7681
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1982
bool IndustrySpec::IsRawIndustry() const
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1983
{
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1984
	/* Lumber mills are extractive/organic, but can always be built like a non-raw industry */
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1985
	return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0 &&
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1986
			(this->behaviour & INDUSTRYBEH_CUT_TREES) == 0;
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1987
}
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1988
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1989
Money IndustrySpec::GetConstructionCost() const
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1990
{
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1991
	return (_price.build_industry *
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1992
			(_patches.raw_industry_construction == 1 && this->IsRawIndustry() ?
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1993
					this->raw_industry_cost_multiplier :
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1994
					this->cost_multiplier
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1995
			)) >> 8;
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1996
}
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  1997
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7976
diff changeset
  1998
static CommandCost TerraformTile_Industry(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7976
diff changeset
  1999
{
8078
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2000
	if (AutoslopeEnabled()) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2001
		/* We imitate here TTDP's behaviour:
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2002
		 *  - Both new and old slope must not be steep.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2003
		 *  - TileMaxZ must not be changed.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2004
		 *  - Allow autoslope by default.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2005
		 *  - Disallow autoslope if callback succeeds and returns non-zero.
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2006
		 */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2007
		Slope tileh_old = GetTileSlope(tile, NULL);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2008
		/* TileMaxZ must not be changed. Slopes must not be steep. */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2009
		if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2010
			const IndustryGfx gfx = GetIndustryGfx(tile);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2011
			const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2012
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2013
			/* Call callback 3C 'disable autosloping for industry tiles'. */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2014
			if (HASBIT(itspec->callback_flags, CBM_INDT_AUTOSLOPE)) {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2015
				/* If the callback fails, allow autoslope. */
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2016
				uint16 res = GetIndustryTileCallback(CBID_INDUSTRY_AUTOSLOPE, 0, 0, gfx, GetIndustryByTile(tile), tile);
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2017
				if ((res == 0) || (res == CALLBACK_FAILED)) return _price.terraform;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2018
			} else {
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2019
				// allow autoslope
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2020
				return _price.terraform;
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2021
			}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2022
		}
bdf94bf88568 (svn r11107) -Feature: some tool so one can still build tunnels under rails (and other structures) when the owner of the structure built it on foundations and if you have enough "empty" space ofcourse. One could use the tool for some other construction needs too. Patch by frosch.
rubidium
parents: 8073
diff changeset
  2023
	}
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7976
diff changeset
  2024
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); // funny magic bulldozer
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7976
diff changeset
  2025
}
7681
0105448f6e5c (svn r10459) -Codechange: add helper functions to determine whether an industry is a primary industry and how much it costs to build such an industry.
rubidium
parents: 7673
diff changeset
  2026
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2027
extern const TileTypeProcs _tile_type_industry_procs = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2028
	DrawTile_Industry,           /* draw_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2029
	GetSlopeZ_Industry,          /* get_slope_z_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2030
	ClearTile_Industry,          /* clear_tile_proc */
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
  2031
	GetAcceptedCargo_Industry,   /* get_accepted_cargo_proc */
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2032
	GetTileDesc_Industry,        /* get_tile_desc_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2033
	GetTileTrackStatus_Industry, /* get_tile_track_status_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2034
	ClickTile_Industry,          /* click_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2035
	AnimateTile_Industry,        /* animate_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2036
	TileLoop_Industry,           /* tile_loop_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2037
	ChangeTileOwner_Industry,    /* change_tile_owner_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2038
	GetProducedCargo_Industry,   /* get_produced_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  2039
	NULL,                        /* vehicle_enter_tile_proc */
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7830
diff changeset
  2040
	GetFoundation_Industry,      /* get_foundation_proc */
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7976
diff changeset
  2041
	TerraformTile_Industry,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2043
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1800
diff changeset
  2044
static const SaveLoad _industry_desc[] = {
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2045
	SLE_CONDVAR(Industry, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2046
	SLE_CONDVAR(Industry, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2047
	    SLE_VAR(Industry, width,                      SLE_UINT8),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2048
	    SLE_VAR(Industry, height,                     SLE_UINT8),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2049
	    SLE_REF(Industry, town,                       REF_TOWN),
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  2050
	SLE_CONDNULL( 2, 2, 60),       ///< used to be industry's produced_cargo
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  2051
	SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16, 3,              70, SL_MAX_VERSION),
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7647
diff changeset
  2052
	    SLE_ARR(Industry, produced_cargo_waiting,     SLE_UINT16, 2),
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2053
	    SLE_ARR(Industry, production_rate,            SLE_UINT8,  2),
7132
08abbae3073e (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
belugas
parents: 7056
diff changeset
  2054
	SLE_CONDNULL( 3, 2, 60),       ///< used to be industry's accepts_cargo
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2055
	    SLE_VAR(Industry, prod_level,                 SLE_UINT8),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2056
	    SLE_ARR(Industry, this_month_production,      SLE_UINT16, 2),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2057
	    SLE_ARR(Industry, this_month_transported,     SLE_UINT16, 2),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2058
	    SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8,  2),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2059
	    SLE_ARR(Industry, last_month_production,      SLE_UINT16, 2),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2060
	    SLE_ARR(Industry, last_month_transported,     SLE_UINT16, 2),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2061
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2062
	    SLE_VAR(Industry, counter,                    SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
7315
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2064
	    SLE_VAR(Industry, type,                       SLE_UINT8),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2065
	    SLE_VAR(Industry, owner,                      SLE_UINT8),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2066
	    SLE_VAR(Industry, random_color,               SLE_UINT8),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2067
	SLE_CONDVAR(Industry, last_prod_year,             SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2068
	SLE_CONDVAR(Industry, last_prod_year,             SLE_INT32,                 31, SL_MAX_VERSION),
f1b2591ad082 (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium
parents: 7311
diff changeset
  2069
	    SLE_VAR(Industry, was_cargo_delivered,        SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
8018
03b60ab13605 (svn r11041) -Fix (r10460) [FS#1195]: the industry's owner was saved twice instead of the owner and the founder. Patch by frosch.
rubidium
parents: 7990
diff changeset
  2071
	SLE_CONDVAR(Industry, founder,                    SLE_UINT8,                 70, SL_MAX_VERSION),
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  2072
	SLE_CONDVAR(Industry, construction_date,          SLE_INT32,                 70, SL_MAX_VERSION),
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  2073
	SLE_CONDVAR(Industry, construction_type,          SLE_UINT8,                 70, SL_MAX_VERSION),
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  2074
	SLE_CONDVAR(Industry, last_cargo_accepted_at,     SLE_INT32,                 70, SL_MAX_VERSION),
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7916
diff changeset
  2075
	SLE_CONDVAR(Industry, selected_layout,            SLE_UINT8,                 73, SL_MAX_VERSION),
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7681
diff changeset
  2076
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6418
diff changeset
  2077
	/* reserve extra space in savegame here. (currently 32 bytes) */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3173
diff changeset
  2078
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2081
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2083
static void Save_INDY()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
	Industry *ind;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2086
7784
efb98124ce51 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7762
diff changeset
  2087
	/* Write the industries */
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  2088
	FOR_ALL_INDUSTRIES(ind) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2089
		SlSetArrayIndex(ind->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2090
		SlObject(ind, _industry_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
7786
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2094
/* Save and load the mapping between the industry/tile id on the map, and the grf file
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2095
 * it came from. */
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2096
static const SaveLoad _industries_id_mapping_desc[] = {
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2097
	SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2098
	SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2099
	SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2100
	SLE_END()
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2101
};
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2102
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2103
static void Save_IIDS()
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2104
{
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2105
	uint i;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2106
	uint j = _industry_mngr.GetMaxMapping();
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2107
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2108
	for (i = 0; i < j; i++) {
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2109
		SlSetArrayIndex(i);
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2110
		SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2111
	}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2112
}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2113
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2114
static void Save_TIDS()
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2115
{
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2116
	uint i;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2117
	uint j = _industile_mngr.GetMaxMapping();
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2118
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2119
	for (i = 0; i < j; i++) {
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2120
		SlSetArrayIndex(i);
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2121
		SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2122
	}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2123
}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2124
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
  2125
static void Load_INDY()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
	int index;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  2128
7335
027d2caa4646 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 7320
diff changeset
  2129
	ResetIndustryCounts();
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  2130
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
	while ((index = SlIterateArray()) != -1) {
7886
b02aa3532d1d (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7834
diff changeset
  2132
		Industry *i = new (index) Industry();
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2133
		SlObject(i, _industry_desc);
7320
052da893fbd9 (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 7315
diff changeset
  2134
		IncIndustryTypeCount(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
7786
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2138
static void Load_IIDS()
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2139
{
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2140
	int index;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2141
	uint max_id;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2142
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2143
	/* clear the current mapping stored.
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2144
	 * This will create the manager if ever it is not yet done */
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2145
	_industry_mngr.ResetMapping();
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2146
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2147
	/* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2148
	max_id = _industry_mngr.GetMaxMapping();
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2149
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2150
	while ((index = SlIterateArray()) != -1) {
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2151
		if ((uint)index >= max_id) break;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2152
		SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2153
	}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2154
}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2155
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2156
static void Load_TIDS()
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2157
{
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2158
	int index;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2159
	uint max_id;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2160
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2161
	/* clear the current mapping stored.
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2162
	 * This will create the manager if ever it is not yet done */
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2163
	_industile_mngr.ResetMapping();
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2164
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2165
	/* get boundary for the temporary map loader NUM_INDUSTILES? */
7788
0728ab7b5253 (svn r10640) -Fix(r10638): little typo...
belugas
parents: 7787
diff changeset
  2166
	max_id = _industile_mngr.GetMaxMapping();
7786
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2167
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2168
	while ((index = SlIterateArray()) != -1) {
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2169
		if ((uint)index >= max_id) break;
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2170
		SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2171
	}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2172
}
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2173
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  2174
extern const ChunkHandler _industry_chunk_handlers[] = {
7786
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2175
	{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY},
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2176
	{ 'IIDS', Save_IIDS, Load_IIDS, CH_ARRAY},
7a03d776107a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7784
diff changeset
  2177
	{ 'TIDS', Save_TIDS, Load_TIDS, CH_ARRAY | CH_LAST},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2178
};