void drop_from_all_slots(const entity_handle c, logic_step& step) { const auto& container = c.get<components::container>(); for (const auto& s : container.slots) { const auto items_uninvalidated = s.second.items_inside; for (const auto item : items_uninvalidated) { perform_transfer({ c.get_cosmos()[item], c.get_cosmos()[inventory_slot_id()] }, step); } } }
void gui_system::advance_gui_elements(const logic_step step) { auto& cosmos = step.cosm; for (const auto root : cosmos.get(processing_subjects::WITH_GUI_ELEMENT)) { auto& element = root.get<components::gui_element>(); auto& rect_world = element.rect_world; const auto screen_size = element.get_screen_size(); if (root.has<components::item_slot_transfers>()) { game_gui_rect_tree tree; augs::gui::gui_entropy<game_gui_element_location> entropy; root_of_inventory_gui root_of_gui(screen_size); logic_gui_context context(step, root, tree, root_of_gui); root_of_inventory_gui_in_context root_location; rect_world.build_tree_data_into_context(context, root_location); const auto& entropies = step.entropy.entropy_per_entity; const auto& inputs_for_this_element = entropies.find(root); if (inputs_for_this_element != entropies.end()) { for (const auto& e : (*inputs_for_this_element).second) { //if (!element.is_gui_look_enabled) { // ensure(!e.has_event_for_gui); //} if (e.has_event_for_gui) { bool fetched = false; const auto& change = e.event_for_gui; const auto held_rect = context._dynamic_cast<item_button_in_item>(rect_world.rect_held_by_lmb); if (held_rect != nullptr) { const auto& item_entity = cosmos[held_rect.get_location().item_id]; auto& dragged_charges = element.dragged_charges; if (change.msg == augs::window::event::message::rdown || change.msg == augs::window::event::message::rdoubleclick ) { if (rect_world.held_rect_is_dragged) { step.transient.messages.post(item_slot_transfer_request_data{ item_entity, cosmos[inventory_slot_id()], dragged_charges }); fetched = true; } } if (change.msg == augs::window::event::message::wheel) { const auto& item = item_entity.get<components::item>(); const auto delta = change.scroll.amount; dragged_charges += delta; if (dragged_charges <= 0) { dragged_charges = item.charges + dragged_charges; } if (dragged_charges > item.charges) { dragged_charges = dragged_charges - item.charges; } } } if (!fetched) { rect_world.consume_raw_input_and_generate_gui_events(context, root_location, e.event_for_gui, entropy); } } } } // rect_world.call_idle_mousemotion_updater(context, root_location, entropy); rect_world.advance_elements(context, root_location, entropy, cosmos.get_fixed_delta()); auto& transfers = step.transient.messages.get_queue<item_slot_transfer_request_data>(); for (const auto& t : transfers) { perform_transfer(cosmos[t], step); } rect_world.rebuild_layouts(context, root_location); int max_height = 0; int total_width = 0; for (size_t i = 0; i < element.hotbar_buttons.size(); ++i) { const auto& hb = element.hotbar_buttons[i]; const auto bbox = hb.get_bbox(root); max_height = std::max(max_height, bbox.y); total_width += bbox.x; } const int left_rc_spacing = 2; const int right_rc_spacing = 1; int current_x = screen_size.x / 2 - total_width / 2 - left_rc_spacing; auto set_rc = [&](auto& hb) { const auto bbox = hb.get_bbox(root); hb.rc = xywh(xywhi(current_x, screen_size.y - max_height - 50, bbox.x + left_rc_spacing + right_rc_spacing, max_height)); current_x += bbox.x + left_rc_spacing + right_rc_spacing; }; for (size_t i = 1; i < element.hotbar_buttons.size(); ++i) { set_rc(element.hotbar_buttons[i]); } set_rc(element.hotbar_buttons[0]); transfers.clear(); } } }
void networked_testbed::populate(const logic_step step) { auto& world = step.cosm; const auto crate = prefabs::create_crate(world, vec2(200, 200 + 300), vec2i(100, 100) / 3); const auto crate2 = prefabs::create_crate(world, vec2(400, 200 + 400), vec2i(300, 300)); const auto crate4 = prefabs::create_crate(world, vec2(500, 200 + 0), vec2i(100, 100)); for (int x = -4; x < 4; ++x) { for (int y = -4; y < 4; ++y) { auto obstacle = prefabs::create_crate(world, vec2(2000.f + x * 300.f, -1000.f +2000.f + y * 300.f), vec2i(100, 100)); } } const auto car = prefabs::create_car(world, components::transform(-300, -600, -90)); const auto car2 = prefabs::create_car(world, components::transform(-800, -600, -90)); const auto car3 = prefabs::create_car(world, components::transform(-1300, -600, -90)); const auto motorcycle = prefabs::create_motorcycle(world, components::transform(0, -600, -90)); prefabs::create_motorcycle(world, components::transform(100, -600, -90)); const vec2 bg_size = assets::get_size(assets::texture_id::TEST_BACKGROUND); const int num_floors = 10 * 10; const int side = sqrt(num_floors) / 2; for (int x = -side; x < side; ++x) for (int y = -side; y < side; ++y) { //auto background = world.create_entity("bg[-]"); //ingredients::sprite(background, vec2(-1000, 0) + vec2(x, y) * (bg_size + vec2(1500, 550)), assets::texture_id::TEST_BACKGROUND, white, render_layer::GROUND); //ingredients::standard_static_body(background); auto street = world.create_entity("street[-]"); ingredients::sprite(street, { bg_size * vec2(x, y) }, assets::texture_id::TEST_BACKGROUND, gray1, render_layer::GROUND); //background.add_standard_components(); street.add_standard_components(); } const int num_characters = 6; std::vector<entity_id> new_characters; new_characters.resize(num_characters); auto character = [&](const size_t i) { return i < new_characters.size() ? world[new_characters.at(i)] : world[entity_id()]; }; { { const auto l = world.create_entity("l"); l += components::transform(); auto& light = l += components::light(); light.color = red; l.add_standard_components(); } { const auto l = world.create_entity("l"); l += components::transform(300, 0); auto& light = l += components::light(); light.color = green; l.add_standard_components(); } { const auto l = world.create_entity("l"); l += components::transform(600, 0); auto& light = l += components::light(); light.color = blue; l.add_standard_components(); } { const auto l = world.create_entity("l"); l += components::transform(900, 0); auto& light = l += components::light(); light.color = cyan; l.add_standard_components(); } { const auto l = world.create_entity("l"); l += components::transform(1200, 0); auto& light = l += components::light(); light.color = orange; l.add_standard_components(); } } for (int i = 0; i < num_characters; ++i) { const auto new_character = prefabs::create_character(world, vec2(i * 300.f, 0), vec2(1200, 800), typesafe_sprintf("player%x", i)); new_characters[i] = new_character; if (i == 0) { new_character.get<components::sentience>().health.value = 100; new_character.get<components::sentience>().health.maximum = 100; } if (i == 1) { new_character.get<components::attitude>().parties = party_category::RESISTANCE_CITIZEN; new_character.get<components::attitude>().hostile_parties = party_category::METROPOLIS_CITIZEN; new_character.get<components::attitude>().maximum_divergence_angle_before_shooting = 25; new_character.get<components::sentience>().minimum_danger_amount_to_evade = 20; new_character.get<components::sentience>().health.value = 300; new_character.get<components::sentience>().health.maximum = 300; //ingredients::standard_pathfinding_capability(new_character); //ingredients::soldier_intelligence(new_character); new_character.recalculate_basic_processing_categories(); } if (i == 2) { new_character.get<components::sentience>().health.value = 38; } if (i == 5) { new_character.get<components::attitude>().parties = party_category::METROPOLIS_CITIZEN; new_character.get<components::attitude>().hostile_parties = party_category::RESISTANCE_CITIZEN; new_character.get<components::attitude>().maximum_divergence_angle_before_shooting = 25; new_character.get<components::sentience>().minimum_danger_amount_to_evade = 20; new_character.get<components::sentience>().health.value = 300; new_character.get<components::sentience>().health.maximum = 300; //ingredients::standard_pathfinding_capability(new_character); //ingredients::soldier_intelligence(new_character); new_character.recalculate_basic_processing_categories(); } } if (character(0).alive()) { name_entity(character(0), entity_name::PERSON, L"Attacker"); } prefabs::create_sample_suppressor(world, vec2(300, -500)); const bool many_charges = false; const auto rifle = prefabs::create_sample_rifle(step, vec2(100, -500), prefabs::create_sample_magazine(step, vec2(100, -650), many_charges ? "10" : "0.3", prefabs::create_cyan_charge(world, vec2(0, 0), many_charges ? 1000 : 30))); const auto rifle2 = prefabs::create_sample_rifle(step, vec2(100, -500 + 50), prefabs::create_sample_magazine(step, vec2(100, -650), true ? "10" : "0.3", prefabs::create_cyan_charge(world, vec2(0, 0), true ? 1000 : 30))); prefabs::create_sample_rifle(step, vec2(100, -500 + 100)); prefabs::create_pistol(step, vec2(300, -500 + 50)); const auto pis2 = prefabs::create_pistol(step, vec2(300, 50), prefabs::create_sample_magazine(step, vec2(100, -650), "0.4", prefabs::create_green_charge(world, vec2(0, 0), 40))); const auto submachine = prefabs::create_submachine(step, vec2(500, -500 + 50), prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50))); prefabs::create_submachine(step, vec2(0, -1000), prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50))); prefabs::create_submachine(step, vec2(150, -1000 + 150), prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50))); prefabs::create_submachine(step, vec2(300, -1000 + 300), prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50))); prefabs::create_submachine(step, vec2(450, -1000 + 450), prefabs::create_sample_magazine(step, vec2(100 - 50, -650), many_charges ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), many_charges ? 500 : 50))); prefabs::create_sample_magazine(step, vec2(100 - 50, -650)); prefabs::create_sample_magazine(step, vec2(100 - 100, -650), "0.30"); //prefabs::create_pink_charge(world, vec2(100, 100)); //prefabs::create_pink_charge(world, vec2(100, -400)); //prefabs::create_pink_charge(world, vec2(150, -400)); //prefabs::create_pink_charge(world, vec2(200, -400)); prefabs::create_cyan_charge(world, vec2(150, -500)); prefabs::create_cyan_charge(world, vec2(200, -500)); prefabs::create_cyan_urban_machete(world, vec2(100, 100)); const auto second_machete = prefabs::create_cyan_urban_machete(world, vec2(0, 0)); const auto backpack = prefabs::create_sample_backpack(world, vec2(200, -650)); prefabs::create_sample_backpack(world, vec2(200, -750)); perform_transfer({ backpack, character(0)[slot_function::SHOULDER_SLOT] }, step); perform_transfer({ submachine, character(0)[slot_function::PRIMARY_HAND] }, step); perform_transfer({ rifle, character(0)[slot_function::SECONDARY_HAND] }, step); if (character(1).alive()) { name_entity(character(1), entity_name::PERSON, L"Enemy"); perform_transfer({ rifle2, character(1)[slot_function::PRIMARY_HAND] }, step); } if (character(2).alive()) { name_entity(character(2), entity_name::PERSON, L"Swordsman"); perform_transfer({ second_machete, character(2)[slot_function::PRIMARY_HAND] }, step); } if (character(3).alive()) { name_entity(character(3), entity_name::PERSON, L"Medic"); perform_transfer({ pis2, character(3)[slot_function::PRIMARY_HAND] }, step); } if (character(5).alive()) { const auto new_item = prefabs::create_submachine(step, vec2(0, -1000), prefabs::create_sample_magazine(step, vec2(100 - 50, -650), true ? "10" : "0.5", prefabs::create_pink_charge(world, vec2(0, 0), true ? 500 : 50))); perform_transfer({ new_item, character(5)[slot_function::PRIMARY_HAND] }, step); } //draw_bodies.push_back(crate2); //draw_bodies.push_back(new_characters[0]); //draw_bodies.push_back(backpack); //world.significant.meta.settings.pathfinding.draw_memorised_walls = 1; //world.significant.meta.settings.pathfinding.draw_undiscovered = 1; characters.assign(new_characters.begin(), new_characters.end()); // _controlfp(0, _EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID | _EM_DENORMAL); }