public Int2 GetInteractiveAsset(Int2 _tileGridPos, Sorting _sorting) { Node _nodeTL, _nodeTR, _nodeBR, _nodeBL; NeighborFinder.GetSurroundingNodes(_tileGridPos, out _nodeTL, out _nodeTR, out _nodeBR, out _nodeBL); bool _hasNodeTL = _nodeTL != null; bool _hasNodeTR = _nodeTR != null; bool _hasNodeBR = _nodeBR != null; bool _hasNodeBL = _nodeBL != null; Node.InteractiveObject _interactiveObjectTL = _hasNodeTL ? _nodeTL.AttachedInteractiveObject : null; Node.InteractiveObject _interactiveObjectTR = _hasNodeTR ? _nodeTR.AttachedInteractiveObject : null; Node.InteractiveObject _interactiveObjectBR = _hasNodeBR ? _nodeBR.AttachedInteractiveObject : null; Node.InteractiveObject _interactiveObjectBL = _hasNodeBL ? _nodeBL.AttachedInteractiveObject : null; Node.InteractiveObject _interactiveObjectTemporaryTL = _hasNodeTL ? _nodeTL.AttachedInteractiveObjectTemporary : null; Node.InteractiveObject _interactiveObjectTemporaryTR = _hasNodeTR ? _nodeTR.AttachedInteractiveObjectTemporary : null; Node.InteractiveObject _interactiveObjectTemporaryBR = _hasNodeBR ? _nodeBR.AttachedInteractiveObjectTemporary : null; Node.InteractiveObject _interactiveObjectTemporaryBL = _hasNodeBL ? _nodeBL.AttachedInteractiveObjectTemporary : null; bool _useInteractiveObjectTemporaryTL = _hasNodeTL && _nodeTL.UseAttachedInteractiveObjectTemporary; bool _useInteractiveObjectTemporaryTR = _hasNodeTR && _nodeTR.UseAttachedInteractiveObjectTemporary; bool _useInteractiveObjectTemporaryBR = _hasNodeBR && _nodeBR.UseAttachedInteractiveObjectTemporary; bool _useInteractiveObjectTemporaryBL = _hasNodeBL && _nodeBL.UseAttachedInteractiveObjectTemporary; Node.InteractiveObject _foundInteractive = null; Direction _foundInteractiveDirection = Direction.None; Node _foundInteractivesNode = null; if (TryGetInteractiveObject(_nodeTL, out _foundInteractive)) { _foundInteractiveDirection = Direction.TL; _foundInteractivesNode = _nodeTL; } else if (TryGetInteractiveObject(_nodeTR, out _foundInteractive)) { _foundInteractiveDirection = Direction.TR; _foundInteractivesNode = _nodeTR; } else if (TryGetInteractiveObject(_nodeBR, out _foundInteractive)) { _foundInteractiveDirection = Direction.BR; _foundInteractivesNode = _nodeBR; } else if (TryGetInteractiveObject(_nodeBL, out _foundInteractive)) { _foundInteractiveDirection = Direction.BL; _foundInteractivesNode = _nodeBL; } if (_foundInteractive != null) { return(_foundInteractive.GetTileAssetPos(_sorting, _foundInteractiveDirection)); } return(DefaultAssets.Empty); }
public override void Tick(out State _state) { if (openSet == null || openSet.Count == 0) { _state = State.Abort; return; } PathNode _currentPathNode = openSet.RemoveFirst(); closedSet.Add(_currentPathNode); if (_currentPathNode.GridPos != targetNodeGridPos) { Node[] _neighbors; NeighborFinder.GetSurroundingNodes(_currentPathNode.GridPos, out _neighbors); for (int i = 0; i < _neighbors.Length; i++) { Node _neighbor = _neighbors[i]; if (_neighbor == null) { continue; } PathNode _neighborPathNode = nodeGrid[_neighbor.GridPos.x, _neighbor.GridPos.y]; if (ShouldConsiderUsingNeighbor(_neighborPathNode, _currentPathNode)) { Debug.DrawLine(_currentPathNode.WorldPos, _neighborPathNode.WorldPos, Color.magenta, 1.0f); _neighborPathNode.GCost = GetMovementCost(_currentPathNode, _neighborPathNode); _neighborPathNode.HCost = GetDistance(_neighborPathNode.GridPos, targetNodeGridPos); _neighborPathNode.Parent = _currentPathNode; if (!openSet.Contains(_neighborPathNode)) { openSet.Add(_neighborPathNode); } else { openSet.UpdateItem(_neighborPathNode); } } } _state = State.Tick; } else { RetracePath(out path, out pathFull, out pathLength); _state = State.Done; } }
public void SetLightingBasedOnNeighbors() // TODO: this causes jagged lighting along walls - can definitely be fixed though! { Node _nodeTL, _nodeT, _nodeTR, _nodeR, _nodeBR, _nodeB, _nodeBL, _nodeL; NeighborFinder.GetSurroundingNodes(GridPos, out _nodeTL, out _nodeT, out _nodeTR, out _nodeR, out _nodeBR, out _nodeB, out _nodeBL, out _nodeL); lightingTL = GetLightingFromDirection(Direction.TL); lightingTR = GetLightingFromDirection(Direction.TR); lightingBR = GetLightingFromDirection(Direction.BR); lightingBL = GetLightingFromDirection(Direction.BL); ScheduleUpdateGraphicsForSurroundingTiles(); }
public Node GetClosestFreeNode(Vector3 _worldPos) { Node _node = GetNodeFromWorldPos(_worldPos); if (_node.GetIsWalkable()) { return(_node); } Node[] _nodes; NeighborFinder.GetSurroundingNodes(_node.GridPos, out _nodes); List <Node> _neighbours = new List <Node>(_nodes); int _lastCount = 0; while (_neighbours.Count < (SIZE.x * SIZE.y)) { // iterate over _neighbours until a free node is found for (int i = _lastCount; i < _neighbours.Count; i++) { if (_neighbours[i].GetIsWalkable() && _neighbours[i].GetOccupyingNodeObject() == null) { return(_neighbours[i]); } } int _prevLastCount = _lastCount; _lastCount = _neighbours.Count; // save progress before we add new neighbours, so we don't iterate over old stuff later // iterate over _neighbours - if their neighbours aren't in _neighbours, add them. Node[] _newNeighbours; for (int i = _prevLastCount; i < _lastCount; i++) { NeighborFinder.GetSurroundingNodes(_neighbours[i].GridPos, out _newNeighbours); for (int j = 0; j < _newNeighbours.Length; j++) { if (_neighbours.Contains(_newNeighbours[j])) { continue; } _neighbours.Add(_newNeighbours[j]); } } } return(null); }
public Int2 GetWallAsset(Int2 _tileGridPos, Sorting _sorting) { Node _nodeTL, _nodeTR, _nodeBR, _nodeBL; NeighborFinder.GetSurroundingNodes(_tileGridPos, out _nodeTL, out _nodeTR, out _nodeBR, out _nodeBL); bool _hasNodeTL = _nodeTL != null; bool _hasNodeTR = _nodeTR != null; bool _hasNodeBR = _nodeBR != null; bool _hasNodeBL = _nodeBL != null; bool _isWallTL = _hasNodeTL && _nodeTL.IsWall; bool _isWallTR = _hasNodeTR && _nodeTR.IsWall; bool _isWallBR = _hasNodeBR && _nodeBR.IsWall; bool _isWallBL = _hasNodeBL && _nodeBL.IsWall; bool _isWallTemporaryTL = _hasNodeTL && _nodeTL.IsWallTemporarily; bool _isWallTemporaryTR = _hasNodeTR && _nodeTR.IsWallTemporarily; bool _isWallTemporaryBR = _hasNodeBR && _nodeBR.IsWallTemporarily; bool _isWallTemporaryBL = _hasNodeBL && _nodeBL.IsWallTemporarily; bool _useIsWallTemporaryTL = _hasNodeTL && _nodeTL.UseIsWallTemporary; bool _useIsWallTemporaryTR = _hasNodeTR && _nodeTR.UseIsWallTemporary; bool _useIsWallTemporaryBR = _hasNodeBR && _nodeBR.UseIsWallTemporary; bool _useIsWallTemporaryBL = _hasNodeBL && _nodeBL.UseIsWallTemporary; bool _isEitherKindOfWallTL = _isWallTL || (_useIsWallTemporaryTL && _isWallTemporaryTL); bool _isEitherKindOfWallTR = _isWallTR || (_useIsWallTemporaryTR && _isWallTemporaryTR); bool _isEitherKindOfWallBR = _isWallBR || (_useIsWallTemporaryBR && _isWallTemporaryBR); bool _isEitherKindOfWallBL = _isWallBL || (_useIsWallTemporaryBL && _isWallTemporaryBL); bool _isInsideRoom = false; _isInsideRoom = _isInsideRoom || _hasNodeTL && RoomManager.GetInstance().IsInsideShip(_nodeTL.RoomIndex); _isInsideRoom = _isInsideRoom || _hasNodeTR && RoomManager.GetInstance().IsInsideShip(_nodeTR.RoomIndex); _isInsideRoom = _isInsideRoom || _hasNodeBR && RoomManager.GetInstance().IsInsideShip(_nodeBR.RoomIndex); _isInsideRoom = _isInsideRoom || _hasNodeBL && RoomManager.GetInstance().IsInsideShip(_nodeBL.RoomIndex); if (!_isInsideRoom) { return(DefaultAssets.Empty); } else if (_isEitherKindOfWallTL && _isEitherKindOfWallTR && _isEitherKindOfWallBR && _isEitherKindOfWallBL) { return(DefaultAssets.Wall_TL_TR_BR_BL); } else if (_isEitherKindOfWallTL && _isEitherKindOfWallTR && _isEitherKindOfWallBR) { return(DefaultAssets.Wall_TL_TR_BR); } else if (_isEitherKindOfWallTR && _isEitherKindOfWallBR && _isEitherKindOfWallBL) { return(DefaultAssets.Wall_TR_BR_BL); } else if (_isEitherKindOfWallBR && _isEitherKindOfWallBL && _isEitherKindOfWallTL) { return(DefaultAssets.Wall_BR_BL_TL); } else if (_isEitherKindOfWallBL && _isEitherKindOfWallTL && _isEitherKindOfWallTR) { return(DefaultAssets.Wall_BL_TL_TR); } else if (_isEitherKindOfWallTL && _isEitherKindOfWallTR) { return(DefaultAssets.Wall_TL_TR); } else if (_isEitherKindOfWallTR && _isEitherKindOfWallBR) { return(DefaultAssets.Wall_TR_BR); } else if (_isEitherKindOfWallBR && _isEitherKindOfWallBL) { return(DefaultAssets.Wall_BR_BL); } else if (_isEitherKindOfWallBL && _isEitherKindOfWallTL) { return(DefaultAssets.Wall_BL_TL); } else if (_isEitherKindOfWallTL && _isEitherKindOfWallBR) { return(DefaultAssets.Wall_TL_BR); } else if (_isEitherKindOfWallTR && _isEitherKindOfWallBL) { return(DefaultAssets.Wall_TR_BL); } else if (_isEitherKindOfWallTL) { return(DefaultAssets.Wall_TL); } else if (_isEitherKindOfWallTR) { return(DefaultAssets.Wall_TR); } else if (_isEitherKindOfWallBR) { return(DefaultAssets.Wall_BR); } else if (_isEitherKindOfWallBL) { return(DefaultAssets.Wall_BL); } else { return(DefaultAssets.Wall_None); } }