4 Scalable Building Simulator - Floor Class
5 The Skyscraper Project - Version 1.9 Alpha
6 Copyright (C)2004-2014 Ryan Thoryk
7 http://www.skyscrapersim.com
8 http://sourceforge.net/projects/skyscraper
9 Contact - ryan@tliquest.net
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 extern SBS *sbs; //external pointer to the SBS engine
34 Floor::Floor(int number)
37 object = new Object();
38 object->SetValues(this, sbs->object, "Floor", "", false);
42 //Set floor's object number
45 //Create primary level mesh
46 buffer = ToString(Number);
47 object->SetName(std::string("Floor " + buffer).c_str());
48 buffer.insert(0, "Level ");
50 Level = new MeshObject(object, buffer.c_str());
52 //Create interfloor mesh
53 buffer = ToString(Number);
54 buffer.insert(0, "Interfloor ");
56 Interfloor = new MeshObject(object, buffer.c_str());
58 //Create columnframe mesh
59 buffer = ToString(Number);
60 buffer.insert(0, "ColumnFrame ");
62 ColumnFrame = new MeshObject(object, buffer.c_str());
67 //init other variables
72 IndicatorTexture = "";
83 for (int i = 0; i < (int)ControlArray.size(); i++)
87 ControlArray[i]->object->parent_deleting = true;
88 delete ControlArray[i];
94 for (int i = 0; i < (int)TriggerArray.size(); i++)
98 TriggerArray[i]->object->parent_deleting = true;
99 delete TriggerArray[i];
105 for (int i = 0; i < (int)ModelArray.size(); i++)
109 ModelArray[i]->object->parent_deleting = true;
110 delete ModelArray[i];
116 for (int i = 0; i < (int)lights.size(); i++)
120 lights[i]->object->parent_deleting = true;
126 //delete call buttons
127 for (int i = 0; i < (int)CallButtonArray.size(); i++)
129 if (CallButtonArray[i])
131 CallButtonArray[i]->object->parent_deleting = true;
132 delete CallButtonArray[i];
134 CallButtonArray[i] = 0;
136 CallButtonArray.clear();
139 for (int i = 0; i < (int)DoorArray.size(); i++)
143 DoorArray[i]->object->parent_deleting = true;
150 //delete floor indicators
151 for (int i = 0; i < (int)FloorIndicatorArray.size(); i++)
153 if (FloorIndicatorArray[i])
155 FloorIndicatorArray[i]->object->parent_deleting = true;
156 delete FloorIndicatorArray[i];
159 FloorIndicatorArray.clear();
161 //delete directional indicators
162 for (int i = 0; i < (int)DirIndicatorArray.size(); i++)
164 if (DirIndicatorArray[i])
166 DirIndicatorArray[i]->object->parent_deleting = true;
167 delete DirIndicatorArray[i];
170 DirIndicatorArray.clear();
173 for (int i = 0; i < (int)sounds.size(); i++)
177 sounds[i]->object->parent_deleting = true;
197 //delete walls in external mesh
198 if (sbs->FastDelete == false)
199 sbs->External->DeleteWalls(object);
201 //unregister from parent
202 if (sbs->FastDelete == false && object->parent_deleting == false)
203 sbs->RemoveFloor(this);
208 void Floor::SetCameraFloor()
210 //Moves camera to specified floor (sets altitude to the floor's base plus DefaultAltitude)
212 Ogre::Vector3 camlocation = sbs->camera->GetPosition();
213 sbs->camera->SetPosition(Ogre::Vector3(camlocation.x, GetBase() + sbs->camera->cfg_body_height + sbs->camera->cfg_legs_height, camlocation.z));
216 WallObject* Floor::AddFloor(const char *name, const char *texture, float thickness, float x1, float z1, float x2, float z2, float voffset1, float voffset2, bool reverse_axis, bool texture_direction, float tw, float th, bool isexternal, bool legacy_behavior)
218 //Adds a floor with the specified dimensions and vertical offset
222 if (isexternal == false)
224 wall = Level->CreateWallObject(object, name);
225 sbs->AddFloorMain(wall, name, texture, thickness, x1, z1, x2, z2, GetBase() + voffset1, GetBase() + voffset2, reverse_axis, texture_direction, tw, th, true, legacy_behavior);
229 wall = sbs->External->CreateWallObject(object, name);
230 sbs->AddFloorMain(wall, name, texture, thickness, x1, z1, x2, z2, Altitude + voffset1, Altitude + voffset2, reverse_axis, texture_direction, tw, th, true, legacy_behavior);
235 WallObject* Floor::AddInterfloorFloor(const char *name, const char *texture, float thickness, float x1, float z1, float x2, float z2, float voffset1, float voffset2, bool reverse_axis, bool texture_direction, float tw, float th, bool legacy_behavior)
237 //Adds an interfloor floor with the specified dimensions and vertical offset
239 WallObject *wall = Interfloor->CreateWallObject(object, name);
240 sbs->AddFloorMain(wall, name, texture, thickness, x1, z1, x2, z2, Altitude + voffset1, Altitude + voffset2, reverse_axis, texture_direction, tw, th, true, legacy_behavior);
244 WallObject* Floor::AddWall(const char *name, const char *texture, float thickness, float x1, float z1, float x2, float z2, float height_in1, float height_in2, float voffset1, float voffset2, float tw, float th, bool isexternal)
246 //Adds a wall with the specified dimensions
249 if (isexternal == false)
251 wall = Level->CreateWallObject(object, name);
252 sbs->AddWallMain(wall, name, texture, thickness, x1, z1, x2, z2, height_in1, height_in2, GetBase() + voffset1, GetBase() + voffset2, tw, th, true);
256 wall = sbs->External->CreateWallObject(object, name);
257 sbs->AddWallMain(wall, name, texture, thickness, x1, z1, x2, z2, height_in1, height_in2, Altitude + voffset1, Altitude + voffset2, tw, th, true);
262 WallObject* Floor::AddInterfloorWall(const char *name, const char *texture, float thickness, float x1, float z1, float x2, float z2, float height_in1, float height_in2, float voffset1, float voffset2, float tw, float th)
264 //Adds an interfloor wall with the specified dimensions
266 WallObject *wall = Interfloor->CreateWallObject(object, name);
267 sbs->AddWallMain(wall, name, texture, thickness, x1, z1, x2, z2, height_in1, height_in2, Altitude + voffset1, Altitude + voffset2, tw, th, true);
271 void Floor::Enabled(bool value)
275 if (IsEnabled == value)
278 SBS_PROFILE("Floor::Enabled");
279 Level->Enable(value);
280 Interfloor->Enable(value);
283 EnableColumnFrame(value);
286 for (size_t i = 0; i < (int)ControlArray.size(); i++)
289 ControlArray[i]->Enabled(value);
293 for (size_t i = 0; i < (int)TriggerArray.size(); i++)
296 TriggerArray[i]->Enabled(value);
300 for (size_t i = 0; i < (int)ModelArray.size(); i++)
303 ModelArray[i]->Enable(value);
307 for (size_t i = 0; i < (int)CallButtonArray.size(); i++)
309 if (CallButtonArray[i])
310 CallButtonArray[i]->Enabled(value);
314 for (size_t i = 0; i < (int)DoorArray.size(); i++)
317 DoorArray[i]->Enabled(value);
320 //turn on/off directional indicators
321 for (int i = 0; i < (int)DirIndicatorArray.size(); i++)
323 if (DirIndicatorArray[i])
324 DirIndicatorArray[i]->Enabled(value);
326 UpdateDirectionalIndicators();
329 for (int i = 0; i < (int)FloorIndicatorArray.size(); i++)
331 if (FloorIndicatorArray[i])
332 FloorIndicatorArray[i]->Enabled(value);
334 //update floor indicator values
335 UpdateFloorIndicators();
338 for (int i = 0; i < (int)sounds.size(); i++)
342 if (sounds[i]->GetLoopState() == true)
353 float Floor::FullHeight()
355 //calculate full height of a floor
356 return InterfloorHeight + Height;
359 Object* Floor::AddCallButtons(std::vector<int> &elevators, const char *BackTexture, const char *UpButtonTexture, const char *UpButtonTexture_Lit, const char *DownButtonTexture, const char *DownButtonTexture_Lit, float CenterX, float CenterZ, float voffset, const char *direction, float BackWidth, float BackHeight, bool ShowBack, float tw, float th)
363 //check if any of the elevators serve the current floor
365 for (int i = 0; i < (int)elevators.size(); i++)
367 Elevator *elev = sbs->GetElevator(elevators[i]);
370 if (elev->IsServicedFloor(Number) == true)
378 //exit if none of the elevators serve the floor
383 int Current = (int)CallButtonArray.size();
384 CallButton *button = new CallButton(elevators, Number, Current, BackTexture, UpButtonTexture, UpButtonTexture_Lit, DownButtonTexture, DownButtonTexture_Lit, CenterX, CenterZ, voffset, direction, BackWidth, BackHeight, ShowBack, tw, th);
385 CallButtonArray.push_back(button);
386 return button->object;
389 void Floor::Cut(const Ogre::Vector3 &start, const Ogre::Vector3 &end, bool cutwalls, bool cutfloors, bool fast, int checkwallnumber, bool prepare)
391 //caller to SBS cut function
392 //Y values are relative to the floor's altitude
393 //if fast is specified, skips the interfloor scan
395 for (int i = 0; i < (int)Level->Walls.size(); i++)
401 sbs->Cut(Level->Walls[i], Ogre::Vector3(start.x, Altitude + start.y, start.z), Ogre::Vector3(end.x, Altitude + end.y, end.z), cutwalls, cutfloors, Ogre::Vector3(0, 0, 0), Ogre::Vector3(0, 0, 0), checkwallnumber, reset);
405 for (int i = 0; i < (int)Interfloor->Walls.size(); i++)
407 sbs->Cut(Interfloor->Walls[i], Ogre::Vector3(start.x, Altitude + start.y, start.z), Ogre::Vector3(end.x, Altitude + end.y, end.z), cutwalls, cutfloors, Ogre::Vector3(0, 0, 0), Ogre::Vector3(0, 0, 0), checkwallnumber, false);
412 void Floor::CutAll(const Ogre::Vector3 &start, const Ogre::Vector3 &end, bool cutwalls, bool cutfloors, bool prepare)
414 //cuts all objects related to this floor (floor, interfloor, shafts, stairs and external)
415 //Y values are relative to the floor's altitude
418 Cut(start, end, cutwalls, cutfloors, false);
421 for (int i = 1; i <= sbs->Shafts(); i++)
423 if (sbs->GetShaft(i))
424 sbs->GetShaft(i)->Cut(false, Number, start, end, cutwalls, cutfloors);
428 for (int i = 1; i <= sbs->StairsNum(); i++)
430 if (sbs->GetStairs(i))
431 sbs->GetStairs(i)->Cut(false, Number, start, end, cutwalls, cutfloors);
435 for (int i = 0; i < (int)sbs->External->Walls.size(); i++)
436 sbs->Cut(sbs->External->Walls[i], Ogre::Vector3(start.x, Altitude + start.y, start.z), Ogre::Vector3(end.x, Altitude + end.y, end.z), cutwalls, cutfloors, Ogre::Vector3(0, 0, 0), Ogre::Vector3(0, 0, 0));
439 void Floor::AddGroupFloor(int number)
441 //adds a floor number to the group list.
442 //Groups are used to enable multiple floors at the same time when
443 //a user arrives at a floor
446 for (int i = 0; i < (int)Group.size(); i++)
448 if (Group[i] == number)
453 Group.push_back(number);
454 std::sort(Group.begin(), Group.end());
458 void Floor::RemoveGroupFloor(int number)
460 //removes a floor number from the group list
463 for (int i = 0; i < (int)Group.size(); i++)
465 if (Group[i] == number)
470 for (int i = 0; i < (int)Group.size(); i++)
472 if (Group[i] == number)
473 Group.erase(Group.begin() + i);
478 void Floor::EnableGroup(bool value)
480 //enable floors grouped with this floor
482 SBS_PROFILE("Floor::EnableGroup");
483 if (Group.size() > 0)
485 for (size_t i = 0; i < Group.size(); i++)
487 //check if floor exists
488 if (sbs->GetFloor(Group[i]))
491 sbs->GetFloor(Group[i])->Enabled(value);
493 //enable shafts and stairs for other floor
494 for (int j = 1; j <= sbs->Shafts(); j++)
496 if (sbs->GetShaft(j))
497 sbs->GetShaft(j)->Enabled(Group[i], value, true);
499 for (int j = 1; j <= sbs->StairsNum(); j++)
501 if (sbs->GetStairs(j))
502 sbs->GetStairs(j)->Enabled(Group[i], value);
509 bool Floor::IsInGroup(int floor)
511 //return true if the specified floor is in the group listing
513 if (Group.size() > 0)
515 for (size_t i = 0; i < Group.size(); i++)
517 if (Group[i] == floor)
524 Object* Floor::AddDoor(const char *open_sound, const char *close_sound, bool open_state, const char *texture, float thickness, int direction, float speed, float CenterX, float CenterZ, float width, float height, float voffset, float tw, float th)
526 //interface to the SBS AddDoor function
528 if (direction > 8 || direction < 1)
530 ReportError("Door direction out of range");
534 float x1, z1, x2, z2;
540 z1 = CenterZ - (width / 2);
541 z2 = CenterZ + (width / 2);
545 x1 = CenterX - (width / 2);
546 x2 = CenterX + (width / 2);
553 CutAll(Ogre::Vector3(x1 - 1, GetBase(true) + voffset, z1), Ogre::Vector3(x2 + 1, GetBase(true) + voffset + height, z2), true, false);
555 CutAll(Ogre::Vector3(x1, GetBase(true) + voffset, z1 - 1), Ogre::Vector3(x2, GetBase(true) + voffset + height, z2 + 1), true, false);
557 std::string floornum = ToString(Number);
558 std::string num = ToString((int)DoorArray.size());
559 Door* door = new Door(object, std::string("Floor " + floornum + ":Door " + num).c_str(), open_sound, close_sound, open_state, texture, thickness, direction, speed, CenterX, CenterZ, width, height, voffset + GetBase(), tw, th);
560 DoorArray.push_back(door);
564 bool Floor::CalculateAltitude()
566 //calculate the floor's altitude in relation to floor below (or above it, if it's a basement level)
567 //and return the altitude value
568 //if the related floor does not have an adjacent floor, return false
574 if (sbs->GetFloor(Number - 1))
575 Altitude = sbs->GetFloor(Number - 1)->Altitude + sbs->GetFloor(Number - 1)->FullHeight();
578 return ReportError("Invalid floor number specified - no adjacent floor");
583 Altitude = -FullHeight();
587 if (sbs->GetFloor(Number + 1))
588 Altitude = sbs->GetFloor(Number + 1)->Altitude - FullHeight();
590 return ReportError("Invalid floor number specified - no adjacent floor");
596 void Floor::EnableColumnFrame(bool value)
598 //enable/disable columnframe mesh
599 ColumnFrame->Enable(value);
600 IsColumnFrameEnabled = value;
603 WallObject* Floor::ColumnWallBox(const char *name, const char *texture, float x1, float x2, float z1, float z2, float height_in, float voffset, float tw, float th, bool inside, bool outside, bool top, bool bottom)
605 //create columnframe wall box
607 WallObject *wall = ColumnFrame->CreateWallObject(object, name);
608 sbs->CreateWallBox(wall, name, texture, x1, x2, z1, z2, height_in, Altitude + voffset, tw, th, inside, outside, top, bottom, true);
612 WallObject* Floor::ColumnWallBox2(const char *name, const char *texture, float CenterX, float CenterZ, float WidthX, float LengthZ, float height_in, float voffset, float tw, float th, bool inside, bool outside, bool top, bool bottom)
614 //create columnframe wall box from a central location
616 WallObject *wall = ColumnFrame->CreateWallObject(object, name);
617 sbs->CreateWallBox2(wall, name, texture, CenterX, CenterZ, WidthX, LengthZ, height_in, Altitude + voffset, tw, th, inside, outside, top, bottom, true);
621 Object* Floor::AddFloorIndicator(int elevator, bool relative, const char *texture_prefix, const char *direction, float CenterX, float CenterZ, float width, float height, float voffset)
623 //Creates a floor indicator at the specified location
625 if (relative == false)
627 FloorIndicator *ind = new FloorIndicator(object, elevator, texture_prefix, direction, CenterX, CenterZ, width, height, GetBase() + voffset);
628 FloorIndicatorArray.push_back(ind);
633 Elevator* elev = sbs->GetElevator(elevator);
636 FloorIndicator *ind = new FloorIndicator(object, elevator, texture_prefix, direction, elev->Origin.x + CenterX, elev->Origin.z + CenterZ, width, height, GetBase() + voffset);
637 FloorIndicatorArray.push_back(ind);
645 void Floor::UpdateFloorIndicators(int elevator)
647 //changes the number texture on the floor indicators to the specified elevator's current floor
649 SBS_PROFILE("Floor::UpdateFloorIndicators1");
651 for (int i = 0; i < (int)FloorIndicatorArray.size(); i++)
653 if (FloorIndicatorArray[i])
655 if (FloorIndicatorArray[i]->elev == elevator)
657 Elevator *elev = sbs->GetElevator(elevator);
662 if (elev->UseFloorSkipText == true && elev->IsServicedFloor(elev->GetFloor()) == false)
663 value = elev->GetFloorSkipText();
666 if (elev->DisplayFloors.size() > 0)
668 for (int i = 0; i < (int)elev->DisplayFloors.size(); i++)
670 if (elev->GetFloor() == elev->DisplayFloors[i])
671 value = sbs->GetFloor(elev->GetFloor())->ID;
675 value = sbs->GetFloor(elev->GetFloor())->ID;
679 FloorIndicatorArray[i]->Update(value.c_str());
685 void Floor::UpdateFloorIndicators()
687 //changes the number texture on the floor indicators
689 SBS_PROFILE("Floor::UpdateFloorIndicators2");
691 for (int i = 0; i < (int)FloorIndicatorArray.size(); i++)
693 if (FloorIndicatorArray[i])
695 Elevator *elevator = sbs->GetElevator(FloorIndicatorArray[i]->elev);
700 if (elevator->UseFloorSkipText == true && elevator->IsServicedFloor(elevator->GetFloor()) == false)
701 value = elevator->GetFloorSkipText();
704 if (elevator->DisplayFloors.size() > 0)
706 for (int i = 0; i < (int)elevator->DisplayFloors.size(); i++)
708 if (elevator->GetFloor() == elevator->DisplayFloors[i])
709 value = sbs->GetFloor(elevator->GetFloor())->ID;
713 value = sbs->GetFloor(elevator->GetFloor())->ID;
716 FloorIndicatorArray[i]->Update(value.c_str());
723 //floor object main loop; runs if camera is currently on this floor
725 if (IsEnabled == true)
727 for (int i = 0; i < (int)TriggerArray.size(); i++)
730 TriggerArray[i]->Check();
735 std::vector<int> Floor::GetCallButtons(int elevator)
737 //get numbers of call buttons that service the specified elevator
739 std::vector<int> buttons;
740 buttons.reserve(CallButtonArray.size());
741 for (int i = 0; i < (int)CallButtonArray.size(); i++)
743 //put button number onto the array if it serves the elevator
744 if (CallButtonArray[i])
746 if (CallButtonArray[i]->ServicesElevator(elevator) == true)
747 buttons.push_back(i);
753 CallButton* Floor::GetCallButton(int elevator)
755 //returns the first call button object that services the specified elevator
757 for (int i = 0; i < (int)CallButtonArray.size(); i++)
759 if (CallButtonArray[i])
761 if (CallButtonArray[i]->ServicesElevator(elevator) == true)
762 return CallButtonArray[i];
768 void Floor::AddFillerWalls(const char *texture, float thickness, float CenterX, float CenterZ, float width, float height, float voffset, bool direction, float tw, float th)
770 //convenience function for adding filler walls around doors
771 //direction is either "false" for a door that faces left/right, or "true" for one that faces front/back
773 float x1 = 0, x2 = 0, z1 = 0, z2 = 0, depth1 = 0, depth2 = 0;
775 if (sbs->GetWallOrientation() == 0)
780 if (sbs->GetWallOrientation() == 1)
782 depth1 = thickness / 2;
783 depth2 = thickness / 2;
785 if (sbs->GetWallOrientation() == 2)
791 if (direction == false)
793 //door faces left/right
794 x1 = CenterX - depth1;
795 x2 = CenterX + depth2;
796 z1 = CenterZ - (width / 2);
797 z2 = CenterZ + (width / 2);
801 //door faces front/back
802 x1 = CenterX - (width / 2);
803 x2 = CenterX + (width / 2);
804 z1 = CenterZ - depth1;
805 z2 = CenterZ + depth2;
808 //perform a cut in the area
809 CutAll(Ogre::Vector3(x1, GetBase(true) + voffset, z1), Ogre::Vector3(x2, GetBase(true) + voffset + height, z2), true, false);
812 sbs->DrawWalls(false, true, false, false, false, false);
813 if (direction == false)
814 AddWall("FillerWallLeft", texture, 0, x1, z1, x2, z1, height, height, voffset, voffset, tw, th, false);
816 AddWall("FillerWallLeft", texture, 0, x1, z1, x1, z2, height, height, voffset, voffset, tw, th, false);
819 sbs->DrawWalls(true, false, false, false, false, false);
820 if (direction == false)
821 AddWall("FillerWallRight", texture, 0, x1, z2, x2, z2, height, height, voffset, voffset, tw, th, false);
823 AddWall("FillerWallRight", texture, 0, x2, z1, x2, z2, height, height, voffset, voffset, tw, th, false);
825 AddFloor("FillerWallTop", texture, 0, x1, z1, x2, z2, height + voffset, height + voffset, false, false, tw, th, false);
829 Object* Floor::AddSound(const char *name, const char *filename, Ogre::Vector3 position, bool loop, float volume, int speed, float min_distance, float max_distance, float doppler_level, float cone_inside_angle, float cone_outside_angle, float cone_outside_volume, Ogre::Vector3 direction)
831 //create a looping sound object
833 Sound *sound = new Sound(object, name, false);
834 sounds.push_back(sound);
836 //set parameters and play sound
837 sound->SetPosition(position);
838 sound->SetDirection(direction);
839 sound->SetVolume(volume);
840 sound->SetSpeed(speed);
841 sound->SetDistances(min_distance, max_distance);
842 sound->SetDirection(direction);
843 sound->SetDopplerLevel(doppler_level);
844 sound->SetConeSettings(cone_inside_angle, cone_outside_angle, cone_outside_volume);
845 sound->Load(filename);
850 return sound->object;
853 std::vector<Sound*> Floor::GetSound(const char *name)
857 std::string findname = name;
858 SetCase(findname, false);
859 std::vector<Sound*> soundlist;
860 for (int i = 0; i < (int)sounds.size(); i++)
864 std::string name2 = sounds[i]->GetName();
865 SetCase(name2, false);
866 if (findname == name2)
867 soundlist.push_back(sounds[i]);
873 void Floor::Report(std::string message)
875 //general reporting function
876 sbs->Report("Floor " + ToString2(Number) + ": " + message);
879 bool Floor::ReportError(std::string message)
881 //general reporting function
882 return sbs->ReportError("Floor " + ToString2(Number) + ": " + message);
885 float Floor::GetBase(bool relative)
887 //returns the base of the floor
888 //if Interfloor is on the bottom of the level (by default), the base is GetBase()
889 //otherwise the base is just altitude
890 if (relative == false)
892 if (sbs->InterfloorOnTop == false)
893 return Altitude + InterfloorHeight;
899 if (sbs->InterfloorOnTop == false)
900 return InterfloorHeight;
906 Object* Floor::AddDirectionalIndicator(int elevator, bool relative, bool active_direction, bool single, bool vertical, const char *BackTexture, const char *uptexture, const char *uptexture_lit, const char *downtexture, const char *downtexture_lit, float CenterX, float CenterZ, float voffset, const char *direction, float BackWidth, float BackHeight, bool ShowBack, float tw, float th)
908 //create a directional indicator on the specified floor, associated with a given elevator
911 Report("adding directional indicator");
913 Elevator *elev = sbs->GetElevator(elevator);
918 if (relative == true)
920 x = elev->Origin.x + CenterX;
921 z = elev->Origin.z + CenterZ;
929 if (active_direction == false)
931 //if active_direction is false, only create indicator if the elevator serves the floor
932 if (elev->IsServicedFloor(Number) == false)
936 DirectionalIndicator *indicator = new DirectionalIndicator(object, elevator, Number, active_direction, single, vertical, BackTexture, uptexture, uptexture_lit, downtexture, downtexture_lit, x, z, voffset, direction, BackWidth, BackHeight, ShowBack, tw, th);
937 DirIndicatorArray.push_back(indicator);
938 return indicator->object;
941 void Floor::SetDirectionalIndicators(int elevator, bool UpLight, bool DownLight)
943 //set light status of all standard (non active-direction) directional indicators associated with the given elevator
945 for (int i = 0; i < (int)DirIndicatorArray.size(); i++)
947 if (DirIndicatorArray[i])
949 if (DirIndicatorArray[i]->elevator_num == elevator && DirIndicatorArray[i]->ActiveDirection == false)
951 DirIndicatorArray[i]->DownLight(DownLight);
952 DirIndicatorArray[i]->UpLight(UpLight);
958 void Floor::UpdateDirectionalIndicators(int elevator)
960 //updates the active-direction indicators associated with the given elevator
962 SBS_PROFILE("Floor::UpdateDirectionalIndicators1");
963 for (int i = 0; i < (int)DirIndicatorArray.size(); i++)
965 if (DirIndicatorArray[i])
967 if (DirIndicatorArray[i]->elevator_num == elevator && DirIndicatorArray[i]->ActiveDirection == true)
969 Elevator *elev = sbs->GetElevator(elevator);
974 if (elev->ActiveDirection == 1)
976 DirIndicatorArray[i]->UpLight(true);
977 DirIndicatorArray[i]->DownLight(false);
979 if (elev->ActiveDirection == 0)
981 DirIndicatorArray[i]->UpLight(false);
982 DirIndicatorArray[i]->DownLight(false);
984 if (elev->ActiveDirection == -1)
986 DirIndicatorArray[i]->UpLight(false);
987 DirIndicatorArray[i]->DownLight(true);
994 void Floor::UpdateDirectionalIndicators()
996 //updates all active-direction indicators
998 SBS_PROFILE("Floor::UpdateDirectionalIndicators2");
1000 for (int i = 0; i < (int)DirIndicatorArray.size(); i++)
1002 if (DirIndicatorArray[i])
1004 if (DirIndicatorArray[i]->ActiveDirection == true)
1006 Elevator *elev = sbs->GetElevator(DirIndicatorArray[i]->elevator_num);
1011 if (elev->ActiveDirection == 1)
1013 DirIndicatorArray[i]->UpLight(true);
1014 DirIndicatorArray[i]->DownLight(false);
1016 if (elev->ActiveDirection == 0)
1018 DirIndicatorArray[i]->UpLight(false);
1019 DirIndicatorArray[i]->DownLight(false);
1021 if (elev->ActiveDirection == -1)
1023 DirIndicatorArray[i]->UpLight(false);
1024 DirIndicatorArray[i]->DownLight(true);
1031 Door* Floor::GetDoor(int number)
1034 if (number < (int)DoorArray.size())
1036 if (DoorArray[number])
1037 return DoorArray[number];
1043 void Floor::RemoveCallButton(CallButton *callbutton)
1045 //remove a call button object from the array
1046 //this does not delete the object
1047 for (int i = 0; i < (int)CallButtonArray.size(); i++)
1049 if (CallButtonArray[i] == callbutton)
1051 CallButtonArray.erase(CallButtonArray.begin() + i);
1057 void Floor::RemoveFloorIndicator(FloorIndicator *indicator)
1059 //remove a floor indicator from the array
1060 //this does not delete the object
1061 for (int i = 0; i < (int)FloorIndicatorArray.size(); i++)
1063 if (FloorIndicatorArray[i] == indicator)
1065 FloorIndicatorArray.erase(FloorIndicatorArray.begin() + i);
1071 void Floor::RemoveDirectionalIndicator(DirectionalIndicator *indicator)
1073 //remove a directional indicator from the array
1074 //this does not delete the object
1075 for (int i = 0; i < (int)DirIndicatorArray.size(); i++)
1077 if (DirIndicatorArray[i] == indicator)
1079 DirIndicatorArray.erase(DirIndicatorArray.begin() + i);
1085 void Floor::RemoveDoor(Door *door)
1087 //remove a door from the array
1088 //this does not delete the object
1089 for (int i = 0; i < (int)DoorArray.size(); i++)
1091 if (DoorArray[i] == door)
1093 DoorArray.erase(DoorArray.begin() + i);
1099 void Floor::RemoveSound(Sound *sound)
1101 //remove a sound from the array
1102 //this does not delete the object
1103 for (int i = 0; i < (int)sounds.size(); i++)
1105 if (sounds[i] == sound)
1107 sounds.erase(sounds.begin() + i);
1113 void Floor::RemoveLight(Light *light)
1115 //remove a light reference (does not delete the object itself)
1116 for (int i = 0; i < (int)lights.size(); i++)
1118 if (lights[i] == light)
1120 lights.erase(lights.begin() + i);
1126 void Floor::RemoveModel(Model *model)
1128 //remove a model reference (does not delete the object itself)
1129 for (int i = 0; i < (int)ModelArray.size(); i++)
1131 if (ModelArray[i] == model)
1133 ModelArray.erase(ModelArray.begin() + i);
1139 void Floor::RemoveControl(Control *control)
1141 //remove a control reference (does not delete the object itself)
1142 for (int i = 0; i < (int)ControlArray.size(); i++)
1144 if (ControlArray[i] == control)
1146 ControlArray.erase(ControlArray.begin() + i);
1152 void Floor::RemoveTrigger(Trigger *trigger)
1154 //remove a trigger reference (does not delete the object itself)
1155 for (int i = 0; i < (int)TriggerArray.size(); i++)
1157 if (TriggerArray[i] == trigger)
1159 TriggerArray.erase(TriggerArray.begin() + i);
1165 Object* Floor::AddLight(const char *name, int type, Ogre::Vector3 position, Ogre::Vector3 direction, float color_r, float color_g, float color_b, float spec_color_r, float spec_color_g, float spec_color_b, float spot_inner_angle, float spot_outer_angle, float spot_falloff, float att_range, float att_constant, float att_linear, float att_quadratic)
1169 Light* light = new Light(object, name, type, position + Ogre::Vector3(0, GetBase(), 0), direction, color_r, color_g, color_b, spec_color_r, spec_color_g, spec_color_b, spot_inner_angle, spot_outer_angle, spot_falloff, att_range, att_constant, att_linear, att_quadratic);
1170 lights.push_back(light);
1171 return light->object;
1174 Object* Floor::AddModel(const char *name, const char *filename, bool center, Ogre::Vector3 position, Ogre::Vector3 rotation, float max_render_distance, float scale_multiplier, bool enable_physics, float restitution, float friction, float mass)
1177 Model* model = new Model(object, name, filename, center, position + Ogre::Vector3(0, GetBase(), 0), rotation, max_render_distance, scale_multiplier, enable_physics, restitution, friction, mass);
1178 if (model->load_error == true)
1183 ModelArray.push_back(model);
1184 return model->object;
1187 void Floor::ReplaceTexture(const std::string &oldtexture, const std::string &newtexture)
1189 //change all instances of oldtexture in all meshes to newtexture
1190 Level->ReplaceTexture(oldtexture, newtexture);
1191 Interfloor->ReplaceTexture(oldtexture, newtexture);
1192 ColumnFrame->ReplaceTexture(oldtexture, newtexture);
1195 Object* Floor::AddControl(const char *name, const char *sound, const char *direction, float CenterX, float CenterZ, float width, float height, float voffset, std::vector<std::string> &action_names, std::vector<std::string> &textures)
1198 std::vector<Action*> actionnull; //not used
1199 Control* control = new Control(object, name, sound, action_names, actionnull, textures, direction, width, height, voffset, true);
1200 control->SetPosition(Ogre::Vector3(CenterX, GetBase(), CenterZ));
1201 ControlArray.push_back(control);
1202 return control->object;
1205 Object* Floor::AddTrigger(const char *name, const char *sound_file, Ogre::Vector3 &area_min, Ogre::Vector3 &area_max, std::vector<std::string> &action_names)
1208 Trigger* trigger = new Trigger(object, name, sound_file, area_min, area_max, action_names);
1209 TriggerArray.push_back(trigger);
1210 trigger->SetPosition(Ogre::Vector3(0, GetBase(), 0));
1211 return trigger->object;