예제 #1
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            var heightMap = HeightMapManager.instance.GetHeightMap(unit.position);

            var lookAhead = heightMap.granularity;
            var unitRadius = unit.radius;
            var offsetFactor = (unitRadius + lookAhead);
            var perpOffset = new Vector3(-velocityNormal.z * offsetFactor, 0f, velocityNormal.x * offsetFactor);

            var center = unit.position;
            var backLeft = center - (velocityNormal * unitRadius) - perpOffset;
            var backRight = center - (velocityNormal * unitRadius) + perpOffset;
            var frontLeft = center + (velocityNormal * (unitRadius + lookAhead)) - perpOffset;
            var frontRight = center + (velocityNormal * (unitRadius + lookAhead)) + perpOffset;

            _heightCandidates[0] = heightMap.SampleHeight(backLeft);
            _heightCandidates[1] = heightMap.SampleHeight(backRight);
            _heightCandidates[2] = heightMap.SampleHeight(frontLeft);
            _heightCandidates[3] = heightMap.SampleHeight(frontRight);
            _heightCandidates[4] = heightMap.SampleHeight(center);

            var maxHeight = Mathf.Max(_heightCandidates);

            //Ground pos cannot be less than actual ground level. The reason it can be higher is if the unit is in free fall, in which case gravity will handle the rest.
            var groundPos = Mathf.Max(center.y - unit.baseToPositionOffset, _heightCandidates[4]);

            var diff = maxHeight - groundPos;
            return diff <= unit.heightNavigationCapability.maxClimbHeight ? maxHeight + unit.baseToPositionOffset : _heightCandidates[4] + unit.baseToPositionOffset;
        }
예제 #2
0
        public bool IsBlocked(CellMatrix matrix, UnityEngine.Vector3 position, float blockThreshold)
        {
            var x = (int)position.x;
            var z = (int)position.z;

            return((x % 2 != 0) ^ (z % 2 != 0));
        }
예제 #3
0
        public CellMatrix Import(string[] lines, CellMatrixOverflowPolicy overflowPolicy)
        {
            var matrix = new CellMatrix(lines[0].Length, lines.Length, overflowPolicy); // szerokość to długość zerowej linijki, wysokość to liczba linijek

            for (var x = 0; x < matrix.Width; ++x)
            {
                for (var y = 0; y < matrix.Height; ++y)
                {
                    CellLifeState state;

                    if (lines[y][x] == '#')
                    {
                        state = CellLifeState.Alive;
                    }
                    else
                    {
                        state = CellLifeState.Dead;
                    }

                    matrix.SetCellLifeState(x, y, state);
                }
            }

            return(matrix);
        }
예제 #4
0
 public static double PayOffEvaluation(
     [Parameter(" table for payoff")] CellMatrix OptionPayoff,
     [Parameter(" point for evaluation")] double Spot
     )
 {
     throw new Exception("type Wrapper<PayOff> not supported in xlwDotNet");
 }
예제 #5
0
        public bool TrySampleHeight(Vector3 position, CellMatrix matrix, out float height)
        {
            float plotRange;

            if (matrix != null)
            {
                position.y = matrix.origin.y + matrix.upperBoundary;
                plotRange  = matrix.upperBoundary + matrix.lowerBoundary;

                if (!matrix.bounds.Contains(position))
                {
                    height = Consts.InfiniteDrop;
                    return(false);
                }
            }
            else
            {
                plotRange = Mathf.Infinity;
            }

            RaycastHit hit;

            if (Physics.Raycast(position, Vector3.down, out hit, plotRange, Layers.terrain))
            {
                height = hit.point.y;
                return(true);
            }

            height = Consts.InfiniteDrop;
            return(false);
        }
예제 #6
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            var radius = unit.radius + _lookAhead;
            var start = unit.basePosition;
            var baseHeight = start.y;
            var maxClimb = unit.heightNavigationCapability.maxClimbHeight;

            //Put the start at the unit's head or max climb above its center
            start.y = matrix != null ? matrix.origin.y + matrix.upperBoundary : start.y + Mathf.Max(unit.height, radius + maxClimb);

            RaycastHit hit;
            if (!Physics.SphereCast(start, radius, Vector3.down, out hit, Mathf.Infinity, Layers.terrain))
            {
                return Consts.InfiniteDrop;
            }

            var sampledHeight = hit.point.y;

            var diff = sampledHeight - baseHeight;

            if (diff <= maxClimb)
            {
                return sampledHeight + unit.baseToPositionOffset;
            }

            return SampleHeight(unit.position, matrix) + unit.baseToPositionOffset;
        }
예제 #7
0
        /// <summary>
        /// Creates a data instance from the specified configuration.
        /// </summary>
        /// <param name="matrix">The matrix to store.</param>
        /// <returns>The data instance</returns>
        public static CellMatrixData Create(CellMatrix matrix)
        {
            var so = ScriptableObject.CreateInstance<CellMatrixData>();
            so.Initialize(matrix);

            return so;
        }
예제 #8
0
    private bool TryTranslate(int x, int y, bool rotate)
    {
        // increment index if rotate = true
        int    mask_index_next = (_maskIndex + Convert.ToInt32(rotate)) % _settings.rotationMasks.Length;
        ushort mask            = _settings.rotationMasks[mask_index_next];
        int    dx = x - PositionX;
        int    dy = y - PositionY;

        List <Vector2> newBricksPositions = GetNewBricksPosition(mask, dx, dy);

        if (CellMatrix.IsCellsAvailable(newBricksPositions))
        {
            if (dx != 0)
            {
                PositionX = x;
            }
            if (dy != 0)
            {
                PositionY = y;
            }

            if (_maskIndex != mask_index_next)
            {
                Repaint(mask);
                _maskIndex = mask_index_next;
            }
            return(true);
        }

        return(false);
    }
