Example #1
0
        internal void addPlayerDraggedJobsiteWithBlocks(List <BlockLoc> blocksToAdd, IslandPathingProfile profile,
                                                        PlayerAction.Dragging.DragType dragType)
        {
            /// blocksToAdd = alreadyOccupied;

            switch (dragType)
            {
            case PlayerAction.Dragging.DragType.farm:
                placeFarmWithBlocks(blocksToAdd, profile);
                break;

            case PlayerAction.Dragging.DragType.storeWheat:
                placeStorageAreaWithBlocksToPlaceOn(blocksToAdd, profile, ResourceBlock.ResourceType.Wheat);
                break;

            case PlayerAction.Dragging.DragType.storeWood:
                placeStorageAreaWithBlocksToPlaceOn(blocksToAdd, profile, ResourceBlock.ResourceType.Wood);
                break;

            case PlayerAction.Dragging.DragType.storeStone:
                placeStorageAreaWithBlocksToPlaceOn(blocksToAdd, profile, ResourceBlock.ResourceType.standardBlock);
                break;

            case PlayerAction.Dragging.DragType.excavate:
                foreach (BlockLoc test in blocksToAdd)
                {
                    addExcavationMark(test, workingProfile.getPathingProfile());
                }
                break;
            }
        }
Example #2
0
        private void handleAddVelocityAction(Vector3 velocityAddition, Actor actor, bool isFootPropelled)
        {
            Island closestIsland = islandManager.getClosestIslandToLocation(actor.getLocation());

            if (closestIsland == null)// if no islands are loaded
            {
                actor.setVelocity(new Vector3());
            }
            else
            {
                List <BlockLoc>      intersectedByActor = actor.getBlocksIntersectedByAABB();
                IslandPathingProfile profile            = closestIsland.getPathingProfile();
                if (!profile.isActorStanding(actor) && actor.canBeKnockedBack() && isFootPropelled && !Ocean.pointIsUnderWater(actor.getFootLocation()))
                {
                    actor.addToVelocity(velocityAddition * .02f);//character propells slowly in midair
                    return;
                }
                foreach (BlockLoc test in intersectedByActor)
                {
                    if (profile.isProfileSolidAtWithWithinCheck(test))
                    {
                        actor.setFootLocation(actor.getFootLocation() + new Vector3(0, .3f, 0));
                        return;
                    }
                }
                actor.addToVelocity(velocityAddition);
            }
        }
Example #3
0
        public virtual Path getPathToMakeTheseBlocksAvaiable(
            IslandPathingProfile startProfile,
            BlockLoc startLoc,
            IslandPathingProfile endProfile,
            List <BlockLoc> blockLocs,
            int heightOfEntity,
            out BlockLoc blockMadeAvailable)
        {
            blockMadeAvailable = new BlockLoc();
            HashSet <BlockLoc> goals = new HashSet <BlockLoc>();

            foreach (BlockLoc blockLocToAccess in blockLocs)
            {
                HashSet <BlockLoc> toAdd = endProfile.getFootLocsThatHaveAccessToBlock(blockLocToAccess);
                foreach (BlockLoc addToGoals in toAdd)
                {
                    goals.Add(addToGoals);
                }
            }

            List <BlockLoc> path = getPathWithStartAndEndGroupValidation(startProfile, startLoc, endProfile, goals, heightOfEntity);

            foreach (BlockLoc blockToAcces in blockLocs)
            {
                if (path != null)
                {
                    if (endProfile.getFootLocsThatHaveAccessToBlock(blockToAcces).Contains(path.Last()))
                    {
                        blockMadeAvailable = blockToAcces;
                    }
                }
            }

            return(new Path(path));
        }
Example #4
0
        public Path getPathToSingleBlock(IslandPathingProfile startProfile, BlockLoc startLoc,
                                         IslandPathingProfile endProfile, BlockLoc endLoc, int heightOfEntity)
        {
            HashSet <BlockLoc> goals = new HashSet <BlockLoc>();

            goals.Add(endLoc);
            return(new Path(getPathWithStartAndEndGroupValidation(startProfile, startLoc, endProfile, goals, heightOfEntity)));
        }
Example #5
0
 public Farm(IslandPathingProfile nProfile, IEnumerable <BlockLoc> nBlocksToBeFarmedOnTopOf)
 {
     plantBlocks = new Dictionary <BlockLoc, FarmPlantBlock>();
     foreach (BlockLoc test in nBlocksToBeFarmedOnTopOf)
     {
         plantBlocks.Add(test.getVector3WithAddedIntvec(new IntVector3(0, 1, 0)), new FarmPlantBlock());
     }
     profile = nProfile;
 }
