Beispiel #1
0
        /// <see cref="ICommandService.SendFastCommandOnMinimap"/>
        public void SendFastCommandOnMinimap(RCIntVector position)
        {
            /// TODO: This is a PROTOTYPE CODE!
            if (this.scenarioManager.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (this.selectionManager.LocalPlayer == PlayerEnum.Neutral)
            {
                return;
            }

            RCIntVector minimapPixelCoords = position - this.mapWindowBC.Minimap.MinimapPosition.Location;

            minimapPixelCoords = new RCIntVector(Math.Min(this.mapWindowBC.Minimap.MinimapPosition.Width - 1, Math.Max(0, minimapPixelCoords.X)),
                                                 Math.Min(this.mapWindowBC.Minimap.MinimapPosition.Height - 1, Math.Max(0, minimapPixelCoords.Y)));

            IMinimapPixel minimapPixel     = this.mapWindowBC.Minimap.GetMinimapPixel(minimapPixelCoords);
            RCNumVector   pixelCenterOnMap = minimapPixel.CoveredArea.Location + minimapPixel.CoveredArea.Size / 2;

            if (this.selectionManager.CurrentSelection.Count != 0)
            {
                this.multiplayerService.PostCommand(new RCCommand(null,
                                                                  this.selectionManager.CurrentSelection.ToArray(),
                                                                  pixelCenterOnMap,
                                                                  -1,
                                                                  null));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructs a MapWindowBase instance.
        /// </summary>
        /// <param name="targetScenario">Reference to the target scenario.</param>
        protected MapWindowBase(Scenario targetScenario)
        {
            if (targetScenario == null)
            {
                throw new ArgumentNullException("targetScenario");
            }

            this.isDisposed     = false;
            this.targetScenario = targetScenario;

            this.windowMapCoordsCache = new CachedValue <RCNumRectangle>(this.CalculateWindowMapCoords);
            this.cellWindowCache      = new CachedValue <RCIntRectangle>(this.CalculateCellWindow);
            this.quadTileWindowCache  = new CachedValue <RCIntRectangle>(this.CalculateQuadTileWindow);
            this.windowOffsetCache    = new CachedValue <RCIntVector>(this.CalculateWindowOffset);
            this.pixelWindowCache     = new CachedValue <RCIntRectangle>(this.CalculatePixelWindow);

            RCNumVector nullVectorOfPixelGrid = new RCNumVector(
                (RCNumber)1 / (2 * MapWindowBase.PIXEL_PER_NAVCELL) - (RCNumber)1 / 2,
                (RCNumber)1 / (2 * MapWindowBase.PIXEL_PER_NAVCELL) - (RCNumber)1 / 2);
            RCNumVector baseVectorOfPixelGridX = new RCNumVector((RCNumber)1 / MapWindowBase.PIXEL_PER_NAVCELL, 0);
            RCNumVector baseVectorOfPixelGridY = new RCNumVector(0, (RCNumber)1 / MapWindowBase.PIXEL_PER_NAVCELL);

            this.mapToPixelGridTransformation = new RCCoordTransformation(nullVectorOfPixelGrid, baseVectorOfPixelGridX, baseVectorOfPixelGridY);

            this.fullPixelGrid = new RCIntRectangle(new RCIntVector(0, 0), this.targetScenario.Map.CellSize * MapWindowBase.PIXEL_PER_NAVCELL);
        }
Beispiel #3
0
        /// <summary>
        /// Constructs an RCMotionControlTestPage object.
        /// </summary>
        public RCMotionControlTestPage()
        {
            this.timeSinceLastUpdate = 0;
            this.brush = UIRoot.Instance.GraphicsPlatform.SpriteManager.CreateSprite(RCColor.Green, new RCIntVector(1, 1), UIWorkspace.Instance.PixelScaling);
            this.brush.Upload();

            this.entities = new BspSearchTree <TestEntity>(new RCNumRectangle(HALF_VECT * (-1), MAP_SIZE), 16, 10);
            for (int i = 0; i < ENTITY_COUNT; i++)
            {
                RCNumVector size;
                RCNumVector position;
                TestEntity  newEntity;

                do
                {
                    size = new RCNumVector(RandomService.DefaultGenerator.Next((int)(MIN_ENTITY_SIZE.X * 1000), (int)(MAX_ENTITY_SIZE.X * 1000)) / (RCNumber)1000,
                                           RandomService.DefaultGenerator.Next((int)(MIN_ENTITY_SIZE.Y * 1000), (int)(MAX_ENTITY_SIZE.Y * 1000)) / (RCNumber)1000);
                    position  = new RCNumVector(RandomService.DefaultGenerator.Next(MAP_SIZE.X), RandomService.DefaultGenerator.Next(MAP_SIZE.Y));
                    newEntity = new TestEntity(position, size, this.entities);
                } while (this.entities.GetContents(newEntity.BoundingBox).Count != 0);

                this.entities.AttachContent(newEntity);
            }

            this.MouseSensor.Move += this.OnMouseMove;
            UIRoot.Instance.GraphicsPlatform.RenderLoop.FrameUpdate += this.OnUpdate;
        }
Beispiel #4
0
        /// <see cref="ISelectionManagerBC.AddRemoveEntityToSelection"/>
        public void AddRemoveEntityToSelection(RCNumVector position)
        {
            if (this.ActiveScenario == null)
            {
                throw new InvalidOperationException("No active scenario!");
            }
            if (this.localPlayer == PlayerEnum.Neutral)
            {
                throw new InvalidOperationException("Selection manager not initialized!");
            }

            Entity entityAtPos = this.ActiveScenario.GetElementsOnMap <Entity>(position, MapObjectLayerEnum.AirObjects, MapObjectLayerEnum.GroundObjects).FirstOrDefault();

            if (entityAtPos == null)
            {
                return;
            }

            /// If the entity is already selected then remove it from the selection.
            if (this.currentSelection.Remove(entityAtPos.ID.Read()))
            {
                return;
            }

            /// Otherwise add it to the current selection if possible.
            this.AddEntityToSelection(entityAtPos);
        }
Beispiel #5
0
        /// <see cref="ScenarioElement.AttachToMap"/>
        public override bool AttachToMap(RCNumVector position, params ScenarioElement[] elementsToIgnore)
        {
            /// Check if the position of this Refinery would align with a VespeneGeyser.
            RCSet <VespeneGeyser> vespeneGeysersAtPos = this.Scenario.GetElementsOnMap <VespeneGeyser>(position, MapObjectLayerEnum.GroundObjects);

            if (vespeneGeysersAtPos.Count != 1)
            {
                return(false);
            }
            VespeneGeyser vespeneGeyserAtPos = vespeneGeysersAtPos.First();

            if (this.CalculateArea(position) != vespeneGeyserAtPos.Area)
            {
                return(false);
            }

            /// Save the VespeneGeyser and detach it from the map.
            this.underlyingVespeneGeyser.Write(vespeneGeyserAtPos);
            this.underlyingVespeneGeyser.Read().DetachFromMap();

            /// Try to attach the Refinery.
            bool refineryAttached = base.AttachToMap(position, elementsToIgnore);

            if (!refineryAttached)
            {
                /// If the Refinery could not be attached -> reattach the underlying VespeneGeyser.
                this.underlyingVespeneGeyser.Read().AttachToMap(position);
                this.underlyingVespeneGeyser.Write(null);
            }

            return(refineryAttached);
        }
Beispiel #6
0
        /// <summary>
        /// Creates an RCCommand object from the given RCPackage.
        /// </summary>
        /// <param name="cmdPackage">The RCPackage to be deserialized.</param>
        /// <returns>The created RCCommand.</returns>
        public static RCCommand FromPackage(RCPackage cmdPackage)
        {
            if (cmdPackage == null)
            {
                throw new ArgumentNullException("cmdPackage");
            }
            if (!cmdPackage.IsCommitted)
            {
                throw new ArgumentException("The incoming package is not committed!", "cmdPackage");
            }
            if (cmdPackage.PackageFormat.ID != RCCommand.COMMAND_PACKAGEFORMAT)
            {
                throw new ArgumentException("The incoming package is not a command package!", "cmdPackage");
            }

            RCNumVector targetPosition  = RCNumVector.Undefined;
            int         targetPositionX = cmdPackage.ReadInt(2);
            int         targetPositionY = cmdPackage.ReadInt(3);

            if (targetPositionX != -1 && targetPositionY != -1)
            {
                targetPosition = new RCNumVector(new RCNumber(targetPositionX), new RCNumber(targetPositionY));
            }

            return(new RCCommand(
                       cmdPackage.ReadString(0),
                       cmdPackage.ReadIntArray(1),
                       targetPosition,
                       cmdPackage.ReadInt(4),
                       cmdPackage.ReadString(5)));
        }
Beispiel #7
0
        /// <summary>
        /// Constructs a MagicBox instance for the given recipient entities and target position.
        /// </summary>
        /// <param name="recipientEntities">The recipient entities.</param>
        /// <param name="targetPosition">The target position.</param>
        public MagicBox(RCSet <Entity> recipientEntities, RCNumVector targetPosition)
        {
            this.commonTargetPosition = RCNumVector.Undefined;
            this.targetPositions      = new Dictionary <Entity, RCNumVector>();

            /// Check if we shall keep formation of the recipient entities.
            RCNumRectangle boundingBox = this.CalculateBoundingBox(recipientEntities);

            if (!boundingBox.Contains(targetPosition))
            {
                RCNumVector boundingBoxCenter = (2 * boundingBox.Location + boundingBox.Size) / 2;
                foreach (Entity entity in recipientEntities)
                {
                    RCNumVector boxLocationToEntityVector = entity.MotionControl.PositionVector.Read() - boundingBox.Location;
                    RCNumVector magicBox = entity.MotionControl.IsFlying ? AIR_MAGIC_BOX : GROUND_MAGIC_BOX;
                    if (boxLocationToEntityVector.X > magicBox.X || boxLocationToEntityVector.Y > magicBox.Y)
                    {
                        /// Entity is outside of the magic box -> don't keep formation.
                        this.commonTargetPosition = targetPosition;
                        break;
                    }

                    /// Calculate the target position of the entity.
                    this.targetPositions[entity] = targetPosition + entity.MotionControl.PositionVector.Read() - boundingBoxCenter;
                }
            }
            else
            {
                /// Target position is inside the bounding box -> don't keep formation.
                this.commonTargetPosition = targetPosition;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Attaches this entity to the given quadratic tile on the map.
        /// </summary>
        /// <param name="topLeftTile">The quadratic tile at the top-left corner of this entity.</param>
        /// <param name="elementsToIgnore">An optional list of scenario elements to ignore during attach.</param>
        /// <returns>True if this entity was successfully attached to the map; otherwise false.</returns>
        /// <remarks>Note that the caller has to explicitly call MotionControl.Fix to fix this entity after calling this method.</remarks>
        public bool AttachToMap(IQuadTile topLeftTile, params ScenarioElement[] elementsToIgnore)
        {
            ICell       topLeftCell = topLeftTile.GetCell(new RCIntVector(0, 0));
            RCNumVector position    = topLeftCell.MapCoords - new RCNumVector(1, 1) / 2 - this.ElementType.Area.Read().Location;

            return(this.AttachToMap(position, elementsToIgnore));
        }
Beispiel #9
0
        /// <summary>
        /// Tries to align the minimap horizontally.
        /// </summary>
        /// <param name="minimapControlPixelSize">The size of the minimap control in pixels.</param>
        /// <param name="mapCellSize">The size of the map in cells.</param>
        /// <param name="minimapPosition">The position of the minimap on the minimap control in pixels.</param>
        /// <param name="transformation">The transformation between the map (A) and minimap (B) coordinate-systems.</param>
        /// <returns>True if the alignment was successfully; otherwise false.</returns>
        private static bool TryAlignMinimapHorizontally(
            RCIntVector minimapControlPixelSize,
            RCIntVector mapCellSize,
            out RCIntRectangle minimapPosition,
            out RCCoordTransformation transformation)
        {
            RCNumber horzAlignedMinimapHeight = (RCNumber)(minimapControlPixelSize.X * mapCellSize.Y) / (RCNumber)mapCellSize.X;

            if (horzAlignedMinimapHeight > minimapControlPixelSize.Y)
            {
                /// Cannot align horizontally.
                minimapPosition = RCIntRectangle.Undefined;
                transformation  = null;
                return(false);
            }

            /// Align horizontally
            int minimapPixelHeight = horzAlignedMinimapHeight > (int)horzAlignedMinimapHeight
                                   ? (int)horzAlignedMinimapHeight + 1
                                   : (int)horzAlignedMinimapHeight;

            minimapPosition = new RCIntRectangle(0, (minimapControlPixelSize.Y - minimapPixelHeight) / 2, minimapControlPixelSize.X, minimapPixelHeight);

            /// Create the coordinate transformation
            RCNumVector pixelSizeOnMap = new RCNumVector((RCNumber)mapCellSize.X / (RCNumber)minimapControlPixelSize.X,
                                                         (RCNumber)mapCellSize.X / (RCNumber)minimapControlPixelSize.X);
            RCNumVector nullVectorOfMinimap  = (pixelSizeOnMap / 2) - (new RCNumVector(1, 1) / 2);
            RCNumVector baseVectorOfMinimapX = new RCNumVector(pixelSizeOnMap.X, 0);
            RCNumVector baseVectorOfMinimapY = new RCNumVector(0, pixelSizeOnMap.Y);

            transformation = new RCCoordTransformation(nullVectorOfMinimap, baseVectorOfMinimapX, baseVectorOfMinimapY);

            return(true);
        }
Beispiel #10
0
        /// <summary>
        /// Tries to align the minimap vertically.
        /// </summary>
        /// <param name="minimapControlPixelSize">The size of the minimap control in pixels.</param>
        /// <param name="mapCellSize">The size of the map in cells.</param>
        /// <param name="minimapPosition">The position of the minimap on the minimap control in pixels.</param>
        /// <param name="transformation">The transformation between the map (A) and minimap (B) coordinate-systems.</param>
        /// <returns>True if the alignment was successfully; otherwise false.</returns>
        private static bool TryAlignMinimapVertically(
            RCIntVector minimapControlPixelSize,
            RCIntVector mapCellSize,
            out RCIntRectangle minimapPosition,
            out RCCoordTransformation transformation)
        {
            RCNumber vertAlignedMinimapWidth = (RCNumber)(minimapControlPixelSize.Y * mapCellSize.X) / (RCNumber)mapCellSize.Y;

            if (vertAlignedMinimapWidth > minimapControlPixelSize.X)
            {
                /// Cannot align vertically.
                minimapPosition = RCIntRectangle.Undefined;
                transformation  = null;
                return(false);
            }

            /// Align vertically
            int minimapPixelWidth = vertAlignedMinimapWidth > (int)vertAlignedMinimapWidth
                                  ? (int)vertAlignedMinimapWidth + 1
                                  : (int)vertAlignedMinimapWidth;

            minimapPosition = new RCIntRectangle((minimapControlPixelSize.X - minimapPixelWidth) / 2, 0, minimapPixelWidth, minimapControlPixelSize.Y);

            /// Create the coordinate transformation
            RCNumVector pixelSizeOnMap = new RCNumVector((RCNumber)mapCellSize.Y / (RCNumber)minimapControlPixelSize.Y,
                                                         (RCNumber)mapCellSize.Y / (RCNumber)minimapControlPixelSize.Y);
            RCNumVector nullVectorOfMinimap  = (pixelSizeOnMap / 2) - (new RCNumVector(1, 1) / 2);
            RCNumVector baseVectorOfMinimapX = new RCNumVector(pixelSizeOnMap.X, 0);
            RCNumVector baseVectorOfMinimapY = new RCNumVector(0, pixelSizeOnMap.Y);

            transformation = new RCCoordTransformation(nullVectorOfMinimap, baseVectorOfMinimapX, baseVectorOfMinimapY);

            return(true);
        }
Beispiel #11
0
 /// <summary>
 /// Creates a SCVContinueBuildExecution instance.
 /// </summary>
 /// <param name="recipientSCV">The recipient SCV of this command execution.</param>
 /// <param name="targetPosition">The target position.</param>
 /// <param name="targetBuildingID">The ID of the target building whose construction to be continued.</param>
 public SCVContinueBuildExecution(SCV recipientSCV, RCNumVector targetPosition, int targetBuildingID)
     : base(recipientSCV)
 {
     this.targetBuildingID = this.ConstructField <int>("targetBuildingID");
     this.TargetPosition   = targetPosition;
     this.targetBuildingID.Write(targetBuildingID);
 }
Beispiel #12
0
        /// <summary>
        /// Gets the list of all velocities that are admissible from the given velocity.
        /// </summary>
        /// <param name="currentVelocity">The given velocity.</param>
        /// <returns>All velocities that are admissible from the given velocity.</returns>
        public List <RCNumVector> GetAdmissibleVelocities(RCNumVector currentVelocity)
        {
            if (!this.velocityGraph.ContainsKey(currentVelocity))
            {
                /// Search the velocity that has a minimum difference to the current velocity.
                RCNumber    minDiff         = 0;
                RCNumVector closestVelocity = RCNumVector.Undefined;
                foreach (RCNumVector velocity in this.velocityGraph.Keys)
                {
                    RCNumber diff = MapUtils.ComputeDistance(currentVelocity, velocity);
                    if (closestVelocity == RCNumVector.Undefined || diff < minDiff)
                    {
                        minDiff         = diff;
                        closestVelocity = velocity;
                    }
                }

                if (closestVelocity == RCNumVector.Undefined)
                {
                    throw new InvalidOperationException("Impossible case!");
                }
                currentVelocity = closestVelocity;
            }

            return(new List <RCNumVector>(this.velocityGraph[currentVelocity]));
        }
Beispiel #13
0
        /// <summary>
        /// Updates this missile if it is in Impacted state.
        /// </summary>
        private bool UpdateImpactedState()
        {
            /// Update the target entity position and height if it is still on the map.
            if (this.targetEntity.Read().HasMapObject(MapObjectLayerEnum.GroundObjects, MapObjectLayerEnum.AirObjects))
            {
                this.lastKnownTargetEntityPos.Write(this.targetEntity.Read().MotionControl.PositionVector.Read());
                this.lastKnownTargetEntityIsFlying.Write(this.targetEntity.Read().MotionControl.IsFlying ? (byte)0x01 : (byte)0x00);
            }

            /// Create an impact indicator map object if it has not yet been created and the missile type defines an impact animation.
            if (this.impactIndicator == null && this.missileData.MissileType.ImpactAnimation != null)
            {
                RCNumVector impactIndicatorPos = this.missileData.MissileType.Speed != null
                    ? this.missilePosition.Read()
                    : this.lastKnownTargetEntityPos.Read();

                this.impactIndicator = this.CreateMapObject(this.CalculateArea(impactIndicatorPos), this.lastKnownTargetEntityIsFlying.Read() == 0x01 ? MapObjectLayerEnum.AirMissiles : MapObjectLayerEnum.GroundMissiles);
                this.impactIndicator.StartAnimation(this.missileData.MissileType.ImpactAnimation, this.missileVelocity);
            }

            /// Check if the lifecycle of this missile has already ended.
            if ((this.launchIndicator == null || this.launchIndicator.IsDestroyed) &&
                (this.missileIndicator == null || this.missileIndicator.IsDestroyed) &&
                (this.impactIndicator == null || this.impactIndicator.IsDestroyed))
            {
                return(false);
            }

            return(true);
        }
Beispiel #14
0
        /// <summary>
        /// Gets the scenario elements of the given type that are attached to at least one of the given layers of the map at the given position.
        /// </summary>
        /// <typeparam name="T">The type of the scenario elements to get.</typeparam>
        /// <param name="position">The position to search.</param>
        /// <param name="firstLayer">The first layer to search in.</param>
        /// <param name="furtherLayers">List of the further layers to search in.</param>
        /// <returns>
        /// A list that contains the scenario elements of the given type that are attached to at least one of the given layers of the map at
        /// the given position.
        /// </returns>
        public RCSet <T> GetElementsOnMap <T>(RCNumVector position, MapObjectLayerEnum firstLayer, params MapObjectLayerEnum[] furtherLayers) where T : ScenarioElement
        {
            if (position == RCNumVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }
            if (furtherLayers == null)
            {
                throw new ArgumentNullException("furtherLayers");
            }

            RCSet <T> retList = new RCSet <T>();

            foreach (MapObject mapObj in this.mapObjects[firstLayer].GetContents(position))
            {
                T elementAsT = mapObj.Owner as T;
                if (elementAsT != null)
                {
                    retList.Add(elementAsT);
                }
            }
            foreach (MapObjectLayerEnum furtherLayer in furtherLayers)
            {
                foreach (MapObject mapObj in this.mapObjects[furtherLayer].GetContents(position))
                {
                    T elementAsT = mapObj.Owner as T;
                    if (elementAsT != null)
                    {
                        retList.Add(elementAsT);
                    }
                }
            }
            return(retList);
        }
Beispiel #15
0
        /// <summary>
        /// Do SCV activities during construction.
        /// </summary>
        private void MakeScvActivityDuringConstruction()
        {
            /// Start using the build tool of the SCV and decrease the move-timer.
            TerranBuilding constructedBuilding = this.RecipientSCV.ConstructionJob.ConstructedBuilding;

            if (this.timeToNextScvMoveDuringConstruction.Read() > 0)
            {
                if (!this.recipientSCV.Read().MotionControl.IsMoving&& this.recipientSCV.Read().Armour.Target == null)
                {
                    this.recipientSCV.Read().Armour.StartAttack(constructedBuilding.ID.Read(), SCV.SCV_BUILD_TOOL_NAME);
                }
                this.timeToNextScvMoveDuringConstruction.Write(this.timeToNextScvMoveDuringConstruction.Read() - 1);
                return;
            }

            /// Generate a random position inside the building area and move the SCV there.
            /// TODO: do not use the default random generator because the engine shall be deterministic!
            RCIntRectangle buildingQuadRect = constructedBuilding.MapObject.QuadraticPosition;
            RCIntRectangle buildingCellRect = this.Scenario.Map.QuadToCellRect(buildingQuadRect);
            RCNumVector    movePosition     = new RCNumVector(
                RandomService.DefaultGenerator.Next(buildingCellRect.Left, buildingCellRect.Right),
                RandomService.DefaultGenerator.Next(buildingCellRect.Top, buildingCellRect.Bottom));

            this.recipientSCV.Read().MotionControl.StartMoving(movePosition);
            this.recipientSCV.Read().Armour.StopAttack();

            /// Reset the timer.
            this.timeToNextScvMoveDuringConstruction.Write(TIME_BETWEEN_SCV_MOVES);
        }
Beispiel #16
0
        /// <see cref="IValueRead&lt;MapDirection&gt;.Read"/>
        public MapDirection Read()
        {
            RCNumVector currentHeadingVector = new RCNumVector(0, 0);

            foreach (IValueRead <RCNumVector> headingVector in this.headingVectors)
            {
                currentHeadingVector = headingVector.Read();
                if (currentHeadingVector == RCNumVector.Undefined)
                {
                    throw new InvalidOperationException("Heading vector cannot be RCNumVector.Undefined!");
                }
                if (currentHeadingVector != new RCNumVector(0, 0))
                {
                    break;
                }
            }

            if (currentHeadingVector != this.lastKnownHeadingVector)
            {
                this.CalculateMapDirection(currentHeadingVector);
                this.lastKnownHeadingVector = currentHeadingVector;
            }

            return(this.cachedMapDirection);
        }
Beispiel #17
0
        /// <summary>
        /// Calculates the map coordinates of the window.
        /// </summary>
        /// <returns>The calculated map coordinates of the window.</returns>
        private RCNumRectangle CalculateWindowMapCoords()
        {
            RCNumRectangle pixelWindowPixelCoords     = new RCNumRectangle(this.pixelWindowCache.Value.Location - MapWindowBase.HALF_VECTOR, this.pixelWindowCache.Value.Size);
            RCNumVector    topLeftCornerMapCoords     = this.mapToPixelGridTransformation.TransformBA(pixelWindowPixelCoords.Location);
            RCNumVector    bottomRightCornerMapCoords = this.mapToPixelGridTransformation.TransformBA(pixelWindowPixelCoords.Location + pixelWindowPixelCoords.Size);

            return(new RCNumRectangle(topLeftCornerMapCoords, bottomRightCornerMapCoords - topLeftCornerMapCoords));
        }
Beispiel #18
0
        /// <summary>
        /// Computes the distance between two points on the map.
        /// </summary>
        /// <param name="fromCoords">The first point on the map.</param>
        /// <param name="toCoords">The second point on the map.</param>
        /// <returns>The computed distance between the given points.</returns>
        public static RCNumber ComputeDistance(RCNumVector fromCoords, RCNumVector toCoords)
        {
            RCNumber horz = (toCoords.X - fromCoords.X).Abs();
            RCNumber vert = (toCoords.Y - fromCoords.Y).Abs();
            RCNumber diff = (horz - vert).Abs();

            return((horz < vert ? horz : vert) * RCNumber.ROOT_OF_TWO + diff);
        }
Beispiel #19
0
 /// <see cref="PathTrackerBase.OnAttaching"/>
 public override bool OnAttaching(RCNumVector position)
 {
     if (this.pathfinderAgent != null)
     {
         throw new InvalidOperationException("The controlled entity has already been attached to the map!");
     }
     this.pathfinderAgent = this.pathfinder.PlaceAgent(this.ControlledEntity.ElementType.ObstacleArea.Read() + position.Round(), this);
     return(this.pathfinderAgent != null);
 }
Beispiel #20
0
        /// <summary>
        /// Called when a mouse button has been pushed over the page.
        /// </summary>
        private void OnMouseMove(UISensitiveObject sender, UIMouseEventArgs evtArgs)
        {
            RCNumVector mapCoordinates = new RCNumVector(evtArgs.Position) / CELL_SIZE - HALF_VECT;

            foreach (TestEntity entity in this.entities.GetContents())
            {
                entity.SetGoal(mapCoordinates);
            }
        }
Beispiel #21
0
 /// <summary>
 /// Scrolls the center of this window to the given position on the map.
 /// </summary>
 /// <param name="targetPosition">The coordinates of the target position on the map.</param>
 public void ScrollTo(RCNumVector targetPosition)
 {
     if (targetPosition == RCNumVector.Undefined)
     {
         throw new ArgumentNullException("targetPosition");
     }
     this.desiredWindowCenterMapCoords = targetPosition;
     this.InvalidateCaches();
 }
        /// <see cref="ICommandExecutionFactory.StartCommandExecution"/>
        public void StartCommandExecution(RCSet <Entity> entitySet, RCNumVector targetPosition, int targetEntityID, string parameter)
        {
            RCSet <T> entitiesToHandle = this.CollectEntitiesToHandle(entitySet);

            foreach (CmdExecutionBase commandExecution in this.CreateCommandExecutions(entitiesToHandle, entitySet, targetPosition, targetEntityID, parameter))
            {
                commandExecution.AttachToScenario();
            }
        }
Beispiel #23
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && this.currentMode == Mode.Creating)
            {
                RCNumVector sizeVect = this.currentPos - this.beginPos;
                if (sizeVect.X > 0 && sizeVect.Y > 0)
                {
                    TestContent newContent = new TestContent(new RCNumRectangle(this.beginPos, sizeVect));

                    this.stopwatch.Reset(); this.stopwatch.Start();
                    this.contentManager.AttachContent(newContent);
                    this.stopwatch.Stop(); this.avgAttachContent.NewItem((int)this.stopwatch.ElapsedMilliseconds);

                    this.nonSelectedContents.Add(newContent);
                    this.Invalidate();
                }
                this.currentMode = Mode.None;
            }
            else if (e.Button == MouseButtons.Left && this.currentMode == Mode.Selecting)
            {
                RCNumVector sizeVect = this.currentPos - this.beginPos;
                if (sizeVect.X > 0 && sizeVect.Y > 0)
                {
                    foreach (TestContent content in this.selectedContents)
                    {
                        this.nonSelectedContents.Add(content);
                    }
                    this.selectedContents.Clear();

                    RCNumRectangle selBox = new RCNumRectangle(this.beginPos, sizeVect);

                    this.stopwatch.Reset(); this.stopwatch.Start();
                    RCSet <TestContent> contents = this.contentManager.GetContents(selBox);
                    this.stopwatch.Stop(); this.avgGetContentInBox.NewItem((int)this.stopwatch.ElapsedMilliseconds);

                    foreach (TestContent content in contents)
                    {
                        this.nonSelectedContents.Remove(content);
                        this.selectedContents.Add(content);
                    }
                    this.Invalidate();
                }
                this.currentMode = Mode.None;
            }
            else if (e.Button == MouseButtons.Left && this.currentMode == Mode.Dragging)
            {
                foreach (TestContent draggedContent in this.selectedContents)
                {
                    this.stopwatch.Reset(); this.stopwatch.Start();
                    draggedContent.BoundingBox += this.currentPos - this.beginPos;
                    this.stopwatch.Stop(); this.avgPositionChange.NewItem((int)this.stopwatch.ElapsedMilliseconds);
                }
                this.Invalidate();
                this.currentMode = Mode.None;
            }
        }
Beispiel #24
0
        /// <see cref="ScenarioElement.AttachToMap"/>
        public override bool AttachToMap(RCNumVector position, params ScenarioElement[] elementsToIgnore)
        {
            bool attachToMapSuccess = base.AttachToMap(position, elementsToIgnore);

            if (attachToMapSuccess)
            {
                this.MotionControl.Fix();
            }
            return(attachToMapSuccess);
        }
Beispiel #25
0
        /// <see cref="ScenarioElement.AttachToMap"/>
        public override bool AttachToMap(RCNumVector position, params ScenarioElement[] elementsToIgnore)
        {
            bool attachToMapSuccess = base.AttachToMap(position, elementsToIgnore);

            if (attachToMapSuccess)
            {
                this.MotionControl.Fix();
                this.MapObject.StartAnimation(ANIMATION_NAME, this.MotionControl.VelocityVector);
            }
            return(attachToMapSuccess);
        }
Beispiel #26
0
 /// <summary>
 /// Constructs a TestEntity instance.
 /// </summary>
 /// <param name="startPosition">The initial position of the test entity.</param>
 /// <param name="size">The size of the test entity.</param>
 /// <param name="entities">The map content manager that stores the entities.</param>
 public TestEntity(RCNumVector startPosition, RCNumVector size, ISearchTree <TestEntity> entities)
 {
     this.currentPosition      = startPosition;
     this.size                 = size;
     this.currentSpeed         = 0;
     this.goal                 = this.currentPosition;
     this.currentDirection     = MapDirection.North;
     this.admissableVelocities = new List <Tuple <RCNumber, MapDirection> >();
     this.selectedVelocity     = null;
     this.entities             = entities;
 }
Beispiel #27
0
        /// <see cref="ScenarioElement.DetachFromMap"/>
        public override RCNumVector DetachFromMap()
        {
            RCNumVector currentPosition = this.position.Read();

            if (this.destructionMapObject != null)
            {
                this.DestroyMapObject(this.destructionMapObject);
                this.destructionMapObject = null;
                this.position.Write(RCNumVector.Undefined);
            }
            return(currentPosition);
        }
Beispiel #28
0
        /// <summary>
        /// Constructs an RCCommand instance.
        /// </summary>
        /// <param name="commandType">The type of the command or null if the type of the command is unknown.</param>
        /// <param name="recipientEntities">The recipient entities of the command.</param>
        /// <param name="targetPosition">The target position of the command or RCNumVector.Undefined if the command doesn't have target position.</param>
        /// <param name="targetEntity">The target entity of the command or -1 if the command doesn't have target entity.</param>
        /// <param name="parameter">The optional parameter of the command or null if the command doesn't have parameter.</param>
        public RCCommand(string commandType, int[] recipientEntities, RCNumVector targetPosition, int targetEntity, string parameter)
        {
            if (recipientEntities == null || recipientEntities.Length == 0)
            {
                throw new ArgumentNullException("recipientEntities");
            }

            this.commandType       = commandType;
            this.recipientEntities = recipientEntities;
            this.targetPosition    = targetPosition;
            this.targetEntity      = targetEntity;
            this.parameter         = parameter;
        }
Beispiel #29
0
        /// <summary>
        /// Helper method for setting the position vector and updating the map object of the owner entity.
        /// </summary>
        /// <param name="newPosition">The new value of the position vector.</param>
        private void SetPosition(RCNumVector newPosition)
        {
            if (newPosition == RCNumVector.Undefined)
            {
                throw new InvalidOperationException("Undefined position!");
            }

            this.position.Write(newPosition);
            if (this.owner.Read().MapObject != null)
            {
                this.owner.Read().MapObject.SetLocation(this.owner.Read().Area);
            }
        }
Beispiel #30
0
        /// <see cref="IMapWindow.MapToWindowCoords"/>
        public RCIntVector MapToWindowCoords(RCNumVector mapCoords)
        {
            if (mapCoords == RCNumVector.Undefined)
            {
                throw new ArgumentNullException("mapCoords");
            }
            if (this.isDisposed)
            {
                throw new ObjectDisposedException("IMapWindow");
            }

            return(this.mapToPixelGridTransformation.TransformAB(mapCoords).Round() - this.PixelWindow.Location);
        }