annotate src/industry.h @ 14154:e3fe36dfb81e draft

(svn r18702) -Fix [FS#3467]: Enable DrawGroundSpriteAt() to deal with foundations as DrawGroundSprite() does, and use this for drawing one-way-road-signs and clear-land-fences.
author frosch <frosch@openttd.org>
date Sun, 03 Jan 2010 20:55:00 +0000
parents 1c4c4ae8d716
children 8f89e4b14a05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
1 /* $Id$ */
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12658
diff changeset
9
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 8959
diff changeset
10 /** @file industry.h Base of all industries. */
6201
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6092
diff changeset
11
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
12 #ifndef INDUSTRY_H
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
13 #define INDUSTRY_H
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
14
11974
5328e400636a (svn r16380) -Codechange: rename pool.hpp to pool_type.hpp
smatz <smatz@openttd.org>
parents: 11973
diff changeset
15 #include "core/pool_type.hpp"
8119
b6ec923e9fa8 (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents: 7978
diff changeset
16 #include "core/random_func.hpp"
7610
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7608
diff changeset
17 #include "newgrf_storage.h"
8119
b6ec923e9fa8 (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents: 7978
diff changeset
18 #include "cargo_type.h"
b6ec923e9fa8 (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium <rubidium@openttd.org>
parents: 7978
diff changeset
19 #include "economy_type.h"
8139
db99ba38abc0 (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium <rubidium@openttd.org>
parents: 8138
diff changeset
20 #include "map_type.h"
8213
87c85bb42d6f (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium <rubidium@openttd.org>
parents: 8140
diff changeset
21 #include "industry_type.h"
12477
843a8d074a90 (svn r16914) -Codechange: split Station and BaseStation into different files
rubidium <rubidium@openttd.org>
parents: 12308
diff changeset
22 #include "tile_type.h"
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12477
diff changeset
23 #include "subsidy_type.h"
12826
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
24 #include "industry_map.h"
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
25
6390
a6b14274ee2e (svn r9520) -Codechange: Add the notion of Industry behaviour. It means what an industry can do (plant fields, cut trees, do not change production), what can be done to it (disasters like mine subsidence, jet/chopper attack), when it can be built etc...
belugas <belugas@openttd.org>
parents: 6307
diff changeset
26
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11971
diff changeset
27 typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11971
diff changeset
28 extern IndustryPool _industry_pool;
7390
9ae410265dce (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7337
diff changeset
29
6201
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6092
diff changeset
30 /**
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6092
diff changeset
31 * Defines the internal data of a functionnal industry
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6092
diff changeset
32 */
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11971
diff changeset
33 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
7610
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7608
diff changeset
34 typedef PersistentStorageArray<uint32, 16> PersistentStorage;
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7608
diff changeset
35
6819
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
36 TileIndex xy; ///< coordinates of the primary tile the industry is built one
6201
3b141366478a (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas <belugas@openttd.org>
parents: 6092
diff changeset
37 byte width;
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
38 byte height;
6819
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
39 const Town *town; ///< Nearest town
7645
5178857fa331 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents: 7639
diff changeset
40 CargoID produced_cargo[2]; ///< 2 production cargo slots
7165
c3b231638b80 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents: 7144
diff changeset
41 uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo
c3b231638b80 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium <rubidium@openttd.org>
parents: 7144
diff changeset
42 uint16 incoming_cargo_waiting[3]; ///< incoming cargo waiting to be processed
6819
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
43 byte production_rate[2]; ///< production rate for each cargo
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
44 byte prod_level; ///< general production level
7645
5178857fa331 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx <glx@openttd.org>
parents: 7639
diff changeset
45 CargoID accepts_cargo[3]; ///< 3 input cargo slots
6819
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
46 uint16 this_month_production[2]; ///< stats of this month's production per cargo
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
47 uint16 this_month_transported[2]; ///< stats of this month's transport per cargo
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
48 byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
49 uint16 last_month_production[2]; ///< total units produced per cargo in the last full month
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
50 uint16 last_month_transported[2]; ///< total units transported per cargo in the last full month
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
51 uint16 counter; ///< used for animation and/or production (if available cargo)
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
52
7319
d2b2514b2a5f (svn r10675) -Codechange: unhardcode the industry types used in several locations of the source code.
rubidium <rubidium@openttd.org>
parents: 7291
diff changeset
53 IndustryType type; ///< type of industry.
6819
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
54 OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
11085
8da1855e9f14 (svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents: 10550
diff changeset
55 byte random_colour; ///< randomized colour of the industry, for display purpose
6819
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
56 Year last_prod_year; ///< last year of production
ffc184231f4a (svn r10058) -Codechange: give some industry variable sensible names (like not telling "last_mo_production" when it is the production of the current month).
rubidium <rubidium@openttd.org>
parents: 6815
diff changeset
57 byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
58
12658
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12477
diff changeset
59 PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
b75d8c6681bd (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source
smatz <smatz@openttd.org>
parents: 12477
diff changeset
60
7186
0a85b5cc61f4 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium <rubidium@openttd.org>
parents: 7185
diff changeset
61 OwnerByte founder; ///< Founder of the industry
0a85b5cc61f4 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium <rubidium@openttd.org>
parents: 7185
diff changeset
62 Date construction_date; ///< Date of the construction of the industry
0a85b5cc61f4 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium <rubidium@openttd.org>
parents: 7185
diff changeset
63 uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType)
0a85b5cc61f4 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium <rubidium@openttd.org>
parents: 7185
diff changeset
64 Date last_cargo_accepted_at; ///< Last day cargo was accepted by this industry
7445
3fbe065e867c (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas <belugas@openttd.org>
parents: 7390
diff changeset
65 byte selected_layout; ///< Which tile layout was used when creating the industry
7390
9ae410265dce (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7337
diff changeset
66
7860
9676dc785085 (svn r11410) -Codechange: implement random triggers for industries.
rubidium <rubidium@openttd.org>
parents: 7757
diff changeset
67 byte random_triggers; ///< Triggers for the random
9676dc785085 (svn r11410) -Codechange: implement random triggers for industries.
rubidium <rubidium@openttd.org>
parents: 7757
diff changeset
68 uint16 random; ///< Random value used for randomisation of all kinds of things
9676dc785085 (svn r11410) -Codechange: implement random triggers for industries.
rubidium <rubidium@openttd.org>
parents: 7757
diff changeset
69
7610
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7608
diff changeset
70 PersistentStorage psa; ///< Persistent storage for NewGRF industries.
b5bdd89a6aa2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium <rubidium@openttd.org>
parents: 7608
diff changeset
71
10550
98e8bc97ec6b (svn r14807) -Codechange: use INVALID_TILE instead of 0 to mark invalid depots, industries, towns and waypoints
smatz <smatz@openttd.org>
parents: 10491
diff changeset
72 Industry(TileIndex tile = INVALID_TILE) : xy(tile) {}
7390
9ae410265dce (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7337
diff changeset
73 ~Industry();
12252
f758517b6645 (svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents: 11974
diff changeset
74
12826
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
75 /**
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
76 * Get the industry of the given tile
13070
1c4c4ae8d716 (svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents: 12978
diff changeset
77 * @param tile the tile to get the industry from
12826
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
78 * @pre IsTileType(t, MP_INDUSTRY)
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
79 * @return the industry
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
80 */
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
81 static FORCEINLINE Industry *GetByTile(TileIndex tile)
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
82 {
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
83 return Industry::Get(GetIndustryIndex(tile));
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
84 }
c2f3eaf3b353 (svn r17316) -Codechange: use Industry::GetByTile() instead of GetIndustryByTile()
smatz <smatz@openttd.org>
parents: 12825
diff changeset
85
12252
f758517b6645 (svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()
smatz <smatz@openttd.org>
parents: 11974
diff changeset
86 static Industry *GetRandom();
12978
af3281ea88c4 (svn r17472) -Fix [FS#3182]: industry list was rebuilt too early during industry removal causing the removed industry to be still in the list after removal
rubidium <rubidium@openttd.org>
parents: 12826
diff changeset
87 static void PostDestructor(size_t index);
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
88 };
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
89
6637
7d0d7bde3390 (svn r9868) -Codechange: bring external declaration of functions togueter and adjust a comment
belugas <belugas@openttd.org>
parents: 6636
diff changeset
90 void PlantRandomFarmField(const Industry *i);
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
91
10491
357d932ba53d (svn r14746) -Fix: don't let any disaster vehicle (Helicopter or Airplane) target invalid industry
smatz <smatz@openttd.org>
parents: 10146
diff changeset
92 void ReleaseDisastersTargetingIndustry(IndustryID);
357d932ba53d (svn r14746) -Fix: don't let any disaster vehicle (Helicopter or Airplane) target invalid industry
smatz <smatz@openttd.org>
parents: 10146
diff changeset
93
6533
dfb2e6244177 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas <belugas@openttd.org>
parents: 6493
diff changeset
94 /* smallmap_gui.cpp */
dfb2e6244177 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas <belugas@openttd.org>
parents: 6493
diff changeset
95 void BuildIndustriesLegend();
10146
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 9950
diff changeset
96 /* industry_cmd.cpp */
f5ef198f917d (svn r14332) -Fix[FS#1885]: Balance the monthly random industry changes, by introducing a daily random industry change.
belugas <belugas@openttd.org>
parents: 9950
diff changeset
97 void SetIndustryDailyChanges();
6533
dfb2e6244177 (svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
belugas <belugas@openttd.org>
parents: 6493
diff changeset
98
11971
9daf69237623 (svn r16377) -Codechange: unify FOR_ALL_* macros, use separate index variable instead of var->index
smatz <smatz@openttd.org>
parents: 11930
diff changeset
99 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
9daf69237623 (svn r16377) -Codechange: unify FOR_ALL_* macros, use separate index variable instead of var->index
smatz <smatz@openttd.org>
parents: 11930
diff changeset
100 #define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
5475
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
101
eabf4b86aed6 (svn r7759) -Merge: makefile rewrite. This merge features:
rubidium <rubidium@openttd.org>
parents:
diff changeset
102 #endif /* INDUSTRY_H */