Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / named_entity.cpp
blobf5911e757191bc1e4e50882b59e707cd8d02f681
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/>.
17 #include "stdpch.h"
19 #include "named_entity.h"
20 #include "ai_instance.h"
21 #include "game_share/ryzom_entity_id.h"
22 #include "ai_grp_npc.h"
24 CNamedEntity::CNamedEntity(std::string const& name)
25 : _name(name)
26 , _id(NLMISC::CEntityId::getNewEntityId(RYZOMID::ais_named_entity))
30 std::string const& CNamedEntity::name() const
32 return _name;
35 NLMISC::CEntityId const& CNamedEntity::id() const
37 return _id;
40 std::string const& CNamedEntity::getState()
42 return _state;
45 std::string const& CNamedEntity::getParam1()
47 return _param1;
50 std::string const& CNamedEntity::getParam2()
52 return _param2;
55 void CNamedEntity::set(std::string const& prop, std::string const& value, bool reportChange)
57 if (prop=="state")
58 _state = value;
59 else if (prop=="param1")
60 _param1 = value;
61 else if (prop=="param2")
62 _param2 = value;
63 else
64 nlwarning("Trying to set a bad property ('%s') on named entity '%s'", prop.c_str(), _name.c_str());
65 if (reportChange)
66 namedEntityCb(prop);
69 std::string CNamedEntity::get(std::string const& prop)
71 if (prop=="state")
72 return _state;
73 else if (prop=="param1")
74 return _param1;
75 else if (prop=="param2")
76 return _param2;
77 else
78 nlwarning("Trying to get a bad property ('%s') on named entity '%s'", prop.c_str(), _name.c_str());
79 return std::string();
82 void CNamedEntity::addListenerGroup(std::string const& prop, CGroupNpc* persGrp)
84 _listenerGroups.insert(std::make_pair(prop, persGrp));
87 void CNamedEntity::delListenerGroup(std::string const& prop, CGroupNpc* persGrp)
89 TListenerGroupList::iterator it = _listenerGroups.find(prop);
90 if (it!=_listenerGroups.end())
92 _listenerGroups.erase(it);
96 void CNamedEntity::namedEntityCb(std::string const& prop)
98 TListenerGroupList::const_iterator first, last, grp;
99 first = _listenerGroups.lower_bound(prop);
100 last = _listenerGroups.upper_bound(prop);
101 std::set<CGroupNpc*> groups;
102 for (grp=first; grp!=last; ++grp)
104 groups.insert(grp->second);
106 std::set<CGroupNpc*>::iterator sfirst=groups.begin(), slast=groups.end(), sgrp;
107 for (sgrp=sfirst; sgrp!=slast; ++sgrp)
109 (*sgrp)->namedEntityListenerCb(_name, prop);