예제 #9
0
 public static double EchoDoubleOrNothing(
     [Parameter("value to specify")] CellMatrix x,
     [Parameter("default value")] double defaultValue
     )
 {
     throw new Exception("type DoubleOrNothing not supported in xlwDotNet");
 }
예제 #10
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            var heightMap = HeightMapManager.instance.GetHeightMap(unit.position);

            var lookAhead    = heightMap.granularity;
            var unitRadius   = unit.radius;
            var offsetFactor = (unitRadius + lookAhead);
            var perpOffset   = new Vector3(-velocityNormal.z * offsetFactor, 0f, velocityNormal.x * offsetFactor);

            var center     = unit.position;
            var backLeft   = center - (velocityNormal * unitRadius) - perpOffset;
            var backRight  = center - (velocityNormal * unitRadius) + perpOffset;
            var frontLeft  = center + (velocityNormal * (unitRadius + lookAhead)) - perpOffset;
            var frontRight = center + (velocityNormal * (unitRadius + lookAhead)) + perpOffset;

            _heightCandidates[0] = heightMap.SampleHeight(backLeft);
            _heightCandidates[1] = heightMap.SampleHeight(backRight);
            _heightCandidates[2] = heightMap.SampleHeight(frontLeft);
            _heightCandidates[3] = heightMap.SampleHeight(frontRight);
            _heightCandidates[4] = heightMap.SampleHeight(center);

            var maxHeight = Mathf.Max(_heightCandidates);

            //Ground pos cannot be less than actual ground level. The reason it can be higher is if the unit is in free fall, in which case gravity will handle the rest.
            var groundPos = Mathf.Max(center.y - unit.baseToPositionOffset, _heightCandidates[4]);

            var diff = maxHeight - groundPos;

            return(diff <= unit.heightNavigationCapability.maxClimbHeight ? maxHeight + unit.baseToPositionOffset : _heightCandidates[4] + unit.baseToPositionOffset);
        }
        public bool TrySampleHeight(Vector3 position, CellMatrix matrix, out float height)
        {
            float plotRange;

            if (matrix != null)
            {
                position.y = matrix.origin.y + matrix.upperBoundary;
                plotRange = matrix.upperBoundary + matrix.lowerBoundary;

                if (!matrix.bounds.Contains(position))
                {
                    height = Consts.InfiniteDrop;
                    return false;
                }
            }
            else
            {
                plotRange = Mathf.Infinity;
            }

            RaycastHit hit;
            if (Physics.Raycast(position, Vector3.down, out hit, plotRange, Layers.terrain))
            {
                height = hit.point.y;
                return true;
            }

            height = Consts.InfiniteDrop;
            return false;
        }
예제 #12
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            var radius     = unit.radius + _lookAhead;
            var start      = unit.basePosition;
            var baseHeight = start.y;
            var maxClimb   = unit.heightNavigationCapability.maxClimbHeight;

            //Put the start at the unit's head or max climb above its center
            start.y = matrix != null ? matrix.origin.y + matrix.upperBoundary : start.y + Mathf.Max(unit.height, radius + maxClimb);

            RaycastHit hit;

            if (!Physics.SphereCast(start, radius, Vector3.down, out hit, Mathf.Infinity, Layers.terrain))
            {
                return(Consts.InfiniteDrop);
            }

            var sampledHeight = hit.point.y;

            var diff = sampledHeight - baseHeight;

            if (diff <= maxClimb)
            {
                return(sampledHeight + unit.baseToPositionOffset);
            }

            return(SampleHeight(unit.position, matrix) + unit.baseToPositionOffset);
        }
예제 #13
0
        public static CellMatrix Python(
            [Parameter("The Python Code")] CellMatrix PythonCode,
            [Parameter("The Parameters ")] CellMatrix TheParameters
            )
        {
            if (PythonCode.ColumnsInStructure != 1)
            {
                throw new Exception("The Python code should  be one column of strings");
            }
            string theCode = "";

            for (int i = 0; i < PythonCode.RowsInStructure; ++i)
            {
                if (!PythonCode[i, 0].IsEmpty)
                {
                    theCode = theCode + PythonCode[i, 0].StringValue() + "\n";
                }
            }
            CellFactory theFactory = new CellFactory();

            scope.SetVariable("Input", TheParameters);
            scope.SetVariable("CellFactory", theFactory);
            ScriptSource source = engine.CreateScriptSourceFromString(theCode, SourceCodeKind.Statements);

            source.Execute(scope);
            return((CellMatrix)scope.GetVariable("Output"));
        }
예제 #14
0
        private static void BakeGrid(GridComponent g)
        {
            var builder = g.GetBuilder();

            var matrix = CellMatrix.Create(builder);

            var data = g.bakedData;

            if (data == null)
            {
                data = CellMatrixData.Create(matrix);

                g.bakedData = data;
            }
            else
            {
                data.Refresh(matrix);
            }

            if (g.storeBakedDataAsAsset)
            {
                EditorUtilities.CreateOrUpdateAsset(data, g.friendlyName.Trim());
            }
            else
            {
                EditorUtility.SetDirty(data);
            }

            g.ResetGrid();
            EditorUtility.SetDirty(g);

            Debug.Log(string.Format("The grid {0} was successfully baked.", g.friendlyName));
        }
