Ejemplo n.º 1
0
	// Initially, this will be just Handle User COmmands, but should also migrate any character responses like acknowledgements in here.

	public override bool ExecuteCommand( string command, string preferredHandler = ""){
		// commands initialed thru the NLU, Menu, or Filter should pass thru this for processing
		
		//TODO migrate these next two blocks down to a Trauma Brain override of this method 
		if (HandleUserCommand (command)) { // decision panel, abort, confirm handled here
			// send out the ISM for tracking...
			InteractMsg imsg = new InteractMsg(null, command );
			InteractStatusMsg ism = new InteractStatusMsg(imsg);
			Brain.GetInstance().PutMessage(ism);
			return true;
		}

		if (limitInteractions){
			if (!enabledInteractions.Contains(command)){
				if (SAPISpeechManager.Instance != null)
					SAPISpeechManager.Speak ("That's not what we need to do right now.");
				// give some other kind of feedback ?
				return false;
			}
			else{
				// the desired interaction was called, now open up so scripts can use interactions to run...
				limitInteractions = false;
			}
		}
		
		if (!IsCommandAvailable( command)){ // voice commands can come in that are not currently possible
			VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:CANT:DO:THAT");
//			if (SAPISpeechManager.Instance != null)
//				SAPISpeechManager.Speak ("We can't do that right now");
			return false;
		}

		if (IsCommandQueued( command)){ // voice commands can come in that are already queued
			VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:ALREADY:WORKING");
//			if (SAPISpeechManager.Instance != null)
//				SAPISpeechManager.Speak ("We're already working on that.");
			return false;
		}
		
		// Handle Confirm Command here ?
		SAPISpeechManager.Speak (InteractionMgr.GetInstance ().Get (command).response);
		return base.ExecuteCommand (command, preferredHandler);

	}
Ejemplo n.º 2
0
	public GameMsg ToGameMsg( ScriptedAction scriptedAction ){
		// create a message of the appropriate type, and send it to the singleton, or	
		if (msgType == eMsgType.interactMsg){
			GameObject target = GameObject.Find (gameObjectName); // cant use ObjectManager from the editor
			if (target != null){
				InteractMsg newMsg = new InteractMsg(target,map.GetMap());
				//	newMsg.map.task = map.task; // Task master faults if this is null

				for(int i=0;i<newMsg.map.param.Count;i++)
				{
					if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
						newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
				}
				// this is problematic, because BaseObject.PutMessage does NOTHING! TODO
				//target.GetComponent<BaseObject>().PutMessage(newMsg);
				return newMsg as GameMsg;
			}
		}
		if (msgType == eMsgType.interactStatusMsg){
			GameObject target = GameObject.Find (gameObjectName);
			if (target != null){
				InteractMsg newMsg;
				if (sendMap)
					newMsg = new InteractMsg(target,map.GetMap());
				else
					newMsg = new InteractMsg(target,interactName,log);
				//newMsg.map.task = map.task; // Task master faults if this is null
				if (sendMap)
					for(int i=0;i<newMsg.map.param.Count;i++)
					{
						if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
							newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
					}
				InteractStatusMsg newisMsg = new InteractStatusMsg(newMsg);
				if (Params.Length > 0){
					newisMsg.Params=new List<string>();
					for(int i=0;i<Params.Length;i++)
					{
						if ( Params[i] != null && Params[i] != "" )
							newisMsg.Params.Add (scriptedAction.executedBy.ResolveArgs(Params[i])); // substitute any #values
					}
				}
				return newisMsg as GameMsg;
			}
		}
		if (msgType == eMsgType.quickInfoDialogMsg){
			DialogMsg newMsg = new QuickInfoMsg();
		
			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			newMsg.modal = modal;
			newMsg.command = command;
			
			return newMsg as GameMsg;
		}
		if (msgType == eMsgType.dialogMsg){
			
			DialogMsg newMsg = new DialogMsg();
		
			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			newMsg.modal = modal;
			newMsg.command = command;
			newMsg.className = className;
			newMsg.xmlName = xmlName;
			newMsg.arguments = new List<string>();
			newMsg.callback += scriptedAction.DialogCallback;
			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (scriptedAction.executedBy.ResolveArgs(arg)); // substitute any #values
			}
			// fire off the dialog
			return newMsg as GameMsg;
		}	
		if (msgType == eMsgType.guiScreenMsg){
			
			GUIScreenMsg newMsg = new GUIScreenMsg();
		
			newMsg.ScreenName = ScreenName;

			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (scriptedAction.executedBy.ResolveArgs(arg)); // substitute any #values
			}
			// fire off the dialog
			return newMsg as GameMsg;
		}
		return null;
	}	
