Ejemplo n.º 1
0
void CannonField::moveShot()
{
	QRegion region = shotRect();
	++timerCount;
	
	QRect shotR = shotRect();

	if (shotR.intersects(targetRect()))
	{
		autoShootTimer->stop();
		emit hit();
		emit canShoot(true);
	}	
	else if (shotR.x() > width() || shotR.y() > height() || shotR.intersects(barrierRect()))
	{
		autoShootTimer->stop();	
		emit missed();
		emit canShoot(true);
	}
	else
	{
		region = region.unite(shotR);
	}

	update(region);
}
Ejemplo n.º 2
0
	void IWeaponAmmo::process(const shared_ptr<CMessage>& message) {
		switch( message->getMessageType() ) {
			case Message::CONTROL: {
				if(_ableToShoot) {
					ControlType type = std::static_pointer_cast<CMessageControl>(message)->getType();

					if(type == Control::LEFT_CLICK) {
						if( canUsePrimaryFire() )
							primaryFire();
					}
					else if(type == Control::RIGHT_CLICK) {
						if( canUseSecondaryFire() )
							secondaryFire();
					}
					else if(type == Control::UNLEFT_CLICK) {
							stopPrimaryFire();
					}
					else if(type == Control::UNRIGHT_CLICK) {
							stopSecondaryFire();
					}
				}

				break;
			}
			case Message::REDUCED_COOLDOWN: {
				reduceCooldown(std::static_pointer_cast<CMessageReducedCooldown>(message)->getPercentCooldown());
				break;								
			}
			case Message::BLOCK_SHOOT: {
				auto blockShootMsg = static_pointer_cast<CMessageBlockShoot>(message);
				_ableToShoot = blockShootMsg->canShoot();
				break;
			}
		}
	} // process
