Fold together useDelay and itemTriggerType

This commit is contained in:
2025-07-03 22:25:32 +01:00
parent 8a00450e3f
commit a207073846
12 changed files with 404 additions and 365 deletions
+39 -39
View File
@@ -16,45 +16,45 @@ itemTriggerType itm = case itm ^. itType of
heldTriggerType :: HeldItemType -> TriggerType
heldTriggerType = \case
BANGSTICK{} -> HammerTrigger
REWINDER -> HammerTrigger
TIMESTOPPER -> HammerTrigger
TIMESCROLLER -> HammerTrigger
PISTOL -> HammerTrigger
MACHINEPISTOL -> AutoTrigger
AUTOPISTOL -> AutoTrigger
SMG -> AutoTrigger
BANGCONE -> HammerTrigger
BLUNDERBUSS -> HammerTrigger
GRAPECANNON{} -> HammerTrigger
MINIGUNX{} -> AutoTrigger
BANGSTICK{} -> HammerTrigger 8
REWINDER -> HammerTrigger 20
TIMESTOPPER -> HammerTrigger 20
TIMESCROLLER -> HammerTrigger 20
PISTOL -> HammerTrigger 6
MACHINEPISTOL -> WarmUpCoolDown 50 100 200
AUTOPISTOL -> AutoTrigger 8
SMG -> AutoTrigger 8
BANGCONE -> HammerTrigger 20
BLUNDERBUSS -> HammerTrigger 20
GRAPECANNON{} -> HammerTrigger 20
MINIGUNX{} -> WarmUpNoDelay 100
--VOLLEYGUN i -> BurstTrigger $ fmap (3*) [1 .. i-1]
VOLLEYGUN i -> VolleyGunTrigger i
RIFLE -> HammerTrigger
ALTERIFLE -> HammerTrigger
AUTORIFLE -> AutoTrigger
BURSTRIFLE -> BurstTrigger [3,6]
BANGROD -> HammerTrigger
ELEPHANTGUN -> HammerTrigger
AMR -> HammerTrigger
AUTOAMR -> AutoTrigger
SNIPERRIFLE -> HammerTrigger
FLAMESPITTER -> BurstTrigger [1..9]
FLAMETHROWER -> AutoTrigger
FLAMETORRENT -> AutoTrigger
FLAMEWALL -> AutoTrigger
BLOWTORCH -> AutoTrigger
SPARKGUN -> AutoTrigger
TESLAGUN -> AutoTrigger
LASER -> AutoTrigger
TRACTORGUN -> AutoTrigger
RLAUNCHER -> HammerTrigger
RLAUNCHERX{} -> HammerTrigger
GLAUNCHER -> HammerTrigger
POISONSPRAYER -> AutoTrigger
SHATTERGUN -> HammerTrigger
TORCH -> AutoTrigger
VOLLEYGUN i -> VolleyGunTrigger i 15
RIFLE -> HammerTrigger 6
ALTERIFLE -> HammerTrigger 6
AUTORIFLE -> AutoTrigger 6
BURSTRIFLE -> BurstTrigger [3,6] 8 -- time last used gets updated after last burst fire
BANGROD -> HammerTrigger 12
ELEPHANTGUN -> HammerTrigger 12
AMR -> HammerTrigger 12
AUTOAMR -> AutoTrigger 12
SNIPERRIFLE -> HammerTrigger 12
FLAMESPITTER -> BurstTrigger [1..9] 6
FLAMETHROWER -> NoTrigger
FLAMETORRENT -> NoTrigger
FLAMEWALL -> NoTrigger
BLOWTORCH -> NoTrigger
SPARKGUN -> NoTrigger
TESLAGUN -> NoTrigger
LASER -> NoTrigger
TRACTORGUN -> NoTrigger
RLAUNCHER -> HammerTrigger 20
RLAUNCHERX{} -> HammerTrigger 20
GLAUNCHER -> HammerTrigger 20
POISONSPRAYER -> NoTrigger
SHATTERGUN -> HammerTrigger 20
TORCH -> NoTrigger
FLATSHIELD -> NoTrigger
KEYCARD{} -> NoTrigger
BLINKER -> AlwaysSingleTrigger
BLINKERUNSAFE -> AlwaysSingleTrigger
BLINKER -> HammerTrigger 20
BLINKERUNSAFE -> HammerTrigger 20
+23 -21
View File
@@ -1,4 +1,4 @@
{-# LANGUAGE LambdaCase #-}
--{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.Impulse.UseItem (useItem) where
@@ -19,8 +19,9 @@ useItem :: Int -> PressType -> World -> Maybe World
useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
itmloc <- allInvLocs (_crInv cr) ^? ix invid . _2
let usedloc = chooseUseLocation itmloc
useItemLoc cr usedloc pt w
useItemLoc cr itmloc pt w
-- let usedloc = chooseUseLocation itmloc
-- useItemLoc cr usedloc pt w
useItemLoc :: Creature -> LocationLDT ItemLink OItem -> PressType -> World -> Maybe World
useItemLoc cr loc pt w
@@ -50,29 +51,30 @@ useItemLoc cr loc pt w
, pt == InitialPress
, Just invid' <- itm ^? itLocation . ilInvID =
return $ toggleEquipmentAt invid' cr w
| otherwise = Nothing
| otherwise = (\loc' -> useItemLoc cr loc' pt w) =<< locUp loc
-- ie try location above
where
sf = loc ^. locLDT . ldtValue . _2
ldt = loc ^. locLDT
itm = ldt ^. ldtValue . _1
chooseUseLocation :: LocationLDT ItemLink OItem -> LocationLDT ItemLink OItem
chooseUseLocation loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itType . ibtEquip = loc
| isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
loc
| sf <- loc ^. locLDT . ldtValue . _2
, structureUseAtLoc sf =
loc
| otherwise = maybe loc chooseUseLocation $ locUp loc
structureUseAtLoc :: ItemStructuralFunction -> Bool
structureUseAtLoc = \case
HeldPlatformSF -> True
UnderBarrelPlatformSF -> True
GadgetPlatformSF -> True
MapperSF -> True
_ -> False
--chooseUseLocation :: LocationLDT ItemLink OItem -> LocationLDT ItemLink OItem
--chooseUseLocation loc
-- | isJust $ loc ^? locLDT . ldtValue . _1 . itType . ibtEquip = loc
-- | isJust $ loc ^? locLDT . ldtValue . _1 . itUse . uaParams . apProjectiles . ix 0 =
-- loc
-- | sf <- loc ^. locLDT . ldtValue . _2
-- , structureUseAtLoc sf =
-- loc
-- | otherwise = maybe loc chooseUseLocation $ locUp loc
--
--structureUseAtLoc :: ItemStructuralFunction -> Bool
--structureUseAtLoc = \case
-- HeldPlatformSF -> True
-- UnderBarrelPlatformSF -> True
-- GadgetPlatformSF -> True
-- MapperSF -> True
-- _ -> False
activateDetonator :: LDTree ItemLink OItem -> World -> World
activateDetonator det = fromMaybe id $ do
+8 -7
View File
@@ -3,9 +3,10 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.HeldUse
import Dodge.BaseTriggerType
import Dodge.Data.DoubleTree
import Dodge.Item.Orientation
import Dodge.Item.UseDelay
import Control.Applicative
import Control.Monad
import qualified Data.Map.Strict as M
@@ -166,26 +167,26 @@ invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
w & pointerToItem itm . itParams . wTime
%~ (max 0 . subtract 1)
HELD MACHINEPISTOL{}
| fromMaybe 0 (itm ^? itParams . wTime) >= _coolEnd (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) >= _coolEnd (itemTriggerType itm) ->
w & pointerToItem itm . itParams . wTime
.~ 0
& pointerToItem itm . itParams . coolSound .~ Nothing
| fromMaybe 0 (itm ^? itParams . wTime) == _coolStart (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) == _coolStart (itemTriggerType itm) ->
w
& randGen .~ g
& pointerToItem itm . itParams . wTime +~ 1
& pointerToItem itm . itParams . coolSound ?~ sid
& soundContinue (CrWeaponSound (_crID cr) (fromIntegral $ _itID itm)) (_crPos cr) sid (Just 1)
| fromMaybe 0 (itm ^? itParams . wTime) > _coolStart (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) > _coolStart (itemTriggerType itm) ->
w
& pointerToItem itm . itParams . wTime +~ 1
& soundContinue (CrWeaponSound (_crID cr) (fromIntegral $ _itID itm)) (_crPos cr) (fromMaybe undefined (itm ^? itParams . coolSound . _Just)) (Just 1)
| itm ^? itParams . isWarming == Just True ->
w
& pointerToItem itm . itParams . isWarming .~ False
| fromMaybe 0 (itm ^? itParams . wTime) >= _warmStart (useDelay itm) ->
| fromMaybe 0 (itm ^? itParams . wTime) >= _warmStart (itemTriggerType itm) ->
w & pointerToItem itm . itParams . wTime
.~ _coolStart (useDelay itm)
.~ _coolStart (itemTriggerType itm)
| otherwise ->
w & pointerToItem itm . itParams . wTime
.~ 0
@@ -219,7 +220,7 @@ tryUseParent loc w = fromMaybe w $ do
t <- locUp loc
let t' = t ^. locLDT
cr <- w ^? cWorld . lWorld . creatures . ix 0
return $ heldEffectNoHammerCheck t' cr w
return $ heldEffect InitialPress t' cr w
trySynthBullet :: LocationLDT ItemLink OItem -> World -> World
trySynthBullet loc w = fromMaybe w $ do
+16 -6
View File
@@ -1,18 +1,28 @@
{-# LANGUAGE StrictData #-}
--{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.TriggerType where
import Control.Lens
--import Data.Aeson
--import Data.Aeson.TH
data TriggerType
= AutoTrigger
| HammerTrigger
= AutoTrigger Int
| HammerTrigger Int
| NoTrigger
| AlwaysSingleTrigger
| BurstTrigger [Int]
| VolleyGunTrigger Int
-- | AlwaysSingleTrigger Int
| BurstTrigger {_burstFrames :: [Int], _burstRate :: Int}
| VolleyGunTrigger {_volleyNumBarrels::Int, _volleyRate :: Int}
| WarmUpCoolDown
{ _warmStart :: Int
, _coolStart :: Int
, _coolEnd :: Int
}
| WarmUpNoDelay
{ _warmMax :: Int
}
deriving (Eq, Show, Read)
makeLenses ''TriggerType
--deriveJSON defaultOptions ''TriggerType
-8
View File
@@ -12,14 +12,6 @@ data ItemUseDelay -- should just be Delay
| FixedRate
{ _rateMax :: Int
}
| WarmUpNoDelay
{ _warmMax :: Int
}
| WarmUpCoolDown
{ _warmStart :: Int
, _coolStart :: Int
, _coolEnd :: Int
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''ItemUseDelay
+95 -73
View File
@@ -4,7 +4,7 @@
module Dodge.HeldUse (
gadgetEffect,
heldEffectNoHammerCheck,
heldEffect,
mcUseHeld,
heldEffectMuzzles,
) where
@@ -23,13 +23,11 @@ import Dodge.Creature.Radius
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.Muzzle
import Dodge.Data.UseDelay
import Dodge.Data.World
import Dodge.Gas
import Dodge.Inventory.Lock
import Dodge.Inventory.Path
import Dodge.Item.HeldOffset
import Dodge.Item.UseDelay
import Dodge.Item.Weapon.Bullet
import Dodge.Item.Weapon.Shatter
import Dodge.Projectile.Create
@@ -61,17 +59,8 @@ gadgetEffect pt loc
| otherwise = const id
heldEffect :: PressType -> LDTree ItemLink OItem -> Creature -> World -> World
heldEffect = useTimeCheck . hammerCheck heldEffectMuzzles
heldEffectNoHammerCheck :: LDTree ItemLink OItem -> Creature -> World -> World
heldEffectNoHammerCheck = useTimeCheck heldEffectMuzzles
type ChainEffect =
(LDTree ItemLink OItem -> Creature -> World -> World) ->
LDTree ItemLink OItem ->
Creature ->
World ->
World
heldEffect = hammerCheck heldEffectMuzzles
--heldEffect = useTimeCheck . hammerCheck heldEffectMuzzles
hammerCheck ::
(LDTree ItemLink OItem -> Creature -> World -> World) ->
@@ -80,25 +69,54 @@ hammerCheck ::
Creature ->
World ->
World
hammerCheck f pt it cr w
| BurstTrigger is <- itemTriggerType (it ^. ldtValue . _1)
, pt == InitialPress =
w & f it cr & cWorld . lWorld . delayedEvents .++~ map g is
| BurstTrigger{} <- itemTriggerType (it ^. ldtValue . _1) = w
| VolleyGunTrigger i <- itemTriggerType (it ^. ldtValue . _1)
, pt == InitialPress =
let (is, gen) = getVolleyBurst i (w ^. randGen)
in w & f it cr
& cWorld . lWorld . delayedEvents .++~ map g is
& randGen .~ gen
| VolleyGunTrigger{} <- itemTriggerType (it ^. ldtValue . _1) = w
| t <- itemTriggerType (it ^. ldtValue . _1)
, t == HammerTrigger || t == AlwaysSingleTrigger
hammerCheck f pt it cr w = case itemTriggerType $ it ^. ldtValue . _1 of
WarmUpNoDelay wm
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < wm ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpNoDelay{} -> f it cr w & setwarming
WarmUpCoolDown ws _ _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < ws ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ it ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpCoolDown _ cs _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) it) < cs ->
f it cr w & setwarming
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpCoolDown{} -> w & setwarming
BurstTrigger is t
| w ^. cWorld . lWorld . lClock - t > timelastused
, pt == InitialPress ->
w & f it cr & cWorld . lWorld . delayedEvents .++~ map g is
BurstTrigger{} -> w
VolleyGunTrigger i t
| w ^. cWorld . lWorld . lClock - t > timelastused
, pt == InitialPress ->
let (is, gen) = getVolleyBurst i (w ^. randGen)
in w & f it cr
& cWorld . lWorld . delayedEvents .++~ map g is
& randGen .~ gen
VolleyGunTrigger{} -> w
HammerTrigger t
| w ^. cWorld . lWorld . lClock - t > timelastused
, isNothing $ lookup MakeAutoLink (it ^. ldtRight)
, pt /= InitialPress =
w
| otherwise = f it cr w
, pt == InitialPress ->
f it cr w
AutoTrigger t
| w ^. cWorld . lWorld . lClock - t > timelastused ->
f it cr w
_ -> w
where
cid = _crID cr
-- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also
itRef = it ^?! ldtValue . _1 . itLocation . ilInvID
setwarming =
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . isWarming
%~ const True
timelastused = it ^. ldtValue . _1 . itTimeLastUsed
g x = (x, WdWdBurstFireRepetition (_crID cr) (it ^?! ldtValue . _1 . itLocation . ilInvID))
getVolleyBurst :: (Random a, RandomGen b, Num a) => Int -> b -> ([a], b)
@@ -109,38 +127,44 @@ getVolleyBurst i g =
{- | Applies a world effect after an item use cooldown check.
input buffering?
-}
useTimeCheck :: ChainEffect
useTimeCheck f item cr w = case useDelay $ item ^. ldtValue . _1 of
FixedRate rate
| w ^. cWorld . lWorld . lClock - rate > lastused -> f item cr w
-- note that the time last used must be updated later in the chain!
FixedRate{} -> w
WarmUpNoDelay wm
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) item) < wm ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ item ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpNoDelay{} -> f item cr w & setwarming
WarmUpCoolDown ws _ _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) item) < ws ->
w & setwarming
& soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ item ^. ldtValue . _1 . itType) (Just 2)
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpCoolDown _ cs _
| _wTime (_itParams $ _ldtValue $ fmap (^. _1) item) < cs ->
f item cr w & setwarming
& cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
WarmUpCoolDown{} -> w & setwarming
NoDelay -> f item cr w
where
lastused = item ^. ldtValue . _1 . itTimeLastUsed
cid = _crID cr
setwarming =
cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . isWarming
%~ const True
-- the following is unsafe, but if ilInvID isn't correctly set we probably
-- will have problems elsewhere also
itRef = item ^?! ldtValue . _1 . itLocation . ilInvID
useTimeCheck ::
(LDTree ItemLink OItem -> Creature -> World -> World) ->
LDTree ItemLink OItem ->
Creature ->
World ->
World
useTimeCheck f item cr w = w
-- case useDelay $ item ^. ldtValue . _1 of
-- FixedRate rate
-- | w ^. cWorld . lWorld . lClock - rate > lastused -> f item cr w
-- -- note that the time last used must be updated later in the chain!
-- FixedRate{} -> w
-- WarmUpNoDelay wm
-- | _wTime (_itParams $ _ldtValue $ fmap (^. _1) item) < wm ->
-- w & setwarming
-- & soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ item ^. ldtValue . _1 . itType) (Just 2)
-- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
-- WarmUpNoDelay{} -> f item cr w & setwarming
-- WarmUpCoolDown ws _ _
-- | _wTime (_itParams $ _ldtValue $ fmap (^. _1) item) < ws ->
-- w & setwarming
-- & soundContinue (CrWeaponSound cid 0) (_crPos cr) (warmupSound $ item ^. ldtValue . _1 . itType) (Just 2)
-- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
-- WarmUpCoolDown _ cs _
-- | _wTime (_itParams $ _ldtValue $ fmap (^. _1) item) < cs ->
-- f item cr w & setwarming
-- & cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . wTime +~ 1
-- WarmUpCoolDown{} -> w & setwarming
-- NoDelay -> f item cr w
-- where
-- lastused = item ^. ldtValue . _1 . itTimeLastUsed
-- cid = _crID cr
-- setwarming =
-- cWorld . lWorld . creatures . ix cid . crInv . ix itRef . itParams . isWarming
-- %~ const True
-- -- the following is unsafe, but if ilInvID isn't correctly set we probably
-- -- will have problems elsewhere also
-- itRef = item ^?! ldtValue . _1 . itLocation . ilInvID
heldEffectMuzzles :: LDTree ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles t cr w =
@@ -422,7 +446,7 @@ applyCME itm cr cme
-- the above is quite hacky for now
_ -> failsound
where
coolstart = fromMaybe 0 $ useDelay itm ^? coolStart
coolstart = fromMaybe 0 $ itemTriggerType itm ^? coolStart
itid = itm ^?! itLocation . ilInvID -- unsafe
spush = maybe 0 itemSidePush $ itm ^? itType . ibtHeld
failsound w = case w ^? input . mouseButtons . ix SDL.ButtonLeft of
@@ -775,7 +799,7 @@ useLoadedAmmo ::
useLoadedAmmo _ _ (cme, w) Nothing = (cme, w)
useLoadedAmmo itmtree cr (_, w) (Just (mz, x, magtree)) = (,) True $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itmtree cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullet itmtree cr (mz, x, magtree) w
MuzzleShootBullet -> shootBullets itmtree cr (mz, x, magtree) w
MuzzleLaser -> creatureShootLaser itmtree cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam cr w
@@ -980,18 +1004,18 @@ magAmmoParams itm = case itm ^. itType of
-- Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
-- _ -> 0
shootBullet ::
shootBullets ::
LDTree ItemLink OItem ->
Creature ->
(Muzzle, Int, LDTree ItemLink OItem) ->
World ->
World
shootBullet itmtree cr (mz, x, magtree) w = fromMaybe w $ do
shootBullets itmtree cr (mz, x, magtree) w = fromMaybe w $ do
thebullet <- getBulletType $ fmap (^. _1) magtree
return $ foldl' (&) w (replicate x (makeBullet' thebullet (itmtree ^. ldtValue . _1) cr mz))
return $ foldl' (&) w (replicate x (shootBullet thebullet (itmtree ^. ldtValue . _1) cr mz))
makeBullet' :: Bullet -> Item -> Creature -> Muzzle -> World -> World
makeBullet' bu itm cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
shootBullet :: Bullet -> Item -> Creature -> Muzzle -> World -> World
shootBullet bu itm cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
where
bulpos = _crPos cr + rotateV (_crDir cr) moff
(moff, mrot) = heldItemOrient2D itm cr (_mzPos mz + V2 0 offset) (_mzRot mz)
@@ -1002,8 +1026,6 @@ makeBullet' bu itm cr mz w = makeBullet bu itm bulpos dir . (randGen .~ g) $ w
Just x | x /= 0 -> fst . randomR (- x, x) $ _randGen w
_ -> 0
-- & makeMuzzleSmoke mz itm cr
itemRandomOffset :: HeldItemType -> Float
itemRandomOffset = \case
BANGSTICK{} -> 0
@@ -1238,7 +1260,7 @@ mcShootLaser _ mc =
mcShootAuto :: Item -> Machine -> World -> World
mcShootAuto itm mc w
| Just (FixedRate rate) <- useDelay <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
| Just (AutoTrigger rate) <- itemTriggerType <$> mc ^? mcType . mctTurret . tuWeapon -- . itUse . heldDelay
, w ^. cWorld . lWorld . lClock - rate > lastused =
w
& cWorld . lWorld . machines . ix (_mcID mc) . mcType . mctTurret . tuWeapon
+3 -2
View File
@@ -7,7 +7,8 @@ module Dodge.Item.Display (
itemInternalValue,
) where
import Dodge.Item.UseDelay
import Dodge.BaseTriggerType
--import Dodge.Item.UseDelay
import ShortShow
import Data.Maybe
import Dodge.Data.World
@@ -42,7 +43,7 @@ itemInternalValue itm
maybeWarmupStatus :: Item -> Maybe String
maybeWarmupStatus it = case useDelay it ^? warmMax of
maybeWarmupStatus it = case itemTriggerType it ^? warmMax of
Nothing -> Nothing
--Just m -> case m - (_warmTime . _heldDelay $ _itUse it) of
Just m -> case m - _wTime (_itParams it) of
+2 -1
View File
@@ -92,7 +92,7 @@ itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
getAutoSpringLinks :: Item -> [(ItemStructuralFunction, ItemLink)]
getAutoSpringLinks itm = case itemTriggerType itm of
HammerTrigger -> [(MakeAutoSF, MakeAutoLink)]
HammerTrigger _ -> [(MakeAutoSF, MakeAutoLink)]
_ -> []
extraWeaponLinks :: Item -> [(ItemStructuralFunction, ItemLink)]
@@ -158,6 +158,7 @@ structureToPotentialFunction ldt = case ldt ^. ldtValue . _1 . itType of
ATTACH GIMBAL -> S.singleton ProjectileStabiliserSF
ATTACH GYROSCOPE -> S.singleton ProjectileStabiliserSF
HELD GLAUNCHER -> S.singleton UnderBarrelPlatformSF
HELD BURSTRIFLE -> S.singleton UnderBarrelPlatformSF
_ -> S.singleton (ldt ^. ldtValue . _2)
baseCI :: Item -> CItem
+41 -29
View File
@@ -1,4 +1,5 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Item.HeldOffset (
turretItemOffset,
twoFlatHRot,
@@ -7,20 +8,21 @@ module Dodge.Item.HeldOffset (
heldItemOrient2D,
heldItemOrient2D',
itemRelativeOrient,
locOrientation,
) where
import Dodge.Item.Orientation
import Dodge.DoubleTree
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Creature.Radius
import Dodge.Data.AimStance
import Dodge.Item.AimStance
import qualified Quaternion as Q
import Dodge.Data.ComposedItem
import Dodge.Data.Creature
import Dodge.Data.DoubleTree
import Dodge.Data.Machine
import Dodge.DoubleTree
import Dodge.Item.AimStance
import Dodge.Item.Orientation
import Geometry
import LensHelp
import qualified Quaternion as Q
turretItemOffset :: Item -> Turret -> Machine -> Point3 -> Point3
turretItemOffset it tu mc =
@@ -33,31 +35,31 @@ transToHandle itm = (-.-.- V3 x y 0)
V2 x y = handlePos itm
heldItemOrient2D :: Item -> Creature -> Point2 -> Float -> (Point2, Float)
heldItemOrient2D itm cr p a = (V2 x y, argV . Q.qToV2 $ q )
heldItemOrient2D itm cr p a = (V2 x y, argV . Q.qToV2 $ q)
where
(V3 x y _,q) = heldItemRelativeOrient itm cr (p `v2z` 0, Q.axisAngle (V3 0 0 1) a)
(V3 x y _, q) = heldItemRelativeOrient itm cr (p `v2z` 0, Q.axisAngle (V3 0 0 1) a)
heldItemOrient2D' :: OItem -> Creature -> Point2 -> Float -> (Point2, Float)
heldItemOrient2D' (itm,_,(p1,q1)) cr p a = (V2 x y, argV . Q.qToV2 $ q )
heldItemOrient2D' (itm, _, (p1, q1)) cr p a = (V2 x y, argV . Q.qToV2 $ q)
where
(V3 x y _,q) = heldItemRelativeOrient itm cr (p1 + Q.rotate q1 (p `v2z` 0), q1 * Q.axisAngle (V3 0 0 1) a)
(V3 x y _, q) = heldItemRelativeOrient itm cr (p1 + Q.rotate q1 (p `v2z` 0), q1 * Q.axisAngle (V3 0 0 1) a)
heldItemRelativeOrient
:: Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
heldItemRelativeOrient itm cr (p,q)
| Aiming {} <- _posture (_crStance cr) =
heldItemRelativeOrient ::
Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
heldItemRelativeOrient itm cr (p, q)
| Aiming{} <- _posture (_crStance cr) =
(p + aimingWeaponZeroPos cr itm `v2z` shoulderHeight, Q.qID * q)
| TwoHandFlat <- itemBaseStance itm =
| TwoHandFlat <- itemBaseStance itm =
( V3 (crRad $ cr ^. crType) 0 handD + rotate3 (twoFlatHRot cr) (transToHandle itm p)
, Q.axisAngle (V3 0 0 1) (twoFlatHRot cr) * q
)
| OneHand <- itemBaseStance itm =
( V3 (crRad (cr ^. crType) * 0.7 + handPos) (crRad (cr ^. crType) * negate 0.7) handD
+ transToHandle itm p
, Q.qID * q
)
| otherwise =
( V3 (crRad $ cr ^. crType) 0 handD
| OneHand <- itemBaseStance itm =
( V3 (crRad (cr ^. crType) * 0.7 + handPos) (crRad (cr ^. crType) * negate 0.7) handD
+ transToHandle itm p
, Q.qID * q
)
| otherwise =
( V3 (crRad $ cr ^. crType) 0 handD
+ rotate3 (strideRot cr + 1.2) (V3 (-8) 0 0 + transToHandle itm p)
, Q.axisAngle (V3 0 0 1) (strideRot cr + 1.2) * q
)
@@ -69,6 +71,13 @@ heldItemRelativeOrient itm cr (p,q)
f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
sLen = _strideLength $ _crStance cr
locOrientation :: LocationLDT ItemLink OItem -> Creature -> Point3Q
locOrientation loc cr =
heldItemRelativeOrient
(locToTop loc ^. locLDT . ldtValue . _1)
cr
(loc ^. locLDT . ldtValue . _3)
aimingWeaponZeroPos :: Creature -> Item -> Point2
aimingWeaponZeroPos cr it = aimStanceHandlePos cr it - handlePos it
@@ -81,7 +90,7 @@ aimStanceHandlePos _ it = case itemBaseStance it of
TwoHandFlat -> V2 10 0
heldItemOffset :: Item -> Creature -> Point3 -> Point3
heldItemOffset itm cr p = fst (heldItemRelativeOrient itm cr (p,Q.qID))
heldItemOffset itm cr p = fst (heldItemRelativeOrient itm cr (p, Q.qID))
shoulderHeight :: Float
shoulderHeight = 18
@@ -143,12 +152,15 @@ heldHandlePos = \case
SHATTERGUN -> V2 3 0
TORCH -> V2 3 0
FLATSHIELD -> V2 3 0
KEYCARD {} -> V2 3 0
KEYCARD{} -> V2 3 0
BLINKER -> V2 3 0
BLINKERUNSAFE -> V2 3 0
itemRelativeOrient :: LocationLDT ItemLink Item -> Creature
-> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
itemRelativeOrient loc cr
= heldItemRelativeOrient (locToTop loc ^. locLDT . ldtValue) cr
. orientLocation (V3 0 0 0,Q.qID) loc
itemRelativeOrient ::
LocationLDT ItemLink Item ->
Creature ->
(Point3, Q.Quaternion Float) ->
(Point3, Q.Quaternion Float)
itemRelativeOrient loc cr =
heldItemRelativeOrient (locToTop loc ^. locLDT . ldtValue) cr
. orientLocation (V3 0 0 0, Q.qID) loc
+51 -50
View File
@@ -1,60 +1,61 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Item.UseDelay
(useDelay
, module Dodge.Data.UseDelay
(-- useDelay
module Dodge.Data.UseDelay
) where
import Dodge.Data.UseDelay
import Control.Lens
import Dodge.Data.Item
useDelay :: Item -> ItemUseDelay
useDelay itm = case itm ^. itType of
HELD hit -> heldUseDelay hit
DETECTOR _ -> FixedRate 20
_ -> NoDelay
--useDelay :: Item -> ItemUseDelay
--useDelay itm = case itm ^. itType of
-- HELD hit -> heldUseDelay hit
-- DETECTOR _ -> FixedRate 20
-- _ -> NoDelay
heldUseDelay :: HeldItemType -> ItemUseDelay
heldUseDelay = \case
BANGSTICK _ -> FixedRate 8
REWINDER -> FixedRate 20
TIMESTOPPER -> FixedRate 20
TIMESCROLLER -> FixedRate 20
PISTOL -> FixedRate 6
AUTOPISTOL -> FixedRate 8
SMG -> FixedRate 8
MACHINEPISTOL -> WarmUpCoolDown 50 100 200
BURSTRIFLE -> FixedRate 8 -- time last used gets updated after the last burst fire
BANGCONE -> FixedRate 20
BLUNDERBUSS -> FixedRate 20
GRAPECANNON _ -> FixedRate 20
MINIGUNX _ -> WarmUpNoDelay 100
VOLLEYGUN{} -> FixedRate 15
RIFLE -> FixedRate 6
ALTERIFLE -> FixedRate 6
AUTORIFLE -> FixedRate 6
BANGROD -> FixedRate 12
ELEPHANTGUN -> FixedRate 12
AMR -> FixedRate 12
AUTOAMR -> FixedRate 12
SNIPERRIFLE -> FixedRate 12
FLAMESPITTER -> FixedRate 6
FLAMETHROWER -> NoDelay
FLAMETORRENT -> NoDelay
FLAMEWALL -> NoDelay
POISONSPRAYER -> NoDelay
BLOWTORCH -> NoDelay
SPARKGUN -> NoDelay
TESLAGUN -> NoDelay
LASER -> NoDelay
TRACTORGUN -> NoDelay
RLAUNCHER -> FixedRate 20
RLAUNCHERX{} -> FixedRate 20
GLAUNCHER -> FixedRate 20
SHATTERGUN -> FixedRate 20
BLINKER -> FixedRate 20
BLINKERUNSAFE -> FixedRate 20
TORCH -> NoDelay
FLATSHIELD -> NoDelay
KEYCARD _ -> NoDelay
--heldUseDelay :: HeldItemType -> ItemUseDelay
--heldUseDelay = \case
-- BANGSTICK _ -> FixedRate 8
-- REWINDER -> FixedRate 20
-- TIMESTOPPER -> FixedRate 20
-- TIMESCROLLER -> FixedRate 20
-- PISTOL -> FixedRate 6
-- AUTOPISTOL -> FixedRate 8
-- SMG -> FixedRate 8
-- MACHINEPISTOL -> WarmUpCoolDown 50 100 200
-- --BURSTRIFLE -> FixedRate 8 -- time last used gets updated after the last burst fire
-- BURSTRIFLE -> NoDelay
-- BANGCONE -> FixedRate 20
-- BLUNDERBUSS -> FixedRate 20
-- GRAPECANNON _ -> FixedRate 20
-- MINIGUNX _ -> WarmUpNoDelay 100
-- VOLLEYGUN{} -> FixedRate 15
-- RIFLE -> FixedRate 6
-- ALTERIFLE -> FixedRate 6
-- AUTORIFLE -> FixedRate 6
-- BANGROD -> FixedRate 12
-- ELEPHANTGUN -> FixedRate 12
-- AMR -> FixedRate 12
-- AUTOAMR -> FixedRate 12
-- SNIPERRIFLE -> FixedRate 12
-- FLAMESPITTER -> FixedRate 6
-- FLAMETHROWER -> NoDelay
-- FLAMETORRENT -> NoDelay
-- FLAMEWALL -> NoDelay
-- POISONSPRAYER -> NoDelay
-- BLOWTORCH -> NoDelay
-- SPARKGUN -> NoDelay
-- TESLAGUN -> NoDelay
-- LASER -> NoDelay
-- TRACTORGUN -> NoDelay
-- RLAUNCHER -> FixedRate 20
-- RLAUNCHERX{} -> FixedRate 20
-- GLAUNCHER -> FixedRate 20
-- SHATTERGUN -> FixedRate 20
-- BLINKER -> FixedRate 20
-- BLINKERUNSAFE -> FixedRate 20
-- TORCH -> NoDelay
-- FLATSHIELD -> NoDelay
-- KEYCARD _ -> NoDelay
-2
View File
@@ -31,8 +31,6 @@ testStringInit u = prettyShort (u ^? uvWorld . cWorld . lWorld . creatures . ix
. ix 0 . itTimeLastUsed)
<> prettyShort (u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crInv
. ix 0 . itParams . wTime)
<> prettyShort (u ^? uvWorld . cWorld . lWorld . creatures . ix 0 . crInv
. ix 0 >>= ((^? rateMax) .useDelay))
--return . foldMap (prettyLDT (show . (^. _1 . itType))) . invLDT $ _crInv cr
-- where
-- idp = invDisplayParams $ u ^. uvWorld