Rethink item ammo to item consumables, start item type datatype

This commit is contained in:
2021-11-29 16:22:31 +00:00
parent 3a605b8156
commit f40d486d68
31 changed files with 238 additions and 193 deletions
+5 -5
View File
@@ -34,12 +34,12 @@ defaultAimParams = AimParams
useAmmoParams :: Item -> Creature -> World -> World
useAmmoParams it = withVelWthHiteff (_amBulVel b) (_amBulWth b) (_amBulEff b)
where
b = _aoType $ _wpAmmo it
b = _aoType $ _itConsumption it
useAmmoParamsVelMod :: Float -> Item -> Creature -> World -> World
useAmmoParamsVelMod vfact it = withDelayedVelWthHiteff vfact (_amBulVel b) (_amBulWth b) (_amBulEff b)
where
b = _aoType $ _wpAmmo it
b = _aoType $ _itConsumption it
{- | Creates a bullet with a given velocity, width, and 'HitEffect' -}
withVelWthHiteff
@@ -74,11 +74,11 @@ withDelayedVelWthHiteff vfact vel width hiteff cr = over particles (newbul : )
loadedAmmo :: Item -> Int
loadedAmmo it
| _wpReloadState (_wpAmmo it) == 0 = _wpLoadedAmmo (_wpAmmo it)
| _wpReloadState (_itConsumption it) == 0 = _wpLoadedAmmo (_itConsumption it)
| otherwise = 0
fractionLoadedAmmo :: Item -> Float
fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (_wpMaxAmmo (_wpAmmo it))
fractionLoadedAmmo it = fromIntegral (loadedAmmo it) / fromIntegral (_wpMaxAmmo (_itConsumption it))
fractionLoadedAmmo2 :: Item -> Float
fractionLoadedAmmo2 it = 1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral (_wpMaxAmmo (_wpAmmo it)))**2
fractionLoadedAmmo2 it = 1 - (1 - fromIntegral (loadedAmmo it) / fromIntegral (_wpMaxAmmo (_itConsumption it)))**2
+3 -3
View File
@@ -37,7 +37,7 @@ teslaGun :: Item
teslaGun = defaultGun
{ _itName = "TESLA"
, _itIdentity = TeslaGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 200
, _wpLoadedAmmo = 200
, _wpReloadTime = 80
@@ -67,7 +67,7 @@ lasGun :: Item
lasGun = defaultAutoGun
{ _itName = "LASGUN ////"
, _itIdentity = LasGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 200
, _wpLoadedAmmo = 200
, _wpReloadTime = 80
@@ -105,7 +105,7 @@ tractorGun :: Item
tractorGun = defaultAutoGun
{ _itName = "TRACTORGUN"
, _itIdentity = TractorGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 10000
, _wpLoadedAmmo = 10000
, _wpReloadTime = 40
+1 -1
View File
@@ -42,7 +42,7 @@ bezierGun = defaultGun
, _itScroll = \_ _ -> removeItTarget
, _itEffect = rbSetTarget
, _itZoom = defaultItZoom
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 50
}
}
+3 -3
View File
@@ -37,8 +37,8 @@ boostSelfL
-> World
-> World
boostSelfL x cr invid w = case boostPoint x cr w of
Left p -> crEff p (wpAmmo . wpLoadedAmmo .~ 0)
Right p -> crEff p (wpAmmo . wpLoadedAmmo -~ 1)
Left p -> crEff p (itConsumption . wpLoadedAmmo .~ 0)
Right p -> crEff p (itConsumption . wpLoadedAmmo -~ 1)
where
cid = _crID cr
cpos = _crPos cr
@@ -113,7 +113,7 @@ boosterGun :: Item
boosterGun = defaultGun
{ _itName = "BOOSTER"
, _itIdentity = Blinker
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
, _wpReloadTime = 20
+9 -9
View File
@@ -34,7 +34,7 @@ autoGun :: Item
autoGun = defaultAutoGun
{ _itName = "AUTOGUN"
, _itIdentity = AutoGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _wpMaxAmmo = 30
, _wpLoadedAmmo = 30
@@ -84,7 +84,7 @@ pistol :: Item
pistol = defaultGun
{ _itName = "PISTOL"
, _itIdentity = Pistol
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _wpMaxAmmo = 15
, _wpLoadedAmmo = 15
@@ -128,7 +128,7 @@ hvAutoGun :: Item
hvAutoGun = defaultAutoGun
{ _itName = "AUTO-HV"
, _itIdentity = HvAutoGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = hvBullet
, _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
@@ -164,7 +164,7 @@ ltAutoGun :: Item
ltAutoGun = defaultAutoGun
{ _itName = "AUTO-LT"
, _itIdentity = LtAutoGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = ltBullet
, _wpMaxAmmo = 25
, _wpLoadedAmmo = 25
@@ -200,7 +200,7 @@ miniGun :: Item
miniGun = defaultAutoGun
{ _itName = "MINI-G"
, _itIdentity = MiniGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _wpMaxAmmo = 1500
, _wpLoadedAmmo = 1500
@@ -262,7 +262,7 @@ miniGun = defaultAutoGun
miniGunPictItem :: Item -> SPic
miniGunPictItem it = miniGunPict spin (loadedAmmo it)
where
spin = (-10) * _wpLoadedAmmo (_wpAmmo it) + _warmTime (_useDelay $ _itUse it)
spin = (-10) * _wpLoadedAmmo (_itConsumption it) + _warmTime (_useDelay $ _itUse it)
miniGunPict :: Int -> Int -> SPic
miniGunPict spin am =
@@ -290,7 +290,7 @@ spreadGun :: Item
spreadGun = defaultGun
{ _itName = "SPREAD"
, _itIdentity = SpreadGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _wpMaxAmmo = 5
, _wpLoadedAmmo = 5
@@ -323,7 +323,7 @@ multGun :: Item
multGun = defaultGun
{ _itName = "MULTGUN"
, _itIdentity = MultGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
, _wpMaxAmmo = 2
, _wpLoadedAmmo = 2
@@ -368,7 +368,7 @@ longGun :: Item
longGun = defaultGun
{ _itName = "LONGGUN"
, _itIdentity = LongGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = hvBullet
, _wpMaxAmmo = 1
, _wpLoadedAmmo = 1
+2 -2
View File
@@ -22,7 +22,7 @@ lasDrones :: Item
lasDrones = defaultGun
{ _itName = "DRONES"
, _itIdentity = Generic
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = DroneAmmo { _amString = "LASDRONE" }
, _wpMaxAmmo = 2
, _wpLoadedAmmo = 2
@@ -58,7 +58,7 @@ aDroneWithItemParams
-> World
aDroneWithItemParams it cr w = over props (IM.insert i theShell) w
where
am = _wpAmmo it
am = _itConsumption it
i = IM.newKey $ _props w
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
dir = _crDir cr
+3 -3
View File
@@ -79,10 +79,10 @@ itemLaserScopeEffect
--glowPoint = case listToMaybe $ thingsHitLongLine sp xp w of
-- Just (pos,E3x2 wl) -> pos +.+ 2 *.* wallNormal wl
-- _ -> ep -.- 2 *.* unitVectorAtAngle d
it = (cr ^. crInv) IM.! invid
wpammo = _itConsumption $ (cr ^. crInv) IM.! invid
reloadFrac
| _wpLoadedAmmo (_wpAmmo it) == 0 = 1
| otherwise = fromIntegral (_wpReloadState (_wpAmmo it)) / fromIntegral (_wpReloadTime (_wpAmmo it))
| _wpLoadedAmmo wpammo == 0 = 1
| otherwise = fromIntegral (_wpReloadState wpammo) / fromIntegral (_wpReloadTime wpammo)
--col = mixColors reloadFrac (1-reloadFrac) red green
{- | Automatically send out radar pulses that detect walls. -}
autoRadarEffect :: ItEffect
+2 -1
View File
@@ -15,11 +15,12 @@ basicWeaponDisplay :: Item -> String
basicWeaponDisplay it = midPadL 10 ' ' thename (' ' : thenumber) ++ theparam
where
thename = _itName it
thenumber = case it ^? wpAmmo of
thenumber = case it ^? itConsumption of
Just am@LoadableAmmo{} -> case _wpReloadState am of
0 -> show $ _wpLoadedAmmo am
x -> "R" ++ show x
Just am@ChargeableAmmo{} -> show $ _wpCharge am
Just x@ItemItselfConsumable{} -> show $ _itMaxStack' x
Nothing -> ""
theparam = fromMaybe []
. listToMaybe
+3 -3
View File
@@ -37,7 +37,7 @@ launcher :: Item
launcher = defaultGun
{ _itName = "ROCKO"
, _itIdentity = Launcher
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
, _amString = ""
@@ -140,7 +140,7 @@ aRocketWithItemParams
-> World
aRocketWithItemParams it cr w = over props (IM.insert i theShell) w
where
am = _wpAmmo it
am = _itConsumption it
i = IM.newKey $ _props w
pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
dir = _crDir cr
@@ -240,7 +240,7 @@ remoteLauncher :: Item
remoteLauncher = defaultGun
{ _itName = "ROCKO-REM"
, _itIdentity = RemoteLauncher
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _aoType = defaultShellAmmo
{ _amPayload = makeExplosionAt
, _amString = ""
+2 -2
View File
@@ -22,7 +22,7 @@ radar :: Item
radar = defaultGun
{ _itName = "RADAR"
, _itIdentity = Generic
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
, _wpReloadTime = 200
@@ -44,7 +44,7 @@ sonar :: Item
sonar = defaultGun
{ _itName = "SONAR"
, _itIdentity = Generic
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
, _wpReloadTime = 200
+1 -1
View File
@@ -17,7 +17,7 @@ Creates a creature next to the creature using the item. -}
spawnGun :: Creature -> Item
spawnGun cr = defaultGun
{ _itName = "SPAWNER"
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 1
, _wpLoadedAmmo = 1
, _wpReloadTime = 80
+2 -2
View File
@@ -34,7 +34,7 @@ poisonSprayer :: Item
poisonSprayer = defaultAutoGun
{ _itName = "POISON"
, _itIdentity = PoisonSprayer
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 500
, _wpLoadedAmmo = 500
, _wpReloadTime = 100
@@ -58,7 +58,7 @@ flamer :: Item
flamer = defaultAutoGun
{ _itName = "FLAMER"
, _itIdentity = Flamethrower
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 250
, _wpLoadedAmmo = 250
, _wpReloadTime = 100
+20 -17
View File
@@ -95,10 +95,13 @@ withThickSmokeI eff item cr w = eff item cr
-- fire.
ammoCheckI :: ChainEffect
ammoCheckI eff item cr w
| _wpLoadedAmmo (_wpAmmo item) <= 0
= fromMaybe w (startReloadingWeapon cr w)
| _wpReloadState (_wpAmmo item) > 0 = w
| _wpLoadedAmmo (_itConsumption item) <= 0 = fromMaybe w (startReloadingWeapon cr w)
| _wpReloadState (_itConsumption item) > 0 = w
| otherwise = eff item cr w
itUseAmmo :: Int -> Item -> Item
itUseAmmo x = itConsumption . wpLoadedAmmo %~ (max 0 . subtract x)
{- | Fires at an increasing rate.
Has different effect after first fire.
Applies ammo check and use cooldown check. -}
@@ -109,12 +112,12 @@ rateIncAB
rateIncAB exeffFirst exeffCont eff item cr w
| repeatFire = w
& pointItem %~ ( (itUse . useDelay . rateMax .~ max fastRate (currentRate - 1))
. (wpAmmo . wpLoadedAmmo -~ 1)
. itUseAmmo 1
. (itUse . useDelay . rateTime .~ currentRate) )
& exeffCont eff item cr
| firstFire = w
& pointItem %~ ( (itUse . useDelay . rateMax .~ startRate - 1)
. (wpAmmo . wpLoadedAmmo -~ 1)
. itUseAmmo 1
. (itUse . useDelay . rateTime .~ startRate) )
& exeffFirst eff item cr
| otherwise = w
@@ -125,15 +128,15 @@ rateIncAB exeffFirst exeffCont eff item cr w
itRef = _crInvSel cr
pointItem = creatures . ix cid . crInv . ix itRef
currentRate = _rateMax (_useDelay (_itUse item))
repeatFire = _wpReloadState (_wpAmmo item) == 0 && _rateTime (_useDelay (_itUse item)) == 1
firstFire = _wpReloadState (_wpAmmo item) == 0 && _rateTime (_useDelay (_itUse item)) == 0
repeatFire = _wpReloadState (_itConsumption item) == 0 && _rateTime (_useDelay (_itUse item)) == 1
firstFire = _wpReloadState (_itConsumption item) == 0 && _rateTime (_useDelay (_itUse item)) == 0
{- | Apply effect after a warm up. -}
-- note this is quite unsafe, requires the item to have the correct delay type
withWarmUp
:: SoundID -- ^ warm up sound id
-> ChainEffect
withWarmUp soundID f item cr w
| _wpReloadState (_wpAmmo item) /= 0 = w
| _wpReloadState (_itConsumption item) /= 0 = w
| curWarmUp < maxWarmUp = w
& pointerToItem . itUse . useDelay . warmTime +~ 2
& soundContinue (CrWeaponSound cid 0) (_crPos cr) soundID (Just 2)
@@ -218,7 +221,7 @@ useAmmo
:: Int -- ^ amount of ammo to use
-> ChainEffect
useAmmo amAmount eff item cr = eff item cr
. (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . wpAmmo . wpLoadedAmmo -~ amAmount)
. (creatures . ix (_crID cr) . crInv . ix (_crInvSel cr) . itConsumption . wpLoadedAmmo -~ amAmount)
{- |
Applies a world effect after an item use cooldown check. -}
useTimeCheck :: ChainEffect
@@ -243,7 +246,7 @@ hammerCheckI f it cr w = case it ^? itUse . useHammer . hammerPosition of
ammoUseCheck :: ChainEffect
ammoUseCheck f item cr w
| fireCondition = f item cr w & pointerToItem %~
( (wpAmmo . wpLoadedAmmo -~ 1)
( itUseAmmo 1
. (itUse . useDelay . rateTime .~ _rateMax ( _useDelay (_itUse item)) ))
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
@@ -251,10 +254,10 @@ ammoUseCheck f item cr w
cid = _crID cr
itRef = _crInvSel cr
pointerToItem = creatures . ix cid . crInv . ix itRef
fireCondition = _wpReloadState (_wpAmmo item) == 0
fireCondition = _wpReloadState (_itConsumption item) == 0
&& _rateTime (_useDelay (_itUse item)) == 0
&& _wpLoadedAmmo (_wpAmmo item) > 0
reloadCondition = _wpLoadedAmmo (_wpAmmo item) == 0
&& _wpLoadedAmmo (_itConsumption item) > 0
reloadCondition = _wpLoadedAmmo (_itConsumption item) == 0
{- | Applies a world effect after a hammer position check.
Arbitrary inventory position. -}
hammerCheckL
@@ -278,7 +281,7 @@ shootL
-> World
shootL f cr invid w
| fireCondition = f cr invid w & pointerToItem %~
( (wpAmmo . wpLoadedAmmo -~ 1)
( itUseAmmo 1
. (itUse . useDelay . rateTime .~ _rateMax (_useDelay (_itUse item))) )
| reloadCondition = fromMaybe w $ startReloadingWeapon cr w
| otherwise = w
@@ -286,10 +289,10 @@ shootL f cr invid w
cid = _crID cr
item = _crInv cr IM.! invid
pointerToItem = creatures . ix cid . crInv . ix invid
fireCondition = _wpReloadState (_wpAmmo item) == 0
fireCondition = _wpReloadState (_itConsumption item) == 0
&& _rateTime (_useDelay (_itUse item)) == 0
&& _wpLoadedAmmo (_wpAmmo item) > 0
reloadCondition = _wpLoadedAmmo (_wpAmmo item) == 0
&& _wpLoadedAmmo (_itConsumption item) > 0
reloadCondition = _wpLoadedAmmo (_itConsumption item) == 0
withTempLight :: Int -> Float -> V3 Float -> ChainEffect
withTempLight time rad col eff item cr = eff item cr
. over tempLightSources (theTLS :)
+8 -7
View File
@@ -20,7 +20,7 @@ rewindGun :: Item
rewindGun = defaultGun
{ _itName = "REWINDER"
, _itIdentity = Rewinder
, _wpAmmo = ChargeableAmmo
, _itConsumption = ChargeableAmmo
{ _wpMaxCharge = 250
, _wpCharge = 0
}
@@ -30,11 +30,12 @@ rewindGun = defaultGun
rewindEffect :: ItEffect -> Creature -> Int -> World -> World
rewindEffect _ cr invid w
| Just invid == _crLeftInvSel cr = w & rewindWorlds %~ (take maxcharge . (w' : ))
& creatures . ix (_crID cr) . crInv . ix invid . wpAmmo . wpCharge .~ length (_rewindWorlds w)
& ptrWpCharge .~ length (_rewindWorlds w)
| otherwise = w & rewindWorlds .~ []
& creatures . ix (_crID cr) . crInv . ix invid . wpAmmo . wpCharge .~ 0
& ptrWpCharge .~ 0
where
maxcharge = _wpMaxCharge . _wpAmmo $ _crInv cr IM.! invid
ptrWpCharge = creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge
maxcharge = _wpMaxCharge . _itConsumption $ _crInv cr IM.! invid
w' = w & rewindWorlds .~ []
& rewinding .~ True
@@ -55,7 +56,7 @@ shrinkGun :: Item
shrinkGun = defaultGun
{ _itName = "SHRINKER"
, _itIdentity = Generic
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
, _wpReloadTime = 20
@@ -87,7 +88,7 @@ blinkGun :: Item
blinkGun = defaultGun
{ _itName = "BLINKER"
, _itIdentity = Blinker
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
, _wpReloadTime = 20
@@ -121,7 +122,7 @@ forceFieldGun :: Item
forceFieldGun = defaultGun
{ _itName = "FORCEFIELD"
, _itIdentity = ForceFieldGun
, _wpAmmo = defaultAmmo
, _itConsumption = defaultAmmo
{ _wpMaxAmmo = 100
, _wpLoadedAmmo = 100
, _wpReloadTime = 40