4 Scalable Building Simulator - Moving Walkway Object
5 The Skyscraper Project - Version 1.11 Alpha
6 Copyright (C)2004-2017 Ryan Thoryk
7 http://www.skyscrapersim.com
8 http://sourceforge.net/projects/skyscraper
9 Contact - ryan@skyscrapersim.com
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.
33 #include "dynamicmesh.h"
35 #include "movingwalkway.h"
39 MovingWalkway::MovingWalkway(Object *parent, const std::string &name, int run, float speed, const std::string &sound_file, const std::string &texture, const std::string &direction, float CenterX, float CenterZ, float width, float treadsize, int num_steps, float voffset, float tw, float th) : Object(parent)
41 //create a new moving walkway object
42 //run is either 1 for forward motion, -1 for reverse motion, 0 for stop
43 //direction is where the step base is - front, back, left, or right.
46 SetValues("MovingWalkway", "", false);
49 Floor *floor = dynamic_cast<Floor*>(parent);
51 Name = "Floor" + ToString(floor->Number) + ":"+ name;
59 sbs->IncrementMovingWalkwayCount();
64 sound = new Sound(this, name, true);
65 sound->Load(sound_file);
68 Move(CenterX, voffset, CenterZ);
71 for (int i = 0; i < num_steps; i++)
73 Step *mesh = new Step(this, "Step " + ToString(i + 1), 0, 100);
74 Steps.push_back(mesh);
78 CreateSteps(texture, direction, width, treadsize, tw, th);
81 MovingWalkway::~MovingWalkway()
85 sound->parent_deleting = true;
91 for (size_t i = 0; i < Steps.size(); i++)
95 Steps[i]->parent_deleting = true;
101 //unregister from parent
102 if (sbs->FastDelete == false)
104 sbs->DecrementEscalatorCount();
106 //unregister from parent
107 if (parent_deleting == false)
109 std::string type = GetParent()->GetType();
112 static_cast<Floor*>(GetParent())->RemoveMovingWalkway(this);
117 void MovingWalkway::Enabled(bool value)
119 //enable or disable walkway
121 if (is_enabled == value)
126 for (size_t i = 0; i < Steps.size(); i++)
127 Steps[i]->Enabled(value);
129 if (value == false && sound->IsPlaying() == true)
135 void MovingWalkway::SetRun(int value)
139 for (size_t i = 0; i < Steps.size(); i++)
141 Steps[i]->vector = Ogre::Vector3::ZERO;
149 void MovingWalkway::Report(const std::string &message)
151 //general reporting function
152 Object::Report("Moving Walkway " + GetName() + ": " + message);
155 bool MovingWalkway::ReportError(const std::string &message)
157 //general reporting function
158 return Object::ReportError("Moving Walkway " + GetName() + ": " + message);
161 void MovingWalkway::Loop()
165 SBS_PROFILE("MovingWalkway::Loop");
167 if (!IsEnabled() || Run == 0)
169 if (sound->IsPlaying() == true)
174 if (sound->IsPlaying() == false)
176 sound->SetLoopState(true);
183 void MovingWalkway::CreateSteps(const std::string &texture, const std::string &direction, float width, float treadsize, float tw, float th)
186 std::string Name = GetName();
188 Direction = direction;
189 this->treadsize = treadsize;
190 SetCase(Direction, false);
191 int num_steps = (int)Steps.size();
193 sbs->GetTextureManager()->ResetTextureMapping(true);
194 if (Direction == "right" || Direction == "back")
195 sbs->SetWallOrientation("right");
196 if (Direction == "left" || Direction == "front")
197 sbs->SetWallOrientation("left");
199 for (int i = 1; i <= num_steps; i++)
202 std::string base = Name + ":" + ToString(i);
205 Wall *wall = Steps[i - 1]->CreateWallObject(base);
207 float thickness = treadsize;
209 sbs->DrawWalls(false, true, false, false, false, false);
211 if (Direction == "right")
213 pos = ((treadsize * num_steps + 1) / 2) - (treadsize * i);
214 sbs->AddFloorMain(wall, base, texture, 0, 0, -(width / 2), treadsize, width / 2, 0, 0, false, false, tw, th, true);
215 Steps[i - 1]->Move(Ogre::Vector3(pos, 0, 0));
217 if (Direction == "left")
219 pos = -((treadsize * num_steps + 1) / 2) + (treadsize * i);
220 sbs->AddFloorMain(wall, base, texture, 0, -treadsize, -(width / 2), 0, width / 2, 0, 0, false, false, tw, th, true);
221 Steps[i - 1]->Move(Ogre::Vector3(pos, 0, 0));
223 if (Direction == "back")
225 pos = ((treadsize * num_steps + 1) / 2) - (treadsize * i);
226 sbs->AddFloorMain(wall, base, texture, 0, -(width / 2), 0, width / 2, treadsize, 0, 0, false, false, tw, th, true);
227 Steps[i - 1]->Move(Ogre::Vector3(0, 0, pos));
229 if (Direction == "front")
231 pos = -((treadsize * num_steps + 1) / 2) + (treadsize * i);
232 sbs->AddFloorMain(wall, base, texture, 0, -(width / 2), -treadsize, width / 2, 0, 0, 0, false, false, tw, th, true);
233 Steps[i - 1]->Move(Ogre::Vector3(0, 0, pos));
235 Steps[i - 1]->vector = Ogre::Vector3::ZERO;
236 Steps[1 - 1]->speed = 0;
239 start = Steps[i - 1]->GetPosition();
241 end = Steps[i - 1]->GetPosition();
242 Steps[i - 1]->start = Steps[i - 1]->GetPosition();
245 sbs->ResetWalls(true);
246 sbs->GetTextureManager()->ResetTextureMapping();
249 void MovingWalkway::MoveSteps()
251 for (size_t i = 0; i < Steps.size(); i++)
255 if (Direction == "right")
257 float pos = Steps[i]->GetPosition().x;
258 if (pos < end.x - treadsize)
259 Steps[i]->SetPosition(start);
261 Steps[i]->Move(Ogre::Vector3(-Run, 0, 0), Speed * sbs->delta);
263 if (Direction == "left")
265 float pos = Steps[i]->GetPosition().x;
266 if (pos > end.x + treadsize)
267 Steps[i]->SetPosition(start);
269 Steps[i]->Move(Ogre::Vector3(Run, 0, 0), Speed * sbs->delta);
271 if (Direction == "back")
273 float pos = Steps[i]->GetPosition().z;
274 if (pos < end.z - treadsize)
275 Steps[i]->SetPosition(start);
277 Steps[i]->Move(Ogre::Vector3(0, 0, -Run), Speed * sbs->delta);
279 if (Direction == "front")
281 float pos = Steps[i]->GetPosition().z;
282 if (pos > end.z + treadsize)
283 Steps[i]->SetPosition(start);
285 Steps[i]->Move(Ogre::Vector3(0, 0, Run), Speed * sbs->delta);
290 if (Direction == "right")
292 float pos = Steps[i]->GetPosition().x;
294 Steps[i]->SetPosition(Ogre::Vector3(end.x - treadsize, end.y, end.z));
296 Steps[i]->Move(Ogre::Vector3(-Run, 0, 0), Speed * sbs->delta);
298 if (Direction == "left")
300 float pos = Steps[i]->GetPosition().x;
302 Steps[i]->SetPosition(Ogre::Vector3(end.x + treadsize, end.y, end.z));
304 Steps[i]->Move(Ogre::Vector3(Run, 0, 0), Speed * sbs->delta);
306 if (Direction == "back")
308 float pos = Steps[i]->GetPosition().z;
310 Steps[i]->SetPosition(Ogre::Vector3(end.x, end.y, end.z - treadsize));
312 Steps[i]->Move(Ogre::Vector3(0, 0, -Run), Speed * sbs->delta);
314 if (Direction == "front")
316 float pos = Steps[i]->GetPosition().z;
318 Steps[i]->SetPosition(Ogre::Vector3(end.x, end.y, end.z + treadsize));
320 Steps[i]->Move(Ogre::Vector3(0, 0, Run), Speed * sbs->delta);
326 void MovingWalkway::OnClick(Ogre::Vector3 &position, bool shift, bool ctrl, bool alt, bool right)
328 //cycle run stages if shift-click is performed
335 for (size_t i = 0; i < Steps.size(); i++)
337 Steps[i]->vector = 0;
348 void MovingWalkway::ResetState()
350 //reset walkway state
353 for (size_t i = 0; i < Steps.size(); i++)
355 Steps[i]->SetPosition(Steps[i]->start);