src/industry_cmd.cpp
author KUDr
Sat, 21 Apr 2007 08:23:57 +0000
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
permissions -rw-r--r--
(svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
     3
/** @file industry_cmd.cpp */
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3094
diff changeset
     7
#include "clear_map.h"
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
     8
#include "functions.h"
3314
b8b234d4584f (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
     9
#include "industry_map.h"
3338
2c60ed0dcce3 (svn r4120) Use the new station functions where appropriate
tron
parents: 3331
diff changeset
    10
#include "station_map.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
    11
#include "table/strings.h"
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
    12
#include "table/sprites.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 552
diff changeset
    13
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1202
diff changeset
    14
#include "tile.h"
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
    15
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
#include "economy.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 314
diff changeset
    24
#include "sound.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    25
#include "variables.h"
3654
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    26
#include "table/industry_land.h"
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
    27
#include "table/build_industry.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    28
#include "genworld.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4231
diff changeset
    29
#include "date.h"
5056
20369e09627b (svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents: 4976
diff changeset
    30
#include "water_map.h"
6160
126831e48987 (svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents: 6135
diff changeset
    31
#include "tree_map.h"
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
    32
#include "cargotype.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    34
void ShowIndustryViewWindow(int industry);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    35
void BuildOilRig(TileIndex tile);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    36
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    37
static byte _industry_sound_ctr;
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    38
static TileIndex _industry_sound_tile;
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
    39
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    40
/**
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    41
 * Called if a new block is added to the industry-pool
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    42
 */
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2737
diff changeset
    43
static void IndustryPoolNewBlock(uint start_item)
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    44
{
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    45
	Industry *i;
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    46
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    47
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    48
	 * TODO - This is just a temporary stage, this will be removed. */
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4965
diff changeset
    49
	for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) i->index = start_item++;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    50
}
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    51
5216
d581e4db95b6 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 5118
diff changeset
    52
DEFINE_OLD_POOL(Industry, Industry, IndustryPoolNewBlock, NULL)
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    53
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    54
/**
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    55
 * Retrieve the type for this industry.  Although it is accessed by a tile,
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    56
 * it will return the general type of industry, and not the sprite index
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    57
 * as would do GetIndustryGfx.
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    58
 * The same information can be accessed by looking at Industry->type
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    59
 * @param tile that is queried
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    60
 * @pre IsTileType(tile, MP_INDUSTRY)
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    61
 * @return general type for this industry, as defined in industry.h
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    62
 **/
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    63
IndustryType GetIndustryType(TileIndex tile)
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    64
{
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    65
	IndustryGfx this_type = GetIndustryGfx(tile);
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    66
	IndustryType iloop;
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    67
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    68
	assert(IsTileType(tile, MP_INDUSTRY));
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    69
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
    70
	for (iloop = IT_COAL_MINE; iloop < NUM_INDUSTRYTYPES; iloop += 1) {
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
    71
		if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
    72
				industry_gfx_Solver[iloop].MaxGfx + 1)) {
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    73
			return iloop;
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    74
		}
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    75
	}
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    76
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    77
	return IT_INVALID;  //we have not found equivalent, whatever the reason
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
    78
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    80
/**
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    81
 * Accessor for array _industry_specs.
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    82
 * This will ensure at once : proper access and
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    83
 * not allowing modifications of it.
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
    84
 * @param thistype of industry (which is the index in _industry_specs)
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
    85
 * @pre thistype < NUM_INDUSTRYTYPES
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    86
 * @return a pointer to the corresponding industry spec
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    87
 **/
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3669
diff changeset
    88
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    89
{
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
    90
	assert(thistype < NUM_INDUSTRYTYPES);
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    91
	return &_industry_specs[thistype];
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    92
}
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
    93
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    94
/**
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    95
 * Accessor for array _industry_tile_specs.
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    96
 * This will ensure at once : proper access and
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    97
 * not allowing modifications of it.
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    98
 * @param gfx of industrytile (which is the index in _industry_specs)
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
    99
 * @pre gfx < NUM_INDUSTRY_GFXES
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
   100
 * @return a pointer to the corresponding industrytile spec
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
   101
 **/
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   102
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   103
{
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   104
	assert(gfx < NUM_INDUSTRY_GFXES);
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   105
	return &_industry_tile_specs[gfx];
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   106
}
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   107
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   108
void DestroyIndustry(Industry *i)
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   109
{
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   110
	BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   111
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   112
			if (GetIndustryIndex(tile_cur) == i->index) {
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   113
				DoClearSquare(tile_cur);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   114
			}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   115
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   116
			DeleteOilRig(tile_cur);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   117
		}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   118
	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   119
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   120
	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   121
		/* Remove the farmland and convert it to regular tiles over time. */
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   122
		BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
4815
c2a54b213fde (svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents: 4607
diff changeset
   123
			tile_cur = TILE_MASK(tile_cur);
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   124
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   125
					GetIndustryIndexOfField(tile_cur) == i->index) {
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   126
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   127
			}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   128
		} END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21))
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   129
	}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   130
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   131
	_industry_sort_dirty = true;
5298
6d4c150bdd94 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
   132
	_total_industries--;
