Exemple #1
0
    //------------------------------------------------------------------------------------------------------------------
    int GetNearestZone(int inStartIndex)
    {
        GameZoneZoneControl gzc = Mission.Instance.GameZone as GameZoneZoneControl;

        if (gzc != null)
        {
            SpawnZoneButton btn;
            int             num  = gzc.Zones.Count;
            int             idx0 = inStartIndex;
            int             dir0 = GetTeamDefensiveMarchDir();
            int             idx1 = inStartIndex;
            int             dir1 = GetTeamOffensiveMarchDir();

            for (int i = num; i > 0; --i)             // prefer defense
            {
                idx0 = (idx0 + dir0 + num) % num;
                btn  = GetSpawnZoneButton(gzc.Zones[idx0]);

                if ((btn != null) && (btn.Zone.FlagOwner == m_SelectedTeam))
                {
                    return(btn.ZoneIndex);
                }

                idx1 = (idx1 + dir1 + num) % num;
                btn  = GetSpawnZoneButton(gzc.Zones[idx1]);

                if ((btn != null) && (btn.Zone.FlagOwner == m_SelectedTeam))
                {
                    return(btn.ZoneIndex);
                }
            }
        }

        return(-1);
    }
Exemple #2
0
    void ValidateSpawnZone()
    {
        if (Mission.Instance == null)
        {
            return;
        }

        GameZoneZoneControl gz = Mission.Instance.GameZone as GameZoneZoneControl;

        if (gz == null || gz.Zones == null || gz.Zones.Count <= 0)
        {
            return;
        }

        List <ZoneControlFlag> spawnZones = gz.Zones;

        if (m_SpawnZoneIndex < 0 || spawnZones.Count <= m_SpawnZoneIndex)
        {
            m_SpawnZoneIndex = -1;
        }
        else if (spawnZones[m_SpawnZoneIndex] == null || spawnZones[m_SpawnZoneIndex].FlagOwner != m_SelectedTeam)
        {
            m_SpawnZoneIndex = -1;
        }

        if (m_SpawnZoneIndex < 0)
        {
            if (m_SelectedTeam == E_Team.Good)
            {
                // get first availible zone, forward...

                for (int i = 0; i < spawnZones.Count; i++)
                {
                    if (spawnZones[i] == null || spawnZones[i].FlagOwner != m_SelectedTeam)
                    {
                        continue;
                    }

                    m_SpawnZoneIndex = i;
                    break;
                }
            }
            else if (m_SelectedTeam == E_Team.Bad)
            {
                // get first availible zone, backward...

                for (int i = spawnZones.Count - 1; i >= 0; i--)
                {
                    if (spawnZones[i] == null || spawnZones[i].FlagOwner != m_SelectedTeam)
                    {
                        continue;
                    }

                    m_SpawnZoneIndex = i;
                    break;
                }
            }
        }
    }
Exemple #3
0
    //------------------------------------------------------------------------------------------------------------------
    int GetNearestZoneToEnemy()
    {
        int   bestZone          = -1;
        float bestDist          = float.MaxValue;
        GameZoneZoneControl gzc = Mission.Instance.GameZone as GameZoneZoneControl;

        if ((m_SelectedTeam != E_Team.None) && (gzc != null) && (m_SpawnButtons != null))
        {
            for (int i = 0; i < m_SpawnButtons.Length; ++i)
            {
                SpawnZoneButton iBtn = m_SpawnButtons[i];

                if ((iBtn == null) || (iBtn.Zone == null) || (iBtn.Zone.FlagOwner != m_SelectedTeam))
                {
                    continue;
                }

                if (bestZone == -1)
                {
                    bestZone = iBtn.ZoneIndex;                     // there is at least one available zone
                }

                for (int j = 0; j < m_SpawnButtons.Length; ++j)
                {
                    SpawnZoneButton jBtn = m_SpawnButtons[j];

                    if ((jBtn == null) || (jBtn.Zone.FlagOwner == m_SelectedTeam))
                    {
                        continue;
                    }

                    float dist = (iBtn.Zone.gameObject.transform.position -
                                  jBtn.Zone.gameObject.transform.position).sqrMagnitude;

                    dist -= 1.0e6f * (int)jBtn.Zone.FlagOwner;                   // prefer zones taken by enemy over the unoccupied ones

                    if (dist < bestDist)
                    {
                        bestDist = dist;
                        bestZone = iBtn.ZoneIndex;
                    }
                }
            }
        }

        return(bestZone);
    }
