Skip to content

Commit

Permalink
libcommon|XG: Interpret XG leave_map line class arguments wrt episode…
Browse files Browse the repository at this point in the history
… IDs

Todo: Introduce a mechanism for referencing maps using URIs rather
than rely on interpretation of the old episode and map numbers.
  • Loading branch information
danij-deng committed Aug 19, 2014
1 parent 3def130 commit 047fc7a
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions doomsday/plugins/common/src/p_xgline.cpp
Expand Up @@ -2087,70 +2087,50 @@ int XLTrav_LineTeleport(Line *newLine, dd_bool /*ceiling*/, void *context,
#undef FUDGEFACTOR
}

dd_bool XL_ValidateMap(uint *map, int /*type*/)
{
// Check that the map truly exists.
if(P_MapExists(G_ComposeMapUri(::gameEpisode, *map).compose().toUtf8().constData()))
return true;

XG_Dev("XLTrav_LeaveMap: NOT A VALID MAP NUMBER %u, next will be map 1", *map);
*map = 0; // Should exist always?

return false;
}

int XLTrav_LeaveMap(Line *line, dd_bool /*ceiling*/, void * /*context*/,
void *context2, mobj_t * /*activator*/)
int XLTrav_LeaveMap(Line *line, dd_bool /*ceiling*/, void * /*context*/, void *context2,
mobj_t * /*activator*/)
{
linetype_t *info = static_cast<linetype_t *>(context2);

uint map = 0;
int temp = 0;
dd_bool mapSpecified = false;

// Is this a secret exit?
if(info->iparm[0] > 0)
{
G_SetGameActionMapCompleted(COMMON_GAMESESSION->mapUriForNamedExit("secret"), 0, true);
return false;
}

de::Uri newMapUri;
if(info->iparm[1] == LREF_NONE)
{
// (ip3) will be used to determine next map.
// (ip3) will be used to determine next map (1-based).
if(info->iparm[3])
{
map = info->iparm[3]-1;
mapSpecified = XL_ValidateMap(&map, 0);
newMapUri = G_ComposeMapUri(COMMON_GAMESESSION->episodeId().toInt() - 1, info->iparm[3] - 1);
XG_Dev("XLTrav_LeaveMap: Next map set to \"%s\"", newMapUri.compose().toUtf8().constData());
}
}
else
{ // We might possibly have a data reference to evaluate.
if(line)
// We might possibly have a data reference to evaluate.
else if(line)
{
int const oldMapNumber = XL_ValidateLineRef(line, info->iparm[3], context2, "Map Number");
if(oldMapNumber > 0)
{
temp = XL_ValidateLineRef(line,info->iparm[3], context2,
"Map Number");
if(temp > 0)
{
map = temp - 1;
mapSpecified = XL_ValidateMap(&map, info->iparm[3]);
}
newMapUri = G_ComposeMapUri(COMMON_GAMESESSION->episodeId().toInt() - 1, oldMapNumber - 1);
}

if(!mapSpecified)
XG_Dev("XLTrav_LeaveMap: Reference data not valid. "
"Next map as normal");
}

de::Uri newMapUri;
if(mapSpecified)
if(newMapUri.isEmpty())
{
XG_Dev("XLTrav_LeaveMap: Next map set to %u", map+1);
newMapUri = G_ComposeMapUri(::gameEpisode, map);
newMapUri = COMMON_GAMESESSION->mapUriForNamedExit("next");
XG_Dev("XLTrav_LeaveMap: Next map set to default for the 'next' exit");
}
else

// Check that the map truly exists.
if(!P_MapExists(newMapUri.compose().toUtf8().constData()))
{
newMapUri = COMMON_GAMESESSION->mapUriForNamedExit("next");
// Backward compatibility dictates that invalid refs be interpreted to mean the start map
// of the current episode (which is known to always exist).
newMapUri = de::Uri(COMMON_GAMESESSION->episodeDef()->gets("startMap"), RC_NULL);
}

G_SetGameActionMapCompleted(newMapUri, 0, false);
Expand Down

1 comment on commit 047fc7a

@danij-deng
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of this commit everything once again builds without error. All games other than Hexen should be working as expected (Hexen's MAPINFO is not yet translated during startup...).

Please sign in to comment.