Cleanup targeting

This commit is contained in:
2023-01-05 11:01:12 +00:00
parent c48a553967
commit 0302685053
24 changed files with 66 additions and 95 deletions
+3 -3
View File
@@ -71,13 +71,13 @@ useAmmoParams it cr w =
settrajectory traj = case traj of
BasicBulletTrajectory -> BasicBulletTrajectory
MagnetTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just
tpos <- it ^? itUse . heldTargeting . tgPos . _Just
return $ MagnetTrajectory tpos
FlechetteTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just
tpos <- it ^? itUse . heldTargeting . tgPos . _Just
return $ FlechetteTrajectory tpos
BezierTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itTargeting . tgPos . _Just
tpos <- it ^? itUse . heldTargeting . tgPos . _Just
return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. cWorld . camPos))
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2
+3 -3
View File
@@ -167,9 +167,9 @@ moduleCombinations =
( ModTarget
, homingLaunchers ++ bulletWeapons
,
[ amod [cr MICROCHIP, cr HEATSENSOR] TARGCR
, amod [cr MICROCHIP, cr LIGHTSENSOR] TARGLAS
, amod [cr MICROCHIP, cr SOUNDSENSOR] TARGPOS
[ amod [cr MICROCHIP, cr HEATSENSOR] (TARGET TargetRBCreature)
, amod [cr MICROCHIP, cr LIGHTSENSOR] (TARGET TargetLaser)
, amod [cr MICROCHIP, cr SOUNDSENSOR] (TARGET TargetRBPress)
]
)
,
+2 -4
View File
@@ -19,9 +19,7 @@ moduleModification imt = case imt of
PENBUL -> itUse . heldConsumption . laAmmoType . amBullet . buEffect .~ PenetrateBullet
STATICBUL -> itUse . heldConsumption . laAmmoType . amBullet . buSpawn .~ BulBall TeslaBall
CONCUSBUL -> itUse . heldConsumption . laAmmoType . amBullet . buSpawn .~ BulBall ConcBall
TARGCR -> itTargeting .~ targetRBCreature
TARGLAS -> itTargeting .~ targetLaser
TARGPOS -> itTargeting .~ targetRBPress
TARGET t -> itUse . heldTargeting .~ (defaultTargeting & tgType .~ t)
MAGNETTRAJ ->
(itUse . heldConsumption . laAmmoType . amBullet . buTrajectory .~ MagnetTrajectory 0)
. (itUse . heldConsumption . laAmmoType . amBullet . buVel .~ V2 10 0)
@@ -39,7 +37,7 @@ moduleModification imt = case imt of
where
makeDirectedTele it =
it
& itTargeting .~ targetRBPress
& itUse . heldTargeting .~ (defaultTargeting & tgType .~ TargetRBPress)
& itUse . heldMods %~ ModWithDirectedTeleport -- .:~ withPosDirWallCheck directedTelPos
-- for the camera: the simplest option is to remove all zoom/offset
& itUse . heldAim . aimZoom . izFac .~ 1
+3 -3
View File
@@ -270,12 +270,12 @@ updateAutoRecharge it = case it ^? itUse . leftConsumption of
_ -> it
doItemTargeting :: Int -> Creature -> World -> World
doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
doItemTargeting invid cr w = case cr ^? crInv . ix invid . itUse . heldTargeting of
Nothing -> w
Just NoTargeting -> w
Just t ->
let (w', t') = updateTargeting (_tgUpdate t) (_crInv cr IM.! invid) cr w t
in w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itTargeting .~ t'
let (w', t') = updateTargeting (_tgType t) (_crInv cr IM.! invid) cr w t
in w' & cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itUse . heldTargeting .~ t'
weaponReloadSounds :: Creature -> World -> World
weaponReloadSounds cr w = case cr ^? crInvSel . iselAction of
-3
View File
@@ -13,7 +13,6 @@ module Dodge.Data.Item (
module Dodge.Data.Item.CurseStatus,
module Dodge.Data.Item.Scope,
module Dodge.Data.Item.Combine,
module Dodge.Data.Item.Targeting,
module Dodge.Data.Item.Location,
) where
@@ -29,7 +28,6 @@ import Dodge.Data.Item.Misc
import Dodge.Data.Item.Params
import Dodge.Data.Item.Tweak
import Dodge.Data.Item.Use
import Dodge.Data.Item.Targeting
import Dodge.Data.Item.Location
data Item = Item
@@ -41,7 +39,6 @@ data Item = Item
, _itEffect :: ItEffect
, _itInvSize :: Float
, _itInvColor :: Color
, _itTargeting :: Targeting
, _itDimension :: ItemDimension
, _itCurseStatus :: CurseStatus
, _itTweaks :: ItemTweaks
+2 -3
View File
@@ -5,6 +5,7 @@
module Dodge.Data.Item.Combine where
import Dodge.Data.Item.Targeting
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
@@ -187,9 +188,7 @@ data ItemModuleType
| PENBUL
| STATICBUL
| CONCUSBUL
| TARGCR
| TARGLAS
| TARGPOS
| TARGET TargetType
| MAGNETTRAJ
| FLECHETRAJ
| BEZIERTRAJ
+9 -17
View File
@@ -14,29 +14,21 @@ data Targeting
= NoTargeting
| Targeting
{ _tgPos :: Maybe Point2
, _tgUpdate :: TargetUpdate --Item -> Creature -> World -> Targeting -> (World, Targeting)
, _tgDraw :: TargetDraw --Item -> Creature -> Configuration -> World -> Picture
, _tgType :: TargetType --Item -> Creature -> World -> Targeting -> (World, Targeting)
-- , _tgDraw :: TargetDraw --Item -> Creature -> Configuration -> World -> Picture
, _tgID :: Maybe Int
, _tgActive :: Bool
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data TargetUpdate
= NoTargetUpdate
| TargetLaserUpdate
| TargetRBPressUpdate
| TargetRBCreatureUpdate
| TargetCursorUpdate
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data TargetDraw
= NoTargetDraw
| TargetDistanceDraw
| SimpleDrawTarget
| TargetRBCreatureDraw
data TargetType
= TargetLaser
| TargetRBPress
| TargetRBLine
| TargetRBCreature
| TargetCursor
deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''Targeting
deriveJSON defaultOptions ''TargetUpdate
deriveJSON defaultOptions ''TargetDraw
deriveJSON defaultOptions ''TargetType
deriveJSON defaultOptions ''Targeting
+4
View File
@@ -11,6 +11,7 @@ module Dodge.Data.Item.Use (
module Dodge.Data.Item.HeldDelay,
module Dodge.Data.Item.Use.Consumption,
module Dodge.Data.Hammer,
module Dodge.Data.Item.Targeting,
) where
import Control.Lens
@@ -22,6 +23,7 @@ import Dodge.Data.Item.HeldUse
import Dodge.Data.Item.Use.Consumption
import Dodge.Data.Item.Use.Equipment
import Dodge.Data.Item.HeldDelay
import Dodge.Data.Item.Targeting
data ItemUse
= HeldUse
@@ -32,6 +34,7 @@ data ItemUse
, _heldAim :: AimParams
, _heldScroll :: HeldScroll
, _heldConsumption :: HeldConsumption
, _heldTargeting :: Targeting
}
| LeftUse
{ _leftUse :: Luse
@@ -46,6 +49,7 @@ data ItemUse
}
| EquipUse
{ _equipEffect :: EquipEffect
, _equipTargeting :: Targeting
}
| CraftUse
{_useAmount :: ItAmount}
+1 -1
View File
@@ -13,7 +13,7 @@ import Geometry.Data
data LaserType
= DamageLaser {_laserTypeDamage :: Int}
| TargetLaser
| TargetingLaser
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data LaserStart = LaserStart
+1 -3
View File
@@ -28,9 +28,7 @@ defaultEquipment :: Item
defaultEquipment =
defaultItem
& itInvColor .~ yellow
& itUse .~ EquipUse defaultEquip
& itUse .~ defaultEquipUse
defaultFlIt :: FloorItem
defaultFlIt = FlIt{_flItRot = 0, _flIt = defaultConsumable, _flItPos = V2 0 0, _flItID = 0}
-1
View File
@@ -35,7 +35,6 @@ defaultItem =
, _itParams = NoParams
, _itTweaks = NoTweaks
, _itScope = NoScope
, _itTargeting = NoTargeting
-- , _itValue = ItemValue 0 MundaneItem
}
+5 -1
View File
@@ -21,7 +21,10 @@ defaultLeftUse =
}
defaultEquipUse :: ItemUse
defaultEquipUse = EquipUse{_equipEffect = defaultEquip}
defaultEquipUse = EquipUse
{ _equipEffect = defaultEquip
, _equipTargeting = NoTargeting
}
defaultHeldUse :: ItemUse
defaultHeldUse =
@@ -33,4 +36,5 @@ defaultHeldUse =
, _heldAim = defaultAimParams
, _heldScroll = HeldScrollDoNothing
, _heldConsumption = defaultLoadable
, _heldTargeting = NoTargeting
}
+2 -2
View File
@@ -348,7 +348,7 @@ useMod hm = case hm of
thegapDualBeam = _dbGap . _itParams
directedTelPos it cr w = (p, a)
where
p = fromMaybe (_crPos cr) $ it ^? itTargeting . tgPos . _Just
p = fromMaybe (_crPos cr) $ it ^? itUse . heldTargeting . tgPos . _Just
a = argV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- p)
moddelay x = itUse . heldConsumption . laAmmoType . amBullet . buDelayFraction .~ x
modcrpos x cr =
@@ -511,7 +511,7 @@ shootTeslaArc it cr w =
-- TODO investigate more and fix
useForceFieldGun :: Item -> Creature -> World -> World
useForceFieldGun itm cr w = fromMaybe w $ do
a <- _tgPos $ _itTargeting itm
a <- _tgPos . _heldTargeting $ _itUse itm
let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a)
wlline = (a, b)
+1 -1
View File
@@ -75,7 +75,7 @@ showConsumption :: ItemUse -> String
showConsumption iu = case iu of
HeldUse{} -> showReloadProgress' (_heldConsumption iu)
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
EquipUse ee -> showEUseNumber ee
EquipUse {_equipEffect = ee} -> showEUseNumber ee
_ -> show $ iu ^?! useAmount . getItAmount
showEUseNumber :: EquipEffect -> String
+1 -1
View File
@@ -73,7 +73,7 @@ sniperRifle =
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5}
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itScope .~ ZoomScope (V2 0 0) 0 1 0.5 False
& itTargeting .~ targetLaser
& itUse . heldTargeting .~ (defaultTargeting & tgType .~ TargetLaser)
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1}
machineGun :: Item
+1 -1
View File
@@ -44,7 +44,7 @@ torch =
forceFieldGun :: Item
forceFieldGun =
defaultWeapon
& itTargeting .~ (targetRBPress & tgDraw .~ TargetDistanceDraw)
& itUse . heldTargeting .~ (defaultTargeting & tgType .~ TargetRBLine)
& itParams .~ ParamMID Nothing
& itUse . heldUse .~ HeldForceField --useForceFieldGun
& itUse . heldDelay .~ NoDelay
+2 -26
View File
@@ -1,37 +1,13 @@
module Dodge.Item.Targeting where
import Control.Lens
import Dodge.Data.Item.Targeting
defaultTargeting :: Targeting
defaultTargeting =
Targeting
{ _tgPos = Nothing
, _tgUpdate = NoTargetUpdate
, _tgDraw = NoTargetDraw
, _tgType = TargetRBPress
--, _tgDraw = NoTargetDraw
, _tgID = Nothing
, _tgActive = False
}
targetLaser :: Targeting
targetLaser =
defaultTargeting
& tgUpdate .~ TargetLaserUpdate
targetRBPress :: Targeting
targetRBPress =
defaultTargeting
& tgUpdate .~ TargetRBPressUpdate
& tgDraw .~ SimpleDrawTarget
targetRBCreature :: Targeting
targetRBCreature =
defaultTargeting
& tgUpdate .~ TargetRBCreatureUpdate
& tgDraw .~ TargetRBCreatureDraw
targetCursor :: Targeting
targetCursor =
defaultTargeting
& tgUpdate .~ TargetCursorUpdate
& tgDraw .~ SimpleDrawTarget
+1 -1
View File
@@ -147,7 +147,7 @@ targetLaserUpdate _ cr w t
, _lpDir = _crDir cr
, _lpPos = sp
, _lpColor = col
, _lpType = TargetLaser
, _lpType = TargetingLaser
}
--wpammo = _itConsumption it
-- reloadFrac
+2 -2
View File
@@ -12,9 +12,9 @@ useTargetPos ::
Creature ->
World ->
World
useTargetPos f cr w = case cr ^? crInv . ix (crSel cr) . itTargeting . tgPos of
useTargetPos f cr w = case cr ^? crInv . ix (crSel cr) . itUse . heldTargeting . tgPos of
Nothing -> w
Just p -> f p cr w
removeItTarget :: Item -> Item
removeItTarget = itTargeting . tgPos .~ Nothing
removeItTarget = itUse . heldTargeting . tgPos .~ Nothing
+5 -3
View File
@@ -29,9 +29,11 @@ moduleName imt = case imt of
PENBUL -> Just "+PENETRATE"
STATICBUL -> Just "+STATIC"
CONCUSBUL -> Just "+CONCUSS"
TARGCR -> Just "+CREATURETARGETING"
TARGLAS -> Just "+LASERTARGETING"
TARGPOS -> Just "+POSTIONALTARGETING"
TARGET TargetRBCreature -> Just "+CREATURETARGETING"
TARGET TargetLaser -> Just "+LASERTARGETING"
TARGET TargetRBPress -> Just "+POSTIONALTARGETING"
TARGET TargetCursor -> Just "+CURSORTARGETING"
TARGET TargetRBLine -> Just "+LINETARGETING"
MAGNETTRAJ -> Just "+MAGNETTRAJECTORY"
FLECHETRAJ -> Just "+FLECHETTETRAJECTORY"
BEZIERTRAJ -> Just "+BEZIERTRAJECTORY"
+1 -1
View File
@@ -139,7 +139,7 @@ pjTrack :: Int -> Proj -> World -> World
pjTrack itid pj w = rotateToTarget pj w
where
rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itTargeting . tgPos . _Just
tpos <- w ^? itPoint . itUse . heldTargeting . tgPos . _Just
return $
cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin
.~ turnToAmount
+1 -1
View File
@@ -62,7 +62,7 @@ anyTargeting :: Configuration -> World -> SPic
anyTargeting cfig w = (mempty, pictures $ IM.elems $ IM.mapMaybe f $ _crInv cr)
where
cr = you w
f it = fmap (\g -> drawTargeting g it cr cfig w) (it ^? itTargeting . tgDraw)
f it = fmap (\g -> drawTargeting g it cr cfig w) (it ^? itUse . heldTargeting . tgType)
drawCreature :: Creature -> SPic
drawCreature cr = case _crType cr of
+6 -6
View File
@@ -3,10 +3,10 @@ module Dodge.Targeting where
import Dodge.Data.World
import Dodge.Item.Weapon.ExtraEffect
updateTargeting :: TargetUpdate -> Item -> Creature -> World -> Targeting -> (World, Targeting)
updateTargeting :: TargetType -> Item -> Creature -> World -> Targeting -> (World, Targeting)
updateTargeting tu = case tu of
NoTargetUpdate -> \_ _ w t -> (w, t)
TargetLaserUpdate -> targetLaserUpdate
TargetRBPressUpdate -> targetUpdateWith targetRBPressUpdate
TargetRBCreatureUpdate -> targetRBCreatureUp
TargetCursorUpdate -> targetUpdateWith targetCursorUpdate
TargetLaser -> targetLaserUpdate
TargetRBPress -> targetUpdateWith targetRBPressUpdate
TargetRBLine -> targetUpdateWith targetRBPressUpdate
TargetRBCreature -> targetRBCreatureUp
TargetCursor -> targetUpdateWith targetCursorUpdate
+10 -8
View File
@@ -9,19 +9,21 @@ import LensHelp
import Picture
import ShortShow
drawTargeting :: TargetDraw -> Item -> Creature -> Configuration -> World -> Picture
drawTargeting :: TargetType -> Item -> Creature -> Configuration -> World -> Picture
drawTargeting td = case td of
NoTargetDraw -> \_ _ _ _ -> mempty
SimpleDrawTarget -> targetSimpleDraw
TargetRBCreatureDraw -> targetRBCreatureDraw
TargetDistanceDraw -> targetDistanceDraw
-- NoTargetDraw -> \_ _ _ _ -> mempty
TargetRBCreature -> targetRBCreatureDraw
TargetRBLine -> targetDistanceDraw
TargetLaser -> \_ _ _ _ -> mempty
TargetRBPress -> targetSimpleDraw
TargetCursor -> targetSimpleDraw
targetSimpleDraw :: Item -> Creature -> Configuration -> World -> Picture
targetSimpleDraw = targetDraw $ const activeTargetCursorPic
targetDistanceDraw :: Item -> Creature -> Configuration -> World -> Picture
targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do
p <- itm ^? itTargeting . tgPos . _Just
p <- itm ^? itUse . heldTargeting . tgPos . _Just
let p1 = worldPosToScreen cam p
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
p2 = worldPosToScreen cam mwp
@@ -37,7 +39,7 @@ targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do
targetDraw :: (Item -> Picture) -> Item -> Creature -> Configuration -> World -> Picture
targetDraw f it _ cfig w = fromMaybe mempty $ do
p <- it ^? itTargeting . tgPos . _Just
p <- it ^? itUse . heldTargeting . tgPos . _Just
return $
winScale cfig $
setLayer FixedCoordLayer $
@@ -65,7 +67,7 @@ targetRBCreatureDraw :: Item -> Creature -> Configuration -> World -> Picture
targetRBCreatureDraw = targetDraw thepic
where
thepic it
| _tgActive $ _itTargeting it = activeTargetCursorPic
| _tgActive $ _heldTargeting $ _itUse it = activeTargetCursorPic
| otherwise = targetCursorPic
targCorner :: Picture