Fix aiming with no weapon crash

This commit is contained in:
2022-02-08 12:47:58 +00:00
parent 9ead5b3979
commit 0a860e6f68
39 changed files with 317 additions and 244 deletions
+3
View File
@@ -18,3 +18,6 @@ makeTypeCraft :: CombineType -> Item
makeTypeCraft = makeTypeCraftNum 1
pipe :: Item
pipe = makeTypeCraft PIPE
plateCraft :: Item
plateCraft = makeTypeCraft PLATE
-9
View File
@@ -20,15 +20,6 @@ pictureWeaponOnAim cr i = pictureWeaponOnAimItem (itSPic it) cr i
itSPic :: Item -> SPic
itSPic it = _dimSPic (_itDimension it) it
pictureWeaponOnAim'
:: (Item -> SPic)
-> Creature
-> Int -- ^ Position of item in inventory
-> SPic
pictureWeaponOnAim' f cr i = pictureWeaponOnAimItem pic cr i
where
pic = f (_crInv cr IM.! i)
pictureWeaponAim
:: (Item -> SPic)
-> Creature
+25 -6
View File
@@ -1,6 +1,7 @@
module Dodge.Item.Equipment where
import Dodge.Data
import Dodge.Item.Draw
import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Default
import Dodge.Default.Wall
import Dodge.Picture.Layer
@@ -14,8 +15,7 @@ import Geometry
import ShapePicture
import Shape
import qualified IntMapHelp as IM
import Control.Lens
import LensHelp
magShield :: Item
magShield = defaultEquipment
@@ -66,10 +66,29 @@ frontArmour = defaultEquipment
}
flatShield :: Item
flatShield = defaultEquipment
{ _itEquipPict = pictureWeaponOnAim' flatShieldEquipSPic -- this will not work any more because the shield has no aim stance
{ _itEquipPict = pictureWeaponAim flatShieldEquipSPic
, _itEffect = effectOnOffEquip createShieldWall removeShieldWall
, _itName = "SHIELD"
-- the above seems to work, but I am not sure why: it may break on edge
-- cases
, _itName = "FLATSHIELD"
, _itType = FLATSHIELD
, _itUse = RightUse
{ _rUse = \_ _ -> id
, _useDelay = NoDelay
, _useMods = []
, _useHammer = NoHammer
, _useAim = AimParams
{ _aimSpeed = 0.5
, _aimRange = 0
, _aimZoom = ItZoom 20 0.2 1
, _aimStance = TwoHandFlat
}
}
, _itInvSize = 3
, _itInvDisplay = \it -> head (basicItemDisplay it) :
["*" ++ replicate 13 ' ' ++ "*"
,"*" ++ replicate 13 ' ' ++ "*"
]
}
flatShieldEquipSPic :: Item -> SPic
flatShieldEquipSPic _ =
@@ -102,8 +121,8 @@ shieldWall crid = defaultWall
shieldWallDamage :: DamageType -> Wall -> Int -> World -> World
shieldWallDamage dt wl crid w = case dt of
Lasering {_dmFrom=df,_dmAt=da} ->
w & instantParticles %~ (makeLaserAt 5 (da +.+ normalizeV (df -.- da)) (reflDirWall df da wl) :)
d | isMovementDam d -> w & creatures . ix crid . crState . crDamage %~ (d :)
w & instantParticles .:~ lasRayAt 5 (da +.+ normalizeV (df -.- da)) (reflDirWall df da wl)
d | isMovementDam d -> w & creatures . ix crid . crState . crDamage .:~ d
_ -> w
createShieldWall :: Creature -> Int -> World -> World
+2
View File
@@ -1,6 +1,7 @@
{- | Rexport all weapons -}
module Dodge.Item.Weapon
( module Dodge.Item.Weapon.BulletGuns
, module Dodge.Item.Weapon.SonicGuns
, module Dodge.Item.Weapon.TriggerType
, module Dodge.Item.Weapon.ExtraEffect
, module Dodge.Item.Weapon.UseEffect
@@ -16,6 +17,7 @@ module Dodge.Item.Weapon
) where
import Dodge.Item.Weapon.BulletGuns
import Dodge.Item.Weapon.TriggerType
import Dodge.Item.Weapon.SonicGuns
import Dodge.Item.Weapon.ExtraEffect
import Dodge.Item.Weapon.UseEffect
import Dodge.Item.Weapon.Remote
+6 -7
View File
@@ -2,7 +2,7 @@ module Dodge.Item.Weapon.BatteryGuns
( lasGun
, teslaGun
, tractorGun
, makeLaserAt
, lasRayAt
) where
import Dodge.Data
import Dodge.Creature.HandPos
@@ -67,7 +67,7 @@ teslaGunPic _ = noPic $ colorSH blue $
xb = 9
lasGun :: Item
lasGun = defaultAutoGun
{ _itName = "LASGUN ////"
{ _itName = "LASGUN"
, _itType = LASGUN
, _itConsumption = defaultAmmo
{ _ammoMax = 200
@@ -156,15 +156,14 @@ aTeslaArc cr w = set randGen g w
chooseColor _ = cyan
aLaser :: Item -> Creature -> World -> World
aLaser it cr = particles .:~ makeLaserAt phasev pos dir
aLaser it cr = particles .:~ lasRayAt phasev pos dir
where
pos = _crPos cr +.+ aimingMuzzlePos cr it *.* unitVectorAtAngle dir
dir = _crDir cr
phasev = _phaseV . _itParams $ _crInv cr IM.! j
j = _crInvSel cr
phasev = _phaseV . _itParams $ _crInv cr IM.! _crInvSel cr
makeLaserAt :: Float -> Point2 -> Float -> Particle
makeLaserAt phasev pos dir = Particle
lasRayAt :: Float -> Point2 -> Float -> Particle
lasRayAt phasev pos dir = Particle
{ _ptDraw = const blank
, _ptUpdate = mvLaser phasev pos dir
}
+3 -1
View File
@@ -44,7 +44,9 @@ bangCane = defaultGun
{ _muzVel = 0.8
, _rifling = 0.9
, _bore = 2
, _gunBarrels = SingleBarrel 0.1
, _gunBarrels = SingleBarrel
{ _brlInaccuracy = 0.01
}
}
, _itConsumption = defaultAmmo
{ _aoType = basicBullet
+2 -2
View File
@@ -60,7 +60,7 @@ bangStick i = defaultGun
, withMuzFlareI
, torqueAfterI (0.18 + 0.02 * fromIntegral i)
, spreadLoaded
, applyInaccuracy
-- , applyInaccuracy
, withRecoilI 25
]
, _itID = Nothing
@@ -73,7 +73,7 @@ bangStick i = defaultGun
, _gunBarrels = MultiBarrel
{_brlNum = i
,_brlSpread = SpreadBarrels baseStickSpread
,_brlInaccuracy = 0.05
,_brlInaccuracy = 0.01
}
}
, _itTweaks = defaultBulletSelTweak
+2 -2
View File
@@ -127,7 +127,7 @@ throwArmReset x = ItInvEffect {_itInvEffect = f ,_itEffectCounter = x }
counterDown it
| _itEffectCounter (_itEffect it) == 0 = it
& itUse . useHammer . hammerPosition .~ HammerUp
& itEquipPict .~ pictureWeaponOnAim' (\_ -> grenadePic 50)
& itEquipPict .~ pictureWeaponAim (\_ -> grenadePic 50)
| otherwise = it & itEffect . itEffectCounter -~ 1
--flameGrenade :: Item
@@ -277,7 +277,7 @@ explodeRemoteBomb itid pjid cr w
cid = _crID cr
resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEBOMB"
resetPict = set (creatures . ix cid . crInv . ix j . itEquipPict )
(pictureWeaponOnAim' $ \_ -> (,) emptySH remoteBombUnarmedPic)
(pictureWeaponAim $ \_ -> (,) emptySH remoteBombUnarmedPic)
-- resetScope = creatures . ix cid . crInv . ix j . itScope . _Just . scopePos .~ (0,0)
j = _crInvSel $ _creatures w IM.! cid
remoteBombPic
+1 -1
View File
@@ -26,7 +26,7 @@ basicItemDisplay it = Prelude.take (itSlotsTaken it) $
Just' x -> show x ++ "R" ++ show (_ammoLoaded am)
Just am@ChargeableAmmo{} -> show $ _wpCharge am
Just x@ItemItselfConsumable{} -> "x" ++ show (_itAmount x)
Just NoConsumption -> "NOCONSUMPTION"
Just NoConsumption -> ""
Nothing -> ""
theparam = fromMaybe []
. listToMaybe
+2 -2
View File
@@ -138,7 +138,7 @@ doThrust pj w = w
& randGen .~ g
& props . ix i . pjVel %~ (\v -> accel +.+ frict *.* v)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& makeFlameletTimed (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
& makeFlamelet (oldPos -.- vel) 0 (vel +.+ rotateV (pi+sparkD) accel) Nothing 3 10
& smokeGen
where
accel = _pjAcc pj
@@ -344,7 +344,7 @@ moveRemoteShell cid itid pj w
)
& soundContinue (ShellSound i) newPos missileLaunchS (Just 1)
& smokeGen
& makeFlameletTimed oldPos 20 (0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
& makeFlamelet oldPos 20 (0.5 *.* rotateV (pi+sparkD) accel) Nothing 3 10
| time > -200 = case thingHit of
Just _ -> doExplosion $ stopSoundFrom (ShellSound i) w
Nothing -> w
+2 -2
View File
@@ -32,7 +32,7 @@ radar = defaultGun
& useAim . aimRange .~ 1
& useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1}
-- , _itZoom = defaultItZoom { _itZoomMax = 1}
, _itEquipPict = pictureWeaponOnAim' $ \_ -> (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
, _itEquipPict = pictureWeaponAim $ \_ -> (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
}
{- |
Sends out pulses that display creatures. -}
@@ -50,7 +50,7 @@ sonar = defaultGun
]
& useAim . aimRange .~ 1
& useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1}
, _itEquipPict = pictureWeaponOnAim' $ \_ -> (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
, _itEquipPict = pictureWeaponAim $ \_ -> (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
}
{- |
Automatically sends out pulses that display creatures. -}
+4 -3
View File
@@ -431,13 +431,14 @@ torqueAfterI
:: Float -- ^ Max possible rotation
-> ChainEffect
torqueAfterI torque feff item cr w
| cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w
-- | cid == 0 = rotateScope $ set randGen g $ over cameraRot (+rot) $ feff item cr w
| cid == 0 = set randGen g $ over cameraRot (+rot) $ feff item cr w
| otherwise = set randGen g $ over (creatures . ix cid . crDir) (+rot) $ feff item cr w
where
cid = _crID cr
(rot, g) = randomR (-torque,torque) $ _randGen w
rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
. itAttachment . scopePos %~ rotateV rot
-- rotateScope = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
-- . itAttachment . scopePos %~ rotateV rot
spreadNumI :: ChainEffect
spreadNumI eff item cr w = foldr f w dirs