Ejemplo n.º 3
0
	public void OnScriptComplete(string error){
		if (debug) Debug.Log ("Script "+name+" OnScriptComplete");
		
		// we're done.  Assuming no errors, see if we need to send a :COMPLETE message
		string triggerString = "none";
		if (args.ContainsKey("trigger"))
			triggerString = args["trigger"];
		if (triggerString.Contains(":"))
		{
			// send :COMPLETE msg to brain
			string completion;
			if (error == null || error == "") completion = ":COMPLETE";
			else completion = ":"+error.ToUpper();
            InteractStatusMsg msg = new InteractStatusMsg(triggerString + completion);
            Brain.GetInstance().PutMessage(msg);
		}
//		hasRun = true;
		isRunning = false;
		readyState = readiness.unknown; // will update on the next readiness test.
		currentLine = scriptLines.Length; // so don't update a line by accident
		ScriptedObject myCaller = caller;
		caller = null; // have to do this before, because OnScriptComplete could start us up again!
		// release character task actors

		foreach (ObjectInteraction actor in actorObjects){
			actor.ReleasedBy(this, myCaller);
		}

		
		if (myCaller == null)
			Debug.LogWarning("Script Complete but caller was null!!"+name);
		else{
			// added this block 6/19/14 to keep queue from hanging when scripts owned by another
			// object interaction are run from an objects queue
			if (!actorObjects.Contains(myCaller.ObjectInteraction))
				myCaller.ObjectInteraction.ReleasedBy (this, myCaller);
			myCaller.OnScriptComplete(this,error);
		}

		roleMap.Clear(); // clear the assigned roles so they don't get reserved by accident
		actorObjects.Clear();
	}
Ejemplo n.º 4
0
    public static void Parse(string action)
    {
        // var:object.variable equals:0.5 .. sets equal
        // var:object.variable dec:0.5 .. decrements by .5
#if DEBUG_DECISION_ENGINE
        UnityEngine.Debug.Log("Action.Parse(" + action + ")");
#endif
        if (action.Contains("var") && action.Contains("equals"))
        {
            DecisionVariable variable = GetVar(action, "var");
            if (variable != null)
            {
                // get value of operator
                string val = GetArg(action,"equals");
                if (val != null)
                {
#if DEBUG_DECISION_ENGINE
                    UnityEngine.Debug.Log("Action.Parse(equals:" + action + ") : variable=" + variable.Object + "." + variable.Variable + " : value=" + variable.Get());
#endif
                    variable.Set(val);
                }
            }
        }

        // var:object.variable inc:0.5 .. increments by .5
        if (action.Contains("var") && action.Contains("inc"))
        {
            DecisionVariable variable = GetVar(action, "var");
            if (variable != null)
            {
                // get value of operator
                string val = GetArg(action,"inc");
                if (val != null)
                {
#if DEBUG_DECISION_ENGINE
                    UnityEngine.Debug.Log("Action.Parse(inc:" + action + ") : variable=" + variable.Object + "." + variable.Variable + " : value=" + val);
#endif
                    variable.Inc(val);
                }
            }
        }

        if (action.Contains("var") && action.Contains("dec"))
        {
            DecisionVariable variable = GetVar(action, "var");
            if (variable != null)
            {
                // get value of operator
                string val = GetArg(action,"dec");
                if (val != null)
                {
#if DEBUG_DECISION_ENGINE
                    UnityEngine.Debug.Log("Action.Parse(dec:" + action + ") : variable=" + variable.Object + "." + variable.Variable + " : value=" + val);
#endif
                    variable.Dec(val);
                }
            }
        }

        // var:object interact:MSG:EXAMPLE
        if (action.Contains("var") && action.Contains("interact"))
        {
            string objname = GetArg(action, "var");
            string interaction = GetString(action, "interact");

#if DEBUG_DECISION_ENGINE
            UnityEngine.Debug.Log("Action.Parse(interact:" + action + ") : objname=" + objname + " : interaction=" + interaction);
#endif
            ObjectInteraction objint = ObjectManager.GetInstance().GetBaseObject(objname) as ObjectInteraction;
            if (objint != null)
            {
                InteractionMap map = InteractionMgr.GetInstance().Get(interaction);
                if (map != null)
                {
                    // send interaction
                    InteractMsg imsg = new InteractMsg(objint.gameObject,map,true);
                    objint.PutMessage(imsg);
                }
            }
        }

        if (action.Contains("status:"))
        {
            string status = GetString(action, "status");
            if (status != null)
            {
                InteractStatusMsg ismsg = new InteractStatusMsg(status);
                Brain.GetInstance().PutMessage(ismsg);
            }
        }
		
#if CHANGE_STATE
		if (action.Contains("state:"))
		{
			string state = GetArg(action,"state");
			if ( state != null )
			{
				DecisionState newstate = Parent.FindState(state);
				if ( newstate != null )
				{
					Parent.Current = newstate;
				}
			}
		}
#endif

        // changestate:BRAINSTATE
        if (action.Contains("changestate"))
        {
            string statename = GetArg(action, "changestate");
            if (statename != null)
            {
                ChangeStateMsg msg = new ChangeStateMsg(statename);
                Brain.GetInstance().PutMessage(msg);
            }
        }

        // sound effect
        if (action.Contains("audio:"))
        {
            string audio = GetString(action, "audio");
            if (audio != null)
            {
                Brain.GetInstance().PlayAudio(audio);
            }
        }

        // dialog title:"title" text:"text" timeout:seconds
        if (action.Contains("dialog"))
        {
            string text="none", title="title";
            float time=0.0f;

            if (action.Contains("title"))
            {
                title = GetString(action, "title");
            }
            if (action.Contains("text"))
            {
                text = GetString(action, "text");
            }
            if (action.Contains("timeout"))
            {
                time = Convert.ToSingle(GetArg(action, "timeout"));
            }
            QuickInfoMsg msg = new QuickInfoMsg();
            msg.command = DialogMsg.Cmd.open;
            msg.title = title;
            msg.text = text;
            msg.timeout = time;
            QuickInfoDialog.GetInstance().PutMessage(msg);
        }
    }
