Lua: Allow to use negative value for AddTeam to select a default clan color
authorWuzzy <Wuzzy2@mail.ru>
Wed, 01 Aug 2018 02:49:03 +0200
changeset 13587 517b26009073
parent 13586 9c8749bb0d06
child 13588 141cdfe0f3ca
Lua: Allow to use negative value for AddTeam to select a default clan color
ChangeLog.txt
QTfrontend/hwconsts.h
hedgewars/uConsts.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Tue Jul 31 22:40:23 2018 +0200
+++ b/ChangeLog.txt	Wed Aug 01 02:49:03 2018 +0200
@@ -75,6 +75,7 @@
  + New call: GetVampiric(): Returns true if vampirism is currently active
  + New call: GetLaserSight(): Returns true if laser sight (as utility) is currenctly active (ignoring sniper rifle)
  + New call: IsHogHidden(gear): Returns true if hog is hidden
+ + Changed cal: AddTeam: 2nd param. color: Accepts negative value to use a default clan color from player settings
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
  + New parameter: ShowMission: 6th param. forceDisplay: Set to true to prevent this particular mission panel to be hidden manually by player
  + New Lua library: Achievements
--- a/QTfrontend/hwconsts.h	Tue Jul 31 22:40:23 2018 +0200
+++ b/QTfrontend/hwconsts.h	Wed Aug 01 02:49:03 2018 +0200
@@ -78,6 +78,9 @@
 #define HWENGINE_EXITCODE_OK 0
 #define HWENGINE_EXITCODE_FATAL 52
 
+// Default clan colors
+// NOTE: Always keep this in sync with hedgewars/uVariables.pas (ClanColorArray)
+
 // see https://en.wikipedia.org/wiki/List_of_colors
 /*define HW_TEAMCOLOR_ARRAY  {0xff007fff, /. azure          ./ \
                               0xffdd0000, /. classic red    ./ \
--- a/hedgewars/uConsts.pas	Tue Jul 31 22:40:23 2018 +0200
+++ b/hedgewars/uConsts.pas	Wed Aug 01 02:49:03 2018 +0200
@@ -174,6 +174,8 @@
     cMaxHHIndex      = 7;
     cMaxHHs          = cMaxTeams * (cMaxHHIndex+1);
 
+    cClanColors      = 9;
+
     cMaxEdgePoints = 32768;
 
     cHHRadius = 9;
--- a/hedgewars/uScript.pas	Tue Jul 31 22:40:23 2018 +0200
+++ b/hedgewars/uScript.pas	Wed Aug 01 02:49:03 2018 +0200
@@ -2189,10 +2189,25 @@
 
 function lc_addteam(L : Plua_State) : LongInt; Cdecl;
 var np: LongInt;
+    colorArg: Int64;
+    colorStr: shortstring;
 begin
     if CheckAndFetchParamCount(L, 5, 6, 'AddTeam', 'teamname, color, grave, fort, voicepack [, flag]', np) then
         begin
-        ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true);
+        colorArg:= Trunc(lua_tonumber(L, 2));
+        if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
+            // Pick clan color from settings (recommended)
+            colorStr:= IntToStr(ClanColorArray[Pred(abs(colorArg))])
+        else if (colorArg >= 0) and (colorArg <= $ffffffff) then
+            // Specify color directly
+            colorStr:= IntToStr(colorArg)
+        else
+            begin
+            OutError('Lua error: AddTeam: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
+            lc_addteam:= 0;
+            exit;
+            end;
+        ParseCommand('addteam x ' + colorStr + ' ' + lua_tostring(L, 1), true, true);
         ParseCommand('grave ' + lua_tostring(L, 3), true, true);
         ParseCommand('fort ' + lua_tostring(L, 4), true, true);
         ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
--- a/hedgewars/uVariables.pas	Tue Jul 31 22:40:23 2018 +0200
+++ b/hedgewars/uVariables.pas	Wed Aug 01 02:49:03 2018 +0200
@@ -215,6 +215,7 @@
 
     WaterColorArray : array[0..7] of HwColor4f;
     SDWaterColorArray : array[0..7] of HwColor4f;
+    ClanColorArray : array[0..Pred(cClanColors)] of Longword;
 
     TargetCursorPoint     : TPoint;
     CursorPoint           : TPoint;
@@ -2717,6 +2718,19 @@
 
     WaterOpacity:= $80;
 
+    // default clan colors
+    // always keep in sync with QTfrontend/hwconsts.h
+
+    ClanColorArray[0] := $ffff0204;
+    ClanColorArray[1] := $ff4980c1;
+    ClanColorArray[2] := $ff1de6ba;
+    ClanColorArray[3] := $ffb541ef;
+    ClanColorArray[4] := $ffe55bb0;
+    ClanColorArray[5] := $ff20bf00;
+    ClanColorArray[6] := $fffe8b0e;
+    ClanColorArray[7] := $ff8f5902;
+    ClanColorArray[8] := $ffffff01;
+
     // default sudden death water
 
     // deep water