hedgewars/uAI.pas
changeset 6770 7d2c6cdb816a
parent 6748 9d8763deee42
child 6982 8d41d22a291d
equal deleted inserted replaced
6769:44ad49a3a126 6770:7d2c6cdb816a
   197 begin
   197 begin
   198 ticks:= 0; // avoid compiler hint
   198 ticks:= 0; // avoid compiler hint
   199 Stack.Count:= 0;
   199 Stack.Count:= 0;
   200 
   200 
   201 for a:= Low(TAmmoType) to High(TAmmoType) do
   201 for a:= Low(TAmmoType) to High(TAmmoType) do
   202     CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a);
   202     CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and (HHHasAmmo(Me^.Hedgehog^, a) > 0);
   203 
   203 
   204 BotLevel:= Me^.Hedgehog^.BotLevel;
   204 BotLevel:= Me^.Hedgehog^.BotLevel;
   205 
   205 
   206 tmp:= random(2) + 1;
   206 tmp:= random(2) + 1;
   207 Push(0, Actions, Me^, tmp);
   207 Push(0, Actions, Me^, tmp);
   289         end
   289         end
   290 end;
   290 end;
   291 
   291 
   292 function Think(Me: Pointer): ptrint;
   292 function Think(Me: Pointer): ptrint;
   293 var BackMe, WalkMe: TGear;
   293 var BackMe, WalkMe: TGear;
   294     StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
   294     StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i, switchCount: Longword;
   295     switchImmediatelyAvailable, switchAvailable: boolean;
   295     switchImmediatelyAvailable: boolean;
   296     Actions: TActions;
   296     Actions: TActions;
   297 begin
   297 begin
   298 InterlockedIncrement(hasThread);
   298 InterlockedIncrement(hasThread);
   299 StartTicks:= GameTicks;
   299 StartTicks:= GameTicks;
   300 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
   300 currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
   301 itHedgehog:= currHedgehogIndex;
   301 itHedgehog:= currHedgehogIndex;
   302 switchesNum:= 0;
   302 switchesNum:= 0;
   303 
   303 
   304 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
   304 switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
   305 switchAvailable:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch);
   305 switchCount:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch);
   306 
   306 
   307 if (PGear(Me)^.State and gstAttacked) = 0 then
   307 if (PGear(Me)^.State and gstAttacked) = 0 then
   308     if Targets.Count > 0 then
   308     if Targets.Count > 0 then
   309         begin
   309         begin
   310         // iterate over current team hedgehogs
   310         // iterate over current team hedgehogs
   314             Actions.Count:= 0;
   314             Actions.Count:= 0;
   315             Actions.Pos:= 0;
   315             Actions.Pos:= 0;
   316             Actions.Score:= 0;
   316             Actions.Score:= 0;
   317             if switchesNum > 0 then
   317             if switchesNum > 0 then
   318                 begin
   318                 begin
   319                 if not switchImmediatelyAvailable then
   319                 if not switchImmediatelyAvailable  then
   320                     begin
   320                     begin
   321                     // when AI has to use switcher, make it cost smth
   321                     // when AI has to use switcher, make it cost smth unless they have a lot of switches
   322                     Actions.Score:= -20000;
   322                     if (SwitchCount < 10) then Actions.Score:= (-27+SwitchCount*3)*4000;
   323                     AddAction(Actions, aia_Weapon, Longword(amSwitch), 300 + random(200), 0, 0);                    
   323                     AddAction(Actions, aia_Weapon, Longword(amSwitch), 300 + random(200), 0, 0);                    
   324                     AddAction(Actions, aia_attack, aim_push, 300 + random(300), 0, 0);
   324                     AddAction(Actions, aia_attack, aim_push, 300 + random(300), 0, 0);
   325                     AddAction(Actions, aia_attack, aim_release, 1, 0, 0);
   325                     AddAction(Actions, aia_attack, aim_release, 1, 0, 0);
   326                     end;
   326                     end;
   327                 for i:= 1 to switchesNum do
   327                 for i:= 1 to switchesNum do
   334                 itHedgehog:= Succ(itHedgehog) mod CurrentTeam^.HedgehogsNumber;
   334                 itHedgehog:= Succ(itHedgehog) mod CurrentTeam^.HedgehogsNumber;
   335             until (itHedgehog = currHedgehogIndex) or (CurrentTeam^.Hedgehogs[itHedgehog].Gear <> nil);
   335             until (itHedgehog = currHedgehogIndex) or (CurrentTeam^.Hedgehogs[itHedgehog].Gear <> nil);
   336 
   336 
   337 
   337 
   338             inc(switchesNum);
   338             inc(switchesNum);
   339         until (not (switchImmediatelyAvailable or switchAvailable))
   339         until (not (switchImmediatelyAvailable or (switchCount > 0)))
   340             or StopThinking 
   340             or StopThinking 
   341             or (itHedgehog = currHedgehogIndex)
   341             or (itHedgehog = currHedgehogIndex)
   342             or BestActions.isWalkingToABetterPlace;
   342             or BestActions.isWalkingToABetterPlace;
   343 
   343 
   344         if (StartTicks > GameTicks - 1500) and (not StopThinking) then
   344         if (StartTicks > GameTicks - 1500) and (not StopThinking) then