Exemple #1
0
        //based on the input blocking type, returns a layer mask used in collision detection.
        public static LayerMask GetMaskFromBlockingType(BlockingType bType, bool includeActors = true)
        {
            int mask;

            switch (bType)
            {
            case BlockingType.walking:
                mask = Physics2D.GetLayerCollisionMask(LayerMask.NameToLayer("Walking"));
                if (includeActors == false)
                {
                    mask = mask & ~GetActorMask();
                }
                break;

            case BlockingType.flying:
                mask = Physics2D.GetLayerCollisionMask(LayerMask.NameToLayer("Flying"));
                if (includeActors == false)
                {
                    mask = mask & ~GetActorMask();
                }
                break;

            default:
            case BlockingType.ghost:
                mask = LayerMask.GetMask("Nothing");
                break;
            }
            return(mask);
        }
Exemple #2
0
        //returns a ContactFilter from a blocking type. For convenience.
        public static ContactFilter2D GetFilterFromBlockingType(BlockingType bType, bool includeActors = true)
        {
            ContactFilter2D cFilter = new ContactFilter2D();

            cFilter.layerMask    = GetMaskFromBlockingType(bType, includeActors);
            cFilter.useLayerMask = true;
            return(cFilter);
        }
Exemple #3
0
 public void OpenWindow(BlockingType type)
 {
     windowOpen = true;
     if (type == BlockingType.UI)
     {
         blockUIPanel.SetActive(true);
     }
     else if (type == BlockingType.Scene)
     {
         blockScenePanel.SetActive(true);
     }
 }
Exemple #4
0
 //this is pretty bad, but fortunately it only occurs when (re)generating PathMaps (ie rarely)
 public TilemapList this[BlockingType bType] {
     get{
         //gives precedent to the first list found of the specified blocking type. ideally there shouldn't be duplicates, anyways
         for (int t = 0; t < lists.Length; t++)
         {
             if (lists[t].blockingType == bType)
             {
                 return(lists[t]);
             }
         }
         //not found. Whine and return garbage.
         Debug.Log(System.String.Format("Warning: TilemapList for BlockingType '{0}' not found in Navigator TilemapMatrix.", bType));
         return(new TilemapList());
     }
 }
