int Battle::getDamage(Pokemon& attacking, Pokemon& defending, Move& move) { // get the pokemon's level int level = attacking.getLevel(); // get the relavent values for attack and defense int attackStat; int defenseStat; if(move.getCategory() == PHYSICAL) { attackStat = attacking.getAttack().getModValue(); defenseStat = defending.getDefense().getModValue(); } else { attackStat = attacking.getSpecialAttack().getModValue(); defenseStat = defending.getSpecialDefense().getModValue(); } // get the moves power double attackPower = move.getPower(); // get the stab double STAB = 1.0; if(attacking.getTypeOne() == move.getType() or attacking.getTypeTwo() == move.getType()) { STAB = 1.5; } // get the type multiplier double typeMult = Type::getMultiplier(move.getType(), defending.getTypeOne(), defending.getTypeTwo()); // get the random number 85-100 double randomNumber = (rand() % 16) + 85; // do the calculation double damage = ((((2.0 * level / 5.0 + 2.0) * attackStat * attackPower / defenseStat) / 50.0) + 2.0) * STAB * typeMult * randomNumber / 100.0; // print debug messages println_debug("Damage for " << attacking.getNickname() << " attacking " << defending.getNickname() << " with " << move.getName()); println_debug("Level = " << level); println_debug("attackStat = " << attackStat); println_debug("attackPower = " << attackPower); println_debug("defenseStat = " << defenseStat); println_debug("STAB = " << STAB); println_debug("type = " << typeMult); println_debug("random = " << randomNumber); println_debug("Damage calculated = " << damage); println_debug(""); // round damage return roundDamage(damage); }
//determines if the pokemon will be caught will the given pokeball, and pokemon passed in int Pokeball::canCatch(Pokemon p) { if (!p.isWild()) { //cout << "Cannot capture other trainer's Pokemon!" << endl; return -1; } double f[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; f[0] = 100 - p.getLevel(); f[1] = (1.0 - 1.0*p.getHP() / p.getMaxHP()) * 200; f[2] = rand() % 200; double prob = f[0] + f[1] + f[2]; if (prob >= 250) { // cout << p.getName() << " was successfully caught!" << endl; return 1; } //cout << "Oh no, it broke free!" << endl; return 0; }