fn room_map(&mut self, rooms: &Vec<Room>) -> Vec<Vec<i32>> {
        let (w, h) = (self.map.width, self.map.height);
        let mut result = vec![vec![0i32; h as usize]; w as usize];

        for (i, room) in rooms.iter().enumerate() {
            let room_id = i as i32;
            for x in room.x1..min(w, room.x2 + 2) {
                for y in room.y1..min(h, room.y2 + 2) {
                    if x == room.x1 && (y == room.y1 || y == room.y2 + 1) {
                        result[x as usize][y as usize] = -1;
                    } else if x == room.x2 + 1 && (y == room.y1 || y == room.y2 + 1) {
                        result[x as usize][y as usize] = -1;
                    } else if x == room.x1 && x == 0 {
                        // no doors to edge of the map
                        result[x as usize][y as usize] = -1;
                    } else if y == room.y1 && y == 0 {
                        result[x as usize][y as usize] = -1;
                    } else if x == room.x1 {
                        result[x as usize][y as usize] = room_id * 4 + 1;
                    } else if x == room.x2 + 1 {
                        result[x as usize][y as usize] = room_id * 4 + 2;
                    } else if y == room.y1 {
                        result[x as usize][y as usize] = room_id * 4 + 3;
                    } else if y == room.y2 + 1 {
                        result[x as usize][y as usize] = room_id * 4 + 4;
                    } else {
                        result[x as usize][y as usize] = -2;
                    }
                }
            }
        }

        result
    }
/// Renders a list of rooms to an array so we can quickly test if we have hit a room,
/// and which room we have hit.
///
/// We tag room interiors as -2, and corners as -1
/// normal space is 0, and walls get their own positive index based on the room_id
/// (should probably use an enum or something)
Renders a list of rooms to an array so we can quickly test if we have hit a room,
and which room we have hit.

We tag room interiors as -2, and corners as -1
normal space is 0, and walls get their own positive index based on the room_id
(should probably use an enum or something)
Renders a list of rooms to an array so we can quickly test if we have hit a room and which room we have hit . We tag room interiors as - 2 and corners as - 1 normal space is 0 and walls get their own positive index based on the room_id ( should probably use an enum or something )
fn room_map(&mut self, rooms: &Vec<Room>) -> Vec<Vec<i32>> {
        let (w, h) = (self.map.width, self.map.height);
        let mut result = vec![vec![0i32; h as usize]; w as usize];
        for (i, room) in rooms.iter().enumerate() {
            let room_id = i as i32;
            for x in room.x1..min(w, room.x2 + 2) {
                for y in room.y1..min(h, room.y2 + 2) {
                    if x == room.x1 && (y == room.y1 || y == room.y2 + 1) {
                        result[x as usize][y as usize] = -1;
                    } else if x == room.x2 + 1 && (y == room.y1 || y == room.y2 + 1) {
                        result[x as usize][y as usize] = -1;
                    } else if x == room.x1 && x == 0 {
                        // no doors to edge of the map
                        result[x as usize][y as usize] = -1;
                    } else if y == room.y1 && y == 0 {
                        result[x as usize][y as usize] = -1;
                    } else if x == room.x1 {
                        result[x as usize][y as usize] = room_id * 4 + 1;
                    } else if x == room.x2 + 1 {
                        result[x as usize][y as usize] = room_id * 4 + 2;
                    } else if y == room.y1 {
                        result[x as usize][y as usize] = room_id * 4 + 3;
                    } else if y == room.y2 + 1 {
                        result[x as usize][y as usize] = room_id * 4 + 4;
                    } else {
                        result[x as usize][y as usize] = -2;
                    }
                }
            }
        }
        result
    }
fn room_map ( & mut self , rooms : & Vec < Room > ) -> Vec < Vec < i32 > > { let ( w , h ) = ( self . map . width , self . map . height ) ; let mut result = vec ! [ vec [ 0i32 h as usize ] w as usize ] ; for ( i , room ) in rooms . iter ( ) . enumerate ( ) { let room_id = i as i32 ; for x in room . x1 .. min ( w , room . x2 + 2 ) { for y in room . y1 .. min ( h , room . y2 + 2 ) { if x == room . x1 && ( y == room . y1 || y == room . y2 + 1 ) { result [ x as usize ] [ y as usize ] = - 1 ; } else if x == room . x2 + 1 && ( y == room . y1 || y == room . y2 + 1 ) { result [ x as usize ] [ y as usize ] = - 1 ; } else if x == room . x1 && x == 0 { // no doors to edge of the map result [ x as usize ] [ y as usize ] = - 1 ; } else if y == room . y1 && y == 0 { result [ x as usize ] [ y as usize ] = - 1 ; } else if x == room . x1 { result [ x as usize ] [ y as usize ] = room_id * 4 + 1 ; } else if x == room . x2 + 1 { result [ x as usize ] [ y as usize ] = room_id * 4 + 2 ; } else if y == room . y1 { result [ x as usize ] [ y as usize ] = room_id * 4 + 3 ; } else if y == room . y2 + 1 { result [ x as usize ] [ y as usize ] = room_id * 4 + 4 ; } else { result [ x as usize ] [ y as usize ] = - 2 ; } } } } result }
Renders a list of rooms to an array so we can quickly test if we have hit a room,
and which room we have hit.
Renders a list of rooms to an array so we can quickly test if we have hit a room and which room we have hit .
&mut self
rooms
&Vec<Room>