Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / client_message.cpp
blob142815f3c89a2618c94f3389de84d504ebe785c2
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 #include "stdpch.h"
21 #include "client_message.h"
22 #include "ai_bot_npc.h"
23 #include "ai_grp_npc.h"
25 #include "ai.h"
26 #include "ai_player.h"
27 #include "nel/misc/entity_id.h"
29 using namespace NLMISC;
30 using namespace NLNET;
32 // a big bad global var !
33 extern CAIEntityPhysical *TempSpeaker;
34 extern CBotPlayer *TempPlayer;
37 void cbClientFollowTarget( NLNET::CMessage& msgin, const std::string & serviceName, NLNET::TServiceId serviceId )
39 CEntityId eId;
40 msgin.serial( eId );
42 if (eId.getType()!=RYZOMID::player)
43 return;
45 // then the entity ID
46 CAIEntityPhysical *entityPhys=CAIS::instance().getEntityPhysical(TheDataset.getDataSetRow(eId));
48 if (!entityPhys)
49 return;
51 CBotPlayer *player=NLMISC::safe_cast<CBotPlayer*>(entityPhys);
52 player->setFollowMode(true);
54 if ( ((CAIEntityPhysical*)player->getTarget())
55 || ((CAIEntityPhysical*)player->getVisualTarget()) )
57 // generate the follow event
58 CSpawnBotNpc *bnpc = dynamic_cast<CSpawnBotNpc *>(((CAIEntityPhysical*)player->getTarget()));
59 if (!bnpc)
60 bnpc = dynamic_cast<CSpawnBotNpc *>(((CAIEntityPhysical*)player->getVisualTarget()));
62 if (!bnpc)
63 return;
65 // set the temporary speaker
66 TempSpeaker = bnpc;
67 TempPlayer = player;
70 CGroupNpc &grpNpc = bnpc->getPersistent().grp();
71 // generate en event on this bot group
72 // grpNpc.getEventContainer().EventPlayerTargetNpc.processStateEvent(&grpNpc);
73 grpNpc.processStateEvent(grpNpc.getEventContainer().EventPlayerTargetNpc);
75 // if player is in follow mode, then generate an suplementary event
76 if (player->getFollowMode())
77 grpNpc.processStateEvent(grpNpc.getEventContainer().EventPlayerFollowNpc);
78 // grpNpc.getEventContainer().EventPlayerFollowNpc.processStateEvent(&grpNpc);
81 // reset the temp speaker
82 TempSpeaker = NULL;
83 TempPlayer = NULL;
88 void cbClientNoFollowTarget( NLNET::CMessage& msgin, const std::string & serviceName, NLNET::TServiceId serviceId )
90 CEntityId eId;
91 msgin.serial( eId );
93 if (eId.getType()!=RYZOMID::player)
94 return;
96 // then the entity ID
97 CAIEntityPhysical *const entityPhys=CAIS::instance().getEntityPhysical(TheDataset.getDataSetRow(eId));
99 if (!entityPhys)
100 return;
102 CBotPlayer *const player=NLMISC::safe_cast<CBotPlayer*>(entityPhys);
103 player->setFollowMode(false);
107 //----------------------------
108 // CbClientArray
109 //----------------------------
110 TUnifiedCallbackItem CbClientArray[]=
112 { "CLIENT:TARGET:FOLLOW", cbClientFollowTarget },
113 { "CLIENT:TARGET:NO_FOLLOW", cbClientNoFollowTarget },
116 void CAIClientMessages::init()
118 // setup the callback array
119 CUnifiedNetwork::getInstance()->addCallbackArray( CbClientArray, sizeof(CbClientArray)/sizeof(CbClientArray[0]) );
122 void CAIClientMessages::release()
126 #include "event_reaction_include.h"