-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.cs
1099 lines (951 loc) · 39 KB
/
backup.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.IO;
using System.Diagnostics;
using System.Linq;
using System.Text;
//Include Newtonsoft json -- When on VS
//===NOTES:
//
//Project progress: 46.75%
//+1.25% for each section in NPC
//+2% for the Top Ups
/*
| Module Library = 25% | Algorithims = 25% | Extras = 15% | Interface = 25% | File Management = 10% |
^
*/
//Current version: 0.8.3
//
//When on VS:
//- Complete setInterface()
//- Modify run() and print() with timers and buttons
//- Add file management system
//Required:
//- Banking system
//- Storage systems
//- Random events
//- Trade routes (can be included into the random events or into markets)
//After Base tasks complete (Further Ideas):
//- Crafting system
//- Production facilites (New NPCs tied to rescources)
//- Elections
//- Government NPCs
//- Interactive Map
namespace TradeGame
{
class Program
{
public static List<Material> Materials = new List<Material>();
public static List<Market> LocList = new List<Market>();
public static List<NPC> Players = new List<NPC>();
public static List<Facility> Locs = new List<Facility>();
//Remove new Module(); for file management
public static Module mod = new Module();
public static string filename; //String Path, public
public static void Main(string[] args)
{
//Creating new games and
//storing new file paths on the transfer folder
//will all be done by seperate launch program in VSMS
//mod.setInterface('menu');
//NewGameButton_Click(#){ newGame(NewBox.Text); }
//LoadGameButton_Click(#){ loadGame(SaveList.Selected); }
//loadGame();
//if(time != 0){ createTurnOrder(); }
//mod.runMod(Materials, LocList, Players); //Store lists to module class
Console.WriteLine("Hello World!");
Material Iron = new Material()
{
name = "Iron",
type = "r",
cost = 460.32,
influx = 9,
amount = 60,
total = 10
};
Material Copper = new Material()
{
name = "Copper",
type = "r",
cost = 103.73,
influx = 11,
amount = 15,
total = 16
};
Material Uranium = new Material()
{
name = "Uranium",
type = "r",
cost = 2374.19,
influx = 4,
amount = 3,
total = 10
};
Materials.Add(Iron);
Materials.Add(Copper);
Materials.Add(Uranium);
Material Base = new Material()
{
name = "Money",
type = "c",
cost = 1,
influx = 0,
amount = 10000,
total = 12000,
anchor = "Central"
};
Materials.Add(Base);
Market Central = new Market()
{
name = "Central",
type = "e",
markup = 1.44,
currency = Base
};
LocList.Add(Central);
NPC Tenex = new NPC()
{
name = "Tenex",
type = "c",
intellegence = 72,
location = "Central"
};
NPC Sciton = new NPC()
{
name = "Sciton",
type = "c",
intellegence = 95,
location = "Central"
};
Facility Central1 = new Facility()
{
name = "Cen1s",
type = "s",
location = Central,
mcost = 10.06,
cost = 100,
cap = 1000
};
Facility IronMine = new Facility()
{
name = "im-central",
type = "p",
location = Central,
mcost = 49.67,
cost = 78,
cap = 200
};
Locs.Add(Central1);
Locs.Add(IronMine);
Players.Add(Sciton);
Players.Add(Tenex);
foreach (NPC n in Players)
{
n.invent = new Dictionary<Material, int>();
foreach (Material m in Materials)
{
n.invent.Add(m, 0);
}
}
Tenex.manageInvent("add", Copper, 1);
Tenex.manageInvent("add", Uranium, 7);
Tenex.manageInvent("add", Base, 1000);
Sciton.manageInvent("add", Iron, 70);
Sciton.manageInvent("add", Base, 1000);
IronMine.developProperty(Tenex, Iron);
mod.increment(Materials, LocList, Players, Locs);
mod.createTurnOrder();
if (int.TryParse(Console.ReadLine(), out int x))
{
run(x);
}
}
// Function, public void
//Create new game file
public static void newGame() { }
// Function, public void
//Saves game stats in designated files
public static void saveGame() { }
// Function, public void
//Loads game stats in designated files
public static void loadGame(string file = "") { }
//Replace with timer (and button for players)
public static void run(int period)
{
mod.per = period / 4;
int x = 0;
while (x < period)
{
x++;
for (int i = 0; i < mod.order.Count() - 1; i++)
{
mod.takeTurn(mod.turn, mod.getClass(mod.turn)[0], mod.getClass(mod.turn)[1]);
}
foreach (NPC n in mod.Players)
{
n.prevNet = n.netWorth();
}
mod.time += 0.25;
if (x % (period / 10) == 0)
{
Console.WriteLine("\n*** DAY: " + mod.time + " RUN: " + x.ToString() + " ***\n");
mod.print();
}
}
}
}
//Function Module, used to run everything not bound to the screen elements or file management
//Requres inputs to help set up when first created
//Module will be saved and loaded up
public class Module
{
public double per { get; set; }
public double time { get; set; } //Double, increments by 0.25, public
//Length of time in days
public int difficulty { get; set; } //Integer, public
//Artificially marks up the intelegence of all NPCs
public string turn { get; set; } //String, public
//Determines who's turn it is (name)
public bool playerturn { get; set; } //Bool, public
//Checks if player is playing
public Dictionary<int, string> order; //String[], public
//an array of the order of turns
public int ordern = 0;
public int count = 0;
public bool turnover { get; set; } //Bool, public
//Checks if turn is complete
public List<Material> Materials { get; set; }
public List<Market> LocList { get; set; }
public List<NPC> Players { get; set; }
public List<Facility> Locs { get; set; }
public Random rnd = new Random();
public void increment(List<Material> m, List<Market> mr, List<NPC> p, List<Facility> l)
{
Materials = m;
LocList = mr;
Players = p;
Locs = l;
}
//Replace with timer (and button for players)
public void print()
{
Console.WriteLine(
"--------------------------" +
"\nMaterials (List): Type | Cost | Influx | Amount | Total | Inflation | Anchor |"
);
foreach (Material m in Materials)
{
int x = "Materials (List):".Length - (m.name + "(" + Math.Round(m.netWorth()).ToString() + ")").Length;
string name = "";
for (int i = 0; i < x; i++)
{
name += " ";
}
x = 7 - m.influx.ToString().Length;
string inf = "";
for (int i = 0; i < x; i++)
{
inf += " ";
}
x = 7 - m.amount.ToString().Length;
string am = "";
for (int i = 0; i < x; i++)
{
am += " ";
}
x = 7 - m.cost.ToString().Length;
string c = "";
for (int i = 0; i < x; i++)
{
c += " ";
}
Console.WriteLine
(
(m.name + "(" + Math.Round(m.netWorth()).ToString() + ")") + name + " '" +
m.type + "' " + c +
Math.Round(m.cost, 2).ToString() + inf +
m.influx.ToString() + " " + am +
m.amount.ToString() + " " + am +
m.total.ToString() + " " +
Math.Round(m.inflation, 2).ToString() + " " +
m.anchor
);
}
Console.WriteLine(
"\n--------------------------" +
"\nMarkets (List): Type | Cost | Currency | Anchor |"
);
foreach (Market m in LocList)
{
int x = "Markets (List):".Length - (m.name + "(" + Math.Round(m.netWorth(Locs)).ToString() + ")").Length;
string name = "";
for (int i = 0; i < x; i++)
{
name += " ";
}
x = 7 - m.currency.name.Length;
string a = "";
for (int i = 0; i < x; i++)
{
a += " ";
}
Console.WriteLine
(
(m.name + "(" + Math.Round(m.netWorth(Locs)).ToString() + ")") + name + " '" +
m.type + "' " +
Math.Round(m.markup, 2).ToString() + " " +
m.currency.name + a + " " +
m.anchor
);
}
Console.WriteLine(
"\n--------------------------" +
"\nPlayers & NPCs (List): Type | Intellegence | Location | Sponsor |"
);
foreach (NPC m in Players)
{
int x = "Players & NPCs (List):".Length - (m.name + "(" + Math.Round(m.netWorth()).ToString() + ")").Length;
string name = "";
for (int i = 0; i < x; i++)
{
name += " ";
}
x = 11 - m.location.Length;
string l = "";
for (int i = 0; i < x; i++)
{
l += " ";
}
Console.WriteLine
(
(m.name + "(" + Math.Round(m.netWorth()).ToString() + ")") + name + " '" +
m.type + "' " +
m.intellegence.ToString() + l + " " +
m.location + " " +
m.sponsor
);
}
Console.WriteLine(
"\n--------------------------" +
"\nFacilites 'Locs' (List): Type | MCost | Cost | Cap | Location | Anchor |"
);
foreach (Facility m in Locs)
{
int x = "Facilites 'Locs' (List):".Length - (m.name + "(" + Math.Round(m.netWorth("worth")).ToString() + ")").Length;
string name = "";
for (int i = 0; i < x; i++)
{
name += " ";
}
x = "MCost | ".Length - Math.Round(m.mcost, 2).ToString().Length;
string mcost = "";
for (int i = 0; i < x; i++)
{
mcost += " ";
}
x = "Cost | ".Length - m.cost.ToString().Length;
string cost = "";
for (int i = 0; i < x; i++)
{
cost += " ";
}
x = "Cap | ".Length - m.cap.ToString().Length;
string cap = "";
for (int i = 0; i < x; i++)
{
cap += " ";
}
x = "Location | ".Length - m.location.name.Length;
string l = "";
for (int i = 0; i < x; i++)
{
l += " ";
}
Console.WriteLine
(
(m.name + "(" + Math.Round(m.netWorth("worth")).ToString() + ")") + name + " '" +
m.type + "' " +
Math.Round(m.mcost, 2).ToString() + mcost +
m.cost.ToString() + cost +
m.cap.ToString() + cap +
m.location.name + l +
m.anchor
);
}
}
//Function, public void
//Commences for every NPC, Market and Material run in a set of foreach loops
//Makes the move for each object until over
//if the type is player another function will be called
public void takeTurn(string name, string classname, string type)
{
if (classname == "Material")
{
foreach (Material m in Materials)
{
if (m.name == name)
{
//-----MATERIAL FLUX FORMULA-----
//Net amount: gain is positive (this is demand)
//double net = Math.Pow(m.amount, 2) / m.prevamount;
m.influx = rnd.Next((-1 * m.amount / 2) + 1, 1000);
//D/S = P
//m.inflation = net / m.amount;
if (m.prevamount != 0)
{
m.inflation = Convert.ToDouble(m.prevamount) / Convert.ToDouble(m.amount);
}
else
{
m.inflation = 1;
}
double x = -0.1;
double net;
//Add Currency fluctuations
if (type != "r")
{
//Change/Test, x = ma.netWorth(Locs), no material
foreach (Market ma in LocList) { if (m.anchor == ma.name) { x = ma.netWorth(Locs); } }
foreach (NPC ma in Players) { if (m.anchor == ma.name) { x = ma.netWorth(m); } }
if (m.anchor != "" && m.anchornet > 0)
{
net = x / m.anchornet;
//Calculate average
m.inflation = (m.cost * m.inflation + net) / (1 + m.cost);
//Console.WriteLine(x.ToString() + " | " + m.inflation.ToString());
}
}
else
{
foreach (Facility ma in Locs) { if (m == ma.mat && ma.type != "s") { x = ma.netWorth("worth"); } }
if (m.anchornet > 0)
{
net = x / m.anchornet;
//Calculate average
m.inflation = (m.cost * m.inflation + net) / (1 + m.cost);
//Console.WriteLine(x.ToString() + " | " + m.inflation.ToString());
}
}
//Add Influxes, Inflations and previous amounts
m.cost = m.cost * (m.inflation);
m.prevamount = m.amount;
m.previnflation = m.inflation;
m.anchornet = x;
//Remove when adding Facilites
m.amount += m.influx;
m.total += m.influx;
}
}
}
else if (classname == "Market")
{
foreach (Market m in LocList)
{
if (m.name == name)
{
//
//-----ADD MARKET FLUX FORMULA HERE-----
//
double net = 0;
int x = 0;
//Take average of all facility production
foreach (Facility f in Locs)
{
if (f.location == m && f.developed)
{
net += f.netWorth("prod");
x++;
}
}
if (x > 0)
{
net = net / x;
//Console.WriteLine(net);
}
double p = 0;
foreach (Market ma in LocList)
{
if (m.anchor == ma.name)
{
p = ma.markup;
}
}
if (m.prevNet > 0)
{
double i = net / m.prevNet;
if (p == 0) { p = i; }
m.markup = (i + p) / 2;
}
m.prevNet = net;
}
}
}
else if (classname == "NPC" && type == "p")
{
playerturn = true;
}
else if (classname == "NPC" && type != "p")
{
foreach (NPC n in Players)
{
if (n.name == name)
{
Dictionary<string, double[]> dv = NPCturn(n);
/*
foreach(string s in dv.Keys)
{
if(per % time == 0){
Console.WriteLine("\n"+s+", "+ dv[s][0].ToString());
}
}
*/
//Compile into list
List<double> tally = new List<double>();
foreach (string s in dv.Keys) { tally.Add(dv[s][0]); }
tally.Sort();
//foreach (double d in tally) { Console.WriteLine(d); }
int r = rnd.Next(tally.Count * (n.intellegence / 100), tally.Count - 1);
double[] t = tally.ToArray();
//Console.WriteLine("{0}, {1}",r,tally.Count);
double num = t[r];
string choice = "";
foreach (string s in dv.Keys)
{
if (dv[s][0] == num) { choice = s; }
}
//Console.WriteLine(n.name + ": " + choice);
//Find best option
/*
if (!n.pub)
{
if (per % time == 0)
{
Console.WriteLine("\n" + n.name + ", split: " + dv[n.name][1].ToString() + ", keep: " + dv[n.name][2].ToString());
}
}
*/
}
}
//
//-----ADD NPC DESCISION ALGORITHIM HERE-----
//
}
else if (classname == "Facility")
{
foreach (Facility m in Locs)
{
if (m.name == name)
{
//
//-----ADD FACILITY FLUX FORMULA HERE-----
//
/*double x;
foreach(NPC n in Players)
{
if(n.prevNet > 0 && m.developed && m.anchor == n.name)
{
x = n.netWorth(m.mat);
}
}*/
m.cost = Convert.ToInt32(m.cost * m.location.markup); //* 1);//
//Console.WriteLine("{0}, {1}", m.cost, m.location.markup);
if (m.developed)
{
m.mcost = (m.mcost * m.mat.inflation);
//m.cost = Convert.ToInt32(m.cost * m.mat.inflation);
//Console.WriteLine("{0}, {1}, {2}", m.mcost, m.mat.inflation, m.location.markup);
//ADD CAP ADDITION FORMULA
}
}
}
}
turn = changeTurn();
if (!playerturn)
{
turnover = true;
}
}
public Dictionary<string, double[]> NPCturn(NPC n)
{
Dictionary<string, double[]> l = new Dictionary<string, double[]>();
//Material Calculations
double nw = 0;
double[] marc = new double[2];
foreach (Material m in Materials)
{
foreach (Market ma in LocList)
{
if (n.location == ma.name && ma.type == "e")
{
//Main material calculation formula
//int x = -A + (A * (i+id) / Math.Pow(c, 1/2));
int A = m.amount;
double i = m.inflation;
double id = m.inflation - m.previnflation;
double x = -A + (A * (i + id) / Math.Pow(m.cost, 1 / 2));
//Check for max/min amounts possible
if (x > m.amount * 1 / 4) { x = m.amount * 1 / 4; }
if (-x > n.invent[m]) { x = -n.invent[m]; }
if ((x * m.cost) / ma.currency.cost > n.invent[ma.currency]) { x = (ma.currency.cost * n.invent[ma.currency]) / (m.cost); }
if ((-x * m.cost) / ma.currency.cost > ma.currency.amount * 1 / 4) { x = (ma.currency.amount * ma.currency.cost) / (4 * m.cost); }
double[] matc = new double[] { Math.Abs(x), x };
l.Add(m.name, matc);
}
if (n.location == ma.name)
{
nw = ma.netWorth(Locs, m);
}
}
}
//Market & Facility Calculations
foreach (Market ma in LocList)
{
//Get total nw of all materials
foreach (Material m in Materials)
{
marc[0] = marc[0] + ma.netWorth(Locs, m) - nw;
}
//Get average of material net worth
//marc[0] = marc[0] / Materials.Count;
l.Add(ma.name, marc);
//Same material calculation but for warehouses
foreach (Facility f in Locs)
{
double[] fnet = new double[2];
//
if (!f.developed)
{
//Console.WriteLine("{0}, {1}", f.name, (f.cap * f.cost - f.netWorth("worth")));
fnet[0] = (f.cap * f.cost - f.netWorth("worth"));
fnet[0] = fnet[0] / Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(fnet[0]))) - 2);
//fnet[0] = fnet[0] / Math.Pow(10, Math.Log10(fnet[0]) - 3);
l.Add(f.name + "_ud", fnet);
}
else if (f.developed)
{
//Console.WriteLine("{0}, {1}", f.name, (f.netWorth("worth") - 3 * f.netWorth("prod")));
fnet[0] = (f.netWorth("worth") - 3 * f.netWorth("prod"));
fnet[0] = fnet[0] / Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(fnet[0]))) - 2);
l.Add(f.name + "_sell", fnet);
if (f.type == "s")
{
//Main material calculation formula
//int x = -A + (A * (i+id) / Math.Pow(c, 1/2));
int A = f.mat.amount;
double i = f.mat.inflation;
double id = f.mat.inflation - f.mat.previnflation;
double x = -A + (A * (i + id) / Math.Pow(f.mat.cost, 1 / 2));
//Check for max/min amounts possible
if (x > f.cap * 1 / 4) { x = f.cap * 1 / 4; }
if (-x > n.invent[f.mat]) { x = -n.invent[f.mat]; }
fnet[0] = Math.Abs(x);
fnet[1] = x;
l.Add(f.name + "_store", fnet);
}
}
//Console.WriteLine(f.name + ": " + fnet[0].ToString() + ", " + fnet[1].ToString());
}
}
double[] npc = new double[2];
//NPC Calculations
//Sponsors act as essentially a deed that if the NPC goes bankrupt, the Sponsor will get all the debt
foreach (NPC m in Players)
{
if (m.name != n.name)
{
//Console.WriteLine(m.name + ", " + m.netWorth().ToString() + ", " + m.prevNet.ToString());
npc[0] = m.netWorth() - m.prevNet;
npc[0] = npc[0] / (1 + Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(npc[0]))) - 2));
l.Add(m.name + "_sponsor", npc);
}
}
//GoPublic & Others
if (!n.pub)
{
int mat = 0;
int split = 1000;
foreach (Material m in Materials) { mat += m.amount; }
split = mat / Materials.Count;
int keep = split / 2;
keep = Convert.ToInt32(keep * n.prevNet / n.netWorth());
double[] gp = new double[3];
gp[0] = n.netWorth() / (split - keep);
gp[1] = split;
gp[2] = keep;
l.Add(n.name, gp);
}
return l;
}
//Function, public String[]
//Returns the class and type of the named class member
public string[] getClass(string name)
{
string[] att = new string[2];
foreach (Material m in Materials)
{
if (m.name == name) { att[0] = "Material"; att[1] = m.type; }
}
foreach (Market m in LocList)
{
if (m.name == name) { att[0] = "Market"; att[1] = m.type; }
}
foreach (NPC m in Players)
{
if (m.name == name) { att[0] = "NPC"; att[1] = m.type; }
}
foreach (Facility m in Locs)
{
if (m.name == name) { att[0] = "Facility"; att[1] = m.type; }
}
return att;
}
//Function, public string[]
//Returns an array of the order of turns
public void createTurnOrder()
{
//Get total elements
count = Players.Count + Materials.Count + LocList.Count + Locs.Count;
order = new Dictionary<int, string>();
int x = 0;
foreach (NPC n in Players) { order.Add(x, n.name); x++; }
foreach (Material n in Materials) { order.Add(x, n.name); x++; }
foreach (Market n in LocList) { order.Add(x, n.name); x++; }
foreach (Facility n in Locs) { order.Add(x, n.name); x++; }
}
//Function, public string
//Returns a new name for the turn, based of a prescession of events, checks if time tick is over
public string changeTurn()
{
string x = "";
x = order[ordern];
ordern++;
if (ordern >= count) { ordern = 0; }
return x;
}
//Function, public void
//Sets the interface depending on who's turn it is
//Setting is the type of interface needed e.g 'player', 'map'
public void setInterface(string setting, NPC player = null) { }
}
public class Material
//A rescource that is meant to have several attributes, stored on a json file
{
public string name { get; set; }//String
public string type { get; set; }//String
//'r', 'c', 'sv' or 'm'
public double cost { get; set; }//Integer, constant
//The base price of the Material
public int influx { get; set; }//Integer, constant
//The rate at which more of that material enters the economy
public int amount { get; set; }//Integer, variable
//The amount of that material, unsold
public double inflation { get; set; }//Double, variable
//The base rate at which material prices rise, affected by influx and amount available
public int prevamount { get; set; }//Integer, variable
//The amount of that material, unsold
public double previnflation { get; set; }//Double, variable
//The base rate at which material prices rise, affected by influx and amount available
public int total { get; set; }//Integer, variable
//The amount of that material in total
public string anchor { get; set; } //String
//The Company or Party's attachment to that Material value (Only for type 'c')
public double anchornet = -0.1;
//The previous net worth of the anchor NPC (Only for type 'c')
public Dictionary<Material, int> craftable { get; set; }
//A dictionary of how it is produced (Only for type 'm')
//Function, public int
//Calculates the total amount of money an NPC, Market or Material holds in standard units
public double netWorth()
{
double net = cost * total;
return net;
}
}
public class Market
{
public string name { get; set; } //String
public string type { get; set; } //String
//'e', 'p'
public double markup { get; set; } //Integer, variable
//For markets, cost will help markup/markdown price of a material
public string anchor = ""; //String
//The anchor is a place that the location is tied to having their cost become affected by such
public Material currency { get; set; }
public List<Market> travel { get; set; }
//The places you can travel to from that market
public double prevNet { get; set; }
//Function, public int
//Calculates the total amount of money an NPC, Market or Material holds in standard units
public double netWorth(List<Facility> fl, Material mat = null)
{
double net = 0;
if (mat == null)
{
//foreach (Material m in n.invent.Keys)
//{
// //net += n.invent[m] * m.cost;
//}
foreach (Facility f in fl)
{
if (f.location.name == name)
{
net += f.cost;
}
}
}
else
{
//net += n.invent[mat] * mat.cost;
foreach (Facility f in fl)
{
if (f.location.name == name && f.mat == mat)
{
net += f.cost;
}
}
}
return net;
}
}
public class NPC
{
public string name { get; set; } //String
//Name of the NPC
public string type { get; set; } //String
//'p', 'c', 'i', 'pa', 'gov'
public int intellegence { get; set; } //Integer
//The way the NPC acts and makes descisions during a turn
public Dictionary<Material, int> invent { get; set; } //Dictionary<Material,int>
//All things owned by an NPC - Contains:
//Rescources (Material) - No. of Materials
//Currency (Material) - No. of locations, parties and companies
//the integer value is the amount held by the NPC
public string location { get; set; } //String
//Current location or base of operations for NPCs
public string sponsor { get; set; } //String array
//2 feilds, Company and Party, unique value
//Can only do such for public organisations
public string anchor { get; set; } //ONLY TYPE 'p'
public bool pub = false;
public double prevNet { get; set; }
//Function, public void
//Function that has 2 values to manage, add item or remove one (and their location in 2D array)
public void manageInvent(string operation, Material m = null, int amount = 0)
{
if (operation == "add") { invent[m] += amount; }
if (operation == "remove") { invent[m] -= amount; }
if (operation == "clear") { invent[m] = 0; }
if (operation == "clearall") { foreach (Material i in invent.Keys) { invent[i] = 0; } }
}
//Function, public void
//For each type, this will do certain things
//- Companies will create a new Material
//- Parties will join the election campaign, creating a new Material
//money is the total net worth of the company/party
//split only is needed for the company
//NOTE: Add after 'goPublic', order.Add(count, m); count + 1;
public Material goPublic(List<NPC> lnpc, int split = 1, int keep = 0)
{
string key = "";
Material m = new Material();
if (type == "p" || type == "i")
{
throw new Exception("Invalid input, type must be Company or Party");
}
if (type == "c" || type == "pa")
{
if (type == "c") { key = "Stock"; }
if (type == "pa") { key = "Votes"; }
m.name = name + "_mat";
m.type = key;
m.cost = netWorth() / split;
m.amount = split - keep;
m.total = split;
m.influx = 0;
m.anchor = name;
foreach (NPC n in lnpc)
{
if (n.name == name)
{
n.invent.Add(m, keep);