本文整理汇总了C++中P_NPC::ai方法的典型用法代码示例。如果您正苦于以下问题:C++ P_NPC::ai方法的具体用法?C++ P_NPC::ai怎么用?C++ P_NPC::ai使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类P_NPC
的用法示例。
在下文中一共展示了P_NPC::ai方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: response
/////////////////
// name: response
// purpose: tries to get a response from an npc standing around
// history: heavily revamped/rewritten by Duke, Oct 2001
// remark: The new logic tries to minimize the # of strstr() calls by *first* checking
// what kind of npcs are standing around and then checking only those keywords
// that they might be interested in.
// This is especially usefull in crowded places.
bool Speech::response( cUOSocket* socket, P_PLAYER pPlayer, const QString& comm, QValueVector<Q_UINT16>& keywords )
{
if ( !pPlayer->socket() || pPlayer->isDead() )
{
return false;
}
QString speechUpr = comm.upper();
MapCharsIterator ri = MapObjects::instance()->listCharsInCircle( pPlayer->pos(), 18 );
for ( P_CHAR pChar = ri.first(); pChar; pChar = ri.next() )
{
P_NPC pNpc = dynamic_cast<P_NPC>( pChar );
// We will only process NPCs here
if ( !pNpc )
continue;
// at least they should be on the screen
if ( pPlayer->dist( pNpc ) > 16 )
continue;
if ( pNpc->canHandleEvent( EVENT_SPEECH ) )
{
PyObject* pkeywords = PyTuple_New( keywords.size() );
// Set Items
for ( unsigned int i = 0; i < keywords.size(); ++i )
PyTuple_SetItem( pkeywords, i, PyInt_FromLong( keywords[i] ) );
PyObject* args = Py_BuildValue( "(NNNO)", pNpc->getPyObject(), pPlayer->getPyObject(), QString2Python( comm ), pkeywords );
bool result = pNpc->callEventHandler( EVENT_SPEECH, args );
Py_DECREF( args );
Py_DECREF( pkeywords );
if ( result )
return true;
}
if ( pNpc->ai() )
{
pNpc->ai()->onSpeechInput( pPlayer, speechUpr );
}
if ( QuestionSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
}
return false;
}
示例2: checkScriptAI
void cAIFactory::checkScriptAI( const QStringList& oldSections, const QStringList& newSections )
{
QStringList::const_iterator aiit = oldSections.begin();
for ( ; aiit != oldSections.end(); ++aiit )
{
// We must reset all existing and scripted AI objects, so changes can take effect.
if ( !newSections.contains( *aiit ) )
{
cCharIterator iter;
for ( P_CHAR pChar = iter.first(); pChar; pChar = iter.next() )
{
P_NPC pNPC = dynamic_cast<P_NPC>( pChar );
if ( pNPC )
{
ScriptAI* ai = dynamic_cast<ScriptAI*>( pNPC->ai() );
if ( ai && ai->name() == ( *aiit ) )
{
pNPC->setAI( *aiit );
}
}
}
}
else
{
cCharIterator iter;
for ( P_CHAR pChar = iter.first(); pChar; pChar = iter.next() )
{
P_NPC pNPC = dynamic_cast<P_NPC>( pChar );
if ( pNPC )
{
ScriptAI* ai = dynamic_cast<ScriptAI*>( pNPC->ai() );
if ( ai && ai->name() == ( *aiit ) )
{
delete ai;
pNPC->setAI( NULL );
}
}
}
unregisterType( *aiit );
}
}
aiit = newSections.begin();
while ( aiit != newSections.end() )
{
if ( !oldSections.contains( *aiit ) )
{
ScriptAI::registerInFactory( *aiit );
}
++aiit;
}
}
示例3: response
/////////////////
// name: response
// purpose: tries to get a response from an npc standing around
// history: heavily revamped/rewritten by Duke, Oct 2001
// remark: The new logic tries to minimize the # of strstr() calls by *first* checking
// what kind of npcs are standing around and then checking only those keywords
// that they might be interested in.
// This is especially usefull in crowded places.
bool cSpeech::response( cUOSocket *socket, P_PLAYER pPlayer, const QString& comm, QValueVector< UINT16 > &keywords )
{
if( !pPlayer->socket() || pPlayer->isDead() )
return false;
QString speechUpr = comm.upper();
RegionIterator4Chars ri( pPlayer->pos() );
for( ri.Begin(); !ri.atEnd(); ri++ )
{
P_NPC pNpc = dynamic_cast<P_NPC>(ri.GetData());
// We will only process NPCs here
if( !pNpc )
continue;
// at least they should be on the screen
if( pPlayer->dist( pNpc ) > 16 )
continue;
// Check if the NPC has a script that can handle
// speech events and then check if it can handle everything
// or just certain things
std::vector< WPDefaultScript* > events = pNpc->getEvents();
for( std::vector< WPDefaultScript* >::const_iterator iter = events.begin(); iter != events.end(); ++iter )
{
WPDefaultScript *script = *iter;
if( !script->handleSpeech() )
continue;
if( script->catchAllSpeech() || script->canHandleSpeech( comm, keywords ) )
if( script->onSpeech( pNpc, pPlayer, comm, keywords ) )
return true;
}
cNPC_AI* pAI = pNpc->ai();
if( pAI && pAI->currState() )
{
pAI->currState()->speechInput( pPlayer, speechUpr );
pAI->updateState();
}
if( BankerSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( PetCommand( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( StableSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( UnStableSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( ShieldSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( QuestionSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( TrainerSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
if( PlayerVendorSpeech( socket, pPlayer, pNpc, speechUpr ) )
return true;
}
return false;
}