Refactor shells
This commit is contained in:
@@ -17,9 +17,6 @@ import Data.Aeson.TH
|
||||
import Dodge.Data.Bullet
|
||||
import Dodge.Data.Payload
|
||||
|
||||
data ProjectileDraw = DrawShell | DrawRemoteShell | DrawDrone | DrawBlankProjectile
|
||||
deriving (Show, Eq, Ord, Enum, Bounded, Read) --Generic, Flat)
|
||||
|
||||
data ProjectileHoming
|
||||
= NoHoming
|
||||
| HomeUsingRemoteScreen {_phRemoteID :: NewInt ItmInt}
|
||||
@@ -29,7 +26,8 @@ data ProjectileHoming
|
||||
data ProjectileUpdate
|
||||
= ThrustPU {_pjuStart :: Int, _pjuEnd :: Int, _pjuSmokeless :: Bool}
|
||||
| StartSpinPU {_pjuTime :: Int, _pjuCID :: Int, _pjuSpinAmound :: Int}
|
||||
| RemoteDirectionPU {_pjuStart :: Int, _pjuEnd :: Int, _pjuControllerID :: ProjectileHoming}
|
||||
-- | RemoteDirectionPU {_pjuStart :: Int, _pjuEnd :: Int, _pjuControllerID :: ProjectileHoming}
|
||||
| RemoteDirectionPU {_pjuStart :: Int, _pjuEnd :: Int}
|
||||
| ReduceSpinPU {_pjuReduceSpin :: Float}
|
||||
| DestroyPU {_pjuScreenID :: Maybe (NewInt ItmInt)
|
||||
,_pjuTimer :: Int}
|
||||
@@ -66,7 +64,6 @@ makeLenses ''AmmoType
|
||||
makeLenses ''ProjectileHoming
|
||||
deriveJSON defaultOptions ''GasFuel
|
||||
deriveJSON defaultOptions ''ProjectileHoming
|
||||
deriveJSON defaultOptions ''ProjectileDraw
|
||||
deriveJSON defaultOptions ''ProjectileUpdate
|
||||
deriveJSON defaultOptions ''GasCreate
|
||||
deriveJSON defaultOptions ''ForceFieldType
|
||||
|
||||
@@ -13,17 +13,15 @@ import Geometry.Data
|
||||
|
||||
data ProjectileType
|
||||
= Grenade
|
||||
| Rocket
|
||||
| Rocket {_rocketHoming :: ProjectileHoming}
|
||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||
|
||||
data Projectile
|
||||
= Shell
|
||||
{ _prjPos :: Point2
|
||||
, _prjVel :: Point2
|
||||
-- , _prjAcc :: Point2
|
||||
, _prjDir :: Float
|
||||
, _prjSpin :: Float
|
||||
, _prjDraw :: ProjectileDraw
|
||||
, _prjID :: Int
|
||||
, _prjPayload :: Payload
|
||||
, _prjTimer :: Int
|
||||
@@ -35,5 +33,6 @@ data Projectile
|
||||
deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||
|
||||
makeLenses ''Projectile
|
||||
makeLenses ''ProjectileType
|
||||
deriveJSON defaultOptions ''ProjectileType
|
||||
deriveJSON defaultOptions ''Projectile
|
||||
|
||||
+11
-1
@@ -299,7 +299,7 @@ useLoadedAmmo itmtree cr (cme, w) (mzid, Just (mz, x, magtree)) = (,) (cme & cme
|
||||
MuzzleLaser -> shootLaser itmtree cr mz w
|
||||
MuzzleTesla -> shootTeslaArc itm cr mz w
|
||||
MuzzleTractor -> shootTractorBeam cr w
|
||||
MuzzleRLauncher -> createProjectile Rocket magtree mz itmtree cr w
|
||||
MuzzleRLauncher -> createProjectileR magtree mz itmtree cr w
|
||||
MuzzleGLauncher -> createProjectile Grenade magtree mz itmtree cr w
|
||||
MuzzleNozzle{} -> useGasParams mid mz itm cr $ walkNozzle mzid mz itm cr w
|
||||
MuzzleShatter -> shootShatter itm cr w
|
||||
@@ -606,6 +606,16 @@ determineProjectileTracking magtree itmtree = fromMaybe NoHoming $
|
||||
targetingtree <- lookup WeaponTargetingLink (itmtree ^. ldtRight)
|
||||
return $ HomeUsingTargeting (targetingtree ^. ldtValue . itID)
|
||||
|
||||
createProjectileR ::
|
||||
LabelDoubleTree ComposeLinkType Item ->
|
||||
Muzzle ->
|
||||
LabelDoubleTree ComposeLinkType Item ->
|
||||
Creature ->
|
||||
World ->
|
||||
World
|
||||
createProjectileR magtree muz itmtree cr =
|
||||
createProjectile (Rocket $ determineProjectileTracking magtree itmtree) magtree muz itmtree cr
|
||||
|
||||
createProjectile ::
|
||||
ProjectileType ->
|
||||
LabelDoubleTree ComposeLinkType Item ->
|
||||
|
||||
@@ -12,12 +12,6 @@ import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
|
||||
homingDrawType :: ProjectileHoming -> ProjectileDraw
|
||||
homingDrawType ht = case ht of
|
||||
NoHoming -> DrawShell
|
||||
HomeUsingRemoteScreen {} -> DrawRemoteShell
|
||||
HomeUsingTargeting {} -> DrawRemoteShell
|
||||
|
||||
-- assumes the mscreen is in your inventory
|
||||
createShell :: ProjectileHoming
|
||||
-> Maybe (NewInt ItmInt)
|
||||
@@ -34,7 +28,6 @@ createShell homing mdetonator mscreen smokestatus pjtype payload muz cr w = w
|
||||
, _prjZ = 20
|
||||
, _prjZVel = 5
|
||||
, _prjVel = rotateV dir (V2 speed 0) + cr ^. crPos - cr ^. crOldPos
|
||||
, _prjDraw = homingDrawType homing
|
||||
, _prjID = i
|
||||
-- , _prjAcc = rotateV dir (V2 3 0)
|
||||
, _prjDir = dir
|
||||
@@ -45,7 +38,7 @@ createShell homing mdetonator mscreen smokestatus pjtype payload muz cr w = w
|
||||
[ CollisionEffectPU (homing ^? phRemoteID) mdetonator mscreen
|
||||
, TimePU
|
||||
, StartSpinPU (lifespan - 15) (_crID cr) spinamount
|
||||
, RemoteDirectionPU (lifespan - thrustdelay) 0 homing
|
||||
, RemoteDirectionPU (lifespan - thrustdelay) 0
|
||||
, ReduceSpinPU (1 - spindrag * 2 / 200)
|
||||
] <> thrustorgrav
|
||||
, _prjType = pjtype
|
||||
@@ -53,13 +46,13 @@ createShell homing mdetonator mscreen smokestatus pjtype payload muz cr w = w
|
||||
where
|
||||
speed = case pjtype of
|
||||
Grenade -> 4
|
||||
Rocket -> 1
|
||||
Rocket{} -> 1
|
||||
lifespan = case pjtype of
|
||||
Grenade -> 150
|
||||
Rocket -> 350
|
||||
Rocket{} -> 350
|
||||
thrustorgrav = case pjtype of
|
||||
Grenade -> [ApplyGravityPU]
|
||||
Rocket -> [ThrustPU (lifespan - thrustdelay) 0 smokestatus]
|
||||
Rocket{} -> [ThrustPU (lifespan - thrustdelay) 0 smokestatus]
|
||||
spindrag = 1
|
||||
spinamount = 2
|
||||
thrustdelay = 20
|
||||
|
||||
@@ -9,16 +9,19 @@ import Geometry
|
||||
import Picture
|
||||
import Shape
|
||||
import ShapePicture
|
||||
import Control.Lens
|
||||
|
||||
drawProjectile :: Projectile -> SPic
|
||||
drawProjectile prj = case _prjDraw prj of
|
||||
DrawShell -> drawShell prj
|
||||
DrawRemoteShell -> drawRemoteShell prj
|
||||
DrawDrone -> drawShell prj
|
||||
DrawBlankProjectile -> mempty
|
||||
drawProjectile pj
|
||||
| Just (DestroyPU {}) <- pj ^? prjUpdates . ix 0 = mempty
|
||||
| Just NoHoming <- pj ^? prjType . rocketHoming =
|
||||
drawShell Nothing pj
|
||||
| Just _ <- pj ^? prjType . rocketHoming =
|
||||
drawRemoteShell pj
|
||||
| otherwise = drawShell Nothing pj
|
||||
|
||||
drawShell :: Projectile -> SPic
|
||||
drawShell pj =
|
||||
drawShell :: Maybe Color -> Projectile -> SPic
|
||||
drawShell mcol pj =
|
||||
noPic
|
||||
. translateSHz (_prjZ pj)
|
||||
. uncurryV translateSHxy (_prjPos pj)
|
||||
|
||||
@@ -39,8 +39,8 @@ upProjectile pu pj = case pu of
|
||||
StartSpinPU t cid spinamount
|
||||
| time == t -> trySpinByCID cid spinamount pj
|
||||
| otherwise -> id
|
||||
RemoteDirectionPU st et mscreenid
|
||||
| act st et -> pjRemoteSetDirection mscreenid pj
|
||||
RemoteDirectionPU st et
|
||||
| act st et -> pjRemoteSetDirection (pj ^? prjType . rocketHoming) pj
|
||||
| otherwise -> id
|
||||
ReduceSpinPU x -> reduceSpinBy x (_prjID pj)
|
||||
DestroyPU mitid 0 -> destroyProjectile mitid (_prjID pj)
|
||||
@@ -156,14 +156,14 @@ trySpinByCID cid i pj w = w & cWorld . lWorld . projectiles . ix pjid . prjSpin
|
||||
spinFactor = 5 * (6 - fromIntegral i)
|
||||
|
||||
-- note this only allows YOU to remotely track projectiles
|
||||
pjRemoteSetDirection :: ProjectileHoming -> Projectile -> World -> World
|
||||
pjRemoteSetDirection :: Maybe ProjectileHoming -> Projectile -> World -> World
|
||||
pjRemoteSetDirection ph pj w = case ph of
|
||||
HomeUsingRemoteScreen screenid
|
||||
Just (HomeUsingRemoteScreen screenid)
|
||||
| lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
|
||||
== lw ^? itemLocations . ix (_unNInt screenid) . ilInvID ->
|
||||
w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjDir
|
||||
.~ (w ^. wCam . camRot) + argV (w ^. input . mousePos)
|
||||
HomeUsingTargeting itid
|
||||
Just (HomeUsingTargeting itid)
|
||||
| Just tp <- w ^? pointerToItemID itid . itTargeting . itTgPos . _Just ->
|
||||
w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjDir
|
||||
%~ turnTo 0.2 (_prjPos pj) tp
|
||||
@@ -171,16 +171,6 @@ pjRemoteSetDirection ph pj w = case ph of
|
||||
where
|
||||
lw = w ^. cWorld . lWorld
|
||||
|
||||
--pjRemoteSetDirection mscreenid pj w = fromMaybe w $ do
|
||||
-- screenid <- fmap _unNInt mscreenid
|
||||
-- let newdir
|
||||
-- | w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . imSelectedItem
|
||||
-- == w ^? cWorld . lWorld . itemLocations . ix screenid . ilInvID
|
||||
-- = (w ^. wCam . camRot) + argV (_mousePos (_input w))
|
||||
-- | otherwise = _prjDir pj
|
||||
-- turntonewdir = magV (_prjAcc pj) *.* unitVectorAtAngle newdir
|
||||
-- return $ w & cWorld . lWorld . projectiles . ix (_prjID pj) . prjAcc .~ turntonewdir
|
||||
|
||||
reduceSpinBy :: Float -> Int -> World -> World
|
||||
reduceSpinBy x pjid = cWorld . lWorld . projectiles . ix pjid . prjSpin *~ x
|
||||
|
||||
@@ -189,7 +179,6 @@ decTimMvVel pj =
|
||||
cWorld . lWorld . projectiles . ix pjid
|
||||
%~ ( (prjTimer -~ 1)
|
||||
. (prjPos %~ (+.+ vel))
|
||||
-- . (prjAcc %~ rotateV rot)
|
||||
. (prjDir +~ rot)
|
||||
)
|
||||
where
|
||||
@@ -207,7 +196,7 @@ explodeShell ::
|
||||
explodeShell controlid mdetid screenid pj w =
|
||||
w
|
||||
& cWorld . lWorld . projectiles . ix pjid . prjUpdates .~ [DestroyPU screenid 30]
|
||||
& cWorld . lWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
||||
-- & cWorld . lWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
||||
& usePayload (_prjPayload pj) (_prjPos pj) (_prjVel pj)
|
||||
& stopSoundFrom (ShellSound pjid)
|
||||
& updatedetonator
|
||||
|
||||
@@ -20,7 +20,6 @@ selectUse itm _ w = fromMaybe w $ do
|
||||
return $
|
||||
w
|
||||
& cWorld . lWorld . projectiles . ix pjid . prjUpdates .~ [DestroyPU (Just itid) 30] -- 69 is placeholder, should be removed
|
||||
& cWorld . lWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
|
||||
-- & itPoint . itUse . heldUse .~ HeldDoNothing
|
||||
-- & itPoint . itUse . heldMods .~ DoNothingMod
|
||||
& usePayload (_prjPayload thepj) (_prjPos thepj) (_prjVel thepj)
|
||||
|
||||
Reference in New Issue
Block a user