src/misc_cmd.cpp
changeset 10708 5f1e9cffcfa5
parent 10707 81a4013a7680
child 10775 7061477bfbcf
equal deleted inserted replaced
10707:81a4013a7680 10708:5f1e9cffcfa5
    20 #include "string_func.h"
    20 #include "string_func.h"
    21 #include "player_func.h"
    21 #include "player_func.h"
    22 #include "player_base.h"
    22 #include "player_base.h"
    23 #include "player_gui.h"
    23 #include "player_gui.h"
    24 #include "settings_type.h"
    24 #include "settings_type.h"
    25 #include "station_func.h"
       
    26 
    25 
    27 #include "table/strings.h"
    26 #include "table/strings.h"
    28 
    27 
    29 /** Change the player's face.
    28 /** Change the player's face.
    30  * @param tile unused
    29  * @param tile unused
   378 	}
   377 	}
   379 
   378 
   380 	/* Subtract money from local-player */
   379 	/* Subtract money from local-player */
   381 	return amount;
   380 	return amount;
   382 }
   381 }
   383 
       
   384 /** Change difficulty level/settings (server-only).
       
   385  * We cannot really check for valid values of p2 (too much work mostly); stored
       
   386  * in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows
       
   387  * what to do and does this correctly
       
   388  * @param tile unused
       
   389  * @param flags operation to perform
       
   390  * @param p1 the difficulty setting being changed. If it is -1, the difficulty level
       
   391  *           itself is changed. The new value is inside p2
       
   392  * @param p2 new value for a difficulty setting or difficulty level
       
   393  */
       
   394 CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
       
   395 {
       
   396 	if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR;
       
   397 
       
   398 	DifficultySettings *opt_ptr = (_game_mode == GM_MENU) ? &_settings_newgame.difficulty : &_settings.difficulty;
       
   399 
       
   400 	if (flags & DC_EXEC) {
       
   401 		if (p1 != (uint32)-1L) {
       
   402 			((GDType*)opt_ptr)[p1] = p2;
       
   403 			opt_ptr->diff_level = 3; // custom difficulty level
       
   404 		} else {
       
   405 			opt_ptr->diff_level = p2;
       
   406 		}
       
   407 
       
   408 		/* Since the tolerance of the town council has a direct impact on the noise generation/tolerance,
       
   409 		 * launch a re-evaluation of the actual values only when setting has changed */
       
   410 		if (p2 == GAME_DIFFICULTY_TOWNCOUNCIL_TOLERANCE && _game_mode == GM_NORMAL) {
       
   411 			UpdateAirportsNoise();
       
   412 			if (_settings.economy.station_noise_level) {
       
   413 				InvalidateWindowClassesData(WC_TOWN_VIEW, 0);
       
   414 			}
       
   415 		}
       
   416 
       
   417 		/* If we are a network-client, update the difficult setting (if it is open).
       
   418 		 * Use this instead of just dirtying the window because we need to load in
       
   419 		 * the new difficulty settings */
       
   420 		if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL) {
       
   421 			ShowGameDifficulty();
       
   422 		}
       
   423 	}
       
   424 	return CommandCost();
       
   425 }