Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / family_profile.cpp
bloba16665d8a31112bce9ee8f0c905445e02c026d17
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 "stdpch.h"
20 #include "family_profile.h"
21 #include "continent.h"
22 #include "ai_place_xyr.h"
23 #include "ai_grp_fauna.h"
24 #include "ai_grp_npc.h"
25 #include "ai_mgr_fauna.h"
26 #include "ai_mgr_npc.h"
27 #include "group_profile.h"
28 #include "family_behavior.h"
29 // #include "family_profile_tribe.h"
31 #include "continent_inline.h"
33 //extern bool LogOutpostDebug;
34 extern NLMISC::CVariable<bool> LogOutpostDebug;
36 #include "dyn_grp_inline.h"
38 using namespace std;
39 using namespace NLMISC;
40 using namespace AITYPES;
43 CGroupNpc *IFamilyProfile::createNpcGroup(const CNpcZone *const zone, const CGroupDesc<CGroupFamily> *const groupDesc)
45 CGroupNpc *grp=_FamilyBehavior->createNpcGroup(zone, groupDesc);
46 if (grp)
47 setDefaultProfile(zone, grp);
48 return grp;
52 class CFamilyProfileKitin : public IFamilyProfile
54 public:
55 CFamilyProfileKitin (const IFamilyProfile::CtorParam &ctorParam)
56 :IFamilyProfile(ctorParam)
59 virtual ~CFamilyProfileKitin()
63 void spawnGroup()
65 H_AUTO(FamilySpawnKitin)
67 const CGroupDesc<CGroupFamily> *gd = _FamilyBehavior->grpFamily()->getProportionalGroupDesc(_FamilyBehavior, CPropertySet(), CPropertySet());
68 if (!gd)
69 return;
71 CGrpFauna *grp = gd->createFaunaGroup(_FamilyBehavior);
72 if (!grp)
73 return;
75 // nldebug("DYN: Grp '%p' spawned for fauna", grp);
76 grp->getSpawnObj()->spawnBotOfGroup();
79 /// The main update for the profile. Called aprox every 10 s (100 ticks)
80 void update()
87 class CFamilyProfileFauna : public IFamilyProfile
89 public:
90 CFamilyProfileFauna (const IFamilyProfile::CtorParam &ctorParam)
91 :IFamilyProfile(ctorParam)
94 virtual ~CFamilyProfileFauna()
98 void spawnGroup()
100 H_AUTO(FamilySpawnFauna)
102 const CGroupDesc<CGroupFamily> *const gd = _FamilyBehavior->grpFamily()->getProportionalGroupDesc(_FamilyBehavior, CPropertySet(), CPropertySet());
103 if (!gd)
104 return;
106 CGrpFauna *const grp = gd->createFaunaGroup(_FamilyBehavior);
107 if (!grp)
108 return;
110 // nldebug("DYN: Grp '%p' spawned for fauna", grp);
111 grp->getSpawnObj()->spawnBotOfGroup();
114 /// The main update for the profile. Called aprox every 10 s (100 ticks)
115 void update()
122 class CFamilyProfileNpc : public IFamilyProfile
124 public:
125 CFamilyProfileNpc(const IFamilyProfile::CtorParam &ctorParam)
126 :IFamilyProfile(ctorParam)
129 virtual ~CFamilyProfileNpc()
133 void spawnGroup()
135 H_AUTO(FamilySpawnNpc)
137 AITYPES::CPropertySet flags;
138 _FamilyBehavior->getNpcFlags(flags);
140 const CNpcZone *spawn = _FamilyBehavior->getOwner()->lookupNpcZone(flags, _FamilyBehavior->grpFamily()->getSubstitutionId());
141 if (!spawn)
142 return;
143 const CGroupDesc<CGroupFamily> *const gd = _FamilyBehavior->grpFamily()->getProportionalGroupDesc(_FamilyBehavior, CPropertySet(), CPropertySet());
145 if (!gd)
146 return;
148 const CGroupNpc *const grp=createNpcGroup(spawn, gd);
150 if (!grp)
151 return;
153 grp->getSpawnObj()->spawnBotOfGroup();
156 /// The main update for the profile. Called aprox every 10 s (100 ticks)
157 void update()
163 CAiFactory<IFamilyProfile, CFamilyProfileFauna> _singleProfileFauna;
164 IAiFactory<IFamilyProfile> *_ProfileFauna=&_singleProfileFauna;
166 CAiFactory<IFamilyProfile, CFamilyProfileKitin> _singleProfileKitin;
167 IAiFactory<IFamilyProfile> *_ProfileKitin=&_singleProfileKitin;
169 CAiFactory<IFamilyProfile, CFamilyProfileNpc> _singleProfileNpc;
170 IAiFactory<IFamilyProfile> *_ProfileNpc=&_singleProfileNpc;
173 extern IAiFactory<IFamilyProfile> *_ProfileTribe; // in another cpp.
175 NL_ISO_TEMPLATE_SPEC CAiFactoryContainer<IFamilyProfile, TStringId> *CAiFactoryContainer<IFamilyProfile, TStringId>::_Instance = NULL;
177 CFamilyProfileFactory::CFamilyProfileFactory()
179 registerFactory(CStringMapper::map("groupFamilyProfileFauna"), _ProfileFauna);
180 registerFactory(CStringMapper::map("groupFamilyProfileKitin"), _ProfileKitin);
181 registerFactory(CStringMapper::map("groupFamilyProfileTribe"), _ProfileTribe);
182 registerFactory(CStringMapper::map("groupFamilyProfileNpc"), _ProfileNpc);
185 CFamilyProfileFactory::~CFamilyProfileFactory()
191 CAiFactoryContainer<IFamilyProfile, TStringId> &CFamilyProfileFactory::instance()
193 if (!_Instance)
195 _Instance = new CFamilyProfileFactory();
197 return *_Instance;
200 IFamilyProfile* CFamilyProfileFactory::createFamilyProfile(const TStringId &keyWord, const IFamilyProfile::CtorParam& ctorParam)
203 breakable
205 IAiFactory<IFamilyProfile> *const familyProfile=instance().getFactory(keyWord);
207 if (!familyProfile)
208 break;
210 IFamilyProfile *const profile=familyProfile->createObject(ctorParam);
212 if (!profile)
213 break;
215 return profile;
217 nlwarning("DYN: createProfile no profile available for %s", NLMISC::CStringMapper::unmap(keyWord).c_str());
218 return NULL;
221 IFamilyProfile* IFamilyProfile::createFamilyProfile(const TStringId &profileName, const IFamilyProfile::CtorParam& ctorParam)
223 return CFamilyProfileFactory::createFamilyProfile(profileName, ctorParam);