industry.h
author bjarni
Tue, 05 Dec 2006 22:40:42 +0000
changeset 5255 b693a9941b8c
parent 5247 1f982de55b88
child 5298 46eabcb5c2b2
permissions -rw-r--r--
(svn r7385) -Fix: FS#418 Deleting Train in depot with autoreplace failes
This turned out to be due to continue to drag the old vehicle, that autoreplace sold
This could also be triggered if more than one player used the same company
Now deleting a vehicle will remove all depot highlights of that vehicle
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1330
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 1330
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#ifndef INDUSTRY_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
#define INDUSTRY_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4976
diff changeset
     6
#include "oldpool.h"
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
     7
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
     8
typedef byte IndustryGfx;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
     9
typedef uint8 IndustryType;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    10
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    11
enum {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    12
	INVALID_INDUSTRY = 0xFFFF,
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    13
};
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
    14
4924
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    15
typedef enum IndustryLifeTypes {
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    16
	INDUSTRYLIFE_NOT_CLOSABLE,     ///< Industry can never close
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    17
	INDUSTRYLIFE_PRODUCTION,       ///< Industry can close and change of production
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    18
	INDUSTRYLIFE_CLOSABLE,         ///< Industry can only close (no production change)
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    19
} IndustryLifeType;
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    20
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
struct Industry {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	TileIndex xy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	byte width; /* swapped order of w/h with town */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	byte height;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2436
diff changeset
    25
	const Town* town;
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2630
diff changeset
    26
	CargoID produced_cargo[2];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	uint16 cargo_waiting[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	byte production_rate[2];
3344
fc86351d4641 (svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents: 2630
diff changeset
    29
	CargoID accepts_cargo[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	byte prod_level;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	uint16 last_mo_production[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	uint16 last_mo_transported[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	byte pct_transported[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	uint16 total_production[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	uint16 total_transported[2];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	uint16 counter;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	byte type;
3350
dd1ae4d6b5d6 (svn r4134) Revert part of r4133: Replacing a byte which gets written to savegames by an enum is a very bad idea
tron
parents: 3349
diff changeset
    39
	byte owner;
4942
7fb6c39eb421 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
    40
	byte random_color;
4326
2e2c9d21ed96 (svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents: 4277
diff changeset
    41
	Year last_prod_year;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	byte was_cargo_delivered;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
    43
4330
cf31daa8b321 (svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents: 4328
diff changeset
    44
	IndustryID index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    47
typedef struct IndustryTileTable {
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    48
	TileIndexDiffC ti;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    49
	IndustryGfx gfx;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    50
} IndustryTileTable;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    51
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    52
typedef struct IndustrySpec {
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    53
	/** Tables with the 'layout' of different composition of GFXes */
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    54
	const IndustryTileTable *const *table;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    55
	/** Number of elements in the table */
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    56
	byte num_table;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    57
	/** Base cost multiplier*/
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    58
	byte cost_multiplier;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    59
	/** Industries this industry cannot be close to */
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    60
	IndustryType conflicting[3];
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    61
	/** index to a procedure to check for conflicting circumstances */
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    62
	byte check_proc;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    63
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    64
	CargoID produced_cargo[2];
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    65
	byte production_rate[2];
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    66
	/** The minimum amount of cargo transported to the stations; if the
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    67
	 * waiting cargo is less than this number, no cargo is moved to it*/
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    68
	byte minimal_cargo;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    69
	CargoID accepts_cargo[3];
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    70
4966
9486538c344d (svn r6966) -Fix(6965): Little typo while making the comment doxygen friendly
belugas
parents: 4965
diff changeset
    71
	IndustryLifeType life_type;  ///< This is also known as Industry production flag, in newgrf specs
4965
a09db997a1f3 (svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents: 4942
diff changeset
    72
4966
9486538c344d (svn r6966) -Fix(6965): Little typo while making the comment doxygen friendly
belugas
parents: 4965
diff changeset
    73
	byte climate_availability;  ///< Bitmask, giving landscape enums as bit position
4924
b6fa01b5a80d (svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents: 4403
diff changeset
    74
4942
7fb6c39eb421 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4924
diff changeset
    75
	StringID name;
3689
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    76
	StringID closure_text;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    77
	StringID production_up_text;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    78
	StringID production_down_text;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    79
} IndustrySpec;
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    80
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    81
const IndustrySpec *GetIndustrySpec(IndustryType thistype);
50a3fd4ba752 (svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents: 3499
diff changeset
    82
5216
8bd14ee39af2 (svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents: 4976
diff changeset
    83
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
    84
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
    85
/**
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
    86
 * Check if an Industry really exists.
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
    87
 */
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    88
static inline bool IsValidIndustry(const Industry *industry)
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
    89
{
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
    90
	return industry->xy != 0;
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
    91
}
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1267
diff changeset
    92
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
    93
VARDEF int _total_industries;
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
    94
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
    95
static inline IndustryID GetMaxIndustryIndex(void)
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
    96
{
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
    97
	/* TODO - This isn't the real content of the function, but
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
    98
	 *  with the new pool-system this will be replaced with one that
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
    99
	 *  _really_ returns the highest index. Now it just returns
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   100
	 *  the next safe value we are sure about everything is below.
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   101
	 */
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   102
	return _total_industries - 1;
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   103
}
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   104
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   105
static inline uint GetNumIndustries(void)
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   106
{
4357
aaba385fa723 (svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents: 4356
diff changeset
   107
	return _total_industries;
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   108
}
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4346
diff changeset
   109
4356
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   110
/**
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   111
 * Return a random valid town.
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   112
 */
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   113
static inline Industry *GetRandomIndustry(void)
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   114
{
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   115
	uint num = RandomRange(GetNumIndustries());
4356
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   116
	uint index = 0;
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   117
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   118
	if (GetNumIndustries() == 0) return NULL;
4356
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   119
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   120
	while (num > 0) {
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   121
		num--;
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   122
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   123
		index++;
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   124
		/* Make sure we have a valid industry */
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   125
		while (GetIndustry(index) == NULL) {
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   126
			index++;
5247
1f982de55b88 (svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents: 5216
diff changeset
   127
			if (index > GetMaxIndustryIndex()) index = 0;
4356
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   128
		}
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   129
	}
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   130
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   131
	return GetIndustry(index);
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   132
}
ec4e13f21cd0 (svn r6057) -Codechange: made a function GetRandomXXX, that _always_ returns a valid XXX, unless there are none to pick from. Then NULL is returned.
truelight
parents: 4354
diff changeset
   133
4403
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   134
void DestroyIndustry(Industry *i);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   135
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   136
static inline void DeleteIndustry(Industry *i)
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   137
{
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   138
	DestroyIndustry(i);
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   139
	i->xy = 0;
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   140
}
3f503ac2d0f9 (svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents: 4357
diff changeset
   141
4976
2e3d5e8ec510 (svn r6979) Use the pool macros for the Industry pool
tron
parents: 4966
diff changeset
   142
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   143
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   144
4277
345e1bd9525a (svn r5907) Remove more indirection by using pointers instead of IDs. Also fix some bogus warnings on MSVC by using (void*) casts
tron
parents: 3689
diff changeset
   145
VARDEF const Industry** _industry_sort;
1267
ba42a505ab8a (svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents: 1220
diff changeset
   146
VARDEF bool _industry_sort_dirty;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 830
diff changeset
   147
3496
0959ead7c2af (svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents: 3350
diff changeset
   148
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
void DeleteIndustry(Industry *is);
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4326
diff changeset
   150
void PlantRandomFarmField(const Industry *i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
enum {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   153
	IT_COAL_MINE           =   0,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   154
	IT_POWER_STATION       =   1,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   155
	IT_SAWMILL             =   2,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   156
	IT_FOREST              =   3,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   157
	IT_OIL_REFINERY        =   4,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   158
	IT_OIL_RIG             =   5,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   159
	IT_FACTORY             =   6,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   160
	IT_PRINTING_WORKS      =   7,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   161
	IT_STEEL_MILL          =   8,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   162
	IT_FARM                =   9,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   163
	IT_COPPER_MINE         =  10,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   164
	IT_OIL_WELL            =  11,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   165
	IT_BANK_TEMP           =  12,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   166
	IT_FOOD_PROCESS        =  13,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   167
	IT_PAPER_MILL          =  14,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   168
	IT_GOLD_MINE           =  15,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   169
	IT_BANK_TROPIC_ARCTIC  =  16,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   170
	IT_DIAMOND_MINE        =  17,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   171
	IT_IRON_MINE           =  18,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   172
	IT_FRUIT_PLANTATION    =  19,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   173
	IT_RUBBER_PLANTATION   =  20,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   174
	IT_WATER_SUPPLY        =  21,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   175
	IT_WATER_TOWER         =  22,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   176
	IT_FACTORY_2           =  23,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   177
	IT_FARM_2              =  24,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   178
	IT_LUMBER_MILL         =  25,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   179
	IT_COTTON_CANDY        =  26,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   180
	IT_CANDY_FACTORY       =  27,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   181
	IT_BATTERY_FARM        =  28,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   182
	IT_COLA_WELLS          =  29,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   183
	IT_TOY_SHOP            =  30,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   184
	IT_TOY_FACTORY         =  31,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   185
	IT_PLASTIC_FOUNTAINS   =  32,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   186
	IT_FIZZY_DRINK_FACTORY =  33,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   187
	IT_BUBBLE_GENERATOR    =  34,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   188
	IT_TOFFEE_QUARRY       =  35,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   189
	IT_SUGAR_MINE          =  36,
3499
92f95849788c (svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents: 3496
diff changeset
   190
	IT_END,
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4330
diff changeset
   191
	IT_INVALID             = 255,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   194
#endif /* INDUSTRY_H */