From ff84363a1354d1133a266c2768c8e91da20d0699 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 21 Feb 2022 22:42:19 +0000 Subject: [PATCH] Cleanup --- src/Dodge/Combine/Combinations.hs | 6 +++- src/Dodge/Creature/YourControl.hs | 4 +-- src/Dodge/Data.hs | 43 ++++++++++++++-------------- src/Dodge/Default.hs | 2 ++ src/Dodge/Default/Weapon.hs | 4 +-- src/Dodge/Item/Attachment/Data.hs | 22 +++++++++----- src/Dodge/Item/Weapon/BulletGuns.hs | 16 ++++------- src/Dodge/Item/Weapon/ExtraEffect.hs | 26 ----------------- src/Dodge/Item/Weapon/Grenade.hs | 6 ++-- src/Dodge/Item/Weapon/Launcher.hs | 8 +++--- src/Dodge/Update/Camera.hs | 41 +++++++++++++------------- 11 files changed, 79 insertions(+), 99 deletions(-) diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index ba97c75d0..068f89175 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -112,7 +112,7 @@ moduleCombinations = ] ) , ( ModBulletTarget - , bulletWeapons + , launcher : bulletWeapons , [amod [TELEPORTMODULE,MICROCHIP] "+TELEPORT" (itUse . useMods .:~ withPositionWallCheck (const . const mouseWorldPos)) ,amod [TELEPORTMODULE] "+DIRECTEDTELE" makeDirectedTele ] @@ -121,7 +121,11 @@ moduleCombinations = where makeDirectedTele it = it & itEffect .~ rbSetTarget & itUse . useMods .:~ withPosDirWallCheck directedTelPos +-- for the camera: the simplest option is to remove all zoom/offset & itUse . useAim . aimZoom . itZoomFac .~ 1 + & itUse . useAim . aimRange .~ 0 +-- a better option would be to involve a "scope" centered on the firing +-- position directedTelPos it cr w = (p,a) where p = fromMaybe (_crPos cr) $ do diff --git a/src/Dodge/Creature/YourControl.hs b/src/Dodge/Creature/YourControl.hs index 24fa073ac..224e76785 100644 --- a/src/Dodge/Creature/YourControl.hs +++ b/src/Dodge/Creature/YourControl.hs @@ -58,8 +58,8 @@ wasdWithAiming w speed i cr isAiming = _posture (_crStance cr) == Aiming isReloading = _posture (_crStance cr) == Reloading mouseDir = case w ^? creatures . ix i . crInv . ix (_crInvSel (_creatures w IM.! i)) - . itAttachment of - Just ItScope{_scopePos = p} -> normalizeAngle $ argV + . itScope . scopePos of + Just p -> normalizeAngle $ argV $ p +.+ 2 / _cameraZoom w *.* rotateV (_cameraRot w) (_mousePos w) _ -> normalizeAngle $ argV (_mousePos w) + _cameraRot w diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index e1da2ee26..0fee2108d 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -356,28 +356,27 @@ data ItemConsumption { _itAmount :: Int } | NoConsumption -data Item - = Item - { _itName :: String - , _itConsumption :: ItemConsumption - , _itUse :: ItemUse - , _itEquipPict :: Creature -> Int -> SPic - , _itScroll :: Float -> Creature -> Item -> Item - , _itType :: CombineType - , _itAttachment :: ItAttachment - , _itID :: Maybe Int - , _itEffect :: ItEffect - , _itInvSize :: Float - , _itInvDisplay :: Item -> [String] - , _itInvColor :: Color - , _itTargeting :: Maybe (World -> Maybe Point2, Int -> Item -> Creature -> World -> Picture) - , _itDimension :: ItemDimension - , _itCurseStatus :: CurseStatus - , _itParams :: ItemParams - , _itTweaks :: ItemTweaks - , _itModules :: M.Map ModuleSlot ItemModule - } - +data Item = Item + { _itName :: String + , _itConsumption :: ItemConsumption + , _itUse :: ItemUse + , _itEquipPict :: Creature -> Int -> SPic + , _itScroll :: Float -> Creature -> Item -> Item + , _itType :: CombineType + , _itAttachment :: ItAttachment + , _itID :: Maybe Int + , _itEffect :: ItEffect + , _itInvSize :: Float + , _itInvDisplay :: Item -> [String] + , _itInvColor :: Color + , _itTargeting :: Maybe (World -> Maybe Point2, Int -> Item -> Creature -> World -> Picture) + , _itDimension :: ItemDimension + , _itCurseStatus :: CurseStatus + , _itParams :: ItemParams + , _itTweaks :: ItemTweaks + , _itModules :: M.Map ModuleSlot ItemModule + , _itScope :: Scope + } data ModuleSlot = ModBullet | ModRifleMag diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index c017f3182..cfeb54cd0 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -156,6 +156,7 @@ defaultEquipment = Item , _itTweaks = NoTweaks , _itTargeting = Nothing , _itModules = M.empty + , _itScope = NoScope } defaultItZoom :: ItZoom defaultItZoom = ItZoom 20 0.2 1 @@ -180,6 +181,7 @@ defaultConsumable = Item , _itDimension = defItDimCol blue , _itTweaks = NoTweaks , _itModules = M.empty + , _itScope = NoScope } defaultApplyDamage :: [DamageType] -> Creature -> (World -> World, Creature) defaultApplyDamage ds cr = (id, doPoisonDam $ foldl' (flip $ \d c -> snd $ applyIndividualDamage d c) cr ds') diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index abde267cd..241b063da 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -103,16 +103,15 @@ defaultGun = Item , _itModules = M.fromList [(ModBullet , DefaultModule) ,(ModBulletTarget,DefaultModule) ] + , _itScope = NoScope } defaultCraftable :: Item defaultCraftable = Item { _itName = "default" , _itType = NoCombineType , _itCurseStatus = Uncursed --- , _itIdentity = Generic , _itConsumption = NoConsumption , _itUse = NoUse --- , _itZoom = ItZoom 20 0.2 1 , _itEquipPict = pictureWeaponOnAim , _itScroll = \_ _ -> id , _itAttachment = NoItAttachment @@ -126,6 +125,7 @@ defaultCraftable = Item , _itDimension = defItDimCol green , _itTweaks = NoTweaks , _itModules = M.empty + , _itScope = NoScope } defItDim :: ItemDimension defItDim = ItemDimension diff --git a/src/Dodge/Item/Attachment/Data.hs b/src/Dodge/Item/Attachment/Data.hs index a016cf008..4d5e193f4 100644 --- a/src/Dodge/Item/Attachment/Data.hs +++ b/src/Dodge/Item/Attachment/Data.hs @@ -8,13 +8,7 @@ import Control.Lens import qualified Data.Sequence as Seq data ItAttachment - = ItScope - {_scopePos :: Point2 -- ^ a camera offset - ,_scopeZoomChange :: Int - ,_scopeZoom :: Float - ,_scopeIsCamera :: Bool -- ^ if the camera offset is also the center of vision - } - | ItFuse {_itFuseTime :: Int} + = ItFuse {_itFuseTime :: Int} | ItMode {_itMode :: Int} | ItCharMode {_itCharMode :: Seq.Seq Char } | ItTargetPos { _itTargetPos :: Point2 } @@ -24,4 +18,18 @@ data ItAttachment | ItBool { _itBool :: Bool } | NoItAttachment +data Scope = NoScope + | RemoteScope + {_scopePos :: Point2 -- ^ a camera offset + ,_scopeZoom :: Float + ,_scopeIsCamera :: Bool -- ^ if the camera offset is also the center of vision + } + | ZoomScope + {_scopePos :: Point2 -- ^ a camera offset + ,_scopeZoomChange :: Int + ,_scopeZoom :: Float + ,_scopeIsCamera :: Bool -- ^ if the camera offset is also the center of vision + } + makeLenses ''ItAttachment +makeLenses ''Scope diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index d4966aaa0..bcbbbba00 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -429,7 +429,7 @@ multGun = defaultGun , _itTweaks = defaultBulletSelTweak } longGun :: Item -longGun = defaultGun +longGun = defaultGun { _itName = "LONGGUN" , _itType = LONGGUN , _itConsumption = defaultAmmo @@ -453,23 +453,17 @@ longGun = defaultGun & useAim . aimRange .~ 1 & useAim . aimStance .~ TwoHandTwist & useAim . aimZoom .~ defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} --- , _itFloorPict = longGunSPic --- , _itZoom = defaultItZoom , _itScroll = zoomLongGun - , _itAttachment = ItScope (V2 0 0) 0 1 False + , _itAttachment = NoItAttachment + , _itScope = ZoomScope (V2 0 0) 0 1 False , _itEffect = itemLaserScopeEffect } zoomLongGun :: Float -> Creature -> Item -> Item zoomLongGun x _ - | x > 0 = startZoomInLongGun - | x < 0 = startZoomOutLongGun + | x > 0 = itScope . scopeZoomChange %~ (max 5 . (+5)) + | x < 0 = itScope . scopeZoomChange %~ (min (-5) . subtract 5) | otherwise = id -startZoomInLongGun :: Item -> Item -startZoomInLongGun = itAttachment . scopeZoomChange %~ \x -> max 5 (x + 5) -startZoomOutLongGun :: Item -> Item -startZoomOutLongGun = itAttachment . scopeZoomChange %~ \x -> min (-5) (x-5) - autogunSpread :: Float autogunSpread = 0.07 diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index 9de8e4bcc..859d049a1 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -27,32 +27,6 @@ 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 ---wpRecock = ItInvEffect --- {_itInvEffect = f --- ,_itEffectCounter = 0 --- } --- where --- f _ cr invid = creatures . ix (_crID cr) . crInv . ix invid --- . itUse . useHammer . hammerPosition %~ moveHammerUp --- moveHammerUp HammerDown = HammerReleased --- moveHammerUp HammerReleased = HammerUp --- moveHammerUp HammerUp = HammerUp ---{- | ---Special recock for the bezier gun. ---Not sure of its purpose at this time... -} ---bezierRecock :: ItEffect ---bezierRecock = ItInvEffect --- {_itInvEffect = f --- ,_itEffectCounter = 0 --- } --- where --- f _ cr i = creatures . ix (_crID cr) . crInv %~ IM.adjust fOnIt i --- fOnIt it = case _itHammer it of --- HammerDown -> it & itHammer .~ HammerUp --- _ -> it & itAttachment .~ NoItAttachment -{- | Creates a laser scope and recocks the weapon. TODO add the laser scope! -} diff --git a/src/Dodge/Item/Weapon/Grenade.hs b/src/Dodge/Item/Weapon/Grenade.hs index f6f67569a..9038f758b 100644 --- a/src/Dodge/Item/Weapon/Grenade.hs +++ b/src/Dodge/Item/Weapon/Grenade.hs @@ -202,7 +202,7 @@ moveRemoteBomb itid time pID w setRemoteBombScope :: Int -> Prop -> World -> World setRemoteBombScope itid pj w' = case _itemPositions w' IM.! itid of InInv cid invid - -> w' & creatures . ix cid . crInv . ix invid . itAttachment + -> w' & creatures . ix cid . crInv . ix invid . itScope . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid)) & creatures . ix cid . crInv . ix invid . itUse . useAim . aimZoom .~ (defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}) @@ -293,7 +293,7 @@ remoteBombUnarmedPic = color (dark $ dark orange) $ circleSolid 5 retireRemoteBomb :: Int -> Int -> Int -> World -> World retireRemoteBomb itid 0 pjid w = w & pointToItem (_itemPositions w IM.! itid) %~ - ( (itAttachment . scopePos .~ V2 0 0) + ( (itScope . scopePos .~ V2 0 0) -- . (itZoom .~ defaultItZoom) . (itUse . rUse .~ const throwRemoteBomb) ) @@ -303,7 +303,7 @@ retireRemoteBomb itid t pjid w = setScope w where setScope w' = case _itemPositions w' IM.! itid of InInv cid invid -> w' - & creatures . ix cid . crInv . ix invid . itAttachment + & creatures . ix cid . crInv . ix invid . itScope . scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid)) _ -> w' pos = fromMaybe (V2 0 0) $ w ^? props . ix pjid . pjPos diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index d23b83488..4666a3d05 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -282,7 +282,7 @@ remoteLauncher = launcher & useAim . aimSpeed .~ 0.2 & useAim . aimRange .~ 0.5 & useAim . aimStance .~ TwoHandTwist - , _itAttachment = ItScope (V2 0 0) 0 1 True + , _itScope = RemoteScope (V2 0 0) 1 True -- , _itParams = ShellLauncher -- { _tweakSel = 0 -- , _tweakParams = basicAmPjMoves -- TODO change to allow tweaking rocket speed @@ -409,7 +409,7 @@ remoteShellPic t | otherwise = red retireRemoteRocket :: Int -> Int -> Int -> World -> World retireRemoteRocket itid 0 pjid w = - set (pointToItem (_itemPositions w IM.! itid) . itAttachment . scopePos) (V2 0 0) + set (pointToItem (_itemPositions w IM.! itid) . itScope . scopePos) (V2 0 0) $ set (pointToItem (_itemPositions w IM.! itid) . itUse . rUse) (const fireRemoteLauncher) (w & props %~ IM.delete pjid) retireRemoteRocket itid t pjid w = setScope w @@ -417,7 +417,7 @@ retireRemoteRocket itid t pjid w = setScope w where setScope w' = case _itemPositions w' IM.! itid of InInv cid invid -> w' - & creatures . ix cid . crInv . ix invid . itAttachment + & creatures . ix cid . crInv . ix invid . itScope . scopePos .~ (pos -.- _crPos (_creatures w' IM.! cid)) _ -> w' pos = fromMaybe (V2 0 0) $ w ^? props . ix pjid . pjPos @@ -425,6 +425,6 @@ retireRemoteRocket itid t pjid w = setScope w setRemoteScope :: Int -> Prop -> World -> World setRemoteScope itid pj w' = case w' ^? itemPositions . ix itid of Just (InInv cid' invid ) - -> w' & creatures . ix cid' . crInv . ix invid . itAttachment + -> w' & creatures . ix cid' . crInv . ix invid . itScope . scopePos .~ (_pjPos pj -.- _crPos (_creatures w' IM.! cid')) _ -> w' diff --git a/src/Dodge/Update/Camera.hs b/src/Dodge/Update/Camera.hs index 9374db86e..41a037633 100644 --- a/src/Dodge/Update/Camera.hs +++ b/src/Dodge/Update/Camera.hs @@ -32,7 +32,7 @@ updateCamera cfig = rotateCamera cfig . autoZoomCamera cfig . moveCamera . updat {- Updte the center of the screen camera center and where your avatar's view is from in world. -} moveCamera :: World -> World moveCamera w = w - & cameraCenter .~ idealPos + & cameraCenter .~ idealPos & cameraViewFrom .~ sightFrom where aimRangeFactor @@ -45,17 +45,16 @@ moveCamera w = w idealPos = camCenter +.+ rotateV (_cameraRot w) (aimRangeFactor * aimingMult *.* _mousePos w) camCenter = ypos +.+ scopeOffset - scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itAttachment . scopePos - sightFrom - | fromMaybe False $ yourItem w ^? _Just . itAttachment . scopeIsCamera - = camCenter - | otherwise = ypos + scopeOffset = fromMaybe (V2 0 0) $ yourItem w ^? _Just . itScope . scopePos + sightFrom = case yourItem w ^? _Just . itScope . scopeIsCamera of + Just True -> camCenter + _ -> ypos updateScopeZoom :: World -> World updateScopeZoom w | SDL.ButtonRight `S.member` _mouseButtons w = case w ^? creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) - . itAttachment . scopeZoomChange of + . itScope . scopeZoomChange of Just x | x > 9 -> zoomInLongGun $ zoomInLongGun w | x > 0 -> zoomInLongGun w @@ -64,9 +63,9 @@ updateScopeZoom w | otherwise -> w _ -> w | otherwise = w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) - . itAttachment %~ updateScope + . itScope %~ updateScope where - updateScope (ItScope _ _ _ bl) = ItScope (V2 0 0) 0 1 bl + updateScope (ZoomScope _ _ _ bl) = ZoomScope (V2 0 0) 0 1 bl updateScope otherAtt = otherAtt zoomSpeed :: Float @@ -74,38 +73,39 @@ zoomSpeed = 39/40 -- TODO unify zoom in and out, use scroll speed zoomInLongGun :: World -> World zoomInLongGun w - | currentZoom < 8 = over (wpPointer . itAttachment . scopePos) + | currentZoom < 8 = over (wpPointer . itScope . scopePos) (\p -> p +.+ (4-(4*zoomSpeed)) / currentZoom *.* mousep) - $ over (wpPointer . itAttachment . scopeZoom) (/ zoomSpeed) + $ over (wpPointer . itScope . scopeZoom) (/ zoomSpeed) $ decreaseScopeZoomChange w | otherwise = decreaseScopeZoomChange w where - decreaseScopeZoomChange = wpPointer . itAttachment . scopeZoomChange -~ 1 + decreaseScopeZoomChange = wpPointer . itScope . scopeZoomChange -~ 1 wpPointer = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) wp = _crInv (_creatures w IM.! 0) IM.! _crInvSel (_creatures w IM.! 0) - Just currentZoom = wp ^? itAttachment . scopeZoom + Just currentZoom = wp ^? itScope . scopeZoom mousep = rotateV (_cameraRot w) $ _mousePos w zoomOutLongGun :: World -> World zoomOutLongGun w - | currentZoom > 0.5 = over (wpPointer . itAttachment . scopeZoom) (* zoomSpeed) + | currentZoom > 0.5 = over (wpPointer . itScope . scopeZoom) (* zoomSpeed) $ increaseScopeZoomChange w | otherwise = increaseScopeZoomChange w where - increaseScopeZoomChange = wpPointer . itAttachment . scopeZoomChange +~ 1 + increaseScopeZoomChange = wpPointer . itScope . scopeZoomChange +~ 1 wpPointer = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) wp = _crInv (_creatures w IM.! 0) IM.! _crInvSel (_creatures w IM.! 0) - Just currentZoom = wp ^? itAttachment . scopeZoom + Just currentZoom = wp ^? itScope . scopeZoom ifConfigWallRotate :: Configuration -> World -> World ifConfigWallRotate cfig w | _rotate_to_wall cfig && not (SDL.ButtonRight `S.member` _mouseButtons w) - = rotateToOverlappingWall w + = rotateToOverlappingWall w | otherwise = w rotateToOverlappingWall :: World -> World -rotateToOverlappingWall w = maybe w dowallrotate theWall +rotateToOverlappingWall w = maybe w dowallrotate + $ overlapCircWallsReturnWall p (_crRad cr + 5) (IM.filter _wlRotateTo $ wallsNearPoint p w) where dowallrotate wl' = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl') - _cameraRot w rotateUsing a @@ -118,14 +118,13 @@ rotateToOverlappingWall w = maybe w dowallrotate theWall b' = fromIntegral (round b :: Int) cr = you w p = _crPos cr - theWall = overlapCircWallsReturnWall p (_crRad cr + 5) (IM.filter _wlRotateTo $ wallsNearPoint p w) rotateCameraBy :: Float -> World -> World rotateCameraBy x w = w & cameraRot +~ x & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0)) - . itAttachment . scopePos %~ rotateV x + . itScope . scopePos %~ rotateV x rotateCamera :: Configuration -> World -> World rotateCamera cfig w @@ -168,7 +167,7 @@ autoZoomCamera cfig w = w & cameraZoom %~ changeZoom -- these speeds are inverted, larger means slower zoomInSpeed = 25 zoomOutSpeed = 15 - theScopeZoom = fromMaybe 1 $ yourItem w ^? _Just . itAttachment . scopeZoom + theScopeZoom = fromMaybe 1 $ yourItem w ^? _Just . itScope . scopeZoom farWallDist :: Point2 -> Configuration -> World -> Float farWallDist p cfig w = (winFac /) . min maxViewDistance $ ssfold (> maxViewDistance) findMax 1 vps