Skyscraper 2.0
callstations.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Script Processor - Call Stations 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 "floor.h"
27#include "callstation.h"
28#include "buttonpanel.h"
29#include "control.h"
30#include "indicator.h"
31#include "scriptproc.h"
32#include "section.h"
33
34using namespace SBS;
35
36namespace Skyscraper {
37
42
44{
45 //Process call stations
46
47 //get call station object
48 CallStation *station = 0;
49 Floor *floor = 0;
50
52 if (floor)
53 station = floor->GetCallStation(config->Current);
54 else
55 return sError;
56
57 //create call station if not created already
58 if (!station)
59 station = floor->AddCallStation(config->Current);
60
61 if (!station)
62 return sError;
63
64 //replace variables with actual values
65 if (config->SectionNum == 9) //only run if not being called from floor function
66 {
68 ReplaceAll(LineData, "%callstation%", ToString(config->Current));
69
70 //IF/While statement stub (continue to global commands for processing)
71 if (StartsWithNoCase(LineData, "if") || StartsWithNoCase(LineData, "while"))
72 return sContinue;
73
74 //process math functions
75 if (MathFunctions(LineData) == sError)
76 return sError;
77
78 //process functions
79 if (parent->FunctionProc() == true)
80 return sNextLine;
81 }
82
83 //get text after equal sign
84 bool equals;
85 std::string value = GetAfterEquals(LineData, equals);
86
87 //parameters
88
89 //Name parameter
90 if (StartsWithNoCase(LineData, "name"))
91 {
92 if (equals == false)
93 return ScriptError("Syntax error");
94 station->Name = value;
95 return sNextLine;
96 }
97 //Controller parameter
98 if (StartsWithNoCase(LineData, "controller"))
99 {
100 if (equals == false)
101 return ScriptError("Syntax error");
102 std::string str = Calc(value);
103 int num = 0;
104 if (!IsNumeric(str, num))
105 return ScriptError("Invalid value");
106 station->SetController(num);
107 return sNextLine;
108 }
109 //InvalidInput parameter
110 if (StartsWithNoCase(LineData, "invalidinput"))
111 {
112 //copy string listing of elevators into array
113 int params = SplitAfterEquals(LineData);
114 if (params < 1)
115 return ScriptError("Syntax Error");
116
117 std::vector<std::string> inputs;
118
119 for (int line = 0; line < params; line++)
120 inputs.emplace_back(tempdata[line]);
121
122 station->InvalidInput = inputs;
123
124 return sNextLine;
125 }
126 //TimerDelay parameter
127 if (StartsWithNoCase(LineData, "timerdelay"))
128 {
129 if (equals == false)
130 return ScriptError("Syntax error");
131 std::string str = Calc(value);
132 float num = 0;
133 if (!IsNumeric(str, num))
134 return ScriptError("Invalid value");
135 station->TimerDelay = num;
136 return sNextLine;
137 }
138 //ShowDirection parameter
139 if (StartsWithNoCase(LineData, "showdirection"))
140 {
141 if (equals == false)
142 return ScriptError("Syntax error");
143
144 station->ShowDirection = ToBool(value);
145 return sNextLine;
146 }
147
148 //commands
149
150 //CreatePanel command
151 if (StartsWithNoCase(LineData, "createpanel"))
152 {
153 //get data
154 int params = SplitData(LineData, 12);
155
156 if (params != 10)
157 return ScriptError("Incorrect number of parameters");
158
159 //check numeric values
160 for (int i = 1; i <= 9; i++)
161 {
162 if (i == 3)
163 i = 4;
164 if (!IsNumeric(tempdata[i]))
165 return ScriptError("Invalid value: " + tempdata[i]);
166 }
167
168 StoreCommand(station->CreateButtonPanel(tempdata[0], ToInt(tempdata[1]), ToInt(tempdata[2]), tempdata[3], ToFloat(tempdata[4]), ToFloat(tempdata[5]), ToFloat(tempdata[6]), ToFloat(tempdata[7]), ToFloat(tempdata[8]), ToFloat(tempdata[9])));
169 return sNextLine;
170 }
171
172 //AddControl command
173 if (StartsWithNoCase(LineData, "addcontrol "))
174 {
175 //get data
176 int params = SplitData(LineData, 11);
177
178 if (params < 10)
179 return ScriptError("Incorrect number of parameters");
180
181 int end = 7;
182
183 //check numeric values
184 for (int i = 0; i <= end; i++)
185 {
186 if (i == 0)
187 i++;
188 if (!IsNumeric(tempdata[i]))
189 return ScriptError("Invalid value: " + tempdata[i]);
190 }
191
192 if (!station->GetPanel())
193 return ScriptError("Panel not created yet");
194
195 std::vector<std::string> action_array, tex_array;
196 int slength, parameters;
197
198 //get number of action & texture parameters
199 slength = (int)tempdata.size();
200 parameters = slength - (end + 1); //strip off main parameters
201
202 //action & texture parameter number needs to be even
203 if (IsEven(parameters) == false)
204 return ScriptError("Incorrect number of parameters");
205
206 for (int i = (end + 1); i < slength - (parameters / 2); i++)
207 action_array.emplace_back(tempdata[i]);
208 for (int i = slength - (parameters / 2); i < slength; i++)
209 tex_array.emplace_back(tempdata[i]);
210
211 //check to see if file exists
212 parent->CheckFile("data/" + tempdata[0]);
213
214 //stop here if in Check mode
215 if (config->CheckScript == true)
216 return sNextLine;
217
218 Control* control = 0;
219 control = station->GetPanel()->AddControl(tempdata[0], ToInt(tempdata[1]), ToInt(tempdata[2]), ToFloat(tempdata[3]), ToFloat(tempdata[4]), ToFloat(tempdata[5]), ToFloat(tempdata[6]), ToInt(tempdata[7]), action_array, tex_array);
220
221 if (control)
222 {
223 if (config->lockvalue == 0)
224 control->SetLocked(false, config->keyvalue);
225 else
226 control->SetLocked(true, config->keyvalue);
227 }
228 StoreCommand(control);
229 return sNextLine;
230 }
231
232 //SetPosition command
233 if (StartsWithNoCase(LineData, "setposition "))
234 {
235 //get data
236 int params = SplitData(LineData, 12);
237
238 if (params != 3)
239 return ScriptError("Incorrect number of parameters");
240
241 //check numeric values
242 for (int i = 0; i < 2; i++)
243 {
244 if (!IsNumeric(tempdata[i]))
245 return ScriptError("Invalid value: " + tempdata[i]);
246 }
247
248 Vector3 position = Vector3(ToFloat(tempdata[0]), ToFloat(tempdata[1]), ToFloat(tempdata[2]));
249 station->SetPosition(position);
250 }
251
252 //AddDisplay command
253 if (StartsWithNoCase(LineData, "addindicator"))
254 {
255 //get data
256 int params = SplitData(LineData, 13);
257
258 if (params != 10)
259 return ScriptError("Incorrect number of parameters");
260
261 //check numeric values
262 for (int i = 4; i <= 9; i++)
263 {
264 if (!IsNumeric(tempdata[i]))
265 return ScriptError("Invalid value: " + tempdata[i]);
266 }
267
268 StoreCommand(station->AddIndicator(tempdata[0], tempdata[1], tempdata[2], tempdata[3], ToFloat(tempdata[4]), ToFloat(tempdata[5]), ToFloat(tempdata[6]), ToFloat(tempdata[7]), ToFloat(tempdata[8]), ToFloat(tempdata[9])));
269 return sNextLine;
270 }
271
272 //handle end of call station section
273 if (StartsWithNoCase(LineData, "<endcallstation>") && config->RangeL == config->RangeH)
274 {
275 //return to floor section
276 config->SectionNum = 2;
282
283 if (Simcore->Verbose)
284 engine->Report("Finished call station");
285 return sNextLine;
286 }
287
288 //handle call station range
289 if (config->RangeL != config->RangeH && StartsWithNoCase(LineData, "<endcallstation"))
290 {
291 if (config->Current < config->RangeH)
292 {
293 config->Current++;
294 parent->line = config->RangeStart; //loop back
295 return sNextLine;
296 }
297 else
298 {
299 config->SectionNum = 2; //break out of loop
305 if (Simcore->Verbose)
306 engine->Report("Finished call stations");
307 return sNextLine;
308 }
309 }
310
311 return sContinue;
312}
313
314}
Control * AddControl(const std::string &sound, int row, int column, Real bwidth, Real bheight, Real hoffset, Real voffset, int selection_position, std::vector< std::string > &action_names, std::vector< std::string > &textures)
ButtonPanel * GetPanel()
std::string Name
Definition callstation.h:35
std::vector< std::string > InvalidInput
Definition callstation.h:37
void SetController(int number)
ButtonPanel * CreateButtonPanel(const std::string &texture, int rows, int columns, const std::string &direction, Real width, Real height, Real spacingX, Real spacingY, Real tw, Real th)
void SetPosition(Vector3 &position)
Indicator * AddIndicator(const std::string &sound, const std::string &texture_prefix, const std::string &blank_texture, const std::string &direction, Real CenterX, Real CenterZ, Real width, Real height, Real voffset, Real timer_duration)
CallStation * AddCallStation(int number)
Definition floor.cpp:598
CallStation * GetCallStation(int number)
Definition floor.cpp:1000
void SetLocked(bool value, int keyid)
Definition lock.cpp:37
Floor * GetFloor(int number)
Definition sbs.cpp:1739
bool Verbose
Definition sbs.h:186
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
void StoreCommand(::SBS::Object *object)
std::string Calc(const std::string &expression)
Ogre::Vector3 Vector3
Definition globals.h:58
bool StartsWithNoCase(const std::string &string, const std::string &check_string)
Definition globals.cpp:237
void ReplaceAll(std::string &string, const std::string &original, const std::string &replacement)
Definition globals.cpp:201
int ToInt(const std::string &string)
Definition globals.cpp:402
std::string ToString(int number)
Definition globals.cpp:279
Real ToFloat(const std::string &string)
Definition globals.cpp:397
bool ToBool(std::string string)
Definition globals.cpp:407
bool IsEven(int Number)
Definition globals.cpp:37
bool IsNumeric(const wxString &string)