mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
(svn r20337) -Codechange: unify the construction of objects on the map
This commit is contained in:
parent
f812e80002
commit
3bfe26c69d
@ -1804,7 +1804,7 @@ bool AfterLoadGame()
|
||||
/* Reordering/generalisation of the unmovable bits. */
|
||||
UnmovableType type = GetUnmovableType(t);
|
||||
SetUnmovableAnimationStage(t, type == UNMOVABLE_HQ ? GB(_m[t].m3, 2, 3) : 0);
|
||||
SetUnmovableOffset(t, type == UNMOVABLE_HQ ? GB(_m[t].m3, 1, 1) << 4 | GB(_m[t].m3, 0, 1) : 0);
|
||||
SetUnmovableOffset(t, type == UNMOVABLE_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0);
|
||||
|
||||
/* Make sure those bits are clear as well! */
|
||||
_m[t].m4 = 0;
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "company_base.h"
|
||||
#include "news_func.h"
|
||||
#include "gui.h"
|
||||
#include "unmovable_map.h"
|
||||
#include "unmovable.h"
|
||||
#include "genworld.h"
|
||||
#include "newgrf_debug.h"
|
||||
#include "newgrf_house.h"
|
||||
@ -2504,7 +2504,7 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags)
|
||||
if (CircularTileSearch(&tile, 9, SearchTileForStatue, NULL)) {
|
||||
if (flags & DC_EXEC) {
|
||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
MakeStatue(tile, _current_company, t->index);
|
||||
BuildUnmovable(UNMOVABLE_STATUE, tile, _current_company, t->index);
|
||||
SetBit(t->statues, _current_company); // Once found and built, "inform" the Town.
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
|
@ -16,8 +16,26 @@
|
||||
#include "strings_type.h"
|
||||
#include "unmovable_type.h"
|
||||
|
||||
/**
|
||||
* Update the CompanyHQ to the state associated with the given score
|
||||
* @param c The company to (possibly) update the HQ of.
|
||||
* @param score The current (performance) score of the company.
|
||||
* @pre c != NULL
|
||||
*/
|
||||
void UpdateCompanyHQ(Company *c, uint score);
|
||||
|
||||
/**
|
||||
* Actually build the unmovable object.
|
||||
* @param type The type of object to build.
|
||||
* @param tile The tile to build the northern tile of the object on.
|
||||
* @param owner The owner of the object.
|
||||
* @param index A (generic) index to be stored on the tile, e.g. TownID for statues.
|
||||
* @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);
|
||||
|
||||
|
||||
/** An (unmovable) object that isn't use for transport, industries or houses. */
|
||||
struct UnmovableSpec {
|
||||
StringID name; ///< The name for this object.
|
||||
|
@ -46,6 +46,18 @@
|
||||
return UnmovableSpec::Get(GetUnmovableType(tile));
|
||||
}
|
||||
|
||||
void BuildUnmovable(UnmovableType type, TileIndex tile, CompanyID owner, uint index)
|
||||
{
|
||||
const UnmovableSpec *spec = UnmovableSpec::Get(type);
|
||||
|
||||
TileArea ta(tile, GB(spec->size, 0, 4), GB(spec->size, 4, 4));
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
TileIndex offset = t - tile;
|
||||
MakeUnmovable(t, type, owner, TileY(offset) << 4 | TileX(offset), index);
|
||||
MarkTileDirtyByTile(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the animation stage of a whole structure.
|
||||
* @param northern The northern tile of the structure.
|
||||
@ -143,7 +155,7 @@ static CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32
|
||||
|
||||
c->location_of_HQ = tile;
|
||||
|
||||
MakeCompanyHQ(tile, _current_company);
|
||||
BuildUnmovable(UNMOVABLE_HQ, tile, _current_company);
|
||||
|
||||
UpdateCompanyHQ(c, score);
|
||||
SetWindowDirty(WC_COMPANY, c->index);
|
||||
@ -174,7 +186,7 @@ static CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
MakeOwnedLand(tile, _current_company);
|
||||
BuildUnmovable(UNMOVABLE_OWNED_LAND, tile, _current_company);
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
|
||||
@ -206,7 +218,7 @@ CommandCost CmdBuildUnmovable(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
||||
if (_game_mode != GM_EDITOR) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
MakeUnmovable(tile, type, OWNER_NONE);
|
||||
BuildUnmovable(type, tile);
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
break;
|
||||
@ -275,7 +287,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
|
||||
PaletteID palette = COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile));
|
||||
|
||||
uint8 offset = GetUnmovableOffset(ti->tile);
|
||||
const DrawTileSprites *t = &_unmovable_display_datas[GetCompanyHQSize(ti->tile) << 2 | GB(offset, 4, 1) << 1 | GB(offset, 0, 1)];
|
||||
const DrawTileSprites *t = &_unmovable_display_datas[GetCompanyHQSize(ti->tile) << 2 | GB(offset, 4, 1) | GB(offset, 0, 1) << 1];
|
||||
DrawGroundSprite(t->ground.sprite, palette);
|
||||
|
||||
if (IsInvisibilitySet(TO_STRUCTURES)) break;
|
||||
@ -484,7 +496,7 @@ void GenerateUnmovables()
|
||||
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h >= TILE_HEIGHT * 4 && !IsBridgeAbove(tile)) {
|
||||
if (IsRadioTowerNearby(tile)) continue;
|
||||
|
||||
MakeTransmitter(tile);
|
||||
BuildUnmovable(UNMOVABLE_TRANSMITTER, tile);
|
||||
IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
|
||||
if (--radiotower_to_build == 0) break;
|
||||
}
|
||||
@ -518,7 +530,7 @@ void GenerateUnmovables()
|
||||
for (int j = 0; j < 19; j++) {
|
||||
uint h;
|
||||
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h <= TILE_HEIGHT * 2 && !IsBridgeAbove(tile)) {
|
||||
MakeLighthouse(tile);
|
||||
BuildUnmovable(UNMOVABLE_LIGHTHOUSE, tile);
|
||||
IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
|
||||
lighthouses_to_build--;
|
||||
assert(tile < MapSize());
|
||||
|
@ -160,13 +160,14 @@ static inline void SetUnmovableOffset(TileIndex t, uint8 offset)
|
||||
* @param t The tile to make unmovable.
|
||||
* @param u The unmovable type of the tile.
|
||||
* @param o The new owner of the tile.
|
||||
* @param offset The offset to the northern tile of this object
|
||||
* @param offset The offset to the northern tile of this object.
|
||||
* @param index Generic index associated with the object type.
|
||||
*/
|
||||
static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o, uint8 offset = 0)
|
||||
static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o, uint8 offset, uint index)
|
||||
{
|
||||
SetTileType(t, MP_UNMOVABLE);
|
||||
SetTileOwner(t, o);
|
||||
_m[t].m2 = 0;
|
||||
_m[t].m2 = index;
|
||||
_m[t].m3 = offset;
|
||||
_m[t].m4 = 0;
|
||||
_m[t].m5 = u;
|
||||
@ -174,69 +175,4 @@ static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o, uint8 of
|
||||
_me[t].m7 = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a transmitter tile.
|
||||
* @param t the tile to make a transmitter.
|
||||
*/
|
||||
static inline void MakeTransmitter(TileIndex t)
|
||||
{
|
||||
MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a lighthouse tile.
|
||||
* @param t the tile to make a transmitter.
|
||||
*/
|
||||
static inline void MakeLighthouse(TileIndex t)
|
||||
{
|
||||
MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a statue tile.
|
||||
* @param t the tile to make a statue.
|
||||
* @param o the owner of the statue.
|
||||
* @param town_id the town the statue was built in.
|
||||
*/
|
||||
static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
|
||||
{
|
||||
MakeUnmovable(t, UNMOVABLE_STATUE, o);
|
||||
_m[t].m2 = town_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an 'owned land' tile.
|
||||
* @param t the tile to make an 'owned land' tile.
|
||||
* @param o the owner of the land.
|
||||
*/
|
||||
static inline void MakeOwnedLand(TileIndex t, Owner o)
|
||||
{
|
||||
MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a HeadQuarter tile after making it an Unmovable
|
||||
* @param t the tile to make an HQ.
|
||||
* @param section the part of the HQ this one will be.
|
||||
* @param o the new owner of the tile.
|
||||
*/
|
||||
static inline void MakeUnmovableHQHelper(TileIndex t, uint8 section, Owner o)
|
||||
{
|
||||
MakeUnmovable(t, UNMOVABLE_HQ, o, section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an HQ with the given tile as its northern tile.
|
||||
* @param t the tile to make the northern tile of a HQ.
|
||||
* @param o the owner of the HQ.
|
||||
*/
|
||||
static inline void MakeCompanyHQ(TileIndex t, Owner o)
|
||||
{
|
||||
MakeUnmovableHQHelper(t, 0x00, o);
|
||||
MakeUnmovableHQHelper(t + TileDiffXY(0, 1), 0x01, o);
|
||||
MakeUnmovableHQHelper(t + TileDiffXY(1, 0), 0x10, o);
|
||||
MakeUnmovableHQHelper(t + TileDiffXY(1, 1), 0x11, o);
|
||||
}
|
||||
|
||||
#endif /* UNMOVABLE_MAP_H */
|
||||
|
Loading…
Reference in New Issue
Block a user