| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file localgame.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created level.c and menu.c |
| 10 | * - 3rd of February 2009: Renamed level.c to level.cpp and menu.c to menu.cpp |
| 11 | * - 9th March 2009: Created game.cpp from parts of menu.cpp and level.cpp |
| 12 | * - 3rd June 2009: Created network.cpp from parts of game.cpp |
| 13 | * - 18th July 2009: Created servergame.cpp from parts of game.cpp |
| 14 | * - 18th July 2009: Created clientgame.cpp from parts of game.cpp |
| 15 | * - 3rd October 2010: Created localgame.cpp from parts of game.cpp |
| 16 | * |
| 17 | * @par Licence: |
| 18 | * Copyright (c) 2005-2017 AJ Thomson |
| 19 | * |
| 20 | * OpenJazz is distributed under the terms of |
| 21 | * the GNU General Public License, version 2.0 |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include "game.h" |
| 27 | #include "gamemode.h" |
| 28 | |
| 29 | #include "player/player.h" |
| 30 | #include "setup.h" |
| 31 | #include "util.h" |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * Create a single-player local game |
| 36 | * |
| 37 | * @param firstLevel File name of the first level to play |
| 38 | * @param gameDifficulty Difficulty setting |
| 39 | */ |
| 40 | LocalGame::LocalGame (const char *firstLevel, difficultyType gameDifficulty) { |
| 41 | |
| 42 | levelFile = createString(firstLevel); |
| 43 | levelType = getLevelType(firstLevel); |
| 44 | |
| 45 | difficulty = gameDifficulty; |
| 46 | |
| 47 | mode = new SingleGameMode(); |
| 48 | |
| 49 | // Create the player |
| 50 | nPlayers = 1; |
| 51 | localPlayer = players = new Player[1]; |
| 52 | localPlayer->init(this, setup.characterName, NULL, 0); |
| 53 | |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /** |
| 58 | * Destroy local game |
| 59 | */ |
| 60 | LocalGame::~LocalGame () { |
| 61 | |
| 62 | delete mode; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * Set the next level |
| 69 | * |
| 70 | * @param fileName The file name of the next level |
| 71 | * |
| 72 | * @return Error code |
| 73 | */ |
| 74 | int LocalGame::setLevel (char *fileName) { |
| 75 | |
| 76 | if (levelFile) delete[] levelFile; |
| 77 | |
| 78 | if (fileName) { |
| 79 | |
| 80 | levelFile = createString(fileName); |
| 81 | levelType = getLevelType(fileName); |
| 82 | |
| 83 | } else levelFile = NULL; |
| 84 | |
| 85 | return E_NONE; |
| 86 | |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * No data is sent in local games |
| 92 | * |
| 93 | * @param buffer Data that will not be sent. First byte indicates length. |
| 94 | */ |
| 95 | void LocalGame::send (unsigned char *buffer) { |
| 96 | |
| 97 | (void)buffer; |
| 98 | |
| 99 | // Do nothing |
| 100 | |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * Game iteration - nothing to be done in local games |
| 106 | * |
| 107 | * @param ticks Current time |
| 108 | * |
| 109 | * @return Error code |
| 110 | */ |
| 111 | int LocalGame::step (unsigned int ticks) { |
| 112 | |
| 113 | (void)ticks; |
| 114 | |
| 115 | // Do nothing |
| 116 | |
| 117 | return E_NONE; |
| 118 | |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /** |
| 123 | * No points are assigned to teams in local games |
| 124 | * |
| 125 | * @param team Team to receive point |
| 126 | */ |
| 127 | void LocalGame::score (unsigned char team) { |
| 128 | |
| 129 | (void)team; |
| 130 | |
| 131 | // Do nothing |
| 132 | |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /** |
| 137 | * Set the checkpoint |
| 138 | * |
| 139 | * @param gridX X-coordinate (in tiles) of the checkpoint |
| 140 | * @param gridY Y-coordinate (in tiles) of the checkpoint |
| 141 | */ |
| 142 | void LocalGame::setCheckpoint (int gridX, int gridY) { |
| 143 | |
| 144 | checkX = gridX; |
| 145 | checkY = gridY; |
| 146 | |
| 147 | } |