void Update::exec(uint id) { Room * room = roomIndex()[id]; if (room) { factory()->update(room, &props); RoomCollection * newHome = treeRoot().insertRoom(&props); vector<RoomCollection *> & homes = roomHomes(); RoomCollection * oldHome = homes[id]; if (oldHome) oldHome->erase(room); homes[id] = newHome; newHome->insert(room); } }
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); } }
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; }