5190 {
5191 Weapon_Base weapon_base = Weapon_Base.Cast(weapon);
5194
5196 int last_ammo_magazine_count;
5197 int ammo_magazine_count;
5198
5200 int last_ammo_pile_count;
5201 int ammo_pile_count;
5202
5203
5204 GameInventory inventory = GetInventory();
5206 for (int att_i = 0; att_i < nAttachment; ++att_i)
5207 {
5209 ref CargoBase attachment_cargo = attachment.GetInventory().GetCargo();
5210
5211 if (attachment_cargo)
5212 {
5213 int nAttachmentCargoItem = attachment_cargo.GetItemCount();
5214 for (int cgo_i = 0; cgo_i < nAttachmentCargoItem; ++cgo_i)
5215 {
5216 EntityAI cargo_item = attachment_cargo.GetItem(cgo_i);
5217
5218
5219 if (cargo_item.IsMagazine())
5220 {
5221 Magazine magazine = Magazine.Cast(cargo_item);
5222 ammo_pile_count = magazine.GetAmmoCount();
5223
5224
5226 {
5227 if (ammo_pile_count > 0)
5228 {
5229 if (last_ammo_magazine_count == 0)
5230 {
5231 ammo_magazine = magazine;
5232 last_ammo_magazine_count = ammo_pile_count;
5233 }
5234 else
5235 {
5236 if (last_ammo_magazine_count < ammo_pile_count)
5237 {
5238 ammo_magazine = magazine;
5239 last_ammo_magazine_count = ammo_pile_count;
5240 }
5241 }
5242 }
5243 }
5244
5245 else if (weapon_manager.
CanLoadBullet(weapon_base, magazine))
5246 {
5247 if (ammo_pile_count > 0)
5248 {
5249 if (last_ammo_pile_count == 0)
5250 {
5251 ammo_pile = magazine;
5252 last_ammo_pile_count = ammo_pile_count;
5253 }
5254 else
5255 {
5256 if (last_ammo_pile_count > ammo_pile_count)
5257 {
5258 ammo_pile = magazine;
5259 last_ammo_pile_count = ammo_pile_count;
5260 }
5261 }
5262 }
5263 }
5264 }
5265 }
5266 }
5267 }
5268
5269
5270 if (ammo_magazine)
5271 {
5272 return ammo_magazine;
5273 }
5274
5275 return ammo_pile;
5276 }
proto native EntityAI GetAttachmentFromIndex(int index)
proto native int AttachmentCount()
Returns count of attachments attached to this item.
override WeaponManager GetWeaponManager()
bool CanLoadBullet(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool CanAttachMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)
bool CanSwapMagazine(Weapon_Base wpn, Magazine mag, bool reservationCheck=true)