コード例 #1
0
ファイル: ScanAction.cs プロジェクト: Ruthq/OpenCircuit
    public override bool canExecute()
    {
        RobotArms arms = controller.GetComponentInChildren <RobotArms>();
        RoboEyes  eyes = controller.GetComponentInChildren <RoboEyes>();

        return(eyes != null && eyes.hasScanner() && arms != null && arms.hasTarget());
    }
コード例 #2
0
ファイル: HoverJet.cs プロジェクト: Ruthq/OpenCircuit
    public float calculatePathCost(Vector3 targetPos)
    {
        //Debug.Log ("evaluating path cost");
        //Debug.Log(targetPos);
        float       cost = 0;
        NavMeshPath path = new NavMeshPath();

        if (nav.enabled)
        {
            nav.CalculatePath(targetPos, path);
        }
        List <Vector3> corners = new List <Vector3>(path.corners);

        corners.Add(targetPos);
        //corners
        float pathLength = 0;

        foreach (LabelHandle item in roboController.getTrackedTargets())
        {
            //print ("checking path cost against item: " + item.name);
            //print ("target threatLevel " + item.threatLevel);
            float minDist = -1;
            //Vector3 prevVertex;
            //Debug.Log("numCorners: " + corners.Count);
            for (int i = 0; i < corners.Count; i++)
            {
                Vector3 vertex = corners[i];
                if (i > 0)
                {
                    //Debug.Log("adding path length");
                    pathLength += Vector3.Distance(corners[i - 1], vertex);
                }
                float curDist = Vector3.Distance(vertex, item.getPosition());
                if (minDist == -1)
                {
                    minDist = curDist;
                }
                else if (curDist < minDist)
                {
                    minDist = curDist;
                }
            }
            if (item.hasTag(TagEnum.Threat))
            {
                float threatLevel = item.getTag(TagEnum.Threat).severity;

                RoboEyes eyes = roboController.GetComponentInChildren <RoboEyes>();
                if (eyes != null)
                {
                    cost += threatLevel * (minDist / eyes.sightDistance);
                }
            }
        }
        //if (cost > 0) {
        //	print ("path cost: " + cost);
        //}
        //Debug.Log("cost for target " + cost +" "+ "("+pathLength +"*" + distanceCost+")");
        return(cost + (pathLength * distanceCost));
    }
コード例 #3
0
ファイル: ScanAction.cs プロジェクト: Ruthq/OpenCircuit
    public override void stopExecution()
    {
        base.stopExecution();
        RoboEyes eyes = controller.GetComponentInChildren <RoboEyes>();

        if (eyes != null)
        {
            eyes.getScanner().stopScan();
        }
    }
コード例 #4
0
    public override bool isStale()
    {
        RoboEyes eyes   = controller.GetComponentInChildren <RoboEyes>();
        bool     canSee = false;

        if (eyes != null)
        {
            canSee = (eyes.lookAt(parent.getPosition()) == null);
            if (canSee)
            {
                controller.enqueueMessage(new RobotMessage(RobotMessage.MessageType.TARGET_LOST, "target lost", parent, parent.getPosition(), null));
            }
        }
        return(completed || (canSee) || !((System.DateTime.Now - creationTime).Seconds < InvestigateAction.expirationTimeSeconds));
    }