int main()
{
printf("5170984 %d\n", reversenum(5170984));
printf("406567 %d\n", reversenum(406567));
printf("368750 %d\n", reversenum(368750));
printf("2369510 %d\n", reversenum(2369510));
printf("2183293 %d\n", reversenum(2183293));
return 0;
}
Пример #2
0
void CEngine::angryLinker(CRoom *r)
{
  CRoom *p;
  unsigned int i;
  CRoom *candidates[6];
  int distances[6];
  int z;


  if (!conf->getAngrylinker())
    return;

  print_debug(DEBUG_ROOMS && DEBUG_ANALYZER, "in AngryLinker");

  if (r == NULL) {
    print_debug(DEBUG_ROOMS, "given room is NULL");
    return;
  }

  if (r->anyUndefinedExits() != true) {
    print_debug(DEBUG_ROOMS, "returning, no undefined exits in room found");
    return;     /* no need to try and link this room - there are no undefined exits */
  }

  /* reset the data */
  for (i=0; i <= 5; i++) {
    distances[i] = 15000;
    candidates[i] = 0;
  }
  z = 0;

  // if you are performing the full run over all rooms, it's better
  // to lock the Map completely.
  // else the other thread might delete the room you are examining at the moment!
  //map->lockForWrite();


  QVector<CRoom *> rooms = map->getRooms();
  /* find the closest neighbours by coordinate */
  for (i = 0; i < map->size(); i++) {
      p = rooms[i];

    /* z-axis: up and down exits */
    if (p->getZ() != r->getZ()) {

      if ((p->getX() != r->getX()) || (p->getY() != r->getY()))
        continue;

      /* up exit */
      if (p->getZ() > r->getZ()) {
        z = p->getZ() - r->getZ();
        if (z < distances[ED_UP]) {
          /* update */
          distances[ED_UP] = z;
          candidates[ED_UP] = p;
        }
      }

      /* DOWN exit */
      if (r->getZ() > p->getZ()) {
        z = r->getZ() - p->getZ();
        if (z < distances[ED_DOWN]) {
          /* update */
          distances[ED_DOWN] = z;
          candidates[ED_DOWN] = p;
        }
      }

    }
    /* done with z-axis */

    /* x-axis. */
    if ((p->getY() == r->getY()) && (p->getZ() == r->getZ())) {

      if (p->getX() == r->getX())
        continue;                       /* all coordinates are the same - skip */

      /* EAST exit */
      if (p->getX() > r->getX()) {
        z = p->getX() - r->getX();
        if (z < distances[ED_EAST]) {
          /* update */
          distances[ED_EAST] = z;
          candidates[ED_EAST] = p;
        }
      }

      /* WEST exit */
      if (r->getX() > p->getX()) {
        z = r->getX() - p->getX();
        if (z < distances[ED_WEST]) {
          /* update */
          distances[ED_WEST] = z;
          candidates[ED_WEST] = p;
        }
      }

    }
    /* y-axis.  */
    if ((p->getX() == r->getX()) && (p->getZ() == r->getZ())) {

      if (p->getY() == r->getY())
        continue;                       /* all coordinates are the same - skip */

      /* NORTH exit */
      if (p->getY() > r->getY()) {
        z = p->getY() - r->getY();
        if (z < distances[ED_NORTH]) {
          /* update */
          distances[ED_NORTH] = z;
          candidates[ED_NORTH] = p;
        }
      }

      /* SOUTH exit */
      if (r->getY() > p->getY()) {
        z = r->getY() - p->getY();
        if (z < distances[ED_SOUTH]) {
          /* update */
          distances[ED_SOUTH] = z;
          candidates[ED_SOUTH] = p;
        }
      }

    }


  }

  print_debug(DEBUG_ROOMS, "candidates gathered");

  /* ok, now we have candidates for linking - lets check directions and connections*/
  for (i=0; i <= 5; i++) {
    ExitDirection iDir = static_cast<ExitDirection> (i);

    if (r->isExitUndefined(iDir) && candidates[i] != NULL)
      if (candidates[i]->isExitUndefined( reversenum(iDir) )  == true) {

        if (distances[ i ] <= 2) {
          print_debug(DEBUG_ROOMS, "we have a match for AngryLinker!");
          print_debug(DEBUG_ROOMS, "ID: %i to %i exit %s.", r->getId(), candidates[i]->getId(), exits[i] );

          /* ok, do the linking */
          candidates[ i ]->setExitLeadsTo( reversenum(iDir), r);
          r->setExitLeadsTo(iDir, candidates[ i ]);
          print_debug(DEBUG_ROOMS, "Linked.", r->getId(), candidates[i]->getId(), exits[i] );

          send_to_user("--[ (AngryLinker) Linked exit %s with %s [%i].\r\n",
                      exits[ i ], (const char*) candidates[i]->getName(), candidates[i]->getId());

        }



      }
  }

  //map->unlock();
}
Пример #3
0
// where from where to ... map it!
void CEngine::mapCurrentRoom(CRoom *room, ExitDirection dir)
{
    print_debug(DEBUG_ANALYZER, "in mapCurrentRoom");


    /* casual checks for data */
    if (event.blind) {
        send_to_user( "--[Pandora: Failed to add new room. Blind !\r\n");
        mappingOff();
        return;
    } else if (event.name == "") {
        send_to_user( "--[Pandora: Failed to add new room. Missing roomname!\r\n");
        mappingOff();
        return;
    } else if (event.desc == "") {
        send_to_user( "--[Pandora: Failed to add new room. Missing description!\r\n");
        mappingOff();
        return;
    } else if (event.exits == "") {
        send_to_user( "--[Pandora: Failed to add new room. Missing exits data!\r\n");
        mappingOff();
        return;
    }
    send_to_user("--[ Adding new room!\n");

    int x = room->getX();
    int y = room->getY();
    int z = room->getZ();

    if (dir == ED_NORTH)
        y += 2;
    if (dir == ED_SOUTH)
        y -= 2;
    if (dir == ED_EAST)
        x+= 2;
    if (dir == ED_WEST)
        x -= 2;
    if (dir == ED_UP)
        z += 2;
    if (dir == ED_DOWN)
        z -= 2;

    addedroom = map->createRoom(event.name, event.desc, x, y, z);

    addedroom->setRegion( users_region );

    room->setExitLeadsTo(dir, addedroom);
    if (conf->getDuallinker() == true)
        addedroom->setExitLeadsTo(reversenum(dir), room);
    else
        map->oneway_room_id = room->getId();

    setExits(event.exits);
    do_exits((const char *) event.exits);

    //stacker.put(addedroom);

    CRoom *checkedDups = map->isDuplicate(addedroom);
    if (checkedDups == NULL) {
        resetAddedRoomVar();
    } else {
        stacker.put(checkedDups);
        if (checkedDups == addedroom) {
            // was not a duplicate, so see what angryLinker might be able to achieve
            angryLinker(addedroom);
        } else {
            resetAddedRoomVar();
            send_to_user("--[Pandora: Twin rooms merged!\n");
            proxy->send_line_to_user( (const char *) last_prompt );
            print_debug(DEBUG_ANALYZER, "Twins merged");
        }
    }
    print_debug(DEBUG_ANALYZER, "leaving mapCurrentRoom");

    return;
}