From 08389ad4e020212d03e0785a7f10fce8e4f7d001 Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 3 Mar 2022 10:34:56 +0000 Subject: [PATCH] Cleanup, work towards unifying spayguns --- src/Dodge/Combine.hs | 2 +- src/Dodge/Combine/Combinations.hs | 11 ++--- src/Dodge/Combine/Data.hs | 3 +- src/Dodge/Creature.hs | 7 +-- src/Dodge/Data.hs | 18 +++++-- src/Dodge/Item/Weapon/BulletGun/Rod.hs | 25 ++++++++-- src/Dodge/Item/Weapon/BulletGuns.hs | 10 +--- src/Dodge/Item/Weapon/ExtraEffect.hs | 65 +++++++------------------- src/Dodge/Item/Weapon/Launcher.hs | 25 ++++++---- src/Dodge/Item/Weapon/SprayGuns.hs | 34 +++++++++++--- src/Dodge/Item/Weapon/ZoomScope.hs | 9 ++++ 11 files changed, 118 insertions(+), 91 deletions(-) create mode 100644 src/Dodge/Item/Weapon/ZoomScope.hs diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index 845bf1732..341444073 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -91,7 +91,7 @@ applyModules ms it = foldr f (it & itModules .~ ms) ms -- g ims (ims',s) = map (second (s++)) $ combineModules ims ims' combineModules :: M.Map ModuleSlot ItemModule - -> M.Map ModuleSlot ItemModule + -> M.Map ModuleSlot ItemModule -> ([String],M.Map ModuleSlot ItemModule) combineModules = mergeA (traverseMaybeMissing f) diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index 35ddbc64f..f4d84c224 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -50,12 +50,14 @@ itemCombinations = , p [p 3 PIPE,o HARDWARE] bangRod , po [BANGROD,PLANK,HARDWARE] elephantGun + , po [ELEPHANTGUN,HARDWARE,PRISM] sniperRifle , po [ELEPHANTGUN,HARDWARE,TIN] amr - , po [ELEPHANTGUN,HARDWARE,CAN] sniperRifle + , po [AMR,HARDWARE,SPRING] autoAmr , po [BANGROD,PLATE,DRUM,MOTOR] machineGun , p [p 2 TUBE,o HARDWARE] launcher - , p [p 2 TUBE,o LAUNCHER] doubleLauncher + , p [p 2 TUBE,o LAUNCHER] (launcherX 2) + , p [p 2 TUBE,o $ LAUNCHERX 2] (launcherX 3) , po [TRANSMITTER,MINIDISPLAY,LAUNCHER] remoteLauncher , po [LIGHTER,PIPE,CAN] flameStick @@ -155,10 +157,7 @@ moduleCombinations = amod cts str func = (cts,ItemModule [str] 1 func) homingLaunchers :: [Item] -homingLaunchers = - [ launcher - , doubleLauncher - ] +homingLaunchers = launcher : [launcherX i | i <- [2..3]] bulletWeapons :: [Item] bulletWeapons = [bangStick i | i <- [1..9] ] diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index 5b261c9f7..f3e327c86 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -35,6 +35,7 @@ data CombineType | BANGROD | ELEPHANTGUN | AMR + | AUTOAMR | SNIPERRIFLE | MACHINEGUN | FLAMESTICK @@ -50,7 +51,7 @@ data CombineType | SONICGUN | TRACTORGUN | LAUNCHER - | DOUBLELAUNCHER + | LAUNCHERX Int -- | TRACKINGLAUNCHER | REMOTELAUNCHER | SPRAYER diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index c839ce92d..0be1b49ed 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -170,8 +170,9 @@ testInventory = IM.fromList $ zip [0..] , incendiaryModule , bounceModule , teleportModule + , makeTypeCraftNum 1 LIGHTER , makeTypeCraftNum 5 TUBE - , makeTypeCraftNum 5 CREATURESENSOR +-- , makeTypeCraftNum 5 CREATURESENSOR , makeTypeCraftNum 3 PRISM , makeTypeCraftNum 1 MAGNET , makeTypeCraftNum 5 HARDWARE @@ -181,8 +182,8 @@ testInventory = IM.fromList $ zip [0..] , makeTypeCraftNum 3 PLANK , makeTypeCraftNum 1 MOTOR , makeTypeCraftNum 5 MICROCHIP - , makeTypeCraftNum 1 TRANSMITTER - , makeTypeCraftNum 5 AIUNIT +-- , makeTypeCraftNum 1 TRANSMITTER +-- , makeTypeCraftNum 5 AIUNIT ] stackedInventory :: IM.IntMap Item stackedInventory = IM.fromList $ zip [0..] diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 49b5a6f48..64bd29766 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -399,9 +399,9 @@ data ModuleSlot data ItemModule = DefaultModule | ItemModule - { _modName :: [String] - , _modSize :: Int - , _modModification :: Item -> Item + { _modName :: [String] + , _modSize :: Int + , _modModification :: Item -> Item } data ItemDimension = ItemDimension @@ -549,6 +549,14 @@ data TweakParam = TweakParam , _showTweak :: Int -> String , _nameTweak :: String } +data Nozzle = Nozzle + { _nzPressure :: Int + , _nzDir :: Float + , _nzMaxWalkAngle :: Float + , _nzCurrentWalkAngle :: Float + , _nzWalkSpeed :: Float + , _nzLength :: Float + } data GunBarrels = MultiBarrel { _brlSpread :: BarrelSpread @@ -579,6 +587,9 @@ data ItemParams { _nozzleSpread :: Float , _nozzleNum :: Int } + | Sprayer' + { _sprayerNozzles :: [Nozzle] + } | AngleWalk { _maxWalkAngle :: Float , _currentWalkAngle :: Float @@ -963,3 +974,4 @@ makeLenses ''Gust makeLenses ''GunBarrels makeLenses ''ItemModule makeLenses ''Targeting +makeLenses ''Nozzle diff --git a/src/Dodge/Item/Weapon/BulletGun/Rod.hs b/src/Dodge/Item/Weapon/BulletGun/Rod.hs index 7976afd2b..fe8100734 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Rod.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Rod.hs @@ -2,6 +2,7 @@ module Dodge.Item.Weapon.BulletGun.Rod ( bangRod , elephantGun , amr + , autoAmr , sniperRifle , machineGun ) where @@ -12,8 +13,9 @@ import Dodge.Item.Weapon.BulletGun.Clip import Dodge.Default.Weapon --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Default +import Dodge.Item.Weapon.ZoomScope --import Dodge.Item.Attachment ---import Dodge.Item.Weapon.ExtraEffect +import Dodge.Item.Weapon.ExtraEffect --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.AmmoParams --import Dodge.Item.Draw @@ -43,13 +45,14 @@ bangRod = defaultGun , _bore = 2 , _gunBarrels = SingleBarrel 0.1 } - , _itUse = ruseAmmoParamsRate 6 upHammer + , _itUse = ruseAmmoParamsRate 12 upHammer [ ammoHammerCheck , useTimeCheck - , withSoundStart autoGunS + , withSoundStart bangEchoS , useAmmoAmount 1 , torqueAfterI 0.3 , applyInaccuracy + , withThickSmokeI , withMuzFlareI , withRecoilI 50 ] @@ -90,26 +93,38 @@ elephantGun = bangRod & itUse . useMods .~ [ ammoHammerCheck , useTimeCheck - , withSoundStart autoGunS + , withSoundStart bangEchoS , useAmmoAmount 1 , torqueAfterI 0.1 , applyInaccuracy + , withThickSmokeI , withMuzFlareI , withRecoilI 50 ] amr :: Item amr = elephantGun - & itName .~ "AMR" + & itName .~ "ANTIMATERIELRIFLE" & itType .~ AMR & itConsumption . ammoBaseMax .~ 15 & itDimension . dimSPic .~ (\it -> noPic $ baseAMRShape <> makeTinClipAt 0 (V3 10 (-2) 0) it ) + +autoAmr :: Item +autoAmr = amr + & itName .~ "AUTOAMR" + & itType .~ AUTOAMR + & itUse . useMods %~ ((ammoCheckI :) . tail) + sniperRifle :: Item sniperRifle = elephantGun & itName .~ "SNIPERRIFLE" & itType .~ SNIPERRIFLE & itParams . gunBarrels .~ SingleBarrel 0 + & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} + & itScroll .~ zoomLongGun + & itScope .~ ZoomScope (V2 0 0) 0 1 False + & itTargeting .~ targetLaser machineGun :: Item machineGun = bangRod & itName .~ "MACHINEGUN" diff --git a/src/Dodge/Item/Weapon/BulletGuns.hs b/src/Dodge/Item/Weapon/BulletGuns.hs index 0b0abe650..5dd48df5a 100644 --- a/src/Dodge/Item/Weapon/BulletGuns.hs +++ b/src/Dodge/Item/Weapon/BulletGuns.hs @@ -21,6 +21,7 @@ module Dodge.Item.Weapon.BulletGuns import Dodge.Item.Weapon.BulletGun.Stick import Dodge.Item.Weapon.BulletGun.Cane import Dodge.Item.Weapon.BulletGun.Rod +import Dodge.Item.Weapon.ZoomScope --import Dodge.Item.Weapon.BulletGun.Clip import Dodge.Data --import Dodge.ChainEffect @@ -29,7 +30,6 @@ import Dodge.Default.Weapon import Dodge.Item.Weapon.InventoryDisplay import Dodge.Default import Dodge.Item.Attachment -import Dodge.Item.Weapon.ExtraEffect --import Dodge.Item.Weapon.InventoryDisplay import Dodge.Item.Weapon.AmmoParams import Dodge.Item.Draw @@ -456,14 +456,8 @@ longGun = defaultGun , _itScroll = zoomLongGun , _itAttachment = NoItAttachment , _itScope = ZoomScope (V2 0 0) 0 1 False - , _itEffect = itemLaserScopeEffect +-- , _itEffect = itemLaserScopeEffect } -zoomLongGun :: Float -> Creature -> Item -> Item -zoomLongGun x _ - | x > 0 = itScope . scopeZoomChange %~ (max 5 . (+5)) - | x < 0 = itScope . scopeZoomChange %~ (min (-5) . subtract 5) - | otherwise = id - autogunSpread :: Float autogunSpread = 0.07 diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index 355fdb5e1..28b3882d1 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -1,10 +1,10 @@ -{-# LANGUAGE BangPatterns #-} +--{-# LANGUAGE BangPatterns #-} {- | Extra weapon effects, supplementing explicit use effects. -} module Dodge.Item.Weapon.ExtraEffect - ( itemLaserScopeEffect - , autoSonarEffect + (-- itemLaserScopeEffect + autoSonarEffect , autoRadarEffect , targetRBPress , targetRBCreature @@ -14,11 +14,10 @@ module Dodge.Item.Weapon.ExtraEffect ) where import Dodge.Data import Dodge.Base -import Dodge.Item.Weapon.Decoration +--import Dodge.Item.Weapon.Decoration import Dodge.Item.Weapon.UseEffect import Dodge.Item.Weapon.LaserPath --import Dodge.Item.Attachment.Data -import Dodge.WorldEvent.ThingsHit import Dodge.Picture.Layer import Dodge.Creature.Test import Picture @@ -27,43 +26,8 @@ import Geometry.Data import Data.Maybe import Control.Lens -import qualified Data.IntMap.Strict as IM import qualified Data.Set as S import qualified SDL -{- | -Creates a laser scope and recocks the weapon. -TODO add the laser scope! - -} -itemLaserScopeEffect :: ItEffect -itemLaserScopeEffect - = ItInvEffect {_itInvEffect = f ,_itEffectCounter = 0 } - where - moveHammerUp HammerDown = HammerReleased - moveHammerUp !_ = HammerUp - f _ cr invid w - | invid == _crInvSel cr && crIsAiming' cr = w - & particles %~ (:) (makeLaserScope sp ep reloadFrac) - & creatures . ix (_crID cr) . crInv . ix invid . itUse . useHammer . hammerPosition %~ moveHammerUp - | otherwise = w - where - p = _crPos cr - d = _crDir cr - r = _crRad cr - sp = p +.+ (r + 3) *.* unitVectorAtAngle d - xp = sp +.+ 3000 *.* unitVectorAtAngle d - ep = case listToMaybe $ thingsHitLongLine sp xp w of - Just (pos,_) -> pos - Nothing -> xp - --glowPoint = case listToMaybe $ thingsHitLongLine sp xp w of - -- Just (pos,E3x2 wl) -> pos +.+ 2 *.* wallNormal wl - -- _ -> ep -.- 2 *.* unitVectorAtAngle d - wpammo = _itConsumption $ (cr ^. crInv) IM.! invid - reloadFrac - | _ammoLoaded wpammo == 0 = 1 - | otherwise = case _reloadState wpammo of - Just' rs -> fromIntegral rs / fromIntegral (_reloadTime wpammo) - Nothing' -> 1 - --col = mixColors reloadFrac (1-reloadFrac) red green {- | Automatically send out radar pulses that detect walls. -} autoRadarEffect :: ItEffect autoRadarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 } @@ -97,7 +61,7 @@ defaultTargeting = TargetingOnHeld targetLaser :: Targeting targetLaser = defaultTargeting & tgUpdate .~ targetLaserUpdate - & tgDraw .~ targetLaserDraw + & tgDraw .~ targetLaserDraw targetRBPress :: Targeting targetRBPress = defaultTargeting & tgUpdate .~ targetRBPressUpdate @@ -170,15 +134,22 @@ targetLaserDraw :: Int -> Item -> Creature -> World -> Picture targetLaserDraw _ it _ _ = fromMaybe mempty $ do ps <- it ^? itTargeting . tgPoints return $ setLayer 1 $ pictures - [ setDepth 19 . color (brightX 0 0.5 red) $ thickLine 5 ps - , setDepth 19.5 . color (brightX 5 1 red) $ thickLine 1 ps + [ setDepth 19 . color (brightX 0 0.5 col) $ thickLine 5 ps + , setDepth 19.5 . color (brightX 5 1 col) $ thickLine 1 ps ] - + where + wpammo = _itConsumption it + reloadFrac + | _ammoLoaded wpammo == 0 = 1 + | otherwise = case _reloadState wpammo of + Just' rs -> fromIntegral rs / fromIntegral (_reloadTime wpammo) + Nothing' -> 1 + col = mixColors reloadFrac (1-reloadFrac) red green targetLaserUpdate :: Item -> Creature -> World -> Targeting -> Targeting targetLaserUpdate _ cr w t - | SDL.ButtonRight `S.member` _mouseButtons w = t - & tgPos .~ fmap fst mp - & tgPoints .~ ps ++ [sp] + | crIsAiming cr = t + & tgPos .~ fmap fst mp + & tgPoints .~ sp:ps & tgActive .~ True | otherwise = t & tgPos %~ const Nothing & tgPoints .~ [] diff --git a/src/Dodge/Item/Weapon/Launcher.hs b/src/Dodge/Item/Weapon/Launcher.hs index 3acb6e347..783d3acb7 100644 --- a/src/Dodge/Item/Weapon/Launcher.hs +++ b/src/Dodge/Item/Weapon/Launcher.hs @@ -1,6 +1,6 @@ module Dodge.Item.Weapon.Launcher ( launcher - , doubleLauncher + , launcherX , remoteLauncher , fireTrackingShell ) where @@ -83,25 +83,30 @@ launcher = defaultGun } & itModules . at ModLauncherHoming ?~ DefaultModule -doubleLauncher :: Item -doubleLauncher = launcher - & itName .~ "DOUBLEROCKO" - & itType .~ DOUBLELAUNCHER - & itUse . rUse .~ usePjCreationDouble +launcherX :: Int -> Item +launcherX i = launcher + & itName .~ ("ROCKO-" ++ show i) + & itType .~ LAUNCHERX i + & itConsumption . ammoBaseMax .~ i + & itConsumption . ammoLoaded .~ i + & itUse . rUse .~ usePjCreationX i & itUse . useMods .~ [ hammerCheckI , ammoCheckI , useTimeCheck , withSoundStart tap4S - , useAmmoAmount 1 + , useAmmoAmount i ] usePjCreation :: Item -> Creature -> World -> World usePjCreation it = _amPjCreation (_aoType (_itConsumption it)) it -usePjCreationDouble :: Item -> Creature -> World -> World -usePjCreationDouble it cr = _amPjCreation (_aoType (_itConsumption it)) it cr - . _amPjCreation (_aoType (_itConsumption it)) it (cr & crDir +~ pi) +usePjCreationX :: Int -> Item -> Creature -> World -> World +usePjCreationX i it cr = foldr f + (_amPjCreation (_aoType (_itConsumption it)) it cr) + [1..i-1] + where + f n = (. _amPjCreation (_aoType (_itConsumption it)) it (cr & crDir +~ (2*pi*fromIntegral n / fromIntegral i))) launcherPic :: Item -> SPic launcherPic _ = diff --git a/src/Dodge/Item/Weapon/SprayGuns.hs b/src/Dodge/Item/Weapon/SprayGuns.hs index ed5e710fc..83c312c3e 100644 --- a/src/Dodge/Item/Weapon/SprayGuns.hs +++ b/src/Dodge/Item/Weapon/SprayGuns.hs @@ -29,9 +29,11 @@ import Geometry import Picture import Shape import ShapePicture +import LensHelp -import Data.Function -import Control.Lens +import Data.Traversable +import qualified Data.IntMap.Strict as IM +--import Data.Function import System.Random poisonSprayer :: Item poisonSprayer = defaultAutoGun @@ -80,13 +82,14 @@ flamerPic it = r = 5 am = fractionLoadedAmmo2 it flameStick :: Item -flameStick = undefined +flameStick = flamer + & itUse . rUse .~ const aFlame blowTorch :: Item -blowTorch = undefined +blowTorch = flamer flameThrower :: Item -flameThrower = undefined +flameThrower = flamer flameWall :: Item -flameWall = undefined +flameWall = flamer flamer :: Item flamer = defaultAutoGun { _itName = "FLAMER" @@ -124,8 +127,25 @@ aGasCloud cr w = insertCloud $ set randGen g w vel = (_crPos cr -.- _crOldPos cr) +.+ 10 *.* unitVectorAtAngle dir insertCloud = makeGasCloud pos vel +overNozzles :: (Creature -> World -> Nozzle -> (World,Nozzle)) + -> Item -> Creature -> World -> World +overNozzles eff it cr w = neww & creatures . ix cid . crInv . ix i . itParams . sprayerNozzles .~ newNozzles + where + cid = _crID cr + i = _crInvSel $ _creatures w IM.! cid + (neww,newNozzles) = mapAccumR (eff cr) w $ _sprayerNozzles (_itParams it) + +overNozzle :: (Creature -> World -> World) + -> Creature -> World -> Nozzle -> (World, Nozzle) +overNozzle eff cr w nz = (eff (cr & crDir +~ wa) w & randGen .~ g,nz & nzCurrentWalkAngle .~ wa) + where + (walkamount, g) = randomR (-aspeed,aspeed) (_randGen w) + aspeed = _nzWalkSpeed nz + maxa = _nzMaxWalkAngle nz + wa = min maxa $ max (negate maxa) (_nzCurrentWalkAngle nz + walkamount) + aFlame :: Creature -> World -> World -aFlame cr w = w & particles %~ (aFlameParticle t pos vel (Just cid) :) +aFlame cr w = w & particles .:~ aFlameParticle t pos vel (Just cid) where (t,_) = randomR (99,101) (_randGen w) cid = _crID cr diff --git a/src/Dodge/Item/Weapon/ZoomScope.hs b/src/Dodge/Item/Weapon/ZoomScope.hs new file mode 100644 index 000000000..031676e8c --- /dev/null +++ b/src/Dodge/Item/Weapon/ZoomScope.hs @@ -0,0 +1,9 @@ +module Dodge.Item.Weapon.ZoomScope where +import Dodge.Data +import LensHelp + +zoomLongGun :: Float -> Creature -> Item -> Item +zoomLongGun x _ + | x > 0 = itScope . scopeZoomChange %~ (max 5 . (+5)) + | x < 0 = itScope . scopeZoomChange %~ (min (-5) . subtract 5) + | otherwise = id