1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#include "Component.h"
#include "string/convert.h"
#include "string/case_conv.h"
#include "string/replace.h"
namespace objectives {
std::string Component::getString() {
// This will hold our return value
std::string sentence;
int componentId = _type.getId();
if (isInverted()) {
sentence += "do NOT ";
}
SpecifierPtr sp1 = getSpecifier(Specifier::FIRST_SPECIFIER);
SpecifierPtr sp2 = getSpecifier(Specifier::SECOND_SPECIFIER);
if (componentId == ComponentType::COMP_KILL().getId()) {
// First add the verb
sentence += "kill";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_KO().getId()) {
// First add the verb
sentence += "knockout";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_AI_FIND_ITEM().getId()) {
// First add the verb
sentence += "let AI find item:";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_AI_FIND_BODY().getId()) {
sentence += "let AI find body:";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
sentence += " (amount: " + getArgument(0) + ")";
}
else if (componentId == ComponentType::COMP_ALERT().getId()) {
sentence += "alert";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
// Add the alert level info
sentence += " " + getArgument(0) + " times to a minimum alert level of " + getArgument(1);
}
else if (componentId == ComponentType::COMP_DESTROY().getId()) {
sentence += "destroy";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_ITEM().getId()) {
sentence += "acquire";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_PICKPOCKET().getId()) {
sentence += "pickpocket";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_LOCATION().getId()) {
sentence += "let the target";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
sentence += " be at location";
sentence += (sp2) ? (" " + sp2->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_INFO_LOCATION().getId()) {
sentence += "let the target";
// Add the Specifier details, if any
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
sentence += " be at info_location";
sentence += (sp2) ? (" " + sp2->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_CUSTOM_ASYNC().getId()) {
sentence += "controlled by external script";
}
else if (componentId == ComponentType::COMP_CUSTOM_CLOCKED().getId()) {
sentence += "call the script function ";
sentence += getArgument(0);
}
else if (componentId == ComponentType::COMP_DISTANCE().getId()) {
sentence += "let the entities " + getArgument(0);
sentence += " and " + getArgument(1) + " get closer than ";
sentence += getArgument(2) + " units";
}
else if (componentId == ComponentType::COMP_READABLE_OPENED().getId())
{
sentence += "open the readable ";
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_READABLE_CLOSED().getId())
{
sentence += "close the readable ";
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
else if (componentId == ComponentType::COMP_READABLE_PAGE_REACHED().getId())
{
sentence += "view page " + getArgument(0) + " of readable ";
sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
}
if (getClockInterval() > 0) {
sentence += " (check interval: " + string::to_string(getClockInterval()) + " seconds)";
}
// Convert the first character of the sentence to upper case
if (!sentence.empty()) {
std::string c(sentence.begin(), sentence.begin()+1);
sentence[0] = string::to_upper_copy(c)[0];
// Append a full stop at the end of the sentence
if (sentence[sentence.length() - 1] != '.') {
sentence.append(".");
}
}
// Replace all double-space characters with one single space
string::replace_all(sentence, " ", " ");
return sentence;
}
} // namespace objectives
|