Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_mgr_npc.cpp
blob5d2f381c089f1cefdd78b5899e529ed6b65d1641
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_mgr_npc.h"
19 #include "ai_grp_npc.h"
20 #include "states.h"
21 #include "game_share/base_types.h"
22 #include "npc_description_msg.h"
24 using namespace NLMISC;
25 using namespace NLNET;
26 using namespace std;
27 using namespace RYAI_MAP_CRUNCH;
28 using namespace AITYPES;
30 // Stuff used for management of log messages
31 static bool VerboseLog=false;
32 #define LOG if (!VerboseLog) {} else nlinfo
34 //////////////////////////////////////////////////////////////////////////////
35 // CMgrNpc //
36 //////////////////////////////////////////////////////////////////////////////
38 // instantiate the bot population
39 void CMgrNpc::spawn()
41 nlinfo("--------------- spawn Npc manager: %s ----------------", getName().c_str() );
42 CManager::spawn();
44 // inform the EGS of our existence - simulate connection of EGS
45 if (EGSHasMirrorReady)
46 serviceEvent(CServiceEvent(TServiceId(0), std::string("EGS"), CServiceEvent::SERVICE_UP));
49 // clear the bot population
50 void CMgrNpc::despawnMgr()
52 nlinfo("-------------- despawn manager: %s --------------- ", getName().c_str());
53 CManager::despawnMgr();
56 IAliasCont* CMgrNpc::getAliasCont(TAIType type)
58 switch (type)
60 case AITypeNoGo: // not implemented.
61 return NULL;
62 case AITypeGrp:
63 return &_Groups;
64 case AITypeNpcStateRoute:
65 case AITypeNpcStateZone:
66 case AITypePunctualState:
67 case AITypeKamiDeposit:
68 case AITypeKaravanState:
69 case AITypeState:
70 return &getStateMachine()->states();
71 case AITypeEvent:
72 return &getStateMachine()->eventReactions();
73 case AITypeFolder:
74 default:
75 return NULL;
79 CAliasTreeOwner* CMgrNpc::createChild(IAliasCont* cont, CAIAliasDescriptionNode* aliasTree)
81 CAliasTreeOwner* child = NULL;
83 switch (aliasTree->getType())
85 case AITypeGrp:
86 child = new CGroupNpc(this, aliasTree, Nothing);
87 break;
88 case AITypeNpcStateRoute:
89 case AITypeNpcStateZone:
90 case AITypeKamiDeposit:
91 case AITypeKaravanState:
92 case AITypeState:
93 child = new CAIStatePositional(getStateMachine(), aliasTree);
94 break;
95 case AITypePunctualState:
96 child = new CAIStatePunctual(getStateMachine(), aliasTree);
97 break;
98 case AITypeEvent:
99 child = new CAIEventReaction(getStateMachine(), aliasTree);
100 break;
101 case AITypeNoGo:
102 case AITypeFolder:
103 break;
105 if (child)
106 cont->addAliasChild(child);
107 return child;
110 std::string CMgrNpc::getOneLineInfoString() const
112 return std::string("NPC manager '") + getName() + "'";
115 CMgrNpc::CMgrNpc(IManagerParent* parent, uint32 alias, std::string const& name, std::string const& filename)
116 : CManager(parent, alias, name, filename)
118 registerEvents();
121 CMgrNpc::~CMgrNpc()
123 _StateMachine.clearEventContainerContent();
124 _Groups.clear();
127 void CMgrNpc::update()
129 ++AISStat::MgrTotalUpdCtr;
130 ++AISStat::MgrNpcUpdCtr;
131 CManager::update();
134 void CMgrNpc::registerEvents()
136 _StateMachine.registerEvents();
138 _StateMachine.addEvent( "destination_reached", EventDestinationReachedFirst );
139 _StateMachine.addEvent( "destination_reached_first", EventDestinationReachedFirst );
140 _StateMachine.addEvent( "destination_reached_all", EventDestinationReachedAll );
141 _StateMachine.addEvent( "bot_killed", EventBotKilled );
142 _StateMachine.addEvent( "squad_leader_killed", EventSquadLeaderKilled );
143 _StateMachine.addEvent( "group_eliminated", EventGrpEliminated );
146 std::vector<std::string> CMgrNpc::getMultiLineInfoString() const
148 using namespace MULTI_LINE_FORMATER;
149 std::vector<std::string> container;
150 std::vector<std::string> strings;
153 pushTitle(container, "CMgrNpc");
154 strings = CManager::getMultiLineInfoString();
155 FOREACHC(itString, std::vector<std::string>, strings)
156 pushEntry(container, *itString);
157 // pushEntry(container, "state machine:");
158 strings = _StateMachine.getMultiLineInfoString();
159 FOREACHC(itString, std::vector<std::string>, strings)
160 pushEntry(container, *itString);
161 pushFooter(container);
164 return container;
167 // :KLUDGE: This method should be in event_reaction_container.cpp that doesn't exist
168 std::vector<std::string> CStateMachine::getMultiLineInfoString() const
170 using namespace MULTI_LINE_FORMATER;
171 std::vector<std::string> container;
174 pushTitle(container, "CStateMachine");
175 pushEntry(container, "States:");
176 FOREACHC(itState, CCont<CAIState>, _states)
177 pushEntry(container, " - "+itState->getName());
178 pushFooter(container);
181 return container;