diff --git a/src/influ.c b/src/influ.c index 4d620bc..51f1340 100644 --- a/src/influ.c +++ b/src/influ.c @@ -47,6 +47,7 @@ static void CheckForTuxOutOfMap(); static void analyze_players_mouse_click(); +static void handle_automatic_item_collection(); static int no_left_button_press_in_previous_analyze_mouse_click = FALSE; @@ -756,6 +757,9 @@ void move_tux() if (game_map->state != DEFAULT) analyze_players_mouse_click(); + if (GameConfig.auto_refill_inventory) + handle_automatic_item_collection(); + if (MouseLeftPressed()) no_left_button_press_in_previous_analyze_mouse_click = FALSE; else @@ -1608,6 +1612,30 @@ static void analyze_players_mouse_click() check_for_droids_to_attack_or_talk_with(); } +static void handle_automatic_item_collection() +{ + level *obj_lvl = NULL; + int tmp; + int can_pickup = 0; + + // Test if an object is below player + if ((tmp = get_floor_item_index_under_me(&obj_lvl)) != -1) { + // Can always pick up money + if (item_spec_eq_id(obj_lvl->ItemList[tmp].type, "Valuable Circuits")) + can_pickup = 1; + + // Test if object can be stacked + if (ItemMap[obj_lvl->ItemList[tmp].type].item_group_together_in_inventory) { + // TODO: Test if object already in inventory + can_pickup = 1; + } + + if (can_pickup) { + give_item(&obj_lvl->ItemList[tmp]); + } + } +} + /** * Handles arrow key based movements diff --git a/src/init.c b/src/init.c index f4a42e1..164c844 100644 --- a/src/init.c +++ b/src/init.c @@ -701,6 +701,7 @@ void ResetGameConfigToDefaultValues(void) GameConfig.next_time_height_of_screen = GameConfig.screen_height; GameConfig.fullscreen_on = FALSE; GameConfig.difficulty_level = DIFFICULTY_NORMAL; + GameConfig.auto_refill_inventory = FALSE; if (GameConfig.locale) { free(GameConfig.locale); } diff --git a/src/items.c b/src/items.c index 921ff83..1d1701f 100644 --- a/src/items.c +++ b/src/items.c @@ -1532,6 +1532,33 @@ int get_floor_item_index_under_mouse_cursor(level **item_lvl) return (-1); } +int get_floor_item_index_under_me(level **item_lvl) { + gps virt_mouse_pos; + struct visible_level *vis_lvl, *n; + int i; + + if (world_frozen()) + return -1; + + BROWSE_VISIBLE_LEVELS(vis_lvl, n) { + + level *lvl = vis_lvl->lvl_pointer; + update_virtual_position(&virt_mouse_pos, &Me.pos, lvl->levelnum); + + for (i = 0; i < MAX_ITEMS_PER_LEVEL; i++) { + if (lvl->ItemList[i].type == (-1)) + continue; + + if ((fabsf(virt_mouse_pos.x - lvl->ItemList[i].pos.x) < 0.5) && + (fabsf(virt_mouse_pos.y - lvl->ItemList[i].pos.y) < 0.5)) { + *item_lvl = lvl; + return (i); + } + } + } + return (-1); +} + /** * Handle inventory screen and related things: interact with items in inventory * grid, in inventory slots and in hand. Also handle dropping items in hand and diff --git a/src/menu.c b/src/menu.c index 97aaeb0..c9ab048 100644 --- a/src/menu.c +++ b/src/menu.c @@ -959,6 +959,7 @@ static int Game_handle(int n) { enum { DIFFICULTY = 1, + AUTO_REFILL_INVENTORY = 2, LEAVE_MENU }; switch (n) { @@ -970,6 +971,10 @@ static int Game_handle(int n) GameConfig.difficulty_level %= 3; game_needs_restart = TRUE; return CONTINUE_MENU; + case AUTO_REFILL_INVENTORY: + while (EnterPressed() || SpacePressed()) ; + GameConfig.auto_refill_inventory = !GameConfig.auto_refill_inventory; + return CONTINUE_MENU; case LEAVE_MENU: return EXIT_MENU; default: @@ -987,8 +992,9 @@ static void Game_fill(char *MenuTexts[MAX_MENU_ITEMS]) }; sprintf(MenuTexts[0], _("Difficulty: %s"), _(difficulty_str[GameConfig.difficulty_level])); - strncpy(MenuTexts[1], _("Back"), 1024); - MenuTexts[2][0] = '\0'; + sprintf(MenuTexts[1], _("Auto-Refill Inventory: %s"), GameConfig.auto_refill_inventory ? _("YES") : _("NO")); + strncpy(MenuTexts[2], _("Back"), 1024); + MenuTexts[3][0] = '\0'; } static int Options_handle(int n) diff --git a/src/proto.h b/src/proto.h index 6e42fad..2f2d608 100644 --- a/src/proto.h +++ b/src/proto.h @@ -497,6 +497,7 @@ void CopyItem(item * SourceItem, item * DestItem); void DeleteItem(item * Item); void drop_random_item(int, float, float, int, int); int get_floor_item_index_under_mouse_cursor(level **item_lvl); +int get_floor_item_index_under_me(level **item_lvl); int item_is_currently_equipped(item * Item); enum slot_type get_slot_type_by_name(char *name); const char *item_specs_get_name(int type); diff --git a/src/struct.h b/src/struct.h index 458edec..6461770 100644 --- a/src/struct.h +++ b/src/struct.h @@ -192,6 +192,7 @@ typedef struct configuration_for_freedroid { int show_all_floor_layers; int difficulty_level; + int auto_refill_inventory; string locale;