ManaPlus
Public Member Functions | Private Attributes
FloorItem Class Reference

#include <flooritem.h>

Inheritance diagram for FloorItem:
ActorSprite CompoundSprite Actor Sprite

Public Member Functions

 FloorItem (const BeingId id, const int itemId, const int x, const int y, const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, const Identified identified, const Damaged damaged, const int *const cards)
 
void postInit (Map *const map, int subX, int subY)
 
ActorTypeT getType () const
 
void draw (Graphics *const graphics, const int offsetX, const int offsetY) const
 
int getItemId () const
 
const ItemInfogetInfo () const
 
std::string getName () const
 
int getTileX () const
 
int getTileY () const
 
void incrementPickup ()
 
unsigned getPickupCount () const
 
ItemColor getColor () const
 
bool getShowMsg () const
 
void setShowMsg (const bool n)
 
void disableHightlight ()
 
CursorT getHoverCursor () const
 
void setCards (const int *const cards, int sz)
 
int getCard (const int index) const
 
int getRefine () const
 
ItemTypeT getItemType () const
 
Identified getIdentified () const
 
Damaged getDamaged () const
 
- Public Member Functions inherited from ActorSprite
 ActorSprite (const BeingId id)
 
 ~ActorSprite ()
 
BeingId getId () const
 
void setId (const BeingId id)
 
virtual void logic ()
 
void setMap (Map *const map)
 
virtual BlockTypeT getBlockType () const
 
void controlAutoParticle (Particle *const particle)
 
void controlCustomParticle (Particle *const particle)
 
virtual TargetCursorSizeT getTargetCursorSize () const
 
virtual int getTargetOffsetX () const
 
virtual int getTargetOffsetY () const
 
void setTargetType (const TargetCursorTypeT type)
 
void untarget ()
 
void setStatusEffect (const int32_t index, const Enable active, const IsStart start)
 
void setStatusEffectOpitons (const uint32_t option, const uint32_t opt1, const uint32_t opt2, const uint32_t opt3)
 
void setStatusEffectOpitons (const uint32_t option, const uint32_t opt1, const uint32_t opt2)
 
void setStatusEffectOpiton0 (const uint32_t option)
 
void setAlpha (const float alpha)
 
float getAlpha () const
 
int getWidth () const
 
int getHeight () const
 
void addActorSpriteListener (ActorSpriteListener *const listener)
 
void removeActorSpriteListener (ActorSpriteListener *const listener)
 
int getActorX () const
 
int getActorY () const
 
void setPoison (const bool b)
 
bool getPoison () const
 
void setHaveCart (const bool b)
 
bool getHaveCart () const
 
virtual void setRiding (const bool b)
 
virtual void setTrickDead (const bool b)
 
bool isTrickDead () const
 
const std::set< int32_t > & getStatusEffects () const
 
std::string getStatusEffectsString () const
 
virtual void stopCast (const bool b)
 
size_t getParticlesCount () const
 
void controlParticleDeleted (const Particle *const particle)
 
- Public Member Functions inherited from CompoundSprite
 CompoundSprite ()
 
 ~CompoundSprite ()
 
bool reset ()
 
bool play (const std::string &action)
 
bool update (const int time)
 
void drawSimple (Graphics *const graphics, const int posX, const int posY) const
 
int getWidth () const
 
int getHeight () const
 
const ImagegetImage () const
 
bool setSpriteDirection (const SpriteDirection::Type direction)
 
int getNumberOfLayers () const
 
unsigned int getCurrentFrame () const
 
unsigned int getFrameCount () const
 
void addSprite (Sprite *const sprite)
 
void setSprite (const size_t layer, Sprite *const sprite)
 
void removeSprite (const int layer)
 
void clear ()
 
void ensureSize (const size_t layerCount)
 
void drawSprites (Graphics *const graphics, const int posX, const int posY) const
 
virtual void drawSpritesSDL (Graphics *const graphics, const int posX, const int posY) const
 
void setAlpha (float alpha)
 
bool updateNumber (const unsigned num)
 
int getLastTime () const
 
int getStartTime () const
 
- Public Member Functions inherited from Sprite
virtual ~Sprite ()
 
virtual const void * getHash () const
 
