Example #1
0
 public void GetTingOfTypeOnTile()
 {
     MyTing myTing = _tingRunner.CreateTing<MyTing>("MyTing", new WorldCoordinate(ROOM_NAME, new IntPoint(0, 0)));
     Room room = _roomRunner.GetRoom(ROOM_NAME);
     IntPoint p = new IntPoint(3, 3);
     myTing.position = new WorldCoordinate(ROOM_NAME, p);
     PointTileNode tileNode = room.GetTile(p);
     Assert.AreEqual(null, tileNode.GetOccupantOfType<WeirdTing>());
     Assert.AreSame(myTing, tileNode.GetOccupantOfType<MyTing>());
 }
Example #2
0
        public void SubtractIntPoints()
        {
            IntPoint p1 = new IntPoint(0, 0);
            IntPoint p2 = new IntPoint(1, 0);
            IntPoint p3 = new IntPoint(0, -1);
            IntPoint p4 = new IntPoint(0, -1);

            Assert.AreEqual(new IntPoint(1, 0), p2 - p1);
            Assert.AreEqual(new IntPoint(1, 1), p2 - p3);
            Assert.AreEqual(new IntPoint(0, 1), p1 - p4);
        }
Example #3
0
 public TileNode(Room pRoom, int pX, int pY, TileType pType)
 {
     localPosition = new IntPoint(pX, pY);
     room = pRoom;
     isStartNode = false;
     isGoalNode = false;
     visited = false;
     distanceToGoal = 0f;
     pathCostHere = 0f;
     baseCost = 1f;
     type = pType;
 }
Example #4
0
 public IntPoint WorldToLocalPoint(IntPoint pSource)
 {
     return pSource - worldPosition;
 }
Example #5
0
 public PointTileNode GetTile(IntPoint pPoint)
 {
     return GetTile(pPoint.x, pPoint.y);
 }
Example #6
0
 public TileNode(Room pRoom, IntPoint pLocalPosition)
 {
     room = pRoom;
     localPosition = pLocalPosition;
 }
Example #7
0
 public Door(Room pRoom, string pName, IntPoint pPosition)
     : base(pRoom, pPosition.x, pPosition.y, TileType.DOOR)
 {
     name = pName;
 }
Example #8
0
 public static bool ArePointsWithinDistance(IntPoint p1, IntPoint p2, int pDistance)
 {
     int distance = pDistance;
     int dx = p1.x - p2.x;
     int dy = p1.y - p2.y;
     return ((dx * dx) + (dy * dy)) < (distance * distance);
 }
Example #9
0
 public float EuclidianDistanceTo( IntPoint pOtherPoint )
 {
     IntPoint deltaPoint = pOtherPoint - this;
     return (float)Math.Sqrt(deltaPoint.x * deltaPoint.x + deltaPoint.y * deltaPoint.y);
 }
Example #10
0
 public TileNode(IntPoint pLocalPoint)
 {
     links = new List<PathLink>(5);
     localPoint = pLocalPoint;
 }
Example #11
0
 public WorldCoordinate(string pRoomName, IntPoint pLocalPosition)
 {
     localPosition = pLocalPosition;
     roomName = pRoomName;
 }
Example #12
0
        public void TingChangesTileToOccupy()
        {
            Ting ting = _tingRunner.GetTing("Ting0");
            Room room = _roomRunner.GetRoom(ROOM_NAME);

            IntPoint p1 = new IntPoint(2, 2);
            IntPoint p2 = new IntPoint(4, 4);

            PointTileNode tileNode1 = room.GetTile(p1);
            PointTileNode tileNode2 = room.GetTile(p2);

            Assert.AreEqual(0, tileNode1.GetOccupants().Length);
            Assert.AreEqual(0, tileNode2.GetOccupants().Length);

            ting.position = new WorldCoordinate(ROOM_NAME, p1);

            Assert.AreEqual(1, tileNode1.GetOccupants().Length);
            Assert.AreEqual(0, tileNode2.GetOccupants().Length);

            ting.position = new WorldCoordinate(ROOM_NAME, p2);

            Assert.AreEqual(0, tileNode1.GetOccupants().Length);
            Assert.AreEqual(1, tileNode2.GetOccupants().Length);
        }
