MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / AddMagazine

Method AddMagazine

engine/Poseidon/AI/VehicleAI.cpp:1983–2036  ·  view source on GitHub ↗

! \param name magazine type name \param force add magazine even if no free slots (bypass check) \param autoreload reload magazine into weapon immediatelly \return index of new weapon in array */

Source from the content-addressed store, hash-verified

1981\return index of new weapon in array
1982*/
1983int EntityAI::AddMagazine(Magazine* magazine, bool force, bool autoload)
1984{
1985 if (!CheckAccessCreate(*magazine->_type->_parClass))
1986 {
1987 return -1;
1988 }
1989 // add magazine type
1990 if (!force)
1991 {
1992 AUTO_STATIC_ARRAY(Ref<const Magazine>, conflict, 16);
1993 if (!CheckMagazine(magazine, conflict))
1994 {
1995 return -1;
1996 }
1997 if (conflict.Size() > 0)
1998 {
1999 return -1;
2000 }
2001 }
2002 int index = _magazines.Add(magazine);
2003
2004#if _DEBUG
2005 CheckMagazines();
2006#endif
2007
2008 if (autoload)
2009 {
2010 for (int weapon = 0; weapon < NMagazineSlots(); weapon++)
2011 {
2012 const MagazineSlot& slot = GetMagazineSlot(weapon);
2013 const MuzzleType* muzzle = slot._muzzle;
2014 if (!muzzle)
2015 {
2016 continue;
2017 }
2018 // if slot is not empty, there is no need to reload
2019 if (slot._magazine && slot._magazine->_ammo > 0)
2020 {
2021 continue;
2022 }
2023
2024 for (int k = 0; k < muzzle->_magazines.Size(); k++)
2025 {
2026 if (muzzle->_magazines[k] == magazine->_type)
2027 {
2028 AutoReload(weapon);
2029 return index;
2030 }
2031 }
2032 }
2033 }
2034
2035 return index;
2036}
2037
2038/*!
2039\param name magazine type name

Callers 5

DoRespawnMethod · 0.45
ApplyMethod · 0.45
ObjWeaponsFromPoolFunction · 0.45
ObjAddMagazinePreciseFunction · 0.45
ObjAddMagazineFunction · 0.45

Calls 6

CheckAccessCreateFunction · 0.85
AUTO_STATIC_ARRAYFunction · 0.70
SizeMethod · 0.45
AddMethod · 0.45
NewMethod · 0.45
RandomValueMethod · 0.45

Tested by

no test coverage detected