hedgewars/uTeams.pas
author unc0rr
Mon, 15 Jan 2007 23:25:44 +0000
changeset 344 a98ade8c99b6
parent 312 c36d0b34ac3d
child 351 29bc9c36ad5f
permissions -rw-r--r--
Get further with debug
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
(*
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     2
 * Hedgewars, a worms-like game
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
     3
 * Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    19
unit uTeams;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
interface
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 286
diff changeset
    21
uses SDLh, uConsts, uKeys, uGears, uRandom, uAmmos;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
{$INCLUDE options.inc}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    23
type PHedgehog = ^THedgehog;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
     PTeam     = ^TTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
     THedgehog = record
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 72
diff changeset
    26
                 Name: string[MAXNAMELEN];
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
                 Gear: PGear;
95
1ef5e2c41115 - Fixed compilation
unc0rr
parents: 92
diff changeset
    28
                 NameTag, HealthTag: PSDL_Surface;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    29
                 Ammo: PHHAmmo;
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 286
diff changeset
    30
                 AmmoStore: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
                 CurSlot, CurAmmo: LongWord;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
                 AltSlot, AltAmmo: LongWord;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    33
                 Team: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    34
                 AttacksNum: Longword;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    35
                 visStepPos: LongWord;
5
0dafbd19a04c Show wind speed on bar
unc0rr
parents: 4
diff changeset
    36
                 BotLevel  : LongWord; // 0 - Human player
307
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
    37
                 DamageGiven: Longword;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
    38
                 MaxStepDamage: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    39
                 end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    40
     TTeam = record
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    41
             Next: PTeam;
189
33d147c69a83 Color fixes
unc0rr
parents: 188
diff changeset
    42
             Color, AdjColor: Longword;
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 72
diff changeset
    43
             TeamName: string[MAXNAMELEN];
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    44
             ExtDriven: boolean;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 165
diff changeset
    45
             Binds: TBinds;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
             Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    47
             CurrHedgehog: integer;
95
1ef5e2c41115 - Fixed compilation
unc0rr
parents: 92
diff changeset
    48
             NameTag: PSDL_Surface;
198
6f00e0f4cb88 - New crosshair
unc0rr
parents: 196
diff changeset
    49
             CrosshairSurf: PSDL_Surface;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
    50
             GraveRect, HealthRect: TSDL_Rect;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    51
             GraveName: string;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
             FortName: string;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
    53
             TeamHealth: integer;
146
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
    54
             TeamHealthBarWidth: integer;
49
3afe33c1cf06 - Teams health bars sorting
unc0rr
parents: 47
diff changeset
    55
             DrawHealthY: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
             AttackBar: LongWord;
312
c36d0b34ac3d Use new parameters, small protocol change
unc0rr
parents: 307
diff changeset
    57
             HedgehogsNumber: byte;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    58
             end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    59
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    60
var CurrentTeam: PTeam = nil;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
    TeamsList: PTeam = nil;
304
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
    62
    CurMinAngle, CurMaxAngle: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
function AddTeam: PTeam;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 64
diff changeset
    65
procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    66
procedure SwitchHedgehog;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    67
procedure InitTeams;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    68
function  TeamSize(p: PTeam): Longword;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
    69
procedure RecountTeamHealth(team: PTeam);
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
    70
procedure RestoreTeamsFromSave;
92
0c359a7a2356 - Fix win message to appear only after all hedgehogs death
unc0rr
parents: 89
diff changeset
    71
function CheckForWin: boolean;
165
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
    72
procedure SetWeapon(weap: TAmmoType);
307
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
    73
procedure SendStats;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    75
implementation
196
993cf173218b - Many small fixes
unc0rr
parents: 189
diff changeset
    76
uses uMisc, uWorld, uAI, uLocale, uConsole;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
    77
const MaxTeamHealth: integer = 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    78
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    79
procedure FreeTeamsList; forward;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    80
92
0c359a7a2356 - Fix win message to appear only after all hedgehogs death
unc0rr
parents: 89
diff changeset
    81
function CheckForWin: boolean;
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    82
var team, AliveTeam: PTeam;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    83
    AliveCount: Longword;
306
7b61834edcf6 - Better blowtorch
unc0rr
parents: 304
diff changeset
    84
    s: shortstring;
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    85
begin
92
0c359a7a2356 - Fix win message to appear only after all hedgehogs death
unc0rr
parents: 89
diff changeset
    86
Result:= false;
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    87
AliveCount:= 0;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    88
AliveTeam:= nil;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    89
team:= TeamsList;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    90
while team <> nil do
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    91
      begin
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    92
      if team.TeamHealth > 0 then
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    93
         begin
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    94
         inc(AliveCount);
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    95
         AliveTeam:= team
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    96
         end;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    97
      team:= team.Next
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    98
      end;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
    99
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   100
if AliveCount >= 2 then exit;
92
0c359a7a2356 - Fix win message to appear only after all hedgehogs death
unc0rr
parents: 89
diff changeset
   101
Result:= true;
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   102
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   103
TurnTimeLeft:= 0;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   104
if AliveCount = 0 then
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   105
   begin // draw
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   106
   AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState);