Ejemplo n.º 5
0
	/* ----------------------------  SERIALIZATION ----------------------------------------- */	
	
	
	
	public void PutMessage( ScriptedAction scriptedAction ){
		// create a message of the appropriate type, and send it to the singleton, or	
		if (msgType == eMsgType.interactMsg){
			BaseObject bo = ObjectManager.GetInstance().GetBaseObject(gameObjectName);
			if (bo == null){
				Debug.LogWarning("GameMsgForm "+name+" could not send message to '"+gameObjectName+"', not known to ObjectManager.");
				return;
			}
			GameObject target = bo.gameObject;
			if (target != null){
				InteractMsg newMsg = new InteractMsg(target,map.GetMap());
				// add flag to let everyone know that this command as generated internally
				newMsg.scripted = true;
				//	newMsg.map.task = map.task; // Task master faults if this is null

				for(int i=0;i<newMsg.map.param.Count;i++)
				{
					if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
						newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
				}
				// this is problematic, because BaseObject.PutMessage does NOTHING! TODO
				//target.GetComponent<BaseObject>().PutMessage(newMsg);
				ObjectManager.GetInstance ().GetBaseObject(gameObjectName).PutMessage(newMsg);
			}
		}
		if (msgType == eMsgType.interactStatusMsg){
			GameObject target = GameObject.Find (gameObjectName);
			if (target != null){
				InteractMsg newMsg;
				if (sendMap)
					newMsg = new InteractMsg(target,map.GetMap());
				else
					newMsg = new InteractMsg(target,interactName,log);
				// add flag to let everyone know that this command as generated internally
				newMsg.scripted = true;
				//newMsg.map.task = map.task; // Task master faults if this is null
				if (sendMap)
					for(int i=0;i<newMsg.map.param.Count;i++)
					{
						if ( newMsg.map.param[i] != null && newMsg.map.param[i] != "" )
							newMsg.map.param[i]= scriptedAction.executedBy.ResolveArgs(newMsg.map.param[i]); // substitute any #values
					}
				InteractStatusMsg newisMsg = new InteractStatusMsg(newMsg);
				if (Params != null && Params.Length > 0){
					newisMsg.Params=new List<string>();
					for(int i=0;i<Params.Length;i++)
					{
						if ( Params[i] != null && Params[i] != "" )
							newisMsg.Params.Add (scriptedAction.executedBy.ResolveArgs(Params[i])); // substitute any #values
					}
				}
				// send to all objects
			//	ObjectManager.GetInstance().PutMessage(newisMsg);  // the brain sends to the object manager
				// send to the brain
				Brain.GetInstance().PutMessage(newisMsg);
			}
		}
		if (msgType == eMsgType.animateMsg){
			
		}
		if (msgType == eMsgType.taskMsg){
			
		}
		if (msgType == eMsgType.errorDialogMsg){
			
		}
		if (msgType == eMsgType.interactDialogMsg){
			
		}
		if (msgType == eMsgType.quickInfoDialogMsg){
			QuickInfoMsg newMsg = new QuickInfoMsg();
		
			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			// all the QuickInfo's had a timeout of 0 which was not getting passed, so if you see that, leave it alone
			// treat -1 as the value to leave the dialog up.
			if (timeout == 0) timeout = 2;
			if (timeout == -1) timeout = 0;
			newMsg.timeout = timeout;
			newMsg.modal = modal;
			newMsg.command = command;
			
			QuickInfoDialog.GetInstance().PutMessage( newMsg );
		}
		if (msgType == eMsgType.popupMsg){
			
		}
		if (msgType == eMsgType.dialogMsg){
			
			DialogMsg newMsg = new DialogMsg();

			newMsg.x = x;
			newMsg.y = y;
			newMsg.w = w;
			newMsg.h = h;
			newMsg.text = text;
			newMsg.title = title;
			newMsg.time = time;
			newMsg.modal = modal;
			newMsg.command = command;
			newMsg.className = className;
			newMsg.name = dialogName;
			newMsg.anchor = anchor;
			newMsg.xmlName = xmlName;
			newMsg.arguments = new List<string>();
			newMsg.callback += scriptedAction.DialogCallback;
			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (StringLookup(scriptedAction.executedBy.ResolveArgs(arg))); // substitute any #values
			}
			// fire off the dialog
			GUIManager.GetInstance().PutMessage( newMsg );
		}	
		if (msgType == eMsgType.guiScreenMsg){
			
			GUIScreenMsg newMsg = new GUIScreenMsg();
		
			newMsg.ScreenName = ScreenName;

			foreach( string arg in arguments )
			{
				if ( arg != null && arg != "" )
					newMsg.arguments.Add (StringLookup(scriptedAction.executedBy.ResolveArgs(arg))); // substitute any #values
			}
			// fire off the dialog
			GUIManager.GetInstance().PutMessage( newMsg );
		}		
	}
