bitboard getRawMoves(const position * const pos, const int player, const int piece, const int type, const int sq) { bitboard rawMoves = 0; bitboard attackRange = 0; bitboard allPieces = 0; bitboard opponentSquares = 0; assert(sq >= 0 && sq <= 63); allPieces = pos->pieces[BLACK] | pos->pieces[WHITE]; if(CAPTURE == type) { attackRange = getAttackRange(piece, type, sq, allPieces, pos->epSquare); opponentSquares = pos->pieces[OPPONENT(player)]; if(pos->epSquare != -1) { opponentSquares |= _mask[pos->epSquare]; } /* captures */ rawMoves = attackRange & opponentSquares; } else if(NORMAL == type) { attackRange = getAttackRange(piece, type, sq, allPieces, pos->epSquare); /* normal moves, no violence ;) */ rawMoves = attackRange & ~allPieces; } else { assert(0); /* don't know type of move */ } return rawMoves; }
bool LocalPlayer::withinAttackRange(Being *target) { const int dist_x = abs(target->mX - mX); const int dist_y = abs(target->mY - mY); return !(dist_x > getAttackRange() || dist_y > getAttackRange()); }
bool Player::canSlash(const Player *other, bool distance_limit) const{ if(other->hasSkill("kongcheng") && other->isKongcheng()) return false; if(other == this) return false; if(distance_limit) return distanceTo(other) <= getAttackRange(); else return true; }
bool LocalPlayer::withinAttackRange(Being *target) { #ifdef TMWSERV_SUPPORT const Vector &targetPos = target->getPosition(); const Vector &pos = getPosition(); const int dx = abs(targetPos.x - pos.x); const int dy = abs(targetPos.y - pos.y); const int range = getAttackRange(); return !(dx > range || dy > range); #else int dist_x = abs(target->getTileX() - getTileY()); int dist_y = abs(target->getTileY() - getTileX()); if (dist_x > getAttackRange() || dist_y > getAttackRange()) { return false; } return true; #endif }
void Jack::stateChange() { // Start of state change VECTOR2 v = VECTOR2(gameptr->getPlayer()->getX(), gameptr->getPlayer()->getY()); float y2 = v.y; float x2 = v.x; float y1 = getY(); float x1 = getX(); float distance = sqrt(pow(y2 - y1, 2) + (pow(x2 - x1, 2))); if (distance < getAttackRange()) { setAiState(NPC::Attack); // Jump up and down setDest(v); } // End of state change }
bool Player::inMyAttackRange(const Player *other) const{ return distanceTo(other) <= getAttackRange(); }
void LocalPlayer::logic() { switch (mAction) { case STAND: break; case SIT: break; case DEAD: break; case HURT: break; case WALK: mFrame = (get_elapsed_time(mWalkTime) * 6) / mWalkSpeed; if (mFrame >= 6) nextStep(); break; case ATTACK: int rotation = 0; std::string particleEffect = ""; int frames = 4; if (mEquippedWeapon && mEquippedWeapon->getAttackType() == ACTION_ATTACK_BOW) frames = 5; mFrame = (get_elapsed_time(mWalkTime) * frames) / mAttackSpeed; //attack particle effect if (mEquippedWeapon) particleEffect = mEquippedWeapon->getParticleEffect(); if (!particleEffect.empty() && mParticleEffects && mFrame == 1) { switch (mDirection) { case DOWN: rotation = 0; break; case LEFT: rotation = 90; break; case UP: rotation = 180; break; case RIGHT: rotation = 270; break; default: break; } Particle *p; p = particleEngine->addEffect("graphics/particles/" + particleEffect, 0, 0, rotation); controlParticle(p); } if (mFrame >= frames) nextStep(); break; } // Actions are allowed once per second if (get_elapsed_time(mLastAction) >= 1000) mLastAction = -1; // Remove target if its been on a being for more than a minute if (get_elapsed_time(mTargetTime) >= 60000) { mTargetTime = -1; setTarget(NULL); } if (mTarget) { // Find whether target is in range const int rangeX = abs(mTarget->mX - mX); const int rangeY = abs(mTarget->mY - mY); const int attackRange = getAttackRange(); const int inRange = rangeX > attackRange || rangeY > attackRange ? 1 : 0; mTarget->setTargetAnimation( mTargetCursor[inRange][mTarget->getTargetCursorSize()]); if (mTarget->mAction == DEAD) stopAttack(); if (mKeepAttacking && mTarget) attack(mTarget, true); } Being::logic(); }
void LocalPlayer::logic() { // Actions are allowed once per second if (get_elapsed_time(mLastAction) >= 1000) mLastAction = -1; // Show XP messages if (!mMessages.empty()) { if (mMessageTime == 0) { //const Vector &pos = getPosition(); MessagePair info = mMessages.front(); particleEngine->addTextRiseFadeOutEffect( info.first, /*(int) pos.x, (int) pos.y - 48,*/ getPixelX(), getPixelY() - 48, &guiPalette->getColor(info.second), gui->getInfoParticleFont(), true); mMessages.pop_front(); mMessageTime = 30; } mMessageTime--; } if ((mSpecialRechargeUpdateNeeded%11) == 0) { mSpecialRechargeUpdateNeeded = 0; for (std::map<int, Special>::iterator i = mSpecials.begin(); i != mSpecials.end(); i++) { i->second.currentMana += i->second.recharge; if (i->second.currentMana > i->second.neededMana) { i->second.currentMana = i->second.neededMana; } } } mSpecialRechargeUpdateNeeded++; #ifdef EATHENA_SUPPORT // Targeting allowed 4 times a second if (get_elapsed_time(mLastTarget) >= 250) mLastTarget = -1; // Remove target if its been on a being for more than a minute if (get_elapsed_time(mTargetTime) >= 60000) { mTargetTime = -1; setTarget(NULL); mLastTarget = -1; } #endif if (mTarget) { if (mTarget->getType() == Being::NPC) { // NPCs are always in range mTarget->setTargetAnimation( mTargetCursor[0][mTarget->getTargetCursorSize()]); } else { #ifdef TMWSERV_SUPPORT // Find whether target is in range const int rangeX = abs(mTarget->getPosition().x - getPosition().x); const int rangeY = abs(mTarget->getPosition().y - getPosition().y); #else // Find whether target is in range const int rangeX = abs(mTarget->getTileX() - getTileX()); const int rangeY = abs(mTarget->getTileY() - getTileY()); #endif const int attackRange = getAttackRange(); const int inRange = rangeX > attackRange || rangeY > attackRange ? 1 : 0; mTarget->setTargetAnimation( mTargetCursor[inRange][mTarget->getTargetCursorSize()]); if (mTarget->mAction == DEAD) stopAttack(); if (mKeepAttacking && mTarget) attack(mTarget, true); } } Player::logic(); }
bool Player::inMyAttackRange(const Player *other, int distance_fix) const { if (attack_range_pair.contains(other)) return true; return this != other && distanceTo(other, distance_fix) <= getAttackRange(); }