virtual const void * getHash2 () const
 
- Public Member Functions inherited from Actor
virtual ~Actor ()
 
const VectorgetPixelPositionF () const
 
virtual void setPixelPositionF (const Vector &pos)
 
int getPixelX () const
 
virtual int getPixelY () const
 
virtual int getSortPixelY () const
 
virtual int getNumberOfLayers () const
 
const MapgetMap () const
 

Private Attributes

int mCards [4]
 
int mItemId
 
int mX
 
int mY
 
time_t mDropTime
 
int mAmount
 
int mRefine
 
int mHeightPosDiff
 
ItemTypeT mItemType
 
unsigned int mPickupCount
 
CursorT mCursor
 
ItemColor mColor
 
Identified mIdentified
 
Damaged mDamaged
 
bool mShowMsg
 
bool mHighlight
 

Additional Inherited Members

- Public Types inherited from CompoundSprite
typedef std::vector< Sprite * >::iterator SpriteIterator
 
typedef std::vector< Sprite * >::const_iterator SpriteConstIterator
 
- Static Public Member Functions inherited from ActorSprite
static void load ()
 
static void unload ()
 
- Static Public Member Functions inherited from CompoundSprite
static void setEnableDelay (bool b)
 
- Data Fields inherited from CompoundSprite
std::vector< Sprite * > mSprites
 
- Data Fields inherited from Actor
int mPixelX
 
int mPixelY
 
- Protected Types inherited from ActorSprite
typedef std::list< ActorSpriteListener * > ActorSpriteListeners
 
typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator
 
- Protected Types inherited from CompoundSprite
typedef std::list< CompoundItem * > ImagesCache
 
- Protected Member Functions inherited from ActorSprite
virtual void updateStatusEffect (const int32_t index, const Enable newStatus, const IsStart start)
 
virtual void handleStatusEffect (const StatusEffect *const effect, const int32_t effectId, const Enable newStatus, const IsStart start)
 
void setupSpriteDisplay (const SpriteDisplay &display, const ForceDisplay forceDisplay, const DisplayTypeT displayType, const std::string &color)
 
- Protected Member Functions inherited from CompoundSprite
void redraw () const
 
void updateImages () const
 
bool updateFromCache () const
 
void initCurrentCacheItem () const
 
- Protected Member Functions inherited from Sprite
 Sprite ()
 
- Protected Member Functions inherited from Actor
 Actor ()
 
- Static Protected Member Functions inherited from ActorSprite
static void initTargetCursor ()
 
static void cleanupTargetCursors ()
 
- Protected Attributes inherited from ActorSprite
std::set< int32_t > mStatusEffects
 
ParticleVector mStatusParticleEffects
 
ParticleList mChildParticleEffects
 
int mHorseId
 
BeingId mId
 
AnimatedSpritemUsedTargetCursor
 
ActorSpriteListeners mActorSpriteListeners
 
int mCursorPaddingX
 
int mCursorPaddingY
 
bool mMustResetParticles
 
bool mPoison
 
bool mHaveCart
 
bool mTrickDead
 
- Protected Attributes inherited from CompoundSprite
ImagesCache imagesCache
 
CompoundItemmCacheItem
 
ImagemImage
 
ImagemAlphaImage
 
int mOffsetX
 
int mOffsetY
 
int mStartTime
 
int mLastTime
 
int mNextRedrawTime
 
bool mNeedsRedraw
 
bool mEnableAlphaFix
 
bool mDisableAdvBeingCaching
 
bool mDisableBeingCaching
 
- Protected Attributes inherited from Sprite
float mAlpha
 
- Protected Attributes inherited from Actor
MapmMap
 
Vector mPos
 
int mYDiff
 
- Static Protected Attributes inherited from ActorSprite
static AnimatedSpritetargetCursor [static_cast< size_t >(TargetCursorType::NUM_TCT)][static_cast< size_t >(TargetCursorSize::NUM_TC)]
 
static bool loaded = false
 
- Static Protected Attributes inherited from CompoundSprite
static bool mEnableDelay = true
 

Detailed Description

An item lying on the floor.

Definition at line 44 of file flooritem.h.

Constructor & Destructor Documentation