306
7b61834edcf6 - Better blowtorch
unc0rr
parents: 304
diff changeset
   107
   SendStat(siGameResult, trmsg[sidDraw]);
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   108
   AddGear(0, 0, gtATFinishGame, 0, 0, 0, 2000)
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   109
   end else // win
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   110
   begin
306
7b61834edcf6 - Better blowtorch
unc0rr
parents: 304
diff changeset
   111
   s:= Format(trmsg[sidWinner], AliveTeam.TeamName);
7b61834edcf6 - Better blowtorch
unc0rr
parents: 304
diff changeset
   112
   AddCaption(s, $FFFFFF, capgrpGameState);
7b61834edcf6 - Better blowtorch
unc0rr
parents: 304
diff changeset
   113
   SendStat(siGameResult, s);
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   114
   AddGear(0, 0, gtATFinishGame, 0, 0, 0, 2000)
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   115
   end;
307
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   116
SendStats
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   117
end;
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   118
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   119
procedure SwitchHedgehog;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   120
var tteam: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   121
    th: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   122
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   123
FreeActionsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   124
TargetPoint.X:= NoPointX;
89
f9db56409a86 - Fix various bugs
unc0rr
parents: 83
diff changeset
   125
TryDo(CurrentTeam <> nil, 'nil Team', true);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
tteam:= CurrentTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   127
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
294
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   128
     if Gear <> nil then
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   129
        begin
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   130
        Gear.Message:= 0;
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   131
        Gear.Z:= cHHZ
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   132
        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   133
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   134
repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   135
  CurrentTeam:= CurrentTeam.Next;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   136
  if CurrentTeam = nil then CurrentTeam:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   137
  th:= CurrentTeam.CurrHedgehog;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   138
  repeat
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   139
    CurrentTeam.CurrHedgehog:= Succ(CurrentTeam.CurrHedgehog) mod (cMaxHHIndex + 1);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   140
  until (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil) or (CurrentTeam.CurrHedgehog = th)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   141
until (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear <> nil) or (CurrentTeam = tteam);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   142
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   143
TryDo(CurrentTeam <> tteam, 'Switch hedgehog: only one team?!', true);
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   144
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   145
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   146
     begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   147
     AttacksNum:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   148
     with Gear^ do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   149
          begin
294
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   150
          Z:= cCurrHHZ;
32
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 17
diff changeset
   151
          State:= gstHHDriven;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   152
          Active:= true
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   153
          end;
294
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   154
     RemoveGearFromList(Gear);
92a7ccd67bb9 Current hedgehog is on top of others in Z-order
unc0rr
parents: 288
diff changeset
   155
     InsertGearToList(Gear);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   156
     FollowGear:= Gear
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   157
     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   158
ResetKbd;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   159
cWindSpeed:= (GetRandom * 2 - 1) * cMaxWindSpeed;
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   160
AddGear(0, 0, gtATSmoothWindCh, 0, 0, 0, 1).Tag:= round(72 * cWindSpeed / cMaxWindSpeed);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   161
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF}
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 64
diff changeset
   162
ApplyAmmoChanges(CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog]);
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 165
diff changeset
   163
if CurrentTeam.ExtDriven then SetDefaultBinds
805fa9a27e9e "Trusted" binds
unc0rr
parents: 165
diff changeset
   164
                         else SetBinds(CurrentTeam.Binds);
176
533d03041dcd 'h' marks out current hedgehog
unc0rr
parents: 167
diff changeset
   165
bShowFinger:= true;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   166
TurnTimeLeft:= cHedgehogTurnTime
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   168
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   169
function AddTeam: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   170
begin
17
a6bed8d31444 minor code review
unc0rr
parents: 13
diff changeset
   171
New(Result);
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   172
TryDo(Result <> nil, 'AddTeam: Result = nil', true);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   173
FillChar(Result^, sizeof(TTeam), 0);
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 72
diff changeset
   174
