summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2014-09-07 16:12:58 +0000
committeralberth <alberth@openttd.org>2014-09-07 16:12:58 +0000
commitf72ad87540a5fa575bf790bb2796c484152998b5 (patch)
tree8d7b659dbd7d3e03717e49fc27b8a658b418c15c /src
parenteb41511cd1dacb1f9012c64818d26ccb7ec71e00 (diff)
downloadopenttd-f72ad87540a5fa575bf790bb2796c484152998b5.tar.xz
(svn r26802) -Add: Command to set visibility of an engine for a company (based on patch by Juanjo).
Diffstat (limited to 'src')
-rw-r--r--src/command.cpp2
-rw-r--r--src/command_type.h1
-rw-r--r--src/company_cmd.cpp3
-rw-r--r--src/engine.cpp36
-rw-r--r--src/engine_base.h11
-rw-r--r--src/saveload/engine_sl.cpp2
-rw-r--r--src/saveload/saveload.cpp3
7 files changed, 57 insertions, 1 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 67fc5e2b0..959610cd2 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -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
diff --git a/src/command_type.h b/src/command_type.h
index a369be665..f318216ac 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -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
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 3dfcc3234..577ea884d 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -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);
diff --git a/src/engine.cpp b/src/engine.cpp
index 362bd014a..f8fc0ee6a 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -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.
@@ -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
diff --git a/src/engine_base.h b/src/engine_base.h
index 99a15aaea..6a2e6816c 100644
--- a/src/engine_base.h
+++ b/src/engine_base.h
@@ -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.
@@ -112,6 +113,16 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> {
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.
*/
diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp
index 07bad4606..af53e4006 100644
--- a/src/saveload/engine_sl.cpp
+++ b/src/saveload/engine_sl.cpp
@@ -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);
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 411b0e7a8..8638b8163 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -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