freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Bucket.cpp
Go to the documentation of this file.
1  /* freg, Free-Roaming Elementary Game with open and interactive world
2  * Copyright (C) 2012-2014 Alexander 'mmaulwurff' Kromm
3  * mmaulwurff@gmail.com
4  *
5  * This file is part of FREG.
6  *
7  * FREG is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FREG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with FREG. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "Bucket.h"
21 
22 Bucket::Bucket(const int kind, const int sub) :
23  Block(kind, sub),
24  Inventory(1)
25 {}
26 
27 Bucket::Bucket(QDataStream & str, const int kind, const int sub) :
28  Block(str, kind, sub),
29  Inventory(str, 1)
30 {}
31 
32 void Bucket::Damage(int, int) { Break(); }
33 void Bucket::ReceiveSignal(const QString str) { Block::ReceiveSignal(str); }
34 Inventory * Bucket::HasInventory() { return this; }
36 
37 QString Bucket::FullName() const {
38  QString name;
39  switch ( Sub() ) {
40  default: name = QObject::tr("Bucket"); break;
41  case GLASS: name = QObject::tr("Bottle"); break;
42  }
43  return ( GetInvSub(0) == AIR ) ?
44  QObject::tr("Empty bucket (%1)").arg(SubName(Sub())) :
45  QObject::tr("%1 (%2) with %3 (%4/%5 full)")
46  .arg(name)
47  .arg(SubName(Sub()))
48  .arg(ShowBlock(0)->FullName().toLower())
49  .arg(Number(0))
50  .arg(MAX_STACK_SIZE);
51 }
52 
53 bool Bucket::Get(Block * const block, const int start) {
54  if ( block->Wearable() == WEARABLE_VESSEL ) {
55  for (int i=start; i<Size(); ++i) {
56  if ( GetExact(block, i) ) {
57  return true;
58  }
59  }
60  }
61  return false;
62 }
63 
64 void Bucket::SaveAttributes(QDataStream & out) const {
66 }
67 
68 int Bucket::Weight() const {
69  return Block::Weight()/6 + Inventory::Weight();
70 }
Bucket(int sub, int id)
Definition: Bucket.cpp:22
static QString SubName(int sub)
Returns translated substance name.
Definition: Block.cpp:69
int Number(int i) const
Definition: Inventory.cpp:28
usage_types Use(Block *) override
Definition: Bucket.cpp:35
virtual int Weight() const
Definition: Block.cpp:242
Inventory * HasInventory() overridefinal
Definition: Bucket.cpp:34
int GetInvSub(int i) const
Returns AIR if slot number i is empty.
Definition: Inventory.cpp:159
Block * ShowBlock(int slot) const
Definition: Inventory.cpp:182
QString FullName() const override
Definition: Bucket.cpp:37
int Size() const
Definition: Inventory.cpp:27
9
Definition: header.h:169
bool Get(Block *block, int start) override
Returns true on success.
Definition: Bucket.cpp:53
int Sub() const
Definition: Block.h:144
void ReceiveSignal(QString str) override
Receive text signal.
Definition: Bucket.cpp:33
virtual wearable Wearable() const
Definition: Block.cpp:212
virtual bool GetExact(Block *block, int num)
Returns true if block found its place.
Definition: Inventory.cpp:103
void Damage(int dmg, int dmg_kind) override
Definition: Bucket.cpp:32
19
Definition: header.h:179
usage_types
Definition: header.h:196
virtual int Weight() const
Definition: Inventory.cpp:169
void SaveAttributes(QDataStream &out) const override
Definition: Bucket.cpp:64
Provides block ability to contain other blocks inside.
Definition: Inventory.h:33
void Break()
Set durability to null.
Definition: Block.cpp:230
const int MAX_STACK_SIZE
Definition: Inventory.h:29
virtual void ReceiveSignal(QString)
Receive text signal.
Definition: Block.cpp:211
Block without special physics and attributes.
Definition: Block.h:89
virtual void SaveAttributes(QDataStream &out) const
Definition: Inventory.cpp:65
int Weight() const override
Definition: Bucket.cpp:68