Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

U2Dialog.DialogTrigger


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
//=============================================================================
// DialogTrigger.uc
// Created By: Mike Baldwin
// Created On: 3/29/2001
// $Author: Mbaldwin $
// $Date: 12/17/02 1:10p $
// $Revision: 12 $
//=============================================================================

class DialogTrigger extends Trigger;

/*
When Actors come into range of the trigger, the Participants list is evaluated
against the current Actors list.  If the list is matched, then the
DialogList[] is processed in order to invoke a dialog session for the specified
participants (involuntary participants are also added by the dialog system due
to "Proximity" -- but they may be dropped if none of the trees contain dialog
for them).

When the trigger is triggered, the "bEnabled" status for each entry in the
DialogList[] is re-evaluated based on LastDialogTime and the Delay. 
(bEnabled=true nodes are automatically skipped).

If one or more trees are found to be "enabled", a dialog session is created, and
the selected tree is added to that session.

When the session is concluded, the LastDialogTime is updated, and the bEnabled
flags are adjusted according corresponding value of the bLeaveEnabled flags.
*/

struct DialogListT
{
	var() name Topic;					// dialog tree topic
	var() float Delay;					// time to wait before "enabling" the next entry in the list
	var() bool bEnabled;				// available for characters to speak
	var() bool bLeaveEnabled;			// after delivery -- normally false
};

var() array<DialogListT> DialogList;	// list of Dialogs Trees to trigger for these participants
var() array<string> Participants;		// speaker strings of characters that must be present
var() bool bEnforceTalkRadius;			// Actors leaving dialog trigger radius will be removed from dialog

var array<Actor> ActorsInRange;			// references to the actors that are within trigger radius
var float LastDialogTime;				// tracks the the time that the previous dialog ended in order to determine when the next "Delay" will allow delivery of successive nodes
var int iCurrent;						// current tree
var bool bIsInSession;					// dialog session is currently active


//------------------------------------------------------------------------------
// Triggers Interface
//
event Touch( Actor Other )
{
	if( Other.Speaker != "" )
	{
		Add( Other );
		if( !bIsInSession )
			StartSession();
	}
}

//-----------------------------------------------------------------------------

event UnTouch( Actor Other )
{
	if( bEnforceTalkRadius )
	{
		Remove(Other);
		if( bIsInSession )
			class'DialogEngine'.static.NotifyDialogWalkedAway( Other );
	}
}

//------------------------------------------------------------------------------
// Init
//
event PostBeginPlay()
{
	Super.PostBeginPlay();
	GetTouchingActors();
}

//------------------------------------------------------------------------------
// Add/Remove Participants
//
function Add( Actor NewActor )
{
	local int i;
	for( i=0; i < Participants.Length; i++ )
		if( Participants[i] == NewActor.Speaker )
			ActorsInRange[i] = NewActor;
}

//------------------------------------------------------------------------------

function Remove( Actor OldActor )
{
	local int i;
	for( i=0; i < ActorsInRange.Length; i++ )
		if( ActorsInRange[i] == OldActor )
			ActorsInRange[i] = None;
}

//------------------------------------------------------------------------------

function Clear()
{
	local int i;
	for( i=0; i < ActorsInRange.Length; i++ )
		ActorsInRange[i] = None;
}

//------------------------------------------------------------------------------
// Start/End dialog
//
function StartSession()
{
	// verify that all participants are in trigger radius and, if so, initiate dialog
	if( !bIsInSession && AllCanTalk() && SelectTopic() )
	{
		if( class'DialogEngine'.static.GetInstance(Self).InitiateTrigger(Self) )
			bIsInSession = true;
		else
		{
			// Dialog engine couldn't open a dialog session, disable this topic
			DialogList[iCurrent].bEnabled = false;
			DialogList[iCurrent].bLeaveEnabled = false;
		}
	}
}

//------------------------------------------------------------------------------

function SessionFinished()
{
	// Leave Enabled/Disable for next time
	if( DialogList[iCurrent].bLeaveEnabled == false )
		DialogList[iCurrent].bEnabled = false;

	// Cache the current time
	LastDialogTime = Level.TimeSeconds;

	// Resync with actors within radius (in case radius wasn't enforced during dialog)
	GetTouchingActors();

	// Triggered session is over
	bIsInSession = false;
}

//------------------------------------------------------------------------------
// Participant Helpers
//
function GetTouchingActors()
{
	local Actor A;
	
	Clear();

	ForEach TouchingActors( class'Actor', A )
		if( A.Speaker != "" )
			Add( A );
}

//------------------------------------------------------------------------------
// Verify that each participants actor is within the trigger and they can talk
//
function bool AllCanTalk()
{
	local int i;
	for( i=0; i < Participants.Length; i++ )
		if( i >= ActorsInRange.Length ||			// actor is not in the radius
			!CanTalk( ActorsInRange[i] ) )			// actor can't talk right now
			return false;
	return true;
}

//------------------------------------------------------------------------------

function bool CanTalk( Actor Who )
{
	local int i;

	if( Who == None ) return false;
	if( Who.Speaker == "Player" ) return true;

	// mib-tbd Can he be used by all the others?
	for( i=0; i < ActorsInRange.Length; i++ )
		if( ActorsInRange[i] != None &&
			ActorsInRange[i] != Who &&
			!ActorsInRange[i].IsUsable( Who ) )
			return false;

	return true;
}

//------------------------------------------------------------------------------
// Topic Helpers
//
function name CurrentTopic()
{
	return DialogList[iCurrent].Topic;
}

//------------------------------------------------------------------------------
	
function bool SelectTopic()
{
	local int i;

	// search from starting point to end of list
	for( i = iCurrent+1; i < DialogList.Length; i++ )
		if( CheckTopic( i ) ) { iCurrent = i;  return true; }

	// search begining of list to starting point
	for( i=0; i <= iCurrent; i++ )
		if( CheckTopic( i ) ) { iCurrent = i;  return true; }

	// no topics available not even the previously current one.
	// MIB - tbr
	//DMDLG(Self @ "couldn't find an enabled topic" );
	return false;
}

//------------------------------------------------------------------------------

function bool CheckTopic( int Which )
{
	// Check topic, enabled, and delay time
	if( DialogList[Which].Topic != ''	&&
		DialogList[Which].bEnabled		&&
		DialogList[Which].Delay < Level.TimeSeconds - LastDialogTime )
		return true;

	return false;
}

//------------------------------------------------------------------------------

defaultproperties
{
	iCurrent=-1
	TriggerType=TT_AnyProximity
     UseReticleOnEvents(0)="UseReticleText"
     UseReticleOnEvents(1)="UseReticleCorners"
     UseReticleOnEvents(2)="UseReticleTopBars"
     ProximityReticleOnEvents(0)="ProximityReticleCorners"
     ProximityReticleOnEvents(1)="ProximityReticleTopBars"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: sk 3-1-2016 10:38:42.000 - Creation time: sk 3-1-2016 10:48:38.199 - Created with UnCodeX