Debian Codegraph @

plugins/dm.objectives/Component.cpp

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