Esempio n. 1
0
    private ObjDestination getNextDest(ObjDestination examined)
    {
        ObjDestination ans = new ObjDestination(examined.obj, moveQueue[examined.obj].First());

        moveQueue[examined.obj].Remove(moveQueue[examined.obj].First());
        return(ans);
    }
Esempio n. 2
0
 public bool isShipMoving(Ship what)
 {
     for (int i = 0; i < objToMove.Count; i++)
     {
         ObjDestination objNow = objToMove[i];
         if (objNow.obj == what)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
 public Vector3 getDest(Ship ship)
 {
     if (moveQueue.ContainsKey(ship) && moveQueue[ship].Count != 0)
     {
         return(moveQueue[ship][moveQueue[ship].Count - 1]);
     }
     for (int i = 0; i < objToMove.Count; i++)
     {
         ObjDestination objNow = objToMove[i];
         if (objNow.obj == ship)
         {
             return(objNow.coords);
         }
     }
     return(Vector3.zero);
 }
Esempio n. 4
0
    void Update()
    {
        if (objToMove != null && objToMove.Count != 0)
        {
            for (int i = 0; i < objToMove.Count; i++)
            {
                ObjDestination objNow = objToMove[i];
                if (objNow.obj == null)
                {
                    objToMove.Remove(objNow);
                    i--;
                }
                tpLength = objNow.obj.getSpeed() * Time.deltaTime * 60;
                Vector3 position = objNow.obj.transform.position;

                if (++objNow.iteration == 1)
                {
                    objNow.obj.getObj().transform.LookAt(new Vector3(objNow.coords.x, objNow.coords.y, objNow.coords.z));
                    objNow.obj.getObj().transform.Rotate(new Vector3(-90f, 0f, 0f), Space.Self);
                    if (objNow.obj.toString() == "spy")
                    {
                        objNow.obj.getObj().transform.Rotate(new Vector3(0f, 0f, 180f), Space.Self);
                    }
                }

                // making a move by a fixed length, so going straight forward and
                // turning will have the same fixed speed
                Vector3 diff = objNow.coords - position;
                if (VectorUtility.vecLength(objNow.coords, position) + almostZero >= tpLength)
                {
                    diff /= VectorUtility.vecLength(objNow.coords, position);
                    diff *= tpLength;
                    objNow.obj.getObj().transform.position += diff;
                }
                else if (moveQueue.ContainsKey(objNow.obj) && moveQueue[objNow.obj].Count != 0)
                {
                    float rest = tpLength - VectorUtility.vecLength(objNow.coords, position);
                    objNow.obj.getObj().transform.position = objNow.coords;
                    while (rest > almostZero)
                    {
                        if (moveQueue.ContainsKey(objNow.obj) && moveQueue[objNow.obj].Count != 0)
                        {
                            objToMove.RemoveAt(i);
                            objNow = getNextDest(objNow);
                            objToMove.Insert(i, objNow);
                        }
                        else
                        {
                            objNow.obj.getObj().transform.position = objNow.coords;
                            break;
                        }
                        objNow.obj.getObj().transform.LookAt(new Vector3(objNow.coords.x, objNow.coords.y, objNow.coords.z));
                        objNow.obj.getObj().transform.Rotate(new Vector3(-90f, 0f, 0f), Space.Self);
                        if (objNow.obj.toString() == "spy")
                        {
                            objNow.obj.getObj().transform.Rotate(new Vector3(0f, 0f, 180f), Space.Self);
                        }
                        diff = objNow.coords - position;
                        if (VectorUtility.vecLength(objNow.coords, position) + almostZero >= rest)
                        {
                            diff /= VectorUtility.vecLength(objNow.coords, position);
                            diff *= rest;
                            objNow.obj.getObj().transform.position += diff;
                            break;
                        }
                        else
                        {
                            objNow.obj.getObj().transform.position = objNow.coords;
                            rest -= VectorUtility.vecLength(objNow.coords, position);
                        }
                    }
                }
                else
                {
                    objNow.obj.getObj().transform.position = objNow.coords;
                }

                if (objNow.obj.transform.position == objNow.coords)
                {
                    objToMove.Remove(objNow);
                    i--;
                    if (moveQueue.ContainsKey(objNow.obj) && moveQueue[objNow.obj].Count != 0)
                    {
                        objToMove.Add(getNextDest(objNow));
                    }
                    else
                    {
                        // This is very precious source of information, don't delete!
                        //print("AUTO PILOT END IN: " + (Time.time - debugTimer));
                        objNow.obj.getObj().GetComponent <MeshCollider>().enabled = true;
                    }
                }
            }
        }
    }