Skip to content

Commit

Permalink
Enhance: store current player location in map file on a per profile b…
Browse files Browse the repository at this point in the history
…asis

It is possible to copy a saved map from one profile to another - even if
that other profile is in use.  However this will lose the details of where
the (other) player is located in THAT profile.  This commit aims to correct
that by sneaking a look at where the other player is and storing that
in the file that is both copied for this profile before it is copied and to
the file that is copied over.

This data was stored in (int) TMap::mRoomId which has now become a:
(QHash<QString, int>) TMap::mRoomIdHash with the profile name as the key
and the Value being the equivalent of mRoomId in the new code.  This has
required an increment in the Map file format version from 17 to 18.  The
default - that will be used unless the developer or tester changes it in
the Profile Preferences dialog remains at 16.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven committed Mar 21, 2016
1 parent 275a712 commit 94dd41b
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 85 deletions.
20 changes: 10 additions & 10 deletions src/T2DMap.cpp
Expand Up @@ -467,7 +467,7 @@ void T2DMap::paintEvent( QPaintEvent * e )
int px,py;
QList<int> exitList;
QList<int> oneWayExits;
TRoom * pPlayerRoom = mpMap->mpRoomDB->getRoom( mpMap->mRoomId );
TRoom * pPlayerRoom = mpMap->mpRoomDB->getRoom( mpMap->mRoomIdHash.value( mpHost->getName() ) );
if( !pPlayerRoom )
{
p.drawText(_w/2,_h/2,"No map or no valid position.");
Expand All @@ -476,7 +476,7 @@ void T2DMap::paintEvent( QPaintEvent * e )
}

int ox, oy; // N/U: oz;
if( mRID != mpMap->mRoomId && mShiftMode ) mShiftMode = false;
if( mRID != mpMap->mRoomIdHash.value( mpHost->getName() ) && mShiftMode )
{
mShiftMode = false;
}
Expand All @@ -492,7 +492,7 @@ void T2DMap::paintEvent( QPaintEvent * e )
{
return;
}
mRID = mpMap->mRoomId;
mRID = mpMap->mRoomIdHash.value( mpHost->getName() );
pRID = mpMap->mpRoomDB->getRoom( mRID );
mAID = pRID->getArea();
pAID = mpMap->mpRoomDB->getArea( mAID );
Expand Down Expand Up @@ -1423,9 +1423,9 @@ void T2DMap::paintEvent( QPaintEvent * e )
if( mpMap->mpRoomDB->getRoom(mTarget) )
{
mpMap->mTargetID = mTarget;
if( mpMap->findPath( mpMap->mRoomId, mpMap->mTargetID) )
if( mpMap->findPath( mpMap->mRoomIdHash.value( mpHost->getName() ), mpMap->mTargetID) )
{
mpMap->mpHost->startSpeedWalk();
mpHost->startSpeedWalk();
}
else
{
Expand Down Expand Up @@ -1504,7 +1504,7 @@ void T2DMap::paintEvent( QPaintEvent * e )
p.setPen(__pen);
}

if( mShiftMode && currentAreaRoom == mpMap->mRoomId )
if( mShiftMode && currentAreaRoom == mpMap->mRoomIdHash.value( mpHost->getName() ) )
{
float _radius = (1.2*tx)/2;
QPointF _center = QPointF(rx,ry);
Expand Down Expand Up @@ -1654,9 +1654,9 @@ void T2DMap::paintEvent( QPaintEvent * e )
if( mpMap->mpRoomDB->getRoom(mTarget) )
{
mpMap->mTargetID = mTarget;
if( mpMap->findPath( mpMap->mRoomId, mpMap->mTargetID) )
if( mpMap->findPath( mpMap->mRoomIdHash.value( mpHost->getName() ), mpMap->mTargetID) )
{
mpMap->mpHost->startSpeedWalk();
mpHost->startSpeedWalk();
}
else
{
Expand Down Expand Up @@ -1702,7 +1702,7 @@ void T2DMap::paintEvent( QPaintEvent * e )
if( mpMap->mpRoomDB->getRoom(mTarget) )
{
mpMap->mTargetID = mTarget;
if( mpMap->findPath( mpMap->mRoomId, mpMap->mTargetID) )
if( mpMap->findPath( mpMap->mRoomIdHash.value( mpHost->getName() ), mpMap->mTargetID) )
{
mpMap->mpHost->startSpeedWalk();
}
Expand Down Expand Up @@ -3023,7 +3023,7 @@ void T2DMap::slot_setPlayerLocation()
int _newRoomId = *( mMultiSelectionSet.constBegin() );
if( mpMap->mpRoomDB->getRoom( _newRoomId ) ) {
// No need to check it is a DIFFERENT room - that is taken care of by en/dis-abling the control
mpMap->mRoomId = _newRoomId;
mpMap->mRoomIdHash[ mpHost->getName() ] = _newRoomId;
mpMap->mNewMove = true;
TEvent manualSetEvent;
manualSetEvent.mArgumentList.append( QStringLiteral( "sysManualLocationSetEvent" ) );
Expand Down
1 change: 1 addition & 0 deletions src/TArea.h
Expand Up @@ -41,6 +41,7 @@ class TArea

friend bool TMap::serialize( QDataStream & );
friend bool TMap::restore( QString );
friend const bool TMap::retrieveMapFileStats( QString , QString *, int *, int *, int *, int * );

public:
TArea(TMap*, TRoomDB*);
Expand Down
4 changes: 2 additions & 2 deletions src/TLuaInterpreter.cpp
Expand Up @@ -1129,7 +1129,7 @@ int TLuaInterpreter::centerview( lua_State * L )
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
if( pHost->mpMap && pHost->mpMap->mpRoomDB->getRoom( roomid ) )
{
pHost->mpMap->mRoomId = roomid;
pHost->mpMap->mRoomIdHash[ pHost->getName() ] = roomid;
pHost->mpMap->mNewMove = true;
if( pHost->mpMap->mpM )
{
Expand Down Expand Up @@ -4448,7 +4448,7 @@ int TLuaInterpreter::getRoomWeight( lua_State *L )
}
else
{
roomId = pHost->mpMap->mRoomId;
roomId = pHost->mpMap->mRoomIdHash.value( pHost->getName() );
}

TRoom * pR = pHost->mpMap->mpRoomDB->getRoom( roomId );
Expand Down

0 comments on commit 94dd41b

Please sign in to comment.