コード例 #1
0
ファイル: Ticks.cs プロジェクト: thegamedesigner/cff
    public static GameState CreateGameState()
    {
        //Prepare a gameState
        GameState g  = new GameState();       //gamestate. A GameState is a list of GameItems.
        GameState cg = new GameState();       //Complete gamestate. Not pared down based on what has changed.

        g.timeStamp = Time.timeSinceLevelLoad;

        //Create some temp lists to fill
        List <GameItem> items = new List <GameItem>();

        if (ObjFuncs.objs.Count <= 0)
        {
            return(null);
        }
        //loop through every object
        for (int i = 0; i < ObjFuncs.objs.Count; i++)
        {
            //do this part
            ObjFuncs.Obj o = ObjFuncs.objs[i];

            //Add all the syncd vars,
            //whether or not they're different from last time
            //(this is moving them into the same format, so I can more easily check if they've changed from last time)

            //Goal
            GameItem item = new GameItem();
            item.uId         = o.uId;
            item.syncdVar    = (int)SyncdVars.Goal;
            item.newValue    = new float[3];
            item.newValue[0] = o.goal.x;
            item.newValue[1] = o.goal.y;
            item.newValue[2] = o.goal.z;
            items.Add(item);
        }

        //Copy to cg, CompleteGamestate, so I can store that.
        cg.items = new GameItem[items.Count];
        for (int i = 0; i < cg.items.Length; i++)
        {
            cg.items[i]          = new GameItem();
            cg.items[i].uId      = items[i].uId;
            cg.items[i].syncdVar = items[i].syncdVar;
            cg.items[i].newValue = items[i].newValue;
        }
        completeGameStates.Add(cg);

        //Now compare it to the last complete game state, and cut out all the parts that haven't changed values
        //...Do this here...
        if (completeGameStates.Count > 2)
        {
            g = CompareTicks(items, completeGameStates[completeGameStates.Count - 2]);
            if (g == null)
            {
                Debug.Log("Something is wrong. This should never return null.");
            }
        }
        else
        {
            g = cg;            //Just send the full state. There has only ever been 1 tick so far.
        }
        //(dont bother right now, just send complete game states until the system is proven to work, then add this)

        return(g);
    }
コード例 #2
0
ファイル: Ticks.cs プロジェクト: thegamedesigner/vrt
    public static float[] CreateCompleteGameState()    //Returns entire game state. Does zero paring down.
    {
        //Prepare a gameState
        List <float> s = new List <float>();


        //Add svTime
        s.Add(hl.svTime);        //The first float is always the time, so it functions as a time stamp

        //loop through every peer
        if (hl.peers != null)
        {
            for (int i = 0; i < hl.peers.Count; i++)
            {
                //Pop
                s.Add((float)Type.Pop);
                s.Add(5);        //Number of floats, including this one
                s.Add(hl.peers[i].uId);
                s.Add(hl.peers[i].pop);
                s.Add(hl.peers[i].maxPop);

                //Money
                s.Add((float)Type.Money);
                s.Add(5);        //Number of floats, including this one
                s.Add(hl.peers[i].uId);
                s.Add(hl.peers[i].money);
                s.Add(hl.peers[i].moneyIncrease);

                //Muntions
                s.Add((float)Type.Muntions);
                s.Add(5);        //Number of floats, including this one
                s.Add(hl.peers[i].uId);
                s.Add(hl.peers[i].munitions);
                s.Add(hl.peers[i].munitionsIncrease);

                //Fuel
                s.Add((float)Type.Fuel);
                s.Add(5);        //Number of floats, including this one
                s.Add(hl.peers[i].uId);
                s.Add(hl.peers[i].fuel);
                s.Add(hl.peers[i].fuelIncrease);
            }
        }

        //loop through every object
        for (int i = 0; i < ObjFuncs.objs.Count; i++)
        {
            //do this part
            ObjFuncs.Obj o = ObjFuncs.objs[i];

            //Goal
            s.Add((float)Type.ObjGoal);
            s.Add(6);            //Number of floats, including this one
            s.Add(o.uId);
            s.Add(o.goal.x);
            s.Add(o.goal.y);
            s.Add(o.goal.z);

            //Health
            s.Add((float)Type.ObjHealth);
            s.Add(4);            //Number of floats, including this one
            s.Add(o.uId);
            s.Add(o.health);
        }

        //Done. Return this as a float array
        float[] cgs = new float[s.Count];
        for (int i = 0; i < cgs.Length; i++)
        {
            cgs[i] = s[i];
        }
        return(cgs);
    }
