Changeset - r21664:0999bd2815df
[Not reviewed]
master
0 7 0
alberth - 10 years ago 2014-09-07 16:12:58
alberth@openttd.org
(svn r26802) -Add: Command to set visibility of an engine for a company (based on patch by Juanjo).
7 files changed with 57 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -84,6 +84,7 @@ CommandProc CmdBuildVehicle;
 
CommandProc CmdSellVehicle;
 
CommandProc CmdRefitVehicle;
 
CommandProc CmdSendVehicleToDepot;
 
CommandProc CmdSetVehicleVisibility;
 

	
 
CommandProc CmdForceTrainProceed;
 
CommandProc CmdReverseTrainDirection;
 
@@ -243,6 +244,7 @@ static const Command _command_proc_table
 
	DEF_CMD(CmdSellVehicle,                        CMD_CLIENT_ID, CMDT_VEHICLE_CONSTRUCTION  ), // CMD_SELL_VEHICLE
 
	DEF_CMD(CmdRefitVehicle,                                   0, CMDT_VEHICLE_CONSTRUCTION  ), // CMD_REFIT_VEHICLE
 
	DEF_CMD(CmdSendVehicleToDepot,                             0, CMDT_VEHICLE_MANAGEMENT    ), // CMD_SEND_VEHICLE_TO_DEPOT
 
	DEF_CMD(CmdSetVehicleVisibility,                           0, CMDT_COMPANY_SETTING       ), // CMD_SET_VEHICLE_VISIBILITY
 

	
 
	DEF_CMD(CmdMoveRailVehicle,                                0, CMDT_VEHICLE_CONSTRUCTION  ), // CMD_MOVE_RAIL_VEHICLE
 
	DEF_CMD(CmdForceTrainProceed,                              0, CMDT_VEHICLE_MANAGEMENT    ), // CMD_FORCE_TRAIN_PROCEED
src/command_type.h
Show inline comments
 
