hedgewars/HHHandlers.inc
changeset 4881 35e6269227b6
parent 4867 e604ee83e34f
child 4976 088d40d8aba2
equal deleted inserted replaced
4880:07e9849c6a70 4881:35e6269227b6
    39         3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack);
    39         3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack);
    40     end
    40     end
    41 end;
    41 end;
    42 
    42 
    43 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
    43 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
    44 function ChangeAmmo(Gear: PGear): boolean;
    44 function ChangeAmmo(HHGear: PGear): boolean;
    45 var slot, i: Longword;
    45 var slot, i: Longword;
    46     ammoidx: LongInt;
    46     ammoidx: LongInt;
    47 begin
    47 begin
    48 ChangeAmmo:= false;
    48 ChangeAmmo:= false;
    49 slot:= Gear^.MsgParam;
    49 slot:= HHGear^.MsgParam;
    50 
    50 
    51 with Gear^.Hedgehog^ do
    51 with HHGear^.Hedgehog^ do
    52     begin
    52     begin
    53     Gear^.Message:= Gear^.Message and not gmSlot;
    53     HHGear^.Message:= HHGear^.Message and not gmSlot;
    54     ammoidx:= 0;
    54     ammoidx:= 0;
    55     if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or
    55     if ((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) or
    56        (TargetPoint.X <> NoPointX) or
    56        (TargetPoint.X <> NoPointX) or
    57        ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or
    57        ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or
    58        ((Gear^.State and gstHHDriven) = 0) then exit;
    58        ((HHGear^.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(Gear^.Hedgehog^);
    63     if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then OnUsedAmmo(HHGear^.Hedgehog^);
    64 
    64 
    65     MultiShootAttacks:= 0;
    65     MultiShootAttacks:= 0;
    66     Gear^.Message:= Gear^.Message and not (gmLJump or gmHJump);
    66     HHGear^.Message:= HHGear^.Message and not (gmLJump or gmHJump);
    67     
    67     
    68     if Ammoz[CurAmmoType].Slot = slot then
    68     if Ammoz[CurAmmoType].Slot = slot then
    69         begin
    69         begin
    70         i:= 0;
    70         i:= 0;
    71         repeat
    71         repeat
    92         end;
    92         end;
    93         if ammoidx >= 0 then CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
    93         if ammoidx >= 0 then CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
    94     end
    94     end
    95 end;
    95 end;
    96 
    96 
    97 procedure HHSetWeapon(Gear: PGear);
    97 procedure HHSetWeapon(HHGear: PGear);
    98 var t: LongInt;
    98 var t: LongInt;
    99     weap: TAmmoType;
    99     weap: TAmmoType;
   100     Hedgehog: PHedgehog;
   100     Hedgehog: PHedgehog;
   101     s: boolean;
   101     s: boolean;
   102 begin
   102 begin
   103 s:= false;
   103 s:= false;
   104 
   104 
   105 weap:= TAmmoType(Gear^.MsgParam);
   105 weap:= TAmmoType(HHGear^.MsgParam);
   106 Hedgehog:= Gear^.Hedgehog;
   106 Hedgehog:= HHGear^.Hedgehog;
   107 
   107 
   108 if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon is not activated yet
   108 if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon is not activated yet
   109 
   109 
   110 Gear^.MsgParam:= Ammoz[weap].Slot;
   110 HHGear^.MsgParam:= Ammoz[weap].Slot;
   111 
   111 
   112 t:= cMaxSlotAmmoIndex;
   112 t:= cMaxSlotAmmoIndex;
   113 
   113 
   114 Gear^.Message:= Gear^.Message and not gmWeapon;
   114 HHGear^.Message:= HHGear^.Message and not gmWeapon;
   115 
   115 
   116 with Hedgehog^ do
   116 with Hedgehog^ do
   117     while (CurAmmoType <> weap) and (t >= 0) do
   117     while (CurAmmoType <> weap) and (t >= 0) do
   118         begin
   118         begin
   119         s:= ChangeAmmo(Gear);
   119         s:= ChangeAmmo(HHGear);
   120         dec(t)
   120         dec(t)
   121         end;
   121         end;
   122 
   122 
   123 if s then ApplyAmmoChanges(Gear^.Hedgehog^)
   123 if s then ApplyAmmoChanges(HHGear^.Hedgehog^)
   124 end;
   124 end;
   125 
   125 
   126 procedure HHSetTimer(Gear: PGear);
   126 procedure HHSetTimer(Gear: PGear);
   127 var CurWeapon: PAmmo;
   127 var CurWeapon: PAmmo;
   128 begin
   128 begin
   313                                 gtResurrector, 0, _0, _0, 0);
   313                                 gtResurrector, 0, _0, _0, 0);
   314                         CurAmmoGear^.SoundChannel := LoopSound(sndResurrector);
   314                         CurAmmoGear^.SoundChannel := LoopSound(sndResurrector);
   315                     end;
   315                     end;
   316                    amDrillStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 3, _0, _0, CurWeapon^.Timer);
   316                    amDrillStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 3, _0, _0, CurWeapon^.Timer);
   317                    //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
   317                    //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
       
   318                      amStructure: begin
       
   319                                   FollowGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, 0, SignAs(_0_03, dX), _0, 0);
       
   320                                   FollowGear^.Hedgehog:= Gear^.Hedgehog;
       
   321                                   end;
   318                   end;
   322                   end;
   319 
   323 
   320         uStats.AmmoUsed(CurAmmoType);
   324         uStats.AmmoUsed(CurAmmoType);
   321 
   325 
   322         if not (SpeechText = '') then
   326         if not (SpeechText = '') then
   633    end;
   637    end;
   634    AddGearCI(Gear)
   638    AddGearCI(Gear)
   635    end
   639    end
   636 end;
   640 end;
   637 
   641 
   638 procedure HedgehogChAngle(Gear: PGear);
   642 procedure HedgehogChAngle(HHGear: PGear);
   639 var da: LongWord;
   643 var da: LongWord;
   640 begin
   644 begin
   641 with Gear^.Hedgehog^ do
   645 with HHGear^.Hedgehog^ do
   642     if (CurAmmoType = amRope)
   646     if (CurAmmoType = amRope)
   643     and ((Gear^.State and (gstMoving or gstHHJumping)) = gstMoving) then da:= 2 else da:= 1;
   647     and ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving) then da:= 2 else da:= 1;
   644 
   648 
   645 if (((Gear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
   649 if (((HHGear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
   646     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Angle >= CurMinAngle + da) then dec(Gear^.Angle, da)
   650     if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then dec(HHGear^.Angle, da)
   647     else
   651     else
   648     if ((Gear^.Message and gmDown) <> 0) and (Gear^.Angle + da <= CurMaxAngle) then inc(Gear^.Angle, da)
   652     if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then inc(HHGear^.Angle, da)
   649 end;
   653 end;
   650 
   654 
   651 procedure doStepHedgehog(Gear: PGear); forward;
   655 procedure doStepHedgehog(Gear: PGear); forward;
   652 ////////////////////////////////////////////////////////////////////////////////
   656 ////////////////////////////////////////////////////////////////////////////////
   653 procedure doStepHedgehogMoving(Gear: PGear);
   657 procedure doStepHedgehogMoving(Gear: PGear);
   774     Gear^.FlightTime:= 0;
   778     Gear^.FlightTime:= 0;
   775     end;
   779     end;
   776 
   780 
   777 end;
   781 end;
   778 
   782 
   779 procedure doStepHedgehogDriven(Gear: PGear);
   783 procedure doStepHedgehogDriven(HHGear: PGear);
   780 var t: PGear;
   784 var t: PGear;
   781     wasJumping: boolean;
   785     wasJumping: boolean;
   782     Hedgehog: PHedgehog;
   786     Hedgehog: PHedgehog;
   783 begin
   787 begin
   784 Hedgehog:= Gear^.Hedgehog;
   788 Hedgehog:= HHGear^.Hedgehog;
   785 if not isInMultiShoot then
   789 if not isInMultiShoot then
   786    AllInactive:= false
   790    AllInactive:= false
   787 else
   791 else
   788    Gear^.Message:= 0;
   792    HHGear^.Message:= 0;
   789 
   793 
   790 if (TurnTimeLeft = 0) or (Gear^.Damage > 0) then
   794 if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
   791     begin
   795     begin
   792     TurnTimeLeft:= 0;
   796     TurnTimeLeft:= 0;
   793     isCursorVisible:= false;
   797     isCursorVisible:= false;
   794     Gear^.State:= Gear^.State and not (gstHHDriven or gstAnimation or gstAttacking);
   798     HHGear^.State:= HHGear^.State and not (gstHHDriven or gstAnimation or gstAttacking);
   795     AttackBar:= 0;
   799     AttackBar:= 0;
   796     if Gear^.Damage > 0 then
   800     if HHGear^.Damage > 0 then
   797         Gear^.State:= Gear^.State and not (gstHHJumping or gstHHHJump);
   801         HHGear^.State:= HHGear^.State and not (gstHHJumping or gstHHHJump);
   798     exit
   802     exit
   799     end;
   803     end;
   800 
   804 
   801 if (Gear^.State and gstAnimation) <> 0 then
   805 if (HHGear^.State and gstAnimation) <> 0 then
   802     begin
   806     begin
   803     Gear^.Message:= 0;
   807     HHGear^.Message:= 0;
   804     if (Gear^.Pos = Wavez[TWave(Gear^.Tag)].VoiceDelay) and (Gear^.Timer = 0) then PlaySound(Wavez[TWave(Gear^.Tag)].Voice, Hedgehog^.Team^.voicepack);
   808     if (HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].VoiceDelay) and (HHGear^.Timer = 0) then PlaySound(Wavez[TWave(HHGear^.Tag)].Voice, Hedgehog^.Team^.voicepack);
   805     inc(Gear^.Timer);
   809     inc(HHGear^.Timer);
   806     if Gear^.Timer = Wavez[TWave(Gear^.Tag)].Interval then
   810     if HHGear^.Timer = Wavez[TWave(HHGear^.Tag)].Interval then
   807         begin
   811         begin
   808         Gear^.Timer:= 0;
   812         HHGear^.Timer:= 0;
   809         inc(Gear^.Pos);
   813         inc(HHGear^.Pos);
   810         if Gear^.Pos = Wavez[TWave(Gear^.Tag)].FramesCount then
   814         if HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].FramesCount then
   811             Gear^.State:= Gear^.State and not gstAnimation
   815             HHGear^.State:= HHGear^.State and not gstAnimation
   812         end;
   816         end;
   813     exit
   817     exit
   814     end;
   818     end;
   815 
   819 
   816 if ((Gear^.State and gstMoving) <> 0)
   820 if ((HHGear^.State and gstMoving) <> 0)
   817     or (StepTicks = cHHStepTicks)
   821     or (StepTicks = cHHStepTicks)
   818     or (CurAmmoGear <> nil) then // we are moving
   822     or (CurAmmoGear <> nil) then // we are moving
   819     begin
   823     begin
   820     with Hedgehog^ do
   824     with Hedgehog^ do
   821         if (CurAmmoGear = nil)
   825         if (CurAmmoGear = nil)
   822         and (Gear^.dY > _0_39)
   826         and (HHGear^.dY > _0_39)
   823         and (CurAmmoType = amParachute) then Gear^.Message:= Gear^.Message or gmAttack;
   827         and (CurAmmoType = amParachute) then HHGear^.Message:= HHGear^.Message or gmAttack;
   824     // check for case with ammo
   828     // check for case with ammo
   825     t:= CheckGearNear(Gear, gtCase, 36, 36);
   829     t:= CheckGearNear(HHGear, gtCase, 36, 36);
   826     if t <> nil then
   830     if t <> nil then
   827         PickUp(Gear, t)
   831         PickUp(HHGear, t)
   828     end;
   832     end;
   829 
   833 
   830 if (CurAmmoGear = nil) then
   834 if (CurAmmoGear = nil) then
   831     if (((Gear^.Message and gmAttack) <> 0)
   835     if (((HHGear^.Message and gmAttack) <> 0)
   832         or ((Gear^.State and gstAttacking) <> 0)) then
   836         or ((HHGear^.State and gstAttacking) <> 0)) then
   833         Attack(Gear) // should be before others to avoid desync with '/put' msg and changing weapon msgs
   837         Attack(HHGear) // should be before others to avoid desync with '/put' msg and changing weapon msgs
   834     else
   838     else
   835 else 
   839 else 
   836     with Hedgehog^ do
   840     with Hedgehog^ do
   837         if ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
   841         if ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
   838             and ((Gear^.Message and gmLJump) <> 0)
   842             and ((HHGear^.Message and gmLJump) <> 0)
   839             and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
   843             and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
   840             begin
   844             begin
   841             Attack(Gear);
   845             Attack(HHGear);
   842             Gear^.Message:= Gear^.Message and not gmLJump
   846             HHGear^.Message:= HHGear^.Message and not gmLJump
   843             end;
   847             end;
   844 
   848 
   845 if (CurAmmoGear = nil)
   849 if (CurAmmoGear = nil)
   846     or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) 
   850     or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) 
   847     or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) then
   851     or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) then
   848     begin
   852     begin
   849     if ((Gear^.Message and gmSlot) <> 0) then
   853     if ((HHGear^.Message and gmSlot) <> 0) then
   850         if ChangeAmmo(Gear) then ApplyAmmoChanges(Hedgehog^);
   854         if ChangeAmmo(HHGear) then ApplyAmmoChanges(Hedgehog^);
   851 
   855 
   852     if ((Gear^.Message and gmWeapon) <> 0) then HHSetWeapon(Gear);
   856     if ((HHGear^.Message and gmWeapon) <> 0) then HHSetWeapon(HHGear);
   853 
   857 
   854     if ((Gear^.Message and gmTimer) <> 0) then HHSetTimer(Gear);
   858     if ((HHGear^.Message and gmTimer) <> 0) then HHSetTimer(HHGear);
   855     end;
   859     end;
   856 
   860 
   857 if CurAmmoGear <> nil then
   861 if CurAmmoGear <> nil then
   858    begin
   862    begin
   859    CurAmmoGear^.Message:= Gear^.Message;
   863    CurAmmoGear^.Message:= HHGear^.Message;
   860    exit
   864    exit
   861    end;
   865    end;
   862 
   866 
   863 if not isInMultiShoot then
   867 if not isInMultiShoot then
   864    HedgehogChAngle(Gear);
   868    HedgehogChAngle(HHGear);
   865 
   869 
   866 if (Gear^.State and gstMoving) <> 0 then
   870 if (HHGear^.State and gstMoving) <> 0 then
   867     begin
   871     begin
   868     wasJumping:= ((Gear^.State and gstHHJumping) <> 0);
   872     wasJumping:= ((HHGear^.State and gstHHJumping) <> 0);
   869 
   873 
   870     if ((Gear^.Message and gmHJump) <> 0) and
   874     if ((HHGear^.Message and gmHJump) <> 0) and
   871         wasJumping and
   875         wasJumping and
   872         ((Gear^.State and gstHHHJump) = 0) then
   876         ((HHGear^.State and gstHHHJump) = 0) then
   873         if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
   877         if (not (hwAbs(HHGear^.dX) > cLittle)) and (HHGear^.dY < -_0_02) then
   874             begin
   878             begin
   875             Gear^.State:= Gear^.State or gstHHHJump;
   879             HHGear^.State:= HHGear^.State or gstHHHJump;
   876             Gear^.dY:= -_0_25;
   880             HHGear^.dY:= -_0_25;
   877             if not cArtillery then Gear^.dX:= -SignAs(_0_02, Gear^.dX);
   881             if not cArtillery then HHGear^.dX:= -SignAs(_0_02, HHGear^.dX);
   878             PlaySound(sndJump2, Hedgehog^.Team^.voicepack)
   882             PlaySound(sndJump2, Hedgehog^.Team^.voicepack)
   879             end;
   883             end;
   880 
   884 
   881     Gear^.Message:= Gear^.Message and not (gmLJump or gmHJump);
   885     HHGear^.Message:= HHGear^.Message and not (gmLJump or gmHJump);
   882 
   886 
   883     if (not cArtillery) and wasJumping and
   887     if (not cArtillery) and wasJumping and
   884         TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
   888         TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
   885 
   889 
   886     doStepHedgehogMoving(Gear);
   890     if Hedgehog^.Gear <> nil then doStepHedgehogMoving(HHGear);
   887 
   891 
   888     if ((Gear^.State and (gstMoving or gstDrowning)) = 0) then
   892     if ((HHGear^.State and (gstMoving or gstDrowning)) = 0) then
   889         begin
   893         begin
   890         AddGearCI(Gear);
   894         AddGearCI(HHGear);
   891         if wasJumping then
   895         if wasJumping then
   892             StepTicks:= 410
   896             StepTicks:= 410
   893         else
   897         else
   894             StepTicks:= 95
   898             StepTicks:= 95
   895         end;
   899         end;
   896     exit
   900     exit
   897     end;
   901     end;
   898 
   902 
   899     if not isInMultiShoot then
   903     if not isInMultiShoot and (Hedgehog^.Gear <> nil) then
   900         begin
   904         begin
   901         if StepTicks > 0 then dec(StepTicks);
   905         if StepTicks > 0 then dec(StepTicks);
   902         if (StepTicks = 0) then HedgehogStep(Gear)
   906         if (StepTicks = 0) then HedgehogStep(HHGear)
   903         end
   907         end
   904 end;
   908 end;
   905 
   909 
   906 ////////////////////////////////////////////////////////////////////////////////
   910 ////////////////////////////////////////////////////////////////////////////////
   907 procedure doStepHedgehogFree(Gear: PGear);
   911 procedure doStepHedgehogFree(Gear: PGear);