Add bot level to CPU flag
authornemo
Sun, 05 Aug 2012 15:00:59 -0400
changeset 7495 2592240b7b62
parent 7492 3188794b9d87
child 7498 86984f6fa1b9
Add bot level to CPU flag
QTfrontend/ui/page/pageeditteam.cpp
hedgewars/uConsts.pas
hedgewars/uStore.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
share/hedgewars/Data/Graphics/Flags/cpu_plain.png
share/hedgewars/Data/Graphics/botlevels.png
--- a/QTfrontend/ui/page/pageeditteam.cpp	Sat Aug 04 22:51:41 2012 -0400
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Sun Aug 05 15:00:59 2012 -0400
@@ -289,6 +289,9 @@
     int idx = list.indexOf("cpu.png");
     if (idx >= 0)
         list.removeAt(idx);
+    idx = list.indexOf("cpu_plain.png");
+    if (idx >= 0)
+        list.removeAt(idx);
     idx = list.indexOf("hedgewars.png");
     if (idx >= 0)
         list.removeAt(idx);
--- a/hedgewars/uConsts.pas	Sat Aug 04 22:51:41 2012 -0400
+++ b/hedgewars/uConsts.pas	Sun Aug 05 15:00:59 2012 -0400
@@ -165,7 +165,7 @@
     cMinZoomLevel = 3.5;
     cZoomDelta = 0.20;
 {$ELSE}
-    cMaxZoomLevel = 1.0;
+    cMaxZoomLevel = 0.25;
     cMinZoomLevel = 3.0;
     cZoomDelta = 0.25;
 {$ENDIF}
--- a/hedgewars/uStore.pas	Sat Aug 04 22:51:41 2012 -0400
+++ b/hedgewars/uStore.pas	Sun Aug 05 15:00:59 2012 -0400
@@ -131,10 +131,11 @@
 
 procedure WriteNames(Font: THWFont);
 var t: LongInt;
-    i: LongInt;
+    i, maxLevel: LongInt;
     r, rr: TSDL_Rect;
     drY: LongInt;
     texsurf, flagsurf, iconsurf: PSDL_Surface;
+    foundBot: boolean;
 begin
 r.x:= 0;
 r.y:= 0;
@@ -172,11 +173,28 @@
         DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true);
 
         // overwrite flag for cpu teams and keep players from using it
-        if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then
-            if Flag = 'hedgewars' then
-                Flag:= 'cpu'
-        else if Flag = 'cpu' then
-            Flag:= 'hedgewars';
+        foundBot:= false;
+        maxLevel:= -1;
+        for i:= 0 to cMaxHHIndex do
+            with Hedgehogs[i] do
+                if (Gear <> nil) and (BotLevel > 0) then
+                    begin
+                    foundBot:= true;
+                    // initially was going to do the highest botlevel of the team, but for now, just apply if entire team has same bot level
+                    if maxLevel = -1 then maxLevel:= BotLevel
+                    else if (maxLevel > 0) and (maxLevel <> BotLevel) then maxLevel:= 0; 
+                    //if (maxLevel > 0) and (BotLevel < maxLevel) then maxLevel:= BotLevel
+                    end
+                else if Gear <> nil then  maxLevel:= 0;
+
+        if foundBot then
+            begin
+            // disabled the plain flag - I think it looks ok even w/ full bars obscuring CPU
+            //if (maxLevel > 0) and (maxLevel < 3) then Flag:= 'cpu_plain' else 
+            Flag:= 'cpu'
+            end
+        else if (Flag = 'cpu') or (Flag = 'cpu_plain') then
+                Flag:= 'hedgewars';
 
         flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone);
         if flagsurf = nil then
@@ -186,16 +204,27 @@
         if flagsurf = nil then
             flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
         TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
+
+        case maxLevel of
+            1: copyToXY(SpritesData[sprBotlevels].Surface, flagsurf, 0, 0); 
+            2: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 5, 2, 17, 13, 5, 2); 
+            3: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 9, 5, 13, 10, 9, 5); 
+            4: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 13, 9, 9, 6, 13, 9); 
+            5: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 17, 11, 5, 4, 17, 11)
+            end;
+
         copyToXY(flagsurf, texsurf, 2, 2);
         SDL_FreeSurface(flagsurf);
         flagsurf:= nil;
 
+
         // restore black border pixels inside the flag
         PLongwordArray(texsurf^.pixels)^[32 * 2 +  2]:= cNearBlackColor;
         PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor;
         PLongwordArray(texsurf^.pixels)^[32 * 16 +  2]:= cNearBlackColor;
         PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor;
 
+
         FlagTex:= Surface2Tex(texsurf, false);
         SDL_FreeSurface(texsurf);
         texsurf:= nil;
@@ -204,7 +233,7 @@
 
         dec(drY, r.h + 2);
         DrawHealthY:= drY;
-        for i:= 0 to 7 do
+        for i:= 0 to cMaxHHIndex do
             with Hedgehogs[i] do
                 if Gear <> nil then
                     begin
@@ -294,7 +323,6 @@
             WriteLnToConsole(msgOK)
             end;
 
-WriteNames(fnt16);
 MakeCrossHairs;
 LoadGraves;
 if not reload then
@@ -391,6 +419,8 @@
                 Surface:= nil
         end;
 
+WriteNames(fnt16);
+
 if not reload then
     AddProgress;
 
--- a/hedgewars/uTypes.pas	Sat Aug 04 22:51:41 2012 -0400
+++ b/hedgewars/uTypes.pas	Sun Aug 05 15:00:59 2012 -0400
@@ -86,7 +86,7 @@
             sprHandResurrector, sprCross, sprAirDrill, sprNapalmBomb,
             sprBulletHit, sprSnowball, sprHandSnowball, sprSnow,
             sprSDFlake, sprSDWater, sprSDCloud, sprSDSplash, sprSDDroplet, sprTardis,
-            sprSlider
+            sprSlider, sprBotlevels
             );
 
     // Gears that interact with other Gears and/or Land
--- a/hedgewars/uVariables.pas	Sat Aug 04 22:51:41 2012 -0400
+++ b/hedgewars/uVariables.pas	Sun Aug 05 15:00:59 2012 -0400
@@ -644,7 +644,9 @@
             (FileName:  'TARDIS'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
             Width:  48; Height: 79; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprTardis
             (FileName:  'slider'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
-            Width: 3; Height: 17; imageWidth: 3; imageHeight: 17; saveSurf: false; priority: tpLow; getDimensions: false; getImageDimensions: false) // sprSlider
+            Width: 3; Height: 17; imageWidth: 3; imageHeight: 17; saveSurf: false; priority: tpLow; getDimensions: false; getImageDimensions: false), // sprSlider
+            (FileName:  'botlevels'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 22; Height: 15; imageWidth: 22; imageHeight: 15; saveSurf: true; priority: tpLow; getDimensions: false; getImageDimensions: false) // sprBotlevels
             );
 
 const
Binary file share/hedgewars/Data/Graphics/Flags/cpu_plain.png has changed
Binary file share/hedgewars/Data/Graphics/botlevels.png has changed