Пример #1
0
Room * RemoveExit::tryExec()
{
  vector<Room *> & rooms = roomIndex();
  Room * rfrom = rooms[from];
  if (rfrom) rfrom->exit(dir).removeOut(to);
  Room * rto = rooms[to];
  if (rto) rto->exit(factory()->opposite(dir)).removeIn(from);
	return rfrom;
}
Пример #2
0
void ModifyExitFlags::exec(uint id)
{
    Room *room = roomIndex()[id];
    if (room) {
        uint exitFlags = room->exit(dir)[fieldNum].toUInt();
        modifyFlags(exitFlags, flags, mode);
        room->exit(dir)[fieldNum] = exitFlags;
    }
}
Пример #3
0
Room * AddExit::tryExec() {
	vector<Room *> & rooms = roomIndex();
	Room * rfrom = rooms[from];
	if (!rfrom) return 0;
	Room * rto = rooms[to];
	if (!rto) return 0;

	rfrom->exit(dir).addOut(to);
	rto->exit(factory()->opposite(dir)).addIn(from);
	return rfrom;
}
Пример #4
0
void UpdateExitField::exec(uint id)
{
    Room *room = roomIndex()[id];
    if (room) {
        room->exit(dir)[fieldNum] = update;
    }
}
Пример #5
0
void MergeRelative::exec(uint id)
{
    Room *source = roomIndex()[id];
    if (!source) return;
    Map &roomMap = map();
    vector<Room *> &rooms = roomIndex();
    const Coordinate &c = source->getPosition();
    Coordinate newPos = c + move;
    Room *target = roomMap.get(newPos);
    if (target) {
        factory()->update(target, source);
        ParseEvent *props = factory()->getEvent(target);
        uint oid = target->getId();
        RoomCollection *newHome = treeRoot().insertRoom(props);
        vector<RoomCollection *> &homes = roomHomes();
        RoomCollection *oldHome = homes[oid];
        if (oldHome) oldHome->erase(target);

        homes[oid] = newHome;
        if (newHome) newHome->insert(target);
        const ExitsList &exits = source->getExitsList();
        for (int dir = 0; dir < exits.size(); ++dir) {
            const Exit &e = exits[dir];
            for (set<uint>::const_iterator i = e.inBegin(); i != e.inEnd(); ++i) {
                uint oeid = *i;
                Room *oe = rooms[oeid];
                if (oe) {
                    oe->exit(Mmapper2Exit::opposite(dir)).addOut(oid);
                    target->exit(dir).addIn(oeid);
                }
            }
            for (set<uint>::const_iterator i = e.outBegin(); i != e.outEnd(); ++i) {
                uint oeid = *i;
                Room *oe = rooms[oeid];
                if (oe) {
                    oe->exit(Mmapper2Exit::opposite(dir)).addIn(oid);
                    target->exit(dir).addOut(oeid);
                }
            }
        }
        Remove::exec(source->getId());
    } else {
        Coordinate newPos = c + move;
        roomMap.setNearest(newPos, source);
    }
}
Пример #6
0
QString MapData::getDoorName(const Coordinate & pos, uint dir)
{
  QMutexLocker locker(&mapLock);
  Room * room = map.get(pos);
  if (room && dir < 7)
  {
    return ::getDoorName(room->exit(dir));
  }
  else return "exit";
}
Пример #7
0
bool MapData::getExitFlag(const Coordinate & pos, uint flag, uint dir, uint field)
{
  QMutexLocker locker(&mapLock);
  Room * room = map.get(pos);
  if (room && dir < 7)
  {
    //ExitFlags ef = ::getFlags(room->exit(dir));
    ExitFlags ef = room->exit(dir)[field].toUInt();
    if (ISSET(ef, flag)) return true;
  }
  return false;
}
Пример #8
0
void ConnectToNeighbours::connectRooms(Room *center, Coordinate &otherPos, uint dir, uint cid)
{
    Room *room = map().get(otherPos);
    if (room) {
        uint oid = room->getId();
        Exit &oexit = room->exit(Mmapper2Exit::opposite(dir));
        oexit.addIn(cid);
        oexit.addOut(cid);
        Exit &cexit = center->exit(dir);
        cexit.addIn(oid);
        cexit.addOut(oid);
    }
}
Пример #9
0
void DisconnectFromNeighbours::exec(uint id)
{
    Room *room = roomIndex()[id];
    if (room) {
        ExitsList &exits = room->getExitsList();
        for (int dir = 0; dir < exits.size(); ++dir) {
            Exit &e = exits[dir];
            for (set<uint>::const_iterator in = e.inBegin(); in != e.inEnd(); ++in) {
                Room *other = roomIndex()[*in];
                if (other) {
                    other->exit(Mmapper2Exit::opposite(dir)).removeOut(id);
                }
            }
            for (set<uint>::const_iterator out = e.outBegin(); out != e.outEnd(); ++out) {
                Room *other = roomIndex()[*out];
                if (other) {
                    other->exit(Mmapper2Exit::opposite(dir)).removeIn(id);
                }
            }
            e.removeAll();
        }
    }
}
Пример #10
0
void Remove::exec(uint id) {
  vector<Room *> & rooms = roomIndex();
  Room * room = rooms[id];
  if (!room) return;
  map().remove(room->getPosition());
  RoomCollection * home = roomHomes()[id];
  if (home) home->erase(room);
  rooms[id] = 0;
  // don't return previously used ids for now
  // unusedIds().push(id);
  const ExitsList & exits = room->getExitsList();
  for(int dir = 0; dir < exits.size(); ++dir) {
    const Exit & e = exits[dir];
    for (set<uint>::const_iterator i = e.inBegin(); i != e.inEnd(); ++i) {
      Room * other = rooms[*i];
      if (other) other->exit(factory()->opposite(dir)).removeOut(id);
    }
    for (set<uint>::const_iterator i = e.outBegin(); i != e.outEnd(); ++i) { 
      Room * other = rooms[*i];
      if (other) other->exit(factory()->opposite(dir)).removeIn(id);
    }
  }
  delete room;
}
Пример #11
0
void CharacterService::startMove(const std::shared_ptr<Character> &c, Direction dir)
{
    Level *currentLevel = c->level();
    Room *r = c->room();
    RoomExit *exit = r->exit(dir);
    if (exit) {
        MoveStartEvent(c, exit->targetRoom()).execute();

        Level *targetLevel = exit->targetRoom()->level();
        auto moveEndEvent = new MoveEndEvent(c, exit->targetRoom());
        auto moveEndTime = MUD->timeAfter(travelTime(c, exit->travelDistance()));
        if (currentLevel == targetLevel) {
            currentLevel->eventQueue()->push(moveEndTime, moveEndEvent);
        }
        else {
            MEQ->push(moveEndTime, moveEndEvent);
        }
    }

}
Пример #12
0
QList<Coordinate> MapData::getPath(const QList<CommandIdType> dirs)
{
  QMutexLocker locker(&mapLock);
  QList<Coordinate> ret;
  Room * room = map.get(m_position);
  if (room)
  {
    QListIterator<CommandIdType> iter(dirs);
    while (iter.hasNext())
    {
      uint dir = iter.next();
      if (dir > 5) break;
      Exit & e = room->exit(dir);
      if (!(getFlags(e) & EF_EXIT)) continue;
      if (e.outBegin() == e.outEnd() || ++e.outBegin() != e.outEnd()) break;
      room = roomIndex[*e.outBegin()];
      if (!room) break;
      ret.append(room->getPosition());
    }
  }
  return ret;
}