-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.cpp
More file actions
359 lines (338 loc) · 11.7 KB
/
Copy pathconsole.cpp
File metadata and controls
359 lines (338 loc) · 11.7 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#include "modifier.h"
#include "trigger.h"
#include "db_object.h"
#include "localization.h"
#include "utils/parser_util.h"
#include "national_idea.h"
#include "effect.h"
#include "paradox_macro.h"
#include "pattern.h"
#include <iostream>
#include <map>
#include <bitset>
#include <sstream>
#include <chrono>
#include <memory>
//
typedef void(*CommandHandler)(std::vector<std::string>);
std::map<std::string,CommandHandler> handlers;
extern std::set<std::string> shortStringSet;
extern std::set<std::string> registeredTriggers;
void printModifier(std::vector<std::string> vec){
ParadoxTag* root = parseFile(vec[0]);
std::vector<Modifier> modifiers;
ParseModifier(root,modifiers);
for(int i = 0;i < modifiers.size();i++){
std::cout << modifiers[i].localize();
std::cout << std::endl;
std::cout << std::endl;
}
clearParserDatas();
}
void printModifierHtml(std::vector<std::string> vec){
ParadoxTag* root = parseFile(vec[0]);
std::vector<Modifier> modifiers;
ParseModifier(root,modifiers);
for(int i = 0;i < modifiers.size();i++){
std::cout << modifiers[i].localizeHtml();
std::cout << std::endl;
std::cout << std::endl;
}
clearParserDatas();
}
void printEffect(std::vector<std::string> vec){
ParadoxTag* root = parseFile(vec[0]);
std::unique_ptr<ComplexEffect> effect = createBaseEffect();
parseEffect(root,effect.get());
std::cout << effect->toString() << std::endl;
}
void printTrigger(std::vector<std::string> vec){
bool multiTriggers = false;
ParadoxTag* root = parseFile(vec[0]);
if(root == nullptr) return;
ComplexTrigger* ct = createBaseTrigger();
ct->depth = 0;
parseTrigger(root,ct);
std::cout << ct->toString(false) << std::endl;
delete ct;
clearParserDatas();
}
void runBench(std::vector<std::string> vec){
auto start = std::chrono::system_clock::now();
ParadoxTag* root = parseFile("./bench.txt");
auto end = std::chrono::system_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "====== node parse phase ======" << std::endl;
std::cout << "parsed node count: " << root->getAsTag(0)->size() + root->getAsTag(1)->size() + 2 << std::endl;
std::cout << "time consumed: " << duration.count() << " microseconds" << std::endl;
std::cout << "time per node: " << duration.count() / (1.0 * root->getAsTag(0)->size() + 1) << " mircoseconds" << std::endl;
start = std::chrono::system_clock::now();
ComplexTrigger* ct = createBaseTrigger();
parseTrigger(root->getAsTag(0),ct);
end = std::chrono::system_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "====== trigger create phase ======" << std::endl;
std::cout << "parsed node count: " << root->getAsTag(0)->size() + 1 << std::endl;
std::cout << "time consumed: " << duration.count() << " microseconds" << std::endl;
std::cout << "time per node: " << duration.count() / (1.0 * root->getAsTag(0)->size() + 1) << " mircoseconds" << std::endl;
start = std::chrono::system_clock::now();
Modifier modifiers;
ParseModifier(root->getAsTag(1),modifiers);
end = std::chrono::system_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "====== modifier create phase ======" << std::endl;
std::cout << "parsed node count: " << root->getAsTag(0)->size() + 1 << std::endl;
std::cout << "time consumed: " << duration.count() << " microseconds" << std::endl;
std::cout << "time per node: " << duration.count() / (1.0 * root->getAsTag(0)->size() + 1) << " mircoseconds" << std::endl;
clearParserDatas();
delete ct;
}
int main(){
using namespace std;
auto start = std::chrono::system_clock::now();
registerInternalScopes();
std::thread& th = readLocalizations();
loadInternalModifier();
registerGood();
log_info(current_location(),"Modifier Loaded!");
registerTriggerItems();
log_info(current_location(),"Trigger Loaded!");
loadScriptedTrigger();
log_info(current_location(),"Scripted Trigger Phase 1 Loaded!");
registerEffectItems();
log_info(current_location(),"Effect Loaded!");
loadNationalIdea();
log_info(current_location(),"Ni Loaded!");
th.join();
loadScriptedTrigger_POST();
log_info(current_location(),"Scripted Trigger Phase 2 Loaded!");
auto end = std::chrono::system_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
log_info(current_location(),"Load Completed! ",duration.count(), " us consumed.");
handlers["credits"] = [](std::vector<std::string> vec){
std::cout << "Paradox Data Parser \nV0.4.0-20260711\nAuthor: Mordd";
};
handlers["future_plan"] = [](std::vector<std::string> vec){
std::cout << "4 / 5 Implement Scripted Trigger" << std::endl;
std::cout << registeredTriggers.size() << " / 898 Internal Triggers" << std::endl;
std::cout << "TODO Implement Scripted Effect" << std::endl;
std::cout << "TODO Event Parser" << std::endl;
};
handlers["print_modifier"] = printModifier;
handlers["print_modifier_html"] = printModifierHtml;
handlers["debug_print"] = [](std::vector<std::string> vec){
if(vec.size() != 0){
if(vec[0] == "named_pattern_test") {
NamedPattern np("Hello,%{name}!");
np.fillName("name","mordd");
std::cout << np.getOutput() << std::endl;
np = NamedPattern("The IQ of Khet is %{IQ}");
np.fillName("IQ",40000);
std::cout << np.getOutput() << std::endl;
np = NamedPattern("Oops,The IQ of Khet is %{IQ:percent} now!");
np.fillName("IQ",399);
std::cout << np.getOutput() << std::endl;
np = NamedPattern("What Khet will do:\n%{KhetAction:effect_literal}");
np.fillName("KhetAction","add_treasury = -300");
std::cout << np.getOutput();
np = NamedPattern("The Trigger of Khet being dumb:\n%{KhetCondition:trigger_literal}");
np.fillName("KhetCondition","always = no");
std::cout << np.getOutput();
np = NamedPattern("Scope Test:%{lorent:scope},%{far_island:scope}");
np.fillName("lorent","A01");
np.fillName("far_island",1);
std::cout << np.getOutput();
}
}
else {
std::cout << shortStringSet.size() << '/' << shortStringSet.max_size() << std::endl;
}
};
handlers["print_trigger"] = printTrigger;
handlers["print_effect"] = printEffect;
handlers["run_bench"] = runBench;
handlers["trade_good"] = [](std::vector<std::string> vec){
if(vec.empty()){
std::cout << "用法:trade_good <good_id>" << std::endl;
return;
}
Good* good = getGood(vec[0]);
if(good == nullptr){
std::cout << "没有名为" << vec[0] << "的商品" << std::endl;
return;
}
std::cout << getLocalization(*good->localizedNamePtr) << std::endl;
good->provinceModifier->localize();
std::cout << "基础价格:" << good->defaultPrice / 1000.0 << std::endl;
std::cout << good->globalModifier->localize();
std::cout << good->provinceModifier->localize();
};
handlers["goods_list"] = [](std::vector<std::string> vec){
std::map<std::string,std::string> map1;
listGoods(map1);
for(auto it : map1){
std::cout << it.first << " " << it.second << std::endl;
}
};
handlers["tag_idea"] = [](std::vector<std::string> vec){
if(vec.empty()){
std::cout << "用法:tag_idea <tag>" << std::endl;
return;
}
const NationalIdea* idea = getTagIdea(vec[0]);
if(idea == nullptr){
std::cout << "没有找到" << vec[0] << "的国家理念" << std::endl;
return;
}
std::cout << idea->toString() << std::endl;
};
handlers["ideas"] = [](std::vector<std::string> vec){
if(vec.empty()){
std::cout << "用法:ideas <tag>" << std::endl;
return;
}
const NationalIdea* idea = getFromName(vec[0]);
if(idea == nullptr){
std::cout << "没有找到" << vec[0] << "的国家理念" << std::endl;
return;
}
std::cout << idea->toString() << std::endl;
};
handlers["tag_idea_text"] = [](std::vector<std::string> vec){
if(vec.empty()){
std::cout << "用法:tag_idea_text <tag>" << std::endl;
return;
}
const NationalIdea* idea = getTagIdea(vec[0]);
if(idea == nullptr){
std::cout << "没有找到" << vec[0] << "的国家理念" << std::endl;
return;
}
for(int i = 0;i < 7;i++){
std::cout << getLocalization(*idea->modifiers[i]->name) << std::endl;
std::cout << getLocalization(*idea->modifiers[i]->name + "_desc") << std::endl;
if(i != 6) std::cout << "=========" << std::endl;
}
};
handlers["reload_loc"] = [](std::vector<std::string> vec){
readLocalizations();
};
handlers["extract_mission"] = [](std::vector<std::string> vec){
if(vec.empty()){
std::cout << "usage: extract_mission <mission_file_name>";
return;
}
ParadoxTag* root = parseFile(vec[0]);
for(std::string str : root->seq){
ParadoxTag* tag = root->getAsTag(str);
if(tag == nullptr) continue;
for(std::string str1: tag->seq){
if(tag->get(str1)->getType() != ParadoxType::TAG) continue;
std::cout << str1 << std::endl;
}
}
};
handlers["read_head"] = [](std::vector<std::string> vec){
if(vec.empty()){
std::cout << "usage: extract_mission <mission_file_name>";
return;
}
ParadoxTag* root = parseFile(vec[0]);
for(std::string str : root->seq){
std::cout << str << std::endl;
}
};
/*
handlers["freespace"] = [](std::vector<std::string> vec){
std::bitset<2600> tag1;
for(int i = 0;i < 2600;i++) tag1.set(i,true);
ParadoxTag* tag = parseFile("./datas/tags.txt")->getAsTag("tags");
for(std::string str :tag->seq){
if(str[1] >= '0' && str[1] <= '9' && str[2] >= '0' && str[2] <= '9'){
int index = (str[0] - 'A') * 100;
index += (str[1] - '0') * 10;
index += (str[2] - '0');
tag1.set(index,false);
}
}
for(int i = 200;i <= 275;i++) tag1.set(i,false);
for(int i = 300;i <= 375;i++) tag1.set(i,false);
for(int i = 400;i <= 450;i++) tag1.set(i,false);
for(int i = 500;i <= 520;i++) tag1.set(i,false);
for(int i = 1000;i <= 1099;i++) tag1.set(i,false);
for(int i = 1400;i <= 1410;i++) tag1.set(i,false);
for(int i = 1800;i <= 1810;i++) tag1.set(i,false);
for(int i = 1900;i <= 1975;i++) tag1.set(i,false);
int start = -1;
for(int i = 0;i < 26;i++){
char t = ('A'+ i);
for(int j = 0;j < 100;j++){
if(tag1[i * 100 + j] && start == -1){
start = j;
}
else if(start != -1 && !tag1[i * 100 + j]){
if(start == j - 1) std::cout << t << start << std::endl;
else {
std::cout << t << start << "-" << t << j - 1 << std::endl;
}
start = -1;
}
}
if(start != -1){
if(start == 99) std::cout << t << start << std::endl;
else {
std::cout << t << start << "-" << t << 99 << std::endl;
}
start = -1;
}
}
};
*/
string command,command1;
vector<string> args;
while(true){
getline(cin,command);
if(command.length() == 0) continue;
stringstream ss;
ss << command;
string command1;
string command2 = "";
ss >> command >> command1;
bool shouldMerge = command1[0] == '\"';
bool broke = false;
if(command1 == "\x0f\x03\x17") break;
while(command1.length() != 0){
if(!shouldMerge){
args.push_back(command1);
command1 = "";
ss >> command1;
}
else {
ss >> command2;
if(command1[command1.length() - 1] == '\"') {
shouldMerge = false;
command1 = command1.substr(1,command1.length() - 2);
command2 = "";
continue;
}
command1.append(" ");
command1.append(command2);
if(command2.length() == 0) {
cout << "ERROR:Incomplete Quotation!" << endl;
broke = true;
break;
}
command2 = "";
}
}
if(broke) {
args.clear();
cout << endl;
continue;
}
if(handlers.find(command) == handlers.end()) cout << "Command Not Found." << endl;
else handlers[command](args);
args.clear();
cout << endl;
}
}