| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2015 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #include "difficultyprofile.hpp" |
| 17 | |
| 18 | #include <cassert> |
| 19 | |
| 20 | DifficultyProfile * DifficultyProfile::m_instance = nullptr; |
| 21 | |
| 22 | DifficultyProfile::DifficultyProfile(Difficulty difficulty) |
| 23 | : m_difficulty(difficulty) |
| 24 | { |
| 25 | assert(!m_instance); |
| 26 | m_instance = this; |
| 27 | } |
| 28 | |
| 29 | DifficultyProfile & DifficultyProfile::instance() |
| 30 | { |
| 31 | assert(m_instance); |
| 32 | return *m_instance; |
| 33 | } |
| 34 | |
| 35 | void DifficultyProfile::setDifficulty(Difficulty difficulty) |
| 36 | { |
| 37 | m_difficulty = difficulty; |
| 38 | |
| 39 | emit difficultyChanged(); |
| 40 | } |
| 41 | |
| 42 | DifficultyProfile::Difficulty DifficultyProfile::difficulty() const |
| 43 | { |
| 44 | return m_difficulty; |
| 45 | } |
| 46 | |
| 47 | bool DifficultyProfile::hasTireWearOut() const |
| 48 | { |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | bool DifficultyProfile::hasBodyDamage() const |
| 53 | { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | float DifficultyProfile::accelerationFrictionMultiplier(bool isHuman) const |
| 58 | { |
| 59 | switch (m_difficulty) |
| 60 | { |
| 61 | case Difficulty::Easy: |
| 62 | return isHuman ? 0.70f : 0.70f * 0.85f; |
| 63 | case Difficulty::Medium: |
| 64 | return isHuman ? 0.85f : 0.85f * 0.85f; |
| 65 | case Difficulty::Hard: |
| 66 | return isHuman ? 1.0f : 1.0f * 0.9f; |
| 67 | } |
| 68 | |
| 69 | return 1.0f; |
| 70 | } |
| 71 | |
| 72 | DifficultyProfile::~DifficultyProfile() |
| 73 | { |
| 74 | m_instance = nullptr; |
| 75 | } |