-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathMain.cpp
More file actions
3304 lines (2881 loc) · 89.7 KB
/
Copy pathMain.cpp
File metadata and controls
3304 lines (2881 loc) · 89.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Base Plugin for FLHook-Plugin
by Cannon.
0.1:
Initial release
*/
// includes
#include <FLHook.h>
#include <plugin.h>
#include <PluginUtilities.h>
#include "Main.h"
#include <sstream>
#include <hookext_exports.h>
// Clients
unordered_map<uint, CLIENT_DATA> clients;
// Bases
unordered_map<uint, PlayerBase*> player_bases;
unordered_map<uint, PlayerBase*>::iterator baseSaveIterator = player_bases.begin();
/// 0 = HTML, 1 = JSON, 2 = Both
int ExportType = 0;
/// The debug mode
int set_plugin_debug = 0;
/// List of banned systems
unordered_set<uint> bannedSystemList;
/// The ship used to construct and upgrade bases
uint set_construction_shiparch = 0;
/// Mininmum distances for base deployment
bool enableDistanceCheck = false;
float minMiningDistance = 30000;
float minPlanetDistance = 2500;
float minStationDistance = 10000;
float minLaneDistance = 5000;
float minJumpDistance = 15000;
float minDistanceMisc = 2500;
float minOtherPOBDistance = 5000;
unordered_set<uint> lowTierMiningCommoditiesSet;
/// Deployment command cooldown trackimg
unordered_map<uint, uint> deploymentCooldownMap;
uint deploymentCooldownDuration = 60;
/// Map of good to quantity for items required by construction ship
map<uint, uint> construction_items;
/// Construction cost in credits
int construction_credit_cost = 0;
/// list of items and quantity used to repair 10000 units of damage
vector<REPAIR_ITEM> set_base_repair_items;
/// list of items used by human crew
vector<uint> set_base_crew_consumption_items;
vector<uint> set_base_crew_food_items;
uint set_crew_check_frequency = 60 * 60 * 12; // 12 hours
/// The commodity used as crew for the base
uint set_base_crew_type;
unordered_set<uint> humanCargoList;
/// A return code to indicate to FLHook if we want the hook processing to continue.
PLUGIN_RETURNCODE returncode;
/// Global recipe map
unordered_map<uint, RECIPE> recipeMap;
/// Maps of shortcut numbers to recipes to construct item.
unordered_map<wstring, map<uint, RECIPE>> recipeCraftTypeNumberMap;
unordered_map<wstring, map<wstring, RECIPE>> recipeCraftTypeNameMap;
unordered_map<uint, vector<wstring>> factoryNicknameToCraftTypeMap;
unordered_map<wstring, RECIPE> moduleNameRecipeMap;
unordered_map<wstring, map<uint, RECIPE>> craftListNumberModuleMap;
unordered_set<wstring> buildingCraftLists;
void AddFactoryRecipeToMaps(const RECIPE& recipe);
void AddModuleRecipeToMaps(const RECIPE& recipe, const vector<wstring> craft_types, const wstring& build_type, uint recipe_number);
/// Map of space obj IDs to base modules to speed up damage algorithms.
unordered_map<uint, Module*> spaceobj_modules;
/// Map of core upgrade recipes
unordered_map<uint, uint> core_upgrade_recipes;
/// Path to shield status html page
string set_status_path_html;
/// same thing but for json
string set_status_path_json;
/// Damage to the base every tick
uint set_damage_per_tick = 600;
/// Additional damage penalty for stations without proper crew
float no_crew_damage_multiplier = 1;
// The seconds per damage tick
uint set_damage_tick_time = 16;
// The seconds per tick
uint set_tick_time = 16;
// How much damage do we heal per repair cycle?
uint repair_per_repair_cycle = 60000;
// set of configurable variables defining the diminishing returns on damage during POB siege
// POB starts at base_shield_strength, then every 'threshold' of damage taken,
// shield goes up in absorption by the 'increment'
// threshold size is to be configured per core level.
unordered_map<int, float> shield_reinforcement_threshold_map;
float shield_reinforcement_increment = 0.0f;
float base_shield_strength = 0.97f;
int vulnerability_window_length = 120; // 2 hours
int vulnerability_window_change_cooldown = 3600 * 24 * 30; // 30 days
int vulnerability_window_minimal_spread = 60 * 8; // 8 hours
bool single_vulnerability_window = false;
const uint shield_fuse = CreateID("player_base_shield");
/// List of commodities forbidden to store on POBs
unordered_set<uint> forbidden_player_base_commodity_set;
// If true, use the new solar based defense platform spawn
bool set_new_spawn = true;
/// True if the settings should be reloaded
bool load_settings_required = true;
/// holiday mode
bool set_holiday_mode = false;
//pob sounds struct
POBSOUNDS pbsounds;
//archtype structure
unordered_map<string, ARCHTYPE_STRUCT> mapArchs;
//commodities to watch for logging
map<uint, wstring> listCommodities;
//the hostility and weapon platform activation from damage caused by one player
float damage_threshold = 400000;
//the amount of damage necessary to deal to one base in order to trigger siege status
float siege_mode_damage_trigger_level = 8000000;
//the distance between bases to share siege mod activation
float siege_mode_chain_reaction_trigger_distance = 8000;
unordered_set<uint> customSolarList;
//siege weaponry definitions
unordered_map<uint, float> siegeWeaponryMap;
uint GetAffliationFromClient(uint client)
{
int rep;
pub::Player::GetRep(client, rep);
uint affiliation;
Reputation::Vibe::Verify(rep);
Reputation::Vibe::GetAffiliation(rep, affiliation, false);
return affiliation;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
PlayerBase *GetPlayerBase(uint base)
{
const auto& i = player_bases.find(base);
if (i != player_bases.end())
{
return i->second;
}
return nullptr;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
PlayerBase *GetPlayerBaseForClient(uint client)
{
auto& j = clients.find(client);
if (j == clients.end())
{
return nullptr;
}
auto i = player_bases.find(j->second.player_base);
if (i == player_bases.end())
{
return nullptr;
}
return i->second;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
PlayerBase *GetLastPlayerBaseForClient(uint client)
{
auto& j = clients.find(client);
if (j == clients.end())
{
return nullptr;
}
auto& i = player_bases.find(j->second.last_player_base);
if (i == player_bases.end())
{
return nullptr;
}
return i->second;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Logging(const char *szString, ...)
{
char szBufString[1024];
va_list marker;
va_start(marker, szString);
_vsnprintf(szBufString, sizeof(szBufString) - 1, szString, marker);
char szBuf[64];
time_t tNow = time(0);
struct tm *t = localtime(&tNow);
strftime(szBuf, sizeof(szBuf), "%d/%m/%Y %H:%M:%S", t);
FILE *Logfile = fopen(("./flhook_logs/flhook_cheaters.log"), "at");
if (Logfile)
{
fprintf(Logfile, "%s %s\n", szBuf, szBufString);
fflush(Logfile);
fclose(Logfile);
}
}
// These logging functions need consolidating.
void BaseLogging(const char *szString, ...)
{
char szBufString[1024];
va_list marker;
va_start(marker, szString);
_vsnprintf(szBufString, sizeof(szBufString) - 1, szString, marker);
char szBuf[64];
time_t tNow = time(0);
struct tm *t = localtime(&tNow);
strftime(szBuf, sizeof(szBuf), "%d/%m/%Y %H:%M:%S", t);
FILE *BaseLogfile = fopen("./flhook_logs/playerbase_events.log", "at");
if (BaseLogfile)
{
fprintf(BaseLogfile, "%s %s\n", szBuf, szBufString);
fflush(BaseLogfile);
fclose(BaseLogfile);
}
}
void RespawnBase(PlayerBase* base)
{
string filepath = base->path;
player_bases.erase(base->base);
delete base;
base = nullptr;
PlayerBase* newBase = new PlayerBase(filepath);
player_bases[newBase->base] = newBase;
newBase->Spawn();
}
FILE *LogfileEventCommodities = fopen("./flhook_logs/event_pobsales.log", "at");
void LoggingEventCommodity(const char *szString, ...)
{
char szBufString[1024];
va_list marker;
va_start(marker, szString);
_vsnprintf(szBufString, sizeof(szBufString) - 1, szString, marker);
char szBuf[64];
time_t tNow = time(0);
struct tm *t = localtime(&tNow);
strftime(szBuf, sizeof(szBuf), "%d/%m/%Y %H:%M:%S", t);
fprintf(LogfileEventCommodities, "%s %s\n", szBuf, szBufString);
fflush(LogfileEventCommodities);
fclose(LogfileEventCommodities);
LogfileEventCommodities = fopen("./flhook_logs/event_pobsales.log", "at");
}
void Notify_Event_Commodity_Sold(uint iClientID, string commodity, int count, string basename)
{
//internal log
wstring wscCharname = (const wchar_t*)Players.GetActiveCharacterName(iClientID);
wstring wscMsgLog = L"<%player> has sold <%units> of the event commodity <%eventname> to the POB <%pob>";
wscMsgLog = ReplaceStr(wscMsgLog, L"%player", wscCharname.c_str());
wscMsgLog = ReplaceStr(wscMsgLog, L"%eventname", stows(commodity).c_str());
wscMsgLog = ReplaceStr(wscMsgLog, L"%units", stows(itos(count)).c_str());
wscMsgLog = ReplaceStr(wscMsgLog, L"%pob", stows(basename).c_str());
string scText = wstos(wscMsgLog);
LoggingEventCommodity("%s", scText.c_str());
}
void LogCheater(uint client, const wstring &reason)
{
CAccount *acc = Players.FindAccountFromClientID(client);
if (!HkIsValidClientID(client) || !acc)
{
AddLog("ERROR: invalid parameter in log cheater, clientid=%u acc=%08x reason=%s", client, acc, wstos(reason).c_str());
return;
}
//internal log
string scText = wstos(reason);
Logging("%s", scText.c_str());
/*
// Set the kick timer to kick this player. We do this to break potential
// stack corruption.
HkDelayedKick(client, 1);
// Ban the account.
flstr *flStr = CreateWString(acc->wszAccID);
Players.BanAccount(*flStr, true);
FreeWString(flStr);
// Overwrite the ban file so that it contains the ban reason
wstring wscDir;
HkGetAccountDirName(acc, wscDir);
string scBanPath = scAcctPath + wstos(wscDir) + "\\banned";
FILE *file = fopen(scBanPath.c_str(), "wb");
if (file)
{
fprintf(file, "Autobanned by BasePlugin\n");
fclose(file);
}
*/
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// For the specified client setup the reputation to any bases in the
// client's system.
void SyncReputationForClientShip(uint ship, uint client)
{
int player_rep;
pub::SpaceObj::GetRep(ship, player_rep);
uint system;
pub::SpaceObj::GetSystem(ship, system);
for (auto& base : player_bases)
{
if (base.second->system == system)
{
float attitude = base.second->GetAttitudeTowardsClient(client);
if (set_plugin_debug > 1)
ConPrint(L"SyncReputationForClientShip:: ship=%u attitude=%f base=%08x\n", ship, attitude, base.first);
for (auto module : base.second->modules)
{
if (module)
{
module->SetReputation(player_rep, attitude);
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// HTML-encodes a string and returns the encoded string.
wstring HtmlEncode(wstring text)
{
wstring sb;
int len = text.size();
for (int i = 0; i < len; i++)
{
switch (text[i])
{
case L'<':
sb.append(L"<");
break;
case L'>':
sb.append(L">");
break;
case L'"':
sb.append(L""");
break;
case L'&':
sb.append(L"&");
break;
default:
if (text[i] > 159)
{
sb.append(L"&#");
sb.append(stows(itos((int)text[i])));
sb.append(L";");
}
else
{
sb.append(1, text[i]);
}
break;
}
}
return sb;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Clear client info when a client connects.
void ClearClientInfo(uint client)
{
returncode = DEFAULT_RETURNCODE;
clients.erase(client);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LoadSettings()
{
returncode = DEFAULT_RETURNCODE;
load_settings_required = true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ValidateItem(const char* goodName)
{
const GoodInfo* gi = GoodList_get()->find_by_name(goodName);
if (!gi)
{
ConPrint(L"\n\nBASE ERROR Invalid good found in config: %ls\n\n", stows((string)goodName).c_str());
}
}
/// Load the configuration
void LoadSettingsActual()
{
returncode = DEFAULT_RETURNCODE;
EquipmentUtilities::ReadIniNicknames();
// The path to the configuration file.
char szCurDir[MAX_PATH];
GetCurrentDirectory(sizeof(szCurDir), szCurDir);
string cfg_file = string(szCurDir) + R"(\flhook_plugins\base.cfg)";
string cfg_fileitems = string(szCurDir) + R"(\flhook_plugins\base_recipe_items.cfg)";
string cfg_filemodules = string(szCurDir) + R"(\flhook_plugins\base_recipe_modules.cfg)";
string cfg_filearch = string(szCurDir) + R"(\flhook_plugins\base_archtypes.cfg)";
string cfg_fileforbiddencommodities = string(szCurDir) + R"(\flhook_plugins\base_forbidden_cargo.cfg)";
uint bmapLoadHyperspaceHubConfig = 0;
for (auto base : player_bases)
{
delete base.second;
}
player_bases.clear();
construction_items.clear();
set_base_repair_items.clear();
set_base_crew_consumption_items.clear();
set_base_crew_food_items.clear();
recipeCraftTypeNumberMap.clear();
recipeCraftTypeNameMap.clear();
factoryNicknameToCraftTypeMap.clear();
moduleNameRecipeMap.clear();
craftListNumberModuleMap.clear();
humanCargoList.clear();
HookExt::ClearMiningObjData();
DefenseModule::LoadSettings(string(szCurDir) + R"(\flhook_plugins\base_wp_ai.cfg)");
INI_Reader ini;
if (ini.open(cfg_file.c_str(), false))
{
while (ini.read_header())
{
if (ini.is_header("general"))
{
while (ini.read_value())
{
if (ini.is_value("debug"))
{
set_plugin_debug = ini.get_value_int(0);
}
else if (ini.is_value("status_path_html"))
{
set_status_path_html = ini.get_value_string();
}
else if (ini.is_value("status_path_json"))
{
set_status_path_json = ini.get_value_string();
}
else if (ini.is_value("damage_threshold"))
{
damage_threshold = ini.get_value_float(0);
}
else if (ini.is_value("siege_mode_damage_trigger_level"))
{
siege_mode_damage_trigger_level = ini.get_value_float(0);
}
else if (ini.is_value("siege_mode_chain_reaction_trigger_distance"))
{
siege_mode_damage_trigger_level = ini.get_value_float(0);
}
else if (ini.is_value("status_export_type"))
{
ExportType = ini.get_value_int(0);
}
else if (ini.is_value("damage_per_tick"))
{
set_damage_per_tick = ini.get_value_int(0);
}
else if (ini.is_value("no_crew_damage_multiplier"))
{
no_crew_damage_multiplier = ini.get_value_float(0);
}
else if (ini.is_value("damage_tick_time"))
{
set_damage_tick_time = ini.get_value_int(0);
}
else if (ini.is_value("tick_time"))
{
set_tick_time = ini.get_value_int(0);
}
else if (ini.is_value("health_to_heal_per_cycle"))
{
repair_per_repair_cycle = ini.get_value_int(0);
}
else if (ini.is_value("shield_reinforcement_threshold_per_core"))
{
shield_reinforcement_threshold_map.emplace(ini.get_value_int(0), ini.get_value_float(1));
}
else if (ini.is_value("shield_reinforcement_increment"))
{
shield_reinforcement_increment = ini.get_value_float(0);
}
else if (ini.is_value("base_shield_strength"))
{
base_shield_strength = ini.get_value_float(0);
}
else if (ini.is_value("base_vulnerability_window_length"))
{
vulnerability_window_length = ini.get_value_int(0);
}
else if (ini.is_value("single_vulnerability_window"))
{
single_vulnerability_window = ini.get_value_bool(0);
}
else if (ini.is_value("construction_shiparch"))
{
set_construction_shiparch = CreateID(ini.get_value_string(0));
}
else if (ini.is_value("construction_item"))
{
ValidateItem(ini.get_value_string(0));
uint good = CreateID(ini.get_value_string(0));
uint quantity = ini.get_value_int(1);
construction_items[good] = quantity;
}
else if (ini.is_value("construction_credit_cost"))
{
construction_credit_cost = ini.get_value_int(0);
}
else if (ini.is_value("base_crew_item"))
{
ValidateItem(ini.get_value_string(0));
set_base_crew_type = CreateID(ini.get_value_string(0));
humanCargoList.insert(set_base_crew_type);
}
else if (ini.is_value("human_cargo_item"))
{
ValidateItem(ini.get_value_string(0));
humanCargoList.insert(CreateID(ini.get_value_string(0)));
}
else if (ini.is_value("base_repair_item"))
{
ValidateItem(ini.get_value_string(0));
REPAIR_ITEM item;
item.good = CreateID(ini.get_value_string(0));
item.quantity = ini.get_value_int(1);
set_base_repair_items.emplace_back(item);
}
else if (ini.is_value("base_crew_consumption_item"))
{
ValidateItem(ini.get_value_string(0));
uint good = CreateID(ini.get_value_string(0));
set_base_crew_consumption_items.emplace_back(good);
}
else if (ini.is_value("base_crew_food_item"))
{
ValidateItem(ini.get_value_string(0));
uint good = CreateID(ini.get_value_string(0));
set_base_crew_food_items.emplace_back(good);
}
else if (ini.is_value("set_crew_check_frequency"))
{
set_crew_check_frequency = ini.get_value_int(0);
}
else if (ini.is_value("set_new_spawn"))
{
set_new_spawn = true;
}
else if (ini.is_value("set_holiday_mode"))
{
set_holiday_mode = ini.get_value_bool(0);
if (set_holiday_mode)
{
ConPrint(L"BASE: Attention, POB Holiday mode is enabled.\n");
}
}
else if (ini.is_value("watch"))
{
uint c = CreateID(ini.get_value_string());
listCommodities[c] = stows(ini.get_value_string());
}
else if (ini.is_value("min_mining_distance"))
{
minMiningDistance = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("min_planet_distance"))
{
minPlanetDistance = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("min_station_distance"))
{
minStationDistance = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("min_trade_lane_distance"))
{
minLaneDistance = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("min_distance_misc"))
{
minDistanceMisc = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("min_pob_distance"))
{
minOtherPOBDistance = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("min_jump_distance"))
{
minJumpDistance = max(0.0f, ini.get_value_float(0));
}
else if (ini.is_value("low_tier_mining_exemption"))
{
lowTierMiningCommoditiesSet.insert(CreateID(ini.get_value_string()));
}
else if(ini.is_value("deployment_cooldown"))
{
deploymentCooldownDuration = ini.get_value_int(0);
}
else if (ini.is_value("enable_distance_check"))
{
enableDistanceCheck = ini.get_value_bool(0);
}
else if (ini.is_value("banned_system"))
{
bannedSystemList.insert(CreateID(ini.get_value_string(0)));
}
else if (ini.is_value("randomize_hyperspace_hub_days"))
{
string typeStr = ToLower(ini.get_value_string(0));
if (typeStr.find("monday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 0;
if (typeStr.find("tuesday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 1;
if (typeStr.find("wednesday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 2;
if (typeStr.find("thursday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 3;
if (typeStr.find("friday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 4;
if (typeStr.find("saturday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 5;
if (typeStr.find("sunday") != string::npos)
bmapLoadHyperspaceHubConfig |= 1 << 6;
if (typeStr.find("always") != string::npos)
bmapLoadHyperspaceHubConfig |= 0xff;
}
else if (ini.is_value("siege_gun"))
{
siegeWeaponryMap[CreateID(ini.get_value_string(0))] = ini.get_value_float(1);
}
else if (ini.is_value("vulnerability_window_change_cooldown"))
{
vulnerability_window_change_cooldown = 3600 * 24 * ini.get_value_int(0);
}
else if (ini.is_value("core_recipe"))
{
core_upgrade_recipes[ini.get_value_int(0)] = CreateID(ini.get_value_string(1));
}
}
}
}
ini.close();
}
if (ini.open(cfg_filemodules.c_str(), false))
{
while (ini.read_header())
{
if (ini.is_header("recipe"))
{
RECIPE recipe;
vector<wstring> craft_types;
wstring build_type;
uint recipe_number;
while (ini.read_value())
{
if (ini.is_value("nickname"))
{
recipe.nickname = CreateID(ini.get_value_string(0));
recipe.nicknameString = ini.get_value_string(0);
}
else if (ini.is_value("infotext"))
{
recipe.infotext = stows(ini.get_value_string(0));
}
else if (ini.is_value("craft_list"))
{
craft_types.emplace_back(stows(ToLower(ini.get_value_string(0))));
}
else if (ini.is_value("build_type"))
{
build_type = stows(ToLower(ini.get_value_string(0)));
}
else if (ini.is_value("recipe_number"))
{
recipe_number = ini.get_value_int(0);
}
else if (ini.is_value("module_class"))
{
recipe.shortcut_number = ini.get_value_int(0);
}
else if (ini.is_value("cooking_rate"))
{
recipe.cooking_rate = ini.get_value_int(0);
}
else if (ini.is_value("credit_cost"))
{
recipe.credit_cost = ini.get_value_int(0);
}
else if (ini.is_value("consumed"))
{
ValidateItem(ini.get_value_string(0));
recipe.consumed_items.emplace_back(make_pair(CreateID(ini.get_value_string(0)), ini.get_value_int(1)));
}
else if (ini.is_value("reqlevel"))
{
recipe.reqlevel = ini.get_value_int(0);
}
}
AddModuleRecipeToMaps(recipe, craft_types, build_type, recipe_number);
}
}
ini.close();
}
if (ini.open(cfg_fileitems.c_str(), false))
{
while (ini.read_header())
{
if (ini.is_header("recipe"))
{
RECIPE recipe;
while (ini.read_value())
{
if (ini.is_value("nickname"))
{
recipe.nickname = CreateID(ini.get_value_string(0));
recipe.nicknameString = ini.get_value_string(0);
}
else if (ini.is_value("produced_item"))
{
ValidateItem(ini.get_value_string(0));
recipe.produced_items.emplace_back(make_pair(CreateID(ini.get_value_string(0)), ini.get_value_int(1)));
}
else if (ini.is_value("loop_production"))
{
recipe.loop_production = ini.get_value_int(0);
}
else if (ini.is_value("shortcut_number"))
{
recipe.shortcut_number = ini.get_value_int(0);
}
else if (ini.is_value("craft_type"))
{
recipe.craft_type = stows(ToLower(ini.get_value_string(0)));
}
else if (ini.is_value("infotext"))
{
recipe.infotext = stows(ini.get_value_string());
}
else if (ini.is_value("cooking_rate"))
{
recipe.cooking_rate = ini.get_value_int(0);
}
else if (ini.is_value("credit_cost"))
{
recipe.credit_cost = ini.get_value_int(0);
}
else if (ini.is_value("consumed"))
{
ValidateItem(ini.get_value_string(0));
recipe.consumed_items.emplace_back(make_pair(CreateID(ini.get_value_string(0)), ini.get_value_int(1)));
}
else if (ini.is_value("catalyst"))
{
ValidateItem(ini.get_value_string(0));
uint cargoHash = CreateID(ini.get_value_string(0));
if (humanCargoList.count(cargoHash))
{
recipe.catalyst_workforce.emplace_back(make_pair(cargoHash, ini.get_value_int(1)));
}
else
{
recipe.catalyst_items.emplace_back(make_pair(cargoHash, ini.get_value_int(1)));
}
}
else if (ini.is_value("reqlevel"))
{
recipe.reqlevel = ini.get_value_int(0);
}
else if (ini.is_value("affiliation_bonus"))
{
recipe.affiliationBonus[MakeId(ini.get_value_string(0))] = ini.get_value_float(1);
}
}
AddFactoryRecipeToMaps(recipe);
}
}
ini.close();
}
if (ini.open(cfg_filearch.c_str(), false))
{
while (ini.read_header())
{
if (ini.is_header("arch"))
{
ARCHTYPE_STRUCT archstruct;
string nickname = "default";
while (ini.read_value())
{
if (ini.is_value("nickname"))
{
nickname = ini.get_value_string(0);
}
else if (ini.is_value("invulnerable"))
{
archstruct.invulnerable = ini.get_value_int(0);
}
else if (ini.is_value("logic"))
{
archstruct.logic = ini.get_value_int(0);
}
else if (ini.is_value("idrestriction"))
{
archstruct.idrestriction = ini.get_value_int(0);
}
else if (ini.is_value("isjump"))
{
archstruct.isjump = ini.get_value_int(0);
}
else if (ini.is_value("ishubreturn"))
{
archstruct.ishubreturn = ini.get_value_int(0);
}
else if (ini.is_value("shipclassrestriction"))
{
archstruct.shipclassrestriction = ini.get_value_int(0);
}
else if (ini.is_value("allowedshipclasses"))
{
archstruct.allowedshipclasses.insert(ini.get_value_int(0));
}
else if (ini.is_value("allowedids"))
{
archstruct.allowedids.insert(CreateID(ini.get_value_string(0)));
}
else if (ini.is_value("module"))
{
archstruct.modules.emplace_back(ini.get_value_string(0));
}
else if (ini.is_value("display"))
{
archstruct.display = ini.get_value_bool(0);
}
else if (ini.is_value("mining"))
{
archstruct.mining = ini.get_value_bool(0);
}
else if (ini.is_value("miningevent"))
{
archstruct.miningevent = ini.get_value_string(0);
}
}
mapArchs[nickname] = archstruct;
}
}
ini.close();
}
PlayerCommands::PopulateHelpMenus();
if (ini.open(cfg_fileforbiddencommodities.c_str(), false))
{
while (ini.read_header())
{
if (ini.is_header("forbidden_commodities"))
{
while (ini.read_value())
{
if (ini.is_value("commodity_name"))
{
forbidden_player_base_commodity_set.insert(CreateID(ini.get_value_string(0)));
}
}
}
}
ini.close();
}
//Create the POB sound hashes
pbsounds.destruction1 = CreateID("pob_evacuate2");
pbsounds.destruction2 = CreateID("pob_firecontrol");
pbsounds.heavydamage1 = CreateID("pob_breach");
pbsounds.heavydamage2 = CreateID("pob_reactor");
pbsounds.heavydamage3 = CreateID("pob_heavydamage");
pbsounds.mediumdamage1 = CreateID("pob_hullbreach");
pbsounds.mediumdamage2 = CreateID("pob_critical");
pbsounds.lowdamage1 = CreateID("pob_fire");
pbsounds.lowdamage2 = CreateID("pob_engineering");
char datapath[MAX_PATH];
GetUserDataPath(datapath);
// Create base account dir if it doesn't exist
string basedir = string(datapath) + R"(\Accts\MultiPlayer\player_bases\)";
CreateDirectoryA(basedir.c_str(), 0);
// Load and spawn all bases
string path = string(datapath) + R"(\Accts\MultiPlayer\player_bases\base_*.ini)";
WIN32_FIND_DATA findfile;
HANDLE h = FindFirstFile(path.c_str(), &findfile);
if (h != INVALID_HANDLE_VALUE)
{
do
{
string filepath = string(datapath) + R"(\Accts\MultiPlayer\player_bases\)" + findfile.cFileName;
PlayerBase *base = new PlayerBase(filepath);
if (base && !base->nickname.empty())
{
player_bases[base->base] = base;
base->Spawn();
}
else
{
AddLog("ERROR POB file corrupted: %s", findfile.cFileName);
}
} while (FindNextFile(h, &findfile));
FindClose(h);
}
// loadHyperspaceHubConfig is weekday where 0 = sunday, 6 = saturday
// if it's today, randomize appropriate 'jump hole' POBs
if (bmapLoadHyperspaceHubConfig)
{
time_t tNow = time(0);
struct tm *t = localtime(&tNow);
uint currWeekday = (t->tm_wday + 6)%7; // conversion from sunday-week-start to monday-start
if (bmapLoadHyperspaceHubConfig & (1 << currWeekday)) // 1 - monday, 2 - tuesday, 4 - wednesday and so on
{
HyperJump::LoadHyperspaceHubConfig(string(szCurDir));
}
}
HyperJump::InitJumpHoleConfig();
// Load and sync player state
struct PlayerData *pd = 0;
while (pd = Players.traverse_active(pd))