Ejemplo n.º 6
0
	public void OnComplete(){
		// tell our scripted object that this action is done and to go on
		hasExecuted = true;
		// we might only want to set these if error == ""
		if (postAttributes != "") SetAttributes(objectToAffect,postAttributes);
		
		if (type == actionType.characterTask){
			if (taskChar != null){
				// need to clear out a few things, but not a full Init();
				// without this, GO HOME in the task master might think we are already InPosition(home)
				taskChar.inPosition = false;
			}
			if (stringParam4 != ""){
				// send :COMPLETE msg to brain
	            InteractStatusMsg msg = new InteractStatusMsg( stringParam4 );
	            Brain.GetInstance().PutMessage(msg);
			}
		}
		
		// see if we are at the end of an "if" block, so we need to jump over the else
		if (((executedBy.currentLine+1) < executedBy.scriptLines.Length) &&
			executedBy.scriptLines[executedBy.currentLine+1].block == blockType.beginElse){
			executedBy.nextLineLabel = "endIf"; // will cause the script to move forward to the next endIfThenElse
		}
//		if (block == blockType.endIfThenElse)
//			executedBy.nestingDepth -= 1; // this could be done up in the script, but we increment in this class, so...
		
		if (sequenceEnd){
			executedBy.nextLineLabel = "sequenceEnd";	
			error="sequenceEnd";
		}
		// be sure our callback doesn't occur now that we are done.
		Brain.GetInstance().RemoveCallback(this.myInteractCallback);
		
		executedBy.OnLineComplete(this);
	}
Ejemplo n.º 7
0
    public void HandleInteractStatusMsg(GameMsg msg)
    {
        // first try making this a InteractStatusMsg
        InteractStatusMsg ismsg = msg as InteractStatusMsg;
        if (ismsg == null)
        {
            // nope, try InteractMsg
            InteractMsg imsg = msg as InteractMsg;
            if (imsg == null)
            {
#if DEBUG_BRAIN
                UnityEngine.Debug.Log("Brain.HandleInteractStatusMsg() : not InteractMsg!!");
#endif
                // not the right msg, hangup
                return;
            }

            ismsg = new InteractStatusMsg(imsg);
        }
        if (ismsg != null)
        {
#if DEBUG_BRAIN
            UnityEngine.Debug.Log("Brain.HandleInteractStatusMsg(" + ismsg.InteractName + ")");
#endif
            // log it
            LogMgr.GetInstance().GetCurrent().Add(new InteractStatusItem(ismsg));

            // send interact status message to everyone
            ObjectManager.GetInstance().PutMessage(ismsg);
			// pass to the GUI manager
			if (GUIManager.GetInstance() != null)
				GUIManager.GetInstance().PutMessage(ismsg);
            // pass to decision mgr
            DecisionMgr.GetInstance().PutMessage(ismsg);
        }
    }
