hedgewars/uTeams.pas
author unc0rr
Mon, 22 Aug 2005 13:35:41 +0000
changeset 1 30f2d1037d5d
child 4 bcbd7adb4e4b
permissions -rw-r--r--
Add current sources. hw, hwserv and runhelper are compilable under Windows and *nix with FreePascal (and use -Od option) and run well on these OSes Hedge.dpr can be run only in Windows... to be ported
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     1
(*
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     4
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     6
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    13
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    21
 *
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    32
 *)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    33
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    34
unit uTeams;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    35
interface
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    36
uses SDLh, uConsts, uKeys, uGears, uRandom;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    37
{$INCLUDE options.inc}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    38
type PHedgehog = ^THedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    39
     PTeam     = ^TTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    40
     PHHAmmo   = ^THHAmmo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    41
     THedgehog = record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    42
                 Name: string[15];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    43
                 Gear: PGear;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    44
                 NameRect, HealthRect, HealthTagRect: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    45
                 Ammo: PHHAmmo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    46
                 CurSlot, CurAmmo: LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    47
                 AltSlot, AltAmmo: LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    48
                 Team: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    49
                 AttacksNum: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    50
                 visStepPos: LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    51
                 BotLevel  : LongWord; // 0 - человек
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    52
                 end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    53
     THHAmmo   = array[0..cMaxSlot, 0..cMaxSlotAmmo] of TAmmo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    54
     TTeam = record
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    55
             Next: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    56
             Color: Cardinal;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    57
             TeamName: string[15];
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    58
             ExtDriven: boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    59
             Aliases: array[0..cKeyMaxIndex] of shortstring;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    60
             Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    61
             Ammos: array[0..cMaxHHIndex] of THHAmmo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    62
             CurrHedgehog: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    63
             NameRect, CrossHairRect, GraveRect: TSDL_Rect;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    64
             GraveName: string;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    65
             FortName: string;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    66
             AttackBar: LongWord;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    67
             end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    68
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    69
var CurrentTeam: PTeam = nil;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    70
    TeamsList: PTeam = nil;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    71
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    72
function AddTeam: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    73
procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    74
procedure SwitchHedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    75
procedure InitTeams;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    76
procedure OnUsedAmmo(Ammo: PHHAmmo);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    77
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    78
implementation
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    79
uses uMisc, uStore, uWorld, uIO, uAIActions;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    80
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    81
procedure FreeTeamsList; forward;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    82
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    83
procedure SwitchHedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    84
var tteam: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    85
    th: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    86
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    87
FreeActionsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    88
TargetPoint.X:= NoPointX;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    89
if CurrentTeam = nil then OutError('nil Team', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    90
tteam:= CurrentTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    91
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    92
     if Gear <> nil then Gear.Message:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    93
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    94
repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    95
  CurrentTeam:= CurrentTeam.Next;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    96
  if CurrentTeam = nil then CurrentTeam:= TeamsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    97
  th:= CurrentTeam.CurrHedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    98
  repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
    99
    CurrentTeam.CurrHedgehog:= Succ(CurrentTeam.CurrHedgehog) mod cMaxHHIndex;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   100
  until (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil) or (CurrentTeam.CurrHedgehog = th)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   101
until (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil) or (CurrentTeam = tteam);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   102
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   103
if (CurrentTeam = tteam) then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   104
   begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   105
   if GameType = gmtDemo then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   106
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   107
      SendIPC('q');
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   108
      GameState:= gsExit;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   109
      exit
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   110
      end else OutError('There''s only one team on map!', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   111
   end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   112
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   113
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   114
     AttacksNum:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   115
     with Gear^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   116
          begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   117
          State:= State or gstHHDriven;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   118
          Active:= true
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   119
          end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   120
     FollowGear:= Gear
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   121
     end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   122
ResetKbd;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   123
cWindSpeed:= (GetRandom * 2 - 1) * cMaxWindSpeed;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   124
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   125
ApplyAmmoChanges(@CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   126
TurnTimeLeft:= cHedgehogTurnTime
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   127
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   128
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   129
procedure SetFirstTurnHedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   130
var i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   131
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   132
if CurrentTeam=nil then OutError('nil Team (SetFirstTurnHedgehog)', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   133
i:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   134
while (i<cMaxHHIndex)and(CurrentTeam.Hedgehogs[i].Gear=nil) do inc(i);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   135
if CurrentTeam.Hedgehogs[i].Gear = nil then OutError(errmsgIncorrectUse + ' (sfth)', true);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   136
CurrentTeam.CurrHedgehog:= i;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   137
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   138
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   139
function AddTeam: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   140
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   141
try
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   142
   New(Result);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   143
except Result:= nil; OutError(errmsgDynamicVar, true) end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   144
FillChar(Result^, sizeof(TTeam), 0);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   145
Result.AttackBar:= 1;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   146
if TeamsList = nil then TeamsList:= Result
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   147
                   else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   148
                        Result.Next:= TeamsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   149
                        TeamsList:= Result
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   150
                        end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   151
CurrentTeam:= Result
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   152
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   153
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   154
procedure FreeTeamsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   155
var t, tt: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   156
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   157
tt:= TeamsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   158
TeamsList:= nil;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   159
while tt<>nil do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   160
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   161
      t:= tt;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   162
      tt:= tt.Next;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   163
      try
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   164
      Dispose(t)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   165
      except OutError(errmsgDynamicVar) end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   166
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   167
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   168
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   169
procedure InitTeams;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   170
var p: PTeam;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   171
    i: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   172
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   173
p:= TeamsList;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   174
while p <> nil do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   175
      begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   176
      for i:= 0 to cMaxHHIndex do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   177
          if p.Hedgehogs[i].Gear <> nil then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   178
             begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   179
             p.Ammos[i][0, 0]:= Ammoz[amGrenade].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   180
             p.Ammos[i][0, 1]:= Ammoz[amUFO].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   181
             p.Ammos[i][1, 0]:= Ammoz[amBazooka].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   182
             p.Ammos[i][2, 0]:= Ammoz[amShotgun].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   183
             p.Ammos[i][3, 0]:= Ammoz[amPickHammer].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   184
             p.Ammos[i][3, 1]:= Ammoz[amRope].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   185
             p.Ammos[i][4, 0]:= Ammoz[amSkip].Ammo;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   186
             p.Hedgehogs[i].Gear.Health:= 100;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   187
             p.Hedgehogs[i].Ammo:= @p.Ammos[0]
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   188
             {0 - общее на всех оружие, i - у каждого своё
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   189
             можно группировать ёжиков, чтобы у каждой группы было своё оружие}
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   190
             end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   191
      p:= p.Next
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   192
      end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   193
SetFirstTurnHedgehog;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   194
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   195
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   196
procedure ApplyAmmoChanges(Hedgehog: PHedgehog);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   197
var s: shortstring;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   198
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   199
with Hedgehog^ do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   200
     begin     
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   201
     if Ammo[CurSlot, CurAmmo].Count = 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   202
        begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   203
        CurAmmo:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   204
        while (CurAmmo <= cMaxSlotAmmo) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurAmmo)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   205
        end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   206
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   207
with Ammo[CurSlot, CurAmmo] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   208
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   209
     s:= Ammoz[AmmoType].Name;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   210
     if Count <> AMMO_INFINITE then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   211
        s:= s + ' (' + IntToStr(Count) + ')';
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   212
     if (Propz and ammoprop_Timerable) <> 0 then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   213
        s:= s + ', ' + inttostr(Timer div 1000) + ' sec';
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   214
     AddCaption(s, Team.Color, capgrpAmmoinfo);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   215
     if (Propz and ammoprop_NeedTarget) <> 0
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   216
        then begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   217
        Gear.State:= Gear.State or      gstHHChooseTarget;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   218
        isCursorVisible:= true
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   219
        end else begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   220
        Gear.State:= Gear.State and not gstHHChooseTarget;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   221
        AdjustMPoint;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   222
        isCursorVisible:= false
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   223
        end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   224
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   225
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   226
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   227
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   228
procedure PackAmmo(Ammo: PHHAmmo; Slot: integer);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   229
var ami: integer;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   230
    b: boolean;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   231
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   232
    repeat
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   233
      b:= false;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   234
      ami:= 0;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   235
      while (not b) and (ami < cMaxSlotAmmo) do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   236
          if (Ammo[slot, ami].Count = 0)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   237
             and (Ammo[slot, ami + 1].Count > 0) then b:= true
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   238
                                                 else inc(ami);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   239
      if b then // есть пустое место
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   240
         begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   241
         Ammo[slot, ami]:= Ammo[slot, ami + 1]
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   242
         end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   243
    until not b;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   244
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   245
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   246
procedure OnUsedAmmo(Ammo: PHHAmmo);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   247
var s, a: Longword;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   248
begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   249
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   250
     begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   251
     if CurAmmoGear = nil then begin s:= CurSlot; a:= CurAmmo end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   252
                          else begin s:= AltSlot; a:= AltAmmo end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   253
     with Ammo[s, a] do
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   254
          if Count <> AMMO_INFINITE then
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   255
             begin
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   256
             dec(Count);
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   257
             if Count = 0 then PackAmmo(Ammo, CurSlot)
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   258
             end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   259
     end
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   260
end;
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   261
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   262
initialization
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   263
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   264
finalization
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   265
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   266
FreeTeamsList
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   267
30f2d1037d5d Add current sources.
unc0rr
parents:
diff changeset
   268
end.