Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        waited += Time.deltaTime;

        if (waited < Frequency)
        {
            return;
        }
        string     aiLog       = "";
        float      bestAiValue = float.MinValue;
        AiBehavior bestAi      = null;

        AiSupport.GetSupport(gameObject).Refresh();

        //select best AI
        foreach (var ai in Ais)
        {
            ai.TimePassed += waited;
            var aiValue = ai.GetWeight() * ai.WeightMultiplier + Random.Range(0, Confusion);
            aiLog += ai.GetType().Name + ": " + aiValue + "\n";
            if (aiValue > bestAiValue)
            {
                bestAiValue = aiValue;
                bestAi      = ai;
            }
        }

        Debug.Log(aiLog);
        bestAi.Execute();
        waited = 0;
    }
Exemple #2
0
    public override float GetWeight()
    {
        if (support == null)
        {
            support = AiSupport.GetSupport(gameObject);
        }

        if (support.Player.Credits < Cost)
        {
            return(0);
        }

        var students = support.Student.Count;
        var bases    = support.Highobject.Count;

        if (bases == 0)
        {
            return(0);
        }

        if (students >= bases * StudentsPerBase)
        {
            return(0);
        }
        return(1);
    }
Exemple #3
0
    private AiSupport support;          //

    /// <summary>
    /// 得到生产无人机权重
    /// </summary>
    /// <returns></returns>
    public override float GetWeight()
    {
        if (support == null)
        {
            support = AiSupport.GetSupport(gameObject);
        }

        if (support.Player.Credits < Cost)
        {
            return(0);
        }

        var drones = support.Drones.Count;
        var bases  = support.CommandBases.Count;

        if (bases == 0)          //判断是否有生产无人机的建筑
        {
            return(0);
        }

        if (drones >= bases * DronesPerBase)
        {
            return(0);                                          //判断无人机总量是否大于建筑可供给的数量
        }
        return(1);
    }
Exemple #4
0
    public int IncreastPerWave = 10;    //每波增加单位数量


    public override void Execute()
    {
        var ai = AiSupport.GetSupport(this.gameObject);          //获得AI

        Debug.Log(ai.Player.Name + " is attacking");

        int wave = (int)(ai.Drones.Count * SquadSize);

        DronesRequired += IncreastPerWave;

        foreach (var p in RtsManager.Current.Players)
        {
            if (p.IsAi)
            {
                continue;
            }

            for (int i = 0; i < wave; i++)
            {
                var drone = ai.Drones[i];
                var nav   = drone.GetComponent <RightClickNavigation>();
                nav.SendToTarget(p.Location.position);
            }
            return;
        }
    }
    void Start()
    {
        SliderScaleValue         *= Scale;
        this.transform.localScale = SliderScaleValue;

        player = GetComponent <Player>().Info;//获取所属玩家信息

        ai   = AiSupport.GetSupport(this.gameObject);
        info = GetComponent <Believers>();
    }
Exemple #6
0
    public override float GetWeight()
    {
        if (TimePassed < TimeDelay)
        {
            return(0);
        }
        TimePassed = 0;

        var ai = AiSupport.GetSupport(this.gameObject);

        if (ai.Drones.Count < DronesRequired)
        {
            return(0);
        }
        return(1);
    }
    public override float GetWeight()
    {
        if (support == null)
        {
            support = AiSupport.GetSupport(gameObject);
        }
        if (support.Player.Credits < Cost || support.Drones.Count == 0)
        {
            return(0);
        }
        if (support.CommandBases.Count * UnitsPerBase <= support.Drones.Count)
        {
            return(1);
        }

        return(0);
    }
Exemple #8
0
    public override float GetWeight()
    {
        if (support == null)
        {
            support = AiSupport.GetSupport(gameObject);
        }

        if (support.Player.Credits < Cost || support.Student.Count == 0)
        {
            return(0);
        }

        if (support.Highobject.Count * UnitsPerBase <= support.Student.Count)
        {
            return(1);
        }
        return(0);

        return((support.Highobject.Count / UnitsPerBase) * support.Student.Count);
    }
Exemple #9
0
    public GameObject BasePrefab;         //建筑物预设

    public override float GetWeight()     //获得建造权重
    {
        if (support == null)
        {
            support = AiSupport.GetSupport(gameObject);
        }

        if (support.Player.Credits < Cost || support.Drones.Count == 0)          //判断有足够的钱和无人机
        {
            return(0);
        }

        if (support.CommandBases.Count == 0)          //如果没有建筑,则优先建造建筑
        {
            return(1);
        }

        if (support.CommandBases.Count * UnitsPerBase <= support.Drones.Count)
        {
            return(1);
        }

        return(0);
    }
Exemple #10
0
    public override void Execute()
    {
        var ai = AiSupport.GetSupport(this.gameObject);


        int wave = (int)(ai.Student.Count * SquadSize);

        StudentRequired += IncreastPerWave;

        foreach (var p in RtsManager.Current.Players)
        {
            if (p.IsAi)
            {
                continue;
            }
            for (int i = 0; i < wave; i++)
            {
                var students = ai.Student[i];
                var nav      = students.GetComponent <RightClickNavigation>();
                nav.SendToTarget(p.Location.position);
            }
            return;
        }
    }