void DefenderWeaponBehaviour::OnPrimaryFire(ComponentWrapper cWeapon, WeaponInfo& wi) { cWeapon["TriggerHeld"] = true; if (canFire(cWeapon, wi)) { fireShell(cWeapon, wi); } }
void Stage::addUnit(Unit* spr){ if(spr->isBullet() && spr->isFromHero() && canFire()) { currBullets++; } units.push_back(spr); }
void MissileWeapon::fire(float angle, Entity* entity) { if(entity->getIdentification()->getName()=="MainChar") std::cout << fireTimer.asSeconds() << " " << initalFireTimer.asSeconds() << std::endl; if(!canFire()) return; unsigned int id = ComponentBase::getNewID(); sf::Vector2f pos = entity->getPosition()->getPosition(); pos.x += 40*std::cos(angle*0.0174532925); pos.y += -40*std::sin(angle*0.0174532925); Entity* bullet = new Entity(id); int bulletSpeed = 10; bullet->setPosition(std::make_shared<WorldPositionComponent>(pos, entity->getPosition()->getLayer(), (float)angle*0.0174532925)); bullet->setRender(std::make_shared<StaticSpriteComponent>("assets/art/SuperMetroidSamus.png", sf::IntRect(423,29,16,6))); bullet->setPhysics(std::make_shared<SimpleBoxPhysics>(bullet->getID(), sf::Vector2f(10,5), 0, PhysicsOptions::isBullet, bullet->getPosition())); bullet->getPhysics()->getBody()->SetLinearVelocity(b2Vec2(std::cos((float)angle*0.0174532925)*bulletSpeed, std::sin((float)angle*0.0174532925)*bulletSpeed)); bullet->getPhysics()->getBody()->SetGravityScale(0); bullet->addScript(std::make_shared<KillScript>(true, damage, sf::Time::Zero)); bullet->addScript(std::make_shared<ExplodeScript>(damage/10)); bullet->setMovement(std::make_shared<AccelerateMovement>(sf::Vector2f(std::cos((float)angle*0.0174532925)*bulletSpeed, std::sin((float)angle*0.0174532925)*bulletSpeed),100)); bullet->setIdentification(entity->getIdentification()); ComponentManager::getInst().addEntity(id, bullet); fireTimer = sf::Time(initalFireTimer); if(currClip!=-1) currClip--; }
NO_SANITIZE_ADDRESS void TimerBase::runInternal() { if (!canFire()) return; m_weakPtrFactory.revokeAll(); TRACE_EVENT0("blink", "TimerBase::run"); #if DCHECK_IS_ON() DCHECK_EQ(m_thread, currentThread()) << "Timer posted by " << m_location.function_name() << " " << m_location.file_name() << " was run on a different thread"; #endif if (m_repeatInterval) { double now = timerMonotonicallyIncreasingTime(); // This computation should be drift free, and it will cope if we miss a // beat, which can easily happen if the thread is busy. It will also cope // if we get called slightly before m_unalignedNextFireTime, which can // happen due to lack of timer precision. double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFireTime, m_repeatInterval); setNextFireTime(timerMonotonicallyIncreasingTime(), intervalToNextFireTime); } else { m_nextFireTime = 0; } fired(); }
void RocketLauncher::fireAtObject(WorldObject* target) { if (canFire()) { Rocket* rocket = WorldObjectBuilder(projectileName()).buildRocket(); setupRocket(rocket, target); World::instance()->god().scheduleSpawn(rocket); onFired(); } }
/** * Fire a new bullet from the gun. * * @return The new bullet. */ VGameEntity* Gun::fire() { if (canFire()) { fOffset *= -1; resetTime(); return fEntityFactory->createBullet(fShip->getPosition() + fOffset, fShip->getDirection(), fShip->getGroup(), fBulletType); } else { return 0; } }
bool ShootingWeapon::startFire(Unit *un) { if(canFire(un) && un != NULL){ unitToShoot = un; // int timerInterval = int(distanceBetweenUnits(agent, unitToShoot)/proyectileVelocity); secureStartTimer(timerID, timerInterval); return true; } return false; }
void Tank::fireShell() { if(canFire()) { // Set fire counter fireCounter = 80; // Decrement ammo numberOfShells--; } }
bool ShootingWeapon::startFire(const QPointF &pt) { if(canFire(pt)) { pointToShoot = pt; // int timerInterval = int(distanceBetweenUnits(agent, unitToShoot)/proyectileVelocity); secureStartTimer(timerID, timerInterval); return true; } return false; }
void Enemy::tick(float delta) { movement(delta); if(canFire()) fire(); if(getCollider()->collides(SphereCollider(Game::getGame().getPlayer().getPosition(), 1))) { // TODO: what side we were hit on Connection::getInstance().write("EVN#1;0;"); destroy(); } }
// Use with the npc to fire at a requested target // Will not fire if not allowed to (out of ammo etc.) // NOTE: If you do not restrict fire radius in the calling method // this method will fire in any direction. void Weapon::npcFire(float targetx, float targety, Handlers* handlers){ // Set shooting direction if (targetx > locX ) lookingRight = true; if (targetx < locX) lookingRight = false; // Set the rotation because the class that calls this might // need it even if it does not fire successfully. // Get angle mTheta = (float)atan2((double)(targety - locY), (double)(targetx - locX)); // Set rotation rotation = (float)(mTheta * (180.0f / 3.14159f)); // Clamp rotation if (rotation < -90.0f) rotation += 180.0f; if (rotation > 90.0f) rotation -= 180.0f; // Check if rotation is valid and restrict angle if (lookingRight){ if (rotation < minAngle){ //rotation = minAngle; rotation = 0.0f; return; } else if (rotation > maxAngle){ //rotation = maxAngle; rotation = 0.0f; return; } } else { if (rotation > -minAngle){ //rotation = -minAngle; rotation = 0.0f; return; } else if (rotation < -maxAngle){ //rotation = -maxAngle; rotation = 0.0f; return; } } // Check for fire shot if (canFire()){ fire(targetx, targety, handlers); } }
// Update weapon input // Note: if this is an NPC weapon, do not call this method void Weapon::updateInput(KeyHandler* mKeyH, MouseHandler* mMouseH, Handlers* handlers){ // Get target shot location float targetX = ((Camera2D*)handlers->camera)->toLevelX(mMouseH->getX()); float targetY = ((Camera2D*)handlers->camera)->toLevelY(mMouseH->getY()); // Set shooting direction if (targetX > locX ) lookingRight = true; if (targetX < locX) lookingRight = false; // Set rotation // Parent class that calls this (UFO or Player should grab the // rotation if it is needed. (Player needs to rotate arm) // Get angle mTheta = (float)atan2((double)(targetY - locY), (double)(targetX - locX)); // Set rotation rotation = (float)(mTheta * (180.0f / 3.14159f)); // Clamp rotation if (rotation < -90.0f) rotation += 180.0f; if (rotation > 90.0f) rotation -= 180.0f; // Check if rotation is valid and restrict angle if (lookingRight){ if (rotation < minAngle) rotation = minAngle; else if (rotation > maxAngle) rotation = maxAngle; } else { if (rotation > -minAngle) rotation = -minAngle; else if (rotation < -maxAngle) rotation = -maxAngle; } // Check for fire shot if (canFire() && ((firetype == FIRETYPE_SINGLE && mMouseH->isLeftDown() && !mMouseH->wasLeftDown()) || (firetype == FIRETYPE_RAPID && mMouseH->isLeftDown()))){ fire(targetX, targetY, handlers); } if (mKeyH->keyPressed(KEY_R)) reload(); }
void AIConditionalAction::step(float dt) { // if (stepCount%AI_CHECKING_INTERVAL == 0) { // } if (canFire()){ if (!isFired) { m_pInnerAction->startWithTarget(m_pTarget); isFired = true; } else { m_pInnerAction->step(dt); } } m_elapsed += dt; stepCount++; }
std::vector<Bullet*> RocketLauncher::fire(Point position, Direction direction, Rect boundingArea) { std::vector<Bullet*> bullets; if (canFire()) { switch (direction) { case Left: { double degrees = 145; double radians = -((degrees * 2.0 * 3.141) / 360.0); bullets.push_back(new Rocket(position.x(), position.y(), cos(radians), sin(radians), 5, 60, boundingArea, Element('\\', COLOR_WHITE))); } break; case Right: { double degrees = 35; double radians = -((degrees * 2.0 * 3.141) / 360.0); bullets.push_back(new Rocket(position.x(), position.y(), cos(radians), sin(radians), 5, 60, boundingArea, Element('/', COLOR_WHITE))); } break; case Center: { double degrees = 90; double radians = -((degrees * 2.0 * 3.14159265) / 360.0); bullets.push_back(new Rocket(position.x(), position.y(), cos(radians), sin(radians), 5, 60, boundingArea, Element('|', COLOR_WHITE))); } break; } if (!_modifiers->isModifierActive(Modifier::mInfiniBullets)) { _ammunition--; } _fireSound->play(); resetCooldownTimer(); } return bullets; }
virtual void tick(const float dt) { Object::tick(dt); if (!_broken && _state.fire) { bool fire = false; if (_fire.tick(dt)) { _fire.reset(); if (canFire()) { fire = true; spawn(_object, _object, v2<float>(), _direction); } } int dirs = 16/* bullet->get_directions_number() */, d = _direction.get_direction(dirs); v2<float> dpos; dpos.fromDirection((d + dirs / 4) % dirs, dirs); dpos *= 16; if (fire) { spawn(_object, _object, dpos, _direction); spawn(_object, _object, -dpos, _direction); } } }
NO_LAZY_SWEEP_SANITIZE_ADDRESS void TimerBase::runInternal() { if (!canFire()) return; TRACE_EVENT0("blink", "TimerBase::run"); ASSERT_WITH_MESSAGE(m_thread == currentThread(), "Timer posted by %s %s was run on a different thread", m_location.functionName(), m_location.fileName()); TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal"); if (m_repeatInterval) { double now = monotonicallyIncreasingTime(); // This computation should be drift free, and it will cope if we miss a beat, // which can easily happen if the thread is busy. It will also cope if we get // called slightly before m_unalignedNextFireTime, which can happen due to lack // of timer precision. double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFireTime, m_repeatInterval); setNextFireTime(monotonicallyIncreasingTime(), intervalToNextFireTime); } else { m_nextFireTime = 0; } fired(); TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping"); }
/* ================= ClientEndServerFrame Called for each player at the end of the server frame and right after spawning ================= */ void ClientEndServerFrame (edict_t * ent) { float bobtime; int i; //char player_name[30]; //char temp[40]; // int damage; // zucc for bleeding current_player = ent; current_client = ent->client; //AQ2:TNG - Slicer : Stuffs the client x seconds after he enters the server, needed for Video check if (ent->client->resp.checktime[0] <= level.time) { ent->client->resp.checktime[0] = level.time + video_checktime->value; if (video_check->value || video_check_lockpvs->value || video_check_glclear->value || darkmatch->value) stuffcmd (ent, "%!fc $vid_ref\n"); if (video_force_restart->value && video_check->value && !ent->client->resp.checked) { stuffcmd (ent, "vid_restart\n"); ent->client->resp.checked = true; } } if (ent->client->resp.checktime[1] <= level.time) { ent->client->resp.checktime[1] = level.time + video_checktime->value; ent->client->resp.checktime[2] = level.time + 1; if (video_check->value || video_check_lockpvs->value || video_check_glclear->value || darkmatch->value) { if (ent->client->resp.vidref && Q_stricmp(ent->client->resp.vidref, "soft")) stuffcmd (ent, "%cpsi $gl_modulate $gl_lockpvs $gl_clear $gl_dynamic $gl_driver\n"); } } if (ent->client->resp.checktime[2] <= level.time) { // ent->client->resp.checktime[2] = level.time + video_checktime->value; if (video_check->value || video_check_lockpvs->value || video_check_glclear->value || darkmatch->value) { if (ent->client->resp.vidref && Q_stricmp(ent->client->resp.vidref, "soft")) VideoCheckClient (ent); } } if(pause_time) { G_SetStats (ent); return; } //FIREBLADE - Unstick avoidance stuff. if (ent->solid == SOLID_TRIGGER && !lights_camera_action) { edict_t *overlap; if ((overlap = FindOverlap (ent, NULL)) == NULL) { ent->solid = SOLID_BBOX; gi.linkentity (ent); RemoveFromTransparentList (ent); } else { do { if (overlap->solid == SOLID_BBOX) { overlap->solid = SOLID_TRIGGER; gi.linkentity (overlap); AddToTransparentList (overlap); } overlap = FindOverlap (ent, overlap); } while (overlap != NULL); } } //FIREBLADE // // If the origin or velocity have changed since ClientThink(), // update the pmove values. This will happen when the client // is pushed by a bmodel or kicked by an explosion. // // If it wasn't updated here, the view position would lag a frame // behind the body position when pushed -- "sinking into plats" // for (i = 0; i < 3; i++) { current_client->ps.pmove.origin[i] = ent->s.origin[i] * 8.0; current_client->ps.pmove.velocity[i] = ent->velocity[i] * 8.0; } // // If the end of unit layout is displayed, don't give // the player any normal movement attributes // if (level.intermissiontime) { // FIXME: add view drifting here? current_client->ps.blend[3] = 0; current_client->ps.fov = 90; G_SetStats (ent); return; } AngleVectors (ent->client->v_angle, forward, right, up); // burn from lava, etc P_WorldEffects (); // // set model angles from view angles so other things in // the world can tell which direction you are looking // if (ent->client->v_angle[PITCH] > 180) ent->s.angles[PITCH] = (-360 + ent->client->v_angle[PITCH]) / 3; else ent->s.angles[PITCH] = ent->client->v_angle[PITCH] / 3; ent->s.angles[YAW] = ent->client->v_angle[YAW]; ent->s.angles[ROLL] = 0; ent->s.angles[ROLL] = SV_CalcRoll (ent->s.angles, ent->velocity) * 4; // // calculate speed and cycle to be used for // all cyclic walking effects // xyspeed = sqrt(ent->velocity[0]*ent->velocity[0] + ent->velocity[1]*ent->velocity[1]); if (xyspeed < 5 || ent->solid == SOLID_NOT) { bobmove = 0; current_client->bobtime = 0; // start at beginning of cycle again } else if (ent->groundentity) { // so bobbing only cycles when on ground if (xyspeed > 210) bobmove = 0.25; else if (xyspeed > 100) bobmove = 0.125; else bobmove = 0.0625; } bobtime = (current_client->bobtime += bobmove); if (current_client->ps.pmove.pm_flags & PMF_DUCKED) bobtime *= 4; bobcycle = (int) bobtime; bobfracsin = fabs (sin (bobtime * M_PI)); // detect hitting the floor P_FallingDamage (ent); // zucc handle any bleeding damage here Do_Bleeding (ent); // apply all the damage taken this frame P_DamageFeedback (ent); // determine the view offsets SV_CalcViewOffset (ent); // determine the gun offsets SV_CalcGunOffset (ent); // determine the full screen color blend // must be after viewoffset, so eye contents can be // accurately determined // FIXME: with client prediction, the contents // should be determined by the client SV_CalcBlend (ent); G_SetStats (ent); //FIREBLADE for (i = 1; i <= maxclients->value; i++) { int stats_copy; edict_t *e = g_edicts + i; if (!ent->inuse || e->client->chase_mode == 0 || e->client->chase_target != ent) continue; for (stats_copy = 0; stats_copy < MAX_STATS; stats_copy++) { if (stats_copy >= STAT_TEAM_HEADER && stats_copy <= STAT_TEAM2_SCORE) continue; // protect these if (stats_copy >= STAT_TEAM3_PIC && stats_copy <= STAT_TEAM3_SCORE) continue; // protect these if (stats_copy == STAT_LAYOUTS || stats_copy == STAT_ID_VIEW) continue; // protect these if (stats_copy == STAT_SNIPER_ICON && e->client->chase_mode != 2) continue; // only show sniper lens when in chase mode 2 if (stats_copy == STAT_FRAGS) continue; e->client->ps.stats[stats_copy] = ent->client->ps.stats[stats_copy]; } //FB e->client->ps.stats[STAT_LAYOUTS] = 1; //FB break; } //FIREBLADE G_SetClientEvent (ent); G_SetClientEffects (ent); G_SetClientSound (ent); G_SetClientFrame (ent); VectorCopy (ent->velocity, ent->client->oldvelocity); VectorCopy (ent->client->ps.viewangles, ent->client->oldviewangles); // clear weapon kicks VectorClear (ent->client->kick_origin); VectorClear (ent->client->kick_angles); // zucc - clear the open door command ent->client->doortoggle = 0; if (ent->client->push_timeout > 0) ent->client->push_timeout--; /* else { ent->client->attacker = NULL; ent->client->attacker_mod = MOD_BLEEDING; } */ if (ent->client->reload_attempts > 0) { if (((ent->client->latched_buttons | ent->client->buttons) & BUTTON_ATTACK) && canFire(ent)) { ent->client->reload_attempts = 0; } else { Cmd_Reload_f (ent); } } if (ent->client->weapon_attempts > 0) Cmd_Weapon_f (ent); // if the scoreboard is up, update it if (ent->client->showscores && !(level.framenum & 31)) { //FIREBLADE if (ent->client->menu) { PMenu_Update (ent); } else //FIREBLADE DeathmatchScoreboardMessage (ent, ent->enemy); gi.unicast (ent, false); } //FIREBLADE if(!pause_time) RadioThink (ent); //FIREBLADE }
void SmallEnemy::move(GameLevel& context) { const byte period = (getType() == 0) ? ZIG_PERIOD : TRI_PERIOD; switch(getType()) { // zigzag case 0: { // moving // x -= 1.5, y -= 0.5 if(timer % 2 == 0) { x -= 2; y += (timer / (ZIG_PERIOD / 4) % 2 == 0) ? 1 : -1; } else { --x; } // firing bullet const byte d = context.difficulty(); const byte typeCond = canFire() || (d >= 70 && d < 80) || d >= 100; // [70,80) or 100 if( timer == 80 && typeCond && // time / type x < SCREEN_WIDTH - W / 2 && // position d >= 20 // dont fire less than 20 ) { const byte bulletType = (d >= 80) ? 3 : 1; // rapid when 80 and over const float subAngle = context.getSubmarineAngle(x, y); context.fireBullet(x, y, subAngle, bulletType); // 3way if((d >= 50 && d < 70) || d >= 90) { context.fireBullet(x, y, subAngle - radians(10), 1); context.fireBullet(x, y, subAngle + radians(10), 1); } } } break; // triangle default: { // moving if(timer % 6 == 0) { --x; } const int half = period / 2; int tmp = half - timer % half; tmp = tmp*tmp / (half*half/4) - 1; if(tmp < 0) { tmp = 0; } x -= tmp; // firing bullet const bool timeCond = timer == 64 || (context.difficulty() >= 25 && timer == 32) || (context.difficulty() >= 75 && timer == 96); if( timeCond && canFire() && // time / type x < SCREEN_WIDTH && x > SCREEN_WIDTH / 2 && // position context.difficulty() >= 20 // difficulty ) { context.fireBullet(x, y, context.getSubmarineAngle(x, y), 1); } } break; } // frame out if(x + 12 < 0) { context.platoons.checkBonus(getPlatoon(), false); inactivate(); } // setting sonar reaction context.echo.add(x, y, y+H); // updating timer timer = (timer + 1) % period; }
void DefenderWeaponBehaviour::UpdateWeapon(ComponentWrapper cWeapon, WeaponInfo& wi, double dt) { CheckBoost(cWeapon, wi); // Decrement reload timer Field<double> reloadTimer = cWeapon["ReloadTimer"]; reloadTimer = glm::max(0.0, reloadTimer - dt); // Start reloading automatically if at 0 mag ammo Field<int> magAmmo = cWeapon["MagazineAmmo"]; if (m_ConfigAutoReload && magAmmo <= 0) { OnReload(cWeapon, wi); } // Handle reloading Field<bool> isReloading = cWeapon["IsReloading"]; if (isReloading && reloadTimer <= 0.0) { double reloadTime = cWeapon["ReloadTime"]; Field<int> magSize = cWeapon["MagazineSize"]; Field<int> ammo = cWeapon["Ammo"]; if (magAmmo < magSize && ammo > 0) { ammo -= 1; magAmmo += 1; reloadTimer = reloadTime; Events::PlaySoundOnEntity e; e.Emitter = wi.Player; e.FilePath = "Audio/weapon/Zoom.wav"; m_EventBroker->Publish(e); } else { isReloading = false; playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "ReloadEnd"); if (wi.ThirdPersonPlayerModel.Valid()) { Events::AutoAnimationBlend eFireIdle; eFireIdle.Duration = 0.2; eFireIdle.RootNode = wi.ThirdPersonPlayerModel; eFireIdle.NodeName = "Fire"; eFireIdle.Start = false; m_EventBroker->Publish(eFireIdle); } } } // Restore view angle if (IsClient) { Field<float> currentTravel = cWeapon["CurrentTravel"]; Field<float> returnSpeed = cWeapon["ViewReturnSpeed"]; if (currentTravel > 0) { float change = returnSpeed * dt; currentTravel = glm::max(0.f, currentTravel - change); EntityWrapper camera = wi.Player.FirstChildByName("Camera"); if (camera.Valid()) { Field<glm::vec3> cameraOrientation = camera["Transform"]["Orientation"]; cameraOrientation.x(cameraOrientation.x() - change); } } } // Fire if we're able to fire if (canFire(cWeapon, wi)) { fireShell(cWeapon, wi); } }
const bool validateFire(const int idx) { if (idx == 0) return canFire(); return true; }