Exemple #5
0
        /*
         * ==== DESCRIPTION ====
         *
         * A Navigator instance is used by any object that wishes to use pathfinding.
         * The Navigator acts as a mediator between Tilemaps in a scene and pathfinding algorithms,
         * and makes extensive use of algorithms in the static MapConverter class to perform conversions.
         *
         * The Navigator is used by calling "GetWorldPath".
         * This provides a suggested path, each entry being a NodeGrid node's world coordinates.
         * Objects trying to navigate should pass in their current location and their destination,
         * then attempt to *directly* move to each node in turn (likely moving on to the next node
         * once arriving within a certain distance of the current node).
         * Calls should be made roughly every time an object's target destination changes.
         * This may be very often if chasing a moving object, so effort should be made to limit calls.
         *
         * The Navigator is handy because its inputs and outputs are world coordinates, so objects
         * have an easy time communicating with it.
         *
         * The Navigator also generates and stores all important pathfinding data (PathMaps and their contents),
         * so that each object/actor using pathfinding does not need its own copy, which saves memory.
         *
         */


        /// <summary>
        /// Get a world location to walk towards, in order to reach the desired destination.
        /// </summary>
        /// <param name="pointA">Entity's current world location.</param></param>
        /// <param name="PointB">World location of final destination.</param>
        public Vector3[] GetWorldPath(BlockingType bType, Vector3 pointA, Vector3 pointB)
        {
            PathMap      pMap      = pathMapDict[bType];
            Vector3Int   pA_vec    = MapConverter.WorldToNode(pMap, pointA);
            Vector3Int   pB_vec    = MapConverter.WorldToNode(pMap, pointB);
            Point        pA        = new Point(pA_vec.x, pA_vec.y);
            Point        pB        = new Point(pB_vec.x, pB_vec.y);
            List <Point> pointList = Pathfinder.FindPath(pMap.nodeGrid, pA, pB);

            Vector3[] coordsList = new Vector3[pointList.Count];
            int       i          = 0;

            pointList.ForEach(delegate(Point p){
                coordsList[i++] = MapConverter.NodeToWorld(pMap, p.x, p.y);
            });
            return(coordsList);
        }
    public BuildQuality GetBuildQuality(MapPoint pt, bool flagOnly = false)
    {
        // Cannot build on blocking objects
        if (world.GetObject(pt)?.blockingType != BlockingType.none)
        {
            return(BuildQuality.nothing);
        }

        BuildQuality curBQ = BuildQuality.flag;
        //////////////////////////////////////////////////////////////////////////
        // 3. Check neighbouring objects that make building impossible

        // Blocking manners of neighbours (cache for reuse)
        List <BlockingType> neighborBlocks = new List <BlockingType>();

        foreach (Direction dir in Directions.allDirections)
        {
            neighborBlocks.Add(world.GetObject(world.GetNeighbor(pt, dir))?.blockingType ?? BlockingType.none);
        }


        if (neighborBlocks.Contains(BlockingType.nothingAround))
        {
            return(BuildQuality.nothing);
        }

        if (flagOnly)
        {
            if (neighborBlocks.Contains(BlockingType.flag))
            {
                return(BuildQuality.nothing);
            }

            return(BuildQuality.flag);
        }

        // Build nothing if we have a flag EAST or SW
        if (neighborBlocks[(int)Direction.east] == BlockingType.flag || neighborBlocks[(int)Direction.southwest] == BlockingType.flag)
        {
            return(BuildQuality.nothing);
        }

        //////////////////////////////////////////////////////////////////////////
        // 4. Potentially reduce BQ if some objects are nearby

        // Trees allow only huts and mines around
        if ((int)curBQ > (int)BuildQuality.hut && curBQ != BuildQuality.mine)
        {
            if (neighborBlocks.Contains(BlockingType.tree))
            {
                curBQ = BuildQuality.hut;
            }
        }

        // Granite type block (stones, fire, grain fields) -> Flag around
        if (neighborBlocks.Contains(BlockingType.flagsAround))
        {
            curBQ = BuildQuality.flag;
        }

        // Castle-sized buildings have extensions -> Need non-blocking object there so it can be removed
        // Note: S2 allowed blocking environment objects here which leads to visual bugs and problems as we can't place the extensions
        if (curBQ == BuildQuality.castle)
        {
            if (neighborBlocks[0] != BlockingType.none || neighborBlocks[1] != BlockingType.none || neighborBlocks[2] != BlockingType.none)
            {
                curBQ = BuildQuality.house;
            }
        }


        // Check for buildings in a range of 2 -> House only
        // Note: This is inconsistent (as in the original) as it allows building a castle then a house, but not the other way round
        // --> Remove this check? Only possible reason why castles could not be build should be the extensions
        if (curBQ == BuildQuality.castle)
        {
            for (int i = 0; i < 12; i++)
            {
                BlockingType surroundingType = (world.GetObject(world.GetSecondNeighbor(pt, i)))?.blockingType ?? BlockingType.none;
                if (surroundingType == BlockingType.building)
                {
                    curBQ = BuildQuality.house;
                    break;
                }
            }
        }

        // Road at attachment -> No castle
        if (curBQ == BuildQuality.castle)
        {
            if (world.IsOnRoad(world.GetNeighbor(pt, Direction.west)) ||
                world.IsOnRoad(world.GetNeighbor(pt, Direction.northeast)) ||
                world.IsOnRoad(world.GetNeighbor(pt, Direction.northwest)))
            {
                curBQ = BuildQuality.house;
            }
        }

        // If point is on a road -> Flag only
        if (curBQ != BuildQuality.flag && world.IsOnRoad(pt))
        {
            curBQ = BuildQuality.flag;
        }

        if (curBQ == BuildQuality.flag)
        {
            // If any neighbour is a flag -> Flag is impossible
            if (neighborBlocks.Contains(BlockingType.flag))
            {
                return(BuildQuality.nothing);
            }
            return(BuildQuality.flag);
        }

        //        // If we can build a castle and this is a harbor point -> Allow harbor
        //        if(curBQ == BQ_CASTLE && world.GetNode(pt).harborId) {
        //            curBQ = BQ_HARBOR;
        //        }

        //////////////////////////////////////////////////////////////////////////
        ///At this point we can still build a building/mine

        // If there is a flag where the house flag would be -> OK
        if (neighborBlocks[4] == BlockingType.flag)
        {
            return(curBQ);
        }

        // If we can build the house flag -> OK
        if (GetBuildQuality(world.GetNeighbor(pt, Direction.southeast), true) != BuildQuality.nothing)
        {
            return(curBQ);
        }

        // If not, we could still build a flag, unless there is another one around
        if (neighborBlocks.GetRange(0, 3).Contains(BlockingType.flag))
        {
            return(BuildQuality.nothing);
        }

        return(curBQ);
    }
