Skyscraper 2.0
controllers.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Script Processor - Controller 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 "controller.h"
27#include "scriptproc.h"
28#include "section.h"
29
30using namespace SBS;
31
32namespace Skyscraper {
33
38
40{
41 //Process controllers
42
43 //create vehicle if not created already
45
46 //replace variables with actual values
47 ReplaceAll(LineData, "%controller%", ToString(config->Current));
48
49 //IF/While statement stub (continue to global commands for processing)
50 if (StartsWithNoCase(LineData, "if") || StartsWithNoCase(LineData, "while"))
51 return sContinue;
52
53 //process math functions
54 if (MathFunctions(LineData) == sError)
55 return sError;
56
57 //process functions
58 if (parent->FunctionProc() == true)
59 return sNextLine;
60
61 //get text after equal sign
62 bool equals;
63 std::string value = GetAfterEquals(LineData, equals);
64
65 //get controller object
67
68 //parameters
69
70 //Name parameter
71 if (StartsWithNoCase(LineData, "name"))
72 {
73 if (equals == false)
74 return ScriptError("Syntax error");
75 c->Name = value;
76 return sNextLine;
77 }
78 //DestinationDispatch parameter
79 if (StartsWithNoCase(LineData, "destinationdispatch"))
80 {
81 if (equals == false)
82 return ScriptError("Syntax error");
83
84 c->DestinationDispatch = ToBool(value);
85 return sNextLine;
86 }
87 //Hybrid parameter
88 if (StartsWithNoCase(LineData, "hybrid"))
89 {
90 if (equals == false)
91 return ScriptError("Syntax error");
92
93 c->Hybrid = ToBool(value);
94 return sNextLine;
95 }
96 //Range parameter
97 if (StartsWithNoCase(LineData, "range"))
98 {
99 if (equals == false)
100 return ScriptError("Syntax error");
101 std::string str = Calc(value);
102 if (!IsNumeric(str, c->Range))
103 return ScriptError("Invalid value");
104 return sNextLine;
105 }
106 //MaxPassengers parameter
107 if (StartsWithNoCase(LineData, "maxpassengers"))
108 {
109 if (equals == false)
110 return ScriptError("Syntax error");
111 std::string str = Calc(value);
112 if (!IsNumeric(str, c->MaxPassengers))
113 return ScriptError("Invalid value");
114 return sNextLine;
115 }
116 //Elevators parameter
117 if (StartsWithNoCase(LineData, "elevators"))
118 {
119 //copy string listing of elevators into array
120 int params = SplitAfterEquals(LineData, false);
121 if (params < 1)
122 return ScriptError("Syntax Error");
123
124 for (int line = 0; line < params; line++)
125 {
126 int start, end;
127 if (GetRange(tempdata[line], start, end))
128 {
129 for (int k = start; k <= end; k++)
130 {
131 if (!c->AddElevator(k))
132 return ScriptError();
133 }
134 }
135 else
136 {
137 std::string str = Calc(tempdata[line]);
138 int data;
139 if (!IsNumeric(str, data))
140 return ScriptError("Invalid value");
141 if (!c->AddElevator(data))
142 return ScriptError();
143 }
144 }
145 return sNextLine;
146 }
147 //Reprocess parameter
148 if (StartsWithNoCase(LineData, "reprocess"))
149 {
150 if (equals == false)
151 return ScriptError("Syntax error");
152
153 c->Reprocess = ToBool(value);
154 return sNextLine;
155 }
156
157 //handle end of controller section
158 if (StartsWithNoCase(LineData, "<endcontroller>") && config->RangeL == config->RangeH)
159 {
160 config->SectionNum = 0;
161 config->Context = "None";
162 engine->Report("Finished controller");
163 return sNextLine;
164 }
165
166 //handle controller range
167 if (config->RangeL != config->RangeH && StartsWithNoCase(LineData, "<endcontroller"))
168 {
169 if (config->Current < config->RangeH)
170 {
171 config->Current++;
172 parent->line = config->RangeStart; //loop back
173 return sNextLine;
174 }
175 else
176 {
177 config->SectionNum = 0; //break out of loop
178 config->Context = "None";
179 config->RangeL = 0;
180 config->RangeH = 0;
181 engine->Report("Finished controllers");
182 return sNextLine;
183 }
184 }
185
186 return sContinue;
187}
188
189}
bool AddElevator(int elevator)
DispatchController * GetController(int number)
Definition sbs.cpp:1774
DispatchController * NewController(int number)
Definition sbs.cpp:1696
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
std::string Calc(const std::string &expression)
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
std::string ToString(int number)
Definition globals.cpp:279
bool ToBool(std::string string)
Definition globals.cpp:407
bool IsNumeric(const wxString &string)