Example #6
0
        public void addExcavationMark(BlockLoc blockLoc, IslandPathingProfile profile)
        {
            if (allBlocksWithJobSites().Contains(blockLoc))
            {
                return;
            }


            excavationSite.addBlockToDestroy(blockLoc);
        }
Example #7
0
        public void addCharacterAt(Vector3 location, Actor.Faction faction, IslandPathingProfile islandPathingProfile, ActorStateProfile actorStateProfile)
        {
            Character character = new Character(new AxisAlignedBoundingBox(location + new Vector3(), .6f, .6f, 1.8f), faction);

            if (faction == Actor.Faction.enemy)
            {
                character.setJobAndCheckUseability(new AggressiveStanceJob(character));
            }
            actors.Add(character);
        }
Example #8
0
 public override Job getJobWhenClicked(Character nWorker, IslandPathingProfile pathingProfile, ActorStateProfile actorState)
 {
     if (areHostile(nWorker.getFaction(), getFaction()))
     {
         return(new AttackActorJob(this, pathingProfile, actorState, nWorker));
     }
     else
     {
         return(new UnemployedJob());
     }
 }
Example #9
0
 internal byte?getBlockAt(ref BlockLoc loc, IslandPathingProfile profile)
 {
     if (withinChunkSpaceInChunkSpace(loc.ISX(profile), loc.ISY(profile), loc.ISZ(profile)))
     {
         return(getChunkSpaceBlockAtWithoutWithinCheck(loc.ISX(profile), loc.ISY(profile), loc.ISZ(profile)));
     }
     else
     {
         return(null);
     }
 }
Example #10
0
        private void placeFarmWithBlocks(IEnumerable <BlockLoc> blocksToAdd, IslandPathingProfile profile)
        {
            HashSet <BlockLoc> locs = new HashSet <BlockLoc>();

            removeAllBlocksAtOrBelowWorkBlock(blocksToAdd, locs);

            if (locs.Count > 0)
            {
                jobSites.Add(new Farm(profile, locs));
            }
        }
Example #11
0
        //!! all path locations are at foot level NOT head level


        protected List <BlockLoc> getPathWithStartAndEndGroupValidation(IslandPathingProfile startProfile, BlockLoc startLoc, IslandPathingProfile endProfile, HashSet <BlockLoc> goals, int heightOfEntity)
        {
            goals = removeUnstandableAndUnswimmableItemsInSet(endProfile, goals, heightOfEntity);
            if (goals.Count == 0)
            {
                return(null);
            }



            return(Path(startProfile, ref startLoc, goals, heightOfEntity));
        }
Example #12
0
        public override Job getJobWhenClicked(Character nWorker, IslandPathingProfile profile, ActorStateProfile actorState)
        {
            IslandGame.GameWorld.CharactersAndAI.CompleteTaskJob getInBoat = new
                                                                             IslandGame.GameWorld.CharactersAndAI.CompleteTaskJob(nWorker, new CharacterTask.GetInBoat(this));

            Path path = new PathHandler().
                        getPathToSingleBlock(profile, new BlockLoc(nWorker.getFootLocation()), profile, new BlockLoc(getFootLocation()), 2);

            TravelAlongPath travel = new TravelAlongPath(path, getInBoat);

            return(travel);
        }
Example #13
0
        protected virtual List <BlockLoc> Path(IslandPathingProfile startProfile, ref BlockLoc startLoc,
                                               HashSet <BlockLoc> goals, int heightOfEntity)
        {
            foreach (BlockLoc goal in goals)
            {
                if (startLoc.Equals(goal))
                {
                    List <BlockLoc> noPathResult = new List <BlockLoc>();
                    noPathResult.Add(startLoc);
                    return(noPathResult);
                }
            }



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

            openNodes.insertNode(new PathNode(null, startLoc, 0, goals.First()));

            IslandPathingProfile profile = startProfile;

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

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

                //adding new nodes to the openNodes unmippedArray
                foreach (BlockLoc next in nextSteps)
                {
                    if (!visitedLocations.Contains(next))
                    {
                        PathNode toAdd = new PathNode(from, next, from.costToGetHere + 1, goals.First());

                        if (goals.Contains(toAdd.loc))
                        {
                            List <BlockLoc> finalPath = getPathListFromEnd(toAdd);
                            finalPath.RemoveAt(0);
                            finalPath.Add(toAdd.loc);


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

                        openNodes.insertNode(toAdd);
                        visitedLocations.Add(next);
                    }
                }
            }
            return(null);//no path found
        }
