hedgewars/uAIMisc.pas
changeset 71 5f56c6979496
parent 70 82d93eeecebe
child 74 42257fee61ae
equal deleted inserted replaced
70:82d93eeecebe 71:5f56c6979496
       
     1 (*
       
     2  * Hedgewars, a worms-like game
       
     3  * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * Distributed under the terms of the BSD-modified licence:
       
     6  *
       
     7  * Permission is hereby granted, free of charge, to any person obtaining a copy
       
     8  * of this software and associated documentation files (the "Software"), to deal
       
     9  * with the Software without restriction, including without limitation the
       
    10  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
       
    11  * sell copies of the Software, and to permit persons to whom the Software is
       
    12  * furnished to do so, subject to the following conditions:
       
    13  *
       
    14  * 1. Redistributions of source code must retain the above copyright notice,
       
    15  *    this list of conditions and the following disclaimer.
       
    16  * 2. Redistributions in binary form must reproduce the above copyright notice,
       
    17  *    this list of conditions and the following disclaimer in the documentation
       
    18  *    and/or other materials provided with the distribution.
       
    19  * 3. The name of the author may not be used to endorse or promote products
       
    20  *    derived from this software without specific prior written permission.
       
    21  *
       
    22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
       
    23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
       
    24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
       
    25  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
       
    28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
       
    29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
       
    30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
       
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    32  *)
       
    33 
     1 unit uAIMisc;
    34 unit uAIMisc;
     2 interface
    35 interface
     3 uses SDLh, uConsts, uGears;
    36 uses SDLh, uConsts, uGears;
     4 
    37 
     5 type TTarget = record
    38 type TTarget = record
    11                 ar: array[0..cMaxHHIndex*5] of TTarget;
    44                 ar: array[0..cMaxHHIndex*5] of TTarget;
    12                 end;
    45                 end;
    13 
    46 
    14 procedure FillTargets;
    47 procedure FillTargets;
    15 procedure FillBonuses(isAfterAttack: boolean);
    48 procedure FillBonuses(isAfterAttack: boolean);
       
    49 procedure AwareOfExplosion(x, y, r: integer);
    16 function RatePlace(Gear: PGear): integer;
    50 function RatePlace(Gear: PGear): integer;
    17 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
    51 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
    18 function TestColl(x, y, r: integer): boolean;
    52 function TestColl(x, y, r: integer): boolean;
    19 function RateExplosion(Me: PGear; x, y, r: integer): integer;
    53 function RateExplosion(Me: PGear; x, y, r: integer): integer;
    20 function HHGo(Gear: PGear): boolean;
    54 function HHGo(Gear: PGear): boolean;
    34               end;
    68               end;
    35 var bonuses: record
    69 var bonuses: record
    36              Count: Longword;
    70              Count: Longword;
    37              ar: array[0..Pred(MAXBONUS)] of TBonus;
    71              ar: array[0..Pred(MAXBONUS)] of TBonus;
    38              end;
    72              end;
       
    73     KnownExplosion: record
       
    74                     X, Y, Radius: integer
       
    75                     end = (X: 0; Y: 0; Radius: 0);
    39 
    76 
    40 procedure FillTargets;
    77 procedure FillTargets;
    41 var t: PTeam;
    78 var t: PTeam;
    42     i: Longword;
    79     i: Longword;
    43 begin
    80 begin
    92                           and (ThinkingHH.Hedgehog <> Gear.Hedgehog)
   129                           and (ThinkingHH.Hedgehog <> Gear.Hedgehog)
    93                           and (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 100, -1);
   130                           and (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 100, -1);
    94                        end;
   131                        end;
    95            end;
   132            end;
    96       Gear:= Gear.NextGear
   133       Gear:= Gear.NextGear
    97       end
   134       end;
       
   135 if isAfterAttack and (KnownExplosion.Radius > 0) then
       
   136    with KnownExplosion do
       
   137         begin
       
   138         AddBonus(X, Y, Radius, -Radius);
       
   139         Radius:= 0
       
   140         end
       
   141 end;
       
   142 
       
   143 procedure AwareOfExplosion(x, y, r: integer);
       
   144 begin
       
   145 KnownExplosion.X:= x;
       
   146 KnownExplosion.Y:= y;
       
   147 KnownExplosion.Radius:= r
    98 end;
   148 end;
    99 
   149 
   100 function RatePlace(Gear: PGear): integer;
   150 function RatePlace(Gear: PGear): integer;
   101 var i, r: integer;
   151 var i, r: integer;
   102 begin
   152 begin
   173 pY:= round(Gear.Y);
   223 pY:= round(Gear.Y);
   174 if pY + cHHRadius >= cWaterLine then exit;
   224 if pY + cHHRadius >= cWaterLine then exit;
   175 if (Gear.State and gstFalling) <> 0 then
   225 if (Gear.State and gstFalling) <> 0 then
   176    begin
   226    begin
   177    Gear.dY:= Gear.dY + cGravity;
   227    Gear.dY:= Gear.dY + cGravity;
   178    if Gear.dY > 0.35 then exit;
   228    if Gear.dY > 0.40 then exit;
   179    Gear.Y:= Gear.Y + Gear.dY;
   229    Gear.Y:= Gear.Y + Gear.dY;
   180    if TestCollisionYwithGear(Gear, 1) then
   230    if TestCollisionYwithGear(Gear, 1) then
   181       begin
   231       begin
   182       Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   232       Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   183       Gear.dY:= 0
   233       Gear.dY:= 0