Exemple #1
0
 public ScanAtStationAction(RobotController controller, List <Goal> goals, LabelHandle scanStation)
     : base(controller, goals, scanStation)
 {
     this.name          = "scanAtStation";
     this.scanStation   = scanStation;
     requiredComponents = new System.Type[] { typeof(HoverJet) };
 }
Exemple #2
0
	public RobotMessage(MessageType type, string message, LabelHandle target, Vector3 targetPos, Vector3? velocity) {
		this.type = type;
		this.message = message;
		this.target = target;
		this.targetPos = targetPos;
		this.targetVelocity = velocity;
	}
 public InvestigateAction(RobotController controller, List<Goal> goals, LabelHandle parent)
     : base(controller, goals, parent)
 {
     creationTime = System.DateTime.Now;
     this.name = "investigate";
     requiredComponents = new System.Type[] { typeof(HoverJet) };
 }
 public InvestigateAction(RobotController controller, List <Goal> goals, LabelHandle parent)
     : base(controller, goals, parent)
 {
     creationTime       = System.DateTime.Now;
     this.name          = "investigate";
     requiredComponents = new System.Type[] { typeof(HoverJet) };
 }
Exemple #5
0
 internal void AddBranch(int ilOffset, LabelHandle label, byte shortOpCode)
 {
     Debug.Assert(ilOffset >= 0);
     Debug.Assert(_branches.Count == 0 || ilOffset > _branches.Last().ILOffset);
     ValidateLabel(label);
     _branches.Add(new BranchInfo(ilOffset, label, shortOpCode));
 }
Exemple #6
0
 internal void AddBranch(int ilOffset, LabelHandle label, byte shortOpCode)
 {
     Debug.Assert(ilOffset >= 0);
     Debug.Assert(_branches.Count == 0 || ilOffset > _branches.Last().ILOffset);
     ValidateLabel(label);
     _branches.Add(new BranchInfo(ilOffset, label, shortOpCode));
 }
 public System.DateTime? getLastSightingTime(LabelHandle target)
 {
     if(targetSightings.ContainsKey(target)) {
         return targetSightings[target].getSightingTime();
     }
     return null;
 }
Exemple #8
0
    public void Awake()
    {
        labelHandle       = new LabelHandle(transform.position, name);
        labelHandle.label = this;

        Label.labels.Add(this);
        if (isVisible)
        {
            visibleLabels.Add(this);
        }
        triggers = new Dictionary <System.Type, List <Operation> >();
        foreach (Operation op in operations)
        {
            addOperation(op, op.getTriggers());
        }

        foreach (EndeavourFactory endeavour in endeavours)
        {
            endeavour.setParent(this);
        }

        foreach (Tag tag in tags)
        {
            tagMap.Add(tag.type, tag);
        }
    }
 public System.Nullable<Vector3> getLastKnownPosition(LabelHandle target)
 {
     if (targetSightings.ContainsKey(target)) {
         return targetSightings[target].getPosition();
     }
     return null;
 }
 public void trackTarget(LabelHandle target)
 {
     trackedTargets.Add(target);
     target.getPosition();
     foreach (InherentEndeavourFactory factory in inherentEndeavours)
     {
         if (factory.isApplicable(target))
         {
             Endeavour action = factory.constructEndeavour(this, target);
             if (action != null)
             {
                 availableEndeavours.Add(action);
                 dirty = true;
             }
         }
     }
     if (target.label != null)
     {
         foreach (Endeavour action in target.label.getAvailableEndeavours(this))
         {
             availableEndeavours.Add(action);
             dirty = true;
         }
     }
 }
