2018-07-22 20:30:17 +00:00
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
2018-08-10 06:58:26 +00:00
|
|
|
{-# LANGUAGE TypeSynonymInstances #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
2018-07-22 20:30:17 +00:00
|
|
|
module Object where
|
|
|
|
|
2018-08-10 20:45:32 +00:00
|
|
|
import Affection as A
|
2018-07-22 20:30:17 +00:00
|
|
|
|
2018-08-10 06:58:26 +00:00
|
|
|
import Control.Monad (when)
|
|
|
|
|
2018-07-22 20:30:17 +00:00
|
|
|
import Data.Ecstasy
|
2018-08-11 09:51:20 +00:00
|
|
|
import Data.Maybe
|
|
|
|
|
|
|
|
import Linear
|
2018-07-22 20:30:17 +00:00
|
|
|
|
|
|
|
import Types
|
|
|
|
|
2018-08-10 06:58:26 +00:00
|
|
|
instance ObjectAction ObjType ObjState where
|
|
|
|
objectAction dt t@ObjCopier s@"copying" ent = do
|
|
|
|
emap (anEnt ent) $ do
|
|
|
|
mtime <- queryMaybe objStateTime
|
|
|
|
case mtime of
|
|
|
|
Nothing -> do
|
2018-09-01 16:26:55 +00:00
|
|
|
liftIO $ logIO Verbose ("Copier " ++ show ent ++ ": copying!")
|
2018-08-10 06:58:26 +00:00
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (actionTime t s)
|
|
|
|
, objState = Set "copying"
|
|
|
|
}
|
2018-09-02 08:44:33 +00:00
|
|
|
Just ttl ->
|
2018-08-10 06:58:26 +00:00
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (ttl - dt)
|
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
trans <- efor (anEnt ent) $ do
|
2018-08-10 06:58:26 +00:00
|
|
|
mttl <- queryMaybe objStateTime
|
|
|
|
case mttl of
|
|
|
|
Nothing -> return False
|
|
|
|
Just ttl -> return (ttl < 0)
|
2019-01-06 02:52:43 +00:00
|
|
|
when (head trans) (setEntity ent =<< objectTransition t s False ent Nothing)
|
2018-08-10 06:58:26 +00:00
|
|
|
|
2018-08-12 04:28:31 +00:00
|
|
|
objectAction dt t@ObjComputer s@"on" ent = do
|
2019-01-06 02:52:43 +00:00
|
|
|
pent <- efor (anEnt ent) $ do
|
2018-09-12 22:51:22 +00:00
|
|
|
with objUsedBy
|
|
|
|
query objUsedBy
|
2019-01-06 02:52:43 +00:00
|
|
|
vls <- efor (anEnt $ head pent) $ do
|
2018-08-12 04:28:31 +00:00
|
|
|
with player
|
|
|
|
with vel
|
|
|
|
query vel
|
|
|
|
emap (anEnt ent) $ do
|
|
|
|
mtime <- queryMaybe objStateTime
|
|
|
|
case mtime of
|
|
|
|
Nothing -> do
|
2018-09-01 16:26:55 +00:00
|
|
|
liftIO $ logIO Verbose ("Computer " ++ show ent ++ ": on!")
|
2018-08-12 04:28:31 +00:00
|
|
|
let dur = actionTime t s
|
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set dur
|
|
|
|
}
|
2018-09-02 08:44:33 +00:00
|
|
|
Just ttl ->
|
2018-08-12 04:28:31 +00:00
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (ttl - dt)
|
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
trans <- efor (anEnt ent) $ do
|
2018-08-12 04:28:31 +00:00
|
|
|
mttl <- queryMaybe objStateTime
|
|
|
|
case mttl of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just ttl -> do
|
|
|
|
pa <- query objPlayerActivated
|
2018-09-02 08:44:33 +00:00
|
|
|
if ttl < 0
|
|
|
|
then
|
2018-08-12 04:28:31 +00:00
|
|
|
return (Just pa)
|
2018-09-12 22:51:22 +00:00
|
|
|
else if not (null vls) && head vls `dot` head vls > 0
|
2018-08-12 04:28:31 +00:00
|
|
|
then return (Just pa)
|
|
|
|
else return Nothing
|
|
|
|
maybe
|
|
|
|
(return ())
|
2018-09-12 22:51:22 +00:00
|
|
|
(\tpa -> setEntity ent =<< objectTransition t s tpa ent Nothing)
|
2019-01-06 02:52:43 +00:00
|
|
|
(head trans)
|
2018-08-12 04:28:31 +00:00
|
|
|
|
2018-08-11 09:51:20 +00:00
|
|
|
objectAction dt t@ObjComputer s@"hack" ent = do
|
2019-01-06 02:52:43 +00:00
|
|
|
aent <- efor (anEnt ent) $ do
|
2018-09-12 22:51:22 +00:00
|
|
|
with objUsedBy
|
|
|
|
query objUsedBy
|
2019-01-06 02:52:43 +00:00
|
|
|
vls <- efor (anEnt $ head aent) $ do
|
2018-08-11 09:51:20 +00:00
|
|
|
with player
|
|
|
|
with vel
|
|
|
|
query vel
|
|
|
|
emap (anEnt ent) $ do
|
|
|
|
mtime <- queryMaybe objStateTime
|
|
|
|
case mtime of
|
|
|
|
Nothing -> do
|
2018-09-01 16:26:55 +00:00
|
|
|
liftIO $ logIO Verbose ("Computer " ++ show ent ++ ": hacking!")
|
2018-08-11 09:51:20 +00:00
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (actionTime t s)
|
|
|
|
}
|
2018-09-02 08:44:33 +00:00
|
|
|
Just ttl ->
|
2018-08-11 09:51:20 +00:00
|
|
|
return unchanged
|
|
|
|
{ objStateTime = Set (ttl - dt)
|
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
trans <- efor (anEnt ent) $ do
|
2018-08-11 09:51:20 +00:00
|
|
|
mttl <- queryMaybe objStateTime
|
|
|
|
case mttl of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just ttl -> do
|
2018-09-12 22:51:22 +00:00
|
|
|
if (ttl < 0) || (not (null vls) && head vls `dot` head vls > 0)
|
2018-08-11 09:51:20 +00:00
|
|
|
then do
|
|
|
|
tpa <- query objPlayerActivated
|
|
|
|
return (Just tpa)
|
|
|
|
else return Nothing
|
|
|
|
maybe
|
|
|
|
(return ())
|
2018-09-12 22:51:22 +00:00
|
|
|
(\tpa -> setEntity ent =<< objectTransition t s tpa ent Nothing)
|
2019-01-06 02:52:43 +00:00
|
|
|
(head trans)
|
2018-08-11 09:51:20 +00:00
|
|
|
|
2018-08-10 06:58:26 +00:00
|
|
|
objectAction _ _ _ _ = return ()
|
|
|
|
|
2018-09-12 22:51:22 +00:00
|
|
|
objectTransition ObjCopier "idle" playerActivated ent (Just aent) = do
|
2019-01-06 02:52:43 +00:00
|
|
|
e <- efor (anEnt ent) $ do
|
2018-07-22 20:30:17 +00:00
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimCopier "copy" N)
|
2018-07-22 20:30:17 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
2018-08-10 09:35:08 +00:00
|
|
|
{ objState = Set "copying"
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Set aent
|
2018-08-10 09:35:08 +00:00
|
|
|
, objPlayerActivated = Set playerActivated
|
|
|
|
, anim = Set nstat
|
2018-08-10 06:58:26 +00:00
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
return (head e)
|
2018-08-10 06:58:26 +00:00
|
|
|
|
2018-09-12 22:51:22 +00:00
|
|
|
objectTransition ObjCopier "copying" _ ent _ = do
|
2019-01-06 02:52:43 +00:00
|
|
|
e <- efor (anEnt ent) $ do
|
2018-08-11 09:51:20 +00:00
|
|
|
ttl <- query objStateTime
|
|
|
|
if ttl < 0
|
|
|
|
then do
|
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimCopier "open" N)
|
2018-08-11 09:51:20 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "idle"
|
|
|
|
, objStateTime = Unset
|
|
|
|
, objPlayerActivated = Unset
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Unset
|
2018-08-11 09:51:20 +00:00
|
|
|
}
|
|
|
|
else return unchanged
|
2019-01-06 02:52:43 +00:00
|
|
|
return (head e)
|
2018-08-11 09:51:20 +00:00
|
|
|
|
2018-09-12 22:51:22 +00:00
|
|
|
objectTransition ObjComputer "off" pa ent (Just aent) = do
|
2019-01-06 02:52:43 +00:00
|
|
|
e <- efor (anEnt ent) $ do
|
2018-08-11 09:51:20 +00:00
|
|
|
solved <- queryMaybe objSolved
|
2019-02-09 14:19:16 +00:00
|
|
|
(_, dir) <- query objAccess
|
2018-08-12 04:28:31 +00:00
|
|
|
if pa
|
|
|
|
then if not (fromMaybe False solved)
|
|
|
|
then do
|
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimComputer "hack" dir)
|
2018-08-12 04:28:31 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "hack"
|
|
|
|
, objPlayerActivated = Set True
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Set aent
|
2018-08-12 04:28:31 +00:00
|
|
|
}
|
|
|
|
else do
|
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimComputer "on" dir)
|
2018-08-12 04:28:31 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "on"
|
|
|
|
, objPlayerActivated = Set True
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Set aent
|
2018-08-12 04:28:31 +00:00
|
|
|
}
|
|
|
|
else do
|
2018-08-11 09:51:20 +00:00
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimComputer "on" dir)
|
2018-08-11 09:51:20 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
2018-08-12 04:28:31 +00:00
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "on"
|
|
|
|
, objPlayerActivated = Set False
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Set aent
|
2018-08-12 04:28:31 +00:00
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
return (head e)
|
2018-08-12 04:28:31 +00:00
|
|
|
|
2018-09-12 22:51:22 +00:00
|
|
|
objectTransition ObjComputer "on" _ ent _ = do
|
2019-01-06 02:52:43 +00:00
|
|
|
e <- efor (anEnt ent) $ do
|
2019-02-09 14:19:16 +00:00
|
|
|
(_, dir) <- query objAccess
|
2018-08-12 04:28:31 +00:00
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimComputer "off" dir)
|
2018-08-12 04:28:31 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
return unchanged
|
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "off"
|
|
|
|
, objPlayerActivated = Unset
|
|
|
|
, objStateTime = Unset
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Unset
|
2018-08-12 04:28:31 +00:00
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
return (head e)
|
2018-08-11 09:51:20 +00:00
|
|
|
|
2018-09-12 22:51:22 +00:00
|
|
|
objectTransition ObjComputer "hack" pa ent _ =
|
2018-09-01 16:27:18 +00:00
|
|
|
if pa
|
|
|
|
then do
|
2019-01-06 02:52:43 +00:00
|
|
|
e <- efor (anEnt ent) $ do
|
2019-02-09 14:19:16 +00:00
|
|
|
(_, dir) <- query objAccess
|
2018-09-01 16:27:18 +00:00
|
|
|
let nstat = AnimState
|
2019-02-14 21:31:00 +00:00
|
|
|
(AnimId AnimComputer "off" dir)
|
2018-09-01 16:27:18 +00:00
|
|
|
0
|
|
|
|
0
|
|
|
|
ost <- query objStateTime
|
|
|
|
return unchanged
|
|
|
|
{ anim = Set nstat
|
|
|
|
, objState = Set "off"
|
|
|
|
, objPlayerActivated = Unset
|
|
|
|
, objStateTime = Unset
|
2018-09-12 22:51:22 +00:00
|
|
|
, objUsedBy = Unset
|
2018-09-01 16:27:18 +00:00
|
|
|
, objSolved = if pa then Set (ost < 0) else Keep
|
|
|
|
}
|
2019-01-06 02:52:43 +00:00
|
|
|
return (head e)
|
2018-09-01 16:27:18 +00:00
|
|
|
else return unchanged
|
2018-08-10 06:58:26 +00:00
|
|
|
|
2018-09-12 22:51:22 +00:00
|
|
|
objectTransition _ _ _ _ _ = return unchanged
|
2018-08-10 06:58:26 +00:00
|
|
|
|
|
|
|
instance ActionTime ObjType ObjState where
|
|
|
|
actionTime ObjCopier "copying" = 5
|
2018-08-11 09:51:20 +00:00
|
|
|
actionTime ObjComputer "off" = 0
|
2018-08-12 04:28:31 +00:00
|
|
|
actionTime ObjComputer "on" = 20
|
2018-08-11 09:51:20 +00:00
|
|
|
actionTime ObjComputer "hack" = 20
|
2018-07-30 13:34:45 +00:00
|
|
|
|
2018-08-12 04:28:31 +00:00
|
|
|
actionTime o s = A.log Error (show o ++ ": " ++ s ++ ": has not a time") 0
|