From beb87b546fac903ea68bf524764557fdb21cd058 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 9 Dec 2023 18:32:17 -0800 Subject: [PATCH] clean up map logging --- src/Map.cc | 27 ++++++++++++++------------- src/Map.hh | 10 +++++++--- src/ReceiveCommands.cc | 2 +- src/ReceiveSubcommands.cc | 13 ------------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/Map.cc b/src/Map.cc index 2a7b12d6..9c4f511c 100644 --- a/src/Map.cc +++ b/src/Map.cc @@ -131,6 +131,9 @@ string Map::Object::str(shared_ptr name_index) const { } } +Map::Map(uint32_t lobby_id) + : log(string_printf("[Lobby:%08" PRIX32 ":map] ", lobby_id), lobby_log.min_level) {} + void Map::clear() { this->objects.clear(); this->enemies.clear(); @@ -334,7 +337,7 @@ void Map::add_enemy( break; case 0x0065: // TObjEnePanarms if ((e.num_children != 0) && (e.num_children != 2)) { - static_game_data_log.warning("PAN_ARMS has an unusual num_children (0x%hX)", e.num_children.load()); + this->log.warning("PAN_ARMS has an unusual num_children (0x%hX)", e.num_children.load()); } default_num_children = -1; // Skip adding children (because we do it here) add(EnemyType::PAN_ARMS); @@ -367,7 +370,7 @@ void Map::add_enemy( break; case 0x00A1: // TObjEneRe4Sorcerer if ((e.num_children != 0) && (e.num_children != 2)) { - static_game_data_log.warning("CHAOS_SORCERER has an unusual num_children (0x%hX)", e.num_children.load()); + this->log.warning("CHAOS_SORCERER has an unusual num_children (0x%hX)", e.num_children.load()); } default_num_children = -1; // Skip adding children (because we do it here) add(EnemyType::CHAOS_SORCERER); @@ -410,7 +413,7 @@ void Map::add_enemy( break; case 0x00C1: // TBoss2DeRolLe if ((e.num_children != 0) && (e.num_children != 0x13)) { - static_game_data_log.warning("DE_ROL_LE has an unusual num_children (0x%hX)", e.num_children.load()); + this->log.warning("DE_ROL_LE has an unusual num_children (0x%hX)", e.num_children.load()); } default_num_children = -1; // Skip adding children (because we do it here) add(EnemyType::DE_ROL_LE); @@ -423,7 +426,7 @@ void Map::add_enemy( break; case 0x00C2: // TBoss3Volopt if ((e.num_children != 0) && (e.num_children != 0x23)) { - static_game_data_log.warning("VOL_OPT has an unusual num_children (0x%hX)", e.num_children.load()); + this->log.warning("VOL_OPT has an unusual num_children (0x%hX)", e.num_children.load()); } default_num_children = -1; // Skip adding children (because we do it here) add(EnemyType::VOL_OPT_1); @@ -445,7 +448,7 @@ void Map::add_enemy( break; case 0x00C8: // TBoss4DarkFalz if ((e.num_children != 0) && (e.num_children != 0x200)) { - static_game_data_log.warning("DARK_FALZ has an unusual num_children (0x%hX)", e.num_children.load()); + this->log.warning("DARK_FALZ has an unusual num_children (0x%hX)", e.num_children.load()); } default_num_children = -1; // Skip adding children (because we do it here) if (difficulty) { @@ -588,14 +591,14 @@ void Map::add_enemy( case 0x00C7: // TBoss3VoloptHiraisin case 0x0118: add(EnemyType::UNKNOWN); - static_game_data_log.warning( + this->log.warning( "(Entry %zu, offset %zX in file) Unknown enemy type %04hX", index, index * sizeof(EnemyEntry), e.base_type.load()); break; default: add(EnemyType::UNKNOWN); - static_game_data_log.warning( + this->log.warning( "(Entry %zu, offset %zX in file) Invalid enemy type %04hX", index, index * sizeof(EnemyEntry), e.base_type.load()); break; @@ -729,7 +732,7 @@ void Map::add_random_enemies_from_map_data( definitions_header.weight_entry_count * sizeof(RandomEnemyWeight)); for (size_t wave_entry_index = 0; wave_entry_index < wave_events_header.entry_count; wave_entry_index++) { - auto entry_log = static_game_data_log.sub(string_printf("(Entry %zu/%" PRIu32 ") ", wave_entry_index, wave_events_header.entry_count.load())); + auto entry_log = this->log.sub(string_printf("(Entry %zu/%" PRIu32 ") ", wave_entry_index, wave_events_header.entry_count.load())); const auto& entry = wave_events_segment_r.get(); size_t remaining_waves = random_state->rand_int_biased(1, entry.max_waves); @@ -841,8 +844,6 @@ vector Map::collect_quest_map_data_sections(const void while (!r.eof()) { size_t header_offset = r.where(); const auto& header = r.get(); - static_game_data_log.info("(DAT:%08zX) type=%08" PRIX32 " floor=%08" PRIX32 " data_size=%08" PRIX32, - header_offset, header.le_type.load(), header.floor.load(), header.data_size.load()); if (header.type() == SectionHeader::Type::END && header.section_size == 0) { break; @@ -918,7 +919,7 @@ void Map::add_enemies_and_objects_from_quest_data( if (header.data_size % sizeof(ObjectEntry)) { throw runtime_error("quest layout object section size is not a multiple of object entry size"); } - static_game_data_log.info("(Floor %02zX) Adding objects", floor); + this->log.info("(Floor %02zX) Adding objects", floor); this->add_objects_from_map_data(floor, r.pgetv(floor_sections.objects + sizeof(header), header.data_size), header.data_size); } @@ -927,7 +928,7 @@ void Map::add_enemies_and_objects_from_quest_data( if (header.data_size % sizeof(EnemyEntry)) { throw runtime_error("quest layout enemy section size is not a multiple of enemy entry size"); } - static_game_data_log.info("(Floor %02zX) Adding enemies", floor); + this->log.info("(Floor %02zX) Adding enemies", floor); this->add_enemies_from_map_data( episode, difficulty, @@ -940,7 +941,7 @@ void Map::add_enemies_and_objects_from_quest_data( } else if ((floor_sections.wave_events != 0xFFFFFFFF) && (floor_sections.random_enemy_locations != 0xFFFFFFFF) && (floor_sections.random_enemy_definitions != 0xFFFFFFFF)) { - static_game_data_log.info("(Floor %02zX) Adding random enemies", floor); + this->log.info("(Floor %02zX) Adding random enemies", floor); const auto& wave_events_header = r.pget(floor_sections.wave_events); const auto& random_enemy_locations_header = r.pget(floor_sections.random_enemy_locations); const auto& random_enemy_definitions_header = r.pget(floor_sections.random_enemy_definitions); diff --git a/src/Map.hh b/src/Map.hh index 6a4d2737..1137550d 100644 --- a/src/Map.hh +++ b/src/Map.hh @@ -253,9 +253,8 @@ struct Map { void generate_shuffled_location_table(const Map::RandomEnemyLocationsHeader& header, StringReader r, uint16_t section); }; - std::vector objects; - std::vector enemies; - std::vector rare_enemy_indexes; + explicit Map(uint32_t lobby_id); + ~Map() = default; void clear(); @@ -308,6 +307,11 @@ struct Map { std::shared_ptr rare_rates = Map::DEFAULT_RARE_ENEMIES); static std::string disassemble_quest_data(const void* data, size_t size); + + PrefixedLogger log; + std::vector objects; + std::vector enemies; + std::vector rare_enemy_indexes; }; // TODO: This class is currently unused. It would be nice if we could use this diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index eb9a1ebf..871d6632 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -4000,7 +4000,7 @@ shared_ptr create_game_generic( } if (game->base_version == Version::BB_V4) { - game->map = make_shared(); + game->map = make_shared(game->lobby_id); for (size_t floor = 0; floor < 0x10; floor++) { c->log.info("[Map/%zu] Using variations %" PRIX32 ", %" PRIX32, floor, game->variations[floor * 2].load(), game->variations[floor * 2 + 1].load()); diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index dd5336ac..f19a3ab3 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -1110,10 +1110,6 @@ static void on_box_or_enemy_item_drop_t(shared_ptr c, uint8_t command, u auto name = s->describe_item(c->version(), item, false); l->log.info("Player %hhu (leader) created floor item %08" PRIX32 " (%s) at %hhu:(%g, %g)", l->leader_id, item.id.load(), name.c_str(), cmd.item.floor, cmd.item.x.load(), cmd.item.z.load()); - if (c->config.check_flag(Client::Flag::DEBUG_ENABLED)) { - string name = s->describe_item(c->version(), item, true); - send_text_message_printf(c, "$C5DROP %08" PRIX32 "\n%s", item.id.load(), name.c_str()); - } } for (auto& lc : l->clients) { @@ -1188,10 +1184,6 @@ static void on_pick_up_item(shared_ptr c, uint8_t command, uint8_t flag, auto name = s->describe_item(c->version(), item, false); l->log.warning("Player %hu attempted to pick up %08" PRIX32 " (%s) but cannot (%s); ignoring command", cmd.header.client_id.load(), cmd.item_id.load(), name.c_str(), e.what()); - if (c->config.check_flag(Client::Flag::DEBUG_ENABLED)) { - auto name = s->describe_item(c->version(), item, true); - send_text_message_printf(c, "$C5PICK/F %08" PRIX32 "\n%s\n$C4%s", cmd.item_id.load(), name.c_str(), e.what()); - } return; } @@ -2244,11 +2236,6 @@ static void on_destroy_ground_item(shared_ptr c, uint8_t command, uint8_ auto name = s->describe_item(c->version(), item, false); l->log.info("Player %hhu destroyed floor item %08" PRIX32 " (%s)", c->lobby_client_id, cmd.item_id.load(), name.c_str()); - if (c->config.check_flag(Client::Flag::DEBUG_ENABLED)) { - string name = s->describe_item(c->version(), item, true); - send_text_message_printf(c, "$C5DESTROY/GND %08" PRIX32 "\n%s", - cmd.item_id.load(), name.c_str()); - } forward_subcommand(c, command, flag, data, size); } }