//Fires the weapon at the target
void BaseWeapon::shootAt(AICharacter * target) {
	
	if (canShoot() == true && isInRange(target->Position) == true && _fireCooldownTime <= 0) {

		//reduce the clip size and reset the time until we can fire next
		_shotsInClip--;
		_fireCooldownTime = FireRate;

		_weaponFired = true;

		float calAccuracy = getAccuracyToCharIncCover(target);

		if (rand() % 100 < calAccuracy) {

			//hit target, damage them for the amount of bullets we fire
			for (int i = 0; i < BulletsPerShot; i++) 
				target->damageTaken(Holder);

			_targetPos = target->Position;
			_shotType = kHit;
		}
		//if they AI missed, create a random position near the target for the simulation line to go to
		else {

			_shotType = kMiss;
			_targetPos = target->Position + Vector3((rand() % 30) + - 30, (rand() % 30) + - 30, 0);
		}
	}
}
Ejemplo n.º 4
0
void CannonField::restartGame()
{
    if ( isShooting() )
	autoShootTimer->stop();
    gameEnded = FALSE;
    repaint();
    emit canShoot( TRUE );
}
Ejemplo n.º 5
0
void CannonField::restartGame()
{
	if (isShooting())	
		autoShootTimer->stop();

	gameEnded = false;
	update();
	emit canShoot(true);
}
Ejemplo n.º 6
0
void Game::shoot(int player)
{
	if (canShoot(player))
	{
		m_bullets[player].pos = m_players[player]->m_pos;
		m_bullets[player].dir = m_players[player]->m_dir;
		m_bullets[player].active = true;
		m_bulletsCnt[player]++;
	}
}
Ejemplo n.º 7
0
void CannonField::shoot()
{
    if ( isShooting() )
	return;
    timerCount = 0;
    shoot_ang = ang;
    shoot_f = f;
    autoShootTimer->start( 50 );
    emit canShoot( FALSE );
}
Ejemplo n.º 8
0
void        BattleShip::shoot( Container & missiles ) {
  if (canShoot()) {
    // missiles.push(new PlasmaCanon(posX + 12, posY + (-2), 1, -.05));
    // missiles.push(new PlasmaCanon(posX + 15, posY + (-1), 1, -.025));
    missiles.push(new PlasmaCanon(posX + 20, posY + 0, 1, 0));
    // missiles.push(new PlasmaCanon(posX + 15, posY + 1, 1, .025));
    // missiles.push(new PlasmaCanon(posX + 12, posY + 2, 1, .05));
    lastShoot = getMilliCount() / 1000.f;
  }
}
Ejemplo n.º 9
0
void EnemyView::shoot(list<AmmoView*>* air, Int2 angle)
{	
	if(state_b == DEAD)
		return;

	list<Ammo*> tmp;
	AmmoView* av;
	
	if(type == REBEL)
	{
		if(current_anim==REBEL_KNIFE && state_b==PRESHOOT)
		{
			Enemy::knife();
		}
		else
		{
			state_b = PRESHOOT;
			state_p = WAIT;
			save_air = air;
			save_angle = angle;
			changeAnimation(REBEL_KNIFE,false,REBEL_WATCH);
		}
	}

	else if(type == BOWSER)
	{
		if(current_anim==BOWSER_FIRE && state_b==PRESHOOT)
		{
			Enemy::shoot(&tmp,angle);
		}
		else
		{
			state_b = PRESHOOT;
			state_p = WAIT;
			save_air = air;
			save_angle = angle;
			changeAnimation(BOWSER_FIRE,false,BOWSER_STAND);
		}
	}

	else if(type == FLYING)
	{
		if(canShoot()) {
			Enemy::shoot(&tmp,angle);
		}
	}	

	for(list<Ammo*>::iterator a = tmp.begin(); a != tmp.end(); a++)
    {
    	av = new AmmoView(**a);
    	air->push_back(av);
    	tmp.erase(a++);
    }

}
Ejemplo n.º 10
0
void CannonField::shoot()
{
	if (isShooting())
		return;
	
	timerCount = 0;
	shootAngle = currentAngle;
	shootForce = currentForce;
	autoShootTimer->start(5);
	emit canShoot(false);
}
Ejemplo n.º 11
0
void CannonField::moveShot()
{
    QRegion r( shotRect() );
    timerCount++;

    QRect shotR = shotRect();

    if ( shotR.intersects( targetRect() ) ) {
	autoShootTimer->stop();
	emit hit();
	emit canShoot( TRUE );
    } else if ( shotR.x() > width() || shotR.y() > height() ) {
	autoShootTimer->stop();
	emit missed();
	emit canShoot( TRUE );
    } else {
	r = r.unite( QRegion( shotR ) );
    }

    repaint( r );
}
Ejemplo n.º 12
0
void
allocEnemies(batstat *batstats)
{
  batstat        *aBatstat, *aBatstat2;

  for (aBatstat = batstats; aBatstat; aBatstat = aBatstat->next) {
    for (aBatstat->noEnemies = 0, aBatstat2 = batstats;
         aBatstat2; aBatstat2 = aBatstat2->next) {
      if (aBatstat != aBatstat2) {
        if (atwar(aBatstat->who, aBatstat2->who) ||
            (atwar(aBatstat2->who, aBatstat->who) &&
             canShoot(aBatstat2->groups))) {
          aBatstat->noEnemies++;
        }
      }
    }

    if (aBatstat->noEnemies) {
      batstat       **enemy;

      aBatstat->enemies = alloc(sizeof(batstat *) * aBatstat->noEnemies);

      assert(aBatstat->enemies != NULL);
      for (enemy = aBatstat->enemies, aBatstat2 = batstats;
           aBatstat2; aBatstat2 = aBatstat2->next) {
        if (aBatstat != aBatstat2) {
          if (atwar(aBatstat->who, aBatstat2->who) ||
              (atwar(aBatstat2->who, aBatstat->who) &&
               canShoot(aBatstat2->groups))) {
            *enemy = aBatstat2;
            enemy++;
          }
        }
      }
    }
  }
}
Ejemplo n.º 13
0
void AirGunTurret::shoot()
{
    if (!canShootNow)
        return;

    upgradeBarrelCoordinates();

    Shell *shell = new Shell(angle, barrelX, barrelY);
    shellList->prepend(shell);
    this->scene()->addItem(shell);

    playShootAnimation();

//    soundShoot.play();

    canShootNow = false;
    QTimer::singleShot(2000, this, SLOT(canShoot()));
}
Ejemplo n.º 14
0
	void IWeaponFeedback::process(const shared_ptr<CMessage>& message) {
		switch( message->getMessageType() ) {
			case Message::PRIMARY_SHOOT: {
				if(_ableToShoot) {
					shared_ptr<CMessagePrimaryShoot> primaryShootMsg = static_pointer_cast<CMessagePrimaryShoot>(message);

					if( primaryShootMsg->getShoot() ) {
						primaryFire();
						_primaryFireIsActive = true;
						//emitParticle(true);
					}
					else {
						stopPrimaryFire();
						_primaryFireIsActive = false;
					}
				}

				break;
			}
			case Message::SECONDARY_SHOOT: {
				if(_ableToShoot) {
					shared_ptr<CMessageSecondaryShoot> secondaryShootMsg = static_pointer_cast<CMessageSecondaryShoot>(message);

					if( secondaryShootMsg->getShoot() ) {
						secondaryFire();
						_secondaryFireIsActive = true;
						//emitParticle(false);
					}
					else {
						stopSecondaryFire();
						_secondaryFireIsActive = false;
					}
				}

				break;
			}
			case Message::BLOCK_SHOOT: {
				auto blockShootMsg = static_pointer_cast<CMessageBlockShoot>(message);
				_ableToShoot = blockShootMsg->canShoot();
				break;
			}
		}
	} // process
