hedgewars/uAIMisc.pas
author unc0rr
Tue, 20 Jun 2006 21:18:49 +0000
changeset 66 9643d75baf1e
parent 64 9df467527ae5
child 70 82d93eeecebe
permissions -rw-r--r--
Many AI improvements, bots do think in separate thread
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
unit uAIMisc;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     2
interface
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
     3
uses SDLh, uConsts, uGears;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     5
type TTarget = record
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     6
               Point: TPoint;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     7
               Score: integer;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     8
               end;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
     9
     TTargets = record
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    10
                Count: Longword;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    11
                ar: array[0..cMaxHHIndex*5] of TTarget;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    12
                end;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    13
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    14
procedure FillTargets;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    15
procedure FillBonuses;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    16
function CheckBonuses(Gear: PGear): integer;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    17
function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
function TestColl(x, y, r: integer): boolean;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    19
function RateExplosion(Me: PGear; x, y, r: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    20
function HHGo(Gear: PGear): boolean;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    21
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    22
var ThinkingHH: PGear;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    23
    Targets: TTargets;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    24
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
implementation
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    26
uses uTeams, uMisc, uLand, uCollisions;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    27
const KillScore = 200;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    28
      MAXBONUS = 1024;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    29
      
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    30
type TBonus = record
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    31
              X, Y: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    32
              Radius: Longword;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    33
              Score: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    34
              end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    35
var bonuses: record
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    36
             Count: Longword;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    37
             ar: array[0..Pred(MAXBONUS)] of TBonus;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    38
             end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    39
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    40
procedure FillTargets;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    41
var t: PTeam;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    42
    i: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    43
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    44
Targets.Count:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    45
t:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    46
while t <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    47
      begin
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    48
      for i:= 0 to cMaxHHIndex do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    49
          if (t.Hedgehogs[i].Gear <> nil)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    50
             and (t.Hedgehogs[i].Gear <> ThinkingHH) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    51
             begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    52
             with Targets.ar[Targets.Count], t.Hedgehogs[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    53
                  begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    54
                  Point.X:= Round(Gear.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    55
                  Point.Y:= Round(Gear.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    56
                  if t <> CurrentTeam then Score:=  Gear.Health
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    57
                                      else Score:= -Gear.Health
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    58
                  end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    59
             inc(Targets.Count)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    60
             end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
      t:= t.Next
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    62
      end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    65
procedure FillBonuses;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    66
var Gear: PGear;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    67
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    68
    procedure AddBonus(x, y: integer; r: Longword; s: integer);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    69
    begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    70
    bonuses.ar[bonuses.Count].x:= x;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    71
    bonuses.ar[bonuses.Count].y:= y;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    72
    bonuses.ar[bonuses.Count].Radius:= r;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    73
    bonuses.ar[bonuses.Count].Score:= s;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    74
    inc(bonuses.Count);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    75
    TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    76
    end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    77
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    78
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    79
bonuses.Count:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    80
Gear:= GearsList;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    81
while Gear <> nil do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    82
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    83
      case Gear.Kind of
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    84
           gtCase: AddBonus(round(Gear.X), round(Gear.Y), 32, 25);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    85
           gtMine: AddBonus(round(Gear.X), round(Gear.Y), 45, -50);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    86
           gtAmmo_Bomb: AddBonus(round(Gear.X), round(Gear.Y), 50, -100);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    87
           gtHedgehog: if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 50, -25);
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
      Gear:= Gear.NextGear
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    90
      end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    91
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    92
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    93
function CheckBonuses(Gear: PGear): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    94
var i: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    95
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    96
Result:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    97
for i:= 0 to Pred(bonuses.Count) do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    98
    with bonuses.ar[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    99
         if sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y)) <= Radius then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   100
            inc(Result, Score) 
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   101
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   102
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
   103
function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   104
const piDIVMaxAngle: Extended = pi/cMaxAngle;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   105
asm
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   106
        fld     _dY
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   107
        fld     _dX
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   108
        fpatan
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   109
        fld     piDIVMaxAngle
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   110
        fdiv
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   111
        sub     esp, 4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   112
        fistp   dword ptr [esp]
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   113
        pop     eax
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   114
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   115
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   116
function TestColl(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   117
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   118
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
   119
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   120
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
   121
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   122
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
   123
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   124
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
   125
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   126
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   127
function RateExplosion(Me: PGear; x, y, r: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   128
var i, dmg: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   129
begin
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   130
Result:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   131
// add our virtual position
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   132
with Targets.ar[Targets.Count] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   133
     begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   134
     Point.x:= round(Me.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   135
     Point.y:= round(Me.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   136
     Score:= - ThinkingHH.Health
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   137
     end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   138
// rate explosion
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   139
for i:= 0 to Targets.Count do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   140
    with Targets.ar[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   141
         begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   142
         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
   143
         if dmg > 0 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   144
            begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   145
            dmg:= dmg shr 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   146
            if dmg > abs(Score) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   147
               if Score > 0 then inc(Result, KillScore)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   148
                            else dec(Result, KillScore * 3)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   149
            else
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   150
               if Score > 0 then inc(Result, dmg)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   151
                            else dec(Result, dmg * 3)
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
         end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   154
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   155
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   156
function HHGo(Gear: PGear): boolean;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   157
var pX, pY: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   158
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   159
Result:= false;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   160
repeat
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   161
pX:= round(Gear.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   162
pY:= round(Gear.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   163
if pY + cHHRadius >= cWaterLine then exit;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   164
if (Gear.State and gstFalling) <> 0 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   165
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   166
   Gear.dY:= Gear.dY + cGravity;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   167
   if Gear.dY > 0.35 then exit;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   168
   Gear.Y:= Gear.Y + Gear.dY;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   169
   if TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   170
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   171
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   172
      Gear.dY:= 0
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   173
      end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   174
   continue
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
   {if ((Gear.Message and gm_LJump )<>0) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   177
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   178
      Gear.Message:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   179
      if not HHTestCollisionYwithGear(Gear, -1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   180
         if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 2 else
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   181
         if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then Gear.Y:= Gear.Y - 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   182
      if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   183
         or   HHTestCollisionYwithGear(Gear, -1)) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   184
         begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   185
         Gear.dY:= -0.15;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   186
         Gear.dX:= Sign(Gear.dX) * 0.15;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   187
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   188
         exit
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   189
         end;
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
   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
   192
   if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   193
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   194
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   195
      if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   196
         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
   197
      if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   198
         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
   199
      if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   200
         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
   201
      if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   202
         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
   203
      if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   204
         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
   205
      if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   206
         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
   207
      end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   208
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   209
   if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then Gear.X:= Gear.X + Gear.dX;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   210
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   211
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   212
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   213
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   214
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   215
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   216
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   217
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   218
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   219
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   220
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   221
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   222
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   223
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   224
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   225
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   226
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   227
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   228
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   229
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   230
      Gear.Y:= Gear.Y - 6;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   231
      Gear.dY:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   232
      Gear.dX:= 0.0000001 * Sign(Gear.dX);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   233
      Gear.State:= Gear.State or gstFalling
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   234
      end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   235
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   236
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   237
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   238
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   239
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   240
   end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   241
if (pX <> round(Gear.X))and ((Gear.State and gstFalling) = 0) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   242
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   243
   Result:= true;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   244
   exit
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   245
   end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   246
until (pX = round(Gear.X)) and (pY = round(Gear.Y)) and ((Gear.State and gstFalling) = 0);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   247
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   248
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   249
end.