Entity.icl 1.71 KB
Newer Older
1 2 3 4 5 6
implementation module C2.Framework.Entity

import iTasks
import StdReal, StdOverloaded
import C2.Framework.GeoRoutines
import qualified Data.Map as DM
7
import Data.Map.GenJSON
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

derive class iTask Entity, Position, RelPos, MovingPos, Structure, RectStruct, Behaviour, Angle

moveEntity :: !Entity -> Entity
moveEntity e = {e & e_position = mv e.e_position}
  where
  mv :: !Position -> Position
  mv (MovingPos mp) = MovingPos (moveEntityPos mp mp.mp_timelate)
  mv x              = x

moveEntityPos :: !MovingPos !Real -> MovingPos
moveEntityPos mp time
  # deltaTime = time - mp.mp_timelate
  # deltaDist = mp.mp_speed * deltaTime
  # newpos    = translate mp.mp_position mp.mp_direction deltaDist
  # newalt    = mp.mp_altitude + mp.mp_vertical_speed * deltaTime
  = {mp & mp_timelate = time, mp_position = newpos, mp_altitude = newalt}

newMovingEntity :: !Int !LatLng -> Entity
newMovingEntity id position = newMovingEntityWithSpeedAndDirection id position 0.0 (rad 0.0)

newMovingEntityWithSpeedAndDirection :: !Int !LatLng !Real !Angle -> Entity
newMovingEntityWithSpeedAndDirection id position speed direction
  = { e_id           = id
    , e_attributes   = 'DM'.newMap
    , e_position     = MovingPos { mp_position         = position
                                 , mp_altitude         = 0.0
                                 , mp_direction        = direction
                                 , mp_speed            = speed
                                 , mp_vertical_speed   = 0.0
                                 , mp_angular_velocity = 0.0
                                 , mp_timelate         = 0.0
                                 }
    , e_subentities  = []
    , e_behaviour    = NoBehaviour
    , e_structure    = NoStructure
    }