Exemplo n.º 1
0
 public FindDivision(DivisionController controller, DivisionController commanderSendingOrder, RememberedDivision finish)
 {
     this.commanderSendingOrder = commanderSendingOrder;
     this.controller            = controller;
     this.finish = finish;
     this.target = null;
 }
Exemplo n.º 2
0
 public void SendOrderTo(RememberedDivision to, Order order, ref Dictionary <int, RememberedDivision> rememberedDivisions)
 {
     SendOrdersTo(to, new List <Order>()
     {
         order
     }, ref rememberedDivisions);
 }
Exemplo n.º 3
0
    private void SendHeartBeat(ControlledDivision Host)
    {
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(Host, CommanderSendingOrderId);
        RememberedDivision rememberedTarget      = GetRememberedDivisionFromHost(Host, RememberedTargetId);

        Host.SendOrdersTo(rememberedTarget, new List <Order>(), ref Host.RememberedDivisions);

        /*
         * DivisionController HeartBeatMessenger;
         * if (Host.TryCreateNewDivision(out HeartBeatMessenger))
         * {
         *  HeartBeatMessenger.name = "Heatbeat messenger";
         *
         *  Debug.Log($" heartbeat {Host.DivisionId} {RememberedTargetId}");
         *  HeartBeatMessenger.AttachedDivision.ReceiveOrders(
         *      new List<Order>()
         *      {
         *      new FindDivision(
         *          HeartBeatMessenger.AttachedDivision,
         *          Host.DivisionId,
         *          RememberedTargetId),
         *      new SendMessage(
         *          HeartBeatMessenger.AttachedDivision,
         *          Host.DivisionId,
         *          new List<Order>(),
         *          RememberedTargetId,
         *          Host.DivisionId)
         *      });
         *
         * }
         */
    }
Exemplo n.º 4
0
    //returns the chain of command to a subordinate
    public List <RememberedDivision> FindDivisionInSubordinates(RememberedDivision start, RememberedDivision end, List <RememberedDivision> prev_, ref Dictionary <int, RememberedDivision> rememberedDivisions)
    {
        List <RememberedDivision> prev = new List <RememberedDivision>(prev_);

        prev.Add(start);
        if (start.DivisionId == end.DivisionId)
        {
            return(prev);
        }

        foreach (int subordinateId in start.Subordinates)
        {
            if (rememberedDivisions.TryGetValue(subordinateId, out RememberedDivision division))
            {
                //RememberedDivision division = rememberedDivisions[subordinateId];
                List <RememberedDivision> temp = FindDivisionInSubordinates(division, end, prev, ref rememberedDivisions);
                if (temp != null)
                {
                    return(temp);
                }
            }
        }

        return(null);
    }
Exemplo n.º 5
0
    public void RefreshRememberedDivisionsFromVisibleDivisions()
    {
        UpdateRememberedDivision(new RememberedDivision(this));

        foreach (var key in VisibleDivisions.Keys)
        {
            UpdateRememberedDivision(new RememberedDivision(VisibleDivisions[key]));

            //only share info with same team
            if (AreSameTeam(VisibleDivisions[key], this))
            {
                var rememberedDivisionKeys = VisibleDivisions[key].RememberedDivisions.Keys.ToList();
                //foreach (var kvp in VisibleDivisions[key].RememberedDivisions)
                for (int i = 0; i < rememberedDivisionKeys.Count; i++)
                {
                    int divisionId = rememberedDivisionKeys[i];
                    RememberedDivision otherDiv = VisibleDivisions[key].RememberedDivisions[divisionId];
                    UpdateRememberedDivision(otherDiv);
                }
            }
        }

        //RefreshSubordinates(RememberedDivisions);
        //RefreshOrdersRememberedDivisions(RememberedDivisions);
    }
