Yogstation 13 - Modules - TypesDefine Details

code/__DEFINES/maths.dm

SIGNGets the sign of x, returns -1 if negative, 0 if 0, 1 if positive
WRAP_UPIncrements a value and wraps it if it exceeds some value. Can be used to circularly iterate through a list through idx = WRAP_UP(idx, length_of_list).
LPFILTERLow-pass filter a value to smooth out high frequent peaks. This can be thought of as a moving average filter as well. delta_time is how many seconds since we last ran this command. RC is the filter constant, high RC means more smoothing See https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter for the maths
TOBITSHIFTGets shift x that would be required the bitflag (1<<x) We need the round because log has floating-point inaccuracy, and if we undershoot at all on list indexing we'll get the wrong index.
DT_PROB_RATEConverts a probability/second chance to probability/delta_time chance For example, if you want an event to happen with a 10% per second chance, but your proc only runs every 5 seconds, do if(prob(100*DT_PROB_RATE(0.1, 5)))
DT_PROBLike DT_PROB_RATE but easier to use, simply put if(DT_PROB(10, 5))
MANHATTAN_DISTANCETaxicab distance--gets you the actual time it takes to get from one turf to another due to how we calculate diagonal movement
LOGISTIC_FUNCTIONA function that exponentially approaches a maximum value of L k is the rate at which is approaches L, x_0 is the point where the function = 0
FORCE_BOOLEANMake sure something is a boolean TRUE/FALSE 1/0 value, since things like bitfield & bitflag doesn't always give 1s and 0s.
TILES_TO_PIXELSGives the number of pixels in an orthogonal line of tiles.
DIAMOND_AREAThe number of cells in a taxicab circle (rasterized diamond) of radius X.

Define Details

DIAMOND_AREA

The number of cells in a taxicab circle (rasterized diamond) of radius X.

DT_PROB

Like DT_PROB_RATE but easier to use, simply put if(DT_PROB(10, 5))

DT_PROB_RATE

Converts a probability/second chance to probability/delta_time chance For example, if you want an event to happen with a 10% per second chance, but your proc only runs every 5 seconds, do if(prob(100*DT_PROB_RATE(0.1, 5)))

FORCE_BOOLEAN

Make sure something is a boolean TRUE/FALSE 1/0 value, since things like bitfield & bitflag doesn't always give 1s and 0s.

LOGISTIC_FUNCTION

A function that exponentially approaches a maximum value of L k is the rate at which is approaches L, x_0 is the point where the function = 0

LPFILTER

Low-pass filter a value to smooth out high frequent peaks. This can be thought of as a moving average filter as well. delta_time is how many seconds since we last ran this command. RC is the filter constant, high RC means more smoothing See https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter for the maths

MANHATTAN_DISTANCE

Taxicab distance--gets you the actual time it takes to get from one turf to another due to how we calculate diagonal movement

SIGN

Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive

TILES_TO_PIXELS

Gives the number of pixels in an orthogonal line of tiles.

TOBITSHIFT

Gets shift x that would be required the bitflag (1<<x) We need the round because log has floating-point inaccuracy, and if we undershoot at all on list indexing we'll get the wrong index.

WRAP_UP

Increments a value and wraps it if it exceeds some value. Can be used to circularly iterate through a list through idx = WRAP_UP(idx, length_of_list).