Skyscraper 2.0
elevator.h
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Elevator Object
3 The Skyscraper Project - Version 2.0
4 Copyright (C)2004-2024 Ryan Thoryk
5 https://www.skyscrapersim.net
6 https://sourceforge.net/projects/skyscraper/
7 Contact - ryan@skyscrapersim.net
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*/
23
24#ifndef _SBS_ELEVATOR_H
25#define _SBS_ELEVATOR_H
26
27namespace SBS {
28
30{
31 friend class ElevatorDoor;
32 friend class ElevatorCar;
33
34public:
35 int Number; //elevator number
36 std::string Name; //elevator name
37 std::string ID; //identifier for Destination Dispatch
38 std::string Type; //type of elevator: standard, express, service, freight
39 bool Created; //has elevator been created with the CreateElevator function?
40 int QueuePositionDirection; //queue processing direction
41 int LastQueueDirection; //last queue processing direction
42 int LastQueueFloor[2]; //last route added to either queue; element 0 is the floor, and element 1 is the direction
43 Real UpSpeed; //maximum up elevator speed
44 Real DownSpeed; //maximum down elevator speed
45 bool MoveElevator; //tells elevator to start going to specified floor
46 int GotoFloor; //floor to move elevator to
47 int GotoFloorCar; //car that requested movement
48 Real Acceleration; //percentage of speed increase
49 Real Deceleration; //deceleration value; may be removed
50 Real AccelJerk; //acceleration jerk rate (rate of change in acceleration; by percentage)
52 Real TempDeceleration; //temporary deceleration value, used in overrun correction
54 Real DistanceToTravel; //distance in Y to travel
56 int AssignedShaft; //shaft number this elevator is assigned to
57 bool IsEnabled; //true if elevator is enabled
58 int Direction; //-1=down, 1=up, 0=stopped
60 bool IsMoving; //is elevator moving?
61 std::string MotorUpStartSound; //motor up start/speedup sound
62 std::string MotorUpRunSound; //motor up move sound
63 std::string MotorUpStopSound; //motor up stop/slowdown sound
64 std::string MotorDownStartSound; //motor down start/speedup sound
65 std::string MotorDownRunSound; //motor down move sound
66 std::string MotorDownStopSound; //motor down stop/slowdown sound
67 std::string MotorIdleSound; //motor idle sound
68 std::string MotorEmergencyStopSound; //motor emergency stop sound
69 bool UseFloorSkipText; //true if text set in SetFloorSkipText should be used
70 bool ACP; //Anti-Crime Protection mode enable/disable
71 int ACPFloor; //floor to stop at in ACP mode
72 bool UpPeak; //Up Peak mode
73 bool DownPeak; //Down Peak mode
74 bool IndependentService; //Independent Service (ISC) mode
75 int IndependentServiceCar; //car number for Independent Service mode
76 bool InspectionService; //Inspection Service (INS) mode
77 int FireServicePhase1; //Fire service (EFS) phase 1 modes: 0 for off, 1 for on, and 2 for bypass
78 int FireServicePhase2; //Fire service (EFS) phase 2 modes: 0 for off, 1 for on, and 2 for hold
79 int FireServicePhase2Car; //car number for Fire service phase 2 mode
80 int RecallFloor; //Fire service recall floor
81 int RecallFloorAlternate; //Fire service alternate recall floor
82 bool OnFloor; //true if elevator is stopped on a floor, false if not
83 bool ManualGo; //go toggle for inspection service mode
84 bool ManualUp; //up toggle for inspection service mode
85 bool ManualDown; //down toggle for inspection service mode
86 Vector3 MotorPosition; //position of motor sound emitter
87 bool QueueResets; //true if system should use automatic queue resets for normal operation
88 int ParkingFloor; //floor to automatically park the elevator on when idle
89 Real ParkingDelay; //time to wait in idle mode before parking
90 bool Leveling; //is elevator in leveling mode?
91 Real LevelingSpeed; //leveling speed
92 Real LevelingOffset; //leveling offset factor
93 Real LevelingOpen; //leveling door open offset
94 bool WaitForDoors; //set to true for the MoveElevatorToFloor() function to wait for the doors to close before running
95 int ActiveDirection; //variant of Direction that doesn't change during slowdown
96 int NotifyEarly; //perform arrival notification earlier (-1 for off, 0 for normal, 1 for at start of leveling, 2 for at start of decel, 3 for both options 0 and 2)
97 bool NotifyLate; //perform arrival notification after doors have opened
98 bool Notified; //true if arrival notification has been performed
99 bool Parking; //is elevator parking?
100 Real DepartureDelay; //delay in seconds between door closure and elevator departure
101 Real ArrivalDelay; //delay in seconds between elevator arrival and door opening
102 bool WaitForTimer; //true if elevator is waiting for the arrival/departure timers to finish before moving
103 Real InspectionSpeed; //inspection service speed multiplier
104 bool LimitQueue; //true to only allow floor selections in the same queue direction
105 bool ReOpen; //true if elevator should reopen doors if the same floor is selected
106 int LastChimeDirection; //direction of last arrival chime
107 bool AutoDoors; //true if doors should be automatic (automatically open when reaching destination and refuse to open if off floor)
108 bool OpenOnStart; //true if doors should automatically open on simulator start
109 int ManualMove; //0 if manual movement is off; -1 for down, 1 for up
110 bool ManualMoveHold; //true if ManualMove is in hold mode
111 bool Interlocks; //lock doors during movement
112 bool GoActive; //true if go function is in use (mouse hold is active)
113 bool FloorHold; //true if floor buttons need to be held for the elevator to proceed to the floor (modern manual mode)
114 bool GoPending; //true if Go() function is active
115 Real EmergencyStopSpeed; //emergency stop deceleration multiplier
116 bool AutoAdjustSound; //auto-adjust stopping sounds
117 bool SkipFloorSound; //skip playing floor sound, for use in FinishMove()
118 bool ChimeOnArrival; //set to true for elevator to always chime on arrival, instead of just when responding to a hall call
119 bool HoistwayAccessHold; //if true, the user needs to hold the mouse button on the control, in Hoistway Access mode
120 Vector3 RopePosition; //position of rope
121 std::string RopeTexture; //texture for rope
122 std::string CounterweightStartSound; //counterweight starting sound
123 std::string CounterweightMoveSound; //counterweight moving sound
124 std::string CounterweightStopSound; //counterweight stopping sound
125 bool Counterweight; //if true, elevator has a counterweight
126 bool Error; //true if an error occurred during movement processing
127
128 //functions
129 Elevator(Object *parent, int number);
130 ~Elevator();
131 bool CreateElevator(bool relative, Real x, Real z, int floor);
132 Wall* CreateCounterweight(const std::string &frame_texture, const std::string &weight_texture, Real x, Real z, const Vector3 &size, Real weight_voffset);
133 bool AddRails(const std::string &main_texture, const std::string &edge_texture, Real x, Real z, bool orientation, Real rail_distance, Real rail_width);
134 bool AddRoute(int floor, int direction, int call_type);
135 bool DeleteRoute(int floor, int direction);
136 bool RouteExists(bool direction, int floor);
137 bool CallCancel();
138 bool CallCancelAll();
139 bool Stop(bool emergency = false);
140 void ProcessCallQueue();
141 void Loop();
142 void DumpQueues();
143 void Enabled(bool value);
144 ElevatorCar* IsInElevator(const Vector3 &position, bool camera = false);
145 Real GetElevatorStart();
146 Real GetDestination();
147 Real GetStoppingDistance();
148 bool GetBrakeStatus();
149 int GetEmergencyStopStatus();
150 void UpdateFloorIndicators();
151 Real GetJerkRate();
152 Real GetJerkPosition();
153 void SetFloorSkipText(const std::string &id);
154 std::string GetFloorSkipText();
155 bool InServiceMode();
156 bool Go(int floor, bool hold = false);
157 bool EnableACP(bool value);
158 bool EnableUpPeak(bool value);
159 bool EnableDownPeak(bool value);
160 bool EnableIndependentService(bool value, int car_number = 0);
161 bool EnableInspectionService(bool value);
162 bool EnableFireService1(int value);
163 bool EnableFireService2(int value, int car_number = 0, bool force = false);
164 bool SetRecallFloor(int floor);
165 bool SetAlternateRecallFloor(int floor);
166 bool SetACPFloor(int floor);
167 void GoToRecallFloor();
168 bool MoveUp();
169 bool MoveDown();
170 bool SetGoButton(bool value);
171 bool SetUpButton(bool value);
172 bool SetDownButton(bool value);
173 int GetTopFloor();
174 int GetBottomFloor();
175 void UpdateDirectionalIndicators();
176 bool IsIdle();
177 void ResetQueue(bool up, bool down, bool stop_if_empty = true);
178 void DeleteActiveRoute();
179 bool IsQueueActive();
180 bool BeyondDecelMarker(int direction, Real destination);
181 void Report(const std::string &message);
182 bool ReportError(const std::string &message);
183 bool IsQueued(int floor, int queue = 0);
184 void SetRunState(bool value);
185 bool IsRunning();
186 bool GetArrivalDirection(int floor);
187 void MoveObjects(Real offset);
188 void OnInit();
189 int AvailableForCall(bool destination, int floor, int direction, bool report_on_failure = true);
190 bool SelectFloor(int floor);
191 bool Check(Vector3 position);
192 bool ReturnToNearestFloor(bool parking = true, int car = 1);
193 bool ReturnToBottomFloor();
194 bool IsLeveled();
195 bool Up();
196 bool Down();
197 bool Up(bool value);
198 bool Down(bool value);
199 Shaft* GetShaft();
200 CallStation* GetPrimaryCallStation();
201 int GetActiveCallFloor();
202 int GetActiveCallDirection();
203 int GetActiveCallType();
204 bool InElevator();
205 bool PeakWaiting();
206 bool OnPeakFloor();
207 bool OnRecallFloor();
208 int GetActiveRecallFloor();
209 std::vector<Floor*> GetLobbies();
210 bool IsStopped();
211 void CancelHallCall(int floor, int direction);
212 bool IsManuallyStopped();
213 DynamicMesh* GetDoorContainer() { return DoorContainer; }
214 bool CheckInterlocks(bool skip_current_floor = false);
215 bool AreDoorsOpen();
216 int AreDoorsMoving(bool car_doors = true, bool shaft_doors = true);
217 bool AreShaftDoorsClosed(bool skip_current_floor = false);
218 bool DoorsStopped();
219 bool AreDoorsOpening(bool car_doors = true, bool shaft_doors = true);
220 bool AreDoorsClosing(bool car_doors = true, bool shaft_doors = true);
221 bool IsServicedFloor(int floor, bool report = true);
222 void ChangeLight(int floor, bool value);
223 void ResetLights();
224 void OpenDoors();
225 void CloseDoors();
226 bool GetHoldStatus();
227 bool OnTopFloor();
228 bool OnBottomFloor();
229 bool IsNudgeModeActive();
230 void ResetShaftDoors(int floor);
231 void ResetDoors();
232 void ResetNudgeTimers(bool start = true);
233 void HoldDoors();
234 void EnableNudgeMode(bool value);
235 bool OnParkingFloor();
236 bool SetHoistwayAccess(int floor, int access);
237 void SetControls(const std::string &action_name);
238 bool GetDestinationDispatch();
239 int GetRecallFloor();
240 void AddController(int controller);
241 void RemoveController(int controller);
242 bool GetCallStatus(int floor, bool &up, bool &down);
243 int GetMotorRoom();
244 void EnableMalfunctions(bool value);
245 void Malfunction();
246
247 ElevatorCar* AddCar();
248 ElevatorCar* GetCar(int number);
249 void RemoveCar(ElevatorCar* car);
250 int GetCarCount();
251 ElevatorCar* GetCarForFloor(int number, bool report_on_failure = false);
252 int GetFloorForCar(int car, int number);
253 Real GetCarOffset(int number);
254
255private:
256
258 {
259 int floor; //floor number
260 int call_type; //0 = car call, 1 = hall call, 2 = system call
261 int car; //car number
262 int direction; //queue direction
263
265 {
266 floor = 0;
267 call_type = 0;
268 car = 0;
269 direction = 0;
270 }
271
272 QueueEntry(int floor, int call_type, int car, int direction)
273 {
274 this->floor = floor;
275 this->call_type = call_type;
276 this->car = car;
277 this->direction = direction;
278 }
279
280 bool operator < (const QueueEntry& element) const
281 {
282 return floor < element.floor;
283 }
284 };
285
286 class Timer; //internal timer class
287
288 //parking timer object
290
291 //arrival and departure delay timers
294
295 //random malfunctions timer
297 int RandomProbability; //probability ratio of random activity, starting with 1 - higher is less frequent
298 Real RandomFrequency; //speed in seconds to make each random action
299
300 //Internal elevator simulation data
301 std::vector<ElevatorCar*> Cars; //car objects
302 std::vector<QueueEntry> UpQueue; //up call queue
303 std::vector<QueueEntry> DownQueue; //down call queue
304 Real ElevatorStart; //elevator vertical starting location
305 Real Destination; //elevator destination Y value
306 Real StoppingDistance; //distance needed to stop the elevator
308 bool Brakes; //internal brake status
309 int EmergencyStop; //internal stop status; 0 for off, 1 for standard stop, 2 for emergency stop
310 Real JerkRate; //current jerk value, used as an acceleration/deceleration multiplier
311 Real JerkPos; //temporary storage for the elevator rate at the end of the jerkrate increments
312 QueueEntry ActiveCall; //active call (that the elevator's currently responding to)
313 bool FirstRun; //used for setting first-run items in the run loop
314 bool Running; //is elevator in run mode?
317 bool UpCall;
319 bool QueuePending; //true if either queue has changed, and needs to be processed
320 int GoActiveFloor; //associated floor number for GoActive flag
321 bool ManualStop; //true if elevator has been manually stopped
322 int HoistwayAccess; //INS mode Hoistway Access; -1 for Down, 0 for Off, 1 for Up
323 int HoistwayAccessFloor; //floor used for Hoistway Access
324 std::vector<int> Controllers; //dispatch controllers this elevator is assigned to
325 RandomGen *rnd_time, *rnd_type;
326
327 //functions
328 void MoveElevatorToFloor();
329 void FinishMove();
330 void PlayStartingSounds();
331 void PlayStoppingSounds(bool emergency = false);
332 void PlayMovingSounds();
333 void HandleDequeue(int direction, bool stop_if_empty = true);
334 void StopSounds();
335 Real GetDestinationAltitude(int floor);
336 Real GetDestinationOffset(int floor);
337 void DirectionalIndicatorsOff();
338 void NotifyArrival(bool early = false);
339 void ProcessGotoFloor(int floor, int direction);
340 void DoSetControls();
341 void SameFloorArrival(int floor, int direction);
342
343 //motor sound objects
346
347 //counterweight sound
349
350 //mesh container for elevator doors (not shaft doors)
352
353 std::queue<std::string> ControlQueue;
354
355 MeshObject* WeightMesh; //counterweight mesh object
356 MeshObject* WeightRopeMesh; //counterweight rope mesh
357 Vector3 weight_size; //counterweight size
358 MeshObject* RopeMesh; //rope mesh
359
360 //elevator misc internals
365 std::string FloorSkipText;
369 bool RecallUnavailable; //true if recall floor is unavailable (alarm has been triggered on that floor)
374};
375
376}
377
378#endif
bool operator<(const XrUuidMSFT &lh, const XrUuidMSFT &rh) noexcept
Definition XrUuid.h:17
Real TempDeceleration
Definition elevator.h:52
int RecallFloor
Definition elevator.h:80
Real DepartureDelay
Definition elevator.h:100
bool ManualMoveHold
Definition elevator.h:110
bool FinishedMove
Definition elevator.h:372
bool Interlocks
Definition elevator.h:111
Real ErrorOffset
Definition elevator.h:53
Vector3 elevposition
Definition elevator.h:370
std::string MotorUpRunSound
Definition elevator.h:62
bool Notified
Definition elevator.h:98
Vector3 MotorPosition
Definition elevator.h:86
Real DecelJerk
Definition elevator.h:51
std::string CounterweightStopSound
Definition elevator.h:124
std::string MotorEmergencyStopSound
Definition elevator.h:68
std::string FloorSkipText
Definition elevator.h:365
bool QueueResets
Definition elevator.h:87
bool HeightSet
Definition elevator.h:59
Real LevelingOpen
Definition elevator.h:93
Real Destination
Definition elevator.h:305
Real InspectionSpeed
Definition elevator.h:103
int GotoFloorCar
Definition elevator.h:47
bool RecallAltSet
Definition elevator.h:367
Real ParkingDelay
Definition elevator.h:89
Real LevelingOffset
Definition elevator.h:92
DynamicMesh * DoorContainer
Definition elevator.h:351
bool UseFloorSkipText
Definition elevator.h:69
int HoistwayAccessFloor
Definition elevator.h:323
Real EmergencyStopSpeed
Definition elevator.h:115
bool lastfloorset
Definition elevator.h:364
Real ElevatorStart
Definition elevator.h:304
std::string MotorDownStartSound
Definition elevator.h:64
int QueuePositionDirection
Definition elevator.h:40
std::vector< QueueEntry > UpQueue
Definition elevator.h:302
bool MoveElevator
Definition elevator.h:45
Sound * motorsound
Definition elevator.h:344
Timer * departure_delay
Definition elevator.h:293
MeshObject * WeightMesh
Definition elevator.h:355
std::string Type
Definition elevator.h:38
bool WaitForDoors
Definition elevator.h:94
Real ArrivalDelay
Definition elevator.h:101
std::string MotorDownRunSound
Definition elevator.h:65
bool Counterweight
Definition elevator.h:125
Timer * malfunction_timer
Definition elevator.h:296
bool ManualDown
Definition elevator.h:85
int FireServicePhase2Car
Definition elevator.h:79
bool AutoAdjustSound
Definition elevator.h:116
bool HoistwayAccessHold
Definition elevator.h:119
bool LimitQueue
Definition elevator.h:104
Real LevelingSpeed
Definition elevator.h:91
bool DownPeak
Definition elevator.h:73
std::string Name
Definition elevator.h:36
bool WaitForTimer
Definition elevator.h:102
bool IndependentService
Definition elevator.h:74
Vector3 weight_size
Definition elevator.h:357
std::vector< ElevatorCar * > Cars
Definition elevator.h:301
bool NotifyLate
Definition elevator.h:97
int ActiveDirection
Definition elevator.h:95
Real StoppingDistance
Definition elevator.h:306
Sound * motoridlesound
Definition elevator.h:345
bool Leveling
Definition elevator.h:90
std::string MotorUpStopSound
Definition elevator.h:63
bool ManualStop
Definition elevator.h:321
RandomGen * rnd_time
Definition elevator.h:325
int AssignedShaft
Definition elevator.h:56
Real AccelJerk
Definition elevator.h:50
int LastChimeDirection
Definition elevator.h:106
bool CalculateStoppingDistance
Definition elevator.h:307
Real DistanceToTravel
Definition elevator.h:54
int EmergencyStop
Definition elevator.h:309
std::string ID
Definition elevator.h:37
Real Deceleration
Definition elevator.h:49
std::queue< std::string > ControlQueue
Definition elevator.h:353
DynamicMesh * GetDoorContainer()
Definition elevator.h:213
std::string RopeTexture
Definition elevator.h:121
std::string MotorIdleSound
Definition elevator.h:67
std::string MotorUpStartSound
Definition elevator.h:61
bool InspectionService
Definition elevator.h:76
Timer * parking_timer
Definition elevator.h:289
int FireServicePhase2
Definition elevator.h:78
std::vector< QueueEntry > DownQueue
Definition elevator.h:303
bool IsMoving
Definition elevator.h:60
int RecallFloorAlternate
Definition elevator.h:81
int GoActiveFloor
Definition elevator.h:320
int IndependentServiceCar
Definition elevator.h:75
bool ACPFloorSet
Definition elevator.h:368
bool UpQueueEmpty
Definition elevator.h:315
Timer * arrival_delay
Definition elevator.h:292
QueueEntry ActiveCall
Definition elevator.h:312
int RandomProbability
Definition elevator.h:297
bool SkipFloorSound
Definition elevator.h:117
bool IsEnabled
Definition elevator.h:57
Sound * counterweightsound
Definition elevator.h:348
bool QueuePending
Definition elevator.h:319
int LastQueueDirection
Definition elevator.h:41
bool ManualUp
Definition elevator.h:84
Real tmpDecelJerk
Definition elevator.h:371
MeshObject * RopeMesh
Definition elevator.h:358
std::string MotorDownStopSound
Definition elevator.h:66
Real Acceleration
Definition elevator.h:48
std::string CounterweightStartSound
Definition elevator.h:122
Real ElevatorRate
Definition elevator.h:55
std::vector< int > Controllers
Definition elevator.h:324
bool MovementRunning
Definition elevator.h:361
bool SoundsQueued
Definition elevator.h:373
bool DownQueueEmpty
Definition elevator.h:316
bool ChimeOnArrival
Definition elevator.h:118
int ParkingFloor
Definition elevator.h:88
int FireServicePhase1
Definition elevator.h:77
int NotifyEarly
Definition elevator.h:96
Real RandomFrequency
Definition elevator.h:298
Real DownSpeed
Definition elevator.h:44
Vector3 RopePosition
Definition elevator.h:120
bool RecallUnavailable
Definition elevator.h:369
MeshObject * WeightRopeMesh
Definition elevator.h:356
bool OpenOnStart
Definition elevator.h:108
bool ManualGo
Definition elevator.h:83
int HoistwayAccess
Definition elevator.h:322
std::string CounterweightMoveSound
Definition elevator.h:123
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
#define SBSIMPEXP
Definition globals.h:53
QueueEntry(int floor, int call_type, int car, int direction)
Definition elevator.h:272