hedgewars/uAmmos.pas
branchqmlfrontend
changeset 12855 1b2b84315d27
parent 12733 353cb2ce6f9c
child 13454 794dcf69a5aa
equal deleted inserted replaced
11843:01f88c3b7b66 12855:1b2b84315d27
    48 function  GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
    48 function  GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
    49 
    49 
    50 var StoreCnt: LongInt;
    50 var StoreCnt: LongInt;
    51 
    51 
    52 implementation
    52 implementation
    53 uses uVariables, uCommands, uUtils, uCaptions, uDebug;
    53 uses uVariables, uCommands, uUtils, uCaptions, uDebug, uScript;
    54 
    54 
    55 type TAmmoCounts = array[TAmmoType] of Longword;
    55 type TAmmoCounts = array[TAmmoType] of Longword;
    56      TAmmoArray = array[TAmmoType] of TAmmo;
    56      TAmmoArray = array[TAmmoType] of TAmmo;
    57 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    57 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
    58     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
    58     ammoLoadout, ammoProbability, ammoDelay, ammoReinforcement: shortstring;
   208 a:= GetAmmoEntry(Hedgehog, ammo);
   208 a:= GetAmmoEntry(Hedgehog, ammo);
   209 if (a^.AmmoType <> amNothing) then
   209 if (a^.AmmoType <> amNothing) then
   210     cnt:= a^.Count
   210     cnt:= a^.Count
   211 else
   211 else
   212     cnt:= 0;
   212     cnt:= 0;
   213 if (cnt <> AMMO_INFINITE) then
   213 if (cnt >= AMMO_INFINITE) or (amt >= AMMO_INFINITE) then
   214     begin
   214     cnt:= AMMO_INFINITE
   215     inc(cnt, amt);
   215 else
   216     SetAmmo(Hedgehog, ammo, cnt)
   216     cnt:= min(AMMO_FINITE_MAX, cnt + amt);
   217     end
   217 SetAmmo(Hedgehog, ammo, cnt);
   218 end;
   218 end;
   219 
   219 
   220 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
   220 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
   221 begin
   221 begin
   222     AddAmmo(Hedgehog, ammo, Ammoz[ammo].NumberInCase);
   222     AddAmmo(Hedgehog, ammo, Ammoz[ammo].NumberInCase);
   285 var CurWeapon: PAmmo;
   285 var CurWeapon: PAmmo;
   286 begin
   286 begin
   287 CurWeapon:= GetCurAmmoEntry(Hedgehog);
   287 CurWeapon:= GetCurAmmoEntry(Hedgehog);
   288 with Hedgehog do
   288 with Hedgehog do
   289     begin
   289     begin
       
   290     if CurAmmoType <> amNothing then
       
   291         ScriptCall('onUsedAmmo', ord(CurAmmoType));
   290 
   292 
   291     MultiShootAttacks:= 0;
   293     MultiShootAttacks:= 0;
   292     with CurWeapon^ do
   294     with CurWeapon^ do
   293         if Count <> AMMO_INFINITE then
   295         if Count <> AMMO_INFINITE then
   294             begin
   296             begin
   327 if Hedgehog.Gear <> nil then
   329 if Hedgehog.Gear <> nil then
   328     with Hedgehog do
   330     with Hedgehog do
   329         begin
   331         begin
   330         if (AmmoType <> amNothing) then
   332         if (AmmoType <> amNothing) then
   331             begin
   333             begin
   332             CurMinAngle:= Ammoz[AmmoType].minAngle;
   334             if ((CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amRope)) then
   333             if Ammoz[AmmoType].maxAngle <> 0 then
   335                 begin
   334                 CurMaxAngle:= Ammoz[AmmoType].maxAngle
   336                 CurMaxAngle:= Ammoz[amRope].maxAngle;
       
   337                 CurMinAngle:= Ammoz[amRope].minAngle;
       
   338                 end
   335             else
   339             else
   336                 CurMaxAngle:= cMaxAngle;
   340                 begin
       
   341                 CurMinAngle:= Ammoz[AmmoType].minAngle;
       
   342                 if Ammoz[AmmoType].maxAngle <> 0 then
       
   343                     CurMaxAngle:= Ammoz[AmmoType].maxAngle
       
   344                 else
       
   345                     CurMaxAngle:= cMaxAngle;
       
   346                 end;
   337 
   347 
   338             with Hedgehog.Gear^ do
   348             with Hedgehog.Gear^ do
   339                 begin
   349                 begin
   340                 if Angle < CurMinAngle then
   350                 if Angle < CurMinAngle then
   341                     Angle:= CurMinAngle;
   351                     Angle:= CurMinAngle;
   374     end
   384     end
   375 end;
   385 end;
   376 
   386 
   377 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
   387 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
   378 var s: ansistring;
   388 var s: ansistring;
   379     CurWeapon: PAmmo;
   389     OldWeapon, CurWeapon: PAmmo;
   380 begin
   390 begin
   381 TargetPoint.X:= NoPointX;
   391 TargetPoint.X:= NoPointX;
   382 
   392 
   383 with Hedgehog do
   393 with Hedgehog do
   384     begin
   394     begin
   385     Timer:= 10;
       
   386 
       
   387     CurWeapon:= GetCurAmmoEntry(Hedgehog);
   395     CurWeapon:= GetCurAmmoEntry(Hedgehog);
       
   396     OldWeapon:= GetCurAmmoEntry(Hedgehog);
   388 
   397 
   389     if (CurWeapon^.Count = 0) then
   398     if (CurWeapon^.Count = 0) then
   390         SwitchToFirstLegalAmmo(Hedgehog)
   399         SwitchToFirstLegalAmmo(Hedgehog)
   391     else if CurWeapon^.AmmoType = amNothing then
   400     else if CurWeapon^.AmmoType = amNothing then
   392         Hedgehog.CurAmmoType:= amNothing;
   401         Hedgehog.CurAmmoType:= amNothing;
   393 
   402 
   394     CurWeapon:= GetCurAmmoEntry(Hedgehog);
   403     CurWeapon:= GetCurAmmoEntry(Hedgehog);
   395 
   404 
       
   405     // Weapon selection animation (if new ammo type)
       
   406     if CurWeapon^.AmmoType <> OldWeapon^.AmmoType then
       
   407         Timer:= 10;
       
   408 
   396     ApplyAngleBounds(Hedgehog, CurWeapon^.AmmoType);
   409     ApplyAngleBounds(Hedgehog, CurWeapon^.AmmoType);
   397 
   410 
   398     with CurWeapon^ do
   411     with CurWeapon^ do
   399         begin
   412         begin
   400         s:= trammo[Ammoz[AmmoType].NameId];
   413         if length(trluaammo[Ammoz[AmmoType].NameId]) > 0 then
       
   414             s:= trluaammo[Ammoz[AmmoType].NameId]
       
   415         else
       
   416             s:= trammo[Ammoz[AmmoType].NameId];
   401         if (Count <> AMMO_INFINITE) and (not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0))) then
   417         if (Count <> AMMO_INFINITE) and (not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0))) then
   402             s:= s + ansistring(' (' + IntToStr(Count) + ')');
   418             s:= s + ansistring(' (' + IntToStr(Count) + ')');
   403         if (Propz and ammoprop_Timerable) <> 0 then
   419         if (Propz and ammoprop_Timerable) <> 0 then
   404             s:= s + ansistring(', ' + IntToStr(Timer div 1000) + ' ') + trammo[sidSeconds];
   420             s:= s + ansistring(', ' + IntToStr(Timer div 1000) + ' ') + trammo[sidSeconds];
   405         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
   421         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);