- Use cloud as 'visual gear'
authorunc0rr
Fri, 07 Mar 2008 18:10:03 +0000
changeset 803 3f73901a350a
parent 802 ed5450a89b96
child 804 30f687f380fa
- Use cloud as 'visual gear' - Small fixes
hedgewars/GSHandlers.inc
hedgewars/hwengine.dpr
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uVisualGears.pas
hedgewars/uWorld.pas
--- a/hedgewars/GSHandlers.inc	Fri Mar 07 17:43:05 2008 +0000
+++ b/hedgewars/GSHandlers.inc	Fri Mar 07 18:10:03 2008 +0000
@@ -109,17 +109,6 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-procedure doStepCloud(Gear: PGear);
-begin
-Gear^.X:= Gear^.X + cWindSpeed * 200 + Gear^.dX;
-if hwRound(Gear^.Y) > -160 then Gear^.dY:= Gear^.dY - _1div50000
-                           else Gear^.dY:= Gear^.dY + _1div50000;
-Gear^.Y:= Gear^.Y + Gear^.dY;
-if hwRound(Gear^.X) < -cScreenWidth - 256 then Gear^.X:= int2hwFloat(cScreenWidth + 2048) else
-if hwRound(Gear^.X) > cScreenWidth + 2048 then Gear^.X:= int2hwFloat(-cScreenWidth - 256)
-end;
-
-////////////////////////////////////////////////////////////////////////////////
 procedure doStepBomb(Gear: PGear);
 var i: LongInt;
 begin
--- a/hedgewars/hwengine.dpr	Fri Mar 07 17:43:05 2008 +0000
+++ b/hedgewars/hwengine.dpr	Fri Mar 07 18:10:03 2008 +0000
@@ -100,10 +100,12 @@
      gsGame : begin
               ProcessKbd;
               DoGameTick(Lag);
+              ProcessVisualGears(Lag);
               DrawWorld(Lag, SDLPrimSurface);
               end;
    gsConsole: begin
               DoGameTick(Lag);
+              ProcessVisualGears(Lag);
               DrawWorld(Lag, SDLPrimSurface);
               DrawConsole(SDLPrimSurface);
               end;
--- a/hedgewars/uConsts.pas	Fri Mar 07 17:43:05 2008 +0000
+++ b/hedgewars/uConsts.pas	Fri Mar 07 18:10:03 2008 +0000
@@ -43,7 +43,7 @@
                    sprQuestion, sprPowerBar, sprWindBar,
                    sprWindL, sprWindR);
 
-     TGearType  = (gtCloud, gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
+     TGearType  = (gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag,
                    gtGrave, gtUFO, gtShotgunShot, gtPickHammer, gtRope,
                    gtSmokeTrace, gtExplosion, gtMine, gtCase, gtDEagleShot, gtDynamite,
                    gtTeamHealthSorter, gtClusterBomb, gtCluster, gtShover, gtFlame,
@@ -51,7 +51,7 @@
                    gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch, gtGirder,
                    gtTeleport, gtSmallDamage, gtSwitcher, gtTarget);
 
-     TVisualGearType = (vgtFlake);
+     TVisualGearType = (vgtFlake, vgtCloud);
 
      TGearsType = set of TGearType;
 
--- a/hedgewars/uGears.pas	Fri Mar 07 17:43:05 2008 +0000
+++ b/hedgewars/uGears.pas	Fri Mar 07 18:10:03 2008 +0000
@@ -59,7 +59,6 @@
 procedure DrawGears(Surface: PSDL_Surface);
 procedure FreeGearsList;
 procedure AddMiscGears;
-procedure AddClouds;
 procedure AssignHHCoords;
 procedure InsertGearToList(Gear: PGear);
 procedure RemoveGearFromList(Gear: PGear);
@@ -101,7 +100,6 @@
 {$INCLUDE HHHandlers.inc}
 
 const doStepHandlers: array[TGearType] of TGearStepProcedure = (
-                                                               @doStepCloud,
                                                                @doStepBomb,
                                                                @doStepHedgehog,
                                                                @doStepGrenade,
@@ -138,21 +136,27 @@
                                                                );
 
 procedure InsertGearToList(Gear: PGear);
-var tmp: PGear;
+var tmp, ptmp: PGear;
 begin
 if GearsList = nil then
    GearsList:= Gear
    else begin
-   // WARNING: this code assumes that the first gears added to the list are clouds (have maximal Z)
    tmp:= GearsList;
-   while (tmp <> nil) and (tmp^.Z < Gear^.Z) do
-          tmp:= tmp^.NextGear;
+   ptmp:= GearsList;
+   while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do
+          begin
+          ptmp:= tmp;
+          tmp:= tmp^.NextGear
+          end;
 
-   if tmp^.PrevGear <> nil then tmp^.PrevGear^.NextGear:= Gear;
-   Gear^.PrevGear:= tmp^.PrevGear;
-   tmp^.PrevGear:= Gear;
-   Gear^.NextGear:= tmp;
-   if GearsList = tmp then GearsList:= Gear
+   if ptmp <> nil then
+      begin
+      Gear^.NextGear:= ptmp^.NextGear;
+      Gear^.PrevGear:= ptmp;
+      if ptmp^.NextGear <> nil then ptmp^.NextGear^.PrevGear:= Gear;
+      ptmp^.NextGear:= Gear
+      end
+   else GearsList:= Gear
    end
 end;
 
@@ -193,7 +197,6 @@
    end;
 
 case Kind of
-       gtCloud: Result^.Z:= High(Result^.Z);
    gtAmmo_Bomb: begin
                 Result^.Radius:= 4;
                 Result^.Elasticity:= _0_6;
@@ -579,7 +582,6 @@
 while Gear<>nil do
       begin
       case Gear^.Kind of
-           gtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface);
        gtAmmo_Bomb: DrawRotated(sprBomb, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.DirAngle);
         gtHedgehog: DrawHH(Gear, Surface);
     gtAmmo_Grenade: DrawRotated(sprGrenade, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, DxDy2Angle(Gear^.dY, Gear^.dX));