Exemple #4
0
    // ---------------------
    // Use this for initialization
    protected override bool OnInit()
    {
        if (base.OnInit() == false)
        {
            return(false);
        }

        GUIBase_Layout layout1;
        GUIBase_Layout layout2;

        m_Labels.Clear();
        m_Pivot = MFGuiManager.Instance.GetPivot("MainHUD_ZoneControlLabels");
        layout1 = m_Pivot.GetLayout("Labels1");
        for (int i = 0; i < 4; i++)
        {
            Label l = new Label();
            l.Base      = layout1.GetWidget("ZoneControlFlag" + i);
            l.Distance  = GuiBaseUtils.GetChildNumber(l.Base, "Number");
            l.Transform = l.Base.transform;
            l.alpha     = 0;
            m_Labels.Add(l);
        }
        layout2 = m_Pivot.GetLayout("Labels2");
        for (int i = 4; i < 7; i++)
        {
            Label l = new Label();
            l.Base      = layout2.GetWidget("ZoneControlFlag" + i);
            l.Distance  = GuiBaseUtils.GetChildNumber(l.Base, "Number");
            l.Transform = l.Base.transform;
            l.alpha     = 0;
            m_Labels.Add(l);
        }

        m_FlagData.Clear();
        GameZoneZoneControl zone = Mission.Instance.GameZone as GameZoneZoneControl;

        for (int i = 0; i < 6; i++)
        {
            if (i < zone.Zones.Count)
            {
                m_FlagData.Add(new FlagInfo(zone.Zones[i]));
            }
        }

        return(true);
    }
Exemple #5
0
    void InitZoneButtons()
    {
        GameZoneZoneControl gz = null;

        if (Mission.Instance != null)
        {
            gz = Mission.Instance.GameZone as GameZoneZoneControl;
        }

        // initialize spawn zone buttons...
        List <ZoneControlFlag> spawnZones = (gz != null) ? gz.Zones : null;

        for (int i = 0; i < m_SpawnButtons.Length; i++)
        {
            int             zoneIndex  = i;
            string          buttonName = "MapSpawn_" + (i + 1) + "_Button";
            GUIBase_Button  button     = Parent.transform.GetChildComponent <GUIBase_Button>(buttonName);
            ZoneControlFlag zone       = (spawnZones != null && i < spawnZones.Count && spawnZones[i] != null) ? spawnZones[i] : null;

            m_SpawnButtons[i] = new SpawnZoneButtonEx(button, buttonName, zoneIndex, zone, SetSpawnIndex);
        }

        UpdateZoneButtons(m_SelectedTeam, m_SpawnZoneIndex);
    }
Exemple #6
0
    //------------------------------------------------------------------------------------------------------------------
    int GetNextZone(int inStartIndex, int inDirection)
    {
        GameZoneZoneControl gzc = Mission.Instance.GameZone as GameZoneZoneControl;

        if (gzc != null)
        {
            SpawnZoneButton btn;
            int             num = gzc.Zones.Count;
            int             idx = inStartIndex;

            for (int i = num; i > 0; --i)
            {
                idx = (idx + inDirection + num) % num;
                btn = GetSpawnZoneButton(gzc.Zones[idx]);

                if ((btn != null) && (btn.Zone.FlagOwner == m_SelectedTeam))
                {
                    return(btn.ZoneIndex);
                }
            }
        }

        return(-1);
    }
