hedgewars/uGearsHedgehog.pas
changeset 12297 071a05275798
parent 12293 6383323fdd2c
child 12303 817522bab39b
equal deleted inserted replaced
12296:62975c0a89c6 12297:071a05275798
    50 
    50 
    51     ParseCommand('/skip', true)
    51     ParseCommand('/skip', true)
    52 end;
    52 end;
    53 
    53 
    54 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
    54 // Shouldn't more of this ammo switching stuff be moved to uAmmos ?
    55 function ChangeAmmo(HHGear: PGear): boolean;
    55 function ChangeAmmo(HHGear: PGear; reverse: boolean): boolean;
    56 var slot, i: Longword;
    56 var slot, i: Longword;
    57     ammoidx: LongInt;
    57     ammoidx,
       
    58     ammochangedir: LongInt;
    58     prevAmmo: TAmmoType;
    59     prevAmmo: TAmmoType;
    59 begin
    60 begin
    60 ChangeAmmo:= false;
    61 ChangeAmmo:= false;
    61 slot:= HHGear^.MsgParam;
    62 slot:= HHGear^.MsgParam;
    62 
    63 
    63 with HHGear^.Hedgehog^ do
    64 with HHGear^.Hedgehog^ do
    64     begin
    65     begin
    65     HHGear^.Message:= HHGear^.Message and (not gmSlot);
    66     HHGear^.Message:= HHGear^.Message and (not gmSlot);
    66     prevAmmo:= CurAmmoType;
    67     prevAmmo:= CurAmmoType;
    67     ammoidx:= 0;
    68     ammoidx:= 0;
       
    69     if (reverse = true) then
       
    70         ammochangedir:= -1
       
    71     else
       
    72         ammochangedir:= 1;
       
    73 
    68     if (((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) and (GameFlags and gfInfAttack = 0))
    74     if (((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) and (GameFlags and gfInfAttack = 0))
    69     or ((HHGear^.State and gstHHDriven) = 0) then
    75     or ((HHGear^.State and gstHHDriven) = 0) then
    70         exit;
    76         exit;
    71     ChangeAmmo:= true;
    77     ChangeAmmo:= true;
    72 
    78    
    73     while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
    79     if CurAmmoType = amNothing then
    74         inc(ammoidx);
    80         ammoidx:= cMaxSlotAmmoIndex
       
    81     else
       
    82         while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
       
    83             inc(ammoidx);
    75 
    84 
    76     if (MultiShootAttacks > 0) then
    85     if (MultiShootAttacks > 0) then
    77         begin
    86         begin
    78         if (CurAmmoType = amSniperRifle) and ((GameFlags and gfArtillery) = 0) then
    87         if (CurAmmoType = amSniperRifle) and ((GameFlags and gfArtillery) = 0) then
    79             cArtillery := false;
    88             cArtillery := false;
    86         end;
    95         end;
    87 
    96 
    88     MultiShootAttacks:= 0;
    97     MultiShootAttacks:= 0;
    89     HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
    98     HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
    90 
    99 
    91     if Ammoz[CurAmmoType].Slot = slot then
   100     if (Ammoz[CurAmmoType].Slot = slot) and (CurAmmoType <> amNothing) then
    92         begin
   101         begin
    93         i:= 0;
   102         i:= 0;
    94         repeat
   103         repeat
    95         inc(ammoidx);
   104         inc(ammoidx, ammochangedir);
    96         if (ammoidx > cMaxSlotAmmoIndex) then
   105         if (ammoidx < 0) or (ammoidx > cMaxSlotAmmoIndex) then
    97             begin
   106             begin
    98             inc(i);
   107             inc(i);
    99             CurAmmoType:= amNothing;
   108             CurAmmoType:= amNothing;
   100             ammoidx:= -1;
   109             ammoidx:= -1;
   101             //TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
   110             //TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
   102             end;
   111             end;
   103         until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0)
   112         until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0)
       
   113         and (Ammo^[slot, ammoidx].AmmoType <> amNothing)
   104         and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns))
   114         and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns))
   105 
   115 
   106         end
   116         end
   107     else
   117     else
   108         begin
   118         begin
   109         i:= 0;
   119         if reverse then
       
   120             i:= cMaxSlotAmmoIndex
       
   121         else
       
   122             i:= 0;
   110         // check whether there is ammo in slot
   123         // check whether there is ammo in slot
   111         while (i <= cMaxSlotAmmoIndex) and ((Ammo^[slot, i].Count = 0)
   124         while (ammoidx >= 0) and (i <= cMaxSlotAmmoIndex) and
   112         or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns))
   125         ((Ammo^[slot, i].Count = 0) or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns) or (Ammo^[slot, i].AmmoType = amNothing))
   113             do inc(i);
   126             do inc(i, ammochangedir);
   114 
   127 
   115         if i <= cMaxSlotAmmoIndex then
   128         if (i >= 0) and (i <= cMaxSlotAmmoIndex) then
   116             ammoidx:= i
   129             ammoidx:= i
   117         else ammoidx:= -1
   130         else ammoidx:= -1
   118         end;
   131         end;
   119         if ammoidx >= 0 then
   132         if ammoidx >= 0 then
   120             CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
   133             CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
   121     // Try again in the next slot
   134     // Try again in the next or previous slot
   122     if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then
   135     if (CurAmmoType = prevAmmo) and (((reverse = false) and (slot < cMaxSlotIndex)) or ((reverse = true) and (slot > 0))) then
   123         begin
   136         begin
   124         inc(slot);
   137         inc(slot, ammochangedir);
   125         HHGear^.MsgParam:= slot;
   138         HHGear^.MsgParam:= slot;
   126         ChangeAmmo(HHGear)
   139         ChangeAmmo(HHGear, reverse)
   127         end
   140         end
   128     end
   141     end
   129 end;
   142 end;
   130 
   143 
   131 procedure HHSetWeapon(HHGear: PGear);
   144 procedure HHSetWeapon(HHGear: PGear);
   152 prevState:= HHGear^.State;
   165 prevState:= HHGear^.State;
   153 newState:= prevState;
   166 newState:= prevState;
   154 with Hedgehog^ do
   167 with Hedgehog^ do
   155     while (CurAmmoType <> weap) and (t >= 0) do
   168     while (CurAmmoType <> weap) and (t >= 0) do
   156         begin
   169         begin
   157         s:= ChangeAmmo(HHGear);
   170         s:= ChangeAmmo(HHGear, false);
   158         if HHGear^.State <> prevState then // so we can keep gstAttacked out of consideration when looping
   171         if HHGear^.State <> prevState then // so we can keep gstAttacked out of consideration when looping
   159             newState:= HHGear^.State;
   172             newState:= HHGear^.State;
   160         HHGear^.State:= prevState;
   173         HHGear^.State:= prevState;
   161         dec(t)
   174         dec(t)
   162         end;
   175         end;
  1311             end;
  1324             end;
  1312 
  1325 
  1313 if (CurAmmoGear = nil)
  1326 if (CurAmmoGear = nil)
  1314 or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)  then
  1327 or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)  then
  1315     begin
  1328     begin
       
  1329     // Press slot key to select weapon slot
  1316     if ((HHGear^.Message and gmSlot) <> 0) then
  1330     if ((HHGear^.Message and gmSlot) <> 0) then
  1317         if ChangeAmmo(HHGear) then ApplyAmmoChanges(Hedgehog^);
  1331         if ((HHGear^.Message and gmPrecise) <> 0) then
       
  1332             begin
       
  1333             // Reverse weapon selection by holding down the Precise key
       
  1334             HHGear^.Message := HHGear^.Message and (not gmPrecise);
       
  1335             if ChangeAmmo(HHGear, true) then ApplyAmmoChanges(Hedgehog^);
       
  1336             HHGear^.Message:= HHGear^.Message or gmPrecise
       
  1337             end
       
  1338         else
       
  1339             // Select next weapon
       
  1340             if ChangeAmmo(HHGear, false) then ApplyAmmoChanges(Hedgehog^);
  1318 
  1341 
  1319     if ((HHGear^.Message and gmWeapon) <> 0) then
  1342     if ((HHGear^.Message and gmWeapon) <> 0) then
  1320         HHSetWeapon(HHGear);
  1343         HHSetWeapon(HHGear);
  1321 
  1344 
  1322     if ((HHGear^.Message and gmTimer) <> 0) then
  1345     if ((HHGear^.Message and gmTimer) <> 0) then