Skyscraper
2.0
src
script
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
30
using namespace
SBS
;
31
32
namespace
Skyscraper
{
33
34
ScriptProcessor::ControllerSection::ControllerSection
(
ScriptProcessor
*parent) :
Section
(parent)
35
{
36
37
}
38
39
int
ScriptProcessor::ControllerSection::Run
(std::string &
LineData
)
40
{
41
//Process controllers
42
43
//create vehicle if not created already
44
Simcore
->
NewController
(
config
->
Current
);
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
66
DispatchController
*c =
Simcore
->
GetController
(
config
->
Current
);
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
}
SBS::DispatchController
Definition
controller.h:30
SBS::DispatchController::AddElevator
bool AddElevator(int elevator)
Definition
controller.cpp:589
SBS::DispatchController::Range
int Range
Definition
controller.h:37
SBS::DispatchController::Name
std::string Name
Definition
controller.h:34
SBS::DispatchController::Hybrid
bool Hybrid
Definition
controller.h:36
SBS::DispatchController::DestinationDispatch
bool DestinationDispatch
Definition
controller.h:35
SBS::DispatchController::Reprocess
bool Reprocess
Definition
controller.h:39
SBS::DispatchController::MaxPassengers
int MaxPassengers
Definition
controller.h:38
SBS::SBS::GetController
DispatchController * GetController(int number)
Definition
sbs.cpp:1774
SBS::SBS::NewController
DispatchController * NewController(int number)
Definition
sbs.cpp:1696
Skyscraper::EngineContext::Report
void Report(const std::string &message)
Definition
enginecontext.cpp:500
Skyscraper::ScriptProcessor::ConfigHandler::Context
std::string Context
Definition
section.h:81
Skyscraper::ScriptProcessor::ConfigHandler::RangeL
int RangeL
Definition
section.h:76
Skyscraper::ScriptProcessor::ConfigHandler::SectionNum
int SectionNum
Definition
section.h:80
Skyscraper::ScriptProcessor::ConfigHandler::RangeH
int RangeH
Definition
section.h:77
Skyscraper::ScriptProcessor::ConfigHandler::Current
int Current
Definition
section.h:79
Skyscraper::ScriptProcessor::ConfigHandler::RangeStart
long RangeStart
Definition
section.h:78
Skyscraper::ScriptProcessor::ControllerSection::ControllerSection
ControllerSection(ScriptProcessor *parent)
Definition
controllers.cpp:34
Skyscraper::ScriptProcessor::ControllerSection::Run
int Run(std::string &LineData)
Definition
controllers.cpp:39
Skyscraper::ScriptProcessor::Section
Definition
section.h:29
Skyscraper::ScriptProcessor
Definition
scriptproc.h:31
Skyscraper::ScriptProcessor::sNextLine
static const int sNextLine
Definition
scriptproc.h:70
Skyscraper::ScriptProcessor::sContinue
static const int sContinue
Definition
scriptproc.h:69
Skyscraper::ScriptProcessor::config
ConfigHandler * config
Definition
scriptproc.h:98
Skyscraper::ScriptProcessor::sError
static const int sError
Definition
scriptproc.h:71
Skyscraper::ScriptProcessor::ScriptError
int ScriptError()
Definition
scriptproc.cpp:648
Skyscraper::ScriptProcessor::LineData
std::string LineData
Definition
scriptproc.h:90
Skyscraper::ScriptProcessor::engine
EngineContext * engine
Definition
scriptproc.h:96
Skyscraper::ScriptProcessor::Calc
std::string Calc(const std::string &expression)
Definition
scriptproc.cpp:665
Skyscraper::ScriptProcessor::Simcore
::SBS::SBS * Simcore
Definition
scriptproc.h:95
Skyscraper::ScriptProcessor::line
int line
Definition
scriptproc.h:89
controller.h
enginecontext.h
globals.h
SBS
Definition
skyscraper.h:45
SBS::StartsWithNoCase
bool StartsWithNoCase(const std::string &string, const std::string &check_string)
Definition
globals.cpp:237
SBS::ReplaceAll
void ReplaceAll(std::string &string, const std::string &original, const std::string &replacement)
Definition
globals.cpp:201
SBS::ToString
std::string ToString(int number)
Definition
globals.cpp:279
SBS::ToBool
bool ToBool(std::string string)
Definition
globals.cpp:407
Skyscraper
Definition
native.cpp:50
Skyscraper::IsNumeric
bool IsNumeric(const wxString &string)
Definition
debugpanel.cpp:784
sbs.h
scriptproc.h
section.h
Generated by
1.11.0