Ejemplo n.º 15
0
int
mustBattle(participant *participants)
{
  int             war;
  participant    *part1, *part2;

  pdebug(DFULL, "mustBattle\n");
  war = FALSE;
  for (part1 = participants; part1 && !war; part1 = part1->next) {
    for (part2 = participants; part2; part2 = part2->next) {
      if (part1 != part2) {
        if (atwar(part1->who, part2->who) && canShoot(part1->groups)) {
          war = TRUE;
          break;
        }
      }
    }
  }
  return war;
}
Ejemplo n.º 16
0
bool CannonField::qt_emit( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->signalOffset() ) {
    case 0:
        hit();
        break;
    case 1:
        missed();
        break;
    case 2:
        angleChanged((int)static_QUType_int.get(_o+1));
        break;
    case 3:
        forceChanged((int)static_QUType_int.get(_o+1));
        break;
    case 4:
        canShoot((bool)static_QUType_bool.get(_o+1));
        break;
    default:
        return QWidget::qt_emit(_id,_o);
    }
    return TRUE;
}
Ejemplo n.º 17
0
void monster_autocannon_findenemy(edict_t *self)
{
	edict_t *e = NULL;

	// can we still use our enemy?
	if (self->enemy)
	{
		if (!canShoot(self, self->enemy))
		{
			self->oldenemy = NULL;
			self->enemy = NULL;
		}
		else if (!visible(self, self->enemy))
		{
			self->oldenemy = self->enemy;
			self->enemy = NULL;
		}
		else if (self->enemy->flags & FL_NOTARGET)
		{
			self->oldenemy = NULL;
			self->enemy = NULL;
		}
		else if (self->enemy->health <= 0)
		{
			self->oldenemy = NULL;
			self->enemy = NULL;
		}
	}

	while(self->enemy == NULL)
	{
		e = findradius(e, self->s.origin, AC_RANGE);
		if (e == NULL)
		{
			if (self->oldenemy == NULL)
				return;

			if (level.time > self->timeout)
			{
				self->oldenemy = NULL;
				return;
			}
			self->enemy = self->oldenemy;
			break;
		}


		if (self->spawnflags & AC_SF_BERSERK)
		{
			// attack clients and monsters
			if (!e->client && !(e->svflags & SVF_MONSTER))
				continue;
		}
		else
		{
			// only attack clients
			if (!e->client)
				continue;
		}

		// don't target dead stuff
		if (e->health <= 0)
			continue;

		// don't target notarget stuff
		if (e->flags & FL_NOTARGET)
			continue;

		// don't target other autocannons
		if (Q_stricmp(e->classname, "monster_autocannon") == 0)
			continue;
		
		// don't target self
		if (e == self)
			continue;
		
		// can it be seen?
		if (!visible(self, e))
			continue;

		if (!autocannonInfront(self, e))
			continue;

		if (canShoot(self, e))
			self->enemy = e;
	}
}
Ejemplo n.º 18
0
void getActionSol(Board * const * const board, Board *soldier, Board *target, const int y, const int x)
{
	Units *units = &gameVar.units;
	Time *times = &gameVar.time;

	int prob = rand()%100;
	if (prob < 2 && (target->character == DOC || target->character == NUR)) {
		prob = rand()%100;
	} 

	if (prob < 80) { 
		if (canShoot(board, y, x)) {
			if (target->character == INF) {
				++units->dead;
				--units->infected;

				target->character = DEAD;
				times->elapsed = 0;
				#ifdef DEBUG
					logMsg("Sol kills Inf\n");
				#endif
			} else if (prob < 2 && (target->character == NUR || target->character == DOC)) {
				if (target->character == NUR) {
					--units->nurses;
					#ifdef DEBUG
						logMsg("Sol kills Nur\n");
					#endif
				} else {
					--units->doctors;
					#ifdef DEBUG
						logMsg("Sol kills Doc\n");
					#endif
				}
				++units->dead;

				target->character = DEAD;
				times->elapsed = 0;
			}
		}

		if (target->character == CIT) {
			if (prob >= 80) {
				--units->citizens;
				++units->soldiers;

				target->character = SOL;
				times->elapsed = 0;
				#ifdef DEBUG
					logMsg("Sol converts Cit\n");
				#endif
			}
		} else if (target->character == DEAD) {
			--units->dead;

			target->character = EMPTY;
			#ifdef DEBUG
				logMsg("Sol cleans Dead\n");
			#endif
		}
	}
}
Ejemplo n.º 19
0
/*!
  The advance function does quite a lot for the ship sprite.
  In \a phase 0, if the ship is marked dead, just return. If
  not, move the ship using its current position and velocity.
  Then get the list of all collisions with the ship and run
  through the list.

  If the ship collides with a rock, then if the shield is
  up, destroy the rock. If the shiled is down (normal), mark
  the ship dead and return.

  If the ship collides with a powerup, then if the shield is
  up, mark the powerup destroyed. If the shield is not up,
  apply the powerup to the ship.

  In phase 1, if the ship is marked dead, explode the ship,
  delete it, and return. Otherwise, handle ship rotation,
  breaking, ship velocity, an teleporting. also update the
  image if the ship is rotating, and the exhaust image, if
  the engine is on. If the shiled is up, handle its image
  and age. Finally, in phase one, handle the firing of the
  missiles.
  \internal
 */
