hedgewars/uAI.pas
changeset 10015 4feced261c68
parent 9998 736015b847e3
parent 9950 2759212a27de
child 10084 83156a03e574
equal deleted inserted replaced
10014:56d2f2d5aad8 10015:4feced261c68
   357 
   357 
   358                 end;
   358                 end;
   359 
   359 
   360             if GoInfo.FallPix >= FallPixForBranching then
   360             if GoInfo.FallPix >= FallPixForBranching then
   361                 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
   361                 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
       
   362 
       
   363             if (StartTicks > GameTicks - 1500) and (not StopThinking) then
       
   364                 SDL_Delay(1000);
       
   365 
   362             end {while};
   366             end {while};
   363 
   367 
   364         if BestRate > BaseRate then
   368         if BestRate > BaseRate then
   365             exit
   369             exit
   366         end {while}
   370         end {while}
   368 end;
   372 end;
   369 
   373 
   370 function Think(Me: PGear): LongInt; cdecl; export;
   374 function Think(Me: PGear): LongInt; cdecl; export;
   371 var BackMe, WalkMe: TGear;
   375 var BackMe, WalkMe: TGear;
   372     switchCount: LongInt;
   376     switchCount: LongInt;
   373     StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
   377     currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
   374     switchImmediatelyAvailable: boolean;
   378     switchImmediatelyAvailable: boolean;
   375     Actions: TActions;
   379     Actions: TActions;
   376 begin
   380 begin
   377 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   381 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   378 StartTicks:= GameTicks;
   382 StartTicks:= GameTicks;
       
   383 
   379 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
   384 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
   380 itHedgehog:= currHedgehogIndex;
   385 itHedgehog:= currHedgehogIndex;
   381 switchesNum:= 0;
   386 switchesNum:= 0;
   382 
   387 
   383 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
   388 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
   395             Actions.Count:= 0;
   400             Actions.Count:= 0;
   396             Actions.Pos:= 0;
   401             Actions.Pos:= 0;
   397             Actions.Score:= 0;
   402             Actions.Score:= 0;
   398             if switchesNum > 0 then
   403             if switchesNum > 0 then
   399                 begin
   404                 begin
   400                 if not switchImmediatelyAvailable  then
   405                 if (not switchImmediatelyAvailable)  then
   401                     begin
   406                     begin
   402                     // when AI has to use switcher, make it cost smth unless they have a lot of switches
   407                     // when AI has to use switcher, make it cost smth unless they have a lot of switches
   403                     if (switchCount < 10) then Actions.Score:= (-27+switchCount*3)*4000;
   408                     if (switchCount < 10) then Actions.Score:= (-27+switchCount*3)*4000;
   404                     AddAction(Actions, aia_Weapon, Longword(amSwitch), 300 + random(200), 0, 0);
   409                     AddAction(Actions, aia_Weapon, Longword(amSwitch), 300 + random(200), 0, 0);
   405                     AddAction(Actions, aia_attack, aim_push, 300 + random(300), 0, 0);
   410                     AddAction(Actions, aia_attack, aim_push, 300 + random(300), 0, 0);
   419         until (not (switchImmediatelyAvailable or (switchCount > 0)))
   424         until (not (switchImmediatelyAvailable or (switchCount > 0)))
   420             or StopThinking
   425             or StopThinking
   421             or (itHedgehog = currHedgehogIndex)
   426             or (itHedgehog = currHedgehogIndex)
   422             or BestActions.isWalkingToABetterPlace;
   427             or BestActions.isWalkingToABetterPlace;
   423 
   428 
   424         if (StartTicks > GameTicks - 1500) and (not StopThinking) then
   429             if (StartTicks > GameTicks - 1500) and (not StopThinking) then
   425             SDL_Delay(1000);
   430                 SDL_Delay(1000);
   426 
   431 
   427         if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then
   432         if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then
   428             begin
   433             begin
   429             BestActions.Count:= 0;
   434             BestActions.Count:= 0;
   430             AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
   435             AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
   435     begin
   440     begin
   436     BackMe:= Me^;
   441     BackMe:= Me^;
   437     i:= 12;
   442     i:= 12;
   438     while (not StopThinking) and (BestActions.Count = 0) and (i > 0) do
   443     while (not StopThinking) and (BestActions.Count = 0) and (i > 0) do
   439         begin
   444         begin
       
   445 
   440 (*
   446 (*
   441         // Maybe this would get a bit of movement out of them? Hopefully not *toward* water. Need to check how often he'd choose that strategy
   447         // Maybe this would get a bit of movement out of them? Hopefully not *toward* water. Need to check how often he'd choose that strategy
   442         if SuddenDeathDmg and ((hwRound(BackMe.Y)+cWaterRise*2) > cWaterLine) then
   448         if SuddenDeathDmg and ((hwRound(BackMe.Y)+cWaterRise*2) > cWaterLine) then
   443             AddBonus(hwRound(BackMe.X), hwRound(BackMe.Y), 250, -40);
   449             AddBonus(hwRound(BackMe.X), hwRound(BackMe.Y), 250, -40);
   444 *)
   450 *)
       
   451 
   445         FillBonuses(true);
   452         FillBonuses(true);
   446         WalkMe:= BackMe;
   453         WalkMe:= BackMe;
   447         Actions.Count:= 0;
   454         Actions.Count:= 0;
   448         Actions.Pos:= 0;
   455         Actions.Pos:= 0;
   449         Actions.Score:= 0;
   456         Actions.Score:= 0;