1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module SpaceTraders.Model.Ship
( Ship(..)
, isDocked
, isInOrbit
, overNinetyPercentFuel
) where
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
import SpaceTraders.Model.Cargo
import SpaceTraders.Model.Fuel
import SpaceTraders.Model.Nav
data Ship = Ship { cargo :: Cargo
, cooldown :: Cooldown
--, crew :: Crew
--, engine :: Engine
--, frame :: Frame
, fuel :: Fuel
--, modules :: [Module]
--, mounts :: [Mount]
, nav :: Nav
--, reactor :: Reactor
--, registration :: Registration
, symbol :: T.Text
} deriving (FromJSON, Generic, Show, ToJSON)
data Cooldown = Cooldown { shipSymbol :: T.Text
, totalSeconds :: Int
, remainingSeconds :: Int
} deriving (FromJSON, Generic, Show, ToJSON)
isDocked :: Ship -> Bool
isDocked ship = status (nav ship) == "DOCKED"
isInOrbit :: Ship -> Bool
isInOrbit = not . isDocked
overNinetyPercentFuel :: Ship -> Bool
overNinetyPercentFuel ship = curr * 10 > capa * 9
where
curr = current f
capa = SpaceTraders.Model.Fuel.capacity f
f = fuel ship
|