Esempio n. 1
0
 //blank link (for the palette)
 public Link(ILinkable linkComponent, formationtype ftype = formationtype.AllToAll)
 {
     this.room       = OrbIt.Game.Room;
     this.components = new Dictionary <Type, ILinkable>();
     this.components[linkComponent.GetType()] = linkComponent;
     this._FormationType = ftype;
     this.formation      = new Formation(this, ftype, InitializeFormation: false);
 }
        public Formation(   Link link, 
                            formationtype FormationType = formationtype.AllToAll,
                            bool Uninhabited = false,
                            int UpdateFrequency = -1,
                            int NearestNValue = 1,
                            bool InitializeFormation = true)
        {
            this.room = OrbIt.game.room;
            this.link = link;
            //this.FormationType = FormationType;
            this.Uninhabited = Uninhabited;
            this.UpdateFrequency = UpdateFrequency;
            this.NearestNValue = NearestNValue;
            this.AffectionSets = new Dictionary<Node, ObservableHashSet<Node>>();

            if (InitializeFormation) UpdateFormation();
        }
Esempio n. 3
0
        public Formation(Link link,
                         formationtype FormationType = formationtype.AllToAll,
                         bool Uninhabited            = false,
                         int UpdateFrequency         = -1,
                         int NearestNValue           = 1,
                         bool InitializeFormation    = true)
        {
            this.room = OrbIt.Game.Room;
            this.link = link;
            //this.FormationType = FormationType;
            this.Uninhabited     = Uninhabited;
            this.UpdateFrequency = UpdateFrequency;
            this.NearestNValue   = NearestNValue;
            this.AffectionSets   = new Dictionary <Node, ObservableHashSet <Node> >();

            if (InitializeFormation)
            {
                UpdateFormation();
            }
        }
Esempio n. 4
0
        private void Initialize(dynamic src, dynamic trg, ILinkable linkComponent, dynamic formation)
        {
            this.room          = OrbIt.Game.Room;
            this.DrawLinkLines = true;

            if (components == null)
            {
                this.components = new Dictionary <Type, ILinkable>();
            }
            if (linkComponent != null)
            {
                linkComponent.link   = this;
                linkComponent.active = true;
                this.components[linkComponent.GetType()] = linkComponent;
            }


            if (src is Node && trg is Node)
            {
                this.ltype = linktype.NodeToNode;
            }
            else if (src is Node && (trg is HashSet <Node> || trg is Group))
            {
                this.ltype = linktype.NodeToGroup;
            }
            else
            {
                this.ltype = linktype.GroupToGroup;
            }

            bool EqualSets = false;

            //source
            if (src is Node)
            {
                this.sourceNode = src;
                this.sources    = new ObservableHashSet <Node>()
                {
                    sourceNode
                };
                sourceNode.SourceLinks.Add(this);
                //linkComponent.parent = sourceNode;
                if (trg is Node)
                {
                    sourceNode.OnAffectOthers += NodeToNodeHandler;
                }
                else
                {
                    sourceNode.OnAffectOthers += NodeToGroupHandler;
                }
            }
            else if (src is HashSet <Node> )
            {
                Group ss = new Group();
                foreach (Node s in src)
                {
                    ss.entities.Add(s);
                }

                this.sourceGroup = ss;
                this.sourceGroup.SourceLinks.Add(this);
                this.sources = this.sourceGroup.fullSet;

                room.MasterGroup.childGroups["Link Groups"].AddGroup(ss);
                //if (OrbIt.ui != null)
                //{
                //    OrbIt.ui.sidebar.UpdateGroupComboBoxes();
                //}

                foreach (Node s in this.sources)
                {
                    s.OnAffectOthers += NodeToGroupHandler;
                    s.SourceLinks.Add(this);
                }
                this.sources.CollectionChanged += sourceGroup_CollectionChanged;

                if (trg is HashSet <Node> && src == trg)
                {
                    EqualSets        = true;
                    this.targetGroup = this.sourceGroup;
                    this.targetGroup.TargetLinks.Add(this);
                    this.targets = this.targetGroup.fullSet;
                    foreach (Node t in this.targets)
                    {
                        t.TargetLinks.Add(this);
                    }
                }
            }
            else if (src is Group)
            {
                this.sourceGroup = src;
                this.sources     = this.sourceGroup.fullSet;

                this.sourceGroup.SourceLinks.Add(this);

                foreach (Node s in sources)
                {
                    s.OnAffectOthers += NodeToGroupHandler;
                    s.SourceLinks.Add(this);
                }
                this.sourceGroup.fullSet.CollectionChanged += sourceGroup_CollectionChanged;
            }
            else
            {
                Console.WriteLine("Unrecongized source type when creating link");
            }

            //target
            if (trg is Node)
            {
                this.targetNode = trg;
                this.targets    = new ObservableHashSet <Node>()
                {
                    targetNode
                };
                targetNode.TargetLinks.Add(this);
            }
            else if (trg is HashSet <Node> && !EqualSets)
            {
                Group ts = new Group();
                foreach (Node t in trg)
                {
                    ts.entities.Add(t);
                }
                this.targetGroup = ts;
                this.targets     = this.targetGroup.fullSet;
                this.targetGroup.TargetLinks.Add(this);

                room.MasterGroup.childGroups["Link Groups"].AddGroup(ts);
                //if (OrbIt.ui != null) OrbIt.ui.sidebar.UpdateGroupComboBoxes();

                foreach (Node t in this.targets)
                {
                    t.TargetLinks.Add(this);
                }
                this.targets.CollectionChanged += targetGroup_CollectionChanged;
            }
            else if (trg is Group)
            {
                this.targetGroup = trg;
                this.targets     = this.targetGroup.fullSet;
                this.targetGroup.TargetLinks.Add(this);

                foreach (Node t in targets)
                {
                    t.TargetLinks.Add(this);
                }
                this.targetGroup.fullSet.CollectionChanged += targetGroup_CollectionChanged;
            }
            else
            {
                Console.WriteLine("Unrecongized target type when creating link");
            }

            if (formation == null)
            {
                this._FormationType = formationtype.AllToAll;
                this.formation      = new Formation(this, formationtype.AllToAll);
            }
            else if (formation is formationtype)
            {
                this._FormationType = formation;
                this.formation      = new Formation(this, formation);
            }
            else if (formation is Formation)
            {
                this._FormationType = formation.FormationType;
                this.formation      = new Formation(this, formation);
            }
        }