1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
18 #include "ai_mgr_fauna.h"
19 #include "ai_grp_fauna.h"
23 using namespace NLMISC
;
24 using namespace NLNET
;
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 //////////////////////////////////////////////////////////////////////////////
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 //////////////////////////////////////////////////////////////////////////////
43 //////////////////////////////////////////////////////////////////////////////
45 CMgrFauna::CMgrFauna(IManagerParent
* parent
, uint32 alias
, std::string
const& name
, std::string
const& filename
)
46 : CManager(parent
, alias
, name
, filename
)
51 CMgrFauna::~CMgrFauna()
53 _StateMachine
.clearEventContainerContent();
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
)
90 return &getStateMachine()->eventReactions();
92 return &getStateMachine()->states();
98 CAliasTreeOwner
* CMgrFauna::createChild(IAliasCont
* cont
, CAIAliasDescriptionNode
* aliasTree
)
100 CAliasTreeOwner
* child
= NULL
;
102 switch (aliasTree
->getType())
105 child
= new CGrpFauna(this, aliasTree
, WaterAndNogo
);
108 child
= new CAIEventReaction(getStateMachine(), aliasTree
);
111 child
= new CAIStatePositional(getStateMachine(), aliasTree
);
115 cont
->addAliasChild(child
);
119 std::string
CMgrFauna::buildDebugString(uint idx
)
124 return CManager::getIndexString() + " " + getFullName() + NLMISC::toString(": %-25s ",getName().c_str());
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")
146 *pointer
= VerboseMgrFaunaUpdateTimer
.timeRemaining();
148 VerboseMgrFaunaUpdateTimer
.set(*pointer
);
151 NLMISC_DYNVARIABLE(uint32
, SimPlayersPerRegion
, "Dump update priority heaps and lists of groups updated for next <n> ticks")
154 *pointer
= PlayersPerRegion
;
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","")
167 StrToBool (VerboseLog
, args
[0]);
169 nlinfo("verboseLogging is %s",VerboseLog
?"ON":"OFF");