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/>.
18 #include "ai_grp_pet.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 //////////////////////////////////////////////////////////////////////////////
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..
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;
56 FOREACH(it
, CCont
<CBot
>, bots())
58 CBotPet
*const pet
=safe_cast
<CBotPet
*>(*it
);
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 //////////////////////////////////////////////////////////////////////////////
82 //////////////////////////////////////////////////////////////////////////////
84 CAIS::CCounter
& CGrpPet::getSpawnCounter()
86 return CAIS::instance()._PetBotCounter
;