Changeset - r28629:c444c801273b
[Not reviewed]
master
0 8 0
Patric Stout - 10 months ago 2024-01-31 22:24:36
truebrain@openttd.org
Remove: [Script] CONFIG_RANDOM from AddSetting flags (#11942)

It had a very weird interaction, and was only ever used by a single
AI.
8 files changed with 6 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_info.cpp
Show inline comments
 
@@ -42,14 +42,14 @@ template <> const char *GetClassName<AII
 
	SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddSetting, "AddSetting");
 
	SQAIInfo.DefSQAdvancedMethod(engine, &AIInfo::AddLabels, "AddLabels");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_NONE");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_RANDOM, "CONFIG_RANDOM");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_RANDOM"); // Deprecated, mapped to NONE.
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_BOOLEAN, "CONFIG_BOOLEAN");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_INGAME, "CONFIG_INGAME");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_DEVELOPER, "CONFIG_DEVELOPER");
 

	
 
	/* Pre 1.2 had an AI prefix */
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "AICONFIG_NONE");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_RANDOM, "AICONFIG_RANDOM");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "AICONFIG_RANDOM"); // Deprecated, mapped to NONE.
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_BOOLEAN, "AICONFIG_BOOLEAN");
 
	SQAIInfo.DefSQConst(engine, SCRIPTCONFIG_INGAME, "AICONFIG_INGAME");
 

	
src/game/game_info.cpp
Show inline comments
 
@@ -40,7 +40,7 @@ template <> const char *GetClassName<Gam
 
	SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddSetting, "AddSetting");
 
	SQGSInfo.DefSQAdvancedMethod(engine, &GameInfo::AddLabels, "AddLabels");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_NONE");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_RANDOM, "CONFIG_RANDOM");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_NONE, "CONFIG_RANDOM"); // Deprecated, mapped to NONE.
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_BOOLEAN, "CONFIG_BOOLEAN");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_INGAME, "CONFIG_INGAME");
 
	SQGSInfo.DefSQConst(engine, SCRIPTCONFIG_DEVELOPER, "CONFIG_DEVELOPER");
src/script/api/ai_changelog.hpp
Show inline comments
 
@@ -24,6 +24,7 @@
 
 *
 
 * API removals:
 
 * \li AIError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
 
 * \li AIInfo::CONFIG_RANDOM, no longer used.
 
 *
 
 * Other changes:
 
 * \li AIGroupList accepts an optional filter function
src/script/api/game_changelog.hpp
Show inline comments
 
@@ -90,6 +90,7 @@
 
 *
 
 * API removals:
 
 * \li GSError::ERR_PRECONDITION_TOO_MANY_PARAMETERS, that error is never returned anymore.
 
 * \li AIInfo::CONFIG_RANDOM, no longer used.
 
 *
 
 * Other changes:
 
 * \li GSGroupList accepts an optional filter function
src/script/api/script_info_docs.hpp
Show inline comments
 
@@ -203,7 +203,6 @@ public:
 
	/** Miscellaneous flags for Script settings. */
 
	enum ScriptConfigFlags {
 
		CONFIG_NONE,      ///< Normal setting.
 
		CONFIG_RANDOM,    ///< When randomizing the Script, pick any value between min_value and max_value (inclusive).
 
		CONFIG_BOOLEAN,   ///< This value is a boolean (either 0 (false) or 1 (true) ).
 
		CONFIG_INGAME,    ///< This setting can be changed while the Script is running.
 
		CONFIG_DEVELOPER, ///< This setting will only be visible when the Script development tools are active.
src/script/script_config.cpp
Show inline comments
 
@@ -34,14 +34,6 @@ void ScriptConfig::Change(std::optional<
 
	this->ClearConfigList();
 

	
 
	if (_game_mode == GM_NORMAL && this->info != nullptr) {
 
		/* If we're in an existing game and the Script is changed, set all settings
 
		 *  for the Script that have the random flag to a random value. */
 
		for (const auto &item : *this->info->GetConfigList()) {
 
			if (item.flags & SCRIPTCONFIG_RANDOM) {
 
				this->SetSetting(item.name, ScriptObject::GetRandomizer(OWNER_NONE).Next(item.max_value + 1 - item.min_value) + item.min_value);
 
			}
 
		}
 

	
 
		this->AddRandomDeviation();
 
	}
 
}
src/script/script_config.hpp
Show inline comments
 
@@ -20,7 +20,7 @@ static const int INT32_DIGITS_WITH_SIGN_
 
/** Bitmask of flags for Script settings. */
 
enum ScriptConfigFlags {
 
	SCRIPTCONFIG_NONE      = 0x0, ///< No flags set.
 
	SCRIPTCONFIG_RANDOM    = 0x1, ///< When randomizing the Script, pick any value between min_value and max_value when on custom difficulty setting.
 
	// Unused flag 0x1.
 
	SCRIPTCONFIG_BOOLEAN   = 0x2, ///< This value is a boolean (either 0 (false) or 1 (true) ).
 
	SCRIPTCONFIG_INGAME    = 0x4, ///< This setting can be changed while the Script is running.
 
	SCRIPTCONFIG_DEVELOPER = 0x8, ///< This setting will only be visible when the Script development tools are active.
src/script/script_info.cpp
Show inline comments
 
@@ -162,12 +162,6 @@ SQInteger ScriptInfo::AddSetting(HSQUIRR
 
	}
 
	sq_pop(vm, 1);
 

	
 
	/* Don't allow both random_deviation and SCRIPTCONFIG_RANDOM to
 
	 * be set for the same config item. */
 
	if ((items & 0x200) != 0 && (config.flags & SCRIPTCONFIG_RANDOM) != 0) {
 
		this->engine->ThrowError("Setting both random_deviation and SCRIPTCONFIG_RANDOM is not allowed");
 
		return SQ_ERROR;
 
	}
 
	/* Reset the bit for random_deviation as it's optional. */
 
	items &= ~0x200;
 

	
0 comments (0 inline, 0 general)