hedgewars/HHHandlers.inc
changeset 4365 4f2b1a152979
parent 4301 4866cc130b8d
child 4372 3836973380b9
equal deleted inserted replaced
4363:e944cc43f7a4 4365:4f2b1a152979
    46     ammoidx: LongInt;
    46     ammoidx: LongInt;
    47 begin
    47 begin
    48 ChangeAmmo:= false;
    48 ChangeAmmo:= false;
    49 slot:= Gear^.MsgParam;
    49 slot:= Gear^.MsgParam;
    50 
    50 
    51 with PHedgehog(Gear^.Hedgehog)^ do
    51 with Gear^.Hedgehog^ do
    52     begin
    52     begin
    53     Gear^.Message:= Gear^.Message and not gmSlot;
    53     Gear^.Message:= Gear^.Message and not gmSlot;
    54     ammoidx:= 0;
    54     ammoidx:= 0;
    55     if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or
    55     if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or
    56        (TargetPoint.X <> NoPointX) or
    56        (TargetPoint.X <> NoPointX) or
    58        ((Gear^.State and gstHHDriven) = 0) then exit;
    58        ((Gear^.State and gstHHDriven) = 0) then exit;
    59     ChangeAmmo:= true;
    59     ChangeAmmo:= true;
    60 
    60 
    61     while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do inc(ammoidx);
    61     while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do inc(ammoidx);
    62 
    62 
    63     if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then OnUsedAmmo(PHedgehog(Gear^.Hedgehog)^);
    63     if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then OnUsedAmmo(Gear^.Hedgehog^);
    64 
    64 
    65     MultiShootAttacks:= 0;
    65     MultiShootAttacks:= 0;
    66     Gear^.Message:= Gear^.Message and not (gmLJump or gmHJump);
    66     Gear^.Message:= Gear^.Message and not (gmLJump or gmHJump);
    67     
    67     
    68     if Ammoz[CurAmmoType].Slot = slot then
    68     if Ammoz[CurAmmoType].Slot = slot then
    99     weap: TAmmoType;
    99     weap: TAmmoType;
   100     Hedgehog: PHedgehog;
   100     Hedgehog: PHedgehog;
   101     s: boolean;
   101     s: boolean;
   102 begin
   102 begin
   103 weap:= TAmmoType(Gear^.MsgParam);
   103 weap:= TAmmoType(Gear^.MsgParam);
   104 Hedgehog:= PHedgehog(Gear^.Hedgehog);
   104 Hedgehog:= Gear^.Hedgehog;
   105 
   105 
   106 if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon is not activated yet
   106 if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon is not activated yet
   107 
   107 
   108 Gear^.MsgParam:= Ammoz[weap].Slot;
   108 Gear^.MsgParam:= Ammoz[weap].Slot;
   109 
   109 
   116         begin
   116         begin
   117         s:= ChangeAmmo(Gear);
   117         s:= ChangeAmmo(Gear);
   118         dec(t)
   118         dec(t)
   119         end;
   119         end;
   120 
   120 
   121 if s then ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
   121 if s then ApplyAmmoChanges(Gear^.Hedgehog^)
   122 end;
   122 end;
   123 
   123 
   124 procedure HHSetTimer(Gear: PGear);
   124 procedure HHSetTimer(Gear: PGear);
   125 var CurWeapon: PAmmo;
   125 var CurWeapon: PAmmo;
   126 begin
   126 begin
   127 Gear^.Message:= Gear^.Message and not gmTimer;
   127 Gear^.Message:= Gear^.Message and not gmTimer;
   128 CurWeapon:= GetAmmoEntry(PHedgehog(Gear^.Hedgehog)^);
   128 CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
   129 with PHedgehog(Gear^.Hedgehog)^ do
   129 with Gear^.Hedgehog^ do
   130     if (CurWeapon^.Propz and ammoprop_Timerable) <> 0 then
   130     if (CurWeapon^.Propz and ammoprop_Timerable) <> 0 then
   131         begin
   131         begin
   132         CurWeapon^.Timer:= 1000 * Gear^.MsgParam;
   132         CurWeapon^.Timer:= 1000 * Gear^.MsgParam;
   133         with CurrentTeam^ do
   133         with CurrentTeam^ do
   134             ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
   134             ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
   141     tmpGear: PVisualGear;
   141     tmpGear: PVisualGear;
   142     CurWeapon: PAmmo;
   142     CurWeapon: PAmmo;
   143     altUse: boolean;
   143     altUse: boolean;
   144 begin
   144 begin
   145 bShowFinger:= false;
   145 bShowFinger:= false;
   146 CurWeapon:= GetAmmoEntry(PHedgehog(Gear^.Hedgehog)^);
   146 CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
   147 with Gear^,
   147 with Gear^,
   148      PHedgehog(Gear^.Hedgehog)^ do
   148      Gear^.Hedgehog^ do
   149      begin
   149      begin
   150      if ((State and gstHHDriven) <> 0)and
   150      if ((State and gstHHDriven) <> 0)and
   151         ((State and (gstAttacked or gstHHChooseTarget)) = 0) and
   151         ((State and (gstAttacked or gstHHChooseTarget)) = 0) and
   152         (((State and gstMoving) = 0) or
   152         (((State and gstMoving) = 0) or
   153             // Allow attacks while moving on ammo with AltAttack
   153             // Allow attacks while moving on ammo with AltAttack
   384 ////////////////////////////////////////////////////////////////////////////////
   384 ////////////////////////////////////////////////////////////////////////////////
   385 procedure doStepHedgehogDead(Gear: PGear);
   385 procedure doStepHedgehogDead(Gear: PGear);
   386 const frametime = 200;
   386 const frametime = 200;
   387       timertime = frametime * 6;
   387       timertime = frametime * 6;
   388 begin
   388 begin
   389 if PHedgehog(Gear^.Hedgehog)^.Unplaced then exit;
   389 if Gear^.Hedgehog^.Unplaced then exit;
   390 if Gear^.Timer > 1 then
   390 if Gear^.Timer > 1 then
   391     begin
   391     begin
   392     AllInactive:= false;
   392     AllInactive:= false;
   393     dec(Gear^.Timer);
   393     dec(Gear^.Timer);
   394     if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
   394     if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
   404     begin
   404     begin
   405     AllInactive:= false;
   405     AllInactive:= false;
   406     Gear^.Z:= cCurrHHZ;
   406     Gear^.Z:= cCurrHHZ;
   407     RemoveGearFromList(Gear);
   407     RemoveGearFromList(Gear);
   408     InsertGearToList(Gear);
   408     InsertGearToList(Gear);
   409     PlaySound(sndByeBye, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   409     PlaySound(sndByeBye, Gear^.Hedgehog^.Team^.voicepack);
   410     Gear^.Pos:= 0;
   410     Gear^.Pos:= 0;
   411     Gear^.Timer:= timertime
   411     Gear^.Timer:= timertime
   412     end
   412     end
   413 end;
   413 end;
   414 
   414 
   415 ////////////////////////////////////////////////////////////////////////////////
   415 ////////////////////////////////////////////////////////////////////////////////
   416 procedure doStepHedgehogGone(Gear: PGear);
   416 procedure doStepHedgehogGone(Gear: PGear);
   417 const frametime = 65;
   417 const frametime = 65;
   418       timertime = frametime * 11;
   418       timertime = frametime * 11;
   419 begin
   419 begin
   420 if PHedgehog(Gear^.Hedgehog)^.Unplaced then exit;
   420 if Gear^.Hedgehog^.Unplaced then exit;
   421 if Gear^.Timer > 1 then
   421 if Gear^.Timer > 1 then
   422     begin
   422     begin
   423     AllInactive:= false;
   423     AllInactive:= false;
   424     dec(Gear^.Timer);
   424     dec(Gear^.Timer);
   425     if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
   425     if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
   432     begin
   432     begin
   433     AllInactive:= false;
   433     AllInactive:= false;
   434     Gear^.Z:= cCurrHHZ;
   434     Gear^.Z:= cCurrHHZ;
   435     RemoveGearFromList(Gear);
   435     RemoveGearFromList(Gear);
   436     InsertGearToList(Gear);
   436     InsertGearToList(Gear);
   437     PlaySound(sndByeBye, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   437     PlaySound(sndByeBye, Gear^.Hedgehog^.Team^.voicepack);
   438     PlaySound(sndWarp);
   438     PlaySound(sndWarp);
   439     Gear^.Pos:= 0;
   439     Gear^.Pos:= 0;
   440     Gear^.Timer:= timertime
   440     Gear^.Timer:= timertime
   441     end
   441     end
   442 end;
   442 end;
   495 
   495 
   496 procedure HedgehogStep(Gear: PGear);
   496 procedure HedgehogStep(Gear: PGear);
   497 var PrevdX: LongInt;
   497 var PrevdX: LongInt;
   498     CurWeapon: PAmmo;
   498     CurWeapon: PAmmo;
   499 begin
   499 begin
   500 CurWeapon:= GetAmmoEntry(PHedgehog(Gear^.Hedgehog)^);
   500 CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
   501 if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then
   501 if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then
   502    begin
   502    begin
   503    if isCursorVisible then
   503    if isCursorVisible then
   504       with PHedgehog(Gear^.Hedgehog)^ do
   504       with Gear^.Hedgehog^ do
   505         with CurWeapon^ do
   505         with CurWeapon^ do
   506           begin
   506           begin
   507           if (Gear^.Message and gmLeft  ) <> 0 then
   507           if (Gear^.Message and gmLeft  ) <> 0 then
   508              Pos:= (Pos - 1 + Ammoz[AmmoType].PosCount) mod Ammoz[AmmoType].PosCount
   508              Pos:= (Pos - 1 + Ammoz[AmmoType].PosCount) mod Ammoz[AmmoType].PosCount
   509           else
   509           else
   534          or   TestCollisionYwithGear(Gear, -1)) then
   534          or   TestCollisionYwithGear(Gear, -1)) then
   535          begin
   535          begin
   536          Gear^.dY:= -_0_15;
   536          Gear^.dY:= -_0_15;
   537          if not cArtillery then Gear^.dX:= SignAs(_0_15, Gear^.dX);
   537          if not cArtillery then Gear^.dX:= SignAs(_0_15, Gear^.dX);
   538          Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   538          Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   539          PlaySound(sndJump1, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   539          PlaySound(sndJump1, Gear^.Hedgehog^.Team^.voicepack);
   540          exit
   540          exit
   541          end;
   541          end;
   542       end;
   542       end;
   543 
   543 
   544    if ((Gear^.Message and gmHJump ) <> 0) then
   544    if ((Gear^.Message and gmHJump ) <> 0) then
   547       Gear^.Message:= Gear^.Message and not gmHJump;
   547       Gear^.Message:= Gear^.Message and not gmHJump;
   548 
   548 
   549       Gear^.dY:= -_0_2;
   549       Gear^.dY:= -_0_2;
   550       SetLittle(Gear^.dX);
   550       SetLittle(Gear^.dX);
   551       Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   551       Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
   552       PlaySound(sndJump3, PHedgehog(Gear^.Hedgehog)^.Team^.voicepack);
   552       PlaySound(sndJump3, Gear^.Hedgehog^.Team^.voicepack);
   553       exit
   553       exit
   554       end;
   554       end;
   555 
   555 
   556    PrevdX:= hwSign(Gear^.dX);
   556    PrevdX:= hwSign(Gear^.dX);
   557    if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
   557    if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
   568       FollowGear:= Gear;
   568       FollowGear:= Gear;
   569       exit
   569       exit
   570       end;
   570       end;
   571    DeleteCI(Gear); // must be after exit!! (see previous line)
   571    DeleteCI(Gear); // must be after exit!! (see previous line)
   572 
   572 
   573    PHedgehog(Gear^.Hedgehog)^.visStepPos:= (PHedgehog(Gear^.Hedgehog)^.visStepPos + 1) and 7;
   573    Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7;
   574    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   574    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   575       begin
   575       begin
   576       if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
   576       if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
   577          or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1;
   577          or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1;
   578       if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
   578       if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
   628 end;
   628 end;
   629 
   629 
   630 procedure HedgehogChAngle(Gear: PGear);
   630 procedure HedgehogChAngle(Gear: PGear);
   631 var da: LongWord;
   631 var da: LongWord;
   632 begin
   632 begin
   633 with PHedgehog(Gear^.Hedgehog)^ do
   633 with Gear^.Hedgehog^ do
   634     if (CurAmmoType = amRope)
   634     if (CurAmmoType = amRope)
   635     and ((Gear^.State and (gstMoving or gstHHJumping)) = gstMoving) then da:= 2 else da:= 1;
   635     and ((Gear^.State and (gstMoving or gstHHJumping)) = gstMoving) then da:= 2 else da:= 1;
   636 
   636 
   637 if (((Gear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
   637 if (((Gear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
   638     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Angle >= CurMinAngle + da) then dec(Gear^.Angle, da)
   638     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Angle >= CurMinAngle + da) then dec(Gear^.Angle, da)
   647 begin
   647 begin
   648 isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius;
   648 isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius;
   649 if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862;
   649 if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862;
   650 if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862;
   650 if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862;
   651 
   651 
   652 if PHedgehog(Gear^.Hedgehog)^.Unplaced then
   652 if Gear^.Hedgehog^.Unplaced then
   653    begin
   653    begin
   654    Gear^.dY:= _0;
   654    Gear^.dY:= _0;
   655    Gear^.dX:= _0;
   655    Gear^.dX:= _0;
   656    Gear^.State:= Gear^.State and not gstMoving;
   656    Gear^.State:= Gear^.State and not gstMoving;
   657    exit
   657    exit
   771 procedure doStepHedgehogDriven(Gear: PGear);
   771 procedure doStepHedgehogDriven(Gear: PGear);
   772 var t: PGear;
   772 var t: PGear;
   773     wasJumping: boolean;
   773     wasJumping: boolean;
   774     Hedgehog: PHedgehog;
   774     Hedgehog: PHedgehog;
   775 begin
   775 begin
   776 Hedgehog:= PHedgehog(Gear^.Hedgehog);
   776 Hedgehog:= Gear^.Hedgehog;
   777 if not isInMultiShoot then
   777 if not isInMultiShoot then
   778    AllInactive:= false
   778    AllInactive:= false
   779 else
   779 else
   780    Gear^.Message:= 0;
   780    Gear^.Message:= 0;
   781 
   781 
   917         Gear^.Timer:= 0;
   917         Gear^.Timer:= 0;
   918         FollowGear:= Gear;
   918         FollowGear:= Gear;
   919         PrvInactive:= false;
   919         PrvInactive:= false;
   920         AllInactive:= false;
   920         AllInactive:= false;
   921 
   921 
   922         if not PHedgehog(Gear^.Hedgehog)^.Team^.hasGone then
   922         if not Gear^.Hedgehog^.Team^.hasGone then
   923             begin
   923             begin
   924             PHedgehog(Gear^.Hedgehog)^.Effects[hePoisoned] := false;
   924             Gear^.Hedgehog^.Effects[hePoisoned] := false;
   925             if PHedgehog(Gear^.Hedgehog)^.Effects[heResurrectable] then begin
   925             if Gear^.Hedgehog^.Effects[heResurrectable] then begin
   926                 ResurrectHedgehog(Gear);
   926                 ResurrectHedgehog(Gear);
   927             end else begin
   927             end else begin
   928                 Gear^.State:= Gear^.State or gstHHDeath;
   928                 Gear^.State:= Gear^.State or gstHHDeath;
   929                 Gear^.doStep:= @doStepHedgehogDead;
   929                 Gear^.doStep:= @doStepHedgehogDead;
   930                 // Death message
   930                 // Death message
   931                 AddCaption(Format(GetEventString(eidDied), PHedgehog(Gear^.Hedgehog)^.Name), cWhiteColor, capgrpMessage);
   931                 AddCaption(Format(GetEventString(eidDied), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
   932             end;
   932             end;
   933             end
   933             end
   934         else
   934         else
   935             begin
   935             begin
   936             Gear^.State:= Gear^.State or gstHHGone;
   936             Gear^.State:= Gear^.State or gstHHGone;
   937             Gear^.doStep:= @doStepHedgehogGone;
   937             Gear^.doStep:= @doStepHedgehogGone;
   938             // Gone message
   938             // Gone message
   939             AddCaption(Format(GetEventString(eidGone), PHedgehog(Gear^.Hedgehog)^.Name), cWhiteColor, capgrpMessage);
   939             AddCaption(Format(GetEventString(eidGone), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
   940             end
   940             end
   941         end;
   941         end;
   942     exit
   942     exit
   943     end;
   943     end;
   944 
   944 
   972 
   972 
   973 if (Gear^.State and gstHHDriven) = 0 then
   973 if (Gear^.State and gstHHDriven) = 0 then
   974     doStepHedgehogFree(Gear)
   974     doStepHedgehogFree(Gear)
   975 else
   975 else
   976     begin
   976     begin
   977     with PHedgehog(Gear^.Hedgehog)^ do
   977     with Gear^.Hedgehog^ do
   978         if Team^.hasGone then TeamGoneEffect(Team^);
   978         if Team^.hasGone then TeamGoneEffect(Team^);
   979     doStepHedgehogDriven(Gear)
   979     doStepHedgehogDriven(Gear)
   980     end;
   980     end;
   981 end;
   981 end;