Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_grp_pet.cpp
blob9e45c0d46e0060ab1cb011f029f302c07dfe4115
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"
18 #include "ai_grp_pet.h"
19 #include "owners.h"
20 #include "ai_share/ai_types.h"
22 #include "ai_profile_pet.h" // for CAIPetProfileStand
24 using namespace NLMISC;
25 using namespace AITYPES;
27 //////////////////////////////////////////////////////////////////////////////
28 // CSpawnGroupPet //
29 //////////////////////////////////////////////////////////////////////////////
31 void CSpawnGroupPet::update ()
33 FOREACH(it, CCont<CBot>, bots())
35 CBotPet* const botPet = safe_cast<CBotPet*>(*it);
36 if (!botPet->isSpawned() || botPet->haveToDespawn()) // must erase this bot.
37 getPersistent().bots().removeChildByIndex(botPet->getChildIndex());
40 CEntityId const& entityId = getPersistent().getPetOwner();
41 CAIEntityPhysical* const petOwner = CAIS::instance().getEntityPhysical(CMirrors::DataSet->getDataSetRow(entityId));
43 // Quick hack to prevent of too much computing..
44 if (petOwner)
46 double const distContDestToRealDest = petOwner->wpos().toAIVector().quickDistTo(_PathCont.getDestination());
48 if (distContDestToRealDest>4) // update only each 4 meters.
49 _PathCont.setDestination(petOwner->wpos());
50 _IsPlayerSpawned = true;
52 else
54 if (_IsPlayerSpawned)
56 FOREACH(it, CCont<CBot>, bots())
58 CBotPet *const pet=safe_cast<CBotPet*>(*it);
59 if (pet->isSpawned())
61 pet->getSpawn()->setAIProfile(new CAIPetProfileStand(pet->getSpawn()));
64 _IsPlayerSpawned = false;
69 uint32 const newTime = CTimeInterface::gameCycle();
70 uint32 const dt = newTime - _LastUpdate;
72 FOREACH(it, CCont<CBot>, bots())
74 (safe_cast<CBotPet*>(*it))->update(dt, petOwner);
76 _LastUpdate = newTime; // record the tick at which we ran this update (for future refference)
80 //////////////////////////////////////////////////////////////////////////////
81 // CGrpPet //
82 //////////////////////////////////////////////////////////////////////////////
84 CAIS::CCounter& CGrpPet::getSpawnCounter()
86 return CAIS::instance()._PetBotCounter;