hedgewars/uAIMisc.pas
author unc0rr
Wed, 26 Oct 2005 17:26:39 +0000
changeset 18 d49c23eba8ba
parent 4 bcbd7adb4e4b
child 53 0e27949850e3
permissions -rw-r--r--
Start to write QT frontend
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
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     3
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     6
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     9
 * with the Software without restriction, including without limitation the
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    12
 * furnished to do so, subject to the following conditions:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    15
 *    this list of conditions and the following disclaimer.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
 *    and/or other materials provided with the distribution.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
 *    derived from this software without specific prior written permission.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    21
 *
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    32
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    33
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    34
unit uAIMisc;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    35
interface
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    36
uses uConsts, uGears, SDLh;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    37
{$INCLUDE options.inc}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    38
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    39
type TTargets = record
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    40
                Count: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    41
                ar: array[0..cMaxHHIndex*5] of TPoint;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    42
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
                
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    44
procedure FillTargets(var Targets: TTargets);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    45
function DxDy2Angle(const _dY, _dX: Extended): integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
function TestColl(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    47
function NoMyHHNear(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    48
function HHGo(Gear: PGear): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    49
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    50
implementation
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    51
uses uTeams, uStore, uMisc, uLand, uCollisions;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    53
procedure FillTargets(var Targets: TTargets);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    54
var t: PTeam;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    55
    i, k: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
    r: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    57
    MaxHealth: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    58
    score: array[0..cMaxHHIndex*5] of integer;
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
  procedure qSort(iLo, iHi: Integer);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
  var
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    62
    Lo, Hi, Mid, T: Integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
    P: TPoint;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
  begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
    Lo := iLo;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    66
    Hi := iHi;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    67
    Mid := score[(Lo + Hi) div 2];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    68
    repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    69
      while score[Lo] > Mid do Inc(Lo);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    70
      while score[Hi] < Mid do Dec(Hi);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    71
      if Lo <= Hi then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    72
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    73
        T := score[Lo];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
        score[Lo] := score[Hi];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    75
        score[Hi] := T;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    76
        P := Targets.ar[Lo];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    77
        Targets.ar[Lo] := Targets.ar[Hi];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    78
        Targets.ar[Hi] := P;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    79
        Inc(Lo);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    80
        Dec(Hi)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    81
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    82
    until Lo > Hi;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    83
    if Hi > iLo then qSort(iLo, Hi);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    84
    if Lo < iHi then qSort(Lo, iHi);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    85
  end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    86
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    87
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    88
Targets.Count:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    89
t:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    90
MaxHealth:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    91
while t <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    92
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    93
      if t <> CurrentTeam then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    94
         for i:= 0 to cMaxHHIndex do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    95
             if t.Hedgehogs[i].Gear <> nil then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    96
                begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    97
                with Targets.ar[Targets.Count], t.Hedgehogs[i] do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    98
                     begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    99
                     X:= Round(Gear.X);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   100
                     Y:= Round(Gear.Y);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   101
                     if integer(Gear.Health) > MaxHealth then MaxHealth:= Gear.Health;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   102
                     score[Targets.Count]:= random(3) - integer(Gear.Health div 5)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   103
                     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   104
                inc(Targets.Count)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   105
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   106
      t:= t.Next
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   107
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   108
// âûñòàâëÿåì îöåíêó çà ïîïàäàíèå â ¸æèêà:
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   109
//  - åñëè åñòü ñîñåäè-ïðîòèâíèêè, òî îöåíêà óâåëè÷èâàåòñÿ
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   110
//  - ÷åì ìåíüøå õåëñà ó ¸æèêà, òåì áîëüøå îöåíêà (êîä ñì. âûøå)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   111
//  - åñëè åñòü ñîñåäè-"ñâîè", òî óìåíüøàåòñÿ
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   112
with Targets do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   113
     for i:= 0 to Targets.Count - 1 do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   114
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   115
         for k:= Succ(i) to Pred(Targets.Count) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   116
             begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   117
             r:= 100 - round(sqrt(sqr(ar[i].X - ar[k].X) + sqr(ar[i].Y - ar[k].Y)));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   118
             if r > 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   119
                begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   120
                inc(score[i], r);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   121
                inc(score[k], r)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   122
                end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   123
             end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   124
         for k:= 0 to cMaxHHIndex do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   125
             with CurrentTeam.Hedgehogs[k] do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
                  if Gear <> nil then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   127
                     begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   128
                     r:= 100 - round(sqrt(sqr(ar[i].X - round(Gear.X)) + sqr(ar[i].Y - round(Gear.Y))));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   129
                     if r > 0 then dec(score[i], (r * 3) div 2 + MaxHealth + 5 - integer(Gear.Health));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   130
                     end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   131
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   132
// ñîðòèðóåì ïî óáûâàíèþ ñîãëàñíî îöåíêå
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   133
if Targets.Count >= 2 then qSort(0, Pred(Targets.Count));
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   134
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   135
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   136
function DxDy2Angle(const _dY, _dX: Extended): integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   137
const piDIVMaxAngle: Extended = pi/cMaxAngle;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   138
asm
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   139
        fld     _dY
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   140
        fld     _dX
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   141
        fpatan
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   142
        fld     piDIVMaxAngle
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   143
        fdiv
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   144
        sub     esp, 4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   145
        fistp   dword ptr [esp]
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   146
        pop     eax
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   147
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   148
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   149
function TestColl(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   150
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   151
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   152
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   153
Result:=(((x-r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x-r] <> 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   154
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   155
Result:=(((x+r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x+r] <> 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   156
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   157
Result:=(((x+r) and $FFFFF800) = 0)and(((y+r) and $FFFFFC00) = 0) and (Land[y+r, x+r] <> 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   158
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   159
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   160
function NoMyHHNear(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   161
var i: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   162
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   163
i:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   164
r:= sqr(r);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   165
Result:= true;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   166
repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
  with CurrentTeam.Hedgehogs[i] do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   168
       if Gear <> nil then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   169
          if sqr(Gear.X - x) + sqr(Gear.Y - y) <= r then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   170
             begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   171
             Result:= false;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   172
             exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   173
             end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   174
inc(i)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   175
until i > cMaxHHIndex
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   176
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   177
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   178
function HHGo(Gear: PGear): boolean; // false åñëè íåëüçÿ äâèãàòüñÿ
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   179
var pX, pY: integer;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   180
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   181
Result:= false;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   182
repeat
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   183
pX:= round(Gear.X);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   184
pY:= round(Gear.Y);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   185
if pY + cHHHalfHeight >= cWaterLine then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   186
if (Gear.State and gstFalling) <> 0 then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   187
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   188
   Gear.dY:= Gear.dY + cGravity;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   189
   if Gear.dY > 0.35 then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   190
   Gear.Y:= Gear.Y + Gear.dY;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   191
   if HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   192
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   193
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   194
      Gear.dY:= 0
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
   continue
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   197
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   198
   {if ((Gear.Message and gm_LJump )<>0) then
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
      Gear.Message:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   201
      if not HHTestCollisionYwithGear(Gear, -1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   202
         if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   203
         if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   204
      if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   205
         or   HHTestCollisionYwithGear(Gear, -1)) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   206
         begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   207
         Gear.dY:= -0.15;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   208
         Gear.dX:= Sign(Gear.dX) * 0.15;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   209
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   210
         exit
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   211
         end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   212
      end;}
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   213
   if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   214
   if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   215
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   216
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   217
      if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   218
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   219
      if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   220
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   221
      if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   222
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   223
      if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   224
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   225
      if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   226
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   227
      if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   228
         or HHTestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   229
      end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   230
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   231
   if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   232
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   233
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   234
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   235
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   236
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   237
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   238
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   239
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   240
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   241
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   242
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   243
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   244
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   245
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   246
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   247
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   248
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   249
   Gear.Y:= Gear.Y + 1;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   250
   if not HHTestCollisionYwithGear(Gear, 1) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   251
      begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   252
      Gear.Y:= Gear.Y - 6;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   253
      Gear.dY:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   254
      Gear.dX:= 0.0000001 * Sign(Gear.dX);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   255
      Gear.State:= Gear.State or gstFalling
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   256
      end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   257
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   258
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   259
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   260
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   261
   end
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   262
   end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   263
if (pX <> round(Gear.X))and ((Gear.State and gstFalling) = 0) then
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   264
   begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   265
   Result:= true;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   266
   exit
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
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   269
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   270
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   271
end.