public void RemoveRoomPortal(VMEntity obj, ushort room) { VMRoomPortal target = null; foreach (var port in RoomInfo[room].Portals) { if (port.ObjectID == obj.ObjectID) { target = port; break; } } if (target != null) { RoomInfo[room].Portals.Remove(target); } }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); var roomN = reader.ReadInt32(); Rooms = new VMRoomPortal[roomN]; for (int i = 0; i < roomN; i++) { Rooms[i] = new VMRoomPortal(reader); } if (reader.ReadBoolean()) { CurrentPortal = new VMRoomPortal(reader); } var wtLen = reader.ReadInt32(); if (wtLen > -1) { WalkTo = new Point[wtLen]; for (int i = 0; i < wtLen; i++) { WalkTo[i] = new Point(reader.ReadInt32(), reader.ReadInt32()); } } WalkDirection = reader.ReadDouble(); TargetDirection = reader.ReadDouble(); IgnoreRooms = reader.ReadBoolean(); State = (VMRoutingFrameState)reader.ReadByte(); PortalTurns = reader.ReadInt32(); WaitTime = reader.ReadInt32(); Timeout = reader.ReadInt32(); Retries = reader.ReadInt32(); AttemptedChair = reader.ReadBoolean(); TurnTweak = reader.ReadSingle(); TurnFrames = reader.ReadInt32(); MoveTotalFrames = reader.ReadInt32(); MoveFrames = reader.ReadInt32(); Velocity = reader.ReadInt32(); CallFailureTrees = reader.ReadBoolean(); var igrN = reader.ReadInt32(); IgnoredRooms = new VMRoomPortal[igrN]; for (int i = 0; i < igrN; i++) { IgnoredRooms[i] = new VMRoomPortal(reader); } var avaN = reader.ReadInt32(); AvatarsToConsider = new short[avaN]; for (int i = 0; i < avaN; i++) { AvatarsToConsider[i] = reader.ReadInt16(); } PreviousPosition.Deserialize(reader); CurrentWaypoint.Deserialize(reader); RoomRouteInvalid = reader.ReadBoolean(); if (reader.ReadBoolean()) { Slot = SLOTItemSerializer.Deserialize(reader); } Target = reader.ReadInt16(); var chLen = reader.ReadInt32(); if (chLen > -1) { Choices = new VMFindLocationResultMarshal[chLen]; for (int i = 0; i < chLen; i++) { Choices[i] = new VMFindLocationResultMarshal(); Choices[i].Deserialize(reader); } } if (reader.ReadBoolean()) { CurRoute = new VMFindLocationResultMarshal(); CurRoute.Deserialize(reader); } if (Version > 29) { LastWalkStyle = reader.ReadInt16(); } }
private bool AttemptRoute(VMFindLocationResult route) //returns false if there is no room portal route to the destination room. { CurRoute = route; var avatar = (VMAvatar)Caller; Rooms = new Stack <VMRoomPortal>(); var DestRoom = VM.Context.GetRoomAt(route.Position); var MyRoom = VM.Context.GetRoomAt(avatar.Position); if (DestRoom == MyRoom || (route.Flags & SLOTFlags.IgnoreRooms) > 0) { return(true); //we don't have to do any room finding for this } else { //find shortest room traversal to destination. Simple A* pathfind. //Portals are considered nodes to allow multiple portals between rooms to be considered. var openSet = new List <VMRoomPortal>(); //we use this like a queue, but we need certain functions for sorted queue that are only provided by list. var closedSet = new HashSet <VMRoomPortal>(); var gScore = new Dictionary <VMRoomPortal, double>(); var fScore = new Dictionary <VMRoomPortal, double>(); var parents = new Dictionary <VMRoomPortal, VMRoomPortal>(); var StartPortal = new VMRoomPortal(Caller.ObjectID, MyRoom); //consider the sim as a portal to this room (as a starting point) openSet.Add(StartPortal); gScore[StartPortal] = 0; fScore[StartPortal] = GetDist(Caller.Position, route.Position); while (openSet.Count != 0) { var current = openSet[0]; openSet.RemoveAt(0); if (current.TargetRoom == DestRoom) { //this portal gets us to the room. while (current != StartPortal) //push previous portals till we get to our first "portal", the sim in its current room (we have already "traversed" this portal) { Rooms.Push(current); current = parents[current]; } return(true); } closedSet.Add(current); var portals = VM.Context.RoomInfo[current.TargetRoom].Portals; foreach (var portal in portals) //evaluate all neighbor portals { if (closedSet.Contains(portal)) { continue; //already evaluated! } var pos = VM.GetObjectById(portal.ObjectID).Position; var gFromCurrent = gScore[current] + GetDist(VM.GetObjectById(current.ObjectID).Position, pos); var newcomer = !openSet.Contains(portal); if (newcomer || gFromCurrent < gScore[portal]) { parents[portal] = current; //best parent for now gScore[portal] = gFromCurrent; fScore[portal] = gFromCurrent + GetDist(pos, route.Position); if (newcomer) //add and move to relevant position { OpenSetSortedInsert(openSet, fScore, portal); } else //remove and reinsert to refresh sort { openSet.Remove(portal); OpenSetSortedInsert(openSet, fScore, portal); } } } } return(false); } }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); var bezierRouting = (Version > 31); var roomN = reader.ReadInt32(); Rooms = new VMRoomPortal[roomN]; for (int i = 0; i < roomN; i++) { Rooms[i] = new VMRoomPortal(reader); } if (reader.ReadBoolean()) { CurrentPortal = new VMRoomPortal(reader); } var wtLen = reader.ReadInt32(); Point[] points = null; if (wtLen > -1) { WalkTo = new VMIPathSegment[wtLen]; if (bezierRouting) { for (int i = 0; i < wtLen; i++) { WalkTo[i] = ReadGenericSegment(reader); } } else { //old point list. convert to line segments. points = new Point[wtLen]; for (int i = 0; i < wtLen; i++) { points[i] = new Point(reader.ReadInt32(), reader.ReadInt32()); } } } WalkDirection = reader.ReadDouble(); TargetDirection = reader.ReadDouble(); IgnoreRooms = reader.ReadBoolean(); State = (VMRoutingFrameState)reader.ReadByte(); PortalTurns = reader.ReadInt32(); WaitTime = reader.ReadInt32(); Timeout = reader.ReadInt32(); Retries = reader.ReadInt32(); AttemptedChair = reader.ReadBoolean(); TurnTweak = reader.ReadSingle(); TurnFrames = reader.ReadInt32(); MoveTotalFrames = reader.ReadInt32(); MoveFrames = reader.ReadInt32(); Velocity = reader.ReadInt32(); CallFailureTrees = reader.ReadBoolean(); var igrN = reader.ReadInt32(); IgnoredRooms = new VMRoomPortal[igrN]; for (int i = 0; i < igrN; i++) { IgnoredRooms[i] = new VMRoomPortal(reader); } var avaN = reader.ReadInt32(); AvatarsToConsider = new short[avaN]; for (int i = 0; i < avaN; i++) { AvatarsToConsider[i] = reader.ReadInt16(); } LotTilePos CurrentWaypoint = new LotTilePos(); PreviousPosition.Deserialize(reader); if (bezierRouting) { CurrentPath = ReadGenericSegment(reader); } else { //convert old format into new CurrentWaypoint.Deserialize(reader); CurrentPath = new VMPathLineSegment( new Point(PreviousPosition.x * 0x8000, PreviousPosition.y * 0x8000), new Point(CurrentWaypoint.x * 0x8000, CurrentWaypoint.y * 0x8000)); if (points != null) { if (points.Length > 0) { WalkTo = new VMIPathSegment[points.Length]; WalkTo[0] = new VMPathLineSegment( new Point(CurrentWaypoint.x * 0x8000, CurrentWaypoint.y * 0x8000), new Point(points[0].X * 0x8000, points[0].Y * 0x8000)); for (int i = 1; i < WalkTo.Length; i++) { WalkTo[i] = new VMPathLineSegment( new Point(points[i - 1].X * 0x8000, points[i - 1].Y * 0x8000), new Point(points[i].X * 0x8000, points[i].Y * 0x8000)); } } else { WalkTo = new VMIPathSegment[0]; } } else { WalkTo = null; } } CurrentPath.CalculateTotalFrames(); CurrentPath.UpdateTotalFrames(MoveTotalFrames); CurrentPath.ResetToFrame(MoveFrames); RoomRouteInvalid = reader.ReadBoolean(); if (reader.ReadBoolean()) { Slot = SLOTItemSerializer.Deserialize(reader); } Target = reader.ReadInt16(); var chLen = reader.ReadInt32(); if (chLen > -1) { Choices = new VMFindLocationResultMarshal[chLen]; for (int i = 0; i < chLen; i++) { Choices[i] = new VMFindLocationResultMarshal(); Choices[i].Deserialize(reader); } } if (reader.ReadBoolean()) { CurRoute = new VMFindLocationResultMarshal(); CurRoute.Deserialize(reader); } if (Version > 29) { LastWalkStyle = reader.ReadInt16(); } }
private void OpenSetSortedInsert(List <VMRoomPortal> set, Dictionary <VMRoomPortal, double> fScore, VMRoomPortal portal) { var myScore = fScore[portal]; for (int i = 0; i < set.Count; i++) { if (myScore < fScore[set[i]]) { set.Insert(i, portal); return; } } set.Add(portal); }