Exemple #11
0
    public void addSighting(LabelHandle target, Vector3 position, Vector3?direction)
    {
        if (targetSightings.ContainsKey(target))
        {
            SensoryInfo info = targetSightings[target];

            if (info.getSightings() == 0)
            {
                // We have to increment the sighting count before we notify listeners
                info.addSighting();
                notifyListenersTargetFound(target);
            }
            else
            {
                // Keep this. See above comment
                info.addSighting();
            }
            info.updatePosition(position);
            info.updateDirection(direction);
        }
        else
        {
            targetSightings[target] = new SensoryInfo(position, direction, 1);
            notifyListenersTargetFound(target);
        }
    }
Exemple #12
0
 public void notifyListenersTargetLost(LabelHandle target)
 {
     for (int i = 0; i < listeners.Count; i++)
     {
         listeners[i].notifySightingLost(target);
     }
 }
Exemple #13
0
 public RobotMessage(MessageType type, string message, LabelHandle target, Vector3 targetPos, Vector3?velocity)
 {
     this.type           = type;
     this.message        = message;
     this.target         = target;
     this.targetPos      = targetPos;
     this.targetVelocity = velocity;
 }
 private void sightingFound(LabelHandle target, Vector3 pos, Vector3?dir)
 {
     if (externalMentalModel != null)
     {
         externalMentalModel.addSighting(target, pos, dir);
     }
     mentalModel.addSighting(target, pos, dir);
 }
 private void sightingLost(LabelHandle target, Vector3 lastKnownPos, Vector3?lastKnownVelocity)
 {
     if (externalMentalModel != null)
     {
         externalMentalModel.removeSighting(target, lastKnownPos, lastKnownVelocity);
     }
     mentalModel.removeSighting(target, lastKnownPos, lastKnownVelocity);
 }
Exemple #16
0
 public HoldAction(RobotController controller, Label target, LabelHandle source) : base(controller, new List <Goal> {
     new Goal(GoalEnum.Offense, 3), new Goal(GoalEnum.Protection, 3)
 }, source)
 {
     this.target        = target;
     this.name          = "grab";
     requiredComponents = new System.Type[] { typeof(RobotArms) };
 }
Exemple #17
0
 public System.DateTime?getLastSightingTime(LabelHandle target)
 {
     if (targetSightings.ContainsKey(target))
     {
         return(targetSightings[target].getSightingTime());
     }
     return(null);
 }
Exemple #18
0
 public System.Nullable <Vector3> getLastKnownPosition(LabelHandle target)
 {
     if (targetSightings.ContainsKey(target))
     {
         return(targetSightings[target].getPosition());
     }
     return(null);
 }
 public void updateInfo(LabelHandle target)
 {
     if (getSightings() > 0) {
         updatePosition(target.getPosition());
         updateTime(System.DateTime.Now);
         updateAttachedTags(target.getTags());
         if (target.getDirection() != null) {
             updateDirection(target.getDirection());
         }
     }
 }
        private void ValidateLabel(LabelHandle label)
        {
            if (label.IsNil)
            {
                Throw.ArgumentNull(nameof(label));
            }

            if (label.Id > _labels.Count)
            {
                Throw.LabelDoesntBelongToBuilder(nameof(label));
            }
        }
Exemple #21
0
        public void Branch(ILOpCode code, LabelHandle label)
        {
            // throws if code is not a branch:
            ILOpCode shortCode = code.GetShortBranch();

            GetBranchBuilder().AddBranch(Offset, label, (byte)shortCode);
            OpCode(shortCode);

            // -1 points in the middle of the branch instruction and is thus invalid.
            // We want to produce invalid IL so that if the caller doesn't patch the branches
            // the branch instructions will be invalid in an obvious way.
            Builder.WriteSByte(-1);
        }
Exemple #22
0
        private void ValidateLabel(LabelHandle label)
        {
            if (label.IsNil)
            {
                throw new ArgumentNullException(nameof(label));
            }

            if (label.Id > _labels.Count)
            {
                // TODO: localize
                throw new ArgumentException("Label not defined", nameof(label));
            }
        }
