Example #1
0
int checkColPlayerDown(int x, int y, int level, int offset) {
	int i;
	int count = 0;
	// First, we check the pixels directly below the player...
	for (i = 1; i < 8; i++) { // I don't know why, but if you start at 0, you can jump 1px into the wall.
								// Because Bob is only 7px wide...

								// And it has to be "< 8", we don't want to forget the pixel at the very right of Bob...
		if (getPixel((x + i), (y + 8)) != 0) {
			count++;
		}
	}
	if (count == 0) {
		return 0; // All pixels below the player are white. There is nothing!
	}

	if (count > 0) {
		y = translatepixelval(y, &count) + 1; // Remember: Below!
		x = translatepixelval((x + offset), &count);
		colY = y;
		colX = x;
		if (isBlock(level, x, y) != 0) {
			return 1;
		}
		if (count > 1) { // Player is 7px wide...
			// We are off...
			if (isBlock(level, (x + 1), y) != 0) {
				colX++;
				return 4;
			}
		}
		if (isBox(level, x, y) != 0) {
			return 2;
		}
		if (count > 1) {
			if (isBox(level, (x + 1), y) != 0) {
				colX++;
				return 5;
			}
		}
		if (isCoin(level, x, y) != 0) {
			return 3;
		}
		if (count > 1) {
			if (isCoin(level, (x + 1), y) != 0) {
				colX++;
				return 6;
			}
		}
		for (i = 0; i < HOWMANYENEMYS; i++) {
			if (isEnemy(level, x, y, i) != 0) {
				return 7;
			}
			if (isEnemy(level, (x + 1), y, i) != 0) {
				colX++;
				return 8;
			}
		}
	}
}
static bool checkWhose(HighlightItem::Whose whose, S32 objectTeam, S32 playerTeam)
{
   switch(whose)
   {
      case HighlightItem::Any:
         return true;

      case HighlightItem::Team:
         return isTeam(objectTeam, playerTeam);

      case HighlightItem::TorNeut:
         return isTeam(objectTeam, playerTeam) || isNeut(objectTeam);

      case HighlightItem::Enemy:
         return isEnemy(objectTeam, playerTeam);

      case HighlightItem::Hostile:
         return isHost(objectTeam);

      case HighlightItem::EorHostile:
         return isEnemy(objectTeam, playerTeam) || isHost(objectTeam);

      case HighlightItem::EorHorN:
         return isEnemy(objectTeam, playerTeam) || isHost(objectTeam) || isNeut(objectTeam);

      case HighlightItem::Neutral:
         return isNeut(objectTeam);

      default:
         TNLAssert(false, "Unknown value of whose!");
         return false;
   }
}
Example #3
0
int checkColPlayerUp(int x, int y, int level, int offset) {
	int i;
	int count = 0;
	// First, we check the pixels directly above the player...
	for (i = 1; i < 7; i++) {
		if (getPixel((x + i), (y - 1))) {
			count++;
		}
	}
	if (count == 0) {
		return 0; // All pixels above the player are white. There is nothing!
	}

	if (count > 0) {
		y = translatepixelval(y, &count);
		x = translatepixelval((x + offset), &count);
		colY = y;
		colX = x;
		if (isBlock(level, x, y) != 0) {
			return 1;
		}
		if (count > 1) { // Player is 7px wide...
			// We are off...
			if (isBlock(level, (x + 1), y) != 0) {
				colX++;
				return 4;
			}
		}
		if (isBox(level, x, y) != 0) {
			return 2;
		}
		if (count > 1) {
			if (isBox(level, (x + 1), y) != 0) {
				colX++;
				return 5;
			}
		}
		if (isCoin(level, x, y) != 0) {
			return 3;
		}
		if (count > 1) {
			if (isCoin(level, (x + 1), y) != 0) {
				colX++;
				return 6;
			}
		}
		for (i = 0; i < HOWMANYENEMYS; i++) {
			if (isEnemy(level, x, y, i) != 0) {
				return 7;
			}
			if (isEnemy(level, (x + 1), y, i) != 0) {
				colX++;
				return 8;
			}
		}
	}
}
Example #4
0
int checkColPlayerLeft(int x, int y, int level, int offset) {
	int i;
	int count = 0;
	for (i = 0; i < 8; i++) {
		if (getPixel((x - 1), (y + i)) != 0) {
			count++;
		}
	}
	if (count == 0) {
		return 0;
	}
	if (count > 0) {
		x = translatepixelval((x + offset), &count);
		y = translatepixelval(y, &count);
		colY = y;
		colX = x;
		if (isBlock(level, x, y) != 0) {
			return 1;
		}
		if (count > 0) {
			if (isBlock(level, x, (y + 1)) != 0) {
				colY++;
				return 4;
			}
		}
		if (isBox(level, x, y) != 0) {
			return 2;
		}
		if (count > 0) {
			if (isBox(level, x, (y + 1)) != 0) {
				colY++;
				return 5;
			}
		}
		if (isCoin(level, x, y) != 0) {
			return 3;
		}
		if (count > 0) {
			if (isBox(level, x, (y + 1)) != 0) {
				colY++;
				return 6;
			}
		}
		for (i = 0; i < HOWMANYENEMYS; i++) {
			if (isEnemy(level, x, y, i) != 0) {
				return 7;
			}
			if (isEnemy(level, x, (y + 1), i) != 0) {
				colY++;
				return 8;
			}
		}
	}
}
Example #5
0
bool Monster::addEnemy(Creature* target, bool print) {
    if(isEnemy(target))
        return false;

    if(print) {
      if(aggroString[0])
          broadcast(nullptr, getRoomParent(), "%M says, \"%s.\"", this, aggroString);

      target->printColor("^r%M attacks you.\n", this);
      broadcast(target->getSock(), getRoomParent(), "%M attacks %N.", this, target);
    }

    if(target->isPlayer()) {
      // take pity on these people
      if(target->isEffected("petrification") || target->isUnconscious())
          return(0);
      // pets should not attack master
      if(isPet() && getMaster() == target)
          return(false);
    }
    if(target->isPet()) {
        addEnemy(target->getMaster());
    }

    adjustThreat(target, 0);
    return(true);
}
Example #6
0
void CHLDMBot :: handleWeapons ()
{
	//
	// Handle attacking at this point
	//
	if ( m_pEnemy && !hasSomeConditions(CONDITION_ENEMY_DEAD) && 
		hasSomeConditions(CONDITION_SEE_CUR_ENEMY) && wantToShoot() && 
		isVisible(m_pEnemy) && isEnemy(m_pEnemy) )
	{
		CBotWeapon *pWeapon;

		pWeapon = getBestWeapon(m_pEnemy,true,true,(m_pEnemy==m_NearestBreakable)&&!rcbot_melee_only.GetBool());

		if ( m_bWantToChangeWeapon && (pWeapon != NULL) && (pWeapon != getCurrentWeapon()) && pWeapon->getWeaponIndex() )
		{
			//selectWeaponSlot(pWeapon->getWeaponInfo()->getSlot());
			selectWeapon(pWeapon->getWeaponIndex());
		}

		setLookAtTask((LOOK_ENEMY));

		///battack = true;

		if ( !handleAttack ( pWeapon, m_pEnemy ) )
		{
			m_pEnemy = NULL;
			m_pOldEnemy = NULL;
			wantToShoot(false);
		}
	}
}
void SpaceStation::drawOnRadar(sf::RenderTarget& window, sf::Vector2f position, float scale, bool long_range)
{
    sf::Sprite objectSprite;
    textureManager.setTexture(objectSprite, radar_trace);
    objectSprite.setPosition(position);
    float sprite_scale = scale * getRadius() * 1.5 / objectSprite.getTextureRect().width;

    if (!long_range)
    {
        sprite_scale *= 0.7;
        drawShieldsOnRadar(window, position, scale, sprite_scale, true);
    }
    sprite_scale = std::max(0.15f, sprite_scale);
    objectSprite.setScale(sprite_scale, sprite_scale);
    if (my_spaceship)
    {
        if (isEnemy(my_spaceship))
            objectSprite.setColor(sf::Color::Red);
        if (isFriendly(my_spaceship))
            objectSprite.setColor(sf::Color(128, 255, 128));
    }else{
        objectSprite.setColor(factionInfo[getFactionId()]->gm_color);
    }
    window.draw(objectSprite);
}
Example #8
0
string Rogue::attackText (string enemyName)
{
    if (!isEnemy())
        return "\tYou slash at the " + enemyName + " with your dagger.";
    else 
        return "\tThe " + enemyName + " slashes at you with his dagger.";
}
Example #9
0
/***********************************************************************
     * Character
     * checkShot

***********************************************************************/
bool fired::Character::checkShot(fired::Shot *shot) {
	if (dead) return false;

	sf::Vector2f  dir(shot->velocity * frameClock);
	sf::FloatRect ray(shot->pos, dir);

	sf::Vector2f c, n, c2, n2;
	float dist;

	if (lineBoxCollision(phys.rect, ray, &c, &n, &dist)) {
		if (!isEnemy(shot->fraction)) return false;

		if (shot->explosive) {
			world->addExplosion(c, shot->explosionRadius, 0.5f, shot->knockback, shot->damage, shot->owner, shot->fraction);
		} else {
			phys.velocity.x -= n.x * shot->knockback;
			world->addBloodSplash(c, n * 200.0f, 20);
			damage(shot->damage, c, shot->knockback, shot->owner);
		}

		return true;
	}


	return false;
}
Example #10
0
void SpaceStation::takeDamage(float damage_amount, DamageInfo info)
{
    shields -= damage_amount;
    if (shields < 0)
    {
        if (info.type != DT_EMP)
        {
            hull_strength -= damage_amount;
            if (hull_strength <= 0.0)
            {
                ExplosionEffect* e = new ExplosionEffect();
                e->setSize(getRadius());
                e->setPosition(getPosition());

                if (info.instigator)
                {
                    if (isEnemy(info.instigator))
                        info.instigator->addReputationPoints((hull_max + shields_max) * 0.1);
                    else
                        info.instigator->removeReputationPoints((hull_max + shields_max) * 0.1);
                }

                destroy();
            }
        }
        shields = 0;
    }else{
        shieldHitEffect = 1.0;
    }
}
Example #11
0
void Animal::updateOffense()
{
    if (isEnemy()) {
        _offense = powf(_height.getMmLength() / 3, 1.2);
    } else {
        _offense = (_height.getMmLength() / 3) * UserDataManager::getInstance()->getOffenseRate();
    }
}
Example #12
0
bool Monster::nearEnmPly() const {
    for(Player* ply : getConstRoomParent()->players) {
        if(isEnemy(ply) && !ply->flagIsSet(P_DM_INVIS))
            return(true);
    }

    return(false);
}
Example #13
0
QList<ServerPlayer *> AI::getEnemies() const{
    QList<ServerPlayer *> players = room->getOtherPlayers(self);
    QList<ServerPlayer *> enemies;
    foreach (ServerPlayer *p, players)
        if (isEnemy(p)) enemies << p;

    return enemies;
}
Example #14
0
bool Monster::nearEnemy(const Creature* target) const {
    const BaseRoom* room = getConstRoomParent();

    for(Player* ply : room->players) {
        if( isEnemy(ply) && !ply->flagIsSet(P_DM_INVIS) && target->getName() != ply->getName())
            return(true);

    }

    for(Monster* mons : room->monsters) {
        if(isEnemy(mons) && !mons->flagIsSet(M_FAST_WANDER))
            return(true);

    }

    return(false);
}
Example #15
0
bool Selection::isCommandable() const {
	//printf("\n\n\n\n********* selection.isCommandable() ---> isEmpty() [%d] isEnemy() [%d] selectedUnits.size() [%d]\n\n",isEmpty(),isEnemy(),(int)selectedUnits.size());

	return
		isEmpty() == false &&
		isEnemy() == false &&
		(selectedUnits.size() == 1 && selectedUnits.front()->isAlive() == false) == false &&
		selectedUnits.front()->getType()->isCommandable();
}
Example #16
0
bool SpaceStation::canBeDockedBy(P<SpaceObject> obj)
{
    if (isEnemy(obj))
        return false;
    P<SpaceShip> ship = obj;
    if (!ship)
        return false;
    return true;
}
Example #17
0
void Rogue::sidestep ()
{
    eva += 5;

    if (!isEnemy())
      cout << "\tYou take a step to the side, away from your enemy's gaze.\n";
    else
      cout << "\tThe rogue takes a step to the side, why is he so hard to hit?\n";
}
Example #18
0
Player::Player(int index)
{
	player = core->g_pEntList->GetClientEntity(index);
	core->g_pEngine->GetPlayerInfo(index, &pInfo);

	enemy = isEnemy();
	getEyes();
	setType();
	distanceFromMe = myHack->get3dDist(myPlayer.position, position);
}
Example #19
0
bool Monster::nearEnemy() const {
    if(nearEnmPly())
        return(true);

    for(Monster* mons : getConstRoomParent()->monsters) {
        if(isEnemy(mons) && !mons->flagIsSet(M_FAST_WANDER))
            return(true);
    }

    return(false);
}
Example #20
0
void Pawn::checkDiagonal(int verticalDirection,int horizontalDirection) {
	ChessboardPos pos(currntPos.letter + horizontalDirection, currntPos.number + verticalDirection);
	if ( !(pos.isImagine() ) ) {
		if ( board->isFreePos(pos) )
			coveragedPos.insert(pos);
		else
			if ( isEnemy(pos) ) {
				coveragedPos.insert(pos);
				allowedMoves.insert(pos);
			} else 
				(*board)[pos]->support = true;
	}
}
Example #21
0
bool NounShip::canAttachCargo( Noun * pCargo ) const
{
	// make sure the cargo has a context, or isEnemy / isFriend won't work correctly!
	if (! pCargo->context() )
		pCargo->setContext( context() );

	if ( isEnemy( pCargo ) )
	{
		// if someone is trying to unload units onto this ship, allow +4 enemy units over max cargo capacity..
		return (availableCargo() + 4 - enemyUnitCount()) > 0;
	}	

	// friendly or neutral cargo item
	return availableCargo() > 0;
}
Example #22
0
File: rate.c Project: yulcat/shogi
int animalCanFlee(Board board, int x, int y, int type){
	int i, tileToFlee = 0;
	for(i=0; i<animalDirectionCount[type]; i++){
		int dirc = animalDirections[type][i];
		int myX = moveX(x, dirc);
		int myY = moveY(y, dirc);
		if(myX>3 || myX<0 || myY>4 || myY<0)
			continue;
		if(board.tile[myX][myY].occupied == 'o')
			tileToFlee = 1;
		if(isEnemy(board.tile[myX][myY].occupied) && board.tile[myX][myY].myNum == 1)
			return 0;
	}
	return tileToFlee;
}
Example #23
0
void BattleRoles::addTestData(void)
{
	//Role

	auto testData = new TestData();
	testData->autorelease();

	for(auto &data : testData->_roleDatas)
	{
		auto role = BattleRole::create(data);
		if (role->isEnemy()) _enemyRoles.pushBack(role);
		else _selfRoles.pushBack(role);
	}

}
Example #24
0
void Animal::fight(AbstractBattleEntity* entity)
{
    if (canAttack() == false) {
        return;
    }

    _state = AnimalState::Battle;
    _target = entity;
    _target->retain();

    Vec2 originPoint = getPosition();
    Vec2 targetPoint = ZMath::divideInternally(getPosition(), entity->getPosition(), 1, 2);
    auto size = _image->getContentSize() * getScale();
    Vec2 effectPoint = ZMath::divideInternally(getPosition(), entity->getPosition(), 1, 1) + Vec2(0, size.height / 2);

    _timeline->play("default", false);
    _stopMoveAction();
    _moveAction = runAction(RepeatForever::create(Sequence::create(
                                MoveTo::create(0.1f, targetPoint),
    CallFunc::create([this, effectPoint]() {
        // sound effect
        if (isEnemy() || isOpponent()) {
            SoundManager::getInstance()->playFight2Sound();
        } else {
            SoundManager::getInstance()->playFightSound();
        }

        // particle effect
        auto effect = ParticleSystemQuad::create("effect/hit3.plist");
        effect->setScale(getScale());
        effect->setPosition(effectPoint);
        effect->setZOrder(100000);
        effect->setAutoRemoveOnFinish(true);
        auto parent = getParent();
        if (parent) {
            parent->addChild(effect);
        }
    }),
    MoveTo::create(0.3f, originPoint),
    DelayTime::create(0.5f),
    NULL
                            )));
    _moveAction->retain();

    if (startFightCallback) {
        startFightCallback(this, _target);
    }
}
Example #25
0
void VillageControl::onPickupEvent(const Creature* who, const vector<Item*>& items) {
  if (getCollective()->getTerritory().contains(who->getPosition()))
    if (isEnemy(who) && villain)
      if (contains(villain->triggers, AttackTriggerId::STOLEN_ITEMS)) {
        bool wasTheft = false;
        for (const Item* it : items)
          if (myItems.contains(it)) {
            wasTheft = true;
            ++stolenItemCount;
            myItems.erase(it);
          }
        if (getCollective()->hasLeader() && wasTheft) {
          who->playerMessage(PlayerMessage("You are going to regret this", MessagePriority::HIGH));
        }
    }
}
Example #26
0
bool Monster::targetClosestEnemy() {
	auto& game = server.game();
	auto position = getPosition();

	SpectatorList spectators;
	game.getSpectators(spectators, position);

	if (spectators.empty()) {
		target(nullptr);
		return false;
	}

	auto closestDistance = std::numeric_limits<uint32_t>::max();
	CreatureP closestSpectator;

	for (auto spectator : spectators) {
		if (!isEnemy(*spectator)) {
			continue;
		}

		if (!canAttack(*spectator)) {
			continue;
		}

		auto spectatorPosition = spectator->getPosition();
		if (!game.isSightClear(position, spectatorPosition, true)) {
			continue;
		}

		auto distance = position.distanceTo(spectatorPosition);
		if (distance < closestDistance) {
			closestSpectator = spectator;
			if (distance == 1) {
				break;
			}

			closestDistance = distance;
		}
	}

	if (closestSpectator == nullptr) {
		target(nullptr);
		return false;
	}

	return target(closestSpectator);
}
Example #27
0
/***********************************************************************
     * Character
     * checkBroadShot

***********************************************************************/
void fired::Character::checkBroadShot(fired::BroadShot *shot) {
	if (dead) return;
	sf::Vector2f c;

	if (phys.rect.intersects(shot->shot)) {
		if (!isEnemy(shot->fraction)) return;

		c = rectCenter(phys.rect);
		c.x += shot->normal.x * phys.size.x / 2.0f;

		phys.velocity -= shot->normal * shot->knockback;
		world->addBloodSplash(c, shot->normal * 200.0f, 20);
		damage(shot->damage, c, shot->knockback, shot->owner);

		if (world->isCharExists(shot->owner)) if (dead) shot->owner->gainXP(stats.maxHP);
	}
}
Example #28
0
/***********************************************************************
     * Character
     * checkMeleeShot

***********************************************************************/
void fired::Character::checkMeleeShot(fired::MeleeShot *shot) {
	if (dead) return;

	sf::FloatRect ray(shot->pos, shot->direction);
	sf::Vector2f c, n, c2, n2;
	float dist;

	if (lineBoxCollision(phys.rect, ray, &c, &n, &dist)) {
		if (!isEnemy(shot->fraction)) return;

		phys.velocity += vNorm(shot->direction) * shot->knockback;
		world->addBloodSplash(c, n * 200.0f, 20);
		damage(shot->damage, c, shot->knockback, shot->owner);

		if (world->isCharExists(shot->owner)) if (dead) shot->owner->gainXP(stats.maxHP);
	}
}
Example #29
0
void VillageControl::considerWelcomeMessage() {
  if (!getCollective()->hasLeader())
    return;
  if (villain)
    if (villain->welcomeMessage)
      switch (*villain->welcomeMessage) {
        case DRAGON_WELCOME:
          for (Position pos : getCollective()->getTerritory().getAll())
            if (Creature* c = pos.getCreature())
              if (c->isAffected(LastingEffect::INVISIBLE) && isEnemy(c) && c->isPlayer()
                  && getCollective()->getLeader()->canSee(c->getPosition())) {
                c->playerMessage(PlayerMessage("\"Well thief! I smell you and I feel your air. "
                      "I hear your breath. Come along!\"", MessagePriority::CRITICAL));
                villain->welcomeMessage.reset();
              }
          break;
      }
}
Example #30
0
File: rate.c Project: yulcat/shogi
int getProfit(Tile tile){ // Get profit from cost comparing
	char target = tile.occupied;
	if(isEnemy(target)==0 || tile.myNum == 0)
		return 0;
		// If target is not enemy, or there is no mine nearby, Profit is 0.
	int enemyLoss = typeToScore(tile.occupied);
	if(tile.myNum > tile.enemyNum)
		return -enemyLoss;
		// If mine is outnumbered, count it profit.
	int i, minMyLoss = typeToScore(tile.myReach[0]);
	for(i=0; i<tile.enemyNum; i++){
		int myLoss = typeToScore(tile.myReach[i]);
		if(minMyLoss > myLoss)
			minMyLoss = myLoss;
	}
	return -(enemyLoss + minMyLoss);
	// If enemy can retake the tile, calculate profit and loss.
}