From f626fce10545e5b8e8942cdab8385e0cf4912c89 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 21 Feb 2022 20:51:01 +0000 Subject: [PATCH] Implement teleporting bullets --- src/Dodge/Base.hs | 2 + src/Dodge/Base/Collide.hs | 2 +- src/Dodge/Combine.hs | 67 ++++++++----- src/Dodge/Combine/Combinations.hs | 117 ++++++++++++++-------- src/Dodge/Combine/Data.hs | 7 +- src/Dodge/Creature.hs | 3 + src/Dodge/Data.hs | 20 ++-- src/Dodge/Default.hs | 11 +- src/Dodge/Default/Weapon.hs | 14 +-- src/Dodge/Inventory/ItemSpace.hs | 1 - src/Dodge/Item/Craftable.hs | 16 +++ src/Dodge/Item/Data.hs | 1 + src/Dodge/Item/MaxAmmo.hs | 12 --- src/Dodge/Item/Weapon/AmmoParams.hs | 24 ++--- src/Dodge/Item/Weapon/Bezier.hs | 29 +++--- src/Dodge/Item/Weapon/BulletGun/Cane.hs | 11 +- src/Dodge/Item/Weapon/BulletGun/Stick.hs | 2 + src/Dodge/Item/Weapon/ExtraEffect.hs | 2 +- src/Dodge/Item/Weapon/InventoryDisplay.hs | 6 +- src/Dodge/Item/Weapon/TriggerType.hs | 28 ++++++ src/Dodge/Module.hs | 13 ++- src/Dodge/Reloading.hs | 10 +- src/Picture.hs | 1 + 23 files changed, 245 insertions(+), 154 deletions(-) delete mode 100644 src/Dodge/Item/MaxAmmo.hs diff --git a/src/Dodge/Base.hs b/src/Dodge/Base.hs index 6a6eb89f8..49cbc785e 100644 --- a/src/Dodge/Base.hs +++ b/src/Dodge/Base.hs @@ -429,6 +429,8 @@ cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate doTranslate p = p -.- _carteCenter w doZoom p = _carteZoom w *.* p doRotate p = rotateV (negate $ _carteRot w) p +crToMousePosOffset :: Creature -> World -> (Point2,Float) +crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr,0) {- | The mouse position in world coordinates. -} mouseWorldPos :: World -> Point2 mouseWorldPos w = _cameraCenter w +.+ (1/_cameraZoom w) *.* rotateV (_cameraRot w) (_mousePos w) diff --git a/src/Dodge/Base/Collide.hs b/src/Dodge/Base/Collide.hs index 02b74b2dc..9a471bd7c 100644 --- a/src/Dodge/Base/Collide.hs +++ b/src/Dodge/Base/Collide.hs @@ -23,7 +23,7 @@ import qualified FoldlHelp as L hasLOS :: Point2 -> Point2 -> World -> Bool {-# INLINE hasLOS #-} -hasLOS p1 p2 w = not $ pointHitsWalls p1 p2 $ wallsAlongLine p1 p2 w +hasLOS p1 p2 = not . pointHitsWalls p1 p2 . wallsAlongLine p1 p2 --hitPointLines -- :: Point2 diff --git a/src/Dodge/Combine.hs b/src/Dodge/Combine.hs index f758d0169..845bf1732 100644 --- a/src/Dodge/Combine.hs +++ b/src/Dodge/Combine.hs @@ -21,6 +21,7 @@ import Data.Bifunctor import qualified Data.IntMap.Strict as IM --import qualified Data.IntSet as IS import qualified Data.Map.Strict as M +import Data.Map.Merge.Strict import Data.Maybe import Data.List (scanl',sortOn) @@ -34,21 +35,25 @@ combinationsTrie = foldr -- trie going through each combine type in your inventory in order, rather than -- creating all multisets of combine types. -lookupItems :: [(ItemModules,CombineType,Int,Int)] -> [ ([(ItemModules,Int)],Item) ] +lookupItems :: [(M.Map ModuleSlot ItemModule,CombineType,Int,Int)] + -> [ ([(M.Map ModuleSlot ItemModule,Int)],Item) ] lookupItems xs = lookupItemsUsingTrie (sortOn (\(_,ct,_,_) -> ct) xs) combinationsTrie -lookupItemsUsingTrie :: [(ItemModules,CombineType,Int,Int)] - -> Trie (Int,CombineType) Item -> [ ([(ItemModules,Int)],Item) ] +lookupItemsUsingTrie :: [(M.Map ModuleSlot ItemModule,CombineType,Int,Int)] + -> Trie (Int,CombineType) Item + -> [ ([(M.Map ModuleSlot ItemModule,Int)],Item) ] lookupItemsUsingTrie [] t = maybeToList $ ([],) <$> _trieMVal t lookupItemsUsingTrie ((mods,ct,i,n):xs) t = do n' <- [1..min n 4] let is = replicate n' (mods,i) concatMap (map (first (is ++)) . lookupItemsUsingTrie xs) $ maybeToList (_trieChildren t M.!? (n',ct)) -invertListInvMult :: IM.IntMap Item -> [[(ItemModules,CombineType,Int,Int)]] +invertListInvMult :: IM.IntMap Item + -> [[(M.Map ModuleSlot ItemModule,CombineType,Int,Int)]] invertListInvMult = powlistUpToN 4 . invertListInv -invertListInv :: IM.IntMap Item -> [(ItemModules,CombineType,Int,Int)] +invertListInv :: IM.IntMap Item + -> [(M.Map ModuleSlot ItemModule,CombineType,Int,Int)] invertListInv = IM.foldrWithKey (\k it -> ((_itModules it,_itType it, k, itStackAmount it) :) ) [] @@ -60,29 +65,45 @@ combineItemListYou :: World -> [([Int],Item)] combineItemListYou = map (second fst) . combineItemListYou' combineItemListYou' :: World -> [([Int],(Item,[String]))] -combineItemListYou' = concatMap addModules . concatMap lookupItems . invertListInvMult . yourInv +combineItemListYou' = map addModules . concatMap lookupItems . invertListInvMult . yourInv -addModules :: ([(ItemModules,Int)],Item) -> [([Int],(Item,[String]))] -addModules (ps,it) = (is , ) <$> [ (it & itModules .~ themodules,s) | (themodules,s) <- combinedmodules] +addModules :: ([(M.Map ModuleSlot ItemModule,Int)],Item) + -> ([Int],(Item,[String])) +addModules (ps,it) = (is , (applyModules newm it, ss)) where (ms,is) = unzip ps - combinedmodules = foldr f [(_itModules it,[])] ms - f :: ItemModules -> [(ItemModules,[String])] -> [(ItemModules,[String])] - f ims imss = concatMap (g ims) imss - g ims (ims',s) = map (second (s++)) $ combineModules ims ims' + m = ([],_itModules it) + (ss,newm) = foldr f m ms + f m' (s,m'') = (s ++ s',m''') + where + (s',m''') = combineModules m' m'' -combineModules :: ItemModules -> ItemModules -> [(ItemModules,[String])] -combineModules (ItemModules a1 b1) (ItemModules a2 b2) - = [(ItemModules a b,as++bs) | (a,as) <- combineModule a1 a2 - , (b,bs) <- combineModule b1 b2] +applyModules :: M.Map ModuleSlot ItemModule -> Item -> Item +applyModules ms it = foldr f (it & itModules .~ ms) ms + where + f m = fromMaybe id (m ^? modModification) +-- (is , ) <$> [ (it & itModules .~ themodules,s) | (themodules,s) <- combinedmodules] +-- where +-- (ms,is) = unzip ps +-- combinedmodules = foldr f [(_itModules it,[])] ms +-- f :: M.Map ModuleSlot ItemModule -> [(M.Map ModuleSlot ItemModule,[String])] -> [(M.Map ModuleSlot ItemModule,[String])] +-- f ims imss = concatMap (g ims) imss +-- g ims (ims',s) = map (second (s++)) $ combineModules ims ims' -combineModule :: ItemModule a -> ItemModule a -> [(ItemModule a,[String])] -combineModule ItemModule{_modName=ss} BlockedModule = [(BlockedModule, "WARNING:REMOVES":ss)] -combineModule _ BlockedModule = [(BlockedModule, [])] -combineModule BlockedModule m = [(m,[])] -combineModule DefaultModule m = [(m,[])] -combineModule ItemModule{_modName=ss} m@ItemModule{} = [(m,"WARNING:REMOVES":ss)] -combineModule m _ = [(m,[])] +combineModules :: M.Map ModuleSlot ItemModule + -> M.Map ModuleSlot ItemModule + -> ([String],M.Map ModuleSlot ItemModule) +combineModules = mergeA + (traverseMaybeMissing f) + (traverseMissing g) + (zipWithAMatched h) + where + f _ ItemModule{_modName=ss} = ("WARNING:REMOVES":ss,Nothing) + f _ _ = ([],Nothing) + g _ m = ([], m) + h _ ItemModule{_modName=ss} im@ItemModule{} = ("WARNING:REMOVES":ss,im) + h _ _ im@ItemModule{} = ([],im) + h _ im _ = ([],im) toggleCombineInv :: World -> World toggleCombineInv w = case _inventoryMode w of diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index 72f02553f..ba97c75d0 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -1,5 +1,6 @@ {-# LANGUAGE TupleSections #-} module Dodge.Combine.Combinations where +import Geometry import Dodge.Data import Dodge.WorldEvent.HitEffect import Dodge.Particle.Bullet.HitEffect @@ -9,8 +10,14 @@ import Dodge.Item.Weapon.BulletGuns import Dodge.Item.Weapon.BatteryGuns import Dodge.Item.Weapon.Launcher import Dodge.Item.Weapon.SprayGuns +import Dodge.Item.Weapon.Bezier +import Dodge.Item.Weapon.TriggerType +import Dodge.Item.Weapon.ExtraEffect +import Dodge.Base +import LensHelp + +import Data.Maybe -import Control.Lens itemCombinations :: [([(Int,CombineType)],Item)] itemCombinations = [ po [PIPE, HARDWARE] (bangStick 1) @@ -34,6 +41,7 @@ itemCombinations = , po [BANGCANE,TIN] rifle , po [RIFLE,PLANK] repeater , po [REPEATER,SPRING,HARDWARE] autoRifle + , po [AUTORIFLE,MICROCHIP,MAGNET] bezierGun , po [REPEATER,SPRING,CAN] burstRifle , po [BURSTRIFLE,SPRING,HARDWARE] fastBurstRifle , po [FASTBURSTRIFLE,SPRING,HARDWARE] completeBurstRifle @@ -67,52 +75,77 @@ itemCombinations = ++ map (\i -> po [REVOLVERX i,CAN] $ revolverX (i+1)) [1..5] ++ map (\i -> p [o (BANGCANEX i),p 2 PIPE] $ bangCaneX (i+1)) [1..5] ++ map (\i -> po [MINIGUNX i,BANGCANE] $ miniGunX (i+1)) [3..15] - ++ [ po [itype,mtype] $ it & itModules . modHitEffect .~ m - | (itype,it) <- firearmTypes , (mtype,m) <- bulletModules - ] - ++ [ po (itype : ctypes) $ it & itModules . modRifleMag .~ m - | (itype,it) <- rifleMagTypes , (ctypes,m) <- rifleMagModules + ++ [ po (_itType it:mtype) $ it & itModules . ix modtype .~ m + | (modtype,is,ms) <- moduleCombinations + , it <- is + , (mtype,m) <- ms ] where p = (,) po xs it = (map o xs,it) o = (1,) -rifleMagTypes :: [(CombineType,Item)] -rifleMagTypes - = [(REPEATER,repeater) - ,(AUTORIFLE,autoRifle) - ,(BURSTRIFLE,burstRifle) - ,(FASTBURSTRIFLE,fastBurstRifle) - ] -rifleMagModules :: [([CombineType],ItemModule RifleMag)] -rifleMagModules = - [([DRUM,HARDWARE], ItemModule DrumMag ["+DRUM MAGAZINE"] 1 id) - ,([MOTOR,HARDWARE], ItemModule BeltMag ["+BELT MAGAZINE"] 1 id) - ,([MAGNET,HARDWARE],ItemModule MagnetMag ["+MAGNET MAGAZINE"] 1 id) +moduleCombinations :: [( ModuleSlot, [Item], [([CombineType],ItemModule)] )] +moduleCombinations = + [ ( ModRifleMag + , [repeater + ,autoRifle + ,burstRifle + ,fastBurstRifle + ] + , [amod [DRUM,HARDWARE] "+DRUM MAG" (itConsumption . ammoBaseMax .~ 45) + ,amod [MOTOR,HARDWARE] "+BELT FEED" (itConsumption . ammoBaseMax .~ 150) + ] + ) + , ( ModAutoMag + , [autoRifle + ,autoPistol + ,smg + ] + , [amod [MAGNET,HARDWARE] "+MAGNET FEED" (itUse . useDelay . rateMax .~ 4) + ] + ) + , ( ModBullet + , bulletWeapons + , [amod [INCENDIARYMODULE] "+INCENDIARY" (f $ destroyOnImpact bulIncCr bulIncWall) + ,amod [BOUNCEMODULE] "+BOUNCE" (f $ destroyOnImpact bulBounceArmCr' bulBounceWall) + ] + ) + , ( ModBulletTarget + , bulletWeapons + , [amod [TELEPORTMODULE,MICROCHIP] "+TELEPORT" (itUse . useMods .:~ withPositionWallCheck (const . const mouseWorldPos)) + ,amod [TELEPORTMODULE] "+DIRECTEDTELE" makeDirectedTele + ] + ) ] + where + makeDirectedTele it = it & itEffect .~ rbSetTarget + & itUse . useMods .:~ withPosDirWallCheck directedTelPos + & itUse . useAim . aimZoom . itZoomFac .~ 1 + directedTelPos it cr w = (p,a) + where + p = fromMaybe (_crPos cr) $ do + (g,_) <- _itTargeting it + g w + a = argV (mouseWorldPos w -.- p) + f ameff = itConsumption . aoType . amBulEff .~ ameff + amod cts str func = (cts,ItemModule [str] 1 func) -firearmTypes :: [(CombineType,Item)] -firearmTypes - = [(BANGSTICK i,bangStick i) | i <- [1..9] ] - ++ [(BANGCANEX i,bangCaneX i) | i <- [1..6] ] - ++ [(REVOLVERX i,revolverX i) | i <- [1..5] ] - ++ [(MINIGUNX i,miniGunX i) | i <- [3..16] ] - ++ [(BANGCANE,bangCane) - ,(PISTOL,pistol) - ,(AUTOPISTOL,autoPistol) - ,(SMG,smg) - ,(MACHINEPISTOL,machinePistol) - ,(REVOLVER,revolver) - ,(RIFLE,rifle) - ,(REPEATER,repeater) - ,(AUTORIFLE,autoRifle) - ,(BURSTRIFLE,burstRifle) - ,(FASTBURSTRIFLE,fastBurstRifle) - ,(COMPLETEBURSTRIFLE,completeBurstRifle) - ] -bulletModules :: [(CombineType,ItemModule HitEffect)] -bulletModules = - [(INCENDIARYMODULE, ItemModule (destroyOnImpact bulIncCr bulIncWall) ["+INCENDIARY"] 1 id) - ,(BOUNCEMODULE, ItemModule (destroyOnImpact bulBounceArmCr' bulBounceWall) ["+BOUNCE"] 1 id) - ] +bulletWeapons :: [Item] +bulletWeapons = [bangStick i | i <- [1..9] ] + ++ [bangCaneX i | i <- [1..6] ] + ++ [revolverX i | i <- [1..5] ] + ++ [miniGunX i | i <- [3..16] ] + ++ [bangCane + ,pistol + ,autoPistol + ,smg + ,machinePistol + ,revolver + ,rifle + ,repeater + ,autoRifle + ,burstRifle + ,fastBurstRifle + ,completeBurstRifle + ] diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index 944279b05..4cbc89a08 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -83,7 +83,7 @@ data CombineType | LIGHTER | MAGNET | PLATE - | MCHIP + | MICROCHIP | LED | NAILBOX | IRONBAR @@ -98,4 +98,9 @@ data CombineType | INCENDIARYMODULE | BOUNCEMODULE | NoCombineType + -- + | TELEPORTMODULE + | TIMEMODULE + | SIZEMODULE + | GRAVITYMODULE deriving (Eq,Ord,Show) diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index e7196e371..086226129 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -169,6 +169,7 @@ testInventory = IM.fromList $ zip [0..] [ makeTypeCraftNum 9 PIPE , incendiaryModule , bounceModule + , teleportModule , makeTypeCraftNum 5 TUBE , makeTypeCraftNum 1 MAGNET , makeTypeCraftNum 5 HARDWARE @@ -177,10 +178,12 @@ testInventory = IM.fromList $ zip [0..] , makeTypeCraftNum 3 TIN , makeTypeCraftNum 3 PLANK , makeTypeCraftNum 1 MOTOR + , makeTypeCraftNum 1 MICROCHIP ] stackedInventory :: IM.IntMap Item stackedInventory = IM.fromList $ zip [0..] [sonicGun + ,teleGun ,spreadGun , pipe ,rewindGun diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index bd36c70d7..e1da2ee26 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -375,25 +375,20 @@ data Item , _itCurseStatus :: CurseStatus , _itParams :: ItemParams , _itTweaks :: ItemTweaks - , _itModules :: ItemModules + , _itModules :: M.Map ModuleSlot ItemModule } -data ItemModules = ItemModules - { _modHitEffect :: ItemModule HitEffect - , _modRifleMag :: ItemModule RifleMag - } -data RifleMag = DrumMag | BeltMag | MagnetMag - data ModuleSlot = ModBullet | ModRifleMag + | ModAutoMag + | ModBulletTarget + deriving (Eq,Ord) -data ItemModule a - = BlockedModule - | DefaultModule +data ItemModule + = DefaultModule | ItemModule - { _theModule :: a - , _modName :: [String] + { _modName :: [String] , _modSize :: Int , _modModification :: Item -> Item } @@ -938,5 +933,4 @@ makeLenses ''ItemPortage makeLenses ''Magnet makeLenses ''Gust makeLenses ''GunBarrels -makeLenses ''ItemModules makeLenses ''ItemModule diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 25e7fefec..c017f3182 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -17,6 +17,7 @@ import Shape import Control.Lens import qualified Data.IntMap.Strict as IM +import qualified Data.Map.Strict as M import qualified Data.Vector as V import Data.List --import Data.Monoid @@ -154,10 +155,7 @@ defaultEquipment = Item , _itParams = NoParams , _itTweaks = NoTweaks , _itTargeting = Nothing - , _itModules = ItemModules - { _modHitEffect = BlockedModule - , _modRifleMag = BlockedModule - } + , _itModules = M.empty } defaultItZoom :: ItZoom defaultItZoom = ItZoom 20 0.2 1 @@ -181,10 +179,7 @@ defaultConsumable = Item , _itParams = NoParams , _itDimension = defItDimCol blue , _itTweaks = NoTweaks - , _itModules = ItemModules - { _modHitEffect = BlockedModule - , _modRifleMag = BlockedModule - } + , _itModules = M.empty } 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 ec276f4fd..abde267cd 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -10,7 +10,7 @@ import Shape import Geometry --import Dodge.TweakBullet ---import qualified Data.IntMap.Strict as IM +import qualified Data.Map.Strict as M import Control.Lens defaultAmmo :: ItemConsumption @@ -100,10 +100,9 @@ defaultGun = Item , _itTargeting = Nothing , _itParams = NoParams , _itTweaks = NoTweaks - , _itModules = ItemModules - { _modHitEffect = DefaultModule - , _modRifleMag = BlockedModule - } + , _itModules = M.fromList [(ModBullet , DefaultModule) + ,(ModBulletTarget,DefaultModule) + ] } defaultCraftable :: Item defaultCraftable = Item @@ -126,10 +125,7 @@ defaultCraftable = Item , _itParams = NoParams , _itDimension = defItDimCol green , _itTweaks = NoTweaks - , _itModules = ItemModules - { _modHitEffect = BlockedModule - , _modRifleMag = BlockedModule - } + , _itModules = M.empty } defItDim :: ItemDimension defItDim = ItemDimension diff --git a/src/Dodge/Inventory/ItemSpace.hs b/src/Dodge/Inventory/ItemSpace.hs index 7829054ec..b769fdf88 100644 --- a/src/Dodge/Inventory/ItemSpace.hs +++ b/src/Dodge/Inventory/ItemSpace.hs @@ -11,4 +11,3 @@ itSlotsTaken :: Item -> Int itSlotsTaken it = case it ^? itConsumption . itAmount of Nothing -> moduleSizes it + ceiling (_itInvSize it) Just i -> moduleSizes it + ceiling (_itInvSize it * fromIntegral i) - diff --git a/src/Dodge/Item/Craftable.hs b/src/Dodge/Item/Craftable.hs index 45ae4607d..f86d7fbb5 100644 --- a/src/Dodge/Item/Craftable.hs +++ b/src/Dodge/Item/Craftable.hs @@ -29,6 +29,22 @@ bounceModule :: Item bounceModule = makeTypeCraft BOUNCEMODULE & itInvSize .~ 1 & itInvColor .~ chartreuse +teleportModule :: Item +teleportModule = makeTypeCraft TELEPORTMODULE + & itInvSize .~ 1 + & itInvColor .~ chartreuse +timeModule :: Item +timeModule = makeTypeCraft TIMEMODULE + & itInvSize .~ 1 + & itInvColor .~ chartreuse +sizeModule :: Item +sizeModule = makeTypeCraft SIZEMODULE + & itInvSize .~ 1 + & itInvColor .~ chartreuse +gravityModule :: Item +gravityModule = makeTypeCraft GRAVITYMODULE + & itInvSize .~ 1 + & itInvColor .~ chartreuse pipe :: Item pipe = makeTypeCraft PIPE diff --git a/src/Dodge/Item/Data.hs b/src/Dodge/Item/Data.hs index 48bd72c34..c61db4871 100644 --- a/src/Dodge/Item/Data.hs +++ b/src/Dodge/Item/Data.hs @@ -54,6 +54,7 @@ data AimStance | LeaveHolstered deriving (Eq,Show,Ord,Enum) +-- TODO check how much of this is necessary data ItZoom = ItZoom { _itZoomMax :: Float , _itZoomMin :: Float diff --git a/src/Dodge/Item/MaxAmmo.hs b/src/Dodge/Item/MaxAmmo.hs deleted file mode 100644 index eb6ae41e0..000000000 --- a/src/Dodge/Item/MaxAmmo.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Dodge.Item.MaxAmmo where -import Dodge.Data - -import Control.Lens - -itMaxAmmo :: Item -> Int -itMaxAmmo it = _ammoBaseMax (_itConsumption it) - + maybe 0 f (it ^? itModules . modRifleMag . theModule) - where - f DrumMag = 45 - f BeltMag = 135 - f MagnetMag = 0 diff --git a/src/Dodge/Item/Weapon/AmmoParams.hs b/src/Dodge/Item/Weapon/AmmoParams.hs index 7a03c3037..ee0e1f1fe 100644 --- a/src/Dodge/Item/Weapon/AmmoParams.hs +++ b/src/Dodge/Item/Weapon/AmmoParams.hs @@ -7,15 +7,12 @@ module Dodge.Item.Weapon.AmmoParams , fractionLoadedAmmo2 ) where import Dodge.Data -import Dodge.Item.MaxAmmo import Dodge.Particle.Bullet.Spawn import Dodge.Creature.HandPos -import Dodge.WorldEvent.HitEffect -import Dodge.Particle.Bullet.HitEffect import Geometry import LensHelp -import Data.Maybe +--import Data.Maybe --import Control.Lens useAmmoParamsRate :: Int @@ -43,25 +40,24 @@ useAmmoParams it cr = withVelWthHiteff (_rifling $ _itParams it) (_amBulWth b) muzlength - bulHitEff --- (_amBulEff b) + (_amBulEff b) cr where muzlength = aimingMuzzlePos cr it muzvel = _muzVel $ _itParams it b = _aoType $ _itConsumption it - bulHitEff = fromMaybe (destroyOnImpact bulHitCr bulHitWall) - $ it ^? itModules . modHitEffect . theModule +-- bulHitEff = fromMaybe (destroyOnImpact bulHitCr bulHitWall) +-- $ it ^? itModules . modHitEffect . theModule useAmmoParamsVelMod :: Float -> Item -> Creature -> World -> World useAmmoParamsVelMod vfact it = withDelayedVelWthHiteff vfact (_amBulVel b) (_rifling $ _itParams it) (_amBulWth b) --- (_amBulEff b) - bulHitEff + (_amBulEff b) +-- bulHitEff where b = _aoType $ _itConsumption it - bulHitEff = fromMaybe (destroyOnImpact bulHitCr bulHitWall) - $ it ^? itModules . modHitEffect . theModule +-- bulHitEff = fromMaybe (destroyOnImpact bulHitCr bulHitWall) +-- $ it ^? itModules . modHitEffect . theModule {- | Creates a bullet with a given velocity, width, and 'HitEffect' -} withVelWthHiteff @@ -104,7 +100,11 @@ loadedAmmo it fractionLoadedAmmo :: Item -> Float fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (itMaxAmmo it) + where + itMaxAmmo = _ammoBaseMax . _itConsumption fractionLoadedAmmo2 :: Item -> Float fractionLoadedAmmo2 it = 1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral (itMaxAmmo it))**2 + where + itMaxAmmo = _ammoBaseMax . _itConsumption diff --git a/src/Dodge/Item/Weapon/Bezier.hs b/src/Dodge/Item/Weapon/Bezier.hs index 1b4acee94..0771ce3c9 100644 --- a/src/Dodge/Item/Weapon/Bezier.hs +++ b/src/Dodge/Item/Weapon/Bezier.hs @@ -1,5 +1,6 @@ module Dodge.Item.Weapon.Bezier ( bezierGun + , teleGun ) where import Dodge.Data import Dodge.Base @@ -16,14 +17,14 @@ import Dodge.RandomHelp import Dodge.SoundLogic.LoadSound import Geometry --import ShapePicture +import LensHelp import Data.Maybe -import Control.Lens import Control.Monad.State bezierGun :: Item bezierGun = defaultGun - { _itName = "B-GUN" - , _itUse = ruseRate 6 (\_ -> useTargetPos $ \p -> shootBezier $ fromJust p) -- <- the start point + { _itName = "BEZIERGUN" + , _itUse = ruseRate 6 (\_ -> useTargetPos $ \p -> shootBezier $ fromJust p) -- <- the start point NoHammer [ ammoCheckI , useTimeCheck @@ -43,21 +44,20 @@ bezierGun = defaultGun , _itEffect = rbSetTarget -- , _itZoom = defaultItZoom , _itConsumption = defaultAmmo - { _ammoBaseMax = 50 + { _ammoBaseMax = 15 } } shootBezier :: Point2 -> Creature -> World -> World -shootBezier targetp cr w = w & particles %~ (theBullet :) +shootBezier targetp cr w = w & particles .:~ aCurveBulAt + (Just cid) + (V4 200 200 200 1) + startp + (controlp +.+ randPos) + (targetp +.+ randPos') + (destroyOnImpact bulHitCr bulHitWall) + 5 where - theBullet = aCurveBulAt - (Just cid) - (V4 200 200 200 1) - startp - (controlp +.+ randPos) - (targetp +.+ randPos') - (destroyOnImpact bulHitCr bulHitWall) - 5 controlp = mouseWorldPos w cid = _crID cr dir = _crDir cr @@ -66,3 +66,6 @@ shootBezier targetp cr w = w & particles %~ (theBullet :) a <- randInCirc 10 b <- randInCirc 20 return (a,b) + +teleGun :: Item +teleGun = bezierGun diff --git a/src/Dodge/Item/Weapon/BulletGun/Cane.hs b/src/Dodge/Item/Weapon/BulletGun/Cane.hs index 291be0d7a..46e91952e 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Cane.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Cane.hs @@ -34,6 +34,7 @@ import Sound.Data import LensHelp import Data.Maybe +--import qualified Data.Map.Strict as M --import qualified Data.Sequence as Seq --import Control.Lens --import Control.Monad.State @@ -64,9 +65,9 @@ bangCane = defaultGun , useAmmoAmount 1 , torqueAfterI 0.1 , applyInaccuracy - , withMuzFlareI , withRecoilI 50 , withSmoke 1 black 20 200 5 + , withMuzFlareI ] , _itTweaks = defaultBulletSelTweak , _itDimension = ItemDimension @@ -153,10 +154,7 @@ rifle = bangCane repeater :: Item repeater = rifle - & itModules .~ ItemModules - { _modHitEffect = DefaultModule - , _modRifleMag = DefaultModule - } + & itModules . at ModRifleMag ?~ DefaultModule & itName .~ "REPEATER" & itType .~ REPEATER & itConsumption . reloadType .~ ActiveClear @@ -177,6 +175,7 @@ autoRifle = repeater & itName .~ "AUTORIFLE" & itType .~ AUTORIFLE & itUse . useMods %~ ((ammoCheckI :) . tail) + & itModules . at ModAutoMag ?~ DefaultModule -- & itUse . useDelay . rateMax .~ 6 burstRifle :: Item burstRifle = repeater @@ -218,7 +217,7 @@ completeBurstRifle :: Item completeBurstRifle = repeater & itName .~ "COMPLETEBURSTRIFLE" & itType .~ COMPLETEBURSTRIFLE - & itModules . modRifleMag .~ BlockedModule + & itModules . at ModRifleMag .~ Nothing & itParams . gunBarrels . brlInaccuracy .~ 0.1 & itUse . useDelay . rateMax .~ 28 & itUse . useMods .~ diff --git a/src/Dodge/Item/Weapon/BulletGun/Stick.hs b/src/Dodge/Item/Weapon/BulletGun/Stick.hs index c1666a807..162b7635e 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Stick.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Stick.hs @@ -199,12 +199,14 @@ autoPistol = pistol & itUse . useMods .~ (ammoCheckI : pistolAfterHamMods) & itName .~ "AUTOPISTOL" & itType .~ AUTOPISTOL + & itModules . at ModAutoMag ?~ DefaultModule machinePistol :: Item machinePistol = autoPistol & itUse . useDelay . rateMax .~ 2 & itUse . useMods .~ (ammoCheckI : machinePistolAfterHamMods) & itName .~ "MACHINEPISTOL" & itType .~ MACHINEPISTOL + & itModules . at ModAutoMag .~ Nothing smg :: Item smg = autoPistol -- & some parameter affecting stability & itUse . useMods .~ (ammoCheckI : smgAfterHamMods) diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index eb9229af9..9de8e4bcc 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -128,7 +128,7 @@ targetRBMousePos w = (f, \_ _ _ w' -> cursorPic w') where f _ = Just mwp mwp = mouseWorldPos w - cursorPic w' = setLayer 1 $ onLayer InvLayer $ uncurryV translate mwp + cursorPic w' = setLayer 1 $ color red $ onLayer InvLayer $ uncurryV translate mwp $ rotate (_cameraRot w') $ pictures [line [V2 x x, V2 (-x) (-x)] diff --git a/src/Dodge/Item/Weapon/InventoryDisplay.hs b/src/Dodge/Item/Weapon/InventoryDisplay.hs index 3c22225e1..6a7ebcc1c 100644 --- a/src/Dodge/Item/Weapon/InventoryDisplay.hs +++ b/src/Dodge/Item/Weapon/InventoryDisplay.hs @@ -10,6 +10,7 @@ module Dodge.Item.Weapon.InventoryDisplay import Dodge.Data import Padding import Dodge.Inventory.ItemSpace +import Dodge.Module import Data.Maybe import Data.Sequence @@ -37,10 +38,7 @@ basicItemDisplay it = Prelude.take (itSlotsTaken it) $ -- , maybeRateStatus ] -moduleStrings :: Item -> [String] -moduleStrings it = map (" " ++) - $ (fromMaybe [] $ it ^? itModules . modHitEffect . modName) - ++ (fromMaybe [] $ it ^? itModules . modRifleMag . modName) +-- this can be moved to Dodge/Module and unified with moduleSizes maybeModeStatus :: Item -> Maybe String maybeModeStatus it = case it ^? itAttachment of diff --git a/src/Dodge/Item/Weapon/TriggerType.hs b/src/Dodge/Item/Weapon/TriggerType.hs index cb665eb10..be94215d6 100644 --- a/src/Dodge/Item/Weapon/TriggerType.hs +++ b/src/Dodge/Item/Weapon/TriggerType.hs @@ -25,6 +25,9 @@ module Dodge.Item.Weapon.TriggerType , withSmoke , withThickSmokeI , withThinSmokeI + , withPositionOffset + , withPositionWallCheck + , withPosDirWallCheck , withRandomOffsetI , withRandomDirI , withRecoilI @@ -51,6 +54,7 @@ module Dodge.Item.Weapon.TriggerType ) where import Dodge.Data +import Dodge.Base.Collide import Dodge.SoundLogic import Dodge.Reloading import Dodge.WorldEvent @@ -398,6 +402,30 @@ withRandomItemParams rip eff it cr w = eff (it & itParams .~ it') cr $ w & randG where (it',g) = runState rip (_randGen w) +withPositionOffset + :: (Item -> Creature -> World -> (Point2,Float)) + -> ChainEffect +withPositionOffset h f it cr w = f it (cr & crPos .+.+~ p & crDir +~ a) w + where + (p,a) = h it cr w + +withPositionWallCheck + :: (Item -> Creature -> World -> Point2) + -> ChainEffect +withPositionWallCheck h f it cr w + | hasLOS p (_crPos cr) w = f it (cr & crPos .~ p) w + | otherwise = w + where + p = h it cr w +withPosDirWallCheck + :: (Item -> Creature -> World -> (Point2,Float)) + -> ChainEffect +withPosDirWallCheck h f it cr w + | hasLOS p (_crPos cr) w = f it (cr & crPos .~ p & crDir .~ a) w + | otherwise = w + where + (p,a) = h it cr w + {- | Apply the effect to a translated creature. -} withRandomOffsetI :: Float -- ^ Max possible translate diff --git a/src/Dodge/Module.hs b/src/Dodge/Module.hs index 38a172a79..487f1ae5d 100644 --- a/src/Dodge/Module.hs +++ b/src/Dodge/Module.hs @@ -1,10 +1,17 @@ module Dodge.Module - where + ( moduleSizes + , moduleStrings + ) where import Dodge.Data import Control.Lens import Data.Maybe moduleSizes :: Item -> Int -moduleSizes it = (fromMaybe 0 $ it ^? itModules . modHitEffect . modSize) - + (fromMaybe 0 $ it ^? itModules . modRifleMag . modSize) +moduleSizes = moduleFold (+) (^? modSize) 0 + +moduleStrings :: Item -> [String] +moduleStrings = moduleFold (++) (^? modName) [] + +moduleFold :: (m -> m -> m) -> (ItemModule -> Maybe m) -> m -> Item -> m +moduleFold g f e = foldr (g . fromMaybe e . f) e . _itModules diff --git a/src/Dodge/Reloading.hs b/src/Dodge/Reloading.hs index d36672e07..ae71d551b 100644 --- a/src/Dodge/Reloading.hs +++ b/src/Dodge/Reloading.hs @@ -1,7 +1,6 @@ module Dodge.Reloading where import Dodge.Data import Dodge.Base -import Dodge.Item.MaxAmmo --import qualified Data.IntMap.Strict as IM --import Data.Maybe @@ -14,7 +13,7 @@ startReloadingWeapon cr = (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) icTryStartReloading :: Item -> Maybe Item icTryStartReloading it - | _ammoLoaded am < itMaxAmmo it && _reloadState am == Nothing' + | _ammoLoaded am < _ammoBaseMax (_itConsumption it) && _reloadState am == Nothing' = Just $ it & itConsumption . reloadState .~ Just' (_reloadTime am) & if _reloadType am == ActiveClear then itConsumption . ammoLoaded .~ 0 else id | otherwise = Nothing @@ -36,14 +35,15 @@ stepReloading cr = case cr ^? crInv . ix isel . itConsumption . reloadState . _J isel = _crInvSel cr doload it = case _reloadType itcon of ActivePartial x - | x + _ammoLoaded itcon < itMaxAmmo it -> it & itConsumption . ammoLoaded %~ (+ x) + | x + _ammoLoaded itcon < itMaxAmmo -> it & itConsumption . ammoLoaded %~ (+ x) & itConsumption . reloadState .~ Just' (_reloadTime itcon) - | otherwise -> it & itConsumption . ammoLoaded .~ itMaxAmmo it + | otherwise -> it & itConsumption . ammoLoaded .~ itMaxAmmo & itConsumption . reloadState .~ Nothing' - _ -> it & itConsumption . ammoLoaded .~ itMaxAmmo it + _ -> it & itConsumption . ammoLoaded .~ itMaxAmmo & itConsumption . reloadState .~ Nothing' where itcon = _itConsumption it + itMaxAmmo = _ammoBaseMax itcon --{- | Start reloading if clip is empty. -} --crAutoReload :: Creature -> Creature diff --git a/src/Picture.hs b/src/Picture.hs index 129074bd3..5bb1de8e5 100644 --- a/src/Picture.hs +++ b/src/Picture.hs @@ -164,6 +164,7 @@ addDepth :: Float -> Picture -> Picture --addDepth d = map $ second $ overPos (\(x,y,z) -> (x,y,z+d)) addDepth d = map $ overPos (\(V3 x y z) -> V3 x y (z+d)) +-- TODO change the Int here to a dedicated type setLayer :: Int -> Picture -> Picture {-# INLINE setLayer #-} setLayer i = map f