Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        isHostInstance = GameManager.getGM().isHostInstance;



        if (PhotonNetwork.PlayerList.Length == 1 || (isHostInstance && GetComponent <CreepControl>() != null))
        {
            localOwned = true;
        }

        //localOwned = isHostInstance;

        explodeStats = GetComponent <ExplodeStats>();

        // spawn icon, set reference here to the TgtHudIconScript of icon spawned
        myHudIconRef = TgtIconManager.tgtIconManager.spawnIcon(this).GetComponent <TgtHudIcon>();// add my icon to hud

        if (!isLocalPlayer)
        {
            spawnRadarIcon();
        }


        if (type == Type.AIRCRAFT)
        {
            GameManager.getGM().getTeamAircraftList(team).Add(this);
        }
    }
Exemplo n.º 2
0
    public void linkToFlow(CombatFlow flow)
    {
        text = GetComponent <Text>();

        linkedFlow = flow;
        //Debug.LogWarning(flow.name + " radar symbol " + flow.radarSymbol);
        text.text       = flow.radarSymbol;
        gameObject.name = flow.gameObject.name + " map icon";
        linkedTgtIcon   = flow.myHudIconRef;
        isLinked        = true;

        showIcon(flow.isActive);

        if (linkedFlow.killCoverageRadius > 100f)
        {
            //Debug.LogError("Creating kill circle for " + linkedFlow.name);
            createRadius();
        }
    }
    public GameObject spawnIcon(CombatFlow unitFlow)
    {
        GameObject iconObj = Instantiate(tgtIconPrefab, transform);

        // initialize icon's data
        TgtHudIcon iconScript = iconObj.GetComponent <TgtHudIcon>();

        iconScript.rootFlow          = unitFlow;
        iconScript.tgtIconManager    = this;
        iconScript.tgtTitleText.text = unitFlow.gameObject.name;

        // IMAGE SETTING
        if (unitFlow.type == CombatFlow.Type.AIRCRAFT)
        {
            iconScript.tgtImageLOS.sprite   = aircraftHudImageLOS;
            iconScript.tgtImageNoLOS.sprite = aircraftHudImageNoLOS;
        }
        else if (unitFlow.type == CombatFlow.Type.PROJECTILE)
        {
            iconScript.tgtImageLOS.sprite   = missileHudImageLOS;
            iconScript.tgtImageNoLOS.sprite = missileHudImageNoLOS;
        }
        else if (unitFlow.type == CombatFlow.Type.GROUND)
        {
            iconScript.tgtImageLOS.sprite   = groundHudImageLOS;
            iconScript.tgtImageNoLOS.sprite = groundHudImageNoLOS;
        }
        else if (unitFlow.type == CombatFlow.Type.ANTI_AIR)
        {
            iconScript.tgtImageLOS.sprite   = antiAirHudImageLOS;
            iconScript.tgtImageNoLOS.sprite = antiAirHudImageNoLOS;
        }
        else if (unitFlow.type == CombatFlow.Type.SAM)
        {
            iconScript.tgtImageLOS.sprite   = SamHudImageLOS;
            iconScript.tgtImageNoLOS.sprite = SamHudImageNoLOS;
        }


        return(iconObj);
    }
Exemplo n.º 4
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);
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 5
0
    // change target to unit closet to zero angle off of camera direction
    public CombatFlow changeTarget()
    {
        //Debug.Log("================== Searching for targets...");
        CombatFlow        newTarget    = null; // default point to currentTarget -- if changeTarget unsuccessful, this won't change
        List <CombatFlow> flowObjArray = CombatFlow.combatUnits;

        if (currentTarget != null && radarLocked)
        {
            if (currentTarget.rwr != null)
            {
                currentTarget.rwr.endNetLock(myRadar);
            }
        }


        float smallestAngle = 180f; //180 is max angle Vector3.angleBetween gives

        // loop through every combatFlow object
        for (short i = 0; i < flowObjArray.Count; i++)
        {
            if (flowObjArray[i] != null)
            {
                CombatFlow currentFlow = flowObjArray[i];

                if (currentFlow != null)
                {
                    float currentAngle = Vector3.Angle(playerInput.cam.camRef.transform.forward, currentFlow.transform.position
                                                       - playerInput.cam.camRef.transform.position);

                    // If maverick is equipped, bias target selection in favor of opponents with Radars


                    if (hardpointController.getActiveHardpoint().weaponTypePrefab.name.Equals("Maverick"))
                    {
                        if (currentFlow.GetComponent <Radar>() != null)
                        {
                            currentAngle *= 0.35f; // halve the angle to make it more likely to be selected
                        }
                        else if (currentFlow.GetComponent <TurretNetworking>() != null)
                        {
                            currentAngle *= 0.6f;
                        }
                    }



                    //if (currentFlow.type == CombatFlow.Type.AIRCRAFT)
                    //{
                    //    Debug.LogWarning(currentFlow + "'s angle is: " + currentAngle + " off camera center");
                    //}
                    //Debug.Log("Current target is: " + currentFlow.gameObject + ", at " + currentAngle + " degrees, smallest angle is: " + smallestAngle + " degrees.");

                    // angle within max, angle smallest, and target is not on same team as localPlayer
                    if ((currentFlow.myHudIconRef.isDetected || currentFlow.myHudIconRef.dataLink) &&
                        //!currentFlow.myHudIconRef.isFar &&
                        currentFlow.isActive &&
                        currentFlow.type != CombatFlow.Type.PROJECTILE && // cannot lock onto projectiles
                        currentAngle < changeTargetMaxAngle &&
                        currentAngle < smallestAngle &&
                        !currentFlow.isLocalPlayer &&
                        currentFlow.team != localPlayerFlow.team

                        )
                    {
                        //Debug.Log("SMALLEST ANGLE: " + currentAngle + " degrees.");
                        smallestAngle = currentAngle;
                        newTarget     = flowObjArray[i].GetComponent <CombatFlow>();
                        prevTarget    = newTarget;
                    }
                }
            }
        }

        if (newTarget != null)
        {
            TgtHudIcon newTargetHudIcon = newTarget.myHudIconRef;
            newTargetHudIcon.targetedState = TgtHudIcon.TargetedState.TARGETED;
            hudControl.mainHud.GetComponent <hudControl>().mapManager.target = newTarget.transform;
        }
        else
        {
            hudControl.mainHud.GetComponent <hudControl>().mapManager.target = null;
        }


        // Debug.Log("New Target is: " + newTarget.gameObject + ", at " + smallestAngle + "degrees off nose");

        if (newTarget != currentTarget) // changing to new target
        {
            if (currentTarget != null)
            {
                // deselect process for previous target
                currentTarget.myHudIconRef.targetedState = TgtHudIcon.TargetedState.NONE;
            }
        }

        return(currentTarget = newTarget);
    }