double uniondist(double mean) { if (getRandNum(100) < 50) return (mean*0.8 + mean*0.2*getRandNum(20) / 20); else return (-mean*0.8 - mean*0.2*getRandNum(20) / 20); }
int tss_populate_basebandvals(plist_t tssreq, plist_t tssparameters, int64_t BbGoldCertId){ plist_t parameters = plist_new_dict(); char bbnonce[noncelen+1]; char bbsnum[5]; int64_t BbChipID = 0; getRandNum(bbnonce, noncelen, 256); getRandNum(bbsnum, 4, 256); int n=0; for (int i=1; i<7; i++) BbChipID += (arc4random() % 10) * pow(10, ++n); plist_dict_set_item(parameters, "BbNonce", plist_new_data(bbnonce, noncelen)); plist_dict_set_item(parameters, "BbChipID", plist_new_uint(BbChipID)); plist_dict_set_item(parameters, "BbGoldCertId", plist_new_uint(BbGoldCertId)); plist_dict_set_item(parameters, "BbSNUM", plist_new_data(bbsnum, 4)); /* BasebandFirmware */ plist_t BasebandFirmware = plist_access_path(tssparameters, 2, "Manifest", "BasebandFirmware"); if (!BasebandFirmware || plist_get_node_type(BasebandFirmware) != PLIST_DICT) { error("ERROR: Unable to get BasebandFirmware node\n"); return -1; } plist_t bbfwdict = plist_copy(BasebandFirmware); BasebandFirmware = NULL; if (plist_dict_get_item(bbfwdict, "Info")) { plist_dict_remove_item(bbfwdict, "Info"); } plist_dict_set_item(tssreq, "BasebandFirmware", bbfwdict); tss_request_add_baseband_tags(tssreq, parameters, NULL); return 0; }
AbstractMessage *NoLocationMessage::creatMessage(QStringList &list) { //在数据库中找点 QMap<QString, AbstractMessage *>::iterator itr; if (list.at(0) != "N") { itr = messageDB.find(list.at(0)); } else { itr = messageDB.find("[Me]"); } if (itr != messageDB.end()) { LocationMessage *message = (LocationMessage *) itr.value(); message->changeMessageType(Message::NOLOCATION); return message; } //为点找一个随机位置信息 QString s; if (list.at(0) == "N") { s = "V" + QString(" 0000 ") + QString::number(getRandNum()) + " N " + QString::number(getRandNum()) + " E " + " 998" + " 180"; } else { s = list.at(0) + " 99999" + " V" + " 0000 " + QString::number(getRandNum()) + " N " + QString::number(getRandNum()) + " E " + " 999" + " 90"; } QStringList randList(s.split(" ", QString::SkipEmptyParts)); AbstractMessage *newMessage; if (randList.at(0) == "V") { newMessage = new SelfLocationMessage(randList); messageDB.insert("[Me]", newMessage); } else { newMessage = new DistanceLocationMessage(randList); messageDB.insert(list.at(0), newMessage); } ((LocationMessage *)newMessage)->changeMessageType(Message::NOLOCATION); return newMessage; }
double getRandExp(double lambda) { int acc=1234567; double prob = ((double)getRandNum(acc)) / acc; double a = -log(1 - prob) / lambda; return a; }
void ServantBerserkerFlail::subHP(int hp, DamageType dt) { bool noDamage = false; int r = getRandNum(); if (((ascension == 1 && r <= getLuk()) || (ascension == 2 && r <= getLuk() * 1.5)) && (dt == D_STR || dt == D_MAG)) { noDamage = true; log->addToEventLog(getFullName() + " deflected the attack and took no damage! Spin to Win!"); } if (!noDamage) { currHP -= hp; int mhp = getMaxHP(); if (currHP > mhp) currHP = mhp; else if (currHP <= 0) { currHP = 0; remAllDebuffs(false); } } }
int tss_populate_random(plist_t tssreq, int is64bit, uint64_t ecid){ char nonce[noncelen+1]; char sep_nonce[noncelen+1]; int n=0; if (!ecid) for (int i=0; i<16; i++) ecid += (arc4random() % 10) * pow(10, n++); getRandNum(nonce, noncelen, 256); getRandNum(sep_nonce, noncelen, 256); nonce[noncelen] = sep_nonce[noncelen] = 0; debug("[TSSR] ecid=%llu\n",ecid); debug("[TSSR] nonce=%s\n",nonce); debug("[TSSR] sepnonce=%s\n",sep_nonce); return tss_populate_devicevals(tssreq, ecid, nonce, noncelen, sep_nonce, noncelen, is64bit); }
void generateW(double * x, double mean, int len, double demand_jump_factor) { std::default_random_engine generator; double sigma = sqrt(mean)*demand_jump_factor; double sigmaJump = mean / 4; std::normal_distribution<double> jumpdistribution(0, sigmaJump); x[0] = mean; double curP = probabilityDensity(x[0], mean, sigma); for (int i = 1; i < len; i++) { x[i] = x[i - 1]; double nextX = x[i - 1]; if (getRandNum(100) <= demand_jump_factor) nextX += uniondist(mean); else nextX +=jumpdistribution(generator); double nextP = probabilityDensity(nextX, mean, sigma); if (nextP >= curP) { curP = nextP; x[i] = nextX; } else { double u = (0.0+abso(getRandNum(10000))) / 10000; if (u < nextP / curP) { curP = nextP; x[i] = nextX; } } if (x[i] < 0) { x[i] = 0; curP = probabilityDensity(0, mean, sigma); } if (isnan(x[i])) printf("Nan...........\n"); } }
void CDNewsImageController::tableViewDidSelectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row) { CCLog("title====%d",(int)getRandNum()); CDShowNewsImage* _controller = new CDShowNewsImage(); _controller->init(); _controller->setTitle(" "); _controller->autorelease(); RootWindow::getInstance()->getDrawerController()->hideLeftViewController(true); RootWindow::getInstance()->getRootNavigationController()->pushViewController(_controller, true); _controller->initNewsImageView(m_ImageMsg[row]); }
/***** Active Skills *****/ int ServantAssassin::poisonStrike(vector<Servant *> defenders) { if (actionMPCosts[ascension][1] > currMP) return 1; // Not enough MP to attack else { subMP(actionMPCosts[ascension][1]); for (unsigned int i = 0; i < defenders.size(); i++) { log->addToEventLog(getFullName() + " used Poison Strike against " + defenders[i]->getFullName() + "!"); // Check if you hit the targets vector<int> opEvade = defenders[i]->getEvade(); bool hit = false; // Calculate accuracy int accuracy = capZero(getHitRate() - opEvade[0]); int r = getRandNum(); if (accuracy >= r) hit = true; // Skill: Presence Detection skips all other evasion checks! // If you hit, apply the poison debuff if (hit) { vector<Stat> dStats; dStats.push_back(HP); vector<int> dAmount; dAmount.push_back(-1 * (defenders[i]->getMaxHP() / 20)); Debuff *poison = new Debuff("Poison", "Poison does damage over time.", defenders[i]->getTeam(), dStats, dAmount, 5); defenders[i]->addDebuff(poison); log->addToEventLog(getFullName() + " poisoned " + defenders[i]->getFullName() + "!"); } else { log->addToEventLog(getFullName() + " missed " + defenders[i]->getFullName() + "!"); } // Poison strike does no damage and thus there is no need to check // if the defender is dead. } } return 0; }
/* * buildFile function * Builds a .dat file that has 20 integers. * @param **file a pointer to a pointer of a file * @param fileSize the number of items in the file */ void buildFile(FILE **file, int fileSize) { int randNum = 0; //integer to store number returned from getRandNum int dataRead = 0; //integer to store the data read from the file //opens/creates the file *file = fopen("pa13.dat", "w+b"); //checks if the file was succesfully opened if( !file ) { puts("Error opening file..."); } else { //writes 20 integers from 0-19 to the file for( int i = 0; i < fileSize; i++ ) { fwrite(&randNum, sizeof(int), 1, *file); } //adds one to the integer that comes up from getRandNum function on the file for( int i = 0; i < 500; i++ ) { //sets the return value of getRandNum to randNum randNum = getRandNum(0, NUM_ITEMS); //seeks from the beginning of the file to randNum fseek(*file, (int)(sizeof(int)) * randNum, SEEK_SET); //reads the data from the current spot in the file fread(&dataRead, sizeof(int), 1, *file); //seeks from the beginning of the file back to the randNum fseek(*file, (int)(sizeof(int)) * randNum, SEEK_SET); //adds one to the current value in the file and sets it to randNum randNum = dataRead + 1; //writes the current value of randNum to the current spot in the file fwrite(&randNum, sizeof(int), 1, *file); } } return; }//end buildFile
void CDNewsImageController::onRefreshRequestFinished(const HttpResponseStatus& status, const CSJson::Value& json) { if (status == HttpResponseSucceed) { const CSJson::Value& value = json["msg"]; int length = value.size(); for (int index = 0; index < length; index++) { newsImage temp_msg; temp_msg.m_title = value[index]["title"].asString(); for (int i=0; i<value[index]["piccon"].size(); i++) { string temp_pic = value[index]["piccon"][i]["pic"].asString(); string temp_dsc = value[index]["piccon"][i]["desc"].asString(); temp_msg.m_imageUrl.push_back(temp_pic); temp_msg.m_imageDesc.push_back(temp_dsc); } m_ImageMsg.push_back(temp_msg); m_ImageNum.push_back((int)getRandNum()); CCLog("title==%s===%d",value[index]["title"].asString().c_str(),value[index]["piccon"].size()); } }else{ p_section--; } do { CC_BREAK_IF(p_pLoading == NULL); if (p_pLoading->isAnimating()) { p_pLoading->stopAnimating(); } else { p_TableView->reloadData(); } } while (0); }
int ServantBerserkerClub::attack(vector<Servant *> defenders, bool counter) { if (actionMPCosts[ascension][0] > currMP) return 1; // Not enough MP to attack else { subMP(actionMPCosts[ascension][0]); for (unsigned int i = 0; i < defenders.size(); i++) { // Add the target to the list of previous targets (if they are not // already on it) if (!previouslyTargeted(defenders[i])) previousTargets.push_back(defenders[i]); int dam = 0; // Check if you hit the targets vector<int> opEvade = defenders[i]->getEvade(); bool hit = false; // Calculate accuracy int accuracy = capZero(getHitRate() - opEvade[0]); int r = getRandNum(); if (accuracy >= r) hit = true; if (opEvade.size() > 1 && hit) { for (unsigned int j = 1; j < opEvade.size() && hit; j++) { r = getRandNum(); if (opEvade[j] >= r) hit = false; } } // If you hit, calculate crit chance if (hit) { int attackMult = 1; int critChance = capZero(getCriticalRate() - defenders[i]->getCriticalEvade()); r = getRandNum(); if (critChance >= r) attackMult *= 3; // If you're at the Final Ascension and have already faced this // target, deal thrice as much damage and decrease DEF by 10 // (Barbarian's Wrath) if(ascension == 2 && previouslyTargeted(defenders[i])) { attackMult *= 3; vector<Stat> tS; tS.push_back(DEF); vector<int> tA; tA.push_back(-10); Debuff* bw = new Debuff("Barbarian's Wrath", "You tried to fight a Club Berserker twice, and paid the price.", defenders[i]->getTeam(), tS, tA, -1); defenders[i]->addDebuff(bw); log->addToEventLog(defenders[i]->getFullName() + " felt " + getFullName() + "'s Wrath!"); } // Deal the damage dam = capZero(getStr() - defenders[i]->getDef()) * attackMult; log->addToEventLog(getFullName() + " dealt " + to_string(dam) + " damage to " + defenders[i]->getFullName() + "."); defenders[i]->subHP(dam, D_STR); // Apply the Crushing Blow debuff vector<Stat> tStats; tStats.push_back(DEF); vector<int> tAmounts; tAmounts.push_back(-2); Debuff* bOut = new Debuff("Crushing Blow", "You took a blow from a Club Berserker, permanetly denting your armor.", defenders[i]->getTeam(), tStats, tAmounts, -1); defenders[i]->addDebuff(bOut); // Check to see if Barbarian's Might activates r = getRandNum(); if (r <= getLuk() * 2) { vector<Stat> tS; tS.push_back(DEF); vector<int> tA; tA.push_back(-5); Debuff* bm = new Debuff("Barbarian's Might", "You took an incredible blow from a Club Berserker, permanetly denting your armor.", defenders[i]->getTeam(), tS, tA, -1); defenders[i]->addDebuff(bm); log->addToEventLog(defenders[i]->getFullName() + " felt " + getFullName() + "'s Might!"); } } else { log->addToEventLog(getFullName() + " missed " + defenders[i]->getFullName() + "!"); } // Check to see if the defender is dead. If they are, do not call // the counterattack. Additionally, if they are an Avenger and they // die, activate Final Revenge. // If they are not dead but they are a Berserker, check to see if // Mad Counter activates. if(defenders[i]->getCurrHP() > 0) { // Check if the defender is a Berserker. If they are, and they // are adjacent to this unit, check to see if Mad Counter // activates. if (defenders[i]->getClass() == Berserker && isAdjacent(defenders[i])) { r = getRandNum(); if (defenders[i]->getLuk() >= r) { // Mad Counter activated! The attacking servant takes // damage equal to the damage they dealt. log->addToEventLog(defenders[i]->getFullName() + "'s Mad Counter activated, dealing " + to_string(dam) + " damage back to " + getFullName() + "."); subHP(dam, C_STR); } } // Call "attack" on the defending servant for their // counterattack, if you are in their range and you are the // initiating servant. if (defenders[i]->isInRange(this) && counter) { vector<Servant *> you; you.push_back(this); defenders[i]->attack(you, false); } } else { if (defenders[i]->getClass() == Avenger) { // Activate Final Revenge Debuff *finRev = defenders[i]->finalRevenge(); addDebuff(finRev); if (defenders[i]->getAscensionLvl() == 2) { subHP(.1 * getMaxHP(), OMNI); subMP(.1 * getMaxMP()); if (getCurrHP() == 0) { setHP(1); } } } } } } return 0; }
void generateSyntheticData(int row, int hosts, double ** m, std::string prefix, std::string topofile, double demand_jump_factor, double demand_locality_factor, int merge_len) { char filedir[200]; sprintf(filedir,"%s%s", prefix.c_str(),"patterns"); printf("dir=%s!\n", filedir); FILE * fPattern = fopen(filedir,"r"); assert(fPattern != NULL && "Unable to open petterns file"); int nWeeks; int frlt=fscanf(fPattern, "%i", &nWeeks); assert(frlt >= 0); double ** totflow = new double *[nWeeks]; for (int curWeek = 0; curWeek < nWeeks;curWeek++) { totflow[curWeek] = new double[2016]; for (int i = 0; i < 2016; i++) frlt=fscanf(fPattern, "%lf", &totflow[curWeek][i]); } const int nfft = 2016; kiss_fft_cfg cfg = kiss_fft_alloc(nfft, false, 0, 0); kiss_fft_cfg cfg2 = kiss_fft_alloc(nfft,true, 0, 0); kiss_fft_cpx cx_in[nfft], cx_out[nfft]; for (int curWeek = 0; curWeek < nWeeks; curWeek++) { for (int i = 0; i < nfft; i++) { cx_in[i].r = totflow[curWeek][i]; cx_in[i].i = 0; } kiss_fft(cfg, cx_in, cx_out); for (int i = 0; i < nfft; i++) { cx_out[i].r /= nfft; cx_out[i].i /= nfft; } int position[nfft]; for (int i = 0; i < nfft; i++) position[i] = i; for (int i = 0; i < nfft - 1; i++) for (int j = i + 1; j < nfft; j++) { double n1 = cxnorm(cx_out[position[i]]); double n2 = cxnorm(cx_out[position[j]]); if (n1 < n2) { int tmp; tmp = position[i]; position[i] = position[j]; position[j] = tmp; } } for (int i = 6; i < nfft; i++) { double a = uniform_rand(0, 3); cx_out[position[i]].r *= a; cx_out[position[i]].i *= a; } kiss_fft(cfg2, cx_out, cx_in); for (int i = 0; i < nfft; i++) totflow[curWeek][i] = cx_in[i].r; } /* FILE * fFFTout = fopen("fftout", "w"); for (int curWeek = 0; curWeek < nWeeks; curWeek++) { for (int i = 0; i < 2016; i++) fprintf(fFFTout, "%.2lf ", totflow[curWeek][i]); fprintf(fFFTout, "\n"); } fclose(fFFTout); */ int nMean; char filedir2[200]; sprintf(filedir2,"%s%s", prefix.c_str(),"pareto"); printf("dir=%s!\n", filedir2); FILE * fpareto = fopen(filedir2, "r"); frlt=fscanf(fpareto, "%i", &nMean); double * saveMean = new double[nMean]; for (int i = 0; i < nMean; i++) frlt=fscanf(fpareto, "%lf", &saveMean[i]); //m[col][row]; double ** Tin = new double*[hosts]; double ** Tout = new double*[hosts]; for (int i = 0; i < hosts; i++) { Tin[i] = new double[row]; Tout[i] = new double[row]; generateW(Tin[i], saveMean[getRandNum(nMean)], row,demand_jump_factor); generateW(Tout[i], saveMean[getRandNum(nMean)], row,demand_jump_factor); } /* for (int i = 0; i < hosts; i++) { printf("No%i ----------%lf ", i, Tin[i][0]); for (int j = 0; j < 100;j++) printf("%.2lf -- ", Tin[i][j]); double avg = 0; for (int j = 0; j < row; j++) avg += Tin[i][j] / row; printf("avg == %.2lf\n\n", avg); } */ double tot_in, tot_out; for (int i = 0; i < row; i++) { tot_in = 0; tot_out = 0; for (int j = 0; j < hosts;j++) { tot_in += Tin[j][i]; tot_out += Tout[j][i]; } if (tot_in==0) tot_in=1; for (int j = 0; j < hosts; j++) { Tin[j][i] /= tot_in; Tout[j][i] /= tot_out; } } /* for (int i = 0; i < 5; i++) { printf("No%i ---------- \n\n\n", i); for (int j = 0; j < 100;j++) printf("%.6lf -- ", Tin[i][j]); }*/ double maxDist = 0; double ** graph=NULL; if (topofile.length() > 1) { FILE* topof=fopen(topofile.c_str(), "r"); assert(topof != NULL); int topo_n, topo_m; int tmp_rlt; tmp_rlt=fscanf(topof, "%i%i", &topo_n, &topo_m); if (tmp_rlt<0) printf("error! in fscanf\n"); graph = new double *[topo_n]; for (int i = 0; i < topo_n; i++) graph[i] = new double[topo_n]; for (int i = 0; i < topo_n; i++) for (int j = 0; j < topo_n; j++) if (i != j) graph[i][j] = 214748368; else graph[i][j] = 0; for (int i = 0; i < topo_m; i++) { int va, vb; double edge_len; double tmp_rlt=fscanf(topof, "%i%i%lf", &va, &vb, &edge_len); if (tmp_rlt<0) printf("error! in fscanf\n"); graph[va][vb] = edge_len; graph[vb][va] = edge_len; } for (int k = 0; k < topo_n; k++) for (int i = 0; i < topo_n; i++) if (k != i) for (int j = 0; j < topo_n; j++) if ((k != j) && (i != j)) if (graph[i][j]>graph[i][k] + graph[k][j]) graph[i][j] = graph[i][k] + graph[k][j]; for (int i = 0; i < topo_n; i++) for (int j = 0; j < topo_n; j++) if (maxDist<graph[i][j]) maxDist = graph[i][j]; fclose(topof); } int next=0; int pickedTotPattern=0; for (int i = 0; i < row; i++) { double s_merge=0; for (int j=0;j<merge_len;j++) { s_merge+= totflow[pickedTotPattern][next]; next++; if (next>=2016) { next=0; pickedTotPattern=0; } } s_merge/=merge_len; for (int j = 0; j < hosts; j++) for (int k = 0; k < hosts; k++){ if (maxDist == 0) m[j*hosts + k][i] = s_merge * Tin[j][i] * Tout[k][i]; else m[j*hosts + k][i] = s_merge * Tin[j][i] * Tout[k][i]* exp(-demand_locality_factor* graph[j][k]/maxDist/2); if (isnan(m[j*hosts+k][i])) printf("%lf %lf %lf", s_merge, Tin[j][i], Tout[k][i]); if (m[j*hosts+k][i]==0) m[j*hosts+k][i]=1000; } } fclose(fPattern); fclose(fpareto); for (int i = 0; i < nWeeks; i++) delete[] totflow[i]; delete[] totflow; delete[] saveMean; delete[] Tin; delete[] Tout; }
double uniform_rand(double a, double b) { double range = 100000; return a + ((double)getRandNum(int(range))) / range * (b - a); }
int ServantBerserkerFlail::attack(vector<Servant *> defenders, bool counter) { if (actionMPCosts[ascension][0] > currMP) return 1; // Not enough MP to attack else { subMP(actionMPCosts[ascension][0]); bool npActive = false; // Check if Lashing Out activates // "Hitting all adjacent opponents" only applies to the first two // ascension levels, as Maelstrom of Death trumps Lashing Out int r = getRandNum(); // Cratered Debuff vector<Stat> tS; tS.push_back(SPD); tS.push_back(DEF); vector<int> tA; tA.push_back(-5); tA.push_back(2); // Get the Team of the opposing team /*Team otherTeam = All; vector<vector<Servant*>> pField = field->getServantLocations(); for (unsigned int i = 0; i < pField.size(); i++) { for(unsigned int j = 0; j < pField[i].size(); j++) { if(pField[i][j] != NULL && pField[i][j]->getTeam() != getTeam()) { otherTeam = pField[i][j]->getTeam(); } } }*/ Debuff* br = new Debuff("Cratered", "The ground has been cratered.", All, tS, tA, -1); vector<Coordinate> crateredRange; if (ascension <= 1 && r < getLuk()) { // Add all adjacent servants to the defenders vector (as long as // they aren't already in it) vector<Servant*> adj = field->getAllInRange(this, getLowToHighRange(1,1)); for (unsigned int i = 0; i < adj.size(); i++) { bool isIn = false; for (unsigned int j = 0; j < defenders.size() && !isIn; j++) { if (adj[i] == defenders[j]) isIn = true; } if (!isIn) defenders.push_back(adj[i]); } crateredRange = getAbsoluteRange(1,1,this); } else if (ascension == 2 && r < getLuk() * 1.5) { crateredRange = getAbsoluteRange(1,2,this); } // Apply the cratered debuff to the appropriate spaces field->addDebuffToRange(br, crateredRange); for (unsigned int i = 0; i < defenders.size(); i++) { int dam = 0; // Check if you hit the targets vector<int> opEvade = defenders[i]->getEvade(); bool hit = false; // Calculate accuracy int accuracy = capZero(getHitRate() - opEvade[0]); r = getRandNum(); if (accuracy >= r) hit = true; // Maelstrom of Death doubles accuracy and prevents other evasion // skills from activating if (ascension == 2) accuracy *= 2; if (opEvade.size() > 1 && hit && ascension <= 1) { for (unsigned int j = 1; j < opEvade.size() && hit; j++) { r = getRandNum(); if (opEvade[j] >= r) hit = false; } } // If you hit, calculate crit chance if (hit) { int attackMult = 1; int critChance = capZero(getCriticalRate() - defenders[i]->getCriticalEvade()); // Spin To Win triples crit chance if (ascension >= 1) critChance *= 3; // Maelstrom of Death also doubles crit chance if (ascension == 2) critChance *= 2; r = getRandNum(); if (critChance >= r) attackMult *= 3; // Deal the damage dam = capZero(getStr() - defenders[i]->getDef()) * attackMult; log->addToEventLog(getFullName() + " dealt " + to_string(dam) + " damage to " + defenders[i]->getFullName() + "."); defenders[i]->subHP(dam, D_STR); } else { log->addToEventLog(getFullName() + " missed " + defenders[i]->getFullName() + "!"); } // Check to see if the defender is dead. If they are, do not call // the counterattack. Additionally, if they are an Avenger and they // die, activate Final Revenge. // If they are not dead but they are a Berserker, check to see if // Mad Counter activates. if(defenders[i]->getCurrHP() > 0) { // Check if the defender is a Berserker. If they are, and they // are adjacent to this unit, check to see if Mad Counter // activates. if (defenders[i]->getClass() == Berserker && isAdjacent(defenders[i])) { r = getRandNum(); if (defenders[i]->getLuk() >= r) { // Mad Counter activated! The attacking servant takes // damage equal to the damage they dealt. log->addToEventLog(defenders[i]->getFullName() + "'s Mad Counter activated, dealing " + to_string(dam) + " damage back to " + getFullName() + "."); subHP(dam, C_STR); } } // Call "attack" on the defending servant for their // counterattack, if you are in their range and you are the // initiating servant. // However if the servant is at their final ascension, or if // Lashing out activates, targets cannot counter if (!npActive && counter && defenders[i]->isInRange(this)) { vector<Servant *> you; you.push_back(this); defenders[i]->attack(you, false); } } else { if (defenders[i]->getClass() == Avenger) { // Activate Final Revenge Debuff *finRev = defenders[i]->finalRevenge(); addDebuff(finRev); if (defenders[i]->getAscensionLvl() == 2) { subHP(.1 * getMaxHP(), OMNI); subMP(.1 * getMaxMP()); if (getCurrHP() == 0) { setHP(1); } } } } } } return 0; }
void schedule(void) { pid_t pid = current->p_pid; if (scheduling_algorithm == 0) while (1) { pid = (pid + 1) % NPROCS; // Run the selected process, but skip // non-runnable processes. // Note that the 'run' function does not return. if (proc_array[pid].p_state == P_RUNNABLE) run(&proc_array[pid]); } else if (scheduling_algorithm == 1) while (1) { int i; for (i = 1; i < NPROCS; i++) { if (proc_array[i].p_state == P_RUNNABLE) run(&proc_array[i]); } } else if (scheduling_algorithm == 2) while (1) { int process = pid; int pri = 100; int i; for (i = pid+1; i <= pid+NPROCS; i++) { if (proc_array[i%NPROCS].p_state == P_RUNNABLE && proc_array[i%NPROCS].p_priority < pri) { process = i%NPROCS; pri = proc_array[i%NPROCS].p_priority; } } run(&proc_array[process]); } else if (scheduling_algorithm == 3) while (1) { int process = pid; while (1) { if (process == 0) { process++; process = process%NPROCS; } if (proc_array[process].p_state == P_RUNNABLE && proc_array[process].p_counter < proc_array[process].p_share) { proc_array[process].p_counter++; run(&proc_array[process]); } else if (proc_array[process].p_state == P_RUNNABLE && proc_array[process].p_counter == proc_array[process%NPROCS].p_share) { proc_array[process].p_counter = 0; process++; process = process%NPROCS; } else { process++; process = process%NPROCS; } } } else if (scheduling_algorithm == 4) while (1) { int proc = getRandNum()%(NPROCS-1); if (proc_array[proc+1].p_state == P_RUNNABLE && proc+1 == proc_array[proc+1].p_ticket) run(&proc_array[proc+1]); } // If we get here, we are running an unknown scheduling algorithm. cursorpos = console_printf(cursorpos, 0x100, "\nUnknown scheduling algorithm %d\n", scheduling_algorithm); while (1) /* do nothing */; }
// Re-define attack to account for the Vengeance skill int ServantAvenger::attack(vector<Servant *> defenders, bool counter) { if (actionMPCosts[ascension][0] > currMP) return 1; // Not enough MP to attack else { subMP(actionMPCosts[ascension][0]); for (unsigned int i = 0; i < defenders.size(); i++) { int dam = 0; // Check if you hit the targets vector<int> opEvade = defenders[i]->getEvade(); bool hit = false; // Calculate accuracy int accuracy = capZero(getHitRate() - opEvade[0]); int r = getRandNum(); if (accuracy >= r) hit = true; if (opEvade.size() > 1 && hit) { for (unsigned int j = 1; j < opEvade.size() && hit; j++) { r = getRandNum(); if (opEvade[j] >= r) hit = false; } } // If you hit, calculate crit chance // Also check if Skill: Vengeance activates if (hit) { int attackMult = 1; int critChance = capZero(getCriticalRate() - defenders[i]->getCriticalEvade()); r = getRandNum(); if (critChance >= r) attackMult *= 3; // Check for Vengeance int addVengeance = 0; r = getRandNum(); if (getSkl() * 2 >= r) { addVengeance = (getMaxHP() - getCurrHP()) * 2; log->addToEventLog(getFullName() + " activated Vengeance!"); } // Deal the damage dam = (capZero(getStr() - defenders[i]->getDef()) + addVengeance) * attackMult; log->addToEventLog(getFullName() + " dealt " + to_string(dam) + " damage to " + defenders[i]->getFullName() + "."); defenders[i]->subHP(dam, D_STR); } else { log->addToEventLog(getFullName() + " missed " + defenders[i]->getFullName() + "!"); } // Check to see if the defender is dead. If they are, do not call // the counterattack. Additionally, if they are an Avenger and they // die, activate Final Revenge. // If they are not dead but they are a Berserker, check to see if // Mad Counter activates. if(defenders[i]->getCurrHP() > 0) { // Check if the defender is a Berserker. If they are, and they // are adjacent to this unit, check to see if Mad Counter // activates. if (defenders[i]->getClass() == Berserker && isAdjacent(defenders[i])) { r = getRandNum(); if (defenders[i]->getLuk() >= r) { // Mad Counter activated! The attacking servant takes // damage equal to the damage they dealt. log->addToEventLog(defenders[i]->getFullName() + "' Mad Counter activated, dealing " + to_string(dam) + " damage back to " + getFullName() + "."); subHP(dam, C_STR); } } // Call "attack" on the defending servant for their // counterattack, if you are in their range and you are the // initiating servant. if (defenders[i]->isInRange(this) && counter) { vector<Servant *> you; you.push_back(this); defenders[i]->attack(you, false); } } else { if (defenders[i]->getClass() == Avenger) { // Activate Final Revenge Debuff *finRev = defenders[i]->finalRevenge(); addDebuff(finRev); if (defenders[i]->getAscensionLvl() == 2) { subHP(.1 * getMaxHP(), OMNI); subMP(.1 * getMaxMP()); if (getCurrHP() == 0) { setHP(1); } } } } } } return 0; }
/***** Function re-definitions *****/ int ServantAssassin::attack(vector<Servant *> defenders, bool counter) { if (actionMPCosts[ascension][0] > currMP) return 1; // Not enough MP to attack else { subMP(actionMPCosts[ascension][0]); for (unsigned int i = 0; i < defenders.size(); i++) { int dam = 0; // Check if you hit the targets vector<int> opEvade = defenders[i]->getEvade(); bool hit = false; // Calculate accuracy int accuracy = capZero(getHitRate() - opEvade[0]); int r = getRandNum(); if (accuracy >= r) hit = true; // Skill: Presence Detection skips all other evasion checks! // If you hit, calculate crit chance if (hit) { int attackMult = 1; int critChance = capZero(getCriticalRate() - defenders[i]->getCriticalEvade()); r = getRandNum(); if (critChance >= r) attackMult *= 3; // Calculate the chance of Lethality r = getRandNum(); if (getSkl() / 8 > r) { dam = defenders[i]->getMaxHP() * attackMult; log->addToEventLog(getFullName() + " activated Lethality against " + defenders[i]->getFullName() + "!" + to_string(dam) + " damage dealt!"); defenders[i]->subHP(dam, D_STR); } else { // Deal the damage dam = capZero(getStr() - defenders[i]->getDef()) * attackMult; log->addToEventLog(getFullName() + " dealt " + to_string(dam) + " damage to " + defenders[i]->getFullName() + "."); defenders[i]->subHP(dam, D_STR); } // Add the weapon-specific debuff to the target Debuff *deb = new Debuff(classDebuff->getDebuffName(), classDebuff->getDebuffDescrip(), defenders[i]->getTeam(), classDebuff->getDebuffStats(), classDebuff->getDebuffAmounts(), classDebuff->getTurnsRemaining()); defenders[i]->addDebuff(deb); } else { log->addToEventLog(getFullName() + " missed " + defenders[i]->getFullName() + "!"); } // Check to see if the defender is dead. If they are, do not call // the counterattack. Additionally, if they are an Avenger and they // die, activate Final Revenge. // If they are not dead but they are a Berserker, check to see if // Mad Counter activates. if(defenders[i]->getCurrHP() > 0) { // Check if the defender is a Berserker. If they are, and they // are adjacent to this unit, check to see if Mad Counter // activates. if (defenders[i]->getClass() == Berserker && isAdjacent(defenders[i])) { r = getRandNum(); if (defenders[i]->getLuk() >= r) { // Mad Counter activated! The attacking servant takes // damage equal to the damage they dealt. log->addToEventLog(defenders[i]->getFullName() + "' Mad Counter activated, dealing " + to_string(dam) + " damage back to " + getFullName() + "."); subHP(dam, C_STR); } } // Call "attack" on the defending servant for their // counterattack, if you are in their range and you are the // initiating servant. if (defenders[i]->isInRange(this) && counter) { vector<Servant *> you; you.push_back(this); defenders[i]->attack(you, false); } } else { if (defenders[i]->getClass() == Avenger) { // Activate Final Revenge Debuff *finRev = defenders[i]->finalRevenge(); addDebuff(finRev); if (defenders[i]->getAscensionLvl() == 2) { subHP(.1 * getMaxHP(), OMNI); subMP(.1 * getMaxMP()); if (getCurrHP() == 0) { setHP(1); } } } } } } return 0; }