DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ FillChamber()

bool Weapon::FillChamber ( string ammoType = "",
int flags = WeaponWithAmmoFlags.CHAMBER )
inlineprotected

Try to fill the chamber.

Аргументы
[in]ammoTypestring The ammo to load, passing in empty string will select random
Заметки
It is best to fill in the actual 'ammo', as in the ones usually prefixed by 'Bullet_', to skip searching for it
Аргументы
[in]flagsint Setup flags, please read WeaponWithAmmoFlags
Возвращает
Whether any chamber was filled

См. определение в файле Weapon_Base.c строка 895

896 {
897 // Quickly check if there are any chambers we can fill
898 int muzzCount = GetMuzzleCount();
899 bool anyEmpty = false;
900
901 for (int m = 0; m < muzzCount; ++m)
902 {
903 if (IsChamberEmpty(m))
904 {
905 anyEmpty = true;
906 break;
907 }
908 }
909
910 if (!anyEmpty)
911 return false;
912
913 // Make sure the given ammoType is actually useable
914 if (ammoType != "")
915 if (!AmmoTypesAPI.MagazineTypeToAmmoType(ammoType, ammoType))
916 return false;
917
918 // Just so we don't '&' wastefully in a loop
919 bool didSomething = false;
920 bool chamberFullRng = (flags & WeaponWithAmmoFlags.CHAMBER_RNG_SPORADIC);
921 bool chamberRng = (flags & WeaponWithAmmoFlags.CHAMBER_RNG);
922 bool chamber = (flags & WeaponWithAmmoFlags.CHAMBER);
923
924 if (chamber || chamberRng || chamberFullRng)
925 {
926 int amountToChamber = muzzCount;
927
928 // No need to do this for full rng, as that will roll for every muzzle
929 if (chamberRng)
930 amountToChamber = Math.RandomIntInclusive(0, muzzCount);
931
932 bool chamberAmmoRng = (ammoType == "");
933 bool chamberAmmoFullRng = chamberAmmoRng && (flags & WeaponWithAmmoFlags.AMMO_CHAMBER_RNG);
934
935 // No full RNG flag, so pick one random and use only this one
936 if (chamberAmmoRng && !chamberAmmoFullRng)
937 ammoType = GetRandomChamberableAmmoTypeName(0);
938
939 for (int i = 0; i < muzzCount; ++i)
940 {
941 // Skip when there's already something in the chamber
942 if (!IsChamberEmpty(i))
943 continue;
944
945 // Roll the rng when enabled
946 if (chamberFullRng)
947 chamber = Math.RandomIntInclusive(0, 1);
948
949 // We chambering
950 if (chamber)
951 {
952 // Full random, decide a new one for every muzzle
953 if ( chamberAmmoFullRng )
954 ammoType = GetRandomChamberableAmmoTypeName(i);
955
956 // Push it
957 PushCartridgeToChamber(i, 0, ammoType);
958 didSomething = true;
959
960 // Stop chambering when we hit the desired amount
961 --amountToChamber;
962 if (amountToChamber <= 0)
963 break;
964 }
965 }
966 }
967
968 // Only fix the FSM and Synchronize when absolutely needed
969 if (!didSomething)
970 return false;
971
972 // FSM cares about chamber state
974 Synchronize();
975
976 return true;
977 }
void Synchronize()
Определения CombinationLock.c:151
void RandomizeFSMState()
With the parameters given, selects a random suitable state for the FSM of the weapon @WARNING: Weapon...
Определения Weapon_Base.c:673

Перекрестные ссылки AmmoTypesAPI::MagazineTypeToAmmoType(), Math::RandomIntInclusive(), RandomizeFSMState() и Synchronize().

Используется в FillInnerMagazine(), SpawnAmmo() и SpawnAttachedMagazine().