Changeset - r16710:faf33b3a6228
[Not reviewed]
master
0 5 0
rubidium - 14 years ago 2010-12-10 21:32:04
rubidium@openttd.org
(svn r21453) -Codechange: add the view of an object to the savegame
5 files changed with 15 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/object.h
Show inline comments
 
@@ -26,15 +26,16 @@ void UpdateCompanyHQ(TileIndex tile, uin
 
/**
 
 * Actually build the 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 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);
 

	
 
#endif /* OBJECT_H */
src/object_base.h
Show inline comments
 
@@ -25,12 +25,13 @@ extern ObjectPool _object_pool;
 
/** An object, such as transmitter, on the map. */
 
struct Object : ObjectPool::PoolItem<&_object_pool> {
 
	Town *town;         ///< Town the object is built in
 
	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() {}
 
	/** Make sure the right destructor is called as well! */
 
	~Object() {}
 

	
src/object_cmd.cpp
Show inline comments
 
@@ -52,21 +52,22 @@ uint16 Object::counts[NUM_OBJECTS];
 
void InitializeObjects()
 
{
 
	_object_pool.CleanPool();
 
	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. */
 
	if (owner == OWNER_NONE) {
 
		o->colour = Random();
 
	} else {
 
@@ -154,32 +155,34 @@ static CommandCost ClearTile_Object(Tile
 

	
 
/**
 
 * Build an object object
 
 * @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
 
 */
 
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	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) {
 
		/* Owned land is special as it can be placed on any slope. */
 
		cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
 
	} else {
 
@@ -268,13 +271,13 @@ CommandCost CmdBuildObject(TileIndex til
 

	
 
		default: // i.e. NewGRF provided.
 
			break;
 
	}
 

	
 
	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);
 
	}
 

	
 
	cost.AddCost(ObjectSpec::Get(type)->GetBuildCost() * size_x * size_y);
src/saveload/object_sl.cpp
Show inline comments
 
@@ -20,12 +20,13 @@ static const SaveLoad _object_desc[] = {
 
	    SLE_VAR(Object, location.tile,              SLE_UINT32),
 
	    SLE_VAR(Object, location.w,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    SLE_VAR(Object, location.h,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    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()
 
};
 

	
 
static void Save_OBJS()
 
{
src/saveload/saveload.cpp
Show inline comments
 
@@ -216,14 +216,15 @@
 
 *  149   20832
 
 *  150   20857
 
 *  151   20918
 
 *  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
 

	
 
uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
0 comments (0 inline, 0 general)