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/>.
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"
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
);
47 setDefaultProfile(zone
, grp
);
52 class CFamilyProfileKitin
: public IFamilyProfile
55 CFamilyProfileKitin (const IFamilyProfile::CtorParam
&ctorParam
)
56 :IFamilyProfile(ctorParam
)
59 virtual ~CFamilyProfileKitin()
65 H_AUTO(FamilySpawnKitin
)
67 const CGroupDesc
<CGroupFamily
> *gd
= _FamilyBehavior
->grpFamily()->getProportionalGroupDesc(_FamilyBehavior
, CPropertySet(), CPropertySet());
71 CGrpFauna
*grp
= gd
->createFaunaGroup(_FamilyBehavior
);
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)
87 class CFamilyProfileFauna
: public IFamilyProfile
90 CFamilyProfileFauna (const IFamilyProfile::CtorParam
&ctorParam
)
91 :IFamilyProfile(ctorParam
)
94 virtual ~CFamilyProfileFauna()
100 H_AUTO(FamilySpawnFauna
)
102 const CGroupDesc
<CGroupFamily
> *const gd
= _FamilyBehavior
->grpFamily()->getProportionalGroupDesc(_FamilyBehavior
, CPropertySet(), CPropertySet());
106 CGrpFauna
*const grp
= gd
->createFaunaGroup(_FamilyBehavior
);
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)
122 class CFamilyProfileNpc
: public IFamilyProfile
125 CFamilyProfileNpc(const IFamilyProfile::CtorParam
&ctorParam
)
126 :IFamilyProfile(ctorParam
)
129 virtual ~CFamilyProfileNpc()
135 H_AUTO(FamilySpawnNpc
)
137 AITYPES::CPropertySet flags
;
138 _FamilyBehavior
->getNpcFlags(flags
);
140 const CNpcZone
*spawn
= _FamilyBehavior
->getOwner()->lookupNpcZone(flags
, _FamilyBehavior
->grpFamily()->getSubstitutionId());
143 const CGroupDesc
<CGroupFamily
> *const gd
= _FamilyBehavior
->grpFamily()->getProportionalGroupDesc(_FamilyBehavior
, CPropertySet(), CPropertySet());
148 const CGroupNpc
*const grp
=createNpcGroup(spawn
, gd
);
153 grp
->getSpawnObj()->spawnBotOfGroup();
156 /// The main update for the profile. Called aprox every 10 s (100 ticks)
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()
195 _Instance
= new CFamilyProfileFactory();
200 IFamilyProfile
* CFamilyProfileFactory::createFamilyProfile(const TStringId
&keyWord
, const IFamilyProfile::CtorParam
& ctorParam
)
205 IAiFactory
<IFamilyProfile
> *const familyProfile
=instance().getFactory(keyWord
);
210 IFamilyProfile
*const profile
=familyProfile
->createObject(ctorParam
);
217 nlwarning("DYN: createProfile no profile available for %s", NLMISC::CStringMapper::unmap(keyWord
).c_str());
221 IFamilyProfile
* IFamilyProfile::createFamilyProfile(const TStringId
&profileName
, const IFamilyProfile::CtorParam
& ctorParam
)
223 return CFamilyProfileFactory::createFamilyProfile(profileName
, ctorParam
);