hedgewars/uTeams.pas
changeset 47 8daf1ee0b9a3
parent 32 78bff13b11c0
child 49 3afe33c1cf06
equal deleted inserted replaced
46:c99140d2355a 47:8daf1ee0b9a3
     1 (*
     1 (*
     2  * Hedgewars, a worms-like game
     2  * Hedgewars, a worms-like game
     3  * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * Distributed under the terms of the BSD-modified licence:
     5  * Distributed under the terms of the BSD-modified licence:
     6  *
     6  *
     7  * Permission is hereby granted, free of charge, to any person obtaining a copy
     7  * Permission is hereby granted, free of charge, to any person obtaining a copy
     8  * of this software and associated documentation files (the "Software"), to deal
     8  * of this software and associated documentation files (the "Software"), to deal
    58              ExtDriven: boolean;
    58              ExtDriven: boolean;
    59              Aliases: array[0..cKeyMaxIndex] of shortstring;
    59              Aliases: array[0..cKeyMaxIndex] of shortstring;
    60              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
    60              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
    61              Ammos: array[0..cMaxHHIndex] of THHAmmo;
    61              Ammos: array[0..cMaxHHIndex] of THHAmmo;
    62              CurrHedgehog: integer;
    62              CurrHedgehog: integer;
    63              NameRect, CrossHairRect, GraveRect: TSDL_Rect;
    63              NameRect, CrossHairRect,
       
    64              GraveRect, HealthRect: TSDL_Rect;
    64              GraveName: string;
    65              GraveName: string;
    65              FortName: string;
    66              FortName: string;
       
    67              TeamHealth: integer;
    66              AttackBar: LongWord;
    68              AttackBar: LongWord;
    67              end;
    69              end;
    68 
    70 
    69 var CurrentTeam: PTeam = nil;
    71 var CurrentTeam: PTeam = nil;
    70     TeamsList: PTeam = nil;
    72     TeamsList: PTeam = nil;
    73 procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
    75 procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
    74 procedure SwitchHedgehog;
    76 procedure SwitchHedgehog;
    75 procedure InitTeams;
    77 procedure InitTeams;
    76 procedure OnUsedAmmo(Ammo: PHHAmmo);
    78 procedure OnUsedAmmo(Ammo: PHHAmmo);
    77 function  TeamSize(p: PTeam): Longword;
    79 function  TeamSize(p: PTeam): Longword;
       
    80 procedure RecountTeamHealth(team: PTeam);
    78 
    81 
    79 implementation
    82 implementation
    80 uses uMisc, uStore, uWorld, uIO, uAIActions;
    83 uses uMisc, uStore, uWorld, uIO, uAIActions;
       
    84 const MaxTeamHealth: integer = 0;
    81 
    85 
    82 procedure FreeTeamsList; forward;
    86 procedure FreeTeamsList; forward;
    83 
    87 
    84 procedure SwitchHedgehog;
    88 procedure SwitchHedgehog;
    85 var tteam: PTeam;
    89 var tteam: PTeam;
   176     Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
   180     Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
   177     inc(mi[Ammoz[a].Slot])
   181     inc(mi[Ammoz[a].Slot])
   178     end;
   182     end;
   179 end;
   183 end;
   180 
   184 
       
   185 procedure RecountAllTeamsHealth;
       
   186 var p: PTeam;
       
   187 begin
       
   188 p:= TeamsList;
       
   189 while p <> nil do
       
   190       begin
       
   191       RecountTeamHealth(p);
       
   192       p:= p.Next
       
   193       end
       
   194 end;
       
   195 
   181 procedure InitTeams;
   196 procedure InitTeams;
   182 var p: PTeam;
   197 var p: PTeam;
   183     i: integer;
   198     i: integer;
       
   199     th: integer;
   184 begin
   200 begin
   185 p:= TeamsList;
   201 p:= TeamsList;
   186 while p <> nil do
   202 while p <> nil do
   187       begin
   203       begin
       
   204       th:= 0;
   188       FillAmmoGroup(@p.Ammos[0]);
   205       FillAmmoGroup(@p.Ammos[0]);
   189       for i:= 0 to cMaxHHIndex do
   206       for i:= 0 to cMaxHHIndex do
   190           if p.Hedgehogs[i].Gear <> nil then
   207           if p.Hedgehogs[i].Gear <> nil then
   191              begin
   208              begin
   192              p.Hedgehogs[i].Gear.Health:= 100;
   209              p.Hedgehogs[i].Gear.Health:= 100;
       
   210              inc(th, 100);
   193              p.Hedgehogs[i].Ammo:= @p.Ammos[0] // 0 means all hedgehogs
   211              p.Hedgehogs[i].Ammo:= @p.Ammos[0] // 0 means all hedgehogs
   194              // will have common set of ammo
   212              // will have common set of ammo
   195              end;
   213              end;
       
   214       if th > MaxTeamHealth then MaxTeamHealth:= th;
   196       p:= p.Next
   215       p:= p.Next
   197       end;
   216       end;
   198 SetFirstTurnHedgehog;
   217 SetFirstTurnHedgehog;
       
   218 RecountAllTeamsHealth
   199 end;
   219 end;
   200 
   220 
   201 procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
   221 procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
   202 var s: shortstring;
   222 var s: shortstring;
   203 begin
   223 begin
   204 with Hedgehog^ do
   224 with Hedgehog^ do
   205      begin     
   225      begin
   206      if Ammo[CurSlot, CurAmmo].Count = 0 then
   226      if Ammo[CurSlot, CurAmmo].Count = 0 then
   207         begin
   227         begin
   208         CurAmmo:= 0;
   228         CurAmmo:= 0;
   209         while (CurAmmo <= cMaxSlotAmmoIndex) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurAmmo)
   229         while (CurAmmo <= cMaxSlotAmmoIndex) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurAmmo)
   210         end;
   230         end;
   271 Result:= 0;
   291 Result:= 0;
   272 for i:= 0 to cMaxHHIndex do
   292 for i:= 0 to cMaxHHIndex do
   273     if p.Hedgehogs[i].Gear <> nil then inc(Result)
   293     if p.Hedgehogs[i].Gear <> nil then inc(Result)
   274 end;
   294 end;
   275 
   295 
       
   296 procedure RecountTeamHealth(team: PTeam);
       
   297 var i: integer;
       
   298 begin
       
   299 with team^ do
       
   300      begin
       
   301      TeamHealth:= 0;
       
   302      for i:= 0 to cMaxHHIndex do
       
   303          if Hedgehogs[i].Gear <> nil then
       
   304             inc(TeamHealth, Hedgehogs[i].Gear.Health);
       
   305      if TeamHealth > MaxTeamHealth then
       
   306         begin
       
   307         MaxTeamHealth:= TeamHealth;
       
   308         RecountAllTeamsHealth;
       
   309         end else TeamHealth:= (TeamHealth * cTeamHealthWidth) div MaxTeamHealth
       
   310      end
       
   311 end;
       
   312 
   276 initialization
   313 initialization
   277 
   314 
   278 finalization
   315 finalization
   279 
   316 
   280 FreeTeamsList
   317 FreeTeamsList