mirror of https://github.com/OpenTTD/OpenTTD
(svn r20336) -Codechange: rework the HQ updating
parent
ffedcc6533
commit
f812e80002
|
@ -101,9 +101,9 @@ static const DrawTileSprites _unmovable_display_datas[] = {
|
||||||
#undef TILE_SPRITE_LINE
|
#undef TILE_SPRITE_LINE
|
||||||
|
|
||||||
static const UnmovableSpec _original_unmovable[] = {
|
static const UnmovableSpec _original_unmovable[] = {
|
||||||
{STR_LAI_UNMOVABLE_DESCRIPTION_TRANSMITTER, 1, 1},
|
{STR_LAI_UNMOVABLE_DESCRIPTION_TRANSMITTER, 0x11, 1, 1},
|
||||||
{STR_LAI_UNMOVABLE_DESCRIPTION_LIGHTHOUSE, 1, 1},
|
{STR_LAI_UNMOVABLE_DESCRIPTION_LIGHTHOUSE, 0x11, 1, 1},
|
||||||
{STR_TOWN_BUILDING_NAME_STATUE_1, 1, 1},
|
{STR_TOWN_BUILDING_NAME_STATUE_1, 0x11, 1, 1},
|
||||||
{STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_OWNED_LAND, 10, 2},
|
{STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_OWNED_LAND, 0x11, 10, 2},
|
||||||
{STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_HEADQUARTERS, 1, 1},
|
{STR_LAI_UNMOVABLE_DESCRIPTION_COMPANY_HEADQUARTERS, 0x22, 1, 1},
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@ void UpdateCompanyHQ(Company *c, uint score);
|
||||||
/** An (unmovable) object that isn't use for transport, industries or houses. */
|
/** An (unmovable) object that isn't use for transport, industries or houses. */
|
||||||
struct UnmovableSpec {
|
struct UnmovableSpec {
|
||||||
StringID name; ///< The name for this object.
|
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 build_cost_multiplier; ///< Build cost multiplier per tile.
|
||||||
uint8 clear_cost_multiplier; ///< Clear cost multiplier per tile.
|
uint8 clear_cost_multiplier; ///< Clear cost multiplier per tile.
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,27 @@
|
||||||
return UnmovableSpec::Get(GetUnmovableType(tile));
|
return UnmovableSpec::Get(GetUnmovableType(tile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase the animation stage of a whole structure.
|
||||||
|
* @param northern The northern tile of the structure.
|
||||||
|
* @pre GetUnmovableOffset(northern) == 0
|
||||||
|
*/
|
||||||
|
void IncreaseAnimationStage(TileIndex northern)
|
||||||
|
{
|
||||||
|
assert(GetUnmovableOffset(northern) == 0);
|
||||||
|
const UnmovableSpec *spec = UnmovableSpec::GetByTile(northern);
|
||||||
|
|
||||||
|
TileArea ta(northern, GB(spec->size, 0, 4), GB(spec->size, 4, 4));
|
||||||
|
TILE_AREA_LOOP(t, ta) {
|
||||||
|
SetUnmovableAnimationStage(t, GetUnmovableAnimationStage(t) + 1);
|
||||||
|
MarkTileDirtyByTile(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** We encode the company HQ size in the animation stage. */
|
/** We encode the company HQ size in the animation stage. */
|
||||||
#define GetCompanyHQSize GetUnmovableAnimationStage
|
#define GetCompanyHQSize GetUnmovableAnimationStage
|
||||||
|
/** We encode the company HQ size in the animation stage. */
|
||||||
|
#define IncreaseCompanyHQSize IncreaseAnimationStage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a HQ.
|
* Destroy a HQ.
|
||||||
|
@ -91,12 +110,9 @@ void UpdateCompanyHQ(Company *c, uint score)
|
||||||
(val++, score < 720) ||
|
(val++, score < 720) ||
|
||||||
(val++, true);
|
(val++, true);
|
||||||
|
|
||||||
EnlargeCompanyHQ(tile, val);
|
while (GetCompanyHQSize(tile) < val) {
|
||||||
|
IncreaseCompanyHQSize(tile);
|
||||||
MarkTileDirtyByTile(tile);
|
}
|
||||||
MarkTileDirtyByTile(tile + TileDiffXY(0, 1));
|
|
||||||
MarkTileDirtyByTile(tile + TileDiffXY(1, 0));
|
|
||||||
MarkTileDirtyByTile(tile + TileDiffXY(1, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern CommandCost CheckFlatLand(TileArea tile_area, DoCommandFlag flags);
|
extern CommandCost CheckFlatLand(TileArea tile_area, DoCommandFlag flags);
|
||||||
|
|
|
@ -153,25 +153,6 @@ static inline void SetUnmovableOffset(TileIndex t, uint8 offset)
|
||||||
_m[t].m3 = offset;
|
_m[t].m3 = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enlarge the given HQ to the given size. If the new size
|
|
||||||
* is larger than the current size, nothing happens.
|
|
||||||
* @param t the tile of the HQ.
|
|
||||||
* @param size the new size of the HQ.
|
|
||||||
* @pre t is the northern tile of the HQ
|
|
||||||
*/
|
|
||||||
static inline void EnlargeCompanyHQ(TileIndex t, byte size)
|
|
||||||
{
|
|
||||||
assert(GetUnmovableOffset(t) == 0);
|
|
||||||
assert(size <= 4);
|
|
||||||
if (size <= GetUnmovableAnimationStage(t)) return;
|
|
||||||
|
|
||||||
SetUnmovableAnimationStage(t, size);
|
|
||||||
SetUnmovableAnimationStage(t + TileDiffXY(0, 1), size);
|
|
||||||
SetUnmovableAnimationStage(t + TileDiffXY(1, 0), size);
|
|
||||||
SetUnmovableAnimationStage(t + TileDiffXY(1, 1), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an Unmovable tile.
|
* Make an Unmovable tile.
|
||||||
|
|
Loading…
Reference in New Issue