Allow duplicate colors when map has LUA script#1888
Allow duplicate colors when map has LUA script#1888Flamefire wants to merge 4 commits intoReturn-To-The-Roots:masterfrom
Conversation
This can be used to `static_assert` the size of the `PLAYER_COLORS` array.
For e.g. campaigns the creator might intend duplicate colors so allow that. This also resolves the issue where color set by LUA is changed as it is still taken even though the conflicting players color might get changed right afterwards so colors would be unique when the script is done. That makes setting the colors dependent on the order which is hard. Fixes Return-To-The-Roots#1884
|
@Flamefire I just had a look at the docu (probably for that one the first time): So we can add any color? And can we maybe document the colorIdxs (guess there is an array somewhere). Also what does happen if we use an invalid index (guess just nothing) |
| RTTR_Assert(playerIdx < playerInfos.size()); | ||
| RTTR_Assert(playerInfos.size() <= PLAYER_COLORS.size()); // Else we may not find a valid color! | ||
| // If either of those fails we may not find a valid color! | ||
| static_assert(PLAYER_COLORS.size() >= MAX_PLAYERS, "Not enough player colors defined!"); |
There was a problem hiding this comment.
I fail to wrap my head around this - shouldn't player clolors always be more than MAX_PLAYERS?
Expected this rather to be PLAYER_COLORS.size() < MAX_PLAYERS
There was a problem hiding this comment.
That's exactly what the assertion says: Assert at least as many colors as max players
| RTTR_Assert(playerInfos.size() <= PLAYER_COLORS.size()); // Else we may not find a valid color! | ||
| // If either of those fails we may not find a valid color! | ||
| static_assert(PLAYER_COLORS.size() >= MAX_PLAYERS, "Not enough player colors defined!"); | ||
| RTTR_Assert(playerInfos.size() <= PLAYER_COLORS.size()); |
There was a problem hiding this comment.
Also this one, shouldn't the same size work fine?
There was a problem hiding this comment.
"assert" (roughly) means "make sure this is true" and <= includes "equal"
Yes any color. I enhanced the documentation to refer to the array and stated that custom colors are ARGB. |
459f35c to
ac36b3c
Compare
For e.g. campaigns the creator might intend duplicate colors so allow that.
This also resolves the issue where color set by LUA is changed as it is
still taken even though the conflicting players color might get changed
right afterwards so colors would be unique when the script is done.
That makes setting the colors dependent on the order which is hard.
This also makes the behavior consistent with the documentation.
Fixes #1884