Log inGet started
Package

RaceSim.module

Newest version

README.md

RaceSim — the rules of a turf race

The whole of the game's logic, with nothing drawn and nothing scheduled. Every other piece of the game reads it:

  • RaceDirector.component steps it every frame and places the horses from it.
  • HorseRaceUI.module draws the standings, clock and times it produces.
  • Racecourse.sceneModule and scenes/main.scene/build.luau mirror its TRACK numbers so the horses are always on the turf they model.

The oval

RaceSim.TRACK = { A = 92, B = 56, WIDTH = 22, RAIL_OUT = 12.4, RAIL_IN = 11.6, SAMPLES = 720 }

An ellipse in the XZ plane. Distance is measured in metres run from the finish line, and the finish line sits at t = 0 — the point of least curvature, world (92, 0, 0) — so the home straight runs along Z and the stands stand outside it at +X. A model on the track faces +Z.

RaceSim.pose(distance, lane) -> x, z, yaw, nx, nz

lane is -1 (inner) through 1 (outer); yaw turns a +Z-facing model down the track; nx, nz is the outward normal, which is how the broadcast camera finds the outside of the rail. RaceSim.LENGTH is the oval's circumference in metres (about 472).

The field

RaceSim.FIELD is the eight horses: number, name, coat body, silk and cap colours, a preferred style, and the three hidden parameters speed / stamina / guts (0–100). Horse 1 is the player's, ヒカリノサクラ.

RaceSim.STYLES are the four 作戦 — nige 逃げ, senko 先行, sashi 差し, oikomi 追込 — with STYLE_NAME and STYLE_NOTE for the screen.

One race

local race = RaceSim.newRace(plan, career)   -- plan overrides horse 1's style
local events = RaceSim.step(race, dt)        -- { kind = "lead"|"final"|"drain"|"finish", ... }
local rows = RaceSim.standings(race)         -- place, number, name, colour, gap, finished, time

step is where the race is decided:

  • Pace — each style keeps its own multiplier through 序盤 / 中盤 / 終盤 (PACE, ×0.92 to ×1.09 of the horse's own top speed). Front runners go early, 差し and 追込 keep something for the last stretch.
  • Stamina — drains with (v/16)^3, so a horse that runs faster empties it sooner; a full tank lasts 38 + 0.62 × stamina seconds at racing speed. Below 14% the horse fades toward ×0.78 — that is 失速, and it happens in the last 200 m to the horses that were asked too much too early.
  • 根性 — every rival within 5 m adds up to ×1.03, scaled by guts/100 and by how late the race is, so horses that are level in the straight fight each other harder than horses alone.

RaceSim.FINAL is the last 200 m. RaceSim.formatTime writes m:ss.cc, RaceSim.prize pays a placing in 万円, RaceSim.colourOf / nameOf look a horse up by number.

Changing the track

Change A, B and WIDTH here and change the same three numbers in Racecourse.sceneModule (it cannot require this module — a scene module compiles in its own environment) and the scene's start gate follows. Everything else — distances, pace, finish times — works in metres and needs no edit.