Beispiel #1
0
    private CombatFlow findNearestTarget()
    {
        CombatFlow closestTarget = null;

        // don't bother targeting someone outside of schutDistance
        float shortestDist = maxTargetRange;

        List <CombatFlow> allUnits = CombatFlow.combatUnits;

        for (int i = 0; i < allUnits.Count; i++)
        {
            CombatFlow currentFlow = allUnits[i];
            bool       seeFlow     = false;
            if (currentFlow != null)
            {
                if (currentFlow.team != rootFlow.team && currentFlow.type == CombatFlow.Type.AIRCRAFT)
                {
                    if (radar.tryDetect(currentFlow))
                    {
                        // contribute to datalink network, even if not selecting this as closest target
                        seeFlow = true;

                        float currentDistance = Vector3.Distance(currentFlow.transform.position, transform.position);
                        if (currentDistance < shortestDist)
                        {
                            closestTarget = currentFlow;
                            shortestDist  = currentDistance;
                        }
                    }

                    if (seeFlow)
                    {
                        currentFlow.tryAddSeenBy(rootFlow.photonView.ViewID);
                    }
                    else
                    {
                        currentFlow.tryRemoveSeenBy(rootFlow.photonView.ViewID);
                    }
                }
            }
        }



        return(closestTarget);
    }
Beispiel #2
0
    // once per frame, after physics update
    private void LateUpdate()
    {
        if (localPlayerFlow.isLocalPlayer)
        {
            List <CombatFlow> flowArray = CombatFlow.combatUnits;

            // Loop through all combatUnits
            for (int i = 0; i < CombatFlow.combatUnits.Count; i++)
            {
                if (flowArray[i] != null)
                {
                    // Current CombatFlow to attempt to see
                    CombatFlow currentFlow = flowArray[i];


                    if (currentFlow != null)
                    {
                        TgtHudIcon currentFlowHudIcon = currentFlow.myHudIconRef;

                        if (currentFlowHudIcon != null)
                        {
                            //  =====================  DISTANCE

                            // Distance between this gameobject and target
                            currentFlowHudIcon.currentDistance = Vector3.Distance(currentFlow.transform.position, transform.position);

                            // ======================== LINE OF SIGHT
                            int terrainLayer = 1 << 10; // line only collides with terrain layer
                            currentFlowHudIcon.hasLineOfSight = !Physics.Linecast(transform.position, currentFlow.transform.position, terrainLayer);


                            // ========================  IFF
                            currentFlowHudIcon.isFriendly = localPlayerFlow.team == currentFlow.team;

                            //{ // debug block

                            //    Weapon currentWeap = currentFlow.GetComponent<Weapon>();
                            //    if(currentWeap != null && currentFlow.localOwned)
                            //    {
                            //        Debug.LogWarning(currentFlow.gameObject.name + "'s team is: " + currentFlow.team + ", local player's is : "
                            //            + localPlayerFlow.team);
                            //    }

                            //}


                            // =====================  VISIBILITY

                            // Various conditions will attempt to make this true
                            bool isVisible = false;



                            // Show unit if this is NOT the local player
                            if (!currentFlow.isLocalPlayer && currentFlow.isActive)
                            {
                                if (currentFlow.team == localPlayerFlow.team)
                                {
                                    isVisible = true;
                                }
                                else
                                {
                                    isVisible = Vector3.Distance(currentFlow.transform.position, transform.position) < visibleRange &&
                                                currentFlow.myHudIconRef.hasLineOfSight;
                                    if (!isVisible)
                                    {
                                        isVisible = myRadar.tryDetect(currentFlow);
                                    }
                                }
                            }

                            // if nonfriendly
                            if (currentFlow.team != localPlayerFlow.team && currentFlow.type != CombatFlow.Type.PROJECTILE)
                            {
                                if (isVisible)
                                {
                                    currentFlow.tryAddSeenBy(localPlayerFlow.photonView.ViewID);
                                }
                                else
                                {
                                    currentFlow.tryRemoveSeenBy(localPlayerFlow.photonView.ViewID);
                                }

                                currentFlowHudIcon.dataLink = currentFlow.checkSeen(localPlayerFlow.photonView.ViewID);
                            }

                            //  Send visibility result
                            currentFlowHudIcon.isDetected = isVisible;

                            if (isVisible && prevTarget != null && currentFlow == prevTarget && currentTarget == null)
                            {
                                currentTarget = currentFlow;
                                TgtHudIcon newTargetHudIcon = currentTarget.myHudIconRef;
                                newTargetHudIcon.targetedState = TgtHudIcon.TargetedState.TARGETED;
                                hudControl.mainHud.GetComponent <hudControl>().mapManager.target = currentTarget.transform;
                            }

                            //canShowCurrentTarget = isVisible;

                            if (!isVisible && !currentFlowHudIcon.dataLink && currentTarget == currentFlow)
                            {
                                currentTarget.myHudIconRef.targetedState = TgtHudIcon.TargetedState.NONE;
                                currentTarget = null;
                                //canShowCurrentTarget = false;
                                hudControl.mainHud.GetComponent <hudControl>().mapManager.target = null;
                                playerInput.cam.lookAtObj = null;
                            }

                            // ========= TRY TO LOCK
                            tryLockTarget(currentFlow);
                        }
                    }
                }
            }
        }
    }