public AIPath(Pathfinder.PathDeliverAdress pda,Vector3 from, Vector3 to) { waypoints = new List<Vector3>(); origin = from; target = to; deliveryAdress = pda; }
public MoveUnitEvent(EventID eventID, object sender, EventArgs<Actors.Cursor, Pathfinder, float> e) : base(eventID, sender, e) { this.cursor = e.Value; this.pathfinder = e.Value2; this.moveSpeed = e.Value3; }
public override void Generate() { pathfinderObject = new GameObject(GraphName); pathfinderObject.transform.parent = GraphContainer; pathfinderObject.transform.position = GraphPosition; pathfinderObject.tag = GraphTag; pathfinder = pathfinderObject.AddComponent<Pathfinder>(); pathfinder.ColorTraversable = ColorTraversable; pathfinder.ColorOutOfReach = ColorOutOfReach; pathfinder.ColorNeutral = ColorNeutral; pathfindingNodes = new PathfindingNode[GraphWidth, GraphHeight]; for (int y = 0; y < GraphHeight; y++) { for (int x = 0; x < GraphWidth; x++) { pathfinderNodeObject = GameObject.Instantiate(NodePrefab) as GameObject; pathfindingNode = pathfinderNodeObject.GetComponent<PathfindingNode>(); pathfindingNode.SetColor(pathfinder.ColorNeutral); pathfinderNodeObject.name = "(" + x + ", " + y + ") " + NodePrefab.name; pathfinderNodeObject.transform.parent = pathfinderObject.transform; pathfinderNodeObject.transform.position = new Vector3(x, y, 0); pathfindingNodes[x, y] = pathfindingNode; } } pathfinder.SetNodes(pathfindingNodes); }
public TerrainTile(int x, int y, Terrain terrain, Pathfinder pathfinder) { // MapChunks = new TerrainChunk[TerrainConstants.ChunksPerTileSide, TerrainConstants.ChunksPerTileSide]; TileX = x; TileY = y; Terrain = terrain; Pathfinder = pathfinder; }
//This submits a request for a path to the pathfinder thread. This is the main point of entry for usage. - DarkLotus public PathRequestTask GetPath(Actor owner, Vector3D vector3D, Vector3D heading) { if (aipather == null) aipather = new Pathfinder(); var pathRequestTask = new PathRequestTask(aipather, owner, owner.Position, heading); _queuedPathTasks.TryAdd(owner.DynamicID, pathRequestTask); return pathRequestTask; }
public int SolutionPart2(params string[] input) { var segments = new List<Segment>(); foreach (var line in input) segments.Add(new Segment(line)); var p = new Pathfinder(segments); return p.GetLongestPath().Distance; }
public Map(int Width, int Height) { Tiles = new Tile[Width, Height]; for (int x = 0; x < Width; x++) for (int y = 0; y < Height; y++) Tiles[x, y].Back = 2; Camera = new Camera(); Pathfinder = new Pathfinder(Width, Height); Waypoints = new List<Point>[3]; for (int i = 0; i < Waypoints.Length; i++) Waypoints[i] = new List<Point>(); Spawns = new List<Point>[3]; for (int i = 0; i < Spawns.Length; i++) Spawns[i] = new List<Point>(); Bullets = new List<Line>(); }
public static void HandleGameMapMovementRequestMessage(Bot bot, GameMapMovementRequestMessage message) { bot.SendToClient(new DebugClearHighlightCellsMessage()); var clientPath = Path.BuildFromClientCompressedPath(bot.Character.Map, message.keyMovements); var pathfinder = new Pathfinder(bot.Character.Map.CellInformationProvider, bot.Character.Map); var botPath = pathfinder.FindPath(bot.Character.Position.Cell, clientPath.End, true); // if you see red cells it means the pathfinder is wrong and don't get the same path as the client bot.SendToClient(new DebugHighlightCellsMessage(Color.Red.ToArgb(), botPath.Cells.Select(entry => entry.Id).ToArray())); bot.SendToClient(new DebugHighlightCellsMessage(Color.Blue.ToArgb(), clientPath.Cells.Select(entry => entry.Id).ToArray())); }
public IEnumerable<Order> PlanPathTo(Point to) { var from = Position.ToSquare(); var pf = new Pathfinder(m, ContentMask); var path = pf.FindPath(from, to).ToList(); for (int i = path.Count - 1; i >= 0; i--) { var walkTo = path[i].SquareToCenter(); yield return Orders.Face(MakeDirection(from, path[i], 0), 1); yield return Orders.Walk(walkTo, 6); from = path[i]; } }
protected override void Init() { canvas = Canvas.FindObjectOfType<Canvas>(); canvasManager = canvas.GetComponent<CanvasManager>(); aquariaWorldInterface = AquariaWorldInterface.CreateAquariaWorld(worldSize); worldInterface = aquariaWorldInterface; pointObjectManager = APointObjectManager.CreateAPointObjectManager(); actionManager = gameObject.AddComponent<AquariaActionManager>(); workManager = gameObject.AddComponent<WorkManager>(); visitorManager = new VisitorManager(aquariaWorldInterface); pathFinder = new Pathfinder(); BuildStartArea(); }
protected virtual void Init() { canvas = Canvas.FindObjectOfType<Canvas>(); canvasManager = canvas.GetComponent<CanvasManager>(); //WorldInterface.CreateGameWorld(worldSize); worldInterface = WorldInterface.CreateWorldInterface(worldSize); pointObjectManager = PointObjectManager.CreatePointObjectManager(); actionManager = gameObject.AddComponent<ActionManager>(); workManager = gameObject.AddComponent<WorkManager>(); pathFinder = new Pathfinder(); if (buildStartArea) { BuildStartArea(); } }
public void GenerateWorld() { _towerColumn1Ys = new List<ushort>(); _towerColumn2Ys = new List<ushort>(); Random random = new Random(); while(_towerColumn1Ys.Count != _numberOfLanes) { ushort n = (ushort) random.Next(0, _worldHeight); if(!_towerColumn1Ys.Contains(n)) { _towerColumn1Ys.Add(n); } } _towerColumn1Ys.Sort(); _towerColumn1Ys.Reverse(); while(_towerColumn2Ys.Count != _numberOfLanes) { ushort n = (ushort)random.Next(0, _worldHeight); if(!_towerColumn2Ys.Contains(n)) { _towerColumn2Ys.Add(n); } } _towerColumn2Ys.Sort(); _towerColumn2Ys.Reverse(); Pathfinder P = new Pathfinder(Pathfinder.GenerateGrid(_worldWidth, _worldHeight)); List<List<Pathfinder.PathfinderNode>> Lanes = new List<List<Pathfinder.PathfinderNode>>(_numberOfLanes); for(byte i = 0; i < _numberOfLanes; i++) { List<Pathfinder.PathfinderNode> Part1 = P.FindPath(P.GetNodeAt(_startX, _startY), P.GetNodeAt(_towerColumn1X, _towerColumn1Ys[i]), true); List<Pathfinder.PathfinderNode> Part2 = P.FindPath(P.GetNodeAt(_towerColumn1X, _towerColumn1Ys[i]), P.GetNodeAt(_towerColumn2X, _towerColumn2Ys[i]), true); Lanes.Add(new List<Pathfinder.PathfinderNode>(Part1.Count + Part2.Count)); Lanes[i].AddRange(Part1); Lanes[i].AddRange(Part2); Lanes[i] = Lanes[i].Distinct().ToList(); } for(byte i = 0; i < Lanes[0].Count; i++) { Debug.WriteLine(Lanes[0][i].X + ", " + Lanes[0][i].Y); } }
static void MoveGroup(MapRecord map,MonsterGroup group) { var random = new AsyncRandom(); var info = MonsterGroup.GetActorInformations(map, group); List<short> cells = Pathfinding.GetCircleCells(info.disposition.cellId, MoveCellsCount); cells.Remove(info.disposition.cellId); cells.RemoveAll(x => !map.WalkableCells.Contains(x)); cells.RemoveAll(x => PathHelper.GetDistanceBetween(info.disposition.cellId, x) <= MoveCellsCount); if (cells.Count == 0) return; var newCell = cells[random.Next(0, cells.Count())]; var path = new Pathfinder(map, info.disposition.cellId, newCell).FindPath(); if (path != null) { path.Insert(0, info.disposition.cellId); map.Instance.Send(new GameMapMovementMessage(path, info.contextualId)); group.CellId = (ushort)newCell; } else Logger.Error("Unable to move group" + group.MonsterGroupId + " on map " + map.Id + ", wrong path"); }
private void Awake() { enemy = GetComponent <Enemy>(); pathfinder = FindObjectOfType <Pathfinder>(); gridManager = FindObjectOfType <GridManager>(); }
private void Awake() { Pathfinder.instance = this; }
protected override void Start() { pathfinderScript = gameManager.GetComponent <Pathfinder>(); thePath = new Vector2[0]; base.Start(); }
public void AlignToGrid() => transform.position = Pathfinder.GetWorldPosition(Position);
public PathRequestTask(Pathfinder pathing, Actor actor, Vector3D Start, Vector3D Destination) { this._pathfinder = pathing; this._actor = actor; this._start = Start; this._destination = Destination; this.Path = new List<Vector3D>(); }
// Use this for initialization void Start() { _testAI = Entity.CreateTestAI (Destination1); _pathfinder = new Pathfinder (Map, Entity); }
/// /// PathfindNode() /// Raw pathfind creation public PathfindNode(Pathfinder pathfinder) { this.pathfinder = pathfinder; }
void Start() { _pathfinder = new Pathfinder (Map, EntityManager); }
public void Move(Cell cell, int mp) { if(!IsPlaying()) return; var pathfinding = new Pathfinder(Map, Fight, false); var path = pathfinding.FindPath(Cell, cell, false, Stats.CurrentMP > mp ? Stats.CurrentMP : mp); if (NotifyStartMoving(path)) Character.Bot.SendToServer(new GameMapMovementRequestMessage(path.GetClientPathKeys(), Map.Id)); }
/// <summary> /// The awake. /// </summary> private void Awake() { ThePathfinder = gameObject.GetComponent<Pathfinder>(); }
// Use this for initialization private void Start() { sprite = GetComponentInChildren<SpriteRenderer>(); pathfinder = GetComponent<Pathfinder>(); if (afterLoadFacing.HasValue) { SetNewFacing(afterLoadFacing.Value); afterLoadFacing = default(Facing?); } animator = GetComponent<Animator>(); }
private TaskGetPathToBlock PathFinder(Pathfinder.DWalkableBlocks rules, Coordinate unitStart) { return new TaskGetPathToBlock(rules, unitStart, standPositions, unit.getModel().collider); }
void Awake() { _pathfinder = new Pathfinder (Map, EntityManager); }
private static void SetWaveTactic(IReadOnlyCollection <Zombie> wave, double passedTime) { IAttackable target = null; var position = wave.First().Position; // Avoid multiple zombies attacking the same target and blocking themselves var targets = new IAttackable[(int)Math.Ceiling((float)wave.Count / 2)]; var flockTargets = false; // Choose tactic: attack economy vs. trying to finish if (sRandom.NextDouble() < passedTime / (passedTime + 5) * Game1.Difficulty || !ObjectManager.Instance.GetAnimals().Any()) { UnitPath farmerPath = null; UnitPath farmhousePath = null; if (ObjectManager.Instance.GetFarmer() != null && Pathfinder.ExistsPath(position, ObjectManager.Instance.GetFarmer().Position)) { farmerPath = Pathfinder.GetPath(position, ObjectManager.Instance.GetFarmer().Position); } if (ObjectManager.Instance.GetFarmhouse() != null && Pathfinder.ExistsPath(position, ObjectManager.Instance.GetFarmhouse().Position)) { farmhousePath = Pathfinder.GetPath(position, ObjectManager.Instance.GetFarmhouse().Position); } if (farmerPath != null && (farmhousePath == null || farmerPath.Length <= farmhousePath.Length)) { target = ObjectManager.Instance.GetFarmer(); } else if (farmhousePath != null) { target = ObjectManager.Instance.GetFarmhouse(); } else { foreach (var tower in ObjectManager.Instance.GetTowers()) { if (target == null || Vector2.Distance(position, tower.Position) < Vector2.Distance(position, target.Position)) { target = tower; } } if (target == null || !Pathfinder.ExistsPath(position, target.Position)) { flockTargets = true; var fences = ObjectManager.Instance.GetFences().ToArray(); var maxIndex = 0; for (var i = 0; i < targets.Length && i < fences.Length; i++) { targets[i] = fences[i]; if (Vector2.Distance(position, fences[i].Position) < Vector2.Distance(position, targets[maxIndex].Position)) { maxIndex = i; } } for (var i = targets.Length; i < fences.Length; i++) { if (!(Vector2.Distance(position, fences[i].Position) < Vector2.Distance(position, targets[maxIndex].Position))) { continue; } targets[maxIndex] = fences[i]; for (var j = 0; j < targets.Length; j++) { if (Vector2.Distance(position, targets[j].Position) > Vector2.Distance(position, targets[maxIndex].Position)) { maxIndex = j; } } } } } } else { flockTargets = true; var animals = ObjectManager.Instance.GetAnimals().ToArray(); var maxIndex = 0; for (var i = 0; i < targets.Length && i < animals.Length; i++) { targets[i] = animals[i]; if (Vector2.Distance(position, animals[i].Position) < Vector2.Distance(position, targets[maxIndex].Position)) { maxIndex = i; } } for (var i = targets.Length; i < animals.Length; i++) { if (!(Vector2.Distance(position, animals[i].Position) < Vector2.Distance(position, targets[maxIndex].Position))) { continue; } targets[maxIndex] = animals[i]; for (var j = 0; j < targets.Length; j++) { if (Vector2.Distance(position, targets[j].Position) > Vector2.Distance(position, targets[maxIndex].Position)) { maxIndex = j; } } } } if (flockTargets) { var flockedTargets = targets.Where(t => t != null).ToArray(); for (var i = 0; i < wave.Count; i++) { wave.ElementAt(i).Target = flockedTargets[i % flockedTargets.Length]; } } else { foreach (var zombie in wave) { zombie.Target = target; if (!zombie.PathEmpty) { continue; } var closestPosition = target.Position; while (!Pathfinder.ExistsPath(position, closestPosition)) { closestPosition = 0.9f * (closestPosition - zombie.Position) + zombie.Position; } zombie.Charge(closestPosition); zombie.PreferredTargetType = target.GetType(); } } }
public bool TryMove(ref EcsEntity entity, Position target, int range) { if (State == CharacterState.Sitting || State == CharacterState.Dead) { return(false); } if (MoveSpeed <= 0) { return(false); } if (!Map.WalkData.IsCellWalkable(target)) { return(false); } if (WalkPath == null) { WalkPath = new Position[17]; } var hasOld = false; var oldNext = new Position(); var oldCooldown = MoveCooldown; if (MoveStep + 1 < TotalMoveSteps && State == CharacterState.Moving) { oldNext = WalkPath[MoveStep + 1]; hasOld = true; } int len; //we won't interrupt the next step we are currently taking, so append it to the start of our new path. if (hasOld) { len = Pathfinder.GetPathWithInitialStep(Map.WalkData, Position, oldNext, target, WalkPath, range); } else { len = Pathfinder.GetPath(Map.WalkData, Position, target, WalkPath, range); } if (len == 0) { return(false); } TargetPosition = WalkPath[len - 1]; //reset to last point in walkpath MoveCooldown = MoveSpeed; MoveStep = 0; TotalMoveSteps = len; FacingDirection = (WalkPath[1] - WalkPath[0]).GetDirectionForOffset(); State = CharacterState.Moving; if (hasOld) { MoveCooldown = oldCooldown; } Map.StartMove(ref entity, this); ChangeToActionState(); return(true); }
public void SetTileFromNeedFurniture(Tile currentTile, string needFurniture) { tile = Pathfinder.FindPathToFurniture(currentTile, needFurniture).Last(); }
private void Awake() { instance = this; }
//--------------------------------------------------------------------------- public AIComponent(Guid entity) : base(entity) { Area area = AreaManager.Get().FindAreaFromEntity(Entity); m_Pathfinder = new Pathfinder(); }
void Awake() { Instance = this; }
private void DrawPath(Graphics g) { PointData currentPt = new Pathfinder(_map, _start, _end).FindPath(); if (currentPt == null) return; using (GraphicsPath path = new GraphicsPath()) using (Pen pen = new Pen(Color.SteelBlue, (10 * GRID_SIZE) / 40)) { do { path.AddLine(currentPt.X * GRID_SIZE + GRID_SIZE / 2, currentPt.Y * GRID_SIZE + GRID_SIZE / 2, currentPt.Parent.X * GRID_SIZE + GRID_SIZE / 2, currentPt.Parent.Y * GRID_SIZE + GRID_SIZE / 2); currentPt = currentPt.Parent; g.DrawString(currentPt.MovementCost.ToString(), this.Font, Brushes.Black, currentPt.X * GRID_SIZE + GRID_SIZE / 2, currentPt.Y * GRID_SIZE - GRID_SIZE / 2); } while (currentPt.Parent != null); g.DrawPath(pen, path); } }
void Start() { state = State.Playing; Creatures.PrepareCreatures(); playerArmies = new List <Army>(); if (PersistentData.state == PersistentData.State.ExitingCombat) { MonsterGroup pa = PersistentData.playerArmy; for (int i = 0; i < pa.armyCount; i++) { AddSoldiers(pa.armies[i].count); } ; } else { AddSoldiers(5); AddSoldiers(5); AddSoldiers(5); } recruitmentCamps = new List <RecruitmentCamp>(); if (PersistentData.state == PersistentData.State.ExitingCombat) { monsterGroups = PersistentData.monsterGroups.ToArray(); monsterGroupCount = PersistentData.monsterGroups.Count; } else { PrepareMonsterGroups(); } GenerateMap(); if (PersistentData.state == PersistentData.State.ExitingCombat) { List <SavedCamp> camps = PersistentData.recruitmentCamps; for (int i = 0; i < camps.Count; i++) { SavedCamp camp = camps[i]; RecruitmentCamp rCamp = Instantiate(recruitmentCampPrefab, tileContainer[camp.gamePosition.y + mapDY, camp.gamePosition.x + mapDX].transform); rCamp.transform.position = tileContainer[camp.gamePosition.y + mapDY, camp.gamePosition.x + mapDX].transform.position; rCamp.SetMax(camp.max); rCamp.SetCurrent(camp.current); rCamp.gamePosition = camp.gamePosition; recruitmentCamps.Add(rCamp); } for (int i = 0; i < monsterGroupCount; i++) { MonsterGroup group = monsterGroups[i]; int count = group.GetGroupCount(); GameObject mgPrefab = GetMonsterGroupPrefab(count); GameObject mgIcon = Instantiate(mgPrefab, tileContainer[group.gamePosition.y + mapDY, group.gamePosition.x + mapDX].transform); mgIcon.transform.localScale = new Vector3(1.0f, 10.0f, 1.0f); tileContainer[group.gamePosition.y + mapDY, group.gamePosition.x + mapDX].hasMonsters = true; } } mainCamera = Camera.main.gameObject.GetComponent <CameraController>(); mainCamera.SetConstraint( -mapWidth / 2 * tilePrefab.transform.localScale.x + 4, mapWidth / 2 * tilePrefab.transform.localScale.x + 4, 5, 5, -mapHeight / 2 * tilePrefab.transform.localScale.z - 3, mapHeight / 2 * tilePrefab.transform.localScale.z - 3 ); if (PersistentData.state == PersistentData.State.ExitingCombat) { Vector2i position = PersistentData.playerPosition; player.SetPosition(position.x, position.y); } else { player.SetPosition(3, -4); } pathfinder = new Pathfinder(); pathfinder.SetTerrain(terrainPassable); if (PersistentData.state == PersistentData.State.ExitingCombat) { currentDay = PersistentData.day; currentWeek = PersistentData.week; currentMonth = PersistentData.month; } else { currentDay = 1; currentWeek = 1; currentMonth = 1; } if (PersistentData.state == PersistentData.State.ExitingCombat) { SetPlayerMovement(PersistentData.movementPoints); } else { SetPlayerMovement(6); } monthValue.text = currentMonth.ToString(); weekValue.text = currentWeek.ToString(); dayValue.text = currentDay.ToString(); weekdayValue.text = ((WeekDay)currentDay).ToString(); if (monsterGroupCount == 0) { victory.gameObject.SetActive(true); } PersistentData.state = PersistentData.State.WorldMap; #if UNITY_EDITOR DynamicGI.UpdateEnvironment(); #endif }
public override bool isObstacle(Pathfinder pathfinder) { return (pathfinder.identification == forPathfinder); }
protected void Awake() { _pathfinder = new Pathfinder(this); UpdateGrid(); }
private void Awake() { _gridManager = FindObjectOfType <GridManager>(); _pathfinder = FindObjectOfType <Pathfinder>(); }
public Waypoint(Pathfinder pathfinder, AllNavigationSettings.SettingsLevelName level, IMyEntity targetEntity, Vector3D worldOffset) : this(pathfinder, level, new Destination(targetEntity, ref worldOffset)) { }
protected override void OnSimulate() { if (!CanMove) { return; } //TODO: Organize/split this function if (IsMoving) { if (CanPathfind) { if (DoPathfind) { DoPathfind = false; if (viableDestination) { if (Pathfinder.GetStartNode(cachedBody.Position, out currentNode)) { if (currentNode.DoesEqual(this.destinationNode)) { if (this.RepathTries >= 1) { this.Arrive(); } } else { if (straightPath) { if (Pathfinder.NeedsPath(currentNode, destinationNode, this.GridSize)) { if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath, GridSize, GetNodeHash(destinationNode))) { hasPath = true; pathIndex = 0; } else { if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } } straightPath = false; } else { } } else { if (Pathfinder.NeedsPath(currentNode, destinationNode, this.GridSize)) { if (Pathfinder.FindPath(Destination, currentNode, destinationNode, myPath, GridSize, GetNodeHash(destinationNode))) { hasPath = true; pathIndex = 0; } else { if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } } } else { straightPath = true; } } } } else { } } else { hasPath = false; if (IsFormationMoving) { StartMove(MyMovementGroup.Destination); IsFormationMoving = false; } } } else { } if (straightPath) { targetPos = Destination; } else if (hasPath) { if (pathIndex >= myPath.Count) { targetPos = this.Destination; } else { targetPos = myPath[pathIndex]; } } else { targetPos = Destination; } } else { targetPos = Destination; } movementDirection = targetPos - cachedBody._position; movementDirection.Normalize(out distance); if (targetPos.x != lastTargetPos.x || targetPos.y != lastTargetPos.y) { lastTargetPos = targetPos; targetDirection = movementDirection; } bool movingToWaypoint = (this.hasPath && this.pathIndex < myPath.Count - 1); long stuckThreshold = timescaledAcceleration / LockstepManager.FrameRate; long slowDistance = cachedBody.VelocityMagnitude.Div(timescaledDecceleration); if (distance > slowDistance || movingToWaypoint) { desiredVelocity = (movementDirection); if (CanTurn) { cachedTurn.StartTurnDirection(movementDirection); } } else { if (distance < FixedMath.Mul(closingDistance, StopMultiplier)) { Arrive(); //TODO: Don't skip this frame of slowing down return; } if (distance > closingDistance) { if (CanTurn) { cachedTurn.StartTurnDirection(movementDirection); } } if (distance <= slowDistance) { long closingSpeed = distance.Div(slowDistance); if (CanTurn) { cachedTurn.StartTurnDirection(movementDirection); } desiredVelocity = movementDirection * closingSpeed; decellerating = true; //Reduce occurence of units preventing other units from reaching destination stuckThreshold *= 4; } } //If unit has not moved stuckThreshold in a frame, it's stuck StuckTime++; if (GetCanAutoStop()) { if (Agent.Body.Position.FastDistance(AveragePosition) <= (stuckThreshold * stuckThreshold)) { if (StuckTime > StuckTimeThreshold) { if (movingToWaypoint) { this.pathIndex++; } else { if (RepathTries < StuckRepathTries) { DoPathfind = true; RepathTries++; } else { RepathTries = 0; this.Arrive(); } } StuckTime = 0; } } else { if (StuckTime > 0) { StuckTime -= 1; } RepathTries = 0; } } if (movingToWaypoint) { if ( ( this.pathIndex >= 0 && distance < closingDistance && (movementDirection).Dot(waypointDirection) < 0 ) || distance < FixedMath.Mul(closingDistance, FixedMath.Half)) { this.pathIndex++; } } desiredVelocity *= Speed; cachedBody._velocity += GetAdjustVector(desiredVelocity); cachedBody.VelocityChanged = true; } else { decellerating = true; //Slowin' down if (cachedBody.VelocityMagnitude > 0) { cachedBody.Velocity += GetAdjustVector(Vector2d.zero); } StoppedTime++; } decellerating = false; AutoStopPauser--; CollisionStopPauser--; StopPauseLooker--; AveragePosition = AveragePosition.Lerped(Agent.Body.Position, FixedMath.One / 2); }
void Start() { Pathfinder pathfinder = FindObjectOfType <Pathfinder>(); StartCoroutine(FollowPath(pathfinder.Path)); }
// Start is called before the first frame update void Start() { selectedUnits = new List <Unit>(); pathFinder = new Pathfinder(accuracy, GameObject.Find("Manager").GetComponent <Grid>()); }
private void SearchPath(Pathfinder.PathfindingMode _SearchMode) { Debug.Log(_SearchMode); /** * if (m_StartTile == null) * { * m_StartTile = m_GameGrid.GetTileAt(m_RowStart, m_ColumnStart); * } * * if (m_EndTile == null) * { * m_EndTile = m_GameGrid.GetTileAt(m_RowEnd, m_ColumnEnd); * } * /**/ if (m_PathVisualizer) { m_PathVisualizer.gameObject.SetActive(false); } Path path = null; ChronoInfos infos = new ChronoInfos(); float timeLimit = m_HasLimitSearchTime ? m_TimeLimit : -1; switch (_SearchMode) { case Pathfinder.PathfindingMode.PM_Dijkstra: path = Pathfinder.SearchDijkstraPathFromTo(m_StartTile, m_EndTile, out infos, timeLimit); break; case Pathfinder.PathfindingMode.PM_Dijkstra_LinkOpti: path = Pathfinder.SearchDisjktraPathFromTo_LinkOpti(m_StartTile, m_EndTile, out infos, timeLimit); break; case Pathfinder.PathfindingMode.PM_AStar: path = Pathfinder.AStarCustomBasic(m_StartTile, m_EndTile, out infos, timeLimit); break; case Pathfinder.PathfindingMode.PM_AStar_LinkOpti: path = Pathfinder.AStar_LinkOpti(m_StartTile, m_EndTile, out infos, timeLimit); break; case Pathfinder.PathfindingMode.PM_HPA: path = Pathfinder.SearchHPAFromTo(m_GridClustered, m_StartTile, m_EndTile, out infos, timeLimit); break; default: break; } Debug.Log(infos.ToLogMessage()); m_Hud?.SetChronoLog(infos); if (m_PathVisualizer && path != null) { m_PathVisualizer.gameObject.SetActive(true); m_PathVisualizer.TracePath(path, m_GameGrid.TilesRows); } }
private void Start() { _pathFinder = FindObjectOfType <Pathfinder>(); FollowPath(); }
public ShowMovementAreaEvent(EventID eventID, object sender, EventArgs<Pathfinder, Actors.Cursor> e) : base(eventID, sender, e) { this.pathfinder = e.Value; this.cursor = e.Value2; }
protected override void ActionMethod(Pathfinder pathfinder) { pathfinder.NavSet.Settings_Task_NavMove.Stay_In_Formation = true; }
// Use this for initialization void Start() { _pathFinder = Pathfinder.Instance; _unit = GetComponent<Unit>(); EventManager.Instance.AddListener<OnEventStartMovingCharacter>(OnMovingCharacter); }
private void Awake() { instance = this; pathfinder = new Pathfinder(this); }
public void MoveTo(Tile target) { Path = Tile.ToTileList(Pathfinder.FindPath(Tile, target, 10000)); Path.RemoveAt(0); }
protected virtual void Awake() { pathfinder = GetComponent <Pathfinder>(); }
private const float _maxStateDuration = 4.0f; //Only to prevent thrashing in the update public PathToState(PathToConfig config) : base(config) { _config = config; _path = Pathfinder.GetPath(Config.Owner.transform.position, _config.Target); _targetNode = Pathfinder.NearestNode(Config.Owner.transform.position); }
protected override bool HandleDoubleClick(int x, int y, Event.Button button) { if (!interf.Ingame) { return(false); } if (button != Event.Button.Left) { return(false); } // if clicked into the viewport, close notifications and other popups interf.CloseMessage(); interf.ClosePopup(); var position = new Position(x, y); var mapPosition = map.RenderMap.CoordinateSpace.ViewSpaceToTileSpace(position); var player = interf.Player; if (interf.IsBuildingRoad) { if (mapPosition != interf.GetMapCursorPosition()) { var roadEndPosition = interf.GetBuildingRoad().EndPosition; var road = Pathfinder.FindShortestPath(map, roadEndPosition, mapPosition, interf.GetBuildingRoad(), int.MaxValue, true); if (road.Length != 0) { int result = interf.ExtendRoad(road); if (result < 0) { PlaySound(Freeserf.Audio.Audio.TypeSfx.NotAccepted); } else if (result == 1) { PlaySound(Freeserf.Audio.Audio.TypeSfx.Accepted); } else { if (interf.Game.BuildFlag(interf.GetMapCursorPosition(), player)) { interf.BuildRoad(); PlaySound(Freeserf.Audio.Audio.TypeSfx.Accepted); } else { PlaySound(Freeserf.Audio.Audio.TypeSfx.Click); } } } else { PlaySound(Freeserf.Audio.Audio.TypeSfx.NotAccepted); } } else { bool result = interf.Game.BuildFlag(interf.GetMapCursorPosition(), player); if (result) { interf.BuildRoad(); } else { PlaySound(Freeserf.Audio.Audio.TypeSfx.NotAccepted); } } } else { interf.UpdateMapCursorPosition(mapPosition); if (map.GetObject(mapPosition) == Map.Object.None || map.GetObject(mapPosition) > Map.Object.Castle) { PlaySound(Freeserf.Audio.Audio.TypeSfx.Click); return(false); } if (map.GetObject(mapPosition) == Map.Object.Flag) { if (map.GetOwner(mapPosition) == player.Index) { interf.OpenPopup(PopupBox.Type.TransportInfo); } player.SelectedObjectIndex = map.GetObjectIndex(mapPosition); PlaySound(Freeserf.Audio.Audio.TypeSfx.Click); } else { // Building if (map.GetOwner(mapPosition) == player.Index || interf.AccessRights != Viewer.Access.Player) { PlaySound(Freeserf.Audio.Audio.TypeSfx.Click); var building = interf.Game.GetBuildingAtPosition(mapPosition); if (building.BuildingType == Building.Type.Castle) { interf.OpenPopup(PopupBox.Type.CastleResources); } else if (!building.IsDone) { interf.OpenPopup(PopupBox.Type.OrderedBld); } else if (building.BuildingType == Building.Type.Stock) { if (!building.IsActive) { return(false); } interf.OpenPopup(PopupBox.Type.CastleResources); } else if (building.BuildingType == Building.Type.Hut || building.BuildingType == Building.Type.Tower || building.BuildingType == Building.Type.Fortress) { interf.OpenPopup(PopupBox.Type.Defenders); } else if (building.BuildingType == Building.Type.StoneMine || building.BuildingType == Building.Type.CoalMine || building.BuildingType == Building.Type.IronMine || building.BuildingType == Building.Type.GoldMine) { interf.OpenPopup(PopupBox.Type.MineOutput); } else { interf.OpenPopup(PopupBox.Type.BuildingStock); } player.SelectedObjectIndex = map.GetObjectIndex(mapPosition); } else { // Foreign building // TODO handle coop mode if (player.PrepareAttack(mapPosition)) { PlaySound(Freeserf.Audio.Audio.TypeSfx.Accepted); interf.OpenPopup(PopupBox.Type.StartAttack); } else { PlaySound(Freeserf.Audio.Audio.TypeSfx.NotAccepted); } } } } return(false); }
public void setMyPathfinder(Pathfinder p) { myPathfinder = p; }
public TerrainTile(int x, int y, Terrain terrain) : this(x, y, terrain, null) { Pathfinder = new Pathfinder(this); }
public void Move(Cell cell) { if (cell == null) throw new ArgumentNullException("cell"); var pathfinder = new Pathfinder(Map, Map); var path = pathfinder.FindPath(Position.Cell, cell, true); if (IsMoving()) CancelMove(); if (NotifyStartMoving(path)) Bot.SendToServer(new GameMapMovementRequestMessage(path.GetClientPathKeys(), Map.Id)); }
public override int CompareTo(Pathfinder.Packaging.IPackage package) { return Package.Version.CompareTo(((NugetPackage)package).Package.Version); }
// Start is called before the first frame update void Start() { this.selectionIndicatorSprite = SelectionIndicator.GetComponent <SpriteRenderer>(); this.pathFinder = this.GetComponent <Pathfinder>(); }
public IDictionary <PathfinderNode <Sector>, ISet <PathfinderNode <Sector> > > CreateDijkstraMap(IMobileSpaceObject me, Sector start) { return(Pathfinder.CreateDijkstraMap(me, start, Destination, AvoidEnemies, true)); }
public void SetActive(bool value) { if (!value) { Destroy(gameObject); _instance = null; return; } _instance = Instance; }
//Set singleton! void Awake() { instance = this; }
public BattlePane(BattleManager battleManager) { BattleManager = battleManager; StackPane spMain = new StackPane(); spMain.PercentWidth = spMain.PercentHeight = 100; PercentWidth = PercentHeight = 100; hlThumbs = new HList(); hlThumbs.HAlignment = HAlignment.Left; hlThumbs.VAlignment = VAlignment.Top; hlThumbs.PercentWidth = 15; hlThumbs.PercentHeight = 15; hlThumbs.VisibleRange = 5; hlThumbs.Color = Color.Black; hlThumbs.Alpha = 0.5f; hpApCost = new HPane(); hpApCost.VAlignment = VAlignment.Top; hpApCost.PercentWidth = 100; hpApCost.Color = Color.Gray; hpApCost.Alpha = 0.5f; vlSkills = new VList(); vlSkills.PercentWidth = 100; vlSkills.VisibleRange = 3; vlSkills.IsStatic = false; vlSkills.Color = Color.Gray; vlSkills.Alpha = 0.5f; skillPane = new VPane(hpApCost, vlSkills); skillPane.HAlignment = HAlignment.Left; // skillPane.HAlignment = HAlignment.Left; // skillPane.VAlignment = VAlignment.Bottom; // skillPane.PercentWidth = 15; // skillPane.PercentHeight = 30; skillPane.PercentWidth = 100; skillPane.PercentHeight = 100; skillPane.Color = Color.Black; skillPane.Alpha = 0.5f; teamInfo = new TeamInfoPane(); teamInfo.HAlignment = HAlignment.Right; teamInfo.VAlignment = VAlignment.Bottom; teamInfo.PercentWidth = 40; teamInfo.PercentHeight = 20; teamInfo.Color = Color.Black; teamInfo.Alpha = 0.5f; objectInfo = new MapObjectInfoPane(); objectInfo.HAlignment = HAlignment.Right; objectInfo.VAlignment = VAlignment.Bottom; objectInfo.PercentWidth = 25; objectInfo.PercentHeight = 20; objectInfo.Color = Color.Black; objectInfo.Alpha = 0.5f; abilityInfo = new AbilityInfoPane(); abilityInfo.HAlignment = HAlignment.Left; abilityInfo.VAlignment = VAlignment.Bottom; // abilityInfo.HAlignment = HAlignment.Center; // abilityInfo.VAlignment = VAlignment.Bottom; abilityInfo.Color = Color.Black; abilityInfo.Alpha = 0.5f; HPane hpSkills = new HPane(skillPane, abilityInfo); hpSkills.HAlignment = HAlignment.Left; hpSkills.VAlignment = VAlignment.Bottom; hpSkills.PercentWidth = 15; hpSkills.PercentHeight = 30; vlSkills.ActionEvent += (sender, args) => { int s = args.SelectedIndex; if (player.ContainingMap.Slave is Cursor) { if (s == 0) { if (moveCost > player.AP || moveCost <= 0) { return; } movePath = new Queue <Point>(pathCache); moveCost = getMoveCost(player, movePath.Count); } else if (s > 0) { nextAbility = player.Abilities[s - 1]; } vlSkills.ControlLock = false; player.ContainingMap.hideCursor(); cursor.MoveStartedEvent -= onCursorMove; objectInfo.hide(); abilityInfo.hide(); hideSkillList(); // teamInfo.show(); // TODO looks to busy } else { int cost = s == 0 ? 10 : player.Abilities[s - 1].APCost; // TODO move cost if (cost > player.AP) { return; } playerPF = new Pathfinder(player); player.ContainingMap.showCursor(player.Position); cursor = player.ContainingMap.Cursor; cursor.MoveStartedEvent -= onCursorMove; cursor.MoveStartedEvent += onCursorMove; objectInfo.MapCursor = cursor; vlSkills.ControlLock = true; objectInfo.show(); teamInfo.hide(); abilityInfo.hide(); } }; vlSkills.CancelEvent += (sender, args) => { if (cursor == null) { return; } vlSkills.ControlLock = false; player.ContainingMap.hideCursor(); cursor.MoveStartedEvent -= onCursorMove; cursor = null; objectInfo.hide(); teamInfo.show(); }; vlSkills.SelectedEvent += (sender, args) => { int sel = args.SelectedIndex; if (sel > 0) { abilityInfo.Ability = player.Abilities[sel - 1]; abilityInfo.show(); } else { abilityInfo.hide(); } }; hlThumbs.SelectedEvent += (sender, args) => { int sel = args.SelectedIndex; int off = sel + hlThumbs.VisibleRange; if (off < hlThumbs.Children.Count) { (hlThumbs.Children[off] as MenuItem).Disabled = false; } }; // spMain.add(hlThumbs, skillPane, objectInfo, teamInfo, abilityInfo); spMain.add(hlThumbs, objectInfo, teamInfo, hpSkills); add(spMain); hide(); }