◆ FloorItem()

FloorItem::FloorItem ( const BeingId  id,
const int  itemId,
const int  x,
const int  y,
const ItemTypeT  itemType,
const int  amount,
const int  refine,
const ItemColor  color,
const Identified  identified,
const Damaged  damaged,
const int *const  cards 
)

Constructor.

Parameters
idthe unique ID of this item instance
itemIdthe item ID
xthe x position in tiles
ythe y position in tiles
amountthe item amount
colorthe item color

Definition at line 50 of file flooritem.cpp.

59  :
60  ActorSprite(id),
61  mCards(),
62  mItemId(itemId),
63  mX(x),
64  mY(y),
66  mAmount(amount),
67  mRefine(refine),
68  mHeightPosDiff(0),
69  mItemType(itemType),
70  mPickupCount(0),
72  mColor(color),
73  mIdentified(identified),
74  mDamaged(damaged),
75  mShowMsg(true),
76  mHighlight(config.getBoolValue("floorItemsHighlight"))
77 {
78  setCards(cards, maxCards);
79 }
#define maxCards
Definition: cards.h:25
ActorSprite(const BeingId id)
Definition: actorsprite.cpp:69
bool getBoolValue(const std::string &key) const
int mCards[4]
Definition: flooritem.h:137
int mAmount
Definition: flooritem.h:141
int mHeightPosDiff
Definition: flooritem.h:143
int mRefine
Definition: flooritem.h:142
ItemTypeT mItemType
Definition: flooritem.h:144
Identified mIdentified
Definition: flooritem.h:148
bool mShowMsg
Definition: flooritem.h:150
time_t mDropTime
Definition: flooritem.h:140
void setCards(const int *const cards, int sz)
Definition: flooritem.cpp:130
ItemColor mColor
Definition: flooritem.h:147
bool mHighlight
Definition: flooritem.h:151
unsigned int mPickupCount
Definition: flooritem.h:145
Damaged mDamaged
Definition: flooritem.h:149
int mItemId
Definition: flooritem.h:138
CursorT mCursor
Definition: flooritem.h:146
Configuration config
volatile time_t cur_time
Definition: timer.cpp:58
@ CURSOR_PICKUP
Definition: cursor.h:35

References maxCards, and setCards().

Member Function Documentation

◆ disableHightlight()

void FloorItem::disableHightlight ( )
inline

Definition at line 114 of file flooritem.h.

115  { mHighlight = false; }

References mHighlight.

Referenced by ActorManager::createItem().

◆ draw()

void FloorItem::draw ( Graphics *const  graphics,
const int  offsetX,
const int  offsetY 
) const
virtual

Draws the Actor to the given graphics context.

Note: this function could be simplified if the graphics context would support setting a translation offset. It already does this partly with the clipping rectangle support.

Implements Actor.

Definition at line 159 of file flooritem.cpp.

161 {
162  if (mMap == nullptr)
163  return;
164 
165  BLOCK_START("FloorItem::draw")
166  const int x = mX * mMap->getTileWidth() + offsetX;
167  const int y = mY * mMap->getTileHeight() + offsetY - mHeightPosDiff;
168  Font *font = nullptr;
169 
170  if (mHighlight)
171  {
172  const time_t curTime = cur_time;
173  font = gui->getFont();
174  if (mDropTime < curTime)
175  {
176  const int dx = mapTileSize;
177  const int dy = mapTileSize;
178 
179  if (curTime > mDropTime + 28 && curTime < mDropTime + 50)
180  {
181  graphics->setColor(Color(80, 200, 20, 200));
182  graphics->fillRectangle(Rect(
183  x, y, dx, dy));
184  }
185  else if (curTime > mDropTime + 19
186  && curTime < mDropTime + 28)
187  {
188  graphics->setColor(Color(200, 80, 20,
189  80 + 10 * CAST_S32(curTime - mDropTime - 18)));
190  graphics->fillRectangle(Rect(
191  x, y, dx, dy));
192  }
193  else if (curTime > mDropTime && curTime < mDropTime + 20)
194  {
195  graphics->setColor(Color(20, 20, 255,
196  7 * CAST_S32(curTime - mDropTime)));
197  graphics->fillRectangle(Rect(x, y, dx, dy));
198  }
199  }
200  }
201 
202  const int px = getActorX() + offsetX;
203  const int py = getActorY() + offsetY;
204  CompoundSprite::drawSimple(graphics, px, py);
205 
206  if (mHighlight)
207  {
208  if (font != nullptr && mAmount > 1)
209  {
210  const Color &color = userPalette->getColor(
212  255U);
213  font->drawString(graphics,
214  color, color,
215  toString(mAmount),
216  x, y);
217  }
218  }
219  BLOCK_END("FloorItem::draw")
220 }
#define CAST_S32
Definition: cast.h:30
int getActorX() const
Definition: actorsprite.h:160
int getActorY() const
Definition: actorsprite.h:163
Map * mMap
Definition: actor.h:139
Definition: color.h:76
void drawSimple(Graphics *const graphics, const int posX, const int posY) const
Definition: font.h:90
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
Font * getFont() const
Definition: gui.h:160
Definition: rect.h:74
const Color & getColor(UserColorIdT type, const unsigned int alpha)
Definition: userpalette.h:160
static const int mapTileSize
Definition: map.h:27
if(!vert) return
Gui * gui
Definition: gui.cpp:111
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
UserPalette * userPalette
Definition: userpalette.cpp:34

