/******************************************* * HUFFMAN * Driver program to exercise the huffman generation code *******************************************/ void huffman() { // Declare variables PAIR temp; BNODE * node; BNODEVECTOR data; STRINGVECTOR code; // Prompt the user for the file name. string filename; getFile(filename); // read the file readFile(filename, temp, node, data); // sort for the tree sort(data.begin(), data.end(), compareFrequencies); // Create the tree createtree(data); // Determine the path of the nodes on the tree encode(data[0], "", code); // sort the tree sort(code.begin(), code.end(), compareStrings); // Display the path display(code); return; }
int CraftManager::GetIntParam(const STRINGVECTOR &strVector, size_t index) { if(index >= strVector.size()) return 0; return atoi(strVector[index].c_str()); }
void CraftManager::GenerateOutputs(const CraftRecipe *recipe, std::vector<CraftInputSlot> &inputItems, std::vector<CraftInputSlot> &outputItems) { for(size_t i = 0; i < recipe->mActions.size(); i++) { STRINGVECTOR args; Util::Split(recipe->mActions[i], ",", args); if(args.size() == 0) continue; if(args[0].compare("giveid") == 0) { int itemID = GetIntParam(args, 1); int itemCount = GetIntParam(args, 2); if(itemCount <= 0) itemCount = 1; outputItems.push_back(CraftInputSlot(0, itemID, itemCount, NULL)); } else if(args[0].compare("giveidxmult") == 0) { int itemID = GetIntParam(args, 1); int checkIndex = GetIntParam(args, 2); int mult = GetIntParam(args, 3); if(mult < 1) mult = 1; if(checkIndex < 0 || checkIndex >= inputItems.size()) continue; int count = inputItems[checkIndex].mStackCount * mult; outputItems.push_back(CraftInputSlot(0, itemID, count, NULL)); } else if(args[0].compare("giveidxdiv") == 0) { int itemID = GetIntParam(args, 1); int checkIndex = GetIntParam(args, 2); int div = GetIntParam(args, 3); if(div < 1) div = 1; if(checkIndex < 0 || checkIndex >= inputItems.size()) continue; int count = inputItems[checkIndex].mStackCount / div; if(count > 0) outputItems.push_back(CraftInputSlot(0, itemID, count, NULL)); } else { g_Logs.server->error("CraftManager::CheckCondition unknown action [%v]", args[0].c_str()); } } }
/********************************************************************* * ENCODE * Determines the path for a given node on the tree. If it goes left * then it is assigned a 0. If it goes right then it is assigned a 1. *********************************************************************/ void encode(BNODE * newNode, string newString, STRINGVECTOR & code) { if(newNode == NULL) return; encode(newNode->pLeft, newString + "0", code); encode(newNode->pRight, newString + "1", code); if(newNode->pLeft == NULL && newNode->pRight == NULL) code.push_back(STRINGPAIR(newNode->data.first, newString)); }
void TransferWallpapers() { STRINGVECTOR wallpaperRepository; LoadWallpaperRepository(&wallpaperRepository); int paramLength = 1; int size = wallpaperRepository.size(); for (int i = 0; i < size; ++i) { wchar_t *str = wallpaperRepository[i]; paramLength += wcslen(str) + 1; } if (paramLength > 1) { wchar_t *param = new wchar_t[paramLength]; memset(param, 0, paramLength * sizeof(wchar_t)); wchar_t *tmp = param; for (int i = 0; i < size; ++i) { wchar_t *str = wallpaperRepository[i]; memcpy(tmp, str, (wcslen(str) + 1) * sizeof(wchar_t)); tmp += wcslen(str) + 1; } HKEY hKey = NULL; RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Shell\\WallpaperSets", 0, 0, &hKey); if (hKey) { RegSetValueEx(hKey, L"OEMWallpapers", 0, REG_MULTI_SZ, (LPBYTE)param, paramLength * sizeof(wchar_t)); RegCloseKey(hKey); } delete[] param; } for (STRINGVECTOR::iterator iterator = wallpaperRepository.begin(); iterator != wallpaperRepository.end(); ++iterator) { delete(*iterator); } wallpaperRepository.erase(wallpaperRepository.begin(), wallpaperRepository.end()); }
/********************************************************************** * DISPLAY * Display the path to a node **********************************************************************/ void display(const STRINGVECTOR code) { for(int i = 0; i < code.size(); i++) cout << code[i].first << " = " << code[i].second << endl; }
bool CraftManager::CheckCondition(const STRINGVECTOR &conditions, const std::vector<CraftInputSlot> &inputItems) { size_t passed = 0; for(size_t i = 0; i < conditions.size(); i++) { STRINGVECTOR args; Util::Split(conditions[i], ",", args); if(args.size() <= 2) continue; int itemIndex = GetIntParam(args, 0); if(itemIndex < 0 || itemIndex >= (int)inputItems.size()) return false; const char *op = GetStringParam(args, 1); if(op == NULL) return false; if(strcmp(op, "requireid") == 0) { int itemID = GetIntParam(args, 2); int itemCount = GetIntParam(args, 3); if(inputItems[itemIndex].mID != itemID) return false; if((itemCount >= 0) && (inputItems[itemIndex].mStackCount != itemCount)) return false; passed++; } else if(strcmp(op, "requireidxmult") == 0) { int itemID = GetIntParam(args, 2); int checkIndex = GetIntParam(args, 3); int mult = GetIntParam(args, 4); if(mult < 1) mult = 1; if(inputItems[itemIndex].mID != itemID) return false; if(checkIndex < 0 || checkIndex >= (int)inputItems.size()) return false; if(inputItems[itemIndex].mStackCount != inputItems[checkIndex].mStackCount * mult) return false; passed++; } else if(strcmp(op, "requireidmult") == 0) { int itemID = GetIntParam(args, 2); int itemCount = GetIntParam(args, 3); if(inputItems[itemIndex].mID != itemID) return false; if((inputItems[itemIndex].mStackCount % itemCount) != 0) return false; passed++; } else if(strcmp(op, "itemtype") == 0) { int typeVal = GetIntParam(args, 2); if(inputItems[itemIndex].mItemDef->mType != typeVal) return false; passed++; } else if(strcmp(op, "quality") == 0) { int quality = GetIntParam(args, 2); if(inputItems[itemIndex].mItemDef->mQualityLevel != quality) return false; passed++; } else if(strcmp(op, "cmp") == 0) { int leftValue = GetProperty(inputItems[itemIndex], GetStringParam(args, 2)); if(leftValue == INVALID_PROPERTY) return false; int comparator = GetComparator(GetStringParam(args, 3)); int rightValue = GetIntParam(args, 4); if(Compare(leftValue, comparator, rightValue) == false) return false; passed++; } else { g_Logs.server->error("CraftManager::CheckCondition unknown condition [%v]", op); } } if(passed == conditions.size()) return true; return false; }