Result.AttackBar:= 2;
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   175
Result.CurrHedgehog:= cMaxHHIndex;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   176
if TeamsList = nil then TeamsList:= Result
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   177
                   else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   178
                        Result.Next:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   179
                        TeamsList:= Result
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   180
                        end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   181
CurrentTeam:= Result
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   182
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   183
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   184
procedure FreeTeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   185
var t, tt: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   186
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   187
tt:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   188
TeamsList:= nil;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   189
while tt<>nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   190
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   191
      t:= tt;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   192
      tt:= tt.Next;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   193
      Dispose(t)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   194
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   195
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   196
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   197
procedure RecountAllTeamsHealth;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   198
var p: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   199
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   200
p:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   201
while p <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   202
      begin
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   203
      RecountTeamHealth(p);
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   204
      p:= p.Next
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   205
      end
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   206
end;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   207
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   208
procedure InitTeams;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   209
var p: PTeam;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   210
    i: integer;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   211
    th: integer;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   212
begin
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   213
p:= TeamsList;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   214
while p <> nil do
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   215
      begin
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   216
      th:= 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   217
      for i:= 0 to cMaxHHIndex do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   218
          if p.Hedgehogs[i].Gear <> nil then
312
c36d0b34ac3d Use new parameters, small protocol change
unc0rr
parents: 307
diff changeset
   219
             inc(th, p.Hedgehogs[i].Gear.Health);
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   220
      if th > MaxTeamHealth then MaxTeamHealth:= th;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   221
      p:= p.Next
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   222
      end;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   223
RecountAllTeamsHealth
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   224
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   225
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 64
diff changeset
   226
procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   227
var s: shortstring;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   228
begin
162
4822f6face35 Ammo menu now works!
unc0rr
parents: 146
diff changeset
   229
TargetPoint.X:= NoPointX;
4822f6face35 Ammo menu now works!
unc0rr
parents: 146
diff changeset
   230
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 64
diff changeset
   231
with Hedgehog do
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   232
     begin
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   233
     if Ammo[CurSlot, CurAmmo].Count = 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   234
        begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   235
        CurAmmo:= 0;
288
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 286
diff changeset
   236
        CurSlot:= 0;
929c44745fd9 Ammo schemes and ammo stores support in engine
unc0rr
parents: 286
diff changeset
   237
        while (CurSlot <= cMaxSlotIndex) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurSlot)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   238
        end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   239
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   240
with Ammo[CurSlot, CurAmmo] do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   241
     begin
304
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   242
     CurMinAngle:= Ammoz[AmmoType].minAngle;
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   243
     if Ammoz[AmmoType].maxAngle <> 0 then CurMaxAngle:= Ammoz[AmmoType].maxAngle
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   244
                                      else CurMaxAngle:= cMaxAngle;
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   245
     with Hedgehog.Gear^ do
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   246
        begin
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   247
        if Angle < CurMinAngle then Angle:= CurMinAngle;
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   248
        if Angle > CurMaxAngle then Angle:= CurMaxAngle;
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   249
        end;
8096e69e839e Attack angle constraints
unc0rr
parents: 295
diff changeset
   250
        
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   251
     s:= trammo[Ammoz[AmmoType].NameId];
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   252
     if Count <> AMMO_INFINITE then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   253
        s:= s + ' (' + IntToStr(Count) + ')';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   254
     if (Propz and ammoprop_Timerable) <> 0 then
83
207c85fbef51 - First hedgehog in team has first turn in team
unc0rr
parents: 81
diff changeset
   255
        s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds];
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   256
     AddCaption(s, Team.Color, capgrpAmmoinfo);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   257
     if (Propz and ammoprop_NeedTarget) <> 0
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   258
        then begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   259
        Gear.State:= Gear.State or      gstHHChooseTarget;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   260
        isCursorVisible:= true
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   261
        end else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   262
        Gear.State:= Gear.State and not gstHHChooseTarget;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   263
        isCursorVisible:= false
13
7a5db822fd3f - Show no crosshair when using mine
unc0rr
parents: 10
diff changeset
   264
        end;
