hedgewars/uAmmos.pas
branchsdl2transition
changeset 11342 ed5a6478e710
parent 11046 47a8c19ecb60
child 11537 bf86c6cb9341
equal deleted inserted replaced
11340:31570b766315 11342:ed5a6478e710
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    12  * GNU General Public License for more details.
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    17  *)
    17  *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uAmmos;
    21 unit uAmmos;
    41 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
    41 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
    42 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
    42 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
    43 procedure SetWeapon(weap: TAmmoType);
    43 procedure SetWeapon(weap: TAmmoType);
    44 procedure DisableSomeWeapons;
    44 procedure DisableSomeWeapons;
    45 procedure ResetWeapons;
    45 procedure ResetWeapons;
    46 function  GetAmmoByNum(num: Longword): PHHAmmo;
    46 function  GetAmmoByNum(num: LongInt): PHHAmmo;
    47 function  GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo;
    47 function  GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo;
    48 function  GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
    48 function  GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo;
    49 
    49 
    50 var StoreCnt: Longword;
    50 var StoreCnt: LongInt;
    51 
    51 
    52 implementation
    52 implementation
    53 uses uLocale, uVariables, uCommands, uUtils, uCaptions, uDebug;
    53 uses uVariables, uCommands, uUtils, uCaptions, uDebug;
    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;
   130         and (a <> amTeleport) and (a <> amSkip)
   130         and (a <> amTeleport) and (a <> amSkip)
   131         and (Ammoz[a].SkipTurns < 10000) then
   131         and (Ammoz[a].SkipTurns < 10000) then
   132             inc(Ammoz[a].SkipTurns,10000);
   132             inc(Ammoz[a].SkipTurns,10000);
   133     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
   133     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
   134         ammos[a]:= AMMO_INFINITE
   134         ammos[a]:= AMMO_INFINITE
   135         end 
   135         end
   136         
   136 
   137     else
   137     else
   138         ammos[a]:= AMMO_INFINITE;
   138         ammos[a]:= AMMO_INFINITE;
   139     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then 
   139     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
   140         InitialCounts[Pred(StoreCnt)][a]:= cnt
   140         InitialCounts[Pred(StoreCnt)][a]:= cnt
   141     else
   141     else
   142         InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
   142         InitialCounts[Pred(StoreCnt)][a]:= ammos[a];
   143     end;
   143     end;
   144     
   144 
   145     for a:= Low(TAmmoType) to High(TAmmoType) do
   145     for a:= Low(TAmmoType) to High(TAmmoType) do
   146         begin
   146         begin
   147         newAmmos[a]:= Ammoz[a].Ammo;
   147         newAmmos[a]:= Ammoz[a].Ammo;
   148         newAmmos[a].Count:= ammos[a]
   148         newAmmos[a].Count:= ammos[a]
   149         end;
   149         end;
   150         
   150 
   151 FillAmmoStore(StoresList[Pred(StoreCnt)], newAmmos)
   151 FillAmmoStore(StoresList[Pred(StoreCnt)], newAmmos)
   152 end;
   152 end;
   153 
   153 
   154 function GetAmmoByNum(num: Longword): PHHAmmo;
   154 function GetAmmoByNum(num: LongInt): PHHAmmo;
   155 begin
   155 begin
   156     TryDo(num < StoreCnt, 'Invalid store number', true);
   156     TryDo(num < StoreCnt, 'Invalid store number', true);
   157     GetAmmoByNum:= StoresList[num]
   157     GetAmmoByNum:= StoresList[num]
   158 end;
   158 end;
   159 
   159 
   270         if b then // there is a free item in ammo stack
   270         if b then // there is a free item in ammo stack
   271             begin
   271             begin
   272             Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1];
   272             Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1];
   273             Ammo^[Slot, ami + 1].Count:= 0
   273             Ammo^[Slot, ami + 1].Count:= 0
   274             end;
   274             end;
   275     until not b;
   275     until (not b);
   276 AmmoMenuInvalidated:= true;
   276 AmmoMenuInvalidated:= true;
   277 end;
   277 end;
   278 
   278 
   279 procedure OnUsedAmmo(var Hedgehog: THedgehog);
   279 procedure OnUsedAmmo(var Hedgehog: THedgehog);
   280 var CurWeapon: PAmmo;
   280 var CurWeapon: PAmmo;
   309     begin
   309     begin
   310         with Hedgehog.Ammo^[Slot, ami] do
   310         with Hedgehog.Ammo^[Slot, ami] do
   311             if (AmmoType = Ammo) then
   311             if (AmmoType = Ammo) then
   312                 if Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns then
   312                 if Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns then
   313                     exit(Count)
   313                     exit(Count)
   314                 else 
   314                 else
   315                     exit(0);
   315                     exit(0);
   316         inc(ami)
   316         inc(ami)
   317     end;
   317     end;
   318 end;
   318 end;
   319 
   319 
   364             inc(slot)
   364             inc(slot)
   365             end
   365             end
   366         end;
   366         end;
   367     TryDo(slot <= cMaxSlotIndex, 'Ammo slot index overflow', true);
   367     TryDo(slot <= cMaxSlotIndex, 'Ammo slot index overflow', true);
   368     CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
   368     CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
   369     if CurAmmoType = amKnife then LoadHedgehogHat(Hedgehog, 'Reserved/chef')
       
   370     end
   369     end
   371 end;
   370 end;
   372 
   371 
   373 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
   372 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
   374 var s: shortstring;
   373 var s: ansistring;
   375     CurWeapon: PAmmo;
   374     CurWeapon: PAmmo;
   376 begin
   375 begin
   377 TargetPoint.X:= NoPointX;
   376 TargetPoint.X:= NoPointX;
   378 
   377 
   379 with Hedgehog do
   378 with Hedgehog do
   393 
   392 
   394     with CurWeapon^ do
   393     with CurWeapon^ do
   395         begin
   394         begin
   396         s:= trammo[Ammoz[AmmoType].NameId];
   395         s:= trammo[Ammoz[AmmoType].NameId];
   397         if (Count <> AMMO_INFINITE) and (not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0))) then
   396         if (Count <> AMMO_INFINITE) and (not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0))) then
   398             s:= s + ' (' + IntToStr(Count) + ')';
   397             s:= s + ansistring(' (' + IntToStr(Count) + ')');
   399         if (Propz and ammoprop_Timerable) <> 0 then
   398         if (Propz and ammoprop_Timerable) <> 0 then
   400             s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds];
   399             s:= s + ansistring(', ' + IntToStr(Timer div 1000) + ' ') + trammo[sidSeconds];
   401         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
   400         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
   402         if (Propz and ammoprop_NeedTarget) <> 0 then
   401         if (Propz and ammoprop_NeedTarget) <> 0 then
   403             begin
   402             begin
   404             if Gear <> nil then Gear^.State:= Gear^.State or      gstHHChooseTarget;
   403             if Gear <> nil then Gear^.State:= Gear^.State or      gstChooseTarget;
   405             isCursorVisible:= true
   404             isCursorVisible:= true
   406             end
   405             end
   407         else
   406         else
   408             begin
   407             begin
   409             if Gear <> nil then Gear^.State:= Gear^.State and (not gstHHChooseTarget);
   408             if Gear <> nil then Gear^.State:= Gear^.State and (not gstChooseTarget);
   410             isCursorVisible:= false
   409             isCursorVisible:= false
   411             end;
   410             end;
   412         end
   411         end
   413     end;
   412     end;
   414 end;
   413 end;
   480         for i:= 0 to cMaxHHIndex do
   479         for i:= 0 to cMaxHHIndex do
   481             Hedgehogs[i].CurAmmoType:= amNothing;
   480             Hedgehogs[i].CurAmmoType:= amNothing;
   482 
   481 
   483 for a:= Low(TAmmoType) to High(TAmmoType) do
   482 for a:= Low(TAmmoType) to High(TAmmoType) do
   484     newAmmos[a]:= Ammoz[a].Ammo;
   483     newAmmos[a]:= Ammoz[a].Ammo;
   485     
   484 
   486 for i:= 0 to Pred(StoreCnt) do
   485 for i:= 0 to Pred(StoreCnt) do
   487     begin
   486     begin
   488     for a:= Low(TAmmoType) to High(TAmmoType) do
   487     for a:= Low(TAmmoType) to High(TAmmoType) do
   489         newAmmos[a].Count:= InitialCounts[i][a];
   488         newAmmos[a].Count:= InitialCounts[i][a];
   490     FillAmmoStore(StoresList[i], newAmmos);
   489     FillAmmoStore(StoresList[i], newAmmos);
   497 
   496 
   498 
   497 
   499 
   498 
   500 procedure chAddAmmoStore(var descr: shortstring);
   499 procedure chAddAmmoStore(var descr: shortstring);
   501 begin
   500 begin
   502 descr:= ''; // avoid compiler hint
   501     descr:= ''; // avoid compiler hint
   503 AddAmmoStore
   502     AddAmmoStore
   504 end;
   503 end;
   505 
   504 
   506 procedure initModule;
   505 procedure initModule;
   507 var i: Longword;
   506 var i: Longword;
   508 begin
   507 begin