more proper implementation of TARDIS
authornemo
Wed, 31 Aug 2011 00:58:48 -0400
changeset 5706 4454aa0523e7
parent 5704 718f98a9df12
child 5708 8972de340fa1
more proper implementation of TARDIS
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uGears.pas
hedgewars/uGearsRender.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
share/hedgewars/Data/Graphics/AmmoMenu/Ammos.png
share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw.png
share/hedgewars/Data/Graphics/TARDIS.png
--- a/hedgewars/GSHandlers.inc	Tue Aug 30 12:32:33 2011 -0400
+++ b/hedgewars/GSHandlers.inc	Wed Aug 31 00:58:48 2011 -0400
@@ -1226,21 +1226,21 @@
     b := false;
 
     if abs(LongInt(HHGear^.Angle) - BTPrevAngle) > 7  then
-    begin
+        begin
         Gear^.dX := SignAs(AngleSin(HHGear^.Angle) * _0_5, HHGear^.dX);
         Gear^.dY := AngleCos(HHGear^.Angle) * ( - _0_5);
         BTPrevAngle := HHGear^.Angle;
         b := true
-    end;
+        end;
 
     if ((HHGear^.State and gstMoving) <> 0) then
-    begin
+        begin
         doStepHedgehogMoving(HHGear);
         if (HHGear^.State and gstHHDriven) = 0 then Gear^.Timer := 0
-    end;
+        end;
 
     if Gear^.Timer mod cHHStepTicks = 0 then
-    begin
+        begin
         b := true;
         if Gear^.dX.isNegative then
             HHGear^.Message := (HHGear^.Message and (gmAttack or gmUp or gmDown)) or gmLeft
@@ -1248,7 +1248,7 @@
             HHGear^.Message := (HHGear^.Message and (gmAttack or gmUp or gmDown)) or gmRight;
 
         if ((HHGear^.State and gstMoving) = 0) then
-        begin
+            begin
             HHGear^.State := HHGear^.State and not gstAttacking;
             prevX := hwRound(HHGear^.X);
 
@@ -1261,24 +1261,24 @@
                CheckLandValue(hwRound(HHGear^.X + SignAs(_6, HHGear^.dX)), hwRound(HHGear^.Y),
                lfIndestructible) then HHGear^.X := HHGear^.X + SignAs(_1, HHGear^.dX);
             HHGear^.State := HHGear^.State or gstAttacking
-        end;
+            end;
 
         inc(BTSteps);
         if BTSteps = 7 then
-        begin
+            begin
             BTSteps := 0;
             if CheckLandValue(hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_6,
                Gear^.dX)), hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)),
                lfIndestructible) then
-            begin
+                begin
                 Gear^.X := HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC);
                 Gear^.Y := HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC);
-            end;
+                end;
             HHGear^.State := HHGear^.State or gstNoDamage;
             AmmoShove(Gear, 2, 15);
             HHGear^.State := HHGear^.State and not gstNoDamage
+            end;
         end;
