EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Blueprint.h
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Bloody.Rabbit
24  Updates: Allan
25 */
26 
27 #ifndef __BLUEPRINT_ITEM__H__INCL__
28 #define __BLUEPRINT_ITEM__H__INCL__
29 
30 #include "EVEServerConfig.h"
31 #include "StaticDataMgr.h"
32 #include "inventory/ItemType.h"
35 
36 /*
37  * Class which contains blueprint type data.
38  */
40 : public ItemType
41 {
42  friend class ItemType; // To let our parent redirect construction to our _Load().
43 public:
44  static BlueprintType* Load(uint16 typeID);
45 
46  /* Access functions */
48  const ItemType& productType() const { return m_productType; }
49  uint8 techLevel() const { return m_data.techLevel; }
50  uint16 wasteFactor() const { return m_data.wasteFactor; }
51  uint16 productTypeID() const { return productType().id(); }
60  uint16 parentBlueprintTypeID() const { return (m_parentBlueprintType == nullptr ? 0 : parentBlueprintType()->id()); }
61  float chanceOfRE() const { return m_data.chanceOfRE; }
62 
63 protected:
64  BlueprintType(uint16 _id, const Inv::TypeData& _data,
65  const BlueprintType *_parentBlueprintType, const ItemType& _productType,
66  const EvERam::bpTypeData& _tData);
67 
68  /*
69  * Member functions
70  */
71  using ItemType::_Load;
72 
73  // Template loader:
74  template<class _Ty>
75  static _Ty *_LoadType(uint16 typeID, const Inv::TypeData& data) {
76  // check if we are really loading a blueprint
77  Inv::GrpData gdata = Inv::GrpData();
78  sDataMgr.GetGroup(data.groupID, gdata);
79  if (gdata.catID != EVEDB::invCategories::Blueprint ) {
80  _log( ITEM__ERROR, "Trying to load %s as BlueprintType.", sDataMgr.GetCategoryName(gdata.catID));
81  return nullptr;
82  }
83 
84  // get blueprint type data
86  sDataMgr.GetBpTypeData(typeID, tData);
87 
88  // obtain parent blueprint type (might be NULL)
89  const BlueprintType* parentBlueprintType(nullptr);
90  if (tData.parentBlueprintTypeID) {
91  parentBlueprintType = sItemFactory.GetBlueprintType( tData.parentBlueprintTypeID );
92  if (parentBlueprintType == nullptr)
93  return nullptr;
94  }
95 
96  // obtain product type
97  const ItemType* productType = sItemFactory.GetType( tData.productTypeID );
98  if (productType == nullptr)
99  return nullptr;
100 
101  return new BlueprintType(typeID, data, parentBlueprintType, *productType, tData);
102  }
103 
104  /*
105  * Data members
106  */
109 
111 };
112 
113 
115 : public InventoryItem
116 {
117  friend class InventoryItem; // to let it construct us
118 public:
119  /* virtual functions default to base class and overridden as needed */
120  virtual void Delete(); //remove the item from the DB.
121  // overload to merge the blueprints properly
122  virtual bool Merge(InventoryItemRef to_merge, uint32 qty=0, bool notify=true);
123  // overload to split the blueprints properly
124  virtual InventoryItemRef Split(int32 qty_to_take, bool notify=true)
125  { return SplitBlueprint( qty_to_take, notify ); }
126 
127  BlueprintRef SplitBlueprint(int32 qty_to_take, bool notify=true);
128 
129  static BlueprintRef Load( uint32 blueprintID);
130  static BlueprintRef Spawn( ItemData& data, EvERam::bpData& bdata);
131 
132  // query methods
133  const BlueprintType& type() const { return m_bpType; }
134  const ItemType& productType() const { return m_bpType.productType(); }
136  bool copy() { return m_data.copy; }
137  int8 mLevel() { return m_data.mLevel; }
138  int8 pLevel() { return m_data.pLevel; }
139  int16 runs() { return m_data.runs; }
140  float GetPE() { return m_data.pLevel / (1 + m_data.pLevel); }
141  float GetME();
142 
143  // set methods
144  void SetMLevel(int8 me) { m_data.mLevel = me; SaveBlueprint(); }
145  void SetPLevel(int8 pe) { m_data.pLevel = pe; SaveBlueprint(); }
146  void SetCopy(bool copy) { m_data.copy = copy; SaveBlueprint(); }
148 
149  // update methods
150  void UpdateMLevel(int8 me) { m_data.mLevel += me; SaveBlueprint(); }
151  void UpdatePLevel(int8 pe) { m_data.pLevel += pe; SaveBlueprint(); }
153 
154  // is this used? should it be?
155  bool infinite() { return (m_data.runs < 0); }
156 
157  /*
158  * Primary public packet builders:
159  */
161 
162 
163 protected:
164  Blueprint( uint32 _blueprintID, const BlueprintType& _bpType, const ItemData& _data, EvERam::bpData& _bpData);
165 
166  /*
167  * Member functions
168  */
169  using InventoryItem::_Load;
170 
171  // Template loader:
172  template<class _Ty>
173  static RefPtr<_Ty> _LoadItem( uint32 blueprintID, const ItemType& type, const ItemData& data)
174  {
176  _log(ITEM__ERROR, "Trying to load %s as Blueprint.", sDataMgr.GetCategoryName(type.categoryID()));
177  if (sConfig.debug.StackTrace)
178  EvE::traceStack();
179  return RefPtr<_Ty>();
180  }
181  const BlueprintType& bpType = static_cast<const BlueprintType& >( type );
182 
183  EvERam::bpData bdata = EvERam::bpData();
184  if (!FactoryDB::GetBlueprint( blueprintID, bdata ) )
185  return RefPtr<_Ty>();
186 
187  return BlueprintRef( new Blueprint( blueprintID, bpType, data, bdata ) );
188  }
189 
190  void SaveBlueprint();
191  static uint32 CreateItemID( ItemData& data, EvERam::bpData& bdata);
192 
193 private:
196 
197 };
198 
199 #endif /* !__BLUEPRINT_ITEM__H__INCL__ */
200 
#define sConfig
A macro for easier access to the singleton.
unsigned __int8 uint8
Definition: eve-compat.h:46
void UpdatePLevel(int8 pe)
Definition: Blueprint.h:151
void SetCopy(bool copy)
Definition: Blueprint.h:146
uint32 researchTechTime() const
Definition: Blueprint.h:54
uint16 productTypeID
Definition: EVE_RAM.h:118
int16 runs()
Definition: Blueprint.h:139
uint16 parentBlueprintTypeID() const
Definition: Blueprint.h:60
bool copy()
Definition: Blueprint.h:136
const ItemType & m_productType
Definition: Blueprint.h:108
const BlueprintType & type() const
Definition: Blueprint.h:133
#define _log(type, fmt,...)
Definition: logsys.h:124
uint16 id() const
Definition: ItemType.h:63
static uint32 CreateItemID(ItemData &data, EvERam::bpData &bdata)
Definition: Blueprint.cpp:80
PyDict * GetBlueprintAttributes()
Definition: Blueprint.cpp:139
Blueprint(uint32 _blueprintID, const BlueprintType &_bpType, const ItemData &_data, EvERam::bpData &_bpData)
Definition: Blueprint.cpp:58
void SaveBlueprint()
Definition: Blueprint.cpp:134
Python's dictionary.
Definition: PyRep.h:719
BlueprintRef SplitBlueprint(int32 qty_to_take, bool notify=true)
Definition: Blueprint.cpp:105
const BlueprintType * parentBlueprintType() const
Definition: Blueprint.h:47
uint16 wasteFactor
Definition: EVE_RAM.h:117
static RefPtr< _Ty > _LoadItem(uint32 blueprintID, const ItemType &type, const ItemData &data)
Definition: Blueprint.h:173
uint32 materialModifier
Definition: EVE_RAM.h:126
uint32 researchCopyTime
Definition: EVE_RAM.h:123
uint32 researchTechTime
Definition: EVE_RAM.h:124
float GetPE()
Definition: Blueprint.h:140
uint32 maxProductionLimit() const
Definition: Blueprint.h:56
static BlueprintRef Load(uint32 blueprintID)
Definition: Blueprint.cpp:67
void SetPLevel(int8 pe)
Definition: Blueprint.h:145
virtual bool _Load()
virtual InventoryItemRef Split(int32 qty_to_take, bool notify=true)
Definition: Blueprint.h:124
static bool GetBlueprint(uint32 blueprintID, EvERam::bpData &into)
Definition: FactoryDB.cpp:140
signed __int8 int8
Definition: eve-compat.h:45
EvERam::bpTypeData m_data
Definition: Blueprint.h:110
uint32 productivityModifier() const
Definition: Blueprint.h:58
uint8 categoryID() const
Definition: ItemType.h:66
signed __int32 int32
Definition: eve-compat.h:49
uint32 researchCopyTime() const
Definition: Blueprint.h:53
uint32 productTypeID() const
Definition: Blueprint.h:135
virtual bool _Load()
Definition: ItemType.cpp:114
BlueprintType(uint16 _id, const Inv::TypeData &_data, const BlueprintType *_parentBlueprintType, const ItemType &_productType, const EvERam::bpTypeData &_tData)
Definition: Blueprint.cpp:37
void UpdateMLevel(int8 me)
Definition: Blueprint.h:150
float chanceOfRE() const
Definition: Blueprint.h:61
uint32 productionTime() const
Definition: Blueprint.h:52
const BlueprintType & m_bpType
Definition: Blueprint.h:194
uint32 maxProductionLimit
Definition: EVE_RAM.h:127
void SetMLevel(int8 me)
Definition: Blueprint.h:144
uint16 wasteFactor() const
Definition: Blueprint.h:50
uint32 productivityModifier
Definition: EVE_RAM.h:125
float GetME()
Definition: Blueprint.cpp:157
EvERam::bpData m_data
Definition: Blueprint.h:195
uint16 parentBlueprintTypeID
Definition: EVE_RAM.h:119
const BlueprintType * m_parentBlueprintType
Definition: Blueprint.h:107
uint32 productionTime
Definition: EVE_RAM.h:120
uint8 techLevel() const
Definition: Blueprint.h:49
RefPtr< Blueprint > BlueprintRef
Definition: ItemRef.h:53
bool infinite()
Definition: Blueprint.h:155
static _Ty * _LoadType(uint16 typeID, const Inv::TypeData &data)
Definition: Blueprint.h:75
unsigned __int32 uint32
Definition: eve-compat.h:50
void UpdateRuns(int16 runs)
Definition: Blueprint.h:152
uint32 researchProductivityTime
Definition: EVE_RAM.h:121
const ItemType & productType() const
Definition: Blueprint.h:48
virtual bool Merge(InventoryItemRef to_merge, uint32 qty=0, bool notify=true)
Definition: Blueprint.cpp:120
void SetRuns(int16 runs)
Definition: Blueprint.h:147
static BlueprintRef Spawn(ItemData &data, EvERam::bpData &bdata)
Definition: Blueprint.cpp:71
uint32 researchMaterialTime() const
Definition: Blueprint.h:57
int8 mLevel()
Definition: Blueprint.h:137
signed __int16 int16
Definition: eve-compat.h:47
uint32 materialModifier() const
Definition: Blueprint.h:55
void traceStack(void)
Definition: misc.cpp:169
int8 pLevel()
Definition: Blueprint.h:138
#define sItemFactory
Definition: ItemFactory.h:165
int16 runs
Definition: EVE_RAM.h:110
unsigned __int16 uint16
Definition: eve-compat.h:48
const ItemType & productType() const
Definition: Blueprint.h:134
static BlueprintType * Load(uint16 typeID)
Definition: Blueprint.cpp:50
virtual void Delete()
Definition: Blueprint.cpp:100
uint32 researchProductivityTime() const
Definition: Blueprint.h:59
uint16 productTypeID() const
Definition: Blueprint.h:51
uint32 researchMaterialTime
Definition: EVE_RAM.h:122
#define sDataMgr