[10046] Store guids instead slot data for trade items.
[getmangos.git] / contrib / vmap_assembler / vmap_assembler.cpp
blob7da98b59982f4a4ebe74d33b5d9225fe7bdb33fe
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string>
5 #include "TileAssembler.h"
7 //=======================================================
8 // remove last return or LF and tailing SPACE
9 // remove all char after a #
11 void chompAndTrim(std::string& str)
13 for(unsigned int i=0;i<str.length(); ++i) {
14 char lc = str[i];
15 if(lc == '#') {
16 str = str.substr(0,i);
17 break;
21 while(str.length() >0) {
22 char lc = str[str.length()-1];
23 if(lc == '\r' || lc == '\n' || lc == ' ') {
24 str = str.substr(0,str.length()-1);
25 } else {
26 break;
31 //=======================================================
32 /**
33 This callback method is called for each model found in the dir file.
34 return true if it should be included in the vmap
36 bool modelNameFilter(char *pName)
38 #if 0
39 bool result;
40 result = !Wildcard::wildcardfit("*bush[0-9]*", pName);
41 if(result) result = !Wildcard::wildcardfit("*shrub[0-9]*", pName);
42 if(result) result = !Wildcard::wildcardfit("*_Bushes_*", pName);
43 if(result) result = !Wildcard::wildcardfit("*_Bush_*", pName);
44 if(!result) {
45 printf("%s",pName);
47 #endif
48 return true;
51 //=======================================================
52 /**
53 File contains map names that should be split into tiles
54 A '#' at the beginning of a line defines a comment
57 bool readConfigFile(char *pConffile, VMAP::TileAssembler* pTa)
59 bool result = false;
60 char buffer[501];
61 FILE *cf = fopen(pConffile, "rb");
62 if(cf) {
63 while(fgets(buffer, 500, cf)) {
64 std::string name = std::string(buffer);
65 size_t pos = name.find_first_not_of(' ');
66 name = name.substr(pos);
67 chompAndTrim(name); // just to be sure
68 if(name[0] != '#' && name.size() >0) { // comment?
69 unsigned int mapId = atoi(name.c_str());
70 pTa->addWorldAreaMapId(mapId);
73 fclose(cf);
74 result = true;
76 return(result);
78 //=======================================================
79 int main(int argc, char* argv[])
81 if(argc != 3 && argc != 4)
83 printf("\nusage: %s <raw data dir> <vmap dest dir> [config file name]\n", argv[0]);
84 return 1;
87 char *src = argv[1];
88 char *dest = argv[2];
89 char *conffile = NULL;
90 if(argc >= 4)
91 conffile = argv[3];
93 VMAP::TileAssembler* ta = new VMAP::TileAssembler(std::string(src), std::string(dest));
94 ta->setModelNameFilterMethod(modelNameFilter);
97 All the names in the list are considered to be world maps or huge instances.
98 These maps will be spilt into tiles in the vmap assemble process
100 if(conffile != NULL)
102 if(!readConfigFile(conffile, ta))
104 printf("Can not open file config file: %s\n", conffile);
105 delete ta;
106 return 1;
110 if(!ta->convertWorld())
112 printf("exit with errors\n");
113 delete ta;
114 return 1;
117 delete ta;
118 printf("Ok, all done\n");
119 return 0;