src/industry_cmd.cpp
author rubidium
Sun, 06 Apr 2008 15:09:45 +0000
changeset 8843 45fdf630deaa
parent 8840 332412c2e9c1
child 8847 426dd2d582e7
permissions -rw-r--r--
(svn r12593) -Codechange: hide Order's flags in most of the code.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
     3
/** @file industry_cmd.cpp */
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3094
diff changeset
     7
#include "clear_map.h"
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
     8
#include "industry_map.h"
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3331
diff changeset
     9
#include "station_map.h"
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
    10
#include "train.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6307
diff changeset
    11
#include "landscape.h"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8203
diff changeset
    12
#include "viewport_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    13
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "town.h"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8656
diff changeset
    16
#include "news_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "saveload.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    18
#include "variables.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    19
#include "genworld.h"
5056
8fabd0020af7 (svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents: 4976
diff changeset
    20
#include "water_map.h"
5909
35595e20c0c4 (svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents: 5884
diff changeset
    21
#include "tree_map.h"
6091
c8827d9ae04a (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: 5909
diff changeset
    22
#include "cargotype.h"
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
    23
#include "newgrf.h"
7293
e62b277bc10e (svn r10641) -Fix(r10638): Forgotten Son... err...include
belugas
parents: 7292
diff changeset
    24
#include "newgrf_commons.h"
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7165
diff changeset
    25
#include "newgrf_industries.h"
6970
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
    26
#include "newgrf_industrytiles.h"
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
    27
#include "newgrf_callbacks.h"
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
    28
#include "misc/autoptr.hpp"
7582
80c8517b08d1 (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: 7577
diff changeset
    29
#include "autoslope.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7823
diff changeset
    30
#include "transparency.h"
7948
e408508f5727 (svn r11504) -Fix [FS#1467]: removing docks/ship depots could result in non-canal water where canals should have been build.
rubidium
parents: 7947
diff changeset
    31
#include "water.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8108
diff changeset
    32
#include "strings_func.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    33
#include "tile_cmd.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8119
diff changeset
    34
#include "functions.h"
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8119
diff changeset
    35
#include "window_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    36
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    37
#include "vehicle_func.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8154
diff changeset
    38
#include "sound_func.h"
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8763
diff changeset
    39
#include "station_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8234
diff changeset
    41
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8234
diff changeset
    42
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8234
diff changeset
    43
#include "table/industry_land.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8234
diff changeset
    44
#include "table/build_industry.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8234
diff changeset
    45
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    46
void ShowIndustryViewWindow(int industry);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    47
void BuildOilRig(TileIndex tile);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    48
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    49
static byte _industry_sound_ctr;
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    50
static TileIndex _industry_sound_tile;
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    51
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
    52
int _total_industries;                      //general counter
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
    53
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
    54
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
    55
const Industry **_industry_sort;
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
    56
bool _industry_sort_dirty;
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
    57
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    58
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    59
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    60
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    61
/** This function initialize the spec arrays of both
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    62
 * industry and industry tiles.
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    63
 * It adjusts the enabling of the industry too, based on climate availability.
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    64
 * This will allow for clearer testings */
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    65
void ResetIndustries()
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    66
{
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    67
	memset(&_industry_specs, 0, sizeof(_industry_specs));
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    68
	memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs));
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    69
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    70
	/* once performed, enable only the current climate industries */
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    71
	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
7654
533a9c9a5e83 (svn r11185) -Codechange: prepare some more code for the introduction of NewIndustries. Patch by Belugas.
rubidium
parents: 7650
diff changeset
    72
		_industry_specs[i].enabled = i < NEW_INDUSTRYOFFSET &&
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
    73
				HasBit(_origin_industry_specs[i].climate_availability, _opt.landscape);
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    74
	}
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    75
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    76
	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    77
	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
7666
69cabc700c4d (svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents: 7663
diff changeset
    78
69cabc700c4d (svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents: 7663
diff changeset
    79
	/* Reset any overrides that have been set. */
69cabc700c4d (svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents: 7663
diff changeset
    80
	_industile_mngr.ResetOverride();
69cabc700c4d (svn r11197) -Fix: It is not useful to reset the override of an entity every time a new grf file is been submitted.
belugas
parents: 7663
diff changeset
    81
	_industry_mngr.ResetOverride();
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    82
}
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
    83
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
    84
void ResetIndustryCreationProbility(IndustryType type)
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
    85
{
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
    86
	assert(type < INVALID_INDUSTRYTYPE);
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
    87
	_industry_specs[type].appear_creation[_opt.landscape] = 0;
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
    88
}
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
    89
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
    90
DEFINE_OLD_POOL_GENERIC(Industry, Industry)
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    91
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    92
/**
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    93
 * Retrieve the type for this industry.  Although it is accessed by a tile,
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    94
 * it will return the general type of industry, and not the sprite index
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    95
 * as would do GetIndustryGfx.
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    96
 * @param tile that is queried
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    97
 * @pre IsTileType(tile, MP_INDUSTRY)
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    98
 * @return general type for this industry, as defined in industry.h
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    99
 **/
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   100
IndustryType GetIndustryType(TileIndex tile)
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   101
{
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   102
	assert(IsTileType(tile, MP_INDUSTRY));
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   103
6639
d9e4445b518d (svn r9870) -Codechange: Silence two compiler warnings and give proper type to the "type" member of industry struct
belugas
parents: 6636
diff changeset
   104
	const Industry *ind = GetIndustryByTile(tile);
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   105
	return ind->IsValid() ? ind->type : (IndustryType)IT_INVALID;
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   106
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   108
/**
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   109
 * Accessor for array _industry_specs.
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   110
 * This will ensure at once : proper access and
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   111
 * not allowing modifications of it.
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   112
 * @param thistype of industry (which is the index in _industry_specs)
6493
6bbb7ebd6a31 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6491
diff changeset
   113
 * @pre thistype < NUM_INDUSTRYTYPES
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   114
 * @return a pointer to the corresponding industry spec
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   115
 **/
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3669
diff changeset
   116
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   117
{
6493
6bbb7ebd6a31 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6491
diff changeset
   118
	assert(thistype < NUM_INDUSTRYTYPES);
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   119
	return &_industry_specs[thistype];
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   120
}
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   121
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   122
/**
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   123
 * Accessor for array _industry_tile_specs.
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   124
 * This will ensure at once : proper access and
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   125
 * not allowing modifications of it.
7288
9059a49c2102 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7266
diff changeset
   126
 * @param gfx of industrytile (which is the index in _industry_tile_specs)
6749
be85c217e87e (svn r9984) -Codechange: Remove an obsolete structure and a now meaningless enum, in favor of the "real thing"
belugas
parents: 6748
diff changeset
   127
 * @pre gfx < INVALID_INDUSTRYTILE
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   128
 * @return a pointer to the corresponding industrytile spec
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   129
 **/
7462
74a281f80498 (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7461
diff changeset
   130
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
6092
53c6b9b18d0b (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 6091
diff changeset
   131
{
6749
be85c217e87e (svn r9984) -Codechange: Remove an obsolete structure and a now meaningless enum, in favor of the "real thing"
belugas
parents: 6748
diff changeset
   132
	assert(gfx < INVALID_INDUSTRYTILE);
7462
74a281f80498 (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7461
diff changeset
   133
	return &_industry_tile_specs[gfx];
6092
53c6b9b18d0b (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 6091
diff changeset
   134
}
53c6b9b18d0b (svn r8827) -Codechange: Cleanup of industry_cmd (Step-6). Implementation of IndustryTileSPec, the alter ego of IndustrySpec.
belugas
parents: 6091
diff changeset
   135
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   136
Industry::~Industry()
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   137
{
7420
0e3afa8102f0 (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: 7401
diff changeset
   138
	if (CleaningPool()) return;
0e3afa8102f0 (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: 7401
diff changeset
   139
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   140
	/* Industry can also be destroyed when not fully initialized.
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   141
	 * This means that we do not have to clear tiles either. */
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   142
	if (this->width == 0) {
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   143
		this->xy = 0;
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   144
		return;
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   145
	}
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   146
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   147
	BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   148
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   149
			if (GetIndustryIndex(tile_cur) == this->index) {
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   150
				DoClearSquare(tile_cur);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   151
			}
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   152
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   153
			DeleteOilRig(tile_cur);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   154
		}
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   155
	END_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   156
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   157
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   158
		/* Remove the farmland and convert it to regular tiles over time. */
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   159
		BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
4815
d702c4027451 (svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents: 4607
diff changeset
   160
			tile_cur = TILE_MASK(tile_cur);
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   161
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   162
					GetIndustryIndexOfField(tile_cur) == this->index) {
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   163
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   164
			}
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   165
		} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   166
	}
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   167
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   168
	_industry_sort_dirty = true;
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   169
	DecIndustryTypeCount(this->type);
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
   170
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   171
	DeleteSubsidyWithIndustry(this->index);
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   172
	DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   173
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   174
	this->xy = 0;
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   175
}
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   176
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   177
static void IndustryDrawSugarMine(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   179
	const DrawIndustryAnimationStruct *d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   181
	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
   182
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   183
	d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   185
	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
   186
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   187
	if (d->image_2 != 0) {
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   188
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   189
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   191
	if (d->image_3 != 0) {
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   192
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   193
			_drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   194
	}
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
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   197
static void IndustryDrawToffeeQuarry(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
{
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   199
	uint8 x = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   200
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   201
	if (IsIndustryCompleted(ti->tile)) {
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   202
		x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)];
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   203
		if (x == 0xFF)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   207
	AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   208
	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
   209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   211
static void IndustryDrawBubbleGenerator( const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
{
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   213
	if (IsIndustryCompleted(ti->tile)) {
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   214
		AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   215
	} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   216
		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
   217
	}
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
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   220
static void IndustryDrawToyFactory(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
{
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   222
	const DrawIndustryAnimationStruct *d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   224
	d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	if (d->image_1 != 0xFF) {
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   227
		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
   228
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	if (d->image_2 != 0xFF) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   231
		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
   232
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   234
	AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   235
	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
   236
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   238
static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
{
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   240
	if (IsIndustryCompleted(ti->tile)) {
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   241
		uint8 image = GetIndustryAnimationState(ti->tile);
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   242
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
		if (image != 0 && image < 7) {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   244
			AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   245
				PAL_NONE,
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   246
				_coal_plant_sparks[image - 1].x,
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   247
				_coal_plant_sparks[image - 1].y
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		}
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
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   253
typedef void IndustryDrawTileProc(const TileInfo *ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   255
	IndustryDrawSugarMine,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   256
	IndustryDrawToffeeQuarry,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   257
	IndustryDrawBubbleGenerator,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   258
	IndustryDrawToyFactory,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   259
	IndustryDrawCoalPlantSparks,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
static void DrawTile_Industry(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
{
6970
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   264
	IndustryGfx gfx = GetIndustryGfx(ti->tile);
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   265
	Industry *ind = GetIndustryByTile(ti->tile);
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   266
	const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   267
	const DrawBuildingsTileStruct *dits;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   268
	SpriteID image;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   269
	SpriteID pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
6970
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   271
	/* Retrieve pointer to the draw industry tile struct */
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   272
	if (gfx >= NEW_INDUSTRYTILEOFFSET) {
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   273
		/* Draw the tile using the specialized method of newgrf industrytile.
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   274
		 * DrawNewIndustry will return false if ever the resolver could not
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   275
		 * find any sprite to display.  So in this case, we will jump on the
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   276
		 * substitute gfx instead. */
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   277
		if (indts->grf_prop.spritegroup != NULL && DrawNewIndustryTile(ti, ind, gfx, indts)) {
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   278
			return;
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   279
		} else {
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   280
			/* No sprite group (or no valid one) found, meaning no graphics associated.
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   281
			 * Use the substitute one instead */
7461
09deed76b5d6 (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7445
diff changeset
   282
			if (indts->grf_prop.subst_id != INVALID_INDUSTRYTILE) {
09deed76b5d6 (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7445
diff changeset
   283
				gfx = indts->grf_prop.subst_id;
09deed76b5d6 (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7445
diff changeset
   284
				/* And point the industrytile spec accordingly */
09deed76b5d6 (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7445
diff changeset
   285
				indts = GetIndustryTileSpec(gfx);
09deed76b5d6 (svn r10962) -Codechange: protect yourself against an illicit substitution
belugas
parents: 7445
diff changeset
   286
			}
6970
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   287
		}
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   288
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
6970
b489d8ec5d4a (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 6950
diff changeset
   290
	dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ?
7291
5e5bc8463be7 (svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents: 7290
diff changeset
   291
			GetIndustryAnimationState(ti->tile) & INDUSTRY_COMPLETED :
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5435
diff changeset
   292
			GetIndustryConstructionStage(ti->tile))];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   294
	image = dits->ground.sprite;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   295
	if (HasBit(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   296
		pal = GENERAL_SPRITE_COLOR(ind->random_color);
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   297
	} else {
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   298
		pal = dits->ground.pal;
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   299
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
7335
141c6b86ec1f (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: 7334
diff changeset
   301
	/* DrawFoundation() modifes ti->z and ti->tileh */
141c6b86ec1f (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: 7334
diff changeset
   302
	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
   303
7035
9af867b5802a (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: 7026
diff changeset
   304
	DrawGroundSprite(image, pal);
9af867b5802a (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: 7026
diff changeset
   305
8806
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8785
diff changeset
   306
	/* If industries are transparent and invisible, do not draw the upper part */
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8785
diff changeset
   307
	if (IsInvisibilitySet(TO_INDUSTRIES)) return;
4fe163e0b52a (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 8785
diff changeset
   308
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	/* Add industry on top of the ground? */
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   310
	image = dits->building.sprite;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   311
	if (image != 0) {
7333
e48228e44be8 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7319
diff changeset
   312
		AddSortableSpriteToDraw(image,
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   313
			(HasBit(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) ? GENERAL_SPRITE_COLOR(ind->random_color) : dits->building.pal,
2653
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   314
			ti->x + dits->subtile_x,
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   315
			ti->y + dits->subtile_y,
7577
ab000224166b (svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents: 7531
diff changeset
   316
			dits->width,
ab000224166b (svn r11102) -Codechange: remove some pointless addition+substractions. Patch by frosch.
rubidium
parents: 7531
diff changeset
   317
			dits->height,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
			dits->dz,
7335
141c6b86ec1f (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: 7334
diff changeset
   319
			ti->z,
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7823
diff changeset
   320
			IsTransparencySet(TO_INDUSTRIES));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7823
diff changeset
   322
		if (IsTransparencySet(TO_INDUSTRIES)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   325
	{
3654
c09872510a61 (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   326
		int proc = dits->draw_proc - 1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   327
		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
   328
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   331
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y)
2537
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   332
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   333
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
7335
141c6b86ec1f (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: 7334
diff changeset
   336
static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   337
{
7335
141c6b86ec1f (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: 7334
diff changeset
   338
	return FlatteningFoundation(tileh);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   339
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   340
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   341
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
{
7199
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   343
	IndustryGfx gfx = GetIndustryGfx(tile);
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   344
	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   345
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   346
	/* When we have to use a callback, we put our data in the next two variables */
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   347
	CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)];
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   348
	uint8 raw_acceptance[lengthof(itspec->acceptance)];
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   349
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   350
	/* And then these will always point to a same sized array with the required data */
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   351
	const CargoID *accepts_cargo = itspec->accepts_cargo;
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   352
	const uint8 *acceptance = itspec->acceptance;
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   353
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   354
	if (HasBit(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) {
7199
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   355
		uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile);
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   356
		if (res != CALLBACK_FAILED) {
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   357
			accepts_cargo = raw_accepts_cargo;
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   358
			for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile);
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   359
		}
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   360
	}
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   361
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   362
	if (HasBit(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) {
7199
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   363
		uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile);
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   364
		if (res != CALLBACK_FAILED) {
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   365
			acceptance = raw_acceptance;
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   366
			for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4);
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   367
		}
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   368
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
6736
9f55d5e22875 (svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents: 6683
diff changeset
   370
	for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) {
7199
e65a28455ee3 (svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
rubidium
parents: 7186
diff changeset
   371
		CargoID a = accepts_cargo[i];
7655
314256ffab9d (svn r11186) -Fix: only fill the accepted cargo fields once, not multiple times.
rubidium
parents: 7654
diff changeset
   372
		/* Only set the value once. */
314256ffab9d (svn r11186) -Fix: only fill the accepted cargo fields once, not multiple times.
rubidium
parents: 7654
diff changeset
   373
		if (a != CT_INVALID && ac[a] == 0) ac[a] = acceptance[i];
6736
9f55d5e22875 (svn r9969) -Codechange: Cleanup of industries (Step-14). Remove hardcoded-run-time tile acceptance and put in corresponding tile
belugas
parents: 6683
diff changeset
   374
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   377
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
{
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   379
	const Industry *i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	td->owner = i->owner;
4942
7fb6c39eb421 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
   382
	td->str = GetIndustrySpec(i->type)->name;
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   383
	if (!IsIndustryCompleted(tile)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   384
		SetDParamX(td->dparam, 0, td->str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
		td->str = STR_2058_UNDER_CONSTRUCTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6910
diff changeset
   389
static CommandCost ClearTile_Industry(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
{
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   391
	Industry *i = GetIndustryByTile(tile);
6390
802629b3c7f1 (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: 6357
diff changeset
   392
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   394
	/* water can destroy industries
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   395
	 * in editor you can bulldoze industries
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   396
	 * with magic_bulldozer cheat you can destroy industries
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   397
	 * (area around OILRIG is water, so water shouldn't flood it
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   398
	 */
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   399
	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
   400
			!_cheats.magic_bulldozer.value) ||
7637
43e2956af72e (svn r11168) -Fix [FS#1256]: assert on terraforming of industries. Patch by frosch.
rubidium
parents: 7629
diff changeset
   401
			((flags & DC_AUTO) != 0) ||
6390
802629b3c7f1 (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: 6357
diff changeset
   402
			(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
802629b3c7f1 (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: 6357
diff changeset
   403
		SetDParam(0, indspec->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
		return_cmd_error(STR_4800_IN_THE_WAY);
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
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
   407
	if (flags & DC_EXEC) delete i;
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
   408
	return CommandCost(EXPENSES_CONSTRUCTION, indspec->GetRemovalCost());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   411
static void TransportIndustryGoods(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
{
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   413
	Industry *i = GetIndustryByTile(tile);
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   414
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
7799
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   415
	bool moved_cargo = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
7799
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   417
	for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   418
		uint cw = min(i->produced_cargo_waiting[j], 255);
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   419
		if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   420
			i->produced_cargo_waiting[j] -= cw;
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   421
7799
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   422
			/* fluctuating economy? */
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   423
			if (_economy.fluct <= 0) cw = (cw + 1) / 2;
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   424
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   425
			i->this_month_production[j] += cw;
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   426
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   427
			uint am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[j], cw);
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   428
			i->this_month_transported[j] += am;
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   429
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   430
			moved_cargo |= (am != 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
7799
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   434
	if (moved_cargo && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   435
		uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   436
7799
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   437
		if (newgfx != INDUSTRYTILE_NOANIM) {
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   438
			ResetIndustryConstructionStage(tile);
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   439
			SetIndustryCompleted(tile, true);
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   440
			SetIndustryGfx(tile, newgfx);
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   441
			MarkTileDirtyByTile(tile);
72e48b8cf207 (svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
rubidium
parents: 7760
diff changeset
   442
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   447
static void AnimateTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
{
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   449
	byte m;
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   450
	IndustryGfx gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   452
	if (GetIndustryTileSpec(gfx)->animation_info != 0xFFFF) {
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   453
		AnimateNewIndustryTile(tile);
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   454
		return;
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   455
	}
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   456
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   457
	switch (gfx) {
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   458
	case GFX_SUGAR_MINE_SIEVE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
		if ((_tick_counter & 1) == 0) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   460
			m = GetIndustryAnimationState(tile) + 1;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   461
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2868
diff changeset
   462
			switch (m & 7) {
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   463
			case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   464
			case 6: SndPlayTileFx(SND_29_RIP, tile); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
			}
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
			if (m >= 96) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
			}
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   471
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   477
	case GFX_TOFFEE_QUARY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
		if ((_tick_counter & 3) == 0) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   479
			m = GetIndustryAnimationState(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   480
6519
3207d8852fb9 (svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.
belugas
parents: 6493
diff changeset
   481
			if (_industry_anim_offs_toffee[m] == 0xFF) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   482
				SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
			}
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
			if (++m >= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
			}
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   489
			SetIndustryAnimationState(tile, m);
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
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   495
	case GFX_BUBBLE_CATCHER:
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   496
		if ((_tick_counter & 1) == 0) {
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   497
			m = GetIndustryAnimationState(tile);
0
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
			if (++m >= 40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
			}
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   503
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   509
	/* Sparks on a coal plant */
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   510
	case GFX_POWERPLANT_SPARKS:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		if ((_tick_counter & 3) == 0) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   512
			m = GetIndustryAnimationState(tile);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   513
			if (m == 6) {
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   514
				SetIndustryAnimationState(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
			} else {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   517
				SetIndustryAnimationState(tile, m + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   523
	case GFX_TOY_FACTORY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
		if ((_tick_counter & 1) == 0) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   525
			m = GetIndustryAnimationState(tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
6468
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   527
			switch (m) {
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   528
				case  1: SndPlayTileFx(SND_2C_MACHINERY, tile); break;
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   529
				case 23: SndPlayTileFx(SND_2B_COMEDY_HIT, tile); break;
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   530
				case 28: SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); break;
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   531
				default:
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   532
					if (m >= 50) {
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   533
						int n = GetIndustryAnimationLoop(tile) + 1;
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   534
						m = 0;
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   535
						if (n >= 8) {
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   536
							n = 0;
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   537
							DeleteAnimatedTile(tile);
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   538
						}
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   539
						SetIndustryAnimationLoop(tile, n);
ab54a3aeeacd (svn r9644) -Codechange: if else cascade into a switch case
belugas
parents: 6467
diff changeset
   540
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   543
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
5434
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   548
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   549
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   550
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   551
	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
   552
		if ((_tick_counter & 3) == 0) {
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   553
			IndustryGfx gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   555
			gfx = (gfx < 155) ? gfx + 1 : 148;
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   556
			SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   561
	case GFX_OILWELL_ANIMATED_1:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   562
	case GFX_OILWELL_ANIMATED_2:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   563
	case GFX_OILWELL_ANIMATED_3:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
		if ((_tick_counter & 7) == 0) {
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   565
			bool b = Chance16(1, 7);
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   566
			IndustryGfx gfx = GetIndustryGfx(tile);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   567
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   568
			m = GetIndustryAnimationState(tile) + 1;
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   569
			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   570
				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   571
				SetIndustryConstructionStage(tile, 3);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   572
				DeleteAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
			} else {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   574
				SetIndustryAnimationState(tile, m);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   575
				SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
				MarkTileDirtyByTile(tile);
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   581
	case GFX_COAL_MINE_TOWER_ANIMATED:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   582
	case GFX_COPPER_MINE_TOWER_ANIMATED:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   583
	case GFX_GOLD_MINE_TOWER_ANIMATED: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
			int state = _tick_counter & 0x7FF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
			if ((state -= 0x400) < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
			if (state < 0x1A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
				if (state < 0x20 || state >= 0x180) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   591
					m = GetIndustryAnimationState(tile);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   592
					if (!(m & 0x40)) {
5436
b3d017be25b4 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5435
diff changeset
   593
						SetIndustryAnimationState(tile, m | 0x40);
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   594
						SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
					if (state & 7)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
					if (state & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
				}
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   602
				m = (GetIndustryAnimationState(tile) + 1) | 0x40;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
				if (m > 0xC2) m = 0xC0;
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   604
				SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
			} else if (state >= 0x200 && state < 0x3A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
				int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
				i = (state < 0x220 || state >= 0x380) ? 7 : 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
				if (state & i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   612
				m = (GetIndustryAnimationState(tile) & 0xBF) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
				if (m < 0x80) m = 0x82;
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   614
				SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   621
static void CreateIndustryEffectSmoke(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
{
3773
0019b5f70ea9 (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
   623
	uint x = TileX(tile) * TILE_SIZE;
0019b5f70ea9 (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
   624
	uint y = TileY(tile) * TILE_SIZE;
0019b5f70ea9 (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
   625
	uint z = GetTileMaxZ(tile);
3094
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   626
3773
0019b5f70ea9 (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
   627
	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
   628
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
3495
6672c181ace4 (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
   630
static void MakeIndustryTileBigger(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
{
3495
6672c181ace4 (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
	byte cnt = GetIndustryConstructionCounter(tile) + 1;
6672c181ace4 (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
	byte stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
3495
6672c181ace4 (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
   635
	if (cnt != 4) {
6672c181ace4 (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
   636
		SetIndustryConstructionCounter(tile, cnt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
3495
6672c181ace4 (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
   640
	stage = GetIndustryConstructionStage(tile) + 1;
6672c181ace4 (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
   641
	SetIndustryConstructionCounter(tile, 0);
6672c181ace4 (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
   642
	SetIndustryConstructionStage(tile, stage);
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   643
	StartStopIndustryTileAnimation(tile, IAT_CONSTRUCTION_STATE_CHANGE);
7291
5e5bc8463be7 (svn r10639) -Codechange: Give meaninfull name to a magic number
belugas
parents: 7290
diff changeset
   644
	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
   645
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   648
	if (!IsIndustryCompleted(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   650
	IndustryGfx gfx = GetIndustryGfx(tile);
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   651
	if (gfx >= NEW_INDUSTRYTILEOFFSET) {
7853
4bdbe434e076 (svn r11403) -Fix: NewIndustries GRF assume that tiles are already animated during construction.
rubidium
parents: 7852
diff changeset
   652
		/* New industries are already animated on construction. */
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   653
		return;
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   654
	}
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   655
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   656
	switch (gfx) {
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   657
	case GFX_POWERPLANT_CHIMNEY:
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   658
		CreateIndustryEffectSmoke(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
4607
323a239feef7 (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
   661
	case GFX_OILRIG_1:
323a239feef7 (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
   662
		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
   663
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
3545
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   665
	case GFX_TOY_FACTORY:
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   666
	case GFX_BUBBLE_CATCHER:
b08ce1bbb589 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   667
	case GFX_TOFFEE_QUARY:
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   668
		SetIndustryAnimationState(tile, 0);
3538
750c4ea83357 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
   669
		SetIndustryAnimationLoop(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
5434
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   672
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   673
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   674
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
4739ee9714f5 (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   675
	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
   676
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   681
static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	int dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	static const int8 _tileloop_ind_case_161[12] = {
4344
7e123fec5b0b (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
   686
		11,   0, -4, -14,
7e123fec5b0b (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
   687
		-4, -10, -4,   1,
7e123fec5b0b (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
   688
		49,  59, 60,  65,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   691
	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
   692
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	dir = Random() & 3;
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
	v = CreateEffectVehicleAbove(
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   696
		TileX(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 0],
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   697
		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
   698
		_tileloop_ind_case_161[dir + 8],
1359
52782e5cf7c9 (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
   699
		EV_BUBBLE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
7334
ed9a43cf642a (svn r10697) -Codechange: give a more sensible names to some of the unkX variables.
rubidium
parents: 7333
diff changeset
   702
	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
   703
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   705
static void TileLoop_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
{
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   707
	IndustryGfx newgfx;
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   708
	IndustryGfx gfx;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7853
diff changeset
   710
	TriggerIndustryTile(tile, INDTILE_TRIGGER_TILE_LOOP);
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7853
diff changeset
   711
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   712
	if (!IsIndustryCompleted(tile)) {
3495
6672c181ace4 (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
   713
		MakeIndustryTileBigger(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   717
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	TransportIndustryGoods(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   721
	if (StartStopIndustryTileAnimation(tile, IAT_TILELOOP)) return;
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
   722
6305
185ebf766d4e (svn r9162) -Codechange: Cleanup of industry_cmd (Step-8). Gather tile animation data into IndustryTileSpec array
belugas
parents: 6283
diff changeset
   723
	newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next;
6743
e84a3b89d46b (svn r9976) -Codechange: Declare a writable array of specs for industry and industry tiles.
belugas
parents: 6736
diff changeset
   724
	if (newgfx != INDUSTRYTILE_NOANIM) {
3495
6672c181ace4 (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
   725
		ResetIndustryConstructionStage(tile);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   726
		SetIndustryGfx(tile, newgfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   731
	gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   733
	switch (gfx) {
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   734
	case GFX_OILRIG_1: // coast line at oilrigs
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   735
	case GFX_OILRIG_2:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   736
	case GFX_OILRIG_3:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   737
	case GFX_OILRIG_4:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   738
	case GFX_OILRIG_5:
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   739
		TileLoop_Water(tile);
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   740
		break;
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   741
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   742
	case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   743
	case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   744
	case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   745
		if (!(_tick_counter & 0x400) && Chance16(1, 2)) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   746
			switch (gfx) {
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   747
				case GFX_COAL_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_ANIMATED;   break;
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   748
				case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break;
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   749
				case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_ANIMATED;   break;
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   750
			}
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   751
			SetIndustryGfx(tile, gfx);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   752
			SetIndustryAnimationState(tile, 0x80);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   753
			AddAnimatedTile(tile);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
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
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   757
	case GFX_OILWELL_NOT_ANIMATED:
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   758
		if (Chance16(1, 6)) {
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   759
			SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   760
			SetIndustryAnimationState(tile, 0);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   761
			AddAnimatedTile(tile);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   762
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   765
	case GFX_COAL_MINE_TOWER_ANIMATED:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   766
	case GFX_COPPER_MINE_TOWER_ANIMATED:
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   767
	case GFX_GOLD_MINE_TOWER_ANIMATED:
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   768
		if (!(_tick_counter & 0x400)) {
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   769
			switch (gfx) {
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   770
				case GFX_COAL_MINE_TOWER_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED;   break;
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   771
				case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break;
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   772
				case GFX_GOLD_MINE_TOWER_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED;   break;
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   773
			}
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   774
			SetIndustryGfx(tile, gfx);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   775
			SetIndustryCompleted(tile, true);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   776
			SetIndustryConstructionStage(tile, 3);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   777
			DeleteAnimatedTile(tile);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
   778
		}
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   779
		break;
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   780
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   781
	case GFX_POWERPLANT_SPARKS:
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   782
		if (Chance16(1, 3)) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   783
			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
			AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   788
	case GFX_COPPER_MINE_CHIMNEY:
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   789
		CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   790
		break;
0
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
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   793
	case GFX_TOY_FACTORY: {
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   794
			Industry *i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
			if (i->was_cargo_delivered) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
				i->was_cargo_delivered = false;
3538
750c4ea83357 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
   797
				SetIndustryAnimationLoop(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
				AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
		}
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
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   803
	case GFX_BUBBLE_GENERATOR:
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   804
		TileLoopIndustry_BubbleGenerator(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   805
		break;
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   806
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   807
	case GFX_TOFFEE_QUARY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
4583
af31ba5db77d (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   811
	case GFX_SUGAR_MINE_SIEVE:
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   812
		if (Chance16(1, 3)) AddAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
	}
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
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   817
static void ClickTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
{
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   819
	ShowIndustryViewWindow(GetIndustryIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
8616
fd862a55c47f (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 8596
diff changeset
   822
static TrackStatus GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
	return 0;
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
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   827
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
{
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
   829
	const Industry *i = GetIndustryByTile(tile);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
   830
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	b[0] = i->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	b[1] = i->produced_cargo[1];
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
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   835
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
   836
{
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   837
	/* If the founder merges, the industry was created by the merged company */
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   838
	Industry *i = GetIndustryByTile(tile);
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
   839
	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
   840
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
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
   843
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   844
static bool IsBadFarmFieldTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   846
	switch (GetTileType(tile)) {
5684
b764bfdb935d (svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents: 5668
diff changeset
   847
		case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8436
diff changeset
   848
		case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE);
2955
24de69e236d2 (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
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
	}
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
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   853
static bool IsBadFarmFieldTile2(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   855
	switch (GetTileType(tile)) {
5684
b764bfdb935d (svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents: 5668
diff changeset
   856
		case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
8459
86e0352eb993 (svn r12029) -Feature: Allow trees on shore.
frosch
parents: 8436
diff changeset
   857
		case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE);
2955
24de69e236d2 (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
   858
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   862
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
   863
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
		tile = TILE_MASK(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   866
1035
812f837ee03f (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
   867
		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   868
			byte or_ = type;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   869
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   870
			if (or_ == 1 && Chance16(1, 7)) or_ = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   872
			if (direction == AXIS_X) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   873
				SetFenceSE(tile, or_);
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   874
			} else {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   875
				SetFenceSW(tile, or_);
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
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   878
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   879
		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
   880
	} while (--size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
4330
cf31daa8b321 (svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents: 4329
diff changeset
   883
static void PlantFarmField(TileIndex tile, IndustryID industry)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	uint size_x, size_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	uint32 r;
2133
d7f582b7001d (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   887
	uint count;
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   888
	uint counter;
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   889
	uint field_type;
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   890
	int type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   892
	if (_opt.landscape == LT_ARCTIC) {
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6307
diff changeset
   893
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
	/* determine field size */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	r = (Random() & 0x303) + 0x404;
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   899
	if (_opt.landscape == LT_ARCTIC) r += 0x404;
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   900
	size_x = GB(r, 0, 8);
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   901
	size_y = GB(r, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
	/* offset tile to match size */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   904
	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
   905
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	/* check the amount of bad tiles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	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
   909
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
		count += IsBadFarmFieldTile(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
2133
d7f582b7001d (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   912
	if (count * 2 >= size_x * size_y) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	/* determine type of field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	r = Random();
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   916
	counter = GB(r, 5, 3);
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   917
	field_type = GB(r, 8, 8) * 9 >> 8;
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
	/* make field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	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
   921
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
		if (!IsBadFarmFieldTile2(cur_tile)) {
4328
1b3940c35724 (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
   923
			MakeField(cur_tile, field_type, industry);
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   924
			SetClearCounter(cur_tile, counter);
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   925
			MarkTileDirtyByTile(cur_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	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
   928
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	type = 3;
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   930
	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
   931
		type = _plantfarmfield_type[Random() & 0xF];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   934
	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   935
	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   936
	SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   937
	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
   938
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
4328
1b3940c35724 (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
void PlantRandomFarmField(const Industry *i)
1b3940c35724 (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
{
1b3940c35724 (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
   942
	int x = i->width  / 2 + Random() % 31 - 16;
1b3940c35724 (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
   943
	int y = i->height / 2 + Random() % 31 - 16;
1b3940c35724 (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
   944
1b3940c35724 (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
   945
	TileIndex tile = TileAddWrap(i->xy, x, y);
1b3940c35724 (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
   946
1b3940c35724 (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
   947
	if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
1b3940c35724 (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
   948
}
1b3940c35724 (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
   949
5118
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   950
/**
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   951
 * Search callback function for ChopLumberMillTrees
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   952
 * @param tile to test
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   953
 * @param data that is passed by the caller.  In this case, nothing
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
   954
 * @return the result of the test
5118
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   955
 */
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   956
static bool SearchLumberMillTrees(TileIndex tile, uint32 data)
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   957
{
5909
35595e20c0c4 (svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents: 5884
diff changeset
   958
	if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
5118
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   959
		PlayerID old_player = _current_player;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   960
		/* found a tree */
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   961
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   962
		_current_player = OWNER_NONE;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   963
		_industry_sound_ctr = 1;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   964
		_industry_sound_tile = tile;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   965
		SndPlayTileFx(SND_38_CHAINSAW, tile);
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   966
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   967
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   968
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   969
		_current_player = old_player;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   970
		return true;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   971
	}
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   972
	return false;
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   973
}
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   974
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   975
/**
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   976
 * Perform a circular search around the Lumber Mill in order to find trees to cut
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   977
 * @param i industry
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   978
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
static void ChopLumberMillTrees(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
{
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   981
	TileIndex tile = i->xy;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   982
5118
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   983
	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
   984
5118
9640617e1abb (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   985
	if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles  to search
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
   986
		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
   987
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
static void ProduceIndustryGoods(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	uint num;
6655
3d46f5ba9b6e (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 6639
diff changeset
   993
	const IndustrySpec *indsp = GetIndustrySpec(i->type);
0
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
	/* play a sound? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	if ((i->counter & 0x3F) == 0) {
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
   997
		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
   998
			SndPlayTileFx(
6655
3d46f5ba9b6e (svn r9886) -Codechange: Cleanup of industries (Step-13). Include the sounds table into the industry's spec.
belugas
parents: 6639
diff changeset
   999
				(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
				i->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
	i->counter--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	/* produce some cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
	if ((i->counter & 0xFF) == 0) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1008
		if (HasBit(indsp->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7165
diff changeset
  1009
7757
3e63b119a5bf (svn r11302) -Fix (r9520): typo
glx
parents: 7756
diff changeset
  1010
		IndustryBehaviour indbehav = indsp->behaviour;
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1011
		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]);
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1012
		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
  1013
7205
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1014
		if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1015
			bool plant;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1016
			if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
7205
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1017
				plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0);
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1018
			} else {
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
  1019
				plant = Chance16(1, 8);
7205
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1020
			}
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1021
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1022
			if (plant) PlantRandomFarmField(i);
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1023
		}
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1024
		if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1025
			bool cut = ((i->counter & 0x1FF) == 0);
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1026
			if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
7205
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1027
				cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0);
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1028
			}
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1029
0a6d45455ae5 (svn r10483) -Codechange: add support for callbacks to manipulate the building chance of farm fields and chopping chance for lumber mills.
rubidium
parents: 7203
diff changeset
  1030
			if (cut) ChopLumberMillTrees(i);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1031
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
	}
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
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  1035
void OnTick_Industry()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
	if (_industry_sound_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
		_industry_sound_ctr++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
		if (_industry_sound_ctr == 75) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1043
			SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
		} 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
  1045
			_industry_sound_ctr = 0;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1046
			SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile);
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
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1050
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1052
	FOR_ALL_INDUSTRIES(i) {
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7853
diff changeset
  1053
		TriggerIndustry(i, INDUSTRY_TRIGGER_INDUSTRY_TICK);
7229
a5f262f6df1b (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7227
diff changeset
  1054
		StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK);
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1055
		ProduceIndustryGoods(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1059
static bool CheckNewIndustry_NULL(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	return true;
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
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1064
static bool CheckNewIndustry_Forest(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
{
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1066
	if (_opt.landscape == LT_ARCTIC) {
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6307
diff changeset
  1067
		if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1075
static bool CheckNewIndustry_OilRefinery(TileIndex tile)
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1076
{
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1077
	if (_game_mode == GM_EDITOR) return true;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1078
	if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true;
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1079
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1080
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1081
	return false;
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1082
}
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1083
7
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1084
extern bool _ignore_restrictions;
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1085
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1086
static bool CheckNewIndustry_OilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1088
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1089
	if (TileHeight(tile) == 0 &&
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1090
			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
  1091
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	return false;
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
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1096
static bool CheckNewIndustry_Farm(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
{
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
  1098
	if (_opt.landscape == LT_ARCTIC) {
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6307
diff changeset
  1099
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
			_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
		}
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
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1107
static bool CheckNewIndustry_Plantation(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
{
3379
50b253bb9819 (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
  1109
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	}
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
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1117
static bool CheckNewIndustry_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
{
3379
50b253bb9819 (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
  1119
	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
		_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
  1121
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	}
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
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1127
static bool CheckNewIndustry_Lumbermill(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
{
3379
50b253bb9819 (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
  1129
	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
		_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
  1131
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1136
static bool CheckNewIndustry_BubbleGen(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
{
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1138
	return GetTileZ(tile) <= TILE_HEIGHT * 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1141
typedef bool CheckNewIndustryProc(TileIndex tile);
3663
548dfb4ad4cc (svn r4578) CodeChange : Cleanup of industry_cmd (Step-2).
belugas
parents: 3662
diff changeset
  1142
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
  1143
	CheckNewIndustry_NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	CheckNewIndustry_Forest,
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1145
	CheckNewIndustry_OilRefinery,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	CheckNewIndustry_Farm,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	CheckNewIndustry_Plantation,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	CheckNewIndustry_Water,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	CheckNewIndustry_Lumbermill,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	CheckNewIndustry_BubbleGen,
3877
0a298def0202 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1151
	CheckNewIndustry_OilRig
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1154
static bool CheckSuitableIndustryPos(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
{
926
a6d140a6a4de (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
  1156
	uint x = TileX(tile);
a6d140a6a4de (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
  1157
	uint y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1158
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1159
	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
  1160
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
		return false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1167
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
{
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1169
	const Town *t;
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1170
	const Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
	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
  1173
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1174
	if (_patches.multiple_industry_per_town) return t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1176
	FOR_ALL_INDUSTRIES(i) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1177
		if (i->type == (byte)type &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
				i->town == t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
			return NULL;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
	return t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1187
bool IsSlopeRefused(Slope current, Slope refused)
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1188
{
7733
bc007653ce57 (svn r11268) -Fix[FS#1336]: Call IsSlopeRefused whenever it is required. Looks like there was one spot missing. Thanks frosch
belugas
parents: 7676
diff changeset
  1189
	if (IsSteepSlope(current)) return true;
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1190
	if (current != SLOPE_FLAT) {
8030
135a60c84e95 (svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents: 7989
diff changeset
  1191
		if (IsSteepSlope(refused)) return true;
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1192
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1193
		Slope t = ComplementSlope(current);
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1194
8030
135a60c84e95 (svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents: 7989
diff changeset
  1195
		if (refused & SLOPE_W && (t & SLOPE_NW)) return true;
135a60c84e95 (svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents: 7989
diff changeset
  1196
		if (refused & SLOPE_S && (t & SLOPE_NE)) return true;
135a60c84e95 (svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents: 7989
diff changeset
  1197
		if (refused & SLOPE_E && (t & SLOPE_SW)) return true;
135a60c84e95 (svn r11590) -Fix (r11193): IsSlopeRefused() result was half wrong
glx
parents: 7989
diff changeset
  1198
		if (refused & SLOPE_N && (t & SLOPE_SE)) return true;
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1199
	}
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1200
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1201
	return false;
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1202
}
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1203
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1204
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check = NULL)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	_error_message = STR_0239_SITE_UNSUITABLE;
7663
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1207
	bool refused_slope = false;
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1208
	bool custom_shape = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
	do {
7467
e586e63fc58e (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: 7462
diff changeset
  1211
		IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx);
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1212
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1213
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
		if (!IsValidTile(cur_tile)) {
7473
3dfe8243a870 (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: 7467
diff changeset
  1215
			if (gfx == GFX_WATERTILE_SPECIALCHECK) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1218
7473
3dfe8243a870 (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: 7467
diff changeset
  1219
		if (gfx == GFX_WATERTILE_SPECIALCHECK) {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1220
			if (!IsTileType(cur_tile, MP_WATER) ||
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1221
					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1222
				return false;
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1223
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
		} else {
7758
17ad53748c7b (svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.
rubidium
parents: 7757
diff changeset
  1225
			if (!EnsureNoVehicleOnGround(cur_tile)) return false;
6893
ccfe9df6410f (svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents: 6859
diff changeset
  1226
			if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false;
ccfe9df6410f (svn r10140) -Fix [FS#867]: an industry could overbuild a bridge.
rubidium
parents: 6859
diff changeset
  1227
7531
3319970f2de9 (svn r11050) -Codechange: Use the translated gfx, not the original one.
belugas
parents: 7522
diff changeset
  1228
			const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
3319970f2de9 (svn r11050) -Codechange: Use the translated gfx, not the original one.
belugas
parents: 7522
diff changeset
  1229
7757
3e63b119a5bf (svn r11302) -Fix (r9520): typo
glx
parents: 7756
diff changeset
  1230
			IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
7756
646255a72a89 (svn r11301) -Fix: water check when building industries didn't work
glx
parents: 7755
diff changeset
  1232
			/* Perform land/water check if not disabled */
8471
ba4c15fe147b (svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents: 8459
diff changeset
  1233
			if (!HasBit(its->slopes_refused, 5) && (IsWaterTile(cur_tile) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return false;
7756
646255a72a89 (svn r11301) -Fix: water check when building industries didn't work
glx
parents: 7755
diff changeset
  1234
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1235
			if (HasBit(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
7663
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1236
				custom_shape = true;
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1237
				if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
			} else {
7756
646255a72a89 (svn r11301) -Fix: water check when building industries didn't work
glx
parents: 7755
diff changeset
  1239
				Slope tileh = GetTileSlope(cur_tile, NULL);
646255a72a89 (svn r11301) -Fix: water check when building industries didn't work
glx
parents: 7755
diff changeset
  1240
				refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1241
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
8054
ccf0f72dfe10 (svn r11615) -Fix (r11609): temperate banks can only be built in towns (over a house)
glx
parents: 8049
diff changeset
  1243
			if (ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) {
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1244
				if (!IsTileType(cur_tile, MP_HOUSE)) {
8049
4182740f3d82 (svn r11609) -Fix [FS#1524]: wrong error messages were shown when trying to build some industries in the scenario editor.
rubidium
parents: 8030
diff changeset
  1245
					_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1246
					return false;
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1247
				}
7227
76ebda957d0e (svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents: 7216
diff changeset
  1248
				if (CmdFailed(DoCommand(cur_tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR))) return false;
76ebda957d0e (svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents: 7216
diff changeset
  1249
			} else if ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) == 0 || !IsTileType(cur_tile, MP_HOUSE)) {
76ebda957d0e (svn r10506) -Fix: the (manual) building of banks was always rejected.
rubidium
parents: 7216
diff changeset
  1250
				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
  1251
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
		}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1253
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
7663
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1255
	if (custom_shape_check != NULL) *custom_shape_check = custom_shape;
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1256
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1257
	/* It is almost impossible to have a fully flat land in TG, so what we
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1258
	 *  do is that we check if we can make the land flat later on. See
798fd9251f8e (svn r11194) -Fix: industries with not all tiles custom slope checked (but at least one) would be build on wrongly sloped tiles.
rubidium
parents: 7662
diff changeset
  1259
	 *  CheckIfCanLevelIndustryPlatform(). */
8049
4182740f3d82 (svn r11609) -Fix [FS#1524]: wrong error messages were shown when trying to build some industries in the scenario editor.
rubidium
parents: 8030
diff changeset
  1260
	return !refused_slope || (_patches.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1263
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1264
{
6390
802629b3c7f1 (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: 6357
diff changeset
  1265
	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1266
		_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1267
		return false;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1268
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1269
6390
802629b3c7f1 (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: 6357
diff changeset
  1270
	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1271
		_error_message = STR_0239_SITE_UNSUITABLE;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1272
		return false;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1273
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1274
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1275
	return true;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1276
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1277
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1278
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1279
{
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1280
	int size_x, size_y;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1281
	uint curh;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1282
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1283
	size_x = 2;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1284
	size_y = 2;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1285
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1286
	/* Check if we don't leave the map */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1287
	if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1288
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1289
	tile += TileDiffXY(-1, -1);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1290
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1291
		curh = TileHeight(tile_walk);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1292
		/* Is the tile clear? */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1293
		if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES))
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1294
			return false;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1295
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1296
		/* Don't allow too big of a change if this is the sub-tile check */
7970
7d6b9ab57081 (svn r11526) -Codechange: Rename the function delta fitting to the naming style
skidd13
parents: 7967
diff changeset
  1297
		if (internal != 0 && Delta(curh, height) > 1) return false;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1298
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1299
		/* Different height, so the surrounding tiles of this tile
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1300
		 *  has to be correct too (in level, or almost in level)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1301
		 *  else you get a chain-reaction of terraforming. */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1302
		if (internal == 0 && curh != height) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1303
			if (!CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1))
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1304
				return false;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1305
		}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1306
	} END_TILE_LOOP(tile_walk, size_x, size_y, tile);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1307
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1308
	return true;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1309
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1310
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1311
/**
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1312
 * This function tries to flatten out the land below an industry, without
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1313
 *  damaging the surroundings too much.
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1314
 */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1315
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable* it, int type)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1316
{
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1317
	const int MKEND = -0x80;   // used for last element in an IndustryTileTable (see build_industry.h)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1318
	int max_x = 0;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1319
	int max_y = 0;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1320
	TileIndex cur_tile;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1321
	uint size_x, size_y;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1322
	uint h, curh;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1323
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1324
	/* Finds dimensions of largest variant of this industry */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1325
	do {
7629
711bbbc7a171 (svn r11160) -Fix: A gfx of 0xFF does not count when it's time to establish the size of the industry.
belugas
parents: 7615
diff changeset
  1326
		if (it->gfx == 0xFF) continue;  //  FF been a marquer for a check on clear water, skip it
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1327
		if (it->ti.x > max_x) max_x = it->ti.x;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1328
		if (it->ti.y > max_y) max_y = it->ti.y;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1329
	} while ((++it)->ti.x != MKEND);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1330
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1331
	/* Remember level height */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1332
	h = TileHeight(tile);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1333
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1334
	/* Check that all tiles in area and surrounding are clear
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1335
	 * this determines that there are no obstructing items */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1336
	cur_tile = tile + TileDiffXY(-1, -1);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1337
	size_x = max_x + 4;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1338
	size_y = max_y + 4;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1339
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1340
	/* Check if we don't leave the map */
4313
fc428e434474 (svn r5966) -Fix: prevent that the industry placement's terraforming checks can leave the map on the southern side
rubidium
parents: 4301
diff changeset
  1341
	if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1342
7640
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1343
	/* _current_player is OWNER_NONE for randomly generated industries and in editor, or the player who funded or prospected the industry.
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1344
	 * Perform terraforming as OWNER_TOWN to disable autoslope. */
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1345
	PlayerID old_player = _current_player;
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1346
	_current_player = OWNER_TOWN;
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1347
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1348
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1349
		curh = TileHeight(tile_walk);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1350
		if (curh != h) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1351
			/* This tile needs terraforming. Check if we can do that without
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1352
			 *  damaging the surroundings too much. */
7640
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1353
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1354
				_current_player = old_player;
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1355
				return false;
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1356
			}
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1357
			/* This is not 100% correct check, but the best we can do without modifying the map.
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1358
			 *  What is missing, is if the difference in height is more than 1.. */
7640
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1359
			if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) {
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1360
				_current_player = old_player;
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1361
				return false;
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1362
			}
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1363
		}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1364
	} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1365
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1366
	if (flags & DC_EXEC) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1367
		/* Terraform the land under the industry */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1368
		BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1369
			curh = TileHeight(tile_walk);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1370
			while (curh != h) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1371
				/* We give the terraforming for free here, because we can't calculate
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1372
				 *  exact cost in the test-round, and as we all know, that will cause
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1373
				 *  a nice assert if they don't match ;) */
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7473
diff changeset
  1374
				DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1375
				curh += (curh > h) ? -1 : 1;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1376
			}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1377
		} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1378
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1379
7640
8cf1b20cc69f (svn r11171) -Fix [FS#1257]: disable autoslope for automatically changed stuff (like towns and industries) and enable it in the scenario editor. Patch by frosch.
rubidium
parents: 7637
diff changeset
  1380
	_current_player = old_player;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1381
	return true;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1382
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1383
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1384
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1385
static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
{
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1387
	const IndustrySpec *indspec = GetIndustrySpec(type);
3662
d9683fb55b45 (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1388
	const Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1390
	if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1391
		/* Allow primary industries to be placed close to any other industry */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		return true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1393
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1394
	FOR_ALL_INDUSTRIES(i) {
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1395
		/* Within 14 tiles from another industry is considered close */
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1396
		bool in_low_distance = DistanceMax(tile, i->xy) <= 14;
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1397
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1398
		/* check if an industry that accepts the same goods is nearby */
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1399
		if (in_low_distance &&
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1400
				indspec->accepts_cargo[0] != CT_INVALID && // not a primary industry?
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1401
				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1402
				/* at least one of those options must be true */
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1403
				_game_mode != GM_EDITOR || // editor must not be stopped
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1404
				!_patches.same_industry_close ||
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1405
				!_patches.multiple_industry_per_town)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1406
			_error_message = STR_INDUSTRY_TOO_CLOSE;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1407
			return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1408
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1410
		/* check if there are any conflicting industry types around */
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1411
		if ((i->type == indspec->conflicting[0] ||
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1412
				i->type == indspec->conflicting[1] ||
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1413
				i->type == indspec->conflicting[2]) &&
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1414
				in_low_distance) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
			_error_message = STR_INDUSTRY_TOO_CLOSE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1422
/** Production level maximum, minimum and default values.
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1423
 * It is not a value been really used in order to change, but rather an indicator
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1424
 * of how the industry is behaving. */
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1425
enum ProductionLevels {
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1426
	PRODLEVEL_CLOSURE = 0x00,  ///< signal set to actually close the industry
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1427
	PRODLEVEL_MINIMUM = 0x04,  ///< below this level, the industry is set to be closing
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1428
	PRODLEVEL_DEFAULT = 0x10,  ///< default level set when the industry is created
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1429
	PRODLEVEL_MAXIMUM = 0x80,  ///< the industry is running at full speed
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1430
};
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1431
7445
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1432
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
  1433
{
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1434
	const IndustrySpec *indspec = GetIndustrySpec(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
	uint32 r;
7646
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1436
	uint j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
	i->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	i->width = i->height = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
	i->type = type;
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
  1441
	IncIndustryTypeCount(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1443
	i->produced_cargo[0] = indspec->produced_cargo[0];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1444
	i->produced_cargo[1] = indspec->produced_cargo[1];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1445
	i->accepts_cargo[0] = indspec->accepts_cargo[0];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1446
	i->accepts_cargo[1] = indspec->accepts_cargo[1];
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1447
	i->accepts_cargo[2] = indspec->accepts_cargo[2];
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1448
	i->production_rate[0] = indspec->production_rate[0];
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1449
	i->production_rate[1] = indspec->production_rate[1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
7947
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  1451
	/* don't use smooth economy for industries using production related callbacks */
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  1452
	if (_patches.smooth_economy &&
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  1453
	    !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  1454
	    !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE))             // production change callbacks
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  1455
	) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
		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
  1457
		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
  1458
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	i->town = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
	i->owner = owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
2484
0e45d70ae908 (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2469
diff changeset
  1463
	r = Random();
7862
1d710dd7e197 (svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents: 7860
diff changeset
  1464
	i->random_color = GB(r, 0, 4);
1d710dd7e197 (svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents: 7860
diff changeset
  1465
	i->counter = GB(r, 4, 12);
1d710dd7e197 (svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents: 7860
diff changeset
  1466
	i->random = GB(r, 16, 16);
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1467
	i->produced_cargo_waiting[0] = 0;
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1468
	i->produced_cargo_waiting[1] = 0;
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1469
	i->incoming_cargo_waiting[0] = 0;
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1470
	i->incoming_cargo_waiting[1] = 0;
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  1471
	i->incoming_cargo_waiting[2] = 0;
6819
f986f54e2660 (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: 6815
diff changeset
  1472
	i->this_month_production[0] = 0;
f986f54e2660 (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: 6815
diff changeset
  1473
	i->this_month_production[1] = 0;
f986f54e2660 (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: 6815
diff changeset
  1474
	i->this_month_transported[0] = 0;
f986f54e2660 (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: 6815
diff changeset
  1475
	i->this_month_transported[1] = 0;
f986f54e2660 (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: 6815
diff changeset
  1476
	i->last_month_pct_transported[0] = 0;
f986f54e2660 (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: 6815
diff changeset
  1477
	i->last_month_pct_transported[1] = 0;
f986f54e2660 (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: 6815
diff changeset
  1478
	i->last_month_transported[0] = 0;
f986f54e2660 (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: 6815
diff changeset
  1479
	i->last_month_transported[1] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
	i->was_cargo_delivered = false;
4329
0e6e689f66e7 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4328
diff changeset
  1481
	i->last_prod_year = _cur_year;
6819
f986f54e2660 (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: 6815
diff changeset
  1482
	i->last_month_production[0] = i->production_rate[0] * 8;
f986f54e2660 (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: 6815
diff changeset
  1483
	i->last_month_production[1] = i->production_rate[1] * 8;
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  1484
	i->founder = _current_player;
7646
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1485
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1486
	if (HasBit(indspec->callback_flags, CBM_IND_DECIDE_COLOUR)) {
7650
780f1f477317 (svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents: 7646
diff changeset
  1487
		uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
780f1f477317 (svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents: 7646
diff changeset
  1488
		if (res != CALLBACK_FAILED) i->random_color = GB(res, 0, 4);
780f1f477317 (svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents: 7646
diff changeset
  1489
	}
780f1f477317 (svn r11181) -Codechange: add support for newgrf callback 14A (Belugas)
glx
parents: 7646
diff changeset
  1490
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1491
	if (HasBit(indspec->callback_flags, CBM_IND_INPUT_CARGO_TYPES)) {
7646
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1492
		for (j = 0; j < lengthof(i->accepts_cargo); j++) i->accepts_cargo[j] = CT_INVALID;
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1493
		for (j = 0; j < lengthof(i->accepts_cargo); j++) {
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1494
			uint16 res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1495
			if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1496
			i->accepts_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1497
		}
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1498
	}
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1499
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1500
	if (HasBit(indspec->callback_flags, CBM_IND_OUTPUT_CARGO_TYPES)) {
7646
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1501
		for (j = 0; j < lengthof(i->produced_cargo); j++) i->produced_cargo[j] = CT_INVALID;
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1502
		for (j = 0; j < lengthof(i->produced_cargo); j++) {
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1503
			uint16 res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1504
			if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1505
			i->produced_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1506
		}
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1507
	}
dc8c0fa95dae (svn r11177) -Codechange: add support for newgrf callbacks 14B and 14C
glx
parents: 7645
diff changeset
  1508
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  1509
	i->construction_date = _date;
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  1510
	i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR :
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  1511
			(_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
7445
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1513
	/* Adding 1 here makes it conform to specs of var44 of varaction2 for industries
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1514
	 * 0 = created prior of newindustries
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1515
	 * else, chosen layout + 1 */
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1516
	i->selected_layout = layout + 1;
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1517
6819
f986f54e2660 (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: 6815
diff changeset
  1518
	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
  1519
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  1520
	i->prod_level = PRODLEVEL_DEFAULT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
	do {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1523
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
7473
3dfe8243a870 (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: 7467
diff changeset
  1525
		if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
			byte size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1528
			size = it->ti.x;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
			if (size > i->width) i->width = size;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1530
			size = it->ti.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
			if (size > i->height)i->height = size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
3491
35d747bb5e82 (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
  1533
			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
  1534
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
  1535
			MakeIndustry(cur_tile, i->index, it->gfx, Random());
7853
4bdbe434e076 (svn r11403) -Fix: NewIndustries GRF assume that tiles are already animated during construction.
rubidium
parents: 7852
diff changeset
  1536
5435
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
  1537
			if (_generating_world) {
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
  1538
				SetIndustryConstructionCounter(cur_tile, 3);
ffb0c3620c6e (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5434
diff changeset
  1539
				SetIndustryConstructionStage(cur_tile, 2);
7862
1d710dd7e197 (svn r11412) -Fix (r11403): animation was not turned on properly.
rubidium
parents: 7860
diff changeset
  1540
			}
8311
033318a20764 (svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents: 8302
diff changeset
  1541
033318a20764 (svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents: 8302
diff changeset
  1542
			/* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */
033318a20764 (svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents: 8302
diff changeset
  1543
			IndustryGfx cur_gfx = GetTranslatedIndustryTileID(it->gfx);
033318a20764 (svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents: 8302
diff changeset
  1544
			const IndustryTileSpec *its = GetIndustryTileSpec(cur_gfx);
033318a20764 (svn r11876) -Fix: Start industry tile animation also for overridden industry tiles. (Will only apply to new games or newly build industries.)
frosch
parents: 8302
diff changeset
  1545
			if (its->animation_info != 0xFFFF) AddAnimatedTile(cur_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
		}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1547
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
	i->width++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
	i->height++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
6390
802629b3c7f1 (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: 6357
diff changeset
  1552
	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
4328
1b3940c35724 (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
  1553
		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1559
/** Helper function for Build/Fund an industry
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1560
 * @param tile tile where industry is built
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1561
 * @param type of industry to build
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1562
 * @param flags of operations to conduct
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1563
 * @param indspec pointer to industry specifications
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7205
diff changeset
  1564
 * @param itspec_index the index of the itsepc to build/fund
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1565
 * @param seed random seed (possibly) used by industries
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1566
 * @return the pointer of the newly created industry, or NULL if it failed
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1567
 */
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1568
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed)
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1569
{
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7205
diff changeset
  1570
	const IndustryTileTable *it = indspec->table[itspec_index];
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1571
	bool custom_shape_check = false;
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1572
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1573
	if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL;
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1574
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1575
	if (HasBit(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) {
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1576
		if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL;
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1577
	} else {
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1578
		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7205
diff changeset
  1579
	}
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1580
8049
4182740f3d82 (svn r11609) -Fix [FS#1524]: wrong error messages were shown when trying to build some industries in the scenario editor.
rubidium
parents: 8030
diff changeset
  1581
	if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
8234
ce9107c79628 (svn r11798) -Codechange: add comments and give a more representative function's name
belugas
parents: 8230
diff changeset
  1582
	if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1583
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7205
diff changeset
  1584
	const Town *t = CheckMultipleIndustryInTown(tile, type);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1585
	if (t == NULL) return NULL;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1586
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1587
	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1588
	if (!CheckSuitableIndustryPos(tile)) return NULL;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1589
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
  1590
	Industry *i = new Industry(tile);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1591
	if (i == NULL) return NULL;
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
  1592
	AutoPtrT<Industry> i_auto_delete = i;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1593
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1594
	if (flags & DC_EXEC) {
7212
5d99296fb545 (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7207
diff changeset
  1595
		if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
7445
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  1596
		DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE);
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
  1597
		i_auto_delete.Detach();
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1598
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1599
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1600
	return i;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1601
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1602
1786
7cfd46c3fcc4 (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
  1603
/** Build/Fund an industry
3491
35d747bb5e82 (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
  1604
 * @param tile tile where industry is built
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1605
 * @param flags of operations to conduct
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1606
 * @param p1 various bitstuffed elements
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1607
 * - p1 = (bit  0 - 15) - industry type see build_industry.h and see industry.h
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1608
 * - p1 = (bit 16 - 31) - first layout to try
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1609
 * @param p2 seed to use for variable 8F
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1610
 * @return index of the newly create industry, or CMD_ERROR if it failed
1786
7cfd46c3fcc4 (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
  1611
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6910
diff changeset
  1612
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
  1613
{
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1614
	const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16));
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1615
4965
a09db997a1f3 (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
  1616
	/* Check if the to-be built/founded industry is available for this climate. */
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1617
	if (!indspec->enabled) {
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1618
		return CMD_ERROR;
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1619
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
2638
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1621
	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
7185
1b6b21b69c2d (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: 7177
diff changeset
  1622
	 * Raw material industries are industries that do not accept cargo (at least for now) */
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7205
diff changeset
  1623
	if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
2638
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1624
		return CMD_ERROR;
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1625
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7205
diff changeset
  1627
	if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
7177
f9796d5be926 (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: 7168
diff changeset
  1628
		if (flags & DC_EXEC) {
f9796d5be926 (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: 7168
diff changeset
  1629
			/* Prospecting has a chance to fail, however we cannot guarantee that something can
f9796d5be926 (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: 7168
diff changeset
  1630
			 * be built on the map, so the chance gets lower when the map is fuller, but there
f9796d5be926 (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: 7168
diff changeset
  1631
			 * is nothing we can really do about that. */
f9796d5be926 (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: 7168
diff changeset
  1632
			if (Random() <= indspec->prospecting_chance) {
f9796d5be926 (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: 7168
diff changeset
  1633
				for (int i = 0; i < 5000; i++) {
8154
a074ca3d3e0a (svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents: 8144
diff changeset
  1634
					/* We should not have more than one Random() in a function call
a074ca3d3e0a (svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents: 8144
diff changeset
  1635
					 * because parameter evaluation order is not guaranteed in the c++ standard
a074ca3d3e0a (svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents: 8144
diff changeset
  1636
					 */
a074ca3d3e0a (svn r11716) -Fix [FS#1561]: don't put more than one Random() in function calls because parameter evaluation order is not guaranteed in the c++ standard (can lead to desyncs)
glx
parents: 8144
diff changeset
  1637
					tile = RandomTile();
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1638
					const Industry *ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2);
7203
39f68ddb39cc (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7199
diff changeset
  1639
					if (ind != NULL) {
39f68ddb39cc (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7199
diff changeset
  1640
						SetDParam(0, indspec->name);
7755
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1641
						if (indspec->new_industry_text > STR_LAST_STRINGID) {
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1642
							SetDParam(1, STR_TOWN);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1643
							SetDParam(2, ind->town->index);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1644
						} else {
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1645
							SetDParam(1, ind->town->index);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1646
						}
7203
39f68ddb39cc (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7199
diff changeset
  1647
						AddNewsItem(indspec->new_industry_text,
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8656
diff changeset
  1648
								NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, DNC_NONE, ind->xy, 0);
7203
39f68ddb39cc (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7199
diff changeset
  1649
						break;
39f68ddb39cc (svn r10481) -Codechange: Show a news message with the new industry when primary industry prospecting succeeds.
maedhros
parents: 7199
diff changeset
  1650
					}
7177
f9796d5be926 (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: 7168
diff changeset
  1651
				}
f9796d5be926 (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: 7168
diff changeset
  1652
			}
f9796d5be926 (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: 7168
diff changeset
  1653
		}
f9796d5be926 (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: 7168
diff changeset
  1654
	} else {
7760
d10e2e25cd5f (svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents: 7758
diff changeset
  1655
		int count = indspec->num_table;
d10e2e25cd5f (svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents: 7758
diff changeset
  1656
		const IndustryTileTable * const *itt = indspec->table;
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1657
		int num = Clamp(GB(p1, 16, 16), 0, count - 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
7748
805820a59bf5 (svn r11285) -Fix: 'site unsuitable' was always shown instead specified message when trying to build industry ingame (Csaboka)
glx
parents: 7739
diff changeset
  1659
		_error_message = STR_0239_SITE_UNSUITABLE;
7177
f9796d5be926 (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: 7168
diff changeset
  1660
		do {
7760
d10e2e25cd5f (svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents: 7758
diff changeset
  1661
			if (--count < 0) return CMD_ERROR;
d10e2e25cd5f (svn r11305) -Codechange: randomise layout when building an industry ingame
glx
parents: 7758
diff changeset
  1662
			if (--num < 0) num = indspec->num_table - 1;
7662
b9da9d79a9a9 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 7655
diff changeset
  1663
		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1664
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1665
		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2) == NULL) return CMD_ERROR;
7177
f9796d5be926 (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: 7168
diff changeset
  1666
	}
f9796d5be926 (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: 7168
diff changeset
  1667
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  1668
	return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
3538
750c4ea83357 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
  1672
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1674
	const IndustrySpec *indspec = GetIndustrySpec(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1676
	uint32 seed = Random();
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8407
diff changeset
  1677
	return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
7338
00527f7584a2 (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: 7337
diff changeset
  1680
enum {
00527f7584a2 (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: 7337
diff changeset
  1681
	NB_NUMOFINDUSTRY = 11,
00527f7584a2 (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: 7337
diff changeset
  1682
	NB_DIFFICULTY_LEVEL = 5,
00527f7584a2 (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: 7337
diff changeset
  1683
};
00527f7584a2 (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: 7337
diff changeset
  1684
00527f7584a2 (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: 7337
diff changeset
  1685
static const byte _numof_industry_table[NB_DIFFICULTY_LEVEL][NB_NUMOFINDUSTRY] = {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  1686
	/* difficulty settings for number of industries */
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1687
	{0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0},   //none
6560
24106d85dcf5 (svn r9762) -Feature: Two new difficulty settings : Very low number of towns and very low number of industries
belugas
parents: 6519
diff changeset
  1688
	{0, 1, 1, 1, 1, 1, 1, 1,  1,  1,  1},   //very low
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1689
	{0, 1, 1, 1, 2, 2, 3, 3,  4,  4,  5},   //low
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1690
	{0, 1, 2, 3, 4, 5, 6, 7,  8,  9, 10},   //normal
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1691
	{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
  1692
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
6442
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1694
/** This function is the one who really do the creation work
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1695
 * of random industries during game creation
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1696
 * @param type IndustryType of the desired industry
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1697
 * @param amount of industries that need to be built */
3669
753648f181a0 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1698
static void PlaceInitialIndustry(IndustryType type, int amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
{
7338
00527f7584a2 (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: 7337
diff changeset
  1700
	/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
00527f7584a2 (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: 7337
diff changeset
  1701
	 * _numof_industry_table.  newgrf can specify a big amount */
00527f7584a2 (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: 7337
diff changeset
  1702
	int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_opt.diff.number_industries][amount];
6757
385cb1bf2ba9 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 6749
diff changeset
  1703
	const IndustrySpec *ind_spc = GetIndustrySpec(type);
2072
66d208875eda (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
  1704
6442
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1705
	/* These are always placed next to the coastline, so we scale by the perimeter instead. */
6757
385cb1bf2ba9 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 6749
diff changeset
  1706
	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
  1707
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1708
	if (_opt.diff.number_industries != 0) {
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1709
		PlayerID old_player = _current_player;
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1710
		_current_player = OWNER_NONE;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1711
		assert(num > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
		do {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1714
			uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1715
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1716
			IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1717
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1718
			for (i = 0; i < 2000; i++) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1719
				if (CreateNewIndustry(RandomTile(), type) != NULL) break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1720
			}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1721
		} while (--num);
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1722
267
ee1ce0133772 (svn r273) -Fix: sorry, wrongly fixed
darkvater
parents: 266
diff changeset
  1723
		_current_player = old_player;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1724
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
6442
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1727
/** This function will create ramdon industries during game creation.
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1728
 * It will scale the amount of industries by map size as well as difficulty level */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  1729
void GenerateIndustries()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1731
	uint i = 0;
6442
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1732
	uint8 chance;
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1733
	IndustryType it;
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1734
	const IndustrySpec *ind_spc;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1735
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1736
	/* Find the total amount of industries */
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1737
	if (_opt.diff.number_industries > 0) {
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7293
diff changeset
  1738
		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1739
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1740
			ind_spc = GetIndustrySpec(it);
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1741
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1742
			if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) {
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1743
				ResetIndustryCreationProbility(it);
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1744
			}
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1745
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1746
			chance = ind_spc->appear_creation[_opt.landscape];
7262
8eef461d2c43 (svn r10575) -Fix r10573: misplaced )
glx
parents: 7261
diff changeset
  1747
			if (ind_spc->enabled && chance > 0) {
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1748
				/* once the chance of appearance is determind, it have to be scaled by
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1749
				 * the difficulty level. The "chance" in question is more an index into
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1750
				 * the _numof_industry_table,in fact */
7338
00527f7584a2 (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: 7337
diff changeset
  1751
				int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_opt.diff.number_industries][chance];
6442
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1752
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1753
				/* These are always placed next to the coastline, so we scale by the perimeter instead. */
6757
385cb1bf2ba9 (svn r9992) -Codechange: Remove some hardcoded references to Industry IDs.
belugas
parents: 6749
diff changeset
  1754
				num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1755
				i += num;
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1756
			}
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1757
		}
6442
1bab3df59b91 (svn r9579) -Codechange: Cleanup of industry_cmd (Step-11). Use industry's spec appear_creation during random map creation.
belugas
parents: 6438
diff changeset
  1758
	}
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1759
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1760
	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1762
	if (_opt.diff.number_industries > 0) {
7319
9b20d1dbe5d6 (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium
parents: 7293
diff changeset
  1763
		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1764
			/* Once the number of industries has been determined, let's really create them.
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1765
			 * The test for chance allows us to try create industries that are available only
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1766
			 * for this landscape.
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1767
			 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1768
			 *          processed that scaling above? No, don't think so.  Will find a way. */
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1769
			ind_spc = GetIndustrySpec(it);
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1770
			if (ind_spc->enabled) {
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1771
				chance = ind_spc->appear_creation[_opt.landscape];
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1772
				if (chance > 0) PlaceInitialIndustry(it, chance);
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1773
			}
6748
7579278d958f (svn r9983) -Codechange: Use the "enabled" property of the industry spec.
belugas
parents: 6743
diff changeset
  1774
		}
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1775
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
static void UpdateIndustryStatistics(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1779
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
	byte pct;
6467
7bce7e0c9937 (svn r9643) -Codechange: Simplify a test.
belugas
parents: 6442
diff changeset
  1781
	bool refresh = false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1782
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1783
	for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  1784
		if (i->produced_cargo[j] != CT_INVALID) {
6636
fec086b5c340 (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: 6560
diff changeset
  1785
			pct = 0;
6819
f986f54e2660 (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: 6815
diff changeset
  1786
			if (i->this_month_production[j] != 0) {
6636
fec086b5c340 (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: 6560
diff changeset
  1787
				i->last_prod_year = _cur_year;
6819
f986f54e2660 (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: 6815
diff changeset
  1788
				pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255);
6636
fec086b5c340 (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: 6560
diff changeset
  1789
			}
6819
f986f54e2660 (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: 6815
diff changeset
  1790
			i->last_month_pct_transported[j] = pct;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
6819
f986f54e2660 (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: 6815
diff changeset
  1792
			i->last_month_production[j] = i->this_month_production[j];
f986f54e2660 (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: 6815
diff changeset
  1793
			i->this_month_production[j] = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
6819
f986f54e2660 (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: 6815
diff changeset
  1795
			i->last_month_transported[j] = i->this_month_transported[j];
f986f54e2660 (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: 6815
diff changeset
  1796
			i->this_month_transported[j] = 0;
6636
fec086b5c340 (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: 6560
diff changeset
  1797
			refresh = true;
fec086b5c340 (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: 6560
diff changeset
  1798
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1801
	if (refresh) InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
6431
137965651de7 (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: 6427
diff changeset
  1804
/** Simple helper that will collect data for the generation of industries */
137965651de7 (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: 6427
diff changeset
  1805
struct ProbabilityHelper {
137965651de7 (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: 6427
diff changeset
  1806
	uint16 prob;      ///< probability
137965651de7 (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: 6427
diff changeset
  1807
	IndustryType ind; ///< industry id correcponding
137965651de7 (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: 6427
diff changeset
  1808
};
137965651de7 (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: 6427
diff changeset
  1809
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1810
/**
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1811
 * Try to create a random industry, during gameplay
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1812
 */
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1813
static void MaybeNewIndustry(void)
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1814
{
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1815
	Industry *ind;               //will receive the industry's creation pointer
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1816
	IndustryType rndtype, j;     // Loop controlers
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1817
	const IndustrySpec *ind_spc;
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1818
	uint num = 0;
6493
6bbb7ebd6a31 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6491
diff changeset
  1819
	ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1820
	uint16 probability_max = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1822
	/* Generate a list of all possible industries that can be built. */
6493
6bbb7ebd6a31 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6491
diff changeset
  1823
	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
7823
7445cb71f080 (svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents: 7821
diff changeset
  1824
		ind_spc = GetIndustrySpec(j);
7445cb71f080 (svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents: 7821
diff changeset
  1825
		byte chance = ind_spc->appear_ingame[_opt.landscape];
7445cb71f080 (svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents: 7821
diff changeset
  1826
7445cb71f080 (svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents: 7821
diff changeset
  1827
		if (!ind_spc->enabled || chance == 0) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1828
7261
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1829
		/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
a39e79710d5a (svn r10573) -Codechange: Use function CheckIfCallBackAllowsAvailability for random map generation as well as for ingame random industry creation
belugas
parents: 7229
diff changeset
  1830
		 * and if appearing chance for this landscape is above 0, this industry can be chosen */
7823
7445cb71f080 (svn r11373) -Fix [FS#1398]: do not even think about building disabled industries.
rubidium
parents: 7821
diff changeset
  1831
		if (CheckIfCallBackAllowsAvailability(j, IACT_RANDOMCREATION)) {
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1832
			probability_max += chance;
6431
137965651de7 (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: 6427
diff changeset
  1833
			/* adds the result for this industry */
137965651de7 (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: 6427
diff changeset
  1834
			cumulative_probs[num].ind = j;
137965651de7 (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: 6427
diff changeset
  1835
			cumulative_probs[num++].prob = probability_max;
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1836
		}
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1837
	}
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1838
6431
137965651de7 (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: 6427
diff changeset
  1839
	/* Find a random type, with maximum being what has been evaluate above*/
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1840
	rndtype = RandomRange(probability_max);
6493
6bbb7ebd6a31 (svn r9676) -Codechange: introduce NUM_INDUSTRYTYPES instead of IT_END.
belugas
parents: 6491
diff changeset
  1841
	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
6431
137965651de7 (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: 6427
diff changeset
  1842
		/* and choose the index of the industry that matches as close as possible this random type */
137965651de7 (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: 6427
diff changeset
  1843
		if (cumulative_probs[j].prob >= rndtype) break;
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1844
	}
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1845
6431
137965651de7 (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: 6427
diff changeset
  1846
	ind_spc = GetIndustrySpec(cumulative_probs[j].ind);
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1847
	/*  Check if it is allowed */
6390
802629b3c7f1 (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: 6357
diff changeset
  1848
	if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return;
802629b3c7f1 (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: 6357
diff changeset
  1849
	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
  1850
6431
137965651de7 (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: 6427
diff changeset
  1851
	/* try to create 2000 times this industry */
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1852
	num = 2000;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1853
	for (;;) {
6431
137965651de7 (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: 6427
diff changeset
  1854
		ind = CreateNewIndustry(RandomTile(), cumulative_probs[j].ind);
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1855
		if (ind != NULL) break;
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  1856
		if (--num == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1857
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
6266
fd42b0893130 (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: 6247
diff changeset
  1859
	SetDParam(0, ind_spc->name);
7755
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1860
	if (ind_spc->new_industry_text > STR_LAST_STRINGID) {
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1861
		SetDParam(1, STR_TOWN);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1862
		SetDParam(2, ind->town->index);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1863
	} else {
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1864
		SetDParam(1, ind->town->index);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  1865
	}
6266
fd42b0893130 (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: 6247
diff changeset
  1866
	AddNewsItem(ind_spc->new_industry_text,
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8656
diff changeset
  1867
		NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, DNC_NONE, ind->xy, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1870
/**
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1871
 * Protects an industry from closure if the appropriate flags and conditions are met
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1872
 * INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1873
 * count of industries of this type must one (or lower) in order to be protected
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1874
 * against closure.
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1875
 * @param type IndustryType been queried
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1876
 * @result true if protection is on, false otherwise (except for oil wells)
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1877
 */
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1878
static bool CheckIndustryCloseDownProtection(IndustryType type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
{
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1880
	const IndustrySpec *indspec = GetIndustrySpec(type);
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1881
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1882
	/* oil wells (or the industries with that flag set) are always allowed to closedown */
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1883
	if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _opt.landscape == LT_TEMPERATE) return false;
7821
dbdfb0db23ba (svn r11371) -Fix [FS#1396]: the industry protection only kicked in when it should not kick in.
rubidium
parents: 7806
diff changeset
  1884
	return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && GetIndustryTypeCount(type) <= 1;
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1885
}
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  1886
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1887
/**
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1888
* Can given cargo type be accepted or produced by the industry?
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1889
* @param cargo: Cargo type
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1890
* @param ind: Industry
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1891
* @param *c_accepts: Pointer to boolean for acceptance of cargo
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1892
* @param *c_produces: Pointer to boolean for production of cargo
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1893
* @return: \c *c_accepts is set when industry accepts the cargo type,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1894
*          \c *c_produces is set when the industry produces the cargo type
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1895
*/
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1896
static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1897
{
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1898
	const IndustrySpec *indspec = GetIndustrySpec(ind->type);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1899
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1900
	/* Check for acceptance of cargo */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1901
	for (uint j = 0; j < lengthof(ind->accepts_cargo) && ind->accepts_cargo[j] != CT_INVALID; j++) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1902
		if (cargo == ind->accepts_cargo[j]) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1903
			if (HasBit(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1904
				uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1905
						0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile),
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1906
						ind, ind->type, ind->xy);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1907
				if (res == 0) continue;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1908
			}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1909
			*c_accepts = true;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1910
			break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1911
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1912
	}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1913
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1914
	/* Check for produced cargo */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1915
	for (uint j = 0; j < lengthof(ind->produced_cargo) && ind->produced_cargo[j] != CT_INVALID; j++) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1916
		if (cargo == ind->produced_cargo[j]) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1917
			*c_produces = true;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1918
			break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1919
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1920
	}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1921
}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1922
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1923
/**
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1924
* Compute who can service the industry.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1925
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1926
* Here, 'can service' means that he/she has trains and stations close enough
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1927
* to the industry with the right cargo type and the right orders (ie has the
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1928
* technical means).
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1929
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1930
* @param ind: Industry being investigated.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1931
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1932
* @return: 0 if nobody can service the industry, 2 if the local player can
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1933
* service the industry, and 1 otherwise (only competitors can service the
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1934
* industry)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1935
*/
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1936
int WhoCanServiceIndustry(Industry* ind)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1937
{
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1938
	/* Find all stations within reach of the industry */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1939
	StationSet stations = FindStationsAroundIndustryTile(ind->xy, ind->width, ind->height);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1940
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1941
	if (stations.size() == 0) return 0; // No stations found at all => nobody services
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1942
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1943
	const Vehicle *v;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1944
	int result = 0;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1945
	FOR_ALL_VEHICLES(v) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1946
		/* Is it worthwhile to try this vehicle? */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1947
		if (v->owner != _local_player && result != 0) continue;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1948
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1949
		/* Check whether it accepts the right kind of cargo */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1950
		bool c_accepts = false;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1951
		bool c_produces = false;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1952
		if (v->type == VEH_TRAIN && IsFrontEngine(v)) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1953
			const Vehicle *u = v;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1954
			BEGIN_ENUM_WAGONS(u)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1955
				CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1956
			END_ENUM_WAGONS(u)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1957
		} else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1958
			CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1959
		} else {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1960
			continue;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1961
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1962
		if (!c_accepts && !c_produces) continue; // Wrong cargo
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1963
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1964
		/* Check orders of the vehicle.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1965
		 * We cannot check the first of shared orders only, since the first vehicle in such a chain
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1966
		 * may have a different cargo type.
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1967
		 */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1968
		const Order *o;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1969
		FOR_VEHICLE_ORDERS(v, o) {
8843
45fdf630deaa (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 8840
diff changeset
  1970
			if (o->IsType(OT_GOTO_STATION) && !HasBit(o->GetUnloadType(), OF_TRANSFER)) {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1971
				/* Vehicle visits a station to load or unload */
8840
332412c2e9c1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium
parents: 8836
diff changeset
  1972
				Station *st = GetStation(o->GetDestination());
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1973
				if (!st->IsValid()) continue;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1974
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1975
				/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
8843
45fdf630deaa (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium
parents: 8840
diff changeset
  1976
				if (HasBit(o->GetUnloadType(), OF_UNLOAD) && !c_accepts) break;
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1977
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1978
				if (stations.find(st) != stations.end()) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1979
					if (v->owner == _local_player) return 2; // Player services industry
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1980
					result = 1; // Competitor services industry
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1981
				}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1982
			}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1983
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1984
	}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1985
	return result;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1986
}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1987
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1988
/**
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1989
* Report news that industry production has changed significantly
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1990
*
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1991
* @param ind: Industry with changed production
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1992
* @param type: Cargo type that has changed
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1993
* @param percent: Percentage of change (>0 means increase, <0 means decrease)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1994
*/
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1995
static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent)
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1996
{
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1997
	NewsType nt;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1998
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  1999
	switch (WhoCanServiceIndustry(ind)) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2000
		case 0: nt = NT_INDUSTRY_NOBODY; break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2001
		case 1: nt = NT_INDUSTRY_OTHER;  break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2002
		case 2: nt = NT_INDUSTRY_PLAYER; break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2003
		default: NOT_REACHED(); break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2004
	}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2005
	SetDParam(2, abs(percent));
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2006
	SetDParam(0, GetCargo(type)->name);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2007
	SetDParam(1, ind->index);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2008
	AddNewsItem(
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2009
		percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8656
diff changeset
  2010
		NM_THIN, NF_VIEWPORT | NF_TILE, nt, DNC_NONE,
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2011
		ind->xy + TileDiffXY(1, 1), 0
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2012
	);
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2013
}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2014
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2015
enum {
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2016
	PERCENT_TRANSPORTED_60 = 153,
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2017
	PERCENT_TRANSPORTED_80 = 204,
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2018
};
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2019
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2020
/** Change industry production or do closure
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2021
 * @param i Industry for which changes are performed
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2022
 * @param monthly true if it's the monthly call, false if it's the random call
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2023
 */
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2024
static void ChangeIndustryProduction(Industry *i, bool monthly)
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2025
{
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  2026
	StringID str = STR_NULL;
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2027
	bool closeit = false;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2028
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2029
	bool standard = true;
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2030
	bool suppress_message = false;
7947
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  2031
	/* don't use smooth economy for industries using production related callbacks */
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  2032
	bool smooth_economy = _patches.smooth_economy &&
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  2033
	                      !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  2034
	                      !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE));            // production change callbacks
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2035
	byte div = 0;
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2036
	byte mul = 0;
7976
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2037
	int8 increment = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  2038
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2039
	if (HasBit(indspec->callback_flags, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE)) {
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2040
		uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy);
7947
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  2041
		standard = false;
91d47e2ebc1a (svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
glx
parents: 7945
diff changeset
  2042
		monthly = false; // smooth economy is disabled so we need to fake random industry production change to allow 'use standard' result
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2043
		if (res != CALLBACK_FAILED) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2044
			suppress_message = HasBit(res, 7);
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2045
			/* Get the custom message if any */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2046
			if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grffile->grfid, GB(GetRegister(0x100), 0, 16));
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2047
			res = GB(res, 0, 4);
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2048
			switch(res) {
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2049
				default: NOT_REACHED();
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2050
				case 0x0: break;                  // Do nothing, but show the custom message if any
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2051
				case 0x1: div = 1; break;         // Halve industry production. If production reaches the quarter of the default, the industry is closed instead.
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2052
				case 0x2: mul = 1; break;         // Double industry production if it hasn't reached eight times of the original yet.
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2053
				case 0x3: closeit = true; break;  // The industry announces imminent closure, and is physically removed from the map next month.
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2054
				case 0x4: standard = true; break; // Do the standard random production change as if this industry was a primary one.
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2055
				case 0x5: case 0x6: case 0x7:     // Divide production by 4, 8, 16
7944
990095c53ecc (svn r11499) -Fix (r11144): mul/div factor were wrong (off by two)
glx
parents: 7928
diff changeset
  2056
				case 0x8: div = res - 0x3; break; // Divide production by 32
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2057
				case 0x9: case 0xA: case 0xB:     // Multiply production by 4, 8, 16
7944
990095c53ecc (svn r11499) -Fix (r11144): mul/div factor were wrong (off by two)
glx
parents: 7928
diff changeset
  2058
				case 0xC: mul = res - 0x7; break; // Multiply production by 32
7976
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2059
				case 0xD:                         // decrement production
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2060
				case 0xE:                         // increment production
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2061
					increment = res == 0x0D ? -1 : 1;
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2062
					break;
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2063
			}
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2064
		}
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2065
	}
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  2066
7676
926233c6e06a (svn r11207) -Fix [FS#1301]: don't use smooth_economy for industries using production callbacks as they may have no production for more than a month
glx
parents: 7666
diff changeset
  2067
	if (standard && monthly != smooth_economy) return;
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2068
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2069
	if (standard && indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2070
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2071
	if (standard && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2072
		/* decrease or increase */
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2073
		bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE;
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2074
7676
926233c6e06a (svn r11207) -Fix [FS#1301]: don't use smooth_economy for industries using production callbacks as they may have no production for more than a month
glx
parents: 7666
diff changeset
  2075
		if (smooth_economy) {
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2076
			closeit = true;
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  2077
			for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2078
				uint32 r = Random();
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2079
				int old_prod, new_prod, percent;
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2080
				/* If over 60% is transported, mult is 1, else mult is -1. */
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2081
				int mult = (i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_60) ? 1 : -1;
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2082
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2083
				new_prod = old_prod = i->production_rate[j];
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2084
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2085
				/* For industries with only_decrease flags (temperate terrain Oil Wells),
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2086
				 * the multiplier will always be -1 so they will only decrease. */
7972
8c4b44015a5f (svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents: 7970
diff changeset
  2087
				if (only_decrease) {
8c4b44015a5f (svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents: 7970
diff changeset
  2088
					mult = -1;
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2089
				/* For normal industries, if over 60% is transported, 33% chance for decrease.
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2090
				 * Bonus for very high station ratings (over 80%): 16% chance for decrease. */
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2091
				} else if (Chance16I(1, ((i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_80) ? 6 : 3), r)) {
7972
8c4b44015a5f (svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents: 7970
diff changeset
  2092
					mult *= -1;
8c4b44015a5f (svn r11528) -Fix (r11500): With smooth economy enabled, industries that should only decrease production would always increase it when more than 60% was transported.
maedhros
parents: 7970
diff changeset
  2093
				}
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2094
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2095
				/* 4.5% chance for 3-23% (or 1 unit for very low productions) production change,
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2096
				 * determined by mult value. If mult = 1 prod. increases, else (-1) it decreases. */
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2097
				if (Chance16I(1, 22, r >> 16)) {
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2098
					new_prod += mult * (max(((RandomRange(50) + 10) * old_prod) >> 8, 1U));
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2099
				}
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2100
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2101
				/* Prevent production to overflow or Oil Rig passengers to be over-"produced" */
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7891
diff changeset
  2102
				new_prod = Clamp(new_prod, 1, 255);
7945
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2103
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2104
				if (((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) && j == 1)
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2105
					new_prod = Clamp(new_prod, 0, 16);
5cbff3e57db2 (svn r11500) -Codechange: Smooth economy fine-tuning, making industries more responsive. Patch by Sirkoz.
belugas
parents: 7944
diff changeset
  2106
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2107
				/* Do not stop closing the industry when it has the lowest possible production rate */
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2108
				if (new_prod == old_prod && old_prod > 1) {
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2109
					closeit = false;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2110
					continue;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2111
				}
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2112
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2113
				percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2114
				i->production_rate[j] = new_prod;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2115
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2116
				/* Close the industry when it has the lowest possible production rate */
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2117
				if (new_prod > 1) closeit = false;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2118
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2119
				if (abs(percent) >= 10) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2120
					ReportNewsProductionChangeIndustry(i, i->produced_cargo[j], percent);
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2121
				}
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2122
			}
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2123
		} else {
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
  2124
			if (only_decrease || Chance16(1, 3)) {
8203
0e805a0ce012 (svn r11766) -Codechange: Last fine tunings on smooth economy, by Sirkoz.
belugas
parents: 8157
diff changeset
  2125
				/* If more than 60% transported, 66% chance of increase, else 33% chance of increase */
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
  2126
				if (!only_decrease && (i->last_month_pct_transported[0] > PERCENT_TRANSPORTED_60) != Chance16(1, 3)) {
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2127
					mul = 1; // Increase production
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  2128
				} else {
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2129
					div = 1; // Decrease production
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2130
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
			}
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2132
		}
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2133
	}
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2134
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2135
	if (standard && indspec->life_type & INDUSTRYLIFE_PROCESSING) {
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
  2136
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && Chance16(1, smooth_economy ? 180 : 2)) {
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2137
			closeit = true;
7144
8e73641511f3 (svn r10418) -Codechange: implement/resurrect the industry production flags.
rubidium
parents: 7132
diff changeset
  2138
		}
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  2139
	}
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  2140
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2141
	/* Increase if needed */
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  2142
	while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
8517
a185893bcb61 (svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents: 8516
diff changeset
  2143
		i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM);
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2144
		i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF);
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2145
		i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF);
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2146
		if (str == STR_NULL) str = indspec->production_up_text;
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2147
	}
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2148
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2149
	/* Decrease if needed */
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2150
	while (div-- != 0 && !closeit) {
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  2151
		if (i->prod_level == PRODLEVEL_MINIMUM) {
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2152
			closeit = true;
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2153
		} else {
8517
a185893bcb61 (svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents: 8516
diff changeset
  2154
			i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC
a185893bcb61 (svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents: 8516
diff changeset
  2155
			i->production_rate[0] = (i->production_rate[0] + 1) / 2;
a185893bcb61 (svn r12092) -Fix(r11532)[FS#1755]: Make sure the production level will not get out of delimited boundaries, while using var result 0D/0E and than multiplying/dividing it.
belugas
parents: 8516
diff changeset
  2156
			i->production_rate[1] = (i->production_rate[1] + 1) / 2;
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2157
			if (str == STR_NULL) str = indspec->production_down_text;
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2158
		}
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2159
	}
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2160
8406
0f86dbef7522 (svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents: 8383
diff changeset
  2161
	/* Increase or Decreasing the production level if needed */
7976
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2162
	if (increment != 0) {
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  2163
		if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) {
8406
0f86dbef7522 (svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents: 8383
diff changeset
  2164
			closeit = true;
0f86dbef7522 (svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents: 8383
diff changeset
  2165
		} else {
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  2166
			i->prod_level = ClampU(i->prod_level + increment, PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM);
8406
0f86dbef7522 (svn r11976) -Fix: It seems that industries using results 0D/0E on callback cb29/35 were a bit too eager to close down.
belugas
parents: 8383
diff changeset
  2167
		}
7976
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2168
	}
e7b6d94291fc (svn r11532) -Feature[newgrf]: Add decrement(0x0D) / increment(0x0E) production operations from result of production callback cb29/35.
belugas
parents: 7972
diff changeset
  2169
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2170
	/* Close if needed and allowed */
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2171
	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  2172
		i->prod_level = PRODLEVEL_CLOSURE;
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2173
		str = indspec->closure_text;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2174
	}
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2175
7615
8ffd309681c2 (svn r11144) -Codechange: add support for newgrf callbacks 29 and 35
glx
parents: 7613
diff changeset
  2176
	if (!suppress_message && str != STR_NULL) {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2177
		NewsType nt;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2178
		/* Compute news category */
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2179
		if (closeit) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2180
			nt = NT_OPENCLOSE;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2181
		} else {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2182
			switch (WhoCanServiceIndustry(i)) {
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2183
				case 0: nt = NT_INDUSTRY_NOBODY; break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2184
				case 1: nt = NT_INDUSTRY_OTHER;  break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2185
				case 2: nt = NT_INDUSTRY_PLAYER; break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2186
				default: NOT_REACHED(); break;
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2187
			}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2188
		}
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2189
		/* Set parameters of news string */
7755
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2190
		if (str > STR_LAST_STRINGID) {
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2191
			SetDParam(0, STR_TOWN);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2192
			SetDParam(1, i->town->index);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2193
			SetDParam(2, indspec->name);
7870
e8f028f9895f (svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents: 7862
diff changeset
  2194
		} else if (closeit) {
e8f028f9895f (svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents: 7862
diff changeset
  2195
			SetDParam(0, STR_INDUSTRY_FORMAT);
e8f028f9895f (svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents: 7862
diff changeset
  2196
			SetDParam(1, i->town->index);
e8f028f9895f (svn r11420) -Fix [FS#1006]: industry closure news not properly shown when the news item pops up after the industry has been removed from the map.
rubidium
parents: 7862
diff changeset
  2197
			SetDParam(2, indspec->name);
7755
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2198
		} else {
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2199
			SetDParam(0, i->index);
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7748
diff changeset
  2200
		}
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2201
		/* and report the news to the user */
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2202
		AddNewsItem(str,
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8656
diff changeset
  2203
			NM_THIN, NF_VIEWPORT | NF_TILE, nt, DNC_NONE,
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2204
			i->xy + TileDiffXY(1, 1), 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2206
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  2208
void IndustryMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2209
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
	Industry *i;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  2211
	PlayerID old_player = _current_player;
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  2212
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  2214
	FOR_ALL_INDUSTRIES(i) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2215
		UpdateIndustryStatistics(i);
8516
4b3cba59c003 (svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
belugas
parents: 8471
diff changeset
  2216
		if (i->prod_level == PRODLEVEL_CLOSURE) {
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2217
			delete i;
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2218
		} else {
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2219
			ChangeIndustryProduction(i, true);
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2220
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2221
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2222
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  2223
	/* 3% chance that we start a new industry */
7967
a230c063a672 (svn r11523) -Codechange: Move the CHANCE macros to core/random_func.cpp cause they depend on Random()
skidd13
parents: 7948
diff changeset
  2224
	if (Chance16(3, 100)) {
6419
d2e19c0fb769 (svn r9555) -Codechange: Cleanup of industry_cmd (Step-9). Use in-game appearing chances for industry creation.
belugas
parents: 6390
diff changeset
  2225
		MaybeNewIndustry();
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2226
	} else {
4356
ec4e13f21cd0 (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
  2227
		i = GetRandomIndustry();
7613
a186fd355933 (svn r11142) -Codechange: prepare industry production change code for newgrf callbacks 29 and 35
glx
parents: 7610
diff changeset
  2228
		if (i != NULL) ChangeIndustryProduction(i, false);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2229
	}
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  2230
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  2231
	_current_player = old_player;
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  2232
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  2233
	/* production-change */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2234
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2235
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2236
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2238
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  2239
void InitializeIndustries()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2240
{
7401
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7390
diff changeset
  2241
	_Industry_pool.CleanPool();
7a72cc2a1196 (svn r10773) -Codechange: use pool.CleanPool instead of CleanPool(&pool) and similarly for AddBlock*.
rubidium
parents: 7390
diff changeset
  2242
	_Industry_pool.AddBlockToPool();
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2243
6839
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6824
diff changeset
  2244
	ResetIndustryCounts();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2245
	_industry_sort_dirty = true;
4587
859ab734e211 (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
  2246
	_industry_sound_tile = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2247
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
7185
1b6b21b69c2d (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: 7177
diff changeset
  2249
bool IndustrySpec::IsRawIndustry() const
1b6b21b69c2d (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: 7177
diff changeset
  2250
{
1b6b21b69c2d (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: 7177
diff changeset
  2251
	/* Lumber mills are extractive/organic, but can always be built like a non-raw industry */
1b6b21b69c2d (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: 7177
diff changeset
  2252
	return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0 &&
1b6b21b69c2d (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: 7177
diff changeset
  2253
			(this->behaviour & INDUSTRYBEH_CUT_TREES) == 0;
1b6b21b69c2d (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: 7177
diff changeset
  2254
}
1b6b21b69c2d (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: 7177
diff changeset
  2255
1b6b21b69c2d (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: 7177
diff changeset
  2256
Money IndustrySpec::GetConstructionCost() const
1b6b21b69c2d (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: 7177
diff changeset
  2257
{
1b6b21b69c2d (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: 7177
diff changeset
  2258
	return (_price.build_industry *
1b6b21b69c2d (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: 7177
diff changeset
  2259
			(_patches.raw_industry_construction == 1 && this->IsRawIndustry() ?
1b6b21b69c2d (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: 7177
diff changeset
  2260
					this->raw_industry_cost_multiplier :
1b6b21b69c2d (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: 7177
diff changeset
  2261
					this->cost_multiplier
1b6b21b69c2d (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: 7177
diff changeset
  2262
			)) >> 8;
1b6b21b69c2d (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: 7177
diff changeset
  2263
}
1b6b21b69c2d (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: 7177
diff changeset
  2264
7978
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7976
diff changeset
  2265
Money IndustrySpec::GetRemovalCost() const
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7976
diff changeset
  2266
{
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7976
diff changeset
  2267
	return (_price.remove_house * this->removal_cost_multiplier) >> 8;
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7976
diff changeset
  2268
}
c74fc8173339 (svn r11534) -Feature(newgrf): Implement property 23h for Industries.
belugas
parents: 7976
diff changeset
  2269
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7480
diff changeset
  2270
static CommandCost TerraformTile_Industry(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7480
diff changeset
  2271
{
7582
80c8517b08d1 (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: 7577
diff changeset
  2272
	if (AutoslopeEnabled()) {
80c8517b08d1 (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: 7577
diff changeset
  2273
		/* We imitate here TTDP's behaviour:
80c8517b08d1 (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: 7577
diff changeset
  2274
		 *  - Both new and old slope must not be steep.
80c8517b08d1 (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: 7577
diff changeset
  2275
		 *  - TileMaxZ must not be changed.
80c8517b08d1 (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: 7577
diff changeset
  2276
		 *  - Allow autoslope by default.
80c8517b08d1 (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: 7577
diff changeset
  2277
		 *  - Disallow autoslope if callback succeeds and returns non-zero.
80c8517b08d1 (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: 7577
diff changeset
  2278
		 */
80c8517b08d1 (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: 7577
diff changeset
  2279
		Slope tileh_old = GetTileSlope(tile, NULL);
80c8517b08d1 (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: 7577
diff changeset
  2280
		/* TileMaxZ must not be changed. Slopes must not be steep. */
80c8517b08d1 (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: 7577
diff changeset
  2281
		if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
80c8517b08d1 (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: 7577
diff changeset
  2282
			const IndustryGfx gfx = GetIndustryGfx(tile);
80c8517b08d1 (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: 7577
diff changeset
  2283
			const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
80c8517b08d1 (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: 7577
diff changeset
  2284
80c8517b08d1 (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: 7577
diff changeset
  2285
			/* Call callback 3C 'disable autosloping for industry tiles'. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  2286
			if (HasBit(itspec->callback_flags, CBM_INDT_AUTOSLOPE)) {
7582
80c8517b08d1 (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: 7577
diff changeset
  2287
				/* If the callback fails, allow autoslope. */
80c8517b08d1 (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: 7577
diff changeset
  2288
				uint16 res = GetIndustryTileCallback(CBID_INDUSTRY_AUTOSLOPE, 0, 0, gfx, GetIndustryByTile(tile), tile);
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  2289
				if ((res == 0) || (res == CALLBACK_FAILED)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (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: 7577
diff changeset
  2290
			} else {
7891
aef0c16244d7 (svn r11442) -Feature: make news messages related to the industry (production) changes better configurable; you can now disable news messages popping up for industries you are not servicing. Patch by Alberth.
rubidium
parents: 7870
diff changeset
  2291
				/* allow autoslope */
8230
64f28fe2d5c8 (svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium
parents: 8225
diff changeset
  2292
				return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
7582
80c8517b08d1 (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: 7577
diff changeset
  2293
			}
80c8517b08d1 (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: 7577
diff changeset
  2294
		}
80c8517b08d1 (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: 7577
diff changeset
  2295
	}
7637
43e2956af72e (svn r11168) -Fix [FS#1256]: assert on terraforming of industries. Patch by frosch.
rubidium
parents: 7629
diff changeset
  2296
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7480
diff changeset
  2297
}
7185
1b6b21b69c2d (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: 7177
diff changeset
  2298
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2299
extern const TileTypeProcs _tile_type_industry_procs = {
4344
7e123fec5b0b (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
  2300
	DrawTile_Industry,           /* draw_tile_proc */
7e123fec5b0b (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
  2301
	GetSlopeZ_Industry,          /* get_slope_z_proc */
7e123fec5b0b (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
  2302
	ClearTile_Industry,          /* clear_tile_proc */
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
  2303
	GetAcceptedCargo_Industry,   /* get_accepted_cargo_proc */
4344
7e123fec5b0b (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
  2304
	GetTileDesc_Industry,        /* get_tile_desc_proc */
7e123fec5b0b (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
  2305
	GetTileTrackStatus_Industry, /* get_tile_track_status_proc */
7e123fec5b0b (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
  2306
	ClickTile_Industry,          /* click_tile_proc */
7e123fec5b0b (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
  2307
	AnimateTile_Industry,        /* animate_tile_proc */
7e123fec5b0b (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
  2308
	TileLoop_Industry,           /* tile_loop_proc */
7e123fec5b0b (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
  2309
	ChangeTileOwner_Industry,    /* change_tile_owner_proc */
7e123fec5b0b (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
  2310
	GetProducedCargo_Industry,   /* get_produced_cargo_proc */
7e123fec5b0b (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
  2311
	NULL,                        /* vehicle_enter_tile_proc */
7335
141c6b86ec1f (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: 7334
diff changeset
  2312
	GetFoundation_Industry,      /* get_foundation_proc */
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7480
diff changeset
  2313
	TerraformTile_Industry,      /* terraform_tile_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2314
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2315
1881
435d39bd6ee0 (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
  2316
static const SaveLoad _industry_desc[] = {
6819
f986f54e2660 (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: 6815
diff changeset
  2317
	SLE_CONDVAR(Industry, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
f986f54e2660 (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: 6815
diff changeset
  2318
	SLE_CONDVAR(Industry, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
f986f54e2660 (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: 6815
diff changeset
  2319
	    SLE_VAR(Industry, width,                      SLE_UINT8),
f986f54e2660 (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: 6815
diff changeset
  2320
	    SLE_VAR(Industry, height,                     SLE_UINT8),
f986f54e2660 (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: 6815
diff changeset
  2321
	    SLE_REF(Industry, town,                       REF_TOWN),
8359
6efdb08cedb8 (svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents: 8311
diff changeset
  2322
	SLE_CONDNULL( 2, 0, 60),       ///< used to be industry's produced_cargo
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  2323
	SLE_CONDARR(Industry, produced_cargo,             SLE_UINT8,  2,              78, SL_MAX_VERSION),
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  2324
	SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16, 3,              70, SL_MAX_VERSION),
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7151
diff changeset
  2325
	    SLE_ARR(Industry, produced_cargo_waiting,     SLE_UINT16, 2),
6819
f986f54e2660 (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: 6815
diff changeset
  2326
	    SLE_ARR(Industry, production_rate,            SLE_UINT8,  2),
8359
6efdb08cedb8 (svn r11925) -Fix (r122, r9867): loading old, pre savegame version 2, savegames.
rubidium
parents: 8311
diff changeset
  2327
	SLE_CONDNULL( 3, 0, 60),       ///< used to be industry's accepts_cargo
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7640
diff changeset
  2328
	SLE_CONDARR(Industry, accepts_cargo,              SLE_UINT8,  3,              78, SL_MAX_VERSION),
6819
f986f54e2660 (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: 6815
diff changeset
  2329
	    SLE_VAR(Industry, prod_level,                 SLE_UINT8),
f986f54e2660 (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: 6815
diff changeset
  2330
	    SLE_ARR(Industry, this_month_production,      SLE_UINT16, 2),
f986f54e2660 (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: 6815
diff changeset
  2331
	    SLE_ARR(Industry, this_month_transported,     SLE_UINT16, 2),
f986f54e2660 (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: 6815
diff changeset
  2332
	    SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8,  2),
f986f54e2660 (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: 6815
diff changeset
  2333
	    SLE_ARR(Industry, last_month_production,      SLE_UINT16, 2),
f986f54e2660 (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: 6815
diff changeset
  2334
	    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
  2335
6819
f986f54e2660 (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: 6815
diff changeset
  2336
	    SLE_VAR(Industry, counter,                    SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2337
6819
f986f54e2660 (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: 6815
diff changeset
  2338
	    SLE_VAR(Industry, type,                       SLE_UINT8),
f986f54e2660 (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: 6815
diff changeset
  2339
	    SLE_VAR(Industry, owner,                      SLE_UINT8),
f986f54e2660 (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: 6815
diff changeset
  2340
	    SLE_VAR(Industry, random_color,               SLE_UINT8),
f986f54e2660 (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: 6815
diff changeset
  2341
	SLE_CONDVAR(Industry, last_prod_year,             SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
f986f54e2660 (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: 6815
diff changeset
  2342
	SLE_CONDVAR(Industry, last_prod_year,             SLE_INT32,                 31, SL_MAX_VERSION),
f986f54e2660 (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: 6815
diff changeset
  2343
	    SLE_VAR(Industry, was_cargo_delivered,        SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2344
7522
050baf772f07 (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: 7494
diff changeset
  2345
	SLE_CONDVAR(Industry, founder,                    SLE_UINT8,                 70, SL_MAX_VERSION),
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  2346
	SLE_CONDVAR(Industry, construction_date,          SLE_INT32,                 70, SL_MAX_VERSION),
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  2347
	SLE_CONDVAR(Industry, construction_type,          SLE_UINT8,                 70, SL_MAX_VERSION),
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  2348
	SLE_CONDVAR(Industry, last_cargo_accepted_at,     SLE_INT32,                 70, SL_MAX_VERSION),
7445
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7420
diff changeset
  2349
	SLE_CONDVAR(Industry, selected_layout,            SLE_UINT8,                 73, SL_MAX_VERSION),
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7185
diff changeset
  2350
7610
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
  2351
	SLE_CONDARRX(cpp_offsetof(Industry, psa) + cpp_offsetof(Industry::PersistentStorage, storage), SLE_UINT32, 16, 76, SL_MAX_VERSION),
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7608
diff changeset
  2352
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7853
diff changeset
  2353
	SLE_CONDVAR(Industry, random_triggers,            SLE_UINT8,                 82, SL_MAX_VERSION),
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7853
diff changeset
  2354
	SLE_CONDVAR(Industry, random,                     SLE_UINT16,                82, SL_MAX_VERSION),
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7853
diff changeset
  2355
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6092
diff changeset
  2356
	/* reserve extra space in savegame here. (currently 32 bytes) */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3173
diff changeset
  2357
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2358
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2359
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2360
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2361
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  2362
static void Save_INDY()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2363
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2364
	Industry *ind;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2365
7288
9059a49c2102 (svn r10635) -Codechange: Correct some typos and code beautifying (a little bit)
belugas
parents: 7266
diff changeset
  2366
	/* Write the industries */
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  2367
	FOR_ALL_INDUSTRIES(ind) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2368
		SlSetArrayIndex(ind->index);
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  2369
		SlObject(ind, _industry_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2370
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2371
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2372
7290
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2373
/* Save and load the mapping between the industry/tile id on the map, and the grf file
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2374
 * it came from. */
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2375
static const SaveLoad _industries_id_mapping_desc[] = {
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2376
	SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2377
	SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2378
	SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2379
	SLE_END()
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2380
};
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2381
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2382
static void Save_IIDS()
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2383
{
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2384
	uint i;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2385
	uint j = _industry_mngr.GetMaxMapping();
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2386
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2387
	for (i = 0; i < j; i++) {
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2388
		SlSetArrayIndex(i);
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2389
		SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2390
	}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2391
}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2392
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2393
static void Save_TIDS()
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2394
{
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2395
	uint i;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2396
	uint j = _industile_mngr.GetMaxMapping();
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2397
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2398
	for (i = 0; i < j; i++) {
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2399
		SlSetArrayIndex(i);
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2400
		SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2401
	}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2402
}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2403
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
  2404
static void Load_INDY()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2405
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2406
	int index;
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  2407
6839
2cc0a04fa761 (svn r10078) -Codechange: Centralize all industry counts data and access
belugas
parents: 6824
diff changeset
  2408
	ResetIndustryCounts();
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  2409
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2410
	while ((index = SlIterateArray()) != -1) {
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7338
diff changeset
  2411
		Industry *i = new (index) Industry();
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  2412
		SlObject(i, _industry_desc);
6824
b37cba5bf2ca (svn r10063) -Codechange: Change VARDEF for extern
belugas
parents: 6819
diff changeset
  2413
		IncIndustryTypeCount(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2414
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2415
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2416
7290
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2417
static void Load_IIDS()
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2418
{
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2419
	int index;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2420
	uint max_id;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2421
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2422
	/* clear the current mapping stored.
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2423
	 * This will create the manager if ever it is not yet done */
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2424
	_industry_mngr.ResetMapping();
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2425
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2426
	/* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2427
	max_id = _industry_mngr.GetMaxMapping();
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2428
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2429
	while ((index = SlIterateArray()) != -1) {
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2430
		if ((uint)index >= max_id) break;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2431
		SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2432
	}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2433
}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2434
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2435
static void Load_TIDS()
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2436
{
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2437
	int index;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2438
	uint max_id;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2439
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2440
	/* clear the current mapping stored.
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2441
	 * This will create the manager if ever it is not yet done */
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2442
	_industile_mngr.ResetMapping();
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2443
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2444
	/* get boundary for the temporary map loader NUM_INDUSTILES? */
7292
1e15f344fc54 (svn r10640) -Fix(r10638): little typo...
belugas
parents: 7291
diff changeset
  2445
	max_id = _industile_mngr.GetMaxMapping();
7290
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2446
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2447
	while ((index = SlIterateArray()) != -1) {
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2448
		if ((uint)index >= max_id) break;
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2449
		SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2450
	}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2451
}
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2452
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  2453
extern const ChunkHandler _industry_chunk_handlers[] = {
7290
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2454
	{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY},
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2455
	{ 'IIDS', Save_IIDS, Load_IIDS, CH_ARRAY},
bb6d72d5230a (svn r10638) -Codechange: Save the mapping of the industries and tiles, making them persistent.
belugas
parents: 7288
diff changeset
  2456
	{ '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
  2457
};