Exemple #7
0
    // ---------------------------------------------------------------------------------------------------------------------------------
    //                      P U B L I C      P A R T
    // ---------------------------------------------------------------------------------------------------------------------------------

    // ---------
    protected override bool OnInit()
    {
        if (base.OnInit() == false)
        {
            return(false);
        }

        //m_DetectedAgents = null;

        m_FlagData.Clear();
        GUIBase_Pivot pivot = MFGuiManager.Instance.GetPivot(s_PivotMainName);

        if (!pivot)
        {
            Debug.LogError("'" + s_PivotMainName + "' not found!!! Assert should come now");
            return(false);
        }
        GUIBase_Layout layout = pivot.GetLayout(s_LayoutMainName);

        if (!layout)
        {
            Debug.LogError("'" + s_LayoutMainName + "' not found!!! Assert should come now");
            return(false);
        }

        Radar       = layout.GetWidget(s_RadarName).GetComponent <GUIBase_Widget>();
        RadarBkg    = layout.GetWidget(s_RadarBackgroundName).GetComponent <GUIBase_Sprite>();
        RadarCenter = layout.GetWidget(s_RadarCenterName).GetComponent <GUIBase_Sprite>();
        Pulse       = layout.GetWidget(s_PulseName).GetComponent <GUIBase_Sprite>();
        Pulse.transform.localScale = Vector3.zero;
        Pulse.Widget.SetModify();
        PulseTimer = 0;

        RadarEnemies = new GUIBase_Sprite[s_RadarEnemyNames.Length];
        int index = 0;

        foreach (string name in s_RadarEnemyNames)
        {
            RadarEnemies[index++] = layout.GetWidget(name).GetComponent <GUIBase_Sprite>();
        }

        PlayerPersistantInfo ppi = (Player.LocalInstance) ? PPIManager.Instance.GetPPI(Player.LocalInstance.networkView.owner) : null;

        //E_Team                    playerTeam	= (ppi != null) ? ppi.Team : E_Team.None;
        RadarFriends = new RadarFriend[s_RadarFriendNames.Length];
        index        = 0;
        foreach (string name in s_RadarFriendNames)
        {
            RadarFriends[index] = new RadarFriend(layout.GetWidget(name).GetComponent <GUIBase_MultiSprite>());
            ++index;
        }

        // ------
        GameZoneZoneControl zone = Mission.Instance.GameZone as GameZoneZoneControl;

        if (zone != null)
        {
            foreach (ZoneControlFlag flag in zone.Zones)
            {
                m_FlagData.Add(new FlagInfo(flag));
            }
        }
        foreach (FlagInfo flagInfo in m_FlagData)
        {
            index = flagInfo.Flag.ZoneNameIndex - 0500480;
            if ((index < 0) || (index > s_RadarFlagNames.Length))
            {
                Debug.LogWarning("Can't translate Flag.ZoneNameIndex into index for radar!");
                m_FlagData.Clear();
                break;
            }
            else
            {
                flagInfo.RadarFlag = layout.GetWidget(s_RadarFlagNames[index]).GetComponent <GUIBase_Sprite>();
            }
        }
        RadarFlags = new GUIBase_Sprite[s_RadarFlagNames.Length];
        index      = 0;
        foreach (string name in s_RadarFlagNames)
        {
            RadarFlags[index] = layout.GetWidget(name).GetComponent <GUIBase_Sprite>();
            ++index;
        }
        // ------

        Transform radarTrans = Radar.transform;
        Vector3   lossyScale = radarTrans.lossyScale;

        //Debug.Log("Radar.Widget.m_Width: "+Radar.Widget.m_Width);
        Vector2 size = new Vector2(RadarBkg.Widget.GetWidth() - 60, RadarBkg.Widget.GetWidth() - 60);

        // layout.LayoutSpaceDeltaToScreen(new Vector2(RadarBkg.Widget.m_Width - 16, RadarBkg.Widget.m_Width - 16));
        size.x            = size.x * lossyScale.x;
        size.y            = size.y * lossyScale.y;
        RadarScreenRadius = size.x / 2.0f;
        size = new Vector2(RadarCenter.Widget.GetWidth(), RadarCenter.Widget.GetWidth());
        //layout.LayoutSpaceDeltaToScreen(new Vector2(RadarCenter.Widget.m_Width, RadarCenter.Widget.m_Width));
        size.x            *= lossyScale.x;
        size.y            *= lossyScale.y;
        RadarCenterRadius  = size.x / 2.0f;
        RadarScreenRadius -= RadarCenterRadius;

        RadarRange  = RadarMaxRange;
        HasDetector = false;
        // -----
        if (Player.LocalInstance)
        {
            ppi = PPIManager.Instance.GetPPI(Player.LocalInstance.Owner.NetworkView.owner);
            foreach (PPIItemData d in ppi.EquipList.Items)
            {
                ItemSettings item = ItemSettingsManager.Instance.Get(d.ID);
                if (item.ItemBehaviour == E_ItemBehaviour.Detector)
                {
                    HasDetector = true;
                    break;
                }
            }
        }

        return(true);
    }
