Continue reload refactor

This commit is contained in:
2022-06-21 14:07:17 +01:00
parent 14a7189b44
commit 53c8be0679
33 changed files with 106 additions and 115 deletions
+4 -4
View File
@@ -243,16 +243,16 @@ stripNoItems cr = organiseInvKeys (_crID cr) .
organiseInvKeys :: Int -> World -> World
organiseInvKeys cid w = w & creatures . ix cid %~
( ( crInvSel .~ newSelKey ) . (crInv .~ newInv ) )
( ( crInvSel . iselPos .~ newSelKey ) . (crInv .~ newInv ) )
where
cr = _creatures w IM.! cid
pairs = IM.toList (_crInv cr)
newSelKey = fromMaybe 0 $ findIndex ( (== _crInvSel cr) . fst) pairs
newSelKey = fromMaybe 0 $ findIndex ( (== crSel cr) . fst) pairs
newInv = IM.fromAscList $ zip [0..] $ map snd pairs
dropUnselected :: Creature -> World -> World
dropUnselected cr w = foldr (dropItem cr) w . IM.keys
$ _crInvSel cr `IM.delete` _crInv cr
$ crSel cr `IM.delete` _crInv cr
dropExcept :: Creature -> Int -> World -> World
dropExcept cr invid w = foldr (dropItem cr) w . IM.keys
@@ -276,7 +276,7 @@ youDropItem w
youDropItem' :: World -> World
youDropItem' w = case yourItem w ^? _Just . itCurseStatus of
Just Uncursed -> w
& dropItem cr (_crInvSel cr)
& dropItem cr (crSel cr)
& soundStart (CrSound (_crID cr)) (_crPos cr) whiteNoiseFadeOutS Nothing
_ -> w
where
-1
View File
@@ -31,7 +31,6 @@ autoCrit = defaultCreature
, _crGoal = []
}
, _crInv = IM.fromList [(0,autoGun),(1,medkit 100)]
, _crInvSel = 0
, _crRad = 10
, _crHP = 300
, _crMvType = defaultAimMvType
+1 -1
View File
@@ -61,7 +61,7 @@ followImpulse cr w imp = case imp of
TurnTo p -> crup $ creatureTurnTo p cr
ChangePosture post -> crup $ cr & crStance . posture .~ post
UseItem -> (useItem cr, cr)
SwitchToItem i -> crup $ cr & crInvSel .~ i
SwitchToItem i -> crup $ cr & crInvSel .~ InvSel i NoInvSelAction
Melee cid' -> (hitCr cid'
, crMvBy (10 *.* normalizeV (posFromID cid' -.- cpos)) $ cr & crMeleeCooldown .~ 20)
RandomTurn a -> (randGen .~ snd (rr a), creatureTurn (fst $ rr a) cr)
+7 -7
View File
@@ -13,7 +13,7 @@ import Data.Maybe
useItem :: Creature -> World -> World
useItem cr' w = fromMaybe (f w) $ do
cr <- w ^? creatures . ix (_crID cr')
it <- cr ^? crInv . ix (_crInvSel cr)
it <- cr ^? crInv . ix (crSel cr)
return $ itemEffect cr it w
where
f = creatures . ix (_crID cr') . crHammerPosition .~ HammerDown
@@ -25,7 +25,7 @@ itemEffect cr it w = case it ^? itUse of
Just LeftUse {} -> doequipmentchange
Just EquipUse{} -> doequipmentchange
-- ConsumeUse will cause problems if the item is not selected
Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ eff it cr . rmInvItem (_crID cr) (_crInvSel cr)
Just (ConsumeUse eff) -> setuhamdown $ hammerTest $ eff it cr . rmInvItem (_crID cr) (crSel cr)
Just NoUse -> setuhamdown w
Nothing -> setuhamdown w
where
@@ -33,7 +33,7 @@ itemEffect cr it w = case it ^? itUse of
HammerUp -> f w
_ -> w & setuhamdown
setuhamdown = creatures . ix (_crID cr) . crHammerPosition .~ HammerDown
doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (_crInvSel cr) cr
doequipmentchange = setuhamdown $ hammerTest (toggleEquipmentAt (_rbOptions w) (crSel cr) cr
. activateEquipmentAt (_rbOptions w) cr)
activateEquipmentAt :: RightButtonOptions -> Creature -> World -> World
@@ -72,7 +72,7 @@ toggleEquipmentAt rbops invid cr w = case rbops ^? opAllocateEquipment of
where
crpoint = creatures . ix (_crID cr)
itmat i = _crInv cr IM.! i
itm = itmat (_crInvSel cr)
itm = itmat (crSel cr)
onequip itm' = (_eqOnEquip . _eqEq . _itUse) itm' itm'
onremove itm' = (_eqOnRemove . _eqEq . _itUse) itm' itm'
@@ -87,8 +87,8 @@ useLeftItem cid w
return $ f itm cr w
where
cr = _creatures w IM.! cid
itmShouldBeUsed = isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . cUse)
|| ( isJust (cr ^? crInv . ix (_crInvSel cr) . itUse . eqEq . eqUse)
&& _crLeftInvSel cr /= Just (_crInvSel cr)
itmShouldBeUsed = isJust (cr ^? crInv . ix (crSel cr) . itUse . cUse)
|| ( isJust (cr ^? crInv . ix (crSel cr) . itUse . eqEq . eqUse)
&& _crLeftInvSel cr /= Just (crSel cr)
)
-- TODO determine itmShouldBeUsed with reference to config options
-1
View File
@@ -46,7 +46,6 @@ launcherCrit = defaultCreature
, _crGoal = []
}
, _crInv = IM.fromList [(0,launcher)]
, _crInvSel = 0
, _crRad = 10
, _crState = defaultState
, _crHP = 300
-1
View File
@@ -50,7 +50,6 @@ ltAutoCrit = defaultCreature
, _crGoal = []
}
, _crInv = IM.fromList [(0,autoPistol),(1,medkit 100)]
, _crInvSel = 0
, _crRad = 10
, _crHP = 500
}
-1
View File
@@ -47,7 +47,6 @@ pistolCrit = defaultCreature
, _crGoal = []
}
, _crInv = IM.fromList [(0,pistol),(1,medkit 100)]
, _crInvSel = 0
, _crRad = 10
, _crHP = 500
}
+1 -1
View File
@@ -125,7 +125,7 @@ doStrategyActions cr = case cr ^? crActionPlan . crStrategy of
reloadOverride :: Creature -> Creature
reloadOverride cr
| cr ^? crInv . ix (_crInvSel cr) . itConsumption . laLoaded == Just 0
| cr ^? crInv . ix (crSel cr) . itConsumption . laLoaded == Just 0
&& cr ^. crStance . posture == Aiming
= cr & crActionPlan . crStrategy .~ StrategyActions Reload reloadActions
| otherwise = cr
-1
View File
@@ -52,7 +52,6 @@ spreadGunCrit = defaultCreature
, _crGoal = []
}
, _crInv = IM.fromList [(0,bangStick 6),(1,medkit 100)]
, _crInvSel = 0
, _crRad = 10
, _crHP = 500
}
-1
View File
@@ -29,7 +29,6 @@ data FootForward
deriving
(Eq,Ord,Show)
data Posture = Aiming
| Reloading
| AtEase
deriving
(Eq,Ord,Show)
+3 -3
View File
@@ -217,8 +217,8 @@ invSideEff cr w = weaponReloadSounds cr $ IM.foldrWithKey f w (_crInv cr)
itemUpdate :: Creature -> Int -> Item -> Item
itemUpdate cr i
| i == _crInvSel cr = baseupdate True
| otherwise = baseupdate False
| i == crSel cr = baseupdate True
| otherwise = baseupdate False
where
baseupdate bool = (itUse %~ useUpdate) . (itInvPos ?~ i) . (itIsHeld .~ bool)
@@ -230,7 +230,7 @@ doItemTargeting invid cr w = case cr ^? crInv . ix invid . itTargeting of
in w' & creatures . ix (_crID cr) . crInv . ix invid . itTargeting .~ t'
weaponReloadSounds :: Creature -> World -> World
weaponReloadSounds cr w = case cr ^? crInvSelAction of
weaponReloadSounds cr w = case cr ^? crInvSel . iselAction of
Just ReloadAction{} -> soundContinue (CrReloadSound cid) (_crPos cr) reloadS (Just 1) w
_ -> w
-- PassiveReload stype | Just (_laReloadTime am) == am ^? laTransfer . transferTime
+3 -2
View File
@@ -3,6 +3,7 @@ module Dodge.Creature.Statistics
, getCrDexterity
) where
import Dodge.Data
import Dodge.Creature.Test
import qualified IntMapHelp as IM
import LensHelp
@@ -31,6 +32,6 @@ crCurrentEquipment cr = merge dropMissing dropMissing (zipWithMatched (\_ _ itm
strFromHeldItem :: Creature -> Int
strFromHeldItem cr
| _posture (_crStance cr) == Aiming || _posture (_crStance cr) == Reloading
= negate $ fromMaybe 0 $ cr ^? crInv . ix (_crInvSel cr) . itUse . useAim . aimWeight
| _posture (_crStance cr) == Aiming || crIsReloading cr
= negate $ fromMaybe 0 $ cr ^? crInv . ix (crSel cr) . itUse . useAim . aimWeight
| otherwise = 0
+5 -5
View File
@@ -24,12 +24,12 @@ onBoth :: (a -> b -> c) -> (d -> a) -> (d -> b) -> d -> c
onBoth f g h x = f (g x) (h x)
crIsReloading :: Creature -> Bool
crIsReloading cr = case cr ^? crStance . posture of
Just Reloading -> True
crIsReloading cr = case cr ^? crInvSel . iselAction of
Just ReloadAction {} -> True
_ -> False
crWeaponReady :: Creature -> Bool
crWeaponReady cr = isNothing $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . laProgress . _Just
crWeaponReady cr = isNothing $ cr ^? crInv . ix (crSel cr) . itConsumption . laProgress . _Just
crCanSeeCr :: Creature -> (World, Creature) -> Bool
crCanSeeCr tcr (w,cr) = hasLOS (_crPos cr) (_crPos tcr) w
@@ -65,14 +65,14 @@ crAwayFromPost cr = case find sentinelGoal . _crGoal $ _crActionPlan cr of
sentinelGoal _ = False
crHasAmmo :: Creature -> Bool
crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . laLoaded
crHasAmmo cr = maybe False (> 0) $ cr ^? crInv . ix (crSel cr) . itConsumption . laLoaded
crCanShoot :: Creature -> Bool
crCanShoot p = crIsAiming p && crHasAmmo p
crInAimStance :: AimStance -> Creature -> Bool
crInAimStance as cr = crIsAiming cr -- || (_posture (_crStance cr) == Reloading && hasAmmo cr)
&& cr ^? crInv . ix (_crInvSel cr) . itUse . useAim . aimStance == Just as
&& cr ^? crInv . ix (crSel cr) . itUse . useAim . aimStance == Just as
oneH :: Creature -> Bool
oneH = crInAimStance OneHand
+4 -6
View File
@@ -4,6 +4,7 @@ module Dodge.Creature.YourControl
import Dodge.Data
import Dodge.Base.Coordinate
import Dodge.Creature.Impulse.Movement
import Dodge.Creature.Test
import Dodge.Update.UsingInput
import Dodge.InputFocus
--import Dodge.Config.KeyConfig
@@ -33,7 +34,7 @@ wasdWithAiming
-> Creature
wasdWithAiming w speed cr
| isAiming = addAnyTwist $ set crDir mouseDir $ theMovement cr
| isReloading && SDL.ButtonRight `S.member` _mouseButtons w
| crIsReloading cr && SDL.ButtonRight `S.member` _mouseButtons w
= addAnyTwist $ set crDir (mouseDir + anytwist) $ theMovement cr
| otherwise = theMovement $ theTurn $ removeTwist cr
where
@@ -41,7 +42,7 @@ wasdWithAiming w speed cr
removeTwist cr' = cr'
& crDir +~ _crTwist cr'
& crTwist .~ 0
anytwist = case cr ^? crInv . ix (_crInvSel cr) . itUse . useAim . aimStance of
anytwist = case cr ^? crInv . ix (crSel cr) . itUse . useAim . aimStance of
Just TwoHandTwist -> twistamount * pi
_ -> 0
addAnyTwist = crTwist .~ anytwist
@@ -53,8 +54,7 @@ wasdWithAiming w speed cr
dir = _cameraRot w + argV movDir
movAbs = rotateV (_cameraRot w) $ normalizeV movDir
isAiming = _posture (_crStance cr) == Aiming
isReloading = _posture (_crStance cr) == Reloading
mouseDir = case cr ^? crInv . ix (_crInvSel cr) . itScope . scopePos of
mouseDir = case cr ^? crInv . ix (crSel cr) . itScope . scopePos of
Just _ -> argV $ mouseWorldPos w -.- _crPos cr
_ -> argV (_mousePos w) + _cameraRot w
@@ -72,9 +72,7 @@ wasdDir = foldr ((+.+) . wasdM) (V2 0 0) . _keys
{- | Set posture according to mouse presses. -}
mouseActionsCr :: S.Set SDL.MouseButton -> Creature -> Creature
mouseActionsCr pkeys cr
| _posture (_crStance cr) == Reloading = cr
| rbPressed = cr & crStance . posture .~ Aiming
| otherwise = cr & crStance . posture .~ AtEase
where
-- reloading = isJust $ cr ^? crInv . ix (_crInvSel cr) . itConsumption . laReloadState . _Just'
rbPressed = SDL.ButtonRight `S.member` pkeys