Changeset - r15665:8a1a5d5b328a
[Not reviewed]
master
0 4 0
rubidium - 14 years ago 2010-08-03 12:07:55
rubidium@openttd.org
(svn r20340) -Codechange: introduce some flags for objects and use them in some places
4 files changed with 57 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/table/unmovable_land.h
Show inline comments
 
@@ -122,12 +122,12 @@ static const DrawTileSprites _unmovable_
 
};
 

	
 
#undef TILE_SPRITE_LINE
 

	
 
/** Specification of the original unmovable structures. */
 
static const UnmovableSpec _original_unmovable[] = {
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_TRANSMITTER,          0x11,   1,   1 },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_LIGHTHOUSE,           0x11,   1,   1 },
 
	{ STR_TOWN_BUILDING_NAME_STATUE_1,                    0x11,   1,   1 },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_OWNED_LAND,   0x11,  10,   2 },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_HEADQUARTERS, 0x22,   1,   1 },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_TRANSMITTER,          0x11,   1,   1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_REQUIRE_FLAT },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_LIGHTHOUSE,           0x11,   1,   1, OBJECT_FLAG_CANNOT_REMOVE | OBJECT_FLAG_REQUIRE_FLAT },
 
	{ STR_TOWN_BUILDING_NAME_STATUE_1,                    0x11,   1,   1, OBJECT_FLAG_CANNOT_REMOVE },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_OWNED_LAND,   0x11,  10,   2, OBJECT_FLAG_AUTOREMOVE | OBJECT_FLAG_CLEAR_INCOME | OBJECT_FLAG_HAS_NO_FOUNDATION | OBJECT_FLAG_ALLOW_UNDER_BRIDGE },
 
	{ STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_HEADQUARTERS, 0x22,   1,   1, OBJECT_FLAG_CANNOT_REMOVE },
 
};
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -13,13 +13,13 @@
 
 * @todo seperate this file into two
 
 */
 

	
 
#include "stdafx.h"
 
#include "rail_map.h"
 
#include "landscape.h"
 
#include "unmovable_map.h"
 
#include "unmovable.h"
 
#include "viewport_func.h"
 
#include "cmd_helper.h"
 
#include "command_func.h"
 
#include "town.h"
 
#include "train.h"
 
#include "ship.h"
 