Exemple #23
0
    private void pursueTarget()
    {
        if (target != null)
        {
            if (hasReachedTargetLocation())
            {
                if (!hasMatchedTargetRotation())
                {
                    roboController.transform.rotation = Quaternion.RotateTowards(Quaternion.LookRotation(roboController.transform.forward), Quaternion.LookRotation(target.label.transform.forward), nav.angularSpeed * Time.deltaTime);
                }
                else
                {
                    roboController.enqueueMessage(new RobotMessage(RobotMessage.MessageType.ACTION, "target reached", target, target.getPosition(), null));
                    target = null;
                    return;
                }
            }

            if (nav.enabled)
            {
                nav.speed = pursueSpeed;
                if (target.getDirection().HasValue&& Vector3.Distance(roboController.transform.position, target.getPosition()) > target.getDirection().Value.magnitude)
                {
                    nav.SetDestination((target.getPosition()));                    // +
                    //target.getDirection().Value
                    //* .08f
                    //* (1 + Vector3.Dot(target.getDirection().Value.normalized, (target.getPosition() - roboController.transform.position).normalized))
                    //*(target.getDirection().Value.magnitude/nav.speed)
                    //* Vector3.Distance(roboController.transform.position, target.getPosition())));
                }
                else
                {
                    nav.SetDestination(target.getPosition());
                }

#if UNITY_EDITOR
                if (roboController.debug)
                {
                    Destroy(dest);
                    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cube.transform.position = nav.destination;
                    cube.GetComponent <MeshRenderer>().material.color = Color.green;
                    Destroy(cube.GetComponent <BoxCollider>());
                    cube.transform.localScale = new Vector3(.3f, .3f, .3f);
                    dest = cube;
                }
#endif
            }
        }
    }
Exemple #24
0
 public void setTarget(LabelHandle target, bool matchRotation = false)
 {
     this.target = target;
     if (target == null)
     {
         nav.Stop();
         isPursuit = false;
     }
     else
     {
         nav.Resume();
     }
     matchTargetRotation = matchRotation;
 }
Exemple #25
0
	public void OnCollisionEnter(Collision col) {
		float volume = col.impulse.magnitude *this.volume;
		if (volume > volumeThreshold) {
			source.volume = volume;
			if (source.clip == null)
				source.clip = clip;
			source.Play(0);
			LabelHandle audioLabel = new LabelHandle(transform.position, "rock");
			audioLabel.addTag(new Tag(TagEnum.Sound, volume));
			audioLabel.addTag(new Tag(TagEnum.Threat, 5f));
			AudioEvent rockCollisionSound = new AudioEvent(transform.position, audioLabel, transform.position);
			rockCollisionSound.broadcast(volume);

		}
	}
    public void removeSighting(LabelHandle target, Vector3 position, Vector3? direction)
    {
        if (targetSightings.ContainsKey (target)) {
            SensoryInfo info = targetSightings[target];

            info.removeSighting();
            if (info.getSightings() < 1) {
                notifyListenersTargetLost (target);
            }
            info.updatePosition(position);
        } else {
            //Realistically we should never get here. This case is stupid.
            targetSightings[target] = new SensoryInfo(position, direction, 0);
            notifyListenersTargetLost (target);
            Debug.LogWarning("Target '" + target.getName() + "' that was never found has been lost. Shenanigans?");
        }
    }
Exemple #27
0
        public void Equality()
        {
            var a1 = new LabelHandle(1);
            var a2 = new LabelHandle(2);
            var b1 = new LabelHandle(1);

            Assert.False(((object)a1).Equals(a2));
            Assert.False(a1.Equals(new object()));
            Assert.False(a1.Equals(a2));
            Assert.False(a1 == a2);

            Assert.True(((object)a1).Equals(b1));
            Assert.True(a1.Equals(b1));
            Assert.True(a1 == b1);

            Assert.Equal(a1.GetHashCode(), b1.GetHashCode());
        }
