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_npc.h"
19 #include "ai_grp_npc.h"
21 #include "game_share/base_types.h"
22 #include "npc_description_msg.h"
24 using namespace NLMISC
;
25 using namespace NLNET
;
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 //////////////////////////////////////////////////////////////////////////////
36 //////////////////////////////////////////////////////////////////////////////
38 // instantiate the bot population
41 nlinfo("--------------- spawn Npc manager: %s ----------------", getName().c_str() );
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
)
60 case AITypeNoGo
: // not implemented.
64 case AITypeNpcStateRoute
:
65 case AITypeNpcStateZone
:
66 case AITypePunctualState
:
67 case AITypeKamiDeposit
:
68 case AITypeKaravanState
:
70 return &getStateMachine()->states();
72 return &getStateMachine()->eventReactions();
79 CAliasTreeOwner
* CMgrNpc::createChild(IAliasCont
* cont
, CAIAliasDescriptionNode
* aliasTree
)
81 CAliasTreeOwner
* child
= NULL
;
83 switch (aliasTree
->getType())
86 child
= new CGroupNpc(this, aliasTree
, Nothing
);
88 case AITypeNpcStateRoute
:
89 case AITypeNpcStateZone
:
90 case AITypeKamiDeposit
:
91 case AITypeKaravanState
:
93 child
= new CAIStatePositional(getStateMachine(), aliasTree
);
95 case AITypePunctualState
:
96 child
= new CAIStatePunctual(getStateMachine(), aliasTree
);
99 child
= new CAIEventReaction(getStateMachine(), aliasTree
);
106 cont
->addAliasChild(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
)
123 _StateMachine
.clearEventContainerContent();
127 void CMgrNpc::update()
129 ++AISStat::MgrTotalUpdCtr
;
130 ++AISStat::MgrNpcUpdCtr
;
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
);
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
);