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); }
void Functions::randomName(Aurora::NWScript::FunctionContext &ctx) { // Use 'names.LTR' for generic names Aurora::LTRFile namesFile("names"); ctx.getReturn() = namesFile.generateRandomName(14); }
int seqNoise::writeOutput(string fastaFileName, string namesFileName, string uMapFileName, vector<int> finalTau, vector<int> centroids, vector<int> otuData, vector<string> sequences, vector<string> uniqueNames, vector<string> redundantNames, vector<int> seqFreq, vector<double>& distances){ try { int numOTUs = finalTau.size(); int numSeqs = uniqueNames.size(); ofstream fastaFile(fastaFileName.c_str()); ofstream namesFile(namesFileName.c_str()); ofstream uMapFile(uMapFileName.c_str()); vector<int> maxSequenceAbund(numOTUs, 0); vector<int> maxSequenceIndex(numOTUs, 0); for(int i=0;i<numSeqs;i++){ if (m->control_pressed) { return 0; } if(maxSequenceAbund[otuData[i]] < seqFreq[i]){ maxSequenceAbund[otuData[i]] = seqFreq[i]; maxSequenceIndex[otuData[i]] = i; } } int count = 1; for(int i=0;i<numOTUs;i++){ if (m->control_pressed) { return 0; } if(finalTau[i] > 0){ if(maxSequenceIndex[i] != centroids[i] && distances[maxSequenceIndex[i]*numSeqs + centroids[i]] == 0){ // cout << uniqueNames[centroids[i]] << '\t' << uniqueNames[maxSequenceIndex[i]] << '\t' << count << endl; centroids[i] = maxSequenceIndex[i]; } int index = centroids[i]; fastaFile << '>' << uniqueNames[index] << endl << sequences[index] << endl; namesFile << uniqueNames[index] << '\t'; string refSeq = sequences[index]; string redundantSeqs = redundantNames[index];; vector<freqData> frequencyData; for(int j=0;j<numSeqs;j++){ if(otuData[j] == i && j != index){ frequencyData.push_back(freqData(j, seqFreq[j])); } } sort(frequencyData.rbegin(), frequencyData.rend()); string refDegap = degapSeq(refSeq); vector<int> rUnalign = convertSeq(refDegap); uMapFile << "ideal_seq_" << count << '\t' << finalTau[i] << endl; uMapFile << uniqueNames[index] << '\t' << seqFreq[index] << "\t0\t" << refDegap << endl; for(int j=0;j<frequencyData.size();j++){ if (m->control_pressed) { return 0; } redundantSeqs += ',' + redundantNames[frequencyData[j].index]; uMapFile << uniqueNames[frequencyData[j].index] << '\t' << seqFreq[frequencyData[j].index] << '\t'; string querySeq = sequences[frequencyData[j].index]; string queryDegap = degapSeq(querySeq); vector<int> qUnalign = convertSeq(queryDegap); int udiffs = countDiffs(qUnalign, rUnalign); uMapFile << udiffs << '\t' << queryDegap << endl; } uMapFile << endl; namesFile << redundantSeqs << endl; count++; } } fastaFile.close(); namesFile.close(); uMapFile.close(); return 0; } catch(exception& e) { m->errorOut(e, "seqNoise", "writeOutput"); exit(1); } }