-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHCity.cs
1012 lines (930 loc) · 47.8 KB
/
HCity.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HazeronAdviser
{
class HCity : HObj
{
protected DateTime _lastReportCycle = new DateTime(2000, 1, 1);
public DateTime LastReportCycle => _lastReportCycle;
public string LastReportCycleString => LastReportCycle.ToString("F", Hazeron.DateTimeFormat);
protected int _zone = 0;
public int Zone
{
get { return _zone; }
}
protected bool _capitalEmpire = false;
public bool CapitalEmpire
{
get { return _capitalEmpire; }
}
protected bool _capitalGalaxy = false;
public bool CapitalGalaxy
{
get { return _capitalGalaxy; }
}
protected bool _capitalSector = false;
public bool CapitalSector
{
get { return _capitalSector; }
}
protected string _distressOverview = "";
public string DistressOverview
{
get { return _distressOverview; }
}
protected string _decayOverview = "";
public string DecayOverview
{
get { return _decayOverview; }
}
protected string _eventOverview = "";
public string EventOverview
{
get { return _eventOverview; }
}
protected string _moraleOverview = "";
public string MoraleOverview
{
get { return _moraleOverview; }
}
protected string _moraleColumn = "-";
public string MoraleColumn
{
get { return _moraleColumn; }
}
protected int _morale = 0;
public int Morale
{
get { return _morale; }
}
protected Dictionary<string, int> _moraleModifiers = new Dictionary<string, int>();
public Dictionary<string, int> MoraleModifiers
{
get { return _moraleModifiers; }
}
protected int _abandonment = 0, _abandonmentMax = 0;
public int Abandonment
{
get { return _abandonment; }
}
public int AbandonmentMax
{
get { return _abandonmentMax; }
}
protected string _abandonmentColumn = "-";
public string AbandonmentColumn
{
get { return _abandonmentColumn; }
}
protected string _populationOverview = "-";
public string PopulationOverview
{
get { return _populationOverview; }
}
protected string _populationColumn = "-";
public string PopulationColumn
{
get { return _populationColumn; }
}
protected string _livingConditionsColumn = "-";
public string LivingConditionsColumn
{
get { return _livingConditionsColumn; }
}
protected string _buildingsOverview = "";
public string BuildingsOverview
{
get { return _buildingsOverview; }
}
protected string _race = "";
public string Race
{
get { return _race; }
}
protected int _powerReserve = 0, _powerReserveCapacity = 0;
public int PowerReserve
{
get { return _powerReserve; }
}
public int PowerReserveCapacity
{
get { return _powerReserveCapacity; }
}
protected Dictionary<string, int> _factilitiesJobs = new Dictionary<string, int>();
public Dictionary<string, int> FactilitiesJobs
{
get { return _factilitiesJobs; }
}
protected int _population = 0;
public int Population
{
get { return _population; }
}
protected int _homes = 0;
public int Homes
{
get { return _homes; }
}
protected int _homesQuality = 0;
public int HomesQuality
{
get { return _homesQuality; }
}
protected int _jobs = 0;
public int Jobs
{
get { return _jobs; }
}
protected int _food = 0;
public int Food
{
get { return _food; }
}
protected int _foodRate = 0;
public int FoodRate
{
get { return _foodRate; }
}
protected int _air = 0;
public int Air
{
get { return _air; }
}
protected int _airRate = 0;
public int AirRate
{
get { return _airRate; }
}
protected bool _hashEnv = false;
public bool HashEnv
{
get { return _hashEnv; }
}
protected bool _militaryBase = false;
public bool MilitaryBase
{
get { return _militaryBase; }
}
protected string _officerCadet;
public string OfficerCadet
{
get { return _officerCadet; }
}
protected long _bankBalance = 0;
public long BankBalance
{
get { return _bankBalance; }
}
protected long _bankBalanceOld = 0;
public long BankBalanceOld
{
get { return _bankBalanceOld; }
}
protected long _bankIncomeMinting = 0;
public long BankIncomeMinting
{
get { return _bankIncomeMinting; }
}
protected long _bankIncomePayroll = 0;
public long BankIncomePayroll
{
get { return _bankIncomePayroll; }
}
protected long _bankIncomeProduct = 0;
public long BankIncomeProduct
{
get { return _bankIncomeProduct; }
}
protected long _bankExpensePayroll = 0;
public long BankExpensePayroll
{
get { return _bankExpensePayroll; }
}
protected long _bankExpenseProduct = 0;
public long BankExpenseProduct
{
get { return _bankExpenseProduct; }
}
protected long _bankExpenseLoans = 0;
public long BankExpenseLoans
{
get { return _bankExpenseLoans; }
}
protected long _bankExpenseRewards = 0;
public long BankExpenseRewards
{
get { return _bankExpenseRewards; }
}
protected long _bankExpenseWithdrawals = 0;
public long BankExpenseWithdrawals
{
get { return _bankExpenseWithdrawals; }
}
protected long _bankTribute = 0;
public long BankTribute
{
get { return _bankTribute; }
}
protected string _bankOverview = "", _bankTributeColumn = "-";
public string BankOverview
{
get { return _bankOverview; }
}
public string BankTributeColumn
{
get { return _bankTributeColumn; }
}
protected List<AttentionMessage> _attentions = new List<AttentionMessage>();
public List<AttentionMessage> Attentions
{
get { return _attentions; }
}
public HCity(HMail mail)
: base(mail)
{
}
public override void CompareMail(HMail mail)
{
base.CompareMail(mail);
}
public override void Initialize()
{
if (_mail.Body.Remove(4) == "UTC:")
{
_lastUpdated = HMail.DecodeUTC(_mail.Body.Remove(12));
}
// String working vars.
string[] tempArray;
Dictionary<string, int> sectionsInReport = new Dictionary<string, int>();
string reportSection;
// This is the order of the sections in the mail body, keep them in same order!
const string headlineDISTRESS = "<b style=\"color: rgb(255, 255, 0);\">DISTRESS</b>";
const string headlineDECAY = "<b>DECAY</b>";
const string headlineEVENT = "<b>EVENT LOG</b>";
const string headlineMORALE = "<b>MORALE ";
const string headlinePOPULATION = "<b>POPULATION ";
const string headlineHOMES = "<b>HOMES ";
const string headlineBARRACKS = "<b>BARRACKS ";
const string headlineJOBS = "<b>JOBS ";
const string headlinePOWER = "<b>POWER RESERVE ";
const string headlineBANK = "<b>BANK ";
const string headlineSPACECRAFT = "<b>SPACECRAFT</b>";
const string headlineFACILITIES = "<b>FACILITIES</b>";
const string headlineVEHICLES = "<b>VEHICLES</b>";
const string headlineINVENTORY = "<b>INVENTORY</b>";
const string headlinePOTENTIAL = "<b>SPACECRAFT MANUFACTURING POTENTIAL</b>";
string[] sections = new string[] { headlineDISTRESS
, headlineDECAY
, headlineEVENT
, headlineMORALE
, headlinePOPULATION
, headlineHOMES
, headlineBARRACKS
, headlineJOBS
, headlinePOWER
, headlineBANK
, headlineSPACECRAFT
, headlineFACILITIES
, headlineVEHICLES
, headlineINVENTORY
, headlinePOTENTIAL
};
// Check for sections.
int freakingHell = 0;
foreach (string section in sections)
{
int sigh = _mail.Body.IndexOf(section, freakingHell);
if (sigh >= 0)
{
freakingHell = sigh;
sectionsInReport.Add(section, freakingHell);
}
}
// Time for City spicific things.
bool decaying = false;
int populationChange = 0;
// City Resource Zone & Capital check
{
reportSection = HHelper.CleanText(_mail.Body.Remove(sectionsInReport.Values.OrderBy(x => x).FirstOrDefault()));
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in tempArray)
{
if (line.StartsWith("UTC:"))
{
// That actual report cycle is every 13 minutes from this time.
int secondsAfterEpoch = Int32.Parse(line.Substring(4), System.Globalization.NumberStyles.HexNumber);
DateTime epoch = new DateTime(1970, 1, 1);
_lastReportCycle = epoch.AddSeconds(secondsAfterEpoch);
}
else if (line.Contains("Resource Zone"))
_zone = Convert.ToInt32(line.Substring(line.IndexOf(" Zone ") + " Zone ".Length, 1)); // Assume there will only ever be 9 or less zones.
else if (line.StartsWith("Headquarters at "))
_militaryBase = true;
else if (line == "Empire Capital City")
_capitalEmpire = true;
else if (line == "Galaxy Capital City")
_capitalGalaxy = true;
else if (line == "Sector Capital City")
_capitalSector = true;
}
}
//DISTRESS
if (TryGetSectionText(sectionsInReport, headlineDISTRESS, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_distressOverview = "[color=red]" + "Distress:" + Environment.NewLine + " " + reportSection.Substring(("DISTRESS" + Environment.NewLine).Length).Replace(Environment.NewLine, Environment.NewLine + " ") + "[/color]";
decaying = reportSection.Contains("City is decaying.");
}
// DECAY
if (TryGetSectionText(sectionsInReport, headlineDECAY, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_decayOverview = "[color=red]" + "Decay:" + Environment.NewLine + " " + reportSection.Substring(("DECAY" + Environment.NewLine).Length).Replace(Environment.NewLine, Environment.NewLine + " ") + "[/color]";
}
// EVENT LOG
if (TryGetSectionText(sectionsInReport, headlineEVENT, out reportSection))
{
reportSection = HHelper.CleanText(GetSectionText(sectionsInReport, headlineEVENT));
//tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_eventOverview += HCity.EventLogStyle(reportSection);
}
// MORALE & Abandonment
if (TryGetSectionText(sectionsInReport, headlineMORALE, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_morale = Convert.ToInt32(tempArray[0].Substring(tempArray[0].LastIndexOf(' ') + 1));
tempArray = tempArray.Where((source, index) => index != 0).ToArray(); // Remove first element in array.
int abandonedDays = 0;
int abandonedPenalty = 0;
foreach (string line in tempArray)
{
if (line.Contains("Abandonment Penalty") || line.StartsWith("Abandoned"))
{
if (line.StartsWith("+") || line.StartsWith("-"))
{
_moraleModifiers.Add(line.Substring(line.IndexOf(' ') + 1), Convert.ToInt32(line.Remove(line.IndexOf(' '))));
abandonedPenalty = Convert.ToInt32(line.Remove(line.IndexOf(' ')));
}
else
_moraleModifiers.Add(line, 0);
int posA, posB;
posA = line.LastIndexOf(" in ") + 4;
posB = line.LastIndexOf(" days.");
abandonedDays = Convert.ToInt32(line.Substring(posA, posB - posA));
}
else if (line != "No citizens.")
_moraleModifiers.Add(line.Substring(line.IndexOf(' ') + 1), Convert.ToInt32(line.Remove(line.IndexOf(' '))));
if (line == "-1 Harsh Environment.")
_hashEnv = true;
}
_abandonment = ((_moraleModifiers.Values.Sum() + 1) * Hazeron.AbandonmentInterval) - (abandonedDays % Hazeron.AbandonmentInterval);
_abandonmentMax = ((_moraleModifiers.Values.Sum() - abandonedPenalty + 1) * Hazeron.AbandonmentInterval);
if (_moraleModifiers.Any(x => x.Key.StartsWith("Loyalty Bonus."))) // Ignore loyalty morale bonus. 2016-01-01
{
int loyaltyBonusDays = _moraleModifiers.First(x => x.Key.Contains("Loyalty Bonus.")).Value * 7;
_abandonment -= loyaltyBonusDays;
_abandonmentMax -= loyaltyBonusDays;
}
if (decaying)
_abandonmentColumn = " Decaying";
else if (_abandonmentMax < Hazeron.AbandonmentInterval)
_abandonmentColumn = " Unstable";
else if (_abandonment == _abandonmentMax)
_abandonmentColumn = $"{_abandonment.ToString("00")}~/{_abandonmentMax.ToString("00")} days";
else if (_abandonment > 0)
_abandonmentColumn = $"{_abandonment.ToString("00")} /{_abandonmentMax.ToString("00")} days";
else
_abandonmentColumn = " ERROR!?";
}
// POPULATION
if (TryGetSectionText(sectionsInReport, headlinePOPULATION, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_population = Convert.ToInt32(tempArray[0].Substring(tempArray[0].LastIndexOf(' ') + 1).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
tempArray = tempArray.Where((source, index) => index != 0).ToArray(); // Remove first element in array.
// Get race and population changes.
Dictionary<string, int> populationChanges = new Dictionary<string, int>();
bool mixedRaces = false;
foreach (string line in tempArray)
{
if (mixedRaces)
_race = "mixed races";
else if (line.StartsWith("University graduate ") || line.StartsWith("Star Fleet Academy Cadet ")) // "University graduate <name> is ready for command assignment aboard a spacecraft." and "Star Fleet Academy Cadet <name> is ready for command assignment aboard a fleet spacecraft."
{
_officerCadet = line.Substring(line.StartsWith("University") ? "University graduate ".Length : "Star Fleet Academy Cadet ".Length);
_officerCadet = _officerCadet.Remove(_officerCadet.IndexOf(' '));
}
else if (line == "Citizens are mixed races." || line == "Troops are mixed races.")
mixedRaces = true; // All lines after this one is each of the faces, or a ready cadet.
else if (line.StartsWith("Citizens are ") || line.StartsWith("Troops are "))
_race = line.Remove(line.Length - 1).Substring(line.StartsWith("Citizens") ? "Citizens are ".Length : "Troops are ".Length);
else if (line != "No change.")
populationChanges.Add(line.Substring(line.IndexOf(" · ") + 3), Convert.ToInt32(line.Remove(line.IndexOf(" · "))));
}
if (populationChanges.Values.Sum() < 0)
_populationColumn = $"{_population} (decreased {Math.Abs(populationChanges.Values.Sum())})";
else if (populationChanges.Values.Sum() > 0)
_populationColumn = $"{_population} (increased {populationChanges.Values.Sum()})";
else
_populationColumn = $"{_population} (steady)";
}
// LIVING CONDITIONS
if (TryGetSectionText(sectionsInReport, headlineHOMES, out reportSection) || TryGetSectionText(sectionsInReport, headlineBARRACKS, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_homes = Convert.ToInt32(tempArray[0].Substring(tempArray[0].LastIndexOf(' ') + 1));
tempArray = tempArray.Where((source, index) => index != 0).ToArray(); // Remove first element in array.
// Calculate crampedness.
int large = 0, medium = 0, small = 0;
foreach (string line in tempArray)
{
if (line.StartsWith("Large "))
large = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1));
else if (line.StartsWith("Medium "))
medium = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1));
else if (line.StartsWith("Small "))
small = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1));
}
_homesQuality = (large * 2) + medium - small;
}
if (TryGetSectionText(sectionsInReport, headlineJOBS, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_jobs = Convert.ToInt32(tempArray[0].Substring(tempArray[0].LastIndexOf(' ') + 1));
tempArray = tempArray.Where((source, index) => index != 0).ToArray(); // Remove first element in array.
// Get temporaray jobs. They aren't worth keeping track of.
int construction = 0;
foreach (string line in tempArray)
{
if (line.StartsWith("Construction "))
construction = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1));
}
_jobs -= construction;
}
// POWER RESERVE
if (TryGetSectionText(sectionsInReport, headlinePOWER, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
_powerReserve = Convert.ToInt32(tempArray[0].Substring(tempArray[0].LastIndexOf(' ') + 1).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
tempArray = tempArray.Where((source, index) => index != 0).ToArray(); // Remove first element in array.
// Get reserve capacity.
foreach (string line in tempArray)
{
if (line.StartsWith("Reserve Capacity "))
_powerReserveCapacity = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
}
}
// BANK ACTIVITY
if (TryGetSectionText(sectionsInReport, headlineBANK, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
int startpos = tempArray[0].LastIndexOf(' ') + 1;
_bankBalance = Convert.ToInt64(tempArray[0].Substring(startpos, tempArray[0].Length - 1 - startpos).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
tempArray = tempArray.Where((source, index) => index != 0).ToArray(); // Remove first element in array.
bool income = true;
for (int i = 1; i < tempArray.Length; i++)
{
string line = tempArray[i];
if (line == "Income")
income = true;
else if (line == "Expense")
income = false;
else if (line == "Sub Total")
i++; // Ignore.
else if (line == "Ending Balance")
i++; // Ignore.
else if (line == "Previous Tribute")
{
i++;
//line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
//_bankTribute = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Starting Balance")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankBalanceOld = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Minted Bullion")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankIncomeMinting = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Payroll")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
if (income)
_bankIncomePayroll = Convert.ToInt64(line.Remove(line.Length - 1));
else
_bankExpensePayroll = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Product Sales")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankIncomeProduct = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Product Purchases")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankExpenseProduct = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Citizen Loans")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankExpenseLoans = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Withdrawals")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankExpenseWithdrawals = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Rewards")
{
i++;
line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
_bankExpenseRewards = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Income Tax")
{
i++;
//line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
//_bankTaxIncome = Convert.ToInt64(line.Remove(line.Length - 1));
}
else if (line == "Sales Tax")
{
i++;
//line = tempArray[i].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, "");
//_bankTaxSale = Convert.ToInt64(line.Remove(line.Length - 1));
}
}
}
//// SPACECRAFT
//if (TryGetSectionText(sectionsInReport, headlineSPACECRAFT))
//{
// reportSection = HHelper.CleanText(reportSection);
// tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
//}
// FACILITIES
if (TryGetSectionText(sectionsInReport, headlineFACILITIES, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Read every building.
int lounges = 0, retailers = 0;
for (int i = 1; i < tempArray.Length; i++)
{
if (tempArray[i].StartsWith("Lounges: "))
{
string line = tempArray[i];
if (line.EndsWith(". Includes local civilian lounges."))
line = line.Remove(line.Length - ". Includes local civilian lounges.".Length);
lounges = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
}
else if (tempArray[i].StartsWith("Retail Stores: "))
{
string line = tempArray[i];
if (line.EndsWith(". Includes local civilian stores."))
line = line.Remove(line.Length - ". Includes local civilian stores.".Length);
retailers = Convert.ToInt32(line.Substring(line.LastIndexOf(' ') + 1).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
}
else if (tempArray[i] != "Name")
{
string name = tempArray[i].TrimStart();
int jobs = 0;
if (name == "Cantina")
jobs = lounges;
else if (name == "Retail Store")
jobs = retailers;
else if (name == "University")
jobs = Convert.ToInt32(tempArray[i + 1]);
else if (tempArray[i + 1].EndsWith(" in use"))
{
int startpos = tempArray[i + 1].IndexOf(", ") + 2;
int length = tempArray[i + 1].IndexOf(" in use") - startpos;
jobs = Convert.ToInt32(tempArray[i + 1].Substring(startpos, length).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
}
else
jobs = Convert.ToInt32(tempArray[i + 1].Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
_factilitiesJobs.Add(name, jobs);
i++; // Skip an extra line.
}
}
if (!_factilitiesJobs.ContainsKey("Cantina"))
_factilitiesJobs.Add("Cantina", lounges);
if (!_factilitiesJobs.ContainsKey("Retail Store"))
_factilitiesJobs.Add("Retail Store", retailers);
}
//// VEHICLES
//if (TryGetSectionText(sectionsInReport, headlineVEHICLES))
//{
// reportSection = HHelper.CleanText(reportSection);
// tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
//}
// INVENTORY
if (TryGetSectionText(sectionsInReport, headlineINVENTORY, out reportSection))
{
reportSection = HHelper.CleanText(reportSection);
tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
int startpos, length;
if (reportSection.Contains("Air: "))
{
_hashEnv = true;
startpos = "Air: ".Length;
length = tempArray[1].Length - " total units in stock".Length - startpos;
_air = ConvertToInt32Max(tempArray[1].Substring(startpos, length).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
startpos = "Air Consumption: ".Length;
length = tempArray[2].Length - " units per report period".Length - startpos;
_airRate = Convert.ToInt32(tempArray[2].Substring(startpos, length).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
}
if (reportSection.Contains("Food: "))
{
startpos = "Food: ".Length;
length = tempArray[_hashEnv ? 3 : 1].Length - " total nutrition value in stock".Length - startpos;
_food = ConvertToInt32Max(tempArray[_hashEnv ? 3 : 1].Substring(startpos, length).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
startpos = "Food Consumption: ".Length;
length = tempArray[_hashEnv ? 4 : 2].Length - " nutrition value per report period".Length - startpos;
_foodRate = Convert.ToInt32(tempArray[_hashEnv ? 4 : 2].Substring(startpos, length).Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator, ""));
}
}
//// SPACECRAFT MANUFACTURING POTENTIAL
//if (TryGetSectionText(sectionsInReport, headlinePOTENTIAL))
//{
// reportSection = HHelper.CleanText(reportSection);
// tempArray = reportSection.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
//}
UpdateMoraleOverview();
UpdatePopulationOverwiew(populationChange);
//UpdateLivingOverwiew();
_livingConditionsColumn = $"Jobs {_jobs}, Homes {_homes}";
UpdateBuildingsOverview();
UpdateBankOverview();
// Overview
_overview = "Location:" + Environment.NewLine;
_overview += " " + _systemName + Environment.NewLine;
_overview += " " + _planetName + Environment.NewLine;
if (!_militaryBase && _zone != 0)
_overview += " Zone " + _zone;
if (_distressOverview != "")
_overview += Environment.NewLine + Environment.NewLine + _distressOverview;
if (_decayOverview != "")
_overview += Environment.NewLine + Environment.NewLine + _decayOverview;
if (_eventOverview != "")
_overview += Environment.NewLine + Environment.NewLine + _eventOverview;
// Attentions
if (_population > 1 && _jobs >= _homes) // Overworked.
_attentions.Add(new AttentionMessage(1, "ColumnLivingConditions", "- Overworked." + Environment.NewLine + " " + (_jobs - _homes + 1).ToString().PadLeft(4) + ", Missing workers"));
if (_population > 1 && ((float)(_homes - _jobs) / _homes) > 0.2) // High unemployment.
_attentions.Add(new AttentionMessage(1, "ColumnLivingConditions", "- High unemployment." + Environment.NewLine + " " + ((_homes * 0.8) - _jobs + 1).ToString().PadLeft(4) + ", Excesseding unemployed"));
if (decaying) // Decaying.
_attentions.Add(new AttentionMessage(4, "ColumnAbandonment", "- City is decaying!"));
else if (_abandonment <= 0) // 0 days till decay.
_attentions.Add(new AttentionMessage(3, "ColumnAbandonment", "- City has been abandonment." + Environment.NewLine + " Decay may start at any moment."));
else if (_abandonment <= Hazeron.AbandonmentInterval) // Less than or equal to (Hazeron.AbandonmentInterval) days to decay.
_attentions.Add(new AttentionMessage(2, "ColumnAbandonment", "- City has been abandonment." + Environment.NewLine + " Possible decay in " + _abandonment.ToString() + " days."));
else if (_abandonment <= Hazeron.AbandonmentInterval * 2) // Less than or equal to (Hazeron.AbandonmentInterval * 2) days to decay.
_attentions.Add(new AttentionMessage(1, "ColumnAbandonment", "- City has been abandonment." + Environment.NewLine + " Possible decay in " + _abandonment.ToString() + " days."));
if (_population <= 1) // Population is 1 or 0.
_attentions.Add(new AttentionMessage(1, "ColumnPopulation", "- City is desered."));
if (_population > _homes) // Homelessness.
_attentions.Add(new AttentionMessage(1, "ColumnPopulation", "- Homeless citizens." + Environment.NewLine + (_population - _homes).ToString().PadLeft(4) + ", Homeless"));
if (_population > 1 && _morale < 0) // Morale is negative!
_attentions.Add(new AttentionMessage(2, "ColumnMorale", "- Morale is negative!"));
else if (_population > 1 && _morale < 3) // Morale is low.
_attentions.Add(new AttentionMessage(1, "ColumnMorale", "- Morale is low."));
if (_population > 1 && _moraleModifiers.Values.Sum() < 1) // Morale not positive.
_attentions.Add(new AttentionMessage(2, "ColumnMorale", "- Morale modifiers are dangerously low."));
if (_moraleModifiers.Keys.Any(x => x.EndsWith(" wanted."))) // Morale building wanted.
_attentions.Add(new AttentionMessage(1, "ColumnMorale", "- Missing morale building."));
if (!_militaryBase && _population > 1 && !_factilitiesJobs.ContainsKey("Bank")) // No bank.
_attentions.Add(new AttentionMessage(1, "ColumnBank", "- City has no bank and is not collecting taxes."));
base.Initialize();
}
#region Overviews
protected void UpdateMoraleOverview()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("City's morale:");
if (_morale >= 0)
sb.Append("[color=green]");
else
sb.Append("[color=red]");
sb.AppendLine($" Morale {_morale.ToString("+#0;-#0;±#0").PadLeft(3)}[/color]");
sb.AppendLine();
sb.AppendLine("City's morale modifiers:");
foreach (KeyValuePair<string, int> moraleModifier in _moraleModifiers)
{
if (moraleModifier.Value > 0)
sb.Append("[color=green]");
else
sb.Append("[color=red]");
sb.AppendLine($" {moraleModifier.Value.ToString("+#0;-#0;±#0").PadLeft(3)} {moraleModifier.Key}[/color]");
}
sb.Append($"Total ");
if (_morale >= 0)
sb.Append("[color=green]");
else
sb.Append("[color=red]");
sb.Append($"{_morale.ToString("+#0;-#0;±#0")}[/color]");
sb.Append($" ([color=green]+{_moraleModifiers.Values.Where(x => x > 0).Sum().ToString("#0;#0;#0")}[/color]");
sb.Append($", [color=red]-{_moraleModifiers.Values.Where(x => x < 0).Sum().ToString("#0;#0;#0")}[/color])");
_moraleOverview = sb.ToString();
_moraleColumn = $"{_morale.ToString("+#0;-#0;±#0")} ({Math.Abs(_moraleModifiers.Values.Where(y => y < 0).Sum()).ToString("-#0")}, {_moraleModifiers.Values.Where(y => y > 0).Sum().ToString("+#0")})";
}
protected void UpdatePopulationOverwiew(int populationChange)
{
StringBuilder sb = new StringBuilder();
const int populationPadding = 6;
sb.AppendLine("City's population:");
sb.Append($" {_population.ToString().PadLeft(populationPadding)}, Citizens");
if (populationChange < 0)
sb.Append($" [color=red](decreased by {Math.Abs(populationChange)})[/color]");
else if (populationChange > 0)
sb.Append($" [color=green](increased by {populationChange})[/color]");
//else
// sb.Append(" (steady)");
sb.AppendLine();
sb.Append($" {_homes.ToString().PadLeft(populationPadding)}, Homes");
if (_jobs >= _homes)
{
int needed = (_jobs - _homes + 1); // Need at least one more home than jobs.
sb.Append($" [color=red](Overworked, {needed} more homes needed)[/color]");
}
sb.AppendLine();
sb.Append($" {_jobs.ToString().PadLeft(populationPadding)}, Jobs");
if (((float)(_homes - _jobs) / _homes) > 0.2)
{
int needed = (int)((_homes * 0.8) - _jobs + 1); // Need at least one more job than 80% homes.
sb.Append($" [color=red](Unemployment, {needed} more jobs needed)[/color]");
}
sb.AppendLine();
sb.AppendLine();
sb.AppendLine("City's living conditions:");
sb.AppendLine($" Citizens are {_race}");
{
sb.AppendLine($" {_powerReserve.ToString("N", Hazeron.NumberFormat)}/{_powerReserveCapacity.ToString("N", Hazeron.NumberFormat)} power capacity ({Math.Floor(((float)_powerReserve / _powerReserveCapacity) * 100)}%)");
}
{
int minutesToStarvation = (_foodRate / 13) == 0 ? 0 : (_food / (_foodRate / 13));
if (minutesToStarvation < 120) // Less than two hours.
sb.Append($" {minutesToStarvation} minutes");
else if (minutesToStarvation < 2980) // Less than two days.
sb.Append($" {minutesToStarvation / 60} hours");
else // More than two days.
sb.Append($" {minutesToStarvation / 1490} days");
sb.AppendLine(" worth of food");
}
if (_hashEnv)
{
int minutesToSuffocation = (_airRate / 13) == 0 ? 0 : (_air / (_airRate / 13));
if (minutesToSuffocation < 120) // Less than two hours.
sb.Append($" {minutesToSuffocation} minutes");
else if (minutesToSuffocation < 2980) // Less than two days.
sb.Append($" {minutesToSuffocation / 60} hours");
else // More than two days.
sb.Append($" {minutesToSuffocation / 1490} days");
sb.AppendLine(" worth of air");
}
{
sb.Append($" {Math.Round(((float)_homesQuality / (float)_homes) * 100)}% home quality rating");
if (_homesQuality > 0)
sb.Append($" [color=green]({_homesQuality} additional small homes possible)[/color]");
else if (_homesQuality < 0)
sb.Append($" [color=red](Cramped, {Math.Abs(_homesQuality)} small homes too many)[/color]");
}
if (!string.IsNullOrEmpty(_officerCadet))
{
sb.AppendLine();
sb.AppendLine();
sb.AppendLine("Spacecraft crew:");
sb.Append($" Cadet {_officerCadet}");
}
_populationOverview = sb.ToString();
}
protected void UpdateBuildingsOverview()
{
StringBuilder sb = new StringBuilder();
List<string> buildingList;
sb.AppendLine("City's buildings:");
buildingList = _factilitiesJobs.Keys.ToList();
foreach (string moraleBuilding in Hazeron.MoraleBuildingCityThresholds.Keys)
{
if (!_factilitiesJobs.ContainsKey(moraleBuilding) && _homes >= Hazeron.MoraleBuildingCityThresholds[moraleBuilding])
buildingList.Add(moraleBuilding);
}
if (!buildingList.Contains("Cantina"))
buildingList.Add("Cantina");
if (!buildingList.Contains("Church"))
buildingList.Add("Church");
buildingList.Sort();
foreach (string building in buildingList)
{
int jobs = 0;
if (_factilitiesJobs.ContainsKey(building))
jobs = _factilitiesJobs[building];
sb.AppendLine();
sb.Append($" {jobs.ToString().PadLeft(4)} jobs, {building}");
if (_militaryBase)
{
if (Hazeron.MoraleBuildingBaseThresholds.ContainsKey(building))
{
int jobsNeeded = Hazeron.MoraleBuildingsRequiredBase(building, _homes);
if (jobs < jobsNeeded)
sb.Append($" [color=red]({jobsNeeded - jobs} professional jobs more needed)[/color]");
else if (jobs > jobsNeeded)
sb.Append($" [color=orange]({jobs - jobsNeeded} professional jobs too many)[/color]");
}
}
else
{
if (Hazeron.MoraleBuildingCityThresholds.ContainsKey(building))
{
int jobsNeeded = Hazeron.MoraleBuildingsRequiredCity(building, _homes);
if (jobs < jobsNeeded)
sb.Append($" [color=red]({jobsNeeded - jobs} professional jobs more needed)[/color]");
else if (jobs > jobsNeeded)
sb.Append($" [color=orange]({jobs - jobsNeeded} professional jobs too many)[/color]");
}
}
}
_buildingsOverview = sb.ToString();
}
protected void UpdateBankOverview()
{
if (_militaryBase)
{
_bankTributeColumn = "n/a";
_bankOverview = "Military bases do not have banks.";
return;
}
StringBuilder sb = new StringBuilder();
sb.AppendLine("City's finances:");
if (_capitalEmpire && _bankTribute == 0)
{
_bankTributeColumn = "No tributing";
sb.AppendLine($"{"".PadLeft(Hazeron.CurrencyPadding)} Empire capital does not tribute");
}
else
{
_bankTributeColumn = _bankTribute.ToString("C", Hazeron.NumberFormat) + " tributed";
sb.Append($" {_bankTribute.ToString("C", Hazeron.NumberFormat).PadLeft(Hazeron.CurrencyPadding)} tributed to ");
if (_capitalEmpire)
sb.AppendLine("(overlord/ally)");
else if (_capitalGalaxy)
sb.AppendLine("empire capital city");
else if (_capitalSector)
sb.AppendLine("galaxy capital city");
else
sb.AppendLine("sector capital city");
}
{
sb.Append($"{"".PadLeft(Hazeron.CurrencyPadding)} [color=green](");
int minutesToMidnight = (int)(DateTime.UtcNow.Subtract(DateTime.Now.TimeOfDay).AddDays(1) - _lastUpdated).TotalMinutes;
if (minutesToMidnight < 120) // Less than two hours.
sb.Append($"{minutesToMidnight} minutes");
else // More than two hours.
sb.Append($"{minutesToMidnight / 60} hours");
sb.AppendLine(" to next tribute)[/color]");
}
sb.AppendLine();
sb.AppendLine($" {_bankIncomeMinting.ToString("C", Hazeron.NumberFormat).PadLeft(Hazeron.CurrencyPadding)} bullion minting");
sb.AppendLine();
sb.AppendLine($" {(-_bankExpenseWithdrawals).ToString("C", Hazeron.NumberFormat).PadLeft(Hazeron.CurrencyPadding)} withdrawals");
sb.AppendLine();
sb.AppendLine($" {(_bankBalance - _bankBalanceOld).ToString("C", Hazeron.NumberFormat).PadLeft(Hazeron.CurrencyPadding)} government account net-change");
sb.AppendLine($" {_bankBalance.ToString("C", Hazeron.NumberFormat).PadLeft(Hazeron.CurrencyPadding)} government account balance");
_bankOverview = sb.ToString();
}
#endregion
private int ConvertToInt32Max(string input)
{
if (input.Length > 10)
return int.MaxValue;
int output;