void KShip::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	if (isDead() || teleport_)
	    return;
	KSprite::advance(phase);
	QList<QGraphicsItem*> hits = ship_->collidingItems();
	QList<QGraphicsItem*>::Iterator i;
	for (i=hits.begin(); i!=hits.end(); ++i) {
	    if ((*i)->type() <= ID_Base)
		continue;
	    KSprite* sprite = (KSprite*)(*i);
	    if (sprite->isRock()) {
		if (shield_->isUp()) {
		    /*
		      The ship hit a rock with the shield up.
		      The rock is marked for death, which will
		      cause it to break up or just disappear in
		      in phase 1.

		      The shield's strength is reduced by an
		      amount commensurate with the rock size.
		      If the strength goes to 0, the shield
		      will be dropped in phase 1.
		     */
		    sprite->markDead();
		    int s = 1;
		    if (sprite->isLargeRock())
			s = 3;
		    else if (sprite->isMediumRock())
			s = 2;
		    int pl = s * (SHIELD_HIT_COST - (shield_->strength()*2));
		    shield_->reduceStrength(s);
		    reducePowerLevel(pl);
		}
		else {
		    /*
		      The ship hit a rock with the shield down.
		      Mark the ship dead and return. The ship
		      will be exploded in phase 1.
		     */
                    view_->setCanPause(false);
		    markDead();
		    shield_->markDead();
		    return;
		}
	    }
	    else if (sprite->isPowerup()) {
		if (shield_->isUp()) {
		    sprite->markDead();
		}
		else {
		    /*
		      The ship hit a powerup with the shield down.
		      Mark the powerup for apply. It will be applied
		      to the ship in phase 1, if the ship survives.
		      Also mark the powerup dead, ie consumed.
		     */
		    sprite->markApply();
		    sprite->markDead();
		    return;
		}
	    }
            else if (powerLevel() <= EMPTY_SHIP_POWER_LEVEL) {
                ship_->markDead();
                shield_->markDead();
            }
	}
    }
    else { // phase 1
	if (isDead() || dying()) {
	    explode(); // shatters the ship into spinning fragments.
	    delete this;
	    return;
	}
	if (rotateSlow_)
	    rotateSlow_--;

	if (rotateLeft_) {
	    angleIndex_ -= rotateSlow_ ? 1 : rotationRate_;
	    if (angleIndex_ < 0)
		angleIndex_ = SHIP_STEPS-1;
	    angle_ = angleIndex_ * PI_X_2 / SHIP_STEPS;
	    cosangle_ = cos(angle_);
	    sinangle_ = sin(angle_);
	}

	if (rotateRight_) {
	    angleIndex_ += rotateSlow_ ? 1 : rotationRate_;
	    if (angleIndex_ >= SHIP_STEPS)
		angleIndex_ = 0;
	    angle_ = angleIndex_ * PI_X_2 / SHIP_STEPS;
	    cosangle_ = cos(angle_);
	    sinangle_ = sin(angle_);
	}

	if (isBraking()) {
	    stopEngine();
	    stopRotation();
	    if ((fabs(dx_) < 2.5) && (fabs(dy_) < 2.5)) {
		dx_ = 0.0;
		dy_ = 0.0;
		setVelocity(dx_,dy_);
		releaseBrakes();
	    }
	    else {
		double motionAngle = atan2(-dy_,-dx_);
		if (angle_ > M_PI)
		    angle_ -= PI_X_2;
		double angleDiff = angle_ - motionAngle;
		if (angleDiff > M_PI)
		    angleDiff = PI_X_2 - angleDiff;
		else if (angleDiff < -M_PI)
		    angleDiff = PI_X_2 + angleDiff;
		double fdiff = fabs(angleDiff);
		if (fdiff > 0.08) {
		    if (angleDiff > 0)
			rotateLeft_ = true;
		    else if (angleDiff < 0)
			rotateRight_ = true;
		    if (fdiff > 0.6)
			rotationRate_ = brakeForce() + 1;
		    else if (fdiff > 0.4)
			rotationRate_ = 2;
		    else
			rotationRate_ = 1;

		    if (rotationRate_ > 5)
			rotationRate_ = 5;
		}
		else if ((fabs(dx_)>1) || (fabs(dy_)>1)) {
		    startEngine();
		    // we'll make braking a bit faster
		    dx_ += cosangle_/6 * (brakeForce() - 1);
		    dy_ += sinangle_/6 * (brakeForce() - 1);
		    reducePowerLevel(BRAKE_ON_COST);
		    KExhaust::add(ship_->x() + 10 - cosangle_*11,
				  ship_->y() + 10 - sinangle_*11,
				  dx_-cosangle_,
				  dy_-sinangle_,
				  brakeForce()+1);
		}
	    }
	}
	else if (engineIsOn()) {
	    /*
	      The ship has a terminal velocity, but trying
	      to go faster still uses fuel (can go faster
	      diagonally - don't care).
	    */
	    double thrustx = cosangle_/8;
	    double thrusty = sinangle_/8;
	    if (fabs(dx_ + thrustx) < MAX_SHIP_SPEED)
		dx_ += thrustx;
	    if (fabs(dy_ + thrusty) < MAX_SHIP_SPEED)
		dy_ += thrusty;
	    setVelocity(dx_,dy_);
	    reducePowerLevel(5);
	    KExhaust::add(x() + 10 - cosangle_*10,
			  y() + 10 - sinangle_*10,
			  dx_-cosangle_,
			  dy_-sinangle_,
			  3);
	}

	setImage(angleIndex_ >> 1);

	if (teleport_) {
	    int ra = rand() % 10;
	    if(ra == 0)
		ra += rand() % 20;
	    int xra = ra * 60 + ((rand() % 20) * (rand() % 20));
	    int yra = ra * 50 - ((rand() % 20) * (rand() % 20));
	    setPos(xra,yra);
	    teleport_ = false;
	    if (teleportCount_ > 0) {
		--teleportCount_;
		view_->markVitalsChanged();
	    }
	    wrap();
	}

	if (shield_->isUp()) {
	    /*
	      The shield's position always depends on the
	      ship's position.
	     */
	    static int sf = 0;
	    sf++;
	    if (sf % 2)
		shield_->advanceImage();
	    shield_->setPos(x()-5,y()-5);
	    shield_->show();
	}

	if (isShooting()) {
	    int maxMissiles = firePower_ + 2;
	    if (canShoot() && (KMissile::missiles() < maxMissiles)) {
		KMissile* missile = new KMissile();
		missile->setMaximumAge(12);
		missile->setPos(11 + x() + cosangle_ * 11,
				11 + y() + sinangle_ * 11);
		missile->setVelocity(dx_ + cosangle_ * MISSILE_SPEED,
				     dy_ + sinangle_ * MISSILE_SPEED);
		missile->show();
		reducePowerLevel(1);
		view_->reportMissileFired();
		int delay = 5 - firePower_;
		if (delay < 0)
		    delay = 0;
		delayShooting(delay); // delay firing next missile.
	    }
	    decrementNextShotDelay();
	}
    }
}