Merge branch '164-crash-on-patching-and-possibly-right-after-login' into main/gingo...
[ryzomcore.git] / ryzom / client / src / item_cl.cpp
blob3dcc59a5023cf2819a0b11b7fc050f5af17fab02
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /////////////
21 // INCLUDE //
22 /////////////
23 #include "stdpch.h"
24 // Misc.
25 #include "nel/misc/path.h"
26 // Interface 3D
27 #include "nel/3d/u_scene.h"
28 // Client Sheets
29 #include "client_sheets/item_sheet.h"
30 // Client
31 #include "item_cl.h"
32 #include "ingame_database_manager.h"
33 #include "pacs_client.h"
34 #include "misc.h"
35 #include "debug_client.h"
38 ////////////
39 // USING //
40 ////////////
41 using namespace NL3D;
42 using namespace NLMISC;
45 ////////////
46 // EXTERN //
47 ////////////
48 extern UScene * Scene;
51 //-----------------------------------------------
52 // CItemCL :
54 //-----------------------------------------------
55 CItemCL::CItemCL() : CEntityCL()
57 }// CItemCL //
59 //-----------------------------------------------
60 // CItemCL :
62 //-----------------------------------------------
63 CItemCL::CItemCL(const std::string &fileName) : CEntityCL()
65 initShape( fileName );
66 }// CItemCL //
68 //-----------------------------------------------
69 // CItemCL :
71 //-----------------------------------------------
72 CItemCL::~CItemCL()
74 }// CItemCL //
76 //-----------------------------------------------
77 // build :
78 // Build the entity from a sheet.
79 //-----------------------------------------------
80 bool CItemCL::build(const CEntitySheet *sheet ) // virtual
82 // Cast the sheet in the right type.
83 const CItemSheet *sh = dynamic_cast<const CItemSheet *>(sheet);
84 if(sh==0)
86 nlwarning("Item:build: the sheet is not an item sheet -> entity not initialized.");
87 return false;
89 // Get the DB Entry
90 if(IngameDbMngr.getNodePtr())
92 CCDBNodeBranch *nodeRoot = dynamic_cast<CCDBNodeBranch *>(IngameDbMngr.getNodePtr()->getNode(0));
93 if(nodeRoot)
95 _DBEntry = dynamic_cast<CCDBNodeBranch *>(nodeRoot->getNode(_Slot));
96 if(_DBEntry == 0)
97 pushDebugStr("Cannot get a pointer on the DB entry.");
101 initialize();
103 initShape( sh->getShape() );
104 // Entity Created.
105 return true;
106 }// build //
108 //-----------------------------------------------
109 // initProperties :
110 // Initialize properties for an item.
111 //-----------------------------------------------
112 void CItemCL::initProperties()
114 properties().liftable(true);
115 }// initProperties //
117 //-----------------------------------------------
118 // initShape :
120 //-----------------------------------------------
121 void CItemCL::initShape( const string &fileName )
123 string filePath = CPath::lookup(fileName, false, false);
124 if(!filePath.empty())
125 _Instance = Scene->createInstance( filePath );
126 else
127 nlwarning("Item:initShape:%d: file '%s' not found.", _Slot, fileName.c_str());
128 }// initShape //
130 //-----------------------------------------------
131 // updateVisualProperty0 :
132 /// Update the item position.
133 //-----------------------------------------------
134 void CItemCL::updateVisualPropertyPos(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop, const NLMISC::TGameCycle &/* pI */)
136 // Check the DB entry (the warning is already done in the build method).
137 if(_DBEntry == 0)
138 return;
139 // Get The property 'Y'.
140 CCDBNodeLeaf *nodeY = dynamic_cast<CCDBNodeLeaf *>(_DBEntry->getNode(CLFECOMMON::PROPERTY_POSY));
141 if(nodeY == 0)
143 nlwarning("ITM:updtVPPos:%d: Cannot find the property 'PROPERTY_POSY(%d)'.", _Slot, CLFECOMMON::PROPERTY_POSY);
144 return;
146 // Get The property 'Z'.
147 CCDBNodeLeaf *nodeZ = dynamic_cast<CCDBNodeLeaf *>(_DBEntry->getNode(CLFECOMMON::PROPERTY_POSZ));
148 if(nodeZ == 0)
150 nlwarning("ITM:updtVPPos:%d: Cannot find the property 'PROPERTY_POSZ(%d)'.", _Slot, CLFECOMMON::PROPERTY_POSZ);
151 return;
153 // Insert the primitive into the world.
154 if(_Primitive)
155 _Primitive->insertInWorldImage(dynamicWI);
156 float x = (float)(prop)/1000.0f;
157 float y = (float)(nodeY->getValue64())/1000.0f;
158 float z = (float)(nodeZ->getValue64())/1000.0f;
159 // Set the primitive position.
160 pacsPos(CVectorD(x, y, z));
161 // Snap the entity to the ground.
162 snapToGround();
163 // Change the instance position.
164 if(!_Instance.empty())
166 _Instance.setPos(pos());
167 _Instance.getShapeAABBox(_SelectBox);
168 _SelectBox.setCenter(pos() + _SelectBox.getCenter());
169 // Adjust the collision.
170 if(_Primitive)
172 _Primitive->setRadius(std::min(std::max((_SelectBox.getHalfSize()).x, (_SelectBox.getHalfSize()).y), (float)(RYZOM_ENTITY_SIZE_MAX/2)));
173 _Primitive->setHeight((_SelectBox.getHalfSize()).z);
176 }// updateVisualProperty0 //
179 //---------------------------------------------------
180 // drawBox :
181 // Draw the selection Box.
182 //---------------------------------------------------
183 void CItemCL::drawBox() // virtual
185 ::drawBox(selectBox().getMin(), selectBox().getMax(), CRGBA(250,250,0));
186 }// drawBox //