-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
214 lines (192 loc) · 10.4 KB
/
Program.cs
File metadata and controls
214 lines (192 loc) · 10.4 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
using System;
using Raylib_cs;
using System.IO;
using System.Collections.Generic;
using WorldTens.Map;
using WorldTens;
using WorldTens.Politics;
namespace WorldTens
{
class Program
{
public static int screenWidth;
public static int screenHeight;
public static uint iterations = 0;
public static uint iterTmp = 0;
public static uint iterMax = 200;
public static System.Numerics.Vector2 mouseSelPos;
public static System.Numerics.Vector2 mouseReleasePos;
private static int yearCalc = 0;
static void Main(string[] args)
{
string modelName = args.Length > 0 ? args[0] : "default";
string modelPath = "resources/models/" + modelName;
if (!File.Exists(modelPath + "/map.bmp") || !File.Exists(modelPath + "/spawn.yml")) {
Console.WriteLine("Wrong model title!");
return;
}
World world = new World(modelPath + "/map.bmp");
screenWidth = world.GetMapWidth();
screenHeight = world.GetMapHeight();
Raylib.InitWindow(screenWidth, screenHeight, "WorldTens");
string spawnYaml = System.IO.File.ReadAllText("resources/models/" + modelName + "/spawn.yml");
var deserializer = new YamlDotNet.Serialization.Deserializer();
CreationSet[] creationSets = deserializer.Deserialize<CreationSet[]>(spawnYaml);
for (int i = 0; i < creationSets.Length; i++) {
for (int j = 0; j < creationSets[i].count; j++) {
Creation creation = new Creation(new Vector2(
creationSets[i].posX, creationSets[i].posY
), creationSets[i].mind);
creation.politStatus = creationSets[i].politStatus;
creation.GetDetectorFirstTime(world).creations.Add(creation);
}
}
while (!Raylib.WindowShouldClose()) {
world.DecreaseTens(Raylib.GetFrameTime());
Raylib.BeginDrawing();
if (OperatingSystem.IsWindows() || args.Length < 2 || (args.Length > 1 && args[1] != "time")) {
Raylib.ClearBackground(Color.WHITE);
world.DrawOptimized();
Raylib.DrawText("Good luck in WorldTens!", 10, 10, 14, Color.BLACK);
Raylib.DrawText(iterations.ToString(), 0, screenHeight - 20, 20, Color.BLACK);
Raylib.DrawText(world.GetTension().ToString(), screenWidth - 100, 10, 20, Color.BLACK);
Raylib.DrawText("FPS: " + Raylib.GetFPS().ToString(), 350, 0, 20, Color.BLACK);
}
if (iterTmp >= iterMax || iterations == 0 || OperatingSystem.IsWindows() || (args.Length > 1 && args[1] == "redraw")) {
Raylib.ClearBackground(Color.WHITE);
for (int i = 0; i < world.map.Count; i++) {
for (int j = 0; j < world.map[i].Count; j++) {
world.DrawMapPixel(new Vector2(i, j));
}
}
Raylib.DrawText("Good luck in WorldTens!", 10, 10, 14, Color.BLACK);
Raylib.DrawText(iterations.ToString(), 0, screenHeight - 20, 20, Color.BLACK);
Raylib.DrawText(world.GetTension().ToString(), screenWidth - 100, 10, 20, Color.BLACK);
Raylib.DrawText("FPS: " + Raylib.GetFPS().ToString(), 350, 0, 20, Color.BLACK);
iterTmp = 0;
}
for (int i = 0; i < world.detectors.Count; i++) {
int citizensCounter = 0;
List<Creation> citizens = new List<Creation>();
for (int j = 0; j < world.detectors[i].creations.Count; j++) {
Creation creation = world.detectors[i].creations[j];
//if (world.map[creation.position.x][creation.position.y].city) {
citizensCounter++;
citizens.Add(creation);
//}
Vector2 prevPos = new Vector2(creation.position.x, creation.position.y);
creation.DoAction(Raylib.GetFrameTime(), world);
world.DrawMapPixel(prevPos);
world.DrawMapPixel(creation.position);
if (creation.alive) {
Raylib.DrawPixel(creation.position.x, creation.position.y, Color.RED);
}
else {
Raylib.DrawPixel(creation.position.x, creation.position.y, Color.BROWN);
world.detectors[i].creations.Remove(creation);
}
}
if (citizensCounter > 2) {
if (world.countries.Count == 0) {
world.CreateCountry(citizens, i);
}
int enemyCounter = 0;
int citizenCounter = 0;
foreach (Creation citizen in citizens) {
if (citizen.country == null && world.detectors[i].country == null) {
world.CreateCountry(citizens, i);
}
if (world.detectors[i].country == citizen.country) {
citizenCounter++;
}
else {
enemyCounter++;
}
}
if (enemyCounter > citizenCounter) {
Country dominator = null;
foreach (Creation citizen in citizens) {
if (citizen.country != world.detectors[i].country) {
world.detectors[i].country = citizen.country;
dominator = citizen.country;
break;
}
}
foreach (Creation citizen in citizens) {
if (citizen.country != world.detectors[i].country) {
citizen.country = world.detectors[i].country;
}
}
if (dominator == null) {
world.CreateCountry(citizens, i);
}
Console.WriteLine("territory captured");
}
}
if (world.year != yearCalc) {
foreach (Country country in world.countries) {
if (world.detectors[i].country == country) {
country.CalculateWars(world);
country.CalculateRequirements(world);
country.ExecuteRequirements(citizens);
}
}
}
citizens = null;
}
if (world.year != yearCalc) {
yearCalc = world.year;
}
iterations++;
iterTmp++;
world.AddTime();
if (Raylib.IsKeyDown(KeyboardKey.KEY_KP_MULTIPLY)) {
world.IncreaseTens(100, world.countries[0]);
}
if (Raylib.IsKeyDown(KeyboardKey.KEY_J)) {
Console.WriteLine(world.GetTension());
}
if (Raylib.IsKeyDown(KeyboardKey.KEY_K)) {
foreach (MapDetectorSquare detector in world.detectors) {
if (detector.country != null) {
Random random = new Random(detector.country.ident);
int red = random.Next(255);
int blue = new Random(detector.country.blue).Next(255);
int green = new Random(detector.country.green).Next(255);
Raylib.DrawRectangle(detector.position.x, detector.position.y, detector.wh.x, detector.wh.y, new Color(red, blue, green, 100));
}
}
}
if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) {
mouseSelPos = Raylib.GetMousePosition();
}
if (Raylib.IsMouseButtonReleased(MouseButton.MOUSE_LEFT_BUTTON)) {
mouseReleasePos = Raylib.GetMousePosition();
Rectangle rect = new Rectangle(mouseSelPos.X, mouseReleasePos.Y, Math.Abs(mouseReleasePos.X - mouseSelPos.X), Math.Abs(mouseReleasePos.Y - mouseSelPos.Y));
foreach (MapDetectorSquare detector in world.detectors) {
foreach (Creation creation in detector.creations) {
if (Raylib.CheckCollisionPointRec(new System.Numerics.Vector2(creation.position.x, creation.position.y), rect)) {
if (creation.country != null) {
Console.WriteLine("Country: " + creation.country.ident);
}
else {
Console.WriteLine("Country: null");
}
Console.WriteLine("PolitStatus: " + creation.politStatus);
Vector2 dest = creation.GetDesination();
if (dest != null) {
Console.WriteLine("Destination: {0}, {1}", dest.x, dest.y);
}
else {
Console.WriteLine("Destination: None");
}
}
}
}
}
Raylib.EndDrawing();
}
Raylib.CloseWindow();
}
}
}