Skip to content

Commit

Permalink
fixed forcing the path machine to specific room
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.code.sf.net/p/mmapper/code/trunk/mmapper@100 14c008a5-6e10-0410-bf79-c100e0f1932b
  • Loading branch information
alve committed Oct 14, 2006
1 parent 5df7b0c commit 2a85592
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 54 deletions.
45 changes: 29 additions & 16 deletions src/display/mapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,28 @@ void MapCanvas::wheelEvent ( QWheelEvent * event )

}

void MapCanvas::forceMapperToRoom() {
const RoomSelection *tmpSel = NULL;
if (m_roomSelection) {
tmpSel = m_roomSelection;
m_roomSelection = 0;
}
else {
tmpSel = m_data->select(Coordinate(GLtoMap(m_selX1), GLtoMap(m_selY1), m_selLayer1));
}
if(tmpSel->size() == 1)
{
if (Config().m_mapMode == 2)
{
const Room *r = tmpSel->values().front();
emit charMovedEvent(createEvent( CID_UNKNOWN, getName(r), getDynamicDescription(r), getDescription(r), 0, 0));
}
else
emit setCurrentRoom(tmpSel->keys().front());
}
m_data->unselect(tmpSel);
updateGL();
}

void MapCanvas::mousePressEvent(QMouseEvent *event)
{
Expand Down Expand Up @@ -302,23 +324,14 @@ void MapCanvas::mousePressEvent(QMouseEvent *event)
if ((event->buttons() & Qt::LeftButton) &&
(event->modifiers() & Qt::CTRL ) &&
(event->modifiers() & Qt::ALT ) )
{
m_ctrlPressed = true;
m_altPressed = true;

const RoomSelection *tmpSel = m_data->select(Coordinate(GLtoMap(m_selX1), GLtoMap(m_selY1), m_selLayer1));
if(tmpSel->size() > 0)
{
if (Config().m_mapMode == 2)
{
const Room *r = tmpSel->values().front();
emit charMovedEvent(createEvent( CID_UNKNOWN, getName(r), getDynamicDescription(r), getDescription(r), 0, 0));
}
else
emit setCurrentRoom(tmpSel->keys().front());
{
if (m_roomSelection) {
m_data->unselect(m_roomSelection);
m_roomSelection = 0;
}
m_data->unselect(tmpSel);
updateGL();
m_ctrlPressed = true;
m_altPressed = true;
forceMapperToRoom();
break;
}

Expand Down
3 changes: 3 additions & 0 deletions src/display/mapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class MapCanvas : public QGLWidget//, public RoomRecipient

void drawRoom(const Room* room, const std::vector<Room *> & rooms, const std::vector<std::set<RoomRecipient *> > & locks);



public slots:
void forceMapperToRoom();
void onInfoMarksEditDlgClose();

void setCanvasMouseMode(CanvasMouseMode);
Expand Down
12 changes: 11 additions & 1 deletion src/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ void MainWindow::createActions()
releaseAllPathsAct->setCheckable(false);
connect(releaseAllPathsAct, SIGNAL(triggered()), m_pathMachine, SLOT(releaseAllPaths()));

forceRoomAct = new QAction(QIcon(":/icons/force.png"), tr("Force Path Machine to selected Room"), this);
forceRoomAct->setStatusTip(tr("Force Path Machine to selected Room"));
forceRoomAct->setCheckable(false);
connect(forceRoomAct, SIGNAL(triggered()), getCurrentMapWindow()->getCanvas(), SLOT(forceMapperToRoom()));

roomActGroup = new QActionGroup(this);
roomActGroup->setExclusive(false);
roomActGroup->addAction(editRoomSelectionAct);
Expand Down Expand Up @@ -637,7 +642,11 @@ void MainWindow::setupToolBars()
viewToolBar->addAction(zoomOutAct);
viewToolBar->addAction(layerUpAct);
viewToolBar->addAction(layerDownAct);
viewToolBar->addAction(releaseAllPathsAct);

pathMachineToolBar = addToolBar(tr("Path Machine"));
pathMachineToolBar->setObjectName("PathMachineToolBar");
pathMachineToolBar->addAction(releaseAllPathsAct);
pathMachineToolBar->addAction(forceRoomAct);
//viewToolBar->addAction(m_dockDialog->toggleViewAction());

roomToolBar = addToolBar(tr("Rooms"));
Expand All @@ -656,6 +665,7 @@ void MainWindow::setupToolBars()
connectionToolBar->addAction(deleteConnectionSelectionAct);

settingsToolBar = addToolBar(tr("Preferences"));
settingsToolBar->setObjectName("PreferencesToolBar");
settingsToolBar->addAction(preferencesAct);
}

Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public slots:
QToolBar *modeToolBar;
QToolBar *mapModeToolBar;
QToolBar *viewToolBar;
QToolBar *pathMachineToolBar;
QToolBar *roomToolBar;
QToolBar *connectionToolBar;
QToolBar *settingsToolBar;
Expand Down Expand Up @@ -205,6 +206,7 @@ public slots:
QAction *mergeDownRoomSelectionAct;
QAction *connectToNeighboursRoomSelectionAct;

QAction *forceRoomAct;
QAction *releaseAllPathsAct;

void createActions();
Expand Down
4 changes: 2 additions & 2 deletions src/mapdata/roomfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ ComparisonResult RoomFactory::compare(const Room * room, const ParseEvent * even
return CR_EQUAL;
}

if (m_name.isEmpty() && m_desc.isEmpty() && (!updated))
if (tolerance >= 100 || (m_name.isEmpty() && m_desc.isEmpty() && (!updated)))
{
// user-created
// user-created oder explicit update
return CR_TOLERANCE;
}

Expand Down
44 changes: 17 additions & 27 deletions src/pathmachine/pathmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,31 @@ PathMachine::PathMachine(AbstractRoomFactory * in_factory, bool threaded) :
paths(new list<Path *>)
{}

void PathMachine::setCurrentRoom(uint id)
void PathMachine::setCurrentRoom(Approved * app)
{
releaseAllPaths();
const Room * perhaps = app->oneMatch();
if (perhaps)
{
Approved app(factory, lastEvent, params.matchingTolerance);
emit lookingForRooms(&app, id);
mostLikelyRoom = *perhaps;
emit playerMoved(mostLikelyRoom.getPosition());
state = APPROVED;
}
retry();
}

void PathMachine::setCurrentRoom(const Coordinate & pos)
{
{
Approved app(factory, lastEvent, params.matchingTolerance);
emit lookingForRooms(&app, pos);
}
retry();
Approved app(factory, lastEvent, 100);
emit lookingForRooms(&app, pos);
setCurrentRoom(&app);
}

void PathMachine::setCurrentRoom(uint id)
{
Approved app(factory, lastEvent, 100);
emit lookingForRooms(&app, id);
setCurrentRoom(&app);
}


void PathMachine::init()
Expand Down Expand Up @@ -103,24 +110,7 @@ void PathMachine::retry()
state = SYNCING;
break;
case EXPERIMENTING:
set<Path *> prevPaths;
list<Path *> * newPaths = new list<Path *>;
for (list<Path*>::iterator i = paths->begin(); i != paths->end(); ++i)
{
Path * working = *i;
Path * previous = working->getParent();
previous->removeChild(working);
working->setParent(0);
working->deny();
if (previous && (prevPaths.find(previous) == prevPaths.end()))
{
newPaths->push_back(previous);
prevPaths.insert(previous);
}
}
delete paths;
paths = newPaths;
if (paths->empty()) state = SYNCING;
releaseAllPaths();
break;
}
if (lastEvent) event(lastEvent);
Expand Down
19 changes: 11 additions & 8 deletions src/pathmachine/pathmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,37 @@ class Approved;
* and decides if rooms have to be added (and where) and where the player is
* the results are published via signals
*/
class PathMachine : public Component {
Q_OBJECT
public slots:
class PathMachine : public Component
{
Q_OBJECT
public slots:
virtual void event(ParseEvent *);
virtual void deleteMostLikelyRoom();
virtual void releaseAllPaths();
virtual void retry();
virtual void setCurrentRoom(uint id);
virtual void setCurrentRoom(const Coordinate & pos);

signals:
signals:
void lookingForRooms(RoomRecipient *,ParseEvent *);
void lookingForRooms(RoomRecipient *,uint);
void lookingForRooms(RoomRecipient *,const Coordinate &);
void playerMoved(const Coordinate &);
void createRoom(ParseEvent *, const Coordinate &);
void scheduleAction(MapAction *);

public:
public:
PathMachine(AbstractRoomFactory * factory, bool threaded = true);
virtual void init();
virtual Qt::ConnectionType requiredConnectionType(const QString &);
protected:

protected:
PathParameters params;
void experimenting(ParseEvent * event);
void syncing(ParseEvent * event);
void approved(ParseEvent * event);
void evaluatePaths();
void setCurrentRoom(Approved * app);
void tryExits(const Room *, RoomRecipient *, ParseEvent *, bool out);
void tryExit(const Exit & possible, RoomRecipient * recipient, bool out);
void tryCoordinate(const Room *, RoomRecipient *, ParseEvent *);
Expand All @@ -94,7 +96,8 @@ Q_OBJECT
char state;
std::list<Path *> * paths;

};
}
;


#endif
Expand Down
Binary file added src/resources/icons/force.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/resources/mmapper2.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<file>icons/mapmove.png</file>
<file>icons/layerup.png</file>
<file>icons/layerdown.png</file>
<file>icons/force.png</file>
<file>pixmaps/splash20.png</file>
<file>pixmaps/terrain0.png</file>
<file>pixmaps/terrain1.png</file>
Expand Down

0 comments on commit 2a85592

Please sign in to comment.