Пример #1
0
        private Counterparts GetMenInTheMiddle(Counterparts list)
        {
            Counterparts c = new Counterparts();

            if (!part)
            {
                return(c);
            }

            foreach (Tosh_AutoStrut m in list)
            {
                foreach (Strut s2 in m.mStruts)
                {
                    foreach (Strut s1 in mStruts)
                    {
                        Vector3 v = s2.position - s1.position;
                        foreach (RaycastHit r in Physics.RaycastAll(s1.position, v.normalized, v.magnitude))
                        {
                            Part p = FromCollider(r.collider);
                            if (p && p != part && p.vessel == part.vessel)
                            {
                                Tosh_AutoStrut a = GetMe(p);
                                if (a && !list.Contains(a) && !c.Contains(a))
                                {
                                    c.Add(a);
                                }
                            }
                        }
                    }
                }
            }

            return(c);
        }
Пример #2
0
        // And here's where we get ALL the parts we can connect to.
        private Counterparts GetCounterparts()
        {
            Counterparts s = new Counterparts();

            if (!part)
            {
                return(s);
            }
            if (connectToCounterparts)
            {
                foreach (Part p in part.symmetryCounterparts)
                {
                    Tosh_AutoStrut m = GetMe(p);
                    if (m && !s.Contains(m))
                    {
                        s.Add(m);
                    }
                }
            }

            if (connectToParent && GetMe(part.parent))
            {
                s.Add(GetMe(part.parent));
            }

            Tosh_AutoStrut a;

            foreach (Part p in part.children)
            {
                a = GetMe(p);
                if (a && a.connectToParent)
                {
                    s.Add(a);
                }
            }

            if (detectManInTheMiddle)
            {
                Counterparts middle = GetMenInTheMiddle(s);
                ReviveMen(middle);
                s.AddRange(middle);

                RemoveDeadMen();
                s.AddRange(mMenInMiddle);
            }


            return(s);
        }
Пример #3
0
 // "Revive" the men which are still between the symmetry counterparts
 // and thus should live for one more frame.
 private void ReviveMen(Counterparts list)
 {
     foreach (Tosh_AutoStrut m in list)
     {
         if (!m.mMenInMiddle.Contains(this))
         {
             m.mMenInMiddle.Add(this);
             m.mMenAlive.Add(true);
         }
         else
         {
             m.mMenAlive[m.mMenInMiddle.IndexOf(this)] = true;
         }
     }
 }
Пример #4
0
        // Determine a "desired" strut configuration. If it differs from
        // current one, then the struts need to be rebuilt.
        private StrutConfig DesiredConfig()
        {
            StrutConfig  cfg          = new StrutConfig();
            Counterparts counterparts = GetCounterparts();

            // FIXME: 'naive' algorythm glitches a lot.
            // A better solution would be to minimize a sum of connection lengths
            // amongst all the configurations possible.

            foreach (Strut s in mStruts)
            {
                float min  = Mathf.Infinity;
                Strut cMin = null;

                foreach (Tosh_AutoStrut c in counterparts)
                {
                    foreach (Strut cs in c.mStruts)
                    {
                        float v = (s.position - cs.position).sqrMagnitude;
                        if (v < min)
                        {
                            min  = v;
                            cMin = cs;
                        }
                    }
                }

                if (cMin)
                {
                    cfg.Add(s, cMin, min); // 'add' method eliminates double links
                }
                // and replaces longer ones automatically.
            }

            return(cfg);
        }
