LambdaHack-0.8.3.0: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe HaskellNone
LanguageHaskell2010

Game.LambdaHack.Common.Time

Contents

Description

Game time and speed.

Synopsis

Documentation

data Time #

Game time in ticks. The time dimension. One tick is 1 microsecond (one millionth of a second), one turn is 0.5 s.

Instances
Bounded Time # 
Instance details

Defined in Game.LambdaHack.Common.Time

Enum Time # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

succ :: Time -> Time #

pred :: Time -> Time #

toEnum :: Int -> Time #

fromEnum :: Time -> Int #

enumFrom :: Time -> [Time] #

enumFromThen :: Time -> Time -> [Time] #

enumFromTo :: Time -> Time -> [Time] #

enumFromThenTo :: Time -> Time -> Time -> [Time] #

Eq Time # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

(==) :: Time -> Time -> Bool #

(/=) :: Time -> Time -> Bool #

Ord Time # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

compare :: Time -> Time -> Ordering #

(<) :: Time -> Time -> Bool #

(<=) :: Time -> Time -> Bool #

(>) :: Time -> Time -> Bool #

(>=) :: Time -> Time -> Bool #

max :: Time -> Time -> Time #

min :: Time -> Time -> Time #

Show Time # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

showsPrec :: Int -> Time -> ShowS #

show :: Time -> String #

showList :: [Time] -> ShowS #

Binary Time # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

put :: Time -> Put #

get :: Get Time #

putList :: [Time] -> Put #

timeZero :: Time #

Start of the game time, or zero lenght time interval.

timeEpsilon :: Time #

An infinitesimal time period.

timeClip :: Time #

At least once per clip all moves are resolved and a frame or a frame delay is generated. Currently one clip is 0.05 s, but it may change, and the code should not depend on this fixed value.

timeTurn :: Time #

One turn is 0.5 s. The code may depend on that. Actors at normal speed (2 m/s) take one turn to move one tile (1 m by 1 m).

timeSecond :: Time #

This many ticks fits in a single second. Do not export,

absoluteTimeAdd :: Time -> Time -> Time #

Absolute time addition, e.g., for summing the total game session time from the times of individual games.

absoluteTimeNegate :: Time -> Time #

Absolute time negation. To be used for reversing time flow, e.g., for comparing absolute times in the reverse order.

timeFit :: Time -> Time -> Int #

How many time intervals of the latter kind fits in an interval of the former kind.

timeFitUp :: Time -> Time -> Int #

How many time intervals of the latter kind cover an interval of the former kind (rounded up).

newtype Delta a #

One-dimentional vectors. Introduced to tell apart the 2 uses of Time: as an absolute game time and as an increment.

Constructors

Delta a 
Instances
Functor Delta # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

fmap :: (a -> b) -> Delta a -> Delta b #

(<$) :: a -> Delta b -> Delta a #

Bounded a => Bounded (Delta a) # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

minBound :: Delta a #

maxBound :: Delta a #

Enum a => Enum (Delta a) # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

succ :: Delta a -> Delta a #

pred :: Delta a -> Delta a #

toEnum :: Int -> Delta a #

fromEnum :: Delta a -> Int #

enumFrom :: Delta a -> [Delta a] #

enumFromThen :: Delta a -> Delta a -> [Delta a] #

enumFromTo :: Delta a -> Delta a -> [Delta a] #

enumFromThenTo :: Delta a -> Delta a -> Delta a -> [Delta a] #

Eq a => Eq (Delta a) # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

(==) :: Delta a -> Delta a -> Bool #

(/=) :: Delta a -> Delta a -> Bool #

Ord a => Ord (Delta a) # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

compare :: Delta a -> Delta a -> Ordering #

(<) :: Delta a -> Delta a -> Bool #

(<=) :: Delta a -> Delta a -> Bool #

(>) :: Delta a -> Delta a -> Bool #

(>=) :: Delta a -> Delta a -> Bool #

max :: Delta a -> Delta a -> Delta a #

min :: Delta a -> Delta a -> Delta a #

Show a => Show (Delta a) # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

showsPrec :: Int -> Delta a -> ShowS #

show :: Delta a -> String #

showList :: [Delta a] -> ShowS #

Binary a => Binary (Delta a) # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

put :: Delta a -> Put #

get :: Get (Delta a) #

putList :: [Delta a] -> Put #

timeShift :: Time -> Delta Time -> Time #

Shifting an absolute time by a time vector.

timeDeltaToFrom :: Time -> Time -> Delta Time #

Time time vector between the second and the first absolute times. The arguments are in the same order as in the underlying scalar subtraction.

timeDeltaAdd :: Delta Time -> Delta Time -> Delta Time #

