hedgewars/uTeams.pas
changeset 10 edf56dca1587
parent 6 9c1f00e7b43e
child 13 7a5db822fd3f
equal deleted inserted replaced
9:4cbf854ad095 10:edf56dca1587
    48                  Team: PTeam;
    48                  Team: PTeam;
    49                  AttacksNum: Longword;
    49                  AttacksNum: Longword;
    50                  visStepPos: LongWord;
    50                  visStepPos: LongWord;
    51                  BotLevel  : LongWord; // 0 - Human player
    51                  BotLevel  : LongWord; // 0 - Human player
    52                  end;
    52                  end;
    53      THHAmmo   = array[0..cMaxSlot, 0..cMaxSlotAmmo] of TAmmo;
    53      THHAmmo   = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo;
    54      TTeam = record
    54      TTeam = record
    55              Next: PTeam;
    55              Next: PTeam;
    56              Color: Cardinal;
    56              Color: Cardinal;
    57              TeamName: string[15];
    57              TeamName: string[15];
    58              ExtDriven: boolean;
    58              ExtDriven: boolean;
   166       Dispose(t)
   166       Dispose(t)
   167       except OutError(errmsgDynamicVar) end;
   167       except OutError(errmsgDynamicVar) end;
   168       end;
   168       end;
   169 end;
   169 end;
   170 
   170 
       
   171 procedure FillAmmoGroup(Ammo: PHHAmmo);
       
   172 var mi: array[0..cMaxSlotIndex] of byte;
       
   173     a: TAmmoType;
       
   174 begin
       
   175 FillChar(mi, sizeof(mi), 0);
       
   176 for a:= Low(TAmmoType) to High(TAmmoType) do
       
   177     begin
       
   178     TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
       
   179     Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
       
   180     inc(mi[Ammoz[a].Slot])
       
   181     end;
       
   182 end;
       
   183 
   171 procedure InitTeams;
   184 procedure InitTeams;
   172 var p: PTeam;
   185 var p: PTeam;
   173     i: integer;
   186     i: integer;
   174 begin
   187 begin
   175 p:= TeamsList;
   188 p:= TeamsList;
   176 while p <> nil do
   189 while p <> nil do
   177       begin
   190       begin
       
   191       FillAmmoGroup(@p.Ammos[0]);
   178       for i:= 0 to cMaxHHIndex do
   192       for i:= 0 to cMaxHHIndex do
   179           if p.Hedgehogs[i].Gear <> nil then
   193           if p.Hedgehogs[i].Gear <> nil then
   180              begin
   194              begin
   181              p.Ammos[i][0, 0]:= Ammoz[amGrenade].Ammo;
       
   182              p.Ammos[i][0, 1]:= Ammoz[amUFO].Ammo;
       
   183              p.Ammos[i][1, 0]:= Ammoz[amBazooka].Ammo;
       
   184              p.Ammos[i][2, 0]:= Ammoz[amShotgun].Ammo;
       
   185              p.Ammos[i][3, 0]:= Ammoz[amPickHammer].Ammo;
       
   186              p.Ammos[i][3, 1]:= Ammoz[amRope].Ammo;
       
   187              p.Ammos[i][4, 0]:= Ammoz[amSkip].Ammo;
       
   188              p.Hedgehogs[i].Gear.Health:= 100;
   195              p.Hedgehogs[i].Gear.Health:= 100;
   189              p.Hedgehogs[i].Ammo:= @p.Ammos[0]
   196              p.Hedgehogs[i].Ammo:= @p.Ammos[0] // 0 means all hedgehogs
   190              {0 - общее на всех оружие, i - у каждого своё
   197              // will have common set of ammo
   191              можно группировать ёжиков, чтобы у каждой группы было своё оружие}
       
   192              end;
   198              end;
   193       p:= p.Next
   199       p:= p.Next
   194       end;
   200       end;
   195 SetFirstTurnHedgehog;
   201 SetFirstTurnHedgehog;
   196 end;
   202 end;
   201 with Hedgehog^ do
   207 with Hedgehog^ do
   202      begin     
   208      begin     
   203      if Ammo[CurSlot, CurAmmo].Count = 0 then
   209      if Ammo[CurSlot, CurAmmo].Count = 0 then
   204         begin
   210         begin
   205         CurAmmo:= 0;
   211         CurAmmo:= 0;
   206         while (CurAmmo <= cMaxSlotAmmo) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurAmmo)
   212         while (CurAmmo <= cMaxSlotAmmoIndex) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurAmmo)
   207         end;
   213         end;
   208 
   214 
   209 with Ammo[CurSlot, CurAmmo] do
   215 with Ammo[CurSlot, CurAmmo] do
   210      begin
   216      begin
   211      s:= Ammoz[AmmoType].Name;
   217      s:= Ammoz[AmmoType].Name;
   232     b: boolean;
   238     b: boolean;
   233 begin
   239 begin
   234     repeat
   240     repeat
   235       b:= false;
   241       b:= false;
   236       ami:= 0;
   242       ami:= 0;
   237       while (not b) and (ami < cMaxSlotAmmo) do
   243       while (not b) and (ami < cMaxSlotAmmoIndex) do
   238           if (Ammo[slot, ami].Count = 0)
   244           if (Ammo[slot, ami].Count = 0)
   239              and (Ammo[slot, ami + 1].Count > 0) then b:= true
   245              and (Ammo[slot, ami + 1].Count > 0) then b:= true
   240                                                  else inc(ami);
   246                                                  else inc(ami);
   241       if b then // есть пустое место
   247       if b then // есть пустое место
   242          begin
   248          begin