2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/** @file industry_cmd.cpp */
|
|
|
|
|
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"
|
2007-07-16 09:16:58 +00:00
|
|
|
#include "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"
|
2007-03-20 13:47:00 +00:00
|
|
|
#include "landscape.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"
|
2006-11-08 05:05:35 +00:00
|
|
|
#include "water_map.h"
|
2007-02-02 15:14:28 +00:00
|
|
|
#include "tree_map.h"
|
2007-02-20 22:09:21 +00:00
|
|
|
#include "cargotype.h"
|
2007-07-20 17:32:27 +00:00
|
|
|
#include "newgrf_commons.h"
|
2007-07-05 05:41:56 +00:00
|
|
|
#include "newgrf_industries.h"
|
2007-06-19 17:33:12 +00:00
|
|
|
#include "newgrf_industrytiles.h"
|
|
|
|
#include "newgrf_callbacks.h"
|
2007-08-02 23:21:52 +00:00
|
|
|
#include "misc/autoptr.hpp"
|
2007-09-14 22:27:40 +00:00
|
|
|
#include "autoslope.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);
|
|
|
|
|
|
|
|
static byte _industry_sound_ctr;
|
|
|
|
static TileIndex _industry_sound_tile;
|
|
|
|
|
2007-06-08 15:48:48 +00:00
|
|
|
int _total_industries; //general counter
|
|
|
|
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
|
|
|
|
|
|
|
|
const Industry **_industry_sort;
|
|
|
|
bool _industry_sort_dirty;
|
|
|
|
|
2007-05-29 17:41:59 +00:00
|
|
|
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
|
|
|
|
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
|
|
|
|
|
|
|
|
/** This function initialize the spec arrays of both
|
|
|
|
* industry and industry tiles.
|
|
|
|
* It adjusts the enabling of the industry too, based on climate availability.
|
|
|
|
* This will allow for clearer testings */
|
|
|
|
void ResetIndustries()
|
|
|
|
{
|
|
|
|
memset(&_industry_specs, 0, sizeof(_industry_specs));
|
|
|
|
memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs));
|
|
|
|
|
|
|
|
/* once performed, enable only the current climate industries */
|
|
|
|
for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
|
|
|
|
_industry_specs[i].enabled = HASBIT(_origin_industry_specs[i].climate_availability, _opt.landscape);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
|
|
|
|
memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
|
|
|
|
}
|
|
|
|
|
2007-07-15 00:26:12 +00:00
|
|
|
void ResetIndustryCreationProbility(IndustryType type)
|
|
|
|
{
|
|
|
|
assert(type < INVALID_INDUSTRYTYPE);
|
|
|
|
_industry_specs[type].appear_creation[_opt.landscape] = 0;
|
|
|
|
}
|
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
DEFINE_OLD_POOL_GENERIC(Industry, Industry)
|
2005-02-02 17:30:29 +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.
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_INDUSTRY));
|
|
|
|
|
2007-05-18 17:55:07 +00:00
|
|
|
const Industry *ind = GetIndustryByTile(tile);
|
2007-08-02 23:21:52 +00:00
|
|
|
return ind->IsValid() ? ind->type : (IndustryType)IT_INVALID;
|
2006-04-10 21:00:56 +00:00
|
|
|
}
|
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)
|
2007-04-19 14:50:01 +00:00
|
|
|
* @pre thistype < NUM_INDUSTRYTYPES
|
2007-03-03 04:04:22 +00:00
|
|
|
* @return a pointer to the corresponding industry spec
|
2006-04-26 14:58:06 +00:00
|
|
|
**/
|
2006-04-28 21:58:16 +00:00
|
|
|
const IndustrySpec *GetIndustrySpec(IndustryType thistype)
|
2006-04-26 14:58:06 +00:00
|
|
|
{
|
2007-04-19 14:50:01 +00:00
|
|
|
assert(thistype < NUM_INDUSTRYTYPES);
|
2006-04-26 14:58:06 +00:00
|
|
|
return &_industry_specs[thistype];
|
|
|
|
}
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/**
|
|
|
|
* Accessor for array _industry_tile_specs.
|
|
|
|
* This will ensure at once : proper access and
|
|
|
|
* not allowing modifications of it.
|
2007-07-20 14:49:41 +00:00
|
|
|
* @param gfx of industrytile (which is the index in _industry_tile_specs)
|
2007-05-30 02:08:18 +00:00
|
|
|
* @pre gfx < INVALID_INDUSTRYTILE
|
2007-03-03 04:04:22 +00:00
|
|
|
* @return a pointer to the corresponding industrytile spec
|
|
|
|
**/
|
2007-08-22 01:16:08 +00:00
|
|
|
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx)
|
2007-02-21 02:22:43 +00:00
|
|
|
{
|
2007-05-30 02:08:18 +00:00
|
|
|
assert(gfx < INVALID_INDUSTRYTILE);
|
2007-08-22 01:16:08 +00:00
|
|
|
return &_industry_tile_specs[gfx];
|
2007-02-21 02:22:43 +00:00
|
|
|
}
|
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
Industry::~Industry()
|
2006-08-26 19:51:49 +00:00
|
|
|
{
|
2007-08-06 14:08:25 +00:00
|
|
|
if (CleaningPool()) return;
|
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
/* Industry can also be destroyed when not fully initialized.
|
|
|
|
* This means that we do not have to clear tiles either. */
|
|
|
|
if (this->width == 0) {
|
|
|
|
this->xy = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
|
2006-08-26 19:51:49 +00:00
|
|
|
if (IsTileType(tile_cur, MP_INDUSTRY)) {
|
2007-08-02 23:21:52 +00:00
|
|
|
if (GetIndustryIndex(tile_cur) == this->index) {
|
2006-08-26 19:51:49 +00:00
|
|
|
DoClearSquare(tile_cur);
|
|
|
|
}
|
|
|
|
} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
|
|
|
|
DeleteOilRig(tile_cur);
|
|
|
|
}
|
2007-08-02 23:21:52 +00:00
|
|
|
END_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
|
2006-08-26 19:51:49 +00:00
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
|
2006-08-26 19:51:49 +00:00
|
|
|
/* Remove the farmland and convert it to regular tiles over time. */
|
2007-08-02 23:21:52 +00:00
|
|
|
BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
|
2006-10-11 21:20:53 +00:00
|
|
|
tile_cur = TILE_MASK(tile_cur);
|
2006-08-26 19:51:49 +00:00
|
|
|
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
|
2007-08-02 23:21:52 +00:00
|
|
|
GetIndustryIndexOfField(tile_cur) == this->index) {
|
2006-08-26 19:51:49 +00:00
|
|
|
SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
|
|
|
|
}
|
2007-08-02 23:21:52 +00:00
|
|
|
} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
|
2006-08-26 19:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_industry_sort_dirty = true;
|
2007-08-02 23:21:52 +00:00
|
|
|
DecIndustryTypeCount(this->type);
|
2007-06-08 15:48:48 +00:00
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
DeleteSubsidyWithIndustry(this->index);
|
|
|
|
DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
|
2006-08-26 19:51:49 +00:00
|
|
|
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
2007-08-02 23:21:52 +00:00
|
|
|
this->xy = 0;
|
2006-08-26 19:51:49 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 23:22:21 +00:00
|
|
|
static void IndustryDrawSugarMine(const TileInfo *ti)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-04-21 02:47:33 +00:00
|
|
|
const DrawIndustryAnimationStruct *d;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (!IsIndustryCompleted(ti->tile)) return;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-12-30 11:51:37 +00:00
|
|
|
d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-21 02:47:33 +00:00
|
|
|
if (d->image_2 != 0) {
|
|
|
|
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-21 02:47:33 +00:00
|
|
|
if (d->image_3 != 0) {
|
|
|
|
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
|
|
|
|
_drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
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
|
|
|
{
|
2007-04-21 02:47:33 +00:00
|
|
|
uint8 x = 0;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-03-24 13:46:45 +00:00
|
|
|
if (IsIndustryCompleted(ti->tile)) {
|
2007-04-21 02:47:33 +00:00
|
|
|
x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)];
|
|
|
|
if (x == 0xFF)
|
2004-08-09 17:04:08 +00:00
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x);
|
|
|
|
AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, PAL_NONE, 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)) {
|
2007-04-21 02:47:33 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]);
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2007-01-14 19:57:49 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 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
|
|
|
{
|
2007-04-21 02:47:33 +00:00
|
|
|
const DrawIndustryAnimationStruct *d;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-21 02:47:33 +00:00
|
|
|
d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (d->image_1 != 0xFF) {
|
2007-04-21 02:47:33 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->image_2 != 0xFF) {
|
2007-01-14 19:57:49 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, PAL_NONE, 16 - d->image_2 * 2, 100 + d->image_2);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3);
|
|
|
|
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, PAL_NONE, 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)) {
|
2007-04-21 02:47:33 +00:00
|
|
|
uint8 image = GetIndustryAnimationState(ti->tile);
|
2006-03-24 13:46:45 +00:00
|
|
|
|
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,
|
2007-01-14 19:57:49 +00:00
|
|
|
PAL_NONE,
|
2007-04-21 02:47:33 +00:00
|
|
|
_coal_plant_sparks[image - 1].x,
|
|
|
|
_coal_plant_sparks[image - 1].y
|
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)
|
|
|
|
{
|
2007-06-19 17:33:12 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(ti->tile);
|
|
|
|
Industry *ind = GetIndustryByTile(ti->tile);
|
|
|
|
const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
|
2006-04-24 21:10:56 +00:00
|
|
|
const DrawBuildingsTileStruct *dits;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID image;
|
|
|
|
SpriteID pal;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* Retrieve pointer to the draw industry tile struct */
|
2007-06-19 17:33:12 +00:00
|
|
|
if (gfx >= NEW_INDUSTRYTILEOFFSET) {
|
|
|
|
/* Draw the tile using the specialized method of newgrf industrytile.
|
|
|
|
* DrawNewIndustry will return false if ever the resolver could not
|
|
|
|
* find any sprite to display. So in this case, we will jump on the
|
|
|
|
* substitute gfx instead. */
|
|
|
|
if (indts->grf_prop.spritegroup != NULL && DrawNewIndustryTile(ti, ind, gfx, indts)) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* No sprite group (or no valid one) found, meaning no graphics associated.
|
|
|
|
* Use the substitute one instead */
|
2007-08-22 00:59:46 +00:00
|
|
|
if (indts->grf_prop.subst_id != INVALID_INDUSTRYTILE) {
|
|
|
|
gfx = indts->grf_prop.subst_id;
|
|
|
|
/* And point the industrytile spec accordingly */
|
|
|
|
indts = GetIndustryTileSpec(gfx);
|
|
|
|
}
|
2007-06-19 17:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ?
|
2007-07-20 17:14:03 +00:00
|
|
|
GetIndustryAnimationState(ti->tile) & INDUSTRY_COMPLETED :
|
2006-12-30 11:57:52 +00:00
|
|
|
GetIndustryConstructionStage(ti->tile))];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
image = dits->ground.sprite;
|
|
|
|
if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) {
|
|
|
|
pal = GENERAL_SPRITE_COLOR(ind->random_color);
|
|
|
|
} else {
|
|
|
|
pal = dits->ground.pal;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
/* DrawFoundation() modifes ti->z and ti->tileh */
|
|
|
|
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-24 10:20:05 +00:00
|
|
|
DrawGroundSprite(image, pal);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* Add industry on top of the ground? */
|
2007-01-14 19:57:49 +00:00
|
|
|
image = dits->building.sprite;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (image != 0) {
|
2007-07-26 14:07:11 +00:00
|
|
|
AddSortableSpriteToDraw(image,
|
|
|
|
(HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->building.pal == PAL_NONE) ? GENERAL_SPRITE_COLOR(ind->random_color) : dits->building.pal,
|
2005-11-16 11:55:06 +00:00
|
|
|
ti->x + dits->subtile_x,
|
|
|
|
ti->y + dits->subtile_y,
|
2007-09-14 21:32:21 +00:00
|
|
|
dits->width,
|
|
|
|
dits->height,
|
2004-08-09 17:04:08 +00:00
|
|
|
dits->dz,
|
2007-07-26 16:51:10 +00:00
|
|
|
ti->z,
|
2007-07-26 14:07:11 +00:00
|
|
|
HASBIT(_transparent_opt, TO_INDUSTRIES));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-05 07:49:04 +00:00
|
|
|
if (HASBIT(_transparent_opt, TO_INDUSTRIES)) 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
|
|
|
}
|
|
|
|
|
2007-07-26 16:51:10 +00:00
|
|
|
static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
|
2005-10-22 06:39:32 +00:00
|
|
|
{
|
2007-07-26 16:51:10 +00:00
|
|
|
return FlatteningFoundation(tileh);
|
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
|
|
|
{
|
2007-07-08 17:40:04 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(tile);
|
|
|
|
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
|
|
|
|
|
|
|
|
/* When we have to use a callback, we put our data in the next two variables */
|
|
|
|
CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)];
|
|
|
|
uint8 raw_acceptance[lengthof(itspec->acceptance)];
|
|
|
|
|
|
|
|
/* And then these will always point to a same sized array with the required data */
|
|
|
|
const CargoID *accepts_cargo = itspec->accepts_cargo;
|
|
|
|
const uint8 *acceptance = itspec->acceptance;
|
|
|
|
|
|
|
|
if (HASBIT(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) {
|
|
|
|
uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile);
|
|
|
|
if (res != CALLBACK_FAILED) {
|
|
|
|
accepts_cargo = raw_accepts_cargo;
|
|
|
|
for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HASBIT(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) {
|
|
|
|
uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile);
|
|
|
|
if (res != CALLBACK_FAILED) {
|
|
|
|
acceptance = raw_acceptance;
|
|
|
|
for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4);
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-29 00:15:34 +00:00
|
|
|
for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) {
|
2007-07-08 17:40:04 +00:00
|
|
|
CargoID a = accepts_cargo[i];
|
|
|
|
if (a != CT_INVALID) ac[a] = acceptance[i];
|
2007-05-29 00:15:34 +00:00
|
|
|
}
|
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;
|
2006-10-24 19:19:25 +00:00
|
|
|
td->str = GetIndustrySpec(i->type)->name;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
static CommandCost 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);
|
2007-03-28 20:06:28 +00:00
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
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) ||
|
2007-03-28 20:06:28 +00:00
|
|
|
(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
|
|
|
|
SetDParam(0, indspec->name);
|
2004-08-09 17:04:08 +00:00
|
|
|
return_cmd_error(STR_4800_IN_THE_WAY);
|
|
|
|
}
|
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
if (flags & DC_EXEC) delete i;
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-07-04 18:27:21 +00:00
|
|
|
cw = min(i->produced_cargo_waiting[0], 255);
|
2006-04-26 21:10:01 +00:00
|
|
|
if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
|
2007-07-04 18:27:21 +00:00
|
|
|
i->produced_cargo_waiting[0] -= cw;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2007-06-07 14:38:45 +00:00
|
|
|
i->this_month_production[0] += cw;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-18 00:33:47 +00:00
|
|
|
am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw);
|
2007-06-07 14:38:45 +00:00
|
|
|
i->this_month_transported[0] += am;
|
2007-07-11 15:03:29 +00:00
|
|
|
if (am != 0 && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
|
2007-03-14 02:52:50 +00:00
|
|
|
uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
|
2006-03-25 10:38:28 +00:00
|
|
|
|
2007-05-29 17:41:59 +00:00
|
|
|
if (newgfx != INDUSTRYTILE_NOANIM) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 18:27:21 +00:00
|
|
|
cw = min(i->produced_cargo_waiting[1], 255);
|
2006-04-26 21:10:01 +00:00
|
|
|
if (cw > indspec->minimal_cargo) {
|
2007-07-04 18:27:21 +00:00
|
|
|
i->produced_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
|
|
|
|
2007-06-07 14:38:45 +00:00
|
|
|
i->this_month_production[1] += cw;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-18 00:33:47 +00:00
|
|
|
am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
|
2007-06-07 14:38:45 +00:00
|
|
|
i->this_month_transported[1] += am;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2007-07-11 15:03:29 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(tile);
|
|
|
|
|
|
|
|
if (GetIndustryTileSpec(gfx)->animation_info != 0xFFFF) {
|
|
|
|
AnimateNewIndustryTile(tile);
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-11 15:03:29 +00:00
|
|
|
switch (gfx) {
|
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) {
|
2006-12-30 11:51:37 +00:00
|
|
|
m = GetIndustryAnimationState(tile) + 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);
|
|
|
|
}
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, 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) {
|
2006-12-30 11:51:37 +00:00
|
|
|
m = GetIndustryAnimationState(tile);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-04-21 02:47:33 +00:00
|
|
|
if (_industry_anim_offs_toffee[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);
|
|
|
|
}
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, m);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-04-14 01:54:07 +00:00
|
|
|
case GFX_BUBBLE_CATCHER:
|
2006-12-30 11:51:37 +00:00
|
|
|
if ((_tick_counter & 1) == 0) {
|
|
|
|
m = GetIndustryAnimationState(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (++m >= 40) {
|
|
|
|
m = 0;
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, m);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/* 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) {
|
2006-12-30 11:51:37 +00:00
|
|
|
m = GetIndustryAnimationState(tile);
|
|
|
|
if (m == 6) {
|
|
|
|
SetIndustryAnimationState(tile, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
} else {
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, m + 1);
|
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) {
|
2006-12-30 11:51:37 +00:00
|
|
|
m = GetIndustryAnimationState(tile) + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-16 02:56:48 +00:00
|
|
|
switch (m) {
|
|
|
|
case 1: SndPlayTileFx(SND_2C_MACHINERY, tile); break;
|
|
|
|
case 23: SndPlayTileFx(SND_2B_COMEDY_HIT, tile); break;
|
|
|
|
case 28: SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); break;
|
|
|
|
default:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, m);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-12-30 11:41:54 +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
|
|
|
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) {
|
2007-04-18 22:10:36 +00:00
|
|
|
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
|
|
|
|
2006-12-30 11:51:37 +00:00
|
|
|
m = GetIndustryAnimationState(tile) + 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)) {
|
|
|
|
SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryConstructionStage(tile, 3);
|
2004-09-11 09:55:19 +00:00
|
|
|
DeleteAnimatedTile(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, 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) {
|
2006-12-30 11:51:37 +00:00
|
|
|
m = GetIndustryAnimationState(tile);
|
|
|
|
if (!(m & 0x40)) {
|
2006-12-30 11:57:52 +00:00
|
|
|
SetIndustryAnimationState(tile, m | 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;
|
|
|
|
}
|
2006-12-30 11:51:37 +00:00
|
|
|
m = (GetIndustryAnimationState(tile) + 1) | 0x40;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (m > 0xC2) m = 0xC0;
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, 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;
|
|
|
|
|
2006-12-30 11:51:37 +00:00
|
|
|
m = (GetIndustryAnimationState(tile) & 0xBF) - 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (m < 0x80) m = 0x82;
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, 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);
|
2007-07-11 15:03:29 +00:00
|
|
|
StartStopIndustryTileAnimation(tile, IAT_CONSTRUCTION_STATE_CHANGE);
|
2007-07-20 17:14:03 +00:00
|
|
|
if (stage == INDUSTRY_COMPLETED) 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
|
|
|
|
2007-07-11 15:03:29 +00:00
|
|
|
IndustryGfx gfx = GetIndustryGfx(tile);
|
|
|
|
if (gfx >= NEW_INDUSTRYTILEOFFSET) {
|
|
|
|
/* New industry */
|
|
|
|
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
|
|
|
|
if (its->animation_info != 0xFFFF) AddAnimatedTile(tile);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (gfx) {
|
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:
|
2006-12-30 11:51:37 +00:00
|
|
|
SetIndustryAnimationState(tile, 0);
|
2006-04-12 18:10:54 +00:00
|
|
|
SetIndustryAnimationLoop(tile, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-12-30 11:41:54 +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
|
|
|
);
|
|
|
|
|
2007-07-26 15:37:19 +00:00
|
|
|
if (v != NULL) v->u.special.animation_substate = 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;
|
2006-12-30 11:51:37 +00:00
|
|
|
IndustryGfx gfx;
|
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);
|
|
|
|
|
2007-07-11 15:03:29 +00:00
|
|
|
if (StartStopIndustryTileAnimation(tile, IAT_TILELOOP)) return;
|
|
|
|
|
2007-03-14 02:52:50 +00:00
|
|
|
newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next;
|
2007-05-29 17:41:59 +00:00
|
|
|
if (newgfx != INDUSTRYTILE_NOANIM) {
|
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-12-30 11:51:37 +00:00
|
|
|
gfx = GetIndustryGfx(tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-30 11:51:37 +00:00
|
|
|
switch (gfx) {
|
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:
|
|
|
|
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED:
|
|
|
|
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED:
|
2006-12-30 11:51:37 +00:00
|
|
|
if (!(_tick_counter & 0x400) && CHANCE16(1, 2)) {
|
|
|
|
switch (gfx) {
|
|
|
|
case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED; break;
|
|
|
|
case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break;
|
|
|
|
case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED; break;
|
|
|
|
}
|
|
|
|
SetIndustryGfx(tile, gfx);
|
|
|
|
SetIndustryAnimationState(tile, 0x80);
|
|
|
|
AddAnimatedTile(tile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_OILWELL_NOT_ANIMATED:
|
2006-12-30 11:51:37 +00:00
|
|
|
if (CHANCE16(1, 6)) {
|
|
|
|
SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1);
|
|
|
|
SetIndustryAnimationState(tile, 0);
|
|
|
|
AddAnimatedTile(tile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
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:
|
2006-12-30 11:51:37 +00:00
|
|
|
if (!(_tick_counter & 0x400)) {
|
|
|
|
switch (gfx) {
|
|
|
|
case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED; break;
|
|
|
|
case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break;
|
|
|
|
case GFX_GOLD_MINE_TOWER_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED; break;
|
|
|
|
}
|
|
|
|
SetIndustryGfx(tile, gfx);
|
|
|
|
SetIndustryCompleted(tile, true);
|
|
|
|
SetIndustryConstructionStage(tile, 3);
|
|
|
|
DeleteAnimatedTile(tile);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-08 22:12:57 +00:00
|
|
|
case GFX_POWERPLANT_SPARKS:
|
2007-04-18 22:10:36 +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
|
|
|
}
|
|
|
|
|
2007-05-24 22:41:50 +00:00
|
|
|
static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_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
|
|
|
{
|
2007-05-18 00:33:47 +00:00
|
|
|
const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type);
|
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
|
|
|
{
|
2007-07-07 08:53:19 +00:00
|
|
|
/* If the founder merges, the industry was created by the merged company */
|
|
|
|
Industry *i = GetIndustryByTile(tile);
|
|
|
|
if (i->founder == old_player) i->founder = (new_player == PLAYER_SPECTATOR) ? OWNER_NONE : new_player;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)) {
|
2007-01-15 16:31:46 +00:00
|
|
|
case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
|
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)) {
|
2007-01-15 16:31:46 +00:00
|
|
|
case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT);
|
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)) {
|
2007-01-10 18:56:51 +00:00
|
|
|
byte or_ = type;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-01-10 18:56:51 +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) {
|
2007-01-10 18:56:51 +00:00
|
|
|
SetFenceSE(tile, or_);
|
2006-03-08 06:55:33 +00:00
|
|
|
} else {
|
2007-01-10 18:56:51 +00:00
|
|
|
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
|
|
|
|
2007-03-22 03:42:43 +00:00
|
|
|
if (_opt.landscape == LT_ARCTIC) {
|
2007-03-20 13:47:00 +00:00
|
|
|
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* determine field size */
|
|
|
|
r = (Random() & 0x303) + 0x404;
|
2007-03-22 03:42:43 +00:00
|
|
|
if (_opt.landscape == LT_ARCTIC) 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;
|
2007-03-22 03:42:43 +00:00
|
|
|
if (_opt.landscape != LT_ARCTIC && _opt.landscape != LT_TROPIC) {
|
2004-08-09 17:04:08 +00:00
|
|
|
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-11-17 23:01:58 +00:00
|
|
|
/**
|
|
|
|
* Search callback function for ChopLumberMillTrees
|
|
|
|
* @param tile to test
|
|
|
|
* @param data that is passed by the caller. In this case, nothing
|
2007-03-03 04:04:22 +00:00
|
|
|
* @return the result of the test
|
2006-11-17 23:01:58 +00:00
|
|
|
*/
|
|
|
|
static bool SearchLumberMillTrees(TileIndex tile, uint32 data)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-02-02 15:14:28 +00:00
|
|
|
if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
|
2006-11-17 23:01:58 +00:00
|
|
|
PlayerID old_player = _current_player;
|
|
|
|
/* found a tree */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-17 23:01:58 +00:00
|
|
|
_current_player = OWNER_NONE;
|
|
|
|
_industry_sound_ctr = 1;
|
|
|
|
_industry_sound_tile = tile;
|
|
|
|
SndPlayTileFx(SND_38_CHAINSAW, tile);
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-11-17 23:01:58 +00:00
|
|
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-11-17 23:01:58 +00:00
|
|
|
_current_player = old_player;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-17 23:01:58 +00:00
|
|
|
/**
|
|
|
|
* Perform a circular search around the Lumber Mill in order to find trees to cut
|
|
|
|
* @param i industry
|
|
|
|
*/
|
|
|
|
static void ChopLumberMillTrees(Industry *i)
|
|
|
|
{
|
|
|
|
TileIndex tile = i->xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-17 23:01:58 +00:00
|
|
|
if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed
|
2004-09-25 17:37:32 +00:00
|
|
|
|
2006-11-17 23:01:58 +00:00
|
|
|
if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles to search
|
2007-07-04 18:27:21 +00:00
|
|
|
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ProduceIndustryGoods(Industry *i)
|
|
|
|
{
|
|
|
|
uint32 r;
|
|
|
|
uint num;
|
2007-05-20 00:50:06 +00:00
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* play a sound? */
|
|
|
|
if ((i->counter & 0x3F) == 0) {
|
2007-05-20 00:50:06 +00:00
|
|
|
if (CHANCE16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
SndPlayTileFx(
|
2007-05-20 00:50:06 +00:00
|
|
|
(SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]),
|
2004-08-09 17:04:08 +00:00
|
|
|
i->xy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i->counter--;
|
|
|
|
|
|
|
|
/* produce some cargo */
|
|
|
|
if ((i->counter & 0xFF) == 0) {
|
2007-07-05 05:41:56 +00:00
|
|
|
if (HASBIT(indsp->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
|
|
|
|
|
2007-05-20 00:50:06 +00:00
|
|
|
IndustyBehaviour indbehav = indsp->behaviour;
|
2007-07-04 18:27:21 +00:00
|
|
|
i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]);
|
|
|
|
i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-08 19:54:51 +00:00
|
|
|
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
|
|
|
|
bool plant;
|
|
|
|
if (HASBIT(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
|
|
|
|
plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0);
|
|
|
|
} else {
|
|
|
|
plant = CHANCE16(1, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plant) PlantRandomFarmField(i);
|
|
|
|
}
|
|
|
|
if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) {
|
|
|
|
bool cut = ((i->counter & 0x1FF) == 0);
|
|
|
|
if (HASBIT(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) {
|
|
|
|
cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cut) ChopLumberMillTrees(i);
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void OnTick_Industry()
|
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) {
|
2007-07-11 15:03:29 +00:00
|
|
|
StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK);
|
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
|
|
|
{
|
2007-03-22 03:42:43 +00:00
|
|
|
if (_opt.landscape == LT_ARCTIC) {
|
2007-03-20 13:47:00 +00:00
|
|
|
if (GetTileZ(tile) < HighestSnowLine() + 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
|
|
|
{
|
2007-03-22 03:42:43 +00:00
|
|
|
if (_opt.landscape == LT_ARCTIC) {
|
2007-03-20 13:47:00 +00:00
|
|
|
if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type, bool *custom_shape_check = NULL)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_error_message = STR_0239_SITE_UNSUITABLE;
|
|
|
|
|
|
|
|
do {
|
2007-08-24 00:23:35 +00:00
|
|
|
IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx);
|
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)) {
|
2007-08-26 00:23:32 +00:00
|
|
|
if (gfx == GFX_WATERTILE_SPECIALCHECK) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-08-26 00:23:32 +00:00
|
|
|
if (gfx == GFX_WATERTILE_SPECIALCHECK) {
|
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;
|
2007-06-13 15:22:28 +00:00
|
|
|
if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false;
|
|
|
|
|
2007-09-06 03:02:38 +00:00
|
|
|
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
|
|
|
|
|
2007-03-28 20:06:28 +00:00
|
|
|
IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
if (HASBIT(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
|
|
|
|
if (custom_shape_check != NULL) *custom_shape_check = true;
|
2007-08-24 00:23:35 +00:00
|
|
|
if (!PerformIndustryTileSlopeCheck(cur_tile, its, type, gfx)) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-07-09 18:53:43 +00:00
|
|
|
if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
|
|
|
|
/* As soon as the tile is not water, bail out.
|
|
|
|
* But that does not mean the search is over. You have
|
|
|
|
* to make sure every tile of the industry will be only water*/
|
|
|
|
if (!IsClearWaterTile(cur_tile)) return false;
|
|
|
|
} else {
|
|
|
|
Slope tileh;
|
2006-03-22 19:04:04 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
if (IsClearWaterTile(cur_tile)) return false;
|
2006-03-22 19:04:04 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
tileh = GetTileSlope(cur_tile, NULL);
|
|
|
|
if (IsSteepSlope(tileh)) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
if (_patches.land_generator != LG_TERRAGENESIS || !_generating_world) {
|
|
|
|
/* 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 = its->slopes_refused;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
if (bits & 0x10) return false;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
t = ComplementSlope(tileh);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 18:53:43 +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;
|
|
|
|
}
|
(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
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-07-09 18:53:43 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) {
|
|
|
|
if (!IsTileType(cur_tile, MP_HOUSE)) {
|
|
|
|
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
|
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-07-11 08:20:57 +00:00
|
|
|
if (CmdFailed(DoCommand(cur_tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR))) return false;
|
|
|
|
} else if ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) == 0 || !IsTileType(cur_tile, MP_HOUSE)) {
|
|
|
|
if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR))) return false;
|
2007-07-09 18:53:43 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2007-03-28 20:06:28 +00:00
|
|
|
if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
|
(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
|
|
|
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-28 20:06:28 +00:00
|
|
|
if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
|
(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
|
|
|
_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 */
|
2007-01-10 18:56:51 +00:00
|
|
|
if (internal != 0 && delta(curh, height) > 1) 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
|
|
|
|
|
|
|
/* 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.. */
|
2007-08-27 21:18:04 +00:00
|
|
|
if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) 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
|
|
|
}
|
|
|
|
} 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 ;) */
|
2007-08-27 21:18:04 +00:00
|
|
|
DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
|
(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
|
|
|
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
|
|
|
|
2007-03-03 04:04:22 +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) {
|
2007-03-03 04:04:22 +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 &&
|
2007-06-11 14:25:38 +00:00
|
|
|
indspec->accepts_cargo[0] == GetIndustrySpec(i->type)->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
|
|
|
|
2007-03-03 04:04:22 +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;
|
|
|
|
}
|
|
|
|
|
2007-08-15 00:49:34 +00:00
|
|
|
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner 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;
|
2007-06-08 15:48:48 +00:00
|
|
|
IncIndustryTypeCount(type);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-26 21:10:01 +00:00
|
|
|
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();
|
2006-10-24 19:19:25 +00:00
|
|
|
i->random_color = GB(r, 8, 4);
|
2005-10-05 04:00:39 +00:00
|
|
|
i->counter = GB(r, 0, 12);
|
2007-07-04 18:27:21 +00:00
|
|
|
i->produced_cargo_waiting[0] = 0;
|
|
|
|
i->produced_cargo_waiting[1] = 0;
|
|
|
|
i->incoming_cargo_waiting[0] = 0;
|
|
|
|
i->incoming_cargo_waiting[1] = 0;
|
|
|
|
i->incoming_cargo_waiting[2] = 0;
|
2007-06-07 14:38:45 +00:00
|
|
|
i->this_month_production[0] = 0;
|
|
|
|
i->this_month_production[1] = 0;
|
|
|
|
i->this_month_transported[0] = 0;
|
|
|
|
i->this_month_transported[1] = 0;
|
|
|
|
i->last_month_pct_transported[0] = 0;
|
|
|
|
i->last_month_pct_transported[1] = 0;
|
|
|
|
i->last_month_transported[0] = 0;
|
|
|
|
i->last_month_transported[1] = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
i->was_cargo_delivered = false;
|
2006-08-20 19:05:28 +00:00
|
|
|
i->last_prod_year = _cur_year;
|
2007-06-07 14:38:45 +00:00
|
|
|
i->last_month_production[0] = i->production_rate[0] * 8;
|
|
|
|
i->last_month_production[1] = i->production_rate[1] * 8;
|
2007-07-07 08:53:19 +00:00
|
|
|
i->founder = _current_player;
|
|
|
|
i->construction_date = _date;
|
|
|
|
i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR :
|
|
|
|
(_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-15 00:49:34 +00:00
|
|
|
/* Adding 1 here makes it conform to specs of var44 of varaction2 for industries
|
|
|
|
* 0 = created prior of newindustries
|
|
|
|
* else, chosen layout + 1 */
|
|
|
|
i->selected_layout = layout + 1;
|
|
|
|
|
2007-06-07 14:38:45 +00:00
|
|
|
if (!_generating_world) i->last_month_production[0] = i->last_month_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
|
|
|
|
2007-08-26 00:23:32 +00:00
|
|
|
if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
|
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-12-30 11:51:37 +00:00
|
|
|
if (_generating_world) {
|
|
|
|
SetIndustryConstructionCounter(cur_tile, 3);
|
|
|
|
SetIndustryConstructionStage(cur_tile, 2);
|
|
|
|
}
|
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++;
|
|
|
|
|
2007-03-28 20:06:28 +00:00
|
|
|
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
|
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);
|
|
|
|
}
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/** Helper function for Build/Fund an industry
|
|
|
|
* @param tile tile where industry is built
|
|
|
|
* @param type of industry to build
|
|
|
|
* @param flags of operations to conduct
|
|
|
|
* @param indspec pointer to industry specifications
|
2007-07-09 13:21:49 +00:00
|
|
|
* @param itspec_index the index of the itsepc to build/fund
|
2007-03-03 04:04:22 +00:00
|
|
|
* @return the pointer of the newly created industry, or NULL if it failed
|
|
|
|
*/
|
2007-07-09 13:21:49 +00:00
|
|
|
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint32 flags, const IndustrySpec *indspec, uint itspec_index)
|
(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
|
|
|
{
|
2007-07-09 13:21:49 +00:00
|
|
|
const IndustryTileTable *it = indspec->table[itspec_index];
|
2007-07-09 18:53:43 +00:00
|
|
|
bool custom_shape_check = false;
|
|
|
|
|
|
|
|
if (!CheckIfIndustryTilesAreFree(tile, it, type, &custom_shape_check)) return NULL;
|
|
|
|
|
2007-07-09 13:21:49 +00:00
|
|
|
if (HASBIT(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) {
|
|
|
|
if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index)) return NULL;
|
2007-07-09 18:53:43 +00:00
|
|
|
} else {
|
|
|
|
if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
|
2007-07-09 13:21:49 +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
|
|
|
|
2007-07-09 18:53:43 +00:00
|
|
|
if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
|
(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 (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
|
|
|
|
|
2007-07-09 13:21:49 +00:00
|
|
|
const Town *t = CheckMultipleIndustryInTown(tile, type);
|
(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 (t == NULL) return NULL;
|
|
|
|
|
|
|
|
if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
|
|
|
|
if (!CheckSuitableIndustryPos(tile)) return NULL;
|
|
|
|
|
2007-08-02 23:21:52 +00:00
|
|
|
Industry *i = new Industry(tile);
|
(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 (i == NULL) return NULL;
|
2007-08-02 23:21:52 +00:00
|
|
|
AutoPtrT<Industry> i_auto_delete = 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
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2007-07-09 18:53:43 +00:00
|
|
|
if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
|
2007-08-15 00:49:34 +00:00
|
|
|
DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE);
|
2007-08-02 23:21:52 +00:00
|
|
|
i_auto_delete.Detach();
|
(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 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
|
2007-03-03 04:04:22 +00:00
|
|
|
* @param flags of operations to conduct
|
|
|
|
* @param p1 industry type see build_industry.h and see industry.h
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p2 unused
|
2007-03-03 04:04:22 +00:00
|
|
|
* @return index of the newly create industry, or CMD_ERROR if it failed
|
2005-05-11 00:00:27 +00:00
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost 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);
|
|
|
|
|
2006-10-27 15:54:24 +00:00
|
|
|
indspec = GetIndustrySpec(p1);
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-10-27 15:54:24 +00:00
|
|
|
/* Check if the to-be built/founded industry is available for this climate. */
|
2007-05-30 01:55:11 +00:00
|
|
|
if (!indspec->enabled) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 15:22:12 +00:00
|
|
|
/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
|
2007-07-06 22:33:16 +00:00
|
|
|
* Raw material industries are industries that do not accept cargo (at least for now) */
|
2007-07-09 13:21:49 +00:00
|
|
|
if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
|
2005-11-14 15:22:12 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 13:21:49 +00:00
|
|
|
if (_game_mode != GM_EDITOR && _patches.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
|
2007-07-06 07:24:10 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
/* Prospecting has a chance to fail, however we cannot guarantee that something can
|
|
|
|
* be built on the map, so the chance gets lower when the map is fuller, but there
|
|
|
|
* is nothing we can really do about that. */
|
|
|
|
if (Random() <= indspec->prospecting_chance) {
|
|
|
|
for (int i = 0; i < 5000; i++) {
|
2007-07-09 13:21:49 +00:00
|
|
|
uint tilespec_index = RandomRange(indspec->num_table);
|
|
|
|
const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, tilespec_index);
|
2007-07-08 18:41:34 +00:00
|
|
|
if (ind != NULL) {
|
|
|
|
SetDParam(0, indspec->name);
|
|
|
|
SetDParam(1, ind->town->index);
|
|
|
|
AddNewsItem(indspec->new_industry_text,
|
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
|
|
|
|
break;
|
|
|
|
}
|
2007-07-06 07:24:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
num = indspec->num_table;
|
|
|
|
itt = indspec->table;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-06 07:24:10 +00:00
|
|
|
do {
|
|
|
|
if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
|
|
|
|
} while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-09 13:21:49 +00:00
|
|
|
if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
|
2007-07-06 07:24:10 +00:00
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-06 22:33:16 +00:00
|
|
|
return CommandCost(indspec->GetConstructionCost());
|
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);
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-09 13:21:49 +00:00
|
|
|
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 03:07:05 +00:00
|
|
|
enum {
|
|
|
|
NB_NUMOFINDUSTRY = 11,
|
|
|
|
NB_DIFFICULTY_LEVEL = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte _numof_industry_table[NB_DIFFICULTY_LEVEL][NB_NUMOFINDUSTRY] = {
|
2007-03-03 04:04:22 +00:00
|
|
|
/* difficulty settings for number of industries */
|
2006-04-26 21:10:01 +00:00
|
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //none
|
2007-05-01 17:16:51 +00:00
|
|
|
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //very low
|
2006-04-26 21:10:01 +00:00
|
|
|
{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
|
|
|
};
|
|
|
|
|
2007-04-09 01:43:29 +00:00
|
|
|
/** This function is the one who really do the creation work
|
|
|
|
* of random industries during game creation
|
|
|
|
* @param type IndustryType of the desired industry
|
|
|
|
* @param amount of industries that need to be built */
|
2006-04-26 21:10:01 +00:00
|
|
|
static void PlaceInitialIndustry(IndustryType type, int amount)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-07-27 03:07:05 +00:00
|
|
|
/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
|
|
|
|
* _numof_industry_table. newgrf can specify a big amount */
|
|
|
|
int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_opt.diff.number_industries][amount];
|
2007-05-30 20:20:58 +00:00
|
|
|
const IndustrySpec *ind_spc = GetIndustrySpec(type);
|
2005-07-15 19:51:54 +00:00
|
|
|
|
2007-04-09 01:43:29 +00:00
|
|
|
/* These are always placed next to the coastline, so we scale by the perimeter instead. */
|
2007-05-30 20:20:58 +00:00
|
|
|
num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(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
|
|
|
}
|
|
|
|
|
2007-04-09 01:43:29 +00:00
|
|
|
/** This function will create ramdon industries during game creation.
|
|
|
|
* It will scale the amount of industries by map size as well as difficulty level */
|
2007-03-07 11:47:46 +00:00
|
|
|
void GenerateIndustries()
|
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
|
|
|
uint i = 0;
|
2007-04-09 01:43:29 +00:00
|
|
|
uint8 chance;
|
|
|
|
IndustryType it;
|
|
|
|
const IndustrySpec *ind_spc;
|
(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
|
|
|
|
|
|
|
/* Find the total amount of industries */
|
2007-07-15 00:26:12 +00:00
|
|
|
if (_opt.diff.number_industries > 0) {
|
2007-07-24 19:56:43 +00:00
|
|
|
for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
|
2007-07-15 00:26:12 +00:00
|
|
|
|
|
|
|
ind_spc = GetIndustrySpec(it);
|
|
|
|
|
|
|
|
if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) {
|
|
|
|
ResetIndustryCreationProbility(it);
|
|
|
|
}
|
2007-04-09 01:43:29 +00:00
|
|
|
|
2007-05-30 01:55:11 +00:00
|
|
|
chance = ind_spc->appear_creation[_opt.landscape];
|
2007-07-15 00:45:02 +00:00
|
|
|
if (ind_spc->enabled && chance > 0) {
|
2007-05-30 01:55:11 +00:00
|
|
|
/* once the chance of appearance is determind, it have to be scaled by
|
|
|
|
* the difficulty level. The "chance" in question is more an index into
|
|
|
|
* the _numof_industry_table,in fact */
|
2007-07-27 03:07:05 +00:00
|
|
|
int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_opt.diff.number_industries][chance];
|
2007-05-30 01:55:11 +00:00
|
|
|
|
|
|
|
/* These are always placed next to the coastline, so we scale by the perimeter instead. */
|
2007-05-30 20:20:58 +00:00
|
|
|
num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
|
2007-05-30 01:55:11 +00:00
|
|
|
i += num;
|
|
|
|
}
|
(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
|
|
|
}
|
2007-04-09 01:43:29 +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
|
|
|
|
|
|
|
SetGeneratingWorldProgress(GWP_INDUSTRY, i);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-15 00:26:12 +00:00
|
|
|
if (_opt.diff.number_industries > 0) {
|
2007-07-24 19:56:43 +00:00
|
|
|
for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
|
2007-07-15 00:26:12 +00:00
|
|
|
/* Once the number of industries has been determined, let's really create them.
|
|
|
|
* The test for chance allows us to try create industries that are available only
|
|
|
|
* for this landscape.
|
|
|
|
* @todo : Do we really have to pass chance as un-scaled value, since we've already
|
|
|
|
* processed that scaling above? No, don't think so. Will find a way. */
|
|
|
|
ind_spc = GetIndustrySpec(it);
|
|
|
|
if (ind_spc->enabled) {
|
|
|
|
chance = ind_spc->appear_creation[_opt.landscape];
|
|
|
|
if (chance > 0) PlaceInitialIndustry(it, chance);
|
|
|
|
}
|
2007-05-30 01:55:11 +00:00
|
|
|
}
|
2007-07-15 00:26:12 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-22 00:59:27 +00:00
|
|
|
/**
|
|
|
|
* Protects an industry from closure if the appropriate flags and conditions are met
|
|
|
|
* INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the
|
|
|
|
* count of industries of this type must one (or lower) in order to be protected
|
|
|
|
* against closure.
|
|
|
|
* @param type IndustryType been queried
|
|
|
|
* @result true if protection is on, false otherwise (except for oil wells)
|
|
|
|
*/
|
|
|
|
static bool CheckIndustryCloseDownProtection(IndustryType type)
|
|
|
|
{
|
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
|
|
|
|
/* oil wells (or the industries with that flag set) are always allowed to closedown */
|
|
|
|
if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _opt.landscape == LT_TEMPERATE) return false;
|
|
|
|
return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE && GetIndustryTypeCount(type) <= 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-20 14:49:41 +00:00
|
|
|
/** Change industry production or do closure
|
|
|
|
* @param i Industry for which changes are performed
|
|
|
|
*/
|
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
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-03 19:25:06 +00:00
|
|
|
if ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
|
2007-07-03 19:16:34 +00:00
|
|
|
for (j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){
|
|
|
|
uint32 r = Random();
|
|
|
|
int old_prod, new_prod, percent;
|
|
|
|
int mag;
|
2005-02-06 15:07:29 +00:00
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
new_prod = old_prod = i->production_rate[j];
|
2007-06-26 21:11:17 +00:00
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
if (CHANCE16I(20, 1024, r)) new_prod -= max(((RandomRange(50) + 10) * old_prod) >> 8, 1U);
|
|
|
|
/* Chance of increasing becomes better when more is transported */
|
|
|
|
if (CHANCE16I(20 + (i->last_month_pct_transported[j] * 20 >> 8), 1024, r >> 16) &&
|
|
|
|
((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) == 0 || _opt.landscape != LT_TEMPERATE)) {
|
|
|
|
new_prod += max(((RandomRange(50) + 10) * old_prod) >> 8, 1U);
|
|
|
|
}
|
2007-06-26 21:11:17 +00:00
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
new_prod = clamp(new_prod, 1, 255);
|
|
|
|
/* Do not stop closing the industry when it has the lowest possible production rate */
|
|
|
|
if (new_prod == old_prod && old_prod > 1) {
|
|
|
|
closeit = false;
|
|
|
|
continue;
|
|
|
|
}
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
|
|
|
|
i->production_rate[j] = new_prod;
|
|
|
|
|
|
|
|
/* Close the industry when it has the lowest possible production rate */
|
|
|
|
if (new_prod > 1) closeit = false;
|
|
|
|
|
|
|
|
mag = abs(percent);
|
|
|
|
if (mag >= 10) {
|
|
|
|
SetDParam(2, mag);
|
|
|
|
SetDParam(0, GetCargo(indspec->produced_cargo[j])->name);
|
|
|
|
SetDParam(1, i->index);
|
|
|
|
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
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-07-03 19:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-03 19:25:06 +00:00
|
|
|
if ((indspec->life_type & INDUSTRYLIFE_PROCESSING) != 0) {
|
2007-07-03 19:16:34 +00:00
|
|
|
if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180)) closeit = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 16:20:47 +00:00
|
|
|
/* If industry will be closed down, show this */
|
2007-09-22 00:59:27 +00:00
|
|
|
if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
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,
|
2007-04-18 22:10:36 +00:00
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0),
|
2005-11-14 19:48:04 +00:00
|
|
|
i->xy + TileDiffXY(1, 1), 0
|
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void UpdateIndustryStatistics(Industry *i)
|
|
|
|
{
|
|
|
|
byte pct;
|
2007-04-16 02:53:55 +00:00
|
|
|
bool refresh = false;
|
2007-05-18 00:33:47 +00:00
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
|
|
|
|
|
|
|
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
|
|
|
if (indsp->produced_cargo[j] != CT_INVALID) {
|
|
|
|
pct = 0;
|
2007-06-07 14:38:45 +00:00
|
|
|
if (i->this_month_production[j] != 0) {
|
2007-05-18 00:33:47 +00:00
|
|
|
i->last_prod_year = _cur_year;
|
2007-06-07 14:38:45 +00:00
|
|
|
pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255);
|
2007-05-18 00:33:47 +00:00
|
|
|
}
|
2007-06-07 14:38:45 +00:00
|
|
|
i->last_month_pct_transported[j] = pct;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-07 14:38:45 +00:00
|
|
|
i->last_month_production[j] = i->this_month_production[j];
|
|
|
|
i->this_month_production[j] = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-07 14:38:45 +00:00
|
|
|
i->last_month_transported[j] = i->this_month_transported[j];
|
|
|
|
i->this_month_transported[j] = 0;
|
2007-05-18 00:33:47 +00:00
|
|
|
refresh = true;
|
2004-09-11 09:55:19 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-04-16 02:53:55 +00:00
|
|
|
if (refresh)
|
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) {
|
2007-08-02 23:21:52 +00:00
|
|
|
delete 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
|
|
|
}
|
|
|
|
|
2007-04-06 02:12:15 +00:00
|
|
|
/** Simple helper that will collect data for the generation of industries */
|
|
|
|
struct ProbabilityHelper {
|
|
|
|
uint16 prob; ///< probability
|
|
|
|
IndustryType ind; ///< industry id correcponding
|
|
|
|
};
|
|
|
|
|
2007-04-04 00:32:40 +00:00
|
|
|
/**
|
|
|
|
* Try to create a random industry, during gameplay
|
|
|
|
*/
|
|
|
|
static void MaybeNewIndustry(void)
|
|
|
|
{
|
|
|
|
Industry *ind; //will receive the industry's creation pointer
|
|
|
|
IndustryType rndtype, j; // Loop controlers
|
|
|
|
const IndustrySpec *ind_spc;
|
|
|
|
uint num = 0;
|
2007-04-19 14:50:01 +00:00
|
|
|
ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector
|
2007-04-04 00:32:40 +00:00
|
|
|
uint16 probability_max = 0;
|
|
|
|
|
|
|
|
/* Generate a list of all possible industries that can be built. */
|
2007-04-19 14:50:01 +00:00
|
|
|
for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
|
2007-04-04 00:32:40 +00:00
|
|
|
byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
|
|
|
|
|
2007-07-15 00:26:12 +00:00
|
|
|
/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
|
|
|
|
* and if appearing chance for this landscape is above 0, this industry can be chosen */
|
|
|
|
if (CheckIfCallBackAllowsAvailability(j, IACT_RANDOMCREATION) && chance != 0) {
|
2007-04-04 00:32:40 +00:00
|
|
|
probability_max += chance;
|
2007-04-06 02:12:15 +00:00
|
|
|
/* adds the result for this industry */
|
|
|
|
cumulative_probs[num].ind = j;
|
|
|
|
cumulative_probs[num++].prob = probability_max;
|
2007-04-04 00:32:40 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 02:12:15 +00:00
|
|
|
/* Find a random type, with maximum being what has been evaluate above*/
|
2007-04-04 00:32:40 +00:00
|
|
|
rndtype = RandomRange(probability_max);
|
2007-04-19 14:50:01 +00:00
|
|
|
for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
|
2007-04-06 02:12:15 +00:00
|
|
|
/* and choose the index of the industry that matches as close as possible this random type */
|
|
|
|
if (cumulative_probs[j].prob >= rndtype) break;
|
2007-04-04 00:32:40 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 02:12:15 +00:00
|
|
|
ind_spc = GetIndustrySpec(cumulative_probs[j].ind);
|
2007-04-04 00:32:40 +00:00
|
|
|
/* Check if it is allowed */
|
2007-03-28 20:06:28 +00:00
|
|
|
if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return;
|
|
|
|
if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-06 02:12:15 +00:00
|
|
|
/* try to create 2000 times this industry */
|
2007-04-04 00:32:40 +00:00
|
|
|
num = 2000;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (;;) {
|
2007-04-06 02:12:15 +00:00
|
|
|
ind = CreateNewIndustry(RandomTile(), cumulative_probs[j].ind);
|
2007-04-04 00:32:40 +00:00
|
|
|
if (ind != NULL) break;
|
|
|
|
if (--num == 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-09 02:04:07 +00:00
|
|
|
SetDParam(0, ind_spc->name);
|
2007-04-04 00:32:40 +00:00
|
|
|
SetDParam(1, ind->town->index);
|
2007-03-09 02:04:07 +00:00
|
|
|
AddNewsItem(ind_spc->new_industry_text,
|
2007-04-18 22:10:36 +00:00
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->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
|
|
|
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
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-04 00:54:38 +00:00
|
|
|
if ((indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
|
|
|
|
bool only_decrease = false;
|
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
/* decrease or increase */
|
|
|
|
if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
|
|
|
|
only_decrease = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-03 19:16:34 +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->last_month_pct_transported[0] > 153) != CHANCE16(1, 3)) {
|
|
|
|
/* Increase production */
|
|
|
|
if (i->prod_level != 0x80) {
|
|
|
|
byte b;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
i->prod_level <<= 1;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2007-07-03 19:16:34 +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
|
|
|
|
2007-07-03 19:16:34 +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
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
str = indspec->production_up_text;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Decrease production */
|
|
|
|
if (i->prod_level == 4) {
|
2007-09-22 00:59:27 +00:00
|
|
|
/* Really set the production to 0 when the industrytype allows it,
|
|
|
|
* since it is equivalent to closing it. */
|
|
|
|
if (!CheckIndustryCloseDownProtection(i->type)) {
|
|
|
|
i->prod_level = 0;
|
|
|
|
str = indspec->closure_text;
|
|
|
|
}
|
2005-02-06 15:07:29 +00:00
|
|
|
} else {
|
2007-07-03 19:16:34 +00:00
|
|
|
i->prod_level >>= 1;
|
|
|
|
i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
|
|
|
|
i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
|
2005-02-06 15:07:29 +00:00
|
|
|
|
2007-07-03 19:16:34 +00:00
|
|
|
str = indspec->production_down_text;
|
2005-02-06 15:07:29 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-07-03 19:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-04 00:54:38 +00:00
|
|
|
if (indspec->life_type & INDUSTRYLIFE_PROCESSING) {
|
2007-07-03 19:16:34 +00:00
|
|
|
/* maybe close */
|
2007-09-22 00:59:27 +00:00
|
|
|
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2) && !CheckIndustryCloseDownProtection(i->type)) {
|
2007-07-03 19:16:34 +00:00
|
|
|
i->prod_level = 0;
|
|
|
|
str = indspec->closure_text;
|
|
|
|
}
|
2005-02-06 15:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (str != STR_NULL) {
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, i->index);
|
2007-04-18 22:10:36 +00:00
|
|
|
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, str == indspec->closure_text ? NT_OPENCLOSE : NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void IndustryMonthlyLoop()
|
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 */
|
2007-04-06 12:57:15 +00:00
|
|
|
if (CHANCE16(3, 100)) {
|
2007-04-04 00:32:40 +00:00
|
|
|
MaybeNewIndustry();
|
2006-12-05 13:58:20 +00:00
|
|
|
} else if (!_patches.smooth_economy) {
|
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;
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/* production-change */
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_sort_dirty = true;
|
|
|
|
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeIndustries()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-08-03 20:18:38 +00:00
|
|
|
_Industry_pool.CleanPool();
|
|
|
|
_Industry_pool.AddBlockToPool();
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2007-06-10 01:25:21 +00:00
|
|
|
ResetIndustryCounts();
|
2004-08-09 17:04:08 +00:00
|
|
|
_industry_sort_dirty = true;
|
2006-09-10 08:28:32 +00:00
|
|
|
_industry_sound_tile = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 22:33:16 +00:00
|
|
|
bool IndustrySpec::IsRawIndustry() const
|
|
|
|
{
|
|
|
|
/* Lumber mills are extractive/organic, but can always be built like a non-raw industry */
|
|
|
|
return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0 &&
|
|
|
|
(this->behaviour & INDUSTRYBEH_CUT_TREES) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Money IndustrySpec::GetConstructionCost() const
|
|
|
|
{
|
|
|
|
return (_price.build_industry *
|
|
|
|
(_patches.raw_industry_construction == 1 && this->IsRawIndustry() ?
|
|
|
|
this->raw_industry_cost_multiplier :
|
|
|
|
this->cost_multiplier
|
|
|
|
)) >> 8;
|
|
|
|
}
|
|
|
|
|
2007-08-30 17:17:04 +00:00
|
|
|
static CommandCost TerraformTile_Industry(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
|
|
|
|
{
|
2007-09-14 22:27:40 +00:00
|
|
|
if (AutoslopeEnabled()) {
|
|
|
|
/* We imitate here TTDP's behaviour:
|
|
|
|
* - Both new and old slope must not be steep.
|
|
|
|
* - TileMaxZ must not be changed.
|
|
|
|
* - Allow autoslope by default.
|
|
|
|
* - Disallow autoslope if callback succeeds and returns non-zero.
|
|
|
|
*/
|
|
|
|
Slope tileh_old = GetTileSlope(tile, NULL);
|
|
|
|
/* TileMaxZ must not be changed. Slopes must not be steep. */
|
|
|
|
if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
|
|
|
|
const IndustryGfx gfx = GetIndustryGfx(tile);
|
|
|
|
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
|
|
|
|
|
|
|
|
/* Call callback 3C 'disable autosloping for industry tiles'. */
|
|
|
|
if (HASBIT(itspec->callback_flags, CBM_INDT_AUTOSLOPE)) {
|
|
|
|
/* If the callback fails, allow autoslope. */
|
|
|
|
uint16 res = GetIndustryTileCallback(CBID_INDUSTRY_AUTOSLOPE, 0, 0, gfx, GetIndustryByTile(tile), tile);
|
|
|
|
if ((res == 0) || (res == CALLBACK_FAILED)) return _price.terraform;
|
|
|
|
} else {
|
|
|
|
// allow autoslope
|
|
|
|
return _price.terraform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-30 17:17:04 +00:00
|
|
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); // funny magic bulldozer
|
|
|
|
}
|
2007-07-06 22:33:16 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern 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 */
|
2007-07-26 16:51:10 +00:00
|
|
|
GetFoundation_Industry, /* get_foundation_proc */
|
2007-08-30 17:17:04 +00:00
|
|
|
TerraformTile_Industry, /* terraform_tile_proc */
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2005-05-30 22:16:05 +00:00
|
|
|
static const SaveLoad _industry_desc[] = {
|
2007-06-07 14:38:45 +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),
|
2007-05-18 00:33:47 +00:00
|
|
|
SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo
|
2007-07-04 18:27:21 +00:00
|
|
|
SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION),
|
|
|
|
SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2),
|
2007-06-07 14:38:45 +00:00
|
|
|
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
|
2007-05-18 00:33:47 +00:00
|
|
|
SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo
|
2007-06-07 14:38:45 +00:00
|
|
|
SLE_VAR(Industry, prod_level, SLE_UINT8),
|
|
|
|
SLE_ARR(Industry, this_month_production, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8, 2),
|
|
|
|
SLE_ARR(Industry, last_month_production, SLE_UINT16, 2),
|
|
|
|
SLE_ARR(Industry, last_month_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, random_color, 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
|
|
|
|
2007-09-04 12:00:12 +00:00
|
|
|
SLE_CONDVAR(Industry, founder, SLE_UINT8, 70, SL_MAX_VERSION),
|
2007-07-07 08:53:19 +00:00
|
|
|
SLE_CONDVAR(Industry, construction_date, SLE_INT32, 70, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Industry, construction_type, SLE_UINT8, 70, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Industry, last_cargo_accepted_at, SLE_INT32, 70, SL_MAX_VERSION),
|
2007-08-15 00:49:34 +00:00
|
|
|
SLE_CONDVAR(Industry, selected_layout, SLE_UINT8, 73, SL_MAX_VERSION),
|
2007-07-07 08:53:19 +00:00
|
|
|
|
2007-09-22 13:56:38 +00:00
|
|
|
SLE_CONDARRX(cpp_offsetof(Industry, psa) + cpp_offsetof(Industry::PersistentStorage, storage), SLE_UINT32, 16, 76, SL_MAX_VERSION),
|
|
|
|
|
2007-03-03 04:04:22 +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()
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_INDY()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Industry *ind;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2007-07-20 14:49:41 +00:00
|
|
|
/* Write the industries */
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-20 16:50:11 +00:00
|
|
|
/* Save and load the mapping between the industry/tile id on the map, and the grf file
|
|
|
|
* it came from. */
|
|
|
|
static const SaveLoad _industries_id_mapping_desc[] = {
|
|
|
|
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
|
|
|
|
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
|
|
|
|
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
|
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
static void Save_IIDS()
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
uint j = _industry_mngr.GetMaxMapping();
|
|
|
|
|
|
|
|
for (i = 0; i < j; i++) {
|
|
|
|
SlSetArrayIndex(i);
|
|
|
|
SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Save_TIDS()
|
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
uint j = _industile_mngr.GetMaxMapping();
|
|
|
|
|
|
|
|
for (i = 0; i < j; i++) {
|
|
|
|
SlSetArrayIndex(i);
|
|
|
|
SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_INDY()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int index;
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2007-06-10 01:25:21 +00:00
|
|
|
ResetIndustryCounts();
|
2005-02-02 17:30:29 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
while ((index = SlIterateArray()) != -1) {
|
2007-08-02 23:21:52 +00:00
|
|
|
Industry *i = new (index) Industry();
|
2005-01-06 22:31:58 +00:00
|
|
|
SlObject(i, _industry_desc);
|
2007-06-08 15:48:48 +00:00
|
|
|
IncIndustryTypeCount(i->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-20 16:50:11 +00:00
|
|
|
static void Load_IIDS()
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
uint max_id;
|
|
|
|
|
|
|
|
/* clear the current mapping stored.
|
|
|
|
* This will create the manager if ever it is not yet done */
|
|
|
|
_industry_mngr.ResetMapping();
|
|
|
|
|
|
|
|
/* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */
|
|
|
|
max_id = _industry_mngr.GetMaxMapping();
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
if ((uint)index >= max_id) break;
|
|
|
|
SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Load_TIDS()
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
uint max_id;
|
|
|
|
|
|
|
|
/* clear the current mapping stored.
|
|
|
|
* This will create the manager if ever it is not yet done */
|
|
|
|
_industile_mngr.ResetMapping();
|
|
|
|
|
|
|
|
/* get boundary for the temporary map loader NUM_INDUSTILES? */
|
2007-07-20 17:25:07 +00:00
|
|
|
max_id = _industile_mngr.GetMaxMapping();
|
2007-07-20 16:50:11 +00:00
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
if ((uint)index >= max_id) break;
|
|
|
|
SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const ChunkHandler _industry_chunk_handlers[] = {
|
2007-07-20 16:50:11 +00:00
|
|
|
{ 'INDY', Save_INDY, Load_INDY, CH_ARRAY},
|
|
|
|
{ 'IIDS', Save_IIDS, Load_IIDS, CH_ARRAY},
|
|
|
|
{ 'TIDS', Save_TIDS, Load_TIDS, CH_ARRAY | CH_LAST},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|