Damage sense through immediate damage to machines
This commit is contained in:
@@ -35,7 +35,7 @@ damageWall wlid dt w = fromMaybe (mempty,w) $ do
|
||||
return $ case wl ^. wlStructure of
|
||||
MachinePart mcid -> -- (,) mempty
|
||||
-- $ w' & cWorld . lWorld . machines . ix mcid . mcDamage .:~ dt
|
||||
w' & damageMachine dmam mcid
|
||||
w' & damageMachine dt dmam mcid
|
||||
BlockPart blid ->
|
||||
w' & damageBlock (wl ^. wlMaterial) dmam blid
|
||||
DoorPart drid _ ->
|
||||
@@ -43,11 +43,68 @@ damageWall wlid dt w = fromMaybe (mempty,w) $ do
|
||||
& maybeDestroyDoor drid
|
||||
_ -> (mempty, w')
|
||||
|
||||
damageMachine :: Int -> Int -> World -> (S.Set Int2, World)
|
||||
damageMachine x mcid w = case w ^? cWorld . lWorld . machines . ix mcid of
|
||||
damageMachine :: Damage -> Int -> Int -> World -> (S.Set Int2, World)
|
||||
damageMachine dam x mcid w = case w ^? cWorld . lWorld . machines . ix mcid of
|
||||
Just mc | Just se <- mc ^? mcType . _McDamSensor
|
||||
, sensorTypeDamages (se ^. sensType) dam
|
||||
-> (mempty,mcDamSensorUpdate' (_dmAmount dam) se mc w)
|
||||
Just mc | _mcHP mc < x -> destroyMachine' mc w
|
||||
_ -> (mempty, w & cWorld . lWorld . machines . ix mcid . mcHP -~ x)
|
||||
|
||||
mcDamSensorUpdate' :: Int -> DamageSensor -> Machine -> World -> World
|
||||
mcDamSensorUpdate' x se = senseDamage' x (damageTypeThreshold' (se ^. sensType)) (se ^. sensType)
|
||||
|
||||
senseDamage' :: Int -> Int -> SensorType -> Machine -> World -> World
|
||||
senseDamage' x threshold dt mc =
|
||||
(cWorld . lWorld . machines . ix mcid %~ upmc)
|
||||
. updatels
|
||||
where
|
||||
upmc =
|
||||
mcType
|
||||
. _McDamSensor
|
||||
. sensAmount
|
||||
%~ min (100 * threshold)
|
||||
. max 0
|
||||
. (+ newsense)
|
||||
mcid = _mcID mc
|
||||
newsense
|
||||
| x > 0 = x
|
||||
| otherwise = -5
|
||||
-- where
|
||||
-- f = sensorTypeDamages dt
|
||||
-- x = sum . map _dmAmount $ filter f (_mcDamage mc)
|
||||
ni = fromIntegral (mc ^?! mcType . _McDamSensor . sensAmount) / fromIntegral threshold
|
||||
updatels = fromMaybe id $ do
|
||||
lsid <- mc ^? mcMounts . ix OTLightSource
|
||||
return $ cWorld . lWorld . lightSources . ix lsid . lsParam . lsCol .~ V3 ni ni ni
|
||||
|
||||
damageTypeThreshold' :: SensorType -> Int
|
||||
damageTypeThreshold' = \case
|
||||
LaserSensor -> 1000
|
||||
ElectricSensor -> 500
|
||||
ThermalSensor -> 1000
|
||||
PhysicalSensor -> 1000
|
||||
|
||||
sensorTypeDamages :: SensorType -> Damage -> Bool
|
||||
sensorTypeDamages = \case
|
||||
LaserSensor -> \case
|
||||
Lasering{} -> True
|
||||
_ -> False
|
||||
ElectricSensor -> \case
|
||||
Electrical{} -> True
|
||||
_ -> False
|
||||
ThermalSensor -> \case
|
||||
Flaming{} -> True
|
||||
Sparking{} -> True
|
||||
Explosive{} -> True
|
||||
_ -> False
|
||||
PhysicalSensor -> \case
|
||||
Piercing{} -> True
|
||||
Blunt{} -> True
|
||||
Crushing{} -> True
|
||||
Explosive{} -> True
|
||||
_ -> False
|
||||
|
||||
destroyMachine' :: Machine -> World -> (S.Set Int2, World)
|
||||
destroyMachine' mc w = (js, destroyMachine mc w)
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user