void PlayerTroop::ResolveBattle(PlayerTroop* enemy){ if (getStats()->getAttack() > enemy->getStats()->getDefence()){ float damage = getStats()->getAttack(); damage /= enemy->getStats()->getArmour() + 1; enemy->DealDamage(damage * Game->TIME.delta); } }
/* * Example obtainting client stats from an E_CONNECT or E_STOP event */ void FmsAuthAdaptor::processStats(IFmsAuthEvent* pAev) { I64 statsHandle; FmsClientStats baseStats; if (!getI64Field(pAev, IFmsAuthEvent::F_CLIENT_STATS_HANDLE, statsHandle)) return; char* pAppName = getStringField(pAev, IFmsAuthEvent::F_APP_NAME); if (pAev->getType() == IFmsAuthEvent::E_CONNECT) { getStats(statsHandle, baseStats); // log data char buf[1024]; char hashKey[9]; memset(hashKey, 0, 9); memcpy(hashKey, &statsHandle, sizeof(statsHandle)); sprintf(buf, "client Stats Handle= %s, bytes_in= %f, bytes_out= %f\n", hashKey, static_cast<double>(baseStats.bytes_in), static_cast<double>(baseStats.bytes_out)); m_pFmsAuthServerContext->log(buf, IFmsServerContext::kInformation, false); } else if (pAev->getType() == IFmsAuthEvent::E_STOP) { getStats(statsHandle, baseStats); } }
PlayerTroop::PlayerTroop(int health, int attack, int armour, int defence, int range, float speed, std::string name) : Object(name){ getStats()->setHealth(health); getStats()->setAttack(attack); getStats()->setArmour(armour); getStats()->setDefence(defence); getStats()->setRange(range); getStats()->setSpeed(speed); getStats()->setMaxHealth(health); getStats()->setMaxAttack(attack); getStats()->setMaxArmour(armour); getStats()->setMaxDefence(defence); m_target = NULL; }
/** * Calculate firing accuracy. * Formula = accuracyStat * weaponAccuracy * kneelingbonus(1.15) * one-handPenalty(0.8) * woundsPenalty(% health) * critWoundsPenalty (-10%/wound) * @param actionType * @param item * @return firing Accuracy */ double BattleUnit::getFiringAccuracy(BattleActionType actionType, BattleItem *item) { double result = (double)(getStats()->firing / 100.0); double weaponAcc = item->getRules()->getAccuracySnap(); if (actionType == BA_AIMEDSHOT || actionType == BA_LAUNCH) weaponAcc = item->getRules()->getAccuracyAimed(); else if (actionType == BA_AUTOSHOT) weaponAcc = item->getRules()->getAccuracyAuto(); else if (actionType == BA_HIT) weaponAcc = item->getRules()->getAccuracyMelee(); result *= (double)(weaponAcc/100.0); if (_kneeled) result *= 1.15; if (item->getRules()->isTwoHanded()) { // two handed weapon, means one hand should be empty if (getItem("STR_RIGHT_HAND") != 0 && getItem("STR_LEFT_HAND") != 0) { result *= 0.80; } } return result * getAccuracyModifier(); }
bool Entity::humanCanWieldItem(const Item& item) const { Stat* myStats = getStats(); if ( !myStats ) { return false; } if ( monsterAllyIndex >= 0 && (monsterAllyClass != ALLY_CLASS_MIXED || item.interactNPCUid == getUID()) ) { return monsterAllyEquipmentInClass(item); } switch ( itemCategory(&item) ) { case WEAPON: return true; case ARMOR: return true; case MAGICSTAFF: return false; case THROWN: return false; default: return false; } return false; }
TEST_F(PacksTests, test_discovery_zero_state) { auto pack = Pack("foobar", getPackWithDiscovery()); auto stats = pack.getStats(); EXPECT_EQ(stats.total, 0); EXPECT_EQ(stats.hits, 0); EXPECT_EQ(stats.misses, 0); }
int query13() { char filename[40]; char *linha=NULL; Stats stats=NULL; int ano, npublics,publics; double percentagem=0.0; CatalogoPtr c=NULL; ano = npublics = publics=0; printf("Nome do autor: "); if (fgets(filename, 40, stdin) != NULL) { linha = newline(filename); } ano = 0; printf("Ano: "); if(scanf("%d", &ano)>0) { c=getCatalogo(); stats=getStats(); npublics = npublicsem(c,linha, ano); publics=getPublics(ano,stats); percentagem=(double)npublics/publics; percentagem=percentagem*100; printf("Percentagem relativa ao nr publicações de %d: %f\n",ano,percentagem); } return 1; }
int query10() { int year = 0; FILE *fp; char filename[40]; Stats stats=NULL; int i; printf("Ano: "); if(scanf("%d", &year)>0) { getchar(); printf("Nome do ficheiro em qual quer gravar: "); if (fgets(filename, 40, stdin) != NULL) { fp = NULL; fp = fopen(filename, "w"); fprintf(fp, "#Ano;#Autores;#Publicações\n"); stats = getStats(); while (stats->ano != year) { if (year < stats->ano) { stats = stats->left; } else { stats = stats->right; } } printf("#Ano;#Autores;#Publicações\n"); for (i = 0; i <= 2; i++) { printf("%d;%d;%d\n", stats->ano, i + 1, stats->coautores[i]); fprintf(fp, "%d;%d;%d\n", stats->ano, i + 1, stats->coautores[i]); } fclose(fp); } } return 1; }
STDMETHODIMP MachineDebuggerWrap::GetStats(IN_BSTR aPattern, BOOL aWithDescriptions, BSTR *aStats) { LogRelFlow(("{%p} %s:enter aPattern=%ls aWithDescriptions=%RTbool aStats=%p\n", this, "MachineDebugger::getStats", aPattern, aWithDescriptions, aStats)); VirtualBoxBase::clearError(); HRESULT hrc; try { CheckComArgOutPointerValidThrow(aStats); AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) throw autoCaller.rc(); hrc = getStats(BSTRInConverter(aPattern).str(), aWithDescriptions, BSTROutConverter(aStats).str()); } catch (HRESULT hrc2) { hrc = hrc2; } catch (...) { hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS); } LogRelFlow(("{%p} %s: leave aStats=%ls hrc=%Rhrc\n", this, "MachineDebugger::getStats", *aStats, hrc)); return hrc; }
void run() { //Instance inst1 = InstanceGenerator::generate("./src/instances/test", 25, 3, 0, 0); //generateInstances(); int numAnts = 100; std::string path = "./src/instances/weakly_correlated/10k25i.dat"; //Instance inst = InstanceGenerator::generate(path, 25, 10, 1, 1); Instance inst(path); Colony col(inst, numAnts, 0.95, 2.0, 1.0); getStats(col, 10, inst.getOptimal()); //ColonyTuner cT(inst1, numAnts); //Colony col = cT.test(); //Solution best = col.run(); //printResults(col.getSolutionValues()); //std::cout << "Best solution found: " << best.getValue() << "\n"; //std::cout << "Optimal value: " << inst.getOptimal() << "\n"; //std::cout << best.toString() << "\n"; }
void tr_statsFileCreated (tr_session * session) { struct tr_stats_handle * s; if ((s = getStats (session))) s->single.filesAdded++; }
/** * Get the number of time units a certain action takes. * @param actionType * @param item * @return TUs */ int BattleUnit::getActionTUs(BattleActionType actionType, BattleItem *item) { if (item == 0) { return 0; } switch (actionType) { case BA_PRIME: return (int)floor(getStats()->tu * 0.50); case BA_THROW: return (int)floor(getStats()->tu * 0.25); case BA_AUTOSHOT: return (int)(getStats()->tu * item->getRules()->getTUAuto() / 100); case BA_SNAPSHOT: return (int)(getStats()->tu * item->getRules()->getTUSnap() / 100); case BA_HIT: return (int)(getStats()->tu * item->getRules()->getTUMelee() / 100); case BA_LAUNCH: case BA_AIMEDSHOT: return (int)(getStats()->tu * item->getRules()->getTUAimed() / 100); case BA_USE: return (int)(getStats()->tu * item->getRules()->getTUUse() / 100); case BA_MINDCONTROL: case BA_PANIC: return item->getRules()->getTUUse(); default: return 0; } }
void CInimigo::die() { if(getStats()->getPV() <= 0) { divisorxp->giveXP(); estado = E_MORTO; respawn = ENEMYRESPAWNTIME; } }
void tr_statsAddDownloaded(tr_session* session, uint32_t bytes) { struct tr_stats_handle* s; if ((s = getStats(session)) != NULL) { s->single.downloadedBytes += bytes; s->isDirty = true; } }
Individual<N> * Population<N>::iterate (int iterations) { for (int i = 0; i < iterations; i++) { Individual<N> * fittest = getFittest (); if (fittest) { return fittest; } else { // print (); if (OUTPUT) { std::cout << std::endl << "WHOLE POPULATION:" << std::endl; } getStats (individuals, size); // if (OUTPUT) print (); if (OUTPUT) std::cout << "WINNERS:" << std::endl; Individual<N> * winners = tournament (); getStats (winners, size/2); // if (OUTPUT) print (winners); mutation (winners); if (OUTPUT) std::cout << "WINNERS AFTER MUTATION:" << std::endl; getStats (winners, size/2); // if (OUTPUT) print (winners); if (OUTPUT) std::cout << "CHILDREN:" << std::endl; Individual<N> * children = crossOver (winners); getStats (children, size/2); // if (OUTPUT) print (children); merge (winners, children); return fittest; } } return nullptr; }
TEST_F(PacksTests, test_discovery_cache) { auto pack = Pack("foobar", getPackWithDiscovery()); for (int i = 0; i < 5; i++) { pack.checkDiscovery(); } auto stats = pack.getStats(); EXPECT_EQ(stats.total, 5); EXPECT_EQ(stats.hits, 4); EXPECT_EQ(stats.misses, 1); }
/** * Restore soldier morale */ void BattleUnit::painKillers () { if (!getFatalWounds() || !_needPainKiller) { return ; } _needPainKiller = false; int lostHealth = getStats()->health - _health; _morale += lostHealth; }
void tr_sessionGetCumulativeStats(tr_session const* session, tr_session_stats* setme) { struct tr_stats_handle const* stats = getStats(session); tr_session_stats current = TR_SESSION_STATS_INIT; if (stats != NULL) { tr_sessionGetStats(session, ¤t); addStats(setme, &stats->old, ¤t); } }
void tr_sessionGetStats(tr_session const* session, tr_session_stats* setme) { struct tr_stats_handle const* stats = getStats(session); if (stats != NULL) { *setme = stats->single; setme->secondsActive = tr_time() - stats->startTime; updateRatio(setme); } }
/** * To calculate firing accuracy. Takes health and fatal wounds into account. * Formula = accuracyStat * woundsPenalty(% health) * critWoundsPenalty (-10%/wound) * @return modifier */ double BattleUnit::getAccuracyModifier() { double result = ((double)_health/(double)getStats()->health); int wounds = _fatalWounds[BODYPART_HEAD] + _fatalWounds[BODYPART_RIGHTARM]; if (wounds > 9) wounds = 9; result *= 1 + (-0.1*wounds); return result; }
void tr_statsSaveDirty(tr_session* session) { struct tr_stats_handle* h = getStats(session); if (h != NULL && h->isDirty) { tr_session_stats cumulative = TR_SESSION_STATS_INIT; tr_sessionGetCumulativeStats(session, &cumulative); saveCumulativeStats(session, &cumulative); h->isDirty = false; } }
void tr_statsAddUploaded( tr_session * session, uint32_t bytes ) { struct tr_stats_handle * s; if( ( s = getStats( session ) ) ) { s->single.uploadedBytes += bytes; s->isDirty = TRUE; } }
void tr_statsSaveDirty( tr_session * session ) { struct tr_stats_handle * h = getStats( session ); if( ( h != NULL ) && h->isDirty ) { tr_session_stats cumulative = STATS_INIT; tr_sessionGetCumulativeStats( session, &cumulative ); saveCumulativeStats( session, &cumulative ); h->isDirty = FALSE; } }
void Champion::update(int64 diff) { Unit::update(diff); if(respawnTimer > 0) { respawnTimer -= diff; if(respawnTimer <= 0) { setPosition(map->getRespawnLoc(side).getX(), map->getRespawnLoc(side).getY()); map->getGame()->notifyChampionRespawn(this); getStats().setCurrentHealth(getStats().getMaxHealth()); getStats().setCurrentMana(getStats().getMaxMana()); deathFlag = false; } } bool levelup = false; while(getStats().getLevel() < map->getExpToLevelUp().size() && getStats().getExp() >= map->getExpToLevelUp()[getStats().getLevel()]) { levelUp(); levelup = true; } if(levelup) { map->getGame()->notifyLevelUp(this); } for(Spell* s : spells) { s->update(diff); } }
// if output bit is true. Fix all the operands. // if all the operands are fixed. Fix the output. // given 1,1,1,- == 0, fix - to 0. Result bvAndBothWays(vector<FixedBits*>& operands, FixedBits& output) { Result result = NO_CHANGE; const int bitWidth = output.getWidth(); for (int i = 0; i < bitWidth; i++) { const stats status = getStats(operands, i); // output is fixed to one. But an input value is false! if (output.isFixed(i) && output.getValue(i) && status.fixedToZero > 0) return CONFLICT; // output is fixed to one. But an input value is false! if (output.isFixed(i) && !output.getValue(i) && status.fixedToZero == 0 && status.unfixed == 0) return CONFLICT; // output is fixed to one. So all should be one. if (output.isFixed(i) && output.getValue(i) && status.unfixed > 0) { fixUnfixedTo(operands, i, true); result = CHANGED; } // The output is unfixed. At least one input is false. if (!output.isFixed(i) && status.fixedToZero > 0) { output.setFixed(i, true); output.setValue(i, false); result = CHANGED; } // Everything is fixed to one! if (!output.isFixed(i) && status.fixedToZero == 0 && status.unfixed == 0) { output.setFixed(i, true); output.setValue(i, true); result = CHANGED; } // If the output is false, and there is a single unfixed value with // everything else true.. if (output.isFixed(i) && !output.getValue(i) && status.fixedToZero == 0 && status.unfixed == 1) { fixUnfixedTo(operands, i, false); result = CHANGED; } } return result; }
STATIC bool targExists( TARGET *targ ) /************************************/ { char buffer[_MAX_PATH]; getStats( targ ); /* get date stamp */ if( targ->existing ) { return( true ); } if( targ->attr.symbolic ) { return( false ); } if( TrySufPath( buffer, targ->node.name, NULL, false ) == RET_SUCCESS ) { RenameTarget( targ, buffer ); targ->executed = true; /* force get date */ getStats( targ ); assert( targ->existing ); return( true ); } return( false ); }
STATIC BOOLEAN targExists( TARGET *targ ) /***************************************/ { char buffer[_MAX_PATH]; getStats( targ ); /* get date stamp */ if( targ->existing ) { return( TRUE ); } if( targ->attr.symb ) { return( FALSE ); } if( TrySufPath( buffer, targ->node.name, NULL, FALSE ) == RET_SUCCESS ) { RenameTarget( targ, buffer ); targ->executed = TRUE; /* force get date */ getStats( targ ); assert( targ->existing ); return( TRUE ); } return( FALSE ); }
void tr_sessionGetCumulativeStats (const tr_session * session, tr_session_stats * setme) { const struct tr_stats_handle * stats = getStats (session); tr_session_stats current = STATS_INIT; if (stats) { tr_sessionGetStats (session, ¤t); addStats (setme, &stats->old, ¤t); } }
void CachedPlanStage::updatePlanCache() { const double score = PlanRanker::scoreTree(getStats()->children[0].get()); PlanCache* cache = collection()->infoCache()->getPlanCache(); Status fbs = cache->feedback(*_canonicalQuery, score); if (!fbs.isOK()) { LOG(5) << _canonicalQuery->ns() << ": Failed to update cache with feedback: " << redact(fbs) << " - " << "(query: " << redact(_canonicalQuery->getQueryObj()) << "; sort: " << _canonicalQuery->getQueryRequest().getSort() << "; projection: " << _canonicalQuery->getQueryRequest().getProj() << ") is no longer in plan cache."; } }
Transformation Normalize::analyze(const DataSet* dataset, const Region& descs) const { G_INFO("Doing normalize analysis..."); checkDataSet(dataset); checkMinPoints(dataset, 2); Region region = checkFixedLength(descs.select(RealType), dataset->layout()); // get statistics on the input dataset Point mmin, mmax, mean, var; if (!_params.contains("outliers") || _params.value("outliers").toDouble() < 0.0) { getStats(*dataset, region, mmin, mmax, mean, var); } else { getStatsWithOutliers(*dataset, region, mmin, mmax, mean, var); } Transformation result(dataset->layout()); result.analyzerName = "normalize"; result.analyzerParams = _params; result.applierName = "dotproduct"; // insert info values inside Transfo object: mean & var ParameterMap stats; foreach (const Segment& seg, region.segments) { // FIXME: not necessarily correct if some adjacent descriptors have been // merged into a single segment QString descriptorName = mmin.layout().descriptorName(RealType, FixedLength, seg.begin); ParameterMap meanvar; meanvar.insert("mean", mean.value(descriptorName)); meanvar.insert("var", var.value(descriptorName)); stats.insert(descriptorName, meanvar); } result.info = stats; // insert actual Transformation parameters ParameterMap& applierParams = result.params; applierParams.insert("applyClipping", _params.value("applyClipping", false)); ParameterMap coeffMap; foreach (const Segment& seg, region.segments) { QString descriptorName = mmin.layout().descriptorName(RealType, FixedLength, seg.begin); coeffMap.insert(descriptorName, getNormalizationCoeffs(descriptorName, mmin, mmax, mean, var)); } applierParams.insert("coeffs", coeffMap); G_DEBUG(GAlgorithms, "normalization success!"); return result; }