-    end;
 
     if b then
         DrawTunnel(HHGear^.X - Gear^.dX * cHHRadius, HHGear^.Y - _4 - Gear^.dY * cHHRadius + hwAbs(
@@ -1287,12 +1287,12 @@
         cHHRadius * 5, cHHRadius * 2 + 7);
 
     if (Gear^.Timer = 0) or ((HHGear^.Message and gmAttack) <> 0) then
-    begin
+        begin
         HHGear^.Message := 0;
         HHGear^.State := HHGear^.State and (not gstNotKickable);
         DeleteGear(Gear);
         AfterAttack
-    end
+        end
 end;
 
 procedure doStepBlowTorch(Gear: PGear);
@@ -2949,10 +2949,8 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepSeductionWork(Gear: PGear);
-var 
-    x, y, i: LongInt;
+var i: LongInt;
     hogs: TPGearArray;
-    d: hwFloat;
 begin
     AllInactive := false;
     hogs := GearsNear(Gear^.X, Gear^.Y, gtHedgehog, Gear^.Radius);
@@ -3678,10 +3676,10 @@
     AllInactive := false;
     FollowGear := HHGear;
     with HHGear^ do
-    begin
+        begin
         State := State and not gstAttacking;
         Message := Message and not (gmAttack or gmUp or gmPrecise or gmLeft or gmRight)
-    end
+        end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -4902,47 +4900,127 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-procedure doStepTardis(Gear: PGear);
-(*var 
-    i, x, y: LongInt;
-    dX, dY: hwFloat;
-    Fire: PGear;
-    vg: PVisualGear;*)
+(*
+ TARDIS needs 
+ Warp in.  Pos = 1
+ Pause.    Pos = 2
+ Hide gear  (TARDIS hedgehog was nil)
+ Warp out. Pos = 3
+ ... idle active for some time period ...  Pos = 4
+ Warp in.  Pos = 1
+ Pause.    Pos = 2
+ Restore gear  (TARDIS hedgehog was not nil)
+ Warp out. Pos = 3
+*)
+
+procedure doStepTardisWarp(Gear: PGear);
+var HH: PHedgehog;
+    i,j,cnt: LongWord;
 begin
-    if (Gear^.State and gstTmpFlag) = 0 then dec(Gear^.Timer);
-    if (Gear^.Timer = 0) and (CurAmmoGear = Gear) then
+
+HH:= Gear^.Hedgehog;
+if Gear^.Pos = 2 then
+    begin
+    if (Gear^.Timer = 0) then
         begin
-        if (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then 
+        if HH^.Gear <> nil then
             begin
-            DeleteGear(Gear);
-            exit
+            if Gear = CurAmmoGear then CurAmmoGear := nil;
+            DeleteCI(HH^.Gear);
+            RemoveGearFromList(HH^.Gear);
+            HH^.Gear^.Z := cHHZ;
+            HH^.Gear^.Active := false;
+            HH^.Gear^.State:= HH^.Gear^.State and not (gstHHDriven or gstAttacking);
+            HH^.GearHidden:= HH^.Gear;
+            HH^.Gear:= nil
+            end
+        else if HH^.GearHidden <> nil then
+            begin
+            HH^.Gear:= HH^.GearHidden;
+            HH^.GearHidden:= nil;
+            InsertGearToList(HH^.Gear);
+            HH^.Gear^.State:= (HH^.Gear^.State or gstAttacked) and not gstHHDriven;
+            AddGearCI(HH^.Gear);
+            HH^.Gear^.Active:= true
             end;
-        if Gear = CurAmmoGear then CurAmmoGear := nil;
-        Gear^.Hedgehog:= CurrentHedgehog;
-        RemoveGearFromList(CurrentHedgehog^.Gear);
-        CurrentHedgehog^.Gear^.Z := cHHZ;
-        CurrentHedgehog^.Gear^.Active := false;
-        CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and not gstHHDriven;
-        CurrentHedgehog^.GearHidden:= CurrentHedgehog^.Gear;
-        CurrentHedgehog^.Gear:= nil;
-        Gear^.State:= Gear^.State or gstTmpFlag;
-        Gear^.Timer:= GameTicks + GetRandom(cHedgehogTurnTime*TeamsCount)+cHedgehogTurnTime;
-        end
-    else if (((Gear^.State and gstTmpFlag) <> 0) and (Gear^.Timer = GameTicks)) or SuddenDeath then
+        end;
+
+    inc(Gear^.Timer);
+    if (Gear^.Timer > 2000) and ((GameTicks mod 2000) = 1000) then
+        begin
+        Gear^.Pos:= 3;
+        end;
+    end;
+
+if (Gear^.Pos = 1) and (GameTicks and $1F = 0) and (Gear^.Power < 255) then inc(Gear^.Power);
+if (Gear^.Pos = 3) and (GameTicks and $1F = 0) and (Gear^.Power > 0) then dec(Gear^.Power);
+if (Gear^.Pos = 1) and (Gear^.Power = 255) and ((GameTicks mod 2000) = 1000) then Gear^.Pos:= 2;
+if (Gear^.Pos = 3) and (Gear^.Power = 0) then
+    begin
+    Gear^.Pos:= 4;
+    // This condition might need tweaking
+    Gear^.Timer:= GetRandom(cHedgehogTurnTime*TeamsCount)+cHedgehogTurnTime
+    end;
+
+if (Gear^.Pos = 4) then
+    begin
+    cnt:= 0;
+    for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do
+        for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do
+            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) and
+               ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) and
+               (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health >
+                HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt);
+    if (cnt = 0) or SuddenDeathDmg or (Gear^.Timer = 0) then
         begin
