industry_cmd.c
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 9944 4f027626dbf6
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     4
#include "openttd.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 497
diff changeset
     5
#include "table/strings.h"
2148
47ba4a1b1c3b (svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents: 2140
diff changeset
     6
#include "table/sprites.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     7
#include "functions.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 552
diff changeset
     8
#include "map.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1202
diff changeset
     9
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "town.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "saveload.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "economy.h"
337
66647f97e7c0 (svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents: 314
diff changeset
    18
#include "sound.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    19
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    21
enum {
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    22
	/* Max industries: 64000 (8 * 8000) */
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    23
	INDUSTRY_POOL_BLOCK_SIZE_BITS = 3,       /* In bits, so (1 << 3) == 8 */
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    24
	INDUSTRY_POOL_MAX_BLOCKS      = 8000,
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    25
};
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    26
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    27
/**
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    28
 * Called if a new block is added to the industry-pool
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    29
 */
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2737
diff changeset
    30
static void IndustryPoolNewBlock(uint start_item)
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    31
{
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    32
	Industry *i;
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    33
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
    34
	FOR_ALL_INDUSTRIES_FROM(i, start_item) i->index = start_item++;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    35
}
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    36
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    37
/* Initialize the industry-pool */
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    38
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, 0, 0, NULL };
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
    39
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
    40
static byte _industry_sound_ctr;
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
    41
static TileIndex _industry_sound_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
void ShowIndustryViewWindow(int industry);
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    44
void BuildOilRig(TileIndex tile);
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    45
void DeleteOilRig(TileIndex tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
typedef struct DrawIndustryTileStruct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	uint32 sprite_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	uint32 sprite_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
2653
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    51
	byte subtile_x:4;
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    52
	byte subtile_y:4;
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    53
	byte width:4;
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
    54
	byte height:4;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	byte dz;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	byte proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
} DrawIndustryTileStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
typedef struct DrawIndustrySpec1Struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
	byte x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	byte image_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	byte image_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	byte image_3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
} DrawIndustrySpec1Struct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
typedef struct DrawIndustrySpec4Struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	byte image_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	byte image_2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	byte image_3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
} DrawIndustrySpec4Struct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
typedef struct IndustryTileTable {
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
    74
	TileIndexDiffC ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	byte map5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
} IndustryTileTable;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
typedef struct IndustrySpec {
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
    79
	const IndustryTileTable *const *table;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	byte num_table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	byte a,b,c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	byte produced_cargo[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	byte production_rate[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	byte accepts_cargo[3];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	byte check_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
} IndustrySpec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
    88
#include "table/industry_land.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
#include "table/build_industry.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    91
typedef enum IndustryType {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    92
	INDUSTRY_NOT_CLOSABLE,     //! Industry can never close
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    93
	INDUSTRY_PRODUCTION,       //! Industry can close and change of production
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    94
	INDUSTRY_CLOSABLE,         //! Industry can only close (no production change)
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    95
} IndustryType;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    96
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    97
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    98
static const IndustryType _industry_close_mode[37] = {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
    99
	/* COAL_MINE */         INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   100
	/* POWER_STATION */     INDUSTRY_NOT_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   101
	/* SAWMILL */           INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   102
	/* FOREST */            INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   103
	/* OIL_REFINERY */      INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   104
	/* OIL_RIG */           INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   105
	/* FACTORY */           INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   106
	/* PRINTING_WORKS */    INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   107
	/* STEEL_MILL */        INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   108
	/* FARM */              INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   109
	/* COPPER_MINE */       INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   110
	/* OIL_WELL */          INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   111
	/* BANK */              INDUSTRY_NOT_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   112
	/* FOOD_PROCESS */      INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   113
	/* PAPER_MILL */        INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   114
	/* GOLD_MINE */         INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   115
	/* BANK_2,  */          INDUSTRY_NOT_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   116
	/* DIAMOND_MINE */      INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   117
	/* IRON_MINE */         INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   118
	/* FRUIT_PLANTATION */  INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   119
	/* RUBBER_PLANTATION */ INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   120
	/* WATER_SUPPLY */      INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   121
	/* WATER_TOWER */       INDUSTRY_NOT_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   122
	/* FACTORY_2 */         INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   123
	/* FARM_2 */            INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   124
	/* LUMBER_MILL */       INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   125
	/* COTTON_CANDY */      INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   126
	/* CANDY_FACTORY */     INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   127
	/* BATTERY_FARM */      INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   128
	/* COLA_WELLS */        INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   129
	/* TOY_SHOP */          INDUSTRY_NOT_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   130
	/* TOY_FACTORY */       INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   131
	/* PLASTIC_FOUNTAINS */ INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   132
	/* FIZZY_DRINK_FACTORY */INDUSTRY_CLOSABLE,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   133
	/* BUBBLE_GENERATOR */  INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   134
	/* TOFFEE_QUARRY */     INDUSTRY_PRODUCTION,
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
   135
	/* SUGAR_MINE */        INDUSTRY_PRODUCTION
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
static const StringID _industry_prod_up_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	STR_4836_NEW_COAL_SEAM_FOUND_AT,
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_4835_INCREASES_PRODUCTION,
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_4837_NEW_OIL_RESERVES_FOUND,
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_4835_INCREASES_PRODUCTION,
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_4838_IMPROVED_FARMING_METHODS,
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_4837_NEW_OIL_RESERVES_FOUND,
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_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	STR_4838_IMPROVED_FARMING_METHODS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
	STR_4838_IMPROVED_FARMING_METHODS,
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_4835_INCREASES_PRODUCTION,
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_4838_IMPROVED_FARMING_METHODS,
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
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	STR_4835_INCREASES_PRODUCTION,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
static const StringID _industry_prod_down_strings[] = {
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_4839_PRODUCTION_DOWN_BY_50,
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_483A_INSECT_INFESTATION_CAUSES,
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_4839_PRODUCTION_DOWN_BY_50,
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_483A_INSECT_INFESTATION_CAUSES,
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_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	STR_483A_INSECT_INFESTATION_CAUSES,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	STR_483A_INSECT_INFESTATION_CAUSES,
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_4839_PRODUCTION_DOWN_BY_50,
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_483A_INSECT_INFESTATION_CAUSES,
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_4839_PRODUCTION_DOWN_BY_50,
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_483A_INSECT_INFESTATION_CAUSES,
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
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	STR_4839_PRODUCTION_DOWN_BY_50,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
static const StringID _industry_close_strings[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
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_4832_ANNOUNCES_IMMINENT_CLOSURE,
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_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
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_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
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_4832_ANNOUNCES_IMMINENT_CLOSURE,
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_4833_SUPPLY_PROBLEMS_CAUSE_TO,
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_4834_LACK_OF_NEARBY_TREES_CAUSES,
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_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
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_4833_SUPPLY_PROBLEMS_CAUSE_TO,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   255
	STR_4832_ANNOUNCES_IMMINENT_CLOSURE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   259
static void IndustryDrawTileProc1(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	const DrawIndustrySpec1Struct *d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   264
	if (!(_m[ti->tile].m1 & 0x80)) return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   265
2049
ad0d49c916d4 (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
   266
	d = &_draw_industry_spec1[_m[ti->tile].m3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	AddChildSpriteScreen(0x12A7 + d->image_1, d->x, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   270
	image = d->image_2;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   271
	if (image != 0) AddChildSpriteScreen(0x12B0 + image - 1, 8, 41);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   273
	image = d->image_3;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   274
	if (image != 0) {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   275
		AddChildSpriteScreen(0x12AC + image - 1,
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   276
			_drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   277
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   280
static void IndustryDrawTileProc2(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	int x = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   283
2360
09e42e4ee139 (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
   284
	if (_m[ti->tile].m1 & 0x80) {
2049
ad0d49c916d4 (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
   285
		x = _industry_anim_offs[_m[ti->tile].m3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
		if ( (byte)x == 0xFF)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
			x = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   290
	AddChildSpriteScreen(0x129F, 22 - x, 24 + x);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	AddChildSpriteScreen(0x129E, 6, 0xE);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   294
static void IndustryDrawTileProc3(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
{
2360
09e42e4ee139 (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
   296
	if (_m[ti->tile].m1 & 0x80) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   297
		AddChildSpriteScreen(0x128B, 5, _industry_anim_offs_2[_m[ti->tile].m3]);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   298
	} else {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   299
		AddChildSpriteScreen(4746, 3, 67);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   303
static void IndustryDrawTileProc4(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	const DrawIndustrySpec4Struct *d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
2049
ad0d49c916d4 (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
   307
	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
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	if (d->image_1 != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
		AddChildSpriteScreen(0x126F, 0x32 - d->image_1 * 2, 0x60 + d->image_1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
	if (d->image_2 != 0xFF) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   314
		AddChildSpriteScreen(0x1270, 0x10 - d->image_2 * 2, 100 + d->image_2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	AddChildSpriteScreen(0x126E, 7, d->image_3);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	AddChildSpriteScreen(0x126D, 0, 42);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   321
static void DrawCoalPlantSparkles(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
{
2360
09e42e4ee139 (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
   323
	int image = _m[ti->tile].m1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	if (image & 0x80) {
2140
d708eb80ab8b (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
   325
		image = GB(image, 2, 5);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
		if (image != 0 && image < 7) {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   327
			AddChildSpriteScreen(image + 0x806,
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   328
				_coal_plant_sparkles_x[image - 1],
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   329
				_coal_plant_sparkles_y[image - 1]
0
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   335
typedef void IndustryDrawTileProc(const TileInfo *ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	IndustryDrawTileProc1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
	IndustryDrawTileProc2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	IndustryDrawTileProc3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
	IndustryDrawTileProc4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	DrawCoalPlantSparkles,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
static void DrawTile_Industry(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
   346
	const Industry* ind;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	const DrawIndustryTileStruct *dits;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	uint32 image, ormod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	/* Pointer to industry */
2049
ad0d49c916d4 (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
   352
	ind = GetIndustry(_m[ti->tile].m2);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   353
	ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	/* Retrieve pointer to the draw industry tile struct */
2493
d834d0c1502a (svn r3019) -Codechange: Replace explicit shifting/anding/oring with GB and SB
tron
parents: 2492
diff changeset
   356
	dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	image = dits->sprite_1;
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   359
	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
   360
		image |= ormod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	/* Add bricks below the industry? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	if (ti->tileh & 0xF) {
2535
ed8b9592dc64 (svn r3064) Replace some numbers by sprite names
tron
parents: 2498
diff changeset
   365
		AddSortableSpriteToDraw(SPR_FOUNDATION_BASE + (ti->tileh & 0xF), ti->x, ti->y, 16, 16, 7, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		AddChildSpriteScreen(image, 0x1F, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
		z += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		/* Else draw regular ground */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		DrawGroundSprite(image);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	/* Add industry on top of the ground? */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   374
	image = dits->sprite_2;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   375
	if (image != 0) {
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   376
		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
   377
			image |= ormod;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   378
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   379
		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
   380
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   381
		AddSortableSpriteToDraw(image,
2653
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   382
			ti->x + dits->subtile_x,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   383
			ti->y + dits->subtile_y,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   384
			dits->width  + 1,
4173d9a0a27e (svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents: 2639
diff changeset
   385
			dits->height + 1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
			dits->dz,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
			z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   389
		if (_display_opt & DO_TRANS_BUILDINGS) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   392
	{
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   393
		int proc = dits->proc - 1;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   394
		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
   395
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
2537
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   399
static uint GetSlopeZ_Industry(const TileInfo* ti)
d9c0df52a466 (svn r3066) Constify the parameter of GetSlopeZ_*()
tron
parents: 2535
diff changeset
   400
{
9944
4f027626dbf6 (svn r4014) -Backport from trunk: Slope and height information returned for some tile types is wrong
celestar
parents: 2868
diff changeset
   401
	return ti->z + (ti->tileh == 0 ? 0 : 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   404
static uint GetSlopeTileh_Industry(const TileInfo* ti)
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
   405
{
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   406
	return 0;
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   407
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
   408
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   409
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
{
2049
ad0d49c916d4 (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
   411
	int m5 = _m[tile].m5;
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   412
	CargoID a;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	a = _industry_map5_accepts_1[m5];
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   415
	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
   416
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	a = _industry_map5_accepts_2[m5];
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   418
	if (a != CT_INVALID) ac[a] = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	a = _industry_map5_accepts_3[m5];
2598
574b5774149c (svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents: 2549
diff changeset
   421
	if (a != CT_INVALID) ac[a] = 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   424
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
   426
	const Industry* i = GetIndustry(_m[tile].m2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	td->owner = i->owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
	td->str = STR_4802_COAL_MINE + i->type;
2360
09e42e4ee139 (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
   430
	if ((_m[tile].m1 & 0x80) == 0) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   431
		SetDParamX(td->dparam, 0, td->str);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
		td->str = STR_2058_UNDER_CONSTRUCTION;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   436
static int32 ClearTile_Industry(TileIndex tile, byte flags)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
{
2049
ad0d49c916d4 (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
   438
	Industry *i = GetIndustry(_m[tile].m2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
149
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   440
	/*	* water can destroy industries
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   441
			* in editor you can bulldoze industries
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   442
			* 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
   443
			* (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
   444
	*/
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   445
	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
   446
			!_cheats.magic_bulldozer.value) ||
5f7d4b21df01 (svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents: 131
diff changeset
   447
			(_current_player == OWNER_WATER && i->type == IT_OIL_RIG) ) {
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
   448
 		SetDParam(0, STR_4802_COAL_MINE + i->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
		return_cmd_error(STR_4800_IN_THE_WAY);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   452
	if (flags & DC_EXEC) DeleteIndustry(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	return 0;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
static const byte _industry_min_cargo[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
	5, 5, 5, 30, 5, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	5, 5, 5, 5, 2, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
	5, 5, 5, 15, 15, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	5, 5, 30, 5, 30, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	5, 5, 5, 5, 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   465
static void TransportIndustryGoods(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   467
	Industry* i = GetIndustry(_m[tile].m2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
	uint cw, am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   470
	cw = min(i->cargo_waiting[0], 255);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   471
	if (cw > _industry_min_cargo[i->type]/* && i->produced_cargo[0] != 0xFF*/) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   472
		byte m5;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   473
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
		i->cargo_waiting[0] -= cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
		/* fluctuating economy? */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   477
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
		i->last_mo_production[0] += cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
		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
   482
		i->last_mo_transported[0] += am;
2049
ad0d49c916d4 (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
   483
		if (am != 0 && (m5 = _industry_produce_map5[_m[tile].m5]) != 0xFF) {
2360
09e42e4ee139 (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
   484
			_m[tile].m1 = 0x80;
2049
ad0d49c916d4 (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
   485
			_m[tile].m5 = m5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
		}
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
	cw = min(i->cargo_waiting[1], 255);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   491
	if (cw > _industry_min_cargo[i->type]) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
		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
   493
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   494
		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
   495
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
		i->last_mo_production[1] += cw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
		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
   499
		i->last_mo_transported[1] += am;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
	}
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   504
static void AnimateTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
	byte m,n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
2049
ad0d49c916d4 (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
   508
	switch(_m[tile].m5) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
	case 174:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
		if ((_tick_counter & 1) == 0) {
2049
ad0d49c916d4 (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
   511
			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
   512
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
			switch(m & 7) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   514
			case 2:	SndPlayTileFx(SND_2D_RIP_2, tile); break;
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   515
			case 6: SndPlayTileFx(SND_29_RIP, tile); break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
			}
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
			if (m >= 96) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
			}
2049
ad0d49c916d4 (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
   522
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	case 165:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
		if ((_tick_counter & 3) == 0) {
2049
ad0d49c916d4 (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
   530
			m = _m[tile].m3;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   531
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
			if (_industry_anim_offs[m] == 0xFF) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   533
				SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
			}
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
			if (++m >= 70) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
			}
2049
ad0d49c916d4 (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
   540
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	case 162:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
		if ((_tick_counter&1) == 0) {
2049
ad0d49c916d4 (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
   548
			m = _m[tile].m3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
			if (++m >= 40) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
				m = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
			}
2049
ad0d49c916d4 (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
   554
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
	// Sparks on a coal plant
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	case 10:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
		if ((_tick_counter & 3) == 0) {
2360
09e42e4ee139 (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
   563
			m = _m[tile].m1;
2663
f3e7d6d3e3a1 (svn r3205) Some more uses for GB/SB
tron
parents: 2653
diff changeset
   564
			if (GB(m, 2, 5) == 6) {
f3e7d6d3e3a1 (svn r3205) Some more uses for GB/SB
tron
parents: 2653
diff changeset
   565
				SB(_m[tile].m1, 2, 5, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
			} else {
2360
09e42e4ee139 (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
   568
				_m[tile].m1 = m + (1<<2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
	case 143:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
		if ((_tick_counter & 1) == 0) {
2049
ad0d49c916d4 (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
   576
			m = _m[tile].m3 + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
			if (m == 1) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   579
				SndPlayTileFx(SND_2C_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
			} else if (m == 23) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   581
				SndPlayTileFx(SND_2B_COMEDY_HIT, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
			} else if (m == 28) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   583
				SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
2049
ad0d49c916d4 (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
   586
			if (m >= 50 && (m=0,++_m[tile].m4 >= 8)) {
ad0d49c916d4 (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
				_m[tile].m4 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
				DeleteAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
			}
2049
ad0d49c916d4 (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
   590
			_m[tile].m3 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	case 148: case 149: case 150: case 151:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
	case 152: case 153: case 154: case 155:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		if ((_tick_counter & 3) == 0) {
2049
ad0d49c916d4 (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
   598
			m = _m[tile].m5	+ 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
			if (m == 155+1) m = 148;
2049
ad0d49c916d4 (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
   600
			_m[tile].m5 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
			MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	case 30: case 31: case 32:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
		if ((_tick_counter & 7) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
			bool b = CHANCE16(1,7);
2360
09e42e4ee139 (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
   609
			m = _m[tile].m1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
			m = (m & 3) + 1;
2049
ad0d49c916d4 (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
   611
			n = _m[tile].m5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			if (m == 4 && (m=0,++n) == 32+1 && (n=30,b)) {
2360
09e42e4ee139 (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
   613
				_m[tile].m1 = 0x83;
2049
ad0d49c916d4 (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
   614
				_m[tile].m5 = 29;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   615
				DeleteAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
			} else {
2663
f3e7d6d3e3a1 (svn r3205) Some more uses for GB/SB
tron
parents: 2653
diff changeset
   617
				SB(_m[tile].m1, 0, 2, m);
2049
ad0d49c916d4 (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
   618
				_m[tile].m5 = n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
	case 88:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	case 48:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	case 1: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
			int state = _tick_counter & 0x7FF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
			if ((state -= 0x400) < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
			if (state < 0x1A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
				if (state < 0x20 || state >= 0x180) {
2360
09e42e4ee139 (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
   634
					if (!(_m[tile].m1 & 0x40)) {
09e42e4ee139 (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
						_m[tile].m1 |= 0x40;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   636
						SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
					if (state & 7)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
					if (state & 3)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
						return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
				}
2360
09e42e4ee139 (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
   644
				m = (_m[tile].m1 + 1) | 0x40;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
				if (m > 0xC2) m = 0xC0;
2360
09e42e4ee139 (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
   646
				_m[tile].m1 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
			} else if (state >= 0x200 && state < 0x3A0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
				int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
				i = (state < 0x220 || state >= 0x380) ? 7 : 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
				if (state & i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
2360
09e42e4ee139 (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
   654
				m = (_m[tile].m1 & 0xBF) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
				if (m < 0x80) m = 0x82;
2360
09e42e4ee139 (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
   656
				_m[tile].m1 = m;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
				MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
		} break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
	}
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   663
static void MakeIndustryTileBiggerCase8(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	TileInfo ti;
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   666
	FindLandscapeHeight(&ti, TileX(tile) * 16, TileY(tile) * 16);
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1335
diff changeset
   667
	CreateEffectVehicle(ti.x + 15, ti.y + 14, ti.z + 59 + (ti.tileh != 0 ? 8 : 0), EV_CHIMNEY_SMOKE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   670
static void MakeIndustryTileBigger(TileIndex tile, byte size)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	byte b = (byte)((size + (1<<2)) & (3<<2));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	if (b != 0) {
2360
09e42e4ee139 (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
   675
		_m[tile].m1 = b | (size & 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	size = (size + 1) & 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	if (size == 3) size |= 0x80;
2360
09e42e4ee139 (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
   681
	_m[tile].m1 = size | b;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   682
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
2360
09e42e4ee139 (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
   685
	if (!(_m[tile].m1 & 0x80))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
2049
ad0d49c916d4 (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
   688
	switch(_m[tile].m5) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
	case 8:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
		MakeIndustryTileBiggerCase8(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	case 24:
2049
ad0d49c916d4 (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
   694
		if (_m[tile + TileDiffXY(0, 1)].m5 == 24) BuildOilRig(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	case 143:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	case 162:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
	case 165:
2049
ad0d49c916d4 (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
   700
		_m[tile].m3 = 0;
ad0d49c916d4 (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
   701
		_m[tile].m4 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	case 148: case 149: case 150: case 151:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
	case 152: case 153: case 154: case 155:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
		AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   712
static void TileLoopIndustryCase161(TileIndex tile)
0
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
	int dir;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
	static const int8 _tileloop_ind_case_161[12] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
		11, 0, -4, -14,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
		-4, -10, -4, 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
		49, 59, 60, 65,
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
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   722
	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
   723
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
	dir = Random() & 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	v = CreateEffectVehicleAbove(
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   727
		TileX(tile) * 16 + _tileloop_ind_case_161[dir + 0],
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
   728
		TileY(tile) * 16 + _tileloop_ind_case_161[dir + 4],
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
		_tileloop_ind_case_161[dir + 8],
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1335
diff changeset
   730
		EV_BUBBLE
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   733
	if (v != NULL) v->u.special.unk2 = dir;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   736
static void TileLoop_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
	byte n;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
2360
09e42e4ee139 (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
   740
	if (!(_m[tile].m1 & 0x80)) {
09e42e4ee139 (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
   741
		MakeIndustryTileBigger(tile, _m[tile].m1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   745
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
	TransportIndustryGoods(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
2049
ad0d49c916d4 (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
   749
	n = _industry_map5_animation_next[_m[tile].m5];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
	if (n != 255) {
2360
09e42e4ee139 (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
   751
		_m[tile].m1 = 0;
2049
ad0d49c916d4 (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
   752
		_m[tile].m5 = n;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
		MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
2360
09e42e4ee139 (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
   757
#define SET_AND_ANIMATE(tile, a, b)   { _m[tile].m5 = a; _m[tile].m1 = b; AddAnimatedTile(tile); }
09e42e4ee139 (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
   758
#define SET_AND_UNANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; DeleteAnimatedTile(tile); }
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   760
	switch (_m[tile].m5) {
43
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   761
	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
   762
	case 0x19:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   763
	case 0x1A:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   764
	case 0x1B:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   765
	case 0x1C:
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   766
		TileLoop_Water(tile);
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   767
		break;
3b93861c5478 (svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents: 39
diff changeset
   768
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	case 0:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
		if (!(_tick_counter & 0x400) && CHANCE16(1,2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
			SET_AND_ANIMATE(tile,1,0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	case 47:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
		if (!(_tick_counter & 0x400) && CHANCE16(1,2))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
			SET_AND_ANIMATE(tile,0x30,0x80);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	case 79:
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,0x58,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 29:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
		if (CHANCE16(1,6))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
			SET_AND_ANIMATE(tile,0x1E,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 1:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
		if (!(_tick_counter & 0x400))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
			SET_AND_UNANIMATE(tile, 0, 0x83);
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 48:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
		if (!(_tick_counter & 0x400))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
			SET_AND_UNANIMATE(tile, 0x2F, 0x83);
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 88:
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, 0x4F, 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 10:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		if (CHANCE16(1,3)) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
   806
			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
			AddAnimatedTile(tile);
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
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   811
	case 49:
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1335
diff changeset
   812
		CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   813
		break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
	case 143: {
2049
ad0d49c916d4 (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
   817
			Industry *i = GetIndustry(_m[tile].m2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
			if (i->was_cargo_delivered) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
				i->was_cargo_delivered = false;
2061
f67a12c65223 (svn r2570) Fix: Removed some code that had no effect.
ludde
parents: 2051
diff changeset
   820
				_m[tile].m4 = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
				AddAnimatedTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
		break;
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 161:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
		TileLoopIndustryCase161(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   828
		break;
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   829
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	case 165:
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
		break;
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
	case 174:
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
   835
		if (CHANCE16(1, 3)) AddAnimatedTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   841
static void ClickTile_Industry(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
{
2049
ad0d49c916d4 (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
   843
	ShowIndustryViewWindow(_m[tile].m2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   846
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
0
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
	return 0;
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
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   851
static void GetProducedCargo_Industry(TileIndex tile, byte *b)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
   853
	const Industry* i = GetIndustry(_m[tile].m2);
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
   854
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
	b[0] = i->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	b[1] = i->produced_cargo[1];
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
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2360
diff changeset
   859
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
   860
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
void DeleteIndustry(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
{
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   866
	BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
   867
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
2049
ad0d49c916d4 (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
   868
			if (_m[tile_cur].m2 == i->index) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
				DoClearSquare(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
			}
2049
ad0d49c916d4 (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
   871
		} else if (IsTileType(tile_cur, MP_STATION) && _m[tile_cur].m5 == 0x4B) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
			DeleteOilRig(tile_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
		}
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   874
	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
   875
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	i->xy = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
	_industry_sort_dirty = true;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   878
	DeleteSubsidyWithIndustry(i->index);
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
   879
	DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
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
   884
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   885
static bool IsBadFarmFieldTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   887
	switch (GetTileType(tile)) {
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   888
		case MP_CLEAR: {
2049
ad0d49c916d4 (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
   889
			byte m5 = _m[tile].m5 & 0x1C;
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   890
			return m5 == 0xC || m5 == 0x10;
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   891
		}
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   892
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   893
		case MP_TREES:
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   894
			return false;
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   895
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   896
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
			return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   901
static bool IsBadFarmFieldTile2(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1209
diff changeset
   903
	switch (GetTileType(tile)) {
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   904
		case MP_CLEAR: {
2049
ad0d49c916d4 (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
   905
			byte m5 = _m[tile].m5 & 0x1C;
1048
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   906
			return m5 == 0x10;
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   907
		}
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   908
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   909
		case MP_TREES:
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   910
			return false;
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   911
edfc783f241d (svn r1549) Clean up some functions:
tron
parents: 1035
diff changeset
   912
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
			return true;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   917
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, int direction)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	byte or, and;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
		tile = TILE_MASK(tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   923
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
   924
		if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   925
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
			or = type;
2637
8807e6a63f89 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2630
diff changeset
   927
			if (or == 1 && CHANCE16(1, 7)) or = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
			or <<= 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
			and = (byte)~0x1C;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
			if (direction) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
				or <<= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
				and = (byte)~0xE0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
			}
2049
ad0d49c916d4 (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
   935
			_m[tile].m4 = (_m[tile].m4 & and) | or;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   937
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   938
		tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	} while (--size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   942
static void PlantFarmField(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	uint size_x, size_y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
	uint32 r;
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   946
	uint count;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	int type, type2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
	if (_opt.landscape == LT_HILLY) {
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1320
diff changeset
   950
		if (GetTileZ(tile) + 16 >= _opt.snow_line)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	}
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
	/* determine field size */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
	r = (Random() & 0x303) + 0x404;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	if (_opt.landscape == LT_HILLY) r += 0x404;
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   957
	size_x = GB(r, 0, 8);
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   958
	size_y = GB(r, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	/* offset tile to match size */
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   961
	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
   962
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	/* check the amount of bad tiles */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
	count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
	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
   966
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
		count += IsBadFarmFieldTile(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 2085
diff changeset
   969
	if (count * 2 >= size_x * size_y) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	/* determine type of field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
	r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
	type = ((r & 0xE0) | 0xF);
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2148
diff changeset
   974
	type2 = GB(r, 8, 8) * 9 >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	/* make field */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	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
   978
		cur_tile = TILE_MASK(cur_tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		if (!IsBadFarmFieldTile2(cur_tile)) {
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   980
			ModifyTile(cur_tile,
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
   981
				MP_SETTYPE(MP_CLEAR) |
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
				MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
				type2,			/* map3_lo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
				OWNER_NONE,	/* map_owner */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
				type);			/* map5 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
	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
   988
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
	type = 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
	if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
		type = _plantfarmfield_type[Random() & 0xF];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   994
	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, 1);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   995
	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, 0);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   996
	SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, 1);
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   997
	SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
  1000
static void MaybePlantFarmField(const Industry* i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1002
	if (CHANCE16(1, 8)) {
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1003
		int x = i->width  / 2 + Random() % 31 - 16;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1004
		int y = i->height / 2 + Random() % 31 - 16;
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1005
		TileIndex tile = TileAddWrap(i->xy, x, y);
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1006
		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
  1007
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
static void ChopLumberMillTrees(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
{
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1012
	static const TileIndexDiffC _chop_dir[] = {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1013
		{ 0,  1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1014
		{ 1,  0},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1015
		{ 0, -1},
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1016
		{-1,  0}
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1017
	};
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1018
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1019
	TileIndex tile = i->xy;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1020
	int a;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1022
	if ((_m[tile].m1 & 0x80) == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
	/* search outwards as a rectangular spiral */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1025
	for (a = 1; a != 41; a += 2) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1026
		uint dir;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1027
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1028
		for (dir = 0; dir != 4; dir++) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1029
			int j = a;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1030
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
			do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
				tile = TILE_MASK(tile);
1035
0a170deb6e33 (svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents: 1019
diff changeset
  1033
				if (IsTileType(tile, MP_TREES)) {
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1034
					PlayerID old_player = _current_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
					/* found a tree */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
					_current_player = OWNER_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
					_industry_sound_ctr = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
					_industry_sound_tile = tile;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1040
					SndPlayTileFx(SND_38_CHAINSAW, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
					DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
					SetMapExtraBits(tile, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1045
					i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45);
314
a71488713a05 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 267
diff changeset
  1046
a71488713a05 (svn r320) -Fix: some last _current_player fixes
truelight
parents: 267
diff changeset
  1047
					_current_player = old_player;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
					return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
				}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1050
				tile += ToTileIndexDiff(_chop_dir[dir]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
			} while (--j);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
		}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1053
		tile -= TileDiffXY(1, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
static const byte _industry_sounds[37][2] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1060
	{1, SND_28_SAWMILL},
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},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1064
	{1, SND_03_FACTORY_WHISTLE},
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1065
	{1, SND_03_FACTORY_WHISTLE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1067
	{3, SND_24_SHEEP},
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
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1072
	{1, SND_28_SAWMILL},
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
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1081
	{1, SND_03_FACTORY_WHISTLE},
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
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	{0},
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1090
	{1, SND_33_PLASTIC_MINE},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	{0},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
static void ProduceIndustryGoods(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
	uint num;
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
	/* play a sound? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
	if ((i->counter & 0x3F) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
		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
  1106
			SndPlayTileFx(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
				_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
				i->xy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	i->counter--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	/* produce some cargo */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	if ((i->counter & 0xFF) == 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
		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
  1117
		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
  1118
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1119
		if (i->type == IT_FARM) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
			MaybePlantFarmField(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1121
		} 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
  1122
			ChopLumberMillTrees(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1123
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1127
void OnTick_Industry(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
	Industry *i;
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
	if (_industry_sound_ctr != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
		_industry_sound_ctr++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
		if (_industry_sound_ctr == 75) {
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1135
			SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
		} 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
  1137
			_industry_sound_ctr = 0;
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
  1138
			SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1142
	if (_game_mode == GM_EDITOR) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1144
	FOR_ALL_INDUSTRIES(i) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1145
		if (i->xy != 0) ProduceIndustryGoods(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
	}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1150
static bool CheckNewIndustry_NULL(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	return true;
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1155
static bool CheckNewIndustry_Forest(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1157
	if (_opt.landscape == LT_HILLY) {
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1320
diff changeset
  1158
		if (GetTileZ(tile) < _opt.snow_line + 16U) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
7
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1166
extern bool _ignore_restrictions;
f2e623faa778 (svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents: 0
diff changeset
  1167
1586
d2d8ceccd935 (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
  1168
/* Oil Rig and Oil Refinery */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1169
static bool CheckNewIndustry_Oil(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1171
	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1172
	if (_game_mode == GM_EDITOR && type != IT_OIL_RIG)   return true;
2868
abf76c8376cf (svn r3416) - Fix: Disallow building an oil rig above sea level.
peter1138
parents: 2817
diff changeset
  1173
	if ((type != IT_OIL_RIG || TileHeight(tile) == 0) &&
abf76c8376cf (svn r3416) - Fix: Disallow building an oil rig above sea level.
peter1138
parents: 2817
diff changeset
  1174
			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
  1175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
	return false;
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1180
static bool CheckNewIndustry_Farm(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
	if (_opt.landscape == LT_HILLY) {
1335
a635854c23b6 (svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents: 1320
diff changeset
  1183
		if (GetTileZ(tile) + 16 >= _opt.snow_line) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
			_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1186
		}
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
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1191
static bool CheckNewIndustry_Plantation(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
	if (GetMapExtraBits(tile) == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	}
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
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1201
static bool CheckNewIndustry_Water(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
	if (GetMapExtraBits(tile) != 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
		_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
  1205
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
	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
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1211
static bool CheckNewIndustry_Lumbermill(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
	if (GetMapExtraBits(tile) != 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
		_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
  1215
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1220
static bool CheckNewIndustry_BubbleGen(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1222
	return GetTileZ(tile) <= 32;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1225
typedef bool CheckNewIndustryProc(TileIndex tile, int type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
static CheckNewIndustryProc * const _check_new_industry_procs[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
	CheckNewIndustry_NULL,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	CheckNewIndustry_Forest,
1586
d2d8ceccd935 (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
  1229
	CheckNewIndustry_Oil,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	CheckNewIndustry_Farm,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	CheckNewIndustry_Plantation,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
	CheckNewIndustry_Water,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
	CheckNewIndustry_Lumbermill,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	CheckNewIndustry_BubbleGen,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1235
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1237
static bool CheckSuitableIndustryPos(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
{
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1239
	uint x = TileX(tile);
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1240
	uint y = TileY(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1242
	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
  1243
		_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
		return false;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1250
static const Town* CheckMultipleIndustryInTown(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1252
	const Town* t;
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1253
	const Industry* i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	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
  1256
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1257
	if (_patches.multiple_industry_per_town) return t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1259
	FOR_ALL_INDUSTRIES(i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
		if (i->xy != 0 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
				i->type == (byte)type &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
				i->town == t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
			return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
	return t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
static const byte _industry_map5_bits[] = {
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, 16, 16, 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, 4, 2, 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, 4, 2, 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, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
	16, 16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
	16, 16, 16, 16, 16, 16, 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1296
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
  1297
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	_error_message = STR_0239_SITE_UNSUITABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
	do {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1303
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1304
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
		if (!IsValidTile(cur_tile)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1306
			if (it->map5 == 0xff) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
		}
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1309
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
		FindLandscapeHeightByTile(&ti, cur_tile);
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1311
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
		if (it->map5 == 0xFF) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1313
			if (ti.type != MP_WATER || ti.tileh != 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
		} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1315
			if (!EnsureNoVehicle(cur_tile)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
			if (type == IT_OIL_RIG)  {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1318
				if (ti.type != MP_WATER || ti.map5 != 0) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
			} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1320
				if (ti.type == MP_WATER && ti.map5 == 0) return false;
2085
ae9e92ffe168 (svn r2595) -Codechange: Introduced "IsSteepTileh" to find whether a tile is steep
celestar
parents: 2072
diff changeset
  1321
				if (IsSteepTileh(ti.tileh))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
					return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
				if (ti.tileh != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
					int t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
					byte bits = _industry_map5_bits[it->map5];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1328
					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
  1329
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
					t = ~ti.tileh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1332
					if (bits & 1 && (t & (1 + 8))) return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1333
					if (bits & 2 && (t & (4 + 8))) return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1334
					if (bits & 4 && (t & (1 + 2))) return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1335
					if (bits & 8 && (t & (2 + 4))) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
				if (type == IT_BANK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
					if (ti.type != MP_HOUSE || t->population < 1200) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
						_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
  1341
						return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
				} else if (type == IT_BANK_2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
					if (ti.type != MP_HOUSE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
						_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
  1346
						return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
					}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
				} else if (type == IT_TOY_SHOP) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1349
					if (DistanceMax(t->xy, cur_tile) > 9) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
					if (ti.type != MP_HOUSE) goto do_clear;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
				} else if (type == IT_WATER_TOWER) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
					if (ti.type != MP_HOUSE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
						_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
  1354
						return false;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1355
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
do_clear:
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2663
diff changeset
  1358
					if (CmdFailed(DoCommandByTile(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
  1359
						return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
		}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1363
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1368
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1370
	const IndustrySpec* spec = &_industry_spec[type];
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2537
diff changeset
  1371
	const Industry* i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
	// accepting industries won't be close, not even with patch
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1374
	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
  1375
		return true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1376
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1377
	FOR_ALL_INDUSTRIES(i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
		// 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
  1379
		if (i->xy != 0 &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1380
				DistanceMax(tile, i->xy) <= 14 &&
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1381
				spec->accepts_cargo[0] != CT_INVALID &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1382
				spec->accepts_cargo[0] == i->accepts_cargo[0] && (
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1383
					_game_mode != GM_EDITOR ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1384
					!_patches.same_industry_close ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1385
					!_patches.multiple_industry_per_town
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1386
				)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1387
			_error_message = STR_INDUSTRY_TOO_CLOSE;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1388
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1389
		}
0
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
		// check "not close to" field.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		if (i->xy != 0 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
				(i->type == spec->a || i->type == spec->b || i->type == spec->c) &&
1245
768d9bc95aaa (svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents: 1214
diff changeset
  1394
				DistanceMax(tile, i->xy) <= 14) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
			_error_message = STR_INDUSTRY_TOO_CLOSE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
			return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1402
static Industry *AllocateIndustry(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1406
	FOR_ALL_INDUSTRIES(i) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
		if (i->xy == 0) {
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1408
			uint index = i->index;
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1409
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1410
			if (i->index > _total_industries) _total_industries = i->index;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1411
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1412
			memset(i, 0, sizeof(*i));
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1413
			i->index = index;
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1414
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
			return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	}
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1418
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1419
	/* Check if we can add a block to the pool */
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2548
diff changeset
  1420
	return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL;
0
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
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1423
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
  1424
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
	const IndustrySpec *spec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
	uint32 r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
	i->xy = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
	i->width = i->height = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
	i->type = type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
	spec = &_industry_spec[type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
	i->produced_cargo[0] = spec->produced_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
	i->produced_cargo[1] = spec->produced_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
	i->accepts_cargo[0] = spec->accepts_cargo[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
	i->accepts_cargo[1] = spec->accepts_cargo[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	i->accepts_cargo[2] = spec->accepts_cargo[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
	i->production_rate[0] = spec->production_rate[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
	i->production_rate[1] = spec->production_rate[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
	if (_patches.smooth_economy) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
		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
  1445
		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
  1446
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
	i->town = t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
	i->owner = owner;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2469
diff changeset
  1451
	r = Random();
2492
3f32f9f9fd78 (svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents: 2484
diff changeset
  1452
	i->color_map = GB(r, 8, 4);
3f32f9f9fd78 (svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents: 2484
diff changeset
  1453
	i->counter = GB(r, 0, 12);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
	i->cargo_waiting[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
	i->cargo_waiting[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
	i->last_mo_production[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
	i->last_mo_production[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
	i->last_mo_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
	i->last_mo_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	i->pct_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
	i->pct_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
	i->total_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	i->total_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
	i->was_cargo_delivered = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
	i->last_prod_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	i->total_production[0] = i->production_rate[0] * 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
	i->total_production[1] = i->production_rate[1] * 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1469
	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
  1470
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
	i->prod_level = 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
	do {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1474
		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
		if (it->map5 != 0xFF) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
			byte size;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1479
			size = it->ti.x;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
			if (size > i->width) i->width = size;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1481
			size = it->ti.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
			if (size > i->height)i->height = size;
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
			DoCommandByTile(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1048
diff changeset
  1486
			SetTileType(cur_tile, MP_INDUSTRY);
2049
ad0d49c916d4 (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
  1487
			_m[cur_tile].m5 = it->map5;
ad0d49c916d4 (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
  1488
			_m[cur_tile].m2 = i->index;
2360
09e42e4ee139 (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
  1489
			_m[cur_tile].m1 = _generating_world ? 0x1E : 0; /* maturity */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
		}
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
  1491
	} while ((++it)->ti.x != -0x80);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
	i->width++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	i->height++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
	if (i->type == IT_FARM || i->type == IT_FARM_2) {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1497
		tile = i->xy + TileDiffXY(i->width / 2, i->height / 2);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1498
		for (j = 0; j != 50; j++) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1499
			int x = Random() % 31 - 16;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 541
diff changeset
  1500
			int y = Random() % 31 - 16;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1501
			TileIndex new_tile = TileAddWrap(tile, x, y);
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1502
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1503
			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
  1504
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1510
/** Build/Fund an industry
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1511
 * @param x,y coordinates where industry is built
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1512
 * @param p1 industry type @see build_industry.h and @see industry.h
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1513
 * @param p2 unused
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1514
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1517
	const Town* t;
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1518
	Industry *i;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1519
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
	int num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
	const IndustryTileTable * const *itt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
	const IndustryTileTable *it;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
	const IndustrySpec *spec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1527
	if (!CheckSuitableIndustryPos(tile)) return CMD_ERROR;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1528
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1529
	/* Check if the to-be built/founded industry is available for this climate.
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1530
	 * Unfortunately we have no easy way of checking, except for looping the table */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1531
	{
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1532
		const byte* i;
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1533
		bool found = false;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1534
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1535
		for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1536
			if (*i == p1) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1537
				found = true;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1538
				break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1539
			}
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1540
		}
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1541
		if (!found) return CMD_ERROR;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1542
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
	spec = &_industry_spec[p1];
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1545
	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
1800
39966454c434 (svn r2304) - Fix (regression): excuse the Lumber mill from the list of raw-industries build-restriction, as it can be built always, patch-setting, or no patch-setting.
Darkvater
parents: 1786
diff changeset
  1546
	 * Raw material industries are industries that do not accept cargo (at least for now)
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1547
	 * Exclude the lumber mill (only "raw" industry that can be built) */
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1548
	if (!_patches.build_rawmaterial_ind &&
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1549
			spec->accepts_cargo[0] == CT_INVALID &&
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1550
			spec->accepts_cargo[1] == CT_INVALID &&
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1551
			spec->accepts_cargo[2] == CT_INVALID &&
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1552
			p1 != IT_LUMBER_MILL) {
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1553
		return CMD_ERROR;
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1554
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1556
	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
  1557
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1558
	t = CheckMultipleIndustryInTown(tile, p1);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1559
	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
  1560
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
	num = spec->num_table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
	itt = spec->table;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
	do {
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1565
		if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1566
	} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1, t));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1603
diff changeset
  1569
	if (!CheckIfTooCloseToIndustry(tile, p1)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1571
	i = AllocateIndustry();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1572
	if (i == NULL) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1574
	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
  1575
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
	return (_price.build_industry >> 5) * _industry_type_costs[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
  1580
Industry *CreateNewIndustry(TileIndex tile, int type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
{
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2598
diff changeset
  1582
	const Town* t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
	const IndustryTileTable *it;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
	const IndustrySpec *spec;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1588
	if (!CheckSuitableIndustryPos(tile)) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1590
	spec = &_industry_spec[type];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1591
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1592
	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
  1593
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1594
	t = CheckMultipleIndustryInTown(tile, type);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1595
	if (t == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
	/* pick a random layout */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1598
	it = spec->table[RandomRange(spec->num_table)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1600
	if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) return NULL;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1601
	if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1603
	i = AllocateIndustry();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1604
	if (i == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1606
	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
  1607
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
	return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1611
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
  1612
	{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
  1613
	{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
  1614
	{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
  1615
	{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
  1616
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
static void PlaceInitialIndustry(byte type, int amount)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
{
2072
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1620
	int num = _numof_industry_table[_opt.diff.number_industries][amount];
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1621
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1622
	if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) {
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1623
		// These are always placed next to the coastline, so we scale by the perimeter instead.
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1624
		num = ScaleByMapSize1D(num);
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1625
	} else {
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1626
		num = ScaleByMapSize(num);
c7961c4a74ac (svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents: 2070
diff changeset
  1627
	}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1628
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1629
	if (_opt.diff.number_industries != 0) {
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1630
		PlayerID old_player = _current_player;
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1631
		_current_player = OWNER_NONE;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1632
		assert(num > 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
		do {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1635
			uint i;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1636
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1637
			for (i = 0; i < 2000; i++) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1638
				if (CreateNewIndustry(RandomTile(), type) != NULL) break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1639
			}
110
a22a6b07904b (svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents: 61
diff changeset
  1640
		} while (--num);
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1641
267
dc6103ea959d (svn r273) -Fix: sorry, wrongly fixed
darkvater
parents: 266
diff changeset
  1642
		_current_player = old_player;
61
cd2827156f2a (svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents: 43
diff changeset
  1643
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1646
void GenerateIndustries(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
	const byte *b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
	b = _industry_create_table[_opt.landscape];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
		PlaceInitialIndustry(b[1], b[0]);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
	} while ( (b+=2)[0] != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1654
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
static void ExtChangeIndustryProduction(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
{
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1658
	bool closeit = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1661
	switch (_industry_close_mode[i->type]) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1662
		case INDUSTRY_NOT_CLOSABLE:
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1663
			return;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1664
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1665
		case INDUSTRY_CLOSABLE:
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1666
			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
  1667
				closeit = false;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1668
			break;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1669
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1670
		default: /* INDUSTRY_PRODUCTION */
2638
0c9b00251fce (svn r3180) Replace some magic numbers by symbolic names
tron
parents: 2637
diff changeset
  1671
			for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1672
				uint32 r = Random();
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1673
				int old, new, percent;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1674
				int mag;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1675
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1676
				new = old = i->production_rate[j];
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1677
				if (CHANCE16I(20, 1024, r))
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1678
					new -= ((RandomRange(50) + 10) * old) >> 8;
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1679
				if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16))
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1680
					new += ((RandomRange(50) + 10) * old) >> 8;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1681
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1682
				new = clamp(new, 0, 255);
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1683
				if (new == old) {
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1684
					closeit = false;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1685
					continue;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1686
				}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1687
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1688
				percent = new * 100 / old - 100;
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1689
				i->production_rate[j] = new;
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1690
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1691
				if (new >= _industry_spec[i->type].production_rate[j] / 4)
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1692
					closeit = false;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1693
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1694
				mag = abs(percent);
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1695
				if (mag >= 10) {
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1696
					SetDParam(2, mag);
1603
e67485272abc (svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents: 1586
diff changeset
  1697
					SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]);
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1698
					SetDParam(1, i->index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1699
					AddNewsItem(
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1700
						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1701
						NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1702
						i->xy + TileDiffXY(1, 1), 0
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1703
					);
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1704
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1705
			}
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1706
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
	if (closeit) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1710
		i->prod_level = 0;
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1711
		SetDParam(0, i->index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1712
		AddNewsItem(
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1713
			_industry_close_strings[i->type],
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1714
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1715
			i->xy + TileDiffXY(1, 1), 0
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1716
		);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1719
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1720
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1721
static void UpdateIndustryStatistics(Industry *i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
	byte pct;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1724
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1725
	if (i->produced_cargo[0] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
		pct = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
		if (i->last_mo_production[0] != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
			i->last_prod_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
			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
  1730
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
		i->pct_transported[0] = pct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
		i->total_production[0] = i->last_mo_production[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
		i->last_mo_production[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
		i->total_transported[0] = i->last_mo_transported[0];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
		i->last_mo_transported[0] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1740
	if (i->produced_cargo[1] != CT_INVALID) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
		pct = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
		if (i->last_mo_production[1] != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
			i->last_prod_year = _cur_year;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
			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
  1745
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
		i->pct_transported[1] = pct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
		i->total_production[1] = i->last_mo_production[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
		i->last_mo_production[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
		i->total_transported[1] = i->last_mo_transported[1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
		i->last_mo_transported[1] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
2469
1bfbb0dc0b75 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2436
diff changeset
  1756
	if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID)
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1757
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1758
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1759
	if (i->prod_level == 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
		DeleteIndustry(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1761
	} else if (_patches.smooth_economy) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
		ExtChangeIndustryProduction(i);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1763
	}
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
static const byte _new_industry_rand[4][32] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
	{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
  1768
	{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
  1769
	{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
  1770
	{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
  1771
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
static void MaybeNewIndustry(uint32 r)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
	int type;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
	Industry *i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
2140
d708eb80ab8b (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
  1779
	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
  1780
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1781
	if (type == IT_OIL_WELL && _date > 10958) return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1782
	if (type == IT_OIL_RIG  && _date < 14610) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
	j = 2000;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1785
	for (;;) {
2637
8807e6a63f89 (svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents: 2630
diff changeset
  1786
		i = CreateNewIndustry(RandomTile(), type);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1787
		if (i != NULL) break;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1788
		if (--j == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1790
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1791
	SetDParam(0, type + STR_4802_COAL_MINE);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1792
	SetDParam(1, i->town->index);
2260
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1793
	AddNewsItem(
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1794
		(type != IT_FOREST) ?
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1795
			STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR,
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1796
		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0
3e97367f7cbc (svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents: 2187
diff changeset
  1797
	);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1799
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1800
static void ChangeIndustryProduction(Industry *i)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1801
{
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1802
	bool only_decrease = false;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1803
	StringID str = STR_NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
	int type = i->type;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1805
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1806
	switch (_industry_close_mode[type]) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1807
		case INDUSTRY_NOT_CLOSABLE:
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1808
			return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1810
		case INDUSTRY_PRODUCTION:
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1811
			/* decrease or increase */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1812
			if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL)
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1813
				only_decrease = true;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1814
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1815
			if (only_decrease || CHANCE16(1,3)) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1816
				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1817
				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1818
					/* Increase production */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1819
					if (i->prod_level != 0x80) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1820
						byte b;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 159
diff changeset
  1821
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1822
						i->prod_level <<= 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1823
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1824
						b = i->production_rate[0] * 2;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1825
						if (i->production_rate[0] >= 128)
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1826
							b = 0xFF;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1827
						i->production_rate[0] = b;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1828
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1829
						b = i->production_rate[1] * 2;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1830
						if (i->production_rate[1] >= 128)
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1831
							b = 0xFF;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1832
						i->production_rate[1] = b;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1833
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1834
						str = _industry_prod_up_strings[type];
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1835
					}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1836
				} else {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1837
					/* Decrease production */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1838
					if (i->prod_level == 4) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1839
						i->prod_level = 0;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1840
						str = _industry_close_strings[type];
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1841
					} else {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1842
						i->prod_level >>= 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1843
						i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1844
						i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1845
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1846
						str = _industry_prod_down_strings[type];
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1847
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1848
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
			}
1320
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1850
			break;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1851
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1852
		case INDUSTRY_CLOSABLE:
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1853
			/* maybe close */
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1854
			if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1855
				i->prod_level = 0;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1856
				str = _industry_close_strings[type];
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1857
			}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1858
			break;
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1859
	}
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1860
bf9623526d71 (svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents: 1287
diff changeset
  1861
	if (str != STR_NULL) {
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2061
diff changeset
  1862
		SetDParam(0, i->index);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
  1863
		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
  1864
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1867
void IndustryMonthlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1869
	Industry *i;
2498
befad2fe53d2 (svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents: 2493
diff changeset
  1870
	PlayerID old_player = _current_player;
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1871
	_current_player = OWNER_NONE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1873
	FOR_ALL_INDUSTRIES(i) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1874
		if (i->xy != 0) UpdateIndustryStatistics(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1877
	/* 3% chance that we start a new industry */
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1878
	if (CHANCE16(3, 100)) {
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1879
		MaybeNewIndustry(Random());
1269
80a25996584f (svn r1773) -Fix: [ 1114950 ] Game crashed sometimes when there were no industries
truelight
parents: 1267
diff changeset
  1880
	} else if (!_patches.smooth_economy && _total_industries > 0) {
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1881
		i = GetIndustry(RandomRange(_total_industries));
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1882
		if (i->xy != 0) ChangeIndustryProduction(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
	}
266
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1884
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1885
	_current_player = old_player;
d704fabab036 (svn r272) -Fix: industries are once again generated on a new map
darkvater
parents: 201
diff changeset
  1886
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1887
	// production-change
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1889
	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1893
void InitializeIndustries(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
{
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1895
	CleanPool(&_industry_pool);
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1896
	AddBlockToPool(&_industry_pool);
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1897
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
	_total_industries = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
	_industry_sort_dirty = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
const TileTypeProcs _tile_type_industry_procs = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
	DrawTile_Industry,					/* draw_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	GetSlopeZ_Industry,					/* get_slope_z_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
	ClearTile_Industry,					/* clear_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
	GetAcceptedCargo_Industry,	/* get_accepted_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
	GetTileDesc_Industry,				/* get_tile_desc_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
	GetTileTrackStatus_Industry,/* get_tile_track_status_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
	ClickTile_Industry,					/* click_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
	AnimateTile_Industry,				/* animate_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
	TileLoop_Industry,					/* tile_loop_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
	ChangeTileOwner_Industry,		/* change_tile_owner_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
	GetProducedCargo_Industry,  /* get_produced_cargo_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
	NULL,												/* vehicle_enter_tile_proc */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
	NULL,												/* vehicle_leave_tile_proc */
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 7
diff changeset
  1916
	GetSlopeTileh_Industry,			/* get_slope_tileh_proc */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1800
diff changeset
  1919
static const SaveLoad _industry_desc[] = {
1174
27e386195965 (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
  1920
	SLE_CONDVAR(Industry, xy,					SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
27e386195965 (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
  1921
	SLE_CONDVAR(Industry, xy,					SLE_UINT32, 6, 255),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
	SLE_VAR(Industry,width,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	SLE_VAR(Industry,height,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
	SLE_REF(Industry,town,						REF_TOWN),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	SLE_ARR(Industry,produced_cargo,  SLE_UINT8, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
	SLE_ARR(Industry,cargo_waiting,   SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	SLE_ARR(Industry,production_rate, SLE_UINT8, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	SLE_ARR(Industry,accepts_cargo,		SLE_UINT8, 3),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
	SLE_VAR(Industry,prod_level,			SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	SLE_ARR(Industry,last_mo_production,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	SLE_ARR(Industry,last_mo_transported,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	SLE_ARR(Industry,pct_transported,SLE_UINT8, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
	SLE_ARR(Industry,total_production,SLE_UINT16, 2),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
	SLE_ARR(Industry,total_transported,SLE_UINT16, 2),
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
	SLE_VAR(Industry,counter,					SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
	SLE_VAR(Industry,type,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
	SLE_VAR(Industry,owner,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
	SLE_VAR(Industry,color_map,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
	SLE_VAR(Industry,last_prod_year,	SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
	SLE_VAR(Industry,was_cargo_delivered,SLE_UINT8),
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
	// reserve extra space in savegame here. (currently 32 bytes)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
	SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 4, 2, 255),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1950
static void Save_INDY(void)
0
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
	Industry *ind;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1953
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
	// Write the vehicles
830
8114845804c9 (svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents: 817
diff changeset
  1955
	FOR_ALL_INDUSTRIES(ind) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1956
		if (ind->xy != 0) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1957
			SlSetArrayIndex(ind->index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
			SlObject(ind, _industry_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1959
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1961
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
  1963
static void Load_INDY(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1965
	int index;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1966
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
	_total_industries = 0;
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1968
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
	while ((index = SlIterateArray()) != -1) {
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1970
		Industry *i;
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1971
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1972
		if (!AddBlockIfNeeded(&_industry_pool, index))
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1973
			error("Industries: failed loading savegame: too many industries");
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1974
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1975
		i = GetIndustry(index);
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 909
diff changeset
  1976
		SlObject(i, _industry_desc);
1267
cbd68e5e31ac (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1247
diff changeset
  1977
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2638
diff changeset
  1978
		if (index > _total_industries) _total_industries = index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
const ChunkHandler _industry_chunk_handlers[] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
	{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
};