Ejemplo n.º 8
0
	private bool DispatchMessage ( InteractMsg msg ){

		// this routine includes triggering the Generic Response System voice cues
		
		ObjectInteraction preferredHandler = null;
//		bool phIsValidInteraction = false;
		int phQc = -1; // flags that we have not checked this yet
		float lowestCost=99999;
		List<ObjectInteraction> actorsHavingInteraction = new List<ObjectInteraction>();
		
		if (msg.gameObject != null && msg.gameObject != "" && msg.gameObject != "null" && msg.gameObject.ToLower() != "dispatcher"){ // here. gameObject is just a string.
			preferredHandler = ObjectManager.GetInstance().GetBaseObject(msg.gameObject) as ObjectInteraction;
			if (preferredHandler != null){
				
				// The message asked for SOMEBODY in particular to do this
		
				if (!preferredHandler.IsValidInteraction(msg.map)){
					// the preferred handler doesn't know how to do this interaction.
					
					// if it's a valid interaction, then respond "VOICE:MISMATCH"
					if (InteractionMgr.GetInstance ().Get(msg.map.item)!= null)
						VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:MISMATCH:*"); //* is a wildcard for multiple responses
					// If it's not recognised by the interaction manager, then respond "VOICE:BAD:COMMAND"
					else
						VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:BAD:COMMAND:*");
					return false;
				}
				ScriptedObject phSo = preferredHandler.GetComponent<ScriptedObject>();
				if (phSo != null){
					phQc = phSo.scriptArray.Count;
					if (phQc < 2){ // then we're going to let our ph do this.
						if (phQc == 0){
							//VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:ACKNOWLEDGE");
							VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:ACKNOWLEDGE:*");
						}
						else{
							//VoiceMgr.GetInstance().Play (msg.gameObject,"VOICE:BUSY:QUEUED");
							//Brain.GetInstance().PlayAudio("AUDIO:ACKNOWLEDGE");
							VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:BUSY:QUEUED:*");
						}
						preferredHandler.PutMessage(msg);
						return true;
					}
					else // Qc>= 2: The requested person is pretty busy, is there someone else who can do this?
					{
						ObjectInteraction handoffActor = null;
						foreach(ObjectInteraction testActor in actors){
							if (testActor.IsValidInteraction(msg.map)){
								actorsHavingInteraction.Add(testActor);
							}
						}
						foreach (ObjectInteraction testActor in actorsHavingInteraction){
							// add in cost if we're the scribe nurse
							float cost = ( testActor == scribeNurse )?100:0;
							ScriptedObject taSo = testActor.GetComponent<ScriptedObject>();
							if (taSo != null){
								int taQc = taSo.scriptArray.Count;
								if (phQc == -1 || taQc < phQc){ // shorter queue, choose this one
									handoffActor = testActor;
									phQc = taQc;
									lowestCost = testActor.GetCost(msg.map)+cost;
								}
								else
								{
									if (taQc == phQc){ // same q length, base on cost
										if ((testActor.GetCost(msg.map)+cost) < lowestCost){ // same q. lower cost, choose
											handoffActor = testActor;
											lowestCost = testActor.GetCost(msg.map);
										}
									}
								}
							}	
						}
						if (handoffActor != null){
							// say the handoff message
							// can we set the lookat ?
							CharacterBuilder cb = handoffActor.GetComponent<CharacterBuilder>();
							Transform lookAt;
							if (cb != null)
								lookAt = cb.bodyHeadbone;
							else
								lookAt = handoffActor.transform; // could search for that lookAt child...

							if (preferredHandler as Character != null){
	                  		  	(preferredHandler as Character).LookAt(lookAt, Time.time + 3);
								// set talk time
								(preferredHandler as Character).TalkTime = Time.time + 3;
							}
							
							VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:BUSY:HANDOFF:*");
							// say the acknowledge for the handoff actor
							if (phQc == 0)
								VoiceMgr.GetInstance().Play(handoffActor.Name,"VOICE:ACKNOWLEDGE:*");
							else if (phQc == 1)
								VoiceMgr.GetInstance().Play(handoffActor.Name,"VOICE:BUSY:QUEUED:*");
							else
								VoiceMgr.GetInstance().Play(handoffActor.Name,"VOICE:BUSY:DELAYED:*");
							// send the handoff actor the message
							handoffActor.PutMessage(msg);
							return true;
						}
						
						// no one else to do this, so put it on the queue.
						VoiceMgr.GetInstance().Play(msg.gameObject,"VOICE:BUSY:DELAYED:*");
						preferredHandler.PutMessage(msg);
						return true;
					}
					// here, we have a preferred handler with a q > 2, so we can
					// ask about priorities or hand off
				}				
			} // end the handler specified was valid
		} // end message specified a specific handler
		
		// we've handled all the cases if the handler was specified already.
		
		
		if (preferredHandler == null){ // this should always be true.
			// No valid preferred handler was given, build list of who can do this interaction.
			foreach(ObjectInteraction testActor in actors){
				if (testActor.IsValidInteraction(msg.map))
					actorsHavingInteraction.Add(testActor);
			}	
			// if no one knows how to do this, we just bail.
			if (actorsHavingInteraction.Count == 0){
				Brain.GetInstance().PlayAudio("AUDIO:BAD:COMMAND");
				return false;
			}
			// if someone can do this, pick the best one, weighting Q length the heaviest.
			// and set them up as the preferred handler
			foreach (ObjectInteraction testActor in actorsHavingInteraction)
			{
				// if we're the scribe have a higher cost
				float cost = (testActor == scribeNurse)?100:0;
				//
				ScriptedObject taSo = testActor.GetComponent<ScriptedObject>();
				if (taSo != null){
					int taQc = taSo.scriptArray.Count;
					if (phQc == -1 || taQc+2 < phQc){ // much shorter queue, choose this one
						preferredHandler = testActor;
						phQc = taQc;
						lowestCost = testActor.GetCost(msg.map)+cost;
					}
					else
					{
						if (taQc <= phQc){ // nearly same q length, base on cost
							if ((testActor.GetCost(msg.map)+cost) < lowestCost){ // same q. lower cost, choose
								preferredHandler = testActor;
								phQc = taQc;
								lowestCost = testActor.GetCost(msg.map);
							}
						}
					}
				}	
			}		
		}	
		// we should be guaranteed a preferred handler at this point.
		// we have picked THE best person to perform the task, so we just need to acnowledge appropriately
		if (preferredHandler != null ){

			ScriptedObject phSo = preferredHandler.GetComponent<ScriptedObject>();
			if (phSo != null){
				phQc = phSo.scriptArray.Count;
				if (phQc == 0){ // then we're going to let our ph do this.
						VoiceMgr.GetInstance().Play (preferredHandler.name,"VOICE:ACKNOWLEDGE:*");
				}
				else 
				{	if (phQc == 1) {
						VoiceMgr.GetInstance().Play (preferredHandler.name,"VOICE:BUSY:QUEUED:*");
					}
					else
					{
						VoiceMgr.GetInstance().Play (preferredHandler.name,"VOICE:BUSY:DELAYED:*");
					}
				}
				preferredHandler.PutMessage(msg);
				return true;
			}
		}

#if MAKE_ISM_FROM_IM
		// always dispatch an ISM for each IM (for AssessmentMgr) NOTE!! if we don't have a handler
		InteractStatusMsg ismsg = new InteractStatusMsg(msg);
		Brain.GetInstance().PutMessage(ismsg);
#endif

		// either no preferredHandler, or too busy to do this. Make a list of everyone who can do this.
		return false;
		
		
	}
