Ejemplo n.º 1
0
/*
  This function writes a string in a single line starting at a given
  position of the window, and without changing line. Each new line
  character contained in the string will be considered as a string
  termination, and if the string is too long to fit in the screen, it
  will be truncated. 
  
  So, if on the screen of the example we execute the functions:
  
  win_write_line_at(sc, 3, 26, "en un lugar de la mancha");
  win_write_line_at(sc, 5, 24, "oh!\nI didn't know");
   
  
  we get:
  
                       19             33
     0                  v             v    39
    +----------------------------------------+
  0 |                                        |
    |                                        |
    |                          en un lu      | < 2
    |                                        | 
    |                        oh!             |
    |                                        |
    |                                        | < 6
    |                                        | 
    |                                        |
   9|                                        |
    +----------------------------------------+
  
    Parameters:
      sc:  the window structure on which the function operates.
      r:   the row of the window at which the writing begins
      c:   the column of the window at which the writing begins
      str: the screen that we must write
  
    Returns:
      the number of characters actually written on the screen.
  
 */
int win_write_line_at(sc_rectangle *sc, int r, int c, char *str) {
    char *nl_p;
    char save, av_space, ret;

    if (!_is_visible(sc)) return 0;
    if (r >= sc->nr || c >= sc->nc) return 0;
    nl_p = strchr(str, '\n');
    if (nl_p) *nl_p = 0;
  
    av_space = sc->nc - c;
    save = -1;
    if (strlen(str) > av_space) {
        save = str[av_space - 1];
        str[av_space - 1] = 0;
    }
  
    _prepare_font(sc);
    _move_to(sc, r, c);
    printf("%s", str);
    fflush(stdout);
    if (save > 0) {
        str[av_space - 1] = save;
        ret = av_space;
    } else
        ret = strlen(str);
    if (nl_p) *nl_p = '\n';
    sc->last_line = r;
    return ret;
}
Ejemplo n.º 2
0
/*
   Sets the foreground colour for the window

   Parameters:
      sc:  the window structure on which the function operates.
      col: the new foreground colour;

   Returns:
      1: regular execution
      0: incorrect colour parameter
 */
int win_fgcol(sc_rectangle *sc, int col)
{
    if (!_is_visible(sc))
        return ERR;
    if (col >= 30 && col <= 39)
        sc->bg_color = col;
    return OK;
}
Ejemplo n.º 3
0
/*
  Writes a char at a given position of the window.

    Parameters:
      sc:  the window structure on which the function operates.
      r:   the row of the window at which the writing begins
      c:   the column of the window at which the writing begins
      ch: the character that we must write
  
    Returns:
      The constant 1
  
*/
int win_write_char_at(sc_rectangle *sc, int r, int c, char ch) {
  
    if (!_is_visible(sc)) return 0;
    if (r >= sc->nr || c >= sc->nc) return 0;
  
    _move_to(sc, r, c);
    printf("%c", ch);
    fflush(stdout);
    return 1;
}
Ejemplo n.º 4
0
static void _player_action(int energy_use)
{
    if (possessor_get_toggle() == LEPRECHAUN_TOGGLE_BLINK)
        teleport_player(10, TELEPORT_LINE_OF_SIGHT);

    /* In wilderness travel mode, there is no place for dropped objects to go! */
    if (p_ptr->wild_mode)
        return;

    /* Maintain current form. 
       Rules: If the source is visible, then we can always maintain the form. 
       Otherwise, memorized forms get a saving throw to maintain, but non-memorized 
       forms are simply lost. */
    if ( p_ptr->current_r_idx != MON_MIMIC 
      && one_in_(100) 
      && !_is_visible(p_ptr->current_r_idx) )
    {
        bool lose_form = FALSE;
        if (_is_memorized(p_ptr->current_r_idx))
        {
        #if 0
            /* I'm debating this at the moment. Many forms have disparate body types and a random
               low frequency return to the default body will scatter no longer wieldable equipment
               about in a most annoying fashion. Plus, there is already dispel magic for this ... */
            int r_lvl = r_info[p_ptr->current_r_idx].level;
            int p_lvl = _calc_level(p_ptr->max_plv); /* Use max level in case player is assuming a weak form that decreases player level. */
            p_lvl += 3 + p_ptr->stat_ind[A_DEX];

            if (randint1(p_lvl) < r_lvl)
            {
                msg_print("You lose control over your current form.");
                lose_form = TRUE;
            }
        #endif
        }
        else
        {
            msg_print("Your knowledge of this form fades from memory.");
            lose_form = TRUE;
        }

        if (lose_form)
            _set_current_r_idx(MON_MIMIC);
    }
}