industry_cmd.c
author belugas
Mon, 10 Apr 2006 16:20:47 +0000
changeset 3496 0959ead7c2af
parent 3495 6672c181ace4
child 3499 92f95849788c
permissions -rw-r--r--
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     4
#include "openttd.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3094
diff changeset
     5
#include "clear_map.h"
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
     6
#include "industry_map.h"
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3331
diff changeset
     7
#include "station_map.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     8
#include "table/strings.h"
2148
542ea702738c (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
     9
#include "table/sprites.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
    10
#include "functions.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 552
diff changeset
    11
#include "map.h"
1209
2e00193652b2 (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
    12
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
#include "economy.h"
337
cbe0c766c947 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 314
diff changeset
    21
#include "sound.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    22
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    24
enum {
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    25
	/* Max industries: 64000 (8 * 8000) */
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    26
	INDUSTRY_POOL_BLOCK_SIZE_BITS = 3,       /* In bits, so (1 << 3) == 8 */
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    27
	INDUSTRY_POOL_MAX_BLOCKS      = 8000,
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    28
};
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    29
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    30
/**
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    31
 * Called if a new block is added to the industry-pool
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    32
 */
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2737
diff changeset
    33
static void IndustryPoolNewBlock(uint start_item)
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    34
{
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    35
	Industry *i;
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    36
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
    37
	FOR_ALL_INDUSTRIES_FROM(i, start_item) i->index = start_item++;
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    38
}
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    39
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    40
/* Initialize the industry-pool */
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    41
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, 0, 0, NULL };
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    42
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
    43
static byte _industry_sound_ctr;
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
    44
static TileIndex _industry_sound_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
void ShowIndustryViewWindow(int industry);
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    47
void BuildOilRig(TileIndex tile);
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    48
void DeleteOilRig(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
typedef struct DrawIndustryTileStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	uint32 sprite_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	uint32 sprite_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
2653
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    54
	byte subtile_x:4;
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    55
	byte subtile_y:4;
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    56
	byte width:4;
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    57
	byte height:4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	byte dz;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
	byte proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
} DrawIndustryTileStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
typedef struct DrawIndustrySpec1Struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	byte x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	byte image_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	byte image_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
	byte image_3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
} DrawIndustrySpec1Struct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
typedef struct DrawIndustrySpec4Struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	byte image_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	byte image_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	byte image_3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
} DrawIndustrySpec4Struct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
typedef struct IndustryTileTable {
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
    77
	TileIndexDiffC ti;
3440
811c85e5ca0f (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
    78
	byte gfx;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
} IndustryTileTable;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
typedef struct IndustrySpec {
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
    82
	const IndustryTileTable *const *table;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	byte num_table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	byte a,b,c;
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
    85
	CargoID produced_cargo[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	byte production_rate[2];
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
    87
	CargoID accepts_cargo[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	byte check_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
} IndustrySpec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
    91
#include "table/industry_land.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
#include "table/build_industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    94
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    95
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    96
static const IndustryType _industry_close_mode[37] = {
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
    97
	/* COAL_MINE */          INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
    98
	/* POWER_STATION */      INDUSTRYLIFE_NOT_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
    99
	/* SAWMILL */            INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   100
	/* FOREST */             INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   101
	/* OIL_REFINERY */       INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   102
	/* OIL_RIG */            INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   103
	/* FACTORY */            INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   104
	/* PRINTING_WORKS */     INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   105
	/* STEEL_MILL */         INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   106
	/* FARM */               INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   107
	/* COPPER_MINE */        INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   108
	/* OIL_WELL */           INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   109
	/* BANK */               INDUSTRYLIFE_NOT_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   110
	/* FOOD_PROCESS */       INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   111
	/* PAPER_MILL */         INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   112
	/* GOLD_MINE */          INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   113
	/* BANK_2,  */           INDUSTRYLIFE_NOT_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   114
	/* DIAMOND_MINE */       INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   115
	/* IRON_MINE */          INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   116
	/* FRUIT_PLANTATION */   INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   117
	/* RUBBER_PLANTATION */  INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   118
	/* WATER_SUPPLY */       INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   119
	/* WATER_TOWER */        INDUSTRYLIFE_NOT_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   120
	/* FACTORY_2 */          INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   121
	/* FARM_2 */             INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   122
	/* LUMBER_MILL */        INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   123
	/* COTTON_CANDY */       INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   124
	/* CANDY_FACTORY */      INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   125
	/* BATTERY_FARM */       INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   126
	/* COLA_WELLS */         INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   127
	/* TOY_SHOP */           INDUSTRYLIFE_NOT_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   128
	/* TOY_FACTORY */        INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   129
	/* PLASTIC_FOUNTAINS */  INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   130
	/* FIZZY_DRINK_FACTORY */INDUSTRYLIFE_CLOSABLE,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   131
	/* BUBBLE_GENERATOR */   INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   132
	/* TOFFEE_QUARRY */      INDUSTRYLIFE_PRODUCTION,
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
   133
	/* SUGAR_MINE */         INDUSTRYLIFE_PRODUCTION
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
static const StringID _industry_prod_up_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	STR_4836_NEW_COAL_SEAM_FOUND_AT,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	STR_4837_NEW_OIL_RESERVES_FOUND,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	STR_4837_NEW_OIL_RESERVES_FOUND,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
static const StringID _industry_prod_down_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
static const StringID _industry_close_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	STR_4834_LACK_OF_NEARBY_TREES_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   253
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   257
static void IndustryDrawSugarMine(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	const DrawIndustrySpec1Struct *d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   262
	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
   263
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   264
	d = &_draw_industry_spec1[_m[ti->tile].m3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   266
	AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, d->x, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   268
	image = d->image_2;
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   269
	if (image != 0) AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + image - 1, 8, 41);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   271
	image = d->image_3;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   272
	if (image != 0) {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   273
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + image - 1,
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   274
			_drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   275
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   278
static void IndustryDrawToffeeQuarry(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	int x = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   281
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   282
	if (IsIndustryCompleted(ti->tile)) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   283
		x = _industry_anim_offs[_m[ti->tile].m3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		if ( (byte)x == 0xFF)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   288
	AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, 22 - x, 24 + x);
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   289
	AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, 6, 14);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   292
static void IndustryDrawBubbleGenerator( const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
{
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   294
	if (IsIndustryCompleted(ti->tile)) {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   295
		AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, 5, _industry_anim_offs_2[_m[ti->tile].m3]);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   296
	} else {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   297
		AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, 3, 67);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   301
static void IndustryDrawToyFactory(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	const DrawIndustrySpec4Struct *d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   305
	d = &_industry_anim_offs_3[_m[ti->tile].m3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	if (d->image_1 != 0xFF) {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   308
		AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, 50 - d->image_1 * 2, 96 + d->image_1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	if (d->image_2 != 0xFF) {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   312
		AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, 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
   313
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   315
	AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, 7, d->image_3);
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   316
	AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, 0, 42);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   319
static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
{
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   321
	if (IsIndustryCompleted(ti->tile)) {
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   322
		uint image = GB(_m[ti->tile].m1, 2, 5);
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   323
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
		if (image != 0 && image < 7) {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   325
			AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   326
				_coal_plant_sparks_x[image - 1],
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   327
				_coal_plant_sparks_y[image - 1]
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   333
typedef void IndustryDrawTileProc(const TileInfo *ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   335
	IndustryDrawSugarMine,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   336
	IndustryDrawToffeeQuarry,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   337
	IndustryDrawBubbleGenerator,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   338
	IndustryDrawToyFactory,
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   339
	IndustryDrawCoalPlantSparks,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
};
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
static void DrawTile_Industry(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
   344
	const Industry* ind;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
	const DrawIndustryTileStruct *dits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	uint32 image, ormod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	/* Pointer to industry */
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   350
	ind = GetIndustryByTile(ti->tile);
3326
00cf690a7fe1 (svn r4092) CodeChange : Named sprites instead of magic numbers plus create/use helper macro/enum for recoloring scheme
belugas
parents: 3321
diff changeset
   351
	ormod = GENERAL_SPRITE_COLOR(ind->color_map);
0
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
	/* Retrieve pointer to the draw industry tile struct */
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   354
	dits = &_industry_draw_tile_data[GetIndustryGfx(ti->tile) << 2 | GetIndustryConstructionStage(ti->tile)];
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
	image = dits->sprite_1;
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   357
	if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
		image |= ormod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
	z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	/* Add bricks below the industry? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	if (ti->tileh & 0xF) {
2535
149921ee5e27 (svn r3064) Replace some numbers by sprite names
tron
parents: 2498
diff changeset
   363
		AddSortableSpriteToDraw(SPR_FOUNDATION_BASE + (ti->tileh & 0xF), ti->x, ti->y, 16, 16, 7, z);
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   364
		AddChildSpriteScreen(image, 31, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
		/* Else draw regular ground */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
		DrawGroundSprite(image);
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
	/* Add industry on top of the ground? */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   372
	image = dits->sprite_2;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   373
	if (image != 0) {
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   374
		if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			image |= ormod;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   376
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   377
		if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   378
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   379
		AddSortableSpriteToDraw(image,
2653
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   380
			ti->x + dits->subtile_x,
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   381
			ti->y + dits->subtile_y,
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   382
			dits->width  + 1,
b1945642bf27 (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   383
			dits->height + 1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
			dits->dz,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
			z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   387
		if (_display_opt & DO_TRANS_BUILDINGS) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   390
	{
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   391
		int proc = dits->proc - 1;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   392
		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
   393
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
2537
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   397
static uint GetSlopeZ_Industry(const TileInfo* ti)
5e4ca74e995a (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   398
{
3282
d026008a8f7c (svn r3996) -Fix: Slope and height information returned for some tile types is wrong
tron
parents: 3222
diff changeset
   399
	return ti->z + (ti->tileh == 0 ? 0 : 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
3418
ec9003ebf933 (svn r4242) Pass TileIndex and slope to GetSlopeTileh_*() instead of TileInfo
tron
parents: 3379
diff changeset
   402
static uint GetSlopeTileh_Industry(TileIndex tile, uint tileh)
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   403
{
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   404
	return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   405
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   406
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   407
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
{
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   409
	uint gfx = GetIndustryGfx(tile);
2598
d69238b81415 (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
   410
	CargoID a;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
   412
	a = _industry_section_accepts_1[gfx];
2598
d69238b81415 (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
   413
	if (a != CT_INVALID) ac[a] = (a == 0) ? 1 : 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
   415
	a = _industry_section_accepts_2[gfx];
2598
d69238b81415 (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
   416
	if (a != CT_INVALID) ac[a] = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
   418
	a = _industry_section_accepts_3[gfx];
2598
d69238b81415 (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
   419
	if (a != CT_INVALID) ac[a] = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   422
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
{
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   424
	const Industry* i = GetIndustryByTile(tile);
0
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
	td->owner = i->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
	td->str = STR_4802_COAL_MINE + i->type;
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   428
	if (!IsIndustryCompleted(tile)) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   429
		SetDParamX(td->dparam, 0, td->str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
		td->str = STR_2058_UNDER_CONSTRUCTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   434
static int32 ClearTile_Industry(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
{
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   436
	Industry* i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   438
	/*	* water can destroy industries
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   439
			* in editor you can bulldoze industries
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   440
			* with magic_bulldozer cheat you can destroy industries
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   441
			* (area around OILRIG is water, so water shouldn't flood it
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   442
	*/
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   443
	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
   444
			!_cheats.magic_bulldozer.value) ||
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   445
			(_current_player == OWNER_WATER && i->type == IT_OIL_RIG) ) {
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   446
 		SetDParam(0, STR_4802_COAL_MINE + i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
		return_cmd_error(STR_4800_IN_THE_WAY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   450
	if (flags & DC_EXEC) DeleteIndustry(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
	return 0;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
static const byte _industry_min_cargo[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	5, 5, 5, 30, 5, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
	5, 5, 5, 5, 2, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
	5, 5, 5, 15, 15, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	5, 5, 30, 5, 30, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
	5, 5, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   463
static void TransportIndustryGoods(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
{
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   465
	Industry* i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
	uint cw, am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   468
	cw = min(i->cargo_waiting[0], 255);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   469
	if (cw > _industry_min_cargo[i->type]/* && i->produced_cargo[0] != 0xFF*/) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
		i->cargo_waiting[0] -= cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
		/* fluctuating economy? */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   473
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
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
		i->last_mo_production[0] += cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
		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
   478
		i->last_mo_transported[0] += am;
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   479
		if (am != 0) {
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
   480
			uint newgfx = _industry_produce_section[GetIndustryGfx(tile)];
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   481
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   482
			if (newgfx != 0xFF) {
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   483
				ResetIndustryConstructionStage(tile);
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   484
				SetIndustryCompleted(tile, true);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   485
				SetIndustryGfx(tile, newgfx);
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   486
				MarkTileDirtyByTile(tile);
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   487
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
	cw = min(i->cargo_waiting[1], 255);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   492
	if (cw > _industry_min_cargo[i->type]) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
		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
   494
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   495
		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
   496
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		i->last_mo_production[1] += cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
		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
   500
		i->last_mo_transported[1] += am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   505
static void AnimateTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
{
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   507
	byte m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   509
	switch (GetIndustryGfx(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	case 174:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
		if ((_tick_counter & 1) == 0) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   512
			m = _m[tile].m3 + 1;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   513
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2868
diff changeset
   514
			switch (m & 7) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   515
			case 2:	SndPlayTileFx(SND_2D_RIP_2, tile); break;
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   516
			case 6: SndPlayTileFx(SND_29_RIP, tile); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
			}
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 (m >= 96) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
			}
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   523
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
		break;
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
	case 165:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
		if ((_tick_counter & 3) == 0) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   531
			m = _m[tile].m3;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   532
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
			if (_industry_anim_offs[m] == 0xFF) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   534
				SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
			if (++m >= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
			}
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   541
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
	case 162:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
		if ((_tick_counter&1) == 0) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   549
			m = _m[tile].m3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
			if (++m >= 40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
			}
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   555
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	// Sparks on a coal plant
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
	case 10:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
		if ((_tick_counter & 3) == 0) {
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   564
			m = _m[tile].m1;
2663
e5a3df7f225a (svn r3205) Some more uses for GB/SB
tron
parents: 2653
diff changeset
   565
			if (GB(m, 2, 5) == 6) {
e5a3df7f225a (svn r3205) Some more uses for GB/SB
tron
parents: 2653
diff changeset
   566
				SB(_m[tile].m1, 2, 5, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
			} else {
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   569
				_m[tile].m1 = m + (1<<2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
				MarkTileDirtyByTile(tile);
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
	case 143:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
		if ((_tick_counter & 1) == 0) {
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   577
			m = _m[tile].m3 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
			if (m == 1) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   580
				SndPlayTileFx(SND_2C_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
			} else if (m == 23) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   582
				SndPlayTileFx(SND_2B_COMEDY_HIT, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
			} else if (m == 28) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   584
				SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   587
			if (m >= 50 && (m=0,++_m[tile].m4 >= 8)) {
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   588
				_m[tile].m4 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
			}
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   591
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	case 148: case 149: case 150: case 151:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
	case 152: case 153: case 154: case 155:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
		if ((_tick_counter & 3) == 0) {
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   599
			uint gfx = GetIndustryGfx(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   601
			gfx = (gfx < 155) ? gfx + 1 : 148;
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   602
			SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
		}
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
	case 30: case 31: case 32:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
		if ((_tick_counter & 7) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
			bool b = CHANCE16(1,7);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   610
			uint gfx = GetIndustryGfx(tile);
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   611
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   612
			m = GB(_m[tile].m1, 0, 2) + 1;
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   613
			if (m == 4 && (m = 0, ++gfx) == 32 + 1 && (gfx = 30, b)) {
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   614
				_m[tile].m1 = 0x83;
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   615
				SetIndustryGfx(tile, 29);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   616
				DeleteAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
			} else {
2663
e5a3df7f225a (svn r3205) Some more uses for GB/SB
tron
parents: 2653
diff changeset
   618
				SB(_m[tile].m1, 0, 2, m);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   619
				SetIndustryGfx(tile, gfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	case 88:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	case 48:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
	case 1: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
			int state = _tick_counter & 0x7FF;
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
			if ((state -= 0x400) < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
				return;
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
			if (state < 0x1A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
				if (state < 0x20 || state >= 0x180) {
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   635
					if (!(_m[tile].m1 & 0x40)) {
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   636
						_m[tile].m1 |= 0x40;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   637
						SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
					if (state & 7)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
					if (state & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
				}
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   645
				m = (_m[tile].m1 + 1) | 0x40;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
				if (m > 0xC2) m = 0xC0;
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   647
				_m[tile].m1 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
			} else if (state >= 0x200 && state < 0x3A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
				int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
				i = (state < 0x220 || state >= 0x380) ? 7 : 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
				if (state & i)
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
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   655
				m = (_m[tile].m1 & 0xBF) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   656
				if (m < 0x80) m = 0x82;
2360
4e4ebe18e448 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2260
diff changeset
   657
				_m[tile].m1 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   664
static void CreateIndustryEffectSmoke(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
{
3094
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   666
	uint tileh;
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   667
	uint x;
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   668
	uint y;
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   669
	uint z;
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   670
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   671
	tileh = GetTileSlope(tile, &z);
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   672
	x = TileX(tile) * TILE_SIZE;
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   673
	y = TileY(tile) * TILE_SIZE;
e8318bbdbee5 (svn r3683) Get rid of another FindLandscapeHeight()
tron
parents: 3047
diff changeset
   674
	CreateEffectVehicle(x + 15, y + 14, z + 59 + (tileh != 0 ? 8 : 0), EV_CHIMNEY_SMOKE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   677
static void MakeIndustryTileBigger(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
{
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   679
	byte cnt = GetIndustryConstructionCounter(tile) + 1;
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   680
	byte stage;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   682
	if (cnt != 4) {
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   683
		SetIndustryConstructionCounter(tile, cnt);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   687
	stage = GetIndustryConstructionStage(tile) + 1;
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   688
	SetIndustryConstructionCounter(tile, 0);
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   689
	SetIndustryConstructionStage(tile, stage);
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   690
	if (stage == 3) {
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   691
		SetIndustryCompleted(tile, true);
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   692
	}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   693
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   696
	if (!IsIndustryCompleted(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   698
	switch (GetIndustryGfx(tile)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	case 8:
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   700
		CreateIndustryEffectSmoke(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	case 24:
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   704
		if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == 24) BuildOilRig(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	case 143:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	case 162:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	case 165:
2049
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   710
		_m[tile].m3 = 0;
538e73c53f54 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1981
diff changeset
   711
		_m[tile].m4 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
	case 148: case 149: case 150: case 151:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	case 152: case 153: case 154: case 155:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   722
static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	int dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	static const int8 _tileloop_ind_case_161[12] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
		11, 0, -4, -14,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
		-4, -10, -4, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
		49, 59, 60, 65,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   732
	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
   733
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
	dir = Random() & 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	v = CreateEffectVehicleAbove(
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   737
		TileX(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 0],
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   738
		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
   739
		_tileloop_ind_case_161[dir + 8],
1359
52782e5cf7c9 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1335
diff changeset
   740
		EV_BUBBLE
0
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
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   743
	if (v != NULL) v->u.special.unk2 = dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   746
static void TileLoop_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
{
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   748
	uint newgfx;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
   750
	if (!IsIndustryCompleted(tile)) {
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   751
		MakeIndustryTileBigger(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   755
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	TransportIndustryGoods(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
   759
	newgfx = _industry_section_animation_next[GetIndustryGfx(tile)];
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   760
	if (newgfx != 255) {
3495
6672c181ace4 (svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents: 3494
diff changeset
   761
		ResetIndustryConstructionStage(tile);
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   762
		SetIndustryGfx(tile, newgfx);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
		return;
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
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   767
#define SET_AND_ANIMATE(tile, a, b)   { SetIndustryGfx(tile, a); _m[tile].m1 = b; AddAnimatedTile(tile); }
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   768
#define SET_AND_UNANIMATE(tile, a, b) { SetIndustryGfx(tile, a); _m[tile].m1 = b; DeleteAnimatedTile(tile); }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
3331
da6bbabbb6cc (svn r4108) Add [GS]etIndustryGfx()
tron
parents: 3326
diff changeset
   770
	switch (GetIndustryGfx(tile)) {
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   771
	case 0x18: // coast line at oilrigs
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   772
	case 0x19:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   773
	case 0x1A:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   774
	case 0x1B:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   775
	case 0x1C:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   776
		TileLoop_Water(tile);
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   777
		break;
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   778
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	case 0:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
		if (!(_tick_counter & 0x400) && CHANCE16(1,2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
			SET_AND_ANIMATE(tile,1,0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
		break;
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
	case 47:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
		if (!(_tick_counter & 0x400) && CHANCE16(1,2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
			SET_AND_ANIMATE(tile,0x30,0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	case 79:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		if (!(_tick_counter & 0x400) && CHANCE16(1,2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
			SET_AND_ANIMATE(tile,0x58,0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
	case 29:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
		if (CHANCE16(1,6))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
			SET_AND_ANIMATE(tile,0x1E,0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
	case 1:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
		if (!(_tick_counter & 0x400))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
			SET_AND_UNANIMATE(tile, 0, 0x83);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
	case 48:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		if (!(_tick_counter & 0x400))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
			SET_AND_UNANIMATE(tile, 0x2F, 0x83);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		break;
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
	case 88:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
		if (!(_tick_counter & 0x400))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
			SET_AND_UNANIMATE(tile, 0x4F, 0x83);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
	case 10:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
		if (CHANCE16(1,3)) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
   816
			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
			AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   821
	case 49:
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3418
diff changeset
   822
		CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   823
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
	case 143: {
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   827
			Industry* i = GetIndustryByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
			if (i->was_cargo_delivered) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
				i->was_cargo_delivered = false;
2061
f5bdffb68ae8 (svn r2570) Fix: Removed some code that had no effect.
ludde
parents: 2051
diff changeset
   830
				_m[tile].m4 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
				AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	case 161:
3290
235df477f3ee (svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents: 3282
diff changeset
   837
		TileLoopIndustry_BubbleGenerator(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   838
		break;
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   839
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
	case 165:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	case 174:
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   845
		if (CHANCE16(1, 3)) AddAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   851
static void ClickTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
{
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   853
	ShowIndustryViewWindow(GetIndustryIndex(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   856
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 3338
diff changeset
   861
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
{
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   863
	const Industry* i = GetIndustryByTile(tile);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
   864
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	b[0] = i->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	b[1] = i->produced_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   869
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
   870
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
void DeleteIndustry(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
{
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   876
	BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
   877
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
3314
6aaeba4b92e8 (svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents: 3296
diff changeset
   878
			if (GetIndustryIndex(tile_cur) == i->index) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
				DoClearSquare(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
			}
3338
7cff208f0446 (svn r4120) Use the new station functions where appropriate
tron
parents: 3331
diff changeset
   881
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
			DeleteOilRig(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
		}
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   884
	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   885
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	i->xy = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	_industry_sort_dirty = true;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   888
	DeleteSubsidyWithIndustry(i->index);
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   889
	DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
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
   894
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   895
static bool IsBadFarmFieldTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   897
	switch (GetTileType(tile)) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3440
diff changeset
   898
		case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   899
		case MP_TREES: return false;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   900
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
1048
8611c5c02dcb (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   904
static bool IsBadFarmFieldTile2(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   906
	switch (GetTileType(tile)) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3440
diff changeset
   907
		case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   908
		case MP_TREES: return false;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   909
		default:       return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   913
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
   914
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
		tile = TILE_MASK(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   917
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
   918
		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   919
			byte or = type;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   920
2637
722dae65c4a8 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2630
diff changeset
   921
			if (or == 1 && CHANCE16(1, 7)) or = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   923
			if (direction == AXIS_X) {
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   924
				SetFenceSE(tile, or);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   925
			} else {
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   926
				SetFenceSW(tile, or);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   929
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   930
		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
   931
	} while (--size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   934
static void PlantFarmField(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	uint size_x, size_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	uint32 r;
2133
d7f582b7001d (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   938
	uint count;
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   939
	uint counter;
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   940
	uint field_type;
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   941
	int type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	if (_opt.landscape == LT_HILLY) {
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3421
diff changeset
   944
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	/* determine field size */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
	r = (Random() & 0x303) + 0x404;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
	if (_opt.landscape == LT_HILLY) r += 0x404;
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   951
	size_x = GB(r, 0, 8);
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   952
	size_y = GB(r, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	/* offset tile to match size */
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   955
	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
   956
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	/* check the amount of bad tiles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
	count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
	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
   960
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
		count += IsBadFarmFieldTile(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
2133
d7f582b7001d (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   963
	if (count * 2 >= size_x * size_y) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	/* determine type of field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
	r = Random();
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   967
	counter = GB(r, 5, 3);
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   968
	field_type = GB(r, 8, 8) * 9 >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	/* make field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	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
   972
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
		if (!IsBadFarmFieldTile2(cur_tile)) {
3291
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3290
diff changeset
   974
			MakeField(cur_tile, field_type);
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   975
			SetClearCounter(cur_tile, counter);
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   976
			MarkTileDirtyByTile(cur_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	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
   979
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	type = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
	if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
		type = _plantfarmfield_type[Random() & 0xF];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   985
	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   986
	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   987
	SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3144
diff changeset
   988
	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
   989
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   991
static void MaybePlantFarmField(const Industry* i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
{
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   993
	if (CHANCE16(1, 8)) {
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   994
		int x = i->width  / 2 + Random() % 31 - 16;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   995
		int y = i->height / 2 + Random() % 31 - 16;
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   996
		TileIndex tile = TileAddWrap(i->xy, x, y);
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
   997
		if (tile != INVALID_TILE) PlantFarmField(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   998
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
static void ChopLumberMillTrees(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
{
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1003
	static const TileIndexDiffC _chop_dir[] = {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1004
		{ 0,  1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1005
		{ 1,  0},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1006
		{ 0, -1},
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1007
		{-1,  0}
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1008
	};
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1009
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1010
	TileIndex tile = i->xy;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1011
	int a;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
3321
4061bfef1830 (svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents: 3320
diff changeset
  1013
	if (!IsIndustryCompleted(tile)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	/* search outwards as a rectangular spiral */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1016
	for (a = 1; a != 41; a += 2) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1017
		uint dir;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1018
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1019
		for (dir = 0; dir != 4; dir++) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1020
			int j = a;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1021
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
				tile = TILE_MASK(tile);
1035
812f837ee03f (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
  1024
				if (IsTileType(tile, MP_TREES)) {
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1025
					PlayerID old_player = _current_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
					/* found a tree */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
					_current_player = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
					_industry_sound_ctr = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
					_industry_sound_tile = tile;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1031
					SndPlayTileFx(SND_38_CHAINSAW, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1033
					DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1034
					SetTropicZone(tile, TROPICZONE_INVALID);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
					i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45);
314
75fe42199623 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 267
diff changeset
  1037
75fe42199623 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 267
diff changeset
  1038
					_current_player = old_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
				}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1041
				tile += ToTileIndexDiff(_chop_dir[dir]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
			} while (--j);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
		}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1044
		tile -= TileDiffXY(1, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
}
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
static const byte _industry_sounds[37][2] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
	{0},
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1051
	{1, SND_28_SAWMILL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	{0},
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1055
	{1, SND_03_FACTORY_WHISTLE},
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1056
	{1, SND_03_FACTORY_WHISTLE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	{0},
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1058
	{3, SND_24_SHEEP},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	{0},
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1063
	{1, SND_28_SAWMILL},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	{0},
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1072
	{1, SND_03_FACTORY_WHISTLE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	{0},
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1081
	{1, SND_33_PLASTIC_MINE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
};
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
static void ProduceIndustryGoods(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	uint num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	/* play a sound? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	if ((i->counter & 0x3F) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
		if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
			SndPlayTileFx(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
				_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
				i->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
	i->counter--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	/* produce some cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
	if ((i->counter & 0xFF) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
		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
  1108
		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
  1109
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1110
		if (i->type == IT_FARM) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
			MaybePlantFarmField(i);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1112
		} else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
			ChopLumberMillTrees(i);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1114
		}
0
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
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1118
void OnTick_Industry(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	if (_industry_sound_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
		_industry_sound_ctr++;
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
		if (_industry_sound_ctr == 75) {
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1126
			SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
		} 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
  1128
			_industry_sound_ctr = 0;
541
625227bb2a3d (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1129
			SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1133
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1135
	FOR_ALL_INDUSTRIES(i) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1136
		if (i->xy != 0) ProduceIndustryGoods(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1141
static bool CheckNewIndustry_NULL(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1146
static bool CheckNewIndustry_Forest(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	if (_opt.landscape == LT_HILLY) {
1335
a5f223b9f549 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1320
diff changeset
  1149
		if (GetTileZ(tile) < _opt.snow_line + 16U) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
7
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1157
extern bool _ignore_restrictions;
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1158
1586
d179623e13c9 (svn r2090) CheckNewIndustry_Oilwell() -> CheckNewIndustry_Oil() since it was concerning oil rigs and oil rafineries, but specifically NOT oil wells. ;-) Documented that.
pasky
parents: 1373
diff changeset
  1159
/* Oil Rig and Oil Refinery */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1160
static bool CheckNewIndustry_Oil(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1162
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1163
	if (_game_mode == GM_EDITOR && type != IT_OIL_RIG)   return true;
2868
9678db2d90e8 (svn r3416) - Fix: Disallow building an oil rig above sea level.
peter1138
parents: 2817
diff changeset
  1164
	if ((type != IT_OIL_RIG || TileHeight(tile) == 0) &&
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3421
diff changeset
  1165
			DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16)   return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1171
static bool CheckNewIndustry_Farm(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
	if (_opt.landscape == LT_HILLY) {
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3421
diff changeset
  1174
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
			_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1182
static bool CheckNewIndustry_Plantation(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
{
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1184
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1187
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1191
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1192
static bool CheckNewIndustry_Water(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
{
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1194
	if (GetTropicZone(tile) != TROPICZONE_DESERT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
		_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
  1196
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1202
static bool CheckNewIndustry_Lumbermill(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
{
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3344
diff changeset
  1204
	if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
		_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
  1206
		return false;
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
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1211
static bool CheckNewIndustry_BubbleGen(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
{
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1213
	return GetTileZ(tile) <= 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1216
typedef bool CheckNewIndustryProc(TileIndex tile, int type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
static CheckNewIndustryProc * const _check_new_industry_procs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	CheckNewIndustry_NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	CheckNewIndustry_Forest,
1586
d179623e13c9 (svn r2090) CheckNewIndustry_Oilwell() -> CheckNewIndustry_Oil() since it was concerning oil rigs and oil rafineries, but specifically NOT oil wells. ;-) Documented that.
pasky
parents: 1373
diff changeset
  1220
	CheckNewIndustry_Oil,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	CheckNewIndustry_Farm,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
	CheckNewIndustry_Plantation,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	CheckNewIndustry_Water,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
	CheckNewIndustry_Lumbermill,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	CheckNewIndustry_BubbleGen,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1228
static bool CheckSuitableIndustryPos(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
{
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1230
	uint x = TileX(tile);
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1231
	uint y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1233
	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
  1234
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1241
static const Town* CheckMultipleIndustryInTown(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1243
	const Town* t;
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1244
	const Industry* i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
	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
  1247
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1248
	if (_patches.multiple_industry_per_town) return t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1250
	FOR_ALL_INDUSTRIES(i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
		if (i->xy != 0 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
				i->type == (byte)type &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
				i->town == t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
			return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
	return t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
  1262
static const byte _industry_section_bits[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	16, 16, 4, 2, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
	16, 4, 2, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1287
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable* it, int type, const Town* t)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
	_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	do {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1292
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1293
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
		if (!IsValidTile(cur_tile)) {
3440
811c85e5ca0f (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1295
			if (it->gfx == 0xff) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1298
3440
811c85e5ca0f (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1299
		if (it->gfx == 0xFF) {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1300
			if (!IsTileType(cur_tile, MP_WATER) ||
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1301
					GetTileSlope(cur_tile, NULL) != 0) {
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1302
				return false;
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1303
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
		} else {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1305
			if (!EnsureNoVehicle(cur_tile)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
			if (type == IT_OIL_RIG)  {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1308
				if (!IsTileType(cur_tile, MP_WATER) || _m[cur_tile].m5 != 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
			} else {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1310
				uint tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1312
				if (IsTileType(cur_tile, MP_WATER) && _m[cur_tile].m5 == 0) return false;
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1313
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1314
				tileh = GetTileSlope(cur_tile, NULL);
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1315
				if (IsSteepTileh(tileh)) return false;
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1316
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1317
				if (tileh != 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
					int t;
3494
ba64f1689870 (svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents: 3491
diff changeset
  1319
					byte bits = _industry_section_bits[it->gfx];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1321
					if (bits & 0x10) return false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1322
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1323
					t = ~tileh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1325
					if (bits & 1 && (t & (1 + 8))) return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1326
					if (bits & 2 && (t & (4 + 8))) return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1327
					if (bits & 4 && (t & (1 + 2))) return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1328
					if (bits & 8 && (t & (2 + 4))) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
				if (type == IT_BANK) {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1332
					if (!IsTileType(cur_tile, MP_HOUSE) || t->population < 1200) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
						_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
  1334
						return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
				} else if (type == IT_BANK_2) {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1337
					if (!IsTileType(cur_tile, MP_HOUSE)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
						_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
						return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
				} else if (type == IT_TOY_SHOP) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1342
					if (DistanceMax(t->xy, cur_tile) > 9) return false;
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1343
					if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
				} else if (type == IT_WATER_TOWER) {
3296
34064bbe27a5 (svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents: 3291
diff changeset
  1345
					if (!IsTileType(cur_tile, MP_HOUSE)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
						_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
						return false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1348
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
do_clear:
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1351
					if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
						return false;
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
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
		}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1356
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1361
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1363
	const IndustrySpec* spec = &_industry_spec[type];
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
  1364
	const Industry* i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
	// accepting industries won't be close, not even with patch
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1367
	if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
		return true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1369
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1370
	FOR_ALL_INDUSTRIES(i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		// check if an industry that accepts the same goods is nearby
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
		if (i->xy != 0 &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1373
				DistanceMax(tile, i->xy) <= 14 &&
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1374
				spec->accepts_cargo[0] != CT_INVALID &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1375
				spec->accepts_cargo[0] == i->accepts_cargo[0] && (
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1376
					_game_mode != GM_EDITOR ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1377
					!_patches.same_industry_close ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1378
					!_patches.multiple_industry_per_town
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1379
				)) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1380
			_error_message = STR_INDUSTRY_TOO_CLOSE;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1381
			return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1382
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
		// check "not close to" field.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
		if (i->xy != 0 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
				(i->type == spec->a || i->type == spec->b || i->type == spec->c) &&
1245
3822f77cbc53 (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1214
diff changeset
  1387
				DistanceMax(tile, i->xy) <= 14) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
			_error_message = STR_INDUSTRY_TOO_CLOSE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1395
static Industry *AllocateIndustry(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1399
	FOR_ALL_INDUSTRIES(i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		if (i->xy == 0) {
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1401
			uint index = i->index;
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1402
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1403
			if (i->index > _total_industries) _total_industries = i->index;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1404
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1405
			memset(i, 0, sizeof(*i));
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1406
			i->index = index;
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1407
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
			return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	}
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1411
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1412
	/* Check if we can add a block to the pool */
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1413
	return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1416
static void DoCreateNewIndustry(Industry* i, TileIndex tile, int type, const IndustryTileTable* it, const Town* t, byte owner)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
	const IndustrySpec *spec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
	i->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	i->width = i->height = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
	i->type = type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
	spec = &_industry_spec[type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
	i->produced_cargo[0] = spec->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
	i->produced_cargo[1] = spec->produced_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
	i->accepts_cargo[0] = spec->accepts_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
	i->accepts_cargo[1] = spec->accepts_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
	i->accepts_cargo[2] = spec->accepts_cargo[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
	i->production_rate[0] = spec->production_rate[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
	i->production_rate[1] = spec->production_rate[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
	if (_patches.smooth_economy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
		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
  1438
		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
  1439
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
	i->town = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
	i->owner = owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
2484
0e45d70ae908 (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2469
diff changeset
  1444
	r = Random();
2492
b4785c8f3700 (svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents: 2484
diff changeset
  1445
	i->color_map = GB(r, 8, 4);
b4785c8f3700 (svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents: 2484
diff changeset
  1446
	i->counter = GB(r, 0, 12);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	i->cargo_waiting[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
	i->cargo_waiting[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
	i->last_mo_production[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
	i->last_mo_production[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
	i->last_mo_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
	i->last_mo_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
	i->pct_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
	i->pct_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
	i->total_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
	i->total_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
	i->was_cargo_delivered = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
	i->last_prod_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
	i->total_production[0] = i->production_rate[0] * 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	i->total_production[1] = i->production_rate[1] * 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1462
	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
  1463
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	i->prod_level = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	do {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1467
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
3440
811c85e5ca0f (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1469
		if (it->gfx != 0xFF) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
			byte size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1472
			size = it->ti.x;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
			if (size > i->width) i->width = size;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1474
			size = it->ti.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
			if (size > i->height)i->height = size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1477
			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
  1478
3440
811c85e5ca0f (svn r4270) Rename some bogus map5 to gfx
tron
parents: 3422
diff changeset
  1479
			MakeIndustry(cur_tile, i->index, it->gfx);
3320
e9e284ab853a (svn r4086) Add MakeIndustry()
tron
parents: 3314
diff changeset
  1480
			if (_generating_world) _m[cur_tile].m1 = 0x1E; /* maturity */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1481
		}
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1482
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
	i->width++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
	i->height++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	if (i->type == IT_FARM || i->type == IT_FARM_2) {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1488
		tile = i->xy + TileDiffXY(i->width / 2, i->height / 2);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1489
		for (j = 0; j != 50; j++) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1490
			int x = Random() % 31 - 16;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1491
			int y = Random() % 31 - 16;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1492
			TileIndex new_tile = TileAddWrap(tile, x, y);
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1493
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1494
			if (new_tile != INVALID_TILE) PlantFarmField(new_tile);
131
16e59d059384 (svn r132) -Fix: [1014278] TileAddWrap() gave wrong results. Fixed now.
truelight
parents: 110
diff changeset
  1495
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 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
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1501
/** Build/Fund an industry
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1502
 * @param tile tile where industry is built
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1503
 * @param p1 industry type @see build_industry.h and @see industry.h
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1504
 * @param p2 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1505
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
  1506
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
  1507
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1508
	const Town* t;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1509
	Industry *i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
	const IndustryTileTable * const *itt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	const IndustryTileTable *it;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
	const IndustrySpec *spec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1517
	if (!CheckSuitableIndustryPos(tile)) return CMD_ERROR;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1518
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1519
	/* Check if the to-be built/founded industry is available for this climate.
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1520
	 * Unfortunately we have no easy way of checking, except for looping the table */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1521
	{
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1522
		const byte* i;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1523
		bool found = false;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1524
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1525
		for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1526
			if (*i == p1) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1527
				found = true;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1528
				break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1529
			}
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1530
		}
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1531
		if (!found) return CMD_ERROR;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1532
	}
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
	spec = &_industry_spec[p1];
2638
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1535
	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
1800
1324958d7c73 (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
  1536
	 * Raw material industries are industries that do not accept cargo (at least for now)
2638
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1537
	 * Exclude the lumber mill (only "raw" industry that can be built) */
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1538
	if (!_patches.build_rawmaterial_ind &&
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1539
			spec->accepts_cargo[0] == CT_INVALID &&
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1540
			spec->accepts_cargo[1] == CT_INVALID &&
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1541
			spec->accepts_cargo[2] == CT_INVALID &&
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1542
			p1 != IT_LUMBER_MILL) {
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1543
		return CMD_ERROR;
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1544
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1546
	if (!_check_new_industry_procs[spec->check_proc](tile, p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1547
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1548
	t = CheckMultipleIndustryInTown(tile, p1);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1549
	if (t == NULL) return CMD_ERROR;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1550
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	num = spec->num_table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	itt = spec->table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	do {
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1555
		if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1556
	} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1, t));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1559
	if (!CheckIfTooCloseToIndustry(tile, p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1561
	i = AllocateIndustry();
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1562
	if (i == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1564
	if (flags & DC_EXEC) DoCreateNewIndustry(i, tile, p1, it, t, OWNER_NONE);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1565
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
	return (_price.build_industry >> 5) * _industry_type_costs[p1];
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1570
Industry *CreateNewIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
{
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2598
diff changeset
  1572
	const Town* t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
	const IndustryTileTable *it;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	const IndustrySpec *spec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1578
	if (!CheckSuitableIndustryPos(tile)) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
	spec = &_industry_spec[type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1582
	if (!_check_new_industry_procs[spec->check_proc](tile, type)) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1584
	t = CheckMultipleIndustryInTown(tile, type);
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1585
	if (t == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
	/* pick a random layout */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1588
	it = spec->table[RandomRange(spec->num_table)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1590
	if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) return NULL;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1591
	if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1593
	i = AllocateIndustry();
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1594
	if (i == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
2638
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1596
	DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1597
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
	return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1601
static const byte _numof_industry_table[4][12] = {
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1602
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
	{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
	{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
	{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
static void PlaceInitialIndustry(byte type, int amount)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
{
2072
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1610
	int num = _numof_industry_table[_opt.diff.number_industries][amount];
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1611
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1612
	if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) {
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1613
		// These are always placed next to the coastline, so we scale by the perimeter instead.
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1614
		num = ScaleByMapSize1D(num);
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1615
	} else {
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1616
		num = ScaleByMapSize(num);
66d208875eda (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1617
	}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1618
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1619
	if (_opt.diff.number_industries != 0) {
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1620
		PlayerID old_player = _current_player;
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1621
		_current_player = OWNER_NONE;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1622
		assert(num > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
		do {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1625
			uint i;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1626
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1627
			for (i = 0; i < 2000; i++) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1628
				if (CreateNewIndustry(RandomTile(), type) != NULL) break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1629
			}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1630
		} while (--num);
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1631
267
ee1ce0133772 (svn r273) -Fix: sorry, wrongly fixed
darkvater
parents: 266
diff changeset
  1632
		_current_player = old_player;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1633
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1636
void GenerateIndustries(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	const byte *b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	b = _industry_create_table[_opt.landscape];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
		PlaceInitialIndustry(b[1], b[0]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	} while ( (b+=2)[0] != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1646
/* Change industry production or do closure */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
static void ExtChangeIndustryProduction(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
{
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1649
	bool closeit = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1652
	switch (_industry_close_mode[i->type]) {
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1653
		case INDUSTRYLIFE_NOT_CLOSABLE:
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1654
			return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1655
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1656
		case INDUSTRYLIFE_CLOSABLE:
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1657
			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
  1658
				closeit = false;
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1659
			break;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1660
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1661
		default: /* INDUSTRY_PRODUCTION */
2638
0811adaec525 (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1662
			for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1663
				uint32 r = Random();
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1664
				int old, new, percent;
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1665
				int mag;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1666
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1667
				new = old = i->production_rate[j];
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1668
				if (CHANCE16I(20, 1024, r))
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1669
					new -= ((RandomRange(50) + 10) * old) >> 8;
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1670
				if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16))
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1671
					new += ((RandomRange(50) + 10) * old) >> 8;
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1672
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1673
				new = clamp(new, 0, 255);
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1674
				if (new == old) {
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1675
					closeit = false;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1676
					continue;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1677
				}
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1678
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1679
				percent = new * 100 / old - 100;
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1680
				i->production_rate[j] = new;
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1681
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1682
				if (new >= _industry_spec[i->type].production_rate[j] / 4)
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1683
					closeit = false;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1684
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1685
				mag = abs(percent);
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1686
				if (mag >= 10) {
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1687
					SetDParam(2, mag);
1603
8d6b33f98493 (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1688
					SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]);
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1689
					SetDParam(1, i->index);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1690
					AddNewsItem(
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1691
						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1692
						NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1693
						i->xy + TileDiffXY(1, 1), 0
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1694
					);
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1695
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
			}
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1697
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1700
	/* If industry will be closed down, show this */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
	if (closeit) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1702
		i->prod_level = 0;
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1703
		SetDParam(0, i->index);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1704
		AddNewsItem(
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1705
			_industry_close_strings[i->type],
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1706
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1707
			i->xy + TileDiffXY(1, 1), 0
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1708
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
static void UpdateIndustryStatistics(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
	byte pct;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1716
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1717
	if (i->produced_cargo[0] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
		pct = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
		if (i->last_mo_production[0] != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
			i->last_prod_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
			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
  1722
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
		i->pct_transported[0] = pct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1725
		i->total_production[0] = i->last_mo_production[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
		i->last_mo_production[0] = 0;
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
		i->total_transported[0] = i->last_mo_transported[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
		i->last_mo_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1732
	if (i->produced_cargo[1] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
		pct = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
		if (i->last_mo_production[1] != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
			i->last_prod_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
			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
  1737
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
		i->pct_transported[1] = pct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
		i->total_production[1] = i->last_mo_production[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
		i->last_mo_production[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
		i->total_transported[1] = i->last_mo_transported[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
		i->last_mo_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1748
	if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID)
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1749
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1751
	if (i->prod_level == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
		DeleteIndustry(i);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1753
	} else if (_patches.smooth_economy) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
		ExtChangeIndustryProduction(i);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1755
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
static const byte _new_industry_rand[4][32] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
	{12,12,12,12,12,12,12, 0, 0, 6, 6, 9, 9, 3, 3, 3,18,18, 4, 4, 2, 2, 5, 5, 5, 5, 5, 5, 1, 1, 8, 8},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
	{16,16,16, 0, 0, 0, 9, 9, 9, 9,13,13, 3, 3, 3, 3,15,15,15, 4, 4,11,11,11,11,11,14,14, 1, 1, 7, 7},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
	{21,21,21,24,22,22,22,22,23,23,12,12,12, 4, 4,19,19,19,13,13,20,20,20,11,11,11,17,17,17,10,10,10},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
	{30,30,30,36,36,31,31,31,27,27,27,28,28,28,26,26,26,34,34,34,35,35,35,29,29,29,32,32,32,33,33,33},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
static void MaybeNewIndustry(uint32 r)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
	int type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2133
diff changeset
  1771
	type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1773
	if (type == IT_OIL_WELL && _date > 10958) return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1774
	if (type == IT_OIL_RIG  && _date < 14610) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
	j = 2000;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1777
	for (;;) {
2637
722dae65c4a8 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2630
diff changeset
  1778
		i = CreateNewIndustry(RandomTile(), type);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1779
		if (i != NULL) break;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1780
		if (--j == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1781
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1783
	SetDParam(0, type + STR_4802_COAL_MINE);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1784
	SetDParam(1, i->town->index);
2260
10154bc4c650 (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1785
	AddNewsItem(
10154bc4c650 (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1786
		(type != IT_FOREST) ?
10154bc4c650 (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1787
			STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR,
10154bc4c650 (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1788
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0
10154bc4c650 (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1789
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1791
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1792
static void ChangeIndustryProduction(Industry *i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
{
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1794
	bool only_decrease = false;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1795
	StringID str = STR_NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1796
	int type = i->type;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1797
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1798
	switch (_industry_close_mode[type]) {
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1799
		case INDUSTRYLIFE_NOT_CLOSABLE:
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1800
			return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1802
		case INDUSTRYLIFE_PRODUCTION:
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1803
			/* decrease or increase */
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1804
			if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL)
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1805
				only_decrease = true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1806
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1807
			if (only_decrease || CHANCE16(1,3)) {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1808
				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1809
				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1810
					/* Increase production */
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1811
					if (i->prod_level != 0x80) {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1812
						byte b;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1813
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1814
						i->prod_level <<= 1;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1815
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1816
						b = i->production_rate[0] * 2;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1817
						if (i->production_rate[0] >= 128)
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1818
							b = 0xFF;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1819
						i->production_rate[0] = b;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1820
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1821
						b = i->production_rate[1] * 2;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1822
						if (i->production_rate[1] >= 128)
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1823
							b = 0xFF;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1824
						i->production_rate[1] = b;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1825
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1826
						str = _industry_prod_up_strings[type];
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1827
					}
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1828
				} else {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1829
					/* Decrease production */
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1830
					if (i->prod_level == 4) {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1831
						i->prod_level = 0;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1832
						str = _industry_close_strings[type];
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1833
					} else {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1834
						i->prod_level >>= 1;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1835
						i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1836
						i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1837
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1838
						str = _industry_prod_down_strings[type];
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1839
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
			}
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1842
			break;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1843
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3495
diff changeset
  1844
		case INDUSTRYLIFE_CLOSABLE:
1320
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1845
			/* maybe close */
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1846
			if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1847
				i->prod_level = 0;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1848
				str = _industry_close_strings[type];
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1849
			}
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1850
			break;
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1851
	}
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1852
44a8658d88c0 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1853
	if (str != STR_NULL) {
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1854
		SetDParam(0, i->index);
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1855
		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, 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
  1856
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1857
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1859
void IndustryMonthlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
	Industry *i;
2498
3ed05caa4449 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1862
	PlayerID old_player = _current_player;
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1863
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1865
	FOR_ALL_INDUSTRIES(i) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1866
		if (i->xy != 0) UpdateIndustryStatistics(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1867
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1869
	/* 3% chance that we start a new industry */
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1870
	if (CHANCE16(3, 100)) {
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1871
		MaybeNewIndustry(Random());
1269
0c8818a1c07a (svn r1773) -Fix: [ 1114950 ] Game crashed sometimes when there were no industries
truelight
parents: 1267
diff changeset
  1872
	} else if (!_patches.smooth_economy && _total_industries > 0) {
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1873
		i = GetIndustry(RandomRange(_total_industries));
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1874
		if (i->xy != 0) ChangeIndustryProduction(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
	}
266
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1876
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1877
	_current_player = old_player;
b914f2b7da78 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1878
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
	// production-change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1880
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1885
void InitializeIndustries(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
{
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1887
	CleanPool(&_industry_pool);
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1888
	AddBlockToPool(&_industry_pool);
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1889
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
	_total_industries = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
const TileTypeProcs _tile_type_industry_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
	DrawTile_Industry,					/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1896
	GetSlopeZ_Industry,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
	ClearTile_Industry,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
	GetAcceptedCargo_Industry,	/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
	GetTileDesc_Industry,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
	GetTileTrackStatus_Industry,/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
	ClickTile_Industry,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
	AnimateTile_Industry,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
	TileLoop_Industry,					/* tile_loop_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	ChangeTileOwner_Industry,		/* change_tile_owner_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
	GetProducedCargo_Industry,  /* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	NULL,												/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
	NULL,												/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
  1908
	GetSlopeTileh_Industry,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1800
diff changeset
  1911
static const SaveLoad _industry_desc[] = {
1174
6a5e747f3ba6 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1093
diff changeset
  1912
	SLE_CONDVAR(Industry, xy,					SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
3047
2880aef0ee9d (svn r3627) - Change all hardcoded 255 max-saveload versions with the define SL_MAX_VERSION
Darkvater
parents: 2979
diff changeset
  1913
	SLE_CONDVAR(Industry, xy,					SLE_UINT32, 6, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
	SLE_VAR(Industry,width,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
	SLE_VAR(Industry,height,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
	SLE_REF(Industry,town,						REF_TOWN),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
	SLE_ARR(Industry,produced_cargo,  SLE_UINT8, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
	SLE_ARR(Industry,cargo_waiting,   SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
	SLE_ARR(Industry,production_rate, SLE_UINT8, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1920
	SLE_ARR(Industry,accepts_cargo,		SLE_UINT8, 3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
	SLE_VAR(Industry,prod_level,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
	SLE_ARR(Industry,last_mo_production,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	SLE_ARR(Industry,last_mo_transported,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
	SLE_ARR(Industry,pct_transported,SLE_UINT8, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	SLE_ARR(Industry,total_production,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
	SLE_ARR(Industry,total_transported,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	SLE_VAR(Industry,counter,					SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	SLE_VAR(Industry,type,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	SLE_VAR(Industry,owner,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	SLE_VAR(Industry,color_map,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
	SLE_VAR(Industry,last_prod_year,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
	SLE_VAR(Industry,was_cargo_delivered,SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
	// reserve extra space in savegame here. (currently 32 bytes)
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3173
diff changeset
  1937
	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1942
static void Save_INDY(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
	Industry *ind;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1945
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
	// Write the vehicles
830
36c1366367e4 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1947
	FOR_ALL_INDUSTRIES(ind) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
		if (ind->xy != 0) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1949
			SlSetArrayIndex(ind->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
			SlObject(ind, _industry_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1955
static void Load_INDY(void)
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
	int index;
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1958
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
	_total_industries = 0;
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1960
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
	while ((index = SlIterateArray()) != -1) {
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1962
		Industry *i;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1963
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1964
		if (!AddBlockIfNeeded(&_industry_pool, index))
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1965
			error("Industries: failed loading savegame: too many industries");
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1966
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1967
		i = GetIndustry(index);
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1968
		SlObject(i, _industry_desc);
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1969
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1970
		if (index > _total_industries) _total_industries = index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1973
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1974
const ChunkHandler _industry_chunk_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
	{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
};