예제 #15
0
 public static CellMatrix EchoCells(
     [Parameter(" argument to be echoed")] CellMatrix Echoee
     )
 {
     CellValue.ValueTypeEnum type = Echoee[0, 0].ValueType;
     return(Echoee);
 }
예제 #16
0
        public float SampleHeight(Vector3 position, CellMatrix matrix)
        {
            if (matrix != null)
            {
                return(matrix.origin.y);
            }

            return(Consts.InfiniteDrop);
        }
예제 #17
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            if (matrix != null)
            {
                return(matrix.origin.y + unit.baseToPositionOffset);
            }

            return(unit.position.y);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardCellHeightSettingsProvider"/> class.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 public StandardCellHeightSettingsProvider(CellMatrix matrix)
     : base(matrix)
 {
     var settings = GameServices.heightStrategy.unitsHeightNavigationCapability;
     _maxWalkableSlopeAngle = settings.maxSlopeAngle;
     _maxClimbHeight = settings.maxClimbHeight;
     _maxDropHeight = settings.maxDropHeight;
     _granularity = GameServices.heightStrategy.sampleGranularity;
 }
예제 #19
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            if (matrix != null)
            {
                return matrix.origin.y + unit.baseToPositionOffset;
            }

            return unit.position.y;
        }
        public float SampleHeight(Vector3 position, CellMatrix matrix)
        {
            if (matrix != null)
            {
                return matrix.origin.y;
            }

            return Consts.InfiniteDrop;
        }
예제 #21
0
        public bool TrySampleHeight(Vector3 position, CellMatrix matrix, out float height)
        {
            if (matrix != null)
            {
                height = matrix.origin.y;
                return(true);
            }

            height = Consts.InfiniteDrop;
            return(false);
        }
        public bool TrySampleHeight(Vector3 position, CellMatrix matrix, out float height)
        {
            if (matrix != null)
            {
                height = matrix.origin.y;
                return true;
            }

            height = Consts.InfiniteDrop;
            return false;
        }
        public Matrix <double> GlobalStiffnessMatrix()
        {
            int nverts = mesh.vertexCount;
            int ndof   = DOF * nverts;

            CellMatrix      cellMatrix = new CellMatrix();
            Matrix <double> K          = Matrix <double> .Build.Sparse(ndof, ndof);

            cellMatrix.Assemble(nodes);
            cellMatrix.ComputeCells(K);

            return(K);
        }
예제 #24
0
파일: Clone.cs 프로젝트: Laeeth/d_excelsdk
        public static CellMatrix Clone(this CellMatrix theMatrix)
        {
            CellMatrix theClone = new CellMatrix(theMatrix.RowsInStructure, theMatrix.ColumnsInStructure);
            for (int i = 0; i < theMatrix.RowsInStructure; ++i)
            {
                for (int j = 0; j < theMatrix.ColumnsInStructure; ++j)
                {
                    theClone[i, j] = new CellValue(theMatrix[i, j]);
                }
            }

            return theClone;
        }
예제 #25
0
        public static CellMatrix Clone(this CellMatrix theMatrix)
        {
            CellMatrix theClone = new CellMatrix(theMatrix.RowsInStructure, theMatrix.ColumnsInStructure);
            for (int i = 0; i < theMatrix.RowsInStructure; ++i)
            {
                for (int j = 0; j < theMatrix.ColumnsInStructure; ++j)
                {
                    theClone[i, j] = new CellValue(theMatrix[i, j]);
                }
            }

            return theClone;
        }
예제 #26
0
        public RichCell(CellMatrix parent, Vector3 position, int matrixPosX, int matrixPosZ, bool blocked)
            : base(parent, position, matrixPosX, matrixPosZ, blocked)
        {
            //While a bit redundant (e.g. index 4 being self) it makes it faster to index
            _heightData = new HeightData[9];
            for (int i = 0; i < 9; i++)
            {
                //We use this to indicate an uninitialized state
                _heightData[i].slope = 100f;
            }

            //Worst case scenario for checking all directions
            _worstCase = new HeightData();
        }
예제 #27
0
        private void Initialize(CellMatrix cellMatrix)
        {
            var sizeX = cellMatrix.columns;
            var sizeZ = cellMatrix.rows;

            var matrix = cellMatrix.rawMatrix;

            _heightBlockStatus = new NeighbourPosition[sizeX * sizeZ];

            var blockedIndexsList = new List<int>();
            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    var arrIdx = (z * sizeX) + x;

                    var cell = matrix[x, z];

                    if (!cell.IsWalkableToAny())
                    {
                        blockedIndexsList.Add(arrIdx);
                    }

                    _heightBlockStatus[arrIdx] = cell.heightBlockedNeighbours;
                }
            }

            _blockedIndexes = blockedIndexsList.ToArray();

            var heightSize = cellMatrix.heightMapSize;
            var heightX = heightSize.x;
            var heightZ = heightSize.z;

            _heightEntries = cellMatrix.heightMapEntries;
            _heights = new float[heightX * heightZ];

            for (int x = 0; x < heightX; x++)
            {
                for (int z = 0; z < heightZ; z++)
                {
                    var arrIdx = (z * heightX) + x;

                    _heights[arrIdx] = cellMatrix.SampleHeight(x, z);
                }
            }
        }
