Add LapsPerSection property to map headers, fixes finish line distance in hybrid section-circuit maps

- It is possible to have a circuit map separated into
  sections, where there are multiple "laps" before making
  a full loop
- Normally the lap count is used to multiply the finish
  line distance, but it fails for these maps
- The LapsPerSection property fixes the calculation by
  specifying how many laps make up a full loop
  - Default = 1 lap (most maps)
This commit is contained in:
James R 2024-03-03 03:04:24 -08:00
parent 0d4f42cf80
commit 9f982a574e
5 changed files with 9 additions and 2 deletions

View file

@ -1299,6 +1299,8 @@ void readlevelheader(MYFILE *f, char * name)
mapheaderinfo[num]->encorepal = (UINT16)i;
else if (fastcmp(word, "NUMLAPS"))
mapheaderinfo[num]->numlaps = (UINT8)i;
else if (fastcmp(word, "LAPSPERSECTION"))
mapheaderinfo[num]->lapspersection = max((UINT8)i, 1u);
else if (fastcmp(word, "SKYBOXSCALE"))
mapheaderinfo[num]->skybox_scalex = mapheaderinfo[num]->skybox_scaley = mapheaderinfo[num]->skybox_scalez = (INT16)i;
else if (fastcmp(word, "SKYBOXSCALEX"))

View file

@ -509,6 +509,7 @@ struct mapheader_t
UINT16 levelflags; ///< LF_flags: merged booleans into one UINT16 for space, see below
UINT32 typeoflevel; ///< Combination of typeoflevel flags.
UINT8 numlaps; ///< Number of laps in circuit mode, unless overridden.
UINT8 lapspersection; ///< Number of laps per section in hybrid section-circuit maps.
fixed_t gravity; ///< Map-wide gravity.
char relevantskin[SKINNAMESIZE+1]; ///< Skin to use for tutorial (if not provided, uses Eggman.)

View file

@ -9891,9 +9891,10 @@ static void K_UpdateDistanceFromFinishLine(player_t *const player)
// correct we need to add to it the length of the entire circuit multiplied by the number of laps
// left after this one. This will give us the total distance to the finish line, and allow item
// distance calculation to work easily
if ((mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) == 0U)
const mapheader_t *mapheader = mapheaderinfo[gamemap - 1];
if ((mapheader->levelflags & LF_SECTIONRACE) == 0U)
{
const UINT8 numfulllapsleft = ((UINT8)numlaps - player->laps);
const UINT8 numfulllapsleft = ((UINT8)numlaps - player->laps) / mapheader->lapspersection;
player->distancetofinish += numfulllapsleft * K_GetCircuitLength();
}
}

View file

@ -2535,6 +2535,8 @@ static int mapheaderinfo_get(lua_State *L)
lua_pushinteger(L, header->palette);
else if (fastcmp(field,"numlaps"))
lua_pushinteger(L, header->numlaps);
else if (fastcmp(field,"lapspersection"))
lua_pushinteger(L, header->lapspersection);
else if (fastcmp(field,"levelselect"))
lua_pushinteger(L, header->levelselect);
else if (fastcmp(field,"levelflags"))

View file

@ -458,6 +458,7 @@ static void P_ClearSingleMapHeaderInfo(INT16 num)
mapheaderinfo[num]->palette = UINT16_MAX;
mapheaderinfo[num]->encorepal = UINT16_MAX;
mapheaderinfo[num]->numlaps = NUMLAPS_DEFAULT;
mapheaderinfo[num]->lapspersection = 1;
mapheaderinfo[num]->levelselect = 0;
mapheaderinfo[num]->levelflags = 0;
mapheaderinfo[num]->menuflags = 0;