hedgewars/uAIMisc.pas
author unc0rr
Tue, 23 Jan 2007 16:59:05 +0000
changeset 358 236bbd12d4d9
parent 351 29bc9c36ad5f
child 369 2aed85310727
permissions -rw-r--r--
- New Land Generator - Some perfomance tricks - Some typo fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     1
(*
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     2
 * Hedgewars, a worms-like game
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
    12
 * GNU General Public License for more details.
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 136
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    17
 *)
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    18
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    19
unit uAIMisc;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
interface
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 191
diff changeset
    21
uses SDLh, uConsts, uGears, uFloat;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
    22
{$INCLUDE options.inc}
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 191
diff changeset
    23
 {
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    24
type TTarget = record
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    25
               Point: TPoint;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    26
               Score: integer;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    27
               end;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    28
     TTargets = record
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    29
                Count: Longword;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    30
                ar: array[0..cMaxHHIndex*5] of TTarget;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
                end;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
    32
     TJumpType = (jmpNone, jmpHJump, jmpLJump);
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    33
     TGoInfo = record
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    34
               Ticks: Longword;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
    35
               FallPix: Longword;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
    36
               JumpType: TJumpType;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    37
               end;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    38
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    39
procedure FillTargets;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    40
procedure FillBonuses(isAfterAttack: boolean);
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    41
procedure AwareOfExplosion(x, y, r: integer);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    42
function RatePlace(Gear: PGear): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
function TestColl(x, y, r: integer): boolean;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    44
function RateExplosion(Me: PGear; x, y, r: integer): integer;
79
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
    45
function RateShove(Me: PGear; x, y, r, power: integer): integer;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
    46
function HHGo(Gear, AltGear: PGear; out GoInfo: TGoInfo): boolean;
136
89970b70b076 Implement bot levels
unc0rr
parents: 108
diff changeset
    47
function rndSign(num: integer): integer;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    48
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    49
var ThinkingHH: PGear;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    50
    Targets: TTargets;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 191
diff changeset
    51
                       }
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
implementation
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 191
diff changeset
    53
{uses uTeams, uMisc, uLand, uCollisions;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    54
const KillScore = 200;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    55
      MAXBONUS = 1024;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    56
      
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    57
type TBonus = record
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    58
              X, Y: integer;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    59
              Radius: integer;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    60
              Score: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    61
              end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    62
var bonuses: record
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    63
             Count: Longword;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    64
             ar: array[0..Pred(MAXBONUS)] of TBonus;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    65
             end;
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    66
    KnownExplosion: record
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    67
                    X, Y, Radius: integer
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    68
                    end = (X: 0; Y: 0; Radius: 0);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    69
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    70
procedure FillTargets;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    71
var t: PTeam;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    72
    i: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    73
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
Targets.Count:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    75
t:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    76
while t <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    77
      begin
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    78
      for i:= 0 to cMaxHHIndex do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    79
          if (t.Hedgehogs[i].Gear <> nil)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    80
             and (t.Hedgehogs[i].Gear <> ThinkingHH) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    81
             begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    82
             with Targets.ar[Targets.Count], t.Hedgehogs[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    83
                  begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    84
                  Point.X:= Round(Gear.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    85
                  Point.Y:= Round(Gear.Y);
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
    86
                  if t.Color <> CurrentTeam.Color then Score:=  Gear.Health
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
    87
                                                  else Score:= -Gear.Health
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    88
                  end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    89
             inc(Targets.Count)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    90
             end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    91
      t:= t.Next
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    92
      end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    93
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    94
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    95
procedure FillBonuses(isAfterAttack: boolean);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    96
var Gear: PGear;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    97
    MyColor: Longword;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    98
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    99
    procedure AddBonus(x, y: integer; r: Longword; s: integer);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   100
    begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   101
    bonuses.ar[bonuses.Count].x:= x;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   102
    bonuses.ar[bonuses.Count].y:= y;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   103
    bonuses.ar[bonuses.Count].Radius:= r;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   104
    bonuses.ar[bonuses.Count].Score:= s;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   105
    inc(bonuses.Count);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   106
    TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   107
    end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   108
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   109
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   110
bonuses.Count:= 0;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   111
MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   112
Gear:= GearsList;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   113
while Gear <> nil do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   114
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   115
      case Gear.Kind of
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   116
           gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25);
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   117
           gtMine: if (Gear.State and gstAttacking) = 0 then AddBonus(round(Gear.X), round(Gear.Y), 50, -50)
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   118
                                                        else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   119
           gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75);
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   120
           gtHedgehog: begin
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   121
                       if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 60, -25) else
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   122
                          if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   123
                             if (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 150, -3) // hedgehog-friend
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   124
                                                                                else AddBonus(round(Gear.X), round(Gear.Y), 100, 3)
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   125
                       end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   126
           end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   127
      Gear:= Gear.NextGear
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   128
      end;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   129
