示例#1
0
 public void SetSteeringTarget(SteeringType Type, Unit Target)
 {
     if (Behaviours.ContainsKey(Type))
     {
         Behaviours[Type].SetTarget(Target);
     }
 }
示例#2
0
 public void SetSteeringWeight(SteeringType Type, int Weight)
 {
     if (Behaviours.ContainsKey(Type))
     {
         Behaviours[Type].Weight = Weight;
     }
 }
示例#3
0
 public void RemoveSteering(SteeringType Type)
 {
     if (Behaviours.ContainsKey(Type))
     {
         Behaviours.Remove(Type);
     }
 }
示例#4
0
 // Clears the last Path
 public void ClearPath()
 {
     if (Behaviours.ContainsKey(SteeringType.PathFollowing))
     {
         PathFollowing B = (PathFollowing)Behaviours[SteeringType.PathFollowing];
         B.SetPath(null);
     }
 }
示例#5
0
 // Orders the Unit to move following the provided Path
 public void Move(Path Path)
 {
     if (Behaviours.ContainsKey(SteeringType.PathFollowing))
     {
         PathFollowing B = (PathFollowing)Behaviours[SteeringType.PathFollowing];
         B.SetPath(Path);
     }
 }
示例#6
0
 public virtual void Trigger(int trigger)
 {
     if (!Behaviours.ContainsKey(trigger))
     {
         return;
     }
     foreach (var behaviour in Behaviours[trigger])
     {
         behaviour.Action.Invoke(this);
     }
 }
示例#7
0
文件: Bot.cs 项目: JeffCost/opensim
        public bool AddBehaviour(IBehaviour behaviour)
        {
            lock (Behaviours)
            {
                if (!Behaviours.ContainsKey(behaviour.AbbreviatedName))
                {
                    behaviour.Initialize(this);
                    Behaviours.Add(behaviour.AbbreviatedName, behaviour);

                    return(true);
                }
            }

            return(false);
        }
示例#8
0
        public void ClearGroupTarget()
        {
            if (Behaviours.ContainsKey(SteeringType.Alignment))
            {
                Alignment Alignment = (Alignment)Behaviours[SteeringType.Alignment];
                Alignment.Targets.Clear();
            }

            if (Behaviours.ContainsKey(SteeringType.Cohesion))
            {
                Cohesion Cohesion = (Cohesion)Behaviours[SteeringType.Cohesion];
                Cohesion.Targets.Clear();
            }

            if (Behaviours.ContainsKey(SteeringType.Separation))
            {
                Separation Separation = (Separation)Behaviours[SteeringType.Separation];
                Separation.Targets.Clear();
            }
        }
示例#9
0
        public void SetGroupTarget(List <Unit> Targets)
        {
            if (Behaviours.ContainsKey(SteeringType.Alignment))
            {
                Alignment Alignment = (Alignment)Behaviours[SteeringType.Alignment];
                Alignment.Targets = Targets;
            }

            if (Behaviours.ContainsKey(SteeringType.Cohesion))
            {
                Cohesion Cohesion = (Cohesion)Behaviours[SteeringType.Cohesion];
                Cohesion.Targets = Targets;
            }

            if (Behaviours.ContainsKey(SteeringType.Separation))
            {
                Separation Separation = (Separation)Behaviours[SteeringType.Separation];
                Separation.Targets = Targets;
            }
        }
