Make bezierGun set target on right click

This commit is contained in:
jgk
2021-05-23 20:32:15 +02:00
parent b337fbdab9
commit 3ae454acf4
7 changed files with 76 additions and 19 deletions
+8
View File
@@ -106,6 +106,14 @@ creaturesNearPoint p w = IM.unions [f b $ f a $ _creaturesZone w | a<-[x-1,x,x+
Just val -> val
_ -> IM.empty
creaturesNearPointI :: Int -> Point2 -> World -> IM.IntMap Creature
creaturesNearPointI n p w = IM.unions [f b $ f a $ _creaturesZone w | a<-[x-n..x+n] , b<-[y-n..y+n]]
where
(x,y) = crZoneOfPoint p
f i m = case IM.lookup i m of
Just val -> val
_ -> IM.empty
cloudsNearPoint :: Point2 -> World -> IM.IntMap Cloud
cloudsNearPoint p w = IM.unions [f b $ f a $ _cloudsZone w | a<-[x-1,x,x+1] , b<-[y-1,y,y+1]]
where
+31 -2
View File
@@ -1,5 +1,8 @@
module Dodge.Creature.ArmourChase
( armourChaseCrit
)
where
import Dodge.Base
import Dodge.Data
import Dodge.Default
import Dodge.Creature.State
@@ -7,12 +10,14 @@ import Dodge.Creature.State.Data
import Dodge.Creature.Rationality
import Dodge.Creature.ReaderUpdate
import Dodge.Creature.AlertLevel
import Dodge.Creature.ChooseTarget
import Dodge.Creature.Picture
import Dodge.Item.Equipment
import Dodge.Item.Consumable
import Picture
import Geometry
import Data.Maybe
import Data.List
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Control.Monad.Reader
@@ -23,9 +28,10 @@ armourChaseCrit = defaultCreature
watchUpdateStratR [] >=>
doStrategyActionsR >=>
performActionsR >=>
chaseTargetR targetYouLOS >=>
chaseTargetR (const . _crTarget) >=>
basicPerceptionUpdateR [0] >=>
targetYouWhenCognizantR >=>
flockACCR >=>
overrideMeleeCloseTargetR >=>
return . (crMeleeCooldown . _Just %~ max 0 . subtract 1)
, _crHP = 300
@@ -37,3 +43,26 @@ armourChaseCrit = defaultCreature
, _crMeleeCooldown = Just 0
, _crGroup = ShieldGroup
}
flockACCR :: Creature -> Reader World Creature
flockACCR = reader . flockACC
flockACC :: Creature -> World -> Creature
flockACC cr w = fromMaybe cr $ mFlockACC cr w
mFlockACC :: Creature -> World -> Maybe Creature
mFlockACC cr w = do
tcr <- _crTarget cr
let tpos = _crPos tcr
cpos = _crPos cr
isFarACC cr' = _crGroup cr' == ShieldGroup && _crID cr' /= _crID cr
&& dist (_crPos cr') tpos > dist cpos tpos
-- && circOnSeg (_crPos cr') tpos cpos (_crRad cr + _crRad cr')
nearACCs = IM.filter isFarACC $ creaturesNearPointI 3 cpos w
acr <- listToMaybe $ sortOn (dist cpos . _crPos) $ IM.elems nearACCs
let r = _crRad acr + _crRad cr + 10
horDir = normalizeV (vNormal (cpos -.- tpos))
horShift = if isLHS tpos cpos (_crPos acr)
then r *.* horDir
else negate r *.* horDir
return $ cr & crActionPlan . crImpulse .~ [MoveForward 2.5,TurnToward (tpos +.+ horShift) 0.05 ]
+1 -1
View File
@@ -118,7 +118,7 @@ movementSideEff cr w
invSideEff :: Creature -> World -> World
invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
where
where
f i it w' = case it ^? itEffect . itInvEffect of
Nothing -> w'
Just g -> g cr i w'
+1
View File
@@ -41,5 +41,6 @@ data CrGroup
}
| CrGroupID { _crGroupID :: Int }
| ShieldGroup
deriving (Eq, Show)
makeLenses ''CreatureState
makeLenses ''CrSpState
+1
View File
@@ -54,6 +54,7 @@ roomTreex = do
,[SpecificRoom . pure . pure . Right $ roomGlassOctogon 400
& rmPS %~ ([sPS (0,50) 0 $ PutCrit armourChaseCrit
,sPS (50,25) 0 $ PutCrit armourChaseCrit
,sPS (50,0) 0 $ PutCrit armourChaseCrit
]++)
]
--,[Corridor]
+17 -16
View File
@@ -58,7 +58,6 @@ pistol
,poisonLauncher
,teslaLauncher
,remoteLauncher
,bezierGun
,defaultThrowable
-- ,shatterGun
,longGun,flamer,blinkGun,forceFieldGun :: Item
@@ -319,35 +318,37 @@ teslaLauncher = launcher
, _wpFire = shootWithSound (fromIntegral launcherSound) $ aRocketWithPayload makeTeslaExplosionAt
}
useTargetPos
:: (Point2 -> Int -> World -> World)
-> Int
-> World
-> World
useTargetPos f cid w = case cr ^? crInv . ix (_crInvSel cr) . itAttachment . _Just . itTargetPos of
Nothing -> w
Just p -> f p cid w
where
cr = _creatures w IM.! cid
bezierGun :: Item
bezierGun = defaultAutoGun
{ _itName = "B-GUN"
, _wpFire = hammerCheck $ maybeSetTarget $ \p ->
, _wpFire = useTargetPos $ \p ->
shootWithSound 0
. withMuzFlare
. withRecoil 40
. torqueBefore 0.05 -- I believe that this doesn't affect
$ shootBezier p -- <- the start point
$ shootBezier p -- <- the start point
, _itAttachment = Nothing
, _itScrollUp = removeItAttachment 0
, _itScrollDown = removeItAttachment 0
, _itHammer = HammerUp
, _itEffect = bezierRecock
, _itEffect = bezierTargetEffect
, _itZoom = defaultItZoom
, _itAimingRange = 0
}
maybeSetTarget :: (Point2 -> Int -> World -> World) -> Int -> World -> World
maybeSetTarget f cid w = case join $ w ^? creatures . ix cid . crInv . ix itRef . itAttachment of
Just (ItTargetPos targetp)
-> f targetp cid w
_ -> w & creatures . ix cid . crInv . ix itRef . itAttachment ?~ ItTargetPos mp
where
mp = mouseWorldPos w
cr = _creatures w IM.! cid
itRef = _crInvSel cr
shootBezier :: Point2 -> Int -> World -> World
shootBezier targetp cid w = over particles (theBullet :) w
shootBezier targetp cid w = w & particles %~ (theBullet :)
where
theBullet = aCurveBulAt
(Just cid)
@@ -365,7 +366,7 @@ shootBezier targetp cid w = over particles (theBullet :) w
a <- randInCirc 10
b <- randInCirc 20
return (a,b)
removeItAttachment :: Int -> Int -> World -> World
removeItAttachment i _ w = w & creatures . ix i . crInv . ix itRef . itAttachment .~ Nothing
where
+17
View File
@@ -8,6 +8,7 @@ import Dodge.Data
import Dodge.Base
import Dodge.Item.Weapon.Decoration
import Dodge.Item.Weapon.UseEffect
import Dodge.Item.Attachment.Data
import Dodge.WorldEvent.Flash
import Dodge.WorldEvent.ThingsHit
import Picture
@@ -16,6 +17,8 @@ import Geometry.Vector
import Data.Maybe
import Control.Lens
import qualified Data.IntMap.Strict as IM
import qualified Data.Set as S
import qualified SDL
{- |
Controls resetting a weapon, allows for non-continuous fire needing a button release. -}
wpRecock :: ItEffect
@@ -98,3 +101,17 @@ autoSonarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 }
. itEffect . itInvEffect .~ f 140
f t cr i w = w & creatures . ix (_crID cr) . crInv . ix i
. itEffect . itInvEffect .~ f (t-1)
bezierTargetEffect :: ItEffect
bezierTargetEffect = ItInvEffect
{_itInvEffect = setBezierTarget
,_itEffectCounter = 0
}
setBezierTarget :: Creature -> Int -> World -> World
setBezierTarget cr invid w
| _crInvSel cr /= invid = w
| SDL.ButtonRight `S.member` _mouseButtons w = w
& creatures . ix (_crID cr) . crInv . ix invid . itAttachment
%~ maybe (Just $ ItTargetPos $ mouseWorldPos w) Just
| otherwise = w & creatures . ix (_crID cr) . crInv . ix invid . itAttachment .~ Nothing