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

Function GetReloadActions

engine/Poseidon/AI/VehicleAIPilot.cpp:1220–1271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1218}
1219
1220static void GetReloadActions(EntityAI* veh, UIActions& actions, int iSlot, const MuzzleType* currentMuzzle)
1221{
1222 const MagazineSlot& slot = veh->GetMagazineSlot(iSlot);
1223 const Magazine* magazine = slot._magazine;
1224 const MagazineType* mType = magazine ? magazine->_type : nullptr;
1225 bool empty = false;
1226 if (mType && slot._mode >= 0 && slot._mode < mType->_modes.Size())
1227 {
1228 const WeaponModeType* mode = mType->_modes[slot._mode];
1229 if (mode->_ammo && mType->_maxAmmo > 0)
1230 {
1231 empty = magazine->_ammo == 0;
1232 }
1233 if (!empty && currentMuzzle->_autoReload &&
1234 (mType->_maxAmmo == 1 || (slot._weapon->_weaponType & MaskHardMounted) != 0))
1235 {
1236 // do not offer reload HandGrenade etc.
1237 }
1238 else
1239 {
1240 // magazine of the same type
1241 int best = veh->FindBestMagazine(mType, 0);
1242 if (best >= 0)
1243 {
1244 float prior = empty ? 1.5 : 0.35;
1245 const Magazine* magazine = veh->GetMagazine(best);
1246 RString muzzleID = slot._weapon->GetName() + RString("|") + slot._muzzle->GetName();
1247 actions.Add(ATLoadMagazine, veh, prior, magazine->_creator, empty, true, magazine->_id, muzzleID);
1248 }
1249 }
1250 }
1251 else
1252 {
1253 empty = true;
1254 }
1255 // magazines of other type
1256 for (int i = 0; i < currentMuzzle->_magazines.Size(); i++)
1257 {
1258 const MagazineType* change = currentMuzzle->_magazines[i];
1259 if (change == mType)
1260 {
1261 continue;
1262 }
1263 int best = veh->FindBestMagazine(change, 0);
1264 if (best >= 0)
1265 {
1266 const Magazine* magazine = veh->GetMagazine(best);
1267 RString muzzleID = slot._weapon->GetName() + RString("|") + slot._muzzle->GetName();
1268 actions.Add(ATLoadMagazine, veh, 0.34, magazine->_creator, empty, true, magazine->_id, muzzleID);
1269 }
1270 }
1271}
1272
1273void EntityAI::GetActions(UIActions& actions, AIUnit* unit, bool now)
1274{

Callers 1

GetActionsMethod · 0.85

Calls 6

FindBestMagazineMethod · 0.80
RStringClass · 0.50
SizeMethod · 0.45
GetMagazineMethod · 0.45
GetNameMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected