File diff r4076:ac684fc44bc2 → r4077:259c4c4aacad
unmovable_cmd.c
Show inline comments
 
@@ -30,50 +30,49 @@ static int32 DestroyCompanyHQ(PlayerID p
 
	Player* p = GetPlayer(pid);
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
 

	
 
	if (flags & DC_EXEC) {
 
		TileIndex t = p->location_of_house;
 

	
 
		DoClearSquare(t + TileDiffXY(0, 0));
 
		DoClearSquare(t + TileDiffXY(0, 1));
 
		DoClearSquare(t + TileDiffXY(1, 0));
 
		DoClearSquare(t + TileDiffXY(1, 1));
 
		p->location_of_house = 0; // reset HQ position
 
		InvalidateWindow(WC_COMPANY, pid);
 
	}
 

	
 
	// cost of relocating company is 1% of company value
 
	return CalculateCompanyValue(p) / 100;
 
}
 

	
 
void UpdateCompanyHQ(Player *p, uint score)
 
{
 
	byte val;
 
	TileIndex tile = p->location_of_house;
 

	
 
	if (tile == 0)
 
		return;
 
	if (tile == 0) return;
 

	
 
	(val = 0, score < 170) ||
 
	(val++, score < 350) ||
 
	(val++, score < 520) ||
 
	(val++, score < 720) ||
 
	(val++, true);
 

	
 
	EnlargeCompanyHQ(tile, val);
 

	
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 0));
 
	MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
 
	MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
 
	MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
 
}
 

	
 
/** Build or relocate the HQ. This depends if the HQ is already built or not
 
 * @param tile tile where the HQ will be built or relocated to
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
 
extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, int *);
 
int32 CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Player *p = GetPlayer(_current_player);
 
@@ -89,104 +88,110 @@ int32 CmdBuildCompanyHQ(TileIndex tile, 
 
	if (p->location_of_house != 0) { /* Moving HQ */
 
		cost += DestroyCompanyHQ(_current_player, flags);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		int score = UpdateCompanyRatingAndValue(p, false);
 

	
 
		p->location_of_house = tile;
 

	
 
		MakeCompanyHQ(tile, _current_player);
 

	
 
		UpdateCompanyHQ(p, score);
 
		InvalidateWindow(WC_COMPANY, p->index);
 
	}
 

	
 
	return cost;
 
}
 

	
 
static void DrawTile_Unmovable(TileInfo *ti)
 
{
 
	uint32 image, ormod;
 

	
 
	switch (GetUnmovableType(ti->tile)) {
 
		case UNMOVABLE_TRANSMITTER:
 
		case UNMOVABLE_LIGHTHOUSE:
 
			{
 
		case UNMOVABLE_LIGHTHOUSE: {
 
				const DrawTileUnmovableStruct *dtus;
 

	
 
				if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
 
				DrawClearLandTile(ti, 2);
 

	
 
				dtus = &_draw_tile_unmovable_data[GetUnmovableType(ti->tile)];
 

	
 
				image = dtus->image;
 
				if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
 

	
 
				AddSortableSpriteToDraw(image, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
 
					dtus->width, dtus->height, dtus->z_size, ti->z);
 
			} break;
 
			AddSortableSpriteToDraw(
 
				image, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
 
				dtus->width, dtus->height, dtus->z_size, ti->z
 
			);
 
			break;
 
		}
 

	
 
		case UNMOVABLE_STATUE:
 
			DrawGroundSprite(SPR_CONCRETE_GROUND);
 

	
 
			image = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
 
			image += PALETTE_MODIFIER_COLOR | SPR_STATUE_COMPANY;
 
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
 
			AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 25, ti->z);
 
			break;
 

	
 
		case UNMOVABLE_OWNED_LAND:
 
			DrawClearLandTile(ti, 0);
 

	
 
			AddSortableSpriteToDraw(
 
				PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)) + PALETTE_MODIFIER_COLOR + SPR_BOUGHT_LAND,
 
				ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 10, GetSlopeZ(ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2)
 
			);
 
			break;
 

	
 
			break;
 
		default:
 
			{
 
		default: {
 
				const DrawTileSeqStruct *dtss;
 
				const DrawTileSprites *t;
 

	
 
				assert(IsCompanyHQ(ti->tile));
 
				if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
 

	
 
				ormod = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
 

	
 
				t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)];
 
				DrawGroundSprite(t->ground_sprite | ormod);
 

	
 
				foreach_draw_tile_seq(dtss, t->seq) {
 
					image = dtss->image;
 
					if (_display_opt & DO_TRANS_BUILDINGS) {
 
						MAKE_TRANSPARENT(image);
 
					} else {
 
						image |= ormod;
 
					}
 
					AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
						dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
 
				AddSortableSpriteToDraw(
 
					image, ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
					dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z
 
				);
 
				}
 
			} break;
 
			break;
 
		}
 
	}
 
}
 

	
 
static uint GetSlopeZ_Unmovable(const TileInfo* ti)
 
{
 
	if (IsOwnedLand(ti->tile)) {
 
		return ti->z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh);
 
	} else {
 
		return ti->z + (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT);
 
	}
 
}
 

	
 
static Slope GetSlopeTileh_Unmovable(TileIndex tile, Slope tileh)
 
{
 
	return IsOwnedLand(tile) ? tileh : SLOPE_FLAT;
 
}
 

	
 
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
 
{
 
	if (IsCompanyHQ(tile)) {
 
		if (_current_player == OWNER_WATER) {
 
			return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
 
		} else {
 
			return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);