Rethink damage data type, work on damage sensors
This commit is contained in:
@@ -124,11 +124,12 @@ mntLSLampCol shp (V4 x y z _) wallp lampp = mntLSOn shp Nothing (defaultLS & lsP
|
||||
col = V3 x y z
|
||||
|
||||
mntLSCond :: (Point2 -> Point3 -> Shape)
|
||||
-> (RoomPos -> Room -> Maybe (PlacementSpot,RoomPos))
|
||||
-- -> (RoomPos -> Room -> Maybe (PlacementSpot,RoomPos))
|
||||
-> PlacementSpot
|
||||
-> Placement
|
||||
mntLSCond shp shift = -- updatePSToLevel 1 (const $ PSLnk shift (const id) Nothing) $
|
||||
mntLSCond shp ps = -- updatePSToLevel 1 (const $ PSLnk shift (const id) Nothing) $
|
||||
mntLS shp 0 (V3 0 (-40) 90)
|
||||
& plSpot .~ PSPos shift (const id) Nothing
|
||||
& plSpot .~ ps
|
||||
-- note that this perhaps pushes the vshape light out too far
|
||||
|
||||
mntLight :: Point2 -> Point2 -> Placement
|
||||
@@ -136,11 +137,10 @@ mntLight a b = RandomPlacement $ do
|
||||
shp <- takeOne [vShape,iShape,lShape,jShape,liShape]
|
||||
return $ mntLS shp a (addZ 90 b)
|
||||
|
||||
mntLightLnkCond :: (RoomPos -> Room -> Maybe (PlacementSpot,RoomPos))
|
||||
-> Placement
|
||||
mntLightLnkCond f = RandomPlacement $ do
|
||||
mntLightLnkCond :: PlacementSpot -> Placement
|
||||
mntLightLnkCond ps = RandomPlacement $ do
|
||||
shp <- takeOne [vShape,iShape,lShape,jShape,liShape]
|
||||
return $ mntLSCond shp f
|
||||
return $ mntLSCond shp ps
|
||||
|
||||
spanLSLightI :: LightSource -> Float -> Point2 -> Point2 -> Placement
|
||||
spanLSLightI ls h a b = ps0j (PutLS $ ls & lsParam . lsPos .~ V3 x y h)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module Dodge.Placement.Instance.Sensor
|
||||
( lightSensor
|
||||
, damageSensor
|
||||
) where
|
||||
import Color
|
||||
import Dodge.LightSource
|
||||
@@ -14,41 +15,42 @@ import Control.Lens
|
||||
import Data.Either
|
||||
|
||||
damageSensor
|
||||
:: (DamageType -> Either Int Int) -- Left gets sensed, Right does damage
|
||||
:: DamageType -- Left gets sensed, Right does damage
|
||||
-> Float
|
||||
-> (Machine -> World -> World)
|
||||
-> PlacementSpot -> Placement
|
||||
damageSensor damF wdth upf ps = pContID ps ( PutLS theLS)
|
||||
damageSensor damF wdth upf ps = pContID ps (PutLS theLS)
|
||||
$ \lsid -> Just $ spNoID ps $ PutMachine yellow (reverse $ square wdth) defaultMachine
|
||||
{ _mcDraw = sensorSPic wdth
|
||||
, _mcUpdate = \mc w -> upf mc $ sensorUpdate damF mc w
|
||||
, _mcUpdate = \mc -> upf mc . sensorUpdate damF mc
|
||||
, _mcLSs = [lsid]
|
||||
}
|
||||
where
|
||||
theLS = lsPosCol (V3 0 0 30) 0.1
|
||||
|
||||
lightSensor :: Float -> (Machine -> World -> World) -> PlacementSpot -> Placement
|
||||
lightSensor = damageSensor senseLasering
|
||||
lightSensor = damageSensor Lasering
|
||||
|
||||
senseLasering :: DamageType -> Either Int Int
|
||||
senseLasering Lasering {_dmAmount = x} = Left x
|
||||
senseLasering _ = Right 0
|
||||
|
||||
sensorUpdate :: (DamageType -> Either Int Int) -> Machine -> World -> World
|
||||
sensorUpdate :: DamageType -> Machine -> World -> World
|
||||
sensorUpdate damF mc w = w & machines . ix mcid %~ upmc
|
||||
& lightSources . ix lsid %~ upls
|
||||
where
|
||||
upmc = ( mcSensor %~ \x' -> min 1000 (max 0 (x' - 5 + newSense)) )
|
||||
upmc = ( mcSensorAmount %~ \x' -> min 1000 (max 0 (x' - 5 + newSense)) )
|
||||
. ( mcHP -~ sum dam )
|
||||
. (mcDamage .~ [])
|
||||
x = _mcSensor mc
|
||||
x = _mcSensorAmount mc
|
||||
mcid = _mcID mc
|
||||
lsid = head (_mcLSs mc)
|
||||
(senseData,dam) = partitionEithers $ map damF $ _mcDamage mc
|
||||
(senseData,dam) = partitionEithers $ map (damageUsing damF) $ _mcDamage mc
|
||||
newSense = sum senseData
|
||||
ni = fromIntegral x / 1000
|
||||
upls = lsParam . lsCol .~ V3 ni ni ni
|
||||
|
||||
damageUsing :: DamageType -> Damage -> Either Int Int
|
||||
damageUsing dt dm
|
||||
| _dmType dm == dt = Left $ _dmAmount dm
|
||||
| otherwise = Right 0
|
||||
|
||||
sensorSPic :: Float -> Machine -> SPic
|
||||
sensorSPic wdth _ = ( colorSH yellow $ upperPrismPoly 25 (square wdth)
|
||||
, mempty )
|
||||
|
||||
@@ -82,7 +82,7 @@ updateTurret rotSpeed mc w
|
||||
& creatures . ix cid . crPos .~ mcpos
|
||||
& creatures . ix cid . crDir .~ mcdir
|
||||
dodamage = machines . ix mcid %~
|
||||
( (mcDamage .~ [Electrical (min 2500 $ max 0 (elecDam - 10)) 0 0 0])
|
||||
( (mcDamage .~ [Damage Electrical (min 2500 $ max 0 (elecDam - 10)) 0 0 0 NoDamageEffect])
|
||||
. (mcHP -~ dam)
|
||||
)
|
||||
elecDamBranch
|
||||
|
||||
Reference in New Issue
Block a user