@@ -656,21 +658,6 @@
        FindPlace(AddGear(0, 0, gtMine, 0, _0, _0, 0), false, 0, 2048);
 end;
 
-procedure AddClouds;
-var i: LongInt;
-    dx, dy: hwFloat;
-begin
-for i:= 0 to cCloudsNumber do
-    begin
-    dx.isNegative:= random(2) = 1;
-    dx.QWordValue:= random(214748364);
-    dy.isNegative:= (i and 1) = 1;
-    dy.QWordValue:= 21474836 + random(64424509);
-    AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140,
-             gtCloud, random(4), dx, dy, 0)
-    end
-end;
-
 procedure doMakeExplosion(X, Y, Radius: LongInt; Mask: LongWord);
 var Gear: PGear;
     dmg, dmgRadius: LongInt;
--- a/hedgewars/uVisualGears.pas	Fri Mar 07 17:43:05 2008 +0000
+++ b/hedgewars/uVisualGears.pas	Fri Mar 07 18:10:03 2008 +0000
@@ -38,22 +38,33 @@
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; dX, dY: hwFloat): PVisualGear;
 procedure ProcessVisualGears(Steps: Longword);
 procedure DrawVisualGears();
-//procedure AddClouds;
+procedure AddClouds;
 
 var VisualGearsList: PVisualGear = nil;
 
 implementation
-uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
-     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos, uTriggers, GL;
+uses uWorld, uMisc, uStore, GL;
 
+// ==================================================================
 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
 begin
 end;
 
-// =============
+procedure doStepCloud(Gear: PVisualGear; Steps: Longword);
+begin
+Gear^.X:= Gear^.X + (cWindSpeed * 200 + Gear^.dX) * Steps;
+if hwRound(Gear^.Y) > -160 then Gear^.dY:= Gear^.dY - _1div50000
+                           else Gear^.dY:= Gear^.dY + _1div50000;
+Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
+if hwRound(Gear^.X) < -cScreenWidth - 256 then Gear^.X:= int2hwFloat(cScreenWidth + 2048) else
+if hwRound(Gear^.X) > cScreenWidth + 2048 then Gear^.X:= int2hwFloat(-cScreenWidth - 256)
+end;
+
+// ==================================================================
 const doStepHandlers: array[TVisualGearType] of TVGearStepProcedure =
                         (
-                          @doStepFlake
+                          @doStepFlake,
+                          @doStepCloud
                         );
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; dX, dY: hwFloat): PVisualGear;
@@ -68,6 +79,10 @@
 Result^.dY:= dY;
 Result^.doStep:= doStepHandlers[Kind];
 
+case Kind of
+   vgtCloud: Result^.State:= random(4);
+     end;
+
 if VisualGearsList <> nil then
    begin
    VisualGearsList^.PrevGear:= Result;
@@ -82,6 +97,8 @@
 procedure ProcessVisualGears(Steps: Longword);
 var Gear, t: PVisualGear;
 begin
+if Steps = 0 then exit;
+
 t:= VisualGearsList;
 while t <> nil do
       begin
@@ -98,8 +115,8 @@
 while Gear <> nil do
       begin
       case Gear^.Kind of
-//           gtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, nil);
            vgtFlake: ;
+           vgtCloud: DrawSprite(sprCloud, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, nil);
               end;
       Gear:= Gear^.NextGear
       end;
@@ -108,7 +125,7 @@
 procedure AddClouds;
 var i: LongInt;
     dx, dy: hwFloat;
-begin(*
+begin
 for i:= 0 to cCloudsNumber do
     begin
     dx.isNegative:= random(2) = 1;
@@ -117,7 +134,7 @@
     dy.QWordValue:= 21474836 + random(64424509);
     AddVisualGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140,
              vgtCloud, dx, dy)
-    end*)
+    end
 end;
 
 initialization
--- a/hedgewars/uWorld.pas	Fri Mar 07 17:43:05 2008 +0000
+++ b/hedgewars/uWorld.pas	Fri Mar 07 18:10:03 2008 +0000
@@ -38,7 +38,8 @@
     Frames: Longword = 0;
 
 implementation
-uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL, uAmmos;
+uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL,
+     uAmmos, uVisualGears;
 const FPS: Longword = 0;
       CountTicks: Longword = 0;
       SoundTimerTicks: Longword = 0;
@@ -183,6 +184,8 @@
 DrawRepeated(sprSky, WorldDx * 3 div 8);
 DrawRepeated(sprHorizont, WorldDx * 3 div 5);
 
+DrawVisualGears;
+
 // Waves
 {$WARNINGS OFF}
 for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * 256  + ((WorldDx + (RealTicks shr 6)      ) and $FF), cWaterLine + WorldDy - 64, 0, Surface);