Esempio n. 1
0
void set_symbol(terrain_type *type)
{
  if (!type)
    return;

  long ch = popup_getkey("Enter symbol for %s.", type->name.c_str());
  if (ch == KEY_ESC)
    return;

  type->symbol.symbol = ch;

  Window w_col(1, 1, 20, 6);
  w_col.outline();
  for (int i = 0; i < c_dkgray; i++) {
    w_col.putch(i + 1, 1, nc_color(i), c_black, '#');
    w_col.putch(i + 1, 3, nc_color(i + 8), c_black, '#');
  }
  w_col.putstr(1, 2, c_white, c_black, "12345678");
  w_col.putstr(1, 4, c_white, c_black, "abcdefgh");

  w_col.refresh();
  ch = getch();

  if (ch >= '1' && ch <= '8')
    type->symbol.fg = nc_color(ch - '1');
  if (ch >= 'a' && ch <= 'h')
    type->symbol.fg = nc_color(ch - 'a' + c_dkgray);
  type->symbol.bg = c_black;
}
Esempio n. 2
0
void glyph::load_data(std::istream &datastream)
{
 int fgtmp, bgtmp;
 datastream >> symbol >> fgtmp >> bgtmp;

 fg = nc_color(fgtmp);
 bg = nc_color(bgtmp);
}
Esempio n. 3
0
void change_color(element* ele)
{
  if (!ele) {
    return;
  }
  Window w_col(1, 1, 20, 6);
  w_col.outline();
  for (int i = 0; i < c_dkgray; i++) {
    w_col.putch(i + 1, 1, nc_color(i), c_black, '#');
    w_col.putch(i + 1, 3, nc_color(i + 8), c_black, '#');
  }
  w_col.putstr(1, 2, c_white, c_black, "12345678");
  w_col.putstr(1, 4, c_white, c_black, "abcdefgh");

  w_col.refresh();
  long ch = getch();

  if (ch >= '1' && ch <= '8')
    ele->color = nc_color(ch - '1');
  if (ch >= 'a' && ch <= 'h')
    ele->color = nc_color(ch - 'a' + c_dkgray);
}
Esempio n. 4
0
void element::load_data(std::istream &datastream)
{
  name = load_to_character(datastream, ':', true);
  int tmpcolor, tmpsize;
  datastream >> id >> tmpcolor >> tmpsize;
  color = nc_color(tmpcolor);
  for (int i = 0; i < tmpsize; i++) {
    int tmptrans;
    datastream >> tmptrans;
    transformations.push_back( transform_type(tmptrans) );
  }
  datastream >> tmpsize;
  for (int i = 0; i < tmpsize; i++) {
    int tmpdam;
    datastream >> tmpdam;
    damages.push_back( damage_type(tmpdam) );
  }
}
robot_finds_kitten::robot_finds_kitten( const catacurses::window &w )
{
#ifdef __ANDROID__
    input_context ctxt( "IUSE_SOFTWARE_KITTEN" );
#endif

    ret = false;
    char ktile[83] =
        "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#&()*+./:;=?![]{|}y";
    int used_messages[MAXMESSAGES];

    rfkLINES = 20;
    rfkCOLS = 60;

    const int numbogus = 20;
    nummessages = 201;
    empty.x = -1;
    empty.y = -1;
    empty.color = nc_color();
    empty.character = ' ';
    for( int c = 0; c < rfkCOLS; c++ ) {
        for( int c2 = 0; c2 < rfkLINES; c2++ ) {
            rfkscreen[c][c2] = EMPTY;
        }
    }
    /* Create an array to ensure we don't get duplicate messages. */
    for( int c = 0; c < nummessages; c++ ) {
        used_messages[c] = 0;
        bogus_messages[c] = 0;
        bogus[c] = empty;
    }
    /* Now we initialize the various game OBJECTs.
       * Assign a position to the player. */
    robot.x = rand() % rfkCOLS;
    robot.y = rand() % ( rfkLINES - 3 ) + 3;
    robot.character = '#';
    robot.color = c_white;
    rfkscreen[robot.x][robot.y] = ROBOT;

    /* Assign the kitten a unique position. */
    do {
        kitten.x = rand() % rfkCOLS;
        kitten.y = rand() % ( rfkLINES - 3 ) + 3;
    } while( rfkscreen[kitten.x][kitten.y] != EMPTY );

    /* Assign the kitten a character and a color. */
    do {
        kitten.character = ktile[rand() % 82];
    } while( kitten.character == '#' || kitten.character == ' ' );

    do {
        kitten.color = all_colors.get_random();
    } while( kitten.color == c_black );

    rfkscreen[kitten.x][kitten.y] = KITTEN;

    /* Now, initialize non-kitten OBJECTs. */
    for( int c = 0; c < numbogus; c++ ) {
        /* Assign a unique position. */
        do {
            bogus[c].x = rand() % rfkCOLS;
            bogus[c].y = ( rand() % ( rfkLINES - 3 ) ) + 3;
        } while( rfkscreen[bogus[c].x][bogus[c].y] != EMPTY );
        rfkscreen[bogus[c].x][bogus[c].y] = c + 2;

        /* Assign a character. */
        do {
            bogus[c].character = ktile[rand() % 82];
        } while( bogus[c].character == '#' || bogus[c].character == ' ' );

        do {
            bogus[c].color = all_colors.get_random();
        } while( bogus[c].color == c_black );

        /* Assign a unique message. */
        int index = 0;
        do {
            index = rand() % nummessages;
        } while( used_messages[index] != 0 );
        bogus_messages[c] = index;
        used_messages[index] = 1;
    }

    instructions( w );

    werase( w );
    mvwprintz( w, 0, 0, c_white, _( "robotfindskitten v22July2008 - press q to quit." ) );
    for( int c = 0; c < rfkCOLS; c++ ) {
        mvwputch( w, 2, c, BORDER_COLOR, '_' );
    }
    wmove( w, kitten.y, kitten.x );
    draw_kitten( w );

    for( int c = 0; c < numbogus; c++ ) {
        mvwputch( w, bogus[c].y, bogus[c].x, bogus[c].color, bogus[c].character );
    }

    wmove( w, robot.y, robot.x );
    draw_robot( w );
    int old_x = robot.x;
    int old_y = robot.y;

    wrefresh( w );
    /* Now the fun begins. */
    int input = inp_mngr.get_input_event().get_first_input(); // @todo: use input context

    while( input != 'q' && input != 'Q' && input != KEY_ESCAPE ) {
        process_input( input, w );
        if( ret ) {
            break;
        }
        /* Redraw robot, where available */
        if( !( old_x == robot.x && old_y == robot.y ) ) {
            wmove( w, old_y, old_x );
            wputch( w, c_white, ' ' );
            wmove( w, robot.y, robot.x );
            draw_robot( w );
            rfkscreen[old_x][old_y] = EMPTY;
            rfkscreen[robot.x][robot.y] = ROBOT;
            old_x = robot.x;
            old_y = robot.y;
        }
        wrefresh( w );
        // TODO: use input context / rewrite loop so this is only called at one place
        input = inp_mngr.get_input_event().get_first_input();
    }
}
Esempio n. 6
0
void Game::generate_kingdoms()
{
  if (!world) {
    debugmsg("Game::generate_kingdoms() called with NULL world!");
    return;
  }

  if (!kingdoms.empty()) {
    for (int i = 0; i < kingdoms.size(); i++) {
      delete (kingdoms[i]);
    }
  }
  kingdoms.clear();

  bool color_free[c_null];  // c_null is the last color
  for (int i = 0; i < c_null; i++) {
    color_free[i] = true;
  }
// One kingdom for each race.  Start at 1 to skip RACE_NULL.
  for (int i = 1; i < RACE_MAX; i++) {
    popup_nowait("Initializing kingdoms (%d of %d)...", i, RACE_MAX - 1);

    Kingdom* kingdom = new Kingdom;
    kingdom->uid = i - 1;
    kingdom->set_game(this);
    kingdom->race = Race(i);
    Race_datum* race_dat = Race_data[i];
// Pick a color - try the official race color first
    if (race_dat->color < c_dkgray && color_free[ race_dat->color ]) {
      kingdom->color = race_dat->color;
      color_free[ race_dat->color ] = false;

    } else {
      std::vector<nc_color> colors = race_dat->kingdom_colors;
// Remove any already-used colors
      for (int i = 0; i < colors.size(); i++) {
        if (!color_free[ colors[i] ]) {
          colors.erase(colors.begin() + i);
          i--;
        }
      }
      if (colors.empty()) { // Can't use official colors; use a random one
        std::vector<nc_color> free_colors;
// Start at 1 to skip c_black; stop at c_dkgray to skip bright colors
        for (int i = 1; i < c_dkgray; i++) {
          if (color_free[i]) {
            free_colors.push_back( nc_color(i) );
          }
        }
        if (free_colors.empty()) {  // 8 kingdoms used already!
          kingdom->color = nc_color( rng(1, c_dkgray - 1) );
        } else {
          int index = rng(0, free_colors.size() - 1);
          kingdom->color = free_colors[index];
          color_free[ free_colors[index] ] = false;
        }
      } else {  // We can use an official color!
        int index = rng(0, colors.size() - 1);
        kingdom->color = colors[index];
        color_free[ colors[index] ] = false;
      }
    } // if (!color_free[race_dat->color])

// Place the kingdom.
    if (kingdom->place_capital(world)) {
      kingdoms.push_back( kingdom );  // ...and add to our list.
    }
  } // for (int i = 1; i < RACE_MAX; i++)

/* Now, expand the kingdoms by placing duchy seats.  To keep things fair, each
 * kingdom gets to place a single city/duchy at a time.  We go through our list,
 * each kingdom taking a turn, until all kingdoms are out of points.
 */
  std::vector<int> points, kingdom_index;
  for (int i = 0; i < kingdoms.size(); i++) {
    points.push_back( KINGDOM_EXPANSION_POINTS ); // Defined in kingdom.h
    kingdom_index.push_back( i );
  }

  int iteration = 0, max_points = points.size() * KINGDOM_EXPANSION_POINTS;
  while (!kingdom_index.empty()) {
    iteration++;
    int total_points = 0;
    for (int i = 0; i < points.size(); i++) {
      total_points += points[i];
    }
    int percent = (100 * (max_points - total_points)) / max_points;
    popup_nowait("Placing duchies... [%d%%%%%%%%]", percent);
    for (int i = 0; i < kingdom_index.size(); i++) {
      Kingdom* kingdom = kingdoms[ kingdom_index[i] ];
      if (!kingdom->place_duchy_seat(world, points[i])) {
        kingdom_index.erase( kingdom_index.begin() + i );
        points.erase( points.begin() + i );
      }
    }
  }

// Now each kingdom gets to place minor cities in its duchies.
  for (int i = 0; i < kingdoms.size(); i++) {
    int percent = (100 * (i + 1)) / kingdoms.size();
    popup_nowait("Placing minor cities... [%d%%%%%%%%] [%d/%d]",
                 percent, i + 1, kingdoms.size());
    kingdoms[i]->place_minor_cities(world);
  }

// Build roads from the capital to each duchy.  Building roads from the duchy to
// its minor cities is handled in place_minor_cities().
  for (int i = 0; i < kingdoms.size(); i++) {
    int percent = (100 * (i + 1)) / kingdoms.size();
    popup_nowait("Connecting duchies via road... [%d%%%%%%%%]", percent);
    for (int n = 0; n < kingdoms[i]->dukes.size(); n++) {
      City* capital = kingdoms[i]->capital;
      City* duke = kingdoms[i]->dukes[n];
      kingdoms[i]->build_road( world, capital, duke );
    }
  }

// Finally, swell the territory claimed by each kingdom.
  int expansions = 3;
  for (int n = 0; n < expansions; n++) {
    for (int i = 0; i < kingdoms.size(); i++) {
      popup_nowait("Expanding territories... (%d/%d; %d/%d)",
                   n + 1, expansions, i + 1, kingdoms.size());
      kingdoms[i]->expand_boundaries(world);
    }
  }

// And setup trade routes for all cities!
  for (int i = 0; i < kingdoms.size(); i++) {
    int base_percent = (100 * i) / kingdoms.size();
    kingdoms[i]->setup_trade_routes(base_percent);
  }
}