Ejemplo n.º 9
0
	public void EndTask(Task task) 
    {
        // create new interact msg from task name and this object
        InteractStatusMsg msg = new InteractStatusMsg(task.data.name + ":COMPLETE");
        // send to brain
		Brain.GetInstance().PutMessage(msg);
#if DEBUG_TASK
        UnityEngine.Debug.Log("TaskManager.EndTask() : name=" + msg.InteractName);
#endif
        // end tasks
        foreach (TaskCharacter character in characters)
        {
            character.EndTask(task);
        }
        // remove, we're doe
		tasks.Remove(task);
	}
Ejemplo n.º 10
0
    public override void Update()
    {
        // play audio for HR
        AudioHR();
		// play audio for Breathing

		AudioResp ();
        
        base.Update();
		
#if SHORTCUT_KEYS
        if (Input.GetKeyUp(KeyCode.V))
		{		
			GUIScreen screen = GUIManager.GetInstance().FindScreenByType<VitalsGUI>();
			if ( screen == null )
			{
				// screen doesn't exist, make one
				DialogMsg dmsg = new DialogMsg();
				dmsg.xmlName = "dialog.vitals.grapher";
				dmsg.className = "VitalsGUI";
				GUIManager.GetInstance().LoadDialog( dmsg );
			}
			else
			{
				// exists, close it
				DialogMsg dmsg = new DialogMsg();
				dmsg.className = "VitalsGUI";
				GUIManager.GetInstance().CloseDialog( dmsg );
			}
		}

        if (Input.GetKeyUp(KeyCode.Alpha1))
        {
            bloodbagsIV++;
            InteractStatusMsg ismsg = new InteractStatusMsg("FLUID:CHANGE");
            this.PutMessage(ismsg);
        }

        if (Input.GetKeyUp(KeyCode.Alpha2))
        {
            if (--bloodbagsIV < 0)
                bloodbagsIV = 0;

            InteractStatusMsg ismsg = new InteractStatusMsg("FLUID:CHANGE");
            this.PutMessage(ismsg);
        }

        if (Input.GetKeyUp(KeyCode.Alpha3))
        {
            bloodbagsRI++;
            InteractStatusMsg ismsg = new InteractStatusMsg("FLUID:CHANGE");
            this.PutMessage(ismsg);
        }

        if (Input.GetKeyUp(KeyCode.Alpha4))
        {
            if (--bloodbagsRI < 0)
                bloodbagsRI = 0;

            InteractStatusMsg ismsg = new InteractStatusMsg("FLUID:CHANGE");
            this.PutMessage(ismsg);
        }
#endif

        UpdateVitals();
    }
Ejemplo n.º 11
0
    public void Next()
    { 
        elapsedTime = 0.0f;

        if (++index >= Interactions.Count)
        {
#if DEBUG_INTERACTIONLIST
            UnityEngine.Debug.Log("InteractionList.Next(), at end, current=" + current.Name + " : count=" + Interactions.Count); 
#endif
            // send msg to brain
            InteractStatusMsg msg = new InteractStatusMsg(Map.item + ":COMPLETE");
            Brain.GetInstance().PutMessage(msg);  

            // if loop then restart it, otherwise we are done
            if (Loop == true)
                Start();
            else
            {
                current = null;
            }
        }
        else
        {
            // put next interaction
            current = Interactions[index];
            PutMessage();
        }
    }
