1 | using System; // Tämän tarpeellisuus pitäisi olla itsestäänselvyys |
---|
2 | using Jypeli; // Jypeli |
---|
3 | using Jypeli.ScreenObjects; // Jypeli.ScreenObjects |
---|
4 | using Jypeli.Assets; // Jypeli.Assets |
---|
5 | using System.Collections.Generic; // Jypelin tutoriaali |
---|
6 | using System.IO; // Streamreader vaatii tämän |
---|
7 | using System.Windows.Forms; // jotta voin näyttää msgboxeja |
---|
8 | using ALTKTechs; // Avaruuslaatikon moottorikomponentit |
---|
9 | using ALTKUnits; |
---|
10 | using ALTKCiv; |
---|
11 | using ALTKPromotions; |
---|
12 | using ALTKDiff; |
---|
13 | using ALTKAIBehaviour; |
---|
14 | using BaseRules; // Avaruuslaatikon sääntötiedosto, helpottaa modien tekemistä |
---|
15 | |
---|
16 | namespace ALTKTileEngine |
---|
17 | { |
---|
18 | public class Peli : Game |
---|
19 | { |
---|
20 | bool gamestarted = false; |
---|
21 | int currDiffLevel; // jotta tätä voidaan käyttää missä tahansa |
---|
22 | |
---|
23 | int[,] TerrainMap; // perusmaastokartta |
---|
24 | int[,] DTerrainMap; // erikoismaastokartta |
---|
25 | int[,] OwnershipMap; // ruudukon omistuskartta (kenen pelaajan hallinnassa on mikäkin ruutu) |
---|
26 | int[,] ShroudMap; // pelaajan näkymää pienentävä Shroudmap |
---|
27 | |
---|
28 | string Textpath; |
---|
29 | string OwnershipColorPath; |
---|
30 | |
---|
31 | int AmountofPlayers; // Ihmispelaajien määrä, tällä hetkellä peli tukee vain yhtä |
---|
32 | int TurnNumber; // vuoron numero |
---|
33 | int CurrProduction; // pelaajan tämänhetkinen tuotanto |
---|
34 | |
---|
35 | // !!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
36 | // Pitänee tehdä vielä yksi ALTKSUnit-namespace ALTKCoreen. |
---|
37 | // Tämä sisältäisi tiedot yksiköiden omistajasta, yksikön perusyksiköstä ym. sekä myös karttakoordinaatit |
---|
38 | // (karttakoordinaatit säilyttää myös UnitMap, josta on helppo tarkastaa esim. liikuttaessa yksiköitä, onko ruudussa jo esim. vihollisyksiköitä. |
---|
39 | |
---|
40 | TextDisplay TileDisp; |
---|
41 | TextDisplay UnitStatsDisp; |
---|
42 | TextDisplay ProductionDisp; |
---|
43 | |
---|
44 | int kartanLeveys; |
---|
45 | int kartanKorkeus; |
---|
46 | |
---|
47 | // perusmaastotyypit |
---|
48 | const int Aavikko = 2, Tundra = 3, Vuoristo = 1, Lehtimetsa = 0; |
---|
49 | |
---|
50 | // erikoismaastotyypit |
---|
51 | const int Havumetsa = 2, Tyhja = 0, Kuusimetsa = 3; |
---|
52 | |
---|
53 | // Pelissä on kaksi eri tasoa, toisella perusmaasto ja toisella tarkempaa tietoa (esim. onko ruutu metsää ym.) |
---|
54 | GameObject[,] tile; |
---|
55 | GameObject[,] DTile; |
---|
56 | GameObject[,] TileOwnership; |
---|
57 | GameObject[,] ShroudTile; |
---|
58 | //Vector tileVector; |
---|
59 | |
---|
60 | Vector CamSpeedEast = new Vector(20.0, .0); |
---|
61 | Vector CamSpeedWest = new Vector(-20.0, .0); |
---|
62 | Vector CamSpeedNorth = new Vector(.0, 20.0); |
---|
63 | Vector CamSpeedSouth = new Vector(.0, -20.0); |
---|
64 | |
---|
65 | // Käytän ennemmin enemmän muistia kuin prosessoria, joten lasken nämä jo täällä |
---|
66 | int MouseScreenWidth; |
---|
67 | int MouseScreenHeight; |
---|
68 | int NegMouseScreenWidth; |
---|
69 | int NegMouseScreenHeight; |
---|
70 | # region Aloitusruutuvalikko |
---|
71 | protected override void Begin() |
---|
72 | { |
---|
73 | //SetWindowSize(true); |
---|
74 | Textpath = Application.StartupPath + "\\Content\\Textures\\"; |
---|
75 | OwnershipColorPath = Textpath + "Ownership\\"; |
---|
76 | InitRules(); |
---|
77 | InitStartMenu(); |
---|
78 | //InitControls(); |
---|
79 | //InitMap(); |
---|
80 | } |
---|
81 | void InitStartMenu() |
---|
82 | { |
---|
83 | Level.BackgroundColor = Color.Gray; |
---|
84 | Mouse.Enabled = true; |
---|
85 | Mouse.IsCursorVisible = true; |
---|
86 | |
---|
87 | InputQueryWindow input = new InputQueryWindow(); |
---|
88 | input.InputConfirmed += Player_SetName; |
---|
89 | input.QueryText.Text = "Kirjoita valtiosi nimi:"; |
---|
90 | input.Size = new Vector(300.0, 100.0); |
---|
91 | input.Position = new Vector(-250.0, 350.0); |
---|
92 | input.InputBox.BorderColor = Color.GreenYellow; |
---|
93 | ShowWindow(input); |
---|
94 | |
---|
95 | GameObject TrainingButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
96 | GameObject EasyButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
97 | GameObject NormalButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
98 | GameObject HardButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
99 | GameObject VHardButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
100 | GameObject NightmareButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
101 | GameObject InsanityButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
102 | |
---|
103 | for (int a = 0; a <= 6; a++) |
---|
104 | { |
---|
105 | if (a == 0) { SetDiffButton(TrainingButton, 0); } |
---|
106 | if (a == 1) { SetDiffButton(EasyButton, 1); } |
---|
107 | if (a == 2) { SetDiffButton(NormalButton, 2); } |
---|
108 | if (a == 3) { SetDiffButton(HardButton, 3); } |
---|
109 | if (a == 4) { SetDiffButton(VHardButton, 4); } |
---|
110 | if (a == 5) { SetDiffButton(NightmareButton, 5); } |
---|
111 | if (a == 6) { SetDiffButton(InsanityButton, 6); } |
---|
112 | } |
---|
113 | Mouse.ListenOn(TrainingButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 0); |
---|
114 | Mouse.ListenOn(EasyButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 1); |
---|
115 | Mouse.ListenOn(NormalButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 2); |
---|
116 | Mouse.ListenOn(HardButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 3); |
---|
117 | Mouse.ListenOn(VHardButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 4); |
---|
118 | Mouse.ListenOn(NightmareButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 5); |
---|
119 | Mouse.ListenOn(InsanityButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 6); |
---|
120 | } |
---|
121 | |
---|
122 | void Player_SetName(InputQueryWindow sender, string input) |
---|
123 | { |
---|
124 | Rules.pCivs[0].Name = input; |
---|
125 | Rules.pCivs[0].HumanPlayer = true; |
---|
126 | Rules.pCivs[0].Enabled = true; |
---|
127 | Rules.pCivs[0].Color = "red"; |
---|
128 | } |
---|
129 | |
---|
130 | void SetDiffButton(GameObject diffbutton, int difflevel) |
---|
131 | { |
---|
132 | diffbutton.X = 250; |
---|
133 | diffbutton.Y = ((difflevel * -50) + 300); |
---|
134 | if (difflevel == 0) { diffbutton.Image = LoadImage(Textpath + "training"); } |
---|
135 | else if (difflevel == 1) { diffbutton.Image = LoadImage(Textpath + "easy"); } |
---|
136 | else if (difflevel == 2) { diffbutton.Image = LoadImage(Textpath + "normal"); } |
---|
137 | else if (difflevel == 3) { diffbutton.Image = LoadImage(Textpath + "hard"); } |
---|
138 | else if (difflevel == 4) { diffbutton.Image = LoadImage(Textpath + "vhard"); } |
---|
139 | else if (difflevel == 5) { diffbutton.Image = LoadImage(Textpath + "nightmare"); } |
---|
140 | else if (difflevel == 6) { diffbutton.Image = LoadImage(Textpath + "insanity"); } |
---|
141 | Add(diffbutton); |
---|
142 | //return diffbutton; |
---|
143 | } |
---|
144 | |
---|
145 | void SelectDifficulty(int difflevel) |
---|
146 | { |
---|
147 | ClearAll(); |
---|
148 | currDiffLevel = new int(); |
---|
149 | currDiffLevel = difflevel; |
---|
150 | InitControls(); |
---|
151 | InitMap(); |
---|
152 | gamestarted = true; |
---|
153 | } |
---|
154 | # endregion |
---|
155 | # region Kartan luominen |
---|
156 | |
---|
157 | void InitMap() |
---|
158 | { |
---|
159 | TurnNumber = new int(); |
---|
160 | AmountofPlayers = new int(); |
---|
161 | Int32 i; |
---|
162 | Int32 j; |
---|
163 | string mLine; |
---|
164 | TextReader bReader; |
---|
165 | bReader = new StreamReader("Content\\Maps\\1\\base.txt"); |
---|
166 | //try |
---|
167 | //{ |
---|
168 | |
---|
169 | // Yleensä kartan kaksi ensimmäistä riviä ovat kommentteja |
---|
170 | bReader.ReadLine(); |
---|
171 | bReader.ReadLine(); |
---|
172 | |
---|
173 | kartanLeveys = Convert.ToInt32(bReader.ReadLine().Substring(9, 2)); |
---|
174 | kartanKorkeus = Convert.ToInt32(bReader.ReadLine().Substring(10, 2)); |
---|
175 | |
---|
176 | Int32 mapWidthJ = (kartanLeveys * 48) / 2; |
---|
177 | Int32 mapHeightJ = (kartanKorkeus * 48) / 2; |
---|
178 | |
---|
179 | bReader.ReadLine(); |
---|
180 | // Ladataan TerrainMapit muistiin myöhempää käyttöä varten |
---|
181 | |
---|
182 | TerrainMap = new int[kartanKorkeus, kartanLeveys]; |
---|
183 | DTerrainMap = new int[kartanKorkeus, kartanLeveys]; |
---|
184 | OwnershipMap = new int[kartanKorkeus, kartanLeveys]; |
---|
185 | ShroudMap = new int[kartanKorkeus, kartanLeveys]; |
---|
186 | InitTerrain(0); |
---|
187 | InitTerrain(1); |
---|
188 | InitTerrain(2); |
---|
189 | InitTerrain(3); |
---|
190 | |
---|
191 | tile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
192 | DTile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
193 | TileOwnership = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
194 | ShroudTile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
195 | InitTerrainGraphics(0); |
---|
196 | InitTerrainGraphics(1); |
---|
197 | InitTerrainGraphics(2); |
---|
198 | InitTerrainGraphics(3); |
---|
199 | |
---|
200 | // Koodi käännetty RGE:n VB.netistä |
---|
201 | // Asettaa ja piirtää pohjamaaston |
---|
202 | |
---|
203 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
204 | { |
---|
205 | mLine = bReader.ReadLine(); |
---|
206 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
207 | { |
---|
208 | // MessageBox.Show(mLine + " " + j + " " + i); |
---|
209 | tile[i, j].Shape = Shapes.Rectangle; |
---|
210 | tile[i, j].X = (j * 48) - mapWidthJ; |
---|
211 | tile[i, j].Y = (i * 48) - mapHeightJ; |
---|
212 | TerrainMap[i, j] = getTerrainType(mLine.Substring(j, 1), 0, i, j); |
---|
213 | tile[i, j].Image = LoadImage(getTexture_fromTerrainType(TerrainMap[i, j], 0, i, j)); |
---|
214 | Add(tile[i, j]); |
---|
215 | |
---|
216 | //Mouse.ListenMovement(tile[i, j], showTileInfo_forTileDisp, null, i, j); |
---|
217 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | // Luetaan karttatiedoston rivivälit |
---|
222 | bReader.ReadLine(); |
---|
223 | bReader.ReadLine(); |
---|
224 | |
---|
225 | // Rami 16. 6. 2010: Omistuskartta pitää sittenkin säätää ennen erikoismaastoa, sillä |
---|
226 | // kaupungit ja omistusrinki piirretään erikoismaaston asettamiskoodin kutsusta |
---|
227 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
228 | { |
---|
229 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
230 | { |
---|
231 | // MessageBox.Show(mLine + " " + j + " " + i); |
---|
232 | OwnershipMap[i, j] = -1; |
---|
233 | TileOwnership[i, j].Shape = Shapes.Rectangle; |
---|
234 | TileOwnership[i, j].X = (j * 48) - mapWidthJ; |
---|
235 | TileOwnership[i, j].Y = (i * 48) - mapHeightJ; |
---|
236 | //TileOwnership[i, j].Image = LoadImage(Textpath + "nothing"); poistettu optimisoinnin takia |
---|
237 | //Add(TileOwnership[i, j]); eihän näitä tarvitse vielä lisätä, optimisointia |
---|
238 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
239 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | // Initialisoidaan Shroudmap |
---|
244 | |
---|
245 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
246 | { |
---|
247 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
248 | { |
---|
249 | ShroudMap[i, j] = 1; |
---|
250 | ShroudTile[i, j].Shape = Shapes.Rectangle; |
---|
251 | ShroudTile[i, j].X = (j * 48) - mapWidthJ; |
---|
252 | ShroudTile[i, j].Y = (i * 48) - mapHeightJ; |
---|
253 | ShroudTile[i, j].Image = LoadImage(Textpath + "fogofwar"); |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | // Asettaa ja piirtää erikoismaaston |
---|
258 | |
---|
259 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
260 | { |
---|
261 | mLine = bReader.ReadLine(); |
---|
262 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
263 | { |
---|
264 | DTile[i, j].Shape = Shapes.Rectangle; |
---|
265 | DTile[i, j].X = (j * 48) - mapWidthJ; |
---|
266 | DTile[i, j].Y = (i * 48) - mapHeightJ; |
---|
267 | DTerrainMap[i, j] = getTerrainType(mLine.Substring(j, 1), 1, i, j); |
---|
268 | DTile[i, j].Image = LoadImage(getTexture_fromTerrainType(DTerrainMap[i, j], 1, i, j)); |
---|
269 | Add(DTile[i, j]); |
---|
270 | if (getTexture_fromTerrainType(DTerrainMap[i, j], 1, i, j).Contains("city")) |
---|
271 | { |
---|
272 | DrawOwnership(i, j); |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | // Piirretään ShroudTile vasta tässä, jotta se olisi DTilen päällä |
---|
278 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
279 | { |
---|
280 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
281 | { |
---|
282 | if (ShroudMap[i, j] == 1) |
---|
283 | { |
---|
284 | Add(ShroudTile[i, j]); |
---|
285 | } |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | //catch |
---|
290 | //{ |
---|
291 | // MessageBox.Show("Map error!"); |
---|
292 | // bReader.Close(); |
---|
293 | // Exit(); |
---|
294 | //} |
---|
295 | bReader.Close(); |
---|
296 | //for (int playernumber = 0; playernumber <= 30; playernumber++) |
---|
297 | //{ |
---|
298 | // Rules.pCivs[playernumber].Color = setAIOwnershipColor(playernumber); |
---|
299 | //} |
---|
300 | Level.BackgroundColor = Color.Black; |
---|
301 | InitGUI(); |
---|
302 | TurnSystem_Start(0); // Antaa pelin alkaa! |
---|
303 | } |
---|
304 | |
---|
305 | private void InitGUI() |
---|
306 | { |
---|
307 | TileDisp = new TextDisplay(); |
---|
308 | TileDisp.X = Screen.Left + 120; |
---|
309 | TileDisp.Y = Screen.Bottom + 200; |
---|
310 | TileDisp.TextColor = Color.White; |
---|
311 | |
---|
312 | UnitStatsDisp = new TextDisplay(); |
---|
313 | UnitStatsDisp.X = Screen.Left + 120; |
---|
314 | UnitStatsDisp.Y = Screen.Bottom + 300; |
---|
315 | UnitStatsDisp.Text = "d23"; |
---|
316 | UnitStatsDisp.TextColor = Color.DarkRed; |
---|
317 | |
---|
318 | ProductionDisp = new TextDisplay(); |
---|
319 | ProductionDisp.X = Screen.Right - 150; |
---|
320 | ProductionDisp.Y = Screen.Top - 50; |
---|
321 | ProductionDisp.Text = "Tuotanto: 10/120"; |
---|
322 | ProductionDisp.TextColor = Color.Wheat; |
---|
323 | |
---|
324 | Add(TileDisp); |
---|
325 | Add(UnitStatsDisp); |
---|
326 | Add(ProductionDisp); |
---|
327 | } |
---|
328 | |
---|
329 | private void InitTerrain(int tlayer) |
---|
330 | { |
---|
331 | for (int a = 0; a <= (kartanKorkeus - 1); a++) |
---|
332 | { |
---|
333 | for (int b = 0; b <= (kartanLeveys - 1); b++) |
---|
334 | { |
---|
335 | GetTerrainLayer(tlayer)[a, b] = new int(); |
---|
336 | } |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | int[,] GetTerrainLayer(int tlayer) |
---|
341 | { |
---|
342 | if (tlayer == 0) { return TerrainMap; } |
---|
343 | if (tlayer == 1) { return DTerrainMap; } |
---|
344 | if (tlayer == 2) { return OwnershipMap; } |
---|
345 | if (tlayer == 3) { return ShroudMap; } |
---|
346 | return TerrainMap; |
---|
347 | } |
---|
348 | |
---|
349 | private void InitTerrainGraphics(int tlayer) |
---|
350 | { |
---|
351 | for (int a = 0; a <= (kartanKorkeus - 1); a++) |
---|
352 | { |
---|
353 | for (int b = 0; b <= (kartanLeveys - 1); b++) |
---|
354 | { |
---|
355 | GetGraphicsLayer(tlayer)[a, b] = new PhysicsObject(48.0, 48.0); |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | GameObject[,] GetGraphicsLayer(int tlayer) |
---|
361 | { |
---|
362 | if (tlayer == 0) {return tile; } |
---|
363 | if (tlayer == 1) {return DTile; } |
---|
364 | if (tlayer == 2) { return TileOwnership; } |
---|
365 | if (tlayer == 3) { return ShroudTile; } |
---|
366 | return tile; |
---|
367 | } |
---|
368 | |
---|
369 | int getTerrainType(string ch, int terrainlayer, int i, int j) |
---|
370 | { |
---|
371 | if (terrainlayer == 0) |
---|
372 | { |
---|
373 | /*/ Maastotyypit |
---|
374 | * 0 = lehtimetsää |
---|
375 | * 1 = vuoristoa |
---|
376 | * 2 = aavikkoa |
---|
377 | * 3 = tundraa |
---|
378 | /*/ |
---|
379 | if (ch == " ") { return Lehtimetsa; } |
---|
380 | if (ch == "V") { return Vuoristo; } |
---|
381 | if (ch == "A") { return Aavikko; } |
---|
382 | if (ch == "T") { return Tundra; } |
---|
383 | } |
---|
384 | else if (terrainlayer == 1) |
---|
385 | { |
---|
386 | /*/ Erikoismaastotyypit |
---|
387 | * 0 = ei mitään |
---|
388 | * 1 = vuoristoa |
---|
389 | * 2 = metsää |
---|
390 | * 3 = kuusimetsää |
---|
391 | /*/ |
---|
392 | if (ch == " ") { return Tyhja; } |
---|
393 | if (ch == "M") { return Havumetsa; } |
---|
394 | if (ch == "V") { return Vuoristo; } |
---|
395 | if (ch == "K") { return Kuusimetsa; } |
---|
396 | try |
---|
397 | { |
---|
398 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
399 | int Playerstartloc; |
---|
400 | Playerstartloc = Convert.ToInt32(ch); |
---|
401 | AmountofPlayers = AmountofPlayers + 1; |
---|
402 | AddStartingCity(Playerstartloc, i, j); |
---|
403 | return (Playerstartloc + 10); |
---|
404 | } |
---|
405 | catch |
---|
406 | { |
---|
407 | } |
---|
408 | return Tyhja; |
---|
409 | } |
---|
410 | return 0; |
---|
411 | } |
---|
412 | |
---|
413 | private void DrawOwnership(int i, int j) |
---|
414 | { |
---|
415 | if (ShroudMap[i, j] == 0) |
---|
416 | { |
---|
417 | TileOwnership[i, j].Image = LoadImage(OwnershipColorPath + Rules.pCivs[OwnershipMap[i, j]].Color); |
---|
418 | Add(TileOwnership[i, j]); |
---|
419 | } |
---|
420 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
421 | } |
---|
422 | |
---|
423 | private void AddStartingCity(int playernumber, int i, int j) |
---|
424 | { |
---|
425 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
426 | Rules.pCivs[playernumber].Production = Rules.pCivs[playernumber].Production + 10; |
---|
427 | Rules.pCivs[playernumber].NumberofCities = Rules.pCivs[playernumber].NumberofCities + 1; |
---|
428 | Rules.pCivs[playernumber].CityCoords[Rules.pCivs[playernumber].NumberofCities, 0] = i; |
---|
429 | Rules.pCivs[playernumber].CityCoords[Rules.pCivs[playernumber].NumberofCities, 1] = j; |
---|
430 | if (Rules.pCivs[playernumber].HumanPlayer == false) |
---|
431 | { |
---|
432 | Rules.pCivs[playernumber].Color = setAIOwnershipColor(playernumber); |
---|
433 | Rules.pCivs[playernumber].Enabled = true; |
---|
434 | Rules.pCivs[playernumber].Name = Rules.pCivs[playernumber].Color + " " + "Empire"; |
---|
435 | } |
---|
436 | else |
---|
437 | { |
---|
438 | RemoveShroud(i, j); |
---|
439 | for (int shri = i - 2; shri <= i + 2; shri++) |
---|
440 | { |
---|
441 | for (int shrj = j - 2; shrj <= j + 2; shrj++) |
---|
442 | { |
---|
443 | RemoveShroud(shri, shrj); |
---|
444 | } |
---|
445 | } |
---|
446 | } |
---|
447 | OwnershipMap[i, j] = playernumber; |
---|
448 | // 16. 6. 2010: Kutsutaanpa DrawOwnership sittenkin vasta kaupungin piirtämisen jälkeen (ks. InitMap ja DTilen asettaminen) |
---|
449 | //DrawOwnership(i, j); |
---|
450 | |
---|
451 | //DTile[i, j].Image = LoadImage("\\Content\\Textures\\cityancient"); |
---|
452 | } |
---|
453 | |
---|
454 | public string setAIOwnershipColor(int playernumber) |
---|
455 | { |
---|
456 | int c; |
---|
457 | int b; |
---|
458 | bool ColorInUse = false; |
---|
459 | for (b = 0; b <= 20; b++) |
---|
460 | { |
---|
461 | ColorInUse = false; |
---|
462 | for (c = 0; c <= 30; c++) |
---|
463 | { |
---|
464 | if (Rules.pCivs[c].Color == getOwnershipColor_fromInt(b)) |
---|
465 | { |
---|
466 | ColorInUse = true; |
---|
467 | } |
---|
468 | } |
---|
469 | if (ColorInUse == false) |
---|
470 | { |
---|
471 | return getOwnershipColor_fromInt(b); |
---|
472 | } |
---|
473 | } |
---|
474 | return getOwnershipColor_fromInt(0); |
---|
475 | } |
---|
476 | |
---|
477 | public string getOwnershipColor_fromInt(Int32 color) |
---|
478 | { |
---|
479 | if (color == 0) { return "Aqua"; } |
---|
480 | if (color == 1) { return "Beige"; } |
---|
481 | if (color == 2) { return "Limegreen"; } |
---|
482 | if (color == 3) { return "Orange"; } |
---|
483 | if (color == 4) { return "Black"; } |
---|
484 | if (color == 5) { return "Red"; } |
---|
485 | if (color == 6) { return "Rustred"; } |
---|
486 | if (color == 7) { return "Yellow"; } |
---|
487 | if (color == 8) { return "Blue"; } |
---|
488 | if (color == 9) { return "Darkblue"; } |
---|
489 | if (color == 10) { return "Darkgreen"; } |
---|
490 | if (color == 11) { return "Lightblue"; } |
---|
491 | if (color == 12) { return "Purple"; } |
---|
492 | if (color == 13) { return "Darkpurple"; } |
---|
493 | if (color == 14) { return "Lightpurple"; } |
---|
494 | if (color == 15) { return "Gold"; } |
---|
495 | if (color == 16) { return "Silver"; } |
---|
496 | if (color == 17) { return "Pink"; } |
---|
497 | if (color == 18) { return "Teal"; } |
---|
498 | if (color == 19) { return "Greenyellow"; } |
---|
499 | if (color == 20) { return "Darkorange"; } |
---|
500 | if (color == 21) { return "White"; } |
---|
501 | if (color == 22) { return "Darkgray"; } |
---|
502 | return "Aqua"; |
---|
503 | } |
---|
504 | |
---|
505 | string getTexture_fromTerrainType(int terraintype, int terrainlayer, int i, int j) |
---|
506 | { |
---|
507 | if (terrainlayer == 0) |
---|
508 | { |
---|
509 | if (terraintype == Lehtimetsa) { return Application.StartupPath + "\\Content\\Textures\\grassland"; } |
---|
510 | if (terraintype == Vuoristo) { return Application.StartupPath + "\\Content\\Textures\\mountain"; } |
---|
511 | if (terraintype == Aavikko) { return Application.StartupPath + "\\Content\\Textures\\desert"; } |
---|
512 | if (terraintype == Tundra) { return Application.StartupPath + "\\Content\\Textures\\tundra"; } |
---|
513 | } |
---|
514 | else if (terrainlayer == 1) |
---|
515 | { |
---|
516 | if (terraintype == Tyhja) { return Application.StartupPath + "\\Content\\Textures\\nothing"; } |
---|
517 | if (terraintype == Vuoristo) { return Application.StartupPath + "\\Content\\Textures\\mountain"; } |
---|
518 | if (terraintype == Havumetsa) { return Application.StartupPath + "\\Content\\Textures\\forest"; } |
---|
519 | if (terraintype == Kuusimetsa) |
---|
520 | { |
---|
521 | if (TerrainMap[i, j] == 3) |
---|
522 | { |
---|
523 | return Application.StartupPath + "\\Content\\Textures\\spruceforestS"; |
---|
524 | } |
---|
525 | else |
---|
526 | { |
---|
527 | return Application.StartupPath + "\\Content\\Textures\\spruceforest"; |
---|
528 | } |
---|
529 | } |
---|
530 | // Jos terraintype on 10 tai enemmän, ruudussa on pelaajan kaupunki (ks. getTerrainType) |
---|
531 | if (terraintype >= 10) |
---|
532 | { |
---|
533 | if (TerrainMap[i, j] == Tundra) |
---|
534 | { |
---|
535 | return Application.StartupPath + "\\Content\\Textures\\cityancientTundra"; |
---|
536 | //DrawOwnership(i, j); |
---|
537 | } |
---|
538 | else |
---|
539 | { |
---|
540 | return Application.StartupPath + "\\Content\\Textures\\cityancient"; |
---|
541 | } |
---|
542 | } |
---|
543 | return Application.StartupPath + "\\Content\\Textures\\nothing"; |
---|
544 | } |
---|
545 | return Application.StartupPath + "\\Content\\Textures\\grassland.jpg"; |
---|
546 | } |
---|
547 | # endregion |
---|
548 | |
---|
549 | private void InitRules() |
---|
550 | { |
---|
551 | // Käytetään valmiiksi tehtyjä DLL-tiedostoja |
---|
552 | BaseRules.Rules.InitTechs(); |
---|
553 | BaseRules.Rules.InitUnits(); |
---|
554 | BaseRules.Rules.InitDifficulty(); |
---|
555 | BaseRules.Rules.InitCivs(); |
---|
556 | BaseRules.Rules.InitAIBehaviour(); |
---|
557 | } |
---|
558 | |
---|
559 | private void RemoveShroud(int i, int j) |
---|
560 | { |
---|
561 | ShroudMap[i, j] = 0; |
---|
562 | ShroudTile[i, j].Destroy(); |
---|
563 | try |
---|
564 | { |
---|
565 | if (OwnershipMap[i, j] > -1) |
---|
566 | { |
---|
567 | DrawOwnership(i, j); |
---|
568 | } |
---|
569 | } |
---|
570 | catch |
---|
571 | { |
---|
572 | } |
---|
573 | } |
---|
574 | |
---|
575 | private void TurnSystem_Start(int playernumber) |
---|
576 | { |
---|
577 | TurnNumber = TurnNumber + 1; |
---|
578 | ProductionDisp.Text = "Vuoro: " + TurnNumber + Environment.NewLine + |
---|
579 | "Tuotantoa vuorossa: " + Rules.pCivs[playernumber].Production + Environment.NewLine + |
---|
580 | "Tuotantoa jäljellä: " + CurrProduction; |
---|
581 | } |
---|
582 | |
---|
583 | protected override void Update(Time time) |
---|
584 | { |
---|
585 | base.Update(time); |
---|
586 | // Mouse.PositionOnScreen voisi olla vain positiivinen, eikä ruudun pitäisi jakautua keskeltä kahtia |
---|
587 | // negatiivisiin ja positiivisiin kokonaislukuihin |
---|
588 | |
---|
589 | if (gamestarted == true) |
---|
590 | { |
---|
591 | for (int i = 0; i <= (kartanKorkeus - 1); i++) |
---|
592 | { |
---|
593 | for (int j = 0; j <= (kartanLeveys - 1); j++) |
---|
594 | { |
---|
595 | if (Mouse.IsCursorOnGameObject(tile[i, j])) |
---|
596 | { |
---|
597 | TileDisp.Text = getTileInfo_forTileDisp(i, j); |
---|
598 | } |
---|
599 | //Mouse.ListenMovement(tile[i, j], showTileInfo_forTileDisp, null, i, j); |
---|
600 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
601 | } |
---|
602 | } |
---|
603 | //TileDisp.Text = getTileInfo_forTileDisp(Convert.ToInt32(Mouse.PositionOnWorld.X) / -48, Convert.ToInt32(Mouse.PositionOnWorld.Y) / 48); |
---|
604 | if (Mouse.PositionOnScreen.X > MouseScreenWidth) { MoveCamera(0); } |
---|
605 | else if (Mouse.PositionOnScreen.X < NegMouseScreenWidth) { MoveCamera(2); } |
---|
606 | else if (Mouse.PositionOnScreen.Y > MouseScreenHeight) { MoveCamera(1); } |
---|
607 | else if (Mouse.PositionOnScreen.Y < NegMouseScreenHeight) { MoveCamera(3); } |
---|
608 | } |
---|
609 | } |
---|
610 | |
---|
611 | public string getTileInfo_forTileDisp(int i, int j) |
---|
612 | { |
---|
613 | // Haetaan tiedot ruudulle |
---|
614 | string tileinfo; |
---|
615 | int Defensebonus = new int(); |
---|
616 | tileinfo = " "; |
---|
617 | //MessageBox.Show(i + " " + j); |
---|
618 | // Maaston perustiedot |
---|
619 | if (TerrainMap[i, j] == 0) |
---|
620 | { |
---|
621 | tileinfo = "Ruohotasankoa"; |
---|
622 | } |
---|
623 | else if (TerrainMap[i, j] == 1) |
---|
624 | { |
---|
625 | tileinfo = "Vuoristoa"; |
---|
626 | } |
---|
627 | else if (TerrainMap[i, j] == 2) |
---|
628 | { |
---|
629 | tileinfo = "Aavikkoa"; |
---|
630 | Defensebonus = Defensebonus - 25; |
---|
631 | } |
---|
632 | else if (TerrainMap[i, j] == 3) |
---|
633 | { |
---|
634 | tileinfo = "Tundraa"; |
---|
635 | Defensebonus = Defensebonus + 10; |
---|
636 | } |
---|
637 | |
---|
638 | // Erikoismaaston tiedot |
---|
639 | |
---|
640 | if (DTerrainMap[i, j] == 0) |
---|
641 | { |
---|
642 | } |
---|
643 | else if (DTerrainMap[i, j] == 1) |
---|
644 | { |
---|
645 | tileinfo = tileinfo + Environment.NewLine + "Vuoristoa" + Environment.NewLine + "Läpipääsemätön"; |
---|
646 | } |
---|
647 | else if (DTerrainMap[i, j] == 2) |
---|
648 | { |
---|
649 | tileinfo = tileinfo + Environment.NewLine + "Lehtimetsää"; |
---|
650 | Defensebonus = Defensebonus + 10; |
---|
651 | } |
---|
652 | else if (DTerrainMap[i, j] == 3) |
---|
653 | { |
---|
654 | tileinfo = tileinfo + Environment.NewLine + "Kuusimetsää"; |
---|
655 | Defensebonus = Defensebonus + 25; |
---|
656 | } |
---|
657 | else |
---|
658 | { |
---|
659 | // MessageBox.Show(Convert.ToString(ShroudMap[i, j])); |
---|
660 | if (ShroudMap[i, j] == 0) |
---|
661 | { |
---|
662 | try |
---|
663 | { |
---|
664 | if (OwnershipMap[i, j] >= -1) |
---|
665 | { |
---|
666 | tileinfo = tileinfo + Environment.NewLine + "Kaupunki"; |
---|
667 | tileinfo = tileinfo + Environment.NewLine + Rules.pCivs[OwnershipMap[i, j]].Name; |
---|
668 | } |
---|
669 | } |
---|
670 | catch |
---|
671 | { |
---|
672 | } |
---|
673 | } |
---|
674 | } |
---|
675 | if (Defensebonus != 0) |
---|
676 | { |
---|
677 | return tileinfo + Environment.NewLine + "Puolustusbonus: " + Defensebonus + "%"; |
---|
678 | } |
---|
679 | else |
---|
680 | { |
---|
681 | return tileinfo; |
---|
682 | } |
---|
683 | } |
---|
684 | |
---|
685 | private void InitControls() |
---|
686 | { |
---|
687 | Keyboard.Listen(Key.Right, Jypeli.ButtonState.Down, MoveCamera, null, 0); |
---|
688 | Keyboard.Listen(Key.Left, Jypeli.ButtonState.Down, MoveCamera, null, 2); |
---|
689 | Keyboard.Listen(Key.Up, Jypeli.ButtonState.Down, MoveCamera, null, 1); |
---|
690 | Keyboard.Listen(Key.Down, Jypeli.ButtonState.Down, MoveCamera, null, 3); |
---|
691 | Keyboard.Listen(Key.Tab, Jypeli.ButtonState.Down, ActivateDebug, null, 0); |
---|
692 | |
---|
693 | MouseScreenWidth = new int(); |
---|
694 | MouseScreenWidth = Convert.ToInt32(Peli.Screen.Width / 2) - 5; |
---|
695 | MouseScreenHeight = new int(); |
---|
696 | MouseScreenHeight = Convert.ToInt32(Peli.Screen.Height / 2) - 5; |
---|
697 | NegMouseScreenWidth = new int(); |
---|
698 | NegMouseScreenWidth = Convert.ToInt32(Peli.Screen.Width / -2) + 5; |
---|
699 | NegMouseScreenHeight = new int(); |
---|
700 | NegMouseScreenHeight = Convert.ToInt32(Peli.Screen.Height / -2) + 20; |
---|
701 | } |
---|
702 | |
---|
703 | private void ActivateDebug(int asd) |
---|
704 | { |
---|
705 | //Add(MessageDisplay); |
---|
706 | MessageDisplay.Add("DEBUG MODE ACTIVATED"); |
---|
707 | Keyboard.Listen(Key.A, Jypeli.ButtonState.Down, ShowColors, null); |
---|
708 | } |
---|
709 | |
---|
710 | private void ShowColors() |
---|
711 | { |
---|
712 | for (int a = 0; a <= (AmountofPlayers - 1); a++) |
---|
713 | { |
---|
714 | MessageDisplay.Add("Pelaaja: " + a + "; " + Rules.pCivs[a].Color); |
---|
715 | } |
---|
716 | } |
---|
717 | |
---|
718 | private void MoveCamera(Int32 dir) |
---|
719 | { |
---|
720 | if (gamestarted == false) { return; } |
---|
721 | if ((dir == 0) && (Camera.Position.X < (tile[kartanKorkeus - 1, kartanLeveys - 1].X) - (Peli.Screen.Width / 2))) |
---|
722 | { |
---|
723 | Camera.Move(CamSpeedEast); |
---|
724 | } |
---|
725 | if ((dir == 1) && (Camera.Position.Y < (tile[kartanKorkeus - 1, kartanLeveys - 1].Y) - ((Peli.Screen.Height / 2) - 12))) |
---|
726 | { |
---|
727 | Camera.Move(CamSpeedNorth); |
---|
728 | } |
---|
729 | if ((dir == 2) && (Camera.Position.X > (tile[0, 0].X) + (Peli.Screen.Width / 2))) |
---|
730 | { |
---|
731 | Camera.Move(CamSpeedWest); |
---|
732 | } |
---|
733 | if ((dir == 3) && (Camera.Position.Y > (tile[0, 0].Y) + (Peli.Screen.Height / 2))) |
---|
734 | { |
---|
735 | Camera.Move(CamSpeedSouth); |
---|
736 | } |
---|
737 | } |
---|
738 | } |
---|
739 | } |
---|