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; } }
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); } }
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)); }
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))); }
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; }
public void addExcavationMark(BlockLoc blockLoc, IslandPathingProfile profile) { if (allBlocksWithJobSites().Contains(blockLoc)) { return; } excavationSite.addBlockToDestroy(blockLoc); }
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); }
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()); } }
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); } }
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)); } }
//!! 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)); }
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); }
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 }
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); }
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))); }
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); }
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)); }
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); } }
public TreesJobSite(IslandPathingProfile nProfile) { trees = new List <Tree>(); profile = nProfile; }
public ExcavationSite(IslandPathingProfile nProfile) { blocksToBeRemoved = new HashSet <BlockLoc>(); profile = nProfile; }
public WanderAroundJob(IslandPathingProfile nPathingProfile, ActorStateProfile nActorStateProfile, Character nCharacter) { pathingProfile = nPathingProfile; actorProfile = nActorStateProfile; character = nCharacter; }
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; }
public bool isChunkSpaceSolidAt(BlockLoc loc, IslandPathingProfile profile) { return(isChunkSpaceSolidAt(loc.toISIntVec3(profile))); }
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; } } }
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)); } }
public IslandWorkingProfile(JobSiteManager nJobsiteManager, IslandPathingProfile nProfile) { jobSiteManager = nJobsiteManager; profile = nProfile; }
public virtual Job getJobWhenClicked(Character nWorker, IslandPathingProfile profile, ActorStateProfile nActorProfile) { return(new UnemployedJob()); }
public AttackActorJob(Actor nTarget, IslandPathingProfile nPathingProfile, ActorStateProfile nActorStateProfile, Character nCharacter) { target = nTarget; character = nCharacter; setJobType(JobType.combat); }
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 }