@ -52,7 +52,7 @@ namespace
return lowerCase ;
}
bool stringCompareNoCase ( std : : string first , std : : string second )
bool stringCompareNoCase ( const std : : string & first , const std : : string & second )
{
unsigned int i = 0 ;
while ( ( i < first . length ( ) ) & & ( i < second . length ( ) ) )
@ -76,11 +76,12 @@ namespace
namespace MWDialogue
{
DialogueManager : : DialogueManager ( const Compiler : : Extensions & extensions , bool scriptVerbose ) :
DialogueManager : : DialogueManager ( const Compiler : : Extensions & extensions , bool scriptVerbose , Translation : : Storage & translationDataStorage ) :
mCompilerContext ( MWScript : : CompilerContext : : Type_Dialgoue ) ,
mErrorStream ( std : : cout . rdbuf ( ) ) , mErrorHandler ( mErrorStream )
, mTemporaryDispositionChange ( 0.f )
, mPermanentDispositionChange ( 0.f ) , mScriptVerbose ( scriptVerbose )
, mTranslationDataStorage ( translationDataStorage )
{
mChoice = - 1 ;
mIsInChoice = false ;
@ -104,16 +105,45 @@ namespace MWDialogue
}
void DialogueManager : : parseText ( const std : : string & text )
{
std : : vector < HyperTextToken > hypertext = ParseHyperText ( text ) ;
//calculation of standard form fir all hyperlinks
for ( size_t i = 0 ; i < hypertext . size ( ) ; + + i )
{
if ( hypertext [ i ] . mLink )
{
size_t asterisk_count = MWDialogue : : RemovePseudoAsterisks ( hypertext [ i ] . mText ) ;
for ( ; asterisk_count > 0 ; - - asterisk_count )
hypertext [ i ] . mText . append ( " * " ) ;
hypertext [ i ] . mText = mTranslationDataStorage . topicStandardForm ( hypertext [ i ] . mText ) ;
}
}
for ( size_t i = 0 ; i < hypertext . size ( ) ; + + i )
{
std : : list < std : : string > : : iterator it ;
for ( it = mActorKnownTopics . begin ( ) ; it ! = mActorKnownTopics . end ( ) ; + + it )
for ( it = mActorKnownTopics . begin ( ) ; it ! = mActorKnownTopics . end ( ) ; + + it )
{
if ( hypertext [ i ] . mLink )
{
if ( hypertext [ i ] . mText = = * it )
{
mKnownTopics [ hypertext [ i ] . mText ] = true ;
}
}
else if ( ! mTranslationDataStorage . hasTranslation ( ) )
{
size_t pos = find_str_ci ( text , * it , 0 ) ;
size_t pos = find_str_ci ( hyper text[i ] . mText , * it , 0 ) ;
if ( pos ! = std : : string : : npos )
{
mKnownTopics [ * it ] = true ;
}
}
}
}
updateTopics ( ) ;
}
@ -298,7 +328,7 @@ namespace MWDialogue
{
if ( filter . search ( * iter ) )
{
mActorKnownTopics . push_back ( toLower ( iter - > mId ) ) ;
mActorKnownTopics . push_back ( toLower ( iter - > mId ) ) ;
//does the player know the topic?
if ( mKnownTopics . find ( toLower ( iter - > mId ) ) ! = mKnownTopics . end ( ) )
@ -499,4 +529,57 @@ namespace MWDialogue
{
mTemporaryDispositionChange + = delta ;
}
std : : vector < HyperTextToken > ParseHyperText ( const std : : string & text )
{
std : : vector < HyperTextToken > result ;
MyGUI : : UString utext ( text ) ;
size_t pos_begin , pos_end , iteration_pos = 0 ;
for ( ; ; )
{
pos_begin = utext . find ( ' @ ' , iteration_pos ) ;
if ( pos_begin ! = std : : string : : npos )
pos_end = utext . find ( ' # ' , pos_begin ) ;
if ( pos_begin ! = std : : string : : npos & & pos_end ! = std : : string : : npos )
{
result . push_back ( HyperTextToken ( utext . substr ( iteration_pos , pos_begin - iteration_pos ) , false ) ) ;
std : : string link = utext . substr ( pos_begin + 1 , pos_end - pos_begin - 1 ) ;
result . push_back ( HyperTextToken ( link , true ) ) ;
iteration_pos = pos_end + 1 ;
}
else
{
result . push_back ( HyperTextToken ( utext . substr ( iteration_pos ) , false ) ) ;
break ;
}
}
return result ;
}
size_t RemovePseudoAsterisks ( std : : string & phrase )
{
size_t pseudoAsterisksCount = 0 ;
const char specialPseudoAsteriskCharacter = 127 ;
if ( ! phrase . empty ( ) )
{
std : : string : : reverse_iterator rit = phrase . rbegin ( ) ;
while ( rit ! = phrase . rend ( ) & & * rit = = specialPseudoAsteriskCharacter )
{
pseudoAsterisksCount + + ;
+ + rit ;
}
}
phrase = phrase . substr ( 0 , phrase . length ( ) - pseudoAsterisksCount ) ;
return pseudoAsterisksCount ;
}
}