SetClanColor: Accept negative color argument to select user color
authorWuzzy <Wuzzy2@mail.ru>
Mon, 21 Jan 2019 05:57:01 +0100
changeset 14647 bc4296649bbf
parent 14646 7de65fa1f686
child 14648 30d3e1d6aedf
SetClanColor: Accept negative color argument to select user color
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Mon Jan 21 05:51:35 2019 +0100
+++ b/ChangeLog.txt	Mon Jan 21 05:57:01 2019 +0100
@@ -80,6 +80,7 @@
  + New call: AddMissionHog(health): Add a hedgehog for the mission team
  + New call: SetTeamPassive(teamname, isPassive): Mark a team as passive. Passive teams do not play and are treated like frozen teams.
  + New return value: AddTeam/AddMissionTeam return <real team name>, <team index>
+ + SetClanColor: Now accepts negative color argument for user clan color, like in AddTeam
  + Utils library: New calls: getReadableChallengeRecord, updateChallengeRecord
  + New callback: onGameResult(winningClan): Called when the game ends normally. winningClan = index of winning clan or -1 on draw
  + SendStat extension: Option to use predefined modes with siPointType, like "!POINTS" or "!TIME"
--- a/hedgewars/uScript.pas	Mon Jan 21 05:51:35 2019 +0100
+++ b/hedgewars/uScript.pas	Mon Jan 21 05:57:01 2019 +0100
@@ -1361,13 +1361,29 @@
     hht  : THedgehog;
     hhp  : PHedgehog;
     i, j : LongInt;
+    colorArg: Int64;
+    color: LongWord;
 begin
     if CheckLuaParamCount(L, 2, 'SetClanColor', 'clan, color') then
         begin
         i:= Trunc(lua_tonumber(L,1));
         if i >= ClansCount then exit(0);
         clan := ClansArray[i];
-        clan^.Color:= Trunc(lua_tonumber(L, 2)) shr 8;
+        colorArg:= Trunc(lua_tonumber(L, 2));
+        if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
+            // Pick clan color from settings (recommended)
+            color:= ClanColorArray[Pred(abs(colorArg))]
+        else if (colorArg >= 0) and (colorArg <= $ffffffff) then
+            // Specify color directly
+            color:= colorArg shr 8
+        else
+            begin
+            OutError('Lua error: SetClanColor: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
+            lc_setclancolor:= 0;
+            exit;
+            end;
+
+        clan^.Color:= color;
 
         for i:= 0 to Pred(clan^.TeamsNumber) do
             begin