diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-11-02 21:34:39 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | 4f3ea3907e23428461c626b6c861d834b358bc9f (patch) | |
tree | f60f17d713ed155a738adb469eed7f4262ffbe3c /src/script/api/script_object.hpp | |
parent | ccefa76a4686581b8d1a9bd13d7d754807a9f8d1 (diff) | |
download | openttd-4f3ea3907e23428461c626b6c861d834b358bc9f.tar.xz |
Codechange: Un-bitstuff commands taking a ClientID (i.e. CMD_CLIENT_ID).
Diffstat (limited to 'src/script/api/script_object.hpp')
-rw-r--r-- | src/script/api/script_object.hpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index 26da500c4..8d9be14c4 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -347,6 +347,22 @@ namespace ScriptObjectInternal { { ((SanitizeSingleStringHelper(std::get<Tindices>(values))), ...); } + + /** Helper to process a single ClientID argument. */ + template <class T> + static inline void SetClientIdHelper(T &data) + { + if constexpr (std::is_same_v<ClientID, T>) { + if (data == INVALID_CLIENT_ID) data = (ClientID)UINT32_MAX; + } + } + + /** Set all invalid ClientID's to the proper value. */ + template<class Ttuple, size_t... Tindices> + static inline void SetClientIds(Ttuple &values, std::index_sequence<Tindices...>) + { + ((SetClientIdHelper(std::get<Tindices>(values))), ...); + } } template <Commands Tcmd, typename... Targs> @@ -364,8 +380,8 @@ bool ScriptObject::ScriptDoCommandHelper<Tcmd, CommandCost(*)(DoCommandFlag, Tar tile = std::get<0>(args); } - /* Only set p2 when the command does not come from the network. */ - if ((::GetCommandFlags<Tcmd>() & CMD_CLIENT_ID) != 0 && std::get<2>(args) == 0) std::get<2>(args) = UINT32_MAX; + /* Only set ClientID parameters when the command does not come from the network. */ + if constexpr ((::GetCommandFlags<Tcmd>() & CMD_CLIENT_ID) != 0) ScriptObjectInternal::SetClientIds(args, std::index_sequence_for<Targs...>{}); /* Store the command for command callback validation. */ if (!estimate_only && networking) ScriptObject::SetLastCommand(tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), Tcmd); |