Ejemplo n.º 1
0
        protected void EmitMarker(List <PropSocket> pPropSockets, string SocketType, Matrix4x4 transform, IntVector gridPosition, int cellId)
        {
            PropSocket socket = new PropSocket();

            socket.Id           = ++_SocketIdCounter;
            socket.IsConsumed   = false;
            socket.SocketType   = SocketType;
            socket.Transform    = transform;
            socket.gridPosition = gridPosition;
            socket.cellId       = cellId;
            pPropSockets.Add(socket);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Implementations should override this so that the new logical scale and position is set based on the volume's transformation
 /// </summary>
 /// <param name="volume"></param>
 /// <param name="newPositionOnGrid"></param>
 /// <param name="newSizeOnGrid"></param>
 public virtual void OnVolumePositionModified(Volume volume, out IntVector newPositionOnGrid, out IntVector newSizeOnGrid)
 {
     newPositionOnGrid = MathUtils.ToIntVector(volume.transform.position);
     newSizeOnGrid     = MathUtils.ToIntVector(volume.transform.localScale);
 }
Ejemplo n.º 3
0
        public override void EmitMarkers(DungeonBuilder builder)
        {
            if (!(builder is GridDungeonBuilder))
            {
                Debug.LogWarning("Unsupported builder type used with marker emitter MarkerEmitterFreeSpaceDecorator. Expected GridDungeonBuilder. Received:" + (builder != null ? builder.GetType().ToString() : "null"));
                return;
            }

            var model    = builder.Model as GridDungeonModel;
            var gridSize = model.Config.GridCellSize;


            var visited  = new HashSet <IntVector>();
            var occupied = new HashSet <IntVector>();

            foreach (var cell in model.Cells)
            {
                if (cell.CellType == CellType.Unknown)
                {
                    continue;
                }

                for (var distance = 2; distance <= 2; distance++)
                {
                    var bounds = cell.Bounds;
                    bounds = Rectangle.ExpandBounds(bounds, distance);
                    var points = bounds.GetBorderPoints();
                    foreach (var point in points)
                    {
                        var hash = new IntVector(point.x, 0, point.z);
                        if (!visited.Contains(hash))
                        {
                            visited.Add(hash);
                            if (occupied.Contains(hash))
                            {
                                continue;
                            }

                            // Check if this point does not lie in a cell
                            var cellInfo = model.GetGridCellLookup(point.x, point.z);
                            if (cellInfo.CellType == CellType.Unknown)
                            {
                                // Make sure the surrounding area is free so we can place a decorative item
                                bool valid = true;
                                var  s     = distanceFromEdge - 1;
                                for (var dx = -s; dx <= s; dx++)
                                {
                                    for (var dz = -s; dz <= s; dz++)
                                    {
                                        var x            = point.x + dx;
                                        var z            = point.z + dz;
                                        var neighborHash = new IntVector(x, 0, z);
                                        if (occupied.Contains(neighborHash))
                                        {
                                            valid = false;
                                            break;
                                        }
                                        var neighborCellInfo = model.GetGridCellLookup(x, z);
                                        if (neighborCellInfo.CellType != CellType.Unknown)
                                        {
                                            // Occupied by an existing cell
                                            occupied.Add(neighborHash);
                                            valid = false;
                                            break;
                                        }
                                    }
                                    if (!valid)
                                    {
                                        break;
                                    }
                                }


                                if (valid)
                                {
                                    // Valid space.  Occupy the space here
                                    for (var dx = -s; dx <= s; dx++)
                                    {
                                        for (var dz = -s; dz <= s; dz++)
                                        {
                                            var x = point.x + dx;
                                            var z = point.z + dz;
                                            occupied.Add(new IntVector(x, 0, z));
                                        }
                                    }

                                    var pushDownY = 0.0f;
                                    foreach (var pushDownAxis in pushDownTestAxis)
                                    {
                                        var delta        = pushDownAxis * distanceFromEdge;
                                        var x            = point.x + Mathf.RoundToInt(delta.x);
                                        var z            = point.z + Mathf.RoundToInt(delta.z);
                                        var testCellInfo = model.GetGridCellLookup(x, z);
                                        if (testCellInfo.CellType != CellType.Unknown)
                                        {
                                            pushDownY = pushDownAmount;
                                        }
                                    }

                                    var position = point * gridSize + new Vector3(gridSize.x, 0, gridSize.z) * 0.5f;
                                    position.y -= pushDownY;
                                    var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);

                                    builder.EmitMarker(markerName, transform, point, -1);
                                }
                            }
                            else
                            {
                                // Occupied by a cell
                                occupied.Add(hash);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        protected void EmitMarker(string SocketType, Matrix4x4 _transform, int count, Vector3 InterOffset, IntVector gridPosition, int cellId, Vector3 LogicalToWorldScale)
        {
            var iposition = new IntVector(gridPosition.x, gridPosition.y, gridPosition.z);
            var ioffset   = new IntVector(
                Mathf.RoundToInt(InterOffset.x / LogicalToWorldScale.x),
                Mathf.RoundToInt(InterOffset.y / LogicalToWorldScale.y),
                Mathf.RoundToInt(InterOffset.z / LogicalToWorldScale.z)
                );
            Matrix4x4 transform = Matrix.Copy(_transform);
            var       position  = Matrix.GetTranslation(ref transform);

            for (int i = 0; i < count; i++)
            {
                EmitMarker(SocketType, transform, iposition, cellId);
                position  += InterOffset;
                iposition += ioffset;
                transform  = Matrix.Copy(transform);
                Matrix.SetTranslation(ref transform, position);
            }
        }
Ejemplo n.º 5
0
 public static Vector3 ToV3(IntVector iv)
 {
     return(new Vector3(iv.x, iv.y, iv.z));
 }
Ejemplo n.º 6
0
 public IntVector2Key(IntVector a, IntVector b)
 {
     this.a = a;
     this.b = b;
 }
Ejemplo n.º 7
0
 public Rectangle(IntVector location, IntVector size)
 {
     this.location = location;
     this.size     = size;
 }
Ejemplo n.º 8
0
 public Rectangle(int x, int z, int width, int length)
 {
     location = new IntVector(x, 0, z);
     size     = new IntVector(width, 0, length);
 }
Ejemplo n.º 9
0
 public bool Contains(IntVector Point)
 {
     return(Contains(Point.x, Point.z));
 }