Example #13
0
 public void TingOccupyingATile()
 {
     IntPoint p = new IntPoint(5, 3);
     Ting t = _tingRunner.GetTing("Ting0");
     t.position = new WorldCoordinate(ROOM_NAME, p);
     Room room = _roomRunner.GetRoom(ROOM_NAME);
     PointTileNode tileNode = room.GetTile(p);
     Ting[] occupants = tileNode.GetOccupants();
     Assert.AreEqual(1, occupants.Length);
     Assert.AreSame(t, occupants[0]);
 }
        public void EvaWalksWithSaveInTheMiddle()
        {
            const string saveName = "EvaWalksWithSaveInTheMiddle.json";

            // These variables are for checking that everything stays the same after loading the save
            IntPoint midPoint = new IntPoint(-1, -1);
            float walkTimerWhenSaving;
            int walkIteratorWhenSaving;

            {
                _eva.position = new WorldCoordinate("Hallway", IntPoint.Zero);
                _eva.walkSpeed = 1.0f; // 1 tile per second
                _eva.WalkTo(new WorldCoordinate("Hallway", new IntPoint(4, 4)));

                WorldTestHelper.UpdateWorld(_world, 1f);
                Assert.AreEqual("Walking", _eva.actionName);

                WorldTestHelper.UpdateWorld(_world, 2.5f);

                midPoint = _eva.localPoint;
                walkTimerWhenSaving = _eva.walkTimer;
                walkIteratorWhenSaving = _eva.walkIterator;

                _world.Save(saveName);
                _world = null;
            }

            {
                World freshWorld = new World(saveName);

                _eva = freshWorld.tingRunner.GetTing("Eva") as Character;
                Assert.AreEqual(midPoint, _eva.localPoint);
                Assert.AreEqual(walkTimerWhenSaving, _eva.walkTimer);
                Assert.AreEqual(walkIteratorWhenSaving, _eva.walkIterator);

                WorldTestHelper.UpdateWorld(freshWorld, 5.0f);
                Assert.AreEqual(new IntPoint(4, 4), _eva.localPoint);
                Assert.AreEqual("", _eva.actionName);
            }
        }
Example #15
0
        private void UpdateBounds()
        {
            localMinBoundrary = IntPoint.Max;
            localMaxBoundrary = IntPoint.Min;

            foreach (PointTileNode t in _tilesByLocalPositionHash.Values) {
                if (t.localPoint.x > localMaxBoundrary.x)
                    localMaxBoundrary = new IntPoint(t.localPoint.x, localMaxBoundrary.y);
                if (t.localPoint.y > localMaxBoundrary.y)
                    localMaxBoundrary = new IntPoint(localMaxBoundrary.x, t.localPoint.y);
                if (t.localPoint.x < localMinBoundrary.x)
                    localMinBoundrary = new IntPoint(t.localPoint.x, localMinBoundrary.y);
                if (t.localPoint.y < localMinBoundrary.y)
                    localMinBoundrary = new IntPoint(localMinBoundrary.x, t.localPoint.y);
            }
        }
Example #16
0
 public SampleNode(int pX, int pY)
 {
     _localPoint = new IntPoint(pX, pY);
 }
