Skyscraper 2.0
action.cpp
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Action Interface Class
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#include "globals.h"
25#include "sbs.h"
26#include "floor.h"
27#include "elevator.h"
28#include "elevatorcar.h"
29#include "shaft.h"
30#include "stairs.h"
31#include "camera.h"
32#include "callstation.h"
33#include "sound.h"
34#include "mesh.h"
35#include "escalator.h"
36#include "movingwalkway.h"
37#include "cameratexture.h"
38#include "light.h"
39#include "door.h"
40#include "revolvingdoor.h"
41#include "profiler.h"
42#include "action.h"
43
44namespace SBS {
45
46Action::Action(Object *parent, const std::string &name, std::vector<Object*> &action_parents, const std::string &command, const std::vector<std::string> &parameters) : ObjectBase(parent)
47{
48 //create an action
49
50 command_name = command;
51 SetName(name);
53 SetCase(command_name, false);
54
55 command_parameters.resize(parameters.size());
56 for (size_t i = 0; i < parameters.size(); i++)
57 {
58 command_parameters[i] = parameters[i];
60 }
61 parent_objects = action_parents;
62}
63
64Action::Action(Object *parent, const std::string &name, std::vector<Object*> &action_parents, const std::string &command) : ObjectBase(parent)
65{
66 //create an action
67
68 command_name = command;
69 SetName(name);
71 SetCase(command_name, false);
72
73 parent_objects = action_parents;
74}
75
77{
78 if (sbs->FastDelete == false)
79 Report("Deleted action '" + GetName() + "'");
80}
81
83{
84 return command_name;
85}
86
87bool Action::DoAction(Object *caller, bool &hold)
88{
89 //run action on all registered parents
90 //returns true if at least one action succeeded
91
92 bool result = false;
93 size_t count = parent_objects.size();
94 for (size_t i = 0; i < count; i++)
95 {
96 if (!parent_objects[i])
97 continue;
98
99 bool result2 = Run(caller, parent_objects[i], hold);
100 if (result2 == true)
101 result = true;
102 }
103 return result;
104}
105
106bool Action::Run(Object *caller, Object *parent, bool &hold)
107{
108 //Supported action names:
109
111 //ChangeTexture - param1: oldtexture param2: newtexture
112 //PlaySound - param1: sound name, param2: loop (true/false)
113 //StopSound - param1: sound name
114 //Teleport - param1: X coordinate, param2: Y coordinate, param3; Z coordinate
115 //GotoFloor - param1: number
116
118 //Off
119 //(floor number)
120 //Open = Open Doors
121 //Close = Close Doors
122 //OpenInt
123 //CloseInt
124 //OpenExt
125 //CloseExt
126 //OpenManual
127 //CloseManual
128 //OpenIntManual
129 //CloseIntManual
130 //OpenExtManual
131 //CloseExtManual
132 //OpenShaftDoor
133 //CloseShaftDoor
134 //OpenShaftDoorManual
135 //CloseShaftDoorManual
136 //StopDoors
137 //Cancel = Call Cancel
138 //Run
139 //Stop
140 //EStop (emergency stop)
141 //Alarm
142 //Fire1Off
143 //Fire1On
144 //Fire1Bypass
145 //Fire2Off
146 //Fire2On
147 //Fire2Hold
148 //UpPeakOn
149 //UpPeakOff
150 //DownPeakOn
151 //DownPeakOff
152 //PeakOff
153 //IndOn
154 //IndOff
155 //InsOn
156 //InsOff
157 //AcpOn
158 //AcpOff
159 //FanOn
160 //FanOff
161 //MusicOn
162 //MusicOff
163 //Hold
164 //UpOn
165 //UpOff
166 //DownOn
167 //DownOff
168 //GoOn
169 //GoOff
170 //Return
171 //Up
172 //Down
173 //InterlocksOn
174 //InterlocksOff
175 //Sensor
176 //Reset
177 //SensorOn
178 //SensorOff
179 //SensorReset
180 //AccessDown
181 //AccessUp
182 //AccessOff
183 //Input1
184 //Input2
185 //Input3
186 //Input4
187 //Input5
188 //Input6
189 //Input7
190 //Input8
191 //Input9
192 //Input0
193 //InputMinus
194 //InputStar
195 //InputBackspace
196
197 //CallStation actions:
198 //Off
199 //(floor number)
200 //FireOff
201 //FireOn
202 //FireBypass
203 //Input1
204 //Input2
205 //Input3
206 //Input4
207 //Input5
208 //Input6
209 //Input7
210 //Input8
211 //Input9
212 //Input0
213 //InputMinus
214 //InputStar
215 //InputBackspace
216 //Up
217 //Down
218 //PressUp
219 //PressDown
220
221 //Escalator and MovingWalkway actions:
222 //Forward
223 //Reverse
224 //Stop
225
226 //CameraTexture actions:
227 //Enable
228 //Disable
229
230 //Light actions:
231 //On
232 //Off
233
234 //Door actions:
235 //Open
236 //Close
237 //AutoClose
238
239 //RevolvingDoor actions:
240 //On
241 //Off
242
243 SBS_PROFILE("Action::Run");
244
245 Elevator *elevator = dynamic_cast<Elevator*>(parent);
246 ElevatorCar *car = dynamic_cast<ElevatorCar*>(parent);
247 Floor *floor = dynamic_cast<Floor*>(parent);
248 Shaft *shaft = dynamic_cast<Shaft*>(parent);
249 Stairwell *stairs = dynamic_cast<Stairwell*>(parent);
250 CallStation *callstation = dynamic_cast<CallStation*>(parent);
251 Escalator *escalator = dynamic_cast<Escalator*>(parent);
252 MovingWalkway *walkway = dynamic_cast<MovingWalkway*>(parent);
253 CameraTexture *camtex = dynamic_cast<CameraTexture*>(parent);
254 Light *light = dynamic_cast<Light*>(parent);
255 Door *door = dynamic_cast<Door*>(parent);
256 RevolvingDoor *revdoor = dynamic_cast<RevolvingDoor*>(parent);
257
258 std::string caller_name = caller->GetName();
259 std::string caller_type = caller->GetType();
260
261 std::string parent_name = parent->GetName();
262 std::string parent_type = parent->GetType();
263
264 hold = false;
265
266 //report the action used
267 Report("Action '" + GetName() + "': object '" + parent_name + "' using command '" + command_name + "'");
268
269 //if parent is an elevator object, also use default (first) car as car object
270 if (elevator)
271 car = elevator->GetCar(1);
272 //if parent is an elevator car, get parent elevator object
273 else if (car)
274 elevator = car->GetElevator();
275
276 //elevator-specific commands
277 if (elevator && car)
278 {
279 //numeric commands for elevator floor selections
280 if (IsNumeric(command_name) == true)
281 {
282 int floor = ToInt(command_name);
283 return elevator->SelectFloor(floor);
284 }
285
286 //get first call station on recall floor
287 CallStation *station = elevator->GetPrimaryCallStation();
288
289 //if called from a control and mouse button is held down, notify elevator
290 if (caller_type == "Control" && sbs->camera->MouseDown() == true)
291 car->ControlPressActive = true;
292
293 if (command_name == "off")
294 return true;
295
296 //if (!(elevator->FireServicePhase1 == 1 && elevator->FireServicePhase2 == 0))
297 //{
298 if (StartsWith(command_name, "openintmanual", false) == true && elevator->Direction == 0)
299 {
300 int number = 0;
301 if (command_name.length() > 13)
302 number = ToInt(command_name.substr(13, command_name.length() - 13));
303 return car->OpenDoors(number, 2, 0, true);
304 }
305 if (StartsWith(command_name, "closeintmanual", false) == true && elevator->Direction == 0)
306 {
307 int number = 0;
308 if (command_name.length() > 14)
309 number = ToInt(command_name.substr(14, command_name.length() - 14));
310 car->CloseDoors(number, 2, 0, true);
311 return true;
312 }
313 if (StartsWith(command_name, "openextmanual", false) == true && elevator->Direction == 0)
314 {
315 int number = 0;
316 if (command_name.length() > 13)
317 number = ToInt(command_name.substr(13, command_name.length() - 13));
318 return car->OpenDoors(number, 3, 0, true);
319 }
320 if (StartsWith(command_name, "closeextmanual", false) == true && elevator->Direction == 0)
321 {
322 int number = 0;
323 if (command_name.length() > 14)
324 number = ToInt(command_name.substr(14, command_name.length() - 14));
325 car->CloseDoors(number, 3, 0, true);
326 return true;
327 }
328 if (StartsWith(command_name, "openmanual", false) == true && elevator->Direction == 0)
329 {
330 int number = 0;
331 if (command_name.length() > 10)
332 number = ToInt(command_name.substr(10, command_name.length() - 10));
333 return car->OpenDoors(number, 1, 0, true);
334 }
335 if (StartsWith(command_name, "closemanual", false) == true && elevator->Direction == 0)
336 {
337 int number = 0;
338 if (command_name.length() > 11)
339 number = ToInt(command_name.substr(11, command_name.length() - 11));
340 car->CloseDoors(number, 1, 0, true);
341 return true;
342 }
343 if (StartsWith(command_name, "openint", false) == true && elevator->Direction == 0)
344 {
345 int number = 0;
346 if (command_name.length() > 7)
347 number = ToInt(command_name.substr(7, command_name.length() - 7));
348 return car->OpenDoors(number, 2, 0, false);
349 }
350 if (StartsWith(command_name, "closeint", false) == true && elevator->Direction == 0)
351 {
352 int number = 0;
353 if (command_name.length() > 8)
354 number = ToInt(command_name.substr(8, command_name.length() - 8));
355 car->CloseDoors(number, 2, 0, false);
356 return true;
357 }
358 if (StartsWith(command_name, "openext", false) == true && elevator->Direction == 0)
359 {
360 int number = 0;
361 if (command_name.length() > 7)
362 number = ToInt(command_name.substr(7, command_name.length() - 7));
363 return car->OpenDoors(number, 3, car->GetFloor(), false);
364 }
365 if (StartsWith(command_name, "closeext", false) == true && elevator->Direction == 0)
366 {
367 int number = 0;
368 if (command_name.length() > 8)
369 number = ToInt(command_name.substr(8, command_name.length() - 8));
370 car->CloseDoors(number, 3, car->GetFloor(), false);
371 return true;
372 }
373 if (StartsWith(command_name, "open", false) == true && elevator->Direction == 0)
374 {
375 int number = 0;
376 if (command_name.length() > 4)
377 number = ToInt(command_name.substr(4, command_name.length() - 4));
378 return car->OpenDoors(number);
379 }
380 if (StartsWith(command_name, "close", false) == true && elevator->Direction == 0)
381 {
382 int number = 0;
383 if (command_name.length() > 5)
384 number = ToInt(command_name.substr(5, command_name.length() - 5));
385 car->CloseDoors(number);
386 return true;
387 }
388 if (StartsWith(command_name, "stopdoors", false) == true && elevator->Direction == 0)
389 {
390 int number = 0;
391 if (command_name.length() > 9)
392 number = ToInt(command_name.substr(9, command_name.length() - 9));
393 car->StopDoors(number);
394 return true;
395 }
396 //}
397 if (command_name == "cancel")
398 {
399 if (elevator->FireServicePhase2 == 1)
400 return elevator->CallCancelAll();
401 else if (elevator->IndependentService == true)
402 return elevator->CallCancelAll();
403 else
404 return elevator->CallCancel();
405 }
406 if (command_name == "run")
407 {
408 elevator->SetRunState(true);
409 return true;
410 }
411 if (command_name == "stop")
412 {
413 elevator->SetRunState(false);
414 return true;
415 }
416 if (command_name == "estop")
417 return elevator->Stop(true);
418 if (command_name == "alarm")
419 {
420 car->Alarm();
421 return true;
422 }
423 if (command_name == "fire2off")
424 return elevator->EnableFireService2(0, car->Number);
425 if (command_name == "fire2on")
426 return elevator->EnableFireService2(1, car->Number);
427 if (command_name == "fire2hold")
428 return elevator->EnableFireService2(2, car->Number);
429 if (command_name == "uppeakon")
430 return elevator->EnableUpPeak(true);
431 if (command_name == "uppeakoff")
432 return elevator->EnableUpPeak(false);
433 if (command_name == "downpeakon")
434 return elevator->EnableDownPeak(true);
435 if (command_name == "downpeakoff")
436 return elevator->EnableDownPeak(false);
437 if (command_name == "peakoff")
438 {
439 elevator->EnableDownPeak(false);
440 elevator->EnableUpPeak(false);
441 return true;
442 }
443 if (command_name == "indon")
444 return elevator->EnableIndependentService(true, car->Number);
445 if (command_name == "indoff")
446 return elevator->EnableIndependentService(false, car->Number);
447 if (command_name == "inson")
448 return elevator->EnableInspectionService(true);
449 if (command_name == "insoff")
450 return elevator->EnableInspectionService(false);
451 if (command_name == "acpon")
452 return elevator->EnableACP(true);
453 if (command_name == "acpoff")
454 return elevator->EnableACP(false);
455 if (command_name == "fanon")
456 {
457 car->Fan = true;
458 return true;
459 }
460 if (command_name == "fanoff")
461 {
462 car->Fan = false;
463 return true;
464 }
465 if (command_name == "musicon")
466 {
467 car->MusicOn = true;
468 return true;
469 }
470 if (command_name == "musicoff")
471 {
472 car->MusicOn = false;
473 return true;
474 }
475 if (command_name == "upon")
476 {
477 if (elevator->InspectionService == true)
478 return elevator->SetUpButton(true);
479 else
480 return elevator->Up(true);
481 }
482 if (command_name == "upoff")
483 {
484 if (elevator->InspectionService == true)
485 return elevator->SetUpButton(false);
486 else
487 return elevator->Up(false);
488 }
489 if (command_name == "downon")
490 {
491 if (elevator->InspectionService == true)
492 return elevator->SetDownButton(true);
493 else
494 return elevator->Down(true);
495 }
496 if (command_name == "downoff")
497 {
498 if (elevator->InspectionService == true)
499 return elevator->SetDownButton(false);
500 else
501 return elevator->Down(false);
502 }
503 if (elevator->InspectionService == true)
504 {
505 if (command_name == "insupon")
506 return elevator->SetUpButton(true);
507 if (command_name == "insupoff")
508 return elevator->SetUpButton(false);
509 if (command_name == "insdownon")
510 return elevator->SetDownButton(true);
511 if (command_name == "insdownoff")
512 return elevator->SetDownButton(false);
513 }
514 if (command_name == "goon")
515 return elevator->SetGoButton(true);
516 if (command_name == "gooff")
517 return elevator->SetGoButton(false);
518 if (command_name == "return")
519 return elevator->ReturnToNearestFloor();
520 if (command_name == "up")
521 return elevator->Up();
522 if (command_name == "down")
523 return elevator->Down();
524 if (command_name == "interlockson")
525 {
526 elevator->Interlocks = true;
527 return true;
528 }
529 if (command_name == "interlocksoff")
530 {
531 elevator->Interlocks = false;
532 return true;
533 }
534
535 if (station)
536 {
537 if (command_name == "fire1off")
538 return station->FireService(0);
539 if (command_name == "fire1on")
540 return station->FireService(1);
541 if (command_name == "fire1bypass")
542 return station->FireService(2);
543 }
544
545 if (StartsWith(command_name, "hold", false) == true && elevator->Direction == 0)
546 {
547 int number = 0;
548 if (command_name.length() > 4)
549 number = ToInt(command_name.substr(4, command_name.length() - 4));
550 car->HoldDoors(number);
551 return true;
552 }
553 if (StartsWith(command_name, "sensoron", false) == true)
554 {
555 int number = 0;
556 if (command_name.length() > 8)
557 number = ToInt(command_name.substr(8, command_name.length() - 8));
558 car->EnableSensor(true, number);
559 return true;
560 }
561 if (StartsWith(command_name, "sensoroff", false) == true)
562 {
563 int number = 0;
564 if (command_name.length() > 9)
565 number = ToInt(command_name.substr(9, command_name.length() - 9));
566 car->EnableSensor(false, number);
567 return true;
568 }
569 if (StartsWith(command_name, "sensorreset", false) == true && elevator->Direction == 0)
570 {
571 int number = 0;
572 if (command_name.length() > 11)
573 number = ToInt(command_name.substr(11, command_name.length() - 11));
574 car->ResetDoors(number, true);
575 return true;
576 }
577 if (StartsWith(command_name, "sensor", false) == true && elevator->Direction == 0)
578 {
579 int number = 0;
580 if (command_name.length() > 6)
581 number = ToInt(command_name.substr(6, command_name.length() - 6));
582 car->OpenDoors(number);
583 car->HoldDoors(number, true);
584 return true;
585 }
586 if (StartsWith(command_name, "reset", false) == true && elevator->Direction == 0)
587 {
588 int number = 0;
589 if (command_name.length() > 5)
590 number = ToInt(command_name.substr(5, command_name.length() - 5));
591 car->ResetDoors(number);
592 return true;
593 }
594 if (command_name == "openshaftdoor")
595 {
596 if ((int)command_parameters.size() == 2)
597 {
598 int param1 = 0, param2 = 0;
599 if (IsNumeric(command_parameters[0], param1) && IsNumeric(command_parameters[1], param2))
600 return car->OpenDoors(param1, 3, param2, false);
601 }
602 return false;
603 }
604 if (command_name == "closeshaftdoor")
605 {
606 if ((int)command_parameters.size() == 2)
607 {
608 int param1 = 0, param2 = 0;
609 if (IsNumeric(command_parameters[0], param1) && IsNumeric(command_parameters[1], param2))
610 {
611 car->CloseDoors(param1, 3, param2, false);
612 return true;
613 }
614 }
615 return false;
616 }
617 if (command_name == "openshaftdoormanual")
618 {
619 if ((int)command_parameters.size() == 2)
620 {
621 int param1 = 0, param2 = 0;
622 if (IsNumeric(command_parameters[0], param1) && IsNumeric(command_parameters[1], param2))
623 return car->OpenDoors(param1, 3, param2, true);
624 }
625 return false;
626 }
627 if (command_name == "closeshaftdoormanual")
628 {
629 if ((int)command_parameters.size() == 2)
630 {
631 int param1 = 0, param2 = 0;
632 if (IsNumeric(command_parameters[0], param1) && IsNumeric(command_parameters[1], param2))
633 {
634 car->CloseDoors(param1, 3, param2, true);
635 return true;
636 }
637 }
638 return false;
639 }
640 if (command_name == "accessdown")
641 {
642 if ((int)command_parameters.size() == 1)
643 {
644 int param = 0;
645 if (IsNumeric(command_parameters[0], param))
646 {
647 hold = elevator->HoistwayAccessHold;
648 return elevator->SetHoistwayAccess(param, -1);
649 }
650 }
651 return false;
652 }
653 if (command_name == "accessup")
654 {
655 if ((int)command_parameters.size() == 1)
656 {
657 int param = 0;
658 if (IsNumeric(command_parameters[0], param))
659 {
660 hold = elevator->HoistwayAccessHold;
661 return elevator->SetHoistwayAccess(param, 1);
662 }
663 }
664 return false;
665 }
666 if (command_name == "accessoff")
667 {
668 if ((int)command_parameters.size() == 1)
669 {
670 int param = 0;
671 if (IsNumeric(command_parameters[0], param))
672 return elevator->SetHoistwayAccess(param, 0);
673 }
674 return false;
675 }
676
677 if (command_name == "input1")
678 return car->Input("1");
679 if (command_name == "input2")
680 return car->Input("2");
681 if (command_name == "input3")
682 return car->Input("3");
683 if (command_name == "input4")
684 return car->Input("4");
685 if (command_name == "input5")
686 return car->Input("5");
687 if (command_name == "input6")
688 return car->Input("6");
689 if (command_name == "input7")
690 return car->Input("7");
691 if (command_name == "input8")
692 return car->Input("8");
693 if (command_name == "input9")
694 return car->Input("9");
695 if (command_name == "input0")
696 return car->Input("0");
697 if (command_name == "inputminus")
698 return car->Input("-");
699 if (command_name == "inputstar")
700 return car->Input("*");
701 if (command_name == "inputbackspace")
702 return car->Input("<");
703 }
704
705 //if parent is a call station, get parent floor object
706 if (callstation)
707 floor = sbs->GetFloor(callstation->GetFloor());
708
709 //callstation-specific commands
710 if (floor && callstation)
711 {
712 if (command_name == "off")
713 return false;
714 //numeric commands for station floor selections
715 if (IsNumeric(command_name) == true)
716 {
717 int floor = ToInt(command_name);
718 return callstation->SelectFloor(floor);
719 }
720 if (command_name == "fireoff")
721 return callstation->FireService(0);
722 if (command_name == "fireon")
723 return callstation->FireService(1);
724 if (command_name == "firebypass")
725 return callstation->FireService(2);
726 if (command_name == "input1")
727 return callstation->Input("1");
728 if (command_name == "input2")
729 return callstation->Input("2");
730 if (command_name == "input3")
731 return callstation->Input("3");
732 if (command_name == "input4")
733 return callstation->Input("4");
734 if (command_name == "input5")
735 return callstation->Input("5");
736 if (command_name == "input6")
737 return callstation->Input("6");
738 if (command_name == "input7")
739 return callstation->Input("7");
740 if (command_name == "input8")
741 return callstation->Input("8");
742 if (command_name == "input9")
743 return callstation->Input("9");
744 if (command_name == "input0")
745 return callstation->Input("0");
746 if (command_name == "inputminus")
747 return callstation->Input("-");
748 if (command_name == "inputstar")
749 return callstation->Input("*");
750 if (command_name == "inputbackspace")
751 return callstation->Input("<");
752 if (command_name == "up")
753 return callstation->Call(true);
754 if (command_name == "down")
755 return callstation->Call(false);
756 if (command_name == "pressup")
757 return callstation->Press(true);
758 if (command_name == "pressdown")
759 return callstation->Press(false);
760 }
761
762 //escalator-specific commands
763 if (escalator)
764 {
765 if (command_name == "forward")
766 {
767 escalator->SetRun(1);
768 return true;
769 }
770 if (command_name == "reverse")
771 {
772 escalator->SetRun(-1);
773 return true;
774 }
775 if (command_name == "stop")
776 {
777 escalator->SetRun(0);
778 return true;
779 }
780 }
781
782 //moving walkway-specific commands
783 if (walkway)
784 {
785 if (command_name == "forward")
786 {
787 walkway->SetRun(1);
788 return true;
789 }
790 if (command_name == "reverse")
791 {
792 walkway->SetRun(-1);
793 return true;
794 }
795 if (command_name == "stop")
796 {
797 walkway->SetRun(0);
798 return true;
799 }
800 }
801
802 //cameratexture-specific commands
803 if (camtex)
804 {
805 if (command_name == "enable")
806 {
807 camtex->Enabled(true);
808 return true;
809 }
810 if (command_name == "disable")
811 {
812 camtex->Enabled(false);
813 return true;
814 }
815 }
816
817 //light-specific commands
818 if (light)
819 {
820 if (command_name == "on")
821 {
822 light->Enabled(true);
823 return true;
824 }
825 if (command_name == "off")
826 {
827 light->Enabled(false);
828 return true;
829 }
830 }
831
832 //door-specific commands
833 if (door)
834 {
835 if (command_name == "open")
836 {
837 Vector3 pos = door->GetPosition();
838 door->Open(pos);
839 return true;
840 }
841 if (command_name == "close")
842 {
843 door->Close();
844 return true;
845 }
846 if (command_name == "autoclose")
847 {
848 if ((int)command_parameters.size() == 1)
849 {
850 int param = 0;
851 if (IsNumeric(command_parameters[0], param))
852 door->AutoClose(param);
853 }
854 return true;
855 }
856 }
857
858 //revolvingdoor-specific commands
859 if (revdoor)
860 {
861 if (command_name == "on")
862 {
863 revdoor->Run(true);
864 return true;
865 }
866 if (command_name == "off")
867 {
868 revdoor->Run(false);
869 return true;
870 }
871 }
872
873 if (command_name == "changetexture")
874 {
875 if ((int)command_parameters.size() == 2)
876 {
877 if (parent_type == "Mesh")
878 {
879 if (parent_name == "External" && sbs->External)
881 if (parent_name == "Landscape")
883 if (parent_name == "Buildings")
885 return false;
886 }
887 if (parent_type == "Floor")
888 {
889 if (floor)
890 {
892 return true;
893 }
894 return false;
895 }
896 if (parent_type == "Elevator" || parent_type == "ElevatorCar")
897 {
898 if (elevator && car)
900 return false;
901 }
902 if (parent_type == "Shaft")
903 {
904 if (shaft)
905 {
907 return true;
908 }
909 return false;
910 }
911 if (parent_type == "Stairwell")
912 {
913 if (stairs)
914 {
916 return true;
917 }
918 return false;
919 }
920 }
921 return false;
922 }
923
924 if (command_name == "playsound")
925 {
926 if ((int)command_parameters.size() == 2)
927 {
928 std::vector<Sound*> soundlist;
929
930 if (parent_type == "SBS")
931 soundlist = sbs->GetSound(command_parameters[0]);
932 else if (parent_type == "Floor")
933 {
934 if (floor)
935 soundlist = floor->GetSound(command_parameters[0]);
936 else
937 return false;
938 }
939 else if (parent_type == "Elevator" || parent_type == "ElevatorCar")
940 {
941 if (elevator && car)
942 soundlist = car->GetSound(command_parameters[0]);
943 else
944 return false;
945 }
946
947 if ((int)soundlist.size() > 0)
948 {
949 for (size_t i = 0; i < soundlist.size(); i++)
950 {
951 if (soundlist[i])
952 {
953 soundlist[i]->SetLoopState(ToBool(command_parameters[1]));
954 bool result = soundlist[i]->Play();
955
956 if ((int)soundlist.size() == 1)
957 return result;
958 }
959 }
960 return true;
961 }
962 }
963 return false;
964 }
965
966 if (command_name == "stopsound")
967 {
968 if ((int)command_parameters.size() == 1)
969 {
970 std::vector<Sound*> soundlist;
971
972 if (parent_type == "SBS")
973 soundlist = sbs->GetSound(command_parameters[0]);
974 else if (parent_type == "Floor")
975 {
976 if (floor)
977 soundlist = floor->GetSound(command_parameters[0]);
978 else
979 return false;
980 }
981 else if (parent_type == "Elevator" || parent_type == "ElevatorCar")
982 {
983 if (elevator && car)
984 soundlist = car->GetSound(command_parameters[0]);
985 else
986 return false;
987 }
988 else
989 return false;
990
991 for (size_t i = 0; i < soundlist.size(); i++)
992 {
993 if (soundlist[i])
994 soundlist[i]->Stop();
995 }
996 return true;
997 }
998 return false;
999 }
1000
1001 if (command_name == "teleport")
1002 {
1003 if ((int)command_parameters.size() == 3)
1004 {
1006 return true;
1007 }
1008 return false;
1009 }
1010
1011 if (command_name == "gotofloor")
1012 {
1013 if ((int)command_parameters.size() == 1)
1014 {
1016 return true;
1017 }
1018 return false;
1019 }
1020
1021 return false;
1022}
1023
1025{
1026 return (int)parent_objects.size();
1027}
1028
1029const Object* Action::GetParent(int number)
1030{
1031 if (number < 0 || number >= (int)parent_objects.size())
1032 return 0;
1033
1034 return parent_objects[number];
1035}
1036
1037std::string Action::GetParentName(int number)
1038{
1039 if (number < 0 || number >= (int)parent_objects.size())
1040 return "";
1041
1042 if (parent_objects[number])
1043 return parent_objects[number]->GetName();
1044 return "";
1045}
1046
1047std::string Action::GetParentType(int number)
1048{
1049 if (number < 0 || number >= (int)parent_objects.size())
1050 return "";
1051
1052 if (parent_objects[number])
1053 return parent_objects[number]->GetType();
1054 return "";
1055}
1056
1058{
1059 return (int)command_parameters.size();
1060}
1061
1062std::string Action::GetParameter(int index)
1063{
1064 if (index >= 0 && index < (int)command_parameters.size())
1065 return command_parameters[index];
1066 return "";
1067}
1068
1070{
1071 if (!parent)
1072 return false;
1073
1074 for (size_t i = 0; i < parent_objects.size(); i++)
1075 {
1076 if (parent_objects[i] == parent)
1077 return false;
1078 }
1079
1080 parent_objects.emplace_back(parent);
1081 return true;
1082}
1083
1085{
1086 if (!parent)
1087 return false;
1088
1089 for (size_t i = 0; i < parent_objects.size(); i++)
1090 {
1091 if (parent_objects[i] == parent)
1092 {
1093 parent_objects.erase(parent_objects.begin() + i);
1094 return true;
1095 }
1096 }
1097 return false;
1098}
1099
1100}
bool AddParent(Object *parent)
Definition action.cpp:1069
bool Run(Object *caller, Object *parent, bool &hold)
Definition action.cpp:106
std::string GetCommandName()
Definition action.cpp:82
std::string GetParentName(int number)
Definition action.cpp:1037
bool RemoveParent(Object *parent)
Definition action.cpp:1084
int GetParentCount()
Definition action.cpp:1024
std::string GetParameter(int index)
Definition action.cpp:1062
std::vector< Object * > parent_objects
Definition action.h:53
std::vector< std::string > command_parameters
Definition action.h:52
int GetParameterCount()
Definition action.cpp:1057
bool DoAction(Object *caller, bool &hold)
Definition action.cpp:87
Action(Object *parent, const std::string &name, std::vector< Object * > &action_parents, const std::string &command, const std::vector< std::string > &parameters)
Definition action.cpp:46
std::string command_name
Definition action.h:51
std::string GetParentType(int number)
Definition action.cpp:1047
bool Press(bool up)
bool SelectFloor(int floor)
bool Input(const std::string &text)
bool FireService(int value)
bool Call(bool direction)
void Enabled(bool value)
void Teleport(Real X, Real Y, Real Z)
Definition camera.cpp:1516
void GotoFloor(int floor, bool disable_current=true)
Definition camera.cpp:1166
bool MouseDown()
Definition camera.cpp:1497
void Close(bool playsound=true)
Definition door.cpp:165
bool Open(Vector3 &position, bool playsound=true, bool force=false)
Definition door.cpp:131
void AutoClose(int interval)
Definition door.cpp:493
void StopDoors(int number=0)
void HoldDoors(int number=0, bool sensor=false)
std::vector< Sound * > GetSound(const std::string &name)
bool OpenDoors(int number=0, int whichdoors=1, int floor=0, bool manual=false, bool hold=false)
Elevator * GetElevator()
bool ReplaceTexture(const std::string &oldtexture, const std::string &newtexture)
bool Input(const std::string &text)
void CloseDoors(int number=0, int whichdoors=1, int floor=0, bool manual=false, bool hold=false)
void ResetDoors(int number=0, bool sensor=false)
void EnableSensor(bool value, int number=0)
bool EnableACP(bool value)
bool Interlocks
Definition elevator.h:111
bool CallCancelAll()
Definition elevator.cpp:788
bool EnableIndependentService(bool value, int car_number=0)
bool SetDownButton(bool value)
bool SetUpButton(bool value)
bool EnableUpPeak(bool value)
ElevatorCar * GetCar(int number)
bool EnableDownPeak(bool value)
bool SelectFloor(int floor)
bool ReturnToNearestFloor(bool parking=true, int car=1)
bool Stop(bool emergency=false)
Definition elevator.cpp:812
void SetRunState(bool value)
bool HoistwayAccessHold
Definition elevator.h:119
bool IndependentService
Definition elevator.h:74
bool CallCancel()
Definition elevator.cpp:764
bool EnableInspectionService(bool value)
CallStation * GetPrimaryCallStation()
bool SetHoistwayAccess(int floor, int access)
bool InspectionService
Definition elevator.h:76
int FireServicePhase2
Definition elevator.h:78
bool EnableFireService2(int value, int car_number=0, bool force=false)
bool SetGoButton(bool value)
void SetRun(int value)
std::vector< Sound * > GetSound(const std::string &name)
Definition floor.cpp:1108
void ReplaceTexture(const std::string &oldtexture, const std::string &newtexture)
Definition floor.cpp:1597
void Enabled(bool value)
Definition light.cpp:136
bool ReplaceTexture(const std::string &oldtexture, const std::string &newtexture)
Definition mesh.cpp:691
void SetRun(int value)
const std::string & GetName()
Definition object.cpp:53
Object * GetParent()
Definition object.cpp:42
virtual void Report(const std::string &message)
Definition object.cpp:78
void SetName(const std::string &name)
Definition object.cpp:72
virtual Vector3 GetPosition(bool relative=false)
Definition object.cpp:321
const std::string & GetType()
Definition object.cpp:177
void Run(bool value)
MeshObject * External
Definition sbs.h:422
Floor * GetFloor(int number)
Definition sbs.cpp:1739
bool FastDelete
Definition sbs.h:188
MeshObject * Landscape
Definition sbs.h:423
Camera * camera
Definition sbs.h:160
MeshObject * Buildings
Definition sbs.h:421
std::vector< Sound * > GetSound(const std::string &name)
Definition sbs.cpp:2288
void ReplaceTexture(const std::string &oldtexture, const std::string &newtexture)
Definition shaft.cpp:485
void ReplaceTexture(const std::string &oldtexture, const std::string &newtexture)
Definition stairs.cpp:351
Ogre::Vector3 Vector3
Definition globals.h:58
int ToInt(const std::string &string)
Definition globals.cpp:402
void SetCase(std::string &string, bool uppercase)
Definition globals.cpp:172
Real ToFloat(const std::string &string)
Definition globals.cpp:397
bool IsNumeric(char character)
Definition globals.cpp:48
bool StartsWith(const std::string &string, const std::string &check_string, bool ignore_case)
Definition globals.cpp:216
void TrimString(std::string &string)
Definition globals.cpp:188
bool ToBool(std::string string)
Definition globals.cpp:407
#define SBS_PROFILE(name)
Definition profiler.h:131