Cleanup combining code, flatten modules

This commit is contained in:
2024-10-01 10:01:21 +01:00
parent f69d150e00
commit 87cbaf911f
17 changed files with 143 additions and 173 deletions
+26 -15
View File
@@ -5,7 +5,7 @@ module Dodge.HeldUse
)
where
import Color.Data
import Color
import Dodge.Base.Coordinate
import Dodge.Base.Collide
import Dodge.Inventory.Lock
@@ -138,22 +138,32 @@ loadMuzzle t@(LDT _ l _) mz = fromMaybe (t,Nothing) $ do
, Just (mz, usedammo, mag)
)
makeMuzzleFlare :: Muzzle -> Item -> Creature -> World -> World
makeMuzzleFlare mz itm cr = case mz ^. mzFlareType of
makeMuzzleFlare :: Muzzle -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
makeMuzzleFlare mz itmtree cr = case mz ^. mzFlareType of
DefaultFlareType -> id
PistolFlare -> basicMuzFlare pos dir
MiniGunFlare -> makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
HeavySmokeFlare -> basicMuzFlare pos dir
LasGunFlare -> flareCircleAt (_lasColor $ _itParams itm) 0.8 (pos `v2z` 20)
LasGunFlare -> flareCircleAt (getLaserColor itmtree) 0.8 (pos `v2z` 20)
. (cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 100 (xyzV4 . _lasColor $ _itParams itm) (pos `v2z` 10))
tlsTimeRadColPos 1 100 (xyzV4 $ getLaserColor itmtree) (pos `v2z` 10))
TeslaGunFlare -> cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 100 (V3 0 0 1) (pos `v2z` 10)
where
itm = itmtree ^. ldtValue
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
dir = _crDir cr + _mzRot mz
getLaserPhaseV :: LabelDoubleTree ComposeLinkType Item -> Float
getLaserPhaseV = const 1
getLaserDamage :: LabelDoubleTree ComposeLinkType Item -> LaserType
getLaserDamage = const (DamageLaser 11)
getLaserColor :: LabelDoubleTree ComposeLinkType Item -> Color
getLaserColor = const yellow
basicMuzFlare :: Point2 -> Float -> World -> World
basicMuzFlare pos dir = makeTlsTimeRadColPos 2 100 (V3 1 1 0.5) (pos `v2z` 20)
. muzFlareAt (V4 10 10 1 3) (pos `v2z` 20) dir
@@ -186,9 +196,9 @@ useLoadedAmmo :: LabelDoubleTree ComposeLinkType Item
-> (CumulativeMuzzleEffect,World)
useLoadedAmmo _ _ (cme,w) (_,Nothing) = (cme, w)
useLoadedAmmo itmtree cr (cme,w) (mzid,Just (mz,x,magtree)) = (,) (cme & cmeSound .~ True) $
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itm cr $ case _mzEffect mz of
removeAmmoFromMag x mid cr . makeMuzzleFlare mz itmtree cr $ case _mzEffect mz of
MuzzleShootBullet -> shootBullet itmtree cr (mz,x,magtree) w
MuzzleLaser -> shootLaser itm cr mz w
MuzzleLaser -> shootLaser itmtree cr mz w
MuzzleTesla -> shootTeslaArc itm cr mz w
MuzzleTractor -> shootTractorBeam cr w
MuzzleLauncher -> createProjectile magtree mz itmtree cr w
@@ -241,18 +251,19 @@ tractorBeamAt pos outpos dir power =
where
d = unitVectorAtAngle dir * power
shootLaser :: Item -> Creature -> Muzzle -> World -> World
shootLaser itm cr mz w = w
shootLaser :: LabelDoubleTree ComposeLinkType Item -> Creature -> Muzzle -> World -> World
shootLaser itmtree cr mz w = w
& randGen .~ g
& cWorld . lWorld . lasers
.:~ LaserStart
{ _lpType = DamageLaser . _lasDamage $ _itParams itm
, _lpPhaseV = _phaseV $ _itParams itm
{ _lpType = getLaserDamage itmtree
, _lpPhaseV = getLaserPhaseV itmtree
, _lpPos = pos
, _lpDir = dir
, _lpColor = _lasColor $ _itParams itm
, _lpColor = getLaserColor itmtree
}
where
itm = itmtree ^. ldtValue
pos = _crPos cr + rotateV (_crDir cr) (_mzPos mz + aimingWeaponZeroPos cr itm)
(a,g) = randomR (-inacc,inacc) $ _randGen w
inacc = _mzInaccuracy mz
@@ -412,12 +423,12 @@ doGenFloat (UniRandFloat x y) g = randomR (x,y) g
-- & itUse . heldParams . rifling .~ rifl
mcShootLaser :: Item -> Machine -> World -> World
mcShootLaser it mc = cWorld . lWorld . lasers .:~ lasRayAt (_lasColor $ _itParams it) dam phasev pos dir
mcShootLaser _ mc = cWorld . lWorld . lasers .:~ lasRayAt yellow dam phasev pos dir
where
pos = _mcPos mc +.+ 20 *.* unitVectorAtAngle dir
dir = mc ^?! mcType . _McTurret . tuDir
phasev = _phaseV . _itParams $ it
dam = _lasDamage $ _itParams it
phasev = 1
dam = 11
-- | assumes that the item is held
shootTeslaArc :: Item -> Creature -> Muzzle -> World -> World