Esempio n. 1
0
        private void setupPortrait()
        {
            Icon = GuiRoot.RootItem.AddChild(new Gui.Widgets.EmployeePortrait()
            {
                Rect = SpeakerBorder.Rect
            }) as Gui.Widgets.EmployeePortrait;

            var sprite = _employee.GetRoot().GetComponent <LayeredSprites.LayeredCharacterSprite>();

            if (sprite != null)
            {
                Icon.Sprite          = sprite.GetLayers();
                Icon.AnimationPlayer = new AnimationPlayer(sprite.GetAnimation(_employee.Creature.CurrentCharacterMode.ToString() + "FORWARD"));
            }
            else
            {
                Icon.Sprite          = null;
                Icon.AnimationPlayer = null;
            }

            var label = Icon.AddChild(new Widget()
            {
                Text                = _employee.Stats.FullName + "\n(" + (_employee.Stats.Title ?? _employee.Stats.CurrentClass.Name) + ")",
                Font                = "font10",
                TextColor           = Color.White.ToVector4(),
                TextVerticalAlign   = VerticalAlign.Center,
                TextHorizontalAlign = HorizontalAlign.Center,
                AutoLayout          = AutoLayout.DockBottom
            });

            Icon.Layout();
        }
        public IEnumerable <Act.Status> ReleaseAnimal(CreatureAI animal, CreatureAI creature)
        {
            if (creature.Blackboard.GetData <bool>("NoPath", false) &&
                animal.GetRoot().GetComponent <Physics>().HasValue(out var animalPhysics) &&
                creature.World.PersistentData.Designations.GetEntityDesignation(animalPhysics, DesignationType.Wrangle).HasValue(out var designation) &&
                creature.Faction == creature.World.PlayerFaction)
            {
                creature.World.MakeAnnouncement(String.Format("{0} stopped trying to catch {1} because it is unreachable.", creature.Stats.FullName, animal.Stats.FullName));
                creature.World.TaskManager.CancelTask(designation.Task);
            }

            animal.ResetPositionConstraint();
            yield return(Act.Status.Success);
        }
Esempio n. 3
0
        public void AddMinion(CreatureAI minion)
        {
            Minions.Add(minion);
            Inventory targetInventory = minion.GetRoot().GetComponent <Inventory>();

            if (targetInventory != null)
            {
                targetInventory.OnDeath += resources =>
                {
                    if (resources == null)
                    {
                        return;
                    }
                    AssignGather(resources);
                };
            }
        }
Esempio n. 4
0
        public static int[] CalculateOptimalAssignment(List <Task> newGoals, List <CreatureAI> agents)
        {
            int numGoals  = newGoals.Count;
            int numAgents = agents.Count;
            int maxSize   = Math.Max(numGoals, numAgents);

            int[,] goalMatrix = new int[maxSize, maxSize];
            const float multiplier = 100;

            if (numGoals == 0 || numAgents == 0)
            {
                return(null);
            }

            for (int goalIndex = 0; goalIndex < numGoals; goalIndex++)
            {
                Task goal = newGoals[goalIndex];

                for (int agentIndex = 0; agentIndex < numAgents; agentIndex++)
                {
                    CreatureAI agent     = agents[agentIndex];
                    float      floatCost = goal.ComputeCost(agent.Creature);

                    int cost = (int)(floatCost * multiplier);

                    if (goal.IsFeasible(agent.Creature) == Feasibility.Infeasible)
                    {
                        cost += 99999;
                    }

                    if (agent.Creature.Stats.IsAsleep || agent.IsDead || agent.GetRoot().IsDead)
                    {
                        cost += 99999;
                    }

                    cost += agents[agentIndex].Tasks.Count;

                    goalMatrix[agentIndex, goalIndex] = cost;
                }
            }

            // Add additional columns or rows
            if (numAgents > numGoals)
            {
                int maxValue = GetMax(goalMatrix, numAgents, numGoals) + 1;
                for (int dummyGoal = numGoals; dummyGoal < maxSize; dummyGoal++)
                {
                    for (int i = 0; i < numAgents; i++)
                    {
                        // If we have more agents than goals, we need to add additional fake goals
                        // Since goals are in columns, we are essentially adding a new column.
                        goalMatrix[i, dummyGoal] = maxValue;
                    }
                }
            }
            else if (numGoals > numAgents)
            {
                int maxValue = GetMax(goalMatrix, numAgents, numGoals) + 1;
                for (int dummyAngent = numAgents; dummyAngent < maxSize; dummyAngent++)
                {
                    for (int i = 0; i < numGoals; i++)
                    {
                        // If we have more goals than agents, we need to add additional fake agents
                        // Since goals are in columns, we are essentially adding a new row.
                        goalMatrix[dummyAngent, i] = maxValue;
                    }
                }
            }

            return(goalMatrix.FindAssignments());
        }