<commit_before>//
// Room.swift
//
// This source file is part of the SMUD open source project
//
// Copyright (c) 2016 SMUD project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SMUD project authors
//

import Foundation

public class Room {
    public let prototype: Entity
    public var areaInstance: AreaInstance

    public var id: String
    public var title: String
    public var description: String
    public var exits = [Direction: Link]()
    public var creatures = [Creature]()
    public let fight: Fight

    public var orderedDirections: [Direction] {
        var result = [Direction]()
        for direction in Direction.orderedDirections {
            guard exits[direction] != nil else { continue }
            result.append(direction)
        }
        return result
    }

    public var orderedExits: [(Direction, Link)] {
        var result = [(Direction, Link)]()
        for direction in Direction.orderedDirections {
            guard let exit = exits[direction] else { continue }
            result.append((direction, exit))
        }
        return result
    }
    
    public init(prototype: Entity, instance: AreaInstance) {
        fight = Fight(smud: instance.area.world.smud)
        self.prototype = prototype
        self.areaInstance = instance

        let id = prototype["room"]?.string ?? ""
        assert(id != "")
        self.id = id
        
        title = prototype["title"]?.string ?? "No title"
        description = prototype["description"]?.string ?? ""
    }

    public convenience init(id: String, instance: AreaInstance) {
        let prototype = Entity()
        _ = prototype.add(name: "room", value: .tag(id))
        self.init(prototype: prototype, instance: instance)
    }
    
    public func reset(mode: AreaInstance.ResetMode) {
        exits.removeAll(keepingCapacity: true)
        
        if let lastExitIndex = prototype.lastStructureIndex["exit"] {
            for i in 0...lastExitIndex {
                if let north = prototype["exit.north", i]?.link {
                    exits[.north] = north
                }
                if let east = prototype["exit.east", i]?.link {
                    exits[.east] = east
                }
                if let south = prototype["exit.south", i]?.link {
                    exits[.south] = south
                }
                if let west = prototype["exit.west", i]?.link {
                    exits[.west] = west
                }
                if let up = prototype["exit.up", i]?.link {
                    exits[.up] = up
                }<commit_msg>Add FIXME<commit_after>//
// Room.swift
//
// This source file is part of the SMUD open source project
//
// Copyright (c) 2016 SMUD project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SMUD project authors
//

import Foundation

public class Room {
    public let prototype: Entity
    public var areaInstance: AreaInstance

    public var id: String
    public var title: String
    public var description: String
    public var exits = [Direction: Link]()
    public var creatures = [Creature]()
    public let fight: Fight

    public var orderedDirections: [Direction] {
        var result = [Direction]()
        for direction in Direction.orderedDirections {
            guard exits[direction] != nil else { continue }
            result.append(direction)
        }
        return result
    }

    public var orderedExits: [(Direction, Link)] {
        var result = [(Direction, Link)]()
        for direction in Direction.orderedDirections {
            guard let exit = exits[direction] else { continue }
            result.append((direction, exit))
        }
        return result
    }
    
    public init(prototype: Entity, instance: AreaInstance) {
        fight = Fight(smud: instance.area.world.smud)
        self.prototype = prototype
        self.areaInstance = instance

        let id = prototype["room"]?.string ?? ""
        assert(id != "")
        self.id = id
        
        title = prototype["title"]?.string ?? "No title"
        description = prototype["description"]?.string ?? ""
    }

    // FIXME: create prototype in digRoom(), add it to world, construct Room from it
    public convenience init(id: String, instance: AreaInstance) {
        let prototype = Entity()
        _ = prototype.add(name: "room", value: .tag(id))
        self.init(prototype: prototype, instance: instance)
    }
    
    public func reset(mode: AreaInstance.ResetMode) {
        exits.removeAll(keepingCapacity: true)
        
        if let lastExitIndex = prototype.lastStructureIndex["exit"] {
            for i in 0...lastExitIndex {
                if let north = prototype["exit.north", i]?.link {
                    exits[.north] = north
                }
                if let east = prototype["exit.east", i]?.link {
                    exits[.east] = east
                }
                if let south = prototype["exit.south", i]?.link {
                    exits[.south] = south
                }
                if let west = prototype["exit.west", i]?.link {
                    exits[.west] = west
                }
                if let up = prototype["exit.up", i]?.link {
                    exits[.up] = up
                }
{'fraction_non_alphanumeric': 0.1045811279430553, 'fraction_numerical': 0.0025552108048914036, 'mean_word_length': 1.8842105263157896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3599023', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1372, 'n_words': 438}