Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / family_profile_tribe.h
blob99a85bb01911dd3400f79efab3e1680f27ac1df5
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 #ifndef FAMILY_PROFILE_TRIBE_H
20 #define FAMILY_PROFILE_TRIBE_H
22 extern NLMISC::CVariable<bool> LogOutpostDebug;
24 class CFamilyProfileTribe;
26 /// outpost information
27 class COutpostInfo
28 :public NLMISC::CRefCount
30 COutpostInfo (CFamilyBehavior *const familyBehavior, const CFamilyProfileTribe *const familyProfileTribe, const CNpcZone*const zoneNpc)
31 :_State(ZCSTATE::Tribe)
32 ,_FamilyBehavior(familyBehavior)
33 ,_FamilyProfileTribe(familyProfileTribe)
34 ,_ZoneNpc(zoneNpc)
35 ,_FightGroupExist(false)
36 ,_BossGroupExist(false)
37 ,_ContactGroupExist(false)
41 public:
43 static NLMISC::CSmartPtr<COutpostInfo> createOutpost (CFamilyBehavior *const familyBehavior, const CFamilyProfileTribe *const familyProfileTribe, const NLMISC::TStringId &outpostName)
45 const CNpcZone *const zoneNpc=familyBehavior->getOwner()->lookupNpcZoneByName(/*familyBehavior->getFamily(), */NLMISC::CStringMapper::unmap(outpostName));
47 if ( !zoneNpc
48 || !familyProfileTribe
49 || !familyBehavior)
50 return NULL;
52 return new COutpostInfo(familyBehavior, familyProfileTribe, zoneNpc);
55 typedef std::vector<NLMISC::CDbgPtr<CGroupNpc> > TGroupList;
57 virtual ~COutpostInfo()
59 for (TGroupList::iterator it=_FightGroup.begin(), itEnd=_FightGroup.end();it!=itEnd;++it)
61 NLMISC::CDbgPtr<CGroupNpc> &dbgPtr=*it;
62 if (!dbgPtr.isNULL())
63 dbgPtr->despawnGrp();
66 for (TGroupList::iterator it=_ContactGroups.begin(), itEnd=_ContactGroups.end();it!=itEnd;++it)
68 NLMISC::CDbgPtr<CGroupNpc> &dbgPtr=*it;
69 if (!dbgPtr.isNULL())
70 dbgPtr->despawnGrp();
73 if (!_BossGroup.isNULL())
75 _BossGroup->despawnGrp();
80 void spawnBoss ();
82 void outpostEvent (ZCSTATE::TZcState state);
84 void updateOutPostInfo ();
86 void fightGroups(bool exist);
87 void bossGroups(bool exist);
88 void contactGroups(bool exist);
90 void addToDespawnGroupList (CSpawnGroupNpc *grpNpc)
92 grpNpc->activityProfile().setAIProfile(NULL); // remove comportment.
93 _DespawnList.push_back(&grpNpc->getPersistent());
96 void checkDespawnGroupList ();
98 private:
99 /// The npc zone for the outpost
100 NLMISC::CstCDbgPtr<CNpcZone> _ZoneNpc;
102 /// The current outpost state.
103 ZCSTATE::TZcState _State;
105 TGroupList _ContactGroups;
106 /// Fight Groups.
107 TGroupList _FightGroup;
109 TGroupList _DespawnList;
111 /// Pointer on the boss group when present.
112 NLMISC::CDbgPtr<CGroupNpc> _BossGroup;
114 NLMISC::CDbgPtr<CFamilyBehavior> _FamilyBehavior;
115 NLMISC::CDbgPtr<CFamilyProfileTribe> _FamilyProfileTribe;
117 public:
118 bool _FightGroupExist;
119 bool _BossGroupExist;
120 bool _ContactGroupExist;
123 class CFamilyProfileTribe
124 :public NLMISC::CDbgRefCount<CFamilyProfileTribe>
125 ,public IFamilyProfile
127 /// The zone that is used as camp for the tribe.
128 NLMISC::CSmartPtr<const CNpcZone> _CampZone; // smart to have a counter on NpcZone. (Bad but no time to do better).
130 /// The contact group in the camp
131 NLMISC::CstCDbgPtr<CGroupNpc> _CampContact;
132 public:
133 std::vector<uint32> _AggroGroupIds;
136 CFamilyProfileTribe (const CtorParam &ctorParam);
138 virtual ~CFamilyProfileTribe ()
142 CFamilyBehavior *getFamilyBehavior ()
144 return _FamilyBehavior;
147 /// The zone that is used as camp for the tribe.
148 const NLMISC::CSmartPtr<const CNpcZone> &getCampZone() const
150 return _CampZone;
152 void setCampZone (const CNpcZone *campZone)
154 _CampZone=campZone;
157 void spawnBoss(NLMISC::TStringId outpostName);
159 void setDefaultProfile(const CNpcZone *const zone, CGroupNpc *grp);
161 typedef std::map<NLMISC::TStringId, NLMISC::CSmartPtr<COutpostInfo> > TOutpostContainer;
162 TOutpostContainer _OutpostInfos;
164 void fillOutpostNames(std::vector<NLMISC::TStringId> outpostNames)
166 outpostNames.clear();
167 for (TOutpostContainer::const_iterator first(_OutpostInfos.begin()), last(_OutpostInfos.end()); first != last; ++first)
168 outpostNames.push_back(first->first);
172 void outpostAdd(NLMISC::TStringId outpostName);
173 void outpostRemove(NLMISC::TStringId outpostName);
175 void outpostEvent(NLMISC::TStringId outpostName, ZCSTATE::TZcState state)
177 TOutpostContainer::iterator it(_OutpostInfos.find(outpostName));
178 if (it==_OutpostInfos.end())
179 return;
181 // nlassert(it != _OutpostInfos.end());
182 it->second->outpostEvent(state);
185 void spawnGroup();
187 /// The main update for the profile. Called aprox every 10 s (100 ticks)
188 void update();
191 extern IAiFactory<IFamilyProfile> *_ProfileTribe;
194 //---------------------------------------------------------------------------------
195 // CGrpProfileDynContact
196 //---------------------------------------------------------------------------------
200 class CGrpProfileDynContact
201 : public CGrpProfileNormal
203 public:
204 CGrpProfileDynContact(CProfileOwner *const owner, CFamilyProfileTribe *const familyProfile, COutpostInfo *const outPostInfo, bool isTheContactGroup=false)
205 :CGrpProfileNormal(owner)
206 ,_FamilyProfile(familyProfile)
207 ,_isTheContactGroup(isTheContactGroup)
208 ,_OutPostInfo(outPostInfo)
210 _CurrentZone=_FamilyProfile->getCampZone();
211 // this group can't be despawnded
212 _Grp->getPersistent().setDiscardable(!isTheContactGroup);
215 virtual ~CGrpProfileDynContact()
219 //---------------------------------------------------------------------------------------------------------
220 // virtual routines used to mange behaviour of bot
221 // note that this code is responsible for setting the 'nextActivity' bot property and may modify
222 // the 'activityTimer' property - may also set the 'nextTarget' property
224 // routine called when a bot starts to use a given profile
225 // note that bots have a data member called 'void *aiProfileData' reserved for the use of the profile code
226 // this data member should be setup here if it is to be used by the profile
227 virtual void beginProfile();
229 // routine called just before bot starts to use a new profile or when a bot dies
230 virtual void endProfile();
231 // routine called every time the bot is updated (frequency depends on player proximity, etc)
232 virtual void updateProfile(uint ticksSinceLastUpdate);
234 // routine used to build a debug string for detailed information on a bot's status (with respect to their aiProfile)
235 virtual std::string buildDebugString() const;
237 virtual AITYPES::TProfiles getAIProfileType () const
239 return AITYPES::ACTIVITY_CONTACT;
242 void gotoZone(const CNpcZone *const zone, const AITYPES::CPropertySet &flags);
244 private:
245 COutpostInfo *const _OutPostInfo;
246 CFamilyProfileTribe *const _FamilyProfile;
247 NLMISC::CstCDbgPtr<CNpcZone> _CurrentZone;
248 const bool _isTheContactGroup;
256 //---------------------------------------------------------------------------------
257 // CGrpProfileDynHarvest
258 //---------------------------------------------------------------------------------
261 class CGrpProfileDynHarvest: public CGrpProfileNormal
263 public:
264 CGrpProfileDynHarvest(CProfileOwner *const owner, CFamilyProfileTribe *const familyProfile, const CNpcZone *const harvestZone, const CNpcZone *const currentZone)
265 :CGrpProfileNormal(owner)
266 ,_FamilyProfile(familyProfile)
267 ,_HarvestZone(harvestZone)
269 _CurrentZone=currentZone;
272 virtual ~CGrpProfileDynHarvest()
276 //---------------------------------------------------------------------------------------------------------
277 // virtual routines used to mange behaviour of bot
278 // note that this code is responsible for setting the 'nextActivity' bot property and may modify
279 // the 'activityTimer' property - may also set the 'nextTarget' property
281 // routine called when a bot starts to use a given profile
282 // note that bots have a data member called 'void *aiProfileData' reserved for the use of the profile code
283 // this data member should be setup here if it is to be used by the profile
284 virtual void beginProfile();
286 // routine called just before bot starts to use a new profile or when a bot dies
287 virtual void endProfile();
288 // routine called every time the bot is updated (frequency depends on player proximity, etc)
289 virtual void updateProfile(uint ticksSinceLastUpdate);
291 void checkTargetsAround ();
293 // routine used to build a debug string for detailed information on a bot's status (with respect to their aiProfile)
294 virtual std::string buildDebugString() const;
296 virtual AITYPES::TProfiles getAIProfileType () const
298 return AITYPES::ACTIVITY_HARVEST;
301 private:
302 CAITimer _checkTargetTimer;
304 CFamilyProfileTribe *const _FamilyProfile;
305 NLMISC::CstCDbgPtr<CNpcZone> _CurrentZone;
306 NLMISC::CstCDbgPtr<CNpcZone> const _HarvestZone;
310 //---------------------------------------------------------------------------------
311 // CGrpProfileDynHarvest
312 //---------------------------------------------------------------------------------
315 //---------------------------------------------------------------------------------
316 // CGrpProfileDynFight
317 //---------------------------------------------------------------------------------
321 class CGrpProfileDynFight: public CGrpProfileNormal
323 public:
324 CGrpProfileDynFight(CProfileOwner *const owner, CFamilyProfileTribe *const familyProfile, const CNpcZone*const zone, COutpostInfo *const outPostInfo)
325 :CGrpProfileNormal(owner)
326 ,_FamilyProfile(familyProfile)
327 ,_CurrentZone(zone)
328 ,_OutPostInfo(outPostInfo)
332 virtual ~CGrpProfileDynFight()
336 //---------------------------------------------------------------------------------------------------------
337 // virtual routines used to mange behaviour of bot
338 // note that this code is responsible for setting the 'nextActivity' bot property and may modify
339 // the 'activityTimer' property - may also set the 'nextTarget' property
341 // routine called when a bot starts to use a given profile
342 // note that bots have a data member called 'void *aiProfileData' reserved for the use of the profile code
343 // this data member should be setup here if it is to be used by the profile
344 virtual void beginProfile();
346 // routine called just before bot starts to use a new profile or when a bot dies
347 virtual void endProfile();
348 // routine called every time the bot is updated (frequency depends on player proximity, etc)
349 virtual void updateProfile(uint ticksSinceLastUpdate);
351 // routine used to build a debug string for detailed information on a bot's status (with respect to their aiProfile)
352 virtual std::string buildDebugString() const;
354 virtual AITYPES::TProfiles getAIProfileType () const
356 return AITYPES::ACTIVITY_FIGHT;
359 void gotoZone(const CNpcZone *const zone, const AITYPES::CPropertySet &flags);
361 private:
362 COutpostInfo *const _OutPostInfo;
363 CFamilyProfileTribe *const _FamilyProfile;
364 NLMISC::CstCDbgPtr<CNpcZone> _CurrentZone;
367 #endif