MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / fire

Method fire

game/state/shared/aequipment.cpp:727–841  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

725}
726
727void AEquipment::fire(GameState &state, Vec3<float> targetPosition, StateRef<BattleUnit> targetUnit)
728{
729 if (this->type->type != AEquipmentType::Type::Weapon)
730 {
731 LogError("fire() called on non-Weapon");
732 return;
733 }
734 if (!readyToFire)
735 {
736 LogError("fire() called on non-ready Weapon");
737 return;
738 }
739
740 auto unit = ownerAgent->unit;
741 auto payload = getPayloadType();
742 Vec3<float> originalTarget = targetPosition;
743 int number_of_shots;
744
745 if (payload->fire_sfx)
746 {
747 fw().soundBackend->playSample(payload->fire_sfx, unit->position);
748 }
749
750 number_of_shots = std::min(this->type->burst, this->ammo);
751
752 if (type->launcher)
753 {
754 auto item = mksp<AEquipment>();
755 item->type = payload;
756 item->ammo = 1;
757 if (payload->damage_type->effectType == DamageType::EffectType::Brainsucker)
758 {
759 item->prime(false, TICKS_PER_TURN, 10.0f);
760 }
761 else
762 {
763 item->prime();
764 }
765 item->ownerUnit = ownerAgent->unit;
766 float velocityXY = 0.0f;
767 float velocityZ = 0.0f;
768 if (!getVelocityForLaunch(*unit, targetPosition, velocityXY, velocityZ))
769 {
770 LogError("Firing a launcher with no valid trajectory?");
771 return;
772 }
773 // Throw item (accuracy applied inside)
774
775 for (int shot_number = 0; shot_number < number_of_shots; shot_number++)
776 {
777 item->throwItem(state, targetPosition, velocityXY, velocityZ, true);
778 }
779 }
780 else
781 {
782 auto unitPos = unit->getMuzzleLocation();
783
784 auto fromPos = unitPos * VELOCITY_SCALE_BATTLE;

Callers

nothing calls this directly

Calls 12

primeMethod · 0.80
tileIsValidMethod · 0.80
addObjectToMapMethod · 0.80
insertMethod · 0.80
getBoolMethod · 0.80
getPlayerMethod · 0.80
updateSpeedMethod · 0.80
playSampleMethod · 0.45
throwItemMethod · 0.45
getMuzzleLocationMethod · 0.45
isCloakedMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected