bool do_creature_pickup(creature_t* creature) { if ((creature->flag & CF_INTELLIGENT) && count_items_at(current_dungeon, creature->pos.x, creature->pos.y) > 0) { std::vector<item_t*> items = items_at(current_dungeon, creature->pos.x, creature->pos.y); for (auto it = items.begin(); it != items.end(); ++it) { if ((int)(*it)->type < MAX_EQUIP && !creature->equipment[(*it)->type]) { handle_creature_equip(creature, *it); remove_item(current_dungeon, *it, false); return true; } else if ((int)(*it)->type >= MAX_EQUIP) { if ((*it)->type == ITEM_TYPE_WAND) { creature->inventory.push_back(*it); remove_item(current_dungeon, *it, false); } } } } return false; }
void add_item_to_dungeon(dungeon_t* dungeon, item_t* item, int x, int y) { item->pos.x = x; item->pos.y = y; bool added_to_stack = false; // Check for stackable items. ONly stack if identified! std::vector<item_t*> items = items_at(dungeon, x, y); for (auto it = items.begin(); it != items.end(); ++it) { if ((*it)->base_name() == item->base_name() && item->stackable && item->identified) { (*it)->stacksize += item->stacksize; delete item; added_to_stack = true; break; } } if (!added_to_stack) { dungeon->items.push_back(item); } }
static std::vector<item_t*> _do_multi_pickup(int x, int y) { std::vector<item_t*> items = items_at(current_dungeon, x, y); item_list pickup_list { items, item_list::PICKUP }; pickup_list.execute(); return pickup_list.get_chosen_items(); }
void _examine_tile(int x, int y) { if (position_in_fov(current_dungeon, x, y)) { if (stairs_t* stairs = get_stairs_at(current_dungeon, x, y)) { if (stairs->to_branch == current_branch->name) { if (stairs->to && stairs->to->level < current_dungeon->level) append_msg_log("Stairs to %s %d", current_branch->name.c_str(), stairs->to->level - current_branch->base_level + 1); else append_msg_log("Stairs to %s %d", current_branch->name.c_str(), current_dungeon->level - current_branch->base_level + 2); } else { append_msg_log("Stairs to %s", stairs->to_branch.c_str()); } } else { tile_t* tile = get_tile_at(current_dungeon, x, y); append_msg_log("%s.", tile->description); } for (size_t i = 0; i < current_dungeon->creatures.size(); i++) { creature_t* creature = current_dungeon->creatures[i]; if (creature->pos.x == x && creature->pos.y == y && player.sees(creature)) { std::string wield_string = "."; if (creature->equipment[0]) { wield_string = ", wielding a " + creature->equipment[0]->get_item_name(); } for (int i = 1; i < ITEM_TYPE_RING; i++) { if (creature->equipment[i]) { if (wield_string == ".") { wield_string = ""; } wield_string += ", wearing " + creature->equipment[i]->get_item_name(); } } if (strlen(creature->prefix) > 0) { append_msg_log("A %s%s.", creature->name, wield_string.c_str()); } else { append_msg_log("%s%s.", creature->name, wield_string.c_str()); } } } std::vector<item_t*> items = items_at(current_dungeon, x, y); if (items.size() == 1) { item_t* item = items.front(); if (item->stacksize > 1) { append_msg_log("Some %s.", item->plural); } else { append_msg_log("A %s.", item->get_item_name().c_str()); } } else if (items.size() > 1) { append_msg_log("A %s and several other items", items.front()->get_item_name().c_str()); } } }
void player_act() { switch(get_last_action()) { case ACTION_TILL: till(x, y, current_map); break; case ACTION_PICKUP: { item* it = get_item(items_at(x, y, current_map), item_count_at(x, y, current_map), PURPOSE_PICKUP, true); if(!it) break; printf_message(COLOR_DEFAULT, "Picked up %d %s", it->count, it->name); callback("picked_up", it->script_state); take_item(x, y, it, current_map); add_item(it); } break; case ACTION_DROP: { item* it = get_item(inventory, item_count, PURPOSE_DROP, false); if(!it) break; if(it->can_equip && equipment[it->slot] == it) { equipment[it->slot] = 0; printf_message(COLOR_DEFAULT, "You unequip the %s, and drop it on the ground.", it->name); callback("removed", it->script_state); } item* clone = clone_item(it); callback("dropped", clone->script_state); place_item(x, y, clone, current_map); remove_item(it, -1); } break; case ACTION_APPLY: { item* it = get_item(inventory, item_count, PURPOSE_APPLY, false); if(!it) break; callback("apply", it->script_state); remove_item(it, 1); } break; case ACTION_EQUIP: { item* it = get_item(inventory, item_count, PURPOSE_EQUIP, false); if(!it || it->slot == SLOT_INVALID) break; callback("equip", it->script_state); printf_message(COLOR_DEFAULT, "You equip the %s.", it->name); equipment[it->slot] = it; break; } case ACTION_REMOVE: { item* it = get_item(equipment, 3, PURPOSE_REMOVE, false); if(!it) break; callback("remove", it->script_state); equipment[it->slot] = 0; printf_message(COLOR_DEFAULT, "You unequip the %s.", it->name); break; } case ACTION_PLANT: { if(!can_plant(x, y, current_map, true)) break; item* it = get_item(inventory, item_count, PURPOSE_PLANT, false); if(!it) break; if(spawn_plant(x, y, it->plant_id, current_map)) { printf_message(COLOR_DEFAULT, "You plant the %s in the tilled soil.", it->name); remove_item(it, 1); } break; } case ACTION_HARVEST: { add_item(harvest_plant(x, y, current_map)); break; } case ACTION_HELP: show_controls(); break; case ACTION_INVENTORY: get_item(inventory, item_count, PURPOSE_NONE, false); break; case ACTION_WATER: water_tile(x, y, current_map); break; case ACTION_EXAMINE: { int mx, my; get_last_mouse_position(&mx, &my); int xdiff = mx - pres_x; int ydiff = my - pres_y; if(mx < 1 || my < 1 || mx > 78 || my > 78) break; examine(x + xdiff, y +ydiff, current_map); } break; } if(ep_current <= 0) add_message(COLOR_EP_CRIT, "Out of energy, you fall to the ground."); }