<commit_before>#include <curses.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "player.h"

#include "combat.h"
#include "game.h"
#include "level.h"
#include "ui.h"
#include "item.h"

player_info_t player;

static int experience_to_level(int);

void get_speed(int key, int * x, int * y)
{
    switch (key)
    {
    case KEY_LEFT:
        *x = -1;
        break;
    case KEY_RIGHT:
        *x = 1;
        break;
    case KEY_UP:
        *y = -1;
        break;
    case KEY_DOWN:
        *y = 1;
        break;
    default:
        break;
    }
    return;
}


int player_move(int input)
{
    int x_speed = 0, y_speed = 0;
    int mob_id;
    get_speed(input, &x_speed, &y_speed);
    mob_id = get_mob(current_level, player.mob->y + y_speed, player.mob->x + x_speed);

    if (mob_id != -1)
    {
        attack(player.mob, &current_level->mobs[mob_id]);
        return 0;
    }
    else if (try_move_mob(current_level, player.mob, y_speed, x_speed))
    {
        explore();

        if (current_level->map[player.mob->y][player.mob->x].type == tile_stair &&
            prompt_yn("Go down the stairs?"))
        {
            return TURN_DESCEND;
        }

        uint32_t item = current_level->map[player.mob->y][player.mob->x].item;

        if (item)
        {
            char item_n[100];
            char line[MSGLEN];            
    
            item_name(item_n, item);

            snprintf(line, MSGLEN, "Pick up %s?", item_n);

            if (prompt_yn(line))
            {
                if (give_item(item) == 666)
                {
                    print_msg("You're carrying too much shit already.");
                    wait();
                }
                else
                {
                    snprintf(line, MSGLEN,
                             "Okay -- you now have %s.", item_n);
                    print_msg(line);
                    wait();
                    current_level->map[player.mob->y][player.mob->x].item = 0;
                }
            }
            
            clear_msg();
        }

        draw_map(current_level);
        return TURN_COMPLETE;
    }

    print_msg("You cannot go there.");
    return TURN_ABORT;
}


int player_turn(void)
{
    int input, move, itemsel;

    while (1)
    {
        input = getch();

        clear_msg();

        switch (input)
        {
        case 'Q':
            if (prompt_yn("Do you want to quit?"))
                return TURN_QUIT;
            continue;

        case 'd':
        case 'u':
            if (count_items() == 0)
            {<commit_msg>item pickup key instead of prompt<commit_after>#include <curses.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "player.h"

#include "combat.h"
#include "game.h"
#include "level.h"
#include "ui.h"
#include "item.h"

player_info_t player;

static int experience_to_level(int);

void get_speed(int key, int * x, int * y)
{
    switch (key)
    {
    case KEY_LEFT:
        *x = -1;
        break;
    case KEY_RIGHT:
        *x = 1;
        break;
    case KEY_UP:
        *y = -1;
        break;
    case KEY_DOWN:
        *y = 1;
        break;
    default:
        break;
    }
    return;
}


int player_move(int input)
{
    int x_speed = 0, y_speed = 0;
    int mob_id;
    get_speed(input, &x_speed, &y_speed);
    mob_id = get_mob(current_level, player.mob->y + y_speed, player.mob->x + x_speed);

    if (mob_id != -1)
    {
        attack(player.mob, &current_level->mobs[mob_id]);
        return 0;
    }
    else if (try_move_mob(current_level, player.mob, y_speed, x_speed))
    {
        explore();

        if (current_level->map[player.mob->y][player.mob->x].type == tile_stair &&
            prompt_yn("Go down the stairs?"))
        {
            return TURN_DESCEND;
        }

        uint32_t item = current_level->map[player.mob->y][player.mob->x].item;

        if (item)
        {
            char item_n[100];
            char line[MSGLEN];            
    
            item_name(item_n, item);

            snprintf(line, MSGLEN, "There is %s here.", item_n);

            print_msg(line);
            wait();
            
            clear_msg();
        }

        draw_map(current_level);
        return TURN_COMPLETE;
    }

    print_msg("You cannot go there.");
    return TURN_ABORT;
}


int player_turn(void)
{
    int input, move, itemsel;

    while (1)
    {
        input = getch();

        clear_msg();

        switch (input)
        {
        case 'Q':
            if (prompt_yn("Do you want to quit?"))
                return TURN_QUIT;
            continue;

        case 'g':
        case ',':
            ;
            uint32_t item = current_level->map[player.mob->y][player.mob->x].item;

            if (item == 0)
            {
                print_msg("Nothing here!");
                continue;
            }

            char item_n[100];
            char line[MSGLEN];            
            
            item_name(item_n, item);
            
            if (give_item(item) == 666)
            {
                print_msg("You're carrying too much shit already.");
                wait();
            }
            else
            {
                snprintf(line, MSGLEN,
                         "Okay -- you now have %s.", item_n);
                print_msg(line);
                wait();
                current_level->map[player.mob->y][player.mob->x].item = 0;
            }
            
            clear_msg();
            
            return TURN_COMPLETE;


        case 'd':
        case 'u':
            if (count_items() == 0)
            {
{'fraction_non_alphanumeric': 0.12564513258586937, 'fraction_numerical': 0.007830574835379961, 'mean_word_length': 1.3945462292288027, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3029811', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1796, 'n_words': 393}