-        if Gear^.Hedgehog <> nil then
+        Gear^.Pos:= 1;
+        Gear^.Power:= 0;
+        Gear^.Timer:= 0;
+        FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH,true);
+        if HH^.GearHidden <> nil then 
             begin
-            Gear^.Hedgehog^.Gear:= Gear^.Hedgehog^.GearHidden;
-            Gear^.Hedgehog^.GearHidden:= nil;
-            FindPlace(Gear^.Hedgehog^.Gear, false, 0, LAND_WIDTH,true);
-            InsertGearToList(Gear^.Hedgehog^.Gear);
-            Gear^.Hedgehog^.Gear^.State:= (Gear^.Hedgehog^.Gear^.State or gstTmpFlag or gstAttacked) and not gstHHDriven;
-            Gear^.Hedgehog^.Gear^.Timer:= $FF;
-            Gear^.Hedgehog^.Gear^.doStep:= @doStepHedgehogReturn;
-            SetAllHHToActive;
-            end;
-            DeleteGear(Gear)
+            Gear^.X:= HH^.GearHidden^.X;
+            Gear^.Y:= HH^.GearHidden^.Y;
+            end
         end
+    else dec(Gear^.Timer);
+    end;
+
+end;
+
+procedure doStepTardis(Gear: PGear);
+var i,j,cnt: LongWord;
+    HH: PHedgehog;
+begin
+(*
+    Conditions for not activating.
+    1. Hog is last of his clan
+    2. Sudden Death is in play
+    3. Hog is a king
+*)
+    HH:= Gear^.Hedgehog;
+    if (HH^.Gear = nil) or (HH^.King) or (SuddenDeathDmg) then
+        begin
+        DeleteGear(gear);
+        exit
+        end;
+    cnt:= 0;
+    for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do
+        for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do
+            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) and
+               ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) and
+               (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health >
+                HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt);
+    if cnt < 2 then
+        begin
+        DeleteGear(gear);
+        exit
+        end;
+    with HH^.Gear^ do
+        begin
+        Message := Message and not gmAttack
+        end;
+    Gear^.doStep:= @doStepTardisWarp
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/HHHandlers.inc	Tue Aug 30 12:32:33 2011 -0400
+++ b/hedgewars/HHHandlers.inc	Wed Aug 31 00:58:48 2011 -0400
@@ -1093,13 +1093,3 @@
     doStepHedgehogDriven(Gear)
     end;
 end;
-
-procedure doStepHedgehogReturn(Gear: PGear);
-begin
-if (Gear^.Timer > 0) and ((GameTicks mod 20) = 0) then dec(Gear^.Timer)
-else if (Gear^.Timer = 0) then
-    begin
-    Gear^.doStep:= @doStepHedgehog;
-    Gear^.State:= Gear^.State and not gstTmpFlag;
-    end
-end;
--- a/hedgewars/uGears.pas	Tue Aug 30 12:32:33 2011 -0400
+++ b/hedgewars/uGears.pas	Wed Aug 31 00:58:48 2011 -0400
@@ -75,7 +75,6 @@
 procedure AfterAttack; forward;
 procedure HedgehogStep(Gear: PGear); forward;
 procedure doStepHedgehogMoving(Gear: PGear); forward;
-procedure doStepHedgehogReturn(Gear: PGear); forward;
 procedure HedgehogChAngle(HHGear: PGear); forward;
 procedure ShotgunShot(Gear: PGear); forward;
 procedure PickUp(HH, Gear: PGear); forward;
@@ -428,6 +427,11 @@
                 gear^.Elasticity:= _0_3;
                 gear^.Timer:= 0
                 end;
+      gtTardis: begin
+                gear^.Timer:= 0;
+                gear^.Pos:= 1;
+                gear^.Z:= cCurrHHZ+1;
+                end;
       gtMortar: begin
                 gear^.Radius:= 4;
                 gear^.Elasticity:= _0_2;
