Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ai_mgr_fauna.cpp
blobb178cccff67ea3eff9faf56264747174dbcbb3f3
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_fauna.h"
19 #include "ai_grp_fauna.h"
20 #include "timer.h"
21 #include "states.h"
23 using namespace NLMISC;
24 using namespace NLNET;
25 using namespace std;
26 using namespace RYAI_MAP_CRUNCH;
27 using namespace AITYPES;
29 // Stuff used for management of log messages
30 static bool VerboseLog=false;
31 #define LOG if (!VerboseLog) {} else nlinfo
33 //////////////////////////////////////////////////////////////////////////////
34 // Local globals //
35 //////////////////////////////////////////////////////////////////////////////
37 static CAITimer VerboseMgrFaunaUpdateTimer; // for activating verbose debug info for short periods
38 static uint32 PlayersPerRegion = 0; // dummy variable for setting fake number of players per region
41 //////////////////////////////////////////////////////////////////////////////
42 // CMgrFauna //
43 //////////////////////////////////////////////////////////////////////////////
45 CMgrFauna::CMgrFauna(IManagerParent* parent, uint32 alias, std::string const& name, std::string const& filename)
46 : CManager(parent, alias, name, filename)
48 registerEvents();
51 CMgrFauna::~CMgrFauna()
53 _StateMachine.clearEventContainerContent();
54 _Groups.clear();
57 void CMgrFauna::registerEvents()
59 _StateMachine.registerEvents ();
61 _StateMachine.addEvent( "destination_reached", EventDestinationReachedFirst );
62 _StateMachine.addEvent( "destination_reached_first", EventDestinationReachedFirst );
63 _StateMachine.addEvent( "destination_reached_all", EventDestinationReachedAll );
64 _StateMachine.addEvent( "bot_killed", EventBotKilled );
65 _StateMachine.addEvent( "group_eliminated", EventGrpEliminated );
68 void CMgrFauna::init()
70 VerboseMgrFaunaUpdateTimer.set(0);
73 void CMgrFauna::update()
75 H_AUTO(MgrFaunaUpdate);
77 ++AISStat::MgrTotalUpdCtr;
78 ++AISStat::MgrFaunaUpdCtr;
80 CManager::update(); // general update call ..
83 IAliasCont* CMgrFauna::getAliasCont(TAIType type)
85 switch(type)
87 case AITypeGrp:
88 return &_Groups;
89 case AITypeEvent:
90 return &getStateMachine()->eventReactions();
91 case AITypeState:
92 return &getStateMachine()->states();
93 default:
94 return NULL;
98 CAliasTreeOwner* CMgrFauna::createChild(IAliasCont* cont, CAIAliasDescriptionNode* aliasTree)
100 CAliasTreeOwner* child = NULL;
102 switch (aliasTree->getType())
104 case AITypeGrp:
105 child = new CGrpFauna(this, aliasTree, WaterAndNogo);
106 break;
107 case AITypeEvent:
108 child = new CAIEventReaction(getStateMachine(), aliasTree);
109 break;
110 case AITypeState:
111 child = new CAIStatePositional(getStateMachine(), aliasTree);
112 break;
115 cont->addAliasChild(child);
116 return child;
119 std::string CMgrFauna::buildDebugString(uint idx)
121 switch (idx)
123 case 0:
124 return CManager::getIndexString() + " " + getFullName() + NLMISC::toString(": %-25s ",getName().c_str());
125 default:
126 break;
128 return std::string();
131 void CMgrFauna::display(CStringWriter& stringWriter)
133 stringWriter.append(getFullName());
136 std::string CMgrFauna::getOneLineInfoString() const
138 return std::string("Fauna manager '") + getName() + "'";
141 //----------------------------------------------------------------------------
142 // Admin commands and variables
143 NLMISC_DYNVARIABLE(uint32, VerboseMgrUpdate, "Dump update priority heaps and lists of groups updated for next <n> ticks")
145 if (get)
146 *pointer = VerboseMgrFaunaUpdateTimer.timeRemaining();
147 else
148 VerboseMgrFaunaUpdateTimer.set(*pointer);
151 NLMISC_DYNVARIABLE(uint32, SimPlayersPerRegion, "Dump update priority heaps and lists of groups updated for next <n> ticks")
153 if (get)
154 *pointer = PlayersPerRegion;
155 else
156 PlayersPerRegion = *pointer;
159 //----------------------------------------------------------------------------
160 // Control over verbose nature of logging
161 NLMISC_COMMAND(verboseFaunaMgrLog,"Turn on or off or check the state of verbose manager activity logging","")
163 if(args.size()>1)
164 return false;
166 if(args.size()==1)
167 StrToBool (VerboseLog, args[0]);
169 nlinfo("verboseLogging is %s",VerboseLog?"ON":"OFF");
170 return true;