Exemple #8
0
    //------------------------------------------------------------------------------------------------------------------
    void InitZoneButtons()
    {
        // find death-match-map definition...

        GameZoneZoneControl gzc = null;

        if (Mission.Instance != null)
        {
            gzc = Mission.Instance.GameZone as GameZoneZoneControl;
        }

        if ((gzc == null) || (gzc.Zones == null))
        {
            return;
        }

        DominationMapDefinition def = m_Def.GetComponentInChildren <DominationMapDefinition>();

        if ((def == null) || (def.m_SpawnZones == null) || (def.m_SpawnZones.Length == 0))
        {
            return;
        }

        // init on mini-map buttons...

        int bNum = 0;

        m_SpawnButtons = new SpawnZoneButton[def.m_SpawnZones.Length];

        for (int i = 0; i < def.m_SpawnZones.Length; ++i)
        {
            DominationMapDefinition.SpawnZoneData zoneDef = def.m_SpawnZones[i];

            if ((zoneDef.m_SpawnZone == null) || (zoneDef.m_MiniMapButton == null))
            {
                Debug.LogWarning("MiniMapDefinition : Record #" + i + " in 'Spawn Zones' is invalid!");
                continue;
            }

            int zoneIndex = gzc.Zones.FindIndex(sz => sz == zoneDef.m_SpawnZone);

            if (zoneIndex == -1)
            {
                Debug.LogWarning("MiniMapDefinition : Record #" + i + " in 'Spawn Zones' is referencing 'unknown' zone!");
                continue;
            }

            m_SpawnButtons[i] = new SpawnZoneButton(zoneDef.m_MiniMapButton, zoneDef.m_SpawnZone, zoneIndex, OnZoneSelected);

            bNum++;
        }

        //	Debug.LogInfo( "Successfully created " + bNum + " spawn-zone buttons." );

        // init prev/next buttons...

        Transform child = m_MapParent.transform.FindChildByName("SpawnPoint_Enum");

        if (child != null)
        {
            GUIBase_Button prev = child.GetChildComponent <GUIBase_Button>("GUI_enum_left");
            GUIBase_Button next = child.GetChildComponent <GUIBase_Button>("GUI_enum_right");

            if (prev != null)
            {
                prev.RegisterTouchDelegate2(SelectPrevZone);
                prev.SetDisabled(bNum == 0);
            }
            if (next != null)
            {
                next.RegisterTouchDelegate2(SelectNextZone);
                next.SetDisabled(bNum == 0);
            }

            m_SpawnZoneLabel = child.GetChildComponent <GUIBase_Label>("Spawn_Label");

            if (m_SpawnZoneLabel != null)
            {
                m_SpawnZoneLabel.SetNewText(string.Empty);
            }
        }
    }