1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
25 #include "nel/misc/path.h"
27 #include "nel/3d/u_scene.h"
29 #include "client_sheets/item_sheet.h"
32 #include "ingame_database_manager.h"
33 #include "pacs_client.h"
35 #include "debug_client.h"
42 using namespace NLMISC
;
48 extern UScene
* Scene
;
51 //-----------------------------------------------
54 //-----------------------------------------------
55 CItemCL::CItemCL() : CEntityCL()
59 //-----------------------------------------------
62 //-----------------------------------------------
63 CItemCL::CItemCL(const std::string
&fileName
) : CEntityCL()
65 initShape( fileName
);
68 //-----------------------------------------------
71 //-----------------------------------------------
76 //-----------------------------------------------
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
);
86 nlwarning("Item:build: the sheet is not an item sheet -> entity not initialized.");
90 if(IngameDbMngr
.getNodePtr())
92 CCDBNodeBranch
*nodeRoot
= dynamic_cast<CCDBNodeBranch
*>(IngameDbMngr
.getNodePtr()->getNode(0));
95 _DBEntry
= dynamic_cast<CCDBNodeBranch
*>(nodeRoot
->getNode(_Slot
));
97 pushDebugStr("Cannot get a pointer on the DB entry.");
103 initShape( sh
->getShape() );
108 //-----------------------------------------------
110 // Initialize properties for an item.
111 //-----------------------------------------------
112 void CItemCL::initProperties()
114 properties().liftable(true);
115 }// initProperties //
117 //-----------------------------------------------
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
);
127 nlwarning("Item:initShape:%d: file '%s' not found.", _Slot
, fileName
.c_str());
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).
139 // Get The property 'Y'.
140 CCDBNodeLeaf
*nodeY
= dynamic_cast<CCDBNodeLeaf
*>(_DBEntry
->getNode(CLFECOMMON::PROPERTY_POSY
));
143 nlwarning("ITM:updtVPPos:%d: Cannot find the property 'PROPERTY_POSY(%d)'.", _Slot
, CLFECOMMON::PROPERTY_POSY
);
146 // Get The property 'Z'.
147 CCDBNodeLeaf
*nodeZ
= dynamic_cast<CCDBNodeLeaf
*>(_DBEntry
->getNode(CLFECOMMON::PROPERTY_POSZ
));
150 nlwarning("ITM:updtVPPos:%d: Cannot find the property 'PROPERTY_POSZ(%d)'.", _Slot
, CLFECOMMON::PROPERTY_POSZ
);
153 // Insert the primitive into the world.
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.
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.
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 //---------------------------------------------------
181 // Draw the selection Box.
182 //---------------------------------------------------
183 void CItemCL::drawBox() // virtual
185 ::drawBox(selectBox().getMin(), selectBox().getMax(), CRGBA(250,250,0));