Changeset - r10491:e3e4bb1ebaea
[Not reviewed]
master
0 3 0
smatz - 16 years ago 2008-12-26 19:37:50
smatz@openttd.org
(svn r14746) -Fix: don't let any disaster vehicle (Helicopter or Airplane) target invalid industry
3 files changed with 21 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/disaster_cmd.cpp
Show inline comments
 
@@ -1042,32 +1042,48 @@ static void DoDisaster()
 

	
 
	_disaster_initprocs[buf[RandomRange(j)]]();
 
}
 

	
 

	
 
static void ResetDisasterDelay()
 
{
 
	_disaster_delay = GB(Random(), 0, 9) + 730;
 
}
 

	
 
void DisasterDailyLoop()
 
{
 
	if (--_disaster_delay != 0) return;
 

	
 
	ResetDisasterDelay();
 

	
 
	if (_settings_game.difficulty.disasters != 0) DoDisaster();
 
}
 

	
 
void StartupDisasters()
 
{
 
	ResetDisasterDelay();
 
}
 

	
 
/** Marks all disasters targeting this industry in such a way
 
 * they won't call GetIndustry(v->dest_tile) on invalid industry anymore.
 
 * @param i deleted industry
 
 */
 
void ReleaseDisastersTargetingIndustry(IndustryID i)
 
{
 
	Vehicle *v;
 
	FOR_ALL_VEHICLES(v) {
 
		/* primary disaster vehicles that have chosen target */
 
		if (v->type == VEH_DISASTER && (v->subtype == ST_Airplane || v->subtype == ST_Helicopter)) {
 
			/* if it has chosen target, and it is this industry (yes, dest_tile is IndustryID here), set order to "leaving map peacefully" */
 
			if (v->current_order.GetDestination() > 0 && v->dest_tile == i) v->current_order.SetDestination(3);
 
		}
 
	}
 
}
 

	
 
void DisasterVehicle::UpdateDeltaXY(Direction direction)
 
{
 
	this->x_offs        = -1;
 
	this->y_offs        = -1;
 
	this->x_extent      =  2;
 
	this->y_extent      =  2;
 
	this->z_extent      =  5;
 
}
src/industry.h
Show inline comments
 
@@ -217,48 +217,50 @@ struct IndustrySpec {
 
struct IndustryTileSpec {
 
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
 
	uint8 acceptance[3];                  ///< Level of aceptance per cargo type
 
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
 
	byte anim_production;                 ///< Animation frame to start when goods are produced
 
	byte anim_next;                       ///< Next frame in an animation
 
	bool anim_state;                      ///< When true, the tile has to be drawn using the animation
 
	                                      ///< state instead of the construction state
 
	/* Newgrf data */
 
	uint8 callback_flags;                 ///< Flags telling which grf callback is set
 
	uint16 animation_info;                ///< Information about the animation (is it looping, how many loops etc)
 
	uint8 animation_speed;                ///< The speed of the animation
 
	uint8 animation_triggers;             ///< When to start the animation
 
	uint8 animation_special_flags;        ///< Extra flags to influence the animation
 
	bool enabled;                         ///< entity still avaible (by default true).newgrf can disable it, though
 
	struct GRFFileProps grf_prop;
 
};
 

	
 
/* industry_cmd.cpp*/
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries data
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);  ///< Array of industry tiles data
 
void ResetIndustries();
 
void PlantRandomFarmField(const Industry *i);
 

	
 
void ReleaseDisastersTargetingIndustry(IndustryID);
 

	
 
/* writable arrays of specs */
 
extern IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
 
extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
 

	
 
static inline IndustryGfx GetTranslatedIndustryTileID(IndustryGfx gfx)
 
{
 
	/* the 0xFF should be GFX_WATERTILE_SPECIALCHECK but for reasons of include mess,
 
	 * we'll simplify the writing.
 
	 * Basically, the first test is required since the GFX_WATERTILE_SPECIALCHECK value
 
	 * will never be assigned as a tile index and is only required in order to do some
 
	 * tests while building the industry (as in WATER REQUIRED */
 
	if (gfx != 0xFF) {
 
		assert(gfx < INVALID_INDUSTRYTILE);
 
		const IndustryTileSpec *it = &_industry_tile_specs[gfx];
 
		return it->grf_prop.override == INVALID_INDUSTRYTILE ? gfx : it->grf_prop.override;
 
	} else {
 
		return gfx;
 
	}
 
}
 

	
 
/* smallmap_gui.cpp */
 
void BuildIndustriesLegend();
 
/* industry_cmd.cpp */
 
void SetIndustryDailyChanges();
src/industry_cmd.cpp
Show inline comments
 
@@ -145,48 +145,51 @@ Industry::~Industry()
 
	}
 

	
 
	BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
 
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
 
			if (GetIndustryIndex(tile_cur) == this->index) {
 
				/* MakeWaterKeepingClass() can also handle 'land' */
 
				MakeWaterKeepingClass(tile_cur, OWNER_NONE);
 
			}
 
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			DeleteOilRig(tile_cur);
 
		}
 
	END_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
 

	
 
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 
		/* Remove the farmland and convert it to regular tiles over time. */
 
		BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
 
			tile_cur = TILE_MASK(tile_cur);
 
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
 
					GetIndustryIndexOfField(tile_cur) == this->index) {
 
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
 
			}
 
		} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
 
	}
 

	
 
	/* don't let any disaster vehicle target invalid industry */
 
	ReleaseDisastersTargetingIndustry(this->index);
 

	
 
	DecIndustryTypeCount(this->type);
 

	
 
	DeleteSubsidyWithIndustry(this->index);
 
	DeleteWindowById(WC_INDUSTRY_VIEW, this->index);
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
 
	this->xy = 0;
 
}
 

	
 
static void IndustryDrawSugarMine(const TileInfo *ti)
 
{
 
	const DrawIndustryAnimationStruct *d;
 

	
 
	if (!IsIndustryCompleted(ti->tile)) return;
 

	
 
	d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)];
 

	
 
	AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0);
 

	
 
	if (d->image_2 != 0) {
 
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
 
	}
 

	
 
	if (d->image_3 != 0) {
 
		AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
0 comments (0 inline, 0 general)