References BLOCK_END, BLOCK_START, CAST_S32, cur_time, CompoundSprite::drawSimple(), Font::drawString(), Graphics::fillRectangle(), UserColorId::FLOOR_ITEM_TEXT, ActorSprite::getActorX(), ActorSprite::getActorY(), UserPalette::getColor(), Gui::getFont(), Map::getTileHeight(), Map::getTileWidth(), gui, mAmount, mapTileSize, mDropTime, mHeightPosDiff, mHighlight, Actor::mMap, mX, mY, Graphics::setColor(), Catch::toString(), userPalette, x, and y.

◆ getCard()

int FloorItem::getCard ( const int  index) const

Definition at line 222 of file flooritem.cpp.

223 {
224  if (index < 0 || index >= maxCards)
225  return 0;
226  return mCards[index];
227 }

References maxCards, and mCards.

Referenced by PopupMenu::handleLink(), and PopupMenu::showPopup().

◆ getColor()

ItemColor FloorItem::getColor ( ) const
inline

Definition at line 105 of file flooritem.h.

106  { return mColor; }

References mColor.

◆ getDamaged()

Damaged FloorItem::getDamaged ( ) const
inline

Definition at line 133 of file flooritem.h.

134  { return mDamaged; }

References mDamaged.

◆ getHoverCursor()

CursorT FloorItem::getHoverCursor ( ) const
inline

Definition at line 117 of file flooritem.h.

118  { return mCursor; }

References mCursor.

◆ getIdentified()

Identified FloorItem::getIdentified ( ) const
inline

Definition at line 130 of file flooritem.h.

131  { return mIdentified; }

References mIdentified.

◆ getInfo()

const ItemInfo & FloorItem::getInfo ( ) const

Returns the item info for this floor item. Useful for adding an item link for the floor item to chat.

Definition at line 141 of file flooritem.cpp.

142 {
143  return ItemDB::get(mItemId);
144 }
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792

References ItemDB::get(), and mItemId.

◆ getItemId()

int FloorItem::getItemId ( ) const
inline

Returns the item ID.

Definition at line 82 of file flooritem.h.

83  { return mItemId; }

References mItemId.

Referenced by PopupMenu::handleLink(), ItemSoundManager::playSfx(), and PopupMenu::showPopup().

◆ getItemType()

ItemTypeT FloorItem::getItemType ( ) const
inline

Definition at line 127 of file flooritem.h.

128  { return mItemType; }

References mItemType.

◆ getName()

std::string FloorItem::getName ( ) const

Definition at line 146 of file flooritem.cpp.

147 {
148  const ItemInfo &info = ItemDB::get(mItemId);
149 #ifdef TMWA_SUPPORT
151  {
152  return info.getName();
153  }
154 #endif // TMWA_SUPPORT
155 
156  return info.getName(mColor);
157 }
bool info(InputEvent &event)
Definition: commands.cpp:57
ServerTypeT getNetworkType()
Definition: net.cpp:189

