Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
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 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 |
//============================================================================= // DialogNode.uc // Created By: Mike Baldwin // Created On: 2/27/2001 // $Author: Mbaldwin $ // $Date: 12/17/02 1:02p $ // $Revision: 47 $ //============================================================================= class DialogNode extends Dialog native; //----------------------------------------------------------------------------- const DefaultTalkingSpeed = 25.0; // default talking speed in characters/second const MinAudioLength = 2.0; // minimum audio length (no sound file) //----------------------------------------------------------------------------- // Mood adjustments based on dialog struct native MoodChangeInfo { var name Who; // who needs an attitude adjustment var float Amount; // how much to change the mood by }; // Events triggered during a dialog node struct native NodeEventInfo { var name EventName; // name of event to trigger var name Target; // optional target to dispatch event explicitly (speaker string converted to a name) var float PercentDelay; // percent of the audio file duration to wait before triggering the event var byte bPending; // this event is waiting to be dispatched? }; // Animations to play struct native AnimInfo { var name AnimName; // name of animation to play var name Target; // optional actor name that will do the animating var float PercentDelay; // percent of the audio file duration to wait before playing the animation var byte bPending; // this animation is waiting to be played? }; // (Head)Tracking Satellite struct native SatelliteInfo { var name Target; // actor name to track as a satellite var name Tracker; // actor doing the tracking var float PercentDelay; // percent of the audio file duration to wait before triggering the event var byte bPending; // this event is waiting to be dispatched? }; // Pausing NPC's AI Scripting struct native NPCControlInfo { var byte bPauseNPC; // whether to pause or unpause npc's ai scripting var name Target; // speaker string of the npc var float PercentDelay; // percent of the audio file duration to wait before pausing/unpausing npc var byte bPending; // this control is waiting to be excuted? }; // facial animation / hand waving etc. struct native GestureInfo { var byte bUseGestures; // whether to turn gestures on or off var name Target; // speaker string of the npc var float PercentDelay; // percent of the audio file duration to wait before turn gestures on/off var byte bPending; // this gesture change is waiting to be used? }; //----------------------------------------------------------------------------- var DialogTree Tree; // the dialog tree that this node belongs to var string ShortText; // brief summary of dialog (for UI) var string LongText; // text version of dialog (word-for-word) var string Filename; // filename of audio file var bool bUseOggVoice; // .Ogg filename exists and is being used var string Speaker; // the speaker string of who can say this dialog var transient sound Voice; // sound file for this dialog node var float PreDelay; // time (secs) to wait since someone finished speaking before we can say this node var float PostDelay; // time (secs) to wait before allowing others to speak var array<DialogNode> NextNodes; // nodes to branch from this one var array<AnimInfo> NodeAnims; // animations to play during the dialog var array<NodeEventInfo> NodeEvents; // events to be triggered when this node gets spoken var array<ExitEventInfo> ExitEvents; // events to be triggered at the end of the dialog session var int Priority; // 0=Casual Chit-Chat ------> big numbers Important Command var int SpokenCount; // number of times someone said this line var int SpokenMax; // max times we're allowed to say this line var float Mood; // mood of audio (-1 hostile --- 0 neutral --- +1 friendly) var byte Attitude; // attitude toward player var array<MoodChangeInfo> MoodChanges; // Relative change to current mood. var EDialogTone Tone; // Casual, Formal, Command (see ETone in Dialog.uc) var EDialogTone ToneChange; // Tone to set for subsequent nodes (affects DialogSession.Tone) var float AudioDuration; // (for debug use only) useful to tweak timing if the audio file isn't handy var bool bEnabled; // can we speak this node? var bool bDoLipSync; // should the speaker lip sync with the audio? var bool bHideChoices; // don't display this node choice to the HUD (for player nodes only) var EDialogBoolean TurnToSpeaker; // should we turn to the other speaker? var array<NodeEnableInfo> NodeEnables; // nodes to en/disable var float TalkRadius; // distance speaker must maintain to center of conversation var EDialogBoolean UseBookmark; // reset bookmark when the session is over var array<GestureInfo> Gestures; // use dialog-related animations (talking, listening) var array<SatelliteInfo> Satellites; // head tracking satellites var array<NPCControlInfo> NPCControls; // pause/unpause npc's ai scripting var array<AbortMapT> AbortMap; // how to handling when a speaker aborts the conversation var array<ResumeMapT> ResumeMap; // how to resume from the previous dialog with certain speakers var string EndingFocus; // target actor to look at when dialog is over var array<string> SoundSourceActors; // actor to play voice audio from (defaults to speaker actor) var float SoundRadius; // sound radius to pass on to PlaySound / PlayVoice var float Volume; // volume to pass on to PlaySound / PlayVoice var float SubtitleRadius; // if player is within this radius node's subtitles will be displayed (3rd party conversations) //----------------------------------------------------------------------------- var private const native noexport int Condition; // DialogCondition* (expression indicating when this node is valid) //----------------------------------------------------------------------------- native function bool IsValid( optional DialogSession Session, optional bool bIgnoreSpokenCount ); //----------------------------------------------------------------------------- function float GetAudioLength() { local float Result; local SceneManager SM; local DialogEngine DE; if( Voice != None ) { //DMDLG("GetAudioLen - voice:" @ GetSoundDuration( Voice ) ); Result = GetSoundDuration( Voice ); } else if( AudioDuration > 0 ) { //DMDLG("GetAudioLen - audio duration:" @ AudioDuration ); Result = AudioDuration; } else if( LongText != "" ) { //DMDLG("GetAudioLen - guess:" @ Len(LongText) / DefaultTalkingSpeed ); Result = Max( MinAudioLength, (Len(LongText) / DefaultTalkingSpeed) ); } else { //DMDLG("GetAudioLen - empty node"); Result = 0.0; } DE = class'DialogEngine'.static.GetInstance(Self); if( !DE.AllowSlomo ) { // compensate for matinee sped-up / slowed-down cutscenes if( class'UtilGame'.static.CutSceneIsRunning( Self ) ) { //DMDLG("Scale Audio length for" @ LongText @ "by:" @ Level.TimeDilation ); Result = Result * Level.TimeDilation; } } return Result; } //----------------------------------------------------------------------------- function MakeAllPending() { local int i; for( i=0; i < NodeEvents.Length; i++ ) NodeEvents[i].bPending = 1; for( i=0; i < NodeAnims.Length; i++ ) NodeAnims[i].bPending = 1; for( i=0; i < NPCControls.Length; i++ ) NPCControls[i].bPending = 1; for( i=0; i < Satellites.Length; i++ ) Satellites[i].bPending = 1; for( i=0; i < Gestures.Length; i++ ) Gestures[i].bPending = 1; } //----------------------------------------------------------------------------- function ProcessActions( DialogSession S ) { SendNodeEvents( S ); PlayNodeAnims( S ); ProcessNPCControls( S ); TrackSatellites( S ); SetGestures( S ); } //----------------------------------------------------------------------------- function SendNodeEvents( DialogSession S ) { local int i; local Actor TargetActor; for( i=0; i < NodeEvents.Length; i++ ) if( NodeEvents[i].bPending != 0 && PctDelayExpired( NodeEvents[i].PercentDelay, S ) ) { if( NodeEvents[i].Target != '' ) { TargetActor = class'DialogEngine'.static.NameToActor( Self, NodeEvents[i].Target ); if( TargetActor != None ) { class'TriggerHelper'.static.DispatchTrigger( Self, TargetActor, Self, None, NodeEvents[i].EventName ); DMDLG("Sending Event" @ NodeEvents[i].EventName @ "to" @ NodeEvents[i].Target); } else DMDLG("Can't send event" @ NodeEvents[i].EventName @ " -- unable to find actor for target:" @ NodeEvents[i].Target); } else { TriggerEvent( NodeEvents[i].EventName, Self, None ); DMDLG("Sending General Event" @ NodeEvents[i].EventName ); } NodeEvents[i].bPending = 0; } } //----------------------------------------------------------------------------- function PlayNodeAnims( DialogSession S ) { local int i; local actor TargetActor; for( i=0; i < NodeAnims.Length; i++ ) if( NodeAnims[i].bPending != 0 && PctDelayExpired( NodeAnims[i].PercentDelay, S ) ) { if( NodeAnims[i].Target != '' ) TargetActor = class'DialogEngine'.static.NameToActor(Self, NodeAnims[i].Target); else TargetActor = class'DialogEngine'.static.StringToActor(Self, Speaker); if( TargetActor.MeshAgentGetChannelCount() > 0 ) TargetActor.MeshAgentCallAction( NodeAnims[i].AnimName ); else TargetActor.PlayAnim( NodeAnims[i].AnimName ); DMDLG( TargetActor $ "(" $ Speaker $ ") is now playing animation " @ NodeAnims[i].AnimName ); NodeAnims[i].bPending = 0; } } //----------------------------------------------------------------------------- function TrackSatellites( DialogSession S ) { local int i; local DialogController TrackingDC; local actor TargetActor; for( i=0; i < Satellites.Length; i++ ) { if( Satellites[i].bPending != 0 && PctDelayExpired( Satellites[i].PercentDelay, S ) ) { DMDLG("Satellite[" $ i $ "] -- tracker:" @ Satellites[i].Tracker @ "target:" @ Satellites[i].Target ); // if the tracker is not specified, use the current speaker if( Satellites[i].Tracker != '' ) TrackingDC = class'DialogEngine'.static.NameToDC( Self, Satellites[i].Tracker ); else TrackingDC = class'DialogEngine'.static.StringToDC( Self, Speaker ); // Hack: if tracker and target are the same and non-None ==> default headtracking if( Satellites[i].Tracker == Satellites[i].Target ) { TrackingDC.EnableHeadTracking( TrackingDC.OtherParticipant ); DMDLG("Actor" @ TrackingDC.Actor @ "is now tracking(default other)" @ TrackingDC.OtherParticipant ); } // target specified ==> track it else if( Satellites[i].Target != '' ) { TargetActor = class'UtilGame'.static.GetNamedActor( Self, Satellites[i].Target ); TrackingDC.EnableHeadTracking( TargetActor ); DMDLG("Actor" @ TrackingDC.Actor @ "is now tracking" @ TargetActor ); } // no target ==> turn off headtracking else { TrackingDC.DisableHeadTracking(); DMDLG("Actor" @ TrackingDC.Actor @ "has disabled head tracking"); } Satellites[i].bPending = 0; } } } //----------------------------------------------------------------------------- function SetGestures( DialogSession S ) { local int i; local DialogController DC; for( i=0; i < Gestures.Length; i++ ) if( Gestures[i].bPending != 0 && PctDelayExpired( Gestures[i].PercentDelay, S ) ) { if( Gestures[i].Target != '' ) DC = class'DialogEngine'.static.NameToDC(Self, Gestures[i].Target); else DC = class'DialogEngine'.static.StringToDC(Self, Speaker); if( DialogControllerDefault(DC) != None ) DialogControllerDefault(DC).bUseGestures = bool(Gestures[i].bUseGestures); if( Gestures[i].bUseGestures != 0 ) DMDLG( DC.DCSpeaker @ "is using gestures" ); else DMDLG( DC.DCSpeaker @ "is NOT using gestures" ); } } //----------------------------------------------------------------------------- function SetEndingFocus() { local actor SpeakingActor; local actor FocusActor; // if property is not set in the dialog node, don't change the npc's cached focus if( EndingFocus != "" ) { SpeakingActor = class'DialogEngine'.static.StringToActor(Self, Speaker); if( SpeakingActor != None ) { // None means clear out the ending focus if( EndingFocus != "None" ) { FocusActor = class'UtilGame'.static.GetNamedActor(Self, StringToName(EndingFocus)); if( EndingFocus != "" && FocusActor == None ) DMDLG("Warning: SetEndingFocus -- unable to find focus actor" @ EndingFocus ); } DMDLG("SettingEndingFocus:" @ EndingFocus @ "Actor:" @ FocusActor ); SpeakingActor.DialogSetEndingFocus( FocusActor ); } else DMDLG("Warning: SetEndingFocus -- can't find speaking actor" @ Speaker ); } } //----------------------------------------------------------------------------- function ProcessNPCControls( DialogSession S ) { local int i; local Actor TargetActor; for( i=0; i < NPCControls.Length; i++ ) if( NPCControls[i].bPending != 0 && PctDelayExpired( NPCControls[i].PercentDelay, S ) ) { if( NPCControls[i].Target != '' ) { TargetActor = class'DialogEngine'.static.NameToActor( Self, NPCControls[i].Target ); if( TargetActor != None ) if( NPCControls[i].bPauseNPC != 0 ) { DMDLG("Pausing NPC" @ NPCControls[i].Target ); TargetActor.DialogPause(); } else { DMDLG("UnPausing NPC" @ NPCControls[i].Target ); TargetActor.DialogUnPause(); } } NPCControls[i].bPending = 0; } } //----------------------------------------------------------------------------- function bool PctDelayExpired( float PercentDelay, DialogSession Session ) { local float TimeToWait; local float AudioLength; // wait until the percentage of the audio file has played AudioLength = GetAudioLength(); TimeToWait = PercentDelay * AudioLength; if( TimeToWait - AudioLength <= Session.TimeSinceLastSpoken() ) return true; return false; } //----------------------------------------------------------------------------- // how many event are pending? function int NumPendingActions() { local int i; local int count; for( i=0; i < NodeEvents.Length; i++ ) if( NodeEvents[i].bPending != 0 ) count++; for( i=0; i < NodeAnims.Length; i++ ) if( NodeAnims[i].bPending != 0 ) count++; for( i=0; i < NPCControls.Length; i++ ) if( NPCControls[i].bPending != 0 ) count++; for( i=0; i < Satellites.Length; i++ ) if( Satellites[i].bPending != 0 ) count++; for( i=0; i < Gestures.Length; i++ ) if( Gestures[i].bPending != 0 ) count++; return count; } //----------------------------------------------------------------------------- // find the soonest event/animation function float MinPendingPctDelay() { local int i; local float MinPercentDelay; if( NumPendingActions() <= 0 ) return -1; for( i=0; i < NodeEvents.Length; i++ ) { if( NodeEvents[i].bPending != 0 ) { if( MinPercentDelay <= 0 ) MinPercentDelay = NodeEvents[i].PercentDelay; else MinPercentDelay = FMin( MinPercentDelay, NodeEvents[i].PercentDelay ); } } for( i=0; i < NodeAnims.Length; i++ ) { if( NodeAnims[i].bPending != 0 ) { if( MinPercentDelay <= 0 ) MinPercentDelay = NodeAnims[i].PercentDelay; else MinPercentDelay = FMin( MinPercentDelay, NodeAnims[i].PercentDelay ); } } for( i=0; i < NPCControls.Length; i++ ) { if( NPCControls[i].bPending != 0 ) { if( MinPercentDelay <= 0 ) MinPercentDelay = NPCControls[i].PercentDelay; else MinPercentDelay = FMin( MinPercentDelay, NPCControls[i].PercentDelay ); } } for( i=0; i < Satellites.Length; i++ ) { if( Satellites[i].bPending != 0 ) { if( MinPercentDelay <= 0 ) MinPercentDelay = Satellites[i].PercentDelay; else MinPercentDelay = FMin( MinPercentDelay, Satellites[i].PercentDelay ); } } for( i=0; i < Gestures.Length; i++ ) { if( Gestures[i].bPending != 0 ) { if( MinPercentDelay <= 0 ) MinPercentDelay = Gestures[i].PercentDelay; else MinPercentDelay = FMin( MinPercentDelay, Gestures[i].PercentDelay ); } } return MinPercentDelay; } //----------------------------------------------------------------------------- event Destroyed() { if( Voice != None ) { Voice.Delete(); Voice = None; } Super.Destroyed(); } //----------------------------------------------------------------------------- defaultproperties { SpokenMax=1 Tone=DIALOGTONE_Formal bEnabled=true bDoLipSync=true UseReticleOnEvents(0)="UseReticleText" UseReticleOnEvents(1)="UseReticleCorners" UseReticleOnEvents(2)="UseReticleTopBars" ProximityReticleOnEvents(0)="ProximityReticleCorners" ProximityReticleOnEvents(1)="ProximityReticleTopBars" } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |