Cleanup
This commit is contained in:
+90
-78
@@ -1,30 +1,31 @@
|
||||
module Dodge.Machine.Update where
|
||||
import Dodge.Data
|
||||
import Dodge.Machine.Destroy
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Base.You
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Wall.Delete
|
||||
import Dodge.WorldEvent.Explosion
|
||||
import Dodge.FloorItem
|
||||
import Dodge.Item.Weapon.BatteryGuns
|
||||
import Dodge.Default
|
||||
import Dodge.Movement.Turn
|
||||
import Geometry
|
||||
import LensHelp
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
import Data.List (partition)
|
||||
import Data.Maybe
|
||||
import Dodge.Base.Collide
|
||||
import Dodge.Base.You
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
import Dodge.FloorItem
|
||||
import Dodge.Item.Weapon.BatteryGuns
|
||||
import Dodge.Machine.Destroy
|
||||
import Dodge.Movement.Turn
|
||||
import Dodge.SoundLogic
|
||||
import Dodge.Wall.Delete
|
||||
import Dodge.WorldEvent.Explosion
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import LensHelp
|
||||
|
||||
updateMachine :: Machine -> World -> World
|
||||
updateMachine mc
|
||||
| _mcHP mc < 1 = destroyMachine mc
|
||||
| otherwise = mcApplyDamage (_mcDamage mc) mc
|
||||
. mcPlaySound mc
|
||||
. mcSensorTriggerUpdate mc
|
||||
. mcTurretUpdate mc
|
||||
. mcSensorUpdate mc
|
||||
| otherwise =
|
||||
mcApplyDamage (_mcDamage mc) mc
|
||||
. mcPlaySound mc
|
||||
. mcSensorTriggerUpdate mc
|
||||
. mcTurretUpdate mc
|
||||
. mcSensorUpdate mc
|
||||
|
||||
mcTurretUpdate :: Machine -> World -> World
|
||||
mcTurretUpdate mc = case _mcType mc of
|
||||
@@ -33,50 +34,57 @@ mcTurretUpdate mc = case _mcType mc of
|
||||
|
||||
-- this needs a major cleanup
|
||||
updateTurret :: Float -> Machine -> World -> World
|
||||
updateTurret rotSpeed mc w
|
||||
| _mcHP mc < 1 = w & cWorld . machines %~ IM.delete mcid
|
||||
& deleteWallIDs (_mcWallIDs mc)
|
||||
& makeExplosionAt mcpos
|
||||
& copyItemToFloor mcpos lasGun
|
||||
& deleteHomonculus
|
||||
| otherwise = w
|
||||
& initHomonculus
|
||||
& dodamage
|
||||
& maybeFire
|
||||
& elecDamBranch
|
||||
updateTurret rotSpeed mc w
|
||||
| _mcHP mc < 1 =
|
||||
w & cWorld . machines %~ IM.delete mcid
|
||||
& deleteWallIDs (_mcWallIDs mc)
|
||||
& makeExplosionAt mcpos
|
||||
& copyItemToFloor mcpos lasGun
|
||||
& deleteHomonculus
|
||||
| otherwise =
|
||||
w
|
||||
& initHomonculus
|
||||
& dodamage
|
||||
& maybeFire
|
||||
& 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
|
||||
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 . useAim . aimHandlePos -~ 10
|
||||
& itConsumption . 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])
|
||||
. (mcHP -~ dam)
|
||||
)
|
||||
thecreature =
|
||||
defaultCreature
|
||||
& crID .~ cid
|
||||
& crInv . at 0
|
||||
?~ ( _tuWeapon (_mcType mc) & itUse . useAim . 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])
|
||||
. (mcHP -~ dam)
|
||||
)
|
||||
elecDamBranch
|
||||
| elecDam < 10 = updateFiringStatus . doTurn
|
||||
| otherwise = id
|
||||
maybeFire
|
||||
| _tuFireTime (_mcType mc) > 0
|
||||
= fromMaybe id $ do
|
||||
| _tuFireTime (_mcType mc) > 0 =
|
||||
fromMaybe id $ do
|
||||
cid <- _tuMCrID (_mcType mc)
|
||||
return $ cWorld . creatures . ix cid . crActionPlan . apImpulse .~ [UseItem]
|
||||
| otherwise = id
|
||||
@@ -88,13 +96,13 @@ updateTurret rotSpeed mc w
|
||||
(elecDams, dams) = partition isElectrical $ _mcDamage mc
|
||||
dam = sum $ map _dmAmount dams
|
||||
elecDam = sum $ map _dmAmount elecDams
|
||||
doTurn
|
||||
doTurn
|
||||
| seesYou = cWorld . machines . ix mcid . mcDir %~ turnTo rotSpeed mcpos ypos
|
||||
| otherwise = id
|
||||
closeFireAngle = seesYou -- && angleVV (ypos -.- mcpos) (unitVectorAtAngle mcdir) < 1
|
||||
updateFiringStatus
|
||||
updateFiringStatus
|
||||
| closeFireAngle = cWorld . machines . ix mcid . mcType . tuFireTime .~ 20
|
||||
| otherwise = cWorld . machines . ix mcid . mcType . tuFireTime %~ (max 0 . subtract 1)
|
||||
| otherwise = cWorld . machines . ix mcid . mcType . tuFireTime %~ (max 0 . subtract 1)
|
||||
|
||||
mcSensorTriggerUpdate :: Machine -> World -> World
|
||||
mcSensorTriggerUpdate mc = fromMaybe id $ do
|
||||
@@ -107,59 +115,64 @@ mcTriggerVal mc = case mc ^. mcSensor of
|
||||
NoSensor -> Nothing
|
||||
s@ProximitySensor{} -> s ^? sensToggle
|
||||
s@DamageSensor{} -> Just $ _sensAmount s > 900
|
||||
|
||||
|
||||
mcPlaySound :: Machine -> World -> World
|
||||
mcPlaySound mc w = case _mcCloseSound mc of
|
||||
Just sid | d < 100
|
||||
-> soundContinueVol (1-0.01*d) (MachineSound mid) (_mcPos mc) sid (Just 2) w
|
||||
_ -> w
|
||||
Just sid
|
||||
| d < 100 ->
|
||||
soundContinueVol (1 -0.01 * d) (MachineSound mid) (_mcPos mc) sid (Just 2) w
|
||||
_ -> w
|
||||
where
|
||||
d = max 0 (dist (_crPos $ you w) (_mcPos mc) - 100)
|
||||
mid = _mcID mc
|
||||
|
||||
mcApplyDamage :: [Damage] -> Machine -> World -> World
|
||||
mcApplyDamage ds mc = case _mcSensor mc of
|
||||
NoSensor -> cWorld . machines . ix (_mcID mc) %~
|
||||
( (mcDamage .~ []) . (mcHP -~ sum (map _dmAmount ds)) )
|
||||
NoSensor ->
|
||||
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
|
||||
s@DamageSensor{} -> senseDamage (_sensType s) mc w
|
||||
ProximitySensor{} -> mcProximitySensorUpdate mc w
|
||||
|
||||
mcProximitySensorUpdate :: Machine -> World -> World
|
||||
mcProximitySensorUpdate mc w = case
|
||||
( _proxStatus sens
|
||||
, _sensToggle sens
|
||||
, mcProxTest mc w
|
||||
, dist (_crPos ycr) (_mcPos mc) < _proxDist sens) of
|
||||
(_,True,_,_) -> w
|
||||
(_,False,True,True) -> w
|
||||
mcProximitySensorUpdate mc w = case ( _proxStatus sens
|
||||
, _sensToggle sens
|
||||
, mcProxTest mc w
|
||||
, dist (_crPos ycr) (_mcPos mc) < _proxDist sens
|
||||
) of
|
||||
(_, True, _, _) -> w
|
||||
(_, False, True, True) ->
|
||||
w
|
||||
& cWorld . machines . ix (_mcID mc) . mcSensor . sensToggle .~ True
|
||||
& playsound dedaS
|
||||
& cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ IsClose
|
||||
(NotClose,_,False,True) -> w & playsound dedumS
|
||||
(NotClose, _, False, True) ->
|
||||
w & playsound dedumS
|
||||
& cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ IsClose
|
||||
(_,_,_,False) -> w & cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ NotClose
|
||||
(_, _, _, False) -> w & cWorld . machines . ix (_mcID mc) . mcSensor . proxStatus .~ NotClose
|
||||
_ -> w
|
||||
where
|
||||
where
|
||||
playsound sid = soundContinue (MachineAltSound (_mcID mc)) (_mcPos mc) sid Nothing
|
||||
ycr = you w
|
||||
sens = _mcSensor mc
|
||||
|
||||
mcProxTest :: Machine -> World -> Bool
|
||||
mcProxTest mc w = case mc ^? mcSensor . proxRequirement of
|
||||
Just (RequireHealth x) -> _crHP cr >= x
|
||||
Just (RequireEquipment ct) -> any (\itm -> _iyBase (_itType itm) == ct) (_crInv cr)
|
||||
Just (RequireHealth x) -> _crHP cr >= x
|
||||
Just (RequireEquipment ct) -> any (\itm -> _iyBase (_itType itm) == ct) (_crInv cr)
|
||||
_ -> False
|
||||
where
|
||||
cr = you w
|
||||
|
||||
|
||||
senseDamage :: DamageType -> Machine -> World -> World
|
||||
senseDamage dt mc = (cWorld . machines . ix mcid %~ upmc)
|
||||
. updatels
|
||||
senseDamage dt mc =
|
||||
(cWorld . machines . ix mcid %~ upmc)
|
||||
. updatels
|
||||
where
|
||||
upmc = mcSensor . sensAmount %~ min 1000 . max 0 . (+ (newsense - 5))
|
||||
mcid = _mcID mc
|
||||
@@ -173,4 +186,3 @@ damageUsing :: DamageType -> Damage -> Either Int Int
|
||||
damageUsing dt dm
|
||||
| _dmType dm == dt = Left $ _dmAmount dm
|
||||
| otherwise = Right 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user