EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Blueprint.cpp
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  Rewrite: Allan
25 */
26 
29 #include "eve-server.h"
30 
31 #include "packets/Manufacturing.h"
33 
34 /*
35  * BlueprintType
36  */
37 BlueprintType::BlueprintType(uint16 _id, const Inv::TypeData& _data, const BlueprintType* _parentBlueprintType,
38  const ItemType& _productType, const EvERam::bpTypeData& _tData)
39 : ItemType(_id, _data),
40  m_parentBlueprintType(_parentBlueprintType),
41  m_productType(_productType)
42 { // asserts for data consistency
43  assert(_tData.productTypeID == m_productType.id());
44  if (m_parentBlueprintType != nullptr)
45  assert(_tData.parentBlueprintTypeID == m_parentBlueprintType->id());
46 
47  m_data = _tData;
48 }
49 
51 {
52  return ItemType::Load<BlueprintType>(typeID);
53 }
54 
55 /*
56  * Blueprint
57  */
58 Blueprint::Blueprint(uint32 _blueprintID, const BlueprintType& _bpType, const ItemData& _data, EvERam::bpData& _bpData)
59 : InventoryItem(_blueprintID, _bpType, _data),
60 m_bpType(_bpType)
61 {
62  // data consistency asserts
63  assert(_bpType.categoryID() == EVEDB::invCategories::Blueprint);
64  m_data = _bpData;
65 }
66 
68  return InventoryItem::Load<Blueprint>(blueprintID);
69 }
70 
72  uint32 blueprintID(Blueprint::CreateItemID(data, bdata));
73  if (blueprintID == 0)
74  return BlueprintRef(nullptr);
75  BlueprintRef bRef = Blueprint::Load(blueprintID);
76  sItemFactory.AddItem(bRef);
77  return bRef;
78 }
79 
81  // make sure it's a blueprint type
82  const BlueprintType* bpType = sItemFactory.GetBlueprintType(data.typeID);
83  if (bpType == nullptr)
84  return 0;
85 
86  // make the blueprintID
87  uint32 blueprintID(InventoryItem::CreateItemID(data));
88  if (blueprintID == 0)
89  return 0;
90 
91  // insert blueprint data into DB
92  if (!FactoryDB::SaveBlueprintData(blueprintID, bdata)) {
93  ItemDB::DeleteItem(blueprintID);
94  return 0;
95  }
96 
97  return blueprintID;
98 }
99 
103 }
104 
105 BlueprintRef Blueprint::SplitBlueprint(int32 qty_to_take, bool notify/*true*/) {
106  // split item
107  BlueprintRef bRef = BlueprintRef::StaticCast(InventoryItem::Split(qty_to_take, notify));
108  if (bRef.get() == nullptr)
109  return BlueprintRef(nullptr);
110 
111  // copy our attributes
112  bRef->SetCopy(m_data.copy);
113  bRef->SetMLevel(m_data.mLevel);
114  bRef->SetPLevel(m_data.pLevel);
115  bRef->SetRuns(m_data.runs);
116  bRef->SaveBlueprint();
117  return bRef;
118 }
119 
120 bool Blueprint::Merge(InventoryItemRef itemRef, uint32 qty, bool notify) {
121  // singleton is checked and error thrown in InventoryItem::Merge()
122  BlueprintRef bpRef = BlueprintRef::StaticCast(itemRef);
123  if (m_data.mLevel != bpRef->mLevel())
124  return false;
125  if (m_data.pLevel != bpRef->pLevel())
126  return false;
127  if (m_data.runs != bpRef->runs())
128  return false;
129  if (!InventoryItem::Merge(itemRef, qty, notify))
130  return false;
131  return true;
132 }
133 
135  _log( MANUF__TRACE, "Saving blueprint %u.", m_itemID );
137 }
138 
140  Rsp_GetBlueprintAttributes rsp;
141  rsp.blueprintID = m_itemID;
142  rsp.copy = m_data.copy;
143  rsp.productivityLevel = m_data.pLevel;
144  rsp.materialLevel = m_data.mLevel;
145  rsp.licensedProductionRunsRemaining = m_data.runs;
146  rsp.wastageFactor = GetME();
147  rsp.productTypeID = m_bpType.productTypeID();
148  rsp.manufacturingTime = m_bpType.productionTime();
149  rsp.maxProductionLimit = m_bpType.maxProductionLimit();
150  rsp.researchMaterialTime = m_bpType.researchMaterialTime();
151  rsp.researchTechTime = m_bpType.researchTechTime();
152  rsp.researchProductivityTime = m_bpType.researchProductivityTime();
153  rsp.researchCopyTime = m_bpType.researchCopyTime();
154  return rsp.Encode();
155 }
156 
158 {
159  float bwf(m_bpType.wasteFactor());
160  if (m_data.mLevel < 0) {
161  bwf /= (-m_data.mLevel);
162  } else if (m_data.mLevel > 0) {
163  bwf /= (1 + m_data.mLevel);
164  }
165  bwf /= 100.0f;
166  return bwf;
167 }
168 
169 /*
170  if activity in (const.activityManufacturing, const.activityDuplicating):
171  if material.requiredTypeID in indexedExtras and indexedExtras[material.requiredTypeID].quantity > 0:
172  extraAmount = indexedExtras[material.requiredTypeID].quantity
173  indexedExtras[material.requiredTypeID].quantity = 0
174  if activity == const.activityManufacturing:
175  blueprintWaste = float(amountRequired) * float(blueprintMaterialMultiplier)
176  characterWaste = float(amountRequired) * float(characterMaterialMultiplier) - float(amountRequired)
177  amountRequired = amountRequired + extraAmount + blueprintWaste
178  amountRequiredByPlayer = int(round(amountRequired + characterWaste))
179  amountRequired = int(round(amountRequired))
180  */
181 /* invention
182  *
183  *
184  * The chance for a successful invention is calculated by this formula:
185  * Invention_Chance = Base_Chance * (1 + (0.01 * Encryption_Skill_Level)) * (1 + ((Datacore_1_Skill_Level + Datacore_2_Skill_Level) * Decryptor_Modifier
186  * where:
187  * Base Chance
188  * Modules and Ammo have a base probability of 40%
189  * Frigates, Destroyers, Freighters and Skiff have a base probability of 30%
190  * Cruisers, Industrials and Mackinaw have a base probability of 25%
191  * Battlecruisers, Battleships and Hulk have a base probability of 20%
192  * In summary, it's not difficult to get a good chance of success for modules, but progressively more difficult for ships as their size increases. This is why investing in some decryptors is a good idea for Tech II ship invention jobs.
193  * (Racial) Encryption Skill Level
194  * 0.01 x Encryption Skill Level (so something between 0.01 and 0.05)
195  * Science Skills (one for each of the required datacores)
196  * 0.02 x Combined Level of Advanced Science Skills (so something between 0.04 and 0.2)
197  * Decryptor (optional)
198  * See table above for probability multiplier
199  *
200  *
201  */
virtual InventoryItemRef Split(int32 qty=0, bool notify=true, bool silent=false)
uint32 researchTechTime() const
Definition: Blueprint.h:54
uint16 productTypeID
Definition: EVE_RAM.h:118
const ItemType & m_productType
Definition: Blueprint.h:108
#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
virtual bool Merge(InventoryItemRef to_merge, int32 qty=0, bool notify=true)
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
uint32 maxProductionLimit() const
Definition: Blueprint.h:56
static BlueprintRef Load(uint32 blueprintID)
Definition: Blueprint.cpp:67
EvERam::bpTypeData m_data
Definition: Blueprint.h:110
uint8 categoryID() const
Definition: ItemType.h:66
signed __int32 int32
Definition: eve-compat.h:49
uint32 researchCopyTime() const
Definition: Blueprint.h:53
static bool DeleteBlueprint(uint32 blueprintID)
Definition: FactoryDB.cpp:94
BlueprintType(uint16 _id, const Inv::TypeData &_data, const BlueprintType *_parentBlueprintType, const ItemType &_productType, const EvERam::bpTypeData &_tData)
Definition: Blueprint.cpp:37
uint32 productionTime() const
Definition: Blueprint.h:52
const BlueprintType & m_bpType
Definition: Blueprint.h:194
uint16 wasteFactor() const
Definition: Blueprint.h:50
float GetME()
Definition: Blueprint.cpp:157
static bool SaveBlueprintData(uint32 blueprintID, EvERam::bpData &data)
Definition: FactoryDB.cpp:120
EvERam::bpData m_data
Definition: Blueprint.h:195
uint16 parentBlueprintTypeID
Definition: EVE_RAM.h:119
const BlueprintType * m_parentBlueprintType
Definition: Blueprint.h:107
X * get() const
Definition: RefPtr.h:213
RefPtr< Blueprint > BlueprintRef
Definition: ItemRef.h:53
static RefPtr StaticCast(const RefPtr< Y > &oth)
Acts as static_cast from one RefPtr to another.
Definition: RefPtr.h:238
unsigned __int32 uint32
Definition: eve-compat.h:50
uint16 typeID
Definition: ItemType.h:188
virtual bool Merge(InventoryItemRef to_merge, uint32 qty=0, bool notify=true)
Definition: Blueprint.cpp:120
static BlueprintRef Spawn(ItemData &data, EvERam::bpData &bdata)
Definition: Blueprint.cpp:71
uint32 researchMaterialTime() const
Definition: Blueprint.h:57
static uint32 CreateItemID(ItemData &data)
static bool DeleteItem(uint32 itemID)
Definition: ItemDB.cpp:348
virtual void Delete()
#define sItemFactory
Definition: ItemFactory.h:165
int16 runs
Definition: EVE_RAM.h:110
unsigned __int16 uint16
Definition: eve-compat.h:48
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
Reference-counting-based smart pointer.
Definition: RefPtr.h:133