author | Darkvater |
Tue, 31 Oct 2006 23:04:47 +0000 | |
changeset 5009 | 0ae33f104d4f |
parent 4976 | 2e3d5e8ec510 |
child 5056 | 8fabd0020af7 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
4 |
#include "openttd.h" |
3144
33e42feae531
(svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents:
3094
diff
changeset
|
5 |
#include "clear_map.h" |
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
|
6 |
#include "functions.h" |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
7 |
#include "industry_map.h" |
3338
7cff208f0446
(svn r4120) Use the new station functions where appropriate
tron
parents:
3331
diff
changeset
|
8 |
#include "station_map.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
9 |
#include "table/strings.h" |
2148
542ea702738c
(svn r2658) -Codechange: Use MAKE_TRANSPARENT to display a transparented sprite
celestar
parents:
2140
diff
changeset
|
10 |
#include "table/sprites.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
552
diff
changeset
|
11 |
#include "map.h" |
1209
2e00193652b2
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1202
diff
changeset
|
12 |
#include "tile.h" |
0 | 13 |
#include "viewport.h" |
14 |
#include "command.h" |
|
15 |
#include "industry.h" |
|
16 |
#include "town.h" |
|
17 |
#include "vehicle.h" |
|
18 |
#include "news.h" |
|
19 |
#include "saveload.h" |
|
20 |
#include "economy.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
314
diff
changeset
|
21 |
#include "sound.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
22 |
#include "variables.h" |
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
23 |
#include "table/industry_land.h" |
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
24 |
#include "table/build_industry.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
25 |
#include "genworld.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4231
diff
changeset
|
26 |
#include "date.h" |
0 | 27 |
|
4403
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
28 |
void ShowIndustryViewWindow(int industry); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
29 |
void BuildOilRig(TileIndex tile); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
30 |
void DeleteOilRig(TileIndex tile); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
31 |
|
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
32 |
static byte _industry_sound_ctr; |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
33 |
static TileIndex _industry_sound_tile; |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
34 |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
35 |
/** |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
36 |
* Called if a new block is added to the industry-pool |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
37 |
*/ |
2817 | 38 |
static void IndustryPoolNewBlock(uint start_item) |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
39 |
{ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
40 |
Industry *i; |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
41 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
42 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
43 |
* TODO - This is just a temporary stage, this will be removed. */ |
4976
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
44 |
for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) i->index = start_item++; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
45 |
} |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
46 |
|
4976
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
47 |
DEFINE_POOL(Industry, Industry, IndustryPoolNewBlock, NULL) |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
48 |
|
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
|
49 |
/** |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
50 |
* Retrieve the type for this industry. Although it is accessed by a tile, |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
51 |
* it will return the general type of industry, and not the sprite index |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
52 |
* as would do GetIndustryGfx. |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
53 |
* The same information can be accessed by looking at Industry->type |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
54 |
* @param tile that is queried |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
55 |
* @pre IsTileType(tile, MP_INDUSTRY) |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
56 |
* @return general type for this industry, as defined in industry.h |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
57 |
**/ |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
58 |
IndustryType GetIndustryType(TileIndex tile) |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
59 |
{ |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
60 |
IndustryGfx this_type = GetIndustryGfx(tile); |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
61 |
IndustryType iloop; |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
62 |
|
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
63 |
assert(IsTileType(tile, MP_INDUSTRY)); |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
64 |
|
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
65 |
for (iloop = IT_COAL_MINE; iloop < IT_END; iloop += 1) { |
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
66 |
if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx, |
3553
4aab99ade276
(svn r4425) Fix bug introduced in r4411 : while IS_BYTE_INSIDE, max value is STRICKLY LESS THEN. This caused airports animations to stay unanimated. Industries were similarly affected.
belugas
parents:
3545
diff
changeset
|
67 |
industry_gfx_Solver[iloop].MaxGfx+1)) { |
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
|
68 |
return iloop; |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
69 |
} |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
70 |
} |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
71 |
|
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
72 |
return IT_INVALID; //we have not found equivalent, whatever the reason |
92f95849788c
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
belugas
parents:
3496
diff
changeset
|
73 |
} |
0 | 74 |
|
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
75 |
/** |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
76 |
* Accessor for array _industry_specs. |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
77 |
* This will ensure at once : proper access and |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
78 |
* not allowing modifications of it. |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
79 |
* @param thistype of industry (which is the index in _industry_specs) |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
80 |
* @pre thistype < IT_END |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
81 |
**/ |
3689
50a3fd4ba752
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3669
diff
changeset
|
82 |
const IndustrySpec *GetIndustrySpec(IndustryType thistype) |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
83 |
{ |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
84 |
assert(thistype < IT_END); |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
85 |
return &_industry_specs[thistype]; |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
86 |
} |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
87 |
|
4403
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
88 |
void DestroyIndustry(Industry *i) |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
89 |
{ |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
90 |
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
91 |
if (IsTileType(tile_cur, MP_INDUSTRY)) { |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
92 |
if (GetIndustryIndex(tile_cur) == i->index) { |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
93 |
DoClearSquare(tile_cur); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
94 |
} |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
95 |
} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
96 |
DeleteOilRig(tile_cur); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
97 |
} |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
98 |
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
99 |
|
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
100 |
if (i->type == IT_FARM || i->type == IT_FARM_2) { |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
101 |
/* Remove the farmland and convert it to regular tiles over time. */ |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
102 |
BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) { |
4815
d702c4027451
(svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents:
4607
diff
changeset
|
103 |
tile_cur = TILE_MASK(tile_cur); |
4403
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
104 |
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
105 |
GetIndustryIndexOfField(tile_cur) == i->index) { |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
106 |
SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
107 |
} |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
108 |
} END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21)) |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
109 |
} |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
110 |
|
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
111 |
_industry_sort_dirty = true; |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
112 |
DeleteSubsidyWithIndustry(i->index); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
113 |
DeleteWindowById(WC_INDUSTRY_VIEW, i->index); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
114 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
115 |
} |
3f503ac2d0f9
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
truelight
parents:
4357
diff
changeset
|
116 |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
117 |
static void IndustryDrawSugarMine(const TileInfo *ti) |
0 | 118 |
{ |
119 |
const DrawIndustrySpec1Struct *d; |
|
120 |
uint32 image; |
|
121 |
||
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
122 |
if (!IsIndustryCompleted(ti->tile)) return; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
123 |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
124 |
d = &_draw_industry_spec1[_m[ti->tile].m3]; |
0 | 125 |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
126 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, d->x, 0); |
0 | 127 |
|
2639 | 128 |
image = d->image_2; |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
129 |
if (image != 0) AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + image - 1, 8, 41); |
0 | 130 |
|
2639 | 131 |
image = d->image_3; |
132 |
if (image != 0) { |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
133 |
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + image - 1, |
2639 | 134 |
_drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]); |
135 |
} |
|
0 | 136 |
} |
137 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
138 |
static void IndustryDrawToffeeQuarry(const TileInfo *ti) |
0 | 139 |
{ |
140 |
int x = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
141 |
|
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
142 |
if (IsIndustryCompleted(ti->tile)) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
143 |
x = _industry_anim_offs[_m[ti->tile].m3]; |
0 | 144 |
if ( (byte)x == 0xFF) |
145 |
x = 0; |
|
146 |
} |
|
147 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
148 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, 22 - x, 24 + x); |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
149 |
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, 6, 14); |
0 | 150 |
} |
151 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
152 |
static void IndustryDrawBubbleGenerator( const TileInfo *ti) |
0 | 153 |
{ |
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
154 |
if (IsIndustryCompleted(ti->tile)) { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
155 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, 5, _industry_anim_offs_2[_m[ti->tile].m3]); |
2639 | 156 |
} else { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
157 |
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, 3, 67); |
0 | 158 |
} |
159 |
} |
|
160 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
161 |
static void IndustryDrawToyFactory(const TileInfo *ti) |
0 | 162 |
{ |
163 |
const DrawIndustrySpec4Struct *d; |
|
164 |
||
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
165 |
d = &_industry_anim_offs_3[_m[ti->tile].m3]; |
0 | 166 |
|
167 |
if (d->image_1 != 0xFF) { |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
168 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, 50 - d->image_1 * 2, 96 + d->image_1); |
0 | 169 |
} |
170 |
||
171 |
if (d->image_2 != 0xFF) { |
|
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
172 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, 16 - d->image_2 * 2, 100 + d->image_2); |
0 | 173 |
} |
174 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
175 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, 7, d->image_3); |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
176 |
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, 0, 42); |
0 | 177 |
} |
178 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
179 |
static void IndustryDrawCoalPlantSparks(const TileInfo *ti) |
0 | 180 |
{ |
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
181 |
if (IsIndustryCompleted(ti->tile)) { |
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
182 |
uint image = GB(_m[ti->tile].m1, 2, 5); |
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
183 |
|
0 | 184 |
if (image != 0 && image < 7) { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
185 |
AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
186 |
_coal_plant_sparks_x[image - 1], |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
187 |
_coal_plant_sparks_y[image - 1] |
0 | 188 |
); |
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2360
diff
changeset
|
193 |
typedef void IndustryDrawTileProc(const TileInfo *ti); |
0 | 194 |
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
195 |
IndustryDrawSugarMine, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
196 |
IndustryDrawToffeeQuarry, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
197 |
IndustryDrawBubbleGenerator, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
198 |
IndustryDrawToyFactory, |
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
199 |
IndustryDrawCoalPlantSparks, |
0 | 200 |
}; |
201 |
||
202 |
static void DrawTile_Industry(TileInfo *ti) |
|
203 |
{ |
|
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
204 |
const Industry *ind; |
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
205 |
const DrawBuildingsTileStruct *dits; |
0 | 206 |
byte z; |
207 |
uint32 image, ormod; |
|
208 |
||
209 |
/* Pointer to industry */ |
|
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
210 |
ind = GetIndustryByTile(ti->tile); |
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
211 |
ormod = GENERAL_SPRITE_COLOR(ind->random_color); |
0 | 212 |
|
213 |
/* Retrieve pointer to the draw industry tile struct */ |
|
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
214 |
dits = &_industry_draw_tile_data[GetIndustryGfx(ti->tile) << 2 | GetIndustryConstructionStage(ti->tile)]; |
0 | 215 |
|
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
216 |
image = dits->ground; |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
217 |
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0) |
0 | 218 |
image |= ormod; |
219 |
||
220 |
z = ti->z; |
|
221 |
/* Add bricks below the industry? */ |
|
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
222 |
if (ti->tileh != SLOPE_FLAT) { |
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
223 |
AddSortableSpriteToDraw(SPR_FOUNDATION_BASE + ti->tileh, ti->x, ti->y, 16, 16, 7, z); |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
224 |
AddChildSpriteScreen(image, 31, 1); |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
225 |
z += TILE_HEIGHT; |
0 | 226 |
} else { |
227 |
/* Else draw regular ground */ |
|
228 |
DrawGroundSprite(image); |
|
229 |
} |
|
230 |
||
231 |
/* Add industry on top of the ground? */ |
|
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
232 |
image = dits->building; |
2639 | 233 |
if (image != 0) { |
2187
a0e206ce9fbf
(svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents:
2186
diff
changeset
|
234 |
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0) |
0 | 235 |
image |= ormod; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
236 |
|
2639 | 237 |
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
|
238 |
|
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
239 |
AddSortableSpriteToDraw(image, |
2653
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
240 |
ti->x + dits->subtile_x, |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
241 |
ti->y + dits->subtile_y, |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
242 |
dits->width + 1, |
b1945642bf27
(svn r3195) Use bitfields instead of explicit shifting/masking
tron
parents:
2639
diff
changeset
|
243 |
dits->height + 1, |
0 | 244 |
dits->dz, |
245 |
z); |
|
246 |
||
2639 | 247 |
if (_display_opt & DO_TRANS_BUILDINGS) return; |
0 | 248 |
} |
249 |
||
2639 | 250 |
{ |
3654
c09872510a61
(svn r4568) CodeChange : Bring definitions and uses of DrawTypesStructures toguether.
belugas
parents:
3645
diff
changeset
|
251 |
int proc = dits->draw_proc - 1; |
2639 | 252 |
if (proc >= 0) _industry_draw_tile_procs[proc](ti); |
0 | 253 |
} |
254 |
} |
|
255 |
||
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
256 |
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y) |
2537 | 257 |
{ |
4231
2823b3643862
(svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents:
4077
diff
changeset
|
258 |
return GetTileMaxZ(tile); |
0 | 259 |
} |
260 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
261 |
static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh) |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2537
diff
changeset
|
262 |
{ |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
263 |
return SLOPE_FLAT; |
39 | 264 |
} |
265 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
266 |
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) |
0 | 267 |
{ |
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
|
268 |
IndustryGfx gfx = GetIndustryGfx(tile); |
2598
d69238b81415
(svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents:
2549
diff
changeset
|
269 |
CargoID a; |
0 | 270 |
|
3494
ba64f1689870
(svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents:
3491
diff
changeset
|
271 |
a = _industry_section_accepts_1[gfx]; |
2598
d69238b81415
(svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents:
2549
diff
changeset
|
272 |
if (a != CT_INVALID) ac[a] = (a == 0) ? 1 : 8; |
0 | 273 |
|
3494
ba64f1689870
(svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents:
3491
diff
changeset
|
274 |
a = _industry_section_accepts_2[gfx]; |
2598
d69238b81415
(svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents:
2549
diff
changeset
|
275 |
if (a != CT_INVALID) ac[a] = 8; |
0 | 276 |
|
3494
ba64f1689870
(svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents:
3491
diff
changeset
|
277 |
a = _industry_section_accepts_3[gfx]; |
2598
d69238b81415
(svn r3135) Use symbolic names in the tables, which hold the information about accepted goods of industry tiles, instead of magic numbers
tron
parents:
2549
diff
changeset
|
278 |
if (a != CT_INVALID) ac[a] = 8; |
0 | 279 |
} |
280 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
281 |
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) |
0 | 282 |
{ |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
283 |
const Industry *i = GetIndustryByTile(tile); |
0 | 284 |
|
285 |
td->owner = i->owner; |
|
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
286 |
td->str = GetIndustrySpec(i->type)->name; |
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
287 |
if (!IsIndustryCompleted(tile)) { |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
288 |
SetDParamX(td->dparam, 0, td->str); |
0 | 289 |
td->str = STR_2058_UNDER_CONSTRUCTION; |
290 |
} |
|
291 |
} |
|
292 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
293 |
static int32 ClearTile_Industry(TileIndex tile, byte flags) |
0 | 294 |
{ |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
295 |
Industry *i = GetIndustryByTile(tile); |
0 | 296 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
297 |
/* water can destroy industries |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
298 |
* in editor you can bulldoze industries |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
299 |
* with magic_bulldozer cheat you can destroy industries |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
300 |
* (area around OILRIG is water, so water shouldn't flood it |
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
301 |
*/ |
149
5f7d4b21df01
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
darkvater
parents:
131
diff
changeset
|
302 |
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
|
303 |
!_cheats.magic_bulldozer.value) || |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3877
diff
changeset
|
304 |
(_current_player == OWNER_WATER && i->type == IT_OIL_RIG)) { |
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
305 |
SetDParam(0, GetIndustrySpec(i->type)->name); |
0 | 306 |
return_cmd_error(STR_4800_IN_THE_WAY); |
307 |
} |
|
308 |
||
2639 | 309 |
if (flags & DC_EXEC) DeleteIndustry(i); |
0 | 310 |
return 0; |
311 |
} |
|
312 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
313 |
static void TransportIndustryGoods(TileIndex tile) |
0 | 314 |
{ |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
315 |
Industry *i = GetIndustryByTile(tile); |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
316 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
0 | 317 |
uint cw, am; |
318 |
||
2639 | 319 |
cw = min(i->cargo_waiting[0], 255); |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
320 |
if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) { |
0 | 321 |
i->cargo_waiting[0] -= cw; |
322 |
||
323 |
/* fluctuating economy? */ |
|
2639 | 324 |
if (_economy.fluct <= 0) cw = (cw + 1) / 2; |
0 | 325 |
|
326 |
i->last_mo_production[0] += cw; |
|
327 |
||
328 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw); |
|
329 |
i->last_mo_transported[0] += am; |
|
3331 | 330 |
if (am != 0) { |
3494
ba64f1689870
(svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents:
3491
diff
changeset
|
331 |
uint newgfx = _industry_produce_section[GetIndustryGfx(tile)]; |
3331 | 332 |
|
333 |
if (newgfx != 0xFF) { |
|
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
334 |
ResetIndustryConstructionStage(tile); |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
335 |
SetIndustryCompleted(tile, true); |
3331 | 336 |
SetIndustryGfx(tile, newgfx); |
337 |
MarkTileDirtyByTile(tile); |
|
338 |
} |
|
0 | 339 |
} |
340 |
} |
|
341 |
||
342 |
cw = min(i->cargo_waiting[1], 255); |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
343 |
if (cw > indspec->minimal_cargo) { |
0 | 344 |
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
|
345 |
|
2639 | 346 |
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
|
347 |
|
0 | 348 |
i->last_mo_production[1] += cw; |
349 |
||
350 |
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw); |
|
351 |
i->last_mo_transported[1] += am; |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
356 |
static void AnimateTile_Industry(TileIndex tile) |
0 | 357 |
{ |
3331 | 358 |
byte m; |
0 | 359 |
|
3331 | 360 |
switch (GetIndustryGfx(tile)) { |
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
361 |
case GFX_SUGAR_MINE_SIEVE: |
0 | 362 |
if ((_tick_counter & 1) == 0) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
363 |
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
|
364 |
|
2952 | 365 |
switch (m & 7) { |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
366 |
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; |
541 | 367 |
case 6: SndPlayTileFx(SND_29_RIP, tile); break; |
0 | 368 |
} |
369 |
||
370 |
if (m >= 96) { |
|
371 |
m = 0; |
|
372 |
DeleteAnimatedTile(tile); |
|
373 |
} |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
374 |
_m[tile].m3 = m; |
0 | 375 |
|
376 |
MarkTileDirtyByTile(tile); |
|
377 |
} |
|
378 |
break; |
|
379 |
||
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
380 |
case GFX_TOFFEE_QUARY: |
0 | 381 |
if ((_tick_counter & 3) == 0) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
382 |
m = _m[tile].m3; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
383 |
|
0 | 384 |
if (_industry_anim_offs[m] == 0xFF) { |
541 | 385 |
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); |
0 | 386 |
} |
387 |
||
388 |
if (++m >= 70) { |
|
389 |
m = 0; |
|
390 |
DeleteAnimatedTile(tile); |
|
391 |
} |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
392 |
_m[tile].m3 = m; |
0 | 393 |
|
394 |
MarkTileDirtyByTile(tile); |
|
395 |
} |
|
396 |
break; |
|
397 |
||
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
398 |
case GFX_BUBBLE_CATCHER: |
0 | 399 |
if ((_tick_counter&1) == 0) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
400 |
m = _m[tile].m3; |
0 | 401 |
|
402 |
if (++m >= 40) { |
|
403 |
m = 0; |
|
404 |
DeleteAnimatedTile(tile); |
|
405 |
} |
|
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
406 |
_m[tile].m3 = m; |
0 | 407 |
|
408 |
MarkTileDirtyByTile(tile); |
|
409 |
} |
|
410 |
break; |
|
411 |
||
412 |
// Sparks on a coal plant |
|
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
413 |
case GFX_POWERPLANT_SPARKS: |
0 | 414 |
if ((_tick_counter & 3) == 0) { |
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
415 |
m = _m[tile].m1; |
2663 | 416 |
if (GB(m, 2, 5) == 6) { |
417 |
SB(_m[tile].m1, 2, 5, 0); |
|
0 | 418 |
DeleteAnimatedTile(tile); |
419 |
} else { |
|
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
420 |
_m[tile].m1 = m + (1<<2); |
0 | 421 |
MarkTileDirtyByTile(tile); |
422 |
} |
|
423 |
} |
|
424 |
break; |
|
425 |
||
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
426 |
case GFX_TOY_FACTORY: |
0 | 427 |
if ((_tick_counter & 1) == 0) { |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
428 |
m = _m[tile].m3 + 1; |
0 | 429 |
|
430 |
if (m == 1) { |
|
541 | 431 |
SndPlayTileFx(SND_2C_MACHINERY, tile); |
0 | 432 |
} else if (m == 23) { |
541 | 433 |
SndPlayTileFx(SND_2B_COMEDY_HIT, tile); |
0 | 434 |
} else if (m == 28) { |
541 | 435 |
SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); |
0 | 436 |
} |
437 |
||
3538
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
438 |
if (m >= 50) { |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
439 |
int n = GetIndustryAnimationLoop(tile) + 1; |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
440 |
m = 0; |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
441 |
if (n >= 8) { |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
442 |
n = 0; |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
443 |
DeleteAnimatedTile(tile); |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
444 |
} |
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
445 |
SetIndustryAnimationLoop(tile, n); |
0 | 446 |
} |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
447 |
_m[tile].m3 = m; |
0 | 448 |
MarkTileDirtyByTile(tile); |
449 |
} |
|
450 |
break; |
|
451 |
||
452 |
case 148: case 149: case 150: case 151: |
|
453 |
case 152: case 153: case 154: case 155: |
|
454 |
if ((_tick_counter & 3) == 0) { |
|
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
|
455 |
IndustryGfx gfx = GetIndustryGfx(tile); |
0 | 456 |
|
3331 | 457 |
gfx = (gfx < 155) ? gfx + 1 : 148; |
458 |
SetIndustryGfx(tile, gfx); |
|
0 | 459 |
MarkTileDirtyByTile(tile); |
460 |
} |
|
461 |
break; |
|
462 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
463 |
case GFX_OILWELL_ANIMATED_1: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
464 |
case GFX_OILWELL_ANIMATED_2: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
465 |
case GFX_OILWELL_ANIMATED_3: |
0 | 466 |
if ((_tick_counter & 7) == 0) { |
467 |
bool b = CHANCE16(1,7); |
|
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
|
468 |
IndustryGfx gfx = GetIndustryGfx(tile); |
3331 | 469 |
|
470 |
m = GB(_m[tile].m1, 0, 2) + 1; |
|
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
471 |
if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) { |
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
472 |
_m[tile].m1 = 0x83; |
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
473 |
SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
474 |
DeleteAnimatedTile(tile); |
0 | 475 |
} else { |
2663 | 476 |
SB(_m[tile].m1, 0, 2, m); |
3331 | 477 |
SetIndustryGfx(tile, gfx); |
0 | 478 |
MarkTileDirtyByTile(tile); |
479 |
} |
|
480 |
} |
|
481 |
break; |
|
482 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
483 |
case GFX_COAL_MINE_TOWER_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
484 |
case GFX_COPPER_MINE_TOWER_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
485 |
case GFX_GOLD_MINE_TOWER_ANIMATED: { |
0 | 486 |
int state = _tick_counter & 0x7FF; |
487 |
||
488 |
if ((state -= 0x400) < 0) |
|
489 |
return; |
|
490 |
||
491 |
if (state < 0x1A0) { |
|
492 |
if (state < 0x20 || state >= 0x180) { |
|
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
493 |
if (!(_m[tile].m1 & 0x40)) { |
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
494 |
_m[tile].m1 |= 0x40; |
541 | 495 |
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); |
0 | 496 |
} |
497 |
if (state & 7) |
|
498 |
return; |
|
499 |
} else { |
|
500 |
if (state & 3) |
|
501 |
return; |
|
502 |
} |
|
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
503 |
m = (_m[tile].m1 + 1) | 0x40; |
0 | 504 |
if (m > 0xC2) m = 0xC0; |
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
505 |
_m[tile].m1 = m; |
0 | 506 |
MarkTileDirtyByTile(tile); |
507 |
} else if (state >= 0x200 && state < 0x3A0) { |
|
508 |
int i; |
|
509 |
i = (state < 0x220 || state >= 0x380) ? 7 : 3; |
|
510 |
if (state & i) |
|
511 |
return; |
|
512 |
||
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
513 |
m = (_m[tile].m1 & 0xBF) - 1; |
0 | 514 |
if (m < 0x80) m = 0x82; |
2360
4e4ebe18e448
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2260
diff
changeset
|
515 |
_m[tile].m1 = m; |
0 | 516 |
MarkTileDirtyByTile(tile); |
517 |
} |
|
518 |
} break; |
|
519 |
} |
|
520 |
} |
|
521 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
522 |
static void CreateIndustryEffectSmoke(TileIndex tile) |
0 | 523 |
{ |
3773
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
524 |
uint x = TileX(tile) * TILE_SIZE; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
525 |
uint y = TileY(tile) * TILE_SIZE; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
526 |
uint z = GetTileMaxZ(tile); |
3094 | 527 |
|
3773
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3689
diff
changeset
|
528 |
CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE); |
0 | 529 |
} |
530 |
||
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
531 |
static void MakeIndustryTileBigger(TileIndex tile) |
0 | 532 |
{ |
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
533 |
byte cnt = GetIndustryConstructionCounter(tile) + 1; |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
534 |
byte stage; |
0 | 535 |
|
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
536 |
if (cnt != 4) { |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
537 |
SetIndustryConstructionCounter(tile, cnt); |
0 | 538 |
return; |
539 |
} |
|
540 |
||
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
541 |
stage = GetIndustryConstructionStage(tile) + 1; |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
542 |
SetIndustryConstructionCounter(tile, 0); |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
543 |
SetIndustryConstructionStage(tile, stage); |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
544 |
if (stage == 3) { |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
545 |
SetIndustryCompleted(tile, true); |
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
546 |
} |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
547 |
|
0 | 548 |
MarkTileDirtyByTile(tile); |
549 |
||
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
550 |
if (!IsIndustryCompleted(tile)) return; |
0 | 551 |
|
3331 | 552 |
switch (GetIndustryGfx(tile)) { |
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
553 |
case GFX_POWERPLANT_CHIMNEY: |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
554 |
CreateIndustryEffectSmoke(tile); |
0 | 555 |
break; |
556 |
||
4607
323a239feef7
(svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents:
4587
diff
changeset
|
557 |
case GFX_OILRIG_1: |
323a239feef7
(svn r6459) - Fix (r6433): An enum mixup caused oilrigs to not have a station part. Thanks to Znuff for pointing out.
peter1138
parents:
4587
diff
changeset
|
558 |
if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == GFX_OILRIG_1) BuildOilRig(tile); |
0 | 559 |
break; |
560 |
||
3545
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
561 |
case GFX_TOY_FACTORY: |
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
562 |
case GFX_BUBBLE_CATCHER: |
b08ce1bbb589
(svn r4411) CodeChange : Define and use some Gfx for both stations and industries. More are still to come
belugas
parents:
3538
diff
changeset
|
563 |
case GFX_TOFFEE_QUARY: |
2049
538e73c53f54
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1981
diff
changeset
|
564 |
_m[tile].m3 = 0; |
3538
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
565 |
SetIndustryAnimationLoop(tile, 0); |
0 | 566 |
break; |
567 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
568 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
569 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_2: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
570 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
571 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_4: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
572 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
573 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
574 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
575 |
case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: |
0 | 576 |
AddAnimatedTile(tile); |
577 |
break; |
|
578 |
} |
|
579 |
} |
|
580 |
||
581 |
||
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
582 |
static void TileLoopIndustry_BubbleGenerator(TileIndex tile) |
0 | 583 |
{ |
584 |
int dir; |
|
585 |
Vehicle *v; |
|
586 |
static const int8 _tileloop_ind_case_161[12] = { |
|
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
|
587 |
11, 0, -4, -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
|
588 |
-4, -10, -4, 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
|
589 |
49, 59, 60, 65, |
0 | 590 |
}; |
591 |
||
541 | 592 |
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
|
593 |
|
0 | 594 |
dir = Random() & 3; |
595 |
||
596 |
v = CreateEffectVehicleAbove( |
|
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
597 |
TileX(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 0], |
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
598 |
TileY(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 4], |
0 | 599 |
_tileloop_ind_case_161[dir + 8], |
1359
52782e5cf7c9
(svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents:
1335
diff
changeset
|
600 |
EV_BUBBLE |
0 | 601 |
); |
602 |
||
2639 | 603 |
if (v != NULL) v->u.special.unk2 = dir; |
0 | 604 |
} |
605 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
606 |
static void TileLoop_Industry(TileIndex tile) |
0 | 607 |
{ |
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
|
608 |
IndustryGfx newgfx; |
0 | 609 |
|
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
610 |
if (!IsIndustryCompleted(tile)) { |
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
611 |
MakeIndustryTileBigger(tile); |
0 | 612 |
return; |
613 |
} |
|
614 |
||
2639 | 615 |
if (_game_mode == GM_EDITOR) return; |
0 | 616 |
|
617 |
TransportIndustryGoods(tile); |
|
618 |
||
3494
ba64f1689870
(svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents:
3491
diff
changeset
|
619 |
newgfx = _industry_section_animation_next[GetIndustryGfx(tile)]; |
3331 | 620 |
if (newgfx != 255) { |
3495
6672c181ace4
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
belugas
parents:
3494
diff
changeset
|
621 |
ResetIndustryConstructionStage(tile); |
3331 | 622 |
SetIndustryGfx(tile, newgfx); |
0 | 623 |
MarkTileDirtyByTile(tile); |
624 |
return; |
|
625 |
} |
|
626 |
||
3331 | 627 |
#define SET_AND_ANIMATE(tile, a, b) { SetIndustryGfx(tile, a); _m[tile].m1 = b; AddAnimatedTile(tile); } |
628 |
#define SET_AND_UNANIMATE(tile, a, b) { SetIndustryGfx(tile, a); _m[tile].m1 = b; DeleteAnimatedTile(tile); } |
|
0 | 629 |
|
3331 | 630 |
switch (GetIndustryGfx(tile)) { |
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
631 |
case GFX_OILRIG_1: // coast line at oilrigs |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
632 |
case GFX_OILRIG_2: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
633 |
case GFX_OILRIG_3: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
634 |
case GFX_OILRIG_4: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
635 |
case GFX_OILRIG_5: |
43
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
636 |
TileLoop_Water(tile); |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
637 |
break; |
3b93861c5478
(svn r44) Fix: Coast line near edge of map and near oilrigs (Dribbel)
dominik
parents:
39
diff
changeset
|
638 |
|
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
639 |
case GFX_COAL_MINE_TOWER_NOT_ANIMATED: |
0 | 640 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
641 |
SET_AND_ANIMATE(tile, GFX_COAL_MINE_TOWER_ANIMATED, 0x80); |
0 | 642 |
break; |
643 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
644 |
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
645 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
646 |
SET_AND_ANIMATE(tile, GFX_COPPER_MINE_TOWER_ANIMATED, 0x80); |
0 | 647 |
break; |
648 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
649 |
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
650 |
if (!(_tick_counter & 0x400) && CHANCE16(1,2)) |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
651 |
SET_AND_ANIMATE(tile, GFX_GOLD_MINE_TOWER_ANIMATED, 0x80); |
0 | 652 |
break; |
653 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
654 |
case GFX_OILWELL_NOT_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
655 |
if (CHANCE16(1,6)) |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
656 |
SET_AND_ANIMATE(tile, GFX_OILWELL_ANIMATED_1, 0x80); |
0 | 657 |
break; |
658 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
659 |
case GFX_COAL_MINE_TOWER_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
660 |
if (!(_tick_counter & 0x400)) |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
661 |
SET_AND_UNANIMATE(tile, GFX_COAL_MINE_TOWER_NOT_ANIMATED, 0x83); |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
662 |
break; |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
663 |
|
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
664 |
case GFX_COPPER_MINE_TOWER_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
665 |
if (!(_tick_counter & 0x400)) |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
666 |
SET_AND_UNANIMATE(tile, GFX_COPPER_MINE_TOWER_NOT_ANIMATED, 0x83); |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
667 |
break; |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
668 |
|
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
669 |
case GFX_GOLD_MINE_TOWER_ANIMATED: |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
670 |
if (!(_tick_counter & 0x400)) |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
671 |
SET_AND_UNANIMATE(tile, GFX_GOLD_MINE_TOWER_NOT_ANIMATED, 0x83); |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
672 |
break; |
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
673 |
|
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
674 |
case GFX_POWERPLANT_SPARKS: |
0 | 675 |
if (CHANCE16(1,3)) { |
541 | 676 |
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); |
0 | 677 |
AddAnimatedTile(tile); |
678 |
} |
|
679 |
break; |
|
680 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
681 |
case GFX_COPPER_MINE_CHIMNEY: |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3418
diff
changeset
|
682 |
CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE); |
2639 | 683 |
break; |
0 | 684 |
|
685 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
686 |
case GFX_TOY_FACTORY: { |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
687 |
Industry *i = GetIndustryByTile(tile); |
0 | 688 |
if (i->was_cargo_delivered) { |
689 |
i->was_cargo_delivered = false; |
|
3538
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
690 |
SetIndustryAnimationLoop(tile, 0); |
0 | 691 |
AddAnimatedTile(tile); |
692 |
} |
|
693 |
} |
|
694 |
break; |
|
695 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
696 |
case GFX_BUBBLE_GENERATOR: |
3290
235df477f3ee
(svn r4004) -CodeChange : Renaming sprites and functions
belugas
parents:
3282
diff
changeset
|
697 |
TileLoopIndustry_BubbleGenerator(tile); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
698 |
break; |
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
699 |
|
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
700 |
case GFX_TOFFEE_QUARY: |
0 | 701 |
AddAnimatedTile(tile); |
702 |
break; |
|
703 |
||
4583
af31ba5db77d
(svn r6433) -Codechange: replace some magic numbers (industry gfx indices) by enums.
rubidium
parents:
4434
diff
changeset
|
704 |
case GFX_SUGAR_MINE_SIEVE: |
2639 | 705 |
if (CHANCE16(1, 3)) AddAnimatedTile(tile); |
0 | 706 |
break; |
707 |
} |
|
708 |
} |
|
709 |
||
710 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
711 |
static void ClickTile_Industry(TileIndex tile) |
0 | 712 |
{ |
3314
6aaeba4b92e8
(svn r4077) Add GetIndustry{Index,ByTile}() to get the industry index resp. the industry from a tile
tron
parents:
3296
diff
changeset
|
713 |
ShowIndustryViewWindow(GetIndustryIndex(tile)); |
0 | 714 |
} |
715 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
716 |
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode) |
0 | 717 |
{ |
718 |
return 0; |
|
719 |
} |
|
720 |
||
3344
fc86351d4641
(svn r4128) - CodeChange: Add proper semantics for CargoID for such variables instead of using the general byte-type.
Darkvater
parents:
3338
diff
changeset
|
721 |
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) |
0 | 722 |
{ |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
723 |
const Industry *i = GetIndustryByTile(tile); |
2630 | 724 |
|
0 | 725 |
b[0] = i->produced_cargo[0]; |
726 |
b[1] = i->produced_cargo[1]; |
|
727 |
} |
|
728 |
||
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2360
diff
changeset
|
729 |
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player) |
0 | 730 |
{ |
731 |
/* not used */ |
|
732 |
} |
|
733 |
||
734 |
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; |
|
735 |
||
1048 | 736 |
static bool IsBadFarmFieldTile(TileIndex tile) |
0 | 737 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
738 |
switch (GetTileType(tile)) { |
3447 | 739 |
case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
740 |
case MP_TREES: return false; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
741 |
default: return true; |
0 | 742 |
} |
743 |
} |
|
744 |
||
1048 | 745 |
static bool IsBadFarmFieldTile2(TileIndex tile) |
0 | 746 |
{ |
1214
8262981ac274
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1209
diff
changeset
|
747 |
switch (GetTileType(tile)) { |
3447 | 748 |
case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW); |
2955
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
749 |
case MP_TREES: return false; |
24de69e236d2
(svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
2952
diff
changeset
|
750 |
default: return true; |
0 | 751 |
} |
752 |
} |
|
753 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
754 |
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction) |
0 | 755 |
{ |
756 |
do { |
|
757 |
tile = TILE_MASK(tile); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
758 |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
759 |
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
760 |
byte or = type; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
761 |
|
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
762 |
if (or == 1 && CHANCE16(1, 7)) or = 2; |
0 | 763 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
764 |
if (direction == AXIS_X) { |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
765 |
SetFenceSE(tile, or); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
766 |
} else { |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
767 |
SetFenceSW(tile, or); |
0 | 768 |
} |
769 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
770 |
|
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
771 |
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); |
0 | 772 |
} while (--size); |
773 |
} |
|
774 |
||
4330
cf31daa8b321
(svn r6005) -Cleanup: introduce IndustryID and use it
rubidium
parents:
4329
diff
changeset
|
775 |
static void PlantFarmField(TileIndex tile, IndustryID industry) |
0 | 776 |
{ |
777 |
uint size_x, size_y; |
|
778 |
uint32 r; |
|
2133 | 779 |
uint count; |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
780 |
uint counter; |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
781 |
uint field_type; |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
782 |
int type; |
0 | 783 |
|
784 |
if (_opt.landscape == LT_HILLY) { |
|
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3421
diff
changeset
|
785 |
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line) |
0 | 786 |
return; |
787 |
} |
|
788 |
||
789 |
/* determine field size */ |
|
790 |
r = (Random() & 0x303) + 0x404; |
|
791 |
if (_opt.landscape == LT_HILLY) r += 0x404; |
|
2150
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
792 |
size_x = GB(r, 0, 8); |
f710b959b1c4
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
2148
diff
changeset
|
793 |
size_y = GB(r, 8, 8); |
0 | 794 |
|
795 |
/* offset tile to match size */ |
|
1981 | 796 |
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
|
797 |
|
0 | 798 |
/* check the amount of bad tiles */ |
799 |
count = 0; |
|
800 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
801 |
cur_tile = TILE_MASK(cur_tile); |
|
802 |
count += IsBadFarmFieldTile(cur_tile); |
|
803 |
END_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
2133 | 804 |
if (count * 2 >= size_x * size_y) return; |
0 | 805 |
|
806 |
/* determine type of field */ |
|
807 |
r = Random(); |
|
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
808 |
counter = GB(r, 5, 3); |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
809 |
field_type = GB(r, 8, 8) * 9 >> 8; |
0 | 810 |
|
811 |
/* make field */ |
|
812 |
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) |
|
813 |
cur_tile = TILE_MASK(cur_tile); |
|
814 |
if (!IsBadFarmFieldTile2(cur_tile)) { |
|
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
|
815 |
MakeField(cur_tile, field_type, industry); |
2979
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
816 |
SetClearCounter(cur_tile, counter); |
3ddf7c78d469
(svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents:
2955
diff
changeset
|
817 |
MarkTileDirtyByTile(cur_tile); |
0 | 818 |
} |
819 |
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
|
820 |
|
0 | 821 |
type = 3; |
822 |
if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) { |
|
823 |
type = _plantfarmfield_type[Random() & 0xF]; |
|
824 |
} |
|
825 |
||
3157
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
826 |
SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
827 |
SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
828 |
SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y); |
3f35e2d9c8e3
(svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents:
3144
diff
changeset
|
829 |
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); |
0 | 830 |
} |
831 |
||
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
|
832 |
void PlantRandomFarmField(const Industry *i) |
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
|
833 |
{ |
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
|
834 |
int x = i->width / 2 + Random() % 31 - 16; |
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
|
835 |
int y = i->height / 2 + Random() % 31 - 16; |
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
|
836 |
|
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
|
837 |
TileIndex tile = TileAddWrap(i->xy, x, y); |
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
|
838 |
|
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
|
839 |
if (tile != INVALID_TILE) PlantFarmField(tile, i->index); |
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
|
840 |
} |
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
|
841 |
|
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
842 |
static void MaybePlantFarmField(const Industry *i) |
0 | 843 |
{ |
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
|
844 |
if (CHANCE16(1, 8)) PlantRandomFarmField(i); |
0 | 845 |
} |
846 |
||
847 |
static void ChopLumberMillTrees(Industry *i) |
|
848 |
{ |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
849 |
static const TileIndexDiffC _chop_dir[] = { |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
850 |
{ 0, 1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
851 |
{ 1, 0}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
852 |
{ 0, -1}, |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
853 |
{-1, 0} |
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
854 |
}; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
855 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
856 |
TileIndex tile = i->xy; |
2639 | 857 |
int a; |
0 | 858 |
|
3321
4061bfef1830
(svn r4087) Add IsIndustryCompleted() to check if a industry tile is fully built
tron
parents:
3320
diff
changeset
|
859 |
if (!IsIndustryCompleted(tile)) return; |
0 | 860 |
|
861 |
/* search outwards as a rectangular spiral */ |
|
2639 | 862 |
for (a = 1; a != 41; a += 2) { |
863 |
uint dir; |
|
864 |
||
865 |
for (dir = 0; dir != 4; dir++) { |
|
866 |
int j = a; |
|
867 |
||
0 | 868 |
do { |
869 |
tile = TILE_MASK(tile); |
|
1035
812f837ee03f
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1019
diff
changeset
|
870 |
if (IsTileType(tile, MP_TREES)) { |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
871 |
PlayerID old_player = _current_player; |
0 | 872 |
/* found a tree */ |
873 |
||
874 |
_current_player = OWNER_NONE; |
|
875 |
_industry_sound_ctr = 1; |
|
876 |
_industry_sound_tile = tile; |
|
541 | 877 |
SndPlayTileFx(SND_38_CHAINSAW, tile); |
0 | 878 |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
879 |
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3344
diff
changeset
|
880 |
SetTropicZone(tile, TROPICZONE_INVALID); |
0 | 881 |
|
882 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45); |
|
314 | 883 |
|
884 |
_current_player = old_player; |
|
0 | 885 |
return; |
886 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
887 |
tile += ToTileIndexDiff(_chop_dir[dir]); |
0 | 888 |
} while (--j); |
889 |
} |
|
1981 | 890 |
tile -= TileDiffXY(1, 1); |
0 | 891 |
} |
892 |
} |
|
893 |
||
894 |
static const byte _industry_sounds[37][2] = { |
|
895 |
{0}, |
|
896 |
{0}, |
|
541 | 897 |
{1, SND_28_SAWMILL}, |
0 | 898 |
{0}, |
899 |
{0}, |
|
900 |
{0}, |
|
541 | 901 |
{1, SND_03_FACTORY_WHISTLE}, |
902 |
{1, SND_03_FACTORY_WHISTLE}, |
|
0 | 903 |
{0}, |
541 | 904 |
{3, SND_24_SHEEP}, |
0 | 905 |
{0}, |
906 |
{0}, |
|
907 |
{0}, |
|
908 |
{0}, |
|
541 | 909 |
{1, SND_28_SAWMILL}, |
0 | 910 |
{0}, |
911 |
{0}, |
|
912 |
{0}, |
|
913 |
{0}, |
|
914 |
{0}, |
|
915 |
{0}, |
|
916 |
{0}, |
|
917 |
{0}, |
|
541 | 918 |
{1, SND_03_FACTORY_WHISTLE}, |
0 | 919 |
{0}, |
920 |
{0}, |
|
921 |
{0}, |
|
922 |
{0}, |
|
923 |
{0}, |
|
924 |
{0}, |
|
925 |
{0}, |
|
926 |
{0}, |
|
541 | 927 |
{1, SND_33_PLASTIC_MINE}, |
0 | 928 |
{0}, |
929 |
{0}, |
|
930 |
{0}, |
|
931 |
{0}, |
|
932 |
}; |
|
933 |
||
934 |
||
935 |
static void ProduceIndustryGoods(Industry *i) |
|
936 |
{ |
|
937 |
uint32 r; |
|
938 |
uint num; |
|
939 |
||
940 |
/* play a sound? */ |
|
941 |
if ((i->counter & 0x3F) == 0) { |
|
942 |
if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) { |
|
943 |
SndPlayTileFx( |
|
944 |
_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16), |
|
945 |
i->xy); |
|
946 |
} |
|
947 |
} |
|
948 |
||
949 |
i->counter--; |
|
950 |
||
951 |
/* produce some cargo */ |
|
952 |
if ((i->counter & 0xFF) == 0) { |
|
953 |
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]); |
|
954 |
i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]); |
|
955 |
||
2639 | 956 |
if (i->type == IT_FARM) { |
0 | 957 |
MaybePlantFarmField(i); |
2639 | 958 |
} else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) { |
0 | 959 |
ChopLumberMillTrees(i); |
2639 | 960 |
} |
0 | 961 |
} |
962 |
} |
|
963 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
964 |
void OnTick_Industry(void) |
0 | 965 |
{ |
966 |
Industry *i; |
|
967 |
||
968 |
if (_industry_sound_ctr != 0) { |
|
969 |
_industry_sound_ctr++; |
|
970 |
||
971 |
if (_industry_sound_ctr == 75) { |
|
541 | 972 |
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); |
0 | 973 |
} 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
|
974 |
_industry_sound_ctr = 0; |
541 | 975 |
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); |
0 | 976 |
} |
977 |
} |
|
978 |
||
2639 | 979 |
if (_game_mode == GM_EDITOR) return; |
0 | 980 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
981 |
FOR_ALL_INDUSTRIES(i) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
982 |
ProduceIndustryGoods(i); |
0 | 983 |
} |
984 |
} |
|
985 |
||
986 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
987 |
static bool CheckNewIndustry_NULL(TileIndex tile) |
0 | 988 |
{ |
989 |
return true; |
|
990 |
} |
|
991 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
992 |
static bool CheckNewIndustry_Forest(TileIndex tile) |
0 | 993 |
{ |
994 |
if (_opt.landscape == LT_HILLY) { |
|
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
995 |
if (GetTileZ(tile) < _opt.snow_line + TILE_HEIGHT * 2U) { |
0 | 996 |
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; |
997 |
return false; |
|
998 |
} |
|
999 |
} |
|
1000 |
return true; |
|
1001 |
} |
|
1002 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1003 |
static bool CheckNewIndustry_OilRefinery(TileIndex tile) |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1004 |
{ |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1005 |
if (_game_mode == GM_EDITOR) return true; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1006 |
if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true; |
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1007 |
|
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1008 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1009 |
return false; |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1010 |
} |
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1011 |
|
7
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1012 |
extern bool _ignore_restrictions; |
f2e623faa778
(svn r8) Fix: Automatic oil refinery generation in editor
dominik
parents:
0
diff
changeset
|
1013 |
|
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1014 |
static bool CheckNewIndustry_OilRig(TileIndex tile) |
0 | 1015 |
{ |
2639 | 1016 |
if (_game_mode == GM_EDITOR && _ignore_restrictions) return true; |
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1017 |
if (TileHeight(tile) == 0 && |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1018 |
DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true; |
0 | 1019 |
|
1020 |
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED; |
|
1021 |
return false; |
|
1022 |
} |
|
1023 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1024 |
static bool CheckNewIndustry_Farm(TileIndex tile) |
0 | 1025 |
{ |
1026 |
if (_opt.landscape == LT_HILLY) { |
|
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
3421
diff
changeset
|
1027 |
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line) { |
0 | 1028 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1029 |
return false; |
|
1030 |
} |
|
1031 |
} |
|
1032 |
return true; |
|
1033 |
} |
|
1034 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1035 |
static bool CheckNewIndustry_Plantation(TileIndex tile) |
0 | 1036 |
{ |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3344
diff
changeset
|
1037 |
if (GetTropicZone(tile) == TROPICZONE_DESERT) { |
0 | 1038 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1039 |
return false; |
|
1040 |
} |
|
1041 |
||
1042 |
return true; |
|
1043 |
} |
|
1044 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1045 |
static bool CheckNewIndustry_Water(TileIndex tile) |
0 | 1046 |
{ |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3344
diff
changeset
|
1047 |
if (GetTropicZone(tile) != TROPICZONE_DESERT) { |
0 | 1048 |
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; |
1049 |
return false; |
|
1050 |
} |
|
1051 |
||
1052 |
return true; |
|
1053 |
} |
|
1054 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1055 |
static bool CheckNewIndustry_Lumbermill(TileIndex tile) |
0 | 1056 |
{ |
3379
50b253bb9819
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3344
diff
changeset
|
1057 |
if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) { |
0 | 1058 |
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; |
1059 |
return false; |
|
1060 |
} |
|
1061 |
return true; |
|
1062 |
} |
|
1063 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1064 |
static bool CheckNewIndustry_BubbleGen(TileIndex tile) |
0 | 1065 |
{ |
3645
7f950533d510
(svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents:
3636
diff
changeset
|
1066 |
return GetTileZ(tile) <= TILE_HEIGHT * 4; |
0 | 1067 |
} |
1068 |
||
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1069 |
typedef bool CheckNewIndustryProc(TileIndex tile); |
3663
548dfb4ad4cc
(svn r4578) CodeChange : Cleanup of industry_cmd (Step-2).
belugas
parents:
3662
diff
changeset
|
1070 |
static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = { |
0 | 1071 |
CheckNewIndustry_NULL, |
1072 |
CheckNewIndustry_Forest, |
|
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1073 |
CheckNewIndustry_OilRefinery, |
0 | 1074 |
CheckNewIndustry_Farm, |
1075 |
CheckNewIndustry_Plantation, |
|
1076 |
CheckNewIndustry_Water, |
|
1077 |
CheckNewIndustry_Lumbermill, |
|
1078 |
CheckNewIndustry_BubbleGen, |
|
3877
0a298def0202
(svn r4920) Remove parameters, which get only used in certain functions, by splitting those functions.
tron
parents:
3773
diff
changeset
|
1079 |
CheckNewIndustry_OilRig |
0 | 1080 |
}; |
1081 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1082 |
static bool CheckSuitableIndustryPos(TileIndex tile) |
0 | 1083 |
{ |
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1084 |
uint x = TileX(tile); |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
919
diff
changeset
|
1085 |
uint y = TileY(tile); |
0 | 1086 |
|
2639 | 1087 |
if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { |
0 | 1088 |
_error_message = STR_0239_SITE_UNSUITABLE; |
1089 |
return false; |
|
1090 |
} |
|
1091 |
||
1092 |
return true; |
|
1093 |
} |
|
1094 |
||
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1095 |
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type) |
0 | 1096 |
{ |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1097 |
const Town *t; |
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1098 |
const Industry *i; |
0 | 1099 |
|
1100 |
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
|
1101 |
|
2639 | 1102 |
if (_patches.multiple_industry_per_town) return t; |
0 | 1103 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1104 |
FOR_ALL_INDUSTRIES(i) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1105 |
if (i->type == (byte)type && |
0 | 1106 |
i->town == t) { |
1107 |
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; |
|
1108 |
return NULL; |
|
1109 |
} |
|
1110 |
} |
|
1111 |
||
1112 |
return t; |
|
1113 |
} |
|
1114 |
||
3494
ba64f1689870
(svn r4345) -Codechange: Similar to airport tiles, rename _industry_map5_ arrays to _industry_sections
celestar
parents:
3491
diff
changeset
|
1115 |
static const byte _industry_section_bits[] = { |
0 | 1116 |
16, 16, 16, 16, 16, 16, 16, 16, |
1117 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1118 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1119 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1120 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1121 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1122 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
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
|
1123 |
16, 16, 4, 2, 16, 16, 16, 16, |
0 | 1124 |
16, 16, 16, 16, 16, 16, 16, 16, |
1125 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1126 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
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
|
1127 |
16, 4, 2, 16, 16, 16, 16, 16, |
0 | 1128 |
16, 16, 16, 16, 16, 16, 16, 16, |
1129 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1130 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1131 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1132 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1133 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1134 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1135 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1136 |
16, 16, 16, 16, 16, 16, 16, 16, |
|
1137 |
16, 16, 16, 16, 16, 16, 16, |
|
1138 |
}; |
|
1139 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1140 |
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type) |
0 | 1141 |
{ |
1142 |
_error_message = STR_0239_SITE_UNSUITABLE; |
|
1143 |
||
1144 |
do { |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1145 |
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1146 |
|
0 | 1147 |
if (!IsValidTile(cur_tile)) { |
3440 | 1148 |
if (it->gfx == 0xff) continue; |
0 | 1149 |
return false; |
1150 |
} |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1151 |
|
3440 | 1152 |
if (it->gfx == 0xFF) { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1153 |
if (!IsTileType(cur_tile, MP_WATER) || |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1154 |
GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1155 |
return false; |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1156 |
} |
0 | 1157 |
} else { |
2639 | 1158 |
if (!EnsureNoVehicle(cur_tile)) return false; |
0 | 1159 |
|
1160 |
if (type == IT_OIL_RIG) { |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1161 |
if (!IsTileType(cur_tile, MP_WATER) || _m[cur_tile].m5 != 0) return false; |
0 | 1162 |
} else { |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1163 |
Slope tileh; |
0 | 1164 |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1165 |
if (IsTileType(cur_tile, MP_WATER) && _m[cur_tile].m5 == 0) return false; |
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1166 |
|
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1167 |
tileh = GetTileSlope(cur_tile, NULL); |
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3585
diff
changeset
|
1168 |
if (IsSteepSlope(tileh)) return false; |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1169 |
|
4301
848438a6cb16
(svn r5948) -Fix: inversed check caused oringal land-generator to put industries on mountains (tnx Darkvater)
truelight
parents:
4300
diff
changeset
|
1170 |
if (_patches.land_generator != LG_TERRAGENESIS || !_generating_world) { |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1171 |
/* It is almost impossible to have a fully flat land in TG, so what we |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1172 |
* do is that we check if we can make the land flat later on. See |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1173 |
* CheckIfCanLevelIndustryPlatform(). */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1174 |
if (tileh != SLOPE_FLAT) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1175 |
Slope t; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1176 |
byte bits = _industry_section_bits[it->gfx]; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1177 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1178 |
if (bits & 0x10) return false; |
0 | 1179 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1180 |
t = ComplementSlope(tileh); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1181 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1182 |
if (bits & 1 && (t & SLOPE_NW)) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1183 |
if (bits & 2 && (t & SLOPE_NE)) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1184 |
if (bits & 4 && (t & SLOPE_SW)) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1185 |
if (bits & 8 && (t & SLOPE_SE)) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1186 |
} |
0 | 1187 |
} |
1188 |
||
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
|
1189 |
if (type == IT_BANK_TEMP) { |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1190 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
0 | 1191 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1192 |
return false; |
|
1193 |
} |
|
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
|
1194 |
} else if (type == IT_BANK_TROPIC_ARCTIC) { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1195 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
0 | 1196 |
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1197 |
return false; |
|
1198 |
} |
|
1199 |
} else if (type == IT_TOY_SHOP) { |
|
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1200 |
if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear; |
0 | 1201 |
} else if (type == IT_WATER_TOWER) { |
3296
34064bbe27a5
(svn r4027) Remove another call to FindLandscapeHeightByTile()
tron
parents:
3291
diff
changeset
|
1202 |
if (!IsTileType(cur_tile, MP_HOUSE)) { |
0 | 1203 |
_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS; |
1204 |
return false; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1205 |
} |
0 | 1206 |
} else { |
1207 |
do_clear: |
|
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
1208 |
if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) |
0 | 1209 |
return false; |
1210 |
} |
|
1211 |
} |
|
1212 |
} |
|
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1213 |
} while ((++it)->ti.x != -0x80); |
0 | 1214 |
|
1215 |
return true; |
|
1216 |
} |
|
1217 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1218 |
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1219 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1220 |
if (type == IT_BANK_TEMP && t->population < 1200) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1221 |
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1222 |
return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1223 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1224 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1225 |
if (type == IT_TOY_SHOP && DistanceMax(t->xy, tile) > 9) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1226 |
_error_message = STR_0239_SITE_UNSUITABLE; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1227 |
return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1228 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1229 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1230 |
return true; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1231 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1232 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1233 |
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1234 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1235 |
int size_x, size_y; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1236 |
uint curh; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1237 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1238 |
size_x = 2; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1239 |
size_y = 2; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1240 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1241 |
/* Check if we don't leave the map */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1242 |
if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1243 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1244 |
tile += TileDiffXY(-1, -1); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1245 |
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1246 |
curh = TileHeight(tile_walk); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1247 |
/* Is the tile clear? */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1248 |
if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1249 |
return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1250 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1251 |
/* Don't allow too big of a change if this is the sub-tile check */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1252 |
if (internal != 0 && myabs(curh - height) > 1) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1253 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1254 |
/* Different height, so the surrounding tiles of this tile |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1255 |
* has to be correct too (in level, or almost in level) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1256 |
* else you get a chain-reaction of terraforming. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1257 |
if (internal == 0 && curh != height) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1258 |
if (!CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1)) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1259 |
return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1260 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1261 |
} END_TILE_LOOP(tile_walk, size_x, size_y, tile); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1262 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1263 |
return true; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1264 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1265 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1266 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1267 |
* This function tries to flatten out the land below an industry, without |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1268 |
* damaging the surroundings too much. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1269 |
*/ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1270 |
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable* it, int type) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1271 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1272 |
const int MKEND = -0x80; // used for last element in an IndustryTileTable (see build_industry.h) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1273 |
int max_x = 0; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1274 |
int max_y = 0; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1275 |
TileIndex cur_tile; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1276 |
uint size_x, size_y; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1277 |
uint h, curh; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1278 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1279 |
/* Finds dimensions of largest variant of this industry */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1280 |
do { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1281 |
if (it->ti.x > max_x) max_x = it->ti.x; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1282 |
if (it->ti.y > max_y) max_y = it->ti.y; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1283 |
} while ((++it)->ti.x != MKEND); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1284 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1285 |
/* Remember level height */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1286 |
h = TileHeight(tile); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1287 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1288 |
/* Check that all tiles in area and surrounding are clear |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1289 |
* this determines that there are no obstructing items */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1290 |
cur_tile = tile + TileDiffXY(-1, -1); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1291 |
size_x = max_x + 4; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1292 |
size_y = max_y + 4; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1293 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1294 |
/* Check if we don't leave the map */ |
4313
fc428e434474
(svn r5966) -Fix: prevent that the industry placement's terraforming checks can leave the map on the southern side
rubidium
parents:
4301
diff
changeset
|
1295 |
if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1296 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1297 |
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1298 |
curh = TileHeight(tile_walk); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1299 |
if (curh != h) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1300 |
/* This tile needs terraforming. Check if we can do that without |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1301 |
* damaging the surroundings too much. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1302 |
if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1303 |
/* This is not 100% correct check, but the best we can do without modifying the map. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1304 |
* What is missing, is if the difference in height is more than 1.. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1305 |
if (CmdFailed(DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1306 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1307 |
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1308 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1309 |
if (flags & DC_EXEC) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1310 |
/* Terraform the land under the industry */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1311 |
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1312 |
curh = TileHeight(tile_walk); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1313 |
while (curh != h) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1314 |
/* We give the terraforming for free here, because we can't calculate |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1315 |
* exact cost in the test-round, and as we all know, that will cause |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1316 |
* a nice assert if they don't match ;) */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1317 |
DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1318 |
curh += (curh > h) ? -1 : 1; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1319 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1320 |
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1321 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1322 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1323 |
return true; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1324 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1325 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1326 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1327 |
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) |
0 | 1328 |
{ |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1329 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1330 |
const Industry *i; |
0 | 1331 |
|
1332 |
// accepting industries won't be close, not even with patch |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1333 |
if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID) |
0 | 1334 |
return true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1335 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1336 |
FOR_ALL_INDUSTRIES(i) { |
0 | 1337 |
// check if an industry that accepts the same goods is nearby |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1338 |
if (DistanceMax(tile, i->xy) <= 14 && |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1339 |
indspec->accepts_cargo[0] != CT_INVALID && |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1340 |
indspec->accepts_cargo[0] == i->accepts_cargo[0] && ( |
2639 | 1341 |
_game_mode != GM_EDITOR || |
1342 |
!_patches.same_industry_close || |
|
1343 |
!_patches.multiple_industry_per_town |
|
1344 |
)) { |
|
1345 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
|
1346 |
return false; |
|
1347 |
} |
|
0 | 1348 |
|
1349 |
// check "not close to" field. |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1350 |
if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) && |
1245
3822f77cbc53
(svn r1749) Move the functions which calculate distances to map.[ch] and give the more meaningful names
tron
parents:
1214
diff
changeset
|
1351 |
DistanceMax(tile, i->xy) <= 14) { |
0 | 1352 |
_error_message = STR_INDUSTRY_TOO_CLOSE; |
1353 |
return false; |
|
1354 |
} |
|
1355 |
} |
|
1356 |
return true; |
|
1357 |
} |
|
1358 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1359 |
static Industry *AllocateIndustry(void) |
0 | 1360 |
{ |
1361 |
Industry *i; |
|
1362 |
||
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1363 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1364 |
* TODO - This is just a temporary stage, this will be removed. */ |
4976
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1365 |
for (i = GetIndustry(0); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1366 |
IndustryID index = i->index; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1367 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1368 |
if (IsValidIndustry(i)) continue; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1369 |
|
4357
aaba385fa723
(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents:
4356
diff
changeset
|
1370 |
if (i->index >= _total_industries) _total_industries = i->index + 1; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1371 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1372 |
memset(i, 0, sizeof(*i)); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1373 |
i->index = index; |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1374 |
|
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1375 |
return i; |
0 | 1376 |
} |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1377 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1378 |
/* Check if we can add a block to the pool */ |
4976
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1379 |
return AddBlockToPool(&_Industry_pool) ? AllocateIndustry() : NULL; |
0 | 1380 |
} |
1381 |
||
3662
d9683fb55b45
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
belugas
parents:
3661
diff
changeset
|
1382 |
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner) |
0 | 1383 |
{ |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1384 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
0 | 1385 |
uint32 r; |
1386 |
int j; |
|
1387 |
||
1388 |
i->xy = tile; |
|
1389 |
i->width = i->height = 0; |
|
1390 |
i->type = type; |
|
1391 |
||
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1392 |
i->produced_cargo[0] = indspec->produced_cargo[0]; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1393 |
i->produced_cargo[1] = indspec->produced_cargo[1]; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1394 |
i->accepts_cargo[0] = indspec->accepts_cargo[0]; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1395 |
i->accepts_cargo[1] = indspec->accepts_cargo[1]; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1396 |
i->accepts_cargo[2] = indspec->accepts_cargo[2]; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1397 |
i->production_rate[0] = indspec->production_rate[0]; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1398 |
i->production_rate[1] = indspec->production_rate[1]; |
0 | 1399 |
|
1400 |
if (_patches.smooth_economy) { |
|
1401 |
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); |
|
1402 |
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); |
|
1403 |
} |
|
1404 |
||
1405 |
i->town = t; |
|
1406 |
i->owner = owner; |
|
1407 |
||
2484
0e45d70ae908
(svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents:
2469
diff
changeset
|
1408 |
r = Random(); |
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
1409 |
i->random_color = GB(r, 8, 4); |
2492
b4785c8f3700
(svn r3018) -Fix: Fixed industry colour issue introduced in r3010.
peter1138
parents:
2484
diff
changeset
|
1410 |
i->counter = GB(r, 0, 12); |
0 | 1411 |
i->cargo_waiting[0] = 0; |
1412 |
i->cargo_waiting[1] = 0; |
|
1413 |
i->last_mo_production[0] = 0; |
|
1414 |
i->last_mo_production[1] = 0; |
|
1415 |
i->last_mo_transported[0] = 0; |
|
1416 |
i->last_mo_transported[1] = 0; |
|
1417 |
i->pct_transported[0] = 0; |
|
1418 |
i->pct_transported[1] = 0; |
|
1419 |
i->total_transported[0] = 0; |
|
1420 |
i->total_transported[1] = 0; |
|
1421 |
i->was_cargo_delivered = false; |
|
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1422 |
i->last_prod_year = _cur_year; |
0 | 1423 |
i->total_production[0] = i->production_rate[0] * 8; |
1424 |
i->total_production[1] = i->production_rate[1] * 8; |
|
1425 |
||
2639 | 1426 |
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
|
1427 |
|
0 | 1428 |
i->prod_level = 0x10; |
1429 |
||
1430 |
do { |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
1431 |
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); |
0 | 1432 |
|
3440 | 1433 |
if (it->gfx != 0xFF) { |
0 | 1434 |
byte size; |
1435 |
||
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1436 |
size = it->ti.x; |
0 | 1437 |
if (size > i->width) i->width = size; |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1438 |
size = it->ti.y; |
0 | 1439 |
if (size > i->height)i->height = size; |
1440 |
||
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
1441 |
DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); |
0 | 1442 |
|
3440 | 1443 |
MakeIndustry(cur_tile, i->index, it->gfx); |
3320 | 1444 |
if (_generating_world) _m[cur_tile].m1 = 0x1E; /* maturity */ |
0 | 1445 |
} |
909
65cdb609b7a6
(svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents:
889
diff
changeset
|
1446 |
} while ((++it)->ti.x != -0x80); |
0 | 1447 |
|
1448 |
i->width++; |
|
1449 |
i->height++; |
|
1450 |
||
1451 |
if (i->type == IT_FARM || i->type == IT_FARM_2) { |
|
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
|
1452 |
for (j = 0; j != 50; j++) PlantRandomFarmField(i); |
0 | 1453 |
} |
1454 |
_industry_sort_dirty = true; |
|
1455 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1456 |
} |
|
1457 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1458 |
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, const IndustryTileTable *it) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1459 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1460 |
const Town *t; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1461 |
Industry *i; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1462 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1463 |
if (!CheckIfIndustryTilesAreFree(tile, it, type)) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1464 |
if (_patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1465 |
if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1466 |
if (!CheckIfTooCloseToIndustry(tile, type)) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1467 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1468 |
t = CheckMultipleIndustryInTown(tile, type); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1469 |
if (t == NULL) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1470 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1471 |
if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1472 |
if (!CheckSuitableIndustryPos(tile)) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1473 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1474 |
i = AllocateIndustry(); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1475 |
if (i == NULL) return NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1476 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1477 |
if (flags & DC_EXEC) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1478 |
CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1479 |
DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1480 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1481 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1482 |
return i; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1483 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1484 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1485 |
/** Build/Fund an industry |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
1486 |
* @param tile tile where industry is built |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1487 |
* @param p1 industry type @see build_industry.h and @see industry.h |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1488 |
* @param p2 unused |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1489 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3447
diff
changeset
|
1490 |
int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 1491 |
{ |
1492 |
int num; |
|
1493 |
const IndustryTileTable * const *itt; |
|
1494 |
const IndustryTileTable *it; |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1495 |
const IndustrySpec *indspec; |
0 | 1496 |
|
1497 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
|
1498 |
||
4965
a09db997a1f3
(svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents:
4942
diff
changeset
|
1499 |
indspec = GetIndustrySpec(p1); |
2639 | 1500 |
|
4965
a09db997a1f3
(svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents:
4942
diff
changeset
|
1501 |
/* Check if the to-be built/founded industry is available for this climate. */ |
a09db997a1f3
(svn r6965) -CodeChange : Add a climate bitmask member to IndutrySpec.
belugas
parents:
4942
diff
changeset
|
1502 |
if (!HASBIT(indspec->climate_availability, _opt_ptr->landscape)) return CMD_ERROR; |
0 | 1503 |
|
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1504 |
/* If the patch for raw-material industries is not on, you cannot build raw-material industries. |
1800
1324958d7c73
(svn r2304) - Fix (regression): excuse the Lumber mill from the list of raw-industries build-restriction, as it can be built always, patch-setting, or no patch-setting.
Darkvater
parents:
1786
diff
changeset
|
1505 |
* Raw material industries are industries that do not accept cargo (at least for now) |
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1506 |
* Exclude the lumber mill (only "raw" industry that can be built) */ |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1507 |
if (!_patches.build_rawmaterial_ind && |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1508 |
indspec->accepts_cargo[0] == CT_INVALID && |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1509 |
indspec->accepts_cargo[1] == CT_INVALID && |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1510 |
indspec->accepts_cargo[2] == CT_INVALID && |
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1511 |
p1 != IT_LUMBER_MILL) { |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1512 |
return CMD_ERROR; |
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1513 |
} |
0 | 1514 |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1515 |
num = indspec->num_table; |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1516 |
itt = indspec->table; |
0 | 1517 |
|
1518 |
do { |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1603
diff
changeset
|
1519 |
if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1520 |
} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1)); |
0 | 1521 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1522 |
if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1523 |
|
3689
50a3fd4ba752
(svn r4614) CodeChange : Cleanup of industry_cmd (Step-4).
belugas
parents:
3669
diff
changeset
|
1524 |
return (_price.build_industry >> 5) * indspec->cost_multiplier; |
0 | 1525 |
} |
1526 |
||
1527 |
||
3538
750c4ea83357
(svn r4399) CodeChange : Add and make use of [G|S]etIndustryAnimationLoop accessors.
belugas
parents:
3499
diff
changeset
|
1528 |
Industry *CreateNewIndustry(TileIndex tile, IndustryType type) |
0 | 1529 |
{ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1530 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1531 |
const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)]; |
0 | 1532 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1533 |
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it); |
0 | 1534 |
} |
1535 |
||
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1536 |
static const byte _numof_industry_table[4][12] = { |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1537 |
// difficulty settings for number of industries |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1538 |
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //none |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1539 |
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, //low |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1540 |
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, //normal |
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1541 |
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, //high |
0 | 1542 |
}; |
1543 |
||
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1544 |
static void PlaceInitialIndustry(IndustryType type, int amount) |
0 | 1545 |
{ |
2072
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1546 |
int num = _numof_industry_table[_opt.diff.number_industries][amount]; |
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1547 |
|
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1548 |
if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) { |
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1549 |
// These are always placed next to the coastline, so we scale by the perimeter instead. |
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1550 |
num = ScaleByMapSize1D(num); |
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1551 |
} else { |
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1552 |
num = ScaleByMapSize(num); |
66d208875eda
(svn r2582) Fix: Prevent generating unrealistically many Oil refineries on large maps. They are always placed next to the borderline, so the perimeter is used instead of area to scale the number of those industries.
ludde
parents:
2070
diff
changeset
|
1553 |
} |
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1554 |
|
2639 | 1555 |
if (_opt.diff.number_industries != 0) { |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1556 |
PlayerID old_player = _current_player; |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1557 |
_current_player = OWNER_NONE; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1558 |
assert(num > 0); |
0 | 1559 |
|
1560 |
do { |
|
2639 | 1561 |
uint i; |
1562 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1563 |
IncreaseGeneratingWorldProgress(GWP_INDUSTRY); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1564 |
|
2639 | 1565 |
for (i = 0; i < 2000; i++) { |
1566 |
if (CreateNewIndustry(RandomTile(), type) != NULL) break; |
|
1567 |
} |
|
110
a22a6b07904b
(svn r111) -Fix: converted all linebreaks to UNIX-linebreak (\n)
truelight
parents:
61
diff
changeset
|
1568 |
} while (--num); |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1569 |
|
267 | 1570 |
_current_player = old_player; |
61
cd2827156f2a
(svn r62) - Added "None" as option for number of industries in difficulty settings
orudge
parents:
43
diff
changeset
|
1571 |
} |
0 | 1572 |
} |
1573 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1574 |
void GenerateIndustries(void) |
0 | 1575 |
{ |
1576 |
const byte *b; |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1577 |
uint i = 0; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1578 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1579 |
/* Find the total amount of industries */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1580 |
b = _industry_create_table[_opt.landscape]; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1581 |
do { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1582 |
int num = _numof_industry_table[_opt.diff.number_industries][b[0]]; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1583 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1584 |
if (b[1] == IT_OIL_REFINERY || b[1] == IT_OIL_RIG) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1585 |
/* These are always placed next to the coastline, so we scale by the perimeter instead. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1586 |
num = ScaleByMapSize1D(num); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1587 |
} else { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1588 |
num = ScaleByMapSize(num); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1589 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1590 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1591 |
i += num; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1592 |
} while ( (b+=2)[0] != 0); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
1593 |
SetGeneratingWorldProgress(GWP_INDUSTRY, i); |
0 | 1594 |
|
1595 |
b = _industry_create_table[_opt.landscape]; |
|
1596 |
do { |
|
1597 |
PlaceInitialIndustry(b[1], b[0]); |
|
1598 |
} while ( (b+=2)[0] != 0); |
|
1599 |
} |
|
1600 |
||
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1601 |
/* Change industry production or do closure */ |
0 | 1602 |
static void ExtChangeIndustryProduction(Industry *i) |
1603 |
{ |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1604 |
bool closeit = true; |
0 | 1605 |
int j; |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1606 |
const IndustrySpec *indspec = GetIndustrySpec(i->type); |
0 | 1607 |
|
4924
b6fa01b5a80d
(svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents:
4815
diff
changeset
|
1608 |
switch (indspec->life_type) { |
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1609 |
case INDUSTRYLIFE_NOT_CLOSABLE: |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1610 |
return; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1611 |
|
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1612 |
case INDUSTRYLIFE_CLOSABLE: |
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1613 |
if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180)) |
0 | 1614 |
closeit = false; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1615 |
break; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1616 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1617 |
default: /* INDUSTRY_PRODUCTION */ |
2638
0811adaec525
(svn r3180) Replace some magic numbers by symbolic names
tron
parents:
2637
diff
changeset
|
1618 |
for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){ |
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1619 |
uint32 r = Random(); |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1620 |
int old, new, percent; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1621 |
int mag; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1622 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1623 |
new = old = i->production_rate[j]; |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1624 |
if (CHANCE16I(20, 1024, r)) |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1625 |
new -= ((RandomRange(50) + 10) * old) >> 8; |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1626 |
if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16)) |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1627 |
new += ((RandomRange(50) + 10) * old) >> 8; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1628 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1629 |
new = clamp(new, 0, 255); |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1630 |
if (new == old) { |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1631 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1632 |
continue; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1633 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1634 |
|
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1635 |
percent = new * 100 / old - 100; |
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1636 |
i->production_rate[j] = new; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1637 |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1638 |
if (new >= indspec->production_rate[j] / 4) |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1639 |
closeit = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1640 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1641 |
mag = abs(percent); |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1642 |
if (mag >= 10) { |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1643 |
SetDParam(2, mag); |
1603
8d6b33f98493
(svn r2107) - Codechange: Cleanup (well, mostly tidyup) ExtChangeIndustryProduction(). These randoms are strange.
pasky
parents:
1586
diff
changeset
|
1644 |
SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]); |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1645 |
SetDParam(1, i->index); |
2639 | 1646 |
AddNewsItem( |
1647 |
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, |
|
1648 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), |
|
1649 |
i->xy + TileDiffXY(1, 1), 0 |
|
1650 |
); |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1651 |
} |
0 | 1652 |
} |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1653 |
break; |
0 | 1654 |
} |
1655 |
||
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1656 |
/* If industry will be closed down, show this */ |
0 | 1657 |
if (closeit) { |
1658 |
i->prod_level = 0; |
|
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1659 |
SetDParam(0, i->index); |
2639 | 1660 |
AddNewsItem( |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1661 |
indspec->closure_text, |
2639 | 1662 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), |
1663 |
i->xy + TileDiffXY(1, 1), 0 |
|
1664 |
); |
|
0 | 1665 |
} |
1666 |
} |
|
1667 |
||
1668 |
||
1669 |
static void UpdateIndustryStatistics(Industry *i) |
|
1670 |
{ |
|
1671 |
byte pct; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1672 |
|
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1673 |
if (i->produced_cargo[0] != CT_INVALID) { |
0 | 1674 |
pct = 0; |
1675 |
if (i->last_mo_production[0] != 0) { |
|
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1676 |
i->last_prod_year = _cur_year; |
0 | 1677 |
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
|
1678 |
} |
0 | 1679 |
i->pct_transported[0] = pct; |
1680 |
||
1681 |
i->total_production[0] = i->last_mo_production[0]; |
|
1682 |
i->last_mo_production[0] = 0; |
|
1683 |
||
1684 |
i->total_transported[0] = i->last_mo_transported[0]; |
|
1685 |
i->last_mo_transported[0] = 0; |
|
1686 |
} |
|
1687 |
||
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1688 |
if (i->produced_cargo[1] != CT_INVALID) { |
0 | 1689 |
pct = 0; |
1690 |
if (i->last_mo_production[1] != 0) { |
|
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1691 |
i->last_prod_year = _cur_year; |
0 | 1692 |
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
|
1693 |
} |
0 | 1694 |
i->pct_transported[1] = pct; |
1695 |
||
1696 |
i->total_production[1] = i->last_mo_production[1]; |
|
1697 |
i->last_mo_production[1] = 0; |
|
1698 |
||
1699 |
i->total_transported[1] = i->last_mo_transported[1]; |
|
1700 |
i->last_mo_transported[1] = 0; |
|
1701 |
} |
|
1702 |
||
1703 |
||
2469
59a0073914d8
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents:
2436
diff
changeset
|
1704 |
if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID) |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1705 |
InvalidateWindow(WC_INDUSTRY_VIEW, i->index); |
0 | 1706 |
|
2639 | 1707 |
if (i->prod_level == 0) { |
0 | 1708 |
DeleteIndustry(i); |
2639 | 1709 |
} else if (_patches.smooth_economy) { |
0 | 1710 |
ExtChangeIndustryProduction(i); |
2639 | 1711 |
} |
0 | 1712 |
} |
1713 |
||
1714 |
static const byte _new_industry_rand[4][32] = { |
|
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
|
1715 |
{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}, |
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
|
1716 |
{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}, |
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
|
1717 |
{21, 21, 21, 24, 22, 22, 22, 22, 23, 23, 16, 16, 16, 4, 4, 19, 19, 19, 13, 13, 20, 20, 20, 11, 11, 11, 17, 17, 17, 10, 10, 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
|
1718 |
{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}, |
0 | 1719 |
}; |
1720 |
||
1721 |
static void MaybeNewIndustry(uint32 r) |
|
1722 |
{ |
|
1723 |
int type; |
|
1724 |
int j; |
|
1725 |
Industry *i; |
|
1726 |
||
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2133
diff
changeset
|
1727 |
type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)]; |
0 | 1728 |
|
4297
d0311b62255c
(svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents:
4293
diff
changeset
|
1729 |
if (type == IT_OIL_WELL && _cur_year > 1950) return; |
d0311b62255c
(svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents:
4293
diff
changeset
|
1730 |
if (type == IT_OIL_RIG && _cur_year < 1960) return; |
0 | 1731 |
|
1732 |
j = 2000; |
|
2639 | 1733 |
for (;;) { |
2637
722dae65c4a8
(svn r3179) - RandomRange() and RandomTile() instead of home brewed versions
tron
parents:
2630
diff
changeset
|
1734 |
i = CreateNewIndustry(RandomTile(), type); |
2639 | 1735 |
if (i != NULL) break; |
1736 |
if (--j == 0) return; |
|
0 | 1737 |
} |
1738 |
||
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
1739 |
SetDParam(0, GetIndustrySpec(type)->name); |
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1740 |
SetDParam(1, i->town->index); |
2260
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1741 |
AddNewsItem( |
3581
2f89648cf9d2
(svn r4467) -Fix: New plantations now cause the correct ".. being planted .." news item (MeusH)
celestar
parents:
3553
diff
changeset
|
1742 |
(type != IT_FOREST && type != IT_FRUIT_PLANTATION && type != IT_RUBBER_PLANTATION && type != IT_COTTON_CANDY) ? |
2260
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1743 |
STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR, |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1744 |
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0 |
10154bc4c650
(svn r2780) Remove some more unused strings and make the use of a few strings more explicit
tron
parents:
2187
diff
changeset
|
1745 |
); |
0 | 1746 |
} |
1747 |
||
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1748 |
static void ChangeIndustryProduction(Industry *i) |
0 | 1749 |
{ |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1750 |
bool only_decrease = false; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1751 |
StringID str = STR_NULL; |
0 | 1752 |
int type = i->type; |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1753 |
const IndustrySpec *indspec = GetIndustrySpec(type); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1754 |
|
4924
b6fa01b5a80d
(svn r6904) -CodeChange : Cleanup of industry_cmd (Step-5).
belugas
parents:
4815
diff
changeset
|
1755 |
switch (indspec->life_type) { |
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1756 |
case INDUSTRYLIFE_NOT_CLOSABLE: |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1757 |
return; |
0 | 1758 |
|
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1759 |
case INDUSTRYLIFE_PRODUCTION: |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1760 |
/* decrease or increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1761 |
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1762 |
only_decrease = true; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1763 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1764 |
if (only_decrease || CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1765 |
/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1766 |
if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1767 |
/* Increase production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1768 |
if (i->prod_level != 0x80) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1769 |
byte b; |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
159
diff
changeset
|
1770 |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1771 |
i->prod_level <<= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1772 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1773 |
b = i->production_rate[0] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1774 |
if (i->production_rate[0] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1775 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1776 |
i->production_rate[0] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1777 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1778 |
b = i->production_rate[1] * 2; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1779 |
if (i->production_rate[1] >= 128) |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1780 |
b = 0xFF; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1781 |
i->production_rate[1] = b; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1782 |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1783 |
str = indspec->production_up_text; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1784 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1785 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1786 |
/* Decrease production */ |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1787 |
if (i->prod_level == 4) { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1788 |
i->prod_level = 0; |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1789 |
str = indspec->closure_text; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1790 |
} else { |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1791 |
i->prod_level >>= 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1792 |
i->production_rate[0] = (i->production_rate[0] + 1) >> 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1793 |
i->production_rate[1] = (i->production_rate[1] + 1) >> 1; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1794 |
|
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1795 |
str = indspec->production_down_text; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1796 |
} |
0 | 1797 |
} |
1798 |
} |
|
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1799 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1800 |
|
3496
0959ead7c2af
(svn r4347) CodeChange : Renamed IndustryType to IndustryLifeType. Cleanup step toward bringing accessors [G|S]etIndustrype
belugas
parents:
3495
diff
changeset
|
1801 |
case INDUSTRYLIFE_CLOSABLE: |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1802 |
/* maybe close */ |
4329
0e6e689f66e7
(svn r6002) -Cleanup: remove the now redundant BASE_YEAR constant.
rubidium
parents:
4328
diff
changeset
|
1803 |
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) { |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1804 |
i->prod_level = 0; |
3669
753648f181a0
(svn r4584) CodeChange : Cleanup of industry_cmd (Step-3).
belugas
parents:
3663
diff
changeset
|
1805 |
str = indspec->closure_text; |
1320
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1806 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1807 |
break; |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1808 |
} |
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1809 |
|
44a8658d88c0
(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable
truelight
parents:
1287
diff
changeset
|
1810 |
if (str != STR_NULL) { |
2070
47b1f29d4671
(svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents:
2061
diff
changeset
|
1811 |
SetDParam(0, i->index); |
1981 | 1812 |
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0); |
0 | 1813 |
} |
1814 |
} |
|
1815 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1816 |
void IndustryMonthlyLoop(void) |
0 | 1817 |
{ |
1818 |
Industry *i; |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2493
diff
changeset
|
1819 |
PlayerID old_player = _current_player; |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1820 |
_current_player = OWNER_NONE; |
0 | 1821 |
|
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1822 |
FOR_ALL_INDUSTRIES(i) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1823 |
UpdateIndustryStatistics(i); |
0 | 1824 |
} |
1825 |
||
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1826 |
/* 3% chance that we start a new industry */ |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1827 |
if (CHANCE16(3, 100)) { |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1828 |
MaybeNewIndustry(Random()); |
4354
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4346
diff
changeset
|
1829 |
} else if (!_patches.smooth_economy && GetIndustryArraySize() > 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
|
1830 |
i = GetRandomIndustry(); |
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
|
1831 |
if (i != NULL) ChangeIndustryProduction(i); |
0 | 1832 |
} |
266
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1833 |
|
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1834 |
_current_player = old_player; |
b914f2b7da78
(svn r272) -Fix: industries are once again generated on a new map
darkvater
parents:
201
diff
changeset
|
1835 |
|
0 | 1836 |
// production-change |
1837 |
_industry_sort_dirty = true; |
|
1838 |
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); |
|
1839 |
} |
|
1840 |
||
1841 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1842 |
void InitializeIndustries(void) |
0 | 1843 |
{ |
4976
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1844 |
CleanPool(&_Industry_pool); |
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1845 |
AddBlockToPool(&_Industry_pool); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1846 |
|
0 | 1847 |
_total_industries = 0; |
1848 |
_industry_sort_dirty = true; |
|
4587
859ab734e211
(svn r6437) -Fix: reset the location of the last sound as that location can be outside the map when you are loading another (smaller) map. Thanks to MeusH for noticing.
rubidium
parents:
4583
diff
changeset
|
1849 |
_industry_sound_tile = 0; |
0 | 1850 |
} |
1851 |
||
1852 |
const TileTypeProcs _tile_type_industry_procs = { |
|
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
|
1853 |
DrawTile_Industry, /* draw_tile_proc */ |
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
|
1854 |
GetSlopeZ_Industry, /* get_slope_z_proc */ |
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
|
1855 |
ClearTile_Industry, /* clear_tile_proc */ |
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4403
diff
changeset
|
1856 |
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */ |
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
|
1857 |
GetTileDesc_Industry, /* get_tile_desc_proc */ |
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
|
1858 |
GetTileTrackStatus_Industry, /* get_tile_track_status_proc */ |
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
|
1859 |
ClickTile_Industry, /* click_tile_proc */ |
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
|
1860 |
AnimateTile_Industry, /* animate_tile_proc */ |
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
|
1861 |
TileLoop_Industry, /* tile_loop_proc */ |
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
|
1862 |
ChangeTileOwner_Industry, /* change_tile_owner_proc */ |
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
|
1863 |
GetProducedCargo_Industry, /* get_produced_cargo_proc */ |
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
|
1864 |
NULL, /* vehicle_enter_tile_proc */ |
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
|
1865 |
GetSlopeTileh_Industry, /* get_slope_tileh_proc */ |
0 | 1866 |
}; |
1867 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1800
diff
changeset
|
1868 |
static const SaveLoad _industry_desc[] = { |
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
|
1869 |
SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 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
|
1870 |
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
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
|
1871 |
SLE_VAR(Industry, width, SLE_UINT8), |
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
|
1872 |
SLE_VAR(Industry, height, SLE_UINT8), |
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
|
1873 |
SLE_REF(Industry, town, REF_TOWN), |
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
|
1874 |
SLE_ARR(Industry, produced_cargo, SLE_UINT8, 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
|
1875 |
SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 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
|
1876 |
SLE_ARR(Industry, production_rate, SLE_UINT8, 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
|
1877 |
SLE_ARR(Industry, accepts_cargo, SLE_UINT8, 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
|
1878 |
SLE_VAR(Industry, prod_level, SLE_UINT8), |
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
|
1879 |
SLE_ARR(Industry, last_mo_production, SLE_UINT16, 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
|
1880 |
SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 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
|
1881 |
SLE_ARR(Industry, pct_transported, SLE_UINT8, 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
|
1882 |
SLE_ARR(Industry, total_production, SLE_UINT16, 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
|
1883 |
SLE_ARR(Industry, total_transported, SLE_UINT16, 2), |
0 | 1884 |
|
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
|
1885 |
SLE_VAR(Industry, counter, SLE_UINT16), |
0 | 1886 |
|
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
|
1887 |
SLE_VAR(Industry, type, SLE_UINT8), |
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
|
1888 |
SLE_VAR(Industry, owner, SLE_UINT8), |
4942
7fb6c39eb421
(svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents:
4924
diff
changeset
|
1889 |
SLE_VAR(Industry, random_color, SLE_UINT8), |
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
|
1890 |
SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 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
|
1891 |
SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION), |
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
|
1892 |
SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8), |
0 | 1893 |
|
1894 |
// reserve extra space in savegame here. (currently 32 bytes) |
|
3222
6de22e06a1e9
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3173
diff
changeset
|
1895 |
SLE_CONDNULL(32, 2, SL_MAX_VERSION), |
0 | 1896 |
|
1897 |
SLE_END() |
|
1898 |
}; |
|
1899 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1900 |
static void Save_INDY(void) |
0 | 1901 |
{ |
1902 |
Industry *ind; |
|
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1903 |
|
0 | 1904 |
// Write the vehicles |
830
36c1366367e4
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
truelight
parents:
817
diff
changeset
|
1905 |
FOR_ALL_INDUSTRIES(ind) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1906 |
SlSetArrayIndex(ind->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1907 |
SlObject(ind, _industry_desc); |
0 | 1908 |
} |
1909 |
} |
|
1910 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1059
diff
changeset
|
1911 |
static void Load_INDY(void) |
0 | 1912 |
{ |
1913 |
int index; |
|
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1914 |
|
0 | 1915 |
_total_industries = 0; |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1916 |
|
0 | 1917 |
while ((index = SlIterateArray()) != -1) { |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1918 |
Industry *i; |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1919 |
|
4976
2e3d5e8ec510
(svn r6979) Use the pool macros for the Industry pool
tron
parents:
4965
diff
changeset
|
1920 |
if (!AddBlockIfNeeded(&_Industry_pool, index)) |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1921 |
error("Industries: failed loading savegame: too many industries"); |
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1922 |
|
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1923 |
i = GetIndustry(index); |
919
544f374ee392
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
909
diff
changeset
|
1924 |
SlObject(i, _industry_desc); |
1267
ba42a505ab8a
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1247
diff
changeset
|
1925 |
|
4357
aaba385fa723
(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
truelight
parents:
4356
diff
changeset
|
1926 |
if (index >= _total_industries) _total_industries = index + 1; |
0 | 1927 |
} |
1928 |
} |
|
1929 |
||
1930 |
const ChunkHandler _industry_chunk_handlers[] = { |
|
1931 |
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST}, |
|
1932 |
}; |