References ItemDB::get(), Net::getNetworkType(), Actions::info(), mColor, mItemId, and ServerType::TMWATHENA.

Referenced by ActorManager::checkForPickup(), ActorManager::pickUpAll(), ActorManager::pickUpNearest(), and PopupMenu::showPopup().

◆ getPickupCount()

unsigned FloorItem::getPickupCount ( ) const
inline

Definition at line 102 of file flooritem.h.

103  { return mPickupCount; }

References mPickupCount.

Referenced by ActorManager::pickUpAll().

◆ getRefine()

int FloorItem::getRefine ( ) const
inline

Definition at line 124 of file flooritem.h.

125  { return mRefine; }

References mRefine.

◆ getShowMsg()

bool FloorItem::getShowMsg ( ) const
inline

Definition at line 108 of file flooritem.h.

109  { return mShowMsg; }

References mShowMsg.

Referenced by LocalPlayer::pickedUp().

◆ getTileX()

int FloorItem::getTileX ( ) const
inlinevirtual

Returns the x coordinate in tiles of the actor.

Reimplemented from Actor.

Definition at line 93 of file flooritem.h.

94  { return mX; }

References mX.

Referenced by LocalPlayer::pickUp(), and ActorManager::pickUpNearest().

◆ getTileY()

int FloorItem::getTileY ( ) const
inlinevirtual

Returns the y coordinate in tiles of the actor.

Reimplemented from Actor.

Definition at line 96 of file flooritem.h.

97  { return mY; }

References mY.

Referenced by LocalPlayer::pickUp(), and ActorManager::pickUpNearest().

◆ getType()

ActorTypeT FloorItem::getType ( ) const
inlinevirtual

Returns the type of the ActorSprite.

Reimplemented from ActorSprite.

Definition at line 72 of file flooritem.h.

73  { return ActorType::FloorItem; }
@ FloorItem
Definition: actortype.h:34

References ActorType::FloorItem.

◆ incrementPickup()

void FloorItem::incrementPickup ( )
inline

Definition at line 99 of file flooritem.h.

100  { mPickupCount ++; }

References mPickupCount.

Referenced by ActorManager::pickUpAll().

◆ postInit()

void FloorItem::postInit ( Map *const  map,
int  subX,
int  subY 
)

Definition at line 81 of file flooritem.cpp.

82 {
83  setMap(map);
84  const ItemInfo &info = ItemDB::get(mItemId);
85  if (map != nullptr)
86  {
87  const int maxX = info.getMaxFloorOffsetX();
88  const int maxY = info.getMaxFloorOffsetY();
89 
91  {
92  if (subX > maxX)
93  subX = maxX;
94  else if (subX < -maxX)
95  subX = -maxX;
96  if (subY > maxY)
97  subY = maxY;
98  else if (subY < -maxY)
99  subY = -maxY;
100 
101  subX -= 8;
102  subY -= 8;
103  }
104 
105  mHeightPosDiff = map->getHeightOffset(mX, mY) * 16;
106  mPixelX = mX * map->getTileWidth()
107  + subX + mapTileSize / 2;
108  mPixelY = mY * map->getTileHeight()
109  + subY + mapTileSize - mHeightPosDiff;
110  mPos.x = static_cast<float>(mPixelX);
111  mPos.y = static_cast<float>(mPixelY);
112  mYDiff = 31 - mHeightPosDiff;
113  }
114  else
115  {
116  mPixelX = 0;
117  mPixelY = 0;
118  mPos.x = 0;
119  mPos.y = 0;
120  mYDiff = 31;
121  }
122 
123  mCursor = info.getPickupCursor();
124  setupSpriteDisplay(info.getDisplay(),
127  info.getDyeIconColorsString(mColor));
128 }
void setMap(Map *const map)
void setupSpriteDisplay(const SpriteDisplay &display, const ForceDisplay forceDisplay, const DisplayTypeT displayType, const std::string &color)
int mPixelX
Definition: actor.h:133
Vector mPos
Definition: actor.h:140
int mYDiff
Definition: actor.h:141
int mPixelY
Definition: actor.h:134
uint8_t getHeightOffset(const int x, const int y) const
Definition: map.cpp:1631
int getTileHeight() const
Definition: map.h:184
int getTileWidth() const
Definition: map.h:178
virtual bool haveExtendedDropsPosition() const =0
float y
Definition: vector.h:209
float x
Definition: vector.h:209
const bool ForceDisplay_true
Definition: forcedisplay.h:30
Net::ServerFeatures * serverFeatures
Definition: net.cpp:101

