summaryrefslogtreecommitdiff
path: root/src/engine.cpp
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/engine.cpp
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/engine.cpp')
-rw-r--r--src/engine.cpp36
1 files changed, 36 insertions, 0 deletions
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