EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Station.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 
27 #include "eve-server.h"
28 
29 #include "Client.h"
30 #include "EntityList.h"
31 #include "packets/CorporationPkts.h"
32 #include "station/Station.h"
33 #include "station/StationOffice.h"
34 #include "station/StationDataMgr.h"
35 #include "system/Container.h"
36 #include "system/DestinyManager.h"
37 #include "system/SystemEntity.h"
38 #include "system/SystemManager.h"
39 
40 /*
41  * StationType
42  */
44 : ItemType(_id, _data)
45 {
46  // consistency check
47  assert(_data.id == _id);
48  assert(_data.groupID == EVEDB::invGroups::Station);
49 }
50 
52 {
53  return ItemType::Load<StationType>(stationTypeID);
54 }
55 
56 /*
57  * Station Item
58  */
59 StationItem::StationItem(uint32 stationID, const StationType& type, const ItemData& data, const CelestialObjectData& cData)
60 : CelestialObject(stationID, type, data, cData),
61 m_officePyData(nullptr),
62 m_stationType(type),
63 m_stationID(stationID),
64 m_loaded(false)
65 {
67 
68  _log(ITEM__TRACE, "Created Station for item %s (%u).", name(), itemID());
69 }
70 
72 {
73  if (pInventory != nullptr)
74  pInventory->Unload();
76 
77  m_officeMap.clear();
78  m_guestList.clear();
80 }
81 
83 {
84  return InventoryItem::Load<StationItem>(stationID);
85 }
86 
88  if (!pInventory->LoadContents())
89  return false;
90 
91  m_officeMap.clear();
92  m_guestList.clear();
93 
94  stDataMgr.GetStationData(m_stationID, m_data);
95  stDataMgr.LoadOffices(m_stationID, m_officeMap);
97 
98  if (m_data.officeRentalFee < 10000)
99  m_data.officeRentalFee = 10000;
100 
102 
103  return m_loaded;
104 }
105 
107  return InventoryItem::CreateItemID(data);
108 }
109 
111 {
112  if (!IsPlayerCorp(corpID))
113  return 0;
114  for (auto cur : m_officeMap)
115  if (cur.second.corporationID = corpID)
116  return cur.first;
117  return 0;
118 }
119 
121 {
122  if (!IsOfficeID(officeID))
123  return;
124  m_officeLoaded.emplace(officeID, true);
125 }
126 
128 {
129  if (!IsOfficeID(officeID))
130  return false;
131  std::map<uint32, bool>::const_iterator itr = m_officeLoaded.find(officeID);
132  if (itr != m_officeLoaded.end())
133  return itr->second;
134  return false;
135 }
136 
138 {
139  if (!IsOfficeID(officeID))
140  return;
141  m_officeLoaded.erase(officeID);
142 }
143 
145 {
146  if (!IsPlayerCorp(corpID))
147  return;
148  uint32 officeID = GetOfficeID(corpID);
149  if (officeID == 0)
150  return;
151  if (IsOfficeLoaded(officeID))
152  return;
153  _log(CORP__TRACE, "StationItem::LoadStationOffice() is loading corp office %u in stationID %u", officeID, m_stationID);
154  StationOfficeRef oRef = sItemFactory.GetOffice(officeID);
155  if (oRef->GetMyInventory() == nullptr) { // not sure why this would be null, but i *may* have seen errors from it
156  _log(ITEM__ERROR, "StationItem::LoadStationOffice() - GetMyInventory() for corp office %u in stationID %u is NULL.", officeID, m_stationID);
157  return;
158  }
159  oRef->SetLoaded(oRef->GetMyInventory()->LoadContents());
160  m_officeLoaded.emplace(officeID, true);
161 }
162 
164 {
165  std::map<uint32, OfficeData>::iterator itr = m_officeMap.find(officeID);
166  if (itr != m_officeMap.end())
167  itr->second.lockDown = true;
168 }
169 
171 {
172  std::map<uint32, OfficeData>::iterator itr = m_officeMap.find(officeID);
173  if (itr != m_officeMap.end())
174  itr->second.lockDown = false;
175 }
176 
177 
179 {
180  odata.typeID = typeID(); // change from officeTypeID to stationTypeID
182  odata.stationID = m_stationID;
183 
184  // create new office item
185  std::string name = odata.ticker;
186  name += "'s Office";
187  ItemData idata(27, m_data.corporationID, m_stationID, flagOffice, name.c_str());
188  StationOfficeRef oRef = sItemFactory.SpawnOffice(idata, odata);
189  if (oRef.get() == nullptr)
190  return; // make error here?
191 
192  // make and send notifications
193  OnOfficeRentalChanged oorc;
194  oorc.ownerID = odata.corporationID;
195  oorc.officeID = odata.officeID;
196  oorc.officeFolderID = odata.folderID;
197  PyTuple* payload = oorc.Encode();
198  for (auto cur : m_guestList) {
199  PyIncRef(payload);
200  cur.second->SendNotification("OnOfficeRentalChanged", "stationid", &payload, false);
201  }
202  PyDecRef( payload );
203 
204  oRef->ChangeOwner(odata.corporationID, true);
205 
206  // update data
207  stDataMgr.AddOffice(m_stationID, odata);
208  m_officeMap.emplace(odata.officeID, odata);
209  m_officeLoaded.emplace(odata.officeID, true);
212 }
213 
215 {
216  // do we need this here?
217 }
218 
220 {
221  m_guestList.emplace(pClient->GetCharacterID(), pClient);
222 }
223 
224 void StationItem::GetGuestList(std::vector< Client* >& cVec)
225 {
226  for (auto cur : m_guestList)
227  cVec.push_back(cur.second);
228 }
229 
231 {
232  m_guestList.erase(pClient->GetCharacterID());
233 }
234 
235 void StationItem::GetRefineData(uint32& stationCorpID, float& staEfficiency, float& tax)
236 {
237  stationCorpID = m_data.corporationID;
238  staEfficiency = m_data.reprocessingEfficiency;
240 }
241 
243 {
244  std::vector< InventoryItemRef > items;
246 
247  for (auto cur : items)
248  if (cur->categoryID() == EVEDB::invCategories::Ship)
249  if (cur->typeID() != EVEDB::invTypes::Capsule)
250  return true;
251  return false;
252 }
253 
255 {
256  return ShipItemRef::StaticCast(pInventory->GetByID(shipID));
257 }
258 
260 {
262 }
263 
264 
265 /*
266  * Station Entity
267  */
269 : StaticSystemEntity(station, services, system)
270 {
271  // Create default dynamic attributes in the AttributeMap:
272  station->SetAttribute(AttrOnline, EvilOne, false);
274  station->SetAttribute(AttrInertia, EvilOne, false);
275  station->SetAttribute(AttrDamage, EvilZero, false);
276  station->SetAttribute(AttrShieldCapacity, 20000000.0, false);
277  station->SetAttribute(AttrShieldCharge, station->GetAttribute(AttrShieldCapacity), false);
278  station->SetAttribute(AttrArmorHP, station->GetAttribute(AttrArmorHP), false);
280  station->SetAttribute(AttrArmorDamage, EvilZero, false);
281  station->SetAttribute(AttrMass, station->type().mass(), false);
282  station->SetAttribute(AttrRadius, station->type().radius(), false);
283  station->SetAttribute(AttrVolume, station->type().volume(), false);
284 }
285 
287 {
288  using namespace Destiny;
289 
290  BallHeader head = BallHeader();
291  head.entityID = m_self->itemID();
292  head.mode = Ball::Mode::RIGID;
293  head.radius = GetRadius();
294  head.posX = x();
295  head.posY = y();
296  head.posZ = z();
297  head.flags = /*Ball::Flag::HasMiniBalls |*/ Ball::Flag::IsGlobal | Ball::Flag::IsMassive;
298  into.Append( head );
300  main.formationID = 0xFF;
301  into.Append( main );
302 
313  _log(SE__DESTINY, "StationSE::EncodeDestiny(): %s - id:%li, mode:%u, flags:0x%X", GetName(), head.entityID, head.mode, head.flags);
314 }
315 
317  _log(SE__SLIMITEM, "MakeSlimItem for StationSE %s(%u)", m_self->name(), m_self->itemID());
318  PyDict *slim = new PyDict();
319  slim->SetItemString("groupID", new PyInt(m_self->groupID()));
320  slim->SetItemString("name", new PyString(m_self->itemName()));
321  slim->SetItemString("corpID", IsCorp(m_corpID) ? new PyInt(m_corpID) : PyStatic.NewNone());
322  slim->SetItemString("allianceID", IsAlliance(m_allyID) ? new PyInt(m_allyID) : PyStatic.NewNone());
323  slim->SetItemString("warFactionID", IsFaction(m_warID) ? new PyInt(m_warID) : PyStatic.NewNone());
324  slim->SetItemString("typeID", new PyInt(m_self->typeID()));
325  slim->SetItemString("ownerID", new PyInt(m_ownerID));
326  slim->SetItemString("categoryID", new PyInt(m_self->categoryID()));
327  slim->SetItemString("itemID", new PyLong(m_self->itemID()));
328  slim->SetItemString("incapacitated", new PyInt(0));
329  slim->SetItemString("online", PyStatic.NewOne());
330  return slim;
331 }
332 
334 {
336 }
337 
338 /*
339 static const int num_hack_sentry_locs = 8;
340 GPoint hack_sentry_locs[num_hack_sentry_locs] = {
341  GPoint(35000.0f, 35000.0f, 35000.0f),
342  GPoint(35000.0f, 35000.0f, -35000.0f),
343  GPoint(35000.0f, -35000.0f, 35000.0f),
344  GPoint(35000.0f, -35000.0f, -35000.0f),
345  GPoint(-35000.0f, 35000.0f, 35000.0f),
346  GPoint(-35000.0f, 35000.0f, -35000.0f),
347  GPoint(-35000.0f, -35000.0f, 35000.0f),
348  GPoint(-35000.0f, -35000.0f, -35000.0f)
349 };
350 */
void GetInvForOwner(uint32 ownerID, std::vector< InventoryItemRef > &items)
Definition: Inventory.cpp:425
void Append(const T &value)
Appends a single value to buffer.
Definition: Buffer.h:437
CargoContainerRef GetContainerFromInventory(uint32 contID)
Definition: Station.cpp:259
bool IsOfficeLoaded(uint32 officeID)
Definition: Station.cpp:127
virtual bool _Load()
Definition: Station.cpp:87
int32 officeRentalFee
void AddGuest(Client *pClient)
Definition: Station.cpp:219
uint32 corporationID
#define _log(type, fmt,...)
Definition: logsys.h:124
#define stDataMgr
std::map< uint32, bool > m_officeLoaded
Definition: Station.h:165
void LoadStationOffice(uint32 corpID)
Definition: Station.cpp:144
Python string.
Definition: PyRep.h:430
double GetRadius()
Definition: SystemEntity.h:208
uint32 folderID
Python's dictionary.
Definition: PyRep.h:719
uint32 m_ownerID
Definition: SystemEntity.h:283
uint32 stationID
static StationItemRef Load(uint32 stationID)
Definition: Station.cpp:82
StationSE(StationItemRef station, PyServiceMgr &services, SystemManager *system)
Definition: Station.cpp:268
void GetRefineData(uint32 &stationCorpID, float &staEfficiency, float &tax)
Definition: Station.cpp:235
double y()
Definition: SystemEntity.h:214
int32 GetCharacterID() const
Definition: Client.h:113
std::map< uint32, OfficeData > m_officeMap
Definition: Station.h:164
static const int64 STATION_HANGAR_MAX_CAPACITY
Definition: EVE_Consts.h:41
virtual bool _Load()
const char * name()
Python tuple.
Definition: PyRep.h:567
void GetGuestList(std::vector< Client * > &cVec)
Definition: Station.cpp:224
EvilNumber EvilZero
Definition: EvilNumber.cpp:32
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
uint16 groupID() const
const ItemType & type() const
void Unload()
Definition: Inventory.cpp:62
bool HasShip(Client *pClient)
Definition: Station.cpp:242
PyRep * m_officePyData
Definition: Station.h:155
static StationType * Load(uint16 stationTypeID)
Definition: Station.cpp:51
InventoryItemRef m_self
Definition: SystemEntity.h:269
void RemoveLoadedOffice(uint32 officeID)
Definition: Station.cpp:137
Generic class for buffers.
Definition: Buffer.h:40
void ImpoundOffice(uint32 officeID)
Definition: Station.cpp:163
uint32 m_corpID
Definition: SystemEntity.h:281
Inventory * pInventory
float reprocessingStationsTake
float mass() const
Definition: ItemType.h:69
std::map< uint32, Client * > m_guestList
Definition: Station.h:162
virtual PyDict * MakeSlimItem()
Definition: Station.cpp:316
uint32 officeID
Python integer.
Definition: PyRep.h:231
void UnloadStation()
Definition: Station.cpp:333
double z()
Definition: SystemEntity.h:215
void SetAttribute(uint16 attrID, int num, bool notify=true)
std::string ticker
#define PyStatic
Definition: PyRep.h:1209
#define IsPlayerCorp(itemID)
Definition: EVE_Defines.h:241
const char * GetName() const
Definition: SystemEntity.h:210
#define PyDecRef(op)
Definition: PyRep.h:57
uint32 corporationID
double x()
Definition: SystemEntity.h:213
Definition: Client.h:66
ShipItemRef GetShipFromInventory(uint32 shipID)
Definition: Station.cpp:254
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
#define PyIncRef(op)
Definition: PyRep.h:56
void RemoveGuest(Client *pClient)
Definition: Station.cpp:230
static PyRep * GetOffices(uint32 stationID)
Definition: StationDB.cpp:54
bool m_loaded
Definition: Station.h:159
#define IsCorp(itemID)
Definition: EVE_Defines.h:234
RefPtr< InventoryItem > InventoryItemRef
Definition: ItemRef.h:52
static uint32 CreateItemID(ItemData &data)
Definition: Station.cpp:106
#define IsOfficeID(itemID)
Definition: EVE_Defines.h:253
virtual void EncodeDestiny(Buffer &into)
Definition: Station.cpp:286
const std::string & itemName() const
int main(int argc, char *argv[])
#define STATION_OFFICE_OFFSET
Definition: EVE_Defines.h:177
static uint32 CreateItemID(ItemData &data)
EvilNumber GetAttribute(const uint16 attrID) const
bool LoadContents()
Definition: Inventory.cpp:113
#define IsFaction(itemID)
Definition: EVE_Defines.h:250
void AddLoadedOffice(uint32 officeID)
Definition: Station.cpp:120
float radius() const
Definition: ItemType.h:68
StationType(uint16 _id, const Inv::TypeData &_data)
Definition: Station.cpp:43
float volume() const
Definition: ItemType.h:70
#define PySafeDecRef(op)
Definition: PyRep.h:61
#define sItemFactory
Definition: ItemFactory.h:165
virtual ~StationItem()
Definition: Station.cpp:71
EvilNumber EvilOne
Definition: EvilNumber.cpp:34
#define IsAlliance(itemID)
Definition: EVE_Defines.h:244
void RentOffice(OfficeData &odata)
Definition: Station.cpp:178
void SendBill()
Definition: Station.cpp:214
Inventory * GetMyInventory()
Definition: InventoryItem.h:91
StationData m_data
Definition: Station.h:157
unsigned __int16 uint16
Definition: eve-compat.h:48
entityID heal the character with the entityID note giving you detailed ship status information gives a list of all dynamic entities and players and their destinyState in this bubble shows some current destiny variables save all items
float reprocessingEfficiency
uint16 typeID() const
InventoryItemRef GetByID(uint32 id) const
Definition: Inventory.cpp:415
uint8 categoryID() const
uint32 itemID() const
Definition: InventoryItem.h:98
void RecoverOffice(uint32 officeID)
Definition: Station.cpp:170
uint32 m_stationID
Definition: Station.h:160
Python long integer.
Definition: PyRep.h:261
uint32 GetOfficeID(uint32 corpID)
Definition: Station.cpp:110
StationItem(uint32 stationID, const StationType &type, const ItemData &data, const CelestialObjectData &cData)
Definition: Station.cpp:59