Addition of time deltas.

timeDeltaSubtract :: Delta Time -> Delta Time -> Delta Time #

Subtraction of time deltas. The arguments are in the same order as in the underlying scalar subtraction.

timeDeltaReverse :: Delta Time -> Delta Time #

Reverse a time vector.

timeDeltaScale :: Delta Time -> Int -> Delta Time #

Scale the time vector by an Int scalar value.

timeDeltaPercent :: Delta Time -> Int -> Delta Time #

Take the given percent of the time vector.

timeDeltaDiv :: Delta Time -> Int -> Delta Time #

Divide a time vector.

timeDeltaToDigit :: Delta Time -> Delta Time -> Char #

Represent the main 10 thresholds of a time range by digits, given the total length of the time range.

data Speed #

Speed in meters per 1 million seconds (m/Ms). Actors at normal speed (2 m/s) take one time turn (0.5 s) to make one step (move one tile, which is 1 m by 1 m).

Instances
Eq Speed # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

(==) :: Speed -> Speed -> Bool #

(/=) :: Speed -> Speed -> Bool #

Ord Speed # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

compare :: Speed -> Speed -> Ordering #

(<) :: Speed -> Speed -> Bool #

(<=) :: Speed -> Speed -> Bool #

(>) :: Speed -> Speed -> Bool #

(>=) :: Speed -> Speed -> Bool #

max :: Speed -> Speed -> Speed #

min :: Speed -> Speed -> Speed #

Show Speed # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

showsPrec :: Int -> Speed -> ShowS #

show :: Speed -> String #

showList :: [Speed] -> ShowS #

Binary Speed # 
Instance details

Defined in Game.LambdaHack.Common.Time

Methods

put :: Speed -> Put #

get :: Get Speed #

putList :: [Speed] -> Put #

toSpeed :: Int -> Speed #

Constructor for content definitions.

fromSpeed :: Speed -> Int #

Pretty-printing of speed in the format used in content definitions.

speedZero :: Speed #

No movement possible at that speed.

speedWalk :: Speed #

Fast walk speed (2 m/s) that suffices to move one tile in one turn.

speedLimp :: Speed #

Limp speed (1 m/s) that suffices to move one tile in two turns. This is the minimal speed for projectiles to fly just one space and drop.

speedThrust :: Speed #

Sword thrust speed (10 m/s). Base weapon damages, both melee and ranged, are given assuming this speed and ranged damage is modified accordingly when projectile speeds differ. Differences in melee weapon swing speeds are captured in damage bonuses instead, since many other factors influence total damage.

Billiard ball is 25 ms, sword swing at the tip is 35 ms, medieval bow is 70 ms, AK47 is 700 ms.

modifyDamageBySpeed :: Int64 -> Speed -> Int64 #

Modify damage when projectiles is at a non-standard speed. Energy and so damage is proportional to the square of speed, hence the formula.

speedScale :: Rational -> Speed -> Speed #

Scale speed by an Int scalar value.

speedAdd :: Speed -> Speed -> Speed #

Speed addition.

speedNegate :: Speed -> Speed #

Speed negation.

ticksPerMeter :: Speed -> Delta Time #

The number of time ticks it takes to walk 1 meter at the given speed.

speedFromWeight :: Int -> Int -> Speed #

Calculate projectile speed from item weight in grams and velocity percent modifier. See https://github.com/LambdaHack/LambdaHack/wiki/Item-statistics.

rangeFromSpeedAndLinger :: Speed -> Int -> Int #

Calculate maximum range taking into account the linger percentage.

Internal operations

_timeTick :: Time #

The smallest unit of time. Should not be exported and used elsewhere, because the proportion of turn to tick is an implementation detail. The significance of this detail is only that it determines resolution of the time dimension.

turnsInSecond :: Int64 #

This many turns fit in a single second.

sInMs :: Int64 #

Number of seconds in a mega-second.

minimalSpeed :: Int64 #

The minimal speed is half a meter (half a step across a tile) per second (two standard turns, which the time span during which projectile moves, unless it has modified linger value). This is four times slower than standard human movement speed.

It needen't be lower, because rangeFromSpeed gives 0 steps with such speed, so the actor's trajectory is empty, so it drops down at once. Twice that speed already moves a normal projectile one step before it stops. It shouldn't be lower or a slow actor would incur such a time debt for performing a single action that he'd be paralyzed for many turns, e.g., leaving his dead body on the screen for very long.

rangeFromSpeed :: Speed -> Int #

Calculate maximum range in meters of a projectile from its speed. See https://github.com/LambdaHack/LambdaHack/wiki/Item-statistics. With this formula, each projectile flies for at most 1 second, that is 2 standard turns, and then drops to the ground.