diff options
author | rubidium <rubidium@openttd.org> | 2010-08-03 08:58:12 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-08-03 08:58:12 +0000 |
commit | 3bfe26c69d10c8395057a0fe168906182b563769 (patch) | |
tree | c2dc97d833168bb2935913e3de297fe003ab6703 | |
parent | f812e800028ae4fc65230da398c77d5d0fd695e7 (diff) | |
download | openttd-3bfe26c69d10c8395057a0fe168906182b563769.tar.xz |
(svn r20337) -Codechange: unify the construction of objects on the map
-rw-r--r-- | src/saveload/afterload.cpp | 2 | ||||
-rw-r--r-- | src/town_cmd.cpp | 4 | ||||
-rw-r--r-- | src/unmovable.h | 18 | ||||
-rw-r--r-- | src/unmovable_cmd.cpp | 24 | ||||
-rw-r--r-- | src/unmovable_map.h | 72 |
5 files changed, 43 insertions, 77 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 65b9736a4..219ae153a 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -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; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index db93a7a00..c8e271178 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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); } diff --git a/src/unmovable.h b/src/unmovable.h index e0cf4e597..8f3431e66 100644 --- a/src/unmovable.h +++ b/src/unmovable.h @@ -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. diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp index 2db837823..31af9738e 100644 --- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -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()); diff --git a/src/unmovable_map.h b/src/unmovable_map.h index 44395f4d8..ba8fe746f 100644 --- a/src/unmovable_map.h +++ b/src/unmovable_map.h @@ -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 */ |