4403
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   133
	DeleteSubsidyWithIndustry(i->index);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   134
	DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   135
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   136
}
851d2a602806 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   137
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   138
static void IndustryDrawSugarMine(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
{
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   140
	const DrawIndustryAnimationStruct *d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   142
	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
   143
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   144
	d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   146
	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
   147
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   148
	if (d->image_2 != 0) {
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   149
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   150
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   152
	if (d->image_3 != 0) {
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   153
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   154
			_drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   155
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   158
static void IndustryDrawToffeeQuarry(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
{
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   160
	uint8 x = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   161
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   162
	if (IsIndustryCompleted(ti->tile)) {
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   163
		x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)];
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   164
		if (x == 0xFF)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   168
	AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   169
	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
   170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   172
static void IndustryDrawBubbleGenerator( const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
{
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   174
	if (IsIndustryCompleted(ti->tile)) {
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   175
		AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   176
	} else {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   177
		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
   178
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   181
static void IndustryDrawToyFactory(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
{
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   183
	const DrawIndustryAnimationStruct *d;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   185
	d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	if (d->image_1 != 0xFF) {
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   188
		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
   189
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	if (d->image_2 != 0xFF) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   192
		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
   193
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   195
	AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   196
	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
   197
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   199
static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
{
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   201
	if (IsIndustryCompleted(ti->tile)) {
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   202
		uint8 image = GetIndustryAnimationState(ti->tile);
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   203
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		if (image != 0 && image < 7) {
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   205
			AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   206
				PAL_NONE,
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   207
				_coal_plant_sparks[image - 1].x,
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   208
				_coal_plant_sparks[image - 1].y
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   214
typedef void IndustryDrawTileProc(const TileInfo *ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   216
	IndustryDrawSugarMine,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   217
	IndustryDrawToffeeQuarry,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   218
	IndustryDrawBubbleGenerator,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   219
	IndustryDrawToyFactory,
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   220
	IndustryDrawCoalPlantSparks,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
static void DrawTile_Industry(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
{
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5686
diff changeset
   225
	const IndustryGfx gfx = GetIndustryGfx(ti->tile);
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   226
	const Industry *ind;
3654
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   227
	const DrawBuildingsTileStruct *dits;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	byte z;
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   229
	SpriteID image;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   230
	SpriteID pal;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	/* Pointer to industry */
3314
b8b234d4584f (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   233
	ind = GetIndustryByTile(ti->tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	/* Retrieve pointer to the draw industry tile struct */
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   236
	dits = &_industry_draw_tile_data[gfx << 2 | (GetIndustryTileSpec(gfx)->anim_state ?
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5686
diff changeset
   237
			GetIndustryAnimationState(ti->tile) & 3 :
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5686
diff changeset
   238
			GetIndustryConstructionStage(ti->tile))];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   240
	image = dits->ground.sprite;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   241
	if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   242
		pal = GENERAL_SPRITE_COLOR(ind->random_color);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   243
	} else {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   244
		pal = dits->ground.pal;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   245
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	/* Add bricks below the industry? */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   249
	if (ti->tileh != SLOPE_FLAT) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   250
		AddSortableSpriteToDraw(SPR_FOUNDATION_BASE + ti->tileh, PAL_NONE, ti->x, ti->y, 16, 16, 7, z);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   251
		AddChildSpriteScreen(image, pal, 31, 1);
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   252
		z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		/* Else draw regular ground */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   255
		DrawGroundSprite(image, pal);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	/* Add industry on top of the ground? */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   259
	image = dits->building.sprite;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   260
	if (image != 0) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   261
		if (HASBIT(_transparent_opt, TO_INDUSTRIES)) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   262
			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   263
			pal = PALETTE_TO_TRANSPARENT;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   264
		} else {
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   265
			pal = dits->building.pal;
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   266
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   267
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   268
		AddSortableSpriteToDraw(image, pal,
2653
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   269
			ti->x + dits->subtile_x,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   270
			ti->y + dits->subtile_y,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   271
			dits->width  + 1,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   272
			dits->height + 1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
			dits->dz,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
			z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   276
		if (HASBIT(_transparent_opt, TO_INDUSTRIES)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   279
	{
3654
4a3f8056a61c (svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents: 3645
diff changeset
   280
		int proc = dits->draw_proc - 1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   281
		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
   282
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   285
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y)
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   286
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4077
diff changeset
   287
	return GetTileMaxZ(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   290
static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh)
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   291
{
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
   292
	return SLOPE_FLAT;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   293
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   294
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   295
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
{
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   297
	const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   298
	CargoID a;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   300
	a = itspec->accepts_cargo[0];
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   301
	if (a != CT_INVALID) ac[a] = (a == CT_PASSENGERS) ? 1 : 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   303
	a = itspec->accepts_cargo[1];
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   304
	if (a != CT_INVALID) ac[a] = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
   306
	a = itspec->accepts_cargo[2];
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   307
	if (a != CT_INVALID) ac[a] = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   310
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   312
	const Industry *i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	td->owner = i->owner;
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
   315
	td->str = GetIndustrySpec(i->type)->name;
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   316
	if (!IsIndustryCompleted(tile)) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   317
		SetDParamX(td->dparam, 0, td->str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
		td->str = STR_2058_UNDER_CONSTRUCTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   322
static int32 ClearTile_Industry(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   324
	Industry *i = GetIndustryByTile(tile);
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   325
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   327
	/* water can destroy industries
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   328
	 * in editor you can bulldoze industries
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   329
	 * with magic_bulldozer cheat you can destroy industries
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   330
	 * (area around OILRIG is water, so water shouldn't flood it
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   331
	 */
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   332
	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
   333
			!_cheats.magic_bulldozer.value) ||
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   334
			(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   335
		SetDParam(0, indspec->name);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
		return_cmd_error(STR_4800_IN_THE_WAY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   339
	if (flags & DC_EXEC) DeleteIndustry(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   343
static void TransportIndustryGoods(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   345
	Industry *i = GetIndustryByTile(tile);
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   346
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	uint cw, am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   349
	cw = min(i->cargo_waiting[0], 255);
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   350
	if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
		i->cargo_waiting[0] -= cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
		/* fluctuating economy? */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   354
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		i->last_mo_production[0] += cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
		i->last_mo_transported[0] += am;
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   360
		if (am != 0) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   361
			uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   362
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   363
			if (newgfx != INDUTILE_NOANIM) {
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   364
				ResetIndustryConstructionStage(tile);
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   365
				SetIndustryCompleted(tile, true);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   366
				SetIndustryGfx(tile, newgfx);
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   367
				MarkTileDirtyByTile(tile);
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   368
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	cw = min(i->cargo_waiting[1], 255);
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
   373
	if (cw > indspec->minimal_cargo) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
		i->cargo_waiting[1] -= cw;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   375
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   376
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   377
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
		i->last_mo_production[1] += cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
		i->last_mo_transported[1] += am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   386
static void AnimateTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
{
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   388
	byte m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   390
	switch (GetIndustryGfx(tile)) {
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   391
	case GFX_SUGAR_MINE_SIEVE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
		if ((_tick_counter & 1) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   393
			m = GetIndustryAnimationState(tile) + 1;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   394
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2868
diff changeset
   395
			switch (m & 7) {
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
   396
			case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   397
			case 6: SndPlayTileFx(SND_29_RIP, tile); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
			if (m >= 96) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
			}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   404
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   410
	case GFX_TOFFEE_QUARY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		if ((_tick_counter & 3) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   412
			m = GetIndustryAnimationState(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   413
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   414
			if (_industry_anim_offs_toffee[m] == 0xFF) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   415
				SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
			if (++m >= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
			}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   422
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   428
	case GFX_BUBBLE_CATCHER:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   429
		if ((_tick_counter & 1) == 0) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   430
			m = GetIndustryAnimationState(tile);
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
			if (++m >= 40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
			}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   436
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
   442
	/* Sparks on a coal plant */
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   443
	case GFX_POWERPLANT_SPARKS:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		if ((_tick_counter & 3) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   445
			m = GetIndustryAnimationState(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   446
			if (m == 6) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   447
				SetIndustryAnimationState(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
			} else {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   450
				SetIndustryAnimationState(tile, m + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   456
	case GFX_TOY_FACTORY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		if ((_tick_counter & 1) == 0) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   458
			m = GetIndustryAnimationState(tile) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   460
			switch (m) {
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   461
				case  1: SndPlayTileFx(SND_2C_MACHINERY, tile); break;
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   462
				case 23: SndPlayTileFx(SND_2B_COMEDY_HIT, tile); break;
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   463
				case 28: SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); break;
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   464
				default:
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   465
					if (m >= 50) {
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   466
						int n = GetIndustryAnimationLoop(tile) + 1;
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   467
						m = 0;
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   468
						if (n >= 8) {
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   469
							n = 0;
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   470
							DeleteAnimatedTile(tile);
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   471
						}
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   472
						SetIndustryAnimationLoop(tile, n);
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   473
					}
0
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
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   476
			SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
5685
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   481
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   482
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   483
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   484
	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
   485
		if ((_tick_counter & 3) == 0) {
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   486
			IndustryGfx gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   488
			gfx = (gfx < 155) ? gfx + 1 : 148;
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   489
			SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   494
	case GFX_OILWELL_ANIMATED_1:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   495
	case GFX_OILWELL_ANIMATED_2:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   496
	case GFX_OILWELL_ANIMATED_3:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		if ((_tick_counter & 7) == 0) {
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   498
			bool b = CHANCE16(1, 7);
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   499
			IndustryGfx gfx = GetIndustryGfx(tile);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   500
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   501
			m = GetIndustryAnimationState(tile) + 1;
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   502
			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   503
				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   504
				SetIndustryConstructionStage(tile, 3);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   505
				DeleteAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
			} else {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   507
				SetIndustryAnimationState(tile, m);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   508
				SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   514
	case GFX_COAL_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   515
	case GFX_COPPER_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   516
	case GFX_GOLD_MINE_TOWER_ANIMATED: {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
			int state = _tick_counter & 0x7FF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
			if ((state -= 0x400) < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
			if (state < 0x1A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
				if (state < 0x20 || state >= 0x180) {
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   524
					m = GetIndustryAnimationState(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   525
					if (!(m & 0x40)) {
5687
a6f0e780d714 (svn r7642) -Codechange: unify all the different locations where the animation state is stored into a single location.
rubidium
parents: 5686
diff changeset
   526
						SetIndustryAnimationState(tile, m | 0x40);
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   527
						SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
					if (state & 7)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
					if (state & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
				}
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   535
				m = (GetIndustryAnimationState(tile) + 1) | 0x40;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
				if (m > 0xC2) m = 0xC0;
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   537
				SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
			} else if (state >= 0x200 && state < 0x3A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
				int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
				i = (state < 0x220 || state >= 0x380) ? 7 : 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
				if (state & i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   545
				m = (GetIndustryAnimationState(tile) & 0xBF) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
				if (m < 0x80) m = 0x82;
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   547
				SetIndustryAnimationState(tile, m);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   554
static void CreateIndustryEffectSmoke(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
{
3773
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   556
	uint x = TileX(tile) * TILE_SIZE;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   557
	uint y = TileY(tile) * TILE_SIZE;
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   558
	uint z = GetTileMaxZ(tile);
3094
5be98607b6d5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   559
3773
996897ffc8ea (svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents: 3689
diff changeset
   560
	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
   561
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   563
static void MakeIndustryTileBigger(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
{
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   565
	byte cnt = GetIndustryConstructionCounter(tile) + 1;
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   566
	byte stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   568
	if (cnt != 4) {
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   569
		SetIndustryConstructionCounter(tile, cnt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   573
	stage = GetIndustryConstructionStage(tile) + 1;
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   574
	SetIndustryConstructionCounter(tile, 0);
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   575
	SetIndustryConstructionStage(tile, stage);
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   576
	if (stage == 3) {
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   577
		SetIndustryCompleted(tile, true);
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   578
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   579
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   582
	if (!IsIndustryCompleted(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   584
	switch (GetIndustryGfx(tile)) {
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   585
	case GFX_POWERPLANT_CHIMNEY:
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   586
		CreateIndustryEffectSmoke(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
4607
2215d3175ad1 (svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents: 4587
diff changeset
   589
	case GFX_OILRIG_1:
2215d3175ad1 (svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents: 4587
diff changeset
   590
		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
   591
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
3545
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   593
	case GFX_TOY_FACTORY:
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   594
	case GFX_BUBBLE_CATCHER:
3e66bf329257 (svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents: 3538
diff changeset
   595
	case GFX_TOFFEE_QUARY:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   596
		SetIndustryAnimationState(tile, 0);
3538
3eb71c726341 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
   597
		SetIndustryAnimationLoop(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
5685
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   600
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   601
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   602
	case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
b88aca81aa7b (svn r7640) -Codechange: move a table from industry_cmd.c to table/industry_land
rubidium
parents: 5319
diff changeset
   603
	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
   604
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   610
static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
	int dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	static const int8 _tileloop_ind_case_161[12] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   615
		11,   0, -4, -14,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   616
		-4, -10, -4,   1,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   617
		49,  59, 60,  65,
0
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
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   620
	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
   621
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	dir = Random() & 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	v = CreateEffectVehicleAbove(
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   625
		TileX(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 0],
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   626
		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
   627
		_tileloop_ind_case_161[dir + 8],
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1335
diff changeset
   628
		EV_BUBBLE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   631
	if (v != NULL) v->u.special.unk2 = dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   634
static void TileLoop_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
{
3499
e95d6e5f66ae (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   636
	IndustryGfx newgfx;
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   637
	IndustryGfx gfx;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
3321
c5f2375046bc (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   639
	if (!IsIndustryCompleted(tile)) {
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   640
		MakeIndustryTileBigger(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   644
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
	TransportIndustryGoods(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   648
	newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   649
	if (newgfx != INDUTILE_NOANIM) {
3495
f7d3ae07f4aa (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   650
		ResetIndustryConstructionStage(tile);
3331
917914fbbf3c (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   651
		SetIndustryGfx(tile, newgfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   656
	gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   658
	switch (gfx) {
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   659
	case GFX_OILRIG_1: // coast line at oilrigs
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   660
	case GFX_OILRIG_2:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   661
	case GFX_OILRIG_3:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   662
	case GFX_OILRIG_4:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   663
	case GFX_OILRIG_5:
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   664
		TileLoop_Water(tile);
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   665
		break;
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   666
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   667
	case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   668
	case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   669
	case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   670
		if (!(_tick_counter & 0x400) && CHANCE16(1, 2)) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   671
			switch (gfx) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   672
				case GFX_COAL_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   673
				case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   674
				case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   675
			}
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   676
			SetIndustryGfx(tile, gfx);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   677
			SetIndustryAnimationState(tile, 0x80);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   678
			AddAnimatedTile(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   679
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   682
	case GFX_OILWELL_NOT_ANIMATED:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   683
		if (CHANCE16(1, 6)) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   684
			SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   685
			SetIndustryAnimationState(tile, 0);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   686
			AddAnimatedTile(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   687
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   690
	case GFX_COAL_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   691
	case GFX_COPPER_MINE_TOWER_ANIMATED:
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   692
	case GFX_GOLD_MINE_TOWER_ANIMATED:
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   693
		if (!(_tick_counter & 0x400)) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   694
			switch (gfx) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   695
				case GFX_COAL_MINE_TOWER_ANIMATED:   gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   696
				case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   697
				case GFX_GOLD_MINE_TOWER_ANIMATED:   gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED;   break;
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   698
			}
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   699
			SetIndustryGfx(tile, gfx);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   700
			SetIndustryCompleted(tile, true);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   701
			SetIndustryConstructionStage(tile, 3);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   702
			DeleteAnimatedTile(tile);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
   703
		}
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   704
		break;
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   705
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   706
	case GFX_POWERPLANT_SPARKS:
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   707
		if (CHANCE16(1, 3)) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   708
			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
			AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   713
	case GFX_COPPER_MINE_CHIMNEY:
3421
8ab76c47c72c (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   714
		CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   715
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   718
	case GFX_TOY_FACTORY: {
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   719
			Industry *i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
			if (i->was_cargo_delivered) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
				i->was_cargo_delivered = false;
3538
3eb71c726341 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
   722
				SetIndustryAnimationLoop(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
				AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   728
	case GFX_BUBBLE_GENERATOR:
3290
1a02d5e9205c (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   729
		TileLoopIndustry_BubbleGenerator(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   730
		break;
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   731
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   732
	case GFX_TOFFEE_QUARY:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
4583
45b8bf91b1e3 (svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents: 4434
diff changeset
   736
	case GFX_SUGAR_MINE_SIEVE:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   737
		if (CHANCE16(1, 3)) AddAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   743
static void ClickTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
{
3314
b8b234d4584f (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   745
	ShowIndustryViewWindow(GetIndustryIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   748
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
3344
d86c852715fa (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   753
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   755
	const Industry *i = GetIndustryByTile(tile);
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
   756
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	b[0] = i->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
	b[1] = i->produced_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   761
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
   762
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
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
   767
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   768
static bool IsBadFarmFieldTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   770
	switch (GetTileType(tile)) {
5935
6f5ae5d8d407 (svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents: 5919
diff changeset
   771
		case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   772
		case MP_TREES: return false;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   773
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   777
static bool IsBadFarmFieldTile2(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   779
	switch (GetTileType(tile)) {
5935
6f5ae5d8d407 (svn r8145) -Featurette: Allow for Tropic Farm to plant fields after producing cargo, like its counterpart in temperate climate.
belugas
parents: 5919
diff changeset
   780
		case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   781
		case MP_TREES: return false;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   782
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   786
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
   787
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
		tile = TILE_MASK(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   790
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
   791
		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   792
			byte or_ = type;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   793
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   794
			if (or_ == 1 && CHANCE16(1, 7)) or_ = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   796
			if (direction == AXIS_X) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   797
				SetFenceSE(tile, or_);
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   798
			} else {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   799
				SetFenceSW(tile, or_);
0
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
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   802
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   803
		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
   804
	} while (--size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
4330
7306bda145ab (svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents: 4329
diff changeset
   807
static void PlantFarmField(TileIndex tile, IndustryID industry)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
	uint size_x, size_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	uint32 r;
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   811
	uint count;
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   812
	uint counter;
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   813
	uint field_type;
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   814
	int type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   816
	if (_opt.landscape == LT_ARCTIC) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   817
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
	}
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
	/* determine field size */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	r = (Random() & 0x303) + 0x404;
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   823
	if (_opt.landscape == LT_ARCTIC) r += 0x404;
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   824
	size_x = GB(r, 0, 8);
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   825
	size_y = GB(r, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	/* offset tile to match size */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   828
	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
   829
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	/* check the amount of bad tiles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
	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
   833
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
		count += IsBadFarmFieldTile(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   836
	if (count * 2 >= size_x * size_y) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
	/* determine type of field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
	r = Random();
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   840
	counter = GB(r, 5, 3);
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   841
	field_type = GB(r, 8, 8) * 9 >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
	/* make field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	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
   845
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		if (!IsBadFarmFieldTile2(cur_tile)) {
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   847
			MakeField(cur_tile, field_type, industry);
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   848
			SetClearCounter(cur_tile, counter);
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   849
			MarkTileDirtyByTile(cur_tile);
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
	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
   852
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
	type = 3;
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
   854
	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
   855
		type = _plantfarmfield_type[Random() & 0xF];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
3157
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   858
	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   859
	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   860
	SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y);
40de8616c04c (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   861
	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
   862
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   864
void PlantRandomFarmField(const Industry *i)
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   865
{
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   866
	int x = i->width  / 2 + Random() % 31 - 16;
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   867
	int y = i->height / 2 + Random() % 31 - 16;
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   868
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   869
	TileIndex tile = TileAddWrap(i->xy, x, y);
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   870
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   871
	if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   872
}
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   873
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
   874
static void MaybePlantFarmField(const Industry *i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
{
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   876
	if (CHANCE16(1, 8)) PlantRandomFarmField(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   879
/**
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   880
 * Search callback function for ChopLumberMillTrees
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   881
 * @param tile to test
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   882
 * @param data that is passed by the caller.  In this case, nothing
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
   883
 * @return the result of the test
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   884
 */
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   885
static bool SearchLumberMillTrees(TileIndex tile, uint32 data)
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   886
{
6160
126831e48987 (svn r8535) -Feature: Allow lumbermill to cut trees only when they are full grown.
belugas
parents: 6135
diff changeset
   887
	if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   888
		PlayerID old_player = _current_player;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   889
		/* found a tree */
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   890
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   891
		_current_player = OWNER_NONE;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   892
		_industry_sound_ctr = 1;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   893
		_industry_sound_tile = tile;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   894
		SndPlayTileFx(SND_38_CHAINSAW, tile);
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   895
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   896
		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   897
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   898
		_current_player = old_player;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   899
		return true;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   900
	}
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   901
	return false;
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   902
}
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   903
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   904
/**
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   905
 * Perform a circular search around the Lumber Mill in order to find trees to cut
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   906
 * @param i industry
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   907
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
static void ChopLumberMillTrees(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
{
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   910
	TileIndex tile = i->xy;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   911
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   912
	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
   913
5118
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   914
	if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles  to search
5a56a0f12206 (svn r7198) -Codechange: Implement a circular tile search function.
belugas
parents: 5056
diff changeset
   915
		i->cargo_waiting[0] = min(0xffff, i->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
   916
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
static const byte _industry_sounds[37][2] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   921
	{1, SND_28_SAWMILL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   925
	{1, SND_03_FACTORY_WHISTLE},
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   926
	{1, SND_03_FACTORY_WHISTLE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   928
	{3, SND_24_SHEEP},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   933
	{1, SND_28_SAWMILL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   942
	{1, SND_03_FACTORY_WHISTLE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   951
	{1, SND_33_PLASTIC_MINE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
static void ProduceIndustryGoods(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	uint num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
	/* play a sound? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	if ((i->counter & 0x3F) == 0) {
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   966
		if (CHANCE16R(1, 14, r) && (num = _industry_sounds[i->type][0]) != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
			SndPlayTileFx(
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   968
				(SoundFx)(_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16)),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
				i->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
	i->counter--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	/* produce some cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	if ((i->counter & 0xFF) == 0) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   977
		IndustyBehaviour indbehav = GetIndustrySpec(i->type)->behaviour;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
		i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   981
		if (indbehav & INDUSTRYBEH_PLANT_FIELDS) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
			MaybePlantFarmField(i);
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   983
		} else if ((indbehav & INDUSTRYBEH_CUT_TREES) && (i->counter & 0x1FF) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
			ChopLumberMillTrees(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   985
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
   989
void OnTick_Industry()
0
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
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	if (_industry_sound_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
		_industry_sound_ctr++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
		if (_industry_sound_ctr == 75) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   997
			SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
		} 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
   999
			_industry_sound_ctr = 0;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1000
			SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile);
0
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
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1004
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1006
	FOR_ALL_INDUSTRIES(i) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1007
		ProduceIndustryGoods(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1012
static bool CheckNewIndustry_NULL(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1017
static bool CheckNewIndustry_Forest(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
  1019
	if (_opt.landscape == LT_ARCTIC) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
  1020
		if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1028
static bool CheckNewIndustry_OilRefinery(TileIndex tile)
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1029
{
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1030
	if (_game_mode == GM_EDITOR) return true;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1031
	if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true;
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1032
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1033
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1034
	return false;
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1035
}
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1036
7
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1037
extern bool _ignore_restrictions;
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1038
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1039
static bool CheckNewIndustry_OilRig(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1041
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1042
	if (TileHeight(tile) == 0 &&
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1043
			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
  1044
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
	return false;
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
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1049
static bool CheckNewIndustry_Farm(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
  1051
	if (_opt.landscape == LT_ARCTIC) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6298
diff changeset
  1052
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
			_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
		}
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
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1060
static bool CheckNewIndustry_Plantation(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1062
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1070
static bool CheckNewIndustry_Water(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1072
	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
		_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
  1074
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1080
static bool CheckNewIndustry_Lumbermill(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
{
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1082
	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
		_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
  1084
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1089
static bool CheckNewIndustry_BubbleGen(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
{
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1091
	return GetTileZ(tile) <= TILE_HEIGHT * 4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1094
typedef bool CheckNewIndustryProc(TileIndex tile);
3663
50fbc1639a3f (svn r4578) CodeChange : Cleanup of industry_cmd (Step-2).
belugas
parents: 3662
diff changeset
  1095
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
  1096
	CheckNewIndustry_NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	CheckNewIndustry_Forest,
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1098
	CheckNewIndustry_OilRefinery,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	CheckNewIndustry_Farm,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	CheckNewIndustry_Plantation,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
	CheckNewIndustry_Water,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	CheckNewIndustry_Lumbermill,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	CheckNewIndustry_BubbleGen,
3877
53efa8118448 (svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents: 3773
diff changeset
  1104
	CheckNewIndustry_OilRig
0
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1107
static bool CheckSuitableIndustryPos(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
{
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1109
	uint x = TileX(tile);
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1110
	uint y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1112
	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
  1113
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
		return false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1120
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
{
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1122
	const Town *t;
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1123
	const Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
	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
  1126
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1127
	if (_patches.multiple_industry_per_town) return t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1129
	FOR_ALL_INDUSTRIES(i) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1130
		if (i->type == (byte)type &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
				i->town == t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
			return NULL;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	return t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1140
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
	do {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1145
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1146
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
		if (!IsValidTile(cur_tile)) {
3440
3ec61fb6c6c6 (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1148
			if (it->gfx == 0xff) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1151
3440
3ec61fb6c6c6 (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1152
		if (it->gfx == 0xFF) {
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1153
			if (!IsTileType(cur_tile, MP_WATER) ||
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1154
					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1155
				return false;
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1156
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
		} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1158
			if (!EnsureNoVehicle(cur_tile)) return false;
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1159
			IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1161
			if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1162
				/* As soon as the tile is not water, bail out.
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1163
				 * But that does not mean the search is over.  You have
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1164
				 * to make sure every tile of the industry will be only water*/
5056
20369e09627b (svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents: 4976
diff changeset
  1165
				if (!IsClearWaterTile(cur_tile)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
			} else {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1167
				Slope tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
5056
20369e09627b (svn r7109) -Codechange: use map accessor IsClearWaterTile
belugas
parents: 4976
diff changeset
  1169
				if (IsClearWaterTile(cur_tile)) return false;
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1170
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1171
				tileh = GetTileSlope(cur_tile, NULL);
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3585
diff changeset
  1172
				if (IsSteepSlope(tileh)) return false;
3296
69c0c6e467bb (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1173
4301
1352486059b3 (svn r5948) -Fix: inversed check caused oringal land-generator to put industries on mountains (tnx Darkvater)
truelight
parents: 4300
diff changeset
  1174
				if (_patches.land_generator != LG_TERRAGENESIS || !_generating_world) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1175
					/* It is almost impossible to have a fully flat land in TG, so what we
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1176
					 *  do is that we check if we can make the land flat later on. See
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1177
					 *  CheckIfCanLevelIndustryPlatform(). */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1178
					if (tileh != SLOPE_FLAT) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1179
						Slope t;
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
  1180
						byte bits = GetIndustryTileSpec(it->gfx)->slopes_refused;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1181
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1182
						if (bits & 0x10) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1184
						t = ComplementSlope(tileh);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1185
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1186
						if (bits & 1 && (t & SLOPE_NW)) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1187
						if (bits & 2 && (t & SLOPE_NE)) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1188
						if (bits & 4 && (t & SLOPE_SW)) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1189
						if (bits & 8 && (t & SLOPE_SE)) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1190
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1193
				if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1194
					if (!IsTileType(cur_tile, MP_HOUSE)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
						_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
						return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
					}
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1198
				} else {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1199
					if (ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1200
						if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1201
					} else {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1202
do_clear:
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1203
						if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1204
							return false;
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
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
		}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1209
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1214
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1215
{
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1216
	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1217
		_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1218
		return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1219
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1220
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1221
	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1222
		_error_message = STR_0239_SITE_UNSUITABLE;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1223
		return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1224
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1225
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1226
	return true;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1227
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1228
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1229
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1230
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1231
	int size_x, size_y;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1232
	uint curh;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1233
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1234
	size_x = 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1235
	size_y = 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1236
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1237
	/* Check if we don't leave the map */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1238
	if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1239
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1240
	tile += TileDiffXY(-1, -1);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1241
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1242
		curh = TileHeight(tile_walk);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1243
		/* Is the tile clear? */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1244
		if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES))
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1245
			return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1246
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1247
		/* Don't allow too big of a change if this is the sub-tile check */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1248
		if (internal != 0 && delta(curh, height) > 1) return false;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1249
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1250
		/* Different height, so the surrounding tiles of this tile
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1251
		 *  has to be correct too (in level, or almost in level)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1252
		 *  else you get a chain-reaction of terraforming. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1253
		if (internal == 0 && curh != height) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1254
			if (!CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1))
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1255
				return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1256
		}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1257
	} END_TILE_LOOP(tile_walk, size_x, size_y, tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1258
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1259
	return true;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1260
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1261
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1262
/**
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1263
 * This function tries to flatten out the land below an industry, without
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1264
 *  damaging the surroundings too much.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1265
 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1266
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable* it, int type)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1267
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1268
	const int MKEND = -0x80;   // used for last element in an IndustryTileTable (see build_industry.h)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1269
	int max_x = 0;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1270
	int max_y = 0;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1271
	TileIndex cur_tile;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1272
	uint size_x, size_y;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1273
	uint h, curh;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1274
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1275
	/* Finds dimensions of largest variant of this industry */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1276
	do {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1277
		if (it->ti.x > max_x) max_x = it->ti.x;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1278
		if (it->ti.y > max_y) max_y = it->ti.y;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1279
	} while ((++it)->ti.x != MKEND);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1280
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1281
	/* Remember level height */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1282
	h = TileHeight(tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1283
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1284
	/* Check that all tiles in area and surrounding are clear
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1285
	 * this determines that there are no obstructing items */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1286
	cur_tile = tile + TileDiffXY(-1, -1);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1287
	size_x = max_x + 4;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1288
	size_y = max_y + 4;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1289
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1290
	/* Check if we don't leave the map */
4313
bbd84f6e21b0 (svn r5966) -Fix: prevent that the industry placement's terraforming checks can leave the map on the southern side
rubidium
parents: 4301
diff changeset
  1291
	if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1292
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1293
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1294
		curh = TileHeight(tile_walk);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1295
		if (curh != h) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1296
			/* This tile needs terraforming. Check if we can do that without
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1297
			 *  damaging the surroundings too much. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1298
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1299
			/* This is not 100% correct check, but the best we can do without modifying the map.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1300
			 *  What is missing, is if the difference in height is more than 1.. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1301
			if (CmdFailed(DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) return false;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1302
		}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1303
	} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1304
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1305
	if (flags & DC_EXEC) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1306
		/* Terraform the land under the industry */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1307
		BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1308
			curh = TileHeight(tile_walk);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1309
			while (curh != h) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1310
				/* We give the terraforming for free here, because we can't calculate
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1311
				 *  exact cost in the test-round, and as we all know, that will cause
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1312
				 *  a nice assert if they don't match ;) */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1313
				DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1314
				curh += (curh > h) ? -1 : 1;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1315
			}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1316
		} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1317
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1318
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1319
	return true;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1320
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1321
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1322
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1323
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
{
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1325
	const IndustrySpec *indspec = GetIndustrySpec(type);
3662
e9e1533c758b (svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents: 3661
diff changeset
  1326
	const Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1328
	/* accepting industries won't be close, not even with patch */
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1329
	if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
		return true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1331
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1332
	FOR_ALL_INDUSTRIES(i) {
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1333
		/* check if an industry that accepts the same goods is nearby */
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1334
		if (DistanceMax(tile, i->xy) <= 14 &&
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1335
				indspec->accepts_cargo[0] != CT_INVALID &&
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1336
				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1337
					_game_mode != GM_EDITOR ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1338
					!_patches.same_industry_close ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1339
					!_patches.multiple_industry_per_town
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1340
				)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1341
			_error_message = STR_INDUSTRY_TOO_CLOSE;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1342
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1343
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1345
		/* check "not close to" field. */
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1346
		if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1214
diff changeset
  1347
				DistanceMax(tile, i->xy) <= 14) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
			_error_message = STR_INDUSTRY_TOO_CLOSE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1355
static Industry *AllocateIndustry()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1359
	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1360
	 * TODO - This is just a temporary stage, this will be removed. */
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4965
diff changeset
  1361
	for (i = GetIndustry(0); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1362
		IndustryID index = i->index;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1363
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1364
		if (IsValidIndustry(i)) continue;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1365
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1366
		memset(i, 0, sizeof(*i));
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1367
		i->index = index;
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1368
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1369
		return i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
	}
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1371
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1372
	/* Check if we can add a block to the pool */
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4965
diff changeset
  1373
	return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1376
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, Owner owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
{
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1378
	const IndustrySpec *indspec = GetIndustrySpec(type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
5319
65acb2e92975 (svn r7477) -Fix (7451): Allocate(Industry|Town) get called twice when trying to build an industry/town via a command, thus incrementing the number of towns/industries twice when created via a command.
rubidium
parents: 5298
diff changeset
  1382
	_total_industries++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
	i->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
	i->width = i->height = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
	i->type = type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1387
	i->produced_cargo[0] = indspec->produced_cargo[0];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1388
	i->produced_cargo[1] = indspec->produced_cargo[1];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1389
	i->accepts_cargo[0] = indspec->accepts_cargo[0];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1390
	i->accepts_cargo[1] = indspec->accepts_cargo[1];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1391
	i->accepts_cargo[2] = indspec->accepts_cargo[2];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1392
	i->production_rate[0] = indspec->production_rate[0];
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1393
	i->production_rate[1] = indspec->production_rate[1];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
	if (_patches.smooth_economy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
		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
  1397
		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
  1398
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
	i->town = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	i->owner = owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2469
diff changeset
  1403
	r = Random();
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
  1404
	i->random_color = GB(r, 8, 4);
2492
3f32f9f9fd78 (svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents: 2484
diff changeset
  1405
	i->counter = GB(r, 0, 12);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
	i->cargo_waiting[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
	i->cargo_waiting[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	i->last_mo_production[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
	i->last_mo_production[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	i->last_mo_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	i->last_mo_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	i->pct_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
	i->pct_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
	i->total_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
	i->total_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
	i->was_cargo_delivered = false;
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4328
diff changeset
  1417
	i->last_prod_year = _cur_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
	i->total_production[0] = i->production_rate[0] * 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
	i->total_production[1] = i->production_rate[1] * 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1421
	if (!_generating_world) i->total_production[0] = i->total_production[1] = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1422
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	i->prod_level = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
	do {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1426
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
3440
3ec61fb6c6c6 (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1428
		if (it->gfx != 0xFF) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
			byte size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1431
			size = it->ti.x;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
			if (size > i->width) i->width = size;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1433
			size = it->ti.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
			if (size > i->height)i->height = size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1436
			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
  1437
3440
3ec61fb6c6c6 (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1438
			MakeIndustry(cur_tile, i->index, it->gfx);
5686
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1439
			if (_generating_world) {
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1440
				SetIndustryConstructionCounter(cur_tile, 3);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1441
				SetIndustryConstructionStage(cur_tile, 2);
03c3d3b3e7eb (svn r7641) -Codechange: remove the last direct map accesses from industry_cmd.
rubidium
parents: 5685
diff changeset
  1442
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
		}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1444
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
	i->width++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	i->height++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1449
	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
4328
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
  1450
		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1456
/** Helper function for Build/Fund an industry
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1457
 * @param tile tile where industry is built
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1458
 * @param type of industry to build
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1459
 * @param flags of operations to conduct
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1460
 * @param indspec pointer to industry specifications
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1461
 * @param it pointer to list of tile type to build
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1462
 * @return the pointer of the newly created industry, or NULL if it failed
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1463
 */
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1464
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, const IndustryTileTable *it)
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1465
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1466
	const Town *t;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1467
	Industry *i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1468
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1469
	if (!CheckIfIndustryTilesAreFree(tile, it, type)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1470
	if (_patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1471
	if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1472
	if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1473
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1474
	t = CheckMultipleIndustryInTown(tile, type);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1475
	if (t == NULL) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1476
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1477
	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1478
	if (!CheckSuitableIndustryPos(tile)) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1479
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1480
	i = AllocateIndustry();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1481
	if (i == NULL) return NULL;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1482
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1483
	if (flags & DC_EXEC) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1484
		CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1485
		DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1486
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1487
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1488
	return i;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1489
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1490
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1491
/** Build/Fund an industry
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1492
 * @param tile tile where industry is built
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1493
 * @param flags of operations to conduct
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1494
 * @param p1 industry type see build_industry.h and see industry.h
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1495
 * @param p2 unused
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1496
 * @return index of the newly create industry, or CMD_ERROR if it failed
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1497
 */
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1498
int32 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
  1499
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
	const IndustryTileTable * const *itt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
	const IndustryTileTable *it;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1503
	const IndustrySpec *indspec;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
4965
9d4ad0851fde (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
  1507
	indspec = GetIndustrySpec(p1);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1508
4965
9d4ad0851fde (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
  1509
	/* Check if the to-be built/founded industry is available for this climate. */
9d4ad0851fde (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
  1510
	if (!HASBIT(indspec->climate_availability, _opt_ptr->landscape)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1512
	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
1800
39966454c434 (svn r2304) - Fix (regression): excuse the Lumber mill from the list of raw-industries build-restriction, as it can be built always, patch-setting, or no patch-setting.
Darkvater
parents: 1786
diff changeset
  1513
	 * Raw material industries are industries that do not accept cargo (at least for now)
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1514
	 * Exclude the lumber mill (only "raw" industry that can be built) */
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1515
	if (!_patches.build_rawmaterial_ind &&
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1516
			indspec->accepts_cargo[0] == CT_INVALID &&
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1517
			indspec->accepts_cargo[1] == CT_INVALID &&
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1518
			indspec->accepts_cargo[2] == CT_INVALID &&
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1519
			p1 != IT_LUMBER_MILL) {
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1520
		return CMD_ERROR;
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1521
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1523
	num = indspec->num_table;
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1524
	itt = indspec->table;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
	do {
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1527
		if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1528
	} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1530
	if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1531
3689
db67c356f44b (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3669
diff changeset
  1532
	return (_price.build_industry >> 5) * indspec->cost_multiplier;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
3538
3eb71c726341 (svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents: 3499
diff changeset
  1536
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1538
	const IndustrySpec *indspec = GetIndustrySpec(type);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1539
	const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1541
	return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1544
static const byte _numof_industry_table[4][12] = {
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1545
	/* difficulty settings for number of industries */
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1546
	{0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0},   //none
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1547
	{0, 1, 1, 1, 2, 2, 3, 3,  4,  4,  5},   //low
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1548
	{0, 1, 2, 3, 4, 5, 6, 7,  8,  9, 10},   //normal
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1549
	{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
  1550
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1552
/** This function is the one who really do the creation work
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1553
 * of random industries during game creation
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1554
 * @param type IndustryType of the desired industry
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1555
 * @param amount of industries that need to be built */
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1556
static void PlaceInitialIndustry(IndustryType type, int amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
{
2072
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1558
	int num = _numof_industry_table[_opt.diff.number_industries][amount];
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1559
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1560
	/* These are always placed next to the coastline, so we scale by the perimeter instead. */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1561
	num = (type == IT_OIL_REFINERY || type == IT_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1562
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1563
	if (_opt.diff.number_industries != 0) {
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1564
		PlayerID old_player = _current_player;
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1565
		_current_player = OWNER_NONE;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1566
		assert(num > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
		do {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1569
			uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1570
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1571
			IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1572
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1573
			for (i = 0; i < 2000; i++) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1574
				if (CreateNewIndustry(RandomTile(), type) != NULL) break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1575
			}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1576
		} while (--num);
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1577
267
dc6103ea959d (svn r273) -Fix: sorry, wrongly fixed
darkvater
parents: 266
diff changeset
  1578
		_current_player = old_player;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1579
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1582
/** This function will create ramdon industries during game creation.
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1583
 * It will scale the amount of industries by map size as well as difficulty level */
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1584
void GenerateIndustries()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1586
	uint i = 0;
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1587
	uint8 chance;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1588
	IndustryType it;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1589
	const IndustrySpec *ind_spc;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1590
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1591
	/* Find the total amount of industries */
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1592
	for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1593
		int num;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1594
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1595
		ind_spc = GetIndustrySpec(it);
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1596
		chance = ind_spc->appear_creation[_opt.landscape];
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1597
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1598
		if (chance > 0) {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1599
			/* once the chance of appearance is determind, it have to be scaled by
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1600
			 * the difficulty level. The "chance" in question is more an index into
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1601
			 * the _numof_industry_table,in fact */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1602
			num = _numof_industry_table[_opt.diff.number_industries][chance];
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1603
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1604
			/* These are always placed next to the coastline, so we scale by the perimeter instead. */
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1605
			num = (it == IT_OIL_REFINERY || it == IT_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1606
			i += num;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1607
		}
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1608
	}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1609
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
  1610
	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1612
	for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1613
		/* Once the number of industries has been determined, let's really create them.
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1614
		 * The test for chance allows us to try create industries that are available only
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1615
		 * for this landscape.
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1616
		 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1617
		 *          processed that scaling above? No, don't think so.  Will find a way. */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1618
		chance = GetIndustrySpec(it)->appear_creation[_opt.landscape];
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1619
		if (chance > 0) PlaceInitialIndustry(it, chance);
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1620
	};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1623
/* Change industry production or do closure */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
static void ExtChangeIndustryProduction(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
{
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1626
	bool closeit = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
	int j;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1628
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
4924
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4815
diff changeset
  1630
	switch (indspec->life_type) {
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1631
		case INDUSTRYLIFE_NOT_CLOSABLE:
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1632
			return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1633
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1634
		case INDUSTRYLIFE_CLOSABLE:
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4328
diff changeset
  1635
			if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
				closeit = false;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1637
			break;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1638
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1639
		default: /* INDUSTRY_PRODUCTION */
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1640
			for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1641
				uint32 r = Random();
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1642
				int old_prod, new_prod, percent;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1643
				int mag;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1644
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1645
				new_prod = old_prod = i->production_rate[j];
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1646
				if (CHANCE16I(20, 1024, r))
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1647
					new_prod -= ((RandomRange(50) + 10) * old_prod) >> 8;
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1648
				if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16))
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1649
					new_prod += ((RandomRange(50) + 10) * old_prod) >> 8;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1650
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1651
				new_prod = clamp(new_prod, 0, 255);
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1652
				if (new_prod == old_prod) {
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1653
					closeit = false;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1654
					continue;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1655
				}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1656
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1657
				percent = new_prod * 100 / old_prod - 100;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1658
				i->production_rate[j] = new_prod;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1659
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1660
				if (new_prod >= indspec->production_rate[j] / 4)
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1661
					closeit = false;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1662
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1663
				mag = abs(percent);
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1664
				if (mag >= 10) {
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1665
					SetDParam(2, mag);
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6160
diff changeset
  1666
					SetDParam(0, GetCargo(i->produced_cargo[j])->name);
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1667
					SetDParam(1, i->index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1668
					AddNewsItem(
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1669
						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1670
						NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ECONOMY, 0),
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1671
						i->xy + TileDiffXY(1, 1), 0
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1672
					);
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1673
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
			}
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1675
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1678
	/* If industry will be closed down, show this */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
	if (closeit) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
		i->prod_level = 0;
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1681
		SetDParam(0, i->index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1682
		AddNewsItem(
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1683
			indspec->closure_text,
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1684
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0),
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1685
			i->xy + TileDiffXY(1, 1), 0
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1686
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
static void UpdateIndustryStatistics(Industry *i)
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
	byte pct;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1694
	bool refresh = false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1695
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1696
	if (i->produced_cargo[0] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
		pct = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
		if (i->last_mo_production[0] != 0) {
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4328
diff changeset
  1699
			i->last_prod_year = _cur_year;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1700
			pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0], 255);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1701
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
		i->pct_transported[0] = pct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1703
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
		i->total_production[0] = i->last_mo_production[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
		i->last_mo_production[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
		i->total_transported[0] = i->last_mo_transported[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
		i->last_mo_transported[0] = 0;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1709
		refresh = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1712
	if (i->produced_cargo[1] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
		pct = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
		if (i->last_mo_production[1] != 0) {
4329
9759d5c52010 (svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents: 4328
diff changeset
  1715
			i->last_prod_year = _cur_year;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1716
			pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1], 255);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1717
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
		i->pct_transported[1] = pct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
		i->total_production[1] = i->last_mo_production[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
		i->last_mo_production[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
		i->total_transported[1] = i->last_mo_transported[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
		i->last_mo_transported[1] = 0;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1725
		refresh = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1729
	if (refresh)
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1730
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1732
	if (i->prod_level == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
		DeleteIndustry(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1734
	} else if (_patches.smooth_economy) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
		ExtChangeIndustryProduction(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1736
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1739
/** Simple helper that will collect data for the generation of industries */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1740
struct ProbabilityHelper {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1741
	uint16 prob;      ///< probability
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1742
	IndustryType ind; ///< industry id correcponding
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1745
/**
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1746
 * Try to create a random industry, during gameplay
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1747
 */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1748
static void MaybeNewIndustry(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
{
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1750
	Industry *ind;               //will receive the industry's creation pointer
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1751
	IndustryType rndtype, j;     // Loop controlers
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1752
	const IndustrySpec *ind_spc;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1753
	uint num = 0;
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1754
	ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1755
	uint16 probability_max = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1757
	/* Generate a list of all possible industries that can be built. */
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1758
	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1759
		byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1761
		/* if appearing chance for this landscape is above 0, this industry can be chosen */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1762
		if (chance != 0) {
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1763
			probability_max += chance;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1764
			/* adds the result for this industry */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1765
			cumulative_probs[num].ind = j;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1766
			cumulative_probs[num++].prob = probability_max;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1767
		}
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1768
	}
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1769
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1770
	/* Find a random type, with maximum being what has been evaluate above*/
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1771
	rndtype = RandomRange(probability_max);
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1772
	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1773
		/* and choose the index of the industry that matches as close as possible this random type */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1774
		if (cumulative_probs[j].prob >= rndtype) break;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1775
	}
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1776
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1777
	ind_spc = GetIndustrySpec(cumulative_probs[j].ind);
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1778
	/*  Check if it is allowed */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1779
	if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1780
	if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1781
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1782
	/* try to create 2000 times this industry */
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1783
	num = 2000;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1784
	for (;;) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1785
		ind = CreateNewIndustry(RandomTile(), cumulative_probs[j].ind);
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1786
		if (ind != NULL) break;
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1787
		if (--num == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1790
	SetDParam(0, ind_spc->name);
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1791
	SetDParam(1, ind->town->index);
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1792
	AddNewsItem(ind_spc->new_industry_text,
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1793
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1796
static void ChangeIndustryProduction(Industry *i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
{
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1798
	bool only_decrease = false;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1799
	StringID str = STR_NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1800
	int type = i->type;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1801
	const IndustrySpec *indspec = GetIndustrySpec(type);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1802
4924
6e29520a0ba8 (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4815
diff changeset
  1803
	switch (indspec->life_type) {
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1804
		case INDUSTRYLIFE_NOT_CLOSABLE:
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1805
			return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1807
		case INDUSTRYLIFE_PRODUCTION:
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1808
			/* decrease or increase */
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1809
			if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1810
				only_decrease = true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1811
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1812
			if (only_decrease || CHANCE16(1, 3)) {
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1813
				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1814
				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1, 3)) {
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1815
					/* Increase production */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1816
					if (i->prod_level != 0x80) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1817
						byte b;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1818
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1819
						i->prod_level <<= 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1820
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1821
						b = i->production_rate[0] * 2;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1822
						if (i->production_rate[0] >= 128)
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1823
							b = 0xFF;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1824
						i->production_rate[0] = b;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1825
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1826
						b = i->production_rate[1] * 2;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1827
						if (i->production_rate[1] >= 128)
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1828
							b = 0xFF;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1829
						i->production_rate[1] = b;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1830
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1831
						str = indspec->production_up_text;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1832
					}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1833
				} else {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1834
					/* Decrease production */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1835
					if (i->prod_level == 4) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1836
						i->prod_level = 0;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1837
						str = indspec->closure_text;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1838
					} else {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1839
						i->prod_level >>= 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1840
						i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1841
						i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1842
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1843
						str = indspec->production_down_text;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1844
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
			}
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1847
			break;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1848
3496
2775485abdf6 (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1849
		case INDUSTRYLIFE_CLOSABLE:
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1850
			/* maybe close */
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1851
			if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2)) {
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1852
				i->prod_level = 0;
3669
8a3a5d008971 (svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents: 3663
diff changeset
  1853
				str = indspec->closure_text;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1854
			}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1855
			break;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1856
	}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1857
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1858
	if (str != STR_NULL) {
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1859
		SetDParam(0, i->index);
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1860
		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, str == indspec->closure_text ? NT_OPENCLOSE : NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1864
void IndustryMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
	Industry *i;
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1867
	PlayerID old_player = _current_player;
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1868
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1870
	FOR_ALL_INDUSTRIES(i) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1871
		UpdateIndustryStatistics(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1874
	/* 3% chance that we start a new industry */
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1875
	if (CHANCE16(3, 100)) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1876
		MaybeNewIndustry();
5247
c3eece01af11 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
  1877
	} else if (!_patches.smooth_economy) {
4356
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
  1878
		i = GetRandomIndustry();
bc52a48e2590 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
  1879
		if (i != NULL) ChangeIndustryProduction(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	}
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1881
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1882
	_current_player = old_player;
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1883
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1884
	/* production-change */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1885
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1890
void InitializeIndustries()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
{
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4965
diff changeset
  1892
	CleanPool(&_Industry_pool);
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4965
diff changeset
  1893
	AddBlockToPool(&_Industry_pool);
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1894
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
	_total_industries = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1896
	_industry_sort_dirty = true;
4587
47bdc67193da (svn r6437) -Fix: reset the location of the last sound as that location can be outside the map when you are loading another (smaller) map. Thanks to MeusH for noticing.
rubidium
parents: 4583
diff changeset
  1897
	_industry_sound_tile = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1900
extern const TileTypeProcs _tile_type_industry_procs = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1901
	DrawTile_Industry,           /* draw_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1902
	GetSlopeZ_Industry,          /* get_slope_z_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1903
	ClearTile_Industry,          /* clear_tile_proc */
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4403
diff changeset
  1904
	GetAcceptedCargo_Industry,   /* get_accepted_cargo_proc */
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1905
	GetTileDesc_Industry,        /* get_tile_desc_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1906
	GetTileTrackStatus_Industry, /* get_tile_track_status_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1907
	ClickTile_Industry,          /* click_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1908
	AnimateTile_Industry,        /* animate_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1909
	TileLoop_Industry,           /* tile_loop_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1910
	ChangeTileOwner_Industry,    /* change_tile_owner_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1911
	GetProducedCargo_Industry,   /* get_produced_cargo_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1912
	NULL,                        /* vehicle_enter_tile_proc */
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1913
	GetSlopeTileh_Industry,      /* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1800
diff changeset
  1916
static const SaveLoad _industry_desc[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1917
	SLE_CONDVAR(Industry, xy,                  SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1918
	SLE_CONDVAR(Industry, xy,                  SLE_UINT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1919
	    SLE_VAR(Industry, width,               SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1920
	    SLE_VAR(Industry, height,              SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1921
	    SLE_REF(Industry, town,                REF_TOWN),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1922
	    SLE_ARR(Industry, produced_cargo,      SLE_UINT8,  2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1923
	    SLE_ARR(Industry, cargo_waiting,       SLE_UINT16, 2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1924
	    SLE_ARR(Industry, production_rate,     SLE_UINT8,  2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1925
	    SLE_ARR(Industry, accepts_cargo,       SLE_UINT8,  3),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1926
	    SLE_VAR(Industry, prod_level,          SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1927
	    SLE_ARR(Industry, last_mo_production,  SLE_UINT16, 2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1928
	    SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1929
	    SLE_ARR(Industry, pct_transported,     SLE_UINT8,  2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1930
	    SLE_ARR(Industry, total_production,    SLE_UINT16, 2),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1931
	    SLE_ARR(Industry, total_transported,   SLE_UINT16, 2),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1933
	    SLE_VAR(Industry, counter,             SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1935
	    SLE_VAR(Industry, type,                SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1936
	    SLE_VAR(Industry, owner,               SLE_UINT8),
4942
f990abfa4438 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
  1937
	    SLE_VAR(Industry, random_color,        SLE_UINT8),
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1938
	SLE_CONDVAR(Industry, last_prod_year,      SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1939
	SLE_CONDVAR(Industry, last_prod_year,      SLE_INT32,                 31, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
  1940
	    SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1942
	/* reserve extra space in savegame here. (currently 32 bytes) */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3173
diff changeset
  1943
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1948
static void Save_INDY()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
	Industry *ind;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1951
6285
187e3ef04cc9 (svn r9004) [cpp_gui] -Sync with trunk (r8900..r9003)
KUDr
parents: 6268
diff changeset
  1952
	/* Write the vehicles */
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1953
	FOR_ALL_INDUSTRIES(ind) {
4346
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1954
		SlSetArrayIndex(ind->index);
3f00094f2670 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
  1955
		SlObject(ind, _industry_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1956
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6285
diff changeset
  1959
static void Load_INDY()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
	int index;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1962
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1963
	_total_industries = 0;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1964
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
	while ((index = SlIterateArray()) != -1) {
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1966
		Industry *i;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1967
4976
a0d7f63c35b5 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4965
diff changeset
  1968
		if (!AddBlockIfNeeded(&_Industry_pool, index))
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1969
			error("Industries: failed loading savegame: too many industries");
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1970
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1971
		i = GetIndustry(index);
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1972
		SlObject(i, _industry_desc);
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1973
5298
6d4c150bdd94 (svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
rubidium
parents: 5247
diff changeset
  1974
		_total_industries++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1977
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1978
extern const ChunkHandler _industry_chunk_handlers[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
	{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
};