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