unsigned int CCategoryHandler::GetCategories(std::string names) { unsigned int ret = 0; StringToLowerInPlace(names); // split on ' ' std::stringstream namesStream(names); std::string name; while (std::getline(namesStream, name, ' ')) { if (!name.empty()) { ret |= GetCategory(name); } } return ret; }
void HumanListModel::add(const QString profession, float x, float y, float z) { int high = 5; int low = 1; // Set the options QBitArray options(52+12, false); for (int i=2; i<13; i++) { options[i] = true; // These settings seem to be on by default. } options[15] = true; // Set default sleep settings. options[18] = true; // Randomly choose male or female (40 percent chance of female: the in-game // chance is about 33 percent, but that seems a little low somehow.) high = 100; low = 0; bool isFemale = ((qrand() % ((high + 1) - low) + low) > 60) ? true : false; // Choose the proper names file for male/female units, and set the default // name in case we can't get a random name from the names file. QString namesFilename; QString randomlyChosenName; if (isFemale) { namesFilename = "/female_names.txt"; randomlyChosenName = "Alissa"; } else { namesFilename = "/male_names.txt"; randomlyChosenName = "James"; } // Set Gender options[37] = isFemale; // Pick a name from the list of names. If you can't find the file, the default is okay. QFile namesFile(QCoreApplication::applicationDirPath() + namesFilename); if (namesFile.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream namesStream(&namesFile); QString namesString = namesStream.readAll(); QStringList names = namesString.split(QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"), QString::SkipEmptyParts); // Pick a random name randomlyChosenName = names.at(qrand() % names.size()); } QList<int> inventoryPreferences; for(int i=0; i<20; i++) { inventoryPreferences.append(0); } QList<int> inventoryItems; QList<int> spareInventory; QList<float> patrolSetpoints; QList<int> professionEXP; for(int i=0; i<20; i++) { professionEXP.append(0); } // Build the Human and add it to the list. // Randomly choose the expert level, used for the chosen profession. int expertLevel = qrand() % ((8 + 1) - 6) + 6; high = 5; low = 1; appendRow(new Human( profession, x, y, z, randomlyChosenName + " Drone", // The level is raised to expert level if that's this units profession. (profession.compare("Archer"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Blacksmith"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Builder"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Carpenter"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Engineer"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Farmer"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Fisherman"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Forager"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Infantry"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Miner"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Stone Mason"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Wood Chopper"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Tailor"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Trader"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Herder"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Adventurer"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Unknown1"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Unknown2"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Unknown3"))?qrand() % ((high + 1) - low) + low : expertLevel, (profession.compare("Unknown4"))?qrand() % ((high + 1) - low) + low : expertLevel, 1, // experience false, false, false, false, false, false, 0.0, // rotation 127,127,127,127,127, // equip 100, // health options, 10.0f, 1.0f, 1.50f, 0.0f, // time to eat, marole, fatigue, hunger // Inventory data inventoryPreferences, inventoryItems, spareInventory, // Patrol data patrolSetpoints, 0, "NoUnit", // person they're guarding. professionEXP, // There may be a desire to increase the max weight, perhaps when // giving a unit coffee. 10 // max weight (it seems 10 is the default) ) ); qDebug() << "Added" << randomlyChosenName << "the" << qPrintable((isFemale)?"female":"male") << qPrintable(profession); }