Ejemplo n.º 12
0
	public void OrderFluids( string name, int bloodDrip, int bloodPressure, int bloodRapid, int salineDrip, int salinePressure, int salineRapid)
	{
		InteractMsg imsg;
		
		if ( bloodDrip > 0 )
		{
			// ORDER:BLOOD:1:IV
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:BLOOD:" + bloodDrip.ToString() + "IV");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER			
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + bloodDrip);
			imsg.map.param.Add("delivery=\"IV\"");
			imsg.map.param.Add("product=\"bloodbag\"");
			imsg.map.param.Add("affect=\"Patient.%BloodbagsIV\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( bloodPressure > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:BLOOD:" + bloodPressure.ToString() + "PR");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER			
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + bloodPressure);
			imsg.map.param.Add("delivery=\"PR\"");
			imsg.map.param.Add("product=\"bloodbag\"");
			imsg.map.param.Add("affect=\"Patient.%BloodbagsPR\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( bloodRapid > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:BLOOD:" + bloodRapid.ToString() + "RI");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + bloodRapid);
			imsg.map.param.Add("delivery=\"RI\"");
			imsg.map.param.Add("product=\"bloodbag\"");
			imsg.map.param.Add("affect=\"Patient.%BloodbagsRI\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( salineDrip > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:SALINE:" + salineDrip.ToString() + "IV");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + salineDrip);
			imsg.map.param.Add("delivery=\"IV\"");
			imsg.map.param.Add("product=\"salinebag\"");
			imsg.map.param.Add("affect=\"Patient.%SalinebagsIV\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( salinePressure > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:SALINE:" + salinePressure.ToString() + "PR");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + salinePressure);
			imsg.map.param.Add("delivery=\"PR\"");
			imsg.map.param.Add("product=\"salinebag\"");
			imsg.map.param.Add("affect=\"Patient.%SalinebagsPR\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
		if ( salineRapid > 0 )
		{
			InteractStatusMsg ismsg = new InteractStatusMsg("ORDER:SALINE:" + salineRapid.ToString() + "PR");
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(ismsg);
#if LATER
			imsg = new InteractMsg(null,"ORDER:BLOOD:SCRIPT",true);
			imsg.gameObject = name;
			imsg.map.param = new List<string>();
			imsg.map.param.Add("units=" + salineRapid);
			imsg.map.param.Add("delivery=\"RI\"");
			imsg.map.param.Add("product=\"salinebag\"");
			imsg.map.param.Add("affect=\"Patient.%SalineBagsRI\"");
			// send to primary nurse
			ObjectManager.GetInstance().GetBaseObject(name).PutMessage(imsg);
#endif
		}
	}
Ejemplo n.º 13
0
	public void RemoveBag( string site)
	{
		VitalsBehavior behavior = VitalsBehaviorManager.GetInstance().RemoveBehaviorContaining(site);
		
		if (behavior == null){
			UnityEngine.Debug.LogWarning("Patient RemoveBag Found no vitals behavior to remove from "+site);
			return;
		}
		
		List<string> _params = new List<string>();						
		_params.Add("name=" + behavior.name);
		_params.Add("status=removed");
		// add parameters coming from caller
		if ( behavior.CallbackParams != null )
		{
			foreach( string param in behavior.CallbackParams)
				_params.Add(param);
		}
		// do callback
		InteractStatusMsg ismsg = new InteractStatusMsg("FLUID:FINISHED");		
		// add map
		ismsg.InteractMap = new InteractionMap("FLUID:FINISHED",null,null,null,null,null,null,true);
		ismsg.InteractMap.param = _params;
		// add parameters
		ismsg.Params = _params;
		// broadcast
		ObjectManager.GetInstance().PutMessage(ismsg);
		// There is a script "FLUID:FINISHED" on the blood fridge that processes this
	}
