Math

This file stores math utility functions that don’t quite fit in Simba or Lape.

var Math

Global math variables meant to aid scripters.

  • maxInt: The maximum integer value.

Example:

for i := 0 to maxInt do
  writeln(i);

gridBox

function gridBox(slot, columns, rows, w, h, diffX, diffY: integer; starTPoint: TPoint): TBox;

Returns a TBox of the slot ‘slot’ in a grid created by the other parameters. Slots start with 0 being the top left of the grid, and counting accross.

  • columns: number of columns in the grid
  • rows: number of rows in the grid
  • w: the width of each box in the grid
  • h: the height of each box in the grid
  • diffX: pixels from center to center (x)
  • diffY: pixels from center to center (y)
  • starTPoint: the center point of the top left box in the grid

Note

  • by Coh3n
  • Last Modified: Jan. 25th, 2012 by Coh3n

Example:

result := gridBox(Slot, 4, 2, 95, 80, 0, 150, point(110, 100));

grid

function grid(columns, rows, w, h, diffX, diffY: integer; starTPoint: TPoint): TBoxArray;

Returns a grid of TBoxes (see gridBox for parameters).

Note

  • by Coh3n
  • Last Modified: Jan. 25th, 2012 by Coh3n

Example:

SMART_DrawBoxes(false, grid(5, 10, 20, 20, 25, 25, point(30, 30)), clYellow);

groupDigits

function groupDigits(n: integer; token: string): string;

Nicely formats the number passed by placing token in between groups of three numbers.

Note

  • by PriSoner and Nava2

Example:

foo := groupDigits(1000, ','); // foo -> '1,000'
bar := groupDigits(1500423, ' '); // bar -> '1 500 423'

groupDigits

function groupDigits(n: extended; token: string): string;

Nicely formats the number passed by placing token in between groups of three numbers. Uses extended format instead of integer

Note

  • by PriSoner, Nava2 and bonsai

Example:

foo := groupDigits(1000, ','); // foo -> '1,000'
bar := groupDigits(1500423, ' '); // bar -> '1 500 423'

TPABetweenPoints

function TPABetweenPoints(P1, P2: TPoint; Interval, Rand: Integer): TPointArray;

Generates a TPA between P1 and P2, Interval between points; Rand randomness on each point. Very useful for generating a random walking path between the player’s position and the ending position.

Note

Author: Nava2 Last Modified: Apr. 4th, 2012 by Coh3n

Example:

newTPA := TPABetweenPoints(PlayerPos, EndPos, 25, 10);

quickTBASort

procedure quickTBASort(var A: TIntegerArray; var B: TBoxArray; iLo, iHi: Integer; SortUp: Boolean);

Sorts a given TBoxArray

Note

Author: Simba source Last Modified: 1st February 2014 by Olly

Example:

quickTBASort(DistArr, BoxArray, 0, l, True);

sortBoxesFromMidPoint

procedure sortBoxesFromMidPoint(var BoxArray: TBoxArray; const From: TPoint);

Sorts a TBoxArray from the TPoint ‘from’ based from the middle of each box.

Note

Author: Simba source Last Modified: 1st February 2014 by Olly

Example:

sortBoxesFromMidPoint(tba, mainScreen.playerPoint);

gauss

function gauss(): Extended;

Calculates a standard normal value (N(0, 1)). By definition, 68.2% of points will lie within +/- 1*sigma, 95.4% within +/- 2.

Note

  • by: Nava2

gaussRand

..code-block:: pascal

function gaussRand(mean, dev: Extended): Extended;

Calculates a normally distributed point around mean (u) with a standard deviation of dev (o).

..note:

- by: Nava2

Example:

..code-block:: pascal

// shooting arrows simulation: pt := Point(gaussRand(center.x, 0.5), gaussRand(center.y, 0.5)); WriteLn(Format(‘Hit the target at (%d, %d).’, [pt.x, pt.y]));

gaussPoint

procedure gaussPoint(cX, cY: Integer; sAngle, eAngle: Extended; maxRad: Integer; out oX, oY: Integer);

Calculates a point about cX, cY with radius maxRad. The sangle and eangle are in radians. The point is returned in the reference parameters oX, oY.

Note

  • by: Nava2

Example:

var
  gX, gY: Integer;
begin
  // get a gaussian pt in a circle:
  gaussPoint(MMCX, MMCY, 0, math_2PI, MMX2-MMCX, gX, gY);
  WriteLn(Format("gX, gY -> %d, %d", gX, gY);
end;

gaussRangeExt

function gaussRangeExt(minI, maxI: Extended): Extended;

Returns a number between minI and maxI that is normally distributed in the range.

Note

  • by: Nava2

Example:

randMean := gaussRangeExt(0, 20);

gaussRangeInt

function gaussRangeInt(minI, maxI: Integer): Integer;

See gaussRangeExt for more detail. Same function, but with integers.

Note

  • by: Nava2

gaussRandom

function gaussRandom(maxExt: Integer): Integer;

Computes a normally distributed number in [0, maxExt). Thus, it behaves like Random() would be expected to. But normally distributed about maxExt/2.

It is a wrapper for gaussRangeInt.

Note

  • by Nava2

Example:

gaussBox

procedure gaussBox(out px, py: Integer; x1, y1, x2, y2: Integer);

Calculates a point normally distributed from the center of the passed box. It checks for outlying points and will regenerate points if necessary.

Note

  • by: Nava2

Example:

var
  gX, gY: Integer;
begin
  // get a gaussian pt in a circle:
  gauss_Box(gX, gY, MMX1, MMY1, MMX2, MMY2);
  WriteLn(Format("gX, gY -> %d, %d", gX, gY);
end;