hedgewars/uAIMisc.pas
author unc0rr
Wed, 12 Jul 2006 15:39:58 +0000
changeset 78 66bb79dd248d
parent 75 d2b737858ff7
child 79 29b477319854
permissions -rw-r--r--
Cluster bomb
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
 *
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     6
 *
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     9
 * with the Software without restriction, including without limitation the
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    12
 * furnished to do so, subject to the following conditions:
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    13
 *
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    15
 *    this list of conditions and the following disclaimer.
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    18
 *    and/or other materials provided with the distribution.
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    20
 *    derived from this software without specific prior written permission.
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    21
 *
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    32
 *)
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    33
4
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
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    36
uses SDLh, uConsts, uGears;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    37
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    38
type TTarget = record
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    39
               Point: TPoint;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    40
               Score: integer;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    41
               end;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    42
     TTargets = record
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    43
                Count: Longword;
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    44
                ar: array[0..cMaxHHIndex*5] of TTarget;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    45
                end;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    46
     TGoInfo = record
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    47
               Ticks: Longword;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    48
               FallTicks: Longword;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    49
               end;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    50
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    51
procedure FillTargets;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    52
procedure FillBonuses(isAfterAttack: boolean);
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    53
procedure AwareOfExplosion(x, y, r: integer);
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    54
function RatePlace(Gear: PGear): integer;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    55
function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
function TestColl(x, y, r: integer): boolean;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    57
function RateExplosion(Me: PGear; x, y, r: integer): integer;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
    58
function HHGo(Gear: PGear; out GoInfo: TGoInfo): boolean;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    59
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    60
var ThinkingHH: PGear;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    61
    Targets: TTargets;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    62
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    63
implementation
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    64
uses uTeams, uMisc, uLand, uCollisions;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    65
const KillScore = 200;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    66
      MAXBONUS = 1024;
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
type TBonus = record
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    69
              X, Y: integer;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
    70
              Radius: integer;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    71
              Score: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    72
              end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    73
var bonuses: record
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    74
             Count: Longword;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    75
             ar: array[0..Pred(MAXBONUS)] of TBonus;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    76
             end;
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    77
    KnownExplosion: record
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    78
                    X, Y, Radius: integer
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    79
                    end = (X: 0; Y: 0; Radius: 0);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    80
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    81
procedure FillTargets;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    82
var t: PTeam;
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
    83
    i: Longword;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    84
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    85
Targets.Count:= 0;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    86
t:= TeamsList;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    87
while t <> nil do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    88
      begin
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    89
      for i:= 0 to cMaxHHIndex do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    90
          if (t.Hedgehogs[i].Gear <> nil)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    91
             and (t.Hedgehogs[i].Gear <> ThinkingHH) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    92
             begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    93
             with Targets.ar[Targets.Count], t.Hedgehogs[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    94
                  begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    95
                  Point.X:= Round(Gear.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    96
                  Point.Y:= Round(Gear.Y);
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
    97
                  if t.Color <> CurrentTeam.Color then Score:=  Gear.Health
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
    98
                                                  else Score:= -Gear.Health
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
    99
                  end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   100
             inc(Targets.Count)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   101
             end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   102
      t:= t.Next
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
   103
      end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   104
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   105
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   106
procedure FillBonuses(isAfterAttack: boolean);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   107
var Gear: PGear;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   108
    MyColor: Longword;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   109
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   110
    procedure AddBonus(x, y: integer; r: Longword; s: integer);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   111
    begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   112
    bonuses.ar[bonuses.Count].x:= x;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   113
    bonuses.ar[bonuses.Count].y:= y;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   114
    bonuses.ar[bonuses.Count].Radius:= r;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   115
    bonuses.ar[bonuses.Count].Score:= s;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   116
    inc(bonuses.Count);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   117
    TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   118
    end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   119
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   120
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   121
bonuses.Count:= 0;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   122
MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   123
Gear:= GearsList;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   124
while Gear <> nil do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   125
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   126
      case Gear.Kind of
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   127
           gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25);
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   128
           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
   129
                                                        else AddBonus(round(Gear.X), round(Gear.Y), 100, -50); // mine is on
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   130
           gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75);
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   131
           gtHedgehog: begin
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   132
                       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
   133
                          if isAfterAttack and (ThinkingHH.Hedgehog <> Gear.Hedgehog) then
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   134
                             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
   135
                                                                                else AddBonus(round(Gear.X), round(Gear.Y), 100, 3)
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   136
                       end;
66
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
      Gear:= Gear.NextGear
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   139
      end;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   140
if isAfterAttack and (KnownExplosion.Radius > 0) then
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   141
   with KnownExplosion do
74
42257fee61ae - Unicode support for team and hedgehogs names
unc0rr
parents: 71
diff changeset
   142
        AddBonus(X, Y, Radius + 10, -Radius);
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   143
end;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   144
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   145
procedure AwareOfExplosion(x, y, r: integer);
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   146
begin
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   147
KnownExplosion.X:= x;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   148
KnownExplosion.Y:= y;
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
   149
