1 #ifndef ENVIRONMENT_DEFINE 2 #define ENVIRONMENT_DEFINE 3 4 /* 5 * atanks - obliterate each other with oversize weapons 6 * Copyright (C) 2003 Thomas Hudson 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * */ 22 23 24 #include "main.h" 25 #include "network.h" 26 #include "gfxData.h" 27 #include "text.h" 28 29 30 // As everything depends on environment.h, PLAYER, TANK and VIRTUAL_OBJECT 31 // Must be forwarded here, and included before the ENVIRONMENT definition 32 class VIRTUAL_OBJECT; 33 class TANK; 34 class PLAYER; 35 36 37 #ifndef HAS_DIRENT 38 # if defined(ATANKS_IS_MSVC) 39 # include "extern/dirent.h" 40 # else 41 # include <dirent.h> 42 # endif // Linux 43 # define HAS_DIRENT 1 44 #endif //HAS_DIRENT 45 46 47 #ifndef MAX_GRAVITY_DELAY 48 # define GRAVITY_DELAY 200 49 # define MAX_GRAVITY_DELAY 3 50 #endif 51 52 #define SPRING_CHANGE 1.25 53 #define BOUNCE_CHANGE 0.90 54 55 #define GET_R(x) ((x & 0xff0000) >> 16) 56 #define GET_G(x) ((x & 0x00ff00) >> 8) 57 #define GET_B(x) ( x & 0x0000ff) 58 59 60 // Something from externs.h can not be used via include 61 // due to circular dependencies. 62 extern int32_t GREY; 63 extern int32_t GREEN; 64 65 // Defined in sound.cpp: 66 extern int32_t MAX_VOLUME_FACTOR; 67 68 69 /** @class ENVIRONMENT 70 * @brief Fixed values of the current environment the game takes place in. 71 * 72 * This class holds all values and the corresponding methods that define 73 * the gaming environment. 74 * 75 * This means that all values in here must be set on game round start and 76 * must not change until the game round ends. 77 * 78 * So basically this class consolidates everything set up with the options 79 * menu and by the game round initialization. 80 * 81 * Everything that can change between the game round start and the game round 82 * end has to be managed by GLOBALDATA. 83 **/ 84 class ENVIRONMENT 85 { 86 public: 87 88 /* ----------------------------------- 89 * --- Constructors and destructor --- 90 * ----------------------------------- 91 */ 92 explicit ENVIRONMENT (); 93 ~ENVIRONMENT (); 94 95 96 /* ---------------------- 97 * --- Public methods --- 98 * ---------------------- 99 */ 100 void addGamePlayer (PLAYER* player_); 101 PLAYER* createNewPlayer (const char* player_name); 102 void creditWinners (int32_t winner); 103 void decreaseVolume (); 104 void deletePermPlayer (PLAYER* player_); 105 void destroy (); // Must be called before allegro shutdown 106 void find_config_dir (); 107 bool find_data_dir (); 108 void first_init (); // Used for the first init after creation 109 void genItemsList (); 110 int32_t getPlayerByName (const char* player_name); 111 void increaseVolume (); 112 int32_t ingamemenu (); 113 void initialise (); // Does a regular initialization 114 bool isItemAvailable (int32_t itemNum); 115 bool loadBackgroundMusic(); 116 bool loadBitmaps (); 117 bool loadFonts (); 118 bool loadGameFiles (); 119 void load_from_file (FILE *file); 120 bool loadSounds (); 121 void load_text_files (); 122 void newRound (); 123 void removeGamePlayer (PLAYER* player_); 124 void Reset_Options (); 125 bool save_to_file (FILE *file); 126 bool sendToClients (const char* message); // send a short message to all network clients 127 void set_fps (int32_t new_FPS); 128 void window_update (int32_t x, int32_t y, int32_t w, int32_t h); 129 130 131 /* ---------------------- 132 * --- Public members --- 133 * ---------------------- 134 */ 135 136 PLAYER** allPlayers = nullptr; 137 int32_t availableItems[THINGS]; 138 SAMPLE* background_music = nullptr; 139 char** bitmap_filenames = nullptr; 140 int32_t boxedMode = BM_OFF; 141 BITMAP** button = nullptr; 142 bool campaign_mode = false; 143 double campaign_rounds = 0.; // 20% of the total round number 144 bool check_for_updates = true; 145 int32_t colourDepth = 0; 146 int32_t colourTheme = CT_CRISPY; // land and sky gradiant theme 147 char configDir[PATH_MAX + 1]; 148 int32_t current_wallType = 0; 149 int32_t custom_background = 0; 150 char dataDir[PATH_MAX + 1]; 151 int32_t debris_level = 1; 152 bool detailedLandscape = false; 153 bool detailedSky = false; 154 bool ditherGradients = true; 155 bool divide_money = false; 156 bool do_box_wrap = false; 157 bool drawBackground = true; 158 bool dynamicMenuBg = true; 159 bool fadingText = false; 160 int32_t falling_dirt_balls = 0; 161 int32_t fog = 0; 162 int32_t fontHeight = 0; // Fixed in ctor, no calls to text_height(font) needed. 163 double FPS_mod = 0.; // Pre-calculated, used in many places. 164 int32_t frames_per_second = 0; 165 int32_t full_screen = FULL_SCREEN_FALSE; 166 char game_name[GAMENAMELEN + 1]; 167 sGfxData gfxData; 168 double gravity = 0.15; 169 int32_t halfHeight = DEFAULT_SCREEN_HEIGHT / 2; 170 int32_t halfWidth = DEFAULT_SCREEN_WIDTH / 2; 171 double interest = 1.25; 172 int32_t itemtechLevel = 5; 173 bool isBoxed = false; 174 bool isGameLoaded = true; 175 int32_t landSlideDelay = MAX_GRAVITY_DELAY; 176 int32_t landSlideType = SLIDE_GRAVITY; 177 int32_t landType = LAND_RANDOM; 178 eLanguages language = EL_ENGLISH; 179 int32_t lightning = 0; 180 bool loadGame = false; 181 FONT* main_font = nullptr; 182 int32_t maxFireTime = 0; 183 int32_t maxNumTanks = 0; 184 double maxVelocity = 0.; 185 int32_t max_screen_updates = 64; 186 int32_t menuBeginY = 0; 187 int32_t menuEndY = 0; 188 int32_t meteors = 0; 189 BITMAP** misc = nullptr; 190 BITMAP** missile = nullptr; 191 int32_t mouseclock = 0; 192 bool nameAboveTank = true; 193 bool network_enabled = false; 194 int32_t network_port = DEFAULT_NETWORK_PORT; 195 double nextCampaignRound = 0; // When AI players will be raised next 196 int32_t numAvailable = 0; 197 int32_t numGamePlayers = 0; 198 int32_t numHumanPlayers = 0; 199 int32_t numPermanentPlayers = 0; 200 int32_t number_of_bitmaps = 0; 201 bool osMouse = true; // whether we should use the OS or custom mouse 202 bool play_music = true; 203 PLAYER** players = nullptr; 204 PLAYER* playerOrder[MAXPLAYERS]; 205 uint32_t rounds = 5; 206 int32_t satellite = 0; 207 uint32_t saved_gameindex = 0; 208 const char** saved_game_list = nullptr; 209 uint32_t saved_game_list_size = 0; 210 int32_t scoreHitUnit = 75; 211 int32_t scoreRoundWinBonus = 10000; 212 int32_t scoreSelfHit = 25; 213 int32_t scoreTeamHit = 10; 214 int32_t scoreUnitDestroyBonus = 5000; 215 int32_t scoreUnitSelfDestroy = 2500; 216 int32_t screenHeight = DEFAULT_SCREEN_HEIGHT; 217 int32_t screenWidth = DEFAULT_SCREEN_WIDTH; 218 double sellpercent = 0.80; 219 char server_name[129]; 220 char server_port[129]; 221 bool shadowedText = true; 222 bool showAIFeedback = true; 223 bool showFPS = false; 224 int32_t skipComputerPlay = SKIP_HUMANS_DEAD; 225 BITMAP* sky = nullptr; 226 double slope[360][2]; 227 int32_t sound_driver = SD_AUTODETECT; 228 bool sound_enabled = true; 229 SAMPLE** sounds = nullptr; 230 int32_t startmoney = 15000; 231 BITMAP** stock = nullptr; 232 bool swayingText = true; 233 BITMAP** tank = nullptr; 234 BITMAP** tankgun = nullptr; 235 int32_t temp_screenHeight = 0; // 0 to detect command line arguments 236 int32_t temp_screenWidth = 0; // versus loaded configuration. 237 int32_t time_to_fall = 0; // amount of time dirt will hover 238 BITMAP** title = nullptr; 239 int32_t turntype = TURN_RANDOM; 240 double viscosity = 0.5; 241 int32_t violent_death = 0; 242 int32_t voices = 0; 243 int32_t volley_delay = 10; // Delay factor for volley shots, 5-50 244 int32_t volume_factor = MAX_VOLUME_FACTOR; 245 int32_t wallColour = GREEN; 246 int32_t wallType = WALL_RUBBER; 247 int32_t weapontechLevel = 5; 248 BOX window; 249 int32_t windstrength = 8; 250 int32_t windvariation = 1; 251 252 // Text structures holding (translated) lines of in game text 253 TEXTBLOCK* gloat = nullptr; 254 TEXTBLOCK* ingame = nullptr; 255 TEXTBLOCK* instructions = nullptr; 256 TEXTBLOCK* panic = nullptr; 257 TEXTBLOCK* kamikaze = nullptr; 258 TEXTBLOCK* retaliation = nullptr; 259 TEXTBLOCK* revenge = nullptr; 260 TEXTBLOCK* suicide = nullptr; 261 TEXTBLOCK* war_quotes = nullptr; 262 263 264 private: 265 266 /* ----------------------- 267 * --- Private methods --- 268 * ----------------------- 269 */ 270 271 272 /* ----------------------- 273 * --- Private members --- 274 * ----------------------- 275 */ 276 277 DIR* music_dir = nullptr; 278 }; 279 280 281 #define HAS_ENVIRONMENT 1 282 283 #endif 284 285