Added ai command setEquipment
[ryzomcore.git] / ryzom / server / src / ai_service / ai_vision.cpp
blob19007d01de8693b82eadb5472cacd76206abcd51
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 #include "stdpch.h"
22 //----------------------------------------------------------------------
23 // ctor
24 //----------------------------------------------------------------------
26 CAIVision::CAIVision()
30 CAIVision::~CAIVision()
34 //----------------------------------------------------------------------
35 // placing or moving vision entity in world or removing from world
36 //----------------------------------------------------------------------
38 template <class VectorClass>
39 void CAIVision::updateBots(const VectorClass &xy,uint32 botRadiusInMeters)
41 CAIEntityMatrix::CCellTblIteratorLinear *tbl;
42 CAIEntityMatrix::CEntityIteratorRandom it;
44 _bots.clear();
45 tbl==CAIS::bestMatrixIteratorLinearTbl(botRadiusInMeters);
46 for (it=CAIS::botMatrix().beginEntities(tbl,x,y);!it.end();++it)
47 _bots.push_back(&*it);
50 template <class VectorClass>
51 void CAIVision::updatePlayers(const VectorClass &xy,uint32 playerRaadiusInMeters)
53 CAIEntityMatrix::CCellTblIteratorLinear *tbl;
54 CAIEntityMatrix::CEntityIteratorRandom it;
56 _players.clear();
57 tbl==CAIS::bestMatrixIteratorLinearTbl(playerRadiusInMeters);
58 for (it=CAIS::botMatrix().beginEntities(tbl,xy.x(),xy.y());!it.end();++it)
59 _players.push_back(&*it);
62 //----------------------------------------------------------------------
63 // singleton entry point for dealing with vision deltas from the GPMS
64 //----------------------------------------------------------------------
66 void CAIVision::applyVisionDelta( NLMISC::CEntityId eid, const CPlayerVisionDelta &delta )
68 uint idx=(uint)eid.getShortId();
70 if (idx>=_visions.size() || eid.getRawId()!=NLMISC::CEntityId(RYZOMID::aiVision,idx))
72 nlwarning("Unable to treat vision delta for unrecognised entity id: %s",eid.toString().c_str());
73 return;
76 if (_visions[idx]==NULL)
78 nlwarning("Ignoring vision delta for deleted entity id: %s",eid.toString().c_str());
79 return;
82 _visions[idx]->applyVisionDelta( delta );
85 //----------------------------------------------------------------------
86 // dealing with individual vision deltas from the GPMS
87 //----------------------------------------------------------------------
89 void CAIVision::applyVisionDelta( const CPlayerVisionDelta &delta )
91 uint i;
92 //nlinfo("Applying vision delta: in: %d out: %d replace: %d",delta.EntitiesIn.size(),delta.EntitiesOut.size(),delta.EntitiesReplace.size());
94 for (i=0;i<delta.EntitiesOut.size();++i)
96 // remove entities no longer in vision
97 visionBuffer[delta.EntitiesOut[i].Slot]=CAIEntityId();
100 for (i=0;i<delta.EntitiesIn.size();++i)
102 // add new entities to vision
103 visionBuffer[delta.EntitiesIn[i].Slot]=CAIEntityId(delta.EntitiesIn[i].Id);
105 // make sure that the player structures exist in the player map
106 // this code to be replaced when propper player appearance/ disappeara nce treated
107 if (visionBuffer[delta.EntitiesIn[i].Slot].isPlr())
108 CAIS::getPlayer(delta.EntitiesIn[i].Id);
111 for (i=0;i<delta.EntitiesReplace.size();++i)
113 // add more new entities to vision
114 visionBuffer[delta.EntitiesReplace[i].Slot]=CAIEntityId(delta.EntitiesReplace[i].Id);
116 // make sure that the player structures exist in the player map
117 // this code to be replaced when propper player appearance/ disappeara nce treated
118 if (visionBuffer[delta.EntitiesReplace[i].Slot].isPlr())
119 CAIS::getPlayer(delta.EntitiesReplace[i].Id);
123 //----------------------------------------------------------------------
124 // Method used for off-line use of AIS
126 void CAIVision::addEntityId(CAIEntityId entityId)
128 iterator retval = &visionBuffer[0];
129 uint ii = 0;
130 while (*retval != CAIEntityId() && *retval !=CAIEntityId(0) && *retval !=entityId)
132 if (ii >= 256)
133 return;
134 ii++;
135 retval = &visionBuffer[ii];
137 visionBuffer[ii] = entityId;
140 void CAIVision::removeEntityId(CAIEntityId entityId)
142 iterator retval = &visionBuffer[0];
143 uint ii = 0;
144 while (*retval != entityId)
146 if (ii >= 256)
147 return;
148 ii++;
149 retval = &visionBuffer[ii];
151 visionBuffer[ii] = CAIEntityId();