Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_bot_pet.cpp
blob1c2a79ee1e81b4fcac0c5ec340f7a4b0b6295e98
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_bot_pet.h"
19 #include "visual_properties_interface.h"
21 #include "nel/misc/random.h"
22 #include "ai_grp_pet.h"
23 #include "owners.h"
25 using namespace NLMISC;
26 using namespace std;
27 using namespace RYAI_MAP_CRUNCH;
29 //////////////////////////////////////////////////////////////////////////////
30 // CBotPet //
31 //////////////////////////////////////////////////////////////////////////////
33 void CBotPet::getSpawnPos(CAIVector& triedPos, RYAI_MAP_CRUNCH::CWorldPosition& spawnPos, RYAI_MAP_CRUNCH::CWorldMap const& worldMap, CAngle& spawnTheta)
35 // return can be false.
36 worldMap.setWorldPosition(_SpawnPos.h(), spawnPos, _SpawnPos);
37 spawnTheta = _SpawnPos.theta();
38 triedPos = _SpawnPos;
41 CGrpPet& CBotPet::getPetGroup()
43 return *static_cast<CGrpPet*>(getOwner());
46 void CBotPet::update(uint32 ticks, CAIEntityPhysical const* petOwner)
48 CSpawnBotPet* const spawnPet = getSpawn();
49 if (spawnPet)
51 if (spawnPet->isAlive())
53 if (spawnPet->isMounted())
54 spawnPet->updatePos(); // take position from GPMS
55 else
56 spawnPet->updateProfile(ticks); // update pathfinding profile
61 void CBotPet::triggerSetSheet(AISHEETS::ICreatureCPtr const& sheet)
63 nlwarning("Changing the sheet of a pet bot is not currently possible"); // The guy that wrote that is a lazy bastard...
66 //////////////////////////////////////////////////////////////////////////////
67 // CSpawnBotPet //
68 //////////////////////////////////////////////////////////////////////////////
70 /// Return true if the animal is mounted (thus controlled by the GPMS)
71 bool CSpawnBotPet::isMounted() const
73 // Do not control a pet when in mount mode (controlled by the GPMS)
74 CMirrorPropValueRO<MBEHAV::TMode> currentMode( TheDataset, dataSetRow(), DSPropertyMODE );
75 return currentMode().isMountMode();
78 /// Take position from mirror
79 void CSpawnBotPet::updatePos()
81 RYAI_MAP_CRUNCH::CWorldPosition wpos;
82 if (!CWorldContainer::getWorldMap().setWorldPosition(pos().h(), wpos, CAIVector(pos())))
83 return;
84 setWPos(wpos);
86 if (wpos.getFlags() & RYAI_MAP_CRUNCH::Water)
87 setActionFlags(RYZOMACTIONFLAGS::InWater);
88 else
89 removeActionFlags(RYZOMACTIONFLAGS::InWater);
92 CSpawnGroupPet& CSpawnBotPet::spawnGrp()
94 return static_cast<CSpawnGroupPet&>(CSpawnBot::spawnGrp());
97 void CSpawnBotPet::setVisualPropertiesName()
99 CBotPet& botRef = CSpawnBotPet::getPersistent();
100 ucstring name = botRef.getName();
102 if (CVisualPropertiesInterface::UseIdForName)
104 name = NLMISC::toString("AI:%s", botRef.getIndexString().c_str());
107 if (name.empty() && CVisualPropertiesInterface::ForceNames)
109 name = NLMISC::CFile::getFilenameWithoutExtension(botRef.getSheet()->SheetId().toString().c_str());
112 if (!botRef.getCustomName().empty())
113 name = botRef.getCustomName();
115 // no name the bot will appear without name on the client.
116 if (name.empty())
117 return;
119 CVisualPropertiesInterface::setName(dataSetRow(), name);