add --multiply option to convert-rare-item-set

This commit is contained in:
Martin Michelsen
2024-03-07 22:51:32 -08:00
parent 70c57e7727
commit 8a7e19757a
3 changed files with 26 additions and 2 deletions
+9 -2
View File
@@ -1605,7 +1605,7 @@ Action a_cat_client(
Action a_convert_rare_item_set(
"convert-rare-item-set", "\
convert-rare-item-set INPUT-FILENAME [OUTPUT-FILENAME]\n\
convert-rare-item-set INPUT-FILENAME [OUTPUT-FILENAME] [OPTIONS]\n\
If OUTPUT-FILENAME is not given, print the contents of a rare item table in\n\
a human-readable format. Otherwise, convert the input rare item set to a\n\
different format and write it to OUTPUT-FILENAME. Both filenames must end\n\
@@ -1614,10 +1614,13 @@ Action a_convert_rare_item_set(
.gsl (PSO BB little-endian GSL archive)\n\
.gslb (PSO GC big-endian GSL archive)\n\
.afs (PSO V2 little-endian AFS archive)\n\
.rel (Schtserv rare table; cannot be used in output filename)\n",
.rel (Schtserv rare table; cannot be used in output filename)\n\
If the --multiply=X option is given, multiplies all drop rates by X (given\n\
as a decimal value).\n",
+[](Arguments& args) {
auto version = get_cli_version(args);
double rate_factor = args.get<double>("multiply");
auto s = make_shared<ServerState>("system/config.json");
s->load_config_early();
s->load_patch_indexes(false);
@@ -1646,6 +1649,10 @@ Action a_convert_rare_item_set(
throw runtime_error("cannot determine input format; use a filename ending with .json, .gsl, .gslb, .afs, or .rel");
}
if (rate_factor != 1.0) {
rs->multiply_all_rates(rate_factor);
}
string output_filename = args.get<string>(2, false);
if (output_filename.empty() || (output_filename == "-")) {
rs->print_all_collections(stdout, s->item_name_index(version));
+15
View File
@@ -509,6 +509,21 @@ JSON RareItemSet::json(shared_ptr<const ItemNameIndex> name_index) const {
return modes_dict;
}
void RareItemSet::multiply_all_rates(double factor) {
auto multiply_rates_vec = +[](vector<vector<ExpandedDrop>>& vec, double factor) -> void {
for (auto& vec_it : vec) {
for (auto& z_it : vec_it) {
uint64_t new_probability = z_it.probability * factor;
z_it.probability = min<uint64_t>(new_probability, 0xFFFFFFFF);
}
}
};
for (auto& coll_it : this->collections) {
multiply_rates_vec(coll_it.second.rt_index_to_specs, factor);
multiply_rates_vec(coll_it.second.box_area_to_specs, factor);
}
}
void RareItemSet::print_collection(
FILE* stream,
GameMode mode,
+2
View File
@@ -39,6 +39,8 @@ public:
std::string serialize_gsl(bool big_endian) const;
JSON json(std::shared_ptr<const ItemNameIndex> name_index = nullptr) const;
void multiply_all_rates(double factor);
void print_collection(
FILE* stream,
GameMode mode,