(svn r11279) -Codechange: use a typedeffed type for all magic with GameDifficulty instead on relying ints to always be 32 bits, which they are not.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 17 years ago
parent 440fa08669
commit c393a28bf9

@ -380,7 +380,7 @@ CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, ui
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
if (p1 != (uint32)-1L) { if (p1 != (uint32)-1L) {
((int*)&_opt_ptr->diff)[p1] = p2; ((GDType*)&_opt_ptr->diff)[p1] = p2;
_opt_ptr->diff_level = 3; // custom difficulty level _opt_ptr->diff_level = 3; // custom difficulty level
} else { } else {
_opt_ptr->diff_level = p2; _opt_ptr->diff_level = p2;

@ -280,25 +280,27 @@ struct Prices {
#define GAME_DIFFICULTY_NUM 18 #define GAME_DIFFICULTY_NUM 18
/** Specific type for Game Difficulty to ease changing the type */
typedef uint16 GDType;
struct GameDifficulty { struct GameDifficulty {
int max_no_competitors; GDType max_no_competitors;
int competitor_start_time; GDType competitor_start_time;
int number_towns; GDType number_towns;
int number_industries; GDType number_industries;
int max_loan; GDType max_loan;
int initial_interest; GDType initial_interest;
int vehicle_costs; GDType vehicle_costs;
int competitor_speed; GDType competitor_speed;
int competitor_intelligence; // no longer in use GDType competitor_intelligence; // no longer in use
int vehicle_breakdowns; GDType vehicle_breakdowns;
int subsidy_multiplier; GDType subsidy_multiplier;
int construction_cost; GDType construction_cost;
int terrain_type; GDType terrain_type;
int quantity_sea_lakes; GDType quantity_sea_lakes;
int economy; GDType economy;
int line_reverse_mode; GDType line_reverse_mode;
int disasters; GDType disasters;
int town_council_tolerance; // minimum required town ratings to be allowed to demolish stuff GDType town_council_tolerance; // minimum required town ratings to be allowed to demolish stuff
}; };
enum { enum {

@ -1304,8 +1304,8 @@ static const SettingDesc _gameopt_settings[] = {
* XXX - To save file-space and since values are never bigger than about 10? only * XXX - To save file-space and since values are never bigger than about 10? only
* save the first 16 bits in the savegame. Question is why the values are still int32 * save the first 16 bits in the savegame. Question is why the values are still int32
* and why not byte for example? */ * and why not byte for example? */
SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 0, 3), SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16, 0, 0, GameOptions, diff, 17, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 0, 3),
SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 4, SL_MAX_VERSION), SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16, 0, 0, GameOptions, diff, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, NULL, 4, SL_MAX_VERSION),
SDT_VAR(GameOptions, diff_level, SLE_UINT8, 0, 0, 0, 0, 3, 0, STR_NULL, NULL), SDT_VAR(GameOptions, diff_level, SLE_UINT8, 0, 0, 0, 0, 3, 0, STR_NULL, NULL),
SDT_OMANY(GameOptions, currency, SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL), SDT_OMANY(GameOptions, currency, SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
SDT_OMANY(GameOptions, units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL), SDT_OMANY(GameOptions, units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL),

@ -399,7 +399,7 @@ static const GameSettingData _game_setting_info[] = {
* Q: disasters * Q: disasters
* R: area restructuring (0 = permissive, 2 = hostile) * R: area restructuring (0 = permissive, 2 = hostile)
*/ */
static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = { /* static const GDType _default_game_diff[3][GAME_DIFFICULTY_NUM] = { /*
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R*/ A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R*/
{2, 2, 1, 4, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, ///< easy {2, 2, 1, 4, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0}, ///< easy
{4, 1, 1, 3, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, ///< medium {4, 1, 1, 3, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1}, ///< medium
@ -414,7 +414,7 @@ void SetDifficultyLevel(int mode, GameOptions *gm_opt)
gm_opt->diff_level = mode; gm_opt->diff_level = mode;
if (mode != 3) { // not custom if (mode != 3) { // not custom
for (i = 0; i != GAME_DIFFICULTY_NUM; i++) for (i = 0; i != GAME_DIFFICULTY_NUM; i++)
((int*)&gm_opt->diff)[i] = _default_game_diff[mode][i]; ((GDType*)&gm_opt->diff)[i] = _default_game_diff[mode][i];
} }
} }
@ -428,7 +428,7 @@ void CheckDifficultyLevels()
SetDifficultyLevel(_opt_newgame.diff_level, &_opt_newgame); SetDifficultyLevel(_opt_newgame.diff_level, &_opt_newgame);
} else { } else {
for (uint i = 0; i < GAME_DIFFICULTY_NUM; i++) { for (uint i = 0; i < GAME_DIFFICULTY_NUM; i++) {
int *diff = ((int*)&_opt_newgame.diff) + i; GDType *diff = ((GDType*)&_opt_newgame.diff) + i;
*diff = clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max); *diff = clamp(*diff, _game_setting_info[i].min, _game_setting_info[i].max);
*diff -= *diff % _game_setting_info[i].step; *diff -= *diff % _game_setting_info[i].step;
} }
@ -489,7 +489,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
DrawStringCentered(20, y, STR_681A, 0); DrawStringCentered(20, y, STR_681A, 0);
value = _game_setting_info[i].str + ((int*)&_opt_mod_temp.diff)[i]; value = _game_setting_info[i].str + ((GDType*)&_opt_mod_temp.diff)[i];
if (i == 4) value *= 1000; // XXX - handle currency option if (i == 4) value *= 1000; // XXX - handle currency option
SetDParam(0, value); SetDParam(0, value);
DrawString(30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0); DrawString(30, y, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0);
@ -531,7 +531,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
_difficulty_timeout = 5; _difficulty_timeout = 5;
val = ((int*)&_opt_mod_temp.diff)[btn]; val = ((GDType*)&_opt_mod_temp.diff)[btn];
info = &_game_setting_info[btn]; // get information about the difficulty setting info = &_game_setting_info[btn]; // get information about the difficulty setting
if (x >= 10) { if (x >= 10) {
@ -546,7 +546,7 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
} }
// save value in temporary variable // save value in temporary variable
((int*)&_opt_mod_temp.diff)[btn] = val; ((GDType*)&_opt_mod_temp.diff)[btn] = val;
RaiseWindowWidget(w, _opt_mod_temp.diff_level + 3); RaiseWindowWidget(w, _opt_mod_temp.diff_level + 3);
SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom
LowerWindowWidget(w, _opt_mod_temp.diff_level + 3); LowerWindowWidget(w, _opt_mod_temp.diff_level + 3);
@ -563,11 +563,11 @@ static void GameDifficultyWndProc(Window *w, WindowEvent *e)
ShowHighscoreTable(_opt_mod_temp.diff_level, -1); ShowHighscoreTable(_opt_mod_temp.diff_level, -1);
break; break;
case 10: { /* Save button - save changes */ case 10: { /* Save button - save changes */
int btn, val; GDType btn, val;
for (btn = 0; btn != GAME_DIFFICULTY_NUM; btn++) { for (btn = 0; btn != GAME_DIFFICULTY_NUM; btn++) {
val = ((int*)&_opt_mod_temp.diff)[btn]; val = ((GDType*)&_opt_mod_temp.diff)[btn];
// if setting has changed, change it // if setting has changed, change it
if (val != ((int*)&_opt_ptr->diff)[btn]) if (val != ((GDType*)&_opt_ptr->diff)[btn])
DoCommandP(0, btn, val, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); DoCommandP(0, btn, val, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
} }
DoCommandP(0, UINT_MAX, _opt_mod_temp.diff_level, NULL, CMD_CHANGE_DIFFICULTY_LEVEL); DoCommandP(0, UINT_MAX, _opt_mod_temp.diff_level, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);

Loading…
Cancel
Save