@@ -1450,7 +1454,11 @@
                         ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
                     else
                         Gear^.State:= Gear^.State or gstWinner;
-                    if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
+                    if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
+                        begin
+                        if (Ammo^.Hedgehog^.Gear <> nil) then Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and not gstNotKickable;
+                        ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
+                        end;
 
                     DeleteCI(Gear);
                     if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
--- a/hedgewars/uGearsRender.pas	Tue Aug 30 12:32:33 2011 -0400
+++ b/hedgewars/uGearsRender.pas	Wed Aug 31 00:58:48 2011 -0400
@@ -227,13 +227,6 @@
         Tint($FF, $FF, $FF, $FF)
         end;
 
-    if  (CurAmmoGear <> nil) and 
-        (CurrentHedgehog^.Gear <> nil) and
-        (CurrentHedgehog^.Gear = Gear) and 
-        (CurAmmoGear^.Kind = gtTardis) then Tint($FF, $FF, $FF, CurAmmoGear^.Timer div 20)
-    // probably will need a new flag for this
-    else if (Gear^.State and gstTmpFlag <> 0) then Tint($FF, $FF, $FF, $FF-Gear^.Timer);
-
     if ((Gear^.State and gstWinner) <> 0) and
     ((CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtPickHammer)) then
         begin
@@ -1088,6 +1081,15 @@
 //DrawRotatedF(sprFlake, x-SpritesData[sprFlake].Width div 2, y-SpritesData[sprFlake].Height div 2, Gear^.Timer, 1, Gear^.DirAngle);
                         end;
        gtStructure: DrawSprite(sprTarget, x - 16, y - 16, 0);
+          gtTardis: if Gear^.Pos <> 4 then
+                        begin
+                        if (Gear^.Pos = 1) or (Gear^.Pos = 3) then
+                            Tint($FF, $FF, $FF, max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000)))));
+                        DrawSprite(sprTardis, x-24, y-63,0);
+                        if (Gear^.Pos = 1) or (Gear^.Pos = 3) then
+                            Tint($FF, $FF, $FF, $FF)
+                        end;
+
 
          end;
       if Gear^.RenderTimer and (Gear^.Tex <> nil) then DrawCentered(x + 8, y + 8, Gear^.Tex);
--- a/hedgewars/uTypes.pas	Tue Aug 30 12:32:33 2011 -0400
+++ b/hedgewars/uTypes.pas	Wed Aug 31 00:58:48 2011 -0400
@@ -82,7 +82,7 @@
             sprSMineOff, sprSMineOn, sprHandSMine, sprHammer,
             sprHandResurrector, sprCross, sprAirDrill, sprNapalmBomb,
             sprBulletHit, sprSnowball, sprHandSnowball, sprSnow,
-            sprSDFlake, sprSDWater, sprSDCloud, sprSDSplash, sprSDDroplet
+            sprSDFlake, sprSDWater, sprSDCloud, sprSDSplash, sprSDDroplet, sprTardis
             );
 
     // Gears that interact with other Gears and/or Land
--- a/hedgewars/uVariables.pas	Tue Aug 30 12:32:33 2011 -0400
+++ b/hedgewars/uVariables.pas	Wed Aug 31 00:58:48 2011 -0400
@@ -614,7 +614,9 @@
             (FileName:   'SDSplash'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil;
             Width:  80; Height: 50; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: false; getImageDimensions: true),// sprSDSplash
             (FileName:  'SDDroplet'; Path: ptCurrTheme; AltPath: ptSuddenDeath; Texture: nil; Surface: nil;
-            Width:  16; Height: 16; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true)// sprSDDroplet
+            Width:  16; Height: 16; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprSDDroplet
+            (FileName:  'TARDIS'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width:  0; Height: 0; imageWidth: 0; imageHeight: 0; saveSurf: false; priority: tpMedium; getDimensions: true; getImageDimensions: true)// sprTardis
             );
 
 
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos.png has changed
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw.png has changed
Binary file share/hedgewars/Data/Graphics/TARDIS.png has changed