1 /************************************************************************************ 2 3 AstroMenace 4 Hardcore 3D space scroll-shooter with spaceship upgrade possibilities. 5 Copyright (c) 2006-2019 Mikhail Kurinnoi, Viewizard 6 7 8 AstroMenace is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 AstroMenace 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 AstroMenace. If not, see <https://www.gnu.org/licenses/>. 20 21 22 Website: https://viewizard.com/ 23 Project: https://github.com/viewizard/astromenace 24 E-mail: viewizard@viewizard.com 25 26 *************************************************************************************/ 27 28 #ifndef CONFIG_CONFIG_H 29 #define CONFIG_CONFIG_H 30 31 #include "../core/base.h" 32 #include "../game/weapon_panel.h" 33 34 // NOTE switch to nested namespace definition (namespace A::B::C { ... }) (since C++17) 35 namespace viewizard { 36 namespace astromenace { 37 38 // since we have POD structures that could be changed in new version, 39 // make sure we load proper profiles and top scores 40 // note, xml tag can't contain space characters, use underline instead 41 constexpr char CONFIG_VERSION[]{"1.4"}; 42 // TODO remove "reserved" in sPilotProfile on CONFIG_VERSION's update 43 // FIXME WeaponAltControlData in sPilotProfile should be int, look at sGameConfig controls 44 // we store SDL_Keycode (int32_t) here 45 46 namespace config { 47 // (!) changes make previous configuration file incompatible 48 49 // maximum profiles 50 constexpr int MAX_PROFILES{5}; 51 // profile name size 52 constexpr unsigned PROFILE_NAME_SIZE{1024}; 53 // maximum possible missions number for arrays in pilot profile 54 constexpr unsigned MAX_MISSIONS{100}; 55 // maximum ship's weapon slots 56 constexpr unsigned MAX_WEAPONS{6}; 57 // maximum hints 58 constexpr unsigned MAX_HINTS{10}; 59 60 } // config 61 62 namespace config { 63 // (!) changes could corrupt 2D rendering 64 65 constexpr float VirtualWidth_Wide{1228.0f}; 66 constexpr float VirtualHeight_Wide{768.0f}; 67 68 constexpr float VirtualWidth_Standard{1024.0f}; 69 constexpr float VirtualHeight_Standard{768.0f}; 70 71 } // config 72 73 // This structure should be POD, since we "pack" it into config file 74 // as memory block. Don't use std::string or any containers here. 75 struct sPilotProfile { 76 bool Used{false}; 77 78 char Name[config::PROFILE_NAME_SIZE]; 79 80 // difficulty related settings 81 uint8_t EnemyWeaponPenalty{2}; // Enemy weapon fire penalty [1, 3] 82 uint8_t EnemyArmorPenalty{2}; // Enemy armor penalty [1, 4] 83 uint8_t EnemyTargetingSpeedPenalty{2}; // Enemy targeting speed penalty [1, 4] 84 uint8_t UnlimitedAmmo{1}; // 0 - limited ammo, 1 - unlimited ammo 85 // note, we use "Limited Ammo" option in menu, but UnlimitedAmmo variable 86 uint8_t UndestroyableWeapon{1}; // 0 - destroyable, 1 - undestroyable 87 // note, we use "Destroyable Weapon" option, but UndestroyableWeapon variable 88 uint8_t WeaponTargetingMode{0}; // 0 - simulator, 1 - arcade 89 uint8_t SpaceShipControlMode{1}; // 0 - simulator, 1 - arcade 90 uint8_t reserved{0}; 91 92 // default player's ship (first ship, without additional hull upgrades) 93 uint8_t ShipHull{1}; 94 uint8_t ShipHullUpgrade{1}; 95 float ArmorStatus{30.0f}; 96 97 // weapon related settings 98 uint8_t Weapon[config::MAX_WEAPONS]; 99 int WeaponAmmo[config::MAX_WEAPONS]; 100 float WeaponSlotYAngle[config::MAX_WEAPONS]; // weapon Y angle 101 uint8_t WeaponControl[config::MAX_WEAPONS]; // 1 - primary fire control, 2 - secondary fire control, 3 - both 102 uint8_t WeaponAltControl[config::MAX_WEAPONS]; // 0 - disabled, 1 - keyboard, 2 - mouse, 3 - joystick 103 uint8_t WeaponAltControlData[config::MAX_WEAPONS]; // alt control data 104 105 // default systems for default ship 106 uint8_t EngineSystem{1}; 107 uint8_t TargetingSystem{1}; 108 uint8_t AdvancedProtectionSystem{1}; 109 uint8_t PowerSystem{1}; 110 uint8_t TargetingMechanicSystem{1}; 111 112 int Money{200}; 113 int Experience{0}; 114 115 uint8_t PrimaryWeaponFireMode{2}; // 1 - shoot a volley, 2 - shoot a burst 116 uint8_t SecondaryWeaponFireMode{2}; // 1 - shoot a volley, 2 - shoot a burst 117 118 int OpenLevelNum{0}; // allowed missions 119 int LastMission{0}; // last chosen mission 120 121 int ByMissionExperience[config::MAX_MISSIONS]; // experience for each mission 122 int MissionReplayCount[config::MAX_MISSIONS]; // how many times mission was replayed 123 sPilotProfilesPilotProfile124 sPilotProfile() 125 { 126 memset(Name, 0, config::PROFILE_NAME_SIZE); 127 128 for (unsigned i = 0; i < config::MAX_WEAPONS; i++) { 129 Weapon[i] = 0; 130 WeaponAmmo[i] = 0; 131 WeaponSlotYAngle[i] = 0.0f; 132 WeaponControl[i] = 0; 133 WeaponAltControl[i] = 0; 134 WeaponAltControlData[i] = 0; 135 } 136 137 // default weapons for default ship 138 Weapon[0] = 1; 139 WeaponAmmo[0] = 3000; 140 WeaponControl[0] = 1; 141 Weapon[1] = 1; 142 WeaponAmmo[1] = 3000; 143 WeaponControl[1] = 1; 144 Weapon[2] = 16; 145 WeaponAmmo[2] = 200; 146 WeaponControl[2] = 2; 147 148 for (unsigned i = 0; i < config::MAX_MISSIONS; i++) { 149 ByMissionExperience[i] = 0; 150 MissionReplayCount[i] = 0; 151 } 152 } 153 }; 154 155 struct sGameConfig { 156 unsigned int MenuLanguage{0}; // en 157 unsigned int VoiceLanguage{0}; // en 158 int FontNumber{0}; // first font from the list 159 160 int MusicVolume{8}; // in-game music volume [0, 10] 161 int SoundVolume{10}; // in-game sfx volume [0, 10] 162 int VoiceVolume{10}; // in-game voice volume [0, 10] 163 164 int DisplayIndex{0}; 165 int Width{1280}; // view size width 166 int Height{768}; // view size height 167 bool Fullscreen{true}; // fullscreen mode (if false - windowed mode) 168 169 // FIXME should be removed, vw_GetInternalResolution() should be used instead in code 170 // also, all directly usage of 1228/1024/768 should be removed as well 171 float InternalWidth{1228.0f}; // internal resolution's width 172 float InternalHeight{768.0f}; // internal resolution's height 173 174 int VSync{0}; 175 int Brightness{5}; 176 int MSAA{0}; // MS anti aliasing 177 int CSAA{0}; // CS anti aliasing 178 179 int VisualEffectsQuality{0}; // VisualEffectsQuality is inverted (0 - all effects, 2 - minimum effects) 180 int AnisotropyLevel{1}; // textures anisotropic filtering level 181 bool UseGLSL120{false}; // 120 (OpenGL 2.1) 182 int ShadowMap{0}; // gfx (shadow map) 183 int MaxPointLights{3}; // lights point max quantity 184 185 // keyboard 186 int KeyBoardLeft{SDLK_LEFT}; 187 int KeyBoardRight{SDLK_RIGHT}; 188 int KeyBoardUp{SDLK_UP}; 189 int KeyBoardDown{SDLK_DOWN}; 190 int KeyBoardPrimary{SDLK_LCTRL}; 191 int KeyBoardSecondary{SDLK_SPACE}; 192 // mouse 193 int MousePrimary{SDL_BUTTON_LEFT}; 194 int MouseSecondary{SDL_BUTTON_RIGHT}; 195 bool MouseControl{true}; 196 int ControlSensivity{5}; 197 // joystick 198 int JoystickPrimary{0}; 199 int JoystickSecondary{1}; 200 int JoystickNum{0}; 201 int JoystickDeadZone{2}; 202 203 float GameSpeed{1.5f}; 204 bool ShowFPS{false}; 205 eWeaponPanelView WeaponPanelView{eWeaponPanelView::full}; 206 207 sPilotProfile Profile[config::MAX_PROFILES]; 208 209 int LastProfile{-1}; // last used pilot profile 210 211 // tips and hints status 212 bool NeedShowHint[config::MAX_HINTS]; 213 214 int MenuScript{0}; // last used menu background script number 215 sGameConfigsGameConfig216 sGameConfig() 217 { 218 for (unsigned i = 0; i < config::MAX_HINTS; i++) { 219 NeedShowHint[i] = true; 220 } 221 } 222 }; 223 224 225 // Get configuration for read only. 226 const sGameConfig &GameConfig(); 227 // Get configuration for read and write. 228 sGameConfig &ChangeGameConfig(); 229 // Configure virtual internal resolution by view size. 230 void ConfigVirtualInternalResolution(); 231 // Load configuration file. 232 bool LoadXMLConfigFile(bool NeedResetConfig); 233 // Save configuration file. 234 void SaveXMLConfigFile(); 235 236 // Game's difficulty in %, calculated by profile settings (result is cached). 237 // For more speed, we don't check ProfileNumber for [0, config::MAX_PROFILES) range. 238 enum class eDifficultyAction { 239 Get, 240 Update, 241 UpdateAll 242 }; 243 int ProfileDifficulty(int ProfileNumber, eDifficultyAction Action = eDifficultyAction::Get); 244 245 } // astromenace namespace 246 } // viewizard namespace 247 248 #endif // CONFIG_CONFIG_H 249