hedgewars/uGearsHedgehog.pas
changeset 7442 9bb6abdb5675
parent 7390 27bfd8bbde7e
parent 7426 55b49cc1f33a
child 7447 01111960a48d
equal deleted inserted replaced
7392:bc3306c59a08 7442:9bb6abdb5675
    26 procedure AfterAttack; 
    26 procedure AfterAttack; 
    27 procedure HedgehogStep(Gear: PGear); 
    27 procedure HedgehogStep(Gear: PGear); 
    28 procedure doStepHedgehogMoving(Gear: PGear); 
    28 procedure doStepHedgehogMoving(Gear: PGear); 
    29 procedure HedgehogChAngle(HHGear: PGear); 
    29 procedure HedgehogChAngle(HHGear: PGear); 
    30 procedure PickUp(HH, Gear: PGear);
    30 procedure PickUp(HH, Gear: PGear);
       
    31 procedure AddPickup(HH: THedgehog; ammo: TAmmoType; cnt, X, Y: LongWord);
    31 
    32 
    32 implementation
    33 implementation
    33 uses uConsts, uVariables, uFloat, uAmmos, uSound, uCaptions, 
    34 uses uConsts, uVariables, uFloat, uAmmos, uSound, uCaptions, 
    34     uCommands, uLocale, uUtils, uVisualGears, uStats, uIO, uScript,
    35     uCommands, uLocale, uUtils, uVisualGears, uStats, uIO, uScript,
    35     uGearsList, uGears, uCollisions, uRandom, uStore, uTeams, 
    36     uGearsList, uGears, uCollisions, uRandom, uStore, uTeams, 
   563     Gear^.Pos:= 0;
   564     Gear^.Pos:= 0;
   564     Gear^.Timer:= timertime
   565     Gear^.Timer:= timertime
   565     end
   566     end
   566 end;
   567 end;
   567 
   568 
       
   569 procedure AddPickup(HH: THedgehog; ammo: TAmmoType; cnt, X, Y: LongWord);
       
   570 var s: shortstring;
       
   571     vga: PVisualGear;
       
   572 begin
       
   573     PlaySound(sndShotgunReload);
       
   574     if cnt <> 0 then AddAmmo(HH, ammo, cnt)
       
   575     else AddAmmo(HH, ammo);
       
   576 
       
   577     if (not (HH.Team^.ExtDriven 
       
   578     or (HH.BotLevel > 0)))
       
   579     or (HH.Team^.Clan^.ClanIndex = LocalClan)
       
   580     or (GameType = gmtDemo)  then
       
   581         begin
       
   582         if cnt <> 0 then
       
   583             s:= trammo[Ammoz[ammo].NameId] + ' (+' + IntToStr(cnt) + ')'
       
   584         else
       
   585             s:= trammo[Ammoz[ammo].NameId] + ' (+' + IntToStr(Ammoz[ammo].NumberInCase) + ')';
       
   586         AddCaption(s, HH.Team^.Clan^.Color, capgrpAmmoinfo);
       
   587 
       
   588         // show ammo icon
       
   589         vga:= AddVisualGear(X, Y, vgtAmmo);
       
   590         if vga <> nil then
       
   591             vga^.Frame:= Longword(ammo);
       
   592         end;
       
   593 end;
       
   594 
   568 ////////////////////////////////////////////////////////////////////////////////
   595 ////////////////////////////////////////////////////////////////////////////////
   569 procedure PickUp(HH, Gear: PGear);
   596 procedure PickUp(HH, Gear: PGear);
   570 var s: shortstring;
   597 var s: shortstring;
   571     a: TAmmoType;
   598     a: TAmmoType;
   572     i: LongInt;
   599     i: LongInt;
   573     vga: PVisualGear;
   600     vga: PVisualGear;
       
   601     ag, gi: PGear;
   574 begin
   602 begin
   575 Gear^.Message:= gmDestroy;
   603 Gear^.Message:= gmDestroy;
   576 PlaySound(sndShotgunReload);
       
   577 if (Gear^.Pos and posCaseExplode) <> 0 then
   604 if (Gear^.Pos and posCaseExplode) <> 0 then
   578     if (Gear^.Pos and posCasePoison) <> 0 then
   605     if (Gear^.Pos and posCasePoison) <> 0 then
   579         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned)
   606         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned)
   580     else
   607     else
   581         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
   608         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
   583     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned + EXPLNoDamage)
   610     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned + EXPLNoDamage)
   584 else
   611 else
   585 case Gear^.Pos of
   612 case Gear^.Pos of
   586        posCaseUtility,
   613        posCaseUtility,
   587        posCaseAmmo: begin
   614        posCaseAmmo: begin
   588                     if Gear^.AmmoType <> amNothing then a:= Gear^.AmmoType 
   615                     if Gear^.AmmoType <> amNothing then 
       
   616                         begin
       
   617                         AddPickup(HH^.Hedgehog^, Gear^.AmmoType, Gear^.Power, hwRound(Gear^.X), hwRound(Gear^.Y));
       
   618                         end
   589                     else
   619                     else
       
   620                     or (GameType = gmtDemo)  then
   590                         begin
   621                         begin
   591                         for i:= 0 to GameTicks and $7F do
   622 // Add spawning here...
   592                             GetRandom(2); // Burn some random numbers
   623                         AddRandomness(GameTicks);
   593                         if Gear^.Pos = posCaseUtility then
   624                         
   594                             a:= GetUtility(HH^.Hedgehog)
   625                         gi := GearsList;
   595                         else
   626                         while gi <> nil do
   596                             a:= GetAmmo(HH^.Hedgehog)
   627                             begin
       
   628                             if gi^.Kind = gtGenericFaller then
       
   629                                 begin
       
   630                                 gi^.Active:= true;
       
   631                                 gi^.X:= int2hwFloat(GetRandom(rightX-leftX)+leftX);
       
   632                                 gi^.Y:= int2hwFloat(GetRandom(LAND_HEIGHT-topY)+topY);
       
   633                                 gi^.dX:= _90-(GetRandomf*_360);
       
   634                                 gi^.dY:= _90-(GetRandomf*_360)
       
   635                                 end;
       
   636                             gi := gi^.NextGear
       
   637                             end;
       
   638                         ag:= AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAddAmmo, gstInvisible, _0, _0, GetRandom(200)+100);
       
   639                         ag^.Pos:= Gear^.Pos;
       
   640                         ag^.Power:= Gear^.Power
   597                         end;
   641                         end;
   598                     if Gear^.Power <> 0 then AddAmmo(HH^.Hedgehog^, a, Gear^.Power)
       
   599                     else AddAmmo(HH^.Hedgehog^, a);
       
   600 // Possibly needs to check shared clan ammo game flag once added.
       
   601 // On the other hand, no obvious reason that clan members shouldn't know what ammo another clan member picked up
       
   602                     if (not (HH^.Hedgehog^.Team^.ExtDriven 
       
   603                     or (HH^.Hedgehog^.BotLevel > 0)))
       
   604                     or (HH^.Hedgehog^.Team^.Clan^.ClanIndex = LocalClan)
       
   605                     or (GameType in [gmtDemo, gmtRecord])  then
       
   606                         begin
       
   607                         if Gear^.Power <> 0 then
       
   608                             s:= trammo[Ammoz[a].NameId] + ' (+' + IntToStr(Gear^.Power) + ')'
       
   609                         else
       
   610                             s:= trammo[Ammoz[a].NameId] + ' (+' + IntToStr(Ammoz[a].NumberInCase) + ')';
       
   611                         AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
       
   612 
       
   613                         // show ammo icon
       
   614                         vga:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtAmmo);
       
   615                         if vga <> nil then
       
   616                             vga^.Frame:= Longword(a);
       
   617                         end;
       
   618 
       
   619                     end;
   642                     end;
   620      posCaseHealth: begin
   643      posCaseHealth: begin
       
   644                     PlaySound(sndShotgunReload);
   621                     inc(HH^.Health, Gear^.Health);
   645                     inc(HH^.Health, Gear^.Health);
   622                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
   646                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
   623                     str(Gear^.Health, s);
   647                     str(Gear^.Health, s);
   624                     s:= '+' + s;
   648                     s:= '+' + s;
   625                     AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
   649                     AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
   828     Gear^.dY:= _0;
   852     Gear^.dY:= _0;
   829     Gear^.dX:= _0;
   853     Gear^.dX:= _0;
   830     Gear^.State:= Gear^.State and (not gstMoving);
   854     Gear^.State:= Gear^.State and (not gstMoving);
   831     exit
   855     exit
   832     end;
   856     end;
   833 isFalling:= (Gear^.dY.isNegative) or not TestCollisionYKick(Gear, 1);
   857 isFalling:= (Gear^.dY.isNegative) or (not TestCollisionYKick(Gear, 1));
   834 if isFalling then
   858 if isFalling then
   835     begin
   859     begin
   836     if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then
   860     if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then
   837         Gear^.dY:= _0;
   861         Gear^.dY:= _0;
   838     Gear^.State:= Gear^.State or gstMoving;
   862     Gear^.State:= Gear^.State or gstMoving;
   958 if (not isFalling)
   982 if (not isFalling)
   959   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   983   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   960     begin
   984     begin
   961     Gear^.State:= Gear^.State and (not gstWinner);
   985     Gear^.State:= Gear^.State and (not gstWinner);
   962     Gear^.State:= Gear^.State and (not gstMoving);
   986     Gear^.State:= Gear^.State and (not gstMoving);
   963     while (TestCollisionYWithGear(Gear,1) = 0) and not CheckGearDrowning(Gear) do
   987     while (TestCollisionYWithGear(Gear,1) = 0) and (not CheckGearDrowning(Gear)) do
   964         Gear^.Y:= Gear^.Y+_1;
   988         Gear^.Y:= Gear^.Y+_1;
   965     SetLittle(Gear^.dX);
   989     SetLittle(Gear^.dX);
   966     Gear^.dY:= _0
   990     Gear^.dY:= _0
   967     end
   991     end
   968 else
   992 else
  1222 var x,y,tx,ty: LongInt;
  1246 var x,y,tx,ty: LongInt;
  1223     tdX, tdY, slope: hwFloat; 
  1247     tdX, tdY, slope: hwFloat; 
  1224     land: Word; *)
  1248     land: Word; *)
  1225 var slope: hwFloat; 
  1249 var slope: hwFloat; 
  1226 begin
  1250 begin
       
  1251 CheckSum:= CheckSum xor Gear^.Hedgehog^.BotLevel;
  1227 if (Gear^.Message and gmDestroy) <> 0 then
  1252 if (Gear^.Message and gmDestroy) <> 0 then
  1228     begin
  1253     begin
  1229     DeleteGear(Gear);
  1254     DeleteGear(Gear);
  1230     exit
  1255     exit
  1231     end;
  1256     end;