References DisplayType::Floor, ForceDisplay_true, ItemDB::get(), Map::getHeightOffset(), Map::getTileHeight(), Map::getTileWidth(), Net::ServerFeatures::haveExtendedDropsPosition(), Actions::info(), mapTileSize, mColor, mCursor, mHeightPosDiff, mItemId, Actor::mPixelX, Actor::mPixelY, Actor::mPos, mX, mY, Actor::mYDiff, serverFeatures, ActorSprite::setMap(), ActorSprite::setupSpriteDisplay(), Vector::x, and Vector::y.

Referenced by ActorManager::createItem().

◆ setCards()

void FloorItem::setCards ( const int *const  cards,
int  sz 
)

Definition at line 130 of file flooritem.cpp.

132 {
133  if (sz < 0 || cards == nullptr)
134  return;
135  if (sz > maxCards)
136  sz = maxCards;
137  for (int f = 0; f < sz; f ++)
138  mCards[f] = cards[f];
139 }

References maxCards, and mCards.

Referenced by FloorItem().

◆ setShowMsg()

void FloorItem::setShowMsg ( const bool  n)
inline

Definition at line 111 of file flooritem.h.

112  { mShowMsg = n; }

References mShowMsg.

Referenced by LocalPlayer::pickedUp().

Field Documentation

◆ mAmount

int FloorItem::mAmount
private

Definition at line 141 of file flooritem.h.

Referenced by draw().

◆ mCards

int FloorItem::mCards[4]
private

Definition at line 137 of file flooritem.h.

Referenced by getCard(), and setCards().

◆ mColor

ItemColor FloorItem::mColor
private

Definition at line 147 of file flooritem.h.

Referenced by getColor(), getName(), and postInit().

◆ mCursor

CursorT FloorItem::mCursor
private

Definition at line 146 of file flooritem.h.

Referenced by getHoverCursor(), and postInit().

◆ mDamaged

Damaged FloorItem::mDamaged
private

Definition at line 149 of file flooritem.h.

Referenced by getDamaged().

◆ mDropTime

time_t FloorItem::mDropTime
private

Definition at line 140 of file flooritem.h.

Referenced by draw().

◆ mHeightPosDiff

int FloorItem::mHeightPosDiff
private

Definition at line 143 of file flooritem.h.

Referenced by draw(), and postInit().

◆ mHighlight

bool FloorItem::mHighlight
private

Definition at line 151 of file flooritem.h.

Referenced by disableHightlight(), and draw().

◆ mIdentified

Identified FloorItem::mIdentified
private

Definition at line 148 of file flooritem.h.

Referenced by getIdentified().

◆ mItemId

int FloorItem::mItemId
private

Definition at line 138 of file flooritem.h.

Referenced by getInfo(), getItemId(), getName(), and postInit().

◆ mItemType

ItemTypeT FloorItem::mItemType
private

Definition at line 144 of file flooritem.h.

Referenced by getItemType().

◆ mPickupCount

unsigned int FloorItem::mPickupCount
private

Definition at line 145 of file flooritem.h.

Referenced by getPickupCount(), and incrementPickup().

◆ mRefine

int FloorItem::mRefine
private

Definition at line 142 of file flooritem.h.

Referenced by getRefine().

◆ mShowMsg

bool FloorItem::mShowMsg
private

Definition at line 150 of file flooritem.h.

Referenced by getShowMsg(), and setShowMsg().

◆ mX

int FloorItem::mX
private

Definition at line 139 of file flooritem.h.

Referenced by draw(), getTileX(), and postInit().

◆ mY

int FloorItem::mY
private

Definition at line 139 of file flooritem.h.

Referenced by draw(), getTileY(), and postInit().


The documentation for this class was generated from the following files: