Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / egs_interface.cpp
blob37201cf3e887bce786efdf23a1a1f1c430f743bf
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"
20 #include "egs_interface.h"
21 #include "ai.h"
22 #include "ai_mgr.h"
23 #include "server_share/msg_ai_service.h"
24 #include "ai_bot_fauna.h"
25 #include "ai_grp_fauna.h"
26 #include "ai_bot_npc.h"
27 #include "ai_grp_npc.h"
28 #include "nel/misc/path.h"
30 extern bool simulateBug(int bugId);
32 using namespace NLMISC;
33 using namespace NLNET;
34 using namespace std;
37 // call back for synchronize time and day
38 static void cbKamiImpact( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
40 NLMISC::CEntityId charId;
41 uint32 depositId;
42 uint32 score;
44 // Send message to AIS for kami impact
45 msgin.serial( charId );
46 msgin.serial( depositId );
47 msgin.serial( score );
50 // classic init(), update() and release()
51 void CEGSInterface::init()
53 NLNET::TUnifiedCallbackItem _cbArray[] =
55 { "KAMI_IMPACT", cbKamiImpact },
57 CUnifiedNetwork::getInstance()->addCallbackArray( _cbArray, sizeof(_cbArray) / sizeof(_cbArray[0]) );
60 void CEGSInterface::update()
62 H_AUTO(EGSUpdate);
63 // flush output messages
66 void CEGSInterface::release()
70 void CUserEventMsgImp::callback (const std::string &name, NLNET::TServiceId id)
72 CAIInstance *aii = CAIS::instance().getAIInstance(InstanceNumber);
73 if (aii != NULL)
75 CGroup *grp = aii->findGroup(GrpAlias);
76 if (grp)
78 // ok, we found the correct group!
79 grp->setEventParams(Params);
80 grp->setEvent(EventId);
81 grp->setEventParams(vector<string>());
82 // nothing more to do
83 return;
87 nlwarning("CUserEventMsgImp event %u for group alias %u : no such group in instance %u !", EventId, GrpAlias, InstanceNumber);
91 void CSetEscortTeamIdImp::callback (const std::string &name, NLNET::TServiceId id)
93 // for each alias, retrieve the group and sets the escort team
94 for (uint i=0; i<Groups.size(); ++i)
96 CAIInstance *aii = CAIS::instance().getAIInstance(InstanceNumber);
97 if (aii)
99 CGroup *grp = aii->findGroup(Groups[i]); // Fake, to remove when EGS can tell us the corresponding world number.
100 if (grp)
102 grp->setEscortTeamId(TeamId);
104 else
105 nlwarning("CSetEscortTeamIdImp : can't find group with alias %u", Groups[i]);
107 else
109 nlwarning("CSetEscortTeamIdImp::callback : can't find AIInstance %u", InstanceNumber);
116 //////////////////////////////////////////////////////////////////////////
117 // Loot Finished or no loot, EGS ask to remove the creature.
119 void CCreatureDespawnImp::callback (const std::string &name, NLNET::TServiceId id)
121 for (uint i = 0; i < Entities.size(); i++)
123 CAIEntityPhysical*const ep = CAIS::instance().getEntityPhysical(Entities[i]);
124 if (!ep)
125 continue; // not spawn
127 switch(ep->getRyzomType())
129 case RYZOMID::npc:
130 // ok, warn the grp that this bot is totally looted, so we can despawn it
132 CSpawnBotNpc *botNpc = static_cast<CSpawnBotNpc *>(ep);
133 botNpc->spawnGrp().addBotToDespawnAndRespawnTime(&botNpc->getPersistent(), 1, botNpc->spawnGrp().getPersistent().respawnTime());
135 break;
136 case RYZOMID::creature: // Fauna.
138 CSpawnBotFauna *botFauna = static_cast<CSpawnBotFauna*>(ep);
140 if (simulateBug(6))
142 botFauna->spawnGrp().addBotToDespawnAndRespawnTime(&botFauna->getPersistent(),1,2); // 1 second.
144 else
146 // set time before respawn
147 sint32 RespawnTime= botFauna->spawnGrp().getPersistent().timer(CGrpFauna::RESPAWN_TIME);
148 botFauna->spawnGrp().addBotToDespawnAndRespawnTime(&botFauna->getPersistent(), 1, RespawnTime); // 1 tick before despawn
151 break;
152 case RYZOMID::pack_animal: // Pet.
154 CSpawnBotPet *spawnBotPet = static_cast<CSpawnBotPet*>(ep);
155 spawnBotPet->getPersistent().despawnBot(); // direct despawn.
157 break;
159 default:
160 nlwarning("CCreatureDespawnImp Entity %d is not processed", Entities[i].getIndex());
161 break;
166 //////////////////////////////////////////////////////////////////////////
168 void CAddHandledAIGroupImp::callback (const std::string &name, NLNET::TServiceId id)
170 CCont<CAIInstance> &instances = CAIS::instance().AIList();
172 for (uint i=0; i<instances.size(); ++i)
174 CAIInstance *aii = instances[i];
175 if (!aii)
176 continue;
178 CGroupNpc *grp = dynamic_cast<CGroupNpc*>(aii->findGroup(GroupAlias));
179 if (grp != NULL)
181 nlinfo("CAddHandledAIGroupImp on group %u user:%s miss:%d", GroupAlias, PlayerRowId.toString().c_str(), MissionAlias);
182 // ok, we found the correct group!
183 grp->addHandle(PlayerRowId, MissionAlias, DespawnTimeInTick);
184 return;
188 // debug only : AIS can receive message for not the same AiInstance as the group
189 //nlwarning("CAddHandledAIGroupImp group alias %u : not found !", GroupAlias);
192 //////////////////////////////////////////////////////////////////////////
194 void CDelHandledAIGroupImp::callback (const std::string &name, NLNET::TServiceId id)
196 CCont<CAIInstance> &instances = CAIS::instance().AIList();
198 for (uint i=0; i<instances.size(); ++i)
200 CAIInstance *aii = instances[i];
201 if (!aii)
202 continue;
204 CGroupNpc *grp = dynamic_cast<CGroupNpc*>(aii->findGroup(GroupAlias));
205 if (grp != NULL)
207 nlinfo("CDelHandledAIGroupImp on group %u user:%s miss:%d", GroupAlias, PlayerRowId.toString().c_str(), MissionAlias);
208 // ok, we found the correct group!
209 grp->delHandle(PlayerRowId, MissionAlias);
210 return;
213 // debug only : AIS can receive message for not the same AiInstance as the group
214 //nlwarning("CDelHandledAIGroupImp group alias %u : no found !", GroupAlias);