@@ -392,15 +392,17 @@ CommandCost CmdBuildBridge(TileIndex end
 
				case MP_TUNNELBRIDGE:
 
					if (IsTunnel(tile)) break;
 
					if (direction == DiagDirToAxis(GetTunnelBridgeDirection(tile))) goto not_valid_below;
 
					if (z_start < GetBridgeHeight(tile)) goto not_valid_below;
 
					break;
 

	
 
				case MP_UNMOVABLE:
 
					if (!IsOwnedLand(tile)) goto not_valid_below;
 
				case MP_UNMOVABLE: {
 
					const UnmovableSpec *spec = UnmovableSpec::GetByTile(tile);
 
					if ((spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) == 0) goto not_valid_below;
 
					break;
 
				}
 

	
 
				case MP_CLEAR:
 
					break;
 

	
 
				default:
 
	not_valid_below:;
src/unmovable.h
Show inline comments
 
@@ -33,18 +33,39 @@ void UpdateCompanyHQ(Company *c, uint sc
 
 * @pre All preconditions for building the object at that location
 
 *      are met, e.g. slope and clearness of tiles are checked.
 
 */
 
void BuildUnmovable(UnmovableType type, TileIndex tile, CompanyID owner = OWNER_NONE, uint index = 0);
 

	
 

	
 
/** Various object behaviours. */
 
enum ObjectFlags {
 
	OBJECT_FLAG_NONE               =       0, ///< Just nothing.
 
	OBJECT_FLAG_ONLY_IN_SCENEDIT   = 1 <<  0, ///< Object can only be constructed in the scenario editor.
 
	OBJECT_FLAG_CANNOT_REMOVE      = 1 <<  1, ///< Object can not be removed.
 
	OBJECT_FLAG_AUTOREMOVE         = 1 <<  2, ///< Object get automatically removed (like "owned land").
 
	OBJECT_FLAG_BUILT_ON_WATER     = 1 <<  3, ///< Object can be built on water (not required).
 
	OBJECT_FLAG_CLEAR_INCOME       = 1 <<  4, ///< When object is cleared a positive income is generated instead of a cost.
 
	OBJECT_FLAG_HAS_NO_FOUNDATION  = 1 <<  5, ///< Do not display foundations when on a slope.
 
	OBJECT_FLAG_ANIMATION          = 1 <<  6, ///< Object has animated tiles.
 
	OBJECT_FLAG_ONLY_IN_GAME       = 1 <<  7, ///< Object can only be built in game.
 
	OBJECT_FLAG_2CC_COLOUR         = 1 <<  8, ///< Object wants 2CC colour mapping.
 
	OBJECT_FLAG_NOT_ON_LAND        = 1 <<  9, ///< Object can not be on land, implicitly sets #OBJECT_FLAG_BUILT_ON_WATER.
 
	OBJECT_FLAG_DRAW_WATER         = 1 << 10, ///< Object wants to be drawn on water.
 
	OBJECT_FLAG_ALLOW_UNDER_BRIDGE = 1 << 11, ///< Object can built under a bridge.
 
	OBJECT_FLAG_REQUIRE_FLAT       = 1 << 12, ///< Object can only be build of flat land, i.e. not on foundations!
 
};
 
DECLARE_ENUM_AS_BIT_SET(ObjectFlags)
 

	
 

	
 
/** An (unmovable) object that isn't use for transport, industries or houses. */
 
struct UnmovableSpec {
 
	StringID name;               ///< The name for this object.
 
	uint8 size;                  ///< The size of this objects; low nibble for X, high nibble for Y.
 
	uint8 build_cost_multiplier; ///< Build cost multiplier per tile.
 
	uint8 clear_cost_multiplier; ///< Clear cost multiplier per tile.
 
	ObjectFlags flags;           ///< Flags/settings related to the object.
 

	
 
	/**
 
	 * Get the cost for building a structure of this type.
 
	 * @return The cost for building.
 
	 */
 
	Money GetBuildCost() const { return (_price[PR_BUILD_UNMOVABLE] * this->build_cost_multiplier); }
src/unmovable_cmd.cpp
Show inline comments
 
@@ -242,26 +242,39 @@ CommandCost CmdBuildUnmovable(TileIndex 
 

	
 
static Foundation GetFoundation_Unmovable(TileIndex tile, Slope tileh);
 

	
 
static void DrawTile_Unmovable(TileInfo *ti)
 
{
 
	UnmovableType type = GetUnmovableType(ti->tile);
 
	if (type != UNMOVABLE_OWNED_LAND) DrawFoundation(ti, GetFoundation_Unmovable(ti->tile, ti->tileh));
 
	const UnmovableSpec *spec = UnmovableSpec::Get(type);
 
	if ((spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) == 0) DrawFoundation(ti, GetFoundation_Unmovable(ti->tile, ti->tileh));
 

	
 
	const DrawTileSprites *dts = NULL;
 
	Owner to = GetTileOwner(ti->tile);
 
	PaletteID palette = to == OWNER_NONE ? PAL_NONE : COMPANY_SPRITE_COLOUR(to);
 

	
 
	if (type == UNMOVABLE_HQ) {
 
		uint8 offset = GetUnmovableOffset(ti->tile);
 
		dts = &_unmovable_hq[GetCompanyHQSize(ti->tile) << 2 | GB(offset, 4, 1) << 1 | GB(offset, 0, 1)];
 
	} else {
 
		dts = &_unmovables[type];
 
	}
 

	
 
	DrawGroundSprite(dts->ground.sprite, palette);
 
	if (spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) {
 
		/* If an object has no foundation, but tries to draw a (flat) ground
 
		 * type... we have to be nice and convert that for them. */
 
		switch (dts->ground.sprite) {
 
			case SPR_FLAT_BARE_LAND:          DrawClearLandTile(ti, 0); break;
 
			case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1); break;
 
			case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2); break;
 
			case SPR_FLAT_GRASS_TILE:         DrawClearLandTile(ti, 3); break;
 
			default: DrawGroundSprite(dts->ground.sprite, palette);     break;
 
		}
 
	} else {
 
		DrawGroundSprite(dts->ground.sprite, palette);
 
	}
 

	
 
	if (!IsInvisibilitySet(TO_STRUCTURES)) {
 
		const DrawTileSeqStruct *dtss;
 
		foreach_draw_tile_seq(dtss, dts->seq) {
 
			AddSortableSpriteToDraw(
 
				dtss->image.sprite, palette,
 
@@ -270,13 +283,13 @@ static void DrawTile_Unmovable(TileInfo 
 
				dtss->size_z, ti->z + dtss->delta_z,
 
				IsTransparencySet(TO_STRUCTURES)
 
			);
 
		}
 
	}
 

	
 
	if (type == UNMOVABLE_OWNED_LAND) DrawBridgeMiddle(ti);
 
	if (spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) DrawBridgeMiddle(ti);
 
}
 

	
 
static uint GetSlopeZ_Unmovable(TileIndex tile, uint x, uint y)
 
{
 
	if (IsOwnedLand(tile)) {
 
		uint z;
 
@@ -534,19 +547,25 @@ static void ChangeTileOwner_Unmovable(Ti
 
		DoClearSquare(tile);
 
	}
 
}
 

	
 
static CommandCost TerraformTile_Unmovable(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	/* Owned land remains unsold */
 
	UnmovableType type = GetUnmovableType(tile);
 
	const UnmovableSpec *spec = UnmovableSpec::Get(type);
 

	
 
	if (spec->flags & OBJECT_FLAG_REQUIRE_FLAT) {
 
		/* If a flat tile is required by the object, then terraforming is never good. */
 
		return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	}
 

	
 
	if (IsOwnedLand(tile)) {
 
		/* Owned land remains unsold */
 
		CommandCost ret = CheckTileOwnership(tile);
 
		if (ret.Succeeded()) return CommandCost();
 
	}
 

	
 
	if (AutoslopeEnabled() && (IsStatue(tile) || IsCompanyHQ(tile))) {
 
	} else if (AutoslopeEnabled()) {
 
		if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
}
 

	
0 comments (0 inline, 0 general)