hedgewars/uGearsHedgehog.pas
changeset 7439 0a494f951dcf
parent 7426 55b49cc1f33a
child 7442 9bb6abdb5675
child 7459 8511a3f899d3
equal deleted inserted replaced
7358:57a508884052 7439:0a494f951dcf
    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, 
   353                       amLandGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtLandGun,  0, xx * _0_5, yy * _0_5, 0);
   354                       amLandGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtLandGun,  0, xx * _0_5, yy * _0_5, 0);
   354                   amResurrector: begin
   355                   amResurrector: begin
   355                                  newGear:= AddGear(hwRound(lx), hwRound(ly), gtResurrector, 0, _0, _0, 0);
   356                                  newGear:= AddGear(hwRound(lx), hwRound(ly), gtResurrector, 0, _0, _0, 0);
   356                                  newGear^.SoundChannel := LoopSound(sndResurrector);
   357                                  newGear^.SoundChannel := LoopSound(sndResurrector);
   357                                  end;
   358                                  end;
   358                                  //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
       
   359                     amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
   359                     amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
   360                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
   360                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
   361                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
   361                        amIceGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtIceGun, 0, _0, _0, 0);
   362              end;
   362              end;
   363              
   363              
   564     Gear^.Pos:= 0;
   564     Gear^.Pos:= 0;
   565     Gear^.Timer:= timertime
   565     Gear^.Timer:= timertime
   566     end
   566     end
   567 end;
   567 end;
   568 
   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 
   569 ////////////////////////////////////////////////////////////////////////////////
   595 ////////////////////////////////////////////////////////////////////////////////
   570 procedure PickUp(HH, Gear: PGear);
   596 procedure PickUp(HH, Gear: PGear);
   571 var s: shortstring;
   597 var s: shortstring;
   572     a: TAmmoType;
   598     a: TAmmoType;
   573     i: LongInt;
   599     i: LongInt;
   574     vga: PVisualGear;
   600     vga: PVisualGear;
       
   601     ag, gi: PGear;
   575 begin
   602 begin
   576 Gear^.Message:= gmDestroy;
   603 Gear^.Message:= gmDestroy;
   577 PlaySound(sndShotgunReload);
       
   578 if (Gear^.Pos and posCaseExplode) <> 0 then
   604 if (Gear^.Pos and posCaseExplode) <> 0 then
   579     if (Gear^.Pos and posCasePoison) <> 0 then
   605     if (Gear^.Pos and posCasePoison) <> 0 then
   580         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)
   581     else
   607     else
   582         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
   608         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
   584     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)
   585 else
   611 else
   586 case Gear^.Pos of
   612 case Gear^.Pos of
   587        posCaseUtility,
   613        posCaseUtility,
   588        posCaseAmmo: begin
   614        posCaseAmmo: begin
   589                     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
   590                     else
   619                     else
   591                         begin
   620                         begin
   592                         for i:= 0 to GameTicks and $7F do
   621 // Add spawning here...
   593                             GetRandom(2); // Burn some random numbers
   622                         AddRandomness(GameTicks);
   594                         if Gear^.Pos = posCaseUtility then
   623                         
   595                             a:= GetUtility(HH^.Hedgehog)
   624                         gi := GearsList;
   596                         else
   625                         while gi <> nil do
   597                             a:= GetAmmo(HH^.Hedgehog)
   626                             begin
       
   627                             if gi^.Kind = gtGenericFaller then
       
   628                                 begin
       
   629                                 gi^.Active:= true;
       
   630                                 gi^.X:= int2hwFloat(GetRandom(rightX-leftX)+leftX);
       
   631                                 gi^.Y:= int2hwFloat(GetRandom(LAND_HEIGHT-topY)+topY);
       
   632                                 gi^.dX:= _90-(GetRandomf*_360);
       
   633                                 gi^.dY:= _90-(GetRandomf*_360)
       
   634                                 end;
       
   635                             gi := gi^.NextGear
       
   636                             end;
       
   637                         ag:= AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAddAmmo, gstInvisible, _0, _0, GetRandom(200)+100);
       
   638                         ag^.Pos:= Gear^.Pos;
       
   639                         ag^.Power:= Gear^.Power
   598                         end;
   640                         end;
   599                     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 = gmtDemo)  then
       
   606                         begin
       
   607                         s:= trammo[Ammoz[a].NameId] + ' (+' + IntToStr(Ammoz[a].NumberInCase) + ')';
       
   608                         AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
       
   609 
       
   610                         // show ammo icon
       
   611                         vga:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtAmmo);
       
   612                         if vga <> nil then
       
   613                             vga^.Frame:= Longword(a);
       
   614                         end;
       
   615 
       
   616                     end;
   641                     end;
   617      posCaseHealth: begin
   642      posCaseHealth: begin
       
   643                     PlaySound(sndShotgunReload);
   618                     inc(HH^.Health, Gear^.Health);
   644                     inc(HH^.Health, Gear^.Health);
   619                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
   645                     HH^.Hedgehog^.Effects[hePoisoned] := 0;
   620                     str(Gear^.Health, s);
   646                     str(Gear^.Health, s);
   621                     s:= '+' + s;
   647                     s:= '+' + s;
   622                     AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
   648                     AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
   825     Gear^.dY:= _0;
   851     Gear^.dY:= _0;
   826     Gear^.dX:= _0;
   852     Gear^.dX:= _0;
   827     Gear^.State:= Gear^.State and (not gstMoving);
   853     Gear^.State:= Gear^.State and (not gstMoving);
   828     exit
   854     exit
   829     end;
   855     end;
   830 isFalling:= (Gear^.dY.isNegative) or not TestCollisionYKick(Gear, 1);
   856 isFalling:= (Gear^.dY.isNegative) or (not TestCollisionYKick(Gear, 1));
   831 if isFalling then
   857 if isFalling then
   832     begin
   858     begin
   833     if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then
   859     if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then
   834         Gear^.dY:= _0;
   860         Gear^.dY:= _0;
   835     Gear^.State:= Gear^.State or gstMoving;
   861     Gear^.State:= Gear^.State or gstMoving;
   951             Gear^.dX:= -Gear^.Elasticity * Gear^.dX
   977             Gear^.dX:= -Gear^.Elasticity * Gear^.dX
   952         else
   978         else
   953             SetLittle(Gear^.dX);
   979             SetLittle(Gear^.dX);
   954 
   980 
   955 if (not isFalling)
   981 if (not isFalling)
   956 and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   982   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
   957     begin
   983     begin
   958     Gear^.State:= Gear^.State and (not gstWinner);
   984     Gear^.State:= Gear^.State and (not gstWinner);
   959     Gear^.State:= Gear^.State and (not gstMoving);
   985     Gear^.State:= Gear^.State and (not gstMoving);
   960     while TestCollisionYWithGear(Gear,1) = 0 do
   986     while (TestCollisionYWithGear(Gear,1) = 0) and (not CheckGearDrowning(Gear)) do
   961         Gear^.Y:= Gear^.Y+_1;
   987         Gear^.Y:= Gear^.Y+_1;
   962     SetLittle(Gear^.dX);
   988     SetLittle(Gear^.dX);
   963     Gear^.dY:= _0
   989     Gear^.dY:= _0
   964     end
   990     end
   965 else
   991 else
  1219 var x,y,tx,ty: LongInt;
  1245 var x,y,tx,ty: LongInt;
  1220     tdX, tdY, slope: hwFloat; 
  1246     tdX, tdY, slope: hwFloat; 
  1221     land: Word; *)
  1247     land: Word; *)
  1222 var slope: hwFloat; 
  1248 var slope: hwFloat; 
  1223 begin
  1249 begin
       
  1250 CheckSum:= CheckSum xor Gear^.Hedgehog^.BotLevel;
  1224 if (Gear^.Message and gmDestroy) <> 0 then
  1251 if (Gear^.Message and gmDestroy) <> 0 then
  1225     begin
  1252     begin
  1226     DeleteGear(Gear);
  1253     DeleteGear(Gear);
  1227     exit
  1254     exit
  1228     end;
  1255     end;