7a5db822fd3f - Show no crosshair when using mine
unc0rr
parents: 10
diff changeset
   265
     ShowCrosshair:= (Propz and ammoprop_NoCrosshair) = 0
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   266
     end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   267
     end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   268
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   269
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   270
function  TeamSize(p: PTeam): Longword;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   271
var i: Longword;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   272
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   273
Result:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   274
for i:= 0 to cMaxHHIndex do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   275
    if p.Hedgehogs[i].Gear <> nil then inc(Result)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   276
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   277
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   278
procedure RecountTeamHealth(team: PTeam);
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   279
var i: integer;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   280
begin
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   281
with team^ do
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   282
     begin
146
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
   283
     TeamHealthBarWidth:= 0;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   284
     for i:= 0 to cMaxHHIndex do
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   285
         if Hedgehogs[i].Gear <> nil then
146
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
   286
            inc(TeamHealthBarWidth, Hedgehogs[i].Gear.Health);
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
   287
     TeamHealth:= TeamHealthBarWidth;
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
   288
     if TeamHealthBarWidth > MaxTeamHealth then
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   289
        begin
146
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
   290
        MaxTeamHealth:= TeamHealthBarWidth;
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   291
        RecountAllTeamsHealth;
146
458f4f58c1b6 - Fix AI not to damage self hedgehogs
unc0rr
parents: 105
diff changeset
   292
        end else TeamHealthBarWidth:= (TeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
49
3afe33c1cf06 - Teams health bars sorting
unc0rr
parents: 47
diff changeset
   293
     end;
105
e7cb9bb4a9de - Fixed integer->longint
unc0rr
parents: 95
diff changeset
   294
// FIXME: at the game init, gtTeamHealthSorters are created for each team, and they work simultaneously
49
3afe33c1cf06 - Teams health bars sorting
unc0rr
parents: 47
diff changeset
   295
AddGear(0, 0, gtTeamHealthSorter, 0)
47
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   296
end;
8daf1ee0b9a3 Show team health bars, without sorting yet
unc0rr
parents: 32
diff changeset
   297
72
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   298
procedure RestoreTeamsFromSave;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   299
var p: PTeam;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   300
begin
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   301
p:= TeamsList;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   302
while p <> nil do
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   303
      begin
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   304
      p.ExtDriven:= false;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   305
      p:= p.Next
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   306
      end;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   307
end;
aeb2ac1878dc Basic save support in engine
unc0rr
parents: 70
diff changeset
   308
165
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   309
procedure SetWeapon(weap: TAmmoType);
247
07605d2a2024 - Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents: 198
diff changeset
   310
var t: integer;
165
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   311
begin
247
07605d2a2024 - Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents: 198
diff changeset
   312
t:= cMaxSlotAmmoIndex;
165
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   313
with CurrentTeam^ do
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   314
     with Hedgehogs[CurrHedgehog] do
255
97b2d242e2a1 Fix selecting 2nd ammo in slot %-\
unc0rr
parents: 247
diff changeset
   315
          while (Ammo[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do
247
07605d2a2024 - Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents: 198
diff changeset
   316
                begin
165
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   317
                ParseCommand('/slot ' + chr(49 + Ammoz[TAmmoType(weap)].Slot));
247
07605d2a2024 - Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents: 198
diff changeset
   318
                dec(t)
07605d2a2024 - Fix infinite loop when selecting weapon with ammo menu
unc0rr
parents: 198
diff changeset
   319
                end
165
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   320
end;
9b9144948668 Many small fixes
unc0rr
parents: 162
diff changeset
   321
307
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   322
procedure SendStats;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   323
var p: PTeam;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   324
    i: integer;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   325
    msd: Longword; msdhh: PHedgehog;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   326
begin
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   327
msd:= 0; msdhh:= nil;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   328
p:= TeamsList;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   329
while p <> nil do
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   330
      begin
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   331
      for i:= 0 to cMaxHHIndex do
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   332
          if p.Hedgehogs[i].MaxStepDamage > msd then
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   333
             begin
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   334
             msdhh:= @p.Hedgehogs[i];
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   335
             msd:= p.Hedgehogs[i].MaxStepDamage
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   336
             end;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   337
      p:= p.Next
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   338
      end;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   339
if msdhh <> nil then SendStat(siMaxStepDamage, inttostr(msdhh.MaxStepDamage) + ' ' +
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   340
                                               msdhh.Name + ' (' + msdhh.Team.TeamName + ')');
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   341
if KilledHHs > 0 then SendStat(siKilledHHs, inttostr(KilledHHs));
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   342
end;
96b428ac11f2 More statistics
unc0rr
parents: 306
diff changeset
   343
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   344
initialization
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   345
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   346
finalization
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   347
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   348
FreeTeamsList
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   349
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   350
end.