Explorar o código

Implemented itemmoveinfov5.txt generator (#7457)

Jittapan Pluemsumran %!s(int64=2) %!d(string=hai) anos
pai
achega
bc4934373d
Modificáronse 3 ficheiros con 36 adicións e 0 borrados
  1. 29 0
      src/map/itemdb.cpp
  2. 2 0
      src/map/itemdb.hpp
  3. 5 0
      src/map/map.cpp

+ 29 - 0
src/map/itemdb.cpp

@@ -3,7 +3,10 @@
 
 #include "itemdb.hpp"
 
+#include <chrono>
+#include <fstream>
 #include <iostream>
+#include <map>
 #include <stdlib.h>
 #include <math.h>
 #include <unordered_map>
@@ -4595,6 +4598,32 @@ int item_data::inventorySlotNeeded(int quantity)
 	return (this->flag.guid || !this->isStackable()) ? quantity : 1;
 }
 
+void itemdb_gen_itemmoveinfo()
+{
+	ShowInfo("itemdb_gen_itemmoveinfo: Generating itemmoveinfov5.txt.\n");
+	auto starttime = std::chrono::system_clock::now();
+	auto os = std::ofstream("./generated/clientside/data/itemmoveinfov5.txt", std::ios::trunc);
+	std::map<t_itemid, std::shared_ptr<item_data>> sorted_itemdb(item_db.begin(), item_db.end());
+
+	os << "// ItemID,\tDrop,\tVending,\tStorage,\tCart,\tNpc Sale,\tMail,\tAuction,\tGuildStorage\n";
+	os << "// This format does not accept blank lines. Be careful.\n";
+
+	item_data tmp_id{};
+	for (auto it = sorted_itemdb.begin(); it != sorted_itemdb.end(); ++it) {
+		if (it->second->type == IT_UNKNOWN)
+			continue;
+		if (memcmp(&it->second->flag.trade_restriction, &tmp_id.flag.trade_restriction, sizeof(tmp_id.flag.trade_restriction)) == 0)
+			continue;
+
+		os << it->first << "\t" << it->second->flag.trade_restriction.drop << "\t" << it->second->flag.trade_restriction.trade << "\t" << it->second->flag.trade_restriction.storage << "\t" << it->second->flag.trade_restriction.cart << "\t" << it->second->flag.trade_restriction.sell << "\t" << it->second->flag.trade_restriction.mail << "\t" << it->second->flag.trade_restriction.auction << "\t" << it->second->flag.trade_restriction.guild_storage << "\t// " << it->second->name << "\n";
+	}
+
+	os.close();
+
+	auto currenttime = std::chrono::system_clock::now();
+	ShowInfo("itemdb_gen_itemmoveinfo: Done generating itemmoveinfov5.txt. The process took %lldms\n", std::chrono::duration_cast<std::chrono::milliseconds>(currenttime - starttime).count());
+}
+
 /**
 * Reload Item DB
 */

+ 2 - 0
src/map/itemdb.hpp

@@ -2326,6 +2326,8 @@ bool itemdb_isNoEquip(struct item_data *id, uint16 m);
 
 bool itemdb_parse_roulette_db(void);
 
+void itemdb_gen_itemmoveinfo();
+
 void itemdb_reload(void);
 
 void do_final_itemdb(void);

+ 5 - 0
src/map/map.cpp

@@ -191,6 +191,7 @@ int enable_grf = 0;	//To enable/disable reading maps from GRF files, bypassing m
 #ifdef MAP_GENERATOR
 struct s_generator_options {
 	bool navi;
+	bool itemmoveinfo;
 } gen_options;
 #endif
 
@@ -5103,6 +5104,8 @@ int mapgenerator_get_options(int argc, char** argv) {
 
 			if (strcmp(arg, "generate-navi") == 0) {
 				gen_options.navi = true;
+			} else if (strcmp(arg, "generate-itemmoveinfo") == 0) {
+				gen_options.itemmoveinfo = true;
 			} else {
 				// pass through to default get_options
 				continue;
@@ -5292,6 +5295,8 @@ int do_init(int argc, char *argv[])
 	// depending on gen_options, generate the correct things
 	if (gen_options.navi)
 		navi_create_lists();
+	if (gen_options.itemmoveinfo)
+		itemdb_gen_itemmoveinfo();
 	runflag = CORE_ST_STOP;
 #endif