KnownExplosion.Radius:= r
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   150
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   151
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   152
function RatePlace(Gear: PGear): integer;
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   153
var i, r: integer;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   154
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   155
Result:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   156
for i:= 0 to Pred(bonuses.Count) do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   157
    with bonuses.ar[i] do
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   158
         begin
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   159
         r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y)));
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   160
         if r < Radius then
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   161
            inc(Result, Score * (Radius - r))
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   162
         end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   163
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   164
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 53
diff changeset
   165
function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   166
const piDIVMaxAngle: Extended = pi/cMaxAngle;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
asm
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   168
        fld     _dY
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   169
        fld     _dX
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   170
        fpatan
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   171
        fld     piDIVMaxAngle
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   172
        fdiv
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   173
        sub     esp, 4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   174
        fistp   dword ptr [esp]
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   175
        pop     eax
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 TestColl(x, y, r: integer): boolean;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   179
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   180
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
   181
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   182
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
   183
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   184
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
   185
if Result then exit;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   186
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
   187
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   188
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   189
function RateExplosion(Me: PGear; x, y, r: integer): integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   190
var i, dmg: integer;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   191
begin
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   192
Result:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   193
// add our virtual position
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   194
with Targets.ar[Targets.Count] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   195
     begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   196
     Point.x:= round(Me.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   197
     Point.y:= round(Me.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   198
     Score:= - ThinkingHH.Health
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   199
     end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   200
// rate explosion
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   201
for i:= 0 to Targets.Count do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   202
    with Targets.ar[i] do
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   203
         begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   204
         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
   205
         if dmg > 0 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   206
            begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   207
            dmg:= dmg shr 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   208
            if dmg > abs(Score) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   209
               if Score > 0 then inc(Result, KillScore)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   210
                            else dec(Result, KillScore * 3)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   211
            else
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   212
               if Score > 0 then inc(Result, dmg)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   213
                            else dec(Result, dmg * 3)
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   214
            end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   215
         end;
70
82d93eeecebe - Many AI improvements
unc0rr
parents: 66
diff changeset
   216
Result:= Result * 1024
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   217
end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   218
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   219
function HHGo(Gear: PGear; out GoInfo: TGoInfo): boolean;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   220
var pX, pY: integer;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   221
begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   222
Result:= false;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   223
GoInfo.Ticks:= 0;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   224
GoInfo.FallTicks:= 0;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   225
repeat
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   226
pX:= round(Gear.X);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   227
pY:= round(Gear.Y);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   228
if pY + cHHRadius >= cWaterLine then exit;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   229
if (Gear.State and gstFalling) <> 0 then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   230
   begin
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   231
   inc(GoInfo.Ticks);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   232
   Gear.dY:= Gear.dY + cGravity;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   233
   if Gear.dY > 0.40 then
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   234
      begin
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   235
      Goinfo.FallTicks:= 0;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   236
      exit
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   237
      end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   238
   Gear.Y:= Gear.Y + Gear.dY;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   239
   if round(Gear.Y) > pY then inc(GoInfo.FallTicks);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   240
   if TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   241
      begin
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   242
      inc(GoInfo.Ticks, 300);
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   243
      Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   244
      Gear.dY:= 0;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   245
      Result:= true;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   246
      exit
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   247
      end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   248
   continue
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   249
   end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   250
   {if ((Gear.Message and gm_LJump )<>0) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   251
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   252
      Gear.Message:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   253
      if not HHTestCollisionYwithGear(Gear, -1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   254
         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
   255
         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
   256
      if not (TestCollisionXwithGear(Gear, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   257
         or   HHTestCollisionYwithGear(Gear, -1)) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   258
         begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   259
         Gear.dY:= -0.15;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   260
         Gear.dX:= Sign(Gear.dX) * 0.15;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   261
         Gear.State:= Gear.State or gstFalling or gstHHJumping;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   262
         exit
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   263
         end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   264
      end;}
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   265
   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
   266
   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
   267
   if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   268
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   269
      if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   270
         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
   271
      if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   272
         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
   273
      if not (TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   274
         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
   275
      if not (TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   276
         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
   277
      if not (TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   278
         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
   279
      if not (TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX))
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   280
         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
   281
      end;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   282
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   283
   if not TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   284
      begin
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   285
      Gear.X:= Gear.X + Gear.dX;
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   286
      inc(GoInfo.Ticks, cHHStepTicks)
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   287
      end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   288
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   289
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   290
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   291
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   292
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   293
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   294
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   295
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   296
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   297
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   298
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   299
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   300
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   301
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   302
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   303
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   304
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   305
   Gear.Y:= Gear.Y + 1;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   306
   if not TestCollisionYwithGear(Gear, 1) then
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   307
      begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   308
      Gear.Y:= Gear.Y - 6;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   309
      Gear.dY:= 0;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   310
      Gear.dX:= 0.0000001 * Sign(Gear.dX);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   311
      Gear.State:= Gear.State or gstFalling
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   312
      end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   313
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   314
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   315
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   316
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   317
   end
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   318
   end;
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   319
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
   320
   begin
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   321
   Result:= true;
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   322
   exit
75
d2b737858ff7 - New First Aid powerup
unc0rr
parents: 74
diff changeset
   323
   end
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   324
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
   325
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   326
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   327
end.