| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2013 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 "carfactory.hpp" |
| 17 | |
| 18 | #include <MCAssetManager> |
| 19 | |
| 20 | std::unique_ptr<Car> CarFactory::buildCar(size_t index, size_t carCount, Game & game) |
| 21 | { |
| 22 | const int defaultPower = 200000; // This in Watts |
| 23 | const float defaultDrag = 2.5f; |
| 24 | |
| 25 | static std::map<size_t, std::string> carImageMap = { |
| 26 | { 0, "carPink" }, |
| 27 | { 1, "carGrey" }, |
| 28 | { 2, "carDarkRed" }, |
| 29 | { 3, "carGreen" }, |
| 30 | { 4, "carViolet" }, |
| 31 | { 5, "carCyan" }, |
| 32 | { 6, "carBrown" }, |
| 33 | { 7, "carDarkGreen" }, |
| 34 | { 8, "carBlue" }, |
| 35 | { 9, "carRed" }, |
| 36 | { 10, "carOrange" }, |
| 37 | { 11, "carBlack" } |
| 38 | }; |
| 39 | |
| 40 | Car::Description desc; |
| 41 | |
| 42 | // Select car image |
| 43 | std::string carImage("carYellow"); |
| 44 | if (carImageMap.count(index)) |
| 45 | { |
| 46 | carImage = carImageMap[index]; |
| 47 | } |
| 48 | |
| 49 | if (index == 0 || (index == 1 && game.hasTwoHumanPlayers())) |
| 50 | { |
| 51 | desc.power = defaultPower; |
| 52 | desc.dragQuadratic = defaultDrag; |
| 53 | desc.accelerationFriction = 0.55f * Game::instance().difficultyProfile().accelerationFrictionMultiplier(true); |
| 54 | |
| 55 | return std::make_unique<Car>(desc, MCAssetManager::surfaceManager().surface(carImage), index, true); |
| 56 | } |
| 57 | else if (game.hasComputerPlayers()) |
| 58 | { |
| 59 | // Introduce some variance to the power of computer players so that the |
| 60 | // slowest cars have less power than the human player and the fastest |
| 61 | // cars have more power than the human player. |
| 62 | desc.power = defaultPower / 2 + (index + 1) * defaultPower / carCount; |
| 63 | desc.accelerationFriction = (0.3f + 0.4f * float(index + 1) / carCount) * Game::instance().difficultyProfile().accelerationFrictionMultiplier(false); |
| 64 | desc.dragQuadratic = defaultDrag; |
| 65 | |
| 66 | return std::make_unique<Car>(desc, MCAssetManager::surfaceManager().surface(carImage), index, false); |
| 67 | } |
| 68 | |
| 69 | return nullptr; |
| 70 | } |