Пример #5
0
        public void Fill()
        {
            // Fill database only first time - there is no need to fill it every user's request
            if (!_firstFill)
            {
                return;
            }
            _firstFill = false;

            Accounts.RemoveRange(Accounts);
            AccountTypes.RemoveRange(AccountTypes);
            Categories.RemoveRange(Categories);
            Counterparts.RemoveRange(Counterparts);
            Currencies.RemoveRange(Currencies);
            LoanTypes.RemoveRange(LoanTypes);
            Transactions.RemoveRange(Transactions);
            TransactionTypes.RemoveRange(TransactionTypes);
            Icons.RemoveRange(Icons);
            SaveChanges();

            var accountTypes = new List <AccountType>
            {
                new AccountType {
                    Title = "Наличные"
                },
                new AccountType {
                    Title = "Кредитная карта"
                },
                new AccountType {
                    Title = "Дебитовая карта"
                },
            };

            AddRange(accountTypes);

            var currencies = new List <Currency>
            {
                new Currency {
                    Title = "Рубли", Symbol = "₽"
                },
                new Currency {
                    Title = "Доллары", Symbol = "$"
                },
                new Currency {
                    Title = "Евро", Symbol = "€"
                },
                new Currency {
                    Title = "Юани", Symbol = "¥"
                },
                new Currency {
                    Title = "Гривны", Symbol = "₴"
                },
            };

            AddRange(currencies);

            var accountTitles = new List <string>
            {
                "Тинькофф рубли",
                "Сбербанк",
                "Наличные доллары",
                "Юани оставшиеся с поездки",
            };

            var accounts = Enumerable.Range(1, GetRandomValue(15)).Select(index =>
            {
                return(new Account
                {
                    AccountType = accountTypes.GetAny(),
                    Currency = currencies.GetAny(),
                    Title = accountTitles.GetAny()
                });
            });

            AddRange(accounts);

            // TODO: there are much more icons in TempData file
            var icons = TempData.Icons.Take(20).Select(icon => new Icon {
                Tag = icon
            });

            AddRange(icons);

            var categories = new List <Category>
            {
                new Category {
                    Title = "Свободные", Icon = icons.GetAny()
                },
                new Category {
                    Title = "Продукты", Icon = icons.GetAny()
                },
                new Category {
                    Title = "Здоровье", Icon = icons.GetAny()
                },
                new Category {
                    Title = "Дети", Icon = icons.GetAny()
                },
                new Category {
                    Title = "Животные", Icon = icons.GetAny()
                },
                new Category {
                    Title = "Автомобиль", Icon = icons.GetAny()
                },
            };

            AddRange(categories);

            var loanTypes = new List <LoanType>
            {
                new LoanType {
                    Title = "Мне дали/Мне вернули"
                },
                new LoanType {
                    Title = "Я дал/Я вернул"
                },
            };

            AddRange(loanTypes);

            var transactionTypes = new List <TransactionType>
            {
                new TransactionType {
                    Id = 1, Title = "Расход"
                },
                new TransactionType {
                    Id = 2, Title = "Приход"
                },
                new TransactionType {
                    Id = 3, Title = "Перевод между счетами"
                },
                new TransactionType {
                    Id = 4, Title = "Долг"
                },
            };

            AddRange(transactionTypes);

            var counterparts = new List <Counterpart>
            {
                new Counterpart {
                    Title = "Пятерочка"
                },
                new Counterpart {
                    Title = "Дядя Сережа"
                },
                new Counterpart {
                    Title = "Петька"
                },
                new Counterpart {
                    Title = "ООО Рога и копыта"
                },
                new Counterpart {
                    Title = "ИП Мясников Николай Иванович"
                },
                new Counterpart {
                    Title = "ИП Овчинников А.П."
                },
                new Counterpart {
                    Title = "Сбербанк"
                },
                new Counterpart {
                    Title = "Билайн"
                },
                new Counterpart {
                    Title = "ОАО Кольцово"
                },
                new Counterpart {
                    Title = "ПАО Энергосбыт"
                },
            };

            AddRange(counterparts);


            var transactions = Enumerable.Range(1, GetRandomValue(1000)).Select(index =>
            {
                var transaction = new Transaction
                {
                    Account         = accounts.GetAny(),
                    Amount          = GetRandomValue(10000),
                    Category        = categories.GetAny(),
                    Counterpart     = counterparts.GetAny(),
                    Date            = DateTime.Now.AddMinutes(new Random().Next(-100000, 0)),
                    TransactionType = transactionTypes.GetAny(),
                };
                if (transaction.TransactionType.Title.Equals("Долг"))
                {
                    transaction.LoanType = loanTypes.GetAny();
                }

                return(transaction);
            });

            AddRange(transactions);

            SaveChanges();
        }