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 | using System.Threading; // voin käyttää Thread.Sleepiä |
---|
16 | |
---|
17 | namespace ALTKTileEngine |
---|
18 | { |
---|
19 | public class Peli : Game |
---|
20 | { |
---|
21 | bool gamestarted = false; |
---|
22 | int currDiffLevel; // jotta tätä voidaan käyttää missä tahansa |
---|
23 | |
---|
24 | int[,] TerrainMap; // perusmaastokartta |
---|
25 | int[,] DTerrainMap; // erikoismaastokartta |
---|
26 | int[,] OwnershipMap; // ruudukon omistuskartta (kenen pelaajan hallinnassa on mikäkin ruutu) |
---|
27 | int[,] ShroudMap; // pelaajan näkymää pienentävä Shroudmap |
---|
28 | int[,] UnitMap; // yksikkökartta |
---|
29 | |
---|
30 | string Textpath; |
---|
31 | string OwnershipColorPath; |
---|
32 | |
---|
33 | int AmountofPlayers; // Ihmispelaajien määrä, tällä hetkellä peli tukee vain yhtä |
---|
34 | int TurnNumber; // vuoron numero |
---|
35 | int CurrProduction; // pelaajan tämänhetkinen tuotanto |
---|
36 | |
---|
37 | // !!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
38 | // Pitänee tehdä vielä yksi ALTKSUnit-namespace ALTKCoreen. |
---|
39 | // Tämä sisältäisi tiedot yksiköiden omistajasta, yksikön perusyksiköstä ym. sekä myös karttakoordinaatit |
---|
40 | // (karttakoordinaatit säilyttää myös UnitMap, josta on helppo tarkastaa esim. liikuttaessa yksiköitä, onko ruudussa jo esim. vihollisyksiköitä. |
---|
41 | |
---|
42 | int SelectedUnit = -1; |
---|
43 | |
---|
44 | bool UnitsSelected = new bool(); |
---|
45 | |
---|
46 | TextDisplay TileDisp; |
---|
47 | TextDisplay UnitStatsDisp; |
---|
48 | TextDisplay ProductionDisp; |
---|
49 | TextDisplay BuildCityDisp; |
---|
50 | TextDisplay BuildUnitsDisp; |
---|
51 | TextDisplay Unit1Disp; |
---|
52 | TextDisplay Unit2Disp; |
---|
53 | TextDisplay Unit3Disp; |
---|
54 | TextDisplay Unit4Disp; |
---|
55 | TextDisplay ResearchDisp; |
---|
56 | TextDisplay ResearchableTech1; |
---|
57 | TextDisplay ResearchableTech2; |
---|
58 | TextDisplay ResearchableTech3; |
---|
59 | TextDisplay ClicktoResearch; |
---|
60 | |
---|
61 | int kartanLeveys; |
---|
62 | int kartanKorkeus; |
---|
63 | |
---|
64 | int CurrentPlayer; |
---|
65 | |
---|
66 | bool CityPlaceSelection; |
---|
67 | bool TileClickAllowed = false; |
---|
68 | |
---|
69 | bool UnitBuildingMode = false; |
---|
70 | bool UnitPositioningMode = false; |
---|
71 | int currentunit = new int(); |
---|
72 | |
---|
73 | // perusmaastotyypit |
---|
74 | const int Aavikko = 2, Tundra = 3, Vuoristo = 1, Lehtimetsa = 0; |
---|
75 | |
---|
76 | // erikoismaastotyypit |
---|
77 | const int Havumetsa = 2, Tyhja = 0, Kuusimetsa = 3; |
---|
78 | |
---|
79 | // Pelissä on viisi eri tasoa, toisella perusmaasto ja toisella tarkempaa tietoa (esim. onko ruutu metsää ym.) |
---|
80 | // Kolmas taso kertoo, kenen valtion hallinnassa ruutu on, neljäs on Fog of War, ja viides piirtää yksiköt. |
---|
81 | GameObject[,] tile; |
---|
82 | GameObject[,] DTile; |
---|
83 | GameObject[,] TileOwnership; |
---|
84 | GameObject[,] ShroudTile; |
---|
85 | GameObject[,] UnitTile; |
---|
86 | //Vector tileVector; |
---|
87 | |
---|
88 | Vector CamSpeedEast = new Vector(20.0, .0); |
---|
89 | Vector CamSpeedWest = new Vector(-20.0, .0); |
---|
90 | Vector CamSpeedNorth = new Vector(.0, 20.0); |
---|
91 | Vector CamSpeedSouth = new Vector(.0, -20.0); |
---|
92 | |
---|
93 | // Käytän ennemmin enemmän muistia kuin prosessoria, joten lasken nämä jo täällä |
---|
94 | int MouseScreenWidth; |
---|
95 | int MouseScreenHeight; |
---|
96 | int NegMouseScreenWidth; |
---|
97 | int NegMouseScreenHeight; |
---|
98 | # region Aloitusruutuvalikko |
---|
99 | protected override void Begin() |
---|
100 | { |
---|
101 | //SetWindowSize(true); |
---|
102 | Textpath = Application.StartupPath + "\\Content\\Textures\\"; |
---|
103 | OwnershipColorPath = Textpath + "Ownership\\"; |
---|
104 | InitRules(); |
---|
105 | InitStartMenu(); |
---|
106 | //InitControls(); |
---|
107 | //InitMap(); |
---|
108 | } |
---|
109 | void InitStartMenu() |
---|
110 | { |
---|
111 | Level.BackgroundColor = Color.Gray; |
---|
112 | Mouse.Enabled = true; |
---|
113 | Mouse.IsCursorVisible = true; |
---|
114 | |
---|
115 | InputQueryWindow input = new InputQueryWindow(); |
---|
116 | input.InputConfirmed += Player_SetName; |
---|
117 | input.QueryText.Text = "Kirjoita valtiosi nimi:"; |
---|
118 | input.Size = new Vector(300.0, 100.0); |
---|
119 | input.Position = new Vector(-250.0, 350.0); |
---|
120 | input.InputBox.BorderColor = Color.GreenYellow; |
---|
121 | ShowWindow(input); |
---|
122 | |
---|
123 | GameObject TrainingButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
124 | GameObject EasyButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
125 | GameObject NormalButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
126 | GameObject HardButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
127 | GameObject VHardButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
128 | GameObject NightmareButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
129 | GameObject InsanityButton = new GameObject(250, 30, Shapes.Rectangle); |
---|
130 | |
---|
131 | for (int a = 0; a <= 6; a++) |
---|
132 | { |
---|
133 | if (a == 0) { SetDiffButton(TrainingButton, 0); } |
---|
134 | if (a == 1) { SetDiffButton(EasyButton, 1); } |
---|
135 | if (a == 2) { SetDiffButton(NormalButton, 2); } |
---|
136 | if (a == 3) { SetDiffButton(HardButton, 3); } |
---|
137 | if (a == 4) { SetDiffButton(VHardButton, 4); } |
---|
138 | if (a == 5) { SetDiffButton(NightmareButton, 5); } |
---|
139 | if (a == 6) { SetDiffButton(InsanityButton, 6); } |
---|
140 | } |
---|
141 | Mouse.ListenOn(TrainingButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 0); |
---|
142 | Mouse.ListenOn(EasyButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 1); |
---|
143 | Mouse.ListenOn(NormalButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 2); |
---|
144 | Mouse.ListenOn(HardButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 3); |
---|
145 | Mouse.ListenOn(VHardButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 4); |
---|
146 | Mouse.ListenOn(NightmareButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 5); |
---|
147 | Mouse.ListenOn(InsanityButton, MouseButton.Left, Jypeli.ButtonState.Down, SelectDifficulty, "", 6); |
---|
148 | } |
---|
149 | |
---|
150 | void Player_SetName(InputQueryWindow sender, string input) |
---|
151 | { |
---|
152 | Rules.pCivs[0].Name = input; |
---|
153 | Rules.pCivs[0].HumanPlayer = true; |
---|
154 | Rules.pCivs[0].Enabled = true; |
---|
155 | Rules.pCivs[0].Color = "red"; |
---|
156 | } |
---|
157 | |
---|
158 | void SetDiffButton(GameObject diffbutton, int difflevel) |
---|
159 | { |
---|
160 | diffbutton.X = 250; |
---|
161 | diffbutton.Y = ((difflevel * -50) + 300); |
---|
162 | if (difflevel == 0) { diffbutton.Image = LoadImage(Textpath + "training"); } |
---|
163 | else if (difflevel == 1) { diffbutton.Image = LoadImage(Textpath + "easy"); } |
---|
164 | else if (difflevel == 2) { diffbutton.Image = LoadImage(Textpath + "normal"); } |
---|
165 | else if (difflevel == 3) { diffbutton.Image = LoadImage(Textpath + "hard"); } |
---|
166 | else if (difflevel == 4) { diffbutton.Image = LoadImage(Textpath + "vhard"); } |
---|
167 | else if (difflevel == 5) { diffbutton.Image = LoadImage(Textpath + "nightmare"); } |
---|
168 | else if (difflevel == 6) { diffbutton.Image = LoadImage(Textpath + "insanity"); } |
---|
169 | Add(diffbutton); |
---|
170 | //return diffbutton; |
---|
171 | } |
---|
172 | |
---|
173 | void SelectDifficulty(int difflevel) |
---|
174 | { |
---|
175 | ClearAll(); |
---|
176 | currDiffLevel = new int(); |
---|
177 | currDiffLevel = difflevel; |
---|
178 | InitControls(); |
---|
179 | InitMap(); |
---|
180 | gamestarted = true; |
---|
181 | } |
---|
182 | # endregion |
---|
183 | # region Kartan luominen |
---|
184 | |
---|
185 | void InitMap() |
---|
186 | { |
---|
187 | TurnNumber = new int(); |
---|
188 | AmountofPlayers = new int(); |
---|
189 | Int32 i; |
---|
190 | Int32 j; |
---|
191 | string mLine; |
---|
192 | TextReader bReader; |
---|
193 | bReader = new StreamReader("Content\\Maps\\1\\base.txt"); |
---|
194 | //try |
---|
195 | //{ |
---|
196 | |
---|
197 | // Yleensä kartan kaksi ensimmäistä riviä ovat kommentteja |
---|
198 | bReader.ReadLine(); |
---|
199 | bReader.ReadLine(); |
---|
200 | |
---|
201 | kartanLeveys = Convert.ToInt32(bReader.ReadLine().Substring(9, 2)); |
---|
202 | kartanKorkeus = Convert.ToInt32(bReader.ReadLine().Substring(10, 2)); |
---|
203 | |
---|
204 | Int32 mapWidthJ = (kartanLeveys * 48) / 2; |
---|
205 | Int32 mapHeightJ = (kartanKorkeus * 48) / 2; |
---|
206 | |
---|
207 | bReader.ReadLine(); |
---|
208 | // Ladataan TerrainMapit muistiin myöhempää käyttöä varten |
---|
209 | |
---|
210 | TerrainMap = new int[kartanKorkeus, kartanLeveys]; |
---|
211 | DTerrainMap = new int[kartanKorkeus, kartanLeveys]; |
---|
212 | OwnershipMap = new int[kartanKorkeus, kartanLeveys]; |
---|
213 | ShroudMap = new int[kartanKorkeus, kartanLeveys]; |
---|
214 | UnitMap = new int[kartanKorkeus, kartanLeveys]; |
---|
215 | InitTerrain(0); |
---|
216 | InitTerrain(1); |
---|
217 | InitTerrain(2); |
---|
218 | InitTerrain(3); |
---|
219 | InitTerrain(4); |
---|
220 | |
---|
221 | tile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
222 | DTile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
223 | TileOwnership = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
224 | ShroudTile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
225 | UnitTile = new GameObject[kartanKorkeus, kartanLeveys]; |
---|
226 | InitTerrainGraphics(0); |
---|
227 | InitTerrainGraphics(1); |
---|
228 | InitTerrainGraphics(2); |
---|
229 | InitTerrainGraphics(3); |
---|
230 | InitTerrainGraphics(4); |
---|
231 | |
---|
232 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
233 | { |
---|
234 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
235 | { |
---|
236 | UnitMap[i, j] = -1; |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | // Initialisoidaan Unitmap |
---|
241 | |
---|
242 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
243 | { |
---|
244 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
245 | { |
---|
246 | UnitTile[i, j].Shape = Shapes.Rectangle; |
---|
247 | UnitTile[i, j].X = (j * 48) - mapWidthJ; |
---|
248 | UnitTile[i, j].Y = (i * 48) - mapHeightJ; |
---|
249 | UnitTile[i, j].Image = LoadImage(Textpath + "nothing"); |
---|
250 | Add(UnitTile[i, j]); |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | // Koodi käännetty RGE:n VB.netistä |
---|
255 | // Asettaa ja piirtää pohjamaaston |
---|
256 | |
---|
257 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
258 | { |
---|
259 | mLine = bReader.ReadLine(); |
---|
260 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
261 | { |
---|
262 | // MessageBox.Show(mLine + " " + j + " " + i);s |
---|
263 | tile[i, j].Shape = Shapes.Rectangle; |
---|
264 | tile[i, j].X = (j * 48) - mapWidthJ; |
---|
265 | tile[i, j].Y = (i * 48) - mapHeightJ; |
---|
266 | TerrainMap[i, j] = getTerrainType(mLine.Substring(j, 1), 0, i, j); |
---|
267 | tile[i, j].Image = LoadImage(getTexture_fromTerrainType(TerrainMap[i, j], 0, i, j)); |
---|
268 | Add(tile[i, j]); |
---|
269 | Mouse.ListenOn(tile[i, j], MouseButton.Left, Jypeli.ButtonState.Released, TileClicked, "", i, j); |
---|
270 | //Mouse.ListenMovement(tile[i, j], showTileInfo_forTileDisp, null, i, j); |
---|
271 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | // Luetaan karttatiedoston rivivälit |
---|
276 | bReader.ReadLine(); |
---|
277 | bReader.ReadLine(); |
---|
278 | |
---|
279 | // Rami 16. 6. 2010: Omistuskartta pitää sittenkin säätää ennen erikoismaastoa, sillä |
---|
280 | // kaupungit ja omistusrinki piirretään erikoismaaston asettamiskoodin kutsusta |
---|
281 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
282 | { |
---|
283 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
284 | { |
---|
285 | // MessageBox.Show(mLine + " " + j + " " + i); |
---|
286 | OwnershipMap[i, j] = -1; |
---|
287 | TileOwnership[i, j].Shape = Shapes.Rectangle; |
---|
288 | TileOwnership[i, j].X = (j * 48) - mapWidthJ; |
---|
289 | TileOwnership[i, j].Y = (i * 48) - mapHeightJ; |
---|
290 | TileOwnership[i, j].Image = LoadImage(Textpath + "nothing"); |
---|
291 | Add(TileOwnership[i, j]); |
---|
292 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
293 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | // Initialisoidaan Shroudmap |
---|
298 | |
---|
299 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
300 | { |
---|
301 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
302 | { |
---|
303 | ShroudMap[i, j] = 1; |
---|
304 | ShroudTile[i, j].Shape = Shapes.Rectangle; |
---|
305 | ShroudTile[i, j].X = (j * 48) - mapWidthJ; |
---|
306 | ShroudTile[i, j].Y = (i * 48) - mapHeightJ; |
---|
307 | ShroudTile[i, j].Image = LoadImage(Textpath + "fogofwar"); |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | // Asettaa ja piirtää erikoismaaston |
---|
313 | |
---|
314 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
315 | { |
---|
316 | mLine = bReader.ReadLine(); |
---|
317 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
318 | { |
---|
319 | DTile[i, j].Shape = Shapes.Rectangle; |
---|
320 | DTile[i, j].X = (j * 48) - mapWidthJ; |
---|
321 | DTile[i, j].Y = (i * 48) - mapHeightJ; |
---|
322 | DTerrainMap[i, j] = getTerrainType(mLine.Substring(j, 1), 1, i, j); |
---|
323 | DTile[i, j].Image = LoadImage(getTexture_fromTerrainType(DTerrainMap[i, j], 1, i, j)); |
---|
324 | Add(DTile[i, j]); |
---|
325 | if (getTexture_fromTerrainType(DTerrainMap[i, j], 1, i, j).Contains("city")) |
---|
326 | { |
---|
327 | DrawOwnership(i, j); |
---|
328 | } |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | // Piirretään ShroudTile vasta tässä, jotta se olisi DTilen päällä |
---|
333 | for (i = 0; i <= (kartanKorkeus - 1); i++) |
---|
334 | { |
---|
335 | for (j = 0; j <= (kartanLeveys - 1); j++) |
---|
336 | { |
---|
337 | if (ShroudMap[i, j] == 1) |
---|
338 | { |
---|
339 | Add(ShroudTile[i, j]); |
---|
340 | } |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | //catch |
---|
345 | //{ |
---|
346 | // MessageBox.Show("Map error!"); |
---|
347 | // bReader.Close(); |
---|
348 | // Exit(); |
---|
349 | //} |
---|
350 | bReader.Close(); |
---|
351 | //for (int playernumber = 0; playernumber <= 30; playernumber++) |
---|
352 | //{ |
---|
353 | // Rules.pCivs[playernumber].Color = setAIOwnershipColor(playernumber); |
---|
354 | //} |
---|
355 | Level.BackgroundColor = Color.Black; |
---|
356 | InitGUI(); |
---|
357 | |
---|
358 | Application.DoEvents(); |
---|
359 | TurnSystem_Start(0); // Antaa pelin alkaa! |
---|
360 | } |
---|
361 | |
---|
362 | private void InitTerrain(int tlayer) |
---|
363 | { |
---|
364 | for (int a = 0; a <= (kartanKorkeus - 1); a++) |
---|
365 | { |
---|
366 | for (int b = 0; b <= (kartanLeveys - 1); b++) |
---|
367 | { |
---|
368 | GetTerrainLayer(tlayer)[a, b] = new int(); |
---|
369 | } |
---|
370 | } |
---|
371 | } |
---|
372 | |
---|
373 | int[,] GetTerrainLayer(int tlayer) |
---|
374 | { |
---|
375 | if (tlayer == 0) { return TerrainMap; } |
---|
376 | if (tlayer == 1) { return DTerrainMap; } |
---|
377 | if (tlayer == 2) { return OwnershipMap; } |
---|
378 | if (tlayer == 3) { return ShroudMap; } |
---|
379 | if (tlayer == 4) { return UnitMap; } |
---|
380 | return TerrainMap; |
---|
381 | } |
---|
382 | |
---|
383 | private void InitTerrainGraphics(int tlayer) |
---|
384 | { |
---|
385 | for (int a = 0; a <= (kartanKorkeus - 1); a++) |
---|
386 | { |
---|
387 | for (int b = 0; b <= (kartanLeveys - 1); b++) |
---|
388 | { |
---|
389 | GetGraphicsLayer(tlayer)[a, b] = new PhysicsObject(48.0, 48.0); |
---|
390 | } |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | GameObject[,] GetGraphicsLayer(int tlayer) |
---|
395 | { |
---|
396 | if (tlayer == 0) {return tile; } |
---|
397 | if (tlayer == 1) {return DTile; } |
---|
398 | if (tlayer == 2) { return TileOwnership; } |
---|
399 | if (tlayer == 3) { return ShroudTile; } |
---|
400 | if (tlayer == 4) { return UnitTile; } |
---|
401 | return tile; |
---|
402 | } |
---|
403 | |
---|
404 | int getTerrainType(string ch, int terrainlayer, int i, int j) |
---|
405 | { |
---|
406 | if (terrainlayer == 0) |
---|
407 | { |
---|
408 | /*/ Maastotyypit |
---|
409 | * 0 = lehtimetsää |
---|
410 | * 1 = vuoristoa |
---|
411 | * 2 = aavikkoa |
---|
412 | * 3 = tundraa |
---|
413 | /*/ |
---|
414 | if (ch == " ") { return Lehtimetsa; } |
---|
415 | if (ch == "V") { return Vuoristo; } |
---|
416 | if (ch == "A") { return Aavikko; } |
---|
417 | if (ch == "T") { return Tundra; } |
---|
418 | } |
---|
419 | else if (terrainlayer == 1) |
---|
420 | { |
---|
421 | /*/ Erikoismaastotyypit |
---|
422 | * 0 = ei mitään |
---|
423 | * 1 = vuoristoa |
---|
424 | * 2 = metsää |
---|
425 | * 3 = kuusimetsää |
---|
426 | /*/ |
---|
427 | if (ch == " ") { return Tyhja; } |
---|
428 | if (ch == "M") { return Havumetsa; } |
---|
429 | if (ch == "V") { return Vuoristo; } |
---|
430 | if (ch == "K") { return Kuusimetsa; } |
---|
431 | try |
---|
432 | { |
---|
433 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
434 | int Playerstartloc; |
---|
435 | Playerstartloc = Convert.ToInt32(ch); |
---|
436 | AmountofPlayers = AmountofPlayers + 1; |
---|
437 | AddStartingCity(Playerstartloc, i, j); |
---|
438 | return (Playerstartloc + 10); |
---|
439 | } |
---|
440 | catch |
---|
441 | { |
---|
442 | } |
---|
443 | return Tyhja; |
---|
444 | } |
---|
445 | return 0; |
---|
446 | } |
---|
447 | |
---|
448 | private void TileClicked(int i, int j) |
---|
449 | { |
---|
450 | //MessageBox.Show(i + " " + j + Convert.ToString(CityPlaceSelection) + " " + Convert.ToString(UnitPositioningMode)); |
---|
451 | //if (TileClickAllowed == true) |
---|
452 | //{ |
---|
453 | if (CityPlaceSelection == true) |
---|
454 | { |
---|
455 | if (OwnershipMap[i, j] > -1 && OwnershipMap[i, j] != CurrentPlayer) |
---|
456 | { |
---|
457 | MessageDisplay.Add("Ruutu on vihollisen (" + Rules.pCivs[OwnershipMap[i, j]].Name + ") hallinnassa, etkä voi rakentaa siihen kaupunkia."); |
---|
458 | } |
---|
459 | else |
---|
460 | { |
---|
461 | if (DTerrainMap[i, j] == Vuoristo | DTerrainMap[i, j] > 9) |
---|
462 | { |
---|
463 | if (DTerrainMap[i, j] == Vuoristo) |
---|
464 | { |
---|
465 | MessageDisplay.Add("Et voi rakentaa kaupunkia vuorelle!"); |
---|
466 | } |
---|
467 | else |
---|
468 | { |
---|
469 | MessageDisplay.Add("Et voi rakentaa kaupunkia valmiin kaupungin päälle!"); |
---|
470 | } |
---|
471 | } |
---|
472 | else |
---|
473 | { |
---|
474 | bool cityAllowed = false; |
---|
475 | int b; |
---|
476 | int c; |
---|
477 | |
---|
478 | int d; |
---|
479 | int e; |
---|
480 | int f; |
---|
481 | for (int a = 0; a <= Rules.pCivs[CurrentPlayer].NumberofCities - 1; a++) |
---|
482 | { |
---|
483 | b = Rules.pCivs[CurrentPlayer].CityCoords[a, 0]; |
---|
484 | c = Rules.pCivs[CurrentPlayer].CityCoords[a, 1]; |
---|
485 | |
---|
486 | d = i - b; |
---|
487 | e = j - c; |
---|
488 | if (d == 2 | d == 1 | d == 0 | d == -1 | d == -2) |
---|
489 | { |
---|
490 | if (e == 2 | e == 1 | e == 0 | e == -1 | e == -2) |
---|
491 | { |
---|
492 | cityAllowed = true; |
---|
493 | } |
---|
494 | } |
---|
495 | } |
---|
496 | if (cityAllowed == true) |
---|
497 | { |
---|
498 | BuildCityDisp.TextColor = Color.Green; |
---|
499 | BuildCityDisp.X = BuildCityDisp.X + 20; |
---|
500 | Rules.pCivs[CurrentPlayer].BuiltFromCity = 0; |
---|
501 | Rules.pCivs[CurrentPlayer].Production = Rules.pCivs[CurrentPlayer].Production + 10; |
---|
502 | Rules.pCivs[CurrentPlayer].NumberofCities = Rules.pCivs[CurrentPlayer].NumberofCities + 1; |
---|
503 | Rules.pCivs[CurrentPlayer].CityCoords[Rules.pCivs[CurrentPlayer].NumberofCities - 1, 0] = i; |
---|
504 | Rules.pCivs[CurrentPlayer].CityCoords[Rules.pCivs[CurrentPlayer].NumberofCities - 1, 1] = j; |
---|
505 | BuildCityDisp.Text = "Rakenna kaupunki (B) (" + Rules.pCivs[CurrentPlayer].BuiltFromCity + " / " + Rules.pCivs[CurrentPlayer].Production + ")"; |
---|
506 | CityPlaceSelection = false; |
---|
507 | ChangeProductionDispText(); |
---|
508 | DTerrainMap[i, j] = CurrentPlayer + 10; |
---|
509 | DTile[i, j].Image = LoadImage(Textpath + "cityancient"); |
---|
510 | if (OwnershipMap[i, j] == -1) |
---|
511 | { |
---|
512 | OwnershipMap[i, j] = CurrentPlayer; |
---|
513 | DrawOwnership(i, j); |
---|
514 | CheckAndRemoveShroud_FromPos(i, j); |
---|
515 | } |
---|
516 | } |
---|
517 | else |
---|
518 | { |
---|
519 | MessageDisplay.Add("Valitsemasi sijainti on liian kaukana; Maksimietäisyys muista kaupungeista on 2 ruutua."); |
---|
520 | } |
---|
521 | } |
---|
522 | } |
---|
523 | } |
---|
524 | else if (UnitPositioningMode == true) |
---|
525 | { |
---|
526 | MessageBox.Show(Convert.ToString(UnitPositioningMode)); |
---|
527 | if (DTerrainMap[i, j] == CurrentPlayer + 10) |
---|
528 | { |
---|
529 | CreateUnit(i, j, BaseRules.Rules.getUnit_FromId(currentunit), CurrentPlayer); |
---|
530 | UnitPositioningMode = false; |
---|
531 | BuildUnitsClicked(); |
---|
532 | MessageDisplay.Add("Rakensit yksikön " + BaseRules.Rules.getUnit_FromId(currentunit).Name + " kohteeseen " + i + "; " + j + "."); |
---|
533 | currentunit = -1; |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | MessageDisplay.Add("Yksikkö täytyy rakentaa kaupunkiin."); |
---|
538 | } |
---|
539 | } |
---|
540 | else |
---|
541 | { |
---|
542 | if (OwnershipMap[i, j] == 0 && UnitMap[i, j] > -1) |
---|
543 | { |
---|
544 | UnitSelect(i, j); |
---|
545 | } |
---|
546 | } |
---|
547 | } |
---|
548 | //} |
---|
549 | |
---|
550 | private void UnitSelect(int i, int j) |
---|
551 | { |
---|
552 | //MessageBox.Show("UnitSelect: " + Convert.ToString(Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].CurrentMovementPoints)); |
---|
553 | if (Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].CurrentMovementPoints > 0) |
---|
554 | { |
---|
555 | MessageDisplay.Add("Valitsit yksikön " + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].UnitType.Name + " kohteesta " + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].PosY + "; " + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].PosX); |
---|
556 | MessageDisplay.Add("Liikuta valittua yksikköä Numpadista."); |
---|
557 | UnitStatsDisp.Text = "Valittu yksikkö:" + Environment.NewLine + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].UnitType.Name + |
---|
558 | Environment.NewLine + "-Voimakkuus: " + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].UnitType.Strength + Environment.NewLine + |
---|
559 | "-Liikkuvuus: " + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].UnitType.Movement + Environment.NewLine + |
---|
560 | Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].UnitType.Description + Environment.NewLine + |
---|
561 | " HP: " + Rules.pCivs[CurrentPlayer].Units[GetUnit_FromPositionForSelection(i, j)].HP * 100 + "/100"; |
---|
562 | SelectedUnit = GetUnit_FromPositionForSelection(i, j); |
---|
563 | UnitTile[i, j].Image = LoadImage(OwnershipColorPath + "unitsOnTileSelected"); |
---|
564 | UnitsSelected = true; |
---|
565 | //Keyboard.Enable(Key.NumPad1); |
---|
566 | //Keyboard.Enable(Key.NumPad2); |
---|
567 | //Keyboard.Enable(Key.NumPad3); |
---|
568 | //Keyboard.Enable(Key.NumPad4); |
---|
569 | //Keyboard.Enable(Key.NumPad5); |
---|
570 | //Keyboard.Enable(Key.NumPad6); |
---|
571 | //Keyboard.Enable(Key.NumPad7); |
---|
572 | //Keyboard.Enable(Key.NumPad8); |
---|
573 | //Keyboard.Enable(Key.NumPad9); |
---|
574 | } |
---|
575 | } |
---|
576 | |
---|
577 | private void DrawOwnership(int i, int j) |
---|
578 | { |
---|
579 | if (ShroudMap[i, j] == 0) |
---|
580 | { |
---|
581 | TileOwnership[i, j].Image = LoadImage(OwnershipColorPath + Rules.pCivs[OwnershipMap[i, j]].Color); |
---|
582 | //if (TileOwnership[i, j].IsAddedToGame == false | TileOwnership[i, j]. == true) |
---|
583 | //{ |
---|
584 | //try |
---|
585 | //{ |
---|
586 | // Add(TileOwnership[i, j]); |
---|
587 | //} |
---|
588 | //catch |
---|
589 | //{ |
---|
590 | // //MessageDisplay.Add("TileOwnership not added at " + i + "; " + j + " ;; because of an exception."); |
---|
591 | //} |
---|
592 | //} |
---|
593 | } |
---|
594 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
595 | } |
---|
596 | |
---|
597 | //private void DrawUnit(int i, int j) |
---|
598 | //{ |
---|
599 | // if (UnitTile[i, j].IsAddedToGame == false) |
---|
600 | // { |
---|
601 | // Add(UnitTile[i, j]); |
---|
602 | // //Mouse.ListenOn(UnitTile[i, j], MouseButton.Left, Jypeli.ButtonState.Pressed, UnitSelect, "Valitse yksikkö painamalla ruutua", i, j); |
---|
603 | // } |
---|
604 | //} |
---|
605 | |
---|
606 | private void RemoveOwnership(int i, int j) |
---|
607 | { |
---|
608 | OwnershipMap[i, j] = -1; |
---|
609 | TileOwnership[i, j].Destroy(); |
---|
610 | } |
---|
611 | |
---|
612 | private void AddStartingCity(int playernumber, int i, int j) |
---|
613 | { |
---|
614 | //MessageBox.Show(TileOwnership[i, j].X + "x" + TileOwnership[i, j].Y + " " + DTile[i, j].X + "x" + DTile[i, j].Y + " Params: " + i + " " + j); |
---|
615 | Rules.pCivs[playernumber].Production = Rules.pCivs[playernumber].Production + 10; |
---|
616 | Rules.pCivs[playernumber].CityCoords[Rules.pCivs[playernumber].NumberofCities, 0] = i; |
---|
617 | Rules.pCivs[playernumber].CityCoords[Rules.pCivs[playernumber].NumberofCities, 1] = j; |
---|
618 | Rules.pCivs[playernumber].NumberofCities = Rules.pCivs[playernumber].NumberofCities + 1; |
---|
619 | //MessageBox.Show("AddStartingCity: " + i + " " + j + " Playernumber: " + playernumber + "CityCoords: " + Rules.pCivs[playernumber].CityCoords[0, 0] + " " + Rules.pCivs[playernumber].CityCoords[0, 1]); |
---|
620 | if (Rules.pCivs[playernumber].HumanPlayer == false) |
---|
621 | { |
---|
622 | Rules.pCivs[playernumber].Color = setAIOwnershipColor(playernumber); |
---|
623 | Rules.pCivs[playernumber].Enabled = true; |
---|
624 | Rules.pCivs[playernumber].Name = Rules.pCivs[playernumber].Color + " " + "Empire"; |
---|
625 | } |
---|
626 | else |
---|
627 | { |
---|
628 | CheckAndRemoveShroud_FromPos(i, j); |
---|
629 | } |
---|
630 | OwnershipMap[i, j] = playernumber; |
---|
631 | // 16. 6. 2010: Kutsutaanpa DrawOwnership sittenkin vasta kaupungin piirtämisen jälkeen (ks. InitMap ja DTilen asettaminen) |
---|
632 | //DrawOwnership(i, j); |
---|
633 | |
---|
634 | //DTile[i, j].Image = LoadImage("\\Content\\Textures\\cityancient"); |
---|
635 | } |
---|
636 | |
---|
637 | // Aliohjelma yksikön luomiseen |
---|
638 | private void CreateUnit(int i, int j, ALTKUnits.UnitClass unittype, int civnumber) |
---|
639 | { |
---|
640 | //MessageBox.Show(i + " " + j); |
---|
641 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits] = new BaseRules.Unit(); |
---|
642 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits].HP = 1.00; |
---|
643 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits].PosY = i; |
---|
644 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits].PosX = j; |
---|
645 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits].UnitType = unittype; |
---|
646 | Rules.pCivs[civnumber].NumberofUnits = Rules.pCivs[civnumber].NumberofUnits + 1; |
---|
647 | UnitMap[i, j] = civnumber; |
---|
648 | |
---|
649 | UnitTile[i, j].Image = LoadImage(OwnershipColorPath + "unitsOnTile"); |
---|
650 | |
---|
651 | if (OwnershipMap[i, j] == -1) |
---|
652 | { |
---|
653 | } |
---|
654 | else |
---|
655 | { |
---|
656 | OwnershipMap[i, j] = civnumber; |
---|
657 | DrawOwnership(i, j); |
---|
658 | } |
---|
659 | } |
---|
660 | |
---|
661 | public string GetUnits_FromPositionForView(int i, int j) |
---|
662 | { |
---|
663 | //MessageBox.Show("GetUnits..."); |
---|
664 | string units = ""; |
---|
665 | int civid; |
---|
666 | civid = OwnershipMap[i, j]; |
---|
667 | //int[] UnitAmount = new int[23]; |
---|
668 | //MessageBox.Show("GetUnits... Stage 0.5"); |
---|
669 | //for (int c = 0; c <= 23; c++) |
---|
670 | //{ |
---|
671 | //MessageBox.Show("GetUnits... Stage 0.8"); |
---|
672 | //UnitAmount[c] = new int(); |
---|
673 | //} |
---|
674 | //MessageBox.Show("GetUnits... Stage 1"); |
---|
675 | for (int a = 0; a <= Rules.pCivs[civid].NumberofUnits - 1; a++) |
---|
676 | { |
---|
677 | //MessageBox.Show("GetUnits... Stage 2"); |
---|
678 | if (Rules.pCivs[civid].Units[a].PosY == i && Rules.pCivs[civid].Units[a].PosX == j) // && (units.Contains(Rules.pCivs[civid].Units[a].UnitType.Name))) |
---|
679 | { |
---|
680 | //MessageBox.Show("ffff"); |
---|
681 | // UnitAmount[Rules.pCivs[civid].Units[a].UnitType.UnitId] = UnitAmount[Rules.pCivs[civid].Units[a].UnitType.UnitId] + 1; |
---|
682 | units = units + Rules.pCivs[civid].Units[a].UnitType.Name + "(" + BaseRules.Rules.GetUnitType_FromInt(Rules.pCivs[civid].Units[a].UnitType.UnitType) + BaseRules.Rules.GetMountedStatus_FromBool(Rules.pCivs[civid].Units[a].UnitType.Mounted) + ") HP: " + Rules.pCivs[civid].Units[a].HP * 100 + ";; " + Rules.pCivs[civid].Units[a].UnitType.Strength + " : " + |
---|
683 | Rules.pCivs[civid].Units[a].UnitType.Movement + " : " + Rules.pCivs[civid].Units[a].UnitType.Description + Environment.NewLine; |
---|
684 | //UnitAmount[Rules.pCivs[civid].Units[a].UnitType.UnitId] = Rules.pCivs[civid].Units[a].UnitType.UnitId + 1; |
---|
685 | } |
---|
686 | } |
---|
687 | return units; |
---|
688 | //} |
---|
689 | //return units; |
---|
690 | //MessageBox.Show(units); |
---|
691 | //MessageBox.Show("GetUnits... Stage 5"); |
---|
692 | //for (int b = 0; b <= 23; b++) |
---|
693 | //{ |
---|
694 | // if (UnitAmount[b] > 0) |
---|
695 | // { |
---|
696 | // // MessageBox.Show("GetUnits... Stage 6"); |
---|
697 | // if (UnitAmount[b] > 1) |
---|
698 | // { |
---|
699 | // //MessageBox.Show("GetUnits... Stage 7"); |
---|
700 | // units = units + BaseRules.Rules.getUnit_FromId(UnitAmount[b]).Name + " x" + UnitAmount[b] + Environment.NewLine; |
---|
701 | // return units; |
---|
702 | // } |
---|
703 | // else if (UnitAmount[b] == 1) |
---|
704 | // { |
---|
705 | // // MessageBox.Show("GetUnits... Stage 8"); |
---|
706 | // units = units + BaseRules.Rules.getUnit_FromId(UnitAmount[b]).Name + Environment.NewLine; |
---|
707 | // return units; |
---|
708 | // } |
---|
709 | // } |
---|
710 | //} |
---|
711 | //return units; |
---|
712 | // //MessageBox.Show("GetUnits... Stage 9"); |
---|
713 | |
---|
714 | // MessageBox.Show("GetUnits... Stage 10"); |
---|
715 | } |
---|
716 | |
---|
717 | public int GetUnit_FromPositionForSelection(int i, int j) |
---|
718 | { |
---|
719 | int civid; |
---|
720 | civid = OwnershipMap[i, j]; |
---|
721 | for (int a = 0; a <= Rules.pCivs[civid].NumberofUnits - 1; a++) |
---|
722 | { |
---|
723 | if (Rules.pCivs[civid].Units[a].PosY == i && Rules.pCivs[civid].Units[a].PosX == j) |
---|
724 | { |
---|
725 | return a; |
---|
726 | } |
---|
727 | } |
---|
728 | return -1; |
---|
729 | } |
---|
730 | |
---|
731 | public int GetUnit_FromPositionForRemoval(int i, int j, ALTKUnits.UnitClass unittype, double unitHP) |
---|
732 | { |
---|
733 | // MessageBox.Show("GetUnit_FromPosition: " + i + " " + j); |
---|
734 | int civid; |
---|
735 | civid = OwnershipMap[i, j]; |
---|
736 | for (int a = 0; a <= Rules.pCivs[civid].NumberofUnits - 1; a++) |
---|
737 | { |
---|
738 | if (Rules.pCivs[civid].Units[a].PosY == i && Rules.pCivs[civid].Units[a].PosX == j && Rules.pCivs[civid].Units[a].UnitType.Equals(unittype) && Rules.pCivs[civid].Units[a].HP == unitHP) |
---|
739 | { |
---|
740 | return a; |
---|
741 | } |
---|
742 | } |
---|
743 | return -1; |
---|
744 | } |
---|
745 | |
---|
746 | private void RemoveUnit(int i, int j, int civnumber, ALTKUnits.UnitClass unittype, double unitHP) |
---|
747 | { |
---|
748 | //MessageBox.Show(i + " " + j + " " + civnumber); |
---|
749 | int unitpos = GetUnit_FromPositionForRemoval(i, j, unittype, unitHP); |
---|
750 | if (unitpos > 0 && Rules.pCivs[civnumber].NumberofUnits > 2) |
---|
751 | { |
---|
752 | MessageBox.Show("FirstMethod"); |
---|
753 | for (int a = unitpos + 1; a <= Rules.pCivs[civnumber].NumberofUnits - 1; a++) |
---|
754 | { |
---|
755 | Rules.pCivs[civnumber].Units[a - 1].HP = Rules.pCivs[civnumber].Units[a].HP; |
---|
756 | Rules.pCivs[civnumber].Units[a - 1].PosY = Rules.pCivs[civnumber].Units[a].PosY; |
---|
757 | Rules.pCivs[civnumber].Units[a - 1].PosX = Rules.pCivs[civnumber].Units[a].PosX; |
---|
758 | Rules.pCivs[civnumber].Units[a - 1].UnitType = Rules.pCivs[civnumber].Units[a].UnitType; |
---|
759 | } |
---|
760 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosX = 0; |
---|
761 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosY = 0; |
---|
762 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].HP = 0.0; |
---|
763 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].UnitType = null; |
---|
764 | } |
---|
765 | else if (unitpos == 0 && Rules.pCivs[civnumber].NumberofUnits > 1) |
---|
766 | { |
---|
767 | MessageBox.Show("SecondMethod"); |
---|
768 | for (int a = 1; a <= Rules.pCivs[civnumber].NumberofUnits - 1; a++) |
---|
769 | { |
---|
770 | Rules.pCivs[civnumber].Units[a - 1].HP = Rules.pCivs[civnumber].Units[a].HP; |
---|
771 | Rules.pCivs[civnumber].Units[a - 1].PosY = Rules.pCivs[civnumber].Units[a].PosY; |
---|
772 | Rules.pCivs[civnumber].Units[a - 1].PosX = Rules.pCivs[civnumber].Units[a].PosX; |
---|
773 | Rules.pCivs[civnumber].Units[a - 1].UnitType = Rules.pCivs[civnumber].Units[a].UnitType; |
---|
774 | } |
---|
775 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosX = 0; |
---|
776 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosY = 0; |
---|
777 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].HP = 0.0; |
---|
778 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].UnitType = null; |
---|
779 | } |
---|
780 | else if (unitpos == 0 && Rules.pCivs[civnumber].NumberofUnits == 1) |
---|
781 | { |
---|
782 | MessageBox.Show("ThirdMethod"); |
---|
783 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosX = 0; |
---|
784 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosY = 0; |
---|
785 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].HP = 0.0; |
---|
786 | Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].UnitType = null; |
---|
787 | } |
---|
788 | Rules.pCivs[civnumber].NumberofUnits = Rules.pCivs[civnumber].NumberofUnits - 1; |
---|
789 | } |
---|
790 | |
---|
791 | public string setAIOwnershipColor(int playernumber) |
---|
792 | { |
---|
793 | int c; |
---|
794 | int b; |
---|
795 | bool ColorInUse = false; |
---|
796 | for (b = 0; b <= 20; b++) |
---|
797 | { |
---|
798 | ColorInUse = false; |
---|
799 | for (c = 0; c <= 30; c++) |
---|
800 | { |
---|
801 | if (Rules.pCivs[c].Color == getOwnershipColor_fromInt(b)) |
---|
802 | { |
---|
803 | ColorInUse = true; |
---|
804 | } |
---|
805 | } |
---|
806 | if (ColorInUse == false) |
---|
807 | { |
---|
808 | return getOwnershipColor_fromInt(b); |
---|
809 | } |
---|
810 | } |
---|
811 | return getOwnershipColor_fromInt(0); |
---|
812 | } |
---|
813 | |
---|
814 | public string getOwnershipColor_fromInt(Int32 color) |
---|
815 | { |
---|
816 | if (color == 0) { return "Aqua"; } |
---|
817 | if (color == 1) { return "Beige"; } |
---|
818 | if (color == 2) { return "Limegreen"; } |
---|
819 | if (color == 3) { return "Orange"; } |
---|
820 | if (color == 4) { return "Black"; } |
---|
821 | if (color == 5) { return "Red"; } |
---|
822 | if (color == 6) { return "Rustred"; } |
---|
823 | if (color == 7) { return "Yellow"; } |
---|
824 | if (color == 8) { return "Blue"; } |
---|
825 | if (color == 9) { return "Darkblue"; } |
---|
826 | if (color == 10) { return "Darkgreen"; } |
---|
827 | if (color == 11) { return "Lightblue"; } |
---|
828 | if (color == 12) { return "Purple"; } |
---|
829 | if (color == 13) { return "Darkpurple"; } |
---|
830 | if (color == 14) { return "Lightpurple"; } |
---|
831 | if (color == 15) { return "Gold"; } |
---|
832 | if (color == 16) { return "Silver"; } |
---|
833 | if (color == 17) { return "Pink"; } |
---|
834 | if (color == 18) { return "Teal"; } |
---|
835 | if (color == 19) { return "Greenyellow"; } |
---|
836 | if (color == 20) { return "Darkorange"; } |
---|
837 | if (color == 21) { return "White"; } |
---|
838 | if (color == 22) { return "Darkgray"; } |
---|
839 | return "Aqua"; |
---|
840 | } |
---|
841 | |
---|
842 | string getTexture_fromTerrainType(int terraintype, int terrainlayer, int i, int j) |
---|
843 | { |
---|
844 | if (terrainlayer == 0) |
---|
845 | { |
---|
846 | if (terraintype == Lehtimetsa) { return Application.StartupPath + "\\Content\\Textures\\grassland"; } |
---|
847 | if (terraintype == Vuoristo) { return Application.StartupPath + "\\Content\\Textures\\mountain"; } |
---|
848 | if (terraintype == Aavikko) { return Application.StartupPath + "\\Content\\Textures\\desert"; } |
---|
849 | if (terraintype == Tundra) { return Application.StartupPath + "\\Content\\Textures\\tundra"; } |
---|
850 | } |
---|
851 | else if (terrainlayer == 1) |
---|
852 | { |
---|
853 | if (terraintype == Tyhja) { return Application.StartupPath + "\\Content\\Textures\\nothing"; } |
---|
854 | if (terraintype == Vuoristo) { return Application.StartupPath + "\\Content\\Textures\\mountain"; } |
---|
855 | if (terraintype == Havumetsa) { return Application.StartupPath + "\\Content\\Textures\\forest"; } |
---|
856 | if (terraintype == Kuusimetsa) |
---|
857 | { |
---|
858 | if (TerrainMap[i, j] == 3) |
---|
859 | { |
---|
860 | return Application.StartupPath + "\\Content\\Textures\\spruceforestS"; |
---|
861 | } |
---|
862 | else |
---|
863 | { |
---|
864 | return Application.StartupPath + "\\Content\\Textures\\spruceforest"; |
---|
865 | } |
---|
866 | } |
---|
867 | // Jos terraintype on 10 tai enemmän, ruudussa on pelaajan kaupunki (ks. getTerrainType) |
---|
868 | if (terraintype >= 10) |
---|
869 | { |
---|
870 | if (TerrainMap[i, j] == Tundra) |
---|
871 | { |
---|
872 | return Application.StartupPath + "\\Content\\Textures\\cityancientTundra"; |
---|
873 | //DrawOwnership(i, j); |
---|
874 | } |
---|
875 | else |
---|
876 | { |
---|
877 | return Application.StartupPath + "\\Content\\Textures\\cityancient"; |
---|
878 | } |
---|
879 | } |
---|
880 | return Application.StartupPath + "\\Content\\Textures\\nothing"; |
---|
881 | } |
---|
882 | return Application.StartupPath + "\\Content\\Textures\\grassland.jpg"; |
---|
883 | } |
---|
884 | # endregion |
---|
885 | |
---|
886 | private void InitGUI() |
---|
887 | { |
---|
888 | TileDisp = new TextDisplay(); |
---|
889 | TileDisp.X = Screen.Left + 120; |
---|
890 | TileDisp.Y = Screen.Bottom + 200; |
---|
891 | TileDisp.TextColor = Color.White; |
---|
892 | |
---|
893 | UnitStatsDisp = new TextDisplay(); |
---|
894 | UnitStatsDisp.X = Screen.Left + 300; |
---|
895 | UnitStatsDisp.Y = Screen.Bottom + 400; |
---|
896 | UnitStatsDisp.Text = "d23"; |
---|
897 | UnitStatsDisp.TextColor = Color.DarkRed; |
---|
898 | |
---|
899 | ProductionDisp = new TextDisplay(); |
---|
900 | ProductionDisp.X = Screen.Right - 150; |
---|
901 | ProductionDisp.Y = Screen.Top - 50; |
---|
902 | ProductionDisp.Text = "Tuotanto: 10/120"; |
---|
903 | ProductionDisp.TextColor = Color.Wheat; |
---|
904 | |
---|
905 | BuildCityDisp = new TextDisplay(); |
---|
906 | BuildCityDisp.X = Screen.Right - 200; |
---|
907 | BuildCityDisp.Y = Screen.Top - 150; |
---|
908 | BuildCityDisp.TextColor = Color.Green; |
---|
909 | BuildCityDisp.Text = "Rakenna kaupunki"; |
---|
910 | |
---|
911 | //Mouse.ListenOn(BuildCityDisp, MouseButton.Left, Jypeli.ButtonState.Pressed, BuildCityClicked, "Rakenna kaupunki"); |
---|
912 | Keyboard.Listen(Key.B, Jypeli.ButtonState.Pressed, BuildCityClicked, "Rakenna kaupunki"); |
---|
913 | |
---|
914 | BuildUnitsDisp = new TextDisplay(); |
---|
915 | BuildUnitsDisp.X = Screen.Right - 120; |
---|
916 | BuildUnitsDisp.Y = Screen.Top - 200; |
---|
917 | BuildUnitsDisp.TextColor = Color.Green; |
---|
918 | BuildUnitsDisp.Text = "Rakenna yksiköitä (U)"; |
---|
919 | |
---|
920 | Keyboard.Listen(Key.U, Jypeli.ButtonState.Pressed, BuildUnitsClicked, "Näytä yksikkövalikko"); |
---|
921 | |
---|
922 | Unit1Disp = new TextDisplay(); |
---|
923 | Unit1Disp.X = Screen.Right - 150; |
---|
924 | Unit1Disp.Y = Screen.Top - 250; |
---|
925 | Unit1Disp.TextColor = Color.DarkGreen; |
---|
926 | Unit1Disp.Text = ""; |
---|
927 | |
---|
928 | Keyboard.Listen(Key.D1, Jypeli.ButtonState.Pressed, BuildUnit, "Rakenna 1. puun yksikkö", 1); |
---|
929 | |
---|
930 | Unit2Disp = new TextDisplay(); |
---|
931 | Unit2Disp.X = Screen.Right - 150; |
---|
932 | Unit2Disp.Y = Screen.Top - 300; |
---|
933 | Unit2Disp.TextColor = Color.DarkGreen; |
---|
934 | Unit2Disp.Text = ""; |
---|
935 | |
---|
936 | Keyboard.Listen(Key.D2, Jypeli.ButtonState.Pressed, BuildUnit, "Rakenna 2. puun yksikkö", 2); |
---|
937 | |
---|
938 | Unit3Disp = new TextDisplay(); |
---|
939 | Unit3Disp.X = Screen.Right - 150; |
---|
940 | Unit3Disp.Y = Screen.Top - 350; |
---|
941 | Unit3Disp.TextColor = Color.DarkGreen; |
---|
942 | Unit3Disp.Text = ""; |
---|
943 | |
---|
944 | Keyboard.Listen(Key.D3, Jypeli.ButtonState.Pressed, BuildUnit, "Rakenna 3. puun yksikkö", 3); |
---|
945 | |
---|
946 | Unit4Disp = new TextDisplay(); |
---|
947 | Unit4Disp.X = Screen.Right - 150; |
---|
948 | Unit4Disp.Y = Screen.Top - 400; |
---|
949 | Unit4Disp.TextColor = Color.DarkGreen; |
---|
950 | Unit4Disp.Text = ""; |
---|
951 | |
---|
952 | Keyboard.Listen(Key.D4, Jypeli.ButtonState.Pressed, BuildUnit, "Rakenna 4. puun yksikkö", 4); |
---|
953 | |
---|
954 | ResearchDisp = new TextDisplay(); |
---|
955 | ResearchDisp.X = Screen.Right - 200; |
---|
956 | ResearchDisp.Y = Screen.Top - 500; |
---|
957 | ResearchDisp.TextColor = Color.Green; |
---|
958 | ResearchDisp.Text = "Teknologia:" + Environment.NewLine + "Horseback Riding 199/200"; |
---|
959 | |
---|
960 | ResearchableTech1 = new TextDisplay(); |
---|
961 | ResearchableTech2 = new TextDisplay(); |
---|
962 | ResearchableTech3 = new TextDisplay(); |
---|
963 | |
---|
964 | ClicktoResearch = new TextDisplay(); |
---|
965 | ClicktoResearch.X = Screen.Right - 200; |
---|
966 | ClicktoResearch.Y = Screen.Top - 600; |
---|
967 | ClicktoResearch.TextColor = Color.Green; |
---|
968 | ClicktoResearch.Text = "Kehitä teknologiaa"; |
---|
969 | |
---|
970 | MessageDisplay.TextColor = Color.Orange; |
---|
971 | |
---|
972 | Add(TileDisp); |
---|
973 | Add(UnitStatsDisp); |
---|
974 | Add(ProductionDisp); |
---|
975 | Add(BuildCityDisp); |
---|
976 | Add(BuildUnitsDisp); |
---|
977 | Add(Unit1Disp); |
---|
978 | Add(Unit2Disp); |
---|
979 | Add(Unit3Disp); |
---|
980 | Add(Unit4Disp); |
---|
981 | Add(ResearchDisp); |
---|
982 | Add(ClicktoResearch); |
---|
983 | } |
---|
984 | |
---|
985 | private void BuildUnit(int unittree) |
---|
986 | { |
---|
987 | if (UnitBuildingMode == true) |
---|
988 | { |
---|
989 | int UnitCost = new int(); |
---|
990 | if (unittree == 1) |
---|
991 | { |
---|
992 | UnitCost = 20; |
---|
993 | } |
---|
994 | else if (unittree == 2) |
---|
995 | { |
---|
996 | UnitCost = 30; |
---|
997 | } |
---|
998 | else if (unittree == 3) |
---|
999 | { |
---|
1000 | UnitCost = 30; |
---|
1001 | } |
---|
1002 | else if (unittree == 4) |
---|
1003 | { |
---|
1004 | UnitCost = 40; |
---|
1005 | } |
---|
1006 | |
---|
1007 | if (UnitCost > CurrProduction) |
---|
1008 | { |
---|
1009 | MessageDisplay.Add("Sinulla ei ole tarpeeksi tuotantoa yksikön rakentamiseen."); |
---|
1010 | } |
---|
1011 | else |
---|
1012 | { |
---|
1013 | CurrProduction = CurrProduction - UnitCost; |
---|
1014 | ChangeProductionDispText(); |
---|
1015 | MessageDisplay.Add("Rakensit yksikön " + GetBuildableUnit(unittree).Name + ". Valitse kaupunki, mihin yksikkö rakennetaan."); |
---|
1016 | currentunit = GetBuildableUnit(unittree).UnitId; |
---|
1017 | UnitPositioningMode = true; |
---|
1018 | } |
---|
1019 | } |
---|
1020 | else |
---|
1021 | { |
---|
1022 | MessageDisplay.Add("Et ole yksikönrakennustilassa."); |
---|
1023 | } |
---|
1024 | } |
---|
1025 | |
---|
1026 | private ALTKUnits.UnitClass GetBuildableUnit(int unittree) |
---|
1027 | { |
---|
1028 | if (unittree == 1) |
---|
1029 | { |
---|
1030 | return BaseRules.Rules.Warrior; |
---|
1031 | } |
---|
1032 | if (unittree == 2) |
---|
1033 | { |
---|
1034 | return BaseRules.Rules.Archer; |
---|
1035 | } |
---|
1036 | if (unittree == 3) |
---|
1037 | { |
---|
1038 | return BaseRules.Rules.Spearman; |
---|
1039 | } |
---|
1040 | if (unittree == 4) |
---|
1041 | { |
---|
1042 | return BaseRules.Rules.Horseman; |
---|
1043 | } |
---|
1044 | return BaseRules.Rules.Warrior; |
---|
1045 | } |
---|
1046 | |
---|
1047 | private void BuildUnitsClicked() |
---|
1048 | { |
---|
1049 | if (UnitPositioningMode == true) |
---|
1050 | { |
---|
1051 | MessageDisplay.Add("Määritä aikaisemmalle yksikölle rakennussijainti."); |
---|
1052 | } |
---|
1053 | |
---|
1054 | if (UnitBuildingMode == true) |
---|
1055 | { |
---|
1056 | Unit1Disp.Text = ""; |
---|
1057 | Unit2Disp.Text = ""; |
---|
1058 | Unit3Disp.Text = ""; |
---|
1059 | Unit4Disp.Text = ""; |
---|
1060 | UnitBuildingMode = false; |
---|
1061 | } |
---|
1062 | else |
---|
1063 | { |
---|
1064 | UnitBuildingMode = true; |
---|
1065 | |
---|
1066 | // Muutetaan tekstit |
---|
1067 | SetUnitDispText(1); |
---|
1068 | SetUnitDispText(2); |
---|
1069 | SetUnitDispText(3); |
---|
1070 | SetUnitDispText(4); |
---|
1071 | } |
---|
1072 | } |
---|
1073 | |
---|
1074 | private void SetUnitDispText(int unitdisp) |
---|
1075 | { |
---|
1076 | if (unitdisp == 1) |
---|
1077 | { |
---|
1078 | Unit1Disp.Text = "Rakenna " + BaseRules.Rules.getUnit_FromId(BaseRules.Rules.T1Units[0]).Name + " [1] (20)"; |
---|
1079 | } |
---|
1080 | else if (unitdisp == 2) |
---|
1081 | { |
---|
1082 | Unit2Disp.Text = "Rakenna " + BaseRules.Rules.getUnit_FromId(BaseRules.Rules.T2Units[0]).Name + " [2] (30)"; |
---|
1083 | } |
---|
1084 | else if (unitdisp == 3) |
---|
1085 | { |
---|
1086 | Unit3Disp.Text = "Rakenna " + BaseRules.Rules.getUnit_FromId(BaseRules.Rules.T3Units[0]).Name + " [3] (30)"; |
---|
1087 | } |
---|
1088 | else if (unitdisp == 4) |
---|
1089 | { |
---|
1090 | Unit4Disp.Text = "Rakenna " + BaseRules.Rules.getUnit_FromId(BaseRules.Rules.T4Units[0]).Name + " [4] (40)"; |
---|
1091 | } |
---|
1092 | } |
---|
1093 | |
---|
1094 | private void BuildCityClicked() |
---|
1095 | { |
---|
1096 | TileClickAllowed = false; |
---|
1097 | if (CityPlaceSelection == false) |
---|
1098 | { |
---|
1099 | Rules.pCivs[CurrentPlayer].BuiltFromCity = Rules.pCivs[CurrentPlayer].BuiltFromCity + CurrProduction; |
---|
1100 | CurrProduction = 0; |
---|
1101 | BuildCityDisp.Text = "Rakenna kaupunki (B) (" + Rules.pCivs[CurrentPlayer].BuiltFromCity + " / " + Rules.pCivs[CurrentPlayer].Production + ")"; |
---|
1102 | ChangeProductionDispText(); |
---|
1103 | if (Rules.pCivs[CurrentPlayer].BuiltFromCity > Rules.pCivs[CurrentPlayer].Production | Rules.pCivs[CurrentPlayer].BuiltFromCity == Rules.pCivs[CurrentPlayer].Production) |
---|
1104 | { |
---|
1105 | CurrProduction = Rules.pCivs[CurrentPlayer].BuiltFromCity - Rules.pCivs[CurrentPlayer].Production; |
---|
1106 | MessageDisplay.Add("Sait kaupungin valmiiksi; valitse uuden kaupungin sijainti."); |
---|
1107 | BuildCityDisp.Text = "Peruuta kaupungin rakentaminen (B) (" + Rules.pCivs[CurrentPlayer].Production / 2 + ")"; |
---|
1108 | BuildCityDisp.TextColor = Color.Red; |
---|
1109 | BuildCityDisp.X = BuildCityDisp.X - 20; |
---|
1110 | ChangeProductionDispText(); |
---|
1111 | CityPlaceSelection = true; |
---|
1112 | } |
---|
1113 | } |
---|
1114 | else |
---|
1115 | { |
---|
1116 | BuildCityDisp.TextColor = Color.Green; |
---|
1117 | BuildCityDisp.X = BuildCityDisp.X + 20; |
---|
1118 | Rules.pCivs[CurrentPlayer].BuiltFromCity = 0; |
---|
1119 | BuildCityDisp.Text = "Rakenna kaupunki (B) (" + Rules.pCivs[CurrentPlayer].BuiltFromCity + " / " + Rules.pCivs[CurrentPlayer].Production + ")"; |
---|
1120 | CityPlaceSelection = false; |
---|
1121 | CurrProduction = CurrProduction + (Rules.pCivs[CurrentPlayer].Production / 2); |
---|
1122 | ChangeProductionDispText(); |
---|
1123 | } |
---|
1124 | TileClickAllowed = true; |
---|
1125 | } |
---|
1126 | |
---|
1127 | private void ChangeProductionDispText() |
---|
1128 | { |
---|
1129 | ProductionDisp.Text = "Vuoro: " + TurnNumber + Environment.NewLine + |
---|
1130 | "Tuotantoa vuorossa: " + Rules.pCivs[CurrentPlayer].Production + Environment.NewLine + |
---|
1131 | "Tuotantoa jäljellä: " + CurrProduction; |
---|
1132 | } |
---|
1133 | |
---|
1134 | private void InitRules() |
---|
1135 | { |
---|
1136 | // Käytetään valmiiksi tehtyjä DLL-tiedostoja |
---|
1137 | BaseRules.Rules.InitTechs(); |
---|
1138 | BaseRules.Rules.InitUnits(); |
---|
1139 | BaseRules.Rules.InitDifficulty(); |
---|
1140 | BaseRules.Rules.InitCivs(); |
---|
1141 | BaseRules.Rules.InitAIBehaviour(); |
---|
1142 | } |
---|
1143 | |
---|
1144 | private void RemoveShroud(int i, int j) |
---|
1145 | { |
---|
1146 | try |
---|
1147 | { |
---|
1148 | ShroudMap[i, j] = 0; |
---|
1149 | ShroudTile[i, j].Destroy(); |
---|
1150 | try |
---|
1151 | { |
---|
1152 | if (OwnershipMap[i, j] > -1) |
---|
1153 | { |
---|
1154 | DrawOwnership(i, j); |
---|
1155 | } |
---|
1156 | } |
---|
1157 | catch |
---|
1158 | { |
---|
1159 | } |
---|
1160 | } |
---|
1161 | catch |
---|
1162 | { |
---|
1163 | MessageDisplay.Add("Shroud not removed from tile " + i + "; " + j + " because of IndexoutofRange exception."); |
---|
1164 | } |
---|
1165 | } |
---|
1166 | |
---|
1167 | private void CheckAndRemoveShroud_FromPos(int i, int j) |
---|
1168 | { |
---|
1169 | RemoveShroud(i, j); |
---|
1170 | for (int shri = i - 2; shri <= i + 2; shri++) |
---|
1171 | { |
---|
1172 | for (int shrj = j - 2; shrj <= j + 2; shrj++) |
---|
1173 | { |
---|
1174 | RemoveShroud(shri, shrj); |
---|
1175 | } |
---|
1176 | } |
---|
1177 | } |
---|
1178 | |
---|
1179 | private void TurnSystem_Start(int playernumber) |
---|
1180 | { |
---|
1181 | TurnNumber = TurnNumber + 1; |
---|
1182 | MessageDisplay.Add("Vuorosi on alkanut!"); |
---|
1183 | CurrentPlayer = playernumber; |
---|
1184 | CurrProduction = Rules.pCivs[playernumber].Production; |
---|
1185 | ProductionDisp.Text = "Vuoro: " + TurnNumber + Environment.NewLine + |
---|
1186 | "Tuotantoa vuorossa: " + Rules.pCivs[playernumber].Production + Environment.NewLine + |
---|
1187 | "Tuotantoa jäljellä: " + CurrProduction; |
---|
1188 | BuildCityDisp.Text = "Rakenna kaupunki (B) (" + Rules.pCivs[playernumber].BuiltFromCity + " / " + Rules.pCivs[playernumber].Production + ")"; |
---|
1189 | if (TurnNumber == 1) |
---|
1190 | { |
---|
1191 | //CreateUnit(Rules.pCivs[playernumber].CityCoords[0, 0], Rules.pCivs[playernumber].CityCoords[0, 1], Rules.Archer, playernumber); |
---|
1192 | //CreateUnit(Rules.pCivs[playernumber].CityCoords[0, 0], Rules.pCivs[playernumber].CityCoords[0, 1], Rules.Archer, playernumber); |
---|
1193 | CreateUnit(Rules.pCivs[playernumber].CityCoords[0, 0], Rules.pCivs[playernumber].CityCoords[0, 1], Rules.Deathbringer, playernumber); |
---|
1194 | //RemoveUnit(Rules.pCivs[playernumber].Units[0].PosY, Rules.pCivs[playernumber].Units[0].PosX, playernumber); |
---|
1195 | } |
---|
1196 | for (int a = 0; a < Rules.pCivs[playernumber].NumberofUnits; a++) |
---|
1197 | { |
---|
1198 | Rules.pCivs[playernumber].Units[a].CurrentMovementPoints = Rules.pCivs[playernumber].Units[a].UnitType.Movement; |
---|
1199 | } |
---|
1200 | } |
---|
1201 | |
---|
1202 | protected override void Update(Time time) |
---|
1203 | { |
---|
1204 | base.Update(time); |
---|
1205 | // Mouse.PositionOnScreen voisi olla vain positiivinen, eikä ruudun pitäisi jakautua keskeltä kahtia |
---|
1206 | // negatiivisiin ja positiivisiin kokonaislukuihin |
---|
1207 | |
---|
1208 | if (gamestarted == true) |
---|
1209 | { |
---|
1210 | for (int i = 0; i <= (kartanKorkeus - 1); i++) |
---|
1211 | { |
---|
1212 | for (int j = 0; j <= (kartanLeveys - 1); j++) |
---|
1213 | { |
---|
1214 | if (Mouse.IsCursorOnGameObject(tile[i, j])) |
---|
1215 | { |
---|
1216 | TileDisp.Text = getTileInfo_forTileDisp(i, j); |
---|
1217 | if (UnitsSelected == false) |
---|
1218 | { |
---|
1219 | UnitStatsDisp.Text = getUnitDisp(i, j, 0); |
---|
1220 | } |
---|
1221 | //Application.DoEvents(); |
---|
1222 | } |
---|
1223 | //Mouse.ListenMovement(tile[i, j], showTileInfo_forTileDisp, null, i, j); |
---|
1224 | // MessageBox.Show(Convert.ToString(TerrainMap[i, j])); |
---|
1225 | } |
---|
1226 | } |
---|
1227 | //TileDisp.Text = getTileInfo_forTileDisp(Convert.ToInt32(Mouse.PositionOnWorld.X) / -48, Convert.ToInt32(Mouse.PositionOnWorld.Y) / 48); |
---|
1228 | if (Mouse.PositionOnScreen.X > MouseScreenWidth) { MoveCamera(0); } |
---|
1229 | else if (Mouse.PositionOnScreen.X < NegMouseScreenWidth) { MoveCamera(2); } |
---|
1230 | else if (Mouse.PositionOnScreen.Y > MouseScreenHeight) { MoveCamera(1); } |
---|
1231 | else if (Mouse.PositionOnScreen.Y < NegMouseScreenHeight) { MoveCamera(3); } |
---|
1232 | } |
---|
1233 | } |
---|
1234 | |
---|
1235 | public string getTileInfo_forTileDisp(int i, int j) |
---|
1236 | { |
---|
1237 | // Haetaan tiedot ruudulle |
---|
1238 | string tileinfo; |
---|
1239 | int Defensebonus = new int(); |
---|
1240 | tileinfo = i + "; " + j + " :" + Environment.NewLine; |
---|
1241 | //MessageBox.Show(i + " " + j); |
---|
1242 | // Maaston perustiedot |
---|
1243 | if (TerrainMap[i, j] == 0) |
---|
1244 | { |
---|
1245 | tileinfo = tileinfo + "Ruohotasankoa"; |
---|
1246 | } |
---|
1247 | else if (TerrainMap[i, j] == 1) |
---|
1248 | { |
---|
1249 | tileinfo = tileinfo + "Vuoristoa"; |
---|
1250 | } |
---|
1251 | else if (TerrainMap[i, j] == 2) |
---|
1252 | { |
---|
1253 | tileinfo = tileinfo + "Aavikkoa"; |
---|
1254 | Defensebonus = Defensebonus - 25; |
---|
1255 | } |
---|
1256 | else if (TerrainMap[i, j] == 3) |
---|
1257 | { |
---|
1258 | tileinfo = tileinfo + "Tundraa"; |
---|
1259 | Defensebonus = Defensebonus + 10; |
---|
1260 | } |
---|
1261 | |
---|
1262 | // Erikoismaaston tiedot |
---|
1263 | |
---|
1264 | if (DTerrainMap[i, j] == 0) |
---|
1265 | { |
---|
1266 | } |
---|
1267 | else if (DTerrainMap[i, j] == 1) |
---|
1268 | { |
---|
1269 | tileinfo = tileinfo + Environment.NewLine + "Vuoristoa" + Environment.NewLine + "Läpipääsemätön"; |
---|
1270 | } |
---|
1271 | else if (DTerrainMap[i, j] == 2) |
---|
1272 | { |
---|
1273 | tileinfo = tileinfo + Environment.NewLine + "Lehtimetsää"; |
---|
1274 | Defensebonus = Defensebonus + 10; |
---|
1275 | } |
---|
1276 | else if (DTerrainMap[i, j] == 3) |
---|
1277 | { |
---|
1278 | tileinfo = tileinfo + Environment.NewLine + "Kuusimetsää"; |
---|
1279 | Defensebonus = Defensebonus + 25; |
---|
1280 | } |
---|
1281 | else |
---|
1282 | { |
---|
1283 | // MessageBox.Show(Convert.ToString(ShroudMap[i, j])); |
---|
1284 | if (ShroudMap[i, j] == 0) |
---|
1285 | { |
---|
1286 | try |
---|
1287 | { |
---|
1288 | if (OwnershipMap[i, j] >= -1) |
---|
1289 | { |
---|
1290 | tileinfo = tileinfo + Environment.NewLine + "Kaupunki"; |
---|
1291 | } |
---|
1292 | } |
---|
1293 | catch |
---|
1294 | { |
---|
1295 | } |
---|
1296 | } |
---|
1297 | } |
---|
1298 | |
---|
1299 | if (ShroudMap[i, j] == 0) |
---|
1300 | { |
---|
1301 | try |
---|
1302 | { |
---|
1303 | if (OwnershipMap[i, j] > -1) |
---|
1304 | { |
---|
1305 | tileinfo = tileinfo + Environment.NewLine + Rules.pCivs[OwnershipMap[i, j]].Name; |
---|
1306 | } |
---|
1307 | } |
---|
1308 | catch |
---|
1309 | { |
---|
1310 | } |
---|
1311 | |
---|
1312 | if (Defensebonus != 0) |
---|
1313 | { |
---|
1314 | return tileinfo = tileinfo + Environment.NewLine + "Puolustusbonus: " + Defensebonus + "%"; |
---|
1315 | } |
---|
1316 | else |
---|
1317 | { |
---|
1318 | return tileinfo; |
---|
1319 | } |
---|
1320 | } |
---|
1321 | return tileinfo; |
---|
1322 | } |
---|
1323 | |
---|
1324 | public string getUnitDisp(int i, int j, int s) |
---|
1325 | { |
---|
1326 | string unitinfo = ""; |
---|
1327 | if (ShroudMap[i, j] == 0) |
---|
1328 | { |
---|
1329 | try |
---|
1330 | { |
---|
1331 | if (OwnershipMap[i, j] > -1) |
---|
1332 | { |
---|
1333 | //MessageBox.Show("OwnershipMap passed:" + i + " " + j + " UnitMap: " + UnitMap[i, j]); |
---|
1334 | //MessageBox.Show(Convert.ToString(0 > -1)); |
---|
1335 | if (UnitMap[i, j] > -1) |
---|
1336 | { |
---|
1337 | //MessageBox.Show("UnitMap passed:" + i + " " + j); |
---|
1338 | //string unitstats; |
---|
1339 | if (s == 0) |
---|
1340 | { |
---|
1341 | unitinfo = "Ruudun yksiköt: " + Environment.NewLine + GetUnits_FromPositionForView(i, j); |
---|
1342 | } |
---|
1343 | else if (s == 1) |
---|
1344 | { |
---|
1345 | unitinfo = "Valitut yksiköt: " + Environment.NewLine + GetUnits_FromPositionForView(i, j); |
---|
1346 | } |
---|
1347 | } |
---|
1348 | } |
---|
1349 | } |
---|
1350 | catch |
---|
1351 | { |
---|
1352 | } |
---|
1353 | } |
---|
1354 | return unitinfo; |
---|
1355 | } |
---|
1356 | |
---|
1357 | private void EndTurn() |
---|
1358 | { |
---|
1359 | MessageDisplay.Add("Lopetit vuorosi.."); |
---|
1360 | if (SelectedUnit > -1) |
---|
1361 | { |
---|
1362 | DeselectUnit(); |
---|
1363 | } |
---|
1364 | TurnSystem_Start(CurrentPlayer); |
---|
1365 | } |
---|
1366 | |
---|
1367 | private void InitControls() |
---|
1368 | { |
---|
1369 | Keyboard.Listen(Key.Right, Jypeli.ButtonState.Down, MoveCamera, null, 0); |
---|
1370 | Keyboard.Listen(Key.Left, Jypeli.ButtonState.Down, MoveCamera, null, 2); |
---|
1371 | Keyboard.Listen(Key.Up, Jypeli.ButtonState.Down, MoveCamera, null, 1); |
---|
1372 | Keyboard.Listen(Key.Down, Jypeli.ButtonState.Down, MoveCamera, null, 3); |
---|
1373 | Keyboard.Listen(Key.Tab, Jypeli.ButtonState.Down, ActivateDebug, null, 0); |
---|
1374 | Keyboard.Listen(Key.Enter, Jypeli.ButtonState.Pressed, EndTurn, null); |
---|
1375 | |
---|
1376 | Keyboard.Listen(Key.NumPad1, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä lounaaseen.", 1); |
---|
1377 | Keyboard.Listen(Key.NumPad2, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä etelään.", 2); |
---|
1378 | Keyboard.Listen(Key.NumPad3, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä kaakkoon.", 3); |
---|
1379 | Keyboard.Listen(Key.NumPad4, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä länteen.", 4); |
---|
1380 | Keyboard.Listen(Key.NumPad5, Jypeli.ButtonState.Pressed, MoveUnit, "Hyppää yksikkö yli.", 5); |
---|
1381 | Keyboard.Listen(Key.NumPad6, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä itään.", 6); |
---|
1382 | Keyboard.Listen(Key.NumPad7, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä luoteeseen.", 7); |
---|
1383 | Keyboard.Listen(Key.NumPad8, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä pohjoiseen.", 8); |
---|
1384 | Keyboard.Listen(Key.NumPad9, Jypeli.ButtonState.Pressed, MoveUnit, "Liikuta yksikköä koilliseen.", 9); |
---|
1385 | Keyboard.Listen(Key.End, Jypeli.ButtonState.Pressed, SelectUnits, "Valitsee yksiköitä."); |
---|
1386 | Keyboard.Listen(Key.Home, Jypeli.ButtonState.Pressed, SelectNextUnit, "Valitsee seuraavan yksikön."); |
---|
1387 | |
---|
1388 | //Keyboard.Disable(Key.NumPad1); |
---|
1389 | //Keyboard.Disable(Key.NumPad2); |
---|
1390 | //Keyboard.Disable(Key.NumPad3); |
---|
1391 | //Keyboard.Disable(Key.NumPad4); |
---|
1392 | //Keyboard.Disable(Key.NumPad5); |
---|
1393 | //Keyboard.Disable(Key.NumPad6); |
---|
1394 | //Keyboard.Disable(Key.NumPad7); |
---|
1395 | //Keyboard.Disable(Key.NumPad8); |
---|
1396 | //Keyboard.Disable(Key.NumPad9); |
---|
1397 | |
---|
1398 | MouseScreenWidth = new int(); |
---|
1399 | MouseScreenWidth = Convert.ToInt32(Peli.Screen.Width / 2) - 5; |
---|
1400 | MouseScreenHeight = new int(); |
---|
1401 | MouseScreenHeight = Convert.ToInt32(Peli.Screen.Height / 2) - 5; |
---|
1402 | NegMouseScreenWidth = new int(); |
---|
1403 | NegMouseScreenWidth = Convert.ToInt32(Peli.Screen.Width / -2) + 5; |
---|
1404 | NegMouseScreenHeight = new int(); |
---|
1405 | NegMouseScreenHeight = Convert.ToInt32(Peli.Screen.Height / -2) + 20; |
---|
1406 | } |
---|
1407 | |
---|
1408 | private void EnterCombat(int i, int j, int ab, int bb) |
---|
1409 | { |
---|
1410 | if (DTerrainMap[i, j] > 9) |
---|
1411 | { |
---|
1412 | if (UnitMap[i, j] > -1) |
---|
1413 | { |
---|
1414 | |
---|
1415 | } |
---|
1416 | else |
---|
1417 | { |
---|
1418 | CityCapture(i, j, ab, bb); |
---|
1419 | } |
---|
1420 | } |
---|
1421 | } |
---|
1422 | |
---|
1423 | private void CityCapture(int i, int j, int ab, int bb) |
---|
1424 | { |
---|
1425 | RemoveCity_FromCivFromPosition(i, j); |
---|
1426 | Rules.pCivs[OwnershipMap[i, j]].NumberofCities = Rules.pCivs[OwnershipMap[i, j]].NumberofCities - 1; |
---|
1427 | Rules.pCivs[OwnershipMap[i, j]].Production = Rules.pCivs[OwnershipMap[i, j]].Production - 10; |
---|
1428 | MessageDisplay.TextColor = Color.Red; |
---|
1429 | MessageDisplay.Add(Rules.pCivs[CurrentPlayer].Name + " on valloittanut kaupungin ruudusta " + i + "; " + j + " (" + Rules.pCivs[OwnershipMap[i, j]].Name + ")"); |
---|
1430 | Thread.Sleep(1000); |
---|
1431 | if (Rules.pCivs[OwnershipMap[i, j]].NumberofCities == 0) |
---|
1432 | { |
---|
1433 | MessageDisplay.Add(Rules.pCivs[OwnershipMap[i, j]].Name + " has been destroyed!"); |
---|
1434 | Rules.pCivs[OwnershipMap[i, j]].Enabled = false; |
---|
1435 | } |
---|
1436 | OwnershipMap[i, j] = CurrentPlayer; |
---|
1437 | DrawOwnership(i, j); |
---|
1438 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY = i; |
---|
1439 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX = j; |
---|
1440 | MessageDisplay.TextColor = Color.Orange; |
---|
1441 | AddCity(i, j); |
---|
1442 | |
---|
1443 | if (GetUnit_FromPositionForSelection(ab, bb) == -1) |
---|
1444 | { |
---|
1445 | OwnershipMap[ab, bb] = -1; |
---|
1446 | TileOwnership[ab, bb].Image = LoadImage(Textpath + "nothing"); |
---|
1447 | } |
---|
1448 | DrawUnit(i, j); |
---|
1449 | } |
---|
1450 | |
---|
1451 | private void AddCity(int i, int j) |
---|
1452 | { |
---|
1453 | Rules.pCivs[CurrentPlayer].Production = Rules.pCivs[CurrentPlayer].Production + 10; |
---|
1454 | Rules.pCivs[CurrentPlayer].NumberofCities = Rules.pCivs[CurrentPlayer].NumberofCities + 1; |
---|
1455 | Rules.pCivs[CurrentPlayer].CityCoords[Rules.pCivs[CurrentPlayer].NumberofCities - 1, 0] = i; |
---|
1456 | Rules.pCivs[CurrentPlayer].CityCoords[Rules.pCivs[CurrentPlayer].NumberofCities - 1, 1] = j; |
---|
1457 | BuildCityDisp.Text = "Rakenna kaupunki (B) (" + Rules.pCivs[CurrentPlayer].BuiltFromCity + " / " + Rules.pCivs[CurrentPlayer].Production + ")"; |
---|
1458 | CityPlaceSelection = false; |
---|
1459 | ChangeProductionDispText(); |
---|
1460 | DTerrainMap[i, j] = CurrentPlayer + 10; |
---|
1461 | DTile[i, j].Image = LoadImage(Textpath + "cityancient"); |
---|
1462 | CheckAndRemoveShroud_FromPos(i, j); |
---|
1463 | if (OwnershipMap[i, j] == -1) |
---|
1464 | { |
---|
1465 | OwnershipMap[i, j] = CurrentPlayer; |
---|
1466 | DrawOwnership(i, j); |
---|
1467 | CheckAndRemoveShroud_FromPos(i, j); |
---|
1468 | } |
---|
1469 | } |
---|
1470 | |
---|
1471 | public int GetCityPosInArray_ForRemoval(int i, int j, int civid) |
---|
1472 | { |
---|
1473 | for (int a = 0; a <= Rules.pCivs[civid].NumberofCities - 1; a++) |
---|
1474 | { |
---|
1475 | if (Rules.pCivs[civid].CityCoords[a, 0] == i && Rules.pCivs[civid].CityCoords[a, 1] == j) |
---|
1476 | { |
---|
1477 | return a; |
---|
1478 | } |
---|
1479 | } |
---|
1480 | return 0; |
---|
1481 | } |
---|
1482 | |
---|
1483 | private void RemoveCity_FromCivFromPosition(int i, int j) |
---|
1484 | { |
---|
1485 | int civowner = new int(); |
---|
1486 | civowner = OwnershipMap[i, j]; |
---|
1487 | int cityPosInArray = GetCityPosInArray_ForRemoval(i, j, civowner); |
---|
1488 | |
---|
1489 | if (cityPosInArray > 0 && Rules.pCivs[civowner].NumberofCities > 2) |
---|
1490 | { |
---|
1491 | for (int a = cityPosInArray + 1; a <= Rules.pCivs[civowner].NumberofCities - 1; a++) |
---|
1492 | { |
---|
1493 | Rules.pCivs[civowner].CityCoords[a - 1, 0] = Rules.pCivs[civowner].CityCoords[a, 0]; |
---|
1494 | Rules.pCivs[civowner].CityCoords[a - 1, 1] = Rules.pCivs[civowner].CityCoords[a, 1]; |
---|
1495 | } |
---|
1496 | Rules.pCivs[civowner].CityCoords[Rules.pCivs[civowner].NumberofCities - 1, 0] = 0; |
---|
1497 | Rules.pCivs[civowner].CityCoords[Rules.pCivs[civowner].NumberofCities - 1, 1] = 0; |
---|
1498 | } |
---|
1499 | else if (cityPosInArray == 0 && Rules.pCivs[civowner].NumberofCities > 1) |
---|
1500 | { |
---|
1501 | for (int a = 1; a <= Rules.pCivs[civowner].NumberofCities - 1; a++) |
---|
1502 | { |
---|
1503 | Rules.pCivs[civowner].CityCoords[a - 1, 0] = Rules.pCivs[civowner].CityCoords[a, 0]; |
---|
1504 | Rules.pCivs[civowner].CityCoords[a - 1, 1] = Rules.pCivs[civowner].CityCoords[a, 1]; |
---|
1505 | } |
---|
1506 | Rules.pCivs[civowner].CityCoords[Rules.pCivs[civowner].NumberofCities - 1, 0] = 0; |
---|
1507 | Rules.pCivs[civowner].CityCoords[Rules.pCivs[civowner].NumberofCities - 1, 1] = 0; |
---|
1508 | } |
---|
1509 | else if (Rules.pCivs[civowner].NumberofCities == 1) |
---|
1510 | { |
---|
1511 | Rules.pCivs[civowner].CityCoords[0, 0] = 0; |
---|
1512 | Rules.pCivs[civowner].CityCoords[0, 1] = 0; |
---|
1513 | Rules.pCivs[civowner].Enabled = false; |
---|
1514 | } |
---|
1515 | // int unitpos = GetUnit_FromPositionForRemoval(i, j, unittype, unitHP); |
---|
1516 | // if (unitpos > 0 && Rules.pCivs[civnumber].NumberofUnits > 2) |
---|
1517 | // { |
---|
1518 | // MessageBox.Show("FirstMethod"); |
---|
1519 | // for (int a = unitpos + 1; a <= Rules.pCivs[civnumber].NumberofUnits - 1; a++) |
---|
1520 | // { |
---|
1521 | // Rules.pCivs[civnumber].Units[a - 1].HP = Rules.pCivs[civnumber].Units[a].HP; |
---|
1522 | // Rules.pCivs[civnumber].Units[a - 1].PosY = Rules.pCivs[civnumber].Units[a].PosY; |
---|
1523 | // Rules.pCivs[civnumber].Units[a - 1].PosX = Rules.pCivs[civnumber].Units[a].PosX; |
---|
1524 | // Rules.pCivs[civnumber].Units[a - 1].UnitType = Rules.pCivs[civnumber].Units[a].UnitType; |
---|
1525 | // } |
---|
1526 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosX = 0; |
---|
1527 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosY = 0; |
---|
1528 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].HP = 0.0; |
---|
1529 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].UnitType = null; |
---|
1530 | // } |
---|
1531 | // else if (unitpos == 0 && Rules.pCivs[civnumber].NumberofUnits > 1) |
---|
1532 | // { |
---|
1533 | // MessageBox.Show("SecondMethod"); |
---|
1534 | // for (int a = 1; a <= Rules.pCivs[civnumber].NumberofUnits - 1; a++) |
---|
1535 | // { |
---|
1536 | // Rules.pCivs[civnumber].Units[a - 1].HP = Rules.pCivs[civnumber].Units[a].HP; |
---|
1537 | // Rules.pCivs[civnumber].Units[a - 1].PosY = Rules.pCivs[civnumber].Units[a].PosY; |
---|
1538 | // Rules.pCivs[civnumber].Units[a - 1].PosX = Rules.pCivs[civnumber].Units[a].PosX; |
---|
1539 | // Rules.pCivs[civnumber].Units[a - 1].UnitType = Rules.pCivs[civnumber].Units[a].UnitType; |
---|
1540 | // } |
---|
1541 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosX = 0; |
---|
1542 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosY = 0; |
---|
1543 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].HP = 0.0; |
---|
1544 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].UnitType = null; |
---|
1545 | // } |
---|
1546 | // else if (unitpos == 0 && Rules.pCivs[civnumber].NumberofUnits == 1) |
---|
1547 | // { |
---|
1548 | // MessageBox.Show("ThirdMethod"); |
---|
1549 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosX = 0; |
---|
1550 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].PosY = 0; |
---|
1551 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].HP = 0.0; |
---|
1552 | // Rules.pCivs[civnumber].Units[Rules.pCivs[civnumber].NumberofUnits - 1].UnitType = null; |
---|
1553 | // } |
---|
1554 | // Rules.pCivs[civnumber].NumberofUnits = Rules.pCivs[civnumber].NumberofUnits - 1; |
---|
1555 | //} |
---|
1556 | } |
---|
1557 | |
---|
1558 | private void SelectNextUnit() |
---|
1559 | { |
---|
1560 | try |
---|
1561 | { |
---|
1562 | SelectedUnit = SelectedUnit + 1; |
---|
1563 | UnitsSelected = true; |
---|
1564 | UnitTile[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX].Image = LoadImage(OwnershipColorPath + "unitsOnTileSelected"); |
---|
1565 | MessageDisplay.Add("Valitsit yksikön " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].UnitType.Name + " kohteesta " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + "; " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1566 | MessageDisplay.Add("Liikuta valittua yksikköä Numpadista."); |
---|
1567 | UnitStatsDisp.Text = "Valittu yksikkö:" + Environment.NewLine + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].UnitType.Name + |
---|
1568 | Environment.NewLine + "-Voimakkuus: " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].UnitType.Strength + Environment.NewLine + |
---|
1569 | "-Liikkuvuus: " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].UnitType.Movement + Environment.NewLine + |
---|
1570 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].UnitType.Description + Environment.NewLine + |
---|
1571 | " HP: " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].HP * 100 + "/100"; |
---|
1572 | return; |
---|
1573 | } |
---|
1574 | catch |
---|
1575 | { |
---|
1576 | SelectedUnit = -1; |
---|
1577 | UnitsSelected = false; |
---|
1578 | MessageDisplay.Add("Ei ole enempää yksiköitä valittavaksi."); |
---|
1579 | } |
---|
1580 | } |
---|
1581 | |
---|
1582 | private void SelectUnits() |
---|
1583 | { |
---|
1584 | //MessageBox.Show("SelectNextUnit"); |
---|
1585 | for (int a = 0; a <= Rules.pCivs[CurrentPlayer].NumberofUnits - 1; a++) |
---|
1586 | { |
---|
1587 | if (Rules.pCivs[CurrentPlayer].Units[a].CurrentMovementPoints == 1 | Rules.pCivs[CurrentPlayer].Units[a].CurrentMovementPoints > 1) |
---|
1588 | { |
---|
1589 | SelectedUnit = a; |
---|
1590 | UnitsSelected = true; |
---|
1591 | UnitTile[Rules.pCivs[CurrentPlayer].Units[a].PosY, Rules.pCivs[CurrentPlayer].Units[a].PosX].Image = LoadImage(OwnershipColorPath + "unitsOnTileSelected"); |
---|
1592 | MessageDisplay.Add("Valitsit yksikön " + Rules.pCivs[CurrentPlayer].Units[a].UnitType.Name + " kohteesta " + Rules.pCivs[CurrentPlayer].Units[a].PosY + "; " + Rules.pCivs[CurrentPlayer].Units[a].PosX); |
---|
1593 | MessageDisplay.Add("Liikuta valittua yksikköä Numpadista."); |
---|
1594 | UnitStatsDisp.Text = "Valittu yksikkö:" + Environment.NewLine + Rules.pCivs[CurrentPlayer].Units[a].UnitType.Name + |
---|
1595 | Environment.NewLine + "-Voimakkuus: " + Rules.pCivs[CurrentPlayer].Units[a].UnitType.Strength + Environment.NewLine + |
---|
1596 | "-Liikkuvuus: " + Rules.pCivs[CurrentPlayer].Units[a].UnitType.Movement + Environment.NewLine + |
---|
1597 | Rules.pCivs[CurrentPlayer].Units[a].UnitType.Description + Environment.NewLine + |
---|
1598 | " HP: " + Rules.pCivs[CurrentPlayer].Units[a].HP * 100 + "/100"; |
---|
1599 | return; |
---|
1600 | } |
---|
1601 | } |
---|
1602 | } |
---|
1603 | |
---|
1604 | private void MoveUnit(int direction) |
---|
1605 | { |
---|
1606 | if (SelectedUnit == -1) |
---|
1607 | { |
---|
1608 | MessageDisplay.Add("Ei ole yksikköä valittuna."); |
---|
1609 | } |
---|
1610 | else |
---|
1611 | { |
---|
1612 | if (direction == 1) |
---|
1613 | { |
---|
1614 | UnitMovementMain(-1, -1); |
---|
1615 | } |
---|
1616 | else if (direction == 2) |
---|
1617 | { |
---|
1618 | UnitMovementMain(-1, 0); |
---|
1619 | } |
---|
1620 | else if (direction == 3) |
---|
1621 | { |
---|
1622 | UnitMovementMain(-1, 1); |
---|
1623 | } |
---|
1624 | else if (direction == 4) |
---|
1625 | { |
---|
1626 | UnitMovementMain(0, -1); |
---|
1627 | } |
---|
1628 | else if (direction == 5) |
---|
1629 | { |
---|
1630 | //SelectNextUnitOnTile(-1, 0); |
---|
1631 | } |
---|
1632 | else if (direction == 6) |
---|
1633 | { |
---|
1634 | UnitMovementMain(0, 1); |
---|
1635 | } |
---|
1636 | else if (direction == 7) |
---|
1637 | { |
---|
1638 | UnitMovementMain(1, -1); |
---|
1639 | } |
---|
1640 | else if (direction == 8) |
---|
1641 | { |
---|
1642 | UnitMovementMain(1, 0); |
---|
1643 | } |
---|
1644 | else if (direction == 9) |
---|
1645 | { |
---|
1646 | UnitMovementMain(1, 1); |
---|
1647 | } |
---|
1648 | if (Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints == 0) |
---|
1649 | { |
---|
1650 | DeselectUnit(); |
---|
1651 | } |
---|
1652 | else |
---|
1653 | { |
---|
1654 | UnitTile[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX].Image = LoadImage(OwnershipColorPath + "unitsOnTileSelected"); |
---|
1655 | } |
---|
1656 | } |
---|
1657 | //Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX - 1; |
---|
1658 | //Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY - 1; |
---|
1659 | //OwnershipMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX] = CurrentPlayer; |
---|
1660 | //DrawOwnership(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1661 | //UnitMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX] = CurrentPlayer; |
---|
1662 | //DrawUnit(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1663 | //CheckAndRemoveShroud_FromPos(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1664 | //Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints - 1; |
---|
1665 | //if (GetUnit_FromPositionForSelection(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + 1, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + 1) == -1) |
---|
1666 | //{ |
---|
1667 | // UnitMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + 1, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + 1] = -1; |
---|
1668 | // UnitTile[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + 1, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + 1].Destroy(); |
---|
1669 | // if (CheckforCityinPos(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + 1, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + 1, CurrentPlayer) == -1) |
---|
1670 | // { |
---|
1671 | // OwnershipMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + 1, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + 1] = -1; |
---|
1672 | // TileOwnership[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + 1, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + 1].Destroy(); |
---|
1673 | // } |
---|
1674 | //} |
---|
1675 | } |
---|
1676 | |
---|
1677 | private void UnitMovementMain(int a, int b) |
---|
1678 | { |
---|
1679 | if (TerrainMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + a, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + b] == Vuoristo | DTerrainMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + a, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + b] == Vuoristo) |
---|
1680 | { |
---|
1681 | MessageDisplay.Add("Et voi liikkua vuorten läpi!"); |
---|
1682 | } |
---|
1683 | else |
---|
1684 | { |
---|
1685 | if (Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints == 0 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints < 0) |
---|
1686 | { |
---|
1687 | MessageDisplay.Add("Valitulla yksiköllä ei ollut liikkumapisteitä."); |
---|
1688 | return; |
---|
1689 | } |
---|
1690 | if (OwnershipMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + a, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + b] != -1 && OwnershipMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + a, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + b] != (CurrentPlayer + 10)) |
---|
1691 | { |
---|
1692 | EnterCombat(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + a, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + b, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1693 | return; |
---|
1694 | } |
---|
1695 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + b; |
---|
1696 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + a; |
---|
1697 | // MessageBox.Show(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + " " + Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1698 | //try |
---|
1699 | //{ |
---|
1700 | int posyK; |
---|
1701 | int posxK; |
---|
1702 | posyK = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + (a * -1); |
---|
1703 | posxK = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + (b * -1); |
---|
1704 | OwnershipMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX] = CurrentPlayer; |
---|
1705 | DrawOwnership(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1706 | UnitMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX] = CurrentPlayer; |
---|
1707 | CheckAndRemoveShroud_FromPos(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1708 | Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints - 1; |
---|
1709 | DrawUnit(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX); |
---|
1710 | //MessageBox.Show(Convert.ToString(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].CurrentMovementPoints)); |
---|
1711 | if (GetUnit_FromPositionForSelection(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + (a * -1), Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + (b * -1)) == -1) |
---|
1712 | { |
---|
1713 | UnitMap[posyK, posxK] = -1; |
---|
1714 | UnitTile[posyK, posxK].Image = LoadImage(Textpath + "nothing"); |
---|
1715 | if (CheckforCityinPos(Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + (a * -1), Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + (b * -1), CurrentPlayer) == -1) |
---|
1716 | { |
---|
1717 | OwnershipMap[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + (a * -1), Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + (b * -1)] = -1; |
---|
1718 | TileOwnership[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY + (a * -1), Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX + (b * -1)].Image = LoadImage(Textpath + "nothing"); |
---|
1719 | } |
---|
1720 | } |
---|
1721 | //catch |
---|
1722 | //{ |
---|
1723 | //MessageDisplay.Add("Et voi liikkua kartan ulkopuolelle!"); |
---|
1724 | //Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX - b; |
---|
1725 | //Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY = Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY - a; |
---|
1726 | //} |
---|
1727 | //} |
---|
1728 | } |
---|
1729 | } |
---|
1730 | |
---|
1731 | private void DrawUnit(int i, int j) |
---|
1732 | { |
---|
1733 | UnitTile[i, j].Image = LoadImage(OwnershipColorPath + "unitsOnTileSelected"); |
---|
1734 | UnitTile[i, j].IsVisible = true; |
---|
1735 | //Add(UnitTile[i, j]); |
---|
1736 | } |
---|
1737 | |
---|
1738 | private void DeselectUnit() |
---|
1739 | { |
---|
1740 | UnitTile[Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosY, Rules.pCivs[CurrentPlayer].Units[SelectedUnit].PosX].Image = LoadImage(OwnershipColorPath + "unitsOnTile"); |
---|
1741 | UnitsSelected = false; |
---|
1742 | SelectedUnit = -1; |
---|
1743 | //Keyboard.Disable(Key.NumPad1); |
---|
1744 | //Keyboard.Disable(Key.NumPad2); |
---|
1745 | //Keyboard.Disable(Key.NumPad3); |
---|
1746 | //Keyboard.Disable(Key.NumPad4); |
---|
1747 | //Keyboard.Disable(Key.NumPad5); |
---|
1748 | //Keyboard.Disable(Key.NumPad6); |
---|
1749 | //Keyboard.Disable(Key.NumPad7); |
---|
1750 | //Keyboard.Disable(Key.NumPad8); |
---|
1751 | //Keyboard.Disable(Key.NumPad9); |
---|
1752 | } |
---|
1753 | |
---|
1754 | public int CheckforCityinPos(int i, int j, int civid) |
---|
1755 | { |
---|
1756 | int returnvalue = new int(); |
---|
1757 | if (DTerrainMap[i, j] - 10 == civid) |
---|
1758 | { |
---|
1759 | returnvalue = civid; |
---|
1760 | } |
---|
1761 | else |
---|
1762 | { |
---|
1763 | returnvalue = -1; |
---|
1764 | } |
---|
1765 | return returnvalue; |
---|
1766 | } |
---|
1767 | |
---|
1768 | private void ActivateDebug(int asd) |
---|
1769 | { |
---|
1770 | //Add(MessageDisplay); |
---|
1771 | MessageDisplay.Add("DEBUG MODE ACTIVATED"); |
---|
1772 | Keyboard.Listen(Key.A, Jypeli.ButtonState.Down, ShowColors, null); |
---|
1773 | } |
---|
1774 | |
---|
1775 | private void ShowColors() |
---|
1776 | { |
---|
1777 | for (int a = 0; a <= (AmountofPlayers - 1); a++) |
---|
1778 | { |
---|
1779 | MessageDisplay.Add("Pelaaja: " + a + "; " + Rules.pCivs[a].Color); |
---|
1780 | } |
---|
1781 | } |
---|
1782 | |
---|
1783 | private void MoveCamera(Int32 dir) |
---|
1784 | { |
---|
1785 | if (gamestarted == false) { return; } |
---|
1786 | if ((dir == 0) && (Camera.Position.X < (tile[kartanKorkeus - 1, kartanLeveys - 1].X) - ((Peli.Screen.Width / 2) - 200))) |
---|
1787 | { |
---|
1788 | Camera.Move(CamSpeedEast); |
---|
1789 | } |
---|
1790 | if ((dir == 1) && (Camera.Position.Y < (tile[kartanKorkeus - 1, kartanLeveys - 1].Y) - ((Peli.Screen.Height / 2) - 12))) |
---|
1791 | { |
---|
1792 | Camera.Move(CamSpeedNorth); |
---|
1793 | } |
---|
1794 | if ((dir == 2) && (Camera.Position.X > (tile[0, 0].X) + (Peli.Screen.Width / 2))) |
---|
1795 | { |
---|
1796 | Camera.Move(CamSpeedWest); |
---|
1797 | } |
---|
1798 | if ((dir == 3) && (Camera.Position.Y > (tile[0, 0].Y) + (Peli.Screen.Height / 2))) |
---|
1799 | { |
---|
1800 | Camera.Move(CamSpeedSouth); |
---|
1801 | } |
---|
1802 | } |
---|
1803 | } |
---|
1804 | } |
---|