Exemplo n.º 6
0
    public override void Proceed(ControlledDivision Host)
    {
        if (!IsFinished && Host.FindVisibleDivision(RememberedTargetId, out ControlledDivision division))
        {
            var distanceToTarget = (division.Controller.transform.position - Host.Controller.transform.position).magnitude;
            if (distanceToTarget > Host.MaxHitRange)
            {
                IsFinished = true;
                return;
            }

            float totalAttackerDamage = 0;
            for (int i = 0; i < Host.Soldiers.Count; i++)
            {
                Soldier soldier = Host.Soldiers[i];

                if (distanceToTarget > soldier.MinRange && distanceToTarget < soldier.MaxRange)
                {
                    var result = soldier.Attack(ref division, distanceToTarget);
                    totalAttackerDamage += result.DamageToDefender;
                }
            }


            bool isDestroyed     = division.CheckDamageDone(Host);
            bool isHostDestroyed = Host.CheckDamageDone(division);
            if (isDestroyed)
            {
                RememberedDivision RememberedTarget = GetRememberedDivisionFromHost(Host, RememberedTargetId);
                RememberedTarget.HasBeenDestroyed = true;
                RememberedTarget.TimeStamp        = GameManager.Instance.GameTime;
                IsFinished = true;
            }
        }
    }
Exemplo n.º 7
0
 public void AddSubordinate(RememberedDivision division)
 {
     if (division.DivisionId != this.DivisionId)
     {
         Subordinates.Add(division.DivisionId);
         OnChange();
     }
 }
Exemplo n.º 8
0
 public SendMessage(DivisionController controller, DivisionController commanderSendingOrder, List <Order> message, RememberedDivision target)
 {
     this.commanderSendingOrder = commanderSendingOrder;
     this.controller            = controller;
     this.finish  = target;
     this.target  = null;
     this.message = message;
 }
Exemplo n.º 9
0
    public override void End()
    {
        controller.GetComponent <Rigidbody>().velocity = Vector3.zero;
        RememberedDivision commander = controller.rememberedDivisions[commanderSendingOrder.divisionId];

        controller.ReceiveOrder(new FindDivision(controller, target, commander));
        controller.ReceiveOrder(new MergeDivisions(controller, commander));
    }
Exemplo n.º 10
0
    public override Vector3 GetPredictedPosition(RememberedDivision rememberedDivision)
    {
        if (OngoingOrder == null)
        {
            return(base.GetPredictedPosition(rememberedDivision));
        }

        return(OngoingOrder.GetPredictedPosition(rememberedDivision));
    }
Exemplo n.º 11
0
    public override void End(ControlledDivision Host)
    {
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(Host, CommanderSendingOrderId);
        RememberedDivision commander             = Host.RememberedDivisions[CommanderSendingOrder.DivisionId];

        Host.ReceiveOrder(new FindDivision(Host, _visibleTarget.DivisionId, commander.DivisionId));
        Host.ReceiveOrder(new MergeDivisions(Host, commander.DivisionId, commander.DivisionId));
        base.End(Host);
    }
