/// <summary> /// Anything related with the cursor on the field is here. /// </summary> public void MoveSquad() { const float MovementSpeed = 0.2f; for (int P = MovementAnimation.Count - 1; P >= 0; --P) { UnitMapComponent ActiveUnitMap = MovementAnimation.ListMovingMapUnit[P]; if (MovementAnimation.ListPosX[P] < ActiveUnitMap.X - MovementSpeed) { MovementAnimation.ListPosX[P] += MovementSpeed; if (MovementAnimation.ListPosX[P] > ActiveUnitMap.X + MovementSpeed) { MovementAnimation.ListPosX[P] = ActiveUnitMap.X; } } else if (MovementAnimation.ListPosX[P] > ActiveUnitMap.X + MovementSpeed) { MovementAnimation.ListPosX[P] -= MovementSpeed; if (MovementAnimation.ListPosX[P] < ActiveUnitMap.X - MovementSpeed) { MovementAnimation.ListPosX[P] = ActiveUnitMap.X; } } else { MovementAnimation.ListPosX[P] = ActiveUnitMap.X; } if (MovementAnimation.ListPosY[P] < ActiveUnitMap.Y - MovementSpeed) { MovementAnimation.ListPosY[P] += MovementSpeed; if (MovementAnimation.ListPosY[P] > ActiveUnitMap.Y + MovementSpeed) { MovementAnimation.ListPosY[P] = ActiveUnitMap.Y; } } else if (MovementAnimation.ListPosY[P] > ActiveUnitMap.Y + MovementSpeed) { MovementAnimation.ListPosY[P] -= MovementSpeed; if (MovementAnimation.ListPosY[P] < ActiveUnitMap.Y - MovementSpeed) { MovementAnimation.ListPosY[P] = ActiveUnitMap.Y; } } else { MovementAnimation.ListPosY[P] = ActiveUnitMap.Y; if (MovementAnimation.ListPosX[P] == ActiveUnitMap.X) { MovementAnimation.RemoveAt(P--); } } } if (InputHelper.InputConfirmPressed() || MouseHelper.InputLeftButtonReleased()) { OnlinePlayers.ExecuteAndSend(new Online.BattleMapLobyScriptHolder.SkipSquadMovementScript(this)); } }
protected override void Execute(IOnlineConnection Host) { for (int P = Map.MovementAnimation.Count - 1; P >= 0; --P) { UnitMapComponent ActiveUnitMap = Map.MovementAnimation.ListMovingMapUnit[P]; Map.MovementAnimation.ListPosX[P] = ActiveUnitMap.X; Map.MovementAnimation.ListPosY[P] = ActiveUnitMap.Y; } }
public int IndexOf(UnitMapComponent MovingMapUnit) { for (int i = ListMovingMapUnit.Count - 1; i >= 0; --i) { if (ListMovingMapUnit.IndexOf(MovingMapUnit) >= 0) { return(ListMovingMapUnit.IndexOf(MovingMapUnit)); } } return(-1); }
public UnitConquest(string Name, ContentManager Content, Dictionary <string, BaseSkillRequirement> DicRequirement, Dictionary <string, BaseEffect> DicEffect) : base(Name) { _UnitStat = new UnitStats(new bool[1, 1] { { true } }); _UnitStat.ListTerrainChoices = new List <string>(1); _UnitStat.ArrayUnitAbility = new BaseAutomaticSkill[0]; MapComponents = new ConquestMapComponent(this, Content); ArrayCharacterActive = new Character[0]; FileStream FS = new FileStream("Content/Units/Conquest/" + Name + ".peu", FileMode.Open, FileAccess.Read); BinaryReader BR = new BinaryReader(FS, Encoding.UTF8); BR.BaseStream.Seek(0, SeekOrigin.Begin); MaxHP = BR.ReadInt32() * 10; MaxMovement = BR.ReadInt32(); MaxAmmo = BR.ReadInt32(); MaxGaz = BR.ReadInt32(); MaxMaterial = BR.ReadInt32(); ListTerrainChoices.Add(BR.ReadString()); ArmourType = BR.ReadString(); GazCostPerTurn = BR.ReadInt32(); VisionRange = BR.ReadInt32(); Weapon1Name = BR.ReadString(); Weapon1PostMovement = BR.ReadBoolean(); Weapon1MinimumRange = BR.ReadInt32(); Weapon1MaximumRange = BR.ReadInt32(); Weapon2Name = BR.ReadString(); Weapon2PostMovement = BR.ReadBoolean(); Weapon2MinimumRange = BR.ReadInt32(); Weapon2MaximumRange = BR.ReadInt32(); if (Content != null) { if (File.Exists("Content\\Units\\Conquest\\Map Sprite\\" + Name + ".xnb")) { SpriteMap = Content.Load <Texture2D>("Units\\Conquest\\Map Sprite\\" + Name); } else { SpriteMap = Content.Load <Texture2D>("Units/Default"); } SpriteUnit = Content.Load <Texture2D>("Units\\Conquest\\Unit Sprite\\" + Name); } FS.Close(); BR.Close(); }
public override float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo) { float MovementCostToNeighbor = 0; if (MapComponent.CurrentMovement == UnitStats.TerrainAir) { if (Map.GetTerrainLetterAttribute(UnitStat, UnitStats.TerrainAir) == 'C' || Map.GetTerrainLetterAttribute(UnitStat, UnitStats.TerrainAir) == 'D' || Map.GetTerrainLetterAttribute(UnitStat, UnitStats.TerrainAir) == '-') { MovementCostToNeighbor += 0.5f; } else { MovementCostToNeighbor += 1; } } else { string TerrainType = Map.GetTerrainType(TerrainToGo); if (!UnitStat.ListTerrainChoices.Contains(TerrainType)) { return(-1); } char TerrainCharacter = Map.GetTerrainLetterAttribute(UnitStat, TerrainType); if ((TerrainCharacter == 'C' || TerrainCharacter == 'D' || TerrainCharacter == '-') && TerrainType != UnitStats.TerrainLand) { MovementCostToNeighbor += TerrainToGo.MVMoveCost + 0.5f; } else if (TerrainCharacter == 'S' && TerrainToGo.MVMoveCost > 1) { MovementCostToNeighbor += TerrainToGo.MVMoveCost / 2; } else { MovementCostToNeighbor += TerrainToGo.MVMoveCost; } if (TerrainToGo.TerrainTypeIndex != GetTile(CurrentNode.Position.X, CurrentNode.Position.Y, (int)MapComponent.Z).TerrainTypeIndex) { MovementCostToNeighbor += TerrainToGo.MVEnterCost; } } return(MovementCostToNeighbor); }
public List <MovementAlgorithmTile> GetAllTerrain(UnitMapComponent ActiveUnit) { List <MovementAlgorithmTile> ListTerrainFound = new List <MovementAlgorithmTile>(); for (int X = 0; X < ActiveUnit.ArrayMapSize.GetLength(0); ++X) { for (int Y = 0; Y < ActiveUnit.ArrayMapSize.GetLength(1); ++Y) { if (ActiveUnit.ArrayMapSize[X, Y]) { ListTerrainFound.Add(LayerManager.ListLayer[(int)ActiveUnit.Z].ArrayTerrain[(int)ActiveUnit.X + X, (int)ActiveUnit.Y + Y]); } } } return(ListTerrainFound); }
public override float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo) { float MovementCostToNeighbor = 0; if (MapComponent.CurrentMovement == "Air") { if (Map.GetTerrainLetterAttribute(UnitStat, "Air") == 'C' || Map.GetTerrainLetterAttribute(UnitStat, "Air") == 'D' || Map.GetTerrainLetterAttribute(UnitStat, "Air") == '-') { MovementCostToNeighbor += 0.5f; } else { MovementCostToNeighbor += 1; } } else { char TerrainCharacter = Map.GetTerrainLetterAttribute(UnitStat, Map.GetTerrainType(TerrainToGo)); if ((TerrainCharacter == 'C' || TerrainCharacter == 'D' || TerrainCharacter == '-') && Map.GetTerrainType(TerrainToGo) != "Land") { MovementCostToNeighbor += TerrainToGo.MVMoveCost + 0.5f; } else if (TerrainCharacter == 'S' && TerrainToGo.MVMoveCost > 1) { MovementCostToNeighbor += TerrainToGo.MVMoveCost / 2; } else { MovementCostToNeighbor += TerrainToGo.MVMoveCost; } if (TerrainToGo.TerrainTypeIndex != GetTile(CurrentNode.Position.X, CurrentNode.Position.Y, MapComponent.LayerIndex).TerrainTypeIndex) { MovementCostToNeighbor += TerrainToGo.MVEnterCost; } } return(MovementCostToNeighbor); }
public void DrawUnitMap(CustomSpriteBatch g, Color PlayerColor, UnitMapComponent ActiveSquad, bool IsGreyed) { //If it's dead, don't draw it. if (!ActiveSquad.IsActive) { return; } float PosZ = ActiveSquad.Z; if (Map.MovementAnimation.Contains(ActiveSquad)) { int IndexOfUnit = Map.MovementAnimation.IndexOf(ActiveSquad); float PosX = (Map.MovementAnimation.ListPosX[IndexOfUnit] - CameraPosition.X) * TileSize.X; float PosY = (Map.MovementAnimation.ListPosY[IndexOfUnit] - CameraPosition.Y) * TileSize.Y; if (ActiveSquad.IsFlying) { g.Draw(Map.sprUnitHover, new Vector2(PosX, PosY), Color.White); PosY -= 7; } ActiveSquad.Draw2DOnMap(g, new Vector3(PosX, PosY, PosZ), Color.White); g.End(); g.Begin(SpriteSortMode.Immediate, BlendState.Additive); ActiveSquad.Draw2DOnMap(g, new Vector3(PosX, PosY, PosZ), Color.White); g.End(); g.Begin(); } else { Color UnitColor; if (Constants.UnitRepresentationState == Constants.UnitRepresentationStates.Colored) { UnitColor = PlayerColor; } else { UnitColor = Color.White; } float PosX = (ActiveSquad.X - CameraPosition.X) * TileSize.X; float PosY = (ActiveSquad.Y - CameraPosition.Y) * TileSize.Y; if (ActiveSquad.IsFlying) { g.Draw(Map.sprUnitHover, new Vector2(PosX, PosY), Color.White); PosY -= 7; } if (Constants.UnitRepresentationState == Constants.UnitRepresentationStates.NonColoredWithBorder) { Vector2 TextureRealSize = new Vector2(ActiveSquad.Width, ActiveSquad.Height); Vector2 TextureOuputSize = new Vector2(TextureRealSize.X + 2, TextureRealSize.Y + 2); Vector2 PixelSize = new Vector2(1 / TextureOuputSize.X, 1 / TextureOuputSize.Y); Vector2 TextureScale = TextureOuputSize / TextureRealSize; Map.fxOutline.Parameters["TextureScale"].SetValue(TextureScale); Map.fxOutline.Parameters["OffsetScale"].SetValue(PixelSize * TextureScale); g.End(); g.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, Map.fxOutline); ActiveSquad.Draw2DOnMap(g, new Vector3(PosX - 1, PosY - 1, PosZ), (int)TextureOuputSize.X, (int)TextureOuputSize.Y, PlayerColor); g.End(); g.Begin(); } //Unit can't move, grayed. if (IsGreyed) { g.End(); g.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, Map.fxGrayscale); ActiveSquad.Draw2DOnMap(g, new Vector3(PosX, PosY, PosZ), Color.White); g.End(); g.Begin(); if (Constants.UnitRepresentationState == Constants.UnitRepresentationStates.Colored) { ActiveSquad.Draw2DOnMap(g, new Vector3(PosX, PosY, PosZ), Color.FromNonPremultiplied(UnitColor.R, UnitColor.G, UnitColor.B, 140)); } } else { ActiveSquad.Draw2DOnMap(g, new Vector3(PosX, PosY, PosZ), UnitColor); } ActiveSquad.DrawExtraOnMap(g, new Vector3(PosX, PosY, PosZ), Color.White); } }
public override float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo) { return(TerrainToGo.MVMoveCost); }
public bool Contains(UnitMapComponent MovingMapUnit) { return(ListMovingMapUnit.Contains(MovingMapUnit)); }
public DrawableTile GetTile(UnitMapComponent ActiveUnit) { return(LayerManager.GetTile((int)ActiveUnit.X, (int)ActiveUnit.Y, (int)ActiveUnit.Z)); }
public List <MovementAlgorithmTile> UpdatePath(MovementAlgorithmTile AStartNode, UnitMapComponent MapComponent, UnitStats UnitStat, int MaxMovement) { MovementAlgorithmTile CurrentNode; ListOpenNode.Add(AStartNode); ListAllNode.Add(AStartNode); while (ListOpenNode.Count > 0) { //Use the node with the lowest cost.(Sort it first) CurrentNode = ListOpenNode[0]; int Lowest = 0; for (int i = 1; i < ListOpenNode.Count; i++) { if (ListOpenNode[i].MovementCost < CurrentNode.MovementCost) { CurrentNode = ListOpenNode[i]; Lowest = i; } } ListOpenNode.RemoveAt(Lowest); ListCloseNode.Add(CurrentNode); // Get successors to the current node List <MovementAlgorithmTile> ListSuccessors = GetSuccessors(CurrentNode, MaxMovement, MapComponent.LayerIndex); foreach (MovementAlgorithmTile Neighbor in ListSuccessors) { if (!ListAllNode.Contains(Neighbor)) { ListAllNode.Add(Neighbor); } //Cost to move to this Neighbor float MovementCostToNeighbor = CurrentNode.MovementCost + GetMVCost(MapComponent, UnitStat, CurrentNode, Neighbor); //Bad path with higher movement cost then it already has. if (ListCloseNode.Contains(Neighbor) && MovementCostToNeighbor >= Neighbor.MovementCost) { continue; } //New path or Neighbor have a lower movement cost then before. if (!ListOpenNode.Contains(Neighbor) || MovementCostToNeighbor < Neighbor.MovementCost) { Neighbor.Parent = CurrentNode; Neighbor.MovementCost = MovementCostToNeighbor; if (!ListOpenNode.Contains(Neighbor)) { ListOpenNode.Add(Neighbor); } } } } return(ListAllNode); }
public Terrain GetTerrain(UnitMapComponent ActiveUnit) { return(GetTerrain(ActiveUnit.X, ActiveUnit.Y, ActiveUnit.LayerIndex)); }
public ActionPanelDeploy(DeathmatchMap Map, UnitMapComponent TransportUnit) : base("Deploy", Map) { this.TransportUnit = TransportUnit; }
public abstract float GetMVCost(UnitMapComponent MapComponent, UnitStats UnitStat, MovementAlgorithmTile CurrentNode, MovementAlgorithmTile TerrainToGo);
public TerrainSorcererStreet GetTerrain(UnitMapComponent ActiveUnit) { return(GetTerrain((int)ActiveUnit.X, (int)ActiveUnit.Y, ActiveUnit.LayerIndex)); }
public List <MovementAlgorithmTile> FindPath(MovementAlgorithmTile AStartNode, UnitMapComponent MapComponent, UnitStats UnitStat, int MaxMovement) { ResetNodes(); return(UpdatePath(AStartNode, MapComponent, UnitStat, MaxMovement)); }
public void Add(float PosX, float PosY, UnitMapComponent MovingMapUnit) { ListPosX.Add(PosX); ListPosY.Add(PosY); ListMovingMapUnit.Add(MovingMapUnit); }
public ActionPanelBoard(DeathmatchMap Map, UnitMapComponent TransportUnit, Squad ActiveSquad) : base(PanelName, Map, false) { this.TransportUnit = TransportUnit; this.ActiveSquad = ActiveSquad; }
public Terrain GetTerrain(UnitMapComponent ActiveUnit) { return(LayerManager.ListLayer[(int)ActiveUnit.Z].ArrayTerrain[(int)ActiveUnit.X, (int)ActiveUnit.Y]); }