Example #14
0
        public bool vehiclePlacedHereCouldBeBoarded(BlockLoc vehicleLoc)
        {
            IslandPathingProfile profile = getPathingProfile();

            if (profile.getFootLocsThatHaveAccessToBlock(vehicleLoc).Count != 0)
            {
                if (profile.getStandableFootLocsThatHaveAccessToBlock(vehicleLoc, 2).Count != 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #15
0
        public Path getPathToBlockEnumerable(IslandPathingProfile startProfile, BlockLoc startLoc,
                                             IslandPathingProfile endProfile, IEnumerable <BlockLoc> goalsEnum, int heightOfEntity)
        {
            HashSet <BlockLoc> goals = new HashSet <BlockLoc>();

            foreach (BlockLoc toAdd in goalsEnum)
            {
                goals.Add(toAdd);
            }
            if (goals.Count == 0)
            {
                return(new Path());
            }
            return(new Path(getPathWithStartAndEndGroupValidation(startProfile, startLoc, endProfile, goals, heightOfEntity)));
        }
Example #16
0
        protected HashSet <BlockLoc> removeUnstandableAndUnswimmableItemsInSet(IslandPathingProfile profile, HashSet <BlockLoc> locs, int entityHeight)
        {
            HashSet <BlockLoc> toRemove = new HashSet <BlockLoc>();

            foreach (BlockLoc test in locs)
            {
                if (!profile.isStandableAtWithHeight(test, 2) && !profile.isSwimableAtWithHeight(test, 2))
                {
                    toRemove.Add(test);
                }
            }

            foreach (BlockLoc itemToRemove in toRemove)
            {
                locs.Remove(itemToRemove);
            }

            return(locs);
        }
Example #17
0
        public override Path getPathToMakeTheseBlocksAvaiable(
            IslandPathingProfile startProfile,
            BlockLoc startLoc,
            IslandPathingProfile endProfile,
            List <BlockLoc> blockLocs,
            int heightOfEntity,
            out BlockLoc blockMadeAvailable)
        {
            blockMadeAvailable = new BlockLoc();
            HashSet <BlockLoc> blocksToMakeAvailable = new HashSet <BlockLoc>();

            foreach (BlockLoc blockLocToAccess in blockLocs)
            {
                blocksToMakeAvailable.Add(blockLocToAccess);
            }

            List <BlockLoc> path = PathToMakeGoalsAvailable(startProfile, ref startLoc, out blockMadeAvailable, blocksToMakeAvailable, heightOfEntity);


            return(new Path(path));
        }
Example #18
0
        private void giveCharacterTravelJob(Character character, Ray rightClickRay)
        {
            Vector3?clicked = getIslandManager().getClosestIslandToLocation(character.getLocation()).getLastSpaceAlongRayConsideringResourceBlocks(rightClickRay);

            if (clicked.HasValue)
            {
                IntVector3           clickedBlock = new IntVector3((Vector3)clicked);
                IslandPathingProfile profile      = getIslandManager().getClosestIslandToLocation(character.getLocation()).getPathingProfile();

                PathHandler pathHandler = new PathHandler();

                Path path = pathHandler.getPathToSingleBlock(profile,
                                                             new BlockLoc(character.getFootLocation()), profile, new BlockLoc(clickedBlock.toVector3()), 2);

                TravelAlongPath walkTask = new TravelAlongPath(path);
                if (walkTask.isUseable())
                {
                    character.setJobAndCheckUseability(walkTask);
                }
                return;
            }

            Vector3?oceanClick = islandManager.getOceanIntersectionAtY1(rightClickRay);

            if (oceanClick.HasValue)
            {
                //List<BlockLoc> path = islandManager.getOceanPath((Vector3)oceanClick, character.getLocation());
                PathHandler pathHandler = new PathHandler();
                BlockLoc    goal        = new BlockLoc((Vector3)oceanClick);
                goal.setValuesInWorldSpace(goal.WSX(), 0, goal.WSZ());
                BlockLoc start = new BlockLoc(character.getLocation());
                start.setValuesInWorldSpace(start.WSX(), 0, start.WSZ());
                Path path = pathHandler.getPathToSingleBlock(getPathingProfile(),
                                                             start, getPathingProfile(), goal, 2);

                character.pathAlongOceanWithOceanPath(path);
            }
        }
Example #19
0
 public TreesJobSite(IslandPathingProfile nProfile)
 {
     trees   = new List <Tree>();
     profile = nProfile;
 }
Example #20
0
 public ExcavationSite(IslandPathingProfile nProfile)
 {
     blocksToBeRemoved = new HashSet <BlockLoc>();
     profile           = nProfile;
 }
Example #21
0
 public WanderAroundJob(IslandPathingProfile nPathingProfile, ActorStateProfile nActorStateProfile, Character nCharacter)
 {
     pathingProfile = nPathingProfile;
     actorProfile   = nActorStateProfile;
     character      = nCharacter;
 }
Example #22
0
        internal void placeWoodBlockPlanAlongRay(Ray placeWoodBlockClickRay, Vector3?exactSpaceHitLocOnIsland, IslandPathingProfile profile, byte typeToAdd)
        {
            placeWoodBlockClickRay.Direction.Normalize();

            Vector3?bestBlockToPlaceOnBuildSite = getLastSpaceAlongRayConsideringBuildSite(placeWoodBlockClickRay, exactSpaceHitLocOnIsland);

            if (bestBlockToPlaceOnBuildSite.HasValue)
            {
                addBlockToBuildSite(buildSite, new BlockLoc((Vector3)bestBlockToPlaceOnBuildSite), typeToAdd);
                return;
            }
        }
 public ResourceBlockJobSite(IslandPathingProfile nprofile)
 {
     resourceBlocks = new Dictionary <BlockLoc, ResourceBlock>();
     stockpiles     = new List <Stockpile>();
     profile        = nprofile;
 }
Example #24
0
 public bool isChunkSpaceSolidAt(BlockLoc loc, IslandPathingProfile profile)
 {
     return(isChunkSpaceSolidAt(loc.toISIntVec3(profile)));
 }
Example #25
0
        public void removeWoodBlockPlanAlongRay(Ray removeWoodBlockClickRay, Vector3?exactBlockHitLocOnIsland, IslandPathingProfile profile)
        {
            float?intersectsJobSite = buildSite.intersects(removeWoodBlockClickRay);

            if (intersectsJobSite.HasValue)
            {
                Vector3 locationOfSelectedSpaceOnJobSite = removeWoodBlockClickRay.Position + removeWoodBlockClickRay.Direction * ((float)intersectsJobSite);

                if (exactBlockHitLocOnIsland.HasValue)
                {
                    if (Vector3.Distance((Vector3)exactBlockHitLocOnIsland, removeWoodBlockClickRay.Position) >
                        Vector3.Distance(locationOfSelectedSpaceOnJobSite, removeWoodBlockClickRay.Position))
                    {
                        BlockLoc blockToRemove = new BlockLoc(locationOfSelectedSpaceOnJobSite + removeWoodBlockClickRay.Direction * .01f);
                        buildSite.removeBlock(blockToRemove);
                        return;
                    }
                }
                else
                {
                    BlockLoc blockToRemove = new BlockLoc(removeWoodBlockClickRay.Position + removeWoodBlockClickRay.Direction * ((float)intersectsJobSite));
                    buildSite.removeBlock(blockToRemove);
                    return;
                }
            }
        }
Example #26
0
        private void placeStorageAreaWithBlocksToPlaceOn(IEnumerable <BlockLoc> blocksToPlaceSiteOn, IslandPathingProfile profile,
                                                         ResourceBlock.ResourceType toStore)
        {
            List <BlockLoc>    blocksForSite   = new List <BlockLoc>();
            HashSet <BlockLoc> alreadyOccupied = allBlocksWithJobSites();

            foreach (BlockLoc inGround in blocksToPlaceSiteOn)
            {
                if (!alreadyOccupied.Contains(BlockLoc.AddIntVec3(inGround, new IntVector3(0, 1, 0))))
                {
                    blocksForSite.Add(BlockLoc.AddIntVec3(inGround, new IntVector3(0, 1, 0)));
                }

                if (!alreadyOccupied.Contains(BlockLoc.AddIntVec3(inGround, new IntVector3(0, 2, 0))))
                {
                    blocksForSite.Add(BlockLoc.AddIntVec3(inGround, new IntVector3(0, 2, 0)));
                }
            }

            HashSet <BlockLoc> locsNotOfWork = new HashSet <BlockLoc>();

            removeAllBlocksAtOrBelowWorkBlock(blocksForSite, locsNotOfWork);
            if (locsNotOfWork.Count > 0)
            {
                HashSet <BlockLoc> locsNotSolid = new HashSet <BlockLoc>();
                foreach (BlockLoc test in locsNotOfWork)
                {
                    if (!profile.isProfileSolidAtWithWithinCheck(test))
                    {
                        locsNotSolid.Add(test);
                    }
                }
                resourceBlockJobsite.addStockpile(new Stockpile(locsNotSolid, toStore));
            }
        }
Example #27
0
 public IslandWorkingProfile(JobSiteManager nJobsiteManager, IslandPathingProfile nProfile)
 {
     jobSiteManager = nJobsiteManager;
     profile        = nProfile;
 }
Example #28
0
 public virtual Job getJobWhenClicked(Character nWorker, IslandPathingProfile profile, ActorStateProfile nActorProfile)
 {
     return(new UnemployedJob());
 }
Example #29
0
 public AttackActorJob(Actor nTarget, IslandPathingProfile nPathingProfile, ActorStateProfile nActorStateProfile, Character nCharacter)
 {
     target    = nTarget;
     character = nCharacter;
     setJobType(JobType.combat);
 }
Example #30
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
        }