Exemple #7
0
 static void addCustom(Color c, BlockingType blocking, uint texture, VertexAwesome[] mesh, string name, string description)
 {
     add(new BlockType
     {
         Schematic = c,
         Name = name,
         Description = description,
         IsCube = false,
         IsEmpty = false,
         IsSolid = false,
         Removable = true,
         Blocking = blocking,
         Texture = texture,
         Mesh = mesh
     });
 }
Exemple #8
0
 static void addCube(Color c, CubeType type, bool removable, BlockingType blocking, uint texture, string name, string description, VertexAwesome[] mesh)
 {
     add(new BlockType
     {
         Schematic = c,
         Name = name,
         Description = description,
         IsCube = true,
         IsEmpty = type == CubeType.Empty,
         IsSolid = type == CubeType.Solid,
         Removable = removable,
         Blocking = blocking,
         Texture = texture,
         //Mesh = mesh
     });
 }
Exemple #9
0
 static void addCube(Color c, CubeType type, bool removable, BlockingType blocking, uint texture, string name, string description)
 {
     addCube(c, type, removable, blocking, texture, name, description, null);
 }
Exemple #10
0
        /*
         * ==== INITIALIZATION ====
         *
         * A Navigator must generate nodes and grids based on the tilemaps in a scene.
         *
         */

        //regenerates pathMap, accounting for changes in blocking tilemaps.
        //probably unnecessary
        public void RefreshPathMap(BlockingType t)
        {
            pathMapDict[t] = MapConverter.TilemapArrToPathMap(tilemapMatrix[t].tileMaps, background.cellBounds);
        }
Exemple #11
0
 public void addCubeTest()
 {
     BlockTypes_Accessor.CubeType type = null; // TODO: Passenden Wert initialisieren
     bool removable = false; // TODO: Passenden Wert initialisieren
     BlockingType blocking = new BlockingType(); // TODO: Passenden Wert initialisieren
     uint texture = 0; // TODO: Passenden Wert initialisieren
     string name = string.Empty; // TODO: Passenden Wert initialisieren
     string description = string.Empty; // TODO: Passenden Wert initialisieren
     BlockTypes_Accessor.addCube(type, removable, blocking, texture, name, description);
     Assert.Inconclusive("Eine Methode, die keinen Wert zurückgibt, kann nicht überprüft werden.");
 }
Exemple #12
0
 public void addCustomTest()
 {
     BlockingType blocking = new BlockingType(); // TODO: Passenden Wert initialisieren
     uint texture = 0; // TODO: Passenden Wert initialisieren
     VertexAwesome[] mesh = null; // TODO: Passenden Wert initialisieren
     string name = string.Empty; // TODO: Passenden Wert initialisieren
     string description = string.Empty; // TODO: Passenden Wert initialisieren
     BlockTypes_Accessor.addCustom(blocking, texture, mesh, name, description);
     Assert.Inconclusive("Eine Methode, die keinen Wert zurückgibt, kann nicht überprüft werden.");
 }
Exemple #13
0
 static void addCustom(Color c, BlockingType blocking, uint texture, VertexAwesome[] mesh, string name, string description)
 {
     addCustom(c, blocking, texture, mesh, name, description, Color.Black);
 }
Exemple #14
0
 static void addCube(Color c, CubeType type, bool removable, BlockingType blocking, uint texture, string name, string description, VertexAwesome[] mesh)
 {
     addCube(c, type, removable, blocking, texture, name, description, mesh, Color.Black);
 }