if isAfterAttack and (KnownExplosion.Radius > 0) then
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   130
   with KnownExplosion do
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   131
        AddBonus(X, Y, Radius + 10, -Radius);
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   132
end;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   133
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   134
procedure AwareOfExplosion(x, y, r: integer);
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   135
begin
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   136
KnownExplosion.X:= x;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   137
KnownExplosion.Y:= y;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   138
KnownExplosion.Radius:= r
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   139
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   140
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   141
function RatePlace(Gear: PGear): integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   142
var i, r: integer;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   143
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   144
Result:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   145
for i:= 0 to Pred(bonuses.Count) do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   146
    with bonuses.ar[i] do
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   147
         begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   148
         r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y)));
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   149
         if r < Radius then
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   150
            inc(Result, Score * (Radius - r))
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   151
         end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   152
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   153
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   154
function TestColl(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   155
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   156
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
   157
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   158
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
   159
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   160
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
   161
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   162
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
   163
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   164
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   165
function RateExplosion(Me: PGear; x, y, r: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   166
var i, dmg: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
begin
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   168
Result:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   169
// add our virtual position
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   170
with Targets.ar[Targets.Count] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   171
     begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   172
     Point.x:= round(Me.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   173
     Point.y:= round(Me.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   174
     Score:= - ThinkingHH.Health
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   175
     end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   176
// rate explosion
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   177
for i:= 0 to Targets.Count do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   178
    with Targets.ar[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   179
         begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   180
         dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y)));
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   181
         if dmg > 0 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   182
            begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   183
            dmg:= dmg shr 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   184
            if dmg > abs(Score) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   185
               if Score > 0 then inc(Result, KillScore)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   186
                            else dec(Result, KillScore * 3)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   187
            else
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   188
               if Score > 0 then inc(Result, dmg)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   189
                            else dec(Result, dmg * 3)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   190
            end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   191
         end;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   192
Result:= Result * 1024
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   193
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   194
79
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   195
function RateShove(Me: PGear; x, y, r, power: integer): integer;
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   196
var i, dmg: integer;
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   197
begin
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   198
Result:= 0;
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   199
for i:= 0 to Targets.Count do
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   200
    with Targets.ar[i] do
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   201
         begin
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   202
         dmg:= r - Round(sqrt(sqr(Point.x - x) + sqr(Point.y - y)));
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   203
         if dmg > 0 then
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   204
            begin
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   205
            if power > abs(Score) then
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   206
               if Score > 0 then inc(Result, KillScore)
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   207
                            else dec(Result, KillScore * 3)
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   208
            else
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   209
               if Score > 0 then inc(Result, power)
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   210
                            else dec(Result, power * 3)
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   211
            end;
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   212
         end;
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   213
Result:= Result * 1024
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   214
end;
29b477319854 - New test map
unc0rr
parents: 75
diff changeset
   215
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   216
function HHJump(Gear: PGear; JumpType: TJumpType; out GoInfo: TGoInfo): boolean;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   217
var bX, bY: integer;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   218
begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   219
Result:= false;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   220
GoInfo.Ticks:= 0;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   221
GoInfo.FallPix:= 0;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   222
GoInfo.JumpType:= jmpNone;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   223
bX:= round(Gear.X);
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   224
bY:= round(Gear.Y);
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   225
case JumpType of
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   226
     jmpNone: exit;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   227
    jmpHJump: if not TestCollisionYwithGear(Gear, -1) then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   228
                 begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   229
                 Gear.dY:= -0.20;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   230
                 Gear.dX:= 0.0000001 * hwSign(Gear.dX);
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   231
                 Gear.X:= Gear.X - hwSign(Gear.dX)*0.00008; // shift compensation
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   232
                 Gear.State:= Gear.State or gstFalling or gstHHJumping;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   233
                 end else exit;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   234
    jmpLJump: begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   235
              if not TestCollisionYwithGear(Gear, -1) then
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   236
                 if not TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   237
                 if not TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   238
              if not (TestCollisionXwithGear(Gear, hwSign(Gear.dX))
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   239
                 or   TestCollisionYwithGear(Gear, -1)) then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   240
                 begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   241
                 Gear.dY:= -0.15;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   242
                 Gear.dX:= hwSign(Gear.dX) * 0.15;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   243
                 Gear.State:= Gear.State or gstFalling or gstHHJumping
82
2f4f3236cccc - New fort
unc0rr
parents: 80
diff changeset
   244
                 end else exit
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   245
              end
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   246
    end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   247
    
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   248
repeat
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   249
if Gear.Y + cHHRadius >= cWaterLine then exit;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   250
if (Gear.State and gstFalling) <> 0 then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   251
   begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   252
   if (GoInfo.Ticks = 350) then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   253
      if (abs(Gear.dX) < 0.0000002) and (Gear.dY < -0.02) then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   254
         begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   255
         Gear.dY:= -0.25;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   256
         Gear.dX:= hwSign(Gear.dX) * 0.02
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   257
         end;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   258
   if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then Gear.dX:= 0.0000001 * hwSign(Gear.dX);
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   259
   Gear.X:= Gear.X + Gear.dX;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   260
   inc(GoInfo.Ticks);
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   261
   Gear.dY:= Gear.dY + cGravity;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   262
   if Gear.dY > 0.40 then exit;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   263
   if (Gear.dY < 0)and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0; 
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   264
   Gear.Y:= Gear.Y + Gear.dY;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   265
   if (Gear.dY >= 0)and TestCollisionYwithGear(Gear, 1) then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   266
      begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   267
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   268
      Gear.dY:= 0;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   269
      case JumpType of
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   270
           jmpHJump: if (bY - Gear.Y > 5) then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   271
                        begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   272
                        Result:= true;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   273
                        GoInfo.JumpType:= jmpHJump;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   274
                        inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   275
                        end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   276
           jmpLJump: if abs(bX - Gear.X) > 30 then
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   277
                        begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   278
                        Result:= true;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   279
                        GoInfo.JumpType:= jmpLJump;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   280
                        inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   281
                        end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   282
           end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   283
      exit
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   284
      end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   285
   end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   286
until false;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   287
end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   288
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   289
function HHGo(Gear, AltGear: PGear; out GoInfo: TGoInfo): boolean;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   290
var pX, pY: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   291
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   292
Result:= false;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   293
AltGear^:= Gear^;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   294
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   295
GoInfo.Ticks:= 0;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   296
GoInfo.FallPix:= 0;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   297
GoInfo.JumpType:= jmpNone;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   298
repeat
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   299
pX:= round(Gear.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   300
pY:= round(Gear.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   301
if pY + cHHRadius >= cWaterLine then exit;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   302
if (Gear.State and gstFalling) <> 0 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   303
   begin
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   304
   inc(GoInfo.Ticks);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   305
   Gear.dY:= Gear.dY + cGravity;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   306
   if Gear.dY > 0.40 then
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   307
      begin
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   308
      Goinfo.FallPix:= 0;
82
2f4f3236cccc - New fort
unc0rr
parents: 80
diff changeset
   309
      HHJump(AltGear, jmpLJump, GoInfo); // try ljump enstead of fall with damage
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   310
      exit
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   311
      end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   312
   Gear.Y:= Gear.Y + Gear.dY;
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   313
   if round(Gear.Y) > pY then inc(GoInfo.FallPix);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   314
   if TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   315
      begin
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   316
      inc(GoInfo.Ticks, 300);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   317
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   318
      Gear.dY:= 0;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   319
      Result:= true;
82
2f4f3236cccc - New fort
unc0rr
parents: 80
diff changeset
   320
      HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   321
      exit
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   322
      end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   323
   continue
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   324
   end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   325
   if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   326
   if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   327
   if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   328
      begin
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   329
      if not (TestCollisionXwithXYShift(Gear, 0, -6, hwSign(Gear.dX))
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   330
         or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   331
      if not (TestCollisionXwithXYShift(Gear, 0, -5, hwSign(Gear.dX))
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   332
         or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   333
      if not (TestCollisionXwithXYShift(Gear, 0, -4, hwSign(Gear.dX))
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   334
         or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   335
      if not (TestCollisionXwithXYShift(Gear, 0, -3, hwSign(Gear.dX))
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   336
         or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   337
      if not (TestCollisionXwithXYShift(Gear, 0, -2, hwSign(Gear.dX))
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   338
         or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   339
      if not (TestCollisionXwithXYShift(Gear, 0, -1, hwSign(Gear.dX))
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   340
         or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   341
      end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   342
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   343
   if not TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   344
      begin
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   345
      Gear.X:= Gear.X + Gear.dX;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   346
      inc(GoInfo.Ticks, cHHStepTicks)
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   347
      end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   348
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   349
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   350
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   351
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   352
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   353
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   354
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   355
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   356
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   357
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   358
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   359
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   360
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   361
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   362
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   363
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   364
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   365
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   366
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   367
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   368
      Gear.Y:= Gear.Y - 6;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   369
      Gear.dY:= 0;
108
08f1fe6f21f8 Small fixes for better FPC compatibility
unc0rr
parents: 100
diff changeset
   370
      Gear.dX:= 0.0000001 * hwSign(Gear.dX);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   371
      Gear.State:= Gear.State or gstFalling
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   372
      end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   373
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   374
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   375
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   376
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   377
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   378
   end;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   379
if (pX <> round(Gear.X)) and ((Gear.State and gstFalling) = 0) then
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   380
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   381
   Result:= true;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   382
   exit
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   383
   end
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   384
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0);
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 79
diff changeset
   385
HHJump(AltGear, jmpHJump, GoInfo)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   386
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   387
136
89970b70b076 Implement bot levels
unc0rr
parents: 108
diff changeset
   388
function rndSign(num: integer): integer;
89970b70b076 Implement bot levels
unc0rr
parents: 108
diff changeset
   389
begin
89970b70b076 Implement bot levels
unc0rr
parents: 108
diff changeset
   390
if random(2) = 0 then Result:=   num
89970b70b076 Implement bot levels
unc0rr
parents: 108
diff changeset
   391
                 else Result:= - num
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 191
diff changeset
   392
end;  }
136
89970b70b076 Implement bot levels
unc0rr
parents: 108
diff changeset
   393
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   394
end.