freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CraftManager.h
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 #ifndef CRAFTMANAGER_H
21 #define CRAFTMANAGER_H
22 
23 #include "header.h"
24 #include <QJsonArray>
25 
26 struct CraftItem final {
27  CraftItem & operator=(const CraftItem &) = delete;
28 
29  bool operator<(const CraftItem & item) const;
30 
31  const int num;
32  const int kind;
33  const int sub;
34 }; // CraftItem
35 
36 /** \class CraftList CraftManager.h
37  * \brief This class represents craft recipe.
38  *
39  * It stores recipe like this:
40  * (QList::size()-products_number) materials (sorted)
41  * (products_number) products.
42  * Comparison (==) of CraftLists is done by materials. */
43 class CraftList final {
44 public:
45  explicit CraftList(int materials_number);
46  ~CraftList();
47 
48  CraftList & operator=(const CraftList &) = delete;
49 
50  void Sort();
51  void LoadItems(const QJsonArray &);
52  int size() const;
53  void clear();
54  int GetMaterialsNumber() const;
55  CraftItem * at(int item_position) const;
56 
57  void operator<<(CraftItem *);
58  bool operator==(const CraftList &) const;
59 
60 private:
61  const int materialsNumber;
62  QList<CraftItem *> items;
63 }; // CraftList
64 
65 class CraftManager final {
66 public:
67  CraftManager();
68  ~CraftManager();
69 
70  bool MiniCraft(CraftItem **) const;
71  bool Craft(CraftList * items, int sub) const;
72 
73 private:
74  CraftManager & operator=(const CraftManager &) = delete;
75  CraftManager(const CraftManager &) = delete;
76  bool CraftSub(CraftList * items, int sub) const;
77 
78  QList<CraftList *> recipesList[LAST_SUB];
79 }; // CraftManager
80 
81 extern const CraftManager * craft_manager;
82 
83 #endif // CRAFTMANAGER_H
CraftItem & operator=(const CraftItem &)=delete
CraftList & operator=(const CraftList &)=delete
bool MiniCraft(CraftItem **) const
const int materialsNumber
Definition: CraftManager.h:61
int GetMaterialsNumber() const
bool CraftSub(CraftList *items, int sub) const
CraftList(int materials_number)
Nothing is made from LAST_SUB.
Definition: header.h:193
void operator<<(CraftItem *)
QList< CraftItem * > items
Definition: CraftManager.h:62
int size() const
const int kind
Definition: CraftManager.h:32
QList< CraftList * > recipesList[LAST_SUB]
Definition: CraftManager.h:78
bool operator<(const CraftItem &item) const
bool operator==(const CraftList &) const
void LoadItems(const QJsonArray &)
const int sub
Definition: CraftManager.h:33
CraftItem * at(int item_position) const
CraftManager & operator=(const CraftManager &)=delete
bool Craft(CraftList *items, int sub) const
const CraftManager * craft_manager
const int num
Definition: CraftManager.h:31
This class represents craft recipe.
Definition: CraftManager.h:43
void Sort()
void clear()