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/>.
19 #include "move_manager.h"
20 #include "nel/misc/config_file.h"
21 #include "nel/net/service.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"
34 #include "game_share/ig_list.h"
35 #include "game_share/used_continent.h"
38 using namespace NLMISC
;
39 using namespace NLPACS
;
40 using namespace NLNET
;
46 CMoveManager::TObstacleGrid
CMoveManager::Grid
;
49 CContinentContainer
CMoveManager::Continents
;
52 CMoveManager::TObstacleMap
CMoveManager::ObstacleMap
;
55 CMoveManager::TPrimZoneMap
CMoveManager::PrimZoneMap
;
59 void CMoveManager::init()
62 Continents
.init(30, 30, 8.0, 2, IService::getInstance()->WriteFilesDirectory
);
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");
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);
83 for (i=sizeof(IGFiles)/sizeof(IGFiles[0]);i--;)
87 NL3D::UInstanceGroup *ig = NL3D::UInstanceGroup::createInstanceGroup(IGFiles[i]);
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)));
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);
109 catch (std::exception &e)
118 void CMoveManager::update()
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);
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()))
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
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
));
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
);
171 TObstacleGrid::CIterator ito
= Grid
.insert(obstacle
, obstacle
.Position
);
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());
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
);
208 void CMoveManager::release()
210 // remove all continents
212 for (i
=0; (sint
)i
<Continents
.size(); ++i
)
213 Continents
.removeContinent(i
);
220 /* End of move_manager.cpp */