Cleanup
This commit is contained in:
+39
-60
@@ -1,13 +1,13 @@
|
||||
module Dodge.Machine.Update where
|
||||
|
||||
import Dodge.Item.Held.BatteryGuns
|
||||
import Data.List (partition)
|
||||
import Data.Maybe
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Base.You
|
||||
import Dodge.Data.World
|
||||
import Dodge.Default
|
||||
import Dodge.FloorItem
|
||||
import Dodge.HeldUse
|
||||
import Dodge.Item.Held.BatteryGuns
|
||||
import Dodge.Machine.Destroy
|
||||
import Dodge.Movement.Turn
|
||||
import Dodge.SoundLogic
|
||||
@@ -28,8 +28,8 @@ updateMachine mc
|
||||
. mcSensorUpdate mc
|
||||
|
||||
mcTurretUpdate :: Machine -> World -> World
|
||||
mcTurretUpdate mc = case _mcType mc of
|
||||
mt@Turret{} -> updateTurret (_tuTurnSpeed mt) mc
|
||||
mcTurretUpdate mc = case mc ^? mcType . _McTurret of
|
||||
Just tu -> updateTurret (_tuTurnSpeed tu) mc
|
||||
_ -> id
|
||||
|
||||
-- this needs a major cleanup
|
||||
@@ -40,40 +40,12 @@ updateTurret rotSpeed mc w
|
||||
& deleteWallIDs (_mcWallIDs mc)
|
||||
& makeExplosionAt mcpos
|
||||
& copyItemToFloor mcpos lasGun
|
||||
& deleteHomonculus
|
||||
| otherwise =
|
||||
w
|
||||
& initHomonculus
|
||||
& dodamage
|
||||
& maybeFire
|
||||
& mcUseItem mc
|
||||
& elecDamBranch
|
||||
where
|
||||
deleteHomonculus = case _tuMCrID (_mcType mc) of
|
||||
Nothing -> id
|
||||
Just cid -> cWorld . creatures . at cid .~ Nothing
|
||||
initHomonculus w' = case w' ^? cWorld . machines . ix mcid . mcType . tuMCrID . _Just of
|
||||
Nothing ->
|
||||
w' & cWorld . machines . ix mcid . mcType . tuMCrID ?~ cid
|
||||
& cWorld . creatures . at cid ?~ thecreature
|
||||
where
|
||||
cid = IM.newKey (_creatures (_cWorld w'))
|
||||
thecreature =
|
||||
defaultCreature
|
||||
& crID .~ cid
|
||||
& crInv . at 0
|
||||
?~ ( _tuWeapon (_mcType mc) & itUse . heldAim . aimHandlePos -~ 10
|
||||
& itUse . heldConsumption . laLoaded .~ 1
|
||||
)
|
||||
& crPos .~ mcpos
|
||||
& crOldPos .~ mcpos
|
||||
& crRad .~ 1
|
||||
& crDir .~ mcdir
|
||||
& crStance . posture .~ Aiming
|
||||
& crMaterial .~ Crystal
|
||||
Just cid ->
|
||||
w'
|
||||
& cWorld . creatures . ix cid . crPos .~ mcpos
|
||||
& cWorld . creatures . ix cid . crDir .~ mcdir
|
||||
dodamage =
|
||||
cWorld . machines . ix mcid
|
||||
%~ ( (mcDamage .~ [Damage ELECTRICAL (min 2500 $ max 0 (elecDam - 10)) 0 0 0 NoDamageEffect])
|
||||
@@ -82,16 +54,10 @@ updateTurret rotSpeed mc w
|
||||
elecDamBranch
|
||||
| elecDam < 10 = updateFiringStatus . doTurn
|
||||
| otherwise = id
|
||||
maybeFire
|
||||
| _tuFireTime (_mcType mc) > 0 =
|
||||
fromMaybe id $ do
|
||||
cid <- _tuMCrID (_mcType mc)
|
||||
return $ cWorld . creatures . ix cid . crActionPlan . apImpulse .~ [UseItem]
|
||||
| otherwise = id
|
||||
mcid = _mcID mc
|
||||
ypos = _crPos $ you w
|
||||
mcpos = _mcPos mc
|
||||
mcdir = _mcDir mc
|
||||
--mcdir = _mcDir mc
|
||||
seesYou = hasLOSIndirect mcpos ypos w
|
||||
(elecDams, dams) = partition isElectrical $ _mcDamage mc
|
||||
dam = sum $ map _dmAmount dams
|
||||
@@ -101,8 +67,21 @@ updateTurret rotSpeed mc w
|
||||
| otherwise = id
|
||||
closeFireAngle = seesYou -- && angleVV (ypos -.- mcpos) (unitVectorAtAngle mcdir) < 1
|
||||
updateFiringStatus
|
||||
| closeFireAngle = cWorld . machines . ix mcid . mcType . tuFireTime .~ 20
|
||||
| otherwise = cWorld . machines . ix mcid . mcType . tuFireTime %~ (max 0 . subtract 1)
|
||||
| closeFireAngle = cWorld . machines . ix mcid . mcType . _McTurret . tuFireTime .~ 20
|
||||
| otherwise = cWorld . machines . ix mcid . mcType . _McTurret . tuFireTime %~ (max 0 . subtract 1)
|
||||
|
||||
mcUseItem :: Machine -> World -> World
|
||||
mcUseItem mc = fromMaybe id $ do
|
||||
tu <- mc ^? mcType . _McTurret
|
||||
let it = tu ^. tuWeapon
|
||||
hit <- it ^? itType . iyBase . ibtHeld
|
||||
return $ mcUseHeld hit it mc
|
||||
|
||||
-- maybeFire
|
||||
-- | _tuFireTime (_mcType mc) > 0 =
|
||||
-- fromMaybe id $ do
|
||||
-- return $ tuUseItem
|
||||
-- | otherwise = id
|
||||
|
||||
mcSensorTriggerUpdate :: Machine -> World -> World
|
||||
mcSensorTriggerUpdate mc = fromMaybe id $ do
|
||||
@@ -111,10 +90,10 @@ mcSensorTriggerUpdate mc = fromMaybe id $ do
|
||||
return $ cWorld . triggers . ix trid .~ bval
|
||||
|
||||
mcTriggerVal :: Machine -> Maybe Bool
|
||||
mcTriggerVal mc = case mc ^. mcSensor of
|
||||
NoSensor -> Nothing
|
||||
s@ProximitySensor{} -> s ^? sensToggle
|
||||
s@DamageSensor{} -> Just $ _sensAmount s > 900
|
||||
mcTriggerVal mc = case mc ^? mcType . _McSensor of
|
||||
Nothing -> Nothing
|
||||
Just s@ProximitySensor{} -> s ^? sensToggle
|
||||
Just s@DamageSensor{} -> Just $ _sensAmount s > 900
|
||||
|
||||
mcPlaySound :: Machine -> World -> World
|
||||
mcPlaySound mc w = case _mcCloseSound mc of
|
||||
@@ -127,17 +106,17 @@ mcPlaySound mc w = case _mcCloseSound mc of
|
||||
mid = _mcID mc
|
||||
|
||||
mcApplyDamage :: [Damage] -> Machine -> World -> World
|
||||
mcApplyDamage ds mc = case _mcSensor mc of
|
||||
NoSensor ->
|
||||
mcApplyDamage ds mc = case mc ^? mcType . _McSensor of
|
||||
Nothing ->
|
||||
cWorld . machines . ix (_mcID mc)
|
||||
%~ ((mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)))
|
||||
_ -> id
|
||||
|
||||
mcSensorUpdate :: Machine -> World -> World
|
||||
mcSensorUpdate mc w = case _mcSensor mc of
|
||||
NoSensor -> w
|
||||
s@DamageSensor{} -> senseDamage (_sensType s) mc w
|
||||
ProximitySensor{} -> mcProximitySensorUpdate mc w
|
||||
mcSensorUpdate mc w = case mc ^? mcType . _McSensor of
|
||||
Nothing -> w
|
||||
Just s@DamageSensor{} -> senseDamage (_sensType s) mc w
|
||||
Just ProximitySensor{} -> mcProximitySensorUpdate mc w
|
||||
|
||||
mcProximitySensorUpdate :: Machine -> World -> World
|
||||
mcProximitySensorUpdate mc w = case ( _proxStatus sens
|
||||
@@ -148,21 +127,21 @@ mcProximitySensorUpdate mc w = case ( _proxStatus sens
|
||||
(_, True, _, _) -> w
|
||||
(_, False, True, True) ->
|
||||
w
|
||||
& cWorld . machines . ix (_mcID mc) . mcSensor . sensToggle .~ True
|
||||
& cWorld . machines . ix (_mcID mc) . mcType . _McSensor . sensToggle .~ True
|
||||
& playsound dedaS
|
||||
& cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ IsClose
|
||||
& cWorld . machines . ix (_mcID mc) . mcType . _McSensor . proxStatus .~ IsClose
|
||||
(NotClose, _, False, True) ->
|
||||
w & playsound dedumS
|
||||
& cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ IsClose
|
||||
(_, _, _, False) -> w & cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ NotClose
|
||||
& cWorld . machines . ix (_mcID mc) . mcType . _McSensor . proxStatus .~ IsClose
|
||||
(_, _, _, False) -> w & cWorld . machines . ix (_mcID mc) . mcType . _McSensor . proxStatus .~ NotClose
|
||||
_ -> w
|
||||
where
|
||||
playsound sid = soundContinue (MachineAltSound (_mcID mc)) (_mcPos mc) sid Nothing
|
||||
ycr = you w
|
||||
sens = _mcSensor mc
|
||||
sens = mc ^?! mcType . _McSensor
|
||||
|
||||
mcProxTest :: Machine -> World -> Bool
|
||||
mcProxTest mc w = case mc ^? mcSensor . proxRequirement of
|
||||
mcProxTest mc w = case mc ^? mcType . _McSensor . proxRequirement of
|
||||
Just (RequireHealth x) -> _crHP cr >= x
|
||||
Just (RequireEquipment ct) -> any (\itm -> _iyBase (_itType itm) == ct) (_crInv cr)
|
||||
_ -> False
|
||||
@@ -174,10 +153,10 @@ senseDamage dt mc =
|
||||
(cWorld . machines . ix mcid %~ upmc)
|
||||
. updatels
|
||||
where
|
||||
upmc = mcSensor . sensAmount %~ min 1000 . max 0 . (+ (newsense - 5))
|
||||
upmc = mcType . _McSensor . sensAmount %~ min 1000 . max 0 . (+ (newsense - 5))
|
||||
mcid = _mcID mc
|
||||
newsense = sum . map _dmAmount $ filter ((== dt) . _dmType) (_mcDamage mc)
|
||||
ni = fromIntegral (_sensAmount $ _mcSensor mc) / 1000
|
||||
ni = fromIntegral (mc ^?! mcType . _McSensor . sensAmount) / 1000
|
||||
updatels = fromMaybe id $ do
|
||||
lsid <- mc ^? mcMounts . ix ObLightSource
|
||||
return $ cWorld . lightSources . ix lsid . lsParam . lsCol .~ V3 ni ni ni
|
||||
|
||||
Reference in New Issue
Block a user