- removed some more hubtravel related player start fudging.

* do not skip the player_t init when travelling in a hub. The old player may still be needed in some edge cases. This applies only to singleplayer for now. The multiplayer version still needs reviewing. I left it alone because it may shuffle players around which is not wanted when doing hub travelling.
 * do not spawn two temp players in G_FinishTravel. Instead handle the case where no player_t::mo can be found gracefully by adding a few nullptr checks. This temp player served no real purpose except for having a valid pointer. The actual start position was retrieved from somewhere else.
This commit is contained in:
Christoph Oelckers 2016-09-25 01:28:27 +02:00
parent 74b8e9f286
commit 6a6a0e8017
2 changed files with 17 additions and 23 deletions

View file

@ -1207,29 +1207,23 @@ void G_FinishTravel ()
pnum = int(pawn->player - players); pnum = int(pawn->player - players);
pawn->ChangeStatNum (STAT_PLAYER); pawn->ChangeStatNum (STAT_PLAYER);
pawndup = pawn->player->mo; pawndup = pawn->player->mo;
start = NULL;
assert (pawn != pawndup); assert (pawn != pawndup);
if (pawndup == NULL)
{ // Oh no! there was no start for this player!
start = G_PickPlayerStart(pnum, PPS_FORCERANDOM);
if (start != NULL) pawndup = P_SpawnPlayer(start, pnum, (level.flags2 & LEVEL2_PRERAISEWEAPON) ? SPF_WEAPONFULLYUP : 0);
if (pawndup == NULL)
{
pawn->flags |= MF_NOSECTOR | MF_NOBLOCKMAP;
pawn->Destroy();
continue;
}
}
if (start == NULL)
{
start = G_PickPlayerStart(pnum, 0); start = G_PickPlayerStart(pnum, 0);
if (start == NULL) if (start == NULL)
{
if (pawndup != nullptr)
{ {
Printf(TEXTCOLOR_RED "No player %d start to travel to!\n", pnum + 1); Printf(TEXTCOLOR_RED "No player %d start to travel to!\n", pnum + 1);
// Move to the coordinates this player had when they left the level. // Move to the coordinates this player had when they left the level.
pawn->SetXYZ(pawndup->Pos()); pawn->SetXYZ(pawndup->Pos());
} }
else
{
// Could not find a start for this player at all. This really should never happen but if it does, let's better abort.
DThinker::DestroyThinkersInList(STAT_TRAVELLING);
I_Error ("No player %d start to travel to!\n", pnum + 1);
}
} }
oldpawn = pawndup; oldpawn = pawndup;
@ -1266,8 +1260,11 @@ void G_FinishTravel ()
pawn->player->camera = pawn; pawn->player->camera = pawn;
pawn->player->viewheight = pawn->ViewHeight; pawn->player->viewheight = pawn->ViewHeight;
pawn->flags2 &= ~MF2_BLASTED; pawn->flags2 &= ~MF2_BLASTED;
if (oldpawn != nullptr)
{
DObject::StaticPointerSubstitution (oldpawn, pawn); DObject::StaticPointerSubstitution (oldpawn, pawn);
oldpawn->Destroy(); oldpawn->Destroy();
}
if (pawndup != NULL) if (pawndup != NULL)
{ {
pawndup->Destroy(); pawndup->Destroy();

View file

@ -537,7 +537,7 @@ void P_SerializeSounds(FSerializer &arc)
//========================================================================== //==========================================================================
void CopyPlayer(player_t *dst, player_t *src, const char *name); void CopyPlayer(player_t *dst, player_t *src, const char *name);
static void ReadOnePlayer(FSerializer &arc, bool skipload); static void ReadOnePlayer(FSerializer &arc);
static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload); static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload);
static void SpawnExtraPlayers(); static void SpawnExtraPlayers();
@ -594,7 +594,7 @@ void P_SerializePlayers(FSerializer &arc, bool skipload)
// first player present, no matter what their name. // first player present, no matter what their name.
if (numPlayers == 1) if (numPlayers == 1)
{ {
ReadOnePlayer(arc, skipload); ReadOnePlayer(arc);
} }
else else
{ {
@ -617,7 +617,7 @@ void P_SerializePlayers(FSerializer &arc, bool skipload)
// //
//========================================================================== //==========================================================================
static void ReadOnePlayer(FSerializer &arc, bool skipload) static void ReadOnePlayer(FSerializer &arc)
{ {
int i; int i;
const char *name = NULL; const char *name = NULL;
@ -636,11 +636,8 @@ static void ReadOnePlayer(FSerializer &arc, bool skipload)
didIt = true; didIt = true;
player_t playerTemp; player_t playerTemp;
playerTemp.Serialize(arc); playerTemp.Serialize(arc);
if (!skipload)
{
CopyPlayer(&players[i], &playerTemp, name); CopyPlayer(&players[i], &playerTemp, name);
} }
}
else else
{ {
if (players[i].mo != NULL) if (players[i].mo != NULL)