Exemple #1
0
        public LinkedList <BlockLoc> GetBlocksBoundBy(BlockLoc loc1, BlockLoc loc2)
        {
            BlockLoc min = new BlockLoc((int)Math.Min(loc1.WSX(), loc2.WSX()), (int)Math.Min(loc1.WSY(), loc2.WSY()), (int)Math.Min(loc1.WSZ(), loc2.WSZ()));
            BlockLoc max = new BlockLoc((int)Math.Max(loc1.WSX(), loc2.WSX()), (int)Math.Max(loc1.WSY(), loc2.WSY()), (int)Math.Max(loc1.WSZ(), loc2.WSZ()));

            LinkedList <BlockLoc> result = new LinkedList <BlockLoc>();

            Island relevant  = getIslandManager().getClosestIslandToLocation(loc2.toWorldSpaceVector3());
            int    spaceSize = (max.WSY() - min.WSY());

            Console.WriteLine(spaceSize + " space size");
            for (int x = min.WSX(); x <= max.WSX(); x++)
            {
                for (int y = min.WSY(); y <= max.WSY(); y++)
                {
                    for (int z = min.WSZ(); z <= max.WSZ(); z++)
                    {
                        BlockLoc toTest = new BlockLoc(x, y, z);
                        byte?    block  = islandManager.getBlockAtOnGivenIsland(ref toTest, relevant);
                        if (block.HasValue)
                        {
                            if (PaintedCubeSpace.isSolidType((byte)block))
                            {
                                result.AddLast(new BlockLoc(x, y, z));
                            }
                        }
                    }
                }
            }
            return(result);
        }
        public bool isStandableAtWithHeight(BlockLoc IslandSpace, int entityHeight)
        {
            BlockLoc underFoot = new BlockLoc(IslandSpace.WSX(), IslandSpace.WSY() - 1, IslandSpace.WSZ());//locInPath + new IntVector3(0, -1, 0);

            if (!isProfileSolidAtWithWithinCheck(IslandSpace) && isInProfileScope(IslandSpace))
            {
                if (isProfileSolidAtWithWithinCheck(underFoot))
                {
                    for (int i = 1; i < entityHeight; i++)
                    {
                        if (isProfileSolidAtWithWithinCheck(IslandSpace.getVector3WithAddedIntvec(new IntVector3(0, i, 0))))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
 public bool isSwimableAtWithHeight(BlockLoc IslandSpace, int entityHeight)
 {
     if (!isProfileSolidAtWithWithinCheck(IslandSpace))
     {
         if (IslandSpace.WSY() == 0)
         {
             for (int i = 1; i < entityHeight; i++)
             {
                 if (isProfileSolidAtWithWithinCheck(IslandSpace.getVector3WithAddedIntvec(new IntVector3(0, i, 0))))
                 {
                     return(false);
                 }
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemple #4
0
        public LinkedList <BlockLoc> getSurfaceBlocksBoundBy(BlockLoc loc1, BlockLoc loc2)
        {
            BlockLoc min = new BlockLoc((int)Math.Min(loc1.WSX(), loc2.WSX()), (int)Math.Min(loc1.WSY(), loc2.WSY()), (int)Math.Min(loc1.WSZ(), loc2.WSZ()));
            BlockLoc max = new BlockLoc((int)Math.Max(loc1.WSX(), loc2.WSX()), (int)Math.Max(loc1.WSY(), loc2.WSY()), (int)Math.Max(loc1.WSZ(), loc2.WSZ()));

            LinkedList <BlockLoc> result = new LinkedList <BlockLoc>();

            Island relevant = getIslandManager().getClosestIslandToLocation(loc2.toWorldSpaceVector3());

            BlockLoc aboveBlockLoc = new BlockLoc();
            BlockLoc blockAtLoc    = new BlockLoc();

            for (int x = min.WSX(); x <= max.WSX(); x++)
            {
                for (int y = min.WSY(); y <= max.WSY(); y++)
                {
                    for (int z = min.WSZ(); z <= max.WSZ(); z++)
                    {
                        blockAtLoc.setValuesInWorldSpace(x, y, z);
                        byte?block = islandManager.getBlockAtOnGivenIsland(ref blockAtLoc, relevant);
                        if (block.HasValue)
                        {
                            if (PaintedCubeSpace.isSolidType((byte)block))
                            {
                                aboveBlockLoc.setValuesInWorldSpace(x, y + 1, z);
                                byte?aboveBlock = islandManager.getBlockAtOnGivenIsland(ref aboveBlockLoc, relevant);
                                if (aboveBlock.HasValue)
                                {
                                    if (!PaintedCubeSpace.isOpaqueType((byte)aboveBlock))
                                    {
                                        result.AddLast(new BlockLoc(x, y, z));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        private List <BlockLoc> PathToMakeGoalsAvailable(IslandPathingProfile startProfile, ref BlockLoc startLoc, out BlockLoc highestAvailableBlockFound,
                                                         HashSet <BlockLoc> blocksToMakeAvailable, int heightOfEntity)
        {
            highestAvailableBlockFound = new BlockLoc();

            if (blocksToMakeAvailable.Count == 0)
            {
                List <BlockLoc> noPathResult = new List <BlockLoc>();
                noPathResult.Add(startLoc);
                return(noPathResult);
            }



            PathNodePriorityQueue openNodes        = new PathNodePriorityQueue();
            HashSet <BlockLoc>    visitedLocations = new HashSet <BlockLoc>();

            PathNodeForFindingLowGoals highestPathNodeFoundSoFar = null;


            openNodes.insertNode(new PathNodeForFindingHighGoals(null, startLoc, 0, blocksToMakeAvailable.First(), int.MaxValue));

            IslandPathingProfile profile = startProfile;

            while (openNodes.size() > 0)
            {
                PathNode from = openNodes.pop();

                List <BlockLoc> nextSteps = profile.getSpacesThatCanBeMovedToFrom(from.loc, heightOfEntity);

                for (int i = nextSteps.Count - 1; i >= 0; i--)
                {
                    if (visitedLocations.Contains(nextSteps[i]))
                    {
                        nextSteps.RemoveAt(i);
                    }
                }


                if (((PathNodeForFindingHighGoals)from).hasExaustedPostGoalSteps() || (((PathNodeForFindingHighGoals)from).isDescendedFromNodeAtAGoal() && nextSteps.Count == 0))
                {
                    List <BlockLoc> finalPath = getPathListFromEnd(highestPathNodeFoundSoFar);
                    finalPath.RemoveAt(0);
                    finalPath.Add(highestPathNodeFoundSoFar.loc);


                    Console.WriteLine(finalPath.Count);
                    return(finalPath);
                }

                //adding new nodes to the openNodes unmippedArray
                foreach (BlockLoc next in nextSteps)
                {
                    PathNodeForFindingHighGoals toAdd = new PathNodeForFindingHighGoals
                                                            (from, next, from.costToGetHere + 1, blocksToMakeAvailable.First(),
                                                            ((PathNodeForFindingHighGoals)from).getStepsUntilGiveUpOnFindingBetterBlock() - 1);

                    HashSet <BlockLoc> blocksAvailableFromToAdd = profile.getBlocksAvailableForWorkFromFootLoc(toAdd.loc);



                    foreach (BlockLoc available in blocksAvailableFromToAdd)
                    {
                        if (blocksToMakeAvailable.Contains(available))
                        {
                            if (highestPathNodeFoundSoFar == null || available.WSY() > highestAvailableBlockFound.WSY())
                            {
                                highestAvailableBlockFound = available;
                                toAdd.setStepCounterWhenNodeIsOnGoal();
                                highestPathNodeFoundSoFar = toAdd;
                            }
                        }
                    }

                    //toAdd.


                    toAdd.incrementPostGoalSteps();
                    //
                    // Compositer.addFlagForThisFrame(toAdd.xLowZ.toWorldSpaceVector3(), "white");
                    openNodes.insertNode(toAdd);
                    visitedLocations.Add(next);
                }
            }

            if (highestPathNodeFoundSoFar != null)
            {
                List <BlockLoc> finalPath = getPathListFromEnd(highestPathNodeFoundSoFar);
                finalPath.RemoveAt(0);
                finalPath.Add(highestPathNodeFoundSoFar.loc);


                Console.WriteLine(finalPath.Count);
                return(finalPath);
            }

            return(null);//no path found
        }
Exemple #6
0
 protected virtual int approximateDistanceTo(BlockLoc endLoc)
 {
     return(Math.Abs(loc.WSX() - endLoc.WSX()) + Math.Abs(loc.WSY() - endLoc.WSY()) + Math.Abs(loc.WSZ() - endLoc.WSZ()));
 }