diff --git a/Descent3/Briefing.cpp b/Descent3/Briefing.cpp index fb147e87..34d76e9c 100644 --- a/Descent3/Briefing.cpp +++ b/Descent3/Briefing.cpp @@ -231,7 +231,7 @@ static tBriefingTag HotTags[] = { {"#PLEVELNUM#", TAG_PLEVELNUM, -1}, {"#NLEVELNUM#", TAG_NLEVELNUM, -1}, }; -static const int NumHotTags = std::size(HotTags); +static constexpr int NumHotTags = std::size(HotTags); static int osb_xoff = 0, osb_yoff = 0; static int current_screen = -1; diff --git a/Descent3/CtlCfgElem.cpp b/Descent3/CtlCfgElem.cpp index 4d4d5f99..e5f7ae15 100644 --- a/Descent3/CtlCfgElem.cpp +++ b/Descent3/CtlCfgElem.cpp @@ -385,7 +385,7 @@ static char Ctltext_KeyBindings[][16] = {"", "", ""}; -static int16_t key_binding_indices[] = { +static constexpr int16_t key_binding_indices[] = { KEY_BACKSP, KEY_TAB, KEY_ENTER, KEY_LCTRL, KEY_LSHIFT, KEY_RSHIFT, KEY_PADMULTIPLY, KEY_LALT, KEY_SPACEBAR, KEY_CAPSLOCK, 0x45, KEY_SCROLLOCK, KEY_PAD7, KEY_PAD8, KEY_PAD9, KEY_PADMINUS, KEY_PAD4, KEY_PAD5, KEY_PAD6, KEY_PADPLUS, KEY_PAD1, KEY_PAD2, KEY_PAD3, KEY_PAD0, diff --git a/Descent3/GameCheat.cpp b/Descent3/GameCheat.cpp index 5321da81..2235b197 100644 --- a/Descent3/GameCheat.cpp +++ b/Descent3/GameCheat.cpp @@ -160,7 +160,7 @@ char OldCheatBuffer[] = "AAAAAAAAAAAAAAA"; extern bool Force_one_texture; extern uint8_t AutomapVisMap[MAX_ROOMS]; -const char *LamerCheats[] = { +constexpr const char *LamerCheats[] = { "?E9FI=()", // gabbagabbahey "=-OQESN1", // motherlode "C= 0 && teamnum <= 3); - int flags[] = {RF_GOAL1, RF_GOAL2, RF_GOAL3, RF_GOAL4}; + static constexpr int flags[] = {RF_GOAL1, RF_GOAL2, RF_GOAL3, RF_GOAL4}; for (int i = 0; i <= Highest_room_index; i++) { if (Rooms[i].used && (Rooms[i].flags & flags[teamnum])) { diff --git a/Descent3/TelComCargo.cpp b/Descent3/TelComCargo.cpp index 6c800bff..a45d709f 100644 --- a/Descent3/TelComCargo.cpp +++ b/Descent3/TelComCargo.cpp @@ -125,7 +125,7 @@ struct tLineInfo { int id; }; -tLineInfo StatusLines[] = { +static constexpr tLineInfo StatusLines[] = { {LIT_TITLE, "Ship Status", LID_NONE}, {LIT_VALUE, "Shields", LID_SHIELDS}, {LIT_VALUE, "Energy", LID_ENERGY}, {LIT_TITLE, "Primaries", LID_PRIMARIES}, {LIT_TITLE, "Secondaries", LID_SECONDARIES}, {LIT_TITLE, "Counter Measures", LID_COUNTERMEASURES}, diff --git a/Descent3/fireball.cpp b/Descent3/fireball.cpp index 2ba31aba..6bd8154d 100644 --- a/Descent3/fireball.cpp +++ b/Descent3/fireball.cpp @@ -1315,7 +1315,7 @@ void PlayObjectExplosionSound(object *objp) { if (sound != -1) Sound_system.Play3dSound(sound, SND_PRIORITY_HIGH, objp); } -const char *dead_object_types[] = { +static constexpr const char *dead_object_types[] = { "swatter", "swatter(deadmodel)", "Hangturret", "Securityturret(DEAD)", "Lance", "Lance(DEAD)", "L10 swatter", "swatter(deadmodel)", }; @@ -2396,18 +2396,18 @@ int GetRandomExplosion(float size) { // TODO: MTS: only found in this file. // Returns a random medium sized explosion int GetRandomMediumExplosion() { - int choices[] = {MED_EXPLOSION_INDEX, MED_EXPLOSION_INDEX2, MED_EXPLOSION_INDEX3}; + static constexpr int choices[] = {MED_EXPLOSION_INDEX, MED_EXPLOSION_INDEX2, MED_EXPLOSION_INDEX3}; int pick = ps_rand() % 3; return (choices[pick]); } int GetRandomSmallExplosion() { - int choices[] = {SMALL_EXPLOSION_INDEX, SMALL_EXPLOSION_INDEX2}; + static constexpr int choices[] = {SMALL_EXPLOSION_INDEX, SMALL_EXPLOSION_INDEX2}; int pick = ps_rand() % 2; return (choices[pick]); } // TODO: MTS: only found in this file. int GetRandomBillowingExplosion() { - int choices[] = {BILLOWING_INDEX, MED_EXPLOSION_INDEX2}; + static constexpr int choices[] = {BILLOWING_INDEX, MED_EXPLOSION_INDEX2}; int pick = ps_rand() % 2; return (choices[pick]); } diff --git a/Descent3/localization.cpp b/Descent3/localization.cpp index 68df3d9d..711c7863 100644 --- a/Descent3/localization.cpp +++ b/Descent3/localization.cpp @@ -103,7 +103,7 @@ struct tLangTag { int length; }; -tLangTag Language_tags[] = { +static tLangTag Language_tags[] = { {"!=!", -1}, // English {"!G!", -1}, // German {"!S!", -1}, // Spanish @@ -120,7 +120,7 @@ int String_table_size = 0; char **String_table = NULL; // list of the string table files, they will be loaded in the order they are listed -const char *String_table_list[] = {"D3.STR", NULL}; +constexpr const char *String_table_list[] = {"D3.STR", NULL}; const char *_Error_string = "!!ERROR MISSING STRING!!"; const char *_Empty_string = "\0"; diff --git a/Descent3/multisafe.cpp b/Descent3/multisafe.cpp index 84acbac2..9c7b9840 100644 --- a/Descent3/multisafe.cpp +++ b/Descent3/multisafe.cpp @@ -2498,7 +2498,7 @@ void msafe_DoPowerup(msafe_struct *mstruct) { } } // Data for primary powerups -struct { +static constexpr struct { const char *name; int weapon_index; int pickup_msg, already_have_msg, ammo_msg, full_msg; @@ -2514,7 +2514,7 @@ struct { {"Omegacannon", OMEGA_INDEX, TXI_MSG_OMEGA, TXI_MSG_OMEGAHAVE, -1, -1}, }; #define NUM_POWERUP_TYPES_PRIMARY std::size(powerup_data_primary) -struct { +static constexpr struct { const char *name; int weapon_index; int added_one_msg, added_multi_msg, full_msg; @@ -2535,7 +2535,7 @@ struct { {"4PackGuided", GUIDED_INDEX, TXI_MSG_GUIDED, TXI_MSG_MULTI_GUIDED, TXI_MSG_GUIDEDFULL}, }; #define NUM_POWERUP_TYPES_SECONDARY std::size(powerup_data_secondary) -struct { +static constexpr struct { const char *name; int weapon_index; int ammo_msg, full_msg; diff --git a/Descent3/newui_core.cpp b/Descent3/newui_core.cpp index fbfc62cd..6e15d79d 100644 --- a/Descent3/newui_core.cpp +++ b/Descent3/newui_core.cpp @@ -513,7 +513,7 @@ static inline UISnazzyTextItem *GadgetLargeText(const char *text) { ////////////////////////////////////////////////////////////////////////////// // DATA -static const char *Preloaded_bitmap_list[] = { +static constexpr const char *Preloaded_bitmap_list[] = { NEWUI_LRGBTN_FILE, // common buttons NEWUI_LRGBTNLIT_FILE, NEWUI_LBTN_FILE, NEWUI_LBTNLIT_FILE, NEWUI_BTN_FILE, NEWUI_BTNLIT_FILE, NEWUI_LCHKBTN_FILE, NEWUI_LCHKBTNLIT_FILE, NEWUI_CHKBTN_FILE, diff --git a/Descent3/objinfo.cpp b/Descent3/objinfo.cpp index a833379d..4a922d5f 100644 --- a/Descent3/objinfo.cpp +++ b/Descent3/objinfo.cpp @@ -47,9 +47,9 @@ int Num_object_ids[MAX_OBJECT_TYPES]; // Objects that must be remapped so we can reference by index // If you change this array then you must change the defines in the header file // #ifdef _WIN32 -// char *Static_object_names[]={TBL_GENERIC("GuideBot"),TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")}; +// static constexpr char *Static_object_names[]={TBL_GENERIC("GuideBot"),TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")}; // #else -const char *Static_object_names[] = {TBL_GENERIC("GuideBot"), TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")}; +static constexpr const char *Static_object_names[] = {TBL_GENERIC("GuideBot"), TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")}; // #endif #define NUM_STATIC_OBJECTS std::size(Static_object_names) diff --git a/Descent3/weapon.cpp b/Descent3/weapon.cpp index 7ddc5d62..430fc764 100644 --- a/Descent3/weapon.cpp +++ b/Descent3/weapon.cpp @@ -367,7 +367,7 @@ weapon Weapons[MAX_WEAPONS]; int Num_weapons = 0; -const char *Static_weapon_names[] = { +const char *const Static_weapon_names[] = { // Primary weapons "Laser", "Vauss", @@ -394,7 +394,7 @@ const char *Static_weapon_names[] = { "Yellow Flare", }; -int Static_weapon_names_msg[] = { +const int Static_weapon_names_msg[] = { // Primary weapons TXI_WPN_LASER, TXI_WPN_VAUSS, @@ -421,7 +421,7 @@ int Static_weapon_names_msg[] = { TXI_WPN_YELL_FLARE, }; -int Static_weapon_ckpt_names[][2] = { +const int Static_weapon_ckpt_names[][2] = { // Primary weapons {TXI_WPNC_LASER_1, TXI_WPNC_LASER_2}, {TXI_WPNC_VAUSS_1, TXI_WPNC_VAUSS_2}, diff --git a/Descent3/weapon.h b/Descent3/weapon.h index 4cdfa32d..44d10403 100644 --- a/Descent3/weapon.h +++ b/Descent3/weapon.h @@ -326,9 +326,9 @@ extern float Primary_ramp_time, Secondary_ramp_time; extern int Num_weapons; extern weapon Weapons[MAX_WEAPONS]; -extern const char *Static_weapon_names[]; -extern int Static_weapon_names_msg[]; -extern int Static_weapon_ckpt_names[][2]; +extern const char *const Static_weapon_names[]; +extern const int Static_weapon_names_msg[]; +extern const int Static_weapon_ckpt_names[][2]; // Sets all weapons to unused void InitWeapons(); diff --git a/grtext/grtext.cpp b/grtext/grtext.cpp index 8aaaa165..960029e4 100644 --- a/grtext/grtext.cpp +++ b/grtext/grtext.cpp @@ -210,7 +210,7 @@ static badword bad_words[] = { #define NUM_BAD_WORDS std::size(bad_words) -static const char subst_chars[] = "#!&@&#%*"; +static constexpr char subst_chars[] = "#!&@&#%*"; #define NUM_SUBST_CHARS (sizeof(subst_chars) - 1) diff --git a/scripts/clutter.cpp b/scripts/clutter.cpp index 92a02a5d..c35a3800 100644 --- a/scripts/clutter.cpp +++ b/scripts/clutter.cpp @@ -67,7 +67,8 @@ struct tScriptInfo { const char *name; }; -static tScriptInfo ScriptIDs[] = {{ID_FRAGCRATE, "fragcrate"}, +static constexpr tScriptInfo ScriptIDs[] = { + {ID_FRAGCRATE, "fragcrate"}, {ID_NAPALMBARREL, "napalmbarrel"}, {ID_ALIENCUPLINK, "Aliencuplink"}, {ID_TNTHIGHYIELD, "TNTCrateHighYield"},