Move towards allowing equipable targeting items

This commit is contained in:
2023-01-06 11:01:32 +00:00
parent bf479ca080
commit 612ee85579
23 changed files with 152 additions and 145 deletions
+3 -3
View File
@@ -71,13 +71,13 @@ useAmmoParams it cr w =
settrajectory traj = case traj of settrajectory traj = case traj of
BasicBulletTrajectory -> BasicBulletTrajectory BasicBulletTrajectory -> BasicBulletTrajectory
MagnetTrajectory{} -> fromMaybe BasicBulletTrajectory $ do MagnetTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itUse . heldTargeting . tgPos . _Just tpos <- cr ^? crTargeting . ctPos . _Just
return $ MagnetTrajectory tpos return $ MagnetTrajectory tpos
FlechetteTrajectory{} -> fromMaybe BasicBulletTrajectory $ do FlechetteTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itUse . heldTargeting . tgPos . _Just tpos <- cr ^? crTargeting . ctPos . _Just
return $ FlechetteTrajectory tpos return $ FlechetteTrajectory tpos
BezierTrajectory{} -> fromMaybe BasicBulletTrajectory $ do BezierTrajectory{} -> fromMaybe BasicBulletTrajectory $ do
tpos <- it ^? itUse . heldTargeting . tgPos . _Just tpos <- cr ^? crTargeting . ctPos . _Just
return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. cWorld . camPos)) return $ BezierTrajectory sp tpos (mouseWorldPos (w ^. input) (w ^. cWorld . camPos))
bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2 bounceDir :: (Point2, Either Creature Wall) -> Maybe Point2
+9
View File
@@ -27,11 +27,20 @@ backpackCombinations =
po xs it = (map o xs, it) po xs it = (map o xs, it)
o = (1,) o = (1,)
hatCombinations :: [([(ItAmount,ItemBaseType)],Item)]
hatCombinations =
[ po [EQUIP HAT, CRAFT (TARGETMODULE tt)] (targetingHat tt) | tt <- [minBound..]
]
where
po xs it = (map o xs, it)
o = (1,)
itemCombinations :: [([(ItAmount, ItemBaseType)], Item)] itemCombinations :: [([(ItAmount, ItemBaseType)], Item)]
itemCombinations = itemCombinations =
watchCombinations ++ watchCombinations ++
backpackCombinations ++ backpackCombinations ++
hatCombinations ++
[ po [CRAFT PIPE, CRAFT HARDWARE] (bangStick 1) [ po [CRAFT PIPE, CRAFT HARDWARE] (bangStick 1)
, po [HELD (BANGSTICK 1), CRAFT TIN] pistol , po [HELD (BANGSTICK 1), CRAFT TIN] pistol
, po [HELD PISTOL, CRAFT SPRING] autoPistol , po [HELD PISTOL, CRAFT SPRING] autoPistol
+2 -3
View File
@@ -1,7 +1,6 @@
module Dodge.Combine.Module where module Dodge.Combine.Module where
import Data.Foldable import Data.Foldable
import Dodge.Item.Targeting
import Dodge.Data.Beam import Dodge.Data.Beam
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Tesla import Dodge.Tesla
@@ -19,7 +18,7 @@ moduleModification imt = case imt of
PENBUL -> itUse . heldConsumption . laAmmoType . amBullet . buEffect .~ PenetrateBullet PENBUL -> itUse . heldConsumption . laAmmoType . amBullet . buEffect .~ PenetrateBullet
STATICBUL -> itUse . heldConsumption . laAmmoType . amBullet . buSpawn .~ BulBall TeslaBall STATICBUL -> itUse . heldConsumption . laAmmoType . amBullet . buSpawn .~ BulBall TeslaBall
CONCUSBUL -> itUse . heldConsumption . laAmmoType . amBullet . buSpawn .~ BulBall ConcBall CONCUSBUL -> itUse . heldConsumption . laAmmoType . amBullet . buSpawn .~ BulBall ConcBall
TARGET t -> itUse . heldTargeting .~ (defaultTargeting & tgType .~ t) TARGET t -> itUse . useTargeting .~ (Just t)
MAGNETTRAJ -> MAGNETTRAJ ->
(itUse . heldConsumption . laAmmoType . amBullet . buTrajectory .~ MagnetTrajectory 0) (itUse . heldConsumption . laAmmoType . amBullet . buTrajectory .~ MagnetTrajectory 0)
. (itUse . heldConsumption . laAmmoType . amBullet . buVel .~ V2 10 0) . (itUse . heldConsumption . laAmmoType . amBullet . buVel .~ V2 10 0)
@@ -37,7 +36,7 @@ moduleModification imt = case imt of
where where
makeDirectedTele it = makeDirectedTele it =
it it
& itUse . heldTargeting .~ (defaultTargeting & tgType .~ TargetRBPress) & itUse . useTargeting .~ (Just TargetRBPress)
& itUse . heldMods %~ ModWithDirectedTeleport -- .:~ withPosDirWallCheck directedTelPos & itUse . heldMods %~ ModWithDirectedTeleport -- .:~ withPosDirWallCheck directedTelPos
-- for the camera: the simplest option is to remove all zoom/offset -- for the camera: the simplest option is to remove all zoom/offset
& itUse . heldAim . aimZoom . izFac .~ 1 & itUse . heldAim . aimZoom . izFac .~ 1
+1
View File
@@ -203,6 +203,7 @@ inventoryX c = case c of
] ]
'K' -> 'K' ->
[ autoRifle [ autoRifle
, targetingHat TargetRBPress
, makeTypeCraftNum 7 MICROCHIP , makeTypeCraftNum 7 MICROCHIP
, makeTypeCraftNum 4 HARDWARE , makeTypeCraftNum 4 HARDWARE
, makeTypeCraftNum 2 MAGNET , makeTypeCraftNum 2 MAGNET
+36 -10
View File
@@ -3,18 +3,19 @@ module Dodge.Creature.State (
doDamage, doDamage,
) where ) where
import Data.Maybe
import Dodge.Creature.Test
import Data.Foldable import Data.Foldable
import Data.Maybe
import Dodge.Base import Dodge.Base
import Dodge.Corpse.Make import Dodge.Corpse.Make
import Dodge.Creature.Action import Dodge.Creature.Action
import Dodge.Creature.Damage import Dodge.Creature.Damage
import Dodge.Creature.Impulse.Movement import Dodge.Creature.Impulse.Movement
import Dodge.Creature.State.WalkCycle import Dodge.Creature.State.WalkCycle
import Dodge.Creature.Test
import Dodge.Damage import Dodge.Damage
import Dodge.Data.World import Dodge.Data.World
import Dodge.EnergyBall import Dodge.EnergyBall
import Dodge.Equipment
import Dodge.Euse import Dodge.Euse
import Dodge.Hammer import Dodge.Hammer
import Dodge.ItEffect import Dodge.ItEffect
@@ -233,11 +234,16 @@ equipmentEffects cr = flip (foldl' $ flip $ useEquipment cr) (IM.keys $ _crInvEq
-- a loop going over all inventory items -- a loop going over all inventory items
invSideEff :: Creature -> World -> World invSideEff :: Creature -> World -> World
invSideEff cr w = weaponReloadSounds cr $ IM.foldlWithKey' f w (_crInv cr) invSideEff cr w =
crDoTargeting cr $
weaponReloadSounds cr $
over (cWorld . lWorld . creatures . ix (_crID cr)) crSetTargeting $
IM.foldl' f w (_crInv cr)
where where
f w' i it = f w' it =
itemInvSideEffect cr it $ itemInvSideEffect cr it $
doItemTargeting i cr w' & maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv) --doItemTargeting i cr w' & maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv)
w' & maybe id (\g -> doInvEffect g it cr) (it ^? itEffect . ieInv)
itemInvSideEffect :: Creature -> Item -> World -> World itemInvSideEffect :: Creature -> Item -> World -> World
itemInvSideEffect cr it itemInvSideEffect cr it
@@ -269,13 +275,33 @@ updateAutoRecharge it = case it ^? itUse . leftConsumption of
| l < m -> it & itUse . leftConsumption . arProgress -~ 1 | l < m -> it & itUse . leftConsumption . arProgress -~ 1
_ -> it _ -> it
crSetTargeting :: Creature -> Creature
crSetTargeting cr = fromMaybe cr $ do
itm <- find hastargeting $ helditem ++ IM.elems (getCrEquipment cr)
tt <- itm ^? itUse . useTargeting . _Just
return $ cr & crTargeting . ctType ?~ tt
where
hastargeting itm = isJust (itm ^? itUse . useTargeting . _Just)
helditem = fromMaybe [] $ do
i <- cr ^? crInvSel . iselPos
itm <- cr ^? crInv . ix i
return [itm]
crDoTargeting :: Creature -> World -> World
crDoTargeting cr = fromMaybe id $ do
itm <- find hastargeting $ helditem ++ IM.elems (getCrEquipment cr)
invid <- itm ^? itLocation . ipInvID
return $ doItemTargeting invid cr
where
helditem = maybeToList $ cr ^? crInv . ix (crSel cr)
hastargeting itm = case itm ^? itUse . useTargeting of
Just _ -> True
_ -> False
doItemTargeting :: Int -> Creature -> World -> World doItemTargeting :: Int -> Creature -> World -> World
doItemTargeting invid cr w = case cr ^? crInv . ix invid . itUse . heldTargeting of doItemTargeting invid cr w = case cr ^? crInv . ix invid . itUse . useTargeting . _Just of
Nothing -> w Nothing -> w
Just NoTargeting -> w Just t -> updateTargeting t cr w
Just 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 :: Creature -> World -> World
weaponReloadSounds cr w = case cr ^? crInvSel . iselAction of weaponReloadSounds cr w = case cr ^? crInvSel . iselAction of
+10
View File
@@ -72,10 +72,18 @@ data Creature = Creature
, _crName :: String , _crName :: String
, _crStatistics :: CreatureStatistics , _crStatistics :: CreatureStatistics
, _crCamouflage :: CamouflageStatus , _crCamouflage :: CamouflageStatus
, _crTargeting :: CreatureTargeting
} }
--deriving (Eq, Show, Read) --Generic, Flat) --deriving (Eq, Show, Read) --Generic, Flat)
data CreatureTargeting = CreatureTargeting
{ _ctPos :: Maybe Point2
, _ctType :: Maybe TargetType
, _ctID :: Maybe Int
, _ctActive :: Bool
}
data CreatureCorpse = MakeDefaultCorpse data CreatureCorpse = MakeDefaultCorpse
--deriving (Eq, Ord, Show, Read) --Generic, Flat) --deriving (Eq, Ord, Show, Read) --Generic, Flat)
@@ -92,6 +100,7 @@ crSel :: Creature -> Int
crSel = _iselPos . _crInvSel crSel = _iselPos . _crInvSel
makeLenses ''Creature makeLenses ''Creature
makeLenses ''CreatureTargeting
makeLenses ''Intention makeLenses ''Intention
concat concat
@@ -100,4 +109,5 @@ concat
[ ''CreatureCorpse [ ''CreatureCorpse
, ''Creature , ''Creature
, ''Intention , ''Intention
, ''CreatureTargeting
] ]
+2
View File
@@ -79,6 +79,8 @@ data CraftType
| TIMEMODULE | TIMEMODULE
| SIZEMODULE | SIZEMODULE
| GRAVITYMODULE | GRAVITYMODULE
| TARGETMODULE TargetType
deriving (Eq,Ord,Show,Read) deriving (Eq,Ord,Show,Read)
--deriving (Eq, Ord, Show, Enum, Read) --Generic, Flat) --deriving (Eq, Ord, Show, Enum, Read) --Generic, Flat)
+1 -14
View File
@@ -10,25 +10,12 @@ import Data.Aeson
import Data.Aeson.TH import Data.Aeson.TH
import Geometry.Data import Geometry.Data
data Targeting
= NoTargeting
| Targeting
{ _tgPos :: Maybe Point2
, _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 TargetType data TargetType
= TargetLaser = TargetLaser
| TargetRBPress | TargetRBPress
| TargetRBLine | TargetRBLine
| TargetRBCreature | TargetRBCreature
| TargetCursor | TargetCursor
deriving (Eq, Ord, Show, Read) --Generic, Flat) deriving (Eq, Ord, Show, Read, Enum, Bounded) --Generic, Flat)
makeLenses ''Targeting
deriveJSON defaultOptions ''TargetType deriveJSON defaultOptions ''TargetType
deriveJSON defaultOptions ''Targeting
+2 -2
View File
@@ -34,7 +34,7 @@ data ItemUse
, _heldAim :: AimParams , _heldAim :: AimParams
, _heldScroll :: HeldScroll , _heldScroll :: HeldScroll
, _heldConsumption :: HeldConsumption , _heldConsumption :: HeldConsumption
, _heldTargeting :: Targeting , _useTargeting :: Maybe TargetType
} }
| LeftUse | LeftUse
{ _leftUse :: Luse { _leftUse :: Luse
@@ -49,7 +49,7 @@ data ItemUse
} }
| EquipUse | EquipUse
{ _equipEffect :: EquipEffect { _equipEffect :: EquipEffect
, _equipTargeting :: Targeting , _useTargeting :: Maybe TargetType
} }
| CraftUse | CraftUse
{_useAmount :: ItAmount} {_useAmount :: ItAmount}
+1 -1
View File
@@ -24,7 +24,7 @@ data ProjectileCreate = CreateShell | CreateTrackingShell
data ProjectileUpdate data ProjectileUpdate
= PJThrust {_pjuStart :: Int, _pjuEnd :: Int} = PJThrust {_pjuStart :: Int, _pjuEnd :: Int}
| PJSpin {_pjuTime :: Int, _pjuCID :: Int, _pjuSpinAmound :: Int} | PJSpin {_pjuTime :: Int, _pjuCID :: Int, _pjuSpinAmound :: Int}
| PJTrack {_pjuStart :: Int, _pjuEnd :: Int, _pjuITID :: Int} | PJTrack {_pjuStart :: Int, _pjuEnd :: Int, _pjuCRID :: Int}
| PJReduceSpin {_pjuReduceSpin :: Float} | PJReduceSpin {_pjuReduceSpin :: Float}
| PJRemoteDirection {_pjuStart :: Int, _pjuEnd :: Int, _pjuCID :: Int, _pjuITID :: Int} | PJRemoteDirection {_pjuStart :: Int, _pjuEnd :: Int, _pjuCID :: Int, _pjuITID :: Int}
| PJSetScope {_pjuITID :: Int} | PJSetScope {_pjuITID :: Int}
+4
View File
@@ -54,8 +54,12 @@ defaultCreature =
, _crName = "DEFAULTCRNAME" , _crName = "DEFAULTCRNAME"
, _crStatistics = CreatureStatistics 10 10 10 , _crStatistics = CreatureStatistics 10 10 10
, _crCamouflage = FullyVisible , _crCamouflage = FullyVisible
, _crTargeting = defaultCreatureTargeting
} }
defaultCreatureTargeting :: CreatureTargeting
defaultCreatureTargeting = CreatureTargeting Nothing Nothing Nothing False
defaultCreatureSkin :: CreatureType defaultCreatureSkin :: CreatureType
defaultCreatureSkin = Humanoid (greyN 0.9) (light4 green) (greyN 0.3) InanimateAI defaultCreatureSkin = Humanoid (greyN 0.9) (light4 green) (greyN 0.3) InanimateAI
+2 -2
View File
@@ -23,7 +23,7 @@ defaultLeftUse =
defaultEquipUse :: ItemUse defaultEquipUse :: ItemUse
defaultEquipUse = EquipUse defaultEquipUse = EquipUse
{ _equipEffect = defaultEquip { _equipEffect = defaultEquip
, _equipTargeting = NoTargeting , _useTargeting = Nothing
} }
defaultHeldUse :: ItemUse defaultHeldUse :: ItemUse
@@ -36,5 +36,5 @@ defaultHeldUse =
, _heldAim = defaultAimParams , _heldAim = defaultAimParams
, _heldScroll = HeldScrollDoNothing , _heldScroll = HeldScrollDoNothing
, _heldConsumption = defaultLoadable , _heldConsumption = defaultLoadable
, _heldTargeting = NoTargeting , _useTargeting = Nothing
} }
+2 -2
View File
@@ -348,7 +348,7 @@ useMod hm = case hm of
thegapDualBeam = _dbGap . _itParams thegapDualBeam = _dbGap . _itParams
directedTelPos it cr w = (p, a) directedTelPos it cr w = (p, a)
where where
p = fromMaybe (_crPos cr) $ it ^? itUse . heldTargeting . tgPos . _Just p = fromMaybe (_crPos cr) $ cr ^? crTargeting . ctPos . _Just
a = argV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- p) a = argV (mouseWorldPos (w ^. input) (w ^. cWorld . camPos) -.- p)
moddelay x = itUse . heldConsumption . laAmmoType . amBullet . buDelayFraction .~ x moddelay x = itUse . heldConsumption . laAmmoType . amBullet . buDelayFraction .~ x
modcrpos x cr = modcrpos x cr =
@@ -511,7 +511,7 @@ shootTeslaArc it cr w =
-- TODO investigate more and fix -- TODO investigate more and fix
useForceFieldGun :: Item -> Creature -> World -> World useForceFieldGun :: Item -> Creature -> World -> World
useForceFieldGun itm cr w = fromMaybe w $ do useForceFieldGun itm cr w = fromMaybe w $ do
a <- _tgPos . _heldTargeting $ _itUse itm a <- cr ^? crTargeting . ctPos . _Just
let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos) let mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a) b = if dist a mwp < 100 then mwp else a +.+ 100 *.* normalizeV (mwp -.- a)
wlline = (a, b) wlline = (a, b)
+1 -2
View File
@@ -17,7 +17,6 @@ module Dodge.Item.Equipment (
flameShield, flameShield,
) where ) where
import Dodge.Item.Targeting
import Geometry.Data import Geometry.Data
import Dodge.Data.CamouflageStatus import Dodge.Data.CamouflageStatus
import Dodge.Data.Item import Dodge.Data.Item
@@ -93,7 +92,7 @@ targetingHat tt =
defaultEquipment defaultEquipment
& itUse . equipEffect . eeSite .~ GoesOnHead & itUse . equipEffect . eeSite .~ GoesOnHead
& itType . iyBase .~ EQUIP (TARGETINGHAT tt) & itType . iyBase .~ EQUIP (TARGETINGHAT tt)
& itUse . equipTargeting .~ (defaultTargeting & tgType .~ tt) & itUse . useTargeting .~ (Just tt)
headLamp :: Item headLamp :: Item
headLamp = headLamp =
+1 -2
View File
@@ -7,7 +7,6 @@ module Dodge.Item.Held.Rod (
machineGun, machineGun,
) where ) where
import Dodge.Item.Targeting
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default import Dodge.Default
import Dodge.Item.Weapon.Bullet import Dodge.Item.Weapon.Bullet
@@ -73,7 +72,7 @@ sniperRifle =
& itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5} & itUse . heldAim . aimZoom .~ defaultItZoom{_izMax = 0.5, _izMin = 0.5}
& itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun & itUse . heldScroll .~ HeldScrollZoom -- zoomLongGun
& itScope .~ ZoomScope (V2 0 0) 0 1 0.5 False & itScope .~ ZoomScope (V2 0 0) 0 1 0.5 False
& itUse . heldTargeting .~ (defaultTargeting & tgType .~ TargetLaser) & itUse . useTargeting .~ (Just TargetLaser)
& itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1} & itUse . heldAim . aimZoom .~ defaultItZoom{_izFac = 1}
machineGun :: Item machineGun :: Item
+1 -2
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Held.Utility where module Dodge.Item.Held.Utility where
import Dodge.Item.Targeting
import Dodge.Default.Item import Dodge.Default.Item
import Color import Color
import Control.Lens import Control.Lens
@@ -44,7 +43,7 @@ torch =
forceFieldGun :: Item forceFieldGun :: Item
forceFieldGun = forceFieldGun =
defaultWeapon defaultWeapon
& itUse . heldTargeting .~ (defaultTargeting & tgType .~ TargetRBLine) & itUse . useTargeting .~ Just TargetRBLine
& itParams .~ ParamMID Nothing & itParams .~ ParamMID Nothing
& itUse . heldUse .~ HeldForceField --useForceFieldGun & itUse . heldUse .~ HeldForceField --useForceFieldGun
& itUse . heldDelay .~ NoDelay & itUse . heldDelay .~ NoDelay
+2
View File
@@ -184,6 +184,8 @@ craftInfo fit = case fit of
SIZEMODULE -> "A DEVICE THAT CAN AFFECT PHYSICAL SIZE." SIZEMODULE -> "A DEVICE THAT CAN AFFECT PHYSICAL SIZE."
GRAVITYMODULE -> "A DEVICE THAT CAN AFFECT GRAVITATIONAL FIELDS." GRAVITYMODULE -> "A DEVICE THAT CAN AFFECT GRAVITATIONAL FIELDS."
TARGETMODULE _ -> "A TARGETING MODULE."
detectorInfo :: Detector -> String detectorInfo :: Detector -> String
detectorInfo d = case d of detectorInfo d = case d of
-13
View File
@@ -1,13 +0,0 @@
module Dodge.Item.Targeting where
import Dodge.Data.Item.Targeting
defaultTargeting :: Targeting
defaultTargeting =
Targeting
{ _tgPos = Nothing
, _tgType = TargetRBPress
--, _tgDraw = NoTargetDraw
, _tgID = Nothing
, _tgActive = False
}
+1 -5
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Weapon.Targeting ( module Dodge.Item.Weapon.Targeting (
useTargetPos, useTargetPos,
removeItTarget,
) where ) where
import Control.Lens import Control.Lens
@@ -12,9 +11,6 @@ useTargetPos ::
Creature -> Creature ->
World -> World ->
World World
useTargetPos f cr w = case cr ^? crInv . ix (crSel cr) . itUse . heldTargeting . tgPos of useTargetPos f cr w = case cr ^? crTargeting . ctPos of
Nothing -> w Nothing -> w
Just p -> f p cr w Just p -> f p cr w
removeItTarget :: Item -> Item
removeItTarget = itUse . heldTargeting . tgPos .~ Nothing
+5 -5
View File
@@ -64,8 +64,8 @@ upProjectile pu pj = case pu of
PJSpin t cid spinamount PJSpin t cid spinamount
| ain t -> trySpinByCID cid spinamount pj | ain t -> trySpinByCID cid spinamount pj
| otherwise -> id | otherwise -> id
PJTrack st et itid PJTrack st et crid
| act st et -> pjTrack itid pj | act st et -> pjTrack crid pj
| otherwise -> id | otherwise -> id
PJReduceSpin x -> reduceSpinBy x pj PJReduceSpin x -> reduceSpinBy x pj
PJRemoteDirection st et cid itid PJRemoteDirection st et cid itid
@@ -136,10 +136,10 @@ trySpinByCID cid i pj w = w & cWorld . lWorld . projectiles . ix pjid . prjSpin
spinFactor = 5 * (6 - fromIntegral i) spinFactor = 5 * (6 - fromIntegral i)
pjTrack :: Int -> Proj -> World -> World pjTrack :: Int -> Proj -> World -> World
pjTrack itid pj w = rotateToTarget pj w pjTrack crid pj w = rotateToTarget pj w
where where
rotateToTarget _ = fromMaybe id $ do rotateToTarget _ = fromMaybe id $ do
tpos <- w ^? itPoint . itUse . heldTargeting . tgPos . _Just tpos <- w ^? cWorld . lWorld . creatures . ix crid . crTargeting . ctPos . _Just
return $ return $
cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin
.~ turnToAmount .~ turnToAmount
@@ -147,7 +147,7 @@ pjTrack itid pj w = rotateToTarget pj w
(_prjPos pj) (_prjPos pj)
tpos tpos
(argV $ _prjAcc pj) (argV $ _prjAcc pj)
itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid --itPoint = pointerToItemLocation $ w ^?! cWorld . lWorld . itemLocations . ix itid
reduceSpinBy :: Float -> Proj -> World -> World reduceSpinBy :: Float -> Proj -> World -> World
reduceSpinBy x pj = cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin *~ x reduceSpinBy x pj = cWorld . lWorld . projectiles . ix (_prjID pj) . prjSpin *~ x
+3 -2
View File
@@ -59,10 +59,11 @@ worldSPic cfig w =
pointIsClose = cullPoint cfig w pointIsClose = cullPoint cfig w
anyTargeting :: Configuration -> World -> SPic anyTargeting :: Configuration -> World -> SPic
anyTargeting cfig w = (mempty, pictures $ IM.elems $ IM.mapMaybe f $ _crInv cr) anyTargeting cfig w = fromMaybe mempty $ do
tt <- cr ^? crTargeting . ctType . _Just
return $ noShape $ drawTargeting tt cr cfig w
where where
cr = you w cr = you w
f it = fmap (\g -> drawTargeting g it cr cfig w) (it ^? itUse . heldTargeting . tgType)
drawCreature :: Creature -> SPic drawCreature :: Creature -> SPic
drawCreature cr = case _crType cr of drawCreature cr = case _crType cr of
+48 -61
View File
@@ -1,98 +1,85 @@
module Dodge.Targeting where module Dodge.Targeting where
import Color import Color
import Dodge.Item.Weapon.LaserPath
import Dodge.Creature.Test
import Dodge.Base.Coordinate
import Dodge.Base.Collide
import Dodge.Zoning.Creature
import Geometry.Vector
import FoldableHelp
import Dodge.Data.World
import qualified SDL
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import LensHelp
import Data.Maybe import Data.Maybe
import Dodge.Base.Collide
import Dodge.Base.Coordinate
import Dodge.Creature.Test
import Dodge.Data.World
import Dodge.Item.Weapon.LaserPath
import Dodge.Zoning.Creature
import FoldableHelp
import Geometry.Vector
import LensHelp
import qualified SDL
updateTargeting :: TargetType -> Item -> Creature -> World -> Targeting -> (World, Targeting) updateTargeting :: TargetType -> Creature -> World -> World
updateTargeting tu = case tu of updateTargeting tu = case tu of
TargetLaser -> targetLaserUpdate TargetLaser -> targetLaserUpdate'
TargetRBPress -> targetUpdateWith targetRBPressUpdate TargetRBPress -> upCT (flip targetRBPressUpdate . _crTargeting)
TargetRBLine -> targetUpdateWith targetRBPressUpdate TargetRBLine -> upCT (flip targetRBPressUpdate . _crTargeting)
TargetRBCreature -> targetRBCreatureUp TargetRBCreature -> upCT targetRBCreatureUp
TargetCursor -> targetUpdateWith targetCursorUpdate TargetCursor -> upCT (flip targetCursorUpdate . _crTargeting)
targetRBCreatureUp :: Item -> Creature -> World -> Targeting -> (World, Targeting) upCT :: (Creature -> World -> CreatureTargeting) -> Creature -> World -> World
targetRBCreatureUp it cr w t upCT f cr w = w & cWorld . lWorld . creatures . ix (_crID cr) . crTargeting .~ f cr w
| not $ _itIsHeld it =
( w targetRBCreatureUp :: Creature -> World -> CreatureTargeting
, t targetRBCreatureUp cr w
& tgID .~ Nothing | SDL.ButtonRight `M.member` _mouseButtons (_input w) && isJust (t ^? ctID . _Just)
& tgPos .~ Nothing
& tgActive .~ False
)
| SDL.ButtonRight `M.member` _mouseButtons (_input w) && isJust (t ^? tgID . _Just)
&& canSeeTarget = && canSeeTarget =
(w, t & updatePos & tgActive .~ True) (t & updatePos & ctActive .~ True)
| otherwise = (w, t & tgID .~ fmap _crID newtarg & updatePos & tgActive .~ False) | otherwise = t & ctID .~ fmap _crID newtarg & updatePos & ctActive .~ False
where where
t = _crTargeting cr
newtarg = newtarg =
safeMinimumOn (dist mwp . _crPos) safeMinimumOn (dist mwp . _crPos)
. filter (canseepos . _crPos) . filter (canseepos . _crPos)
$ crsNearCirc mwp 40 w $ crsNearCirc mwp 40 w
canseepos p = hasLOS (_crPos cr) p w canseepos p = hasLOS (_crPos cr) p w
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
updatePos t' = t' & tgPos .~ posFromMaybeID (_tgID t') updatePos t' = t' & ctPos .~ posFromMaybeID (_ctID t')
posFromMaybeID Nothing = Nothing posFromMaybeID Nothing = Nothing
posFromMaybeID (Just i) = w ^? cWorld . lWorld . creatures . ix i . crPos posFromMaybeID (Just i) = w ^? cWorld . lWorld . creatures . ix i . crPos
canSeeTarget = fromMaybe False $ do canSeeTarget = fromMaybe False $ do
cid <- t ^? tgID . _Just cid <- t ^? ctID . _Just
cpos <- w ^? cWorld . lWorld . creatures . ix cid . crPos cpos <- w ^? cWorld . lWorld . creatures . ix cid . crPos
Just $ hasLOS cpos (_crPos cr) w Just $ hasLOS cpos (_crPos cr) w
targetUpdateWith :: targetCursorUpdate :: World -> CreatureTargeting -> CreatureTargeting
(World -> Targeting -> Targeting) -> targetCursorUpdate w ct =
Item -> ct
Creature -> & ctPos . _Just .~ mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
World -> & ctActive .~ True
Targeting ->
(World, Targeting)
targetUpdateWith f it _ w t
| _itIsHeld it = (w, f w t)
| otherwise = (w, t)
targetCursorUpdate :: World -> Targeting -> Targeting targetRBPressUpdate :: World -> CreatureTargeting -> CreatureTargeting
targetCursorUpdate w t
| SDL.ButtonRight `M.member` _mouseButtons (_input w) =
t
& tgPos . _Just .~ mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
& tgActive .~ True
| otherwise =
t & tgPos %~ const Nothing
& tgActive .~ False
targetRBPressUpdate :: World -> Targeting -> Targeting
targetRBPressUpdate w t targetRBPressUpdate w t
| SDL.ButtonRight `M.member` _mouseButtons (_input w) = | SDL.ButtonRight `M.member` _mouseButtons (_input w) =
t t
& tgPos %~ maybe (Just $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos)) Just & ctPos %~ maybe (Just $ mouseWorldPos (w ^. input) (w ^. cWorld . camPos)) Just
& tgActive .~ True & ctActive .~ True
| otherwise = | otherwise =
t & tgPos %~ const Nothing t
& tgActive .~ False & ctPos %~ const Nothing
& ctActive .~ False
targetLaserUpdate :: Item -> Creature -> World -> Targeting -> (World, Targeting) targetLaserUpdate' :: Creature -> World -> World
targetLaserUpdate _ cr w t targetLaserUpdate' cr w = let (w', ct') = targetLaserUpdate cr w (_crTargeting cr)
in w' & cWorld . lWorld . creatures . ix (_crID cr) . crTargeting .~ ct'
targetLaserUpdate :: Creature -> World -> CreatureTargeting -> (World, CreatureTargeting)
targetLaserUpdate cr w t
| crIsAiming cr = | crIsAiming cr =
( addLaserPic w ( addLaserPic w
, t , t
& tgPos .~ fmap fst mp & ctPos .~ fmap fst mp
& tgActive .~ True & ctActive .~ True
) )
| otherwise = | otherwise =
( w ( w
, t & tgPos %~ const Nothing , t & ctPos %~ const Nothing
& tgActive .~ False & ctActive .~ False
) )
where where
(mp, _) = reflectLaserAlong 0.2 sp ep w (mp, _) = reflectLaserAlong 0.2 sp ep w
+15 -16
View File
@@ -9,21 +9,20 @@ import LensHelp
import Picture import Picture
import ShortShow import ShortShow
drawTargeting :: TargetType -> Item -> Creature -> Configuration -> World -> Picture drawTargeting :: TargetType -> Creature -> Configuration -> World -> Picture
drawTargeting td = case td of drawTargeting td = case td of
-- NoTargetDraw -> \_ _ _ _ -> mempty
TargetRBCreature -> targetRBCreatureDraw TargetRBCreature -> targetRBCreatureDraw
TargetRBLine -> targetDistanceDraw TargetRBLine -> targetDistanceDraw
TargetLaser -> \_ _ _ _ -> mempty TargetLaser -> \_ _ _ -> mempty
TargetRBPress -> targetSimpleDraw TargetRBPress -> targetSimpleDraw
TargetCursor -> targetSimpleDraw TargetCursor -> targetSimpleDraw
targetSimpleDraw :: Item -> Creature -> Configuration -> World -> Picture targetSimpleDraw :: Creature -> Configuration -> World -> Picture
targetSimpleDraw = targetDraw $ const activeTargetCursorPic targetSimpleDraw = targetDraw $ activeTargetCursorPic
targetDistanceDraw :: Item -> Creature -> Configuration -> World -> Picture targetDistanceDraw :: Creature -> Configuration -> World -> Picture
targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do targetDistanceDraw cr cfig w = fromMaybe mempty $ do
p <- itm ^? itUse . heldTargeting . tgPos . _Just p <- cr ^? crTargeting . ctPos . _Just
let p1 = worldPosToScreen cam p let p1 = worldPosToScreen cam p
mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos) mwp = mouseWorldPos (w ^. input) (w ^. cWorld . camPos)
p2 = worldPosToScreen cam mwp p2 = worldPosToScreen cam mwp
@@ -37,15 +36,15 @@ targetDistanceDraw itm _ cfig w = fromMaybe mempty $ do
where where
cam = w ^. cWorld . camPos cam = w ^. cWorld . camPos
targetDraw :: (Item -> Picture) -> Item -> Creature -> Configuration -> World -> Picture targetDraw :: Picture -> Creature -> Configuration -> World -> Picture
targetDraw f it _ cfig w = fromMaybe mempty $ do targetDraw f cr cfig w = fromMaybe mempty $ do
p <- it ^? itUse . heldTargeting . tgPos . _Just p <- cr ^? crTargeting . ctPos . _Just
return $ return $
winScale cfig $ winScale cfig $
setLayer FixedCoordLayer $ setLayer FixedCoordLayer $
color white $ color white $
uncurryV translate (worldPosToScreen cam p) $ uncurryV translate (worldPosToScreen cam p) $
f it f
where where
cam = w ^. cWorld . camPos cam = w ^. cWorld . camPos
@@ -63,11 +62,11 @@ transMidLine p1 p2 = translate 20 (f p1 p2) . uncurryV translate (0.5 *.* (p1 +.
| x > x' = min 10 (x - x') | x > x' = min 10 (x - x')
| otherwise = max (-10) (x - x') | otherwise = max (-10) (x - x')
targetRBCreatureDraw :: Item -> Creature -> Configuration -> World -> Picture targetRBCreatureDraw :: Creature -> Configuration -> World -> Picture
targetRBCreatureDraw = targetDraw thepic targetRBCreatureDraw cr = targetDraw thepic cr
where where
thepic it thepic
| _tgActive $ _heldTargeting $ _itUse it = activeTargetCursorPic | _ctActive $ _crTargeting $ cr = activeTargetCursorPic
| otherwise = targetCursorPic | otherwise = targetCursorPic
targCorner :: Picture targCorner :: Picture