From 98c3ff193d8c71e4c07ed0e3e6b41f87e920fa61 Mon Sep 17 00:00:00 2001 From: Anselme Date: Wed, 16 Mar 2016 17:14:52 +0100 Subject: [PATCH] fixed travel --- app/rpgmodule.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/rpgmodule.cpp b/app/rpgmodule.cpp index d5e360a..3a24a90 100644 --- a/app/rpgmodule.cpp +++ b/app/rpgmodule.cpp @@ -142,10 +142,13 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) { if(dir.compare("north") == 0 || dir.compare("n") == 0) { - if(c->y == 0 || (repeat && terrainType != WORLDMAP[c->x][c->y-1])) + bool isDiff = repeat && terrainType != WORLDMAP[c->x][c->y-1]; + if(c->y == 0 || (isDiff && dist != 0)) blocked = true; else { + if(isDiff) + blocked = true; c->y -= 1; ++dist; } @@ -153,10 +156,13 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) } else if(dir.compare("south") == 0 || dir.compare("s") == 0) { - if(c->y == 24 || (repeat && terrainType != WORLDMAP[c->x][c->y+1])) + bool isDiff = repeat && terrainType != WORLDMAP[c->x][c->y+1]; + if(c->y == 24 || (isDiff && dist != 0)) blocked = true; else { + if(isDiff) + blocked = true; c->y += 1; ++dist; } @@ -164,10 +170,13 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) } else if(dir.compare("west") == 0 || dir.compare("w") == 0) { - if(c->x == 0 || (repeat && terrainType != WORLDMAP[c->x-1][c->y])) + bool isDiff = repeat && terrainType != WORLDMAP[c->x-1][c->y]; + if(c->x == 0 || (isDiff && dist != 0)) blocked = true; else { + if(isDiff) + blocked = true; c->x -= 1; ++dist; } @@ -175,10 +184,13 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) } else if(dir.compare("east") == 0 || dir.compare("e") == 0) { - if(c->x == 24 || (repeat && terrainType != WORLDMAP[c->x+1][c->y])) + bool isDiff = repeat && terrainType != WORLDMAP[c->x+1][c->y]; + if(c->x == 24 || (isDiff && dist != 0)) blocked = true; else { + if(isDiff) + blocked = true; c->x += 1; ++dist; } @@ -191,10 +203,12 @@ QString RPGModule::playerTravel(RPGCharacter *c, QString dir, bool repeat) if(blocked) { - if(repeat && dist > 0) + if(repeat) { - QString("%1 travels %2 during %3 hours through %4") - .arg(c->pseudo).arg(direction).arg(dist).arg(currentArea); + if(dist > 0) + return QString("%1 travels %2 during %3 hours through %4") + .arg(c->pseudo).arg(direction).arg(dist).arg(currentArea); + else {} } else return QString("%1 cannot go %2, a hill is blocking his way").arg(c->pseudo).arg(direction);