Exemple #28
0
 public ExceptionHandlerInfo(
     ExceptionRegionKind kind,
     LabelHandle tryStart, 
     LabelHandle tryEnd,
     LabelHandle handlerStart, 
     LabelHandle handlerEnd, 
     LabelHandle filterStart, 
     EntityHandle catchType)
 {
     Kind = kind;
     TryStart = tryStart;
     TryEnd = tryEnd;
     HandlerStart = handlerStart;
     HandlerEnd = handlerEnd;
     FilterStart = filterStart;
     CatchType = catchType;
 }
Exemple #29
0
    public void OnCollisionEnter(Collision col)
    {
        float volume = col.impulse.magnitude * this.volume;

        if (volume > volumeThreshold)
        {
            source.volume = volume;
            if (source.clip == null)
            {
                source.clip = clip;
            }
            source.Play(0);
            LabelHandle audioLabel = new LabelHandle(transform.position, "rock");
            audioLabel.addTag(new Tag(TagEnum.Sound, volume));
            audioLabel.addTag(new Tag(TagEnum.Threat, 5f));
            AudioEvent rockCollisionSound = new AudioEvent(transform.position, audioLabel, transform.position);
            rockCollisionSound.broadcast(volume);
        }
    }
 public void addSighting(LabelHandle target, Vector3 position, Vector3? direction)
 {
     if (targetSightings.ContainsKey (target)) {
         SensoryInfo info = targetSightings[target];
         info.addSighting();
         info.updateInfo(target);
     } else {
         if (staleTargetSightings.ContainsKey(target)) {
             SensoryInfo info = staleTargetSightings[target];
             targetSightings.Add(target, info);
             staleTargetSightings.Remove(target);
             info.addSighting();
         } else {
             targetSightings[target] = new SensoryInfo(position, direction, System.DateTime.Now, target.getTags(), 1);
         }
         registerTags(target);
         notifyListenersTargetFound(target);
     }
 }
Exemple #31
0
	public void addSighting(LabelHandle target, Vector3 position, Vector3? direction) {
		if (targetSightings.ContainsKey (target)) {
			SensoryInfo info = targetSightings[target];
			
			if (info.getSightings() == 0) {
				// We have to increment the sighting count before we notify listeners
				info.addSighting();
				notifyListenersTargetFound(target);
			}
			else {
				// Keep this. See above comment
				info.addSighting();
			}
			info.updatePosition(position);
			info.updateDirection(direction);
		} else {
			targetSightings[target] = new SensoryInfo(position, direction, System.DateTime.Now, 1);
			notifyListenersTargetFound(target);
		}
	}
Exemple #32
0
    public void setTarget(LabelHandle target, bool autoBrake, bool matchRotation = false) {
		this.target = target;
		matchTargetRotation = matchRotation;
		if(target == null) {
			if(nav.enabled) {
				nav.Stop();
			}
			isPursuit = false;
		} else {
			if(hasReachedTargetLocation() && hasMatchedTargetRotation()) {
				this.target = null;
				//print("bailing...");
				return;
			}
			if(nav.enabled) {
				nav.Resume();
			}
		}
		nav.autoBraking = autoBrake;
	}
Exemple #33
0
 public void setTarget(LabelHandle target, bool matchRotation = false)
 {
     this.target = target;
     if (target == null)
     {
         if (nav.enabled)
         {
             nav.Stop();
         }
         isPursuit = false;
     }
     else
     {
         if (nav.enabled)
         {
             nav.Resume();
         }
     }
     matchTargetRotation = matchRotation;
     nav.autoBraking     = true;
 }
Exemple #34
0
    public void removeSighting(LabelHandle target, Vector3 position, Vector3?direction)
    {
        if (targetSightings.ContainsKey(target))
        {
            SensoryInfo info = targetSightings[target];

            info.removeSighting();
            if (info.getSightings() < 1)
            {
                notifyListenersTargetLost(target);
            }
            info.updatePosition(position);
        }
        else
        {
            //Realistically we should never get here. This case is stupid.
            targetSightings[target] = new SensoryInfo(position, direction, 0);
            notifyListenersTargetLost(target);
            Debug.LogWarning("Target '" + target.getName() + "' that was never found has been lost. Shenanigans?");
        }
    }
