A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ItemStack.cc 585B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "ItemStack.h"
  2. #include "Item.h"
  3. namespace Swan {
  4. ItemStack ItemStack::insert(ItemStack st) {
  5. // If this is an empty item stack, just copy over st
  6. if (empty()) {
  7. item_ = st.item_;
  8. count_ = st.count_;
  9. st.item_ = nullptr;
  10. st.count_ = 0;
  11. return st;
  12. }
  13. // If st is a stack of a different kind of item, we don't want it
  14. if (st.item_ != item_)
  15. return st;
  16. // Merge
  17. count_ += st.count_;
  18. if (count_ > item_->maxStack_) {
  19. st.count_ = count_ - item_->maxStack_;
  20. count_ = item_->maxStack_;
  21. } else {
  22. st.count_ = 0;
  23. st.item_ = nullptr;
  24. }
  25. return st;
  26. }
  27. }