1 #include "../../rapidxml-1.13/rapidxml.hpp" 8 #include "../Library/MD5.h" 31 return (stat(name.c_str(), &buffer) == 0);
42 if (command.
delay != 0.0f)
continue;
44 if (command.
name.substr(0, 10) ==
"Scenarios/")
51 sprintf_s(msg, 99,
"ASE:FrameMove Scenario %s loaded, step %i command 0", command.
name.substr(10).c_str(), command.
ivalue);
57 static const char alphanum[] =
59 "ABCDEFGHIJKLMNPQRTUVWXY";
60 for (i = 0; i < 6; i++)
61 randId[i] = alphanum[rand() % (
sizeof(alphanum) - 1)];
65 else if (command.
name ==
"EndScenario")
73 newcommand.
name =
"Viewport-MFD";
74 strcpy_s(newcommand.
svalue, 64,
"Nav");
78 command3.
name =
"Display-Reset";
82 command2.
name =
"Display-Event";
86 else if (command.
name ==
"ContinueScenario")
99 static float verticalStabilized = 0.0f;
101 if (pitchdiff < D3DXToRadian(2.5f))
102 verticalStabilized += fElapsedTime;
104 verticalStabilized = 0.0f;
110 static float lateralStabilized = 0.0f;
112 if (rolldiff < D3DXToRadian(5.0f))
113 lateralStabilized += fElapsedTime;
115 lateralStabilized = 0.0f;
136 if (!command.
vmu.empty())
147 if (command.
voice == 0)
148 path =
"Scenarios/Audio/" +
md5(command.
vmu) +
".mp3";
153 path =
"Scenarios/Audio/" + std::to_string(command.
voice) +
"/" +
md5(cs) +
".mp3";
162 else if (!command.
name.empty())
164 if (command.
name ==
"ModulateOccupantControlAuthority")
168 sprintf_s(msg, 99,
"ASE:FrameMove Handling command: %s", command.
name.c_str());
171 else if (command.
name ==
"SetOccupantControlAuthority")
175 sprintf_s(msg, 99,
"ASE:FrameMove Handling command: %s", command.
name.c_str());
186 sprintf_s(msg, 99,
"ASE:FrameMove Dispatching command: %s", command.
name.c_str());
191 else if (!command.
help.empty())
194 if (command.
help ==
"Clear")
198 else if (command.
help ==
"Highlight")
202 else if (command.
help ==
"Dim")
208 else if (!command.
wait.empty())
211 bool conditionMet =
false;
217 if (busCommand.
delay != 0.0f)
continue;
219 if (command.
wait ==
"BothPilotsPressedTrigger" && busCommand.
name ==
"JoystickTrigger")
226 else if (command.
wait ==
"EitherPilotPressedTrigger" && busCommand.
name ==
"JoystickTrigger")
233 if (command.
wait ==
"StabilizedFlight" && lateralStabilized >= 10.0f && verticalStabilized >= 10.0f)
240 D3DXVECTOR2 diff2 = D3DXVECTOR2(diff3.x, diff3.y);
241 float dist = D3DXVec2Length(&diff2);
242 if (dist <= command.
fvalue)
245 else if (command.
wait ==
"ThrustSetting")
273 else if (!command.
jump.empty())
295 logger->
Log(
"ASE::AdvanceToNextStep Scenario completed!");
305 sprintf_s(msg, 99,
"ASE:AdvanceToNextStep Scenario step %i command %i",
currentStep,
subStep);
310 size_t write_data(
void* ptr,
size_t size,
size_t nmemb, FILE* stream)
312 size_t written = fwrite(ptr, size, nmemb, stream);
318 CURL* curl = curl_easy_init();
322 if (fopen_s(&fp, outputPath.c_str(),
"wb") != 0)
331 std::string encodedRead = curl_easy_escape(curl, read.c_str(), read.length());
332 std::string url =
"http://www.vocalware.com/tts/gen.php?EID=" + voice.
eid +
"&LID=" + voice.
lid +
"&VID=" + voice.
vid +
"&TXT=" + encodedRead +
"&FX_TYPE=" + voice.
fxtype +
"&FX_LEVEL=" + voice.
fxlevel;
335 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
336 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_data);
337 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
338 curl_easy_perform(curl);
339 curl_easy_cleanup(curl);
354 if (path.length() == 0)
361 _sopen_s(&configFile, path.c_str(), _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, SH_DENYWR, S_IREAD);
362 if (configFile == -1)
365 sprintf_s(msg, 99,
"Ase::LoadScenario could not open file: %S", path.c_str());
371 int fileLength = _filelength(configFile);
372 char* buffer =
new char[fileLength + 1];
373 _read(configFile, buffer, fileLength);
375 buffer[fileLength] = 0;
377 using namespace rapidxml;
379 doc.parse<0>(buffer);
381 xml_node<>* scenario = doc.first_node(
"Scenario");
383 for (xml_node<>* stepNode = scenario->first_node(); stepNode; stepNode = stepNode->next_sibling())
385 if (_strcmpi(stepNode->name(),
"Step") != 0)
continue;
389 xml_attribute<>* name = stepNode->first_attribute(
"name");
390 if (name->value()) step.
name = name->value();
392 for (xml_node<>* node = stepNode->first_node(); node; node = node->next_sibling())
396 xml_attribute<>* commandName = node->first_attribute(
"name");
397 if (commandName) command.
name = commandName->value();
398 xml_attribute<>* svalue = node->first_attribute(
"svalue");
400 strcpy_s(command.
svalue, 64, svalue->value());
401 xml_attribute<>* ivalue = node->first_attribute(
"ivalue");
403 command.
ivalue = atoi(ivalue->value());
404 xml_attribute<>* fvalue = node->first_attribute(
"fvalue");
406 command.
fvalue =
static_cast<float>(atof(fvalue->value()));
407 xml_attribute<>* bvalue = node->first_attribute(
"bvalue");
409 command.
bvalue = atoi(bvalue->value()) == 1;
410 xml_attribute<>* vmu = node->first_attribute(
"vmu");
411 if (vmu) command.
vmu = vmu->value();
412 xml_attribute<>* voice = node->first_attribute(
"voice");
413 if (voice) command.
voice = atoi(voice->value());
414 xml_attribute<>* wait = node->first_attribute(
"wait");
415 if (wait) command.
wait = wait->value();
416 xml_attribute<>* timeout = node->first_attribute(
"timeout");
417 if (timeout) command.
timeout =
static_cast<float>(atof(timeout->value()));
419 xml_attribute<>* timeoutStep = node->first_attribute(
"timeoutStep");
420 if (timeoutStep) command.
timeoutStep = timeoutStep->value();
421 xml_attribute<>* jump = node->first_attribute(
"jump");
422 if (jump) command.
jump = jump->value();
423 xml_attribute<>* help = node->first_attribute(
"help");
424 if (help) command.
help = help->value();
425 xml_attribute<>* element = node->first_attribute(
"element");
426 if (element) command.
element = element->value();
432 steps.push_back(step);
450 butch.
FixId =
"BUTCH";
451 butch.
type = Waypoint::WaypointType::FlyoverFix;
458 cssdy.
FixId =
"CASDY";
459 cssdy.
type = Waypoint::WaypointType::FinalApproachFix;
468 e419.
type = Waypoint::WaypointType::TouchdownZone;
476 for (UINT i = 0; i <
steps.size(); i++)
478 if (
steps.at(i).name == stepName)
float EngineThrustCommand[enginesC]
(57) Thrust command (when an information source is installed);
float occupantControlAuthority
bool FileExists(const std::string name)
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
Callback function for CURL.
float occupantPitchControlAuthority
float occupantRollControlAuthority
std::vector< Command > commandStream
bool GenerateTextToSpeech(std::string url, UINT voice, std::string outputPath)
UINT FindStep(std::string stepName)
std::vector< SCommand > commands
std::vector< Vehicle > vehicles
for TCAS, GPWS, FMS
std::vector< Waypoint > waypoints
float PitchAttitude
(6) Pitch attitude;
std::string name
command name
Ase(Bus *prmBus, Logger *prmLogger, int prmSoundDevice, SVocalware vocalware)
float RollAttitude
(7) Roll attitude;
std::vector< SVoice > voices
D3DXVECTOR3 relativeLocation
Abstract base class for modules By definition, instruments don't do any of the work (they don't modif...
void FrameMove(float fElapsedTime) override
HSTREAM PlayStream(std::string filename) const
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
std::string receiptNumber
bool StreamIsPlaying(HSTREAM streamHandle) const
void Initialize(Devices::Bass *prmBass)
void AddHighlight(std::string elementName)
float delay
wait number of seconds before executing command
std::vector< SStep > steps
void LoadScenario(std::string path)
std::string md5(const std::string str)
void RemoveHighlight(std::string elementName)