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 "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
)
26 , _id(NLMISC::CEntityId::getNewEntityId(RYZOMID::ais_named_entity
))
30 std::string
const& CNamedEntity::name() const
35 NLMISC::CEntityId
const& CNamedEntity::id() const
40 std::string
const& CNamedEntity::getState()
45 std::string
const& CNamedEntity::getParam1()
50 std::string
const& CNamedEntity::getParam2()
55 void CNamedEntity::set(std::string
const& prop
, std::string
const& value
, bool reportChange
)
59 else if (prop
=="param1")
61 else if (prop
=="param2")
64 nlwarning("Trying to set a bad property ('%s') on named entity '%s'", prop
.c_str(), _name
.c_str());
69 std::string
CNamedEntity::get(std::string
const& prop
)
73 else if (prop
=="param1")
75 else if (prop
=="param2")
78 nlwarning("Trying to get a bad property ('%s') on named entity '%s'", prop
.c_str(), _name
.c_str());
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
);