Exemple #35
0
	public void Awake() {
		labelHandle = new LabelHandle(transform.position, name);
		labelHandle.label = this;

		Label.labels.Add(this);
		if (isVisible) {
			visibleLabels.Add(this);
		}
		triggers = new Dictionary<System.Type, List<Operation>>();
		foreach(Operation op in operations) {
			addOperation(op, op.getTriggers());
		}

		foreach (EndeavourFactory endeavour in endeavours) {
			endeavour.setParent(this);
		}

		foreach(Tag tag in tags) {
			tagMap.Add(tag.type, tag);
		}
	}
Exemple #36
0
    private void goToTarget()
    {
        if (target != null)
        {
            if (hasReachedTargetLocation())
            {
                if (!hasMatchedTargetRotation())
                {
                    roboController.transform.rotation = Quaternion.RotateTowards(Quaternion.LookRotation(roboController.transform.forward), Quaternion.LookRotation(target.label.transform.forward), nav.angularSpeed * Time.deltaTime);
                }
                else
                {
                    roboController.enqueueMessage(new RobotMessage(RobotMessage.MessageType.ACTION, "target reached", target, target.getPosition(), null));
                    target = null;
                    return;
                }
            }

            if (nav.enabled)
            {
                nav.speed = regularSpeed;
                nav.SetDestination(target.getPosition());

#if UNITY_EDITOR
                if (roboController.debug)
                {
                    Destroy(dest);
                    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    cube.transform.position = target.getPosition();
                    cube.GetComponent <MeshRenderer>().material.color = Color.green;
                    Destroy(cube.GetComponent <BoxCollider>());
                    cube.transform.localScale = new Vector3(.3f, .3f, .3f);
                    dest = cube;
                }
#endif
            }
        }
    }
    public void Awake()
    {
        labelHandle = new LabelHandle(transform.position, name);
        labelHandle.label = this;

        Label.labels.Add(this);
        if (isVisible) {
            visibleLabels.Add(this);
        }
        triggers = new Dictionary<System.Type, List<Operation>>();
        foreach(Operation op in operations) {
            addOperation(op, op.getTriggers());
        }

        tagMap = new Dictionary<TagEnum, Tag>();
        foreach(Tag tag in tags) {
            if (tag == null) {
                Debug.LogWarning("Null tag attached to '" + name + "'");
            }
            tag.setLabelHandle(labelHandle);
            tagMap.Add(tag.type, tag);
        }
    }
 public PatrolTag(float severity, LabelHandle handle)
     : base(TagEnum.PatrolRoute, severity, handle)
 {
 }
Exemple #39
0
 public void notifySightingLost(LabelHandle target)
 {
     broadcastMessage(new EventMessage("target lost", target));
 }
Exemple #40
0
 public void notifySighting(LabelHandle target)
 {
     broadcastMessage(new EventMessage("target found", target));
 }
 private void unregisterTags(LabelHandle handle)
 {
     List<TagEnum> tags = handle.getTagTypes();
     foreach (TagEnum tag in tags) {
         if (knownTags.ContainsKey(tag)) {
             knownTags[tag].Remove(handle.getTag(tag));
         }
     }
 }
 //TODO velocity must not be null when we improve the investigate system!
 public AudioEvent(Vector3 source, LabelHandle handle, Vector3 sourcePos)
     : base(RobotMessage.MessageType.TARGET_SIGHTED, "sound heard", handle, sourcePos, null)
 {
 }
Exemple #43
0
 internal BranchInfo(int ilOffset, LabelHandle label, byte shortOpCode)
 {
     ILOffset = ilOffset;
     Label = label;
     ShortOpCode = shortOpCode;
 }
