Skyscraper 2.0
globals.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Script Processor - Globals Section
3 Copyright (C)2003-2024 Ryan Thoryk
4 https://www.skyscrapersim.net
5 https://sourceforge.net/projects/skyscraper/
6 Contact - ryan@skyscrapersim.net
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*/
22
23#include "globals.h"
24#include "sbs.h"
25#include "enginecontext.h"
26#include "vm.h"
27#include "sky.h"
28#include "camera.h"
29#include "scriptproc.h"
30#include "section.h"
31
32using namespace SBS;
33
34namespace Skyscraper {
35
40
42{
43 //process global parameters
44
45 //get text after equal sign
46 bool equals;
47 std::string value = GetAfterEquals(LineData, equals);
48
49 //store variable values
50
51 //Name parameter
52 if (StartsWithNoCase(LineData, "name"))
53 {
54 Simcore->BuildingName = value;
55 return sNextLine;
56 }
57 //Designer parameter
58 if (StartsWithNoCase(LineData, "designer"))
59 {
61 return sNextLine;
62 }
63 //Location parameter
64 if (StartsWithNoCase(LineData, "location"))
65 {
67 return sNextLine;
68 }
69 //Description parameter
70 if (StartsWithNoCase(LineData, "description"))
71 {
73 return sNextLine;
74 }
75 //Version parameter
76 if (StartsWithNoCase(LineData, "version"))
77 {
78 Simcore->BuildingVersion = value;
79 return sNextLine;
80 }
81 //Sky parameter
82 if (StartsWithNoCase(LineData, "sky"))
83 {
84 Simcore->SkyName = value;
85 return sNextLine;
86 }
87 //DynamicSky parameter
88 if (StartsWithNoCase(LineData, "dynamicsky"))
89 {
90 if (engine->IsRoot() == true)
91 engine->GetVM()->GetSkySystem()->SkyName = value;
92 return sNextLine;
93 }
94 //Collisions parameter
95 if (StartsWithNoCase(LineData, "collisions"))
96 {
98 return sNextLine;
99 }
100 //Gravity parameter
101 if (StartsWithNoCase(LineData, "gravity"))
102 {
104 return sNextLine;
105 }
106 //CameraFloor parameter
107 if (StartsWithNoCase(LineData, "camerafloor"))
108 {
109 int data;
110 std::string str = Calc(value);
111 if (!IsNumeric(str, data))
112 return ScriptError("Invalid floor");
113
114 Simcore->camera->StartFloor = data;
115 return sNextLine;
116 }
117 //CameraPosition parameter
118 if (StartsWithNoCase(LineData, "cameraposition"))
119 {
120 Real x, z;
121 std::string str1 = value.substr(0, value.find(",", 0));
122 std::string str2 = value.substr(value.find(",", 0) + 1);
123 str1 = Calc(str1);
124 str2 = Calc(str2);
125 if (!IsNumeric(str1, x) || !IsNumeric(str2, z))
126 return ScriptError("Invalid position");
127
130 return sNextLine;
131 }
132 //CameraDirection parameter
133 if (StartsWithNoCase(LineData, "cameradirection"))
134 {
135 int loc1 = value.find(",", 0);
136 int loc2 = value.find(",", loc1 + 1);
137 Real x, y, z;
138 std::string str1 = value.substr(0, loc1);
139 std::string str2 = value.substr(loc1 + 1, loc2 - loc1 - 1);
140 std::string str3 = value.substr(loc2 + 1);
141 str1 = Calc(str1);
142 str2 = Calc(str2);
143 str3 = Calc(str3);
144 if (!IsNumeric(str1, x) || !IsNumeric(str2, y) || !IsNumeric(str3, z))
145 return ScriptError("Invalid direction");
146
148 return sNextLine;
149 }
150 //CameraRotation parameter
151 if (StartsWithNoCase(LineData, "camerarotation"))
152 {
153 int loc1 = value.find(",", 0);
154 int loc2 = value.find(",", loc1 + 1);
155 Real x, y, z;
156 std::string str1 = value.substr(0, loc1);
157 std::string str2 = value.substr(loc1 + 1, loc2 - loc1 - 1);
158 std::string str3 = value.substr(loc2 + 1);
159 str1 = Calc(str1);
160 str2 = Calc(str2);
161 str3 = Calc(str3);
162 if (!IsNumeric(str1, x) || !IsNumeric(str2, y) || !IsNumeric(str3, z))
163 return ScriptError("Invalid direction");
164
166 return sNextLine;
167 }
168 //InterfloorOnTop parameter
169 if (StartsWithNoCase(LineData, "interfloorontop"))
170 {
172 return sNextLine;
173 }
174 //Coordinates parameter
175 if (StartsWithNoCase(LineData, "coordinates"))
176 {
177 int loc = value.find(",", 0);
178 Real latitude, longitude;
179 std::string str1 = value.substr(0, loc);
180 std::string str2 = value.substr(loc + 1);
181 str1 = Calc(str1);
182 str2 = Calc(str2);
183 if (!IsNumeric(str1, latitude) || !IsNumeric(str2, longitude))
184 return ScriptError("Invalid latitude");
185
186 if (engine->IsRoot() == true)
187 engine->GetVM()->GetSkySystem()->SetLocation(latitude, longitude);
188 return sNextLine;
189 }
190 //DateTime parameter
191 if (StartsWithNoCase(LineData, "datetime"))
192 {
193 if (engine->IsRoot() == true)
194 {
195 if (value == "now")
197 else
198 {
199 double data;
200 if (!IsNumeric(value, data))
201 return ScriptError("Invalid Julian date/time");
202
204 }
205 }
206 return sNextLine;
207 }
208 //TimeScale parameter
209 if (StartsWithNoCase(LineData, "timescale"))
210 {
211 int data;
212 std::string str = Calc(value);
213 if (!IsNumeric(str, data))
214 return ScriptError("Invalid time scale value");
215
216 if (engine->IsRoot() == true)
217 engine->GetVM()->GetSkySystem()->SkyMult = data;
218 }
219 //Position parameter
220 if (StartsWithNoCase(LineData, "position"))
221 {
222 int params = SplitAfterEquals(LineData);
223 if (params != 3)
224 return ScriptError("Incorrect number of parameters");
225
226 //check numeric values
227 for (int i = 0; i <= 2; i++)
228 {
229 if (!IsNumeric(tempdata[i]))
230 return ScriptError("Invalid value: " + tempdata[i]);
231 }
232
233 Vector3 position;
234 position.x = ToFloat(tempdata[0]);
235 position.y = ToFloat(tempdata[1]);
236 position.z = ToFloat(tempdata[2]);
237
238 if (engine->Moved == false)
239 {
240 engine->Move(position, true);
241 engine->Moved = true;
242 }
243 return sNextLine;
244 }
245 //Rotation parameter
246 if (StartsWithNoCase(LineData, "rotation"))
247 {
248 int rotation;
249 std::string str = Calc(value);
250 if (!IsNumeric(str, rotation))
251 return ScriptError("Invalid rotation");
252
253 Simcore->Rotate(0.0, rotation, 0.0);
254 return sNextLine;
255 }
256 //Bounds parameter
257 if (StartsWithNoCase(LineData, "bounds"))
258 {
259 int params = SplitAfterEquals(LineData);
260 if (params != 6)
261 return ScriptError("Incorrect number of parameters");
262
263 //check numeric values
264 for (int i = 0; i <= 5; i++)
265 {
266 if (!IsNumeric(tempdata[i]))
267 return ScriptError("Invalid value: " + tempdata[i]);
268 }
269
270 Vector3 min, max;
271 min.x = ToFloat(tempdata[0]);
272 min.y = ToFloat(tempdata[1]);
273 min.z = ToFloat(tempdata[2]);
274 max.x = ToFloat(tempdata[3]);
275 max.y = ToFloat(tempdata[4]);
276 max.z = ToFloat(tempdata[5]);
277
278 if (Simcore->HasBounds() == false)
279 Simcore->SetBounds(min, max);
280 return sNextLine;
281 }
282 //Lobby parameter
283 if (StartsWithNoCase(LineData, "lobby"))
284 {
285 int data;
286 std::string str = Calc(value);
287 if (!IsNumeric(str, data))
288 return ScriptError("Invalid floor");
289
290 Simcore->Lobby = data;
291 return sNextLine;
292 }
293 //map parameter
294 if (StartsWithNoCase(LineData, "map"))
295 {
296 bool enabled = false;
297 if (StartsWithNoCase(value, "on") == true)
298 enabled = true;
299 Simcore->EnableMap(enabled);
300 }
301 //handle end of globals section
302 if (StartsWithNoCase(LineData, "<endglobals>"))
303 {
304 config->SectionNum = 0;
305 config->Context = "None";
306 engine->Report("Finished globals");
307 return sNextLine;
308 }
309
310 return sContinue;
311}
312
313}
void SetStartRotation(const Vector3 &rotation)
Definition camera.cpp:446
void SetStartDirection(const Vector3 &direction)
Definition camera.cpp:435
Real StartPositionX
Definition camera.h:52
Real StartPositionZ
Definition camera.h:53
void EnableGravity(bool value)
Definition camera.cpp:967
int StartFloor
Definition camera.h:51
void EnableCollisions(bool value)
Definition camera.cpp:1052
virtual void Rotate(const Vector3 &vector, Real speed=1.0)
Definition object.cpp:353
void EnableMap(bool value)
Definition sbs.cpp:4720
int Lobby
Definition sbs.h:198
std::string BuildingName
Definition sbs.h:145
std::string BuildingLocation
Definition sbs.h:148
std::string SkyName
Definition sbs.h:183
bool InterfloorOnTop
Definition sbs.h:187
Camera * camera
Definition sbs.h:160
bool HasBounds()
Definition sbs.cpp:4528
std::string BuildingDesigner
Definition sbs.h:147
void SetBounds(const Vector3 &area_min, const Vector3 &area_max)
Definition sbs.cpp:4368
std::string BuildingVersion
Definition sbs.h:150
std::string BuildingDescription
Definition sbs.h:149
void Move(Vector3 &position, bool move_children=false)
void Report(const std::string &message)
GlobalsSection(ScriptProcessor *parent)
Definition globals.cpp:36
static const int sNextLine
Definition scriptproc.h:70
static const int sContinue
Definition scriptproc.h:69
std::string Calc(const std::string &expression)
void SetDateTime(double julian_date_time)
Definition sky.cpp:290
void SetDateTimeNow()
Definition sky.cpp:273
void SetLocation(Real latitude, Real longitude)
Definition sky.cpp:266
std::string SkyName
Definition sky.h:55
SkySystem * GetSkySystem()
Definition vm.cpp:135
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
bool StartsWithNoCase(const std::string &string, const std::string &check_string)
Definition globals.cpp:237
Real ToFloat(const std::string &string)
Definition globals.cpp:397
bool ToBool(std::string string)
Definition globals.cpp:407
bool IsNumeric(const wxString &string)