public bool AssignTroopToNearestAvailableTile(Troop t, PlanetGridSquare tile) { List<PlanetGridSquare> list = new List<PlanetGridSquare>(); foreach (PlanetGridSquare planetGridSquare in this.TilesList) { if (planetGridSquare.TroopsHere.Count < planetGridSquare.number_allowed_troops && (planetGridSquare.building == null || planetGridSquare.building != null && planetGridSquare.building.CombatStrength == 0) && (Math.Abs(tile.x - planetGridSquare.x) <= 1 && Math.Abs(tile.y - planetGridSquare.y) <= 1)) list.Add(planetGridSquare); } if (list.Count > 0) { int index = (int)RandomMath.RandomBetween(0.0f, (float)list.Count); PlanetGridSquare planetGridSquare1 = list[index]; foreach (PlanetGridSquare planetGridSquare2 in this.TilesList) { if (planetGridSquare2 == planetGridSquare1) { planetGridSquare2.TroopsHere.Add(t); this.TroopsHere.Add(t); t.SetPlanet(this); return true; } } } return false; }
private bool TryTroopMove(int changex, int changey, PlanetGridSquare start) { foreach (PlanetGridSquare eventLocation in this.TilesList) { if (eventLocation.x == start.x + changex && eventLocation.y == start.y + changey) { if (eventLocation.building != null && eventLocation.building.CombatStrength > 0 || eventLocation.TroopsHere.Count > 0) return false; if (changex > 0) start.TroopsHere[0].facingRight = true; else if (changex < 0) start.TroopsHere[0].facingRight = false; start.TroopsHere[0].SetFromRect(start.TroopClickRect); start.TroopsHere[0].MovingTimer = 0.75f; --start.TroopsHere[0].AvailableMoveActions; start.TroopsHere[0].MoveTimer = (float)start.TroopsHere[0].MoveTimerBase; eventLocation.TroopsHere.Add(start.TroopsHere[0]); start.TroopsHere.Clear(); if (eventLocation.building == null || string.IsNullOrEmpty(eventLocation.building.EventTriggerUID) || (eventLocation.TroopsHere.Count <= 0 || eventLocation.TroopsHere[0].GetOwner().isFaction)) return true; ResourceManager.EventsDict[eventLocation.building.EventTriggerUID].TriggerPlanetEvent(this, eventLocation.TroopsHere[0].GetOwner(), eventLocation, EmpireManager.GetEmpireByName(Planet.universeScreen.PlayerLoyalty), Planet.universeScreen); } } return false; }
public void AssignBuildingToSpecificTile(Building b, PlanetGridSquare pgs) { if (pgs.building != null) this.BuildingList.Remove(pgs.building); pgs.building = b; this.BuildingList.Add(b); }
public override void Draw(GameTime gameTime) { Rectangle buildingsRect; float x = (float)Mouse.GetState().X; MouseState state = Mouse.GetState(); Vector2 MousePos = new Vector2(x, (float)state.Y); base.ScreenManager.FadeBackBufferToBlack(base.TransitionAlpha * 2 / 3); base.ScreenManager.SpriteBatch.Begin(); this.TitleBar.Draw(); base.ScreenManager.SpriteBatch.DrawString(Fonts.Laserian14, Localizer.Token(383), this.TitlePos, new Color(255, 239, 208)); this.EMenu.Draw(); Color TextColor = new Color(118, 102, 67, 50); this.ColoniesList.Draw(base.ScreenManager.SpriteBatch); EmpireScreenEntry e1 = this.ColoniesList.Entries[this.ColoniesList.indexAtTop].item as EmpireScreenEntry; Rectangle PlanetInfoRect = new Rectangle(this.eRect.X + 22, this.eRect.Y + this.eRect.Height, (int)((float)base.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth * 0.3f), base.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight - this.eRect.Y - this.eRect.Height - 22); int iconSize = PlanetInfoRect.X + PlanetInfoRect.Height - (int)((float)(PlanetInfoRect.X + PlanetInfoRect.Height) * 0.4f); Rectangle PlanetIconRect = new Rectangle(PlanetInfoRect.X + 10, PlanetInfoRect.Y + PlanetInfoRect.Height / 2 - iconSize / 2, iconSize, iconSize); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict[string.Concat("Planets/", this.SelectedPlanet.planetType)], PlanetIconRect, Color.White); Vector2 nameCursor = new Vector2((float)(PlanetIconRect.X + PlanetIconRect.Width / 2) - Fonts.Pirulen16.MeasureString(this.SelectedPlanet.Name).X / 2f, (float)(PlanetInfoRect.Y + 15)); base.ScreenManager.SpriteBatch.DrawString(Fonts.Pirulen16, this.SelectedPlanet.Name, nameCursor, Color.White); Vector2 PNameCursor = new Vector2((float)(PlanetIconRect.X + PlanetIconRect.Width + 5), nameCursor.Y + 20f); string fmt = "0.#"; float amount = 80f; if (GlobalStats.Config.Language == "German" || GlobalStats.Config.Language == "Polish") { amount = amount + 25f; } base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, string.Concat(Localizer.Token(384), ":"), PNameCursor, Color.Orange); Vector2 InfoCursor = new Vector2(PNameCursor.X + amount, PNameCursor.Y); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, this.SelectedPlanet.Type, InfoCursor, new Color(255, 239, 208)); PNameCursor.Y = PNameCursor.Y + (float)(Fonts.Arial12Bold.LineSpacing + 2); InfoCursor = new Vector2(PNameCursor.X + amount, PNameCursor.Y); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, string.Concat(Localizer.Token(385), ":"), PNameCursor, Color.Orange); SpriteBatch spriteBatch = base.ScreenManager.SpriteBatch; SpriteFont arial12Bold = Fonts.Arial12Bold; float population = this.SelectedPlanet.Population / 1000f; string str = population.ToString(fmt); float maxPopulation = (this.SelectedPlanet.MaxPopulation + this.SelectedPlanet.MaxPopBonus) / 1000f; spriteBatch.DrawString(arial12Bold, string.Concat(str, "/", maxPopulation.ToString(fmt)), InfoCursor, new Color(255, 239, 208)); Rectangle hoverRect = new Rectangle((int)PNameCursor.X, (int)PNameCursor.Y, (int)Fonts.Arial12Bold.MeasureString(string.Concat(Localizer.Token(385), ":")).X, Fonts.Arial12Bold.LineSpacing); if (HelperFunctions.CheckIntersection(hoverRect, MousePos)) { ToolTip.CreateTooltip(75, base.ScreenManager); } PNameCursor.Y = PNameCursor.Y + (float)(Fonts.Arial12Bold.LineSpacing + 2); InfoCursor = new Vector2(PNameCursor.X + amount, PNameCursor.Y); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, string.Concat(Localizer.Token(386), ":"), PNameCursor, Color.Orange); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, this.SelectedPlanet.Fertility.ToString(fmt), InfoCursor, new Color(255, 239, 208)); hoverRect = new Rectangle((int)PNameCursor.X, (int)PNameCursor.Y, (int)Fonts.Arial12Bold.MeasureString(string.Concat(Localizer.Token(386), ":")).X, Fonts.Arial12Bold.LineSpacing); if (HelperFunctions.CheckIntersection(hoverRect, MousePos)) { ToolTip.CreateTooltip(20, base.ScreenManager); } PNameCursor.Y = PNameCursor.Y + (float)(Fonts.Arial12Bold.LineSpacing + 2); InfoCursor = new Vector2(PNameCursor.X + amount, PNameCursor.Y); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, string.Concat(Localizer.Token(387), ":"), PNameCursor, Color.Orange); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, this.SelectedPlanet.MineralRichness.ToString(fmt), InfoCursor, new Color(255, 239, 208)); hoverRect = new Rectangle((int)PNameCursor.X, (int)PNameCursor.Y, (int)Fonts.Arial12Bold.MeasureString(string.Concat(Localizer.Token(387), ":")).X, Fonts.Arial12Bold.LineSpacing); if (HelperFunctions.CheckIntersection(hoverRect, MousePos)) { ToolTip.CreateTooltip(21, base.ScreenManager); } PNameCursor.Y = PNameCursor.Y + (float)(Fonts.Arial12Bold.LineSpacing + 2); PNameCursor.Y = PNameCursor.Y + (float)(Fonts.Arial12Bold.LineSpacing + 2); string text = HelperFunctions.parseText(Fonts.Arial12Bold, this.SelectedPlanet.Description, (float)(PlanetInfoRect.Width - PlanetIconRect.Width + 15)); if (Fonts.Arial12Bold.MeasureString(text).Y + PNameCursor.Y <= (float)(base.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight - 20)) { base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, text, PNameCursor, Color.White); } else { base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12, HelperFunctions.parseText(Fonts.Arial12, this.SelectedPlanet.Description, (float)(PlanetInfoRect.Width - PlanetIconRect.Width + 15)), PNameCursor, Color.White); } Rectangle MapRect = new Rectangle(PlanetInfoRect.X + PlanetInfoRect.Width, PlanetInfoRect.Y, e1.QueueRect.X - (PlanetInfoRect.X + PlanetInfoRect.Width), PlanetInfoRect.Height); int desiredWidth = 700; int desiredHeight = 500; for (buildingsRect = new Rectangle(MapRect.X, MapRect.Y, desiredWidth, desiredHeight); !MapRect.Contains(buildingsRect); buildingsRect = new Rectangle(MapRect.X, MapRect.Y, desiredWidth, desiredHeight)) { desiredWidth = desiredWidth - 7; desiredHeight = desiredHeight - 5; } buildingsRect = new Rectangle(MapRect.X + MapRect.Width / 2 - desiredWidth / 2, MapRect.Y, desiredWidth, desiredHeight); MapRect.X = buildingsRect.X; MapRect.Width = buildingsRect.Width; int xsize = buildingsRect.Width / 7; int ysize = buildingsRect.Height / 5; List<PlanetGridSquare> localPgsList = new List<PlanetGridSquare>(); foreach (PlanetGridSquare pgs in this.SelectedPlanet.TilesList) { PlanetGridSquare pgnew = new PlanetGridSquare() { Biosphere = pgs.Biosphere, building = pgs.building, ClickRect = new Rectangle(buildingsRect.X + pgs.x * xsize, buildingsRect.Y + pgs.y * ysize, xsize, ysize), foodbonus = pgs.foodbonus, Habitable = pgs.Habitable, prodbonus = pgs.prodbonus, TroopsHere = pgs.TroopsHere, resbonus = pgs.resbonus }; localPgsList.Add(pgnew); } base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict[string.Concat("PlanetTiles/", this.SelectedPlanet.GetTile())], buildingsRect, Color.White); foreach (PlanetGridSquare pgs in localPgsList) { if (!pgs.Habitable) { Primitives2D.FillRectangle(base.ScreenManager.SpriteBatch, pgs.ClickRect, new Color(0, 0, 0, 200)); } Primitives2D.DrawRectangle(base.ScreenManager.SpriteBatch, pgs.ClickRect, new Color(211, 211, 211, 70), 2f); if (pgs.building != null) { Rectangle bRect = new Rectangle(pgs.ClickRect.X + pgs.ClickRect.Width / 2 - 24, pgs.ClickRect.Y + pgs.ClickRect.Height / 2 - 24, 48, 48); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict[string.Concat("Buildings/icon_", pgs.building.Icon, "_48x48")], bRect, Color.White); } else if (pgs.QItem != null) { Rectangle bRect = new Rectangle(pgs.ClickRect.X + pgs.ClickRect.Width / 2 - 24, pgs.ClickRect.Y + pgs.ClickRect.Height / 2 - 24, 48, 48); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict[string.Concat("Buildings/icon_", pgs.QItem.Building.Icon, "_48x48")], bRect, new Color(255, 255, 255, 128)); } this.DrawPGSIcons(pgs); } int xpos = (base.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth - MapRect.Width) / 2; int ypos = (base.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight - MapRect.Height) / 2; Rectangle rectangle = new Rectangle(xpos, ypos, MapRect.Width, MapRect.Height); Primitives2D.DrawRectangle(base.ScreenManager.SpriteBatch, MapRect, new Color(118, 102, 67, 255)); Rectangle GovernorRect = new Rectangle(MapRect.X + MapRect.Width, MapRect.Y, e1.TotalEntrySize.X + e1.TotalEntrySize.Width - (MapRect.X + MapRect.Width), MapRect.Height); Primitives2D.DrawRectangle(base.ScreenManager.SpriteBatch, GovernorRect, new Color(118, 102, 67, 255)); Rectangle portraitRect = new Rectangle(GovernorRect.X + 25, GovernorRect.Y + 25, 124, 148); if ((float)portraitRect.Width > 0.35f * (float)GovernorRect.Width) { portraitRect.Height = portraitRect.Height - (int)(0.25 * (double)portraitRect.Height); portraitRect.Width = portraitRect.Width - (int)(0.25 * (double)portraitRect.Width); } base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict[string.Concat("Portraits/", EmpireManager.GetEmpireByName(this.eui.screen.PlayerLoyalty).data.PortraitName)], portraitRect, Color.White); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Portraits/portrait_shine"], portraitRect, Color.White); if (this.SelectedPlanet.colonyType == Planet.ColonyType.Colony) { base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/x_red"], portraitRect, Color.White); } Primitives2D.DrawRectangle(base.ScreenManager.SpriteBatch, portraitRect, new Color(118, 102, 67, 255)); Vector2 TextPosition = new Vector2((float)(portraitRect.X + portraitRect.Width + 25), (float)portraitRect.Y); Vector2 GovPos = TextPosition; switch (this.SelectedPlanet.colonyType) { case Planet.ColonyType.Core: { Localizer.Token(372); break; } case Planet.ColonyType.Colony: { Localizer.Token(376); break; } case Planet.ColonyType.Industrial: { Localizer.Token(373); break; } case Planet.ColonyType.Research: { Localizer.Token(375); break; } case Planet.ColonyType.Agricultural: { Localizer.Token(371); break; } case Planet.ColonyType.Military: { Localizer.Token(374); break; } case Planet.ColonyType.TradeHub: { Localizer.Token(393); break; } } base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, "Governor", TextPosition, Color.White); TextPosition.Y = (float)(this.GovernorDropdown.r.Y + 25); string desc = ""; switch (this.SelectedPlanet.colonyType) { case Planet.ColonyType.Core: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(378), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } case Planet.ColonyType.Colony: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(382), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } case Planet.ColonyType.Industrial: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(379), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } case Planet.ColonyType.Research: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(381), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } case Planet.ColonyType.Agricultural: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(377), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } case Planet.ColonyType.Military: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(380), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } case Planet.ColonyType.TradeHub: { desc = HelperFunctions.parseText(Fonts.Arial12Bold, Localizer.Token(394), (float)(GovernorRect.Width - 50 - portraitRect.Width - 25)); break; } } base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12Bold, desc, TextPosition, Color.White); desc = Localizer.Token(388); TextPosition = new Vector2((float)(this.AutoButton.X + this.AutoButton.Width / 2) - Fonts.Pirulen16.MeasureString(desc).X / 2f, (float)(this.AutoButton.Y + this.AutoButton.Height / 2 - Fonts.Pirulen16.LineSpacing / 2)); this.GovernorDropdown.r.X = (int)GovPos.X; this.GovernorDropdown.r.Y = (int)GovPos.Y + Fonts.Arial12Bold.LineSpacing + 5; this.GovernorDropdown.Reset(); this.GovernorDropdown.Draw(base.ScreenManager.SpriteBatch); if (this.ColoniesList.Entries.Count > 0) { EmpireScreenEntry entry = this.ColoniesList.Entries[this.ColoniesList.indexAtTop].item as EmpireScreenEntry; Vector2 TextCursor = new Vector2((float)(entry.SysNameRect.X + 30), (float)(this.eRect.Y - Fonts.Arial20Bold.LineSpacing + 33)); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial20Bold, Localizer.Token(192), TextCursor, new Color(255, 239, 208)); TextCursor = new Vector2((float)(entry.PlanetNameRect.X + 30), (float)(this.eRect.Y - Fonts.Arial20Bold.LineSpacing + 33)); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial20Bold, Localizer.Token(389), TextCursor, new Color(255, 239, 208)); this.pop.rect = new Rectangle(entry.PopRect.X + 15 - ResourceManager.TextureDict["NewUI/icon_food"].Width / 2, (int)TextCursor.Y, ResourceManager.TextureDict["NewUI/icon_food"].Width, ResourceManager.TextureDict["NewUI/icon_food"].Height); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["UI/icon_pop"], this.pop.rect, Color.White); this.food.rect = new Rectangle(entry.FoodRect.X + 15 - ResourceManager.TextureDict["NewUI/icon_food"].Width / 2, (int)TextCursor.Y, ResourceManager.TextureDict["NewUI/icon_food"].Width, ResourceManager.TextureDict["NewUI/icon_food"].Height); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_food"], this.food.rect, Color.White); this.prod.rect = new Rectangle(entry.ProdRect.X + 15 - ResourceManager.TextureDict["NewUI/icon_production"].Width / 2, (int)TextCursor.Y, ResourceManager.TextureDict["NewUI/icon_production"].Width, ResourceManager.TextureDict["NewUI/icon_production"].Height); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_production"], this.prod.rect, Color.White); this.res.rect = new Rectangle(entry.ResRect.X + 15 - ResourceManager.TextureDict["NewUI/icon_science"].Width / 2, (int)TextCursor.Y, ResourceManager.TextureDict["NewUI/icon_science"].Width, ResourceManager.TextureDict["NewUI/icon_science"].Height); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_science"], this.res.rect, Color.White); this.money.rect = new Rectangle(entry.MoneyRect.X + 15 - ResourceManager.TextureDict["NewUI/icon_money"].Width / 2, (int)TextCursor.Y, ResourceManager.TextureDict["NewUI/icon_money"].Width, ResourceManager.TextureDict["NewUI/icon_money"].Height); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_money"], this.money.rect, Color.White); TextCursor = new Vector2((float)(entry.SliderRect.X + 30), (float)(this.eRect.Y - Fonts.Arial20Bold.LineSpacing + 33)); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial20Bold, Localizer.Token(390), TextCursor, new Color(255, 239, 208)); TextCursor = new Vector2((float)(entry.StorageRect.X + 30), (float)(this.eRect.Y - Fonts.Arial20Bold.LineSpacing + 33)); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial20Bold, Localizer.Token(391), TextCursor, new Color(255, 239, 208)); TextCursor = new Vector2((float)(entry.QueueRect.X + 30), (float)(this.eRect.Y - Fonts.Arial20Bold.LineSpacing + 33)); base.ScreenManager.SpriteBatch.DrawString(Fonts.Arial20Bold, Localizer.Token(392), TextCursor, new Color(255, 239, 208)); } Color smallHighlight = TextColor; smallHighlight.A = (byte)(TextColor.A / 2); for (int i = this.ColoniesList.indexAtTop; i < this.ColoniesList.Entries.Count && i < this.ColoniesList.indexAtTop + this.ColoniesList.entriesToDisplay; i++) { EmpireScreenEntry entry = this.ColoniesList.Entries[i].item as EmpireScreenEntry; if (i % 2 == 0) { Primitives2D.FillRectangle(base.ScreenManager.SpriteBatch, entry.TotalEntrySize, smallHighlight); } if (entry.p == this.SelectedPlanet) { Primitives2D.FillRectangle(base.ScreenManager.SpriteBatch, entry.TotalEntrySize, TextColor); } entry.SetNewPos(this.eRect.X + 22, this.ColoniesList.Entries[i].clickRect.Y); entry.Draw(base.ScreenManager); Primitives2D.DrawRectangle(base.ScreenManager.SpriteBatch, entry.TotalEntrySize, TextColor); } Color lineColor = new Color(118, 102, 67, 255); Vector2 topLeftSL = new Vector2((float)e1.SysNameRect.X, (float)(this.eRect.Y + 35)); Vector2 botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)e1.PlanetNameRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)e1.PopRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)e1.FoodRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, new Color(lineColor, 100)); topLeftSL = new Vector2((float)e1.ProdRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, new Color(lineColor, 100)); topLeftSL = new Vector2((float)e1.ResRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, new Color(lineColor, 100)); topLeftSL = new Vector2((float)e1.MoneyRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, new Color(lineColor, 100)); topLeftSL = new Vector2((float)e1.SliderRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)(e1.StorageRect.X + 5), (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)e1.QueueRect.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)e1.TotalEntrySize.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); topLeftSL = new Vector2((float)(e1.TotalEntrySize.X + e1.TotalEntrySize.Width), (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, topLeftSL, botSL, lineColor); Vector2 leftBot = new Vector2((float)e1.TotalEntrySize.X, (float)PlanetInfoRect.Y); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, leftBot, botSL, lineColor); leftBot = new Vector2((float)e1.TotalEntrySize.X, (float)(this.eRect.Y + 35)); botSL = new Vector2(topLeftSL.X, (float)(this.eRect.Y + 35)); Primitives2D.DrawLine(base.ScreenManager.SpriteBatch, leftBot, botSL, lineColor); Vector2 pos = new Vector2((float)base.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth - Fonts.Pirulen16.MeasureString("Paused").X - 13f, 44f); base.ScreenManager.SpriteBatch.DrawString(Fonts.Pirulen16, "Paused", pos, Color.White); this.close.Draw(base.ScreenManager); ToolTip.Draw(base.ScreenManager); base.ScreenManager.SpriteBatch.End(); }
private void DrawPGSIcons(PlanetGridSquare pgs) { if (pgs.Biosphere) { Rectangle biosphere = new Rectangle(pgs.ClickRect.X, pgs.ClickRect.Y, 20, 20); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Buildings/icon_biosphere_48x48"], biosphere, Color.White); } if (pgs.TroopsHere.Count > 0) { pgs.TroopClickRect = new Rectangle(pgs.ClickRect.X + pgs.ClickRect.Width - 36, pgs.ClickRect.Y, 35, 35); base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict[string.Concat("Troops/", pgs.TroopsHere[0].TexturePath)], pgs.TroopClickRect, Color.White); } float numFood = 0f; float numProd = 0f; float numRes = 0f; if (pgs.building != null) { if (pgs.building.PlusFlatFoodAmount > 0f || pgs.building.PlusFoodPerColonist > 0f) { numFood = numFood + pgs.building.PlusFoodPerColonist * this.SelectedPlanet.Population / 1000f * this.SelectedPlanet.FarmerPercentage; numFood = numFood + pgs.building.PlusFlatFoodAmount; } if (pgs.building.PlusFlatProductionAmount > 0f || pgs.building.PlusProdPerColonist > 0f) { numProd = numProd + pgs.building.PlusFlatProductionAmount; numProd = numProd + pgs.building.PlusProdPerColonist * this.SelectedPlanet.Population / 1000f * this.SelectedPlanet.WorkerPercentage; } if (pgs.building.PlusResearchPerColonist > 0f || pgs.building.PlusFlatResearchAmount > 0f) { numRes = numRes + pgs.building.PlusResearchPerColonist * this.SelectedPlanet.Population / 1000f * this.SelectedPlanet.ResearcherPercentage; numRes = numRes + pgs.building.PlusFlatResearchAmount; } } float total = numFood + numProd + numRes; float totalSpace = (float)(pgs.ClickRect.Width - 30); float spacing = totalSpace / total; Rectangle rect = new Rectangle(pgs.ClickRect.X, pgs.ClickRect.Y + pgs.ClickRect.Height - ResourceManager.TextureDict["NewUI/icon_food"].Height, ResourceManager.TextureDict["NewUI/icon_food"].Width, ResourceManager.TextureDict["NewUI/icon_food"].Height); for (int i = 0; (float)i < numFood; i++) { if (numFood - (float)i <= 0f || numFood - (float)i >= 1f) { base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_food"], rect, Color.White); } else { Rectangle? nullable = null; base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_food"], new Vector2((float)rect.X, (float)rect.Y), nullable, Color.White, 0f, Vector2.Zero, numFood - (float)i, SpriteEffects.None, 1f); } rect.X = rect.X + (int)spacing; } for (int i = 0; (float)i < numProd; i++) { if (numProd - (float)i <= 0f || numProd - (float)i >= 1f) { base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_production"], rect, Color.White); } else { Rectangle? nullable1 = null; base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_production"], new Vector2((float)rect.X, (float)rect.Y), nullable1, Color.White, 0f, Vector2.Zero, numProd - (float)i, SpriteEffects.None, 1f); } rect.X = rect.X + (int)spacing; } for (int i = 0; (float)i < numRes; i++) { if (numRes - (float)i <= 0f || numRes - (float)i >= 1f) { base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_science"], rect, Color.White); } else { Rectangle? nullable2 = null; base.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["NewUI/icon_science"], new Vector2((float)rect.X, (float)rect.Y), nullable2, Color.White, 0f, Vector2.Zero, numRes - (float)i, SpriteEffects.None, 1f); } rect.X = rect.X + (int)spacing; } }
public void StartCombat(PlanetGridSquare Attacker, PlanetGridSquare Defender) { Combat c = new Combat() { Attacker = Attacker }; if (Attacker.TroopsHere.Count <= 0) { AudioManager.PlayCue("sd_weapon_bigcannon_01"); AudioManager.PlayCue("uzi_loop"); } else { Attacker.TroopsHere[0].DoAttack(); AudioManager.PlayCue(Attacker.TroopsHere[0].sound_attack); } c.Defender = Defender; this.p.ActiveCombats.Add(c); }
public void TriggerPlanetEvent(Planet p, Empire Triggerer, PlanetGridSquare eventLocation, Empire PlayerEmpire, UniverseScreen screen) { int ranMax = 0; int ranMin = 0; foreach (Outcome outcome in this.PotentialOutcomes) { if (outcome.onlyTriggerOnce && outcome.alreadyTriggered && Triggerer.isPlayer) { continue; } else { ranMax += outcome.Chance; } } int Random = (int)RandomMath.RandomBetween(ranMin, ranMax); Outcome triggeredOutcome = new Outcome(); int cursor = 0; foreach (Outcome outcome in this.PotentialOutcomes) { if (outcome.onlyTriggerOnce && outcome.alreadyTriggered && Triggerer.isPlayer) { continue; } else { cursor = cursor + outcome.Chance; if (Random > cursor) { continue; } triggeredOutcome = outcome; if (Triggerer.isPlayer) { outcome.alreadyTriggered = true; } break; } } if (triggeredOutcome != null) { if (triggeredOutcome.GrantArtifact) { List<Ship_Game.Artifact> Potentials = new List<Ship_Game.Artifact>(); foreach (KeyValuePair<string, Ship_Game.Artifact> Artifact in ResourceManager.ArtifactsDict) { if (Artifact.Value.Discovered) { continue; } Potentials.Add(Artifact.Value); } if (Potentials.Count <= 0) { triggeredOutcome.MoneyGranted = 500; } else { int ranart = (int)RandomMath.RandomBetween(0f, (float)Potentials.Count + 0.8f); if (ranart > Potentials.Count - 1) { ranart = Potentials.Count - 1; } Triggerer.data.OwnedArtifacts.Add(Potentials[ranart]); ResourceManager.ArtifactsDict[Potentials[ranart].Name].Discovered = true; triggeredOutcome.SetArtifact(Potentials[ranart]); if (triggeredOutcome.GetArtifact().DiplomacyMod > 0f) { RacialTrait traits = Triggerer.data.Traits; traits.DiplomacyMod = traits.DiplomacyMod + (triggeredOutcome.GetArtifact().DiplomacyMod + triggeredOutcome.GetArtifact().DiplomacyMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().FertilityMod > 0f) { EmpireData triggerer = Triggerer.data; triggerer.EmpireFertilityBonus = triggerer.EmpireFertilityBonus + triggeredOutcome.GetArtifact().FertilityMod; foreach (Planet planet in Triggerer.GetPlanets()) { Planet fertility = planet; fertility.Fertility = fertility.Fertility + (triggeredOutcome.GetArtifact().FertilityMod + triggeredOutcome.GetArtifact().FertilityMod * Triggerer.data.Traits.Spiritual); } } if (triggeredOutcome.GetArtifact().GroundCombatMod > 0f) { RacialTrait groundCombatModifier = Triggerer.data.Traits; groundCombatModifier.GroundCombatModifier = groundCombatModifier.GroundCombatModifier + (triggeredOutcome.GetArtifact().GroundCombatMod + triggeredOutcome.GetArtifact().GroundCombatMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().ModuleHPMod > 0f) { RacialTrait modHpModifier = Triggerer.data.Traits; modHpModifier.ModHpModifier = modHpModifier.ModHpModifier + (triggeredOutcome.GetArtifact().ModuleHPMod + triggeredOutcome.GetArtifact().ModuleHPMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().PlusFlatMoney > 0f) { EmpireData flatMoneyBonus = Triggerer.data; flatMoneyBonus.FlatMoneyBonus = flatMoneyBonus.FlatMoneyBonus + (triggeredOutcome.GetArtifact().PlusFlatMoney + triggeredOutcome.GetArtifact().PlusFlatMoney * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().ProductionMod > 0f) { RacialTrait productionMod = Triggerer.data.Traits; productionMod.ProductionMod = productionMod.ProductionMod + (triggeredOutcome.GetArtifact().ProductionMod + triggeredOutcome.GetArtifact().ProductionMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().ReproductionMod > 0f) { RacialTrait reproductionMod = Triggerer.data.Traits; reproductionMod.ReproductionMod = reproductionMod.ReproductionMod + (triggeredOutcome.GetArtifact().ReproductionMod + triggeredOutcome.GetArtifact().ReproductionMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().ResearchMod > 0f) { RacialTrait researchMod = Triggerer.data.Traits; researchMod.ResearchMod = researchMod.ResearchMod + (triggeredOutcome.GetArtifact().ResearchMod + triggeredOutcome.GetArtifact().ResearchMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().SensorMod > 0f) { EmpireData sensorModifier = Triggerer.data; sensorModifier.SensorModifier = sensorModifier.SensorModifier + (triggeredOutcome.GetArtifact().SensorMod + triggeredOutcome.GetArtifact().SensorMod * Triggerer.data.Traits.Spiritual); } if (triggeredOutcome.GetArtifact().ShieldPenBonus > 0f) { EmpireData shieldPenBonusChance = Triggerer.data; shieldPenBonusChance.ShieldPenBonusChance = shieldPenBonusChance.ShieldPenBonusChance + (triggeredOutcome.GetArtifact().ShieldPenBonus + triggeredOutcome.GetArtifact().ShieldPenBonus * Triggerer.data.Traits.Spiritual); } } } if (triggeredOutcome.BeginArmageddon) { GlobalStats.RemnantArmageddon = true; } foreach (string ship in triggeredOutcome.FriendlyShipsToSpawn) { Triggerer.ForcePoolAdd(ResourceManager.CreateShipAt(ship, Triggerer, p, true)); } foreach (string ship in triggeredOutcome.RemnantShipsToSpawn) { Ship tomake = ResourceManager.CreateShipAt(ship, EmpireManager.GetEmpireByName("The Remnant"), p, true); tomake.GetAI().DefaultAIState = AIState.Exterminate; } if (triggeredOutcome.UnlockTech != null) { if (!Triggerer.GetTDict()[triggeredOutcome.UnlockTech].Unlocked) { Triggerer.UnlockTech(triggeredOutcome.UnlockTech); } else { triggeredOutcome.WeHadIt = true; } } if (triggeredOutcome.RemoveTrigger) { p.BuildingList.Remove(eventLocation.building); eventLocation.building = null; } if (!string.IsNullOrEmpty(triggeredOutcome.ReplaceWith)) { eventLocation.building = ResourceManager.GetBuilding(triggeredOutcome.ReplaceWith); p.BuildingList.Add(eventLocation.building); } Empire money = Triggerer; money.Money = money.Money + (float)triggeredOutcome.MoneyGranted; RacialTrait racialTrait = Triggerer.data.Traits; racialTrait.ResearchMod = racialTrait.ResearchMod + triggeredOutcome.ScienceBonus; RacialTrait traits1 = Triggerer.data.Traits; traits1.ProductionMod = traits1.ProductionMod + triggeredOutcome.IndustryBonus; if (triggeredOutcome.TroopsGranted != null) { foreach (string troopname in triggeredOutcome.TroopsGranted) { Troop t = ResourceManager.CreateTroop(ResourceManager.TroopsDict[troopname], Triggerer); t.SetOwner(Triggerer); if (p.AssignTroopToNearestAvailableTile(t, eventLocation)) { continue; } p.AssignTroopToTile(t); } } if (triggeredOutcome.TroopsToSpawn != null) { foreach (string troopname in triggeredOutcome.TroopsToSpawn) { Troop t = ResourceManager.CreateTroop(ResourceManager.TroopsDict[troopname], EmpireManager.GetEmpireByName("Unknown")); t.SetOwner(EmpireManager.GetEmpireByName("Unknown")); if (p.AssignTroopToNearestAvailableTile(t, eventLocation)) { continue; } p.AssignTroopToTile(t); } } } if (Triggerer == PlayerEmpire) { screen.ScreenManager.AddScreen(new EventPopup(screen, PlayerEmpire, this, triggeredOutcome)); AudioManager.PlayCue("sd_notify_alert"); } }
public static bool TroopCanAttackSquare(PlanetGridSquare ActiveTroop, PlanetGridSquare squareToAttack, Planet p) { if (ActiveTroop != null) { if (ActiveTroop.TroopsHere.Count != 0) { foreach (PlanetGridSquare planetGridSquare1 in p.TilesList) { if (ActiveTroop == planetGridSquare1) { foreach (PlanetGridSquare planetGridSquare2 in p.TilesList) { if (planetGridSquare2 != ActiveTroop && planetGridSquare2 == squareToAttack) { //Added by McShooterz: Prevent troops from firing on own buildings if (planetGridSquare2.TroopsHere.Count == 0 && (planetGridSquare2.building == null || (planetGridSquare2.building != null && planetGridSquare2.building.CombatStrength == 0) || p.Owner == ActiveTroop.TroopsHere[0].GetOwner())) return false; int num1 = Math.Abs(planetGridSquare1.x - planetGridSquare2.x); int num2 = Math.Abs(planetGridSquare1.y - planetGridSquare2.y); if (planetGridSquare2.TroopsHere.Count > 0) { if (planetGridSquare1.TroopsHere.Count != 0 && num1 <= planetGridSquare1.TroopsHere[0].Range && (num2 <= planetGridSquare1.TroopsHere[0].Range && planetGridSquare2.TroopsHere[0].GetOwner() != ActiveTroop.TroopsHere[0].GetOwner())) return true; } else if (planetGridSquare2.building != null && planetGridSquare2.building.CombatStrength > 0 && (num1 <= planetGridSquare1.TroopsHere[0].Range && num2 <= planetGridSquare1.TroopsHere[0].Range)) { if (p.Owner == null) return false; if (p.Owner != ActiveTroop.TroopsHere[0].GetOwner()) return true; } } } } } } else if (ActiveTroop.building != null && ActiveTroop.building.CombatStrength > 0) { foreach (PlanetGridSquare planetGridSquare1 in p.TilesList) { if (ActiveTroop == planetGridSquare1) { foreach (PlanetGridSquare planetGridSquare2 in p.TilesList) { if (planetGridSquare2 != ActiveTroop && planetGridSquare2 == squareToAttack) { //Added by McShooterz: Prevent buildings from firing on buildings if (planetGridSquare2.TroopsHere.Count == 0) return false; int num1 = Math.Abs(planetGridSquare1.x - planetGridSquare2.x); int num2 = Math.Abs(planetGridSquare1.y - planetGridSquare2.y); if (planetGridSquare2.TroopsHere.Count > 0) { if (num1 <= 1 && num2 <= 1 && planetGridSquare2.TroopsHere[0].GetOwner() != p.Owner) return true; } else if (planetGridSquare2.building != null && planetGridSquare2.building.CombatStrength > 0 && (num1 <= 1 && num2 <= 1)) return p.Owner != null; } } } } } } return false; }
public override void HandleInput(InputState input) { this.currentMouse = Mouse.GetState(); Vector2 MousePos = new Vector2((float)this.currentMouse.X, (float)this.currentMouse.Y); bool SelectedSomethingThisFrame = false; this.assetsUI.HandleInput(input); if (this.ActiveTroop != null && this.tInfo.HandleInput(input)) { SelectedSomethingThisFrame = true; } this.selector = null; this.HoveredSquare = null; foreach (PlanetGridSquare pgs in this.p.TilesList) { if (!HelperFunctions.CheckIntersection(pgs.ClickRect, MousePos) || pgs.TroopsHere.Count == 0 && pgs.building == null) { continue; } this.HoveredSquare = pgs; } if (this.OrbitSL.Entries.Count > 0) { if (!HelperFunctions.CheckIntersection(this.LandAll.Rect, input.CursorPosition)) { this.LandAll.State = UIButton.PressState.Normal; } else { this.LandAll.State = UIButton.PressState.Hover; if (input.InGameSelect) { AudioManager.PlayCue("sd_troop_land"); for (int i = 0; i < this.OrbitSL.Entries.Count; i++) { ScrollList.Entry e = this.OrbitSL.Entries[i]; if (e.item is Ship) { (e.item as Ship).GetAI().OrderLandAllTroops(this.p); } else if (e.item is Troop) { (e.item as Troop).GetShip().TroopList.Remove(e.item as Troop); this.p.AssignTroopToTile(e.item as Troop); } } this.OrbitSL.Entries.Clear(); } } } if (p.TroopsHere.Where(mytroops => mytroops.GetOwner() == universeScreen.player).Count() > 0) { if (!HelperFunctions.CheckIntersection(this.LaunchAll.Rect, input.CursorPosition)) { this.LaunchAll.State = UIButton.PressState.Normal; } else { this.LaunchAll.State = UIButton.PressState.Hover; if (input.InGameSelect) { bool play = false; foreach (PlanetGridSquare pgs in this.p.TilesList) { if ( pgs.TroopsHere.Count <= 0 || pgs.TroopsHere[0].GetOwner() !=universeScreen.player || pgs.TroopsHere[0].Launchtimer >= 0) { continue; } try { pgs.TroopsHere[0].AvailableAttackActions = 0; pgs.TroopsHere[0].AvailableMoveActions = 0; pgs.TroopsHere[0].Launchtimer = pgs.TroopsHere[0].MoveTimerBase; pgs.TroopsHere[0].AttackTimer = (float)pgs.TroopsHere[0].AttackTimerBase; pgs.TroopsHere[0].MoveTimer = (float)pgs.TroopsHere[0].MoveTimerBase; play = true; ResourceManager.CreateTroopShipAtPoint((pgs.TroopsHere[0].GetOwner().data.DefaultTroopShip != null) ? pgs.TroopsHere[0].GetOwner().data.DefaultTroopShip : pgs.TroopsHere[0].GetOwner().data.DefaultSmallTransport, pgs.TroopsHere[0].GetOwner(), this.p.Position, pgs.TroopsHere[0]); this.p.TroopsHere.Remove(pgs.TroopsHere[0]); pgs.TroopsHere[0].SetPlanet(null); pgs.TroopsHere.Clear(); } catch { System.Diagnostics.Debug.WriteLine("Troop Launch Crash"); } } if (play) { AudioManager.PlayCue("sd_troop_takeoff"); this.ResetNextFrame = true; } } } } this.OrbitSL.HandleInput(input); foreach (ScrollList.Entry e in this.OrbitSL.Copied) { if (!HelperFunctions.CheckIntersection(e.clickRect, MousePos)) { e.clickRectHover = 0; } else { this.selector = new Selector(this.ScreenManager, e.clickRect); if (this.currentMouse.LeftButton != ButtonState.Pressed || this.previousMouse.LeftButton != ButtonState.Released) { continue; } this.draggedTroop = e; } } if (this.draggedTroop != null && this.currentMouse.LeftButton == ButtonState.Released && this.previousMouse.LeftButton == ButtonState.Pressed) { bool foundPlace = false; foreach (PlanetGridSquare pgs in this.p.TilesList) { if (!HelperFunctions.CheckIntersection(pgs.ClickRect, MousePos)) { continue; } if (!(this.draggedTroop.item is Ship) || (this.draggedTroop.item as Ship).TroopList.Count <= 0) { if (!(this.draggedTroop.item is Troop) || (pgs.building != null || pgs.TroopsHere.Count != 0) && (pgs.building == null || pgs.building.CombatStrength != 0 || pgs.TroopsHere.Count != 0)) { continue; } try { AudioManager.PlayCue("sd_troop_land"); pgs.TroopsHere.Add(this.draggedTroop.item as Troop); pgs.TroopsHere[0].AvailableAttackActions = 0; pgs.TroopsHere[0].AvailableMoveActions = 0; pgs.TroopsHere[0].Launchtimer = pgs.TroopsHere[0].MoveTimerBase; pgs.TroopsHere[0].AttackTimer = (float)pgs.TroopsHere[0].AttackTimerBase; pgs.TroopsHere[0].MoveTimer = (float)pgs.TroopsHere[0].MoveTimerBase; this.p.TroopsHere.Add(this.draggedTroop.item as Troop); (this.draggedTroop.item as Troop).SetPlanet(this.p); this.OrbitSL.Entries.Remove(this.draggedTroop); (this.draggedTroop.item as Troop).GetShip().TroopList.Remove(this.draggedTroop.item as Troop); foundPlace = true; this.draggedTroop = null; } catch { System.Diagnostics.Debug.WriteLine("Troop Launch Crash"); } } else { if ((pgs.building != null || pgs.TroopsHere.Count != 0) && (pgs.building == null || pgs.building.CombatStrength != 0 || pgs.TroopsHere.Count != 0)) { continue; } try { AudioManager.PlayCue("sd_troop_land"); pgs.TroopsHere.Add((this.draggedTroop.item as Ship).TroopList[0]); pgs.TroopsHere[0].AvailableAttackActions = 0; pgs.TroopsHere[0].AvailableMoveActions = 0; pgs.TroopsHere[0].Launchtimer = pgs.TroopsHere[0].MoveTimerBase; pgs.TroopsHere[0].AttackTimer = (float)pgs.TroopsHere[0].AttackTimerBase; pgs.TroopsHere[0].MoveTimer = (float)pgs.TroopsHere[0].MoveTimerBase; this.p.TroopsHere.Add((this.draggedTroop.item as Ship).TroopList[0]); (this.draggedTroop.item as Ship).TroopList[0].SetPlanet(this.p); if (pgs.building != null && !string.IsNullOrEmpty(pgs.building.EventTriggerUID) && pgs.TroopsHere.Count > 0 && !pgs.TroopsHere[0].GetOwner().isFaction && !pgs.TroopsHere[0].GetOwner().MinorRace) { ResourceManager.EventsDict[pgs.building.EventTriggerUID].TriggerPlanetEvent(this.p, pgs.TroopsHere[0].GetOwner(), pgs, EmpireManager.GetEmpireByName(CombatScreen.universeScreen.PlayerLoyalty), CombatScreen.universeScreen); } this.OrbitSL.Entries.Remove(this.draggedTroop); this.OrbitSL.Copied.Remove(this.draggedTroop); (this.draggedTroop.item as Ship).QueueTotalRemoval(); foundPlace = true; this.draggedTroop = null; } catch { System.Diagnostics.Debug.WriteLine("Troop Launch Crash"); } } } if (!foundPlace) { this.draggedTroop = null; AudioManager.PlayCue("UI_Misc20"); } } foreach (PlanetGridSquare pgs in this.p.TilesList) { if (!HelperFunctions.CheckIntersection(pgs.ClickRect, MousePos)) { pgs.highlighted = false; } else { if (!pgs.highlighted) { AudioManager.PlayCue("sd_ui_mouseover"); } pgs.highlighted = true; } if (pgs.CanAttack) { if (!pgs.CanAttack || this.ActiveTroop == null) { continue; } if (!HelperFunctions.CheckIntersection(pgs.TroopClickRect, MousePos)) { pgs.ShowAttackHover = false; } else if (this.ActiveTroop.TroopsHere.Count <= 0) { if (this.ActiveTroop.building == null || this.ActiveTroop.building.CombatStrength <= 0 || this.ActiveTroop.building.AvailableAttackActions <= 0 || this.p.Owner == null || this.p.Owner != EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty)) { continue; } if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released) { Building activeTroop = this.ActiveTroop.building; activeTroop.AvailableAttackActions = activeTroop.AvailableAttackActions - 1; this.ActiveTroop.building.AttackTimer = 10f; this.StartCombat(this.ActiveTroop, pgs); } pgs.ShowAttackHover = true; } else { if (this.ActiveTroop.TroopsHere[0].AvailableAttackActions <= 0 || this.ActiveTroop.TroopsHere[0].GetOwner() != EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty)) { continue; } if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released) { if (pgs.x > this.ActiveTroop.x) { this.ActiveTroop.TroopsHere[0].facingRight = true; } else if (pgs.x < this.ActiveTroop.x) { this.ActiveTroop.TroopsHere[0].facingRight = false; } Troop item = this.ActiveTroop.TroopsHere[0]; item.AvailableAttackActions = item.AvailableAttackActions - 1; this.ActiveTroop.TroopsHere[0].AttackTimer = (float)this.ActiveTroop.TroopsHere[0].AttackTimerBase; Troop availableMoveActions = this.ActiveTroop.TroopsHere[0]; availableMoveActions.AvailableMoveActions = availableMoveActions.AvailableMoveActions - 1; this.ActiveTroop.TroopsHere[0].MoveTimer = (float)this.ActiveTroop.TroopsHere[0].MoveTimerBase; this.StartCombat(this.ActiveTroop, pgs); } pgs.ShowAttackHover = true; } } else { if (pgs.TroopsHere.Count > 0) { if (HelperFunctions.CheckIntersection(pgs.TroopClickRect, MousePos) && this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released) { if (pgs.TroopsHere[0].GetOwner() != EmpireManager.GetEmpireByName(CombatScreen.universeScreen.PlayerLoyalty)) { this.ActiveTroop = pgs; this.tInfo.SetPGS(pgs); SelectedSomethingThisFrame = true; } else { foreach (PlanetGridSquare p1 in this.p.TilesList) { p1.CanAttack = false; p1.CanMoveTo = false; p1.ShowAttackHover = false; } this.ActiveTroop = pgs; this.tInfo.SetPGS(pgs); SelectedSomethingThisFrame = true; } } } else if (pgs.building != null && !pgs.CanMoveTo && HelperFunctions.CheckIntersection(pgs.TroopClickRect, MousePos) && this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released) { if (this.p.Owner != EmpireManager.GetEmpireByName(CombatScreen.universeScreen.PlayerLoyalty)) { this.ActiveTroop = pgs; this.tInfo.SetPGS(pgs); SelectedSomethingThisFrame = true; } else { foreach (PlanetGridSquare p1 in this.p.TilesList) { p1.CanAttack = false; p1.CanMoveTo = false; p1.ShowAttackHover = false; } this.ActiveTroop = pgs; this.tInfo.SetPGS(pgs); SelectedSomethingThisFrame = true; } } if (this.ActiveTroop == null || !pgs.CanMoveTo || this.ActiveTroop.TroopsHere.Count == 0 || !HelperFunctions.CheckIntersection(pgs.ClickRect, MousePos) || this.ActiveTroop.TroopsHere[0].GetOwner() != EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty) || this.currentMouse.LeftButton != ButtonState.Pressed || this.previousMouse.LeftButton != ButtonState.Released || this.ActiveTroop.TroopsHere[0].AvailableMoveActions <= 0) { continue; } if (pgs.x > this.ActiveTroop.x) { this.ActiveTroop.TroopsHere[0].facingRight = true; } else if (pgs.x < this.ActiveTroop.x) { this.ActiveTroop.TroopsHere[0].facingRight = false; } pgs.TroopsHere.Add(this.ActiveTroop.TroopsHere[0]); Troop troop = pgs.TroopsHere[0]; troop.AvailableMoveActions = troop.AvailableMoveActions - 1; pgs.TroopsHere[0].MoveTimer = (float)pgs.TroopsHere[0].MoveTimerBase; pgs.TroopsHere[0].MovingTimer = 0.75f; pgs.TroopsHere[0].SetFromRect(this.ActiveTroop.TroopClickRect); AudioManager.PlayCue(pgs.TroopsHere[0].MovementCue); this.ActiveTroop.TroopsHere.Clear(); this.ActiveTroop = null; this.ActiveTroop = pgs; pgs.CanMoveTo = false; SelectedSomethingThisFrame = true; } } if (this.ActiveTroop != null && !SelectedSomethingThisFrame && this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released && !HelperFunctions.CheckIntersection(this.SelectedItemRect, input.CursorPosition)) { this.ActiveTroop = null; } if (this.ActiveTroop != null) { this.tInfo.pgs = this.ActiveTroop; } this.DetermineAttackAndMove(); this.hInfo.SetPGS(this.HoveredSquare); this.previousMouse = this.currentMouse; if (input.CurrentMouseState.RightButton != ButtonState.Released || input.LastMouseState.RightButton != ButtonState.Released) { universeScreen.ShipsInCombat.Active = true; universeScreen.PlanetsInCombat.Active = true; } }
public static void StartCombat(PlanetGridSquare Attacker, PlanetGridSquare Defender, Planet p) { Combat c = new Combat() { Attacker = Attacker }; if (Attacker.TroopsHere.Count > 0) { Attacker.TroopsHere[0].DoAttack(); } c.Defender = Defender; p.ActiveCombats.Add(c); }
private void DrawPGSIcons(PlanetGridSquare pgs) { float width = (float)(pgs.y * 15 + 64); if (width > 128f) { width = 128f; } if (pgs.building != null && pgs.building.CombatStrength > 0) { width = 64f; } pgs.TroopClickRect = new Rectangle(pgs.ClickRect.X + pgs.ClickRect.Width / 2 - (int)width / 2, pgs.ClickRect.Y + pgs.ClickRect.Height / 2 - (int)width / 2, (int)width, (int)width); if (pgs.TroopsHere.Count > 0) { Rectangle TroopClickRect = pgs.TroopClickRect; if (pgs.TroopsHere[0].MovingTimer > 0f) { float amount = 1f - pgs.TroopsHere[0].MovingTimer; TroopClickRect.X = (int)MathHelper.Lerp((float)pgs.TroopsHere[0].GetFromRect().X, (float)pgs.TroopClickRect.X, amount); TroopClickRect.Y = (int)MathHelper.Lerp((float)pgs.TroopsHere[0].GetFromRect().Y, (float)pgs.TroopClickRect.Y, amount); TroopClickRect.Width = (int)MathHelper.Lerp((float)pgs.TroopsHere[0].GetFromRect().Width, (float)pgs.TroopClickRect.Width, amount); TroopClickRect.Height = (int)MathHelper.Lerp((float)pgs.TroopsHere[0].GetFromRect().Height, (float)pgs.TroopClickRect.Height, amount); } pgs.TroopsHere[0].Draw(this.ScreenManager.SpriteBatch, TroopClickRect); Rectangle MoveRect = new Rectangle(TroopClickRect.X + TroopClickRect.Width + 2, TroopClickRect.Y + 38, 12, 12); if (pgs.TroopsHere[0].AvailableMoveActions <= 0) { int moveTimer = (int)pgs.TroopsHere[0].MoveTimer + 1; HelperFunctions.DrawDropShadowText1(this.ScreenManager, moveTimer.ToString(), new Vector2((float)(MoveRect.X + 4), (float)MoveRect.Y), Fonts.Arial12, Color.White); } else { this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/Ground_Move"], MoveRect, Color.White); } Rectangle AttackRect = new Rectangle(TroopClickRect.X + TroopClickRect.Width + 2, TroopClickRect.Y + 23, 12, 12); if (pgs.TroopsHere[0].AvailableAttackActions <= 0) { int attackTimer = (int)pgs.TroopsHere[0].AttackTimer + 1; HelperFunctions.DrawDropShadowText1(this.ScreenManager, attackTimer.ToString(), new Vector2((float)(AttackRect.X + 4), (float)AttackRect.Y), Fonts.Arial12, Color.White); } else { this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/Ground_Attack"], AttackRect, Color.White); } Rectangle StrengthRect = new Rectangle(TroopClickRect.X + TroopClickRect.Width + 2, TroopClickRect.Y + 5, Fonts.Arial12.LineSpacing + 8, Fonts.Arial12.LineSpacing + 4); Primitives2D.FillRectangle(this.ScreenManager.SpriteBatch, StrengthRect, new Color(0, 0, 0, 200)); Primitives2D.DrawRectangle(this.ScreenManager.SpriteBatch, StrengthRect, pgs.TroopsHere[0].GetOwner().EmpireColor); Vector2 cursor = new Vector2((float)(StrengthRect.X + StrengthRect.Width / 2) - Fonts.Arial12.MeasureString(pgs.TroopsHere[0].Strength.ToString("0.")).X / 2f, (float)(1 + StrengthRect.Y + StrengthRect.Height / 2 - Fonts.Arial12.LineSpacing / 2)); this.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12, pgs.TroopsHere[0].Strength.ToString("0."), cursor, Color.White); if (this.ActiveTroop != null && this.ActiveTroop == pgs) { if (this.ActiveTroop.TroopsHere[0].AvailableAttackActions > 0) { foreach (PlanetGridSquare nearby in this.p.TilesList) { if (nearby == pgs || !nearby.CanAttack) { continue; } this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/GC_Potential_Attack"], nearby.ClickRect, Color.White); } } if (this.ActiveTroop.TroopsHere[0].AvailableMoveActions > 0) { foreach (PlanetGridSquare nearby in this.p.TilesList) { if (nearby == pgs || !nearby.CanMoveTo) { continue; } Primitives2D.FillRectangle(this.ScreenManager.SpriteBatch, nearby.ClickRect, new Color(255, 255, 255, 30)); Vector2 center = new Vector2((float)(nearby.ClickRect.X + nearby.ClickRect.Width / 2), (float)(nearby.ClickRect.Y + nearby.ClickRect.Height / 2)); Primitives2D.DrawCircle(this.ScreenManager.SpriteBatch, center, 5f, 50, Color.White, 5f); Primitives2D.DrawCircle(this.ScreenManager.SpriteBatch, center, 5f, 50, Color.Black); } } } } else if (pgs.building != null) { if (pgs.building.CombatStrength <= 0) { Rectangle bRect = new Rectangle(pgs.ClickRect.X + pgs.ClickRect.Width / 2 - 32, pgs.ClickRect.Y + pgs.ClickRect.Height / 2 - 32, 64, 64); Rectangle StrengthRect = new Rectangle(bRect.X + bRect.Width + 2, bRect.Y + 5, Fonts.Arial12.LineSpacing + 8, Fonts.Arial12.LineSpacing + 4); Primitives2D.FillRectangle(this.ScreenManager.SpriteBatch, StrengthRect, new Color(0, 0, 0, 200)); Primitives2D.DrawRectangle(this.ScreenManager.SpriteBatch, StrengthRect, (this.p.Owner != null ? this.p.Owner.EmpireColor : Color.Gray)); Vector2 cursor = new Vector2((float)(StrengthRect.X + StrengthRect.Width / 2) - Fonts.Arial12.MeasureString(pgs.building.Strength.ToString()).X / 2f, (float)(1 + StrengthRect.Y + StrengthRect.Height / 2 - Fonts.Arial12.LineSpacing / 2)); this.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12, pgs.building.Strength.ToString(), cursor, Color.White); } else { Rectangle AttackRect = new Rectangle(pgs.TroopClickRect.X + pgs.TroopClickRect.Width + 2, pgs.TroopClickRect.Y + 23, 12, 12); if (pgs.building.AvailableAttackActions <= 0) { int num = (int)pgs.building.AttackTimer + 1; this.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12, num.ToString(), new Vector2((float)(AttackRect.X + 4), (float)AttackRect.Y), Color.White); } else { this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/Ground_Attack"], AttackRect, Color.White); } Rectangle StrengthRect = new Rectangle(pgs.TroopClickRect.X + pgs.TroopClickRect.Width + 2, pgs.TroopClickRect.Y + 5, Fonts.Arial12.LineSpacing + 8, Fonts.Arial12.LineSpacing + 4); Primitives2D.FillRectangle(this.ScreenManager.SpriteBatch, StrengthRect, new Color(0, 0, 0, 200)); Primitives2D.DrawRectangle(this.ScreenManager.SpriteBatch, StrengthRect, (this.p.Owner != null ? this.p.Owner.EmpireColor : Color.LightGray)); Vector2 cursor = new Vector2((float)(StrengthRect.X + StrengthRect.Width / 2) - Fonts.Arial12.MeasureString(pgs.building.CombatStrength.ToString()).X / 2f, (float)(1 + StrengthRect.Y + StrengthRect.Height / 2 - Fonts.Arial12.LineSpacing / 2)); this.ScreenManager.SpriteBatch.DrawString(Fonts.Arial12, pgs.building.CombatStrength.ToString(), cursor, Color.White); } if (this.ActiveTroop != null && this.ActiveTroop == pgs && this.ActiveTroop.building.AvailableAttackActions > 0) { foreach (PlanetGridSquare nearby in this.p.TilesList) { if (nearby == pgs || !nearby.CanAttack) { continue; } this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/GC_Potential_Attack"], nearby.ClickRect, Color.White); } } } }
private void DrawCombatInfo(PlanetGridSquare pgs) { if (this.ActiveTroop != null && this.ActiveTroop == pgs || pgs.building != null && pgs.building.CombatStrength > 0 && this.ActiveTroop != null && this.ActiveTroop == pgs) { Rectangle ActiveSelectionRect = new Rectangle(pgs.TroopClickRect.X - 5, pgs.TroopClickRect.Y - 5, pgs.TroopClickRect.Width + 10, pgs.TroopClickRect.Height + 10); this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/GC_Square Selection"], ActiveSelectionRect, Color.White); foreach (PlanetGridSquare nearby in this.ReversedList) { if (nearby == pgs || !nearby.ShowAttackHover) { continue; } this.ScreenManager.SpriteBatch.Draw(ResourceManager.TextureDict["Ground_UI/GC_Attack_Confirm"], nearby.TroopClickRect, Color.White); } } }
public void SetPGS(PlanetGridSquare pgs) { this.pgs = pgs; if (this.pgs == null) { return; } if (pgs.TroopsHere.Count != 0) { this.DescriptionSL.Entries.Clear(); this.DescriptionSL.indexAtTop = 0; HelperFunctions.parseTextToSL(pgs.TroopsHere[0].Description, (float)(this.LeftRect.Width - 15), Fonts.Arial12, ref this.DescriptionSL); return; } if (pgs.building != null) { this.DescriptionSL.Entries.Clear(); this.DescriptionSL.indexAtTop = 0; HelperFunctions.parseTextToSL(Localizer.Token(pgs.building.DescriptionIndex), (float)(this.LeftRect.Width - 15), Fonts.Arial12, ref this.DescriptionSL); } }
private Planet CreatePlanetFromPlanetSaveData(SavedGame.PlanetSaveData data) { Building building; Planet p = new Planet(); if (!string.IsNullOrEmpty(data.Owner)) { p.Owner = EmpireManager.GetEmpireByName(data.Owner); p.Owner.AddPlanet(p); } p.guid = data.guid; p.Name = data.Name; if (data.Scale != null && data.Scale != 0) { p.scale = data.Scale; } else { float scale = RandomMath.RandomBetween(1f, 2f); p.scale = scale; } p.colonyType = data.ColonyType; if (!data.GovernorOn) { p.GovernorOn = data.GovernorOn; p.colonyType = Planet.ColonyType.Colony; } p.OrbitalAngle = data.OrbitalAngle; p.fs = data.FoodState; p.ps = data.ProdState; p.FoodLocked = data.FoodLock; p.ProdLocked = data.ProdLock; p.ResLocked = data.ResLock; p.OrbitalRadius = data.OrbitalDistance; p.Population = data.Population; p.MaxPopulation = data.PopulationMax; p.Fertility = data.Fertility; p.MineralRichness = data.Richness; p.TerraformPoints = data.TerraformPoints; p.hasRings = data.HasRings; p.planetType = data.WhichPlanet; p.ShieldStrengthCurrent = data.ShieldStrength; p.LoadAttributes(); p.Crippled_Turns = data.Crippled_Turns; p.planetTilt = RandomMath.RandomBetween(45f, 135f); p.ObjectRadius = 100f * (float)(1 + ((Math.Log(p.scale)) / 1.5)); // p.scale; //(1 + ((Math.Log(planet.scale))/1.5) ) foreach (Guid guid in data.StationsList) { p.Shipyards.TryAdd(guid, new Ship()); } p.FarmerPercentage = data.farmerPercentage; p.WorkerPercentage = data.workerPercentage; p.ResearcherPercentage = data.researcherPercentage; p.FoodHere = data.foodHere; p.ProductionHere = data.prodHere; if (p.hasRings) { p.ringTilt = RandomMath.RandomBetween(-80f, -45f); } foreach (SavedGame.PGSData d in data.PGSList) { int num = d.x; int num1 = d.y; int num2 = d.foodbonus; int num3 = d.prodbonus; int num4 = d.resbonus; if (d.building != null) { building = d.building; } else { building = null; } PlanetGridSquare pgs = new PlanetGridSquare(num, num1, num2, num3, num4, building, d.Habitable) { Biosphere = d.Biosphere }; if (pgs.Biosphere) { p.BuildingList.Add(Ship_Game.ResourceManager.GetBuilding("Biospheres")); } p.TilesList.Add(pgs); //List<Troop> toremove = new List<Troop>(); foreach (Troop t in d.TroopsHere) { if (Ship_Game.ResourceManager.TroopsDict.ContainsKey(t.Name)) { pgs.TroopsHere.Add(t); p.TroopsHere.Add(t); t.SetPlanet(p); } } // else // { // toremove.Add(t); // } //} //foreach(Troop killit in toremove) //{ //} if (pgs.building == null) { continue; } p.BuildingList.Add(pgs.building); if (!pgs.building.isWeapon) { continue; } pgs.building.theWeapon = Ship_Game.ResourceManager.WeaponsDict[pgs.building.Weapon]; } return p; }