public RoomCoords(PointInRoom room) { this.RoomX = room.RoomX; this.RoomY = room.RoomY; this.RoomWidth = room.RoomWidth; this.RoomHeight = room.RoomHeight; }
public toSort(PointInRoom index, int coord) { this.index = index; this.coord = coord; }
/// <summary> /// Initial implementation at leaf nodes only. TODO: try parents & also redo map for waypoints /// </summary> /// <returns></returns> public override CreaturePatrol CreatureStartPosAndWaypoints(bool clockwise) { //Find a leaf room PointInRoom room = RandomPointInRoom(); //Calculate a patrol around the room int freeSpaceX = (int)Math.Max(0, room.RoomWidth - 2); int freeSpaceY = (int)Math.Max(0, room.RoomHeight - 2); int patrolIndentX = Game.Random.Next(freeSpaceX / 4); int patrolIndentY = Game.Random.Next(freeSpaceY / 4); //Waypoints List <Point> waypointsBase = new List <Point>(); Point tl = new Point(room.RoomX + 1 + patrolIndentX, room.RoomY + 1 + patrolIndentY); Point tr = new Point(room.RoomX + room.RoomWidth - 2 - patrolIndentX, room.RoomY + 1 + patrolIndentY); Point bl = new Point(room.RoomX + 1 + patrolIndentX, room.RoomY + room.RoomHeight - 2 - patrolIndentY); Point br = new Point(room.RoomX + room.RoomWidth - 2 - patrolIndentX, room.RoomY + room.RoomHeight - 2 - patrolIndentY); waypointsBase.Add(tl); waypointsBase.Add(tr); waypointsBase.Add(br); waypointsBase.Add(bl); //Start position is a random spot on this square //Pair: side index, Point List <KeyValuePair <int, Point> > startPos = new List <KeyValuePair <int, Point> >(); for (int i = tl.x; i <= tr.x; i++) { //Top startPos.Add(new KeyValuePair <int, Point>(0, new Point(i, tl.y))); startPos.Add(new KeyValuePair <int, Point>(2, new Point(i, bl.y))); } for (int j = tl.y + 1; j <= bl.y - 1; j++) { startPos.Add(new KeyValuePair <int, Point>(3, new Point(tl.x, j))); startPos.Add(new KeyValuePair <int, Point>(1, new Point(tr.x, j))); } KeyValuePair <int, Point> startLoc = startPos[Game.Random.Next(startPos.Count)]; //Depending on the startLoc, re-order the waypoints so we to a suitable first point List <Point> waypointsReordered = new List <Point>(); if (clockwise == true) { for (int i = 1; i < 5; i++) { waypointsReordered.Add(waypointsBase[(startLoc.Key + i) % 4]); } } else { for (int i = 0; i < 4; i++) { int wayPointNo = startLoc.Key - i; if (wayPointNo < 0) { wayPointNo += 4; } waypointsReordered.Add(waypointsBase[wayPointNo]); } } return(new CreaturePatrol(startLoc.Value, new RoomCoords(room), waypointsReordered)); }