diff --git a/src/object.h b/src/object.h index 4ec12ceee5..48f9b67c8a 100644 --- a/src/object.h +++ b/src/object.h @@ -29,10 +29,11 @@ void UpdateCompanyHQ(TileIndex tile, uint score); * @param tile The tile to build the northern tile of the object on. * @param owner The owner of the object. * @param town Town the tile is related with. + * @param view The view for the object. * @pre All preconditions for building the object at that location * are met, e.g. slope and clearness of tiles are checked. */ -void BuildObject(ObjectType type, TileIndex tile, CompanyID owner = OWNER_NONE, struct Town *town = NULL); +void BuildObject(ObjectType type, TileIndex tile, CompanyID owner = OWNER_NONE, struct Town *town = NULL, uint8 view = 0); void PlaceProc_Object(TileIndex tile); void ShowBuildObjectPicker(struct Window *w); diff --git a/src/object_base.h b/src/object_base.h index 4220a0c4c4..a006e16e7a 100644 --- a/src/object_base.h +++ b/src/object_base.h @@ -28,6 +28,7 @@ struct Object : ObjectPool::PoolItem<&_object_pool> { TileArea location; ///< Location of the object Date build_date; ///< Date of construction byte colour; ///< Colour of the object, for display purpose + byte view; ///< The view setting for this object /** Make sure the object isn't zeroed. */ Object() {} diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 8958a714a3..945a416d98 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -55,15 +55,16 @@ void InitializeObjects() Object::ResetTypeCounts(); } -void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town) +void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view) { const ObjectSpec *spec = ObjectSpec::Get(type); - TileArea ta(tile, GB(spec->size, 0, 4), GB(spec->size, 4, 4)); + TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4)); Object *o = new Object(); o->location = ta; o->town = town == NULL ? CalcClosestTownFromTile(tile) : town; o->build_date = _date; + o->view = view; /* If nothing owns the object, the colour will be random. Otherwise * get the colour from the company's livery settings. */ @@ -157,7 +158,7 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags); * @param tile tile where the object will be located * @param flags type of operation * @param p1 the object type to build - * @param p2 unused + * @param p2 the view for the object * @param text unused * @return the cost of this operation or an error */ @@ -166,17 +167,19 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 CommandCost cost(EXPENSES_PROPERTY); ObjectType type = (ObjectType)GB(p1, 0, 8); + uint8 view = GB(p2, 0, 2); const ObjectSpec *spec = ObjectSpec::Get(type); if (!spec->IsAvailable()) return CMD_ERROR; if (spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT && (_game_mode != GM_EDITOR || _current_company != OWNER_NONE)) return CMD_ERROR; if (spec->flags & OBJECT_FLAG_ONLY_IN_GAME && (_game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR; + if (view >= spec->views) return CMD_ERROR; if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS); if (Town::GetNumItems() == 0) return_cmd_error(STR_ERROR_MUST_FOUND_TOWN_FIRST); - int size_x = GB(spec->size, 0, 4); - int size_y = GB(spec->size, 4, 4); + int size_x = GB(spec->size, HasBit(view, 0) ? 4 : 0, 4); + int size_y = GB(spec->size, HasBit(view, 0) ? 0 : 4, 4); TileArea ta(tile, size_x, size_y); if (type == OBJECT_OWNED_LAND) { @@ -271,7 +274,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } if (flags & DC_EXEC) { - BuildObject(type, tile, _current_company); + BuildObject(type, tile, _current_company, NULL, view); /* Make sure the HQ starts at the right size. */ if (type == OBJECT_HQ) UpdateCompanyHQ(tile, hq_score); diff --git a/src/saveload/object_sl.cpp b/src/saveload/object_sl.cpp index c79da592d9..037fc6b4d3 100644 --- a/src/saveload/object_sl.cpp +++ b/src/saveload/object_sl.cpp @@ -23,6 +23,7 @@ static const SaveLoad _object_desc[] = { SLE_REF(Object, town, REF_TOWN), SLE_VAR(Object, build_date, SLE_UINT32), SLE_CONDVAR(Object, colour, SLE_UINT8, 148, SL_MAX_VERSION), + SLE_CONDVAR(Object, view, SLE_UINT8, 155, SL_MAX_VERSION), SLE_END() }; diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 9c09262008..85a2579c36 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -219,8 +219,9 @@ * 152 21171 * 153 21263 * 154 21426 + * 155 21453 */ -extern const uint16 SAVEGAME_VERSION = 154; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 155; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading