Add infos into target window
[ryzomcore.git] / ryzom / server / src / ags_test / move_manager.cpp
blob9e43fe0344837d85cb6e54d6b167d8614893cd54
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/>.
19 #include "move_manager.h"
20 #include "nel/misc/config_file.h"
21 #include "nel/net/service.h"
22 #include "sheets.h"
24 #include "nel/misc/file.h"
25 #include "nel/misc/path.h"
26 #include "game_share/ryzom_entity_id.h"
29 //#include "nel/3d/u_instance_group.h"
31 #include "sheets.h"
33 // ugly
34 #include "game_share/ig_list.h"
35 #include "game_share/used_continent.h"
37 using namespace std;
38 using namespace NLMISC;
39 using namespace NLPACS;
40 using namespace NLNET;
42 namespace AGS_TEST
45 // the actor grid
46 CMoveManager::TObstacleGrid CMoveManager::Grid;
48 // the continents
49 CContinentContainer CMoveManager::Continents;
52 CMoveManager::TObstacleMap CMoveManager::ObstacleMap;
55 CMoveManager::TPrimZoneMap CMoveManager::PrimZoneMap;
58 // init
59 void CMoveManager::init()
61 // init continents
62 Continents.init(30, 30, 8.0, 2, IService::getInstance()->WriteFilesDirectory);
64 // load continents
65 CUsedContinent::TUsedContinentCont usedCont = CUsedContinent::instance().getContinents();
67 for (uint i=0; i<usedCont.size(); ++i)
69 Continents.loadContinent(usedCont[i].ContinentName, usedCont[i].ContinentName, usedCont[i].ContinentInstance);
70 Continents.getMoveContainer(usedCont[i].ContinentInstance)->setAsStatic(0);
72 /* CConfigFile::CVar& cvUsedContinents = IService::getInstance()->ConfigFile.getVar("UsedContinents");
73 uint i;
74 for (i=0; (sint)i<cvUsedContinents.size(); ++i)
75 if (cvUsedContinents.asString(i) != "")
77 Continents.loadContinent(cvUsedContinents.asString(i), cvUsedContinents.asString(i), i);
78 Continents.getMoveContainer(i)->setAsStatic(0);
82 // load trees ig
83 for (i=sizeof(IGFiles)/sizeof(IGFiles[0]);i--;)
85 try
87 NL3D::UInstanceGroup *ig = NL3D::UInstanceGroup::createInstanceGroup(IGFiles[i]);
88 if (ig == NULL)
89 continue;
91 uint k;
92 for(k = 0; k < ig->getNumInstance(); ++k)
94 const string &name = ig->getShapeName(k);
95 sint sz = name.size();
96 if (sz >= 6 && strlwr(name.substr(sz-6, 6)) == ".shape")
98 const CSheets::CSheet *sheet = CSheets::lookup(CSheetId(ig->getInstanceName(k)));
99 CObstacle obstacle;
100 obstacle.Id = CEntityId(RYZOMID::flora, 0xDEADF00D, IService::getInstance()->getServiceId(), IService::getInstance()->getServiceId());
101 obstacle.Position = ig->getInstancePos(k);
102 obstacle.Radius = (sheet != NULL) ? sheet->Radius : 0.5f;
103 Grid.insert(obstacle, obstacle.Position);
107 delete ig;
109 catch (std::exception &e)
111 nlinfo(e.what());
117 // update
118 void CMoveManager::update()
120 uint i;
121 for (i=0; (sint)i<Continents.size(); ++i)
122 if (Continents.getMoveContainer(i) != NULL)
124 Continents.getMoveContainer(i)->evalCollision(1, 0);
125 Continents.getMoveContainer(i)->evalCollision(1, 1);
130 // process ai vision
131 void CMoveManager::processAIVision(CMessage &msg)
133 TObstacleMap::iterator it;
134 for (it=ObstacleMap.begin(); it!=ObstacleMap.end(); ++it)
135 (*((*it).second)).Updated = false;
137 uint64 AgentId; // should be fakeid...
138 msg.serial( AgentId );
140 while (msg.getPos() < (sint32)(msg.length()))
142 CEntityId id;
143 TTime time;
144 CVectorD pos;
145 CVector heading;
146 float speed;
147 string sheetId;
149 // get all from message
150 msg.serial(id, time, pos, heading, speed, sheetId);
152 it = ObstacleMap.find(id);
153 if (it == ObstacleMap.end())
155 // if not exists yet, creates an obstacle
156 CObstacle obstacle;
157 obstacle.Id = id;
158 obstacle.Position = CVector(pos);
159 obstacle.Radius = 0.5f;
160 obstacle.External = true;
162 // get sheet from this sheetId
163 const CSheets::CSheet *sheet = CSheets::lookup(CSheetId(sheetId));
164 if (sheet != NULL)
165 obstacle.Radius = sheet->Radius;
168 nlinfo("New Object %s in IA vision at (%.1f,%.1f,%.1f), radius %.1f", id.toString().c_str(), pos.x, pos.y, pos.z, obstacle.Radius);
170 // insert in grid
171 TObstacleGrid::CIterator ito = Grid.insert(obstacle, obstacle.Position);
173 // insert in map
174 pair<TObstacleMap::iterator, bool> res = ObstacleMap.insert(make_pair<CEntityId, TObstacleGrid::CIterator>(id, ito));
176 it = ObstacleMap.find(id);
177 nlassert(it != ObstacleMap.end());
179 it = res.first;
181 else
183 (*((*it).second)).Position = pos;
184 Grid.move((*it).second, pos);
187 (*((*it).second)).Updated = true;
190 // erase not updated obstacles
191 for (it=ObstacleMap.begin(); it!=ObstacleMap.end(); )
193 if (!(*((*it).second)).Updated && (*((*it).second)).External)
195 nlinfo("Remove old object %s in IA vision", (*it).first.toString().c_str());
196 TObstacleMap::iterator itr = it++;
197 Grid.remove((*itr).second);
198 ObstacleMap.erase(itr);
200 else
202 ++it;
207 // release
208 void CMoveManager::release()
210 // remove all continents
211 uint i;
212 for (i=0; (sint)i<Continents.size(); ++i)
213 Continents.removeContinent(i);
215 Continents.clear();
218 } // AGS_TEST
220 /* End of move_manager.cpp */