hedgewars/uTeams.pas
changeset 295 8834f3cb620e
parent 294 92a7ccd67bb9
child 304 8096e69e839e
equal deleted inserted replaced
294:92a7ccd67bb9 295:8834f3cb620e
    40              Color, AdjColor: Longword;
    40              Color, AdjColor: Longword;
    41              TeamName: string[MAXNAMELEN];
    41              TeamName: string[MAXNAMELEN];
    42              ExtDriven: boolean;
    42              ExtDriven: boolean;
    43              Binds: TBinds;
    43              Binds: TBinds;
    44              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
    44              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
    45              Ammos: array[0..cMaxHHIndex] of THHAmmo;
       
    46              CurrHedgehog: integer;
    45              CurrHedgehog: integer;
    47              NameTag: PSDL_Surface;
    46              NameTag: PSDL_Surface;
    48              CrosshairSurf: PSDL_Surface;
    47              CrosshairSurf: PSDL_Surface;
    49              GraveRect, HealthRect: TSDL_Rect;
    48              GraveRect, HealthRect: TSDL_Rect;
    50              GraveName: string;
    49              GraveName: string;
    60 
    59 
    61 function AddTeam: PTeam;
    60 function AddTeam: PTeam;
    62 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
    61 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
    63 procedure SwitchHedgehog;
    62 procedure SwitchHedgehog;
    64 procedure InitTeams;
    63 procedure InitTeams;
    65 procedure OnUsedAmmo(Ammo: PHHAmmo);
       
    66 function  HHHasAmmo(Hedgehog: PHedgehog; Ammo: TAmmoType): boolean;
       
    67 function  TeamSize(p: PTeam): Longword;
    64 function  TeamSize(p: PTeam): Longword;
    68 procedure RecountTeamHealth(team: PTeam);
    65 procedure RecountTeamHealth(team: PTeam);
    69 procedure RestoreTeamsFromSave;
    66 procedure RestoreTeamsFromSave;
    70 function CheckForWin: boolean;
    67 function CheckForWin: boolean;
    71 procedure SetWeapon(weap: TAmmoType);
    68 procedure SetWeapon(weap: TAmmoType);
   252      ShowCrosshair:= (Propz and ammoprop_NoCrosshair) = 0
   249      ShowCrosshair:= (Propz and ammoprop_NoCrosshair) = 0
   253      end
   250      end
   254      end
   251      end
   255 end;
   252 end;
   256 
   253 
   257 procedure PackAmmo(Ammo: PHHAmmo; Slot: integer);
       
   258 var ami: integer;
       
   259     b: boolean;
       
   260 begin
       
   261     repeat
       
   262       b:= false;
       
   263       ami:= 0;
       
   264       while (not b) and (ami < cMaxSlotAmmoIndex) do
       
   265           if (Ammo[Slot, ami].Count = 0)
       
   266              and (Ammo[Slot, ami + 1].Count > 0) then b:= true
       
   267                                                  else inc(ami);
       
   268       if b then // there's a free item in ammo stack
       
   269          begin
       
   270          Ammo[Slot, ami]:= Ammo[Slot, ami + 1];
       
   271          Ammo[Slot, ami + 1].Count:= 0
       
   272          end;
       
   273     until not b;
       
   274 end;
       
   275 
       
   276 procedure OnUsedAmmo(Ammo: PHHAmmo);
       
   277 var s, a: Longword;
       
   278 begin
       
   279 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
       
   280      begin
       
   281      if CurAmmoGear = nil then begin s:= CurSlot; a:= CurAmmo end
       
   282                           else begin s:= AltSlot; a:= AltAmmo end;
       
   283      with Ammo[s, a] do
       
   284           if Count <> AMMO_INFINITE then
       
   285              begin
       
   286              dec(Count);
       
   287              if Count = 0 then PackAmmo(Ammo, CurSlot)
       
   288              end
       
   289      end
       
   290 end;
       
   291 
       
   292 function  HHHasAmmo(Hedgehog: PHedgehog; Ammo: TAmmoType): boolean;
       
   293 var slot, ami: integer;
       
   294 begin
       
   295 Slot:= Ammoz[Ammo].Slot;
       
   296 ami:= 0;
       
   297 Result:= false;
       
   298 while (not Result) and (ami <= cMaxSlotAmmoIndex) do
       
   299       begin
       
   300       with  Hedgehog.Ammo[Slot, ami] do
       
   301             if (AmmoType = Ammo) and (Count > 0) then Result:= true;
       
   302       inc(ami)
       
   303       end
       
   304 end;
       
   305 
       
   306 function  TeamSize(p: PTeam): Longword;
   254 function  TeamSize(p: PTeam): Longword;
   307 var i: Longword;
   255 var i: Longword;
   308 begin
   256 begin
   309 Result:= 0;
   257 Result:= 0;
   310 for i:= 0 to cMaxHHIndex do
   258 for i:= 0 to cMaxHHIndex do