Example #1
0
 // Use this for initialization
 void Start()
 {
     line = GetComponent <LineRenderer>();
     prod = GetComponent <UnitProducer>();
     if (line == null)
     {
         line = gameObject.AddComponent <LineRenderer>();
         var mat = new Material(Shader.Find("Sprites/Default"));
         mat.color       = prod.TeamIndex == 0 ? Color.cyan : Color.red;
         line.material   = mat;
         line.startWidth = line.endWidth = lineWidth;
     }
 }
Example #2
0
 public DonateOrder(UnitProducer prod)
 {
     this.prod           = prod;
     this.targetLocation = prod.spawnLocation.position;
     location            = prod.spawnLocation.position;
 }
Example #3
0
    void OnRightClick(Ray ray)
    {
        // The general idea here is to preform a raycast from the camera and see if we hit anything we can select

        RaycastHit hit;

        Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, 1000f);



        if (hit.transform != null)
        {
            UnitBase     unit = hit.transform.gameObject.GetComponent <UnitBase>();
            UnitProducer prod = hit.transform.gameObject.GetComponent <UnitProducer>();
            if (hit.transform.CompareTag("Terrain")) // We hit somewhere we can move to
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    SelectionManager.instance.AddOrder(new MoveOrder(hit.point));
                }
                else
                {
                    SelectionManager.instance.IssueOrder(new MoveOrder(hit.point));
                }
            }

            else if (prod != null && prod.TeamIndex == SelectionManager.instance.TeamIndex)
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    SelectionManager.instance.AddOrder(new DonateOrder(prod));
                }
                else
                {
                    SelectionManager.instance.IssueOrder(new DonateOrder(prod));
                }
            }

            else if (prod != null && prod.TeamIndex != SelectionManager.instance.TeamIndex && prod.convertable)
            {
                print("Issuing donate order");
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    SelectionManager.instance.AddOrder(new DonateOrder(prod));
                }
                else
                {
                    SelectionManager.instance.IssueOrder(new DonateOrder(prod));
                }
            }

            else if (unit != null && unit.isSelectable && unit.TeamIndex != SelectionManager.instance.TeamIndex)
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    SelectionManager.instance.AddOrder(new AttackOrder(hit.transform));
                }
                else
                {
                    SelectionManager.instance.IssueOrder(new AttackOrder(hit.transform));
                }
            }
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        List <UnitProducer> ownedFactories   = new List <UnitProducer>();
        List <UnitProducer> neutralFactories = new List <UnitProducer>();
        List <UnitProducer> enemyFactories   = new List <UnitProducer>();


        foreach (var factory in UnitProducer.FactoryList)
        {
            if (factory.TeamIndex == AI_INDEX)
            {
                ownedFactories.Add(factory);
            }
            else if (factory.TeamIndex == 0)
            {
                enemyFactories.Add(factory);
            }
            else
            {
                neutralFactories.Add(factory);
            }
        }


        foreach (var factory in ownedFactories)
        {
            if (factory.standingOrder != null && factory.standingOrder as DonateOrder != null)
            {
                var donation = factory.standingOrder as DonateOrder;
                if (donation.prod.TeamIndex == 1)
                {
                    factory.standingOrder = null;
                }
            }

            if (factory.standingOrder != null)
            {
                continue;
            }
            if (neutralFactories.Count > 0)
            {
                UnitProducer closest   = null;
                float        closeDist = float.MaxValue;
                foreach (var other in neutralFactories)
                {
                    var dist = Vector3.Distance(factory.transform.position, other.transform.position);
                    if (closest == null || dist < closeDist)
                    {
                        closest   = other;
                        closeDist = dist;
                    }
                }
                factory.SetOrder(new DonateOrder(closest));
            }
            else
            {
                UnitProducer closest   = null;
                float        closeDist = float.MaxValue;
                foreach (var other in enemyFactories)
                {
                    var dist = Vector3.Distance(factory.transform.position, other.transform.position);
                    if (closest == null || dist < closeDist)
                    {
                        closest   = other;
                        closeDist = dist;
                    }
                }

                if (closest.convertable)
                {
                    factory.SetOrder(new DonateOrder(closest));
                }
                else
                {
                    factory.SetOrder(new AttackOrder(closest.transform));
                }
            }
        }
    }