Attack angle constraints
authorunc0rr
Sun, 17 Dec 2006 20:50:49 +0000
changeset 304 8096e69e839e
parent 303 1659c4aad5ab
child 305 1c1cd66ffcdc
Attack angle constraints
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uConsts.pas
hedgewars/uMisc.pas
hedgewars/uTeams.pas
--- a/hedgewars/GSHandlers.inc	Sun Dec 17 18:40:04 2006 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Dec 17 20:50:49 2006 +0000
@@ -427,6 +427,7 @@
 
 procedure doStepBlowTorchWork(Gear: PGear);
 var HHGear: PGear;
+    yy: Double;
 begin
 AllInactive:= false;
 dec(Gear.Timer);
@@ -436,16 +437,17 @@
 
 if Gear.Timer mod cHHStepTicks = 0 then
    begin
-   DrawTunnel(HHGear.X, HHGear.Y - 3,
-              Gear.dX, Cos(HHGear.Angle*pi/cMaxAngle) * (-0.5),
-              cHHRadius * 3, cHHRadius * 2 + 4);
+   yy:= Cos(HHGear.Angle*pi/cMaxAngle) * (-0.5);
+   DrawTunnel(HHGear.X, HHGear.Y - 2 + yy * cHHRadius,
+              Gear.dX, yy,
+              cHHRadius * 3, cHHRadius * 2 + 2);
    if Gear.dX < 0 then HHGear.Message:= (HHGear.Message or gm_Left) and not gm_Right
                   else HHGear.Message:= (HHGear.Message or gm_Right) and not gm_Left;
    HedgehogStep(HHGear);
    if (HHGear.State and gstFalling) <> 0 then Gear.Timer:= 0
    end;
    
-if Gear.Timer = 0 then
+if (Gear.Timer = 0) or ((HHGear.Message and gm_Attack) <> 0) then
    begin
    HHGear.Message:= 0;
    DeleteGear(Gear);
@@ -458,6 +460,7 @@
 begin
 HHGear:= PHedgehog(Gear.Hedgehog).Gear;
 HHGear.State:= HHGear.State and not gstAttacking;
+HHGear.Message:= 0;
 Gear.doStep:= doStepBlowTorchWork
 end;
 
--- a/hedgewars/HHHandlers.inc	Sun Dec 17 18:40:04 2006 +0000
+++ b/hedgewars/HHHandlers.inc	Sun Dec 17 20:50:49 2006 +0000
@@ -222,9 +222,9 @@
 procedure HedgehogChAngle(Gear: PGear);
 begin
 if ((Gear.State and (gstMoving or gstFalling)) = 0) then
-   if (Gear.Message and gm_Up    )<>0 then if Gear.Angle > 0         then dec(Gear.Angle)
+   if (Gear.Message and gm_Up    )<>0 then if Gear.Angle > CurMinAngle then dec(Gear.Angle)
    else else
-   if (Gear.Message and gm_Down  )<>0 then if Gear.Angle < cMaxAngle then inc(Gear.Angle);
+   if (Gear.Message and gm_Down  )<>0 then if Gear.Angle < CurMaxAngle then inc(Gear.Angle);
 end;
 
 procedure doStepHedgehog(Gear: PGear); forward;
--- a/hedgewars/uConsts.pas	Sun Dec 17 18:40:04 2006 +0000
+++ b/hedgewars/uConsts.pas	Sun Dec 17 20:50:49 2006 +0000
@@ -92,6 +92,10 @@
       msgGettingConfig     = 'Getting game config...';
 
 const
+      cMaxPower     = 1500;
+      cMaxAngle     = 2048;
+      cPowerDivisor = 1500;
+      
       MAXNAMELEN = 32;
 
       COLOR_LAND = $00FFFFFF;
@@ -292,6 +296,7 @@
                                   Ammo: TAmmo;
                                   Slot: 0..cMaxSlotIndex;
                                   TimeAfterTurn: Longword;
+                                  minAngle, maxAngle: Longword;
                                   end = (
                                   (NameId: sidGrenade;
                                    Ammo: (Propz: ammoprop_Timerable or
@@ -364,7 +369,8 @@
                                           Timer: 0;
                                           AmmoType: amRope);
                                    Slot: 7;
-                                   TimeAfterTurn: 0),
+                                   TimeAfterTurn: 0;
+                                   maxAngle: cMaxAngle div 2),
                                   (NameId: sidMine;
                                    Ammo: (Propz: ammoprop_NoCrosshair;
                                           Count: 2;
@@ -447,7 +453,9 @@
                                           Timer: 0;
                                           AmmoType: amBlowTorch);
                                    Slot: 6;
-                                   TimeAfterTurn: 3000));
+                                   TimeAfterTurn: 3000;
+                                   minAngle: 510;
+                                   maxAngle: 1400));
 
 implementation
 
--- a/hedgewars/uMisc.pas	Sun Dec 17 18:40:04 2006 +0000
+++ b/hedgewars/uMisc.pas	Sun Dec 17 20:50:49 2006 +0000
@@ -72,11 +72,6 @@
     cVolumeDelta  : integer = 0;
     cTimerInterval   : Longword = 5;
 
-const
-    cMaxPower     = 1500;
-    cMaxAngle     = 2048;
-    cPowerDivisor = 1500;
-
 var
     cSendEmptyPacketTime : LongWord = 2000;
     cSendCursorPosTime   : LongWord = 50;
--- a/hedgewars/uTeams.pas	Sun Dec 17 18:40:04 2006 +0000
+++ b/hedgewars/uTeams.pas	Sun Dec 17 20:50:49 2006 +0000
@@ -56,6 +56,7 @@
 
 var CurrentTeam: PTeam = nil;
     TeamsList: PTeam = nil;
+    CurMinAngle, CurMaxAngle: Longword;
 
 function AddTeam: PTeam;
 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
@@ -232,6 +233,15 @@
 
 with Ammo[CurSlot, CurAmmo] do
      begin
+     CurMinAngle:= Ammoz[AmmoType].minAngle;
+     if Ammoz[AmmoType].maxAngle <> 0 then CurMaxAngle:= Ammoz[AmmoType].maxAngle
+                                      else CurMaxAngle:= cMaxAngle;
+     with Hedgehog.Gear^ do
+        begin
+        if Angle < CurMinAngle then Angle:= CurMinAngle;
+        if Angle > CurMaxAngle then Angle:= CurMaxAngle;
+        end;
+        
      s:= trammo[Ammoz[AmmoType].NameId];
      if Count <> AMMO_INFINITE then
         s:= s + ' (' + IntToStr(Count) + ')';