(svn r26802) -Add: Command to set visibility of an engine for a company (based on patch by Juanjo).

This commit is contained in:
alberth 2014-09-07 16:12:58 +00:00
parent eb41511cd1
commit f72ad87540
7 changed files with 57 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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, CompanyID company = INVALID_COMPANY)
RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, false); // create a random company manager face
SetDefaultCompanySettings(c->index);
ClearEnginesHiddenFlagOfCompany(c->index);
GeneratePresidentName(c);

View File

@ -655,6 +655,7 @@ void StartupOneEngine(Engine *e, Date aging_date)
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.
@ -853,6 +854,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

View File

@ -37,6 +37,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
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.
@ -111,6 +112,16 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
Date GetLifeLengthInDays() const;
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.

View File

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

View File

@ -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