示例#10
0
        public ProfileResult Run(Context c, string behaviour, Dictionary <string, string> tags)
        {
            if (!Behaviours.ContainsKey(behaviour))
            {
                throw new ArgumentException(
                          $"Profile {Name} does not contain the behaviour {behaviour}\nTry one of {string.Join(",", Behaviours.Keys)}");
            }

            var parameters = new Dictionary <string, IExpression>();

            foreach (var(k, v) in DefaultParameters)
            {
                parameters[k.TrimStart('#')] = v;
            }

            foreach (var(k, v) in Behaviours[behaviour])
            {
                parameters[k.TrimStart('#')] = v;
            }

            c = c.WithParameters(parameters)
                .WithAspectName(this.Name);
            tags = new Dictionary <string, string>(tags);
            var canAccess = Access.Run(c, tags);

            tags["access"] = "" + canAccess;
            var speed = (double)Speed.Run(c, tags);

            tags["speed"] = "" + speed;
            var oneway = Oneway.Run(c, tags);

            tags["oneway"] = "" + oneway;

            c.AddFunction("speed", new AspectMetadata(new Constant(Typs.Double, speed),
                                                      "speed", "Actual speed of this function", "NA", "NA", "NA", true));
            c.AddFunction("oneway", new AspectMetadata(new Constant(Typs.String, oneway),
                                                       "oneway", "Actual direction of this function", "NA", "NA", "NA", true));
            c.AddFunction("access", new AspectMetadata(new Constant(Typs.String, canAccess),
                                                       "access", "Actual access of this function", "NA", "NA", "NA", true));


            var priority          = 0.0;
            var weightExplanation = new List <string>();

            foreach (var(paramName, expression) in Priority)
            {
                var aspectInfluence = (double)c.Parameters[paramName].Evaluate(c);
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (aspectInfluence == 0)
                {
                    continue;
                }


                var aspectWeightObj = new Apply(
                    Funcs.EitherFunc.Apply(Funcs.Id, Funcs.Const, expression)
                    , new Constant(tags)).Evaluate(c);

                double aspectWeight;
                switch (aspectWeightObj)
                {
                case bool b:
                    aspectWeight = b ? 1.0 : 0.0;
                    break;

                case double d:
                    aspectWeight = d;
                    break;

                case int j:
                    aspectWeight = j;
                    break;

                case string s:
                    if (s.Equals("yes"))
                    {
                        aspectWeight = 1.0;
                        break;
                    }
                    else if (s.Equals("no"))
                    {
                        aspectWeight = 0.0;
                        break;
                    }

                    throw new Exception($"Invalid value as result for {paramName}: got string {s}");

                default:
                    throw new Exception($"Invalid value as result for {paramName}: got object {aspectWeightObj}");
                }

                weightExplanation.Add($"({paramName} = {aspectInfluence}) * {aspectWeight}");
                priority += aspectInfluence * aspectWeight;
            }

            if (priority <= 0)
            {
                canAccess = "no";
            }

            return(new ProfileResult((string)canAccess, (string)oneway, speed, priority,
                                     string.Join("\n  ", weightExplanation)));
        }
示例#11
0
        // Adds a specific Steering if it's not already contained
        public void AddSteering(SteeringType Type)
        {
            if (!Behaviours.ContainsKey(Type))
            {
                switch (Type)
                {
                case SteeringType.Align:
                    Behaviours.Add(Type, new Align());
                    break;

                case SteeringType.AntiAlign:
                    Behaviours.Add(Type, new AntiAlign());
                    break;

                case SteeringType.Arrive:
                    Behaviours.Add(Type, new Arrive());
                    break;

                case SteeringType.Flee:
                    Behaviours.Add(Type, new Flee());
                    break;

                case SteeringType.Seek:
                    Behaviours.Add(Type, new Seek());
                    break;

                case SteeringType.VelocityMatching:
                    Behaviours.Add(Type, new VelocityMatching());
                    break;

                case SteeringType.Evade:
                    Behaviours.Add(Type, new Evade());
                    break;

                case SteeringType.Face:
                    Behaviours.Add(Type, new Face());
                    break;

                case SteeringType.LookWhereYouGoing:
                    Behaviours.Add(Type, new LookWhereYouGoing());
                    break;

                case SteeringType.ObstacleAvoidance:
                    ObstacleAvoidance O = new ObstacleAvoidance();
                    O.World = Collider.World;
                    Behaviours.Add(Type, O);
                    break;

                case SteeringType.PathFollowing:
                    Behaviours.Add(Type, new PathFollowing());
                    break;

                case SteeringType.Pursue:
                    Behaviours.Add(Type, new Pursue());
                    break;

                case SteeringType.Wander:
                    Behaviours.Add(Type, new Wander());
                    break;

                case SteeringType.Alignment:
                    Behaviours.Add(Type, new Alignment());
                    break;

                case SteeringType.Cohesion:
                    Behaviours.Add(Type, new Cohesion());
                    break;

                case SteeringType.Separation:
                    Behaviours.Add(Type, new Separation());
                    break;

                default:
                    break;
                }
            }
        }