/// <summary> /// Get the movement cost for this tile for a given movement type. /// This will trigger populating the movement data for this tile data instance. /// If no movement data is found it will return NaN to indicate this tile is impassible. /// </summary> /// <param name="movementType">The type of movement to check.</param> /// <returns>The movement cost of the tile for the given movement type. Retuns NaN if no movement data is found.</returns> public float GetMovementCost(MovementType movementType) { // Make sure our dumb dictionary of stupidity is populated before we check movement data for this tile data PopulateMovementData(); return(MovementData.ContainsKey(movementType) && MovementData[movementType].Passable ? MovementData[movementType].MovementCost : float.NaN); }
/// <summary> /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /// /// why do I do these things /// </summary> public void PopulateMovementData() { // Only populate the MovementData dictionary once, if (MovementData.Any() || movementTileData == null) { return; } foreach (var movementData in movementTileData.movementData) { if (MovementData.ContainsKey(movementData.movementType)) { continue; } MovementData.Add(movementData.movementType, movementData); } // If we have a general movement rule then assign it to any movement types that don't have data if (MovementData.ContainsKey(MovementType.General)) { var generalMovementRule = MovementData[MovementType.General]; foreach (var movementType in Enum.GetValues(typeof(MovementType)).Cast <MovementType>()) { if (MovementData.ContainsKey(movementType)) { continue; } MovementData.Add(movementType, generalMovementRule); } } }