A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartItem.cc
Go to the documentation of this file.
1#include "KartItem.hh"
2
5
7
8namespace Kinoko::Item {
9
16
19KartItem::~KartItem() = default;
20
24void KartItem::init(size_t playerIdx) {
25 apply(playerIdx);
26}
27
39 bool prevButton = m_flags.onBit(eFlags::ItemButtonHold);
41
42 const auto &currentInputs = inputs()->currentState();
43 if (currentInputs.item()) {
45 }
46
47 auto &status = KartObjectProxy::status();
48
54 }
55 } else {
60 } else {
61 const auto *raceMgr = System::RaceManager::Instance();
63 canUse = canUse && raceMgr->isStageReached(System::RaceManager::Stage::Race);
65 canUse = canUse && (m_inventory.id() != ItemId::None);
66
67 if (canUse) {
68 // For now, assume only time trials are valid and use a mushroom
70 }
71 }
72 }
73}
74
78 if (m_inventory.id() != ItemId::None) {
80 }
81}
82
89
95
96} // namespace Kinoko::Item
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:470
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:437
void clear()
Clears the item slot and resets the count to 0.
void useItem(int count)
Updates the count to reflect using an item, clearing the id if m_currentCount reaches 0.
ItemId id() const
Gets the current item id in the slot.
void activateMushroom()
Applies a mushroom boost to the kart's movement.
Definition KartItem.cc:92
void init(size_t playerIdx)
Initializes the KartObjectProxy accessor pointer.
Definition KartItem.cc:24
void calc()
Calculates item activation based on the controller input state.
Definition KartItem.cc:38
KartItem()
Constructor.
Definition KartItem.cc:13
ItemInventory m_inventory
The current item inventory for the kart.
Definition KartItem.hh:53
~KartItem()
Default destructor.
@ Lockout
The player cannot currently use an item.
Definition KartItem.hh:44
@ ItemButtonHold
The item button is currently being held down.
Definition KartItem.hh:45
@ ItemButtonActivation
The item button was pressed this frame.
Definition KartItem.hh:46
void useMushroom()
Activates a mushroom boost and decrements the item count in the inventory slot.
Definition KartItem.cc:85
void clear()
Clears the current item inventory if it is not empty.
Definition KartItem.cc:77
Flags m_flags
Bit flags for item usage state.
Definition KartItem.hh:52
Status & status()
Gets a reference to the kart's Status bitfield.
const System::KPad * inputs() const
Gets a pointer to the kart's KPad subsystem.
void apply(size_t idx)
Copies over the KartAccessor pointers from the kart object at the given index.
KartMove * move()
Gets a pointer to the kart's KartMove subsystem.
const RaceInputState & currentState() const
static RaceManager * Instance()
Pertains to item handling.
@ None
No item.
Definition ItemId.hh:9
@ Burnout
Set during a burnout on race start.
Definition Status.hh:60
@ BeforeRespawn
Set on respawn collision, cleared on position snap.
Definition Status.hh:17
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:166
constexpr TBitFlag< T, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:74
constexpr TBitFlag< T, E > & changeBit(bool on, Es... es)
Changes the state of the corresponding bits for the provided enum values.
Definition BitFlag.hh:143
constexpr void makeAllZero()
Resets all the bits to zero.
Definition BitFlag.hh:292
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:85