Ejemplo n.º 14
0
	// use number of bags of blood and saline to compute the rate of
	// decline in vital state
	public void ComputeBloodSalineEffect( InteractStatusMsg ismsg )
	{
        // only do something we we had a bag change
        if (ismsg.InteractName == "FLUID:CHANGE")
		{
			// some debug
			UnityEngine.Debug.Log("Patient.ComputeBloodSalineEffect(" + ismsg.InteractName + ")");
			
			// ok figure out params
			if ( ismsg.InteractMap == null || ismsg.InteractMap.param == null && ismsg.InteractMap.param.Count != 3 )
				return;
			
			// parse what to do
			string product="";
			string delivery="";
			string site="";
			string bagname="";
			string command="";
			string counter="";
			foreach( string param in ismsg.InteractMap.param )
			{			
//				UnityEngine.Debug.LogError("Patient.ComputeBloodSalineEffect(FLUID:CHANGE) : param=" + param);
				GetToken(param,"product",ref product);
				GetToken(param,"delivery",ref delivery);
				GetToken(param,"site",ref site);
				GetToken (param,"command",ref command);
				GetToken (param,"counter",ref counter);
			}
			
			if (command == "remove"){
				RemoveBag(site);
				return;	
			}
			
			// if we have an blood or saline IV or PR we are going to have
			// to animate the bag
			IVBagTextureOvertakeScript overtakeScript=null;	
			//
			if ( product != "" && delivery != "" && site != "")
			{
				GameObject hanger=null;
				if ( delivery == "IV" || delivery == "PR" )
				{
					// find the bag and animate
					
					if ( site == "ivleft" )
						hanger = GameObject.Find("prop_ivHangerCeilingLeft");
					if ( site == "ivright" )
						hanger = GameObject.Find("prop_ivHangerCeilingRight");
				}	
				if ( delivery == "RI") // even though animation isnt important here,
					// finding the bag later is.
				{
					// find the bag and animate
					if ( site == "ivleft" )
						hanger = GameObject.Find("prop_ivFluidWarmer01_door2"); // temporarily use the doors as parents
					if ( site == "ivright" )
						hanger = GameObject.Find("prop_ivFluidWarmer01_door1");
				}
						
				if ( hanger != null )
				{
					// get the UV anim script on the bag
					// there might still be an empty bag hanging here, so we need to check that the overtake amount is 0
					foreach (IVBagTextureOvertakeScript ots in hanger.GetComponentsInChildren<IVBagTextureOvertakeScript>(false)){
						if (ots.overtake == 0){
							overtakeScript = ots;
							break;
						}
					}
					if (overtakeScript!= null)
						bagname = overtakeScript.name;
				}

				// update appropriate counters for assessment, number of each type delivered
				if (counter == "Patient.%UnitsBlood") UnitsBlood++;
				if (counter == "Patient.%UnitsPRBC") UnitsPRBC++;
				if (counter == "Patient.%UnitsPlatelets") UnitsPlatelets++;
				if (counter == "Patient.%UnitsPlasma") UnitsPlasma++;
				if (counter == "Patient.%UnitsSaline") UnitsSaline++;
				if (counter == "Patient.%UnitsCrystal") UnitsCrystal++;
				if (counter == "Patient.%UnitsRingers") UnitsRingers++;
				if (counter == "Patient.%UnitsHypertonic") UnitsHypertonic++;
			}
			else
			{
				// error, return here
				UnityEngine.Debug.LogError("Patient.ComputeBloodSalineEffect(FLUID:CHANGE) : param missing!");
				return;
			}
					
			// Check for bag change, add or remove a bag
			VitalsBehavior behavior = AddBag(product, delivery);	

		
			// add parameters if we're ok
			if ( behavior != null )
			{
				// add the site to the name so we can find it uniquely if we have to remove it on order
				behavior.name += site;
				behavior.CallbackParams = new List<string>();
				behavior.CallbackParams.Add("product=\"" + product+"\""); // quotes are needed to distinguish string values
				behavior.CallbackParams.Add("delivery=\"" + delivery+"\"");
				behavior.CallbackParams.Add("site=\"" + site+"\"");
				behavior.CallbackParams.Add("bagname=\"" + bagname+"\""); // so i can remove it!
				behavior.CallbackParams.Add("counter=\"" + counter+"\""); 
				
			}
		
			// we're done with add/remove, now add a callback the behavior to animate the bag
			if ( behavior != null && overtakeScript != null )
			{
				behavior.AddCallback(overtakeScript.SetPercentage);	
			}
		}
    }
Ejemplo n.º 15
0
	// method called by Vitals behavior on status change
	public void VitalsBehaviorChange( List<string> param )
	{
		// parse callback
		InteractStatusMsg ismsg = new InteractStatusMsg("FLUID:FINISHED");		
		// add map
		ismsg.InteractMap = new InteractionMap("FLUID:FINISHED",null,null,null,null,null,null,true);
		ismsg.InteractMap.param = param;
		// add parameters
		ismsg.Params = param;
		// broadcast
		ObjectManager.GetInstance().PutMessage(ismsg);
		// debug
		UnityEngine.Debug.Log("Patient.VitalsBehaviorChange(FLUID:FINISHED) status=<" + param[0] + ">");
	}
    public VitalsBehavior AddBehavior(VitalsBehavior behavior)
    {
        if (!behavior.stackable && ExistInBehaviors(behavior.name))
            return null;
		actionString += "Add "+behavior.name+":";
		VitalsBehaviorLogItem logItem = new VitalsBehaviorLogItem(Time.time,"ADD:"+this.name);
		LogMgr.GetInstance ().GetCurrent().Add (logItem);
		if (!addingByTrigger && behavior.triggered != null && behavior.triggered != ""){
			// emit the 'triggered' message if it wasn't the cause of this add
			InteractStatusMsg msg = new InteractStatusMsg( behavior.triggered );
			sendingTrigger = true; // flag so we don't respond to our own message
            Brain.GetInstance().PutMessage(msg);
			sendingTrigger = false;
		}
		
		VitalsBehavior newBehavior = behavior.Copy().Init(patient);
        behaviors.Add(newBehavior);
		return newBehavior;
    }