Exemple #1
0
 public void ShowPrimative(NeolithicObject source)
 {
     gameObject.SetActive(true);
     selected         = source;
     agentName.text   = selected.name;
     agentStatus.text = selected.statusString;
 }
Exemple #2
0
        /// <summary>
        /// Sets up a context menu for the given clicked object based on the abilities of the selected object(s)
        /// </summary>
        /// <param name="clickee"></param>
        public void DoContextMenu(NeolithicObject clickee)
        {
            var forbidden = new HashSet <CommandType>(ForbiddenActions);

            var selectedActions  = getSelectedAbilities();
            var availableActions = selectedActions
                                   .Intersect(clickee.actionProfile.targetActions)
                                   .Where((a) => !forbidden.Contains(a))
                                   .ToArray();

            GuiController.ShowContextMenu(availableActions, clickee);
        }
Exemple #3
0
        /// <summary>
        /// Finalizes construction, re-enabling cached compenents and some other prep stuff
        /// </summary>
        public void FinishContruction()
        {
            NeolithicObject no = GetComponent <NeolithicObject>();

            no.selectable    = true;
            no.actionProfile = cachedActionProfile;
            foreach (var r in cachedComponents)
            {
                r.enabled = true;
            }
            UnGhost();
            Destroy(this);
        }
Exemple #4
0
        public void Pickup()
        {
            NeolithicObject neoObject = GetComponent <NeolithicObject>();

            neoObject.snapToGround = false;
            preserved = true;
            GetComponent <NeolithicObject>().selectable = false;
            Warehouse w = GetComponent <Warehouse>();

            if (w)
            {
                Destroy(w);
            }
        }
Exemple #5
0
 /// <summary>
 /// Adds a NeolithicObject to the selected objects and updates the selection menu
 /// </summary>
 /// <param name="sel"></param>
 public void AddSelected(NeolithicObject sel)
 {
     GuiController.HideContextMenu();
     if (!selected.Contains(sel))
     {
         selected.Add(sel);
     }
     if (selected.Count == 1)
     {
         GuiController.ShowSelectionMenu(sel);
     }
     else
     {
         GuiController.HideSelectionMenu();
     }
 }
Exemple #6
0
        /// <summary>
        /// Starts the construction process, disabling and caching some key components
        /// </summary>
        public void StartConstruction()
        {
            if (instabuild)
            {
                foreach (var r in resourceRequirements)
                {
                    var resourceType = (ResourceKind)Enum.Parse(typeof(ResourceKind), r.name);
                    var rp           = new ResourceProfile(resourceType, r.amount);
                    if (!GameController.WithdrawFromAnyWarehouse(rp))
                    {
                        throw new InvalidOperationException("Failed to build building, unable to withdraw " + r.name);
                    }
                }

                FinishContruction();
            }
            else
            {
                NeolithicObject no = GetComponent <NeolithicObject>();
                no.actionProfile = (ActionProfile)Resources.Load("ActionProfiles/Constructable");
                GhostNeutral();
            }
        }
Exemple #7
0
        /// <summary>
        /// Starts the building placement process, caching some components and entering building/blueprint mode
        /// </summary>
        public void StartPlacement()
        {
            NeolithicObject no = GetComponent <NeolithicObject>();

            no.selectable = false;

            cachedActionProfile = no.actionProfile;
            no.actionProfile    = (ActionProfile)Resources.Load("ActionProfiles/Empty");

            cachedComponents = new List <MonoBehaviour>();
            foreach (var r in GetComponents <Reservoir>())
            {
                r.enabled = false;
                cachedComponents.Add(r);
            }
            foreach (var r in GetComponents <Warehouse>())
            {
                r.enabled = false;
                cachedComponents.Add(r);
            }

            GhostBad();
        }
Exemple #8
0
        /// <summary>
        /// Constructs an order from the orderTag against the given target,
        /// and assigns it to all selected actors
        /// </summary>
        public void IssueOrder(CommandType orderTag, NeolithicObject target)
        {
            var actors = selected.Select(go => go.GetComponent <ActorController>()).Where(a => a != null);

            foreach (var actor in actors)
            {
                BaseOrder newOrder = null;
                switch (orderTag)
                {
                case CommandType.ChopWood:
                case CommandType.MineGold:
                case CommandType.MineStone:
                case CommandType.Forage:
                    newOrder = new HarvestFromReservoirOrder(actor, target);
                    break;

                case CommandType.ChuckWood:
                    newOrder = new TransmuteOrder(actor, target, ResourceKind.Wood, ResourceKind.Gold);
                    break;

                case CommandType.Meditate:
                    newOrder = new MeditateOrder(actor, target);
                    break;

                case CommandType.Hunt:
                    newOrder = new HuntOrder(actor, target.GetComponentInParent <Herd>());
                    break;

                case CommandType.Fish:
                    newOrder = new FishOrder(actor, target);
                    break;

                case CommandType.Construct:
                    newOrder = new ConstructOrder(actor, target);
                    break;

                case CommandType.TearDown:
                    newOrder = new TearDownOrder(actor, target);
                    break;

                case CommandType.ForestGarden:
                    var prefab = (GameObject)Resources.Load("Buildings/ForestGarden");
                    if (prefab == null)
                    {
                        throw new InvalidOperationException("Can't find prefab");
                    }
                    newOrder = new UpgradeReservoirOrder(actor, target, prefab);
                    break;

                default:
                    throw new InvalidOperationException("Unrecognized order tag " + orderTag);
                }

                Factory.InjectObject(newOrder);
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    actor.EnqueueOrder(newOrder);
                }
                else
                {
                    actor.OverrideOrder(newOrder);
                }
            }
        }