2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2006-03-05 10:19:33 +00:00
|
|
|
#include "clear_map.h"
|
2006-08-22 21:14:45 +00:00
|
|
|
#include "functions.h"
|
2006-03-24 08:00:45 +00:00
|
|
|
#include "industry_map.h"
|
2006-03-26 19:20:15 +00:00
|
|
|
#include "station_map.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2005-07-20 22:05:13 +00:00
|
|
|
#include "table/sprites.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "viewport.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "saveload.h"
|
|
|
|
#include "economy.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2006-04-24 21:10:56 +00:00
|
|
|
#include "table/industry_land.h"
|
|
|
|
#include "table/build_industry.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#include "genworld.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-26 19:51:49 +00:00
|
|
|
void ShowIndustryViewWindow(int industry);
|
|
|
|
void BuildOilRig(TileIndex tile);
|
|
|
|
void DeleteOilRig(TileIndex tile);
|
|
|
|
|
|
|
|
static byte _industry_sound_ctr;
|
|
|
|
static TileIndex _industry_sound_tile;
|
|
|
|
|
2005-02-02 17:30:29 +00:00
|
|
|
enum {
|
|
|
|
/* Max industries: 64000 (8 * 8000) */
|
|
|
|
INDUSTRY_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */
|
|
|
|
INDUSTRY_POOL_MAX_BLOCKS = 8000,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called if a new block is added to the industry-pool
|
|
|
|
*/
|
2006-01-05 12:40:50 +00:00
|
|
|
static void IndustryPoolNewBlock(uint start_item)
|
2005-02-02 17:30:29 +00:00
|
|
|
{
|
|
|
|
Industry *i;
|
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
|
|
|
* TODO - This is just a temporary stage, this will be removed. */
|
|
|
|
for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) i->index = start_item++;
|
2005-02-02 17:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the industry-pool */
|
2006-04-18 18:48:50 +00:00
|
|
|
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, NULL, 0, 0, NULL };
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2006-04-10 21:00:56 +00:00
|
|
|
static const IndustryType _industry_close_mode[IT_END] = {
|
2006-04-10 16:20:47 +00:00
|
|
|
/* COAL_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* POWER_STATION */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
|
/* SAWMILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* FOREST */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* OIL_REFINERY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* OIL_RIG */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* FACTORY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* PRINTING_WORKS */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* STEEL_MILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* FARM */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* COPPER_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* OIL_WELL */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* BANK */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
|
/* FOOD_PROCESS */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* PAPER_MILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* GOLD_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* BANK_2, */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
|
/* DIAMOND_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* IRON_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* FRUIT_PLANTATION */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* RUBBER_PLANTATION */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* WATER_SUPPLY */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* WATER_TOWER */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
|
/* FACTORY_2 */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* FARM_2 */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* LUMBER_MILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* COTTON_CANDY */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* CANDY_FACTORY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* BATTERY_FARM */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* COLA_WELLS */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* TOY_SHOP */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
|
/* TOY_FACTORY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* PLASTIC_FOUNTAINS */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* FIZZY_DRINK_FACTORY */INDUSTRYLIFE_CLOSABLE,
|
|
|
|
/* BUBBLE_GENERATOR */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* TOFFEE_QUARRY */ INDUSTRYLIFE_PRODUCTION,
|
|
|
|
/* SUGAR_MINE */ INDUSTRYLIFE_PRODUCTION
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-04-10 21:00:56 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the type for this industry. Although it is accessed by a tile,
|
|
|
|
* it will return the general type of industry, and not the sprite index
|
|
|
|
* as would do GetIndustryGfx.
|
|
|
|
* The same information can be accessed by looking at Industry->type
|
|
|
|
* @param tile that is queried
|
|
|
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
|
|
|
* @return general type for this industry, as defined in industry.h
|
|
|
|
**/
|
|
|
|
IndustryType GetIndustryType(TileIndex tile)
|
|
|
|
{
|
|
|
|
IndustryGfx this_type = GetIndustryGfx(tile);
|
|
|
|
IndustryType iloop;
|
|
|
|
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
|
|
|
|
for (iloop = IT_COAL_MINE; iloop < IT_END; iloop += 1) {
|
2006-04-14 01:54:07 +00:00
|
|
|
if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
|
2006-04-15 01:06:53 +00:00
|
|
|
industry_gfx_Solver[iloop].MaxGfx+1)) {
|
2006-04-10 21:00:56 +00:00
|
|
|
return iloop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IT_INVALID; //we have not found equivalent, whatever the reason
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 14:58:06 +00:00
|
|
|
/**
|
|
|
|
* Accessor for array _industry_specs.
|
|
|
|
* This will ensure at once : proper access and
|
|
|
|
* not allowing modifications of it.
|
2006-04-26 21:10:01 +00:00
|
|
|
* @param thistype of industry (which is the index in _industry_specs)
|
2006-04-26 14:58:06 +00:00
|
|
|
* @pre thistype < IT_END
|
|
|
|
**/
|
2006-04-28 21:58:16 +00:00
|
|
|
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
|
2006-04-26 14:58:06 +00:00
|
|
|
{
|
|
|
|
assert(thistype < IT_END);
|
|
|
|
return &_industry_specs[thistype];
|
|
|
|
}
|
|
|
|
|
2006-08-26 19:51:49 +00:00
|
|
|
void DestroyIndustry(Industry *i)
|
|
|
|
{
|
|
|
|
BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
|
|
|
|
if (IsTileType(tile_cur, MP_INDUSTRY)) {
|
|
|
|
if (GetIndustryIndex(tile_cur) == i->index) {
|
|
|
|
DoClearSquare(tile_cur);
|
|
|
|
}
|
|
|
|
} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
|
|
|
|
DeleteOilRig(tile_cur);
|
|
|
|
}
|
|
|
|
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
|
|
|
|
|
|
|
|
if (i->type == IT_FARM || i->type == IT_FARM_2) {
|
|
|
|
/* Remove the farmland and convert it to regular tiles over time. */
|
|
|
|
BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
|
|
|
|
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
|
|
|
|
GetIndustryIndexOfField(tile_cur) == i->index) {
|
|
|
|
SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
|
|
|
|
}
|
|
|
|
} END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21))
|
|
|
|
}
|
|
|
|
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
DeleteSubsidyWithIndustry(i->index);
|
|
|
|
DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
|
|
|
|
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void IndustryDrawSugarMine(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const DrawIndustrySpec1Struct *d;
|
|
|
|
uint32 image;
|
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (!IsIndustryCompleted(ti->tile)) return;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
d = &_draw_industry_spec1[_m[ti->tile].m3];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, d->x, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
image = d->image_2;
|
2006-03-21 23:22:21 +00:00
|
|
|
if (image != 0) AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + image - 1, 8, 41);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
image = d->image_3;
|
|
|
|
if (image != 0) {
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + image - 1,
|
2005-11-14 19:48:04 +00:00
|
|
|
_drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void IndustryDrawToffeeQuarry(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int x = 0;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (IsIndustryCompleted(ti->tile)) {
|
2005-07-13 18:04:01 +00:00
|
|
|
x = _industry_anim_offs[_m[ti->tile].m3];
|
2004-08-09 17:04:08 +00:00
|
|
|
if ( (byte)x == 0xFF)
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, 22 - x, 24 + x);
|
|
|
|
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, 6, 14);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void IndustryDrawBubbleGenerator( const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-24 13:46:45 +00:00
|
|
|
if (IsIndustryCompleted(ti->tile)) {
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, 5, _industry_anim_offs_2[_m[ti->tile].m3]);
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, 3, 67);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void IndustryDrawToyFactory(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const DrawIndustrySpec4Struct *d;
|
|
|
|
|
2005-07-13 18:04:01 +00:00
|
|
|
d = &_industry_anim_offs_3[_m[ti->tile].m3];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (d->image_1 != 0xFF) {
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, 50 - d->image_1 * 2, 96 + d->image_1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->image_2 != 0xFF) {
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, 16 - d->image_2 * 2, 100 + d->image_2);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, 7, d->image_3);
|
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, 0, 42);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-24 13:46:45 +00:00
|
|
|
if (IsIndustryCompleted(ti->tile)) {
|
|
|
|
uint image = GB(_m[ti->tile].m1, 2, 5);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (image != 0 && image < 7) {
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
|
|
|
|
_coal_plant_sparks_x[image - 1],
|
|
|
|
_coal_plant_sparks_y[image - 1]
|
2004-08-09 17:04:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
typedef void IndustryDrawTileProc(const TileInfo *ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = {
|
2006-03-21 23:22:21 +00:00
|
|
|
IndustryDrawSugarMine,
|
|
|
|
IndustryDrawToffeeQuarry,
|
|
|
|
IndustryDrawBubbleGenerator,
|
|
|
|
IndustryDrawToyFactory,
|
|
|
|
IndustryDrawCoalPlantSparks,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void DrawTile_Industry(TileInfo *ti)
|
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
const Industry *ind;
|
2006-04-24 21:10:56 +00:00
|
|
|
const DrawBuildingsTileStruct *dits;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte z;
|
|
|
|
uint32 image, ormod;
|
|
|
|
|
|
|
|
/* Pointer to industry */
|
2006-03-24 08:00:45 +00:00
|
|
|
ind = GetIndustryByTile(ti->tile);
|
2006-03-24 18:16:39 +00:00
|
|
|
ormod = GENERAL_SPRITE_COLOR(ind->color_map);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* Retrieve pointer to the draw industry tile struct */
|
2006-04-10 15:09:56 +00:00
|
|
|
dits = &_industry_draw_tile_data[GetIndustryGfx(ti->tile) << 2 | GetIndustryConstructionStage(ti->tile)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-24 21:10:56 +00:00
|
|
|
image = dits->ground;
|
2005-07-24 15:56:31 +00:00
|
|
|
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
image |= ormod;
|
|
|
|
|
|
|
|
z = ti->z;
|
|
|
|
/* Add bricks below the industry? */
|
2006-04-23 13:48:16 +00:00
|
|
|
if (ti->tileh != SLOPE_FLAT) {
|
|
|
|
AddSortableSpriteToDraw(SPR_FOUNDATION_BASE + ti->tileh, ti->x, ti->y, 16, 16, 7, z);
|
2006-03-21 23:22:21 +00:00
|
|
|
AddChildSpriteScreen(image, 31, 1);
|
2006-04-23 19:35:36 +00:00
|
|
|
z += TILE_HEIGHT;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
/* Else draw regular ground */
|
|
|
|
DrawGroundSprite(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add industry on top of the ground? */
|
2006-04-24 21:10:56 +00:00
|
|
|
image = dits->building;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (image != 0) {
|
2005-07-24 15:56:31 +00:00
|
|
|
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
image |= ormod;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
|
|
|
AddSortableSpriteToDraw(image,
|
2005-11-16 11:55:06 +00:00
|
|
|
ti->x + dits->subtile_x,
|
|
|
|
ti->y + dits->subtile_y,
|
|
|
|
dits->width + 1,
|
|
|
|
dits->height + 1,
|
2004-08-09 17:04:08 +00:00
|
|
|
dits->dz,
|
|
|
|
z);
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_display_opt & DO_TRANS_BUILDINGS) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
{
|
2006-04-24 21:10:56 +00:00
|
|
|
int proc = dits->draw_proc - 1;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (proc >= 0) _industry_draw_tile_procs[proc](ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-06 16:32:49 +00:00
|
|
|
static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y)
|
2005-10-19 14:49:46 +00:00
|
|
|
{
|
2006-08-06 16:32:49 +00:00
|
|
|
return GetTileMaxZ(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-23 13:48:16 +00:00
|
|
|
static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh)
|
2005-10-22 06:39:32 +00:00
|
|
|
{
|
2006-04-23 13:48:16 +00:00
|
|
|
return SLOPE_FLAT;
|
2004-08-13 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 21:00:56 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(tile);
|
2005-11-04 16:12:48 +00:00
|
|
|
CargoID a;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 14:27:26 +00:00
|
|
|
a = _industry_section_accepts_1[gfx];
|
2005-11-04 16:12:48 +00:00
|
|
|
if (a != CT_INVALID) ac[a] = (a == 0) ? 1 : 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 14:27:26 +00:00
|
|
|
a = _industry_section_accepts_2[gfx];
|
2005-11-04 16:12:48 +00:00
|
|
|
if (a != CT_INVALID) ac[a] = 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 14:27:26 +00:00
|
|
|
a = _industry_section_accepts_3[gfx];
|
2005-11-04 16:12:48 +00:00
|
|
|
if (a != CT_INVALID) ac[a] = 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
const Industry *i = GetIndustryByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
td->owner = i->owner;
|
|
|
|
td->str = STR_4802_COAL_MINE + i->type;
|
2006-03-24 13:46:45 +00:00
|
|
|
if (!IsIndustryCompleted(tile)) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParamX(td->dparam, 0, td->str);
|
2004-08-09 17:04:08 +00:00
|
|
|
td->str = STR_2058_UNDER_CONSTRUCTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static int32 ClearTile_Industry(TileIndex tile, byte flags)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
Industry *i = GetIndustryByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-28 18:53:03 +00:00
|
|
|
/* water can destroy industries
|
|
|
|
* in editor you can bulldoze industries
|
|
|
|
* with magic_bulldozer cheat you can destroy industries
|
|
|
|
* (area around OILRIG is water, so water shouldn't flood it
|
|
|
|
*/
|
2004-09-03 17:57:27 +00:00
|
|
|
if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
|
|
|
|
!_cheats.magic_bulldozer.value) ||
|
2006-06-27 21:25:53 +00:00
|
|
|
(_current_player == OWNER_WATER && i->type == IT_OIL_RIG)) {
|
|
|
|
SetDParam(0, STR_4802_COAL_MINE + i->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_4800_IN_THE_WAY);
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (flags & DC_EXEC) DeleteIndustry(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TransportIndustryGoods(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
Industry *i = GetIndustryByTile(tile);
|
2006-04-26 21:10:01 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
uint cw, am;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
cw = min(i->cargo_waiting[0], 255);
|
2006-04-26 21:10:01 +00:00
|
|
|
if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
|
2004-08-09 17:04:08 +00:00
|
|
|
i->cargo_waiting[0] -= cw;
|
|
|
|
|
|
|
|
/* fluctuating economy? */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_economy.fluct <= 0) cw = (cw + 1) / 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
i->last_mo_production[0] += cw;
|
|
|
|
|
|
|
|
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
|
|
|
|
i->last_mo_transported[0] += am;
|
2006-03-25 10:38:28 +00:00
|
|
|
if (am != 0) {
|
2006-04-10 14:27:26 +00:00
|
|
|
uint newgfx = _industry_produce_section[GetIndustryGfx(tile)];
|
2006-03-25 10:38:28 +00:00
|
|
|
|
|
|
|
if (newgfx != 0xFF) {
|
2006-04-10 15:09:56 +00:00
|
|
|
ResetIndustryConstructionStage(tile);
|
|
|
|
SetIndustryCompleted(tile, true);
|
2006-03-25 10:38:28 +00:00
|
|
|
SetIndustryGfx(tile, newgfx);
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cw = min(i->cargo_waiting[1], 255);
|
2006-04-26 21:10:01 +00:00
|
|
|
if (cw > indspec->minimal_cargo) {
|
2004-08-09 17:04:08 +00:00
|
|
|
i->cargo_waiting[1] -= cw;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_economy.fluct <= 0) cw = (cw + 1) / 2;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
i->last_mo_production[1] += cw;
|
|
|
|
|
|
|
|
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
|
|
|
|
i->last_mo_transported[1] += am;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void AnimateTile_Industry(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-25 10:38:28 +00:00
|
|
|
byte m;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-25 10:38:28 +00:00
|
|
|
switch (GetIndustryGfx(tile)) {
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_SUGAR_MINE_SIEVE:
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_tick_counter & 1) == 0) {
|
2005-07-13 18:04:01 +00:00
|
|
|
m = _m[tile].m3 + 1;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (m & 7) {
|
2006-08-28 18:53:03 +00:00
|
|
|
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break;
|
2004-12-04 09:26:39 +00:00
|
|
|
case 6: SndPlayTileFx(SND_29_RIP, tile); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m >= 96) {
|
|
|
|
m = 0;
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_TOFFEE_QUARY:
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_tick_counter & 3) == 0) {
|
2005-07-13 18:04:01 +00:00
|
|
|
m = _m[tile].m3;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_industry_anim_offs[m] == 0xFF) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (++m >= 70) {
|
|
|
|
m = 0;
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_BUBBLE_CATCHER:
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_tick_counter&1) == 0) {
|
2005-07-13 18:04:01 +00:00
|
|
|
m = _m[tile].m3;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (++m >= 40) {
|
|
|
|
m = 0;
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Sparks on a coal plant
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_POWERPLANT_SPARKS:
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_tick_counter & 3) == 0) {
|
2005-08-23 18:47:04 +00:00
|
|
|
m = _m[tile].m1;
|
2005-11-16 13:11:28 +00:00
|
|
|
if (GB(m, 2, 5) == 6) {
|
|
|
|
SB(_m[tile].m1, 2, 5, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
} else {
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = m + (1<<2);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_TOY_FACTORY:
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_tick_counter & 1) == 0) {
|
2005-07-13 18:04:01 +00:00
|
|
|
m = _m[tile].m3 + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (m == 1) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_2C_MACHINERY, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (m == 23) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_2B_COMEDY_HIT, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (m == 28) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-12 18:10:54 +00:00
|
|
|
if (m >= 50) {
|
|
|
|
int n = GetIndustryAnimationLoop(tile) + 1;
|
|
|
|
m = 0;
|
|
|
|
if (n >= 8) {
|
|
|
|
n = 0;
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
|
|
|
SetIndustryAnimationLoop(tile, n);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 148: case 149: case 150: case 151:
|
|
|
|
case 152: case 153: case 154: case 155:
|
|
|
|
if ((_tick_counter & 3) == 0) {
|
2006-04-10 21:00:56 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-25 10:38:28 +00:00
|
|
|
gfx = (gfx < 155) ? gfx + 1 : 148;
|
|
|
|
SetIndustryGfx(tile, gfx);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_OILWELL_ANIMATED_1:
|
|
|
|
case GFX_OILWELL_ANIMATED_2:
|
|
|
|
case GFX_OILWELL_ANIMATED_3:
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_tick_counter & 7) == 0) {
|
|
|
|
bool b = CHANCE16(1,7);
|
2006-04-10 21:00:56 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(tile);
|
2006-03-25 10:38:28 +00:00
|
|
|
|
|
|
|
m = GB(_m[tile].m1, 0, 2) + 1;
|
2006-09-08 22:12:57 +00:00
|
|
|
if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = 0x83;
|
2006-09-08 22:12:57 +00:00
|
|
|
SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
|
2004-09-11 09:55:19 +00:00
|
|
|
DeleteAnimatedTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-11-16 13:11:28 +00:00
|
|
|
SB(_m[tile].m1, 0, 2, m);
|
2006-03-25 10:38:28 +00:00
|
|
|
SetIndustryGfx(tile, gfx);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_COAL_MINE_TOWER_ANIMATED:
|
|
|
|
case GFX_COPPER_MINE_TOWER_ANIMATED:
|
|
|
|
case GFX_GOLD_MINE_TOWER_ANIMATED: {
|
2004-08-09 17:04:08 +00:00
|
|
|
int state = _tick_counter & 0x7FF;
|
|
|
|
|
|
|
|
if ((state -= 0x400) < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state < 0x1A0) {
|
|
|
|
if (state < 0x20 || state >= 0x180) {
|
2005-08-23 18:47:04 +00:00
|
|
|
if (!(_m[tile].m1 & 0x40)) {
|
|
|
|
_m[tile].m1 |= 0x40;
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
if (state & 7)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (state & 3)
|
|
|
|
return;
|
|
|
|
}
|
2005-08-23 18:47:04 +00:00
|
|
|
m = (_m[tile].m1 + 1) | 0x40;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (m > 0xC2) m = 0xC0;
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
} else if (state >= 0x200 && state < 0x3A0) {
|
|
|
|
int i;
|
|
|
|
i = (state < 0x220 || state >= 0x380) ? 7 : 3;
|
|
|
|
if (state & i)
|
|
|
|
return;
|
|
|
|
|
2005-08-23 18:47:04 +00:00
|
|
|
m = (_m[tile].m1 & 0xBF) - 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (m < 0x80) m = 0x82;
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = m;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void CreateIndustryEffectSmoke(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-07 07:55:05 +00:00
|
|
|
uint x = TileX(tile) * TILE_SIZE;
|
|
|
|
uint y = TileY(tile) * TILE_SIZE;
|
|
|
|
uint z = GetTileMaxZ(tile);
|
|
|
|
|
|
|
|
CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
static void MakeIndustryTileBigger(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 15:09:56 +00:00
|
|
|
byte cnt = GetIndustryConstructionCounter(tile) + 1;
|
|
|
|
byte stage;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
if (cnt != 4) {
|
|
|
|
SetIndustryConstructionCounter(tile, cnt);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-04-10 15:09:56 +00:00
|
|
|
stage = GetIndustryConstructionStage(tile) + 1;
|
|
|
|
SetIndustryConstructionCounter(tile, 0);
|
|
|
|
SetIndustryConstructionStage(tile, stage);
|
|
|
|
if (stage == 3) {
|
|
|
|
SetIndustryCompleted(tile, true);
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (!IsIndustryCompleted(tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-25 10:38:28 +00:00
|
|
|
switch (GetIndustryGfx(tile)) {
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_POWERPLANT_CHIMNEY:
|
2006-03-21 23:22:21 +00:00
|
|
|
CreateIndustryEffectSmoke(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-15 21:44:55 +00:00
|
|
|
case GFX_OILRIG_1:
|
|
|
|
if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == GFX_OILRIG_1) BuildOilRig(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_TOY_FACTORY:
|
|
|
|
case GFX_BUBBLE_CATCHER:
|
|
|
|
case GFX_TOFFEE_QUARY:
|
2005-07-13 18:04:01 +00:00
|
|
|
_m[tile].m3 = 0;
|
2006-04-12 18:10:54 +00:00
|
|
|
SetIndustryAnimationLoop(tile, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_1:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_2:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_3:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_4:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_5:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_6:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_7:
|
|
|
|
case GFX_PLASTIC_FOUNTAIN_ANIMATED_8:
|
2004-08-09 17:04:08 +00:00
|
|
|
AddAnimatedTile(tile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int dir;
|
|
|
|
Vehicle *v;
|
|
|
|
static const int8 _tileloop_ind_case_161[12] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
11, 0, -4, -14,
|
|
|
|
-4, -10, -4, 1,
|
|
|
|
49, 59, 60, 65,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
dir = Random() & 3;
|
|
|
|
|
|
|
|
v = CreateEffectVehicleAbove(
|
2006-04-03 05:32:11 +00:00
|
|
|
TileX(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 0],
|
|
|
|
TileY(tile) * TILE_SIZE + _tileloop_ind_case_161[dir + 4],
|
2004-08-09 17:04:08 +00:00
|
|
|
_tileloop_ind_case_161[dir + 8],
|
2005-02-12 15:53:32 +00:00
|
|
|
EV_BUBBLE
|
2004-08-09 17:04:08 +00:00
|
|
|
);
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (v != NULL) v->u.special.unk2 = dir;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void TileLoop_Industry(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-10 21:00:56 +00:00
|
|
|
IndustryGfx newgfx;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (!IsIndustryCompleted(tile)) {
|
2006-04-10 15:09:56 +00:00
|
|
|
MakeIndustryTileBigger(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_game_mode == GM_EDITOR) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
TransportIndustryGoods(tile);
|
|
|
|
|
2006-04-10 14:27:26 +00:00
|
|
|
newgfx = _industry_section_animation_next[GetIndustryGfx(tile)];
|
2006-03-25 10:38:28 +00:00
|
|
|
if (newgfx != 255) {
|
2006-04-10 15:09:56 +00:00
|
|
|
ResetIndustryConstructionStage(tile);
|
2006-03-25 10:38:28 +00:00
|
|
|
SetIndustryGfx(tile, newgfx);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-25 10:38:28 +00:00
|
|
|
#define SET_AND_ANIMATE(tile, a, b) { SetIndustryGfx(tile, a); _m[tile].m1 = b; AddAnimatedTile(tile); }
|
|
|
|
#define SET_AND_UNANIMATE(tile, a, b) { SetIndustryGfx(tile, a); _m[tile].m1 = b; DeleteAnimatedTile(tile); }
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-25 10:38:28 +00:00
|
|
|
switch (GetIndustryGfx(tile)) {
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_OILRIG_1: // coast line at oilrigs
|
|
|
|
case GFX_OILRIG_2:
|
|
|
|
case GFX_OILRIG_3:
|
|
|
|
case GFX_OILRIG_4:
|
|
|
|
case GFX_OILRIG_5:
|
2004-08-13 19:52:45 +00:00
|
|
|
TileLoop_Water(tile);
|
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_COAL_MINE_TOWER_NOT_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(_tick_counter & 0x400) && CHANCE16(1,2))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_ANIMATE(tile, GFX_COAL_MINE_TOWER_ANIMATED, 0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(_tick_counter & 0x400) && CHANCE16(1,2))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_ANIMATE(tile, GFX_COPPER_MINE_TOWER_ANIMATED, 0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(_tick_counter & 0x400) && CHANCE16(1,2))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_ANIMATE(tile, GFX_GOLD_MINE_TOWER_ANIMATED, 0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_OILWELL_NOT_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (CHANCE16(1,6))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_ANIMATE(tile, GFX_OILWELL_ANIMATED_1, 0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_COAL_MINE_TOWER_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(_tick_counter & 0x400))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_UNANIMATE(tile, GFX_COAL_MINE_TOWER_NOT_ANIMATED, 0x83);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_COPPER_MINE_TOWER_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(_tick_counter & 0x400))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_UNANIMATE(tile, GFX_COPPER_MINE_TOWER_NOT_ANIMATED, 0x83);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_GOLD_MINE_TOWER_ANIMATED:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!(_tick_counter & 0x400))
|
2006-09-08 22:12:57 +00:00
|
|
|
SET_AND_UNANIMATE(tile, GFX_GOLD_MINE_TOWER_NOT_ANIMATED, 0x83);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_POWERPLANT_SPARKS:
|
2004-08-09 17:04:08 +00:00
|
|
|
if (CHANCE16(1,3)) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddAnimatedTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_COPPER_MINE_CHIMNEY:
|
2006-04-03 05:32:11 +00:00
|
|
|
CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE);
|
2005-11-14 19:48:04 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_TOY_FACTORY: {
|
2006-04-26 14:58:06 +00:00
|
|
|
Industry *i = GetIndustryByTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (i->was_cargo_delivered) {
|
|
|
|
i->was_cargo_delivered = false;
|
2006-04-12 18:10:54 +00:00
|
|
|
SetIndustryAnimationLoop(tile, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
AddAnimatedTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_BUBBLE_GENERATOR:
|
2006-03-21 23:22:21 +00:00
|
|
|
TileLoopIndustry_BubbleGenerator(tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_TOFFEE_QUARY:
|
2004-08-09 17:04:08 +00:00
|
|
|
AddAnimatedTile(tile);
|
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_SUGAR_MINE_SIEVE:
|
2005-11-14 19:48:04 +00:00
|
|
|
if (CHANCE16(1, 3)) AddAnimatedTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void ClickTile_Industry(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-24 08:00:45 +00:00
|
|
|
ShowIndustryViewWindow(GetIndustryIndex(tile));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-26 22:23:32 +00:00
|
|
|
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
const Industry *i = GetIndustryByTile(tile);
|
2005-11-13 13:43:55 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
b[0] = i->produced_cargo[0];
|
|
|
|
b[1] = i->produced_cargo[1];
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
/* not used */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
|
|
|
|
|
2005-01-17 09:41:46 +00:00
|
|
|
static bool IsBadFarmFieldTile(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW);
|
2006-02-01 15:31:21 +00:00
|
|
|
case MP_TREES: return false;
|
|
|
|
default: return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-17 09:41:46 +00:00
|
|
|
static bool IsBadFarmFieldTile2(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2006-04-04 21:35:13 +00:00
|
|
|
case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW);
|
2006-02-01 15:31:21 +00:00
|
|
|
case MP_TREES: return false;
|
|
|
|
default: return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
tile = TILE_MASK(tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
|
2006-02-05 11:54:25 +00:00
|
|
|
byte or = type;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-11-14 09:21:05 +00:00
|
|
|
if (or == 1 && CHANCE16(1, 7)) or = 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
if (direction == AXIS_X) {
|
2006-02-05 11:54:25 +00:00
|
|
|
SetFenceSE(tile, or);
|
2006-03-08 06:55:33 +00:00
|
|
|
} else {
|
|
|
|
SetFenceSW(tile, or);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
} while (--size);
|
|
|
|
}
|
|
|
|
|
2006-08-20 19:31:58 +00:00
|
|
|
static void PlantFarmField(TileIndex tile, IndustryID industry)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint size_x, size_y;
|
|
|
|
uint32 r;
|
2005-07-19 21:49:35 +00:00
|
|
|
uint count;
|
2006-02-05 11:54:25 +00:00
|
|
|
uint counter;
|
|
|
|
uint field_type;
|
|
|
|
int type;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (_opt.landscape == LT_HILLY) {
|
2006-04-03 09:07:21 +00:00
|
|
|
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line)
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine field size */
|
|
|
|
r = (Random() & 0x303) + 0x404;
|
|
|
|
if (_opt.landscape == LT_HILLY) r += 0x404;
|
2005-07-21 06:31:02 +00:00
|
|
|
size_x = GB(r, 0, 8);
|
|
|
|
size_y = GB(r, 8, 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* offset tile to match size */
|
2005-06-25 16:44:57 +00:00
|
|
|
tile -= TileDiffXY(size_x / 2, size_y / 2);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* check the amount of bad tiles */
|
|
|
|
count = 0;
|
|
|
|
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
|
|
|
cur_tile = TILE_MASK(cur_tile);
|
|
|
|
count += IsBadFarmFieldTile(cur_tile);
|
|
|
|
END_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
2005-07-19 21:49:35 +00:00
|
|
|
if (count * 2 >= size_x * size_y) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* determine type of field */
|
|
|
|
r = Random();
|
2006-02-05 11:54:25 +00:00
|
|
|
counter = GB(r, 5, 3);
|
|
|
|
field_type = GB(r, 8, 8) * 9 >> 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* make field */
|
|
|
|
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
|
|
|
cur_tile = TILE_MASK(cur_tile);
|
|
|
|
if (!IsBadFarmFieldTile2(cur_tile)) {
|
2006-08-20 18:44:26 +00:00
|
|
|
MakeField(cur_tile, field_type, industry);
|
2006-02-05 11:54:25 +00:00
|
|
|
SetClearCounter(cur_tile, counter);
|
|
|
|
MarkTileDirtyByTile(cur_tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
END_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
type = 3;
|
|
|
|
if (_opt.landscape != LT_HILLY && _opt.landscape != LT_DESERT) {
|
|
|
|
type = _plantfarmfield_type[Random() & 0xF];
|
|
|
|
}
|
|
|
|
|
2006-03-08 06:55:33 +00:00
|
|
|
SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
|
|
|
|
SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
|
|
|
|
SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y);
|
|
|
|
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-20 18:44:26 +00:00
|
|
|
void PlantRandomFarmField(const Industry *i)
|
|
|
|
{
|
|
|
|
int x = i->width / 2 + Random() % 31 - 16;
|
|
|
|
int y = i->height / 2 + Random() % 31 - 16;
|
|
|
|
|
|
|
|
TileIndex tile = TileAddWrap(i->xy, x, y);
|
|
|
|
|
|
|
|
if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
|
|
|
|
}
|
|
|
|
|
2006-04-26 14:58:06 +00:00
|
|
|
static void MaybePlantFarmField(const Industry *i)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-20 18:44:26 +00:00
|
|
|
if (CHANCE16(1, 8)) PlantRandomFarmField(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ChopLumberMillTrees(Industry *i)
|
|
|
|
{
|
2005-01-06 11:39:00 +00:00
|
|
|
static const TileIndexDiffC _chop_dir[] = {
|
|
|
|
{ 0, 1},
|
|
|
|
{ 1, 0},
|
|
|
|
{ 0, -1},
|
|
|
|
{-1, 0}
|
|
|
|
};
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex tile = i->xy;
|
2005-11-14 19:48:04 +00:00
|
|
|
int a;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (!IsIndustryCompleted(tile)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* search outwards as a rectangular spiral */
|
2005-11-14 19:48:04 +00:00
|
|
|
for (a = 1; a != 41; a += 2) {
|
|
|
|
uint dir;
|
|
|
|
|
|
|
|
for (dir = 0; dir != 4; dir++) {
|
|
|
|
int j = a;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
|
|
|
tile = TILE_MASK(tile);
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_TREES)) {
|
2005-10-07 07:35:15 +00:00
|
|
|
PlayerID old_player = _current_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
/* found a tree */
|
|
|
|
|
|
|
|
_current_player = OWNER_NONE;
|
|
|
|
_industry_sound_ctr = 1;
|
|
|
|
_industry_sound_tile = tile;
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_38_CHAINSAW, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2006-03-30 19:16:44 +00:00
|
|
|
SetTropicZone(tile, TROPICZONE_INVALID);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45);
|
2004-09-25 17:37:32 +00:00
|
|
|
|
|
|
|
_current_player = old_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-01-06 11:39:00 +00:00
|
|
|
tile += ToTileIndexDiff(_chop_dir[dir]);
|
2004-08-09 17:04:08 +00:00
|
|
|
} while (--j);
|
|
|
|
}
|
2005-06-25 16:44:57 +00:00
|
|
|
tile -= TileDiffXY(1, 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _industry_sounds[37][2] = {
|
|
|
|
{0},
|
|
|
|
{0},
|
2004-12-04 09:26:39 +00:00
|
|
|
{1, SND_28_SAWMILL},
|
2004-08-09 17:04:08 +00:00
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
2004-12-04 09:26:39 +00:00
|
|
|
{1, SND_03_FACTORY_WHISTLE},
|
|
|
|
{1, SND_03_FACTORY_WHISTLE},
|
2004-08-09 17:04:08 +00:00
|
|
|
{0},
|
2004-12-04 09:26:39 +00:00
|
|
|
{3, SND_24_SHEEP},
|
2004-08-09 17:04:08 +00:00
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
2004-12-04 09:26:39 +00:00
|
|
|
{1, SND_28_SAWMILL},
|
2004-08-09 17:04:08 +00:00
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
2004-12-04 09:26:39 +00:00
|
|
|
{1, SND_03_FACTORY_WHISTLE},
|
2004-08-09 17:04:08 +00:00
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
2004-12-04 09:26:39 +00:00
|
|
|
{1, SND_33_PLASTIC_MINE},
|
2004-08-09 17:04:08 +00:00
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
{0},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void ProduceIndustryGoods(Industry *i)
|
|
|
|
{
|
|
|
|
uint32 r;
|
|
|
|
uint num;
|
|
|
|
|
|
|
|
/* play a sound? */
|
|
|
|
if ((i->counter & 0x3F) == 0) {
|
|
|
|
if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) {
|
|
|
|
SndPlayTileFx(
|
|
|
|
_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16),
|
|
|
|
i->xy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i->counter--;
|
|
|
|
|
|
|
|
/* produce some cargo */
|
|
|
|
if ((i->counter & 0xFF) == 0) {
|
|
|
|
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
|
|
|
|
i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (i->type == IT_FARM) {
|
2004-08-09 17:04:08 +00:00
|
|
|
MaybePlantFarmField(i);
|
2005-11-14 19:48:04 +00:00
|
|
|
} else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ChopLumberMillTrees(i);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void OnTick_Industry(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *i;
|
|
|
|
|
|
|
|
if (_industry_sound_ctr != 0) {
|
|
|
|
_industry_sound_ctr++;
|
|
|
|
|
|
|
|
if (_industry_sound_ctr == 75) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (_industry_sound_ctr == 160) {
|
2004-09-11 09:55:19 +00:00
|
|
|
_industry_sound_ctr = 0;
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_game_mode == GM_EDITOR) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2006-08-22 15:33:35 +00:00
|
|
|
ProduceIndustryGoods(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_NULL(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_Forest(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (_opt.landscape == LT_HILLY) {
|
2006-04-23 19:35:36 +00:00
|
|
|
if (GetTileZ(tile) < _opt.snow_line + TILE_HEIGHT * 2U) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_OilRefinery(TileIndex tile)
|
|
|
|
{
|
|
|
|
if (_game_mode == GM_EDITOR) return true;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true;
|
2006-05-20 16:46:37 +00:00
|
|
|
|
|
|
|
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-08-10 16:12:40 +00:00
|
|
|
extern bool _ignore_restrictions;
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_OilRig(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
|
2006-05-20 16:46:37 +00:00
|
|
|
if (TileHeight(tile) == 0 &&
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _patches.oil_refinery_limit) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_Farm(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (_opt.landscape == LT_HILLY) {
|
2006-04-03 09:07:21 +00:00
|
|
|
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_0239_SITE_UNSUITABLE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_Plantation(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-30 19:16:44 +00:00
|
|
|
if (GetTropicZone(tile) == TROPICZONE_DESERT) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_0239_SITE_UNSUITABLE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_Water(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-30 19:16:44 +00:00
|
|
|
if (GetTropicZone(tile) != TROPICZONE_DESERT) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_Lumbermill(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-03-30 19:16:44 +00:00
|
|
|
if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
static bool CheckNewIndustry_BubbleGen(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-23 19:35:36 +00:00
|
|
|
return GetTileZ(tile) <= TILE_HEIGHT * 4;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 16:46:37 +00:00
|
|
|
typedef bool CheckNewIndustryProc(TileIndex tile);
|
2006-04-26 17:01:27 +00:00
|
|
|
static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
CheckNewIndustry_NULL,
|
|
|
|
CheckNewIndustry_Forest,
|
2006-05-20 16:46:37 +00:00
|
|
|
CheckNewIndustry_OilRefinery,
|
2004-08-09 17:04:08 +00:00
|
|
|
CheckNewIndustry_Farm,
|
|
|
|
CheckNewIndustry_Plantation,
|
|
|
|
CheckNewIndustry_Water,
|
|
|
|
CheckNewIndustry_Lumbermill,
|
|
|
|
CheckNewIndustry_BubbleGen,
|
2006-05-20 16:46:37 +00:00
|
|
|
CheckNewIndustry_OilRig
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static bool CheckSuitableIndustryPos(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-07 17:02:43 +00:00
|
|
|
uint x = TileX(tile);
|
|
|
|
uint y = TileY(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_0239_SITE_UNSUITABLE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-04-26 14:58:06 +00:00
|
|
|
static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
const Town *t;
|
|
|
|
const Industry *i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
t = ClosestTownFromTile(tile, (uint)-1);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_patches.multiple_industry_per_town) return t;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2006-08-22 15:33:35 +00:00
|
|
|
if (i->type == (byte)type &&
|
2004-08-09 17:04:08 +00:00
|
|
|
i->town == t) {
|
|
|
|
_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2006-04-10 14:27:26 +00:00
|
|
|
static const byte _industry_section_bits[] = {
|
2004-08-09 17:04:08 +00:00
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
2006-08-22 14:38:37 +00:00
|
|
|
16, 16, 4, 2, 16, 16, 16, 16,
|
2004-08-09 17:04:08 +00:00
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
2006-08-22 14:38:37 +00:00
|
|
|
16, 4, 2, 16, 16, 16, 16, 16,
|
2004-08-09 17:04:08 +00:00
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
16, 16, 16, 16, 16, 16, 16,
|
|
|
|
};
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_error_message = STR_0239_SITE_UNSUITABLE;
|
|
|
|
|
|
|
|
do {
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!IsValidTile(cur_tile)) {
|
2006-04-04 06:04:54 +00:00
|
|
|
if (it->gfx == 0xff) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-04-04 06:04:54 +00:00
|
|
|
if (it->gfx == 0xFF) {
|
2006-03-22 19:04:04 +00:00
|
|
|
if (!IsTileType(cur_tile, MP_WATER) ||
|
2006-04-23 13:48:16 +00:00
|
|
|
GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
|
2006-03-22 19:04:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!EnsureNoVehicle(cur_tile)) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (type == IT_OIL_RIG) {
|
2006-03-22 19:04:04 +00:00
|
|
|
if (!IsTileType(cur_tile, MP_WATER) || _m[cur_tile].m5 != 0) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-04-23 13:48:16 +00:00
|
|
|
Slope tileh;
|
2006-03-22 19:04:04 +00:00
|
|
|
|
|
|
|
if (IsTileType(cur_tile, MP_WATER) && _m[cur_tile].m5 == 0) return false;
|
|
|
|
|
|
|
|
tileh = GetTileSlope(cur_tile, NULL);
|
2006-04-23 13:48:16 +00:00
|
|
|
if (IsSteepSlope(tileh)) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-19 11:28:41 +00:00
|
|
|
if (_patches.land_generator != LG_TERRAGENESIS || !_generating_world) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
/* It is almost impossible to have a fully flat land in TG, so what we
|
|
|
|
* do is that we check if we can make the land flat later on. See
|
|
|
|
* CheckIfCanLevelIndustryPlatform(). */
|
|
|
|
if (tileh != SLOPE_FLAT) {
|
|
|
|
Slope t;
|
|
|
|
byte bits = _industry_section_bits[it->gfx];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (bits & 0x10) return false;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
t = ComplementSlope(tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (bits & 1 && (t & SLOPE_NW)) return false;
|
|
|
|
if (bits & 2 && (t & SLOPE_NE)) return false;
|
|
|
|
if (bits & 4 && (t & SLOPE_SW)) return false;
|
|
|
|
if (bits & 8 && (t & SLOPE_SE)) return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 21:00:56 +00:00
|
|
|
if (type == IT_BANK_TEMP) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (!IsTileType(cur_tile, MP_HOUSE)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
|
|
|
|
return false;
|
|
|
|
}
|
2006-04-10 21:00:56 +00:00
|
|
|
} else if (type == IT_BANK_TROPIC_ARCTIC) {
|
2006-03-22 19:04:04 +00:00
|
|
|
if (!IsTileType(cur_tile, MP_HOUSE)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (type == IT_TOY_SHOP) {
|
2006-03-22 19:04:04 +00:00
|
|
|
if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (type == IT_WATER_TOWER) {
|
2006-03-22 19:04:04 +00:00
|
|
|
if (!IsTileType(cur_tile, MP_HOUSE)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS;
|
|
|
|
return false;
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
do_clear:
|
2006-04-10 07:15:58 +00:00
|
|
|
if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-06 11:39:00 +00:00
|
|
|
} while ((++it)->ti.x != -0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
|
|
|
|
{
|
|
|
|
if (type == IT_BANK_TEMP && t->population < 1200) {
|
|
|
|
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == IT_TOY_SHOP && DistanceMax(t->xy, tile) > 9) {
|
|
|
|
_error_message = STR_0239_SITE_UNSUITABLE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
|
|
|
|
{
|
|
|
|
int size_x, size_y;
|
|
|
|
uint curh;
|
|
|
|
|
|
|
|
size_x = 2;
|
|
|
|
size_y = 2;
|
|
|
|
|
|
|
|
/* Check if we don't leave the map */
|
|
|
|
if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
|
|
|
|
|
|
|
|
tile += TileDiffXY(-1, -1);
|
|
|
|
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) {
|
|
|
|
curh = TileHeight(tile_walk);
|
|
|
|
/* Is the tile clear? */
|
|
|
|
if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Don't allow too big of a change if this is the sub-tile check */
|
|
|
|
if (internal != 0 && myabs(curh - height) > 1) return false;
|
|
|
|
|
|
|
|
/* Different height, so the surrounding tiles of this tile
|
|
|
|
* has to be correct too (in level, or almost in level)
|
|
|
|
* else you get a chain-reaction of terraforming. */
|
|
|
|
if (internal == 0 && curh != height) {
|
|
|
|
if (!CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} END_TILE_LOOP(tile_walk, size_x, size_y, tile);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function tries to flatten out the land below an industry, without
|
|
|
|
* damaging the surroundings too much.
|
|
|
|
*/
|
|
|
|
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const IndustryTileTable* it, int type)
|
|
|
|
{
|
|
|
|
const int MKEND = -0x80; // used for last element in an IndustryTileTable (see build_industry.h)
|
|
|
|
int max_x = 0;
|
|
|
|
int max_y = 0;
|
|
|
|
TileIndex cur_tile;
|
|
|
|
uint size_x, size_y;
|
|
|
|
uint h, curh;
|
|
|
|
|
|
|
|
/* Finds dimensions of largest variant of this industry */
|
|
|
|
do {
|
|
|
|
if (it->ti.x > max_x) max_x = it->ti.x;
|
|
|
|
if (it->ti.y > max_y) max_y = it->ti.y;
|
|
|
|
} while ((++it)->ti.x != MKEND);
|
|
|
|
|
|
|
|
/* Remember level height */
|
|
|
|
h = TileHeight(tile);
|
|
|
|
|
|
|
|
/* Check that all tiles in area and surrounding are clear
|
|
|
|
* this determines that there are no obstructing items */
|
|
|
|
cur_tile = tile + TileDiffXY(-1, -1);
|
|
|
|
size_x = max_x + 4;
|
|
|
|
size_y = max_y + 4;
|
|
|
|
|
|
|
|
/* Check if we don't leave the map */
|
2006-08-20 10:45:36 +00:00
|
|
|
if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
|
|
|
|
curh = TileHeight(tile_walk);
|
|
|
|
if (curh != h) {
|
|
|
|
/* This tile needs terraforming. Check if we can do that without
|
|
|
|
* damaging the surroundings too much. */
|
|
|
|
if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) return false;
|
|
|
|
/* This is not 100% correct check, but the best we can do without modifying the map.
|
|
|
|
* What is missing, is if the difference in height is more than 1.. */
|
|
|
|
if (CmdFailed(DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) return false;
|
|
|
|
}
|
|
|
|
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
/* Terraform the land under the industry */
|
|
|
|
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
|
|
|
|
curh = TileHeight(tile_walk);
|
|
|
|
while (curh != h) {
|
|
|
|
/* We give the terraforming for free here, because we can't calculate
|
|
|
|
* exact cost in the test-round, and as we all know, that will cause
|
|
|
|
* a nice assert if they don't match ;) */
|
|
|
|
DoCommand(tile_walk, 8, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
|
|
|
|
curh += (curh > h) ? -1 : 1;
|
|
|
|
}
|
|
|
|
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 21:10:01 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
2006-04-26 14:58:06 +00:00
|
|
|
const Industry *i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// accepting industries won't be close, not even with patch
|
2006-04-26 21:10:01 +00:00
|
|
|
if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
|
2004-08-09 17:04:08 +00:00
|
|
|
return true;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// check if an industry that accepts the same goods is nearby
|
2006-08-22 15:33:35 +00:00
|
|
|
if (DistanceMax(tile, i->xy) <= 14 &&
|
2006-04-26 21:10:01 +00:00
|
|
|
indspec->accepts_cargo[0] != CT_INVALID &&
|
|
|
|
indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
|
2005-11-14 19:48:04 +00:00
|
|
|
_game_mode != GM_EDITOR ||
|
|
|
|
!_patches.same_industry_close ||
|
|
|
|
!_patches.multiple_industry_per_town
|
|
|
|
)) {
|
|
|
|
_error_message = STR_INDUSTRY_TOO_CLOSE;
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// check "not close to" field.
|
2006-08-22 15:33:35 +00:00
|
|
|
if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) &&
|
2005-01-31 07:23:15 +00:00
|
|
|
DistanceMax(tile, i->xy) <= 14) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_error_message = STR_INDUSTRY_TOO_CLOSE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static Industry *AllocateIndustry(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *i;
|
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
|
|
|
* TODO - This is just a temporary stage, this will be removed. */
|
|
|
|
for (i = GetIndustry(0); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) {
|
|
|
|
IndustryID index = i->index;
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
if (IsValidIndustry(i)) continue;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2006-08-22 21:17:19 +00:00
|
|
|
if (i->index >= _total_industries) _total_industries = i->index + 1;
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2006-08-22 15:33:35 +00:00
|
|
|
memset(i, 0, sizeof(*i));
|
|
|
|
i->index = index;
|
|
|
|
|
|
|
|
return i;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-02-02 17:30:29 +00:00
|
|
|
|
|
|
|
/* Check if we can add a block to the pool */
|
2005-10-23 13:04:44 +00:00
|
|
|
return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-26 14:58:06 +00:00
|
|
|
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-04-26 21:10:01 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 r;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
i->xy = tile;
|
|
|
|
i->width = i->height = 0;
|
|
|
|
i->type = type;
|
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
i->produced_cargo[0] = indspec->produced_cargo[0];
|
|
|
|
i->produced_cargo[1] = indspec->produced_cargo[1];
|
|
|
|
i->accepts_cargo[0] = indspec->accepts_cargo[0];
|
|
|
|
i->accepts_cargo[1] = indspec->accepts_cargo[1];
|
|
|
|
i->accepts_cargo[2] = indspec->accepts_cargo[2];
|
|
|
|
i->production_rate[0] = indspec->production_rate[0];
|
|
|
|
i->production_rate[1] = indspec->production_rate[1];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (_patches.smooth_economy) {
|
|
|
|
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
|
|
|
|
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
i->town = t;
|
|
|
|
i->owner = owner;
|
|
|
|
|
2005-10-03 21:20:01 +00:00
|
|
|
r = Random();
|
2005-10-05 04:00:39 +00:00
|
|
|
i->color_map = GB(r, 8, 4);
|
|
|
|
i->counter = GB(r, 0, 12);
|
2004-08-09 17:04:08 +00:00
|
|
|
i->cargo_waiting[0] = 0;
|
|
|
|
i->cargo_waiting[1] = 0;
|
|
|
|
i->last_mo_production[0] = 0;
|
|
|
|
i->last_mo_production[1] = 0;
|
|
|
|
i->last_mo_transported[0] = 0;
|
|
|
|
i->last_mo_transported[1] = 0;
|
|
|
|
i->pct_transported[0] = 0;
|
|
|
|
i->pct_transported[1] = 0;
|
|
|
|
i->total_transported[0] = 0;
|
|
|
|
i->total_transported[1] = 0;
|
|
|
|
i->was_cargo_delivered = false;
|
2006-08-20 19:05:28 +00:00
|
|
|
i->last_prod_year = _cur_year;
|
2004-08-09 17:04:08 +00:00
|
|
|
i->total_production[0] = i->production_rate[0] * 8;
|
|
|
|
i->total_production[1] = i->production_rate[1] * 8;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!_generating_world) i->total_production[0] = i->total_production[1] = 0;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
i->prod_level = 0x10;
|
|
|
|
|
|
|
|
do {
|
2005-06-24 12:38:35 +00:00
|
|
|
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 06:04:54 +00:00
|
|
|
if (it->gfx != 0xFF) {
|
2004-08-09 17:04:08 +00:00
|
|
|
byte size;
|
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
size = it->ti.x;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (size > i->width) i->width = size;
|
2005-01-06 11:39:00 +00:00
|
|
|
size = it->ti.y;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (size > i->height)i->height = size;
|
|
|
|
|
2006-04-10 07:15:58 +00:00
|
|
|
DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-04 06:04:54 +00:00
|
|
|
MakeIndustry(cur_tile, i->index, it->gfx);
|
2006-03-24 13:31:17 +00:00
|
|
|
if (_generating_world) _m[cur_tile].m1 = 0x1E; /* maturity */
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-06 11:39:00 +00:00
|
|
|
} while ((++it)->ti.x != -0x80);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
i->width++;
|
|
|
|
i->height++;
|
|
|
|
|
|
|
|
if (i->type == IT_FARM || i->type == IT_FARM_2) {
|
2006-08-20 18:44:26 +00:00
|
|
|
for (j = 0; j != 50; j++) PlantRandomFarmField(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
|
|
|
}
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, const IndustryTileTable *it)
|
|
|
|
{
|
|
|
|
const Town *t;
|
|
|
|
Industry *i;
|
|
|
|
|
|
|
|
if (!CheckIfIndustryTilesAreFree(tile, it, type)) return NULL;
|
|
|
|
if (_patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
|
|
|
|
if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
|
|
|
|
if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
|
|
|
|
|
|
|
|
t = CheckMultipleIndustryInTown(tile, type);
|
|
|
|
if (t == NULL) return NULL;
|
|
|
|
|
|
|
|
if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
|
|
|
|
if (!CheckSuitableIndustryPos(tile)) return NULL;
|
|
|
|
|
|
|
|
i = AllocateIndustry();
|
|
|
|
if (i == NULL) return NULL;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
|
|
|
|
DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Build/Fund an industry
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile tile where industry is built
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 industry type @see build_industry.h and @see industry.h
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int num;
|
|
|
|
const IndustryTileTable * const *itt;
|
|
|
|
const IndustryTileTable *it;
|
2006-04-26 21:10:01 +00:00
|
|
|
const IndustrySpec *indspec;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_OTHER);
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/* Check if the to-be built/founded industry is available for this climate.
|
|
|
|
* Unfortunately we have no easy way of checking, except for looping the table */
|
2005-11-14 19:48:04 +00:00
|
|
|
{
|
2006-04-26 14:58:06 +00:00
|
|
|
const byte *i;
|
2005-05-11 00:00:27 +00:00
|
|
|
bool found = false;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (*i == p1) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2005-05-11 00:00:27 +00:00
|
|
|
}
|
|
|
|
if (!found) return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
indspec = GetIndustrySpec(p1);
|
2005-11-14 15:22:12 +00:00
|
|
|
/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
|
2005-05-13 18:19:26 +00:00
|
|
|
* Raw material industries are industries that do not accept cargo (at least for now)
|
2005-11-14 15:22:12 +00:00
|
|
|
* Exclude the lumber mill (only "raw" industry that can be built) */
|
|
|
|
if (!_patches.build_rawmaterial_ind &&
|
2006-04-26 21:10:01 +00:00
|
|
|
indspec->accepts_cargo[0] == CT_INVALID &&
|
|
|
|
indspec->accepts_cargo[1] == CT_INVALID &&
|
|
|
|
indspec->accepts_cargo[2] == CT_INVALID &&
|
2005-11-14 15:22:12 +00:00
|
|
|
p1 != IT_LUMBER_MILL) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
num = indspec->num_table;
|
|
|
|
itt = indspec->table;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
do {
|
2005-05-11 00:00:27 +00:00
|
|
|
if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (CreateNewIndustryHelper(tile, p1, flags, indspec, it) == NULL) return CMD_ERROR;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-04-28 21:58:16 +00:00
|
|
|
return (_price.build_industry >> 5) * indspec->cost_multiplier;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-12 18:10:54 +00:00
|
|
|
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
const IndustryTileTable *it = indspec->table[RandomRange(indspec->num_table)];
|
2004-09-11 09:55:19 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-22 15:56:56 +00:00
|
|
|
static const byte _numof_industry_table[4][12] = {
|
2006-04-26 21:10:01 +00:00
|
|
|
// difficulty settings for number of industries
|
|
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //none
|
|
|
|
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, //low
|
|
|
|
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, //normal
|
|
|
|
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, //high
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
static void PlaceInitialIndustry(IndustryType type, int amount)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-15 19:51:54 +00:00
|
|
|
int num = _numof_industry_table[_opt.diff.number_industries][amount];
|
|
|
|
|
|
|
|
if (type == IT_OIL_REFINERY || type == IT_OIL_RIG) {
|
|
|
|
// These are always placed next to the coastline, so we scale by the perimeter instead.
|
|
|
|
num = ScaleByMapSize1D(num);
|
|
|
|
} else {
|
|
|
|
num = ScaleByMapSize(num);
|
|
|
|
}
|
2004-08-22 15:56:56 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_opt.diff.number_industries != 0) {
|
2005-10-07 07:35:15 +00:00
|
|
|
PlayerID old_player = _current_player;
|
2004-09-16 15:15:04 +00:00
|
|
|
_current_player = OWNER_NONE;
|
2004-08-15 22:17:46 +00:00
|
|
|
assert(num > 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
do {
|
2005-11-14 19:48:04 +00:00
|
|
|
uint i;
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; i < 2000; i++) {
|
|
|
|
if (CreateNewIndustry(RandomTile(), type) != NULL) break;
|
|
|
|
}
|
2004-08-22 15:56:56 +00:00
|
|
|
} while (--num);
|
2004-09-16 15:15:04 +00:00
|
|
|
|
2004-09-16 15:21:24 +00:00
|
|
|
_current_player = old_player;
|
2004-08-15 22:17:46 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void GenerateIndustries(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const byte *b;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
uint i = 0;
|
|
|
|
|
|
|
|
/* Find the total amount of industries */
|
|
|
|
b = _industry_create_table[_opt.landscape];
|
|
|
|
do {
|
|
|
|
int num = _numof_industry_table[_opt.diff.number_industries][b[0]];
|
|
|
|
|
|
|
|
if (b[1] == IT_OIL_REFINERY || b[1] == IT_OIL_RIG) {
|
|
|
|
/* These are always placed next to the coastline, so we scale by the perimeter instead. */
|
|
|
|
num = ScaleByMapSize1D(num);
|
|
|
|
} else {
|
|
|
|
num = ScaleByMapSize(num);
|
|
|
|
}
|
|
|
|
|
|
|
|
i += num;
|
|
|
|
} while ( (b+=2)[0] != 0);
|
|
|
|
SetGeneratingWorldProgress(GWP_INDUSTRY, i);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
b = _industry_create_table[_opt.landscape];
|
|
|
|
do {
|
|
|
|
PlaceInitialIndustry(b[1], b[0]);
|
|
|
|
} while ( (b+=2)[0] != 0);
|
|
|
|
}
|
|
|
|
|
2006-04-10 16:20:47 +00:00
|
|
|
/* Change industry production or do closure */
|
2004-08-09 17:04:08 +00:00
|
|
|
static void ExtChangeIndustryProduction(Industry *i)
|
|
|
|
{
|
2005-02-06 15:07:29 +00:00
|
|
|
bool closeit = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
int j;
|
2006-04-26 21:10:01 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
switch (_industry_close_mode[i->type]) {
|
2006-04-10 16:20:47 +00:00
|
|
|
case INDUSTRYLIFE_NOT_CLOSABLE:
|
2005-02-06 15:07:29 +00:00
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 16:20:47 +00:00
|
|
|
case INDUSTRYLIFE_CLOSABLE:
|
2006-08-20 19:05:28 +00:00
|
|
|
if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180))
|
2004-08-09 17:04:08 +00:00
|
|
|
closeit = false;
|
2005-02-06 15:07:29 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
default: /* INDUSTRY_PRODUCTION */
|
2005-11-14 15:22:12 +00:00
|
|
|
for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
|
2005-03-29 21:42:51 +00:00
|
|
|
uint32 r = Random();
|
|
|
|
int old, new, percent;
|
2005-02-06 15:07:29 +00:00
|
|
|
int mag;
|
|
|
|
|
2005-03-29 21:42:51 +00:00
|
|
|
new = old = i->production_rate[j];
|
|
|
|
if (CHANCE16I(20, 1024, r))
|
|
|
|
new -= ((RandomRange(50) + 10) * old) >> 8;
|
|
|
|
if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16))
|
|
|
|
new += ((RandomRange(50) + 10) * old) >> 8;
|
2005-02-06 15:07:29 +00:00
|
|
|
|
2005-03-29 21:42:51 +00:00
|
|
|
new = clamp(new, 0, 255);
|
|
|
|
if (new == old) {
|
2005-02-06 15:07:29 +00:00
|
|
|
closeit = false;
|
|
|
|
continue;
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-03-29 21:42:51 +00:00
|
|
|
percent = new * 100 / old - 100;
|
|
|
|
i->production_rate[j] = new;
|
2005-02-06 15:07:29 +00:00
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
if (new >= indspec->production_rate[j] / 4)
|
2005-02-06 15:07:29 +00:00
|
|
|
closeit = false;
|
|
|
|
|
|
|
|
mag = abs(percent);
|
|
|
|
if (mag >= 10) {
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(2, mag);
|
2005-03-29 21:42:51 +00:00
|
|
|
SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]);
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(1, i->index);
|
2005-11-14 19:48:04 +00:00
|
|
|
AddNewsItem(
|
|
|
|
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
|
|
|
|
i->xy + TileDiffXY(1, 1), 0
|
|
|
|
);
|
2005-02-06 15:07:29 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-02-06 15:07:29 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 16:20:47 +00:00
|
|
|
/* If industry will be closed down, show this */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (closeit) {
|
|
|
|
i->prod_level = 0;
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, i->index);
|
2005-11-14 19:48:04 +00:00
|
|
|
AddNewsItem(
|
2006-04-26 21:10:01 +00:00
|
|
|
indspec->closure_text,
|
2005-11-14 19:48:04 +00:00
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
|
|
|
|
i->xy + TileDiffXY(1, 1), 0
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void UpdateIndustryStatistics(Industry *i)
|
|
|
|
{
|
|
|
|
byte pct;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-09-28 19:35:36 +00:00
|
|
|
if (i->produced_cargo[0] != CT_INVALID) {
|
2004-08-09 17:04:08 +00:00
|
|
|
pct = 0;
|
|
|
|
if (i->last_mo_production[0] != 0) {
|
2006-08-20 19:05:28 +00:00
|
|
|
i->last_prod_year = _cur_year;
|
2004-08-09 17:04:08 +00:00
|
|
|
pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0],255);
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
i->pct_transported[0] = pct;
|
|
|
|
|
|
|
|
i->total_production[0] = i->last_mo_production[0];
|
|
|
|
i->last_mo_production[0] = 0;
|
|
|
|
|
|
|
|
i->total_transported[0] = i->last_mo_transported[0];
|
|
|
|
i->last_mo_transported[0] = 0;
|
|
|
|
}
|
|
|
|
|
2005-09-28 19:35:36 +00:00
|
|
|
if (i->produced_cargo[1] != CT_INVALID) {
|
2004-08-09 17:04:08 +00:00
|
|
|
pct = 0;
|
|
|
|
if (i->last_mo_production[1] != 0) {
|
2006-08-20 19:05:28 +00:00
|
|
|
i->last_prod_year = _cur_year;
|
2004-08-09 17:04:08 +00:00
|
|
|
pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1],255);
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
i->pct_transported[1] = pct;
|
|
|
|
|
|
|
|
i->total_production[1] = i->last_mo_production[1];
|
|
|
|
i->last_mo_production[1] = 0;
|
|
|
|
|
|
|
|
i->total_transported[1] = i->last_mo_transported[1];
|
|
|
|
i->last_mo_transported[1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-28 19:35:36 +00:00
|
|
|
if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID)
|
2005-01-06 22:31:58 +00:00
|
|
|
InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (i->prod_level == 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteIndustry(i);
|
2005-11-14 19:48:04 +00:00
|
|
|
} else if (_patches.smooth_economy) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ExtChangeIndustryProduction(i);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const byte _new_industry_rand[4][32] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{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},
|
|
|
|
{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},
|
|
|
|
{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},
|
|
|
|
{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},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void MaybeNewIndustry(uint32 r)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
int j;
|
|
|
|
Industry *i;
|
|
|
|
|
2005-07-20 15:29:28 +00:00
|
|
|
type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-17 20:22:35 +00:00
|
|
|
if (type == IT_OIL_WELL && _cur_year > 1950) return;
|
|
|
|
if (type == IT_OIL_RIG && _cur_year < 1960) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
j = 2000;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (;;) {
|
2005-11-14 09:21:05 +00:00
|
|
|
i = CreateNewIndustry(RandomTile(), type);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (i != NULL) break;
|
|
|
|
if (--j == 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, type + STR_4802_COAL_MINE);
|
|
|
|
SetDParam(1, i->town->index);
|
2005-08-01 13:01:14 +00:00
|
|
|
AddNewsItem(
|
2006-04-18 13:16:00 +00:00
|
|
|
(type != IT_FOREST && type != IT_FRUIT_PLANTATION && type != IT_RUBBER_PLANTATION && type != IT_COTTON_CANDY) ?
|
2005-08-01 13:01:14 +00:00
|
|
|
STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
static void ChangeIndustryProduction(Industry *i)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-06 15:07:29 +00:00
|
|
|
bool only_decrease = false;
|
|
|
|
StringID str = STR_NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
int type = i->type;
|
2006-04-26 21:10:01 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
switch (_industry_close_mode[type]) {
|
2006-04-10 16:20:47 +00:00
|
|
|
case INDUSTRYLIFE_NOT_CLOSABLE:
|
2005-02-06 15:07:29 +00:00
|
|
|
return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-10 16:20:47 +00:00
|
|
|
case INDUSTRYLIFE_PRODUCTION:
|
2005-02-06 15:07:29 +00:00
|
|
|
/* decrease or increase */
|
|
|
|
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL)
|
|
|
|
only_decrease = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
if (only_decrease || CHANCE16(1,3)) {
|
|
|
|
/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
|
|
|
|
if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {
|
|
|
|
/* Increase production */
|
|
|
|
if (i->prod_level != 0x80) {
|
|
|
|
byte b;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
i->prod_level <<= 1;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
b = i->production_rate[0] * 2;
|
|
|
|
if (i->production_rate[0] >= 128)
|
|
|
|
b = 0xFF;
|
|
|
|
i->production_rate[0] = b;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 15:07:29 +00:00
|
|
|
b = i->production_rate[1] * 2;
|
|
|
|
if (i->production_rate[1] >= 128)
|
|
|
|
b = 0xFF;
|
|
|
|
i->production_rate[1] = b;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
str = indspec->production_up_text;
|
2005-02-06 15:07:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Decrease production */
|
|
|
|
if (i->prod_level == 4) {
|
|
|
|
i->prod_level = 0;
|
2006-04-26 21:10:01 +00:00
|
|
|
str = indspec->closure_text;
|
2005-02-06 15:07:29 +00:00
|
|
|
} else {
|
|
|
|
i->prod_level >>= 1;
|
|
|
|
i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
|
|
|
|
i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
|
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
str = indspec->production_down_text;
|
2005-02-06 15:07:29 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-02-06 15:07:29 +00:00
|
|
|
break;
|
|
|
|
|
2006-04-10 16:20:47 +00:00
|
|
|
case INDUSTRYLIFE_CLOSABLE:
|
2005-02-06 15:07:29 +00:00
|
|
|
/* maybe close */
|
2006-08-20 19:05:28 +00:00
|
|
|
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
|
2005-02-06 15:07:29 +00:00
|
|
|
i->prod_level = 0;
|
2006-04-26 21:10:01 +00:00
|
|
|
str = indspec->closure_text;
|
2005-02-06 15:07:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str != STR_NULL) {
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, i->index);
|
2005-06-25 16:44:57 +00:00
|
|
|
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void IndustryMonthlyLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *i;
|
2005-10-07 07:35:15 +00:00
|
|
|
PlayerID old_player = _current_player;
|
2004-09-16 15:15:04 +00:00
|
|
|
_current_player = OWNER_NONE;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
2006-08-22 15:33:35 +00:00
|
|
|
UpdateIndustryStatistics(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-02-02 17:30:29 +00:00
|
|
|
/* 3% chance that we start a new industry */
|
|
|
|
if (CHANCE16(3, 100)) {
|
|
|
|
MaybeNewIndustry(Random());
|
2006-08-22 20:41:26 +00:00
|
|
|
} else if (!_patches.smooth_economy && GetIndustryArraySize() > 0) {
|
2006-08-22 21:14:45 +00:00
|
|
|
i = GetRandomIndustry();
|
|
|
|
if (i != NULL) ChangeIndustryProduction(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-16 15:15:04 +00:00
|
|
|
|
|
|
|
_current_player = old_player;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// production-change
|
|
|
|
_industry_sort_dirty = true;
|
|
|
|
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeIndustries(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-02 17:30:29 +00:00
|
|
|
CleanPool(&_industry_pool);
|
|
|
|
AddBlockToPool(&_industry_pool);
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_total_industries = 0;
|
|
|
|
_industry_sort_dirty = true;
|
2006-09-10 08:28:32 +00:00
|
|
|
_industry_sound_tile = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const TileTypeProcs _tile_type_industry_procs = {
|
2006-08-22 14:38:37 +00:00
|
|
|
DrawTile_Industry, /* draw_tile_proc */
|
|
|
|
GetSlopeZ_Industry, /* get_slope_z_proc */
|
|
|
|
ClearTile_Industry, /* clear_tile_proc */
|
2006-08-28 18:53:03 +00:00
|
|
|
GetAcceptedCargo_Industry, /* get_accepted_cargo_proc */
|
2006-08-22 14:38:37 +00:00
|
|
|
GetTileDesc_Industry, /* get_tile_desc_proc */
|
|
|
|
GetTileTrackStatus_Industry, /* get_tile_track_status_proc */
|
|
|
|
ClickTile_Industry, /* click_tile_proc */
|
|
|
|
AnimateTile_Industry, /* animate_tile_proc */
|
|
|
|
TileLoop_Industry, /* tile_loop_proc */
|
|
|
|
ChangeTileOwner_Industry, /* change_tile_owner_proc */
|
|
|
|
GetProducedCargo_Industry, /* get_produced_cargo_proc */
|
|
|
|
NULL, /* vehicle_enter_tile_proc */
|
|
|
|
GetSlopeTileh_Industry, /* get_slope_tileh_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-05-30 22:16:05 +00:00
|
|
|
static const SaveLoad _industry_desc[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
|
|
|
|
SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
SLE_VAR(Industry, width, SLE_UINT8),
|
|
|
|
SLE_VAR(Industry, height, SLE_UINT8),
|
|
|
|
SLE_REF(Industry, town, REF_TOWN),
|
|
|
|
SLE_ARR(Industry, produced_cargo, SLE_UINT8, 2),
|
|
|
|
SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
|
|
|
|
SLE_ARR(Industry, accepts_cargo, SLE_UINT8, 3),
|
|
|
|
SLE_VAR(Industry, prod_level, SLE_UINT8),
|
|
|
|
SLE_ARR(Industry, last_mo_production, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, pct_transported, SLE_UINT8, 2),
|
|
|
|
SLE_ARR(Industry, total_production, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, total_transported, SLE_UINT16, 2),
|
|
|
|
|
|
|
|
SLE_VAR(Industry, counter, SLE_UINT16),
|
|
|
|
|
|
|
|
SLE_VAR(Industry, type, SLE_UINT8),
|
|
|
|
SLE_VAR(Industry, owner, SLE_UINT8),
|
|
|
|
SLE_VAR(Industry, color_map, SLE_UINT8),
|
|
|
|
SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30),
|
|
|
|
SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION),
|
|
|
|
SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8),
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// reserve extra space in savegame here. (currently 32 bytes)
|
2006-03-16 00:20:33 +00:00
|
|
|
SLE_CONDNULL(32, 2, SL_MAX_VERSION),
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Save_INDY(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *ind;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Write the vehicles
|
2004-12-30 10:03:35 +00:00
|
|
|
FOR_ALL_INDUSTRIES(ind) {
|
2006-08-22 15:33:35 +00:00
|
|
|
SlSetArrayIndex(ind->index);
|
|
|
|
SlObject(ind, _industry_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Load_INDY(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int index;
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_total_industries = 0;
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
while ((index = SlIterateArray()) != -1) {
|
2005-02-02 17:30:29 +00:00
|
|
|
Industry *i;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2005-02-02 17:30:29 +00:00
|
|
|
if (!AddBlockIfNeeded(&_industry_pool, index))
|
|
|
|
error("Industries: failed loading savegame: too many industries");
|
|
|
|
|
|
|
|
i = GetIndustry(index);
|
2005-01-06 22:31:58 +00:00
|
|
|
SlObject(i, _industry_desc);
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2006-08-22 21:17:19 +00:00
|
|
|
if (index >= _total_industries) _total_industries = index + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChunkHandler _industry_chunk_handlers[] = {
|
|
|
|
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY | CH_LAST},
|
|
|
|
};
|