Example #17
0
 public WorldCoordinate(string pRoomName, int pX, int pY)
 {
     localPosition = new IntPoint(pX, pY);
     roomName = pRoomName;
 }
        // Returns true on success
        private static bool GetClosestInteractionPoint(RoomRunner pRoomRunner, Room pRoom, PointTileNode pStartTile, IntPoint[] pPossiblePoints, out IntPoint closestPoint, Character pCharacter, bool pIgnoreCharacters)
        {
            D.isNull(pRoom, "pRoom is null");
            D.isNull(pPossiblePoints, "possiblePoints is null");

            if (pRoom != pCharacter.room) {
                throw new Exception("Error for " + pCharacter.name + "! Can only pathfind to closest interaction point in the same room: " + pCharacter.room.name + ", tried to do it in: " + pRoom.name);
            }

            closestPoint = IntPoint.Zero;
            float shortestDistance = float.MaxValue;
            bool foundSomething = false;

            #if LOG
            s_logger.Log("Trying to find closest interaction point for " + pCharacter + ", nr of possible points: " + pPossiblePoints.Length);
            #endif

            foreach(IntPoint p in pPossiblePoints)
            {
                PointTileNode tileNode = pRoom.GetTile(p);
                if(tileNode == null) {
            #if LOG
                    s_logger.Log("Node at " + p + " was null, ignoring it");
            #endif
                    continue;
                }

                var ignoreList = notTrueObstacles;

                if (pIgnoreCharacters) {
                    ignoreList = notTrueObstaclesIncludingCharacters;
                }

                if(tileNode.HasOccupantsButIgnoreSomeTypes(ignoreList)) {
            #if LOG
                    s_logger.Log("Will ignore node at " + p + " since it has occupants: " + tileNode.GetOccupantsAsString());
            #endif
                    continue;
                }

            #if LOG
                s_logger.Log("Checking tile node " + tileNode);
            #endif

                pRoom.Reset();
                var path = _tilePathSolver.FindPath(pStartTile, tileNode, pRoomRunner, false);

            #if LOG
                s_logger.Log("RESULT Path from " + pStartTile + " to " + tileNode + ": " + path.status);
            #endif
                //D.Log("RESULT Path from " + pStartTile + " to " + tileNode + ": " + path.status);

                D.isNull(path, "path is null");
                if((path.status == PathStatus.FOUND_GOAL || path.status == PathStatus.ALREADY_THERE) && path.pathLength < shortestDistance) {
                    closestPoint = p;
                    shortestDistance = path.pathLength;
                    foundSomething = true;
                }

            #if LOG
                s_logger.Log("path.status = " + path.status);
            #endif
            }

            if(!foundSomething) {
            #if LOG
                s_logger.Log(pCharacter + " at position " + pCharacter.position + " can't find an interaction point for final target " + pCharacter.finalTargetTing);
            #endif
                return false;
            }

            return true;
        }
Example #19
0
 public TileType GetTileType(IntPoint pPoint)
 {
     return GetTileType(pPoint.x, pPoint.y);
 }
Example #20
0
 public int ManhattanDistanceTo( IntPoint pOtherPoint )
 {
     IntPoint deltaPoint = pOtherPoint - this;
     deltaPoint.x = deltaPoint.x < 0 ? -deltaPoint.x : deltaPoint.x;
     deltaPoint.y = deltaPoint.y < 0 ? -deltaPoint.y : deltaPoint.y;
     return deltaPoint.x + deltaPoint.y;
 }
Example #21
0
 //        [SprakAPI("Teleport user to another position. Returns an error message as a string.", "x", "y")]
 //        public string API_TeleportUser(string targetRoom, int x, int y)
 //        {
 //            if(_user == null) {
 //                D.Log ("User for door " + name + " is null");
 //                return "Fail";
 //                //throw new Exception("User is null for door " + name);
 //            }
 //            
 //            if(targetDoor != null) {
 //                var targetRoomRef = _roomRunner.GetRoom(targetRoom);
 //                PushAwayBlockers(targetRoomRef, x, y, IntPoint.DirectionToIntPoint(targetDoor.direction));
 //                WorldCoordinate newPosition = new WorldCoordinate(targetRoom, x, y); // OLD VERSION: door.targetPosition;
 //                logger.Log(name + " opened the door " + name + " and will now teleport to " + newPosition);
 //                _user.targetPositionInRoom = targetDoor.position; // makes the Shell not freak out when it is created in the new scene but target is still in the old one
 //                _user.position = newPosition;
 //                _user.direction = targetDoor.direction;
 //                _user.StopAction();
 //                _user.StartAction("WalkingThroughDoorPhase2", null, 1.35f, 1.35f);
 //                _dialogueRunner.EventHappened(_user.name + "_open_" + name);
 //                if(isElevatorEntrance) {
 //                    targetDoor.elevatorFloor = this.elevatorFloor;
 //                }
 //                return "Success";
 //            }
 //            else {
 //                return "Door '" + name + "' doesn't have a target";
 //            }
 //        }
 void PushAwayBlockers(Room targetRoom, int x, int y, IntPoint pushDir)
 {
     var tile = targetRoom.GetTile(x, y);
     if(tile == null) return;
     var blockers = tile.GetOccupants();
     foreach(var blocker in blockers) {
         if(blocker is Character) {
             var newPosition = new WorldCoordinate(blocker.position.roomName, blocker.position.localPosition + pushDir * 2);
             if(targetRoom.GetTile(newPosition.localPosition) != null) {
                 //D.Log(blocker + " was pushed by a door from " + blocker.position + " to " + newPosition);
                 blocker.position = newPosition;
             } else {
                 D.Log("Can't push " + blocker.name + " to " + newPosition + " because there is no tile there");
             }
         }
     }
 }