ammunition_information calc_reloadable_ammo_info(const const_entity_handle item) { ammunition_information out; const auto maybe_magazine_slot = item[slot_function::GUN_DETACHABLE_MAGAZINE]; if (maybe_magazine_slot.alive() && maybe_magazine_slot.has_items()) { const auto mag = item.get_cosmos()[maybe_magazine_slot.get_items_inside()[0]]; const auto ammo_depo = mag[slot_function::ITEM_DEPOSIT]; ensure(ammo_depo->has_limited_space()); out.total_charges += count_charges_in_deposit(mag); out.total_ammo_space += ammo_depo->space_available; out.available_ammo_space += ammo_depo.calc_local_space_available(); } return out; }
components::transform sum_attachment_offsets(const cosmos& cosm, const inventory_item_address addr) { components::transform total; inventory_slot_id current_slot; current_slot.container_entity = addr.root_container; for (size_t i = 0; i < addr.directions.size(); ++i) { current_slot.type = addr.directions[i]; const auto slot_handle = cosm[current_slot]; ensure(slot_handle->is_physical_attachment_slot); ensure(slot_handle->always_allow_exactly_one_item); const auto item_in_slot = slot_handle.get_items_inside()[0]; total += get_attachment_offset(*slot_handle, total, item_in_slot); current_slot.container_entity = item_in_slot; } return total; }
void slot_button::update_rc(const logic_gui_context& context, const this_in_container& this_id) { const auto& step = context.get_step(); const auto& cosmos = step.get_cosmos(); const auto slot_id = cosmos[this_id.get_location().slot_id]; if (slot_id->always_allow_exactly_one_item) { this_id->set_flag(augs::gui::flag::ENABLE_DRAWING); if (slot_id.has_items()) { const_dereferenced_location<item_button_in_item> child_item_button = context.dereference_location(item_button_in_item{ slot_id.get_items_inside()[0].get_id() }); if (child_item_button->is_being_wholely_dragged_or_pending_finish(context, child_item_button)) { this_id->set_flag(augs::gui::flag::ENABLE_DRAWING); } else { this_id->unset_flag(augs::gui::flag::ENABLE_DRAWING); } } } this_id->slot_relative_pos = griddify(this_id->slot_relative_pos); this_id->user_drag_offset = griddify(this_id->user_drag_offset); vec2i absolute_pos = this_id->slot_relative_pos + this_id->user_drag_offset; if (context.get_rect_world().is_currently_dragging(this_id)) { absolute_pos += griddify(context.get_rect_world().current_drag_amount); } this_id->rc.set_position(absolute_pos); }