Exemple #1
0
 public void FShowOffensivePlay(DATA_OffPlay offPlay, PLY_SnapSpot snapSpot)
 {
     for (int i = 0; i < offPlay.mRoles.Length; i++)
     {
         // figure out where they start first.
         Vector2        vStart = new Vector2();
         DATA_Formation f      = IO_Formations.FLOAD_FORMATION(offPlay.mFormation);
         for (int j = 0; j < f.mSpots.Length; j++)
         {
             if (f.mTags[j] == offPlay.mTags[i])
             {
                 vStart    = f.mSpots[j];
                 vStart.y *= -1f;
             }
         }
         if (offPlay.mRoles[i] == "BLOCK")
         {
             RenderPassBlock(vStart, snapSpot);
         }
         // We have to first get the route data.
         else if (offPlay.mRoles[i] == "ROUTE")
         {
             for (int j = 0; j < offPlay.mRoutes.Count; j++)
             {
                 if (offPlay.mRoutes[j].mOwner == offPlay.mTags[i])
                 {
                     // now we render the route piece by piece.
                     RenderRoute(offPlay.mRoutes[j].mSpots, vStart, snapSpot);
                 }
             }
         }
     }
 }
Exemple #2
0
    // This has nasty side effects. For one, overwrites existing roles.
    private void SetUpNewFormation(string name)
    {
        // ----------------------------- Destroy the old spawned items
        ED_OP_Ply[] plys = FindObjectsOfType <ED_OP_Ply>();
        foreach (ED_OP_Ply p in plys)
        {
            Destroy(p.gameObject);
        }

        // ----------------------------- Clear the play data.
        mPlay.mName      = "NAME ME";
        mPlay.mFormation = name;
        mPlay.mRoutes.Clear();

        // ----------------------------- Spawn the new formation.
        mAths.Clear();
        DATA_Formation f = IO_Formations.FLOAD_FORMATION(name);

        for (int i = 0; i < f.mSpots.Length; i++)
        {
            int x = (int)mSnapSpot.x;
            int y = (int)mSnapSpot.y;
            x += (int)(f.mSpots[i].x / 2);
            y += (int)f.mSpots[i].y / 2;
            Vector3 vPos  = rGrid.FGetPos(x, y);
            var     clone = Instantiate(PF_Ath, vPos, transform.rotation);
            clone.rectTransform.SetParent(rGrid.transform);

            ED_OP_Ply p = clone.GetComponent <ED_OP_Ply>();
            p.mTag  = f.mTags[i];
            p.mRole = "NO_ROLE";
            if (p.mTag.Contains("OL"))
            {
                p.mRole = "BLOCK";
            }
            else if (p.mTag.Contains("QB"))
            {
                p.mRole = "QB";
            }
            p.mIxX = x;
            p.mIxY = y;
            mAths.Add(p);
        }

        // --------------------------- Clear the active route list and the graphics.
        rRouteNodes.Clear();
        DestroyJobGraphics();
    }
Exemple #3
0
    public void BT_SaveFormation()
    {
        if (mNameField.text == "")
        {
            Debug.Log("ERROR. No Name");
            return;
        }
        // Formations are saved using the personnel data. RB->TE. So 2WR, 1RB, 2TE becomes 12
        DATA_Formation f     = new DATA_Formation();
        int            numRB = 0;
        int            numTE = 0;

        foreach (ED_FM_Ply p in mAths)
        {
            if (p.mTag.Contains("TE"))
            {
                numTE++;
            }
            else if (p.mTag.Contains("RB"))
            {
                numRB++;
            }
        }
        f.mName = numRB + "-" + numTE + "_" + mNameField.text;
        ED_FM_Ply[] players = FindObjectsOfType <ED_FM_Ply>();
        f.mSpots = new Vector2[players.Length];
        f.mTags  = new string[players.Length];
        for (int i = 0; i < players.Length; i++)
        {
            Vector2 v = new Vector2();
            v.y         = players[i].y * 2;
            v.x         = (players[i].x - rGrid.mAxisLength / 2) * 2;
            f.mSpots[i] = v;
            f.mTags[i]  = players[i].mTag;
        }

        IO_Formations.FWRITE_FORMATION(f);
        mSavedText.FSetVisible();

        PopulateDropdownList();
    }
    // I still want this to return a valid new formation every time, not a reference to the already loaded one. Subject to change.
    public static DATA_Formation FLOAD_FORMATION(string sName)
    {
        string sPath = Application.dataPath + "/FILE_IO/Formations/" + sName + ".txt";

        string[] sLines = System.IO.File.ReadAllLines(sPath);

        DATA_Formation f = new DATA_Formation();

        for (int i = 0; i < sLines.Length; i++)
        {
            if (sLines[i].Contains("NUM PLAY"))
            {
                int numPlayers = int.Parse(sLines[i + 1]);
                f.mTags  = new string[numPlayers];
                f.mSpots = new Vector2[numPlayers];
            }
        }

        for (int i = 0; i < sLines.Length; i++)
        {
            if (sLines[i].Contains("NAME"))
            {
                f.mName = sLines[i + 1];
            }

            if (sLines[i].Contains("POSITIONS AND"))
            {
                int ind = i + 1;
                for (int j = 0; j < f.mTags.Length; j++)
                {
                    f.mTags[j]  = sLines[ind++];
                    f.mSpots[j] = UT_Strings.FGetVecFromString(sLines[ind++]);
                }
            }
        }

        return(f);
    }
Exemple #5
0
    private void LoadAndDisplayFormation(string name)
    {
        DATA_Formation f = IO_Formations.FLOAD_FORMATION(name);

        Debug.Log("Num Players: " + f.mSpots.Length);
        for (int i = 0; i < f.mSpots.Length; i++)
        {
            int x = (int)mSnapSpot.x;
            // int y = (int)mSnapSpot.y;
            int y = 0;
            x += (int)(f.mSpots[i].x / 2);
            y += (int)f.mSpots[i].y / 2;
            Vector3 vPos  = rGrid.FGetPos(x, y);
            var     clone = Instantiate(PF_Player, vPos, transform.rotation);
            clone.rectTransform.SetParent(rGrid.transform);

            ED_FM_Ply p = clone.GetComponent <ED_FM_Ply>();
            p.mTag = f.mTags[i];
            p.x    = x;
            p.y    = y;
            mAths.Add(p);
        }
    }
    public static void FWRITE_FORMATION(DATA_Formation f)
    {
        if (f.mSpots.Length != f.mTags.Length)
        {
            Debug.Log("ERROR SAVING FORMATION, spot tag length mismatch");
            return;
        }

        string       sName = f.mName;
        StreamWriter sw    = new StreamWriter(Application.dataPath + "/FILE_IO/Formations/" + sName + ".txt");

        sw.WriteLine("NAME");
        sw.WriteLine(f.mName);
        sw.WriteLine("NUM PLAYERS");
        sw.WriteLine(f.mSpots.Length);
        sw.WriteLine("POSITIONS AND TAGS");
        for (int i = 0; i < f.mSpots.Length; i++)
        {
            sw.WriteLine(f.mTags[i]);
            sw.WriteLine(UT_Strings.FConvertVecToString(f.mSpots[i]));
        }

        sw.Close();
    }
    public void FSetUpPlayers(string sOffName, PLY_SnapSpot rSnapSpot)
    {
        DATA_OffPlay p = IO_OffensivePlays.FLoadPlay(sOffName);

        Debug.Log("About to run: " + p.mName);

        DATA_Formation f = IO_Formations.FLOAD_FORMATION(p.mFormation);

        Debug.Log("From this formation: " + f.mName);

        List <PRAC_Off_Ply> plys = new List <PRAC_Off_Ply>();

        // --------------- Set up the players according to the formation.
        for (int i = 0; i < f.mTags.Length; i++)
        {
            Vector3 vSpot = new Vector3();
            vSpot.x = f.mSpots[i].x;
            vSpot.z = f.mSpots[i].y * -1f;
            vSpot.y = 0f;
            vSpot  += rSnapSpot.transform.position;
            var clone = Instantiate(PF_OffPlayer, vSpot, transform.rotation);
            clone.mTag = f.mTags[i];

            plys.Add(clone);
        }

        // ---------------- Now give the players their roles.
        for (int i = 0; i < p.mTags.Length; i++)
        {
            for (int j = 0; j < plys.Count; j++)
            {
                if (plys[j].mTag == p.mTags[i])
                {
                    plys[j].mRole = p.mRoles[i];
                }
            }
        }

        // --------------- Assign all the routes to the proper receivers.
        for (int i = 0; i < p.mRoutes.Count; i++)
        {
            for (int j = 0; j < plys.Count; j++)
            {
                if (plys[j].mTag == p.mRoutes[i].mOwner)
                {
                    plys[j].mSpots = p.mRoutes[i].mSpots;
                    for (int k = 0; k < plys[j].mSpots.Count; k++)
                    {
                        Vector2 v = plys[j].mSpots[k];
                        v.y *= -1f;
                        plys[j].mSpots[k] = v;
                    }
                }
            }
        }

        // --------------------------- Shove the player "into" the QB position.
        for (int i = 0; i < plys.Count; i++)
        {
            if (plys[i].mTag == "QB")
            {
                FindObjectOfType <PC_Controller>().transform.position = plys[i].transform.position;
            }
        }

        return;
    }