bool Weapon::Shoot() { MSG_DEBUG("weapon.shoot", "Enough ammo ? %d", EnoughAmmo()); MSG_DEBUG("weapon.shoot", "Enough ammo unit ? %d", EnoughAmmoUnit()); MSG_DEBUG("weapon.shoot", "Use unit on 1st shoot ? %d", use_unit_on_first_shoot); if (!IsReady()) return false; MSG_DEBUG("weapon.shoot", "Enough ammo"); #ifdef DEBUG Point2i hand; ActiveCharacter().GetHandPosition(hand); MSG_DEBUG("weapon.shoot", "%s Shooting at position:%d,%d (hand: %d,%d)", ActiveCharacter().GetName().c_str(), ActiveCharacter().GetX(), ActiveCharacter().GetY(), hand.GetX(), hand.GetY()); ActiveCharacter().body->DebugState(); #endif if (!p_Shoot()) { MSG_DEBUG("weapon.shoot", "shoot has failed!!"); return false; } m_last_fire_time = Time::GetInstance()->Read(); MSG_DEBUG("weapon.shoot", "shoot!"); // Is this the first shoot for this ammo use ? if (ActiveTeam().ReadNbUnits() == m_initial_nb_unit_per_ammo) { UseAmmo(); } if (use_unit_on_first_shoot){ UseAmmoUnit(); } if (max_strength.IsNotZero()) ActiveCharacter().previous_strength = m_strength; Game::GetInstance()->SetCharacterChosen(true); return true; }
void Weapon::Draw(){ if (Game::GetInstance()->ReadState() != Game::PLAYING && m_last_fire_time + 100 < Time::GetInstance()->Read()) return; #ifndef DEBUG_HOLE if (m_last_fire_time + m_fire_remanence_time > Time::GetInstance()->Read()) #endif DrawWeaponFire(); DrawAmmoUnits(); ASSERT(drawable || !ShouldBeDrawn()); if (!(drawable && ShouldBeDrawn())) return; if (ActiveCharacter().IsGhost() || ActiveCharacter().IsDrowned() || ActiveCharacter().IsDead()) return; // rotate weapon if needed if (!EqualsZero(min_angle - max_angle)) { if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT) m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle()); else m_image->SetRotation_rad(ActiveCharacter().GetFiringAngle()-PI); } else { m_image->SetRotation_rad(ZERO); } // flip image if needed if (use_flipping) { m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection()); } // Calculate position of the image int x,y; PosXY (x, y); // Animate the display of the weapon: if (m_time_anim_begin + ANIM_DISPLAY_TIME > Time::GetInstance()->Read()) { if (!EqualsZero(min_angle - max_angle)) { Double angle = m_image->GetRotation_rad(); angle += sin(HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME) * TWO_PI; m_image->SetRotation_rad(angle); m_image->Scale(ONE, ONE); } else { Double scale = sin((Double)1.5 * HALF_PI * Double(Time::GetInstance()->Read() - m_time_anim_begin) / ANIM_DISPLAY_TIME) / sin((Double)1.5 * HALF_PI); if (scale.IsNotZero()) { m_image->Scale(scale, scale); m_image->SetFlipped(DIRECTION_LEFT == ActiveCharacter().GetDirection()); } // Recompute position to get the icon centered over the skin if (origin == weapon_origin_OVER) PosXY(x,y); } } else m_image->Scale(ONE, ONE); if (m_image) m_image->Blit(GetMainWindow(), Point2i(x, y) - Camera::GetInstance()->GetPosition()); #ifdef DEBUG if (IsLOGGING("weapon")) { Point2i hand; ActiveCharacter().GetHandPosition(hand); Rectanglei rect(hand - 1 - Camera::GetInstance()->GetPosition(), Point2i(3, 3)); GetWorld().ToRedrawOnMap(rect); GetMainWindow().RectangleColor(rect, c_red); MSG_DEBUG("weapon.handposition", "Position: %d, %d - hand: %d, %d", ActiveCharacter().GetX(), ActiveCharacter().GetY(), hand.GetX(), hand.GetY()); } if (IsLOGGING("weapon.hole")) { Rectanglei rect(GetGunHolePosition() - Camera::GetInstance()->GetPosition() - 1, Point2i(3, 3)); GetWorld().ToRedrawOnMap(rect); GetMainWindow().RectangleColor(rect, c_red); } #endif }