guards.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /**@class WeaponGuardBase
  2. * @brief represents guard on a transition from state to state
  3. **/
  4. class WeaponGuardBase
  5. {
  6. /**@fn GuardCondition
  7. * @brief enable or disable transition based on condition
  8. * the guard is a boolean operation executed first and which can prevent the transition from firing by returning false
  9. * @return true if transition is allowed
  10. **/
  11. bool GuardCondition (WeaponEventBase e) { return true; }
  12. };
  13. class GuardAnd extends WeaponGuardBase
  14. {
  15. ref WeaponGuardBase m_arg0;
  16. ref WeaponGuardBase m_arg1;
  17. void GuardAnd (WeaponGuardBase arg0 = NULL, WeaponGuardBase arg1 = NULL) { m_arg0 = arg0; m_arg1 = arg1; }
  18. override bool GuardCondition (WeaponEventBase e)
  19. {
  20. bool result = m_arg0.GuardCondition(e) && m_arg1.GuardCondition(e);
  21. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - " + m_arg0.Type() + " && " + m_arg1.Type() + " = " + result); }
  22. return result;
  23. }
  24. };
  25. class GuardNot extends WeaponGuardBase
  26. {
  27. ref WeaponGuardBase m_arg0;
  28. void GuardNot (WeaponGuardBase arg0 = NULL) { m_arg0 = arg0; }
  29. override bool GuardCondition (WeaponEventBase e)
  30. {
  31. bool result = !m_arg0.GuardCondition(e);
  32. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - ! " + m_arg0.Type() + " = " + result); }
  33. return result;
  34. }
  35. };
  36. class GuardOr extends WeaponGuardBase
  37. {
  38. ref WeaponGuardBase m_arg0;
  39. ref WeaponGuardBase m_arg1;
  40. void GuardOr (WeaponGuardBase arg0 = NULL, WeaponGuardBase arg1 = NULL) { m_arg0 = arg0; m_arg1 = arg1; }
  41. override bool GuardCondition (WeaponEventBase e)
  42. {
  43. bool result = m_arg0.GuardCondition(e) || m_arg1.GuardCondition(e);
  44. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - " + m_arg0.Type() + " || " + m_arg1.Type() + " = " + result); }
  45. return result;
  46. }
  47. };
  48. // guards /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. class WeaponGuardJammed extends WeaponGuardBase
  50. {
  51. protected Weapon_Base m_weapon;
  52. void WeaponGuardJammed (Weapon_Base w = NULL) { m_weapon = w; }
  53. override bool GuardCondition (WeaponEventBase e)
  54. {
  55. /*int mi = m_weapon.GetCurrentMuzzle();
  56. if (m_weapon.IsChamberJammed(mi))*/
  57. if (m_weapon.IsJammed())
  58. {
  59. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - jammed"); }
  60. return true;
  61. }
  62. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - not jammed"); }
  63. return false;
  64. }
  65. };
  66. class WeaponGuardIsDestroyed extends WeaponGuardBase
  67. {
  68. protected Weapon_Base m_weapon;
  69. void WeaponGuardIsDestroyed (Weapon_Base w = NULL) { m_weapon = w; }
  70. override bool GuardCondition (WeaponEventBase e)
  71. {
  72. if (m_weapon.IsDamageDestroyed())
  73. {
  74. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - weapon destroyed"); }
  75. return true;
  76. }
  77. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - weapon not destroyed"); }
  78. return false;
  79. }
  80. }
  81. class WeaponGuardHasAmmo extends WeaponGuardBase
  82. {
  83. protected Weapon_Base m_weapon;
  84. void WeaponGuardHasAmmo (Weapon_Base w = NULL) { m_weapon = w; }
  85. override bool GuardCondition (WeaponEventBase e)
  86. {
  87. int mi = m_weapon.GetCurrentMuzzle();
  88. Magazine mag = m_weapon.GetMagazine(mi);
  89. if (mag != NULL && mag.GetAmmoCount() > 0)
  90. {
  91. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - has ammo"); }
  92. return true;
  93. }
  94. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - no ammo"); }
  95. return false;
  96. }
  97. };
  98. class WeaponGuardHasAmmoInnerMagazine extends WeaponGuardBase
  99. {
  100. protected Weapon_Base m_weapon;
  101. void WeaponGuardHasAmmoInnerMagazine (Weapon_Base w = NULL) { m_weapon = w; }
  102. override bool GuardCondition (WeaponEventBase e)
  103. {
  104. int mi = m_weapon.GetCurrentMuzzle();
  105. if (m_weapon.GetInternalMagazineCartridgeCount(mi) >= 1)
  106. {
  107. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - has ammo in inner magazine"); }
  108. return true;
  109. }
  110. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - no ammo in inner magazine"); }
  111. return false;
  112. }
  113. };
  114. class WeaponGuardHasAmmoInEvent extends WeaponGuardBase
  115. {
  116. protected Weapon_Base m_weapon;
  117. void WeaponGuardHasAmmoInEvent (Weapon_Base w = NULL) { m_weapon = w; }
  118. override bool GuardCondition (WeaponEventBase e)
  119. {
  120. Magazine mag = e.m_magazine;
  121. if (mag != NULL && mag.GetAmmoCount() > 0)
  122. {
  123. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - has ammo in event"); }
  124. return true;
  125. }
  126. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - no ammo in event"); }
  127. return false;
  128. }
  129. };
  130. class WeaponGuardHasMag extends WeaponGuardBase
  131. {
  132. protected Weapon_Base m_weapon;
  133. void WeaponGuardHasMag (Weapon_Base w = NULL) { m_weapon = w; }
  134. override bool GuardCondition (WeaponEventBase e)
  135. {
  136. int mi = m_weapon.GetCurrentMuzzle();
  137. Magazine mag = m_weapon.GetMagazine(mi);
  138. if (mag != NULL)
  139. {
  140. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - has magazine"); }
  141. return true;
  142. }
  143. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - no magazine"); }
  144. return false;
  145. }
  146. };
  147. class WeaponGuardChamberEmpty extends WeaponGuardBase
  148. {
  149. protected Weapon_Base m_weapon;
  150. protected int m_muzzle;
  151. void WeaponGuardChamberEmpty (Weapon_Base w = NULL, int muzzle_index = 0 ) { m_weapon = w; m_muzzle = muzzle_index; }
  152. override bool GuardCondition (WeaponEventBase e)
  153. {
  154. if (m_weapon.IsChamberEmpty(m_muzzle))
  155. {
  156. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber (" + m_muzzle + ") empty"); }
  157. return true;
  158. }
  159. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber (" + m_muzzle + ") not empty"); }
  160. return false;
  161. }
  162. };
  163. class WeaponGuardCurrentChamberEmpty extends WeaponGuardBase
  164. {
  165. protected Weapon_Base m_weapon;
  166. void WeaponGuardCurrentChamberEmpty (Weapon_Base w = NULL) { m_weapon = w; }
  167. override bool GuardCondition (WeaponEventBase e)
  168. {
  169. int mi = m_weapon.GetCurrentMuzzle();
  170. if (m_weapon.IsChamberEmpty(mi))
  171. {
  172. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber empty"); }
  173. return true;
  174. }
  175. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber not empty"); }
  176. return false;
  177. }
  178. };
  179. class WeaponGuardAnyChamberEmpty extends WeaponGuardBase
  180. {
  181. protected Weapon_Base m_weapon;
  182. protected int m_muzzle;
  183. void WeaponGuardAnyChamberEmpty (Weapon_Base w = NULL, int muzzle_index = 0 ) { m_weapon = w; m_muzzle = muzzle_index; }
  184. override bool GuardCondition (WeaponEventBase e)
  185. {
  186. for (int i = 0; i < m_weapon.GetMuzzleCount(); i++)
  187. {
  188. if (m_weapon.IsChamberEmpty(i))
  189. {
  190. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - multi chamber (" + i + ") empty"); }
  191. return true;
  192. }
  193. }
  194. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - no chamber empty"); }
  195. return false;
  196. }
  197. };
  198. class WeaponGuardChamberFull extends WeaponGuardBase
  199. {
  200. protected Weapon_Base m_weapon;
  201. protected int m_muzzle;
  202. void WeaponGuardChamberFull (Weapon_Base w = NULL, int muzzle_index = 0 ) { m_weapon = w; m_muzzle = muzzle_index; }
  203. override bool GuardCondition (WeaponEventBase e)
  204. {
  205. if (m_weapon.IsChamberFull(m_muzzle))
  206. {
  207. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber (" + m_muzzle + ") full"); }
  208. return true;
  209. }
  210. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber (" + m_muzzle + ") not full"); }
  211. return false;
  212. }
  213. };
  214. class WeaponGuardCurrentChamberFull extends WeaponGuardBase
  215. {
  216. protected Weapon_Base m_weapon;
  217. void WeaponGuardCurrentChamberFull (Weapon_Base w = NULL) { m_weapon = w; }
  218. override bool GuardCondition (WeaponEventBase e)
  219. {
  220. int mi = m_weapon.GetCurrentMuzzle();
  221. if (m_weapon.IsChamberFull(mi))
  222. {
  223. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber full"); }
  224. return true;
  225. }
  226. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber not full"); }
  227. return false;
  228. }
  229. };
  230. class WeaponGuardInnerMagazineFull extends WeaponGuardBase
  231. {
  232. protected Weapon_Base m_weapon;
  233. void WeaponGuardInnerMagazineFull (Weapon_Base w = NULL) { m_weapon = w; }
  234. override bool GuardCondition (WeaponEventBase e)
  235. {
  236. int mi = m_weapon.GetCurrentMuzzle();
  237. if (m_weapon.IsInternalMagazineFull(mi))
  238. {
  239. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - internal magazine full"); }
  240. return true;
  241. }
  242. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - internal magazine not full"); }
  243. return false;
  244. }
  245. };
  246. class WeaponGuardInnerMagazineFullShareChamber extends WeaponGuardBase
  247. {
  248. protected Weapon_Base m_weapon;
  249. void WeaponGuardInnerMagazineFullShareChamber (Weapon_Base w = NULL) { m_weapon = w; }
  250. override bool GuardCondition (WeaponEventBase e)
  251. {
  252. int mi = m_weapon.GetCurrentMuzzle();
  253. if ( m_weapon.IsChamberFull(mi) && m_weapon.IsInternalMagazineFull(mi))
  254. {
  255. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - internal magazine with share chamber is full"); }
  256. return true;
  257. }
  258. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - internal magazine with share chamber is not full"); }
  259. return false;
  260. }
  261. };
  262. class WeaponGuardChamberFiredOut extends WeaponGuardBase
  263. {
  264. protected Weapon_Base m_weapon;
  265. protected int m_muzzle;
  266. void WeaponGuardChamberFiredOut (Weapon_Base w = NULL, int muzzle_index = 0 ) { m_weapon = w; m_muzzle = muzzle_index; }
  267. override bool GuardCondition (WeaponEventBase e)
  268. {
  269. if (m_weapon.IsChamberFiredOut(m_muzzle))
  270. {
  271. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber (" + m_muzzle + ") fireout"); }
  272. return true;
  273. }
  274. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber (" + m_muzzle + ") not fireout"); }
  275. return false;
  276. }
  277. };
  278. class WeaponGuardCurrentChamberFiredOut extends WeaponGuardBase
  279. {
  280. protected Weapon_Base m_weapon;
  281. void WeaponGuardCurrentChamberFiredOut (Weapon_Base w = NULL) { m_weapon = w; }
  282. override bool GuardCondition (WeaponEventBase e)
  283. {
  284. int mi = m_weapon.GetCurrentMuzzle();
  285. if (m_weapon.IsChamberFiredOut(mi))
  286. {
  287. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber fired out"); }
  288. return true;
  289. }
  290. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber not fired out"); }
  291. return false;
  292. }
  293. };
  294. class WeaponGuardAnyChamberFiredOut extends WeaponGuardBase
  295. {
  296. protected Weapon_Base m_weapon;
  297. void WeaponGuardAnyChamberFiredOut (Weapon_Base w = NULL) { m_weapon = w; }
  298. override bool GuardCondition (WeaponEventBase e)
  299. {
  300. for (int i = 0; i < m_weapon.GetMuzzleCount(); i++)
  301. {
  302. if (m_weapon.IsChamberFiredOut(i))
  303. {
  304. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - multi chamber (" + i + ") fired out"); }
  305. return true;
  306. }
  307. }
  308. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - any chamber has not fired out"); }
  309. return false;
  310. }
  311. };
  312. class WeaponGuardCanAttachMag extends WeaponGuardBase
  313. {
  314. protected Weapon_Base m_weapon;
  315. void WeaponGuardCanAttachMag (Weapon_Base w = NULL) { m_weapon = w; }
  316. override bool GuardCondition (WeaponEventBase e)
  317. {
  318. int mi = m_weapon.GetCurrentMuzzle();
  319. if (m_weapon && e.m_magazine && m_weapon.CanAttachMagazine(mi, e.m_magazine))
  320. {
  321. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - can attach magazine"); }
  322. return true;
  323. }
  324. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - cannot attach magazine"); }
  325. return false;
  326. }
  327. };
  328. class WeaponGuardCanSwapMag extends WeaponGuardBase
  329. {
  330. protected Weapon_Base m_weapon;
  331. void WeaponGuardCanSwapMag (Weapon_Base w = NULL) { m_weapon = w; }
  332. override bool GuardCondition (WeaponEventBase e)
  333. {
  334. int mi = m_weapon.GetCurrentMuzzle();
  335. Magazine attached_mag = m_weapon.GetMagazine(mi);
  336. if (m_weapon && e.m_magazine && e.m_magazine != attached_mag /*&& m_weapon.CanSwapMagazine(mi, e.m_magazine)*/)
  337. {
  338. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - can swap magazine"); }
  339. return true;
  340. }
  341. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - cannot swap magazine"); }
  342. return false;
  343. }
  344. };
  345. class WeaponGuardCanDetachMag extends WeaponGuardBase
  346. {
  347. protected Weapon_Base m_weapon;
  348. void WeaponGuardCanDetachMag (Weapon_Base w = NULL) { m_weapon = w; }
  349. override bool GuardCondition (WeaponEventBase e)
  350. {
  351. int mi = m_weapon.GetCurrentMuzzle();
  352. if (m_weapon && e.m_magazine && m_weapon.GetMagazine(mi)/* && m_weapon.CanDetachMagazine(mi, e.m_magazine)*/)
  353. {
  354. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - can detach magazine"); }
  355. return true;
  356. }
  357. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - cannot detach magazine"); }
  358. return false;
  359. }
  360. };
  361. class WeaponGuardChamberHasRoomForMoreThanOne extends WeaponGuardBase
  362. {
  363. protected Weapon_Base m_weapon;
  364. void WeaponGuardChamberHasRoomForMoreThanOne (Weapon_Base w = NULL) { m_weapon = w; }
  365. override bool GuardCondition (WeaponEventBase e)
  366. {
  367. int mi = m_weapon.GetCurrentMuzzle();
  368. if (m_weapon.GetInternalMagazineMaxCartridgeCount(mi) - m_weapon.GetInternalMagazineCartridgeCount(mi) > 1)
  369. {
  370. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has room for more than 1b"); }
  371. return true;
  372. }
  373. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has no room for more than 1b"); }
  374. return false;
  375. }
  376. };
  377. class WeaponGuardInternalMagazineHasRoomForBullet extends WeaponGuardBase
  378. {
  379. protected Weapon_Base m_weapon;
  380. void WeaponGuardInternalMagazineHasRoomForBullet (Weapon_Base w = NULL) { m_weapon = w; }
  381. override bool GuardCondition (WeaponEventBase e)
  382. {
  383. int mi = m_weapon.GetCurrentMuzzle();
  384. if (m_weapon.GetInternalMagazineMaxCartridgeCount(mi) - m_weapon.GetInternalMagazineCartridgeCount(mi) >= 1)
  385. {
  386. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has room for bullet"); }
  387. return true;
  388. }
  389. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has no room for bullet"); }
  390. return false;
  391. }
  392. };
  393. class WeaponGuardChamberHasRoomForOne extends WeaponGuardBase
  394. {
  395. protected Weapon_Base m_weapon;
  396. void WeaponGuardChamberHasRoomForOne (Weapon_Base w = NULL) { m_weapon = w; }
  397. override bool GuardCondition (WeaponEventBase e)
  398. {
  399. int mi = m_weapon.GetCurrentMuzzle();
  400. if (m_weapon.GetTotalMaxCartridgeCount(mi) - m_weapon.GetTotalCartridgeCount(mi) == 1)
  401. {
  402. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has room for 1b"); }
  403. return true;
  404. }
  405. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has no room for 1b"); }
  406. return false;
  407. }
  408. };
  409. class WeaponGuardChamberMultiHasRoomBulltet extends WeaponGuardBase
  410. {
  411. protected Weapon_Base m_weapon;
  412. void WeaponGuardChamberMultiHasRoomBulltet (Weapon_Base w = NULL) { m_weapon = w; }
  413. override bool GuardCondition (WeaponEventBase e)
  414. {
  415. int i = m_weapon.GetMuzzleCount() - 1;
  416. for ( ; i >= 0; i--)
  417. {
  418. if (m_weapon.GetTotalMaxCartridgeCount(i) - m_weapon.GetTotalCartridgeCount(i) >= 1)
  419. {
  420. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has room for 1b"); }
  421. return true;
  422. }
  423. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has no room for 1b"); }
  424. }
  425. return false;
  426. }
  427. };
  428. class WeaponGuardChamberMultiHasRoomBulltetIgnoreLast extends WeaponGuardBase
  429. {
  430. protected Weapon_Base m_weapon;
  431. void WeaponGuardChamberMultiHasRoomBulltetIgnoreLast (Weapon_Base w = NULL) { m_weapon = w; }
  432. override bool GuardCondition (WeaponEventBase e)
  433. {
  434. int i = m_weapon.GetMuzzleCount() - 1;
  435. bool emty_one = false;
  436. for ( ; i >= 0; i--)
  437. {
  438. if (m_weapon.GetTotalMaxCartridgeCount(i) - m_weapon.GetTotalCartridgeCount(i) >= 1)
  439. {
  440. if ( !emty_one )
  441. {
  442. emty_one = true;
  443. }
  444. else
  445. {
  446. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has room for 1b"); }
  447. return true;
  448. }
  449. }
  450. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - chamber has no room for 1b"); }
  451. }
  452. return false;
  453. }
  454. };
  455. class WeaponGuardHasAmmoInLoopedState extends WeaponGuardBase
  456. {
  457. WeaponChambering_Base m_state;
  458. void WeaponGuardHasAmmoInLoopedState (WeaponChambering_Base state) { m_state = state; }
  459. override bool GuardCondition (WeaponEventBase e)
  460. {
  461. Magazine mag = m_state.m_srcMagazine;
  462. if (mag != NULL && mag.GetAmmoCount() > 0)
  463. {
  464. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - has ammo in looped state"); }
  465. return true;
  466. }
  467. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] guard - no ammo in looped state"); }
  468. return false;
  469. }
  470. };
  471. class WeaponGuardMagazinesHaveEqualSizes extends WeaponGuardBase
  472. {
  473. protected Weapon_Base m_weapon;
  474. void WeaponGuardMagazinesHaveEqualSizes (Weapon_Base w = NULL) { m_weapon = w; }
  475. override bool GuardCondition (WeaponEventBase e)
  476. {
  477. int mi = m_weapon.GetCurrentMuzzle();
  478. Magazine mag = m_weapon.GetMagazine(mi);
  479. Magazine mag2 = e.m_magazine;
  480. if (mag != NULL && mag2 != NULL)
  481. {
  482. bool eq = magazinesHaveEqualSizes(mag, mag2);
  483. if (eq)
  484. {
  485. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - same inventory sizes"); }
  486. return true;
  487. }
  488. if (LogManager.IsWeaponLogEnable()) { wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - different inventory sizes"); }
  489. return false;
  490. }
  491. Error("[wpnfsm] " + Object.GetDebugName(m_weapon) + " guard - mag == NULL or mag2 == NULL, cannot perform comparison");
  492. return false;
  493. }
  494. };
  495. class WeaponGuardWeaponCharged extends WeaponGuardBase
  496. {
  497. protected Weapon_Base m_weapon;
  498. void WeaponGuardWeaponCharged (Weapon_Base w = NULL) { m_weapon = w; }
  499. override bool GuardCondition (WeaponEventBase e)
  500. {
  501. return m_weapon.IsCharged();
  502. }
  503. }
  504. class WeaponGuardWeaponDischarged extends WeaponGuardBase
  505. {
  506. protected Weapon_Base m_weapon;
  507. void WeaponGuardWeaponDischarged (Weapon_Base w = NULL) { m_weapon = w; }
  508. override bool GuardCondition (WeaponEventBase e)
  509. {
  510. return !m_weapon.IsCharged();
  511. }
  512. }
  513. class WeaponGuardWeaponOpen extends WeaponGuardBase
  514. {
  515. protected Weapon_Base m_weapon;
  516. void WeaponGuardWeaponOpen (Weapon_Base w = NULL) { m_weapon = w; }
  517. override bool GuardCondition (WeaponEventBase e)
  518. {
  519. return m_weapon.IsWeaponOpen();
  520. }
  521. }
  522. class WeaponGuardWeaponManagerWantContinue extends WeaponGuardBase
  523. {
  524. override bool GuardCondition (WeaponEventBase e)
  525. {
  526. PlayerBase player = PlayerBase.Cast(e.m_player);
  527. return player.GetWeaponManager().WantContinue();
  528. }
  529. };