hedgewars/uWorld.pas
branchexperimental3D
changeset 4812 f924be23ffb4
parent 4347 0ddb100fea61
parent 4810 76315fdfb7a5
child 4816 c2575faeac3d
--- a/hedgewars/uWorld.pas	Mon Dec 27 23:57:44 2010 +0100
+++ b/hedgewars/uWorld.pas	Tue Jan 04 12:53:46 2011 +0100
@@ -20,25 +20,7 @@
 
 unit uWorld;
 interface
-uses SDLh, uGears, uConsts, uFloat, uRandom;
-
-var FollowGear: PGear;
-    WindBarWidth: LongInt;
-    bShowAmmoMenu: boolean;
-    bSelected: boolean;
-    bShowFinger: boolean;
-    Frames: Longword;
-    AFRToggle: Boolean;
-    WaterColor, DeepWaterColor: TSDL_Color;
-    WorldDx: LongInt;
-    WorldDy: LongInt;
-    SkyOffset: LongInt;
-    HorizontOffset: LongInt;
-    bAFRRight: Boolean;
-{$IFDEF COUNTTICKS}
-    cntTicks: LongWord;
-{$ENDIF}
-    cOffsetY: LongInt;
+uses SDLh, uGears, uConsts, uFloat, uRandom, uTypes;
 
 procedure initModule;
 procedure freeModule;
@@ -46,22 +28,31 @@
 procedure InitWorld;
 procedure DrawWorld(Lag: LongInt);
 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
-procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
 procedure HideMission;
 procedure ShakeCamera(amount: LongWord);
 procedure MoveCamera;
 
 implementation
-uses    uStore, uMisc, uTeams, uIO, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand, GLunit;
-
-type TCaptionStr = record
-                   Tex: PTexture;
-                   EndTime: LongWord;
-                   end;
+uses
+    uStore,
+    uMisc,
+    uIO,
+    uLocale,
+    uSound,
+    uAmmos,
+    uVisualGears,
+    uChat,
+    uLandTexture,
+    GLunit,
+    uVariables,
+    uUtils,
+    uTextures,
+    uRender,
+    uCaptions
+    ;
 
 var cWaveWidth, cWaveHeight: LongInt;
-    Captions: array[TCapGroup] of TCaptionStr;
     AMSlotSize, AMxOffset, AMyOffset, AMWidth, AMxShift, SlotsNum: LongInt;
     tmpSurface: PSDL_Surface;
     fpsTexture: PTexture;
@@ -156,14 +147,14 @@
 ScreenFadeSpeed:= 1;
 
 // modified mine timers?
-if cMinesTime <> 3 then
+if cMinesTime <> 3000 then
     begin
     if cMinesTime = 0 then
         g:= AddGoal(g, gfAny, gidNoMineTimer)
     else if cMinesTime < 0 then
         g:= AddGoal(g, gfAny, gidRandomMineTimer)
     else
-        g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime);
+        g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime div 1000);
     end;
 
 // if the string has been set, show it for (default timeframe) seconds
@@ -397,7 +388,7 @@
 {$IFDEF IPHONEOS}
     ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1);
 {$ELSE}
-    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
+    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, Min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
 {$ENDIF}
 
 bSelected:= false;
@@ -409,10 +400,20 @@
     r: TSDL_Rect;
     lw, lh: GLfloat;
 begin
-    WaterColorArray[0].a := Alpha;
-    WaterColorArray[1].a := Alpha;
-    WaterColorArray[2].a := Alpha;
-    WaterColorArray[3].a := Alpha;
+    if SuddenDeathDmg then
+        begin
+        SDWaterColorArray[0].a := Alpha;
+        SDWaterColorArray[1].a := Alpha;
+        SDWaterColorArray[2].a := Alpha;
+        SDWaterColorArray[3].a := Alpha
+        end
+    else
+        begin
+        WaterColorArray[0].a := Alpha;
+        WaterColorArray[1].a := Alpha;
+        WaterColorArray[2].a := Alpha;
+        WaterColorArray[3].a := Alpha
+        end;
 
     lw:= cScreenWidth / cScaleFactor;
     lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
@@ -436,7 +437,10 @@
 
         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
         glEnableClientState(GL_COLOR_ARRAY);
-        glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
+        if SuddenDeathDmg then
+            glColorPointer(4, GL_UNSIGNED_BYTE, 0, @SDWaterColorArray[0])
+        else
+            glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
 
         glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 
@@ -452,24 +456,39 @@
 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
     lw, waves, shift: GLfloat;
+    sprite: TSprite;
 begin
+if SuddenDeathDmg then
+    sprite:= sprSDWater
+else
+    sprite:= sprWater;
+
+cWaveWidth:= SpritesData[sprite].Width;
+
 lw:= cScreenWidth / cScaleFactor;
 waves:= lw * 2 / cWaveWidth;
 
-Tint(LongInt(tnt) * WaterColorArray[2].r div 255 + 255 - tnt,
-     LongInt(tnt) * WaterColorArray[2].g div 255 + 255 - tnt,
-     LongInt(tnt) * WaterColorArray[2].b div 255 + 255 - tnt,
-     255
-);
+if SuddenDeathDmg then
+    Tint(LongInt(tnt) * SDWaterColorArray[2].r div 255 + 255 - tnt,
+         LongInt(tnt) * SDWaterColorArray[2].g div 255 + 255 - tnt,
+         LongInt(tnt) * SDWaterColorArray[2].b div 255 + 255 - tnt,
+         255
+    )
+else
+    Tint(LongInt(tnt) * WaterColorArray[2].r div 255 + 255 - tnt,
+         LongInt(tnt) * WaterColorArray[2].g div 255 + 255 - tnt,
+         LongInt(tnt) * WaterColorArray[2].b div 255 + 255 - tnt,
+         255
+    );
 
-glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
+glBindTexture(GL_TEXTURE_2D, SpritesData[sprite].Texture^.id);
 
 VertexBuffer[0].X:= -lw;
 VertexBuffer[0].Y:= cWaterLine + WorldDy + dY;
 VertexBuffer[1].X:= lw;
 VertexBuffer[1].Y:= VertexBuffer[0].Y;
 VertexBuffer[2].X:= lw;
-VertexBuffer[2].Y:= VertexBuffer[0].Y + SpritesData[sprWater].Height;
+VertexBuffer[2].Y:= VertexBuffer[0].Y + SpritesData[sprite].Height;
 VertexBuffer[3].X:= -lw;
 VertexBuffer[3].Y:= VertexBuffer[2].Y;
 
@@ -479,7 +498,7 @@
 TextureBuffer[1].X:= TextureBuffer[0].X + waves;
 TextureBuffer[1].Y:= TextureBuffer[0].Y;
 TextureBuffer[2].X:= TextureBuffer[1].X;
-TextureBuffer[2].Y:= SpritesData[sprWater].Texture^.ry;
+TextureBuffer[2].Y:= SpritesData[sprite].Texture^.ry;
 TextureBuffer[3].X:= TextureBuffer[0].X;
 TextureBuffer[3].Y:= TextureBuffer[2].Y;
 
@@ -728,7 +747,7 @@
     begin
         // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway
         ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine);
-        offsetY:= 10 * min(0, -145 - ScreenBottom);
+        offsetY:= 10 * Min(0, -145 - ScreenBottom);
         SkyOffset:= offsetY div 35 + cWaveHeight;
         HorizontOffset:= SkyOffset;
         if ScreenBottom > SkyOffset then
@@ -792,7 +811,10 @@
 
     DrawVisualGears(2);
 
-    DrawWater(cWaterOpacity, 0);
+    if SuddenDeathDmg then
+        DrawWater(cSDWaterOpacity, 0)
+    else
+        DrawWater(cWaterOpacity, 0);
 
     // Waves
     ChangeDepth(RM, cStereo_Water);
@@ -803,10 +825,16 @@
         //DrawWater(cWaterOpacity, - offsetY div 40);
         ChangeDepth(RM, cStereo_Water);
         DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8);
-        DrawWater(cWaterOpacity, - offsetY div 20);
+        if SuddenDeathDmg then
+            DrawWater(cSDWaterOpacity, - offsetY div 20)
+        else
+            DrawWater(cWaterOpacity, - offsetY div 20);
         ChangeDepth(RM, cStereo_Water);
         DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2);