Exemple #44
0
 internal void MarkLabel(int ilOffset, LabelHandle label)
 {
     Debug.Assert(ilOffset >= 0);
     ValidateLabel(label);
     _labels[label.Id - 1] = ilOffset;
 }
Exemple #45
0
	public HoldAction(RobotController controller, Label target, LabelHandle source) : base(controller, new List<Goal>{new Goal(GoalEnum.Offense, 3), new Goal(GoalEnum.Protection, 3)}, source ) {
		this.target = target;
		this.name = "grab";
		requiredComponents = new System.Type[] {typeof(RobotArms)};
	}
Exemple #46
0
	public Endeavour(RobotController controller, List<Goal> goals, LabelHandle parent) {
		this.controller = controller;
		this.goals = goals;
		this.parent = parent;

	}
Exemple #47
0
 public override Endeavour constructEndeavour(RobotController controller, LabelHandle target)
 {
     return(new InvestigateAction(controller, this.goals, target));
 }
Exemple #48
0
 public override bool isApplicable(LabelHandle labelHandel)
 {
     return(labelHandel.hasTag(TagEnum.Sound));
 }
Exemple #49
0
 public void MarkLabel(LabelHandle label)
 {
     GetBranchBuilder().MarkLabel(Offset, label);
 }
 private void registerTags(LabelHandle handle)
 {
     List<TagEnum> tags = handle.getTagTypes();
     foreach (TagEnum tag in tags) {
         if (knownTags.ContainsKey(tag)) {
             knownTags[tag].Add(handle.getTag(tag));
             //Debug.Log("registering tag: " + handle.getTag(tag).GetType() + " as " + tag.ToString());
         } else {
             List<Tag> tagList = new List<Tag>();
             tagList.Add(handle.getTag(tag));
             knownTags[tag] = tagList;
             //Debug.Log("registering tag: " + handle.getTag(tag).GetType() + " as " + tag.ToString() );
         }
     }
 }
 public bool knowsTarget(LabelHandle target)
 {
     return targetSightings.ContainsKey(target);
 }
Exemple #52
0
 public bool knowsTarget(LabelHandle target)
 {
     return(targetSightings.ContainsKey(target));
 }
 private void notifyListenersTargetLost(LabelHandle target)
 {
     foreach (Tag tag in target.getTags()) {
         notifyListenersTagRemoved(tag);
     }
 }
	public ScanAtStationAction(RobotController controller, List<Goal> goals, LabelHandle scanStation)
		: base(controller, goals, scanStation) {
		this.name = "scanAtStation";
		this.scanStation = scanStation;
		requiredComponents = new System.Type[] {typeof(HoverJet)};
	}
 private void notifyListenersTargetFound(LabelHandle target)
 {
     foreach (Tag tag in target.getTags()) {
         notifyListenersTagAdded(tag);
     }
 }
Exemple #56
0
 //TODO velocity must not be null when we improve the investigate system!
 public AudioEvent(Vector3 source, LabelHandle handle, Vector3 sourcePos)
     : base(RobotMessage.MessageType.TARGET_SIGHTED, "sound heard", handle, sourcePos, null)
 {
 }
Exemple #57
0
 public bool canSee(LabelHandle target)
 {
     return(targetSightings.ContainsKey(target) && targetSightings[target].getSightings() > 0);
 }
Exemple #58
0
        private void ValidateLabel(LabelHandle label)
        {
            if (label.IsNil)
            {
                throw new ArgumentNullException(nameof(label));
            }

            if (label.Id > _labels.Count)
            {
                // TODO: localize
                throw new ArgumentException("Label not defined", nameof(label));
            }
        }
 public bool canSee(LabelHandle target)
 {
     return targetSightings.ContainsKey(target) && targetSightings[target].getSightings() > 0;
 }