Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / teleport.cpp
bloba30c2ab56d069e5dd794806ebc1456b338253008
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /////////////
23 // INCLUDE //
24 /////////////
25 #include "stdpch.h"
26 // Client
27 #include "teleport.h"
28 // Misc
29 #include "nel/misc/vectord.h"
30 // Georges
31 #include "nel/georges/u_form.h"
32 #include "nel/georges/u_form_elm.h"
33 #include "nel/georges/u_form_loader.h"
35 #ifdef DEBUG_NEW
36 #define new DEBUG_NEW
37 #endif
39 ///////////
40 // USING //
41 ///////////
42 using namespace NLMISC;
43 using namespace NLGEORGES;
44 using namespace std;
47 ////////////
48 // METHOD //
49 ////////////
50 const NLMISC::CVectorD CTeleport::Unknown = NLMISC::CVectorD(-1.0, -1.0, -1.0);
51 CTeleport::TDestinations CTeleport::_Destinations;
54 //-----------------------------------------------
55 // load :
56 // Load Destinations.
57 //-----------------------------------------------
58 void CTeleport::load(const std::string &/* filename */)
61 // TRAP : no more teleport list to load from georges file if you want this feature again ask me
63 // Clear old destinations.
64 _Destinations.clear();
66 // Load the Form.
67 CSmartPtr<UForm> form = 0;
68 NLGEORGES::UFormLoader *formLoader = UFormLoader::createLoader();
69 if(formLoader)
71 form = formLoader->loadForm(filename.c_str());
72 if(!form)
74 nlwarning("CTeleport::load: can't load form '%s'.", filename.c_str());
75 return;
78 else
80 nlwarning("CTeleport::load: cannot create an UFormLoader *.");
81 return;
84 // Get the root.
85 const UFormElm& rootElmt = form->getRootNode();
88 // Get animations.
89 const UFormElm *elmt = 0;
90 rootElmt.getNodeByName(&elmt, "list");
91 if(elmt)
93 uint arrawSize;
94 elmt->getArraySize(arrawSize);
95 // Get all animation for the State.
96 for(uint i = 0; i<arrawSize; ++i)
98 const UFormElm *tpElmt;
99 elmt->getArrayNode(&tpElmt, i);
100 if(tpElmt)
102 // Destination name.
103 string destName;
104 if(tpElmt->getValueByName(destName, "name"))
106 // Get the position
107 CVector pos;
108 if(tpElmt->getValueByName(pos.x, "position.X")
109 && tpElmt->getValueByName(pos.y, "position.Y")
110 && tpElmt->getValueByName(pos.z, "position.Z"))
112 // All in UPPER CASE to not be CASE SENSITIVE.
113 _Destinations.insert(make_pair(NLMISC::toLowerAscii(destName), pos));
115 else
116 nlwarning("CTeleport::load: Cannot find the one of the key 'position.X or Y or Z' for the element %d.", i);
118 else
119 nlwarning("CTeleport::load: Cannot find the key 'name' for the element %d.", i);
121 else
122 nlwarning("CTeleport::load: element (%d) should be here in 'list'.", i);
125 else
126 nlwarning("CTeleport::load: there is no element 'list'.");
128 // Release the loader.
129 if(formLoader)
131 UFormLoader::releaseLoader(formLoader);
132 formLoader = 0;
135 }// load //
137 //-----------------------------------------------
138 // getPos :
139 // Get the destination position or CTeleport::Unknown.
140 //-----------------------------------------------
141 const NLMISC::CVectorD &CTeleport::getPos(const std::string &/* dest */)
143 return Unknown;
145 TDestinations::const_iterator it = _Destinations.find(dest);
146 if(it == _Destinations.end())
147 return Unknown;
148 else
149 return (*it).second;
151 }// getPos //