# HG changeset patch # User Wuzzy # Date 1593099862 -7200 # Node ID 34c32a11203e5c7637c46d16a454a7370a982b68 # Parent e229d0cacd37c7fa1b1f8ff43e65c50f81bc77b6 Teach AI to use laser sight diff -r e229d0cacd37 -r 34c32a11203e ChangeLog.txt --- a/ChangeLog.txt Thu Jun 25 07:15:58 2020 +0200 +++ b/ChangeLog.txt Thu Jun 25 17:44:22 2020 +0200 @@ -6,7 +6,7 @@ + Easier to push hogs around with blowtorch + Backjumps are now a bit easier + Teach computer players how to ... - + - use drill strike, piano strike, air mine, cleaver, seduction + + - use drill strike, piano strike, air mine, cleaver, seduction, laser sight + - use mine strike (0 seconds only) + - use RC plane (very basic) + - drop mines from a cliff diff -r e229d0cacd37 -r 34c32a11203e hedgewars/uAI.pas --- a/hedgewars/uAI.pas Thu Jun 25 07:15:58 2020 +0200 +++ b/hedgewars/uAI.pas Thu Jun 25 17:44:22 2020 +0200 @@ -106,6 +106,7 @@ begin BotLevel:= Me^.Hedgehog^.BotLevel; windSpeed:= hwFloat2Float(cWindSpeed); +aiLaserSighting:= (cLaserSighting) or (HHHasAmmo(Me^.Hedgehog^, amLaserSight) > 0); useThisActions:= false; Me^.AIHints:= Me^.AIHints and (not aihAmmosChanged); @@ -141,16 +142,21 @@ BestActions.Score:= Actions.Score + Score; - // if not between shots, activate invulnerability/vampirism if available + // if not between shots, activate invulnerability/vampirism/etc. if available if CurrentHedgehog^.MultiShootAttacks = 0 then begin + if (not cLaserSighting) and (HHHasAmmo(Me^.Hedgehog^, amLaserSight) > 0) and ((AmmoTests[a].flags and amtest_LaserSight) <> 0) then + begin + AddAction(BestActions, aia_Weapon, Longword(amLaserSight), 80, 0, 0); + AddAction(BestActions, aia_attack, aim_push, 10, 0, 0); + AddAction(BestActions, aia_attack, aim_release, 10, 0, 0); + end; if (HHHasAmmo(Me^.Hedgehog^, amInvulnerable) > 0) and (Me^.Hedgehog^.Effects[heInvulnerable] = 0) then begin AddAction(BestActions, aia_Weapon, Longword(amInvulnerable), 80, 0, 0); AddAction(BestActions, aia_attack, aim_push, 10, 0, 0); AddAction(BestActions, aia_attack, aim_release, 10, 0, 0); end; - if (HHHasAmmo(Me^.Hedgehog^, amExtraDamage) > 0) and (cDamageModifier <> _1_5) then begin AddAction(BestActions, aia_Weapon, Longword(amExtraDamage), 80, 0, 0); diff -r e229d0cacd37 -r 34c32a11203e hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Thu Jun 25 07:15:58 2020 +0200 +++ b/hedgewars/uAIAmmoTests.pas Thu Jun 25 17:44:22 2020 +0200 @@ -26,8 +26,10 @@ amtest_NoTarget = $00000002; // each pos, but no targetting amtest_MultipleAttacks = $00000004; // test could result in multiple attacks, set AttacksNum amtest_NoTrackFall = $00000008; // skip fall tracing. + amtest_LaserSight = $00000010; // supports laser sighting var windSpeed: real; + aiLaserSighting: boolean; type TAttackParams = record Time, Bounce, AttacksNum: Longword; @@ -81,12 +83,12 @@ (proc: @TestClusterBomb; flags: 0), // amClusterBomb (proc: @TestBazooka; flags: 0), // amBazooka (proc: @TestBee; flags: amtest_Rare), // amBee - (proc: @TestShotgun; flags: 0), // amShotgun + (proc: @TestShotgun; flags: amtest_LaserSight), // amShotgun (proc: nil; flags: 0), // amPickHammer (proc: nil; flags: 0), // amSkip (proc: nil; flags: 0), // amRope (proc: @TestMine; flags: amtest_NoTarget), // amMine - (proc: @TestDesertEagle; flags: amtest_MultipleAttacks), // amDEagle + (proc: @TestDesertEagle; flags: amtest_MultipleAttacks or amtest_LaserSight), // amDEagle (proc: @TestDynamite; flags: amtest_NoTarget), // amDynamite (proc: @TestFirePunch; flags: amtest_NoTarget), // amFirePunch (proc: @TestWhip; flags: amtest_NoTarget), // amWhip @@ -100,7 +102,7 @@ //(proc: @TestTeleport; flags: amtest_OnTurn), // amTeleport (proc: nil; flags: 0), // amSwitch (proc: @TestMortar; flags: 0), // amMortar - (proc: @TestKamikaze; flags: 0), // amKamikaze + (proc: @TestKamikaze; flags: amtest_LaserSight), // amKamikaze (proc: @TestCake; flags: amtest_Rare or amtest_NoTarget), // amCake (proc: @TestSeduction; flags: amtest_NoTarget), // amSeduction (proc: @TestWatermelon; flags: 0), // amWatermelon @@ -108,7 +110,7 @@ (proc: nil; flags: 0), // amNapalm (proc: @TestDrillRocket; flags: 0), // amDrill (proc: nil; flags: 0), // amBallgun - (proc: @TestRCPlane; flags: 0), // amRCPlane + (proc: @TestRCPlane; flags: amtest_LaserSight), // amRCPlane (proc: nil; flags: 0), // amLowGravity (proc: nil; flags: 0), // amExtraDamage (proc: nil; flags: 0), // amInvulnerable @@ -134,9 +136,9 @@ (proc: nil; flags: 0), // amIceGun (proc: @TestKnife; flags: 0), // amKnife (proc: nil; flags: 0), // amRubber - (proc: @TestAirMine; flags: 0), // amAirMine + (proc: @TestAirMine; flags: amtest_LaserSight), // amAirMine (proc: nil; flags: 0), // amCreeper - (proc: @TestMinigun; flags: 0) // amMinigun + (proc: @TestMinigun; flags: amtest_LaserSight) // amMinigun ); implementation @@ -487,7 +489,7 @@ exit(BadTurn); // Apply inaccuracy - if (not cLaserSighting) then + if (not aiLaserSighting) then inc(ap.Angle, + AIrndSign(random((Level - 1) * 9))); if (valueResult <= 0) then @@ -976,7 +978,7 @@ Vy:= (Targ.Point.Y - y) * 1 / 1024; ap.Angle:= DxDy2AttackAnglef(Vx, -Vy); // Apply inaccuracy -if (not cLaserSighting) then +if (not aiLaserSighting) then inc(ap.Angle, + AIrndSign(random((Level - 1) * 10))); repeat x:= x + vX; @@ -1033,7 +1035,7 @@ Vy:= (Targ.Point.Y - y) * t; ap.Angle:= DxDy2AttackAnglef(Vx, -Vy); // Apply inaccuracy -if (not cLaserSighting) then +if (not aiLaserSighting) then inc(ap.Angle, + AIrndSign(random((Level - 1) * 10))); d:= 0; @@ -1319,7 +1321,7 @@ ap.Angle:= DxDy2AttackAnglef(dx, -dy); // Apply inaccuracy - if (not cLaserSighting) then + if (not aiLaserSighting) then inc(ap.Angle, + AIrndSign(random((Level - 1) * 10))); end; @@ -2214,7 +2216,7 @@ // Apply inaccuracy inc(ap.Power, (random(93*(Level-1)) - 31*(Level-1))); // Level 1 spread: -124 .. 248 - if (not cLaserSighting) then + if (not aiLaserSighting) then inc(ap.Angle, + AIrndSign(random((Level - 1) * 10))); if (valueResult <= 0) then @@ -2261,7 +2263,7 @@ exit(BadTurn); // Apply inaccuracy -if (not cLaserSighting) then +if (not aiLaserSighting) then inc(ap.Angle, + AIrndSign(random((Level - 1) * 10))); repeat x:= x + vX;