Exemplo n.º 12
0
    public override void OnClickedInUI(Division Host, PlayerController playerController)
    {
        OrderDisplayManager.Instance.ClearOrders();
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        CommanderSendingOrder.SendOrderTo(
            new RememberedDivision(Host),
            new GatherSuppliesOrder(Host, CommanderSendingOrderId), ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }
Exemplo n.º 13
0
 public void DivisionMenuItemClicked(RememberedDivision division)
 {
     commander = division;
     RegenerateMenuItems();
     //bing up context menu for that division on the bottom right, but do different actions
     GameManager.instance.localPlayer.select(division);
     //need to send messengers to discover its location
     //refresh the division menu with his stuff
 }
Exemplo n.º 14
0
    public void AddAutoRunBackgroundOrders()
    {
        //add background orders which should continously run
        RememberedDivision CommanderSendingOrder = new RememberedDivision(this);

        CommanderSendingOrder.SendOrderTo(
            new RememberedDivision(this),
            new UseSuppliesOrder(this, DivisionId), ref RememberedDivisions);
    }
Exemplo n.º 15
0
    public void OnUnitSelected(Division Host, RememberedDivision division, PlayerController playerController)
    {
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        LocalPlayerController.Instance.UnRegisterUnitSelectCallback(UICallback);
        OrderDisplayManager.Instance.ClearOrders();

        CommanderSendingOrder.SendOrderTo(new RememberedDivision(Host),
                                          new EngageOrder(Host, CommanderSendingOrder.DivisionId, division.DivisionId), ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }
Exemplo n.º 16
0
    public override void OnClickedInUI(Division Host, PlayerController playerController)
    {
        OrderDisplayManager.Instance.ClearOrders();
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        //Debug.Log($"heartbeat {Host.DivisionId} {CommanderSendingOrderId}");
        CommanderSendingOrder.SendOrderTo(
            new RememberedDivision(Host),
            new HeartBeatOrder(Host, CommanderSendingOrderId, CommanderSendingOrderId), ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }
Exemplo n.º 17
0
    public void SendMessenger(RememberedDivision to, RememberedDivision endTarget, List <Order> orders)
    {
        //create a new division
        DivisionController messenger = CreateNewDivision((int)CommandingOfficer.MessengerDivisionSoldierCnt.Value);

        messenger.AttachedDivision.IsMessenger = true;
        messenger.name = "messenger";
        messenger.AttachedDivision.ReceiveOrder(new FindDivision(messenger.AttachedDivision, DivisionId, to.DivisionId));
        messenger.AttachedDivision.ReceiveOrder(new SendMessage(messenger.AttachedDivision, DivisionId, orders, to.DivisionId, endTarget.DivisionId));
    }
Exemplo n.º 18
0
    /// <summary>
    /// commit division to a zone
    /// </summary>
    /// <param name="Host"></param>
    /// <param name="playerController"></param>
    /// <param name="zone"></param>
    public virtual void OnZoneSelected(Division Host, PlayerController playerController, IZone zone)
    {
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        LocalPlayerController.Instance.UnRegisterZoneSelectCallback(UICallback);
        OrderDisplayManager.Instance.ClearOrders();
        Debug.Log("zone" + " " + zone);
        Debug.Log($"{Host.Zones.Count}");
        CommanderSendingOrder.SendOrderTo(new RememberedDivision(Host),
                                          new ZoneOrder(Host, CommanderSendingOrder.DivisionId, zone), ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }
Exemplo n.º 19
0
    public void OnClickReturn(Vector3 mousePos, Division Host, PlayerController playerController)
    {
        finish = new Vector3(mousePos.x, mousePos.y);
        //InputController.Instance.UnRegisterOnClickCallBack(UICallback);
        //clear ui
        OrderDisplayManager.Instance.ClearOrders();
        //need to get
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        CommanderSendingOrder.SendOrderTo(new RememberedDivision(Host), new Move(Host, CommanderSendingOrder.DivisionId, finish), ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }
Exemplo n.º 20
0
 public void AddOrderSet(List <Order> orders, RememberedDivision division, PlayerController playerController)
 {
     foreach (Order order in orders)
     {
         string     name = order.GetType().Name;
         GameObject temp = Instantiate(orderPrefab);
         temp.transform.GetChild(0).GetComponent <Text>().text = name;
         temp.GetComponent <Button>().onClick.AddListener(delegate { order.OnClickedInUI(division, playerController); });
         AddToDisplay(temp);
     }
 }
Exemplo n.º 21
0
 public void Update(RememberedDivision division)
 {
     this.position       = division.position;
     this.velocity       = division.velocity;
     this.orderQueue     = division.orderQueue;
     this.soldiers       = division.soldiers;
     this.divisionId     = division.divisionId;
     this.timeStamp      = division.timeStamp;
     this.possibleOrders = division.possibleOrders;
     this.subordinates   = division.subordinates;
     this.commander      = division.commander;
 }
Exemplo n.º 22
0
    public void AbsorbDivision(DivisionController other)
    {
        TransferSoldiers(other.soldiers);
        //kick him out of his commanders subordinate list
        RememberedDivision parent = other.commander;

        if (parent != null)
        {
            parent.RemoveSubordinate(other.GenerateRememberedDivision());
        }
        GameObject.Destroy(other.gameObject);
        GameManager.instance.RefreshAllDivisons();
    }
Exemplo n.º 23
0
 public void select(RememberedDivision divisionController)
 {
     if (!UIwaitingForSelection)
     {
         //bing up order ui
         OrderDisplayManager.instance.ClearOrders();
         OrderDisplayManager.instance.AddOrderSet(divisionController.possibleOrders);
     }
     else
     {
         UIResponseRememberedDivision(divisionController);
     }
 }
Exemplo n.º 24
0
    public void OnClickReturn(Vector3 mousePos, Division Host, PlayerController playerController)
    {
        finish = new Vector3(mousePos.x, mousePos.y);
        OrderDisplayManager.Instance.ClearOrders();
        var scout = Host.CreateNewDivision((int)Host.CommandingOfficer.ScoutDivisionSoldierCnt.Value);

        scout.name = "scout";

        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        scout.AttachedDivision.ReceiveOrder(new Move(scout.AttachedDivision, CommanderSendingOrder.DivisionId, finish));
        scout.AttachedDivision.ReceiveOrder(new FindDivision(scout.AttachedDivision, CommanderSendingOrder.DivisionId, Host.DivisionId));
        scout.AttachedDivision.ReceiveOrder(new MergeDivisions(scout.AttachedDivision, Host.DivisionId, Host.DivisionId));
    }
Exemplo n.º 25
0
 public RememberedDivision(Vector3 position, Vector3 velocity, List <Order> orders,
                           List <Soldier> soldiers, int divisionId, float timeStamp,
                           List <Order> possibleOrders, List <RememberedDivision> subordinates, RememberedDivision commander)
 {
     this.position       = position;
     this.velocity       = velocity;
     this.orderQueue     = orders;
     this.soldiers       = soldiers;
     this.divisionId     = divisionId;
     this.timeStamp      = timeStamp;
     this.possibleOrders = possibleOrders;
     this.subordinates   = subordinates;
     this.commander      = commander;
 }
Exemplo n.º 26
0
    public RememberedDivision GenerateRememberedDivision()
    {
        List <RememberedDivision> subordinatesDeep = new List <RememberedDivision>();

        foreach (RememberedDivision subordinate in subordinates)
        {
            //subordinatesDeep.Add()
        }

        RememberedDivision rememberedDivision =
            new RememberedDivision(
                transform.position, GetComponent <Rigidbody>().velocity, orderQueue, soldiers, divisionId, Time.time, possibleOrders, subordinatesDeep, commander);

        return(rememberedDivision);
    }
Exemplo n.º 27
0
    public void OnUnitSelected(Division Host, RememberedDivision division, PlayerController playerController)
    {
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        LocalPlayerController.Instance.UnRegisterUnitSelectCallback(UICallback);
        OrderDisplayManager.Instance.ClearOrders();

        var orders = new List <Order>()
        {
            new FindDivision(Host, CommanderSendingOrder.DivisionId, division.DivisionId),
            new AttackOrder(Host, CommanderSendingOrder.DivisionId, division.DivisionId, Host.MaxHitRange)
        };

        CommanderSendingOrder.SendOrdersTo(new RememberedDivision(Host), orders, ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }
Exemplo n.º 28
0
    public void SendOrdersTo(RememberedDivision to, List <Order> orders, ref Dictionary <int, RememberedDivision> rememberedDivisions)
    {
        //follow command tree to get there
        List <RememberedDivision> pathToDivision = FindDivisionInSubordinatesHelper(new RememberedDivision(this), to, ref rememberedDivisions);

        //if path is only size one, we're at where the order needs to go
        if (pathToDivision.Count == 1)
        {
            Controller.AttachedDivision.ReceiveOrders(orders);
            return;
        }

        //send order to the next commander
        pathToDivision[0].Controller.SendMessenger(pathToDivision[1], to, orders);
    }
Exemplo n.º 29
0
    public void SendOrderTo(RememberedDivision to, Order order)
    {
        //follow commander tree to get there
        List <RememberedDivision> pathToDivision = FindDivisionInSubordinates(GenerateRememberedDivision(), to, new List <RememberedDivision>());

        //if path is only size one, were at where the order needs to go
        if (pathToDivision.Count == 1)
        {
            Debug.Log(order);
            ReceiveOrder(order);
            return;
        }

        //send order to the next commander
        SendMessenger(pathToDivision[1], order);
    }
Exemplo n.º 30
0
    public override void OnClickedInUI(Division Host, PlayerController playerController)
    {
        if (Host.Soldiers.Count <= 1)
        {
            return;
        }

        var soldiersWanted = new Dictionary <SoldierType, int>();

        soldiersWanted.Add(SoldierType.Melee, 1);

        OrderDisplayManager.Instance.ClearOrders();
        RememberedDivision CommanderSendingOrder = GetRememberedDivisionFromHost(playerController.GeneralDivision.AttachedDivision, CommanderSendingOrderId);

        CommanderSendingOrder.SendOrderTo(new RememberedDivision(Host), new SplitDivision(Host, CommanderSendingOrderId, soldiersWanted), ref playerController.GeneralDivision.AttachedDivision.RememberedDivisions);
    }