@@ -216,6 +216,7 @@ enum Commands {
 
	CMD_SELL_VEHICLE,                 ///< sell a vehicle
 
	CMD_REFIT_VEHICLE,                ///< refit the cargo space of a vehicle
 
	CMD_SEND_VEHICLE_TO_DEPOT,        ///< send a vehicle to a depot
 
	CMD_SET_VEHICLE_VISIBILITY,       ///< hide or unhide a vehicle in the build vehicle and autoreplace GUIs
 

	
 
	CMD_MOVE_RAIL_VEHICLE,            ///< move a rail vehicle (in the depot)
 
	CMD_FORCE_TRAIN_PROCEED,          ///< proceed a train to pass a red signal
src/company_cmd.cpp
Show inline comments
 
@@ -41,6 +41,8 @@
 

	
 
#include "safeguards.h"
 

	
 
void ClearEnginesHiddenFlagOfCompany(CompanyID cid);
 

	
 
CompanyByte _local_company;   ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR.
 
CompanyByte _current_company; ///< Company currently doing an action.
 
Colours _company_colours[MAX_COMPANIES];  ///< NOSAVE: can be determined from company structs.
 
@@ -558,6 +560,7 @@ Company *DoStartupNewCompany(bool is_ai,
 
	RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, false); // create a random company manager face
 

	
 
	SetDefaultCompanySettings(c->index);
 
	ClearEnginesHiddenFlagOfCompany(c->index);
 

	
 
	GeneratePresidentName(c);
 

	
src/engine.cpp
Show inline comments
 
@@ -655,6 +655,7 @@ void StartupOneEngine(Engine *e, Date ag
 
	e->age = 0;
 
	e->flags = 0;
 
	e->company_avail = 0;
 
	e->company_hidden = 0;
 

	
 
	/* Don't randomise the start-date in the first two years after gamestart to ensure availability
 
	 * of engines in early starting games.
 
@@ -854,6 +855,41 @@ void EnginesDailyLoop()
 
}
 

	
 
/**
 
 * Clear the 'hidden' flag for all engines of a new company.
 
 * @param cid Company being created.
 
 */
 
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
 
{
 
	Engine *e;
 
	FOR_ALL_ENGINES(e) {
 
		SB(e->company_hidden, cid, 1, 0);
 
	}
 
}
 

	
 
/**
 
 * Set the visibility of an engine.
 
 * @param tile Unused.
 
 * @param flags Operation to perform.
 
 * @param p1 Unused.
 
 * @param p2 Bit 31: 0=visible, 1=hidden, other bits for the #EngineID.
 
 * @param text Unused.
 
 * @return The cost of this operation or an error.
 
 */
 
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Engine *e = Engine::GetIfValid(GB(p2, 0, 31));
 
	if (e == NULL || _current_company >= MAX_COMPANIES) return CMD_ERROR;
 
	if ((e->flags & ENGINE_AVAILABLE) == 0 || !HasBit(e->company_avail, _current_company)) return CMD_ERROR;
 

	
 
	if ((flags & DC_EXEC) != 0) {
 
		SB(e->company_hidden, _current_company, 1, GB(p2, 31, 1));
 
		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Accept an engine prototype. XXX - it is possible that the top-company
 
 * changes while you are waiting to accept the offer? Then it becomes invalid
 
 * @param tile unused
src/engine_base.h
Show inline comments
 
@@ -37,6 +37,7 @@ struct Engine : EnginePool::PoolItem<&_e
 
	CompanyByte preview_company;///< Company which is currently being offered a preview \c INVALID_COMPANY means no company.
 
	byte preview_wait;          ///< Daily countdown timer for timeout of offering the engine to the #preview_company company.
 
	CompanyMask company_avail;  ///< Bit for each company whether the engine is available for that company.
 
	CompanyMask company_hidden; ///< Bit for each company whether the engine is normally hidden in the build gui for that company.
 
	uint8 original_image_index; ///< Original vehicle image index, thus the image index of the overridden vehicle
 
	VehicleType type;           ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc.
 

	
 
@@ -112,6 +113,16 @@ struct Engine : EnginePool::PoolItem<&_e
 
	uint16 GetRange() const;
 

	
 
	/**
 
	 * Check whether the engine is hidden in the GUI for the given company.
 
	 * @param c Company to check.
 
	 * @return \c true iff the engine is hidden in the GUI for the given company.
 
	 */
 
	inline bool IsHidden(CompanyByte c) const
 
	{
 
		return c < MAX_COMPANIES && HasBit(this->company_hidden, c);
 
	}
 

	
 
	/**
 
	 * Check if the engine is a ground vehicle.
 
	 * @return True iff the engine is a train or a road vehicle.
 
	 */
src/saveload/engine_sl.cpp
Show inline comments
 
@@ -40,6 +40,7 @@ static const SaveLoad _engine_desc[] = {
 
	SLE_CONDNULL(1,                                                        0,  44),
 
	 SLE_CONDVAR(Engine, company_avail,       SLE_FILE_U8  | SLE_VAR_U16,  0, 103),
 
	 SLE_CONDVAR(Engine, company_avail,       SLE_UINT16,                104, SL_MAX_VERSION),
 
	 SLE_CONDVAR(Engine, company_hidden,      SLE_UINT16,                193, SL_MAX_VERSION),
 
	 SLE_CONDSTR(Engine, name,                SLE_STR, 0,                 84, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(16,                                                       2, 143), // old reserved space
 
@@ -108,6 +109,7 @@ void CopyTempEngineData()
 
		e->preview_company     = se->preview_company;
 
		e->preview_wait        = se->preview_wait;
 
		e->company_avail       = se->company_avail;
 
		e->company_hidden      = se->company_hidden;
 
		if (se->name != NULL) e->name = stredup(se->name);
 
	}
 

	
src/saveload/saveload.cpp
Show inline comments
 
@@ -260,8 +260,9 @@
 
 *  190   26547
 
 *  191   26646
 
 *  192   26700
 
 *  193   26802
 
 */
 
extern const uint16 SAVEGAME_VERSION = 192; ///< Current savegame version of OpenTTD.
 
extern const uint16 SAVEGAME_VERSION = 193; ///< Current savegame version of OpenTTD.
 

	
 
SavegameType _savegame_type; ///< type of savegame we are loading
 

	
0 comments (0 inline, 0 general)