-        DrawWater(cWaterOpacity, - offsetY div 10);
+        if SuddenDeathDmg then
+            DrawWater(cSDWaterOpacity, - offsetY div 10)
+        else
+            DrawWater(cWaterOpacity, - offsetY div 10);
         ChangeDepth(RM, cStereo_Water);
         DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0);
         ResetDepth(RM);
@@ -860,73 +888,8 @@
    DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
    end;
 
-{$IFNDEF IPHONEOS}
-// Timetrial
-if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
-    begin
-    if TimeTrialStopTime = 0 then i:= RealTicks - TimeTrialStartTime else i:= TimeTrialStopTime - TimeTrialStartTime;
-    t:= 272;
-    // right frame
-    DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
-    dec(t, 32);
-    // 1 ms
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
-    dec(t, 32);
-    i:= i div 10;
-    // 10 ms
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
-    dec(t, 32);
-    i:= i div 10;
-    // 100 ms
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
-    dec(t, 16);
-    // Point
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 11);
-    dec(t, 32);
-    i:= i div 10;
-    // 1 s
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
-    dec(t, 32);
-    i:= i div 10;
-    // 10s
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 6);
-    dec(t, 16);
-    // Point
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 10);
-    dec(t, 32);
-    i:= i div 6;
-    // 1 m
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
-    dec(t, 32);
-    i:= i div 10;
-    // 10 m
-    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
-    // left frame
-    DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0);
-    end;
-{$ENDIF}
-
 // Captions
-{$IFDEF IPHONEOS}
-offset:= 40;
-{$ELSE}
-if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48
-else offset:= 8;
-{$ENDIF}
-
-    for grp:= Low(TCapGroup) to High(TCapGroup) do
-        with Captions[grp] do
-            if Tex <> nil then
-            begin
-                DrawCentered(0, offset, Tex);
-                inc(offset, Tex^.h + 2);
-                if EndTime <= RealTicks then
-                begin
-                    FreeTexture(Tex);
-                    Tex:= nil;
-                    EndTime:= 0
-                end;
-            end;
+DrawCaptions;
 
 // Teams Healths
 for t:= 0 to Pred(TeamsCount) do
@@ -935,7 +898,7 @@
       highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
 
       if highlight then
-         Tint(Clan^.Color);
+         Tint(Clan^.Color shl 8 or $FF);
 
       // draw name
       DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY, NameTagTex);
@@ -1034,7 +997,7 @@
     if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag);
     if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0
     if missionTex <> nil then
-        DrawCentered(0, min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
+        DrawCentered(0, Min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
     end;
 
 // fps
@@ -1175,22 +1138,6 @@
 isFirstFrame:= false
 end;
 
-procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
-begin
-//if Group in [capgrpGameState] then WriteLnToConsole(s);
-    if Captions[Group].Tex <> nil then
-        FreeTexture(Captions[Group].Tex);
-    Captions[Group].Tex:= nil;
-
-    Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
-
-    case Group of
-        capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
-    else
-        Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
-    end;
-end;
-
 procedure MoveCamera;
 var EdgesDist,  wdy: LongInt;
     PrevSentPointTime: LongWord = 0;
@@ -1316,8 +1263,8 @@
     end
 else
     begin
-    r.x:= ((-icon - 1) shr 5) * 32;
-    r.y:= ((-icon - 1) mod 32) * 32;
+    r.x:= ((-icon - 1) shr 4) * 32;
+    r.y:= ((-icon - 1) mod 16) * 32;
     missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, SpritesData[sprAMAmmos].Surface, @r)
     end;
 end;
@@ -1330,7 +1277,7 @@
 
 procedure ShakeCamera(amount: LongWord);
 begin
-    amount:= max(1, amount);
+    amount:= Max(1, amount);
     WorldDx:= WorldDx - amount + LongInt(getRandom(1 + amount * 2));
     WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2));
 end;
@@ -1355,8 +1302,6 @@
     missionTimer:= 0;
     missionTex:= nil;
     cOffsetY:= 0;
-
-    FillChar(Captions, sizeof(Captions), 0)
 end;
 
 procedure freeModule;