예제 #28
0
        public static Boolean ContainsError(
            [Parameter("data to check for errors")] CellMatrix input
            )
        {
            for (int i = 0; i < input.RowsInStructure; ++i)
            {
                for (int j = 0; j < input.ColumnsInStructure; ++j)
                {
                    if (input[i, j].IsError)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #29
0
        public static string CreateObject(
            [Parameter("The Object to be cached")]  CellMatrix theObject)
        {
            if (!theObject[0, 0].IsAString)
            {
                throw new Exception("Expected value to be name of the object");
            }
            string theName = theObject[0, 0].StringValue();

            ObjectCache.Instance[theName] = theObject.Clone();
            if (!NumberCache.Instance.ContainsKey(theName))
            {
                NumberCache.Instance[theName] = 0;
            }


            return(theName + "#" + (NumberCache.Instance[theName]++).ToString());
        }
예제 #30
0
            private void Init(Vector3 from, Vector3 to, float circleRadius, CellMatrix matrix)
            {
                var dx = to.x - from.x;
                var dz = to.z - from.z;

                slopeDir = Math.Sign(dz);
                if (slopeDir == 0)
                {
                    slopeDir = 1;
                }

                //Due to floating point errors, we have to treat low x deltas as vertical
                if (Mathf.Abs(dx) < 0.00001f)
                {
                    this.isVertical = true;
                    return;
                }

                _alpha = dz / dx;

                //instead of handling horizontals specifically (and hence vertical secants), we just treat it as a very small alpha
                _alphaSec = (dz == 0f) ? -1000000f : -dx / dz;
                var ortho = new Vector3(-dz, 0f, dx).normalized *circleRadius;

                if (slopeDir < 0)
                {
                    _betaSecLow  = to.z - (_alphaSec * to.x);
                    _betaSecHigh = from.z - (_alphaSec * from.x);
                }
                else
                {
                    _betaSecLow  = from.z - (_alphaSec * from.x);
                    _betaSecHigh = to.z - (_alphaSec * to.x);
                }

                from = from - matrix.start;

                var tmp = from + ortho;

                _betaTanHigh = tmp.z - (_alpha * tmp.x);

                tmp         = from - ortho;
                _betaTanLow = tmp.z - (_alpha * tmp.x);
            }
예제 #31
0
파일: Cell.cs 프로젝트: forwolk/UnityApex
        /// <summary>
        /// Initializes a new instance of the <see cref="Cell"/> class.
        /// </summary>
        /// <param name="parent">The cell matrix that owns this cell.</param>
        /// <param name="position">The position.</param>
        /// <param name="matrixPosX">The matrix position x.</param>
        /// <param name="matrixPosZ">The matrix position z.</param>
        /// <param name="blocked">if set to <c>true</c> the cell will appear permanently blocked.</param>
        public Cell(CellMatrix parent, Vector3 position, int matrixPosX, int matrixPosZ, bool blocked)
        {
            Ensure.ArgumentNotNull(parent, "parent");

            this.position = position;
            this.matrixPosX = matrixPosX;
            this.matrixPosZ = matrixPosZ;

            _parent = parent;
            _permanentlyBlocked = blocked;

            _neighbours = NeighbourPosition.None;

            if (matrixPosX < (parent.columns - 1))
            {
                _neighbours |= NeighbourPosition.Right;

                if (matrixPosZ < (parent.rows - 1))
                {
                    _neighbours |= (NeighbourPosition.Top | NeighbourPosition.TopRight);
                }

                if (matrixPosZ > 0)
                {
                    _neighbours |= (NeighbourPosition.Bottom | NeighbourPosition.BottomRight);
                }
            }

            if (matrixPosX > 0)
            {
                _neighbours |= NeighbourPosition.Left;

                if (matrixPosZ < (parent.rows - 1))
                {
                    _neighbours |= (NeighbourPosition.Top | NeighbourPosition.TopLeft);
                }

                if (matrixPosZ > 0)
                {
                    _neighbours |= (NeighbourPosition.Bottom | NeighbourPosition.BottomLeft);
                }
            }
        }
예제 #32
0
        private void LoadingField()
        {
            targetField    = new CellMatrix(20, 25);
            playerLocation = new Point(2, 2);
            Bitmap field = new Bitmap(fieldSize, fieldSize);

            pictureBox1.Image = new Bitmap(field);
            g = Graphics.FromImage(pictureBox1.Image);
            SolidBrush brush = new SolidBrush(Color.White);

            g.FillRectangle(brush, 0, 0, fieldSize, fieldSize);

            DrawLines();
            FillNumbers();

            ////
            //////
            /////ГЕНЕРАЦИЯ ПОЛЯ ЦЕЛИ
            /////
            for (int i = 0; i < targetField.Size; i++)
            {
                for (int j = 0; j < targetField.Size; j++)
                {
                    var tempIndex = 40 - (int)Math.Round(Math.Sqrt((targetLocation.X - i) * (targetLocation.X - i) +
                                                                   (targetLocation.Y - j) * (targetLocation.Y - j))) * 2;
                    if (tempIndex > 0)
                    {
                        targetField.Cells[i, j] = tempIndex;
                        PaintCell(i * cellSize, j * cellSize, Color.FromArgb(
                                      ((tempIndex * 5)) > 255 ? 255 : 255 - (tempIndex * 5),
                                      ((tempIndex * 5)) > 255 ? 255 : 255 - (tempIndex * 5),
                                      255),
                                  true);
                    }
                }
            }
            //////
            ////
            ///
            PaintCell((targetLocation.X) * cellSize, targetLocation.Y * cellSize, Color.DarkBlue, false); //цель

            PaintCell(playerLocation.X * cellSize, playerLocation.Y * cellSize, Color.Green, false);      //игрок
        }
예제 #33
0
    public void FixBrick()
    {
        List <GameObject> activeBricks = new List <GameObject>();

        for (int i = 0; i < bricks.Length; i++)
        {
            var brick = bricks[i];
            if (brick.activeSelf)
            {
                activeBricks.Add(brick);
            }
            else
            {
                Destroy(brick);
            }
        }

        CellMatrix.FixCell(GetCurrentBricksPosition(), activeBricks);
    }
예제 #34
0
 public static Student ToStudent(CellMatrix cellMatrix)
 {
     if (cellMatrix.ColumnsInStructure != 1)
     {
         throw new Exception("Student must have 1 column");
     }
     if (cellMatrix.RowsInStructure != 2)
     {
         throw new Exception("Student must a name followed by an age");
     }
     if (!cellMatrix[0, 0].IsAString)
     {
         throw new Exception("Expected name of student in first cell");
     }
     if (!cellMatrix[1, 0].IsANumber)
     {
         throw new Exception("Expected age of student in second cell");
     }
     return(new Student(cellMatrix[0, 0].StringValue(), cellMatrix[1, 0].NumericValue()));
 }
예제 #35
0
 public static Student ToStudent(CellMatrix cellMatrix)
 {
     if (cellMatrix.ColumnsInStructure != 1)
     {
         throw new Exception("Student must have 1 column");
     }
     if (cellMatrix.RowsInStructure != 2)
     {
         throw new Exception("Student must a name followed by an age");
     }
     if (!cellMatrix[0, 0].IsAString)
     {
         throw new Exception("Expected name of student in first cell");
     }
     if (!cellMatrix[1, 0].IsANumber)
     {
         throw new Exception ("Expected age of student in second cell");
     }
     return new Student(cellMatrix[0, 0].StringValue(), cellMatrix[1, 0].NumericValue());
 }
예제 #36
0
        public static double SystemTime(
            [Parameter("number to divide by")] CellMatrix ticksPerSecond
            )
        {
            if (ticksPerSecond.ColumnsInStructure != 1 || ticksPerSecond.RowsInStructure != 1)
            {
                throw new Exception("Multiple values given where one expected for a double or nothing ");
            }

            if (!ticksPerSecond[0, 0].IsEmpty && !ticksPerSecond[0, 0].IsANumber)
            {
                throw new Exception("expected a double or nothing, got something else ");
            }

            bool Empty = ticksPerSecond[0, 0].IsEmpty;

            double   Value = Empty ? 1000: ticksPerSecond[0, 0].NumericValue();
            TimeSpan span  = new TimeSpan(DateTime.Now.Ticks - timeAtStart);

            return(span.TotalMilliseconds / Value);
        }
예제 #37
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            var unitRadius = unit.radius;
            var perpOffset = new Vector3(-velocityNormal.z * unitRadius, 0f, velocityNormal.x * unitRadius);

            var center = unit.position;

            _samplePoints[0] = center - (velocityNormal * unitRadius) - perpOffset;
            _samplePoints[1] = center - (velocityNormal * unitRadius) + perpOffset;
            _samplePoints[2] = center + (velocityNormal * (unitRadius + _lookAhead)) - perpOffset;
            _samplePoints[3] = center + (velocityNormal * (unitRadius + _lookAhead)) + perpOffset;
            _samplePoints[4] = center;

            float maxClimb = unit.heightNavigationCapability.maxClimbHeight;

            float rayStart      = matrix != null ? matrix.origin.y + matrix.upperBoundary : center.y + maxClimb;
            float sampledHeight = Consts.InfiniteDrop;
            float maxHeight     = Consts.InfiniteDrop;

            RaycastHit hit;

            for (int i = 0; i < 5; i++)
            {
                _samplePoints[i].y = rayStart;

                if (Physics.Raycast(_samplePoints[i], Vector3.down, out hit, Mathf.Infinity, Layers.terrain))
                {
                    sampledHeight = hit.point.y;
                    if (sampledHeight > maxHeight)
                    {
                        maxHeight = sampledHeight;
                    }
                }
            }

            var diff = maxHeight - unit.basePosition.y;

            //Since sampledHeight will be the height at the center we can just use that directly here in case the max height is too high.
            return(diff <= maxClimb ? maxHeight + unit.baseToPositionOffset : sampledHeight + unit.baseToPositionOffset);
        }
예제 #38
0
        public void CalculateNextMatrix()
        {
            var nextMatrix = new CellMatrix(_currentMatrix.Width, _currentMatrix.Height, _currentMatrix.OverflowPolicy);

            for (var x = 0; x < _currentMatrix.Width; ++x)
            {
                for (var y = 0; y < _currentMatrix.Height; ++y)
                {
                    var state          = _currentMatrix.GetCellLifeState(x, y);
                    var aliveNeighbors = CountAliveNeighbors(x, y);

                    switch (state)
                    {
                    case CellLifeState.Dead:
                        if (aliveNeighbors == 3)
                        {
                            nextMatrix.SetCellLifeState(x, y, CellLifeState.Alive);
                        }
                        else
                        {
                            nextMatrix.SetCellLifeState(x, y, CellLifeState.Dead);
                        }
                        break;

                    case CellLifeState.Alive:
                        if (aliveNeighbors < 2 || aliveNeighbors > 3)
                        {
                            nextMatrix.SetCellLifeState(x, y, CellLifeState.Dead);
                        }
                        else
                        {
                            nextMatrix.SetCellLifeState(x, y, CellLifeState.Alive);
                        }
                        break;
                    }
                }
            }

            _currentMatrix = nextMatrix;
        }
예제 #39
0
        public float SampleHeight(Vector3 position, CellMatrix matrix)
        {
            float plotRange;

            if (matrix != null)
            {
                position.y = matrix.origin.y + matrix.upperBoundary;
                plotRange = matrix.upperBoundary + matrix.lowerBoundary;
            }
            else
            {
                plotRange = Mathf.Infinity;
            }

            RaycastHit hit;
            if (Physics.Raycast(position, Vector3.down, out hit, plotRange, Layers.terrain))
            {
                return hit.point.y;
            }

            return Consts.InfiniteDrop;
        }
예제 #40
0
        public float GetProposedHeight(IUnitFacade unit, CellMatrix matrix, Vector3 velocityNormal)
        {
            var unitRadius = unit.radius;
            var perpOffset = new Vector3(-velocityNormal.z * unitRadius, 0f, velocityNormal.x * unitRadius);

            var center = unit.position;
            _samplePoints[0] = center - (velocityNormal * unitRadius) - perpOffset;
            _samplePoints[1] = center - (velocityNormal * unitRadius) + perpOffset;
            _samplePoints[2] = center + (velocityNormal * (unitRadius + _lookAhead)) - perpOffset;
            _samplePoints[3] = center + (velocityNormal * (unitRadius + _lookAhead)) + perpOffset;
            _samplePoints[4] = center;

            float maxClimb = unit.heightNavigationCapability.maxClimbHeight;

            float rayStart = matrix != null ? matrix.origin.y + matrix.upperBoundary : center.y + maxClimb;
            float sampledHeight = Consts.InfiniteDrop;
            float maxHeight = Consts.InfiniteDrop;

            RaycastHit hit;
            for (int i = 0; i < 5; i++)
            {
                _samplePoints[i].y = rayStart;

                if (Physics.Raycast(_samplePoints[i], Vector3.down, out hit, Mathf.Infinity, Layers.terrain))
                {
                    sampledHeight = hit.point.y;
                    if (sampledHeight > maxHeight)
                    {
                        maxHeight = sampledHeight;
                    }
                }
            }

            var diff = maxHeight - unit.basePosition.y;

            //Since sampledHeight will be the height at the center we can just use that directly here in case the max height is too high.
            return diff <= maxClimb ? maxHeight + unit.baseToPositionOffset : sampledHeight + unit.baseToPositionOffset;
        }
예제 #41
0
        public void SetMap(Burning.DofusProtocol.Data.D2P.Map map, bool useDiagonal)
        {
            currentMap   = map;
            useDiagonals = useDiagonal;
            matrix       = new CellMatrix();
            openList     = new CellList();
            find         = false;
            Burning.DofusProtocol.Data.D2P.CellData cell;
            int id   = 0;
            int loc1 = 0;
            int loc2 = 0;
            int loc3 = 0;

            for (int line = 0; line < 20; line++)
            {
                for (int column = 0; column < 14; column++)
                {
                    cell = currentMap.Cells[id];
                    bool isUsedCell = usedCells.FirstOrDefault(x => x == id) == 0 ? false : true;

                    matrix.Add(id, new Cell(cell.MapChangeData != 0, cell.Mov && !isUsedCell, true, column, loc3, id, new Point(loc1 + column, loc2 + column)));
                    id++;
                }
                loc1++;
                loc3++;
                for (int column = 0; column < 14; column++)
                {
                    cell = currentMap.Cells[id];

                    bool isUsedCell = usedCells.FirstOrDefault(x => x == id) == 0 ? false : true;
                    matrix.Add(id, new Cell(cell.MapChangeData != 0, cell.Mov && !isUsedCell, true, column, loc3, id, new Point(loc1 + column, loc2 + column)));

                    id++;
                }
                loc3++;
                loc2--;
            }
        }
예제 #42
0
        public static String SendRange(
            [Parameter("The Cell Range to send")]    CellMatrix cellMatrix)
        {
            var block = new object[cellMatrix.RowsInStructure];

            for (int i = 0; i < cellMatrix.RowsInStructure; ++i)
            {
                var row = new object[cellMatrix.ColumnsInStructure];
                for (int j = 0; j < cellMatrix.ColumnsInStructure; ++j)
                {
                    switch (cellMatrix[i, j].ValueType)
                    {
                    case CellValue.ValueTypeEnum.Boolean:
                        row[j] = cellMatrix[i, j].BooleanValue();
                        break;

                    case CellValue.ValueTypeEnum.Empty:
                        row[j] = string.Empty;
                        break;

                    case CellValue.ValueTypeEnum.Number:
                        row[j] = cellMatrix[i, j].NumericValue();
                        break;

                    case CellValue.ValueTypeEnum.String:
                        row[j] = cellMatrix[i, j].StringValue();
                        break;

                    case CellValue.ValueTypeEnum.Error:
                        row[j] = "Error : " + cellMatrix[i, j].ErrorValue();
                        break;
                    }
                }
                block[i] = row;
            }
            myHub.broadcast(block);
            return("Cool");
        }
예제 #43
0
        public float SampleHeight(Vector3 position, CellMatrix matrix)
        {
            float plotRange;

            if (matrix != null)
            {
                position.y = matrix.origin.y + matrix.upperBoundary;
                plotRange  = matrix.upperBoundary + matrix.lowerBoundary;
            }
            else
            {
                plotRange = Mathf.Infinity;
            }

            RaycastHit hit;

            if (Physics.Raycast(position, Vector3.down, out hit, plotRange, Layers.terrain))
            {
                return(hit.point.y);
            }

            return(Consts.InfiniteDrop);
        }
 public Cell Create(CellMatrix parent, Vector3 position, int matrixPosX, int matrixPosZ, bool blocked)
 {
     return new FlatCell(parent, position, matrixPosX, matrixPosZ, blocked);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FlatCell"/> class.
 /// </summary>
 /// <param name="parent">The cell matrix that owns this cell.</param>
 /// <param name="position">The position.</param>
 /// <param name="matrixPosX">The matrix position x.</param>
 /// <param name="matrixPosZ">The matrix position z.</param>
 /// <param name="blocked">if set to <c>true</c> the cell will appear permanently blocked.</param>
 public FlatCell(CellMatrix parent, Vector3 position, int matrixPosX, int matrixPosZ, bool blocked)
     : base(parent, position, matrixPosX, matrixPosZ, blocked)
 {
 }
예제 #46
0
        public static CellMatrix GetHistoricDataFromYahoo(
            [Parameter("Yahoo Symbol")] string symbol,
            [Parameter("Begin Date")]   double beginDate,
            [Parameter("End Date")]     double endDate
            )
        {
            DateTime begin = DateTime.FromOADate(beginDate);
            DateTime end = DateTime.FromOADate(endDate);

            string yahooURL =
               @"http://ichart.finance.yahoo.com/table.csv?s=" +
               symbol +
               @"&a=" +
               (begin.Month-1).ToString() +
               @"&b=" +
               begin.Day.ToString() +
               @"&c=" +
               begin.Year.ToString() +
               @"&d=" +
               (end.Month-1).ToString() +
               @"&e=" +
               end.Day.ToString() +
               @"&f=" +
               end.Year.ToString() +
               @"&g=d&ignore=.csv";

            string historicData = "";
            WebClient webConnection = new WebClient();
            try
            {
                historicData = webConnection.DownloadString(yahooURL);

            }
            catch (WebException someWebException)
            {
                throw someWebException;
            }
            finally
            {
                webConnection.Dispose();
            }

            historicData = historicData.Replace("\r", "");
            string[] rows = historicData.Split('\n');
            string[] headings = rows[0].Split(',');

            CellMatrix excelData = new CellMatrix(1,headings.Length);
            for (int i = 0; i < headings.Length; ++i)
            {
                excelData[0, i] = new CellValue(headings[i]);
            }
            for (int i = 1; i < rows.Length; ++i)
            {
                string[] thisRow = rows[i].Split(',');
                if (thisRow.Length == headings.Length)
                {
                    CellMatrix row = new CellMatrix(1, headings.Length);
                    row[0, 0] = new CellValue(DateTime.Parse(thisRow[0]).ToOADate());
                    for (int j = 1; j < headings.Length; ++j)
                    {
                        row[0, j] = new CellValue(double.Parse(thisRow[j]));
                    }
                    excelData.PushBottom(row);
                }
            }

            return excelData;
        }
예제 #47
0
        public bool TrySampleHeight(Vector3 position, CellMatrix matrix, out float height)
        {
            var heightMap = HeightMapManager.instance.GetHeightMap(position);

            return heightMap.TrySampleHeight(position, out height);
        }
예제 #48
0
        public float SampleHeight(Vector3 position, CellMatrix matrix)
        {
            var heightMap = HeightMapManager.instance.GetHeightMap(position);

            return heightMap.SampleHeight(position);
        }
 /// <summary>
 /// Prepares for initialization.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 protected override void PrepareForInitialization(CellMatrix matrix)
 {
     _heightData = new RichCell.HeightData[matrix.columns * matrix.rows * 4];
     _heightDataIndices = new int[matrix.columns * matrix.rows];
     _recordedEntries = 0;
 }
예제 #50
0
        public static CellMatrix GetHistoricDataFromYahoo(
            [Parameter("Yahoo Symbol")] string symbol,
            [Parameter("Begin Date")]   double beginDate,
            [Parameter("End Date")]     double endDate
            )
        {
            DateTime begin = DateTime.FromOADate(beginDate);
            DateTime end   = DateTime.FromOADate(endDate);

            string yahooURL =
                @"http://ichart.finance.yahoo.com/table.csv?s=" +
                symbol +
                @"&a=" +
                (begin.Month - 1).ToString() +
                @"&b=" +
                begin.Day.ToString() +
                @"&c=" +
                begin.Year.ToString() +
                @"&d=" +
                (end.Month - 1).ToString() +
                @"&e=" +
                end.Day.ToString() +
                @"&f=" +
                end.Year.ToString() +
                @"&g=d&ignore=.csv";

            string    historicData  = "";
            WebClient webConnection = new WebClient();

            try
            {
                historicData = webConnection.DownloadString(yahooURL);
            }
            catch (WebException someWebException)
            {
                throw someWebException;
            }
            finally
            {
                webConnection.Dispose();
            }

            historicData = historicData.Replace("\r", "");
            string[] rows     = historicData.Split('\n');
            string[] headings = rows[0].Split(',');

            CellMatrix excelData = new CellMatrix(1, headings.Length);

            for (int i = 0; i < headings.Length; ++i)
            {
                excelData[0, i] = new CellValue(headings[i]);
            }
            for (int i = 1; i < rows.Length; ++i)
            {
                string[] thisRow = rows[i].Split(',');
                if (thisRow.Length == headings.Length)
                {
                    CellMatrix row = new CellMatrix(1, headings.Length);
                    row[0, 0] = new CellValue(DateTime.Parse(thisRow[0]).ToOADate());
                    for (int j = 1; j < headings.Length; ++j)
                    {
                        row[0, j] = new CellValue(double.Parse(thisRow[j]));
                    }
                    excelData.PushBottom(row);
                }
            }


            return(excelData);
        }
예제 #51
0
 public CellMatrix Range(CellMatrix o)
 {
     return new CellMatrix(0);
 }
예제 #52
0
 public static void FixBrick(Brick brick)
 {
     brick.FixBrick();
     CellMatrix.CheckLine();
     Instance.SetState(State.GenerateNext);
 }
 public FlatCellHeightSettingsProvider(CellMatrix matrix)
     : base(matrix)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HeightSettingsProviderBase"/> class.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 protected HeightSettingsProviderBase(CellMatrix matrix)
 {
     _matrix = matrix;
 }
예제 #55
0
 /// <summary>
 /// Prepares for initialization.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 protected override void PrepareForInitialization(CellMatrix matrix)
 {
     /* NOOP */
 }
예제 #56
0
 /// <summary>
 /// Updates the data with the new state of the matrix.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 public void Refresh(CellMatrix matrix)
 {
     Initialize(matrix);
 }
 /// <summary>
 /// Prepares for initialization.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 protected override void PrepareForInitialization(CellMatrix matrix)
 {
     _heightBlockStatus = new NeighbourPosition[matrix.columns * matrix.rows];
 }
예제 #58
0
            public MatrixBounds Prepare(CellMatrix matrix, bool block)
            {
                _lastCoverage = _newCoverage;

                if (!block)
                {
                    _newCoverage = MatrixBounds.nullBounds;
                    return _lastCoverage;
                }

                var velocity = _parent.GetVelocity();

                var sensitivity = (matrix.cellSize / 2f) - (_parent.useGridObstacleSensitivity ? matrix.obstacleSensitivityRange : _parent.customSensitivity);

                var bounds = GrowBoundsByVelocity(_collider.bounds, velocity);

                _newCoverage = matrix.GetMatrixBounds(bounds, sensitivity, true);

                return MatrixBounds.Combine(_lastCoverage, _newCoverage);
            }
예제 #59
0
        public static bool CanReducePath(IPositioned point1, IPositioned point3, IUnitProperties unitProps, CellMatrix matrix, ICellCostStrategy costStrategy)
        {
            Vector3 p1;
            Vector3 p3;

            //Assign the points so we start with the point with the lowest x-value to simplify things
            if (point1.position.x > point3.position.x)
            {
                p1 = point3.position;
                p3 = point1.position;
            }
            else
            {
                p1 = point1.position;
                p3 = point3.position;
            }

            var requesterRadius = unitProps.radius;
            var tan = Tangents.Create(p1, p3, requesterRadius);

            var incZ = tan.slopeDir;
            var cellSize = matrix.cellSize;
            var halfCell = cellSize / 2.0f;

            //Adjust the start and end cells to possibly include their immediate neighbour if the unit's radius crossed said boundary.
            var radiusAdjust = new Vector3(requesterRadius, 0.0f, requesterRadius * incZ);

            //Get the start and end cells, get the cost of the actual start and end, and then reassign the start and end with the above adjustment.
            var startCell = matrix.GetCell(p1, true);
            var startCost = costStrategy.GetCellCost(startCell, unitProps);

            startCell = matrix.GetCell(p1 - radiusAdjust, true);

            var endCell = matrix.GetCell(p3, true);
            var endCost = costStrategy.GetCellCost(endCell, unitProps);

            endCell = matrix.GetCell(p3 + radiusAdjust, true);

            //We want x to end up on cell boundaries, the first of which is this far from the first points position
            var xAdj = p1.x + (startCell.position.x - p1.x) + halfCell;

            //We want to adjust z so that we correctly count impacted cells, this adjusts z so it starts at the bottom boundary of the first cell (for purposes of calculation)
            var zAdj = p1.z - (halfCell + ((p1.z - startCell.position.z) * incZ));

            //The movement across the x-axis
            float deltaX = 0.0f;

            var cellMatrix = matrix.rawMatrix;
            int indexX = 0;
            for (int x = startCell.matrixPosX; x <= endCell.matrixPosX; x++)
            {
                //So instead of just checking all cells in the bounding rect defined by the two cells p1 and p3,
                //we limit it to the cells immediately surrounding the proposed line (tangents), including enough cells that we ensure the unit will be able to pass through,
                //at the extreme routes between the two cells (i.e top corner to top corner and bottom corner to bottom corner
                int startZ;
                int endZ;

                //If the tangents are horizontal or vertical z range is obvious
                if (tan.isAxisAligned)
                {
                    startZ = startCell.matrixPosZ;
                    endZ = endCell.matrixPosZ + incZ;
                }
                else
                {
                    if (indexX == 0)
                    {
                        startZ = startCell.matrixPosZ;
                    }
                    else
                    {
                        var startCellsPassed = Mathf.FloorToInt((tan.LowTangent(deltaX) - zAdj) / cellSize) * incZ;

                        startZ = LimitStart(
                            startCell.matrixPosZ + startCellsPassed,
                            startCell.matrixPosZ,
                            incZ);
                    }

                    //The movement this step will perform across the x-axis
                    deltaX = xAdj + (indexX * cellSize);

                    var endCellsIntercepted = Mathf.FloorToInt((tan.HighTangent(deltaX) - zAdj) / cellSize) * incZ;

                    endZ = LimitEnd(
                        startCell.matrixPosZ + endCellsIntercepted,
                        endCell.matrixPosZ,
                        incZ) + incZ;
                }

                indexX++;

                for (int z = startZ; z != endZ; z += incZ)
                {
                    var intermediary = cellMatrix[x, z];
                    var intermediaryCost = costStrategy.GetCellCost(intermediary, unitProps);
                    if (!intermediary.isWalkableFrom(startCell, unitProps) || (startCost < intermediaryCost && endCost < intermediaryCost))
                    {
                        return false;
                    }
                }
            }

            return true;
        }