Skyscraper 2.0
buildings.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Script Processor - Buildings 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 "vm.h"
26#include "enginecontext.h"
27#include "scriptproc.h"
28#include "section.h"
29
30using namespace SBS;
31
32namespace Skyscraper {
33
38
40{
41 //Load additional buildings
42
43 //IF/While statement stub (continue to global commands for processing)
44 if (StartsWithNoCase(LineData, "if") || StartsWithNoCase(LineData, "while"))
45 return sContinue;
46
47 //process math functions
48 if (MathFunctions(LineData) == sError)
49 return sError;
50
51 //process functions
52 if (parent->FunctionProc() == true)
53 return sNextLine;
54
55 //get text after equal sign
56 bool equals;
57 std::string value = GetAfterEquals(LineData, equals);
58
59 //parameters
60
61 if (engine->IsRoot() == true) //only run these commands if the engine is root
62 {
63 //ConcurrentLoads parameter
64 if (StartsWithNoCase(LineData, "concurrentloads"))
65 {
66 if (equals == false)
67 return ScriptError("Syntax error");
68
70 return sNextLine;
71 }
72 //CutLandscape parameter
73 if (StartsWithNoCase(LineData, "cutlandscape"))
74 {
75 if (equals == false)
76 return ScriptError("Syntax error");
77
78 engine->GetVM()->CutLandscape = ToBool(value);
79 return sNextLine;
80 }
81 //CutBuildings parameter
82 if (StartsWithNoCase(LineData, "cutbuildings"))
83 {
84 if (equals == false)
85 return ScriptError("Syntax error");
86
87 engine->GetVM()->CutBuildings = ToBool(value);
88 return sNextLine;
89 }
90 //CutExternal parameter
91 if (StartsWithNoCase(LineData, "cutexternal"))
92 {
93 if (equals == false)
94 return ScriptError("Syntax error");
95
96 engine->GetVM()->CutExternal = ToBool(value);
97 return sNextLine;
98 }
99 //CutFloors parameter
100 if (StartsWithNoCase(LineData, "cutfloors"))
101 {
102 if (equals == false)
103 return ScriptError("Syntax error");
104
105 engine->GetVM()->CutFloors = ToBool(value);
106 return sNextLine;
107 }
108 }
109
110 //Load command
111 if (StartsWithNoCase(LineData, "load"))
112 {
113 //get data
114 int params = SplitData(LineData, 5, false);
115
116 if (params != 1 && params != 5 && params != 11)
117 return ScriptError("Incorrect number of parameters");
118
119 //check numeric values
120 if (params > 1)
121 {
122 for (int i = 1; i <= params - 1; i++)
123 {
124 tempdata[i] = parent->Calc(tempdata[i]);
125 if (!IsNumeric(tempdata[i]))
126 return ScriptError("Invalid value: " + tempdata[i]);
127 }
128 }
129
130 Vector3 position (Vector3::ZERO);
131 Real rotation = 0.0;
132 Vector3 min (Vector3::ZERO);
133 Vector3 max (Vector3::ZERO);
134
135 if (params > 1)
136 {
137 position.x = ToFloat(tempdata[1]);
138 position.y = ToFloat(tempdata[2]);
139 position.z = ToFloat(tempdata[3]);
140 rotation = ToFloat(tempdata[4]);
141 }
142 if (params == 11)
143 {
144 min.x = ToFloat(tempdata[5]);
145 min.y = ToFloat(tempdata[6]);
146 min.z = ToFloat(tempdata[7]);
147 max.x = ToFloat(tempdata[8]);
148 max.y = ToFloat(tempdata[9]);
149 max.z = ToFloat(tempdata[10]);
150 }
151
152 bool result = engine->GetVM()->Load(false, tempdata[0], engine, position, rotation, min, max);
153
154 return sNextLine;
155 }
156
157 //handle end of buildings section
158 if (StartsWithNoCase(LineData, "<endbuildings>"))
159 {
160 config->SectionNum = 0;
161 config->Context = "None";
162 engine->Report("Finished loading other buildings");
163 return sNextLine;
164 }
165
166 return sContinue;
167}
168
169}
void Report(const std::string &message)
static const int sNextLine
Definition scriptproc.h:70
static const int sContinue
Definition scriptproc.h:69
static const int sError
Definition scriptproc.h:71
bool CutLandscape
Definition vm.h:119
bool CutBuildings
Definition vm.h:119
bool Load(bool clear, const std::string &filename, EngineContext *parent=0, const Vector3 &position=Vector3::ZERO, Real rotation=0.0, const Vector3 &area_min=Vector3::ZERO, const Vector3 &area_max=Vector3::ZERO)
Definition vm.cpp:696
bool ConcurrentLoads
Definition vm.h:116
bool CutExternal
Definition vm.h:119
bool CutFloors
Definition vm.h:119
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)