コード例 #3
0
    public static void SvSideCombat()
    {
        //Figure out combat
        List <ObjFuncs.Obj> objs            = ObjFuncs.objs;
        List <int>          possibleTargets = new List <int>();
        RaycastHit          hit;

        for (int i = 0; i < objs.Count; i++)
        {
            ObjFuncs.Obj o = objs[i];

            /*
             * if (o.range > 0 && o.attachedTo != -1)//Is a gun, and is attached to a unit
             * {
             *      if (Time.timeSinceLevelLoad > (o.firingTimeSet + o.firingDelay))
             *      {
             *              o.firingTimeSet = Time.timeSinceLevelLoad;
             *
             *              Vector3 origin;
             *              Vector3 ang;
             *              Vector3 leftPos;
             *              Vector3 rightPos;
             *              Vector3 centerPos;
             *
             *              origin = o.go.transform.position;
             *              ang = o.go.transform.eulerAngles;
             *              centerPos = MathFuncs.ProjectVec(origin, ang, o.range, Vector3.forward);
             *              leftPos = MathFuncs.ProjectVec(origin, new Vector3(ang.x, ang.y + o.firingConeAngle, ang.z), o.range, Vector3.forward);
             *              rightPos = MathFuncs.ProjectVec(origin, new Vector3(ang.x, ang.y - o.firingConeAngle, ang.z), o.range, Vector3.forward);
             *
             *              //Loop through every other object
             *              for (int a = 0; a < objs.Count; a++)
             *              {
             *                      ObjFuncs.Obj o2 = objs[a];
             *                      if (o2.ownedByClId != o.ownedByClId && o2.health > 0)//If owned by other player
             *                      {
             *                              if (MathFuncs.DistXZ(o.go.transform.position, o2.go.transform.position) <= o.range)
             *                              {
             *                                      //Check if it's within the firing cone
             *                                      if (MathFuncs.CheckCone(o.range, o.firingConeAngle * 0.5f, ang.y, origin, o2.go.transform.position, true))
             *                                      {
             *                                              //Can I raytrace to this point?
             *                                              LayerMask mask = xa.de.CombatMask;//Layers.ReturnMaskForClId(o2.ownedByClId);
             *                                              //Effects.DrawLine(origin, o2.go.transform.position, 0.05f, Effects.Colors.Orange);
             *                                              if (Physics.Linecast(origin, o2.go.transform.position, out hit, mask))
             *                                              {
             *                                                      //If this object is in range
             *                                                      possibleTargets.Add(a);
             *                                              }
             *                                      }
             *                              }
             *                      }
             *              }
             *
             *
             *              int target = -1;
             *              if (possibleTargets.Count > 0)
             *              {
             *                      //Now pick something from the list of possible targets
             *                      int highestValue = -1;
             *                      for (int a = 0; a < possibleTargets.Count; a++)
             *                      {
             *                              if (objs[possibleTargets[a]].priorityValue > highestValue)
             *                              {
             *                                      target = possibleTargets[a];
             *                                      highestValue = objs[possibleTargets[a]].priorityValue;
             *                              }
             *                      }
             *              }
             *              else
             *              {
             *                      //Nothing is viable
             *              }
             *
             *              if (target != -1)
             *              {
             *                      //Draw a line
             *                      Debug.Log("BANG! " + Time.timeSinceLevelLoad);
             *                      Effects.DrawLine(o.go.transform.position, ObjFuncs.objs[target].go.transform.position, 0.2f, Effects.Colors.Yellow);
             *                      ObjFuncs.objs[target].health -= Random.Range(o.minDam,o.maxDam);
             *                      if(ObjFuncs.objs[target].health < 0) {ObjFuncs.objs[target].health = 0; }
             *
             *                      ObjFuncs.objs[target].textMesh.text = "" + ObjFuncs.objs[target].health;
             *              }
             *      }
             * }
             */
        }
    }