hedgewars/uAIMisc.pas
changeset 7164 fad64b97947e
parent 7161 21a9c70b2070
child 7208 62e36dc45098
equal deleted inserted replaced
7163:7db1e3a7422a 7164:fad64b97947e
   127 else friendlyfactor:= max(30, 300 - f * 80 div max(1,e))
   127 else friendlyfactor:= max(30, 300 - f * 80 div max(1,e))
   128 end;
   128 end;
   129 
   129 
   130 procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt); inline;
   130 procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt); inline;
   131 begin
   131 begin
   132 bonuses.ar[bonuses.Count].x:= x;
   132 if(bonuses.Count < MAXBONUS) then
   133 bonuses.ar[bonuses.Count].y:= y;
   133     begin
   134 bonuses.ar[bonuses.Count].Radius:= r;
   134     bonuses.ar[bonuses.Count].x:= x;
   135 bonuses.ar[bonuses.Count].Score:= s;
   135     bonuses.ar[bonuses.Count].y:= y;
   136 inc(bonuses.Count);
   136     bonuses.ar[bonuses.Count].Radius:= r;
   137 TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true)
   137     bonuses.ar[bonuses.Count].Score:= s;
       
   138     inc(bonuses.Count);
       
   139     end;
   138 end;
   140 end;
   139 
   141 
   140 procedure FillBonuses(isAfterAttack: boolean);
   142 procedure FillBonuses(isAfterAttack: boolean);
   141 var Gear: PGear;
   143 var Gear: PGear;
   142     MyClan: PClan;
   144     MyClan: PClan;
   160                 else if (Gear^.State and gstAttacking) <> 0 then
   162                 else if (Gear^.State and gstAttacking) <> 0 then
   161                     AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
   163                     AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
   162                     
   164                     
   163             gtExplosives:
   165             gtExplosives:
   164             if isAfterAttack then
   166             if isAfterAttack then
   165                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health);
   167                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60 + Gear^.Health);
   166                 
   168                 
   167             gtSMine:
   169             gtSMine:
   168                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30);
   170                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30);
   169                 
   171                 
   170             gtDynamite:
   172             gtDynamite:
   208     with bonuses.ar[i] do
   210     with bonuses.ar[i] do
   209         begin
   211         begin
   210         r:= Radius;
   212         r:= Radius;
   211         if abs(gX-X)+abs(gY-Y) < Radius then
   213         if abs(gX-X)+abs(gY-Y) < Radius then
   212             r:= trunc(sqrt(sqr(gX - X)+sqr(gY - Y)));
   214             r:= trunc(sqrt(sqr(gX - X)+sqr(gY - Y)));
   213         if r < 15 then
   215         if r < 20 then
   214                 inc(rate, Score * Radius)
   216                 inc(rate, Score * Radius)
   215         else if r < Radius then
   217         else if r < Radius then
   216                 inc(rate, Score * (Radius - r))
   218                 inc(rate, Score * (Radius - r))
   217         end;
   219         end;
   218     RatePlace:= rate;
   220     RatePlace:= rate;
   610 AltGear^:= Gear^;
   612 AltGear^:= Gear^;
   611 
   613 
   612 GoInfo.Ticks:= 0;
   614 GoInfo.Ticks:= 0;
   613 GoInfo.FallPix:= 0;
   615 GoInfo.FallPix:= 0;
   614 GoInfo.JumpType:= jmpNone;
   616 GoInfo.JumpType:= jmpNone;
       
   617 
   615 repeat
   618 repeat
   616 pX:= hwRound(Gear^.X);
   619     pX:= hwRound(Gear^.X);
   617 pY:= hwRound(Gear^.Y);
   620     pY:= hwRound(Gear^.Y);
   618 if pY + cHHRadius >= cWaterLine then
   621     if pY + cHHRadius >= cWaterLine then
   619     exit(false);
   622         exit(false);
   620 if (Gear^.State and gstMoving) <> 0 then
   623         
   621     begin
   624     // hog is falling    
   622     inc(GoInfo.Ticks);
   625     if (Gear^.State and gstMoving) <> 0 then
   623     Gear^.dY:= Gear^.dY + cGravity;
   626         begin
   624     if Gear^.dY > _0_4 then
   627         inc(GoInfo.Ticks);
   625         begin
   628         Gear^.dY:= Gear^.dY + cGravity;
   626         Goinfo.FallPix:= 0;
   629         if Gear^.dY > _0_4 then
   627         HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage
   630             begin
   628         exit(false)
   631             Goinfo.FallPix:= 0;
   629         end;
   632             // try ljump instead of fall with damage
   630     Gear^.Y:= Gear^.Y + Gear^.dY;
   633             HHJump(AltGear, jmpLJump, GoInfo); 
   631     if hwRound(Gear^.Y) > pY then
   634             exit(false)
   632         inc(GoInfo.FallPix);
   635             end;
   633     if TestCollisionYwithGear(Gear, 1) <> 0 then
   636         Gear^.Y:= Gear^.Y + Gear^.dY;
   634         begin
   637         if hwRound(Gear^.Y) > pY then
   635         inc(GoInfo.Ticks, 410);
   638             inc(GoInfo.FallPix);
   636         Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
   639         if TestCollisionYwithGear(Gear, 1) <> 0 then
   637         Gear^.dY:= _0;
   640             begin
   638         HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
   641             inc(GoInfo.Ticks, 410);
   639         HHGo:= true;
   642             Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
   640         exit(false)
   643             Gear^.dY:= _0;
   641         end;
   644             // try ljump instead of fall
   642     continue
   645             HHJump(AltGear, jmpLJump, GoInfo);
   643     end;
   646             exit(true)
   644     if (Gear^.Message and gmLeft  )<>0 then
   647             end;
   645         Gear^.dX:= -cLittle
   648         continue
   646     else
   649         end;
   647         if (Gear^.Message and gmRight )<>0 then
   650         
   648             Gear^.dX:=  cLittle
   651         // usual walk
       
   652         if (Gear^.Message and gmLeft) <> 0 then
       
   653             Gear^.dX:= -cLittle
   649         else
   654         else
   650             exit(false);
   655             if (Gear^.Message and gmRight) <> 0 then
   651     if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   656                 Gear^.dX:=  cLittle
   652         begin
   657             else
   653         if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
   658                 exit(false);
   654         or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   659                 
       
   660         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then if (TestCollisionYwithGear(Gear, -1) = 0) then
       
   661             begin
   655             Gear^.Y:= Gear^.Y - _1;
   662             Gear^.Y:= Gear^.Y - _1;
       
   663         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then if (TestCollisionYwithGear(Gear, -1) = 0) then
       
   664             begin
       
   665             Gear^.Y:= Gear^.Y - _1;
       
   666         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then if (TestCollisionYwithGear(Gear, -1) = 0) then
       
   667             begin
       
   668             Gear^.Y:= Gear^.Y - _1;
       
   669         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then if (TestCollisionYwithGear(Gear, -1) = 0) then
       
   670             begin
       
   671             Gear^.Y:= Gear^.Y - _1;
       
   672         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then if (TestCollisionYwithGear(Gear, -1) = 0) then
       
   673             begin
       
   674             Gear^.Y:= Gear^.Y - _1;
       
   675         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then if (TestCollisionYwithGear(Gear, -1) = 0) then
       
   676             begin
       
   677             Gear^.Y:= Gear^.Y - _1;
       
   678             if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
       
   679                 Gear^.Y:= Gear^.Y + _6
       
   680             end else Gear^.Y:= Gear^.Y + _5 else
       
   681             end else Gear^.Y:= Gear^.Y + _4 else
       
   682             end else Gear^.Y:= Gear^.Y + _3 else
       
   683             end else Gear^.Y:= Gear^.Y + _2 else
       
   684             end else Gear^.Y:= Gear^.Y + _1
       
   685             end;
       
   686 
       
   687         if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
       
   688         begin
       
   689             Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX));
       
   690             inc(GoInfo.Ticks, cHHStepTicks)
       
   691         end;
       
   692 
       
   693         // too scared to reformat this part
       
   694         if TestCollisionYwithGear(Gear, 1) = 0 then
       
   695             begin
       
   696             Gear^.Y:= Gear^.Y + _1;
   656             
   697             
   657         if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
   698         if TestCollisionYwithGear(Gear, 1) = 0 then
   658         or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   699             begin
   659             Gear^.Y:= Gear^.Y - _1;
   700             Gear^.Y:= Gear^.Y + _1;
   660             
   701             
   661         if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX))
   702         if TestCollisionYwithGear(Gear, 1) = 0 then
   662         or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   703             begin
   663             Gear^.Y:= Gear^.Y - _1;
   704             Gear^.Y:= Gear^.Y + _1;
   664             
   705 
   665         if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
   706         if TestCollisionYwithGear(Gear, 1) = 0 then
   666         or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   707             begin
   667             Gear^.Y:= Gear^.Y - _1;
   708             Gear^.Y:= Gear^.Y + _1;
   668         if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
   709 
   669         or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   710         if TestCollisionYwithGear(Gear, 1) = 0 then
   670             Gear^.Y:= Gear^.Y - _1;
   711             begin
   671             
   712             Gear^.Y:= Gear^.Y + _1;
   672         if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
   713 
   673         or (TestCollisionYwithGear(Gear, -1) <> 0)) then
   714         if TestCollisionYwithGear(Gear, 1) = 0 then
   674             Gear^.Y:= Gear^.Y - _1;
   715             begin
   675         end;
   716             Gear^.Y:= Gear^.Y + _1;
   676 
   717 
   677     if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
   718         if TestCollisionYwithGear(Gear, 1) = 0 then
   678     begin
   719             begin
   679         Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX));
   720             Gear^.Y:= Gear^.Y - _6;
   680         inc(GoInfo.Ticks, cHHStepTicks)
   721             Gear^.dY:= _0;
   681     end;
   722             Gear^.State:= Gear^.State or gstMoving
   682 
   723             end
   683     // too scared to reformat this part
       
   684     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   685         begin
       
   686         Gear^.Y:= Gear^.Y + _1;
       
   687         
       
   688     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   689         begin
       
   690         Gear^.Y:= Gear^.Y + _1;
       
   691         
       
   692     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   693         begin
       
   694         Gear^.Y:= Gear^.Y + _1;
       
   695 
       
   696     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   697         begin
       
   698         Gear^.Y:= Gear^.Y + _1;
       
   699 
       
   700     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   701         begin
       
   702         Gear^.Y:= Gear^.Y + _1;
       
   703 
       
   704     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   705         begin
       
   706         Gear^.Y:= Gear^.Y + _1;
       
   707 
       
   708     if TestCollisionYwithGear(Gear, 1) = 0 then
       
   709         begin
       
   710         Gear^.Y:= Gear^.Y - _6;
       
   711         Gear^.dY:= _0;
       
   712         Gear^.State:= Gear^.State or gstMoving
       
   713         end
   724         end
   714     end
   725         end
   715     end
   726         end
   716     end
   727         end
   717     end
   728         end
   718     end
   729         end;
   719     end;
   730         // we have moved for 1 px
   720 if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
   731         if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
   721     exit(true)
   732             exit(true)
   722 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
   733 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
       
   734 
   723 HHJump(AltGear, jmpHJump, GoInfo);
   735 HHJump(AltGear, jmpHJump, GoInfo);
   724 end;
   736 end;
   725 
   737 
   726 function AIrndSign(num: LongInt): LongInt;
   738 function AIrndSign(num: LongInt): LongInt;
   727 begin
   739 begin