From 3031f2478c6b01e3ddc2c64f21e7407ab1aa096e Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 19 Jul 2022 15:33:49 +0100 Subject: [PATCH] Split bullet spawning and bouncing/penetration --- src/Dodge/Bullet.hs | 25 ++++++------------------- src/Dodge/Combine/Combinations.hs | 10 +++++++++- src/Dodge/Combine/Data.hs | 3 +++ src/Dodge/Combine/Module.hs | 1 + src/Dodge/Creature.hs | 1 + src/Dodge/Data/Bullet.hs | 1 - src/Dodge/Data/Wall.hs | 1 + src/Dodge/Default/Wall.hs | 4 ++++ src/Dodge/Default/Weapon.hs | 7 ++++--- src/Dodge/Module.hs | 1 + src/Dodge/Placement/Instance/Wall.hs | 1 + src/Dodge/PosEvent.hs | 2 +- 12 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/Dodge/Bullet.hs b/src/Dodge/Bullet.hs index 05648692b..2bba058f1 100644 --- a/src/Dodge/Bullet.hs +++ b/src/Dodge/Bullet.hs @@ -21,7 +21,6 @@ import Control.Monad.State updateBullet :: World -> Bullet -> (World,Maybe Bullet) updateBullet w bu = case _buState bu of - DyingBulletState -> (w,Nothing) DelayedBullet x -> mvBullet x w bu _ -> mvBullet 1 w bu @@ -54,16 +53,12 @@ useAmmoParams it cr w = w & instantBullets .:~ (_amBullet bultype mvBullet :: Float -> World -> Bullet -> (World, Maybe Bullet) mvBullet x w bt' | t <= 0 || magV (_buVel bt) < 1 = (endspawn w,Nothing) - | otherwise = bimap (maybespawn . maybebounce) (fmap dodrag) $ + | otherwise = bimap maybebounce (fmap dodrag) $ hiteff bt hitstream w where endspawn w' = fromMaybe w' $ do partspawn <- bulletSpawn bt' return $ partspawn p w' - maybespawn w' = fromMaybe w' $ do - (hp,_) <- runIdentity (S.head_ hitstream) - partspawn <- bulletSpawn bt' - return $ partspawn (hp +.+ normalizeV (_buPos bt' -.- hp)) w' maybebounce = fromMaybe id $ do guard (_buEffect bt' == BounceBullet) (hp,crwl) <- runIdentity (S.head_ hitstream) @@ -101,15 +96,6 @@ bulletSpawn bu = case _buSpawn bu of BulBall IncBall -> Just incBallAt BulBall ConcBall -> Just $ randParticleAt concBall BulBall TeslaBall -> Just makeStaticBall --- where --- dosatate st p w = w' --- & --- where --- (pt,g) = runState do --- partspawn <- bulletSpawn bt' --- let (thepart,g) = runState (partspawn hp) $ _randGen w' --- return $ w' & instantParticles .:~ thepart --- & randGen .~ g hitEffFromBul :: Float -> Bullet -> Stream (Of (Point2, Either Creature Wall)) Identity () @@ -138,10 +124,11 @@ moveBullet x pt = Just $ pt destroyAt' :: Point2 -> Bullet -> Maybe Bullet destroyAt' hitp pt = Just $ pt - & buState .~ DyingBulletState - & buPos .~ hitp - & buOldPos .~ _buPos pt - & buTimer %~ (min 3 . subtract 1) + & buPos .~ hitp +.+ normalizeV (p -.- hitp) + & buOldPos .~ p + & buVel .~ 0 + where + p = _buPos pt --penWalls -- :: HitCreatureEffect' diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index b700ec8b1..cbd9015dd 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -118,6 +118,9 @@ itemCombinations = hd = HELD eq = EQUIP +-- so there are two requirements for a module combination: the module slot must +-- exist on the item, and the item must be in the given list below +-- these two requirements should probably be combined moduleCombinations :: [( ModuleSlot, [Item], [([ItemBaseType],ItemModuleType)] )] moduleCombinations = [ ( ModRifleMag @@ -147,9 +150,14 @@ moduleCombinations = ] ) , ( ModBullet + , bulletWeapons + , [amod [cr BOUNCEMODULE] BOUNCEBUL + ,amod [cr PENMODULE] PENBUL + ] + ) + , ( ModBulletSpawn , bulletWeapons , [amod [cr INCENDIARYMODULE] INCENDBUL - ,amod [cr BOUNCEMODULE] BOUNCEBUL ,amod [cr STATICMODULE] STATICBUL ,amod [cr CONCUSSMODULE] CONCUSBUL ] diff --git a/src/Dodge/Combine/Data.hs b/src/Dodge/Combine/Data.hs index 69a376d6c..1949d2855 100644 --- a/src/Dodge/Combine/Data.hs +++ b/src/Dodge/Combine/Data.hs @@ -61,6 +61,7 @@ data CraftType | FRAGMODULE | FLASHMODULE | BOUNCEMODULE + | PENMODULE -- | TELEPORTMODULE | TIMEMODULE @@ -184,6 +185,7 @@ data ItemModuleType | MAGNETMAG | INCENDBUL | BOUNCEBUL + | PENBUL | STATICBUL | CONCUSBUL | TARGCR @@ -209,6 +211,7 @@ data Detector data ModuleSlot = ModBullet + | ModBulletSpawn | ModRifleMag | ModAutoMag | ModTarget diff --git a/src/Dodge/Combine/Module.hs b/src/Dodge/Combine/Module.hs index 2193f95ec..b91921bb4 100644 --- a/src/Dodge/Combine/Module.hs +++ b/src/Dodge/Combine/Module.hs @@ -19,6 +19,7 @@ moduleModification imt = case imt of MAGNETMAG -> itUse . useDelay . rateMax .~ 4 INCENDBUL -> itConsumption . laAmmoType . amBullet . buSpawn .~ BulBall IncBall BOUNCEBUL -> itConsumption . laAmmoType . amBullet . buEffect .~ BounceBullet + PENBUL -> itConsumption . laAmmoType . amBullet . buEffect .~ PenetrateBullet STATICBUL -> itConsumption . laAmmoType . amBullet . buSpawn .~ BulBall TeslaBall CONCUSBUL -> itConsumption . laAmmoType . amBullet . buSpawn .~ BulBall ConcBall TARGCR -> itTargeting .~ targetRBCreature diff --git a/src/Dodge/Creature.hs b/src/Dodge/Creature.hs index d23a97dce..063f06862 100644 --- a/src/Dodge/Creature.hs +++ b/src/Dodge/Creature.hs @@ -239,6 +239,7 @@ inventoryX c = case c of , makeTypeCraftNum 1 SOUNDSENSOR , makeTypeCraftNum 1 HEATSENSOR , makeTypeCraftNum 1 BOUNCEMODULE + , makeTypeCraftNum 1 PENMODULE , makeTypeCraftNum 1 INCENDIARYMODULE , makeTypeCraftNum 1 CONCUSSMODULE , makeTypeCraftNum 1 STATICMODULE diff --git a/src/Dodge/Data/Bullet.hs b/src/Dodge/Data/Bullet.hs index 3771d83e2..8a0f90ae0 100644 --- a/src/Dodge/Data/Bullet.hs +++ b/src/Dodge/Data/Bullet.hs @@ -20,7 +20,6 @@ data Bullet = Bullet } data EnergyBallType = IncBall | TeslaBall | ConcBall data BulletState = NormalBulletState - | DyingBulletState | DelayedBullet Float data BulletUpdateMod = NoBulletUpdateMod data BulletEffect diff --git a/src/Dodge/Data/Wall.hs b/src/Dodge/Data/Wall.hs index d89f7256c..2c9db2f7d 100644 --- a/src/Dodge/Data/Wall.hs +++ b/src/Dodge/Data/Wall.hs @@ -15,6 +15,7 @@ data Wall = Wall , _wlSeen :: Bool , _wlOpacity :: Opacity , _wlPathable :: Bool + , _wlPenetrable :: Bool , _wlWalkable :: Bool , _wlTouchThrough :: Bool , _wlFireThrough :: Bool diff --git a/src/Dodge/Default/Wall.hs b/src/Dodge/Default/Wall.hs index 0ffa1b097..db85d83f4 100644 --- a/src/Dodge/Default/Wall.hs +++ b/src/Dodge/Default/Wall.hs @@ -13,6 +13,7 @@ defaultWall = Wall , _wlSeen = False , _wlOpacity = Opaque , _wlPathable = False + , _wlPenetrable = False , _wlFireThrough = False , _wlTouchThrough = False , _wlReflect = False @@ -41,6 +42,7 @@ defaultMachineWall = defaultWall , _wlRotateTo = False , _wlStructure = MachinePart 0 , _wlMaterial = Metal + , _wlPenetrable = True } defaultDirtWall :: Wall defaultDirtWall = defaultWall @@ -51,6 +53,7 @@ defaultDirtWall = defaultWall , _wlOpacity = Opaque , _wlRotateTo = False , _wlFireThrough = True + , _wlPenetrable = True , _wlMaterial = Dirt } defaultWindow :: Wall @@ -62,4 +65,5 @@ defaultWindow = defaultWall , _wlOpacity = SeeThrough , _wlFireThrough = True , _wlMaterial = Glass + , _wlPenetrable = True } diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index abe8c4d86..d279f026a 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -100,9 +100,7 @@ defaultWeapon = defaultItem & itUse .~ defaultrUse & itInvColor .~ white & itType . iyModules .~ M.fromList - [(ModBullet, EMPTYMODULE) - ,(ModTarget, EMPTYMODULE) - ,(ModBulletTrajectory, EMPTYMODULE) + [(ModTarget, EMPTYMODULE) ,(ModTeleport, EMPTYMODULE) ] @@ -110,6 +108,9 @@ defaultBulletWeapon :: Item defaultBulletWeapon = defaultWeapon & itConsumption .~ defaultBulletLoadable & itUse . rUse .~ useAmmoParams + & itType . iyModules . at ModBullet ?~ EMPTYMODULE + & itType . iyModules . at ModBulletSpawn ?~ EMPTYMODULE + & itType . iyModules . at ModBulletTrajectory ?~ EMPTYMODULE defaultItemValue :: ItemValue defaultItemValue = ItemValue 10 MundaneItem diff --git a/src/Dodge/Module.hs b/src/Dodge/Module.hs index dec31069f..475089119 100644 --- a/src/Dodge/Module.hs +++ b/src/Dodge/Module.hs @@ -31,6 +31,7 @@ moduleName imt = case imt of MAGNETMAG -> Just "+MAGNET FEED" INCENDBUL -> Just "+INCENDIARY" BOUNCEBUL -> Just "+BOUNCE" + PENBUL -> Just "+PENETRATE" STATICBUL -> Just "+STATIC" CONCUSBUL -> Just "+CONCUSS" TARGCR -> Just "+CREATURETARGETING" diff --git a/src/Dodge/Placement/Instance/Wall.hs b/src/Dodge/Placement/Instance/Wall.hs index dc014848f..c810ca019 100644 --- a/src/Dodge/Placement/Instance/Wall.hs +++ b/src/Dodge/Placement/Instance/Wall.hs @@ -87,6 +87,7 @@ baseBlockPane = defaultWall , _wlOpacity = Opaque , _wlUnshadowed = True , _wlFireThrough = True + , _wlPenetrable = True } -- TODO find home for this {- Replaces instances of a given 'PutID' with 'PSType's drawn from a list. -} diff --git a/src/Dodge/PosEvent.hs b/src/Dodge/PosEvent.hs index 8fb29803b..acc83a9c1 100644 --- a/src/Dodge/PosEvent.hs +++ b/src/Dodge/PosEvent.hs @@ -18,7 +18,7 @@ posEventEffect pv = case _pvType pv of SparkSpawner -> spawnElectricalSparks (_pvPos pv) spawnElectricalSparks :: Point2 -> World -> World -spawnElectricalSparks p = randSpark ELECTRICAL rspeed rcol rdir p +spawnElectricalSparks = randSpark ELECTRICAL rspeed rcol rdir where rspeed = state (randomR (3,6)) rcol = brightX 100 1.5 <$> takeOne [white,azure,blue,cyan]