private static void PromoteSoftware(SoftwareWorkItem item)
        {
            AutoDevWorkItem autoDev = GetAutoDevWorkItem(item);

            AutoDevWorkItem.AutoDevItem autoDevItem = null;
            if (autoDev != null)
            {
                autoDevItem = autoDev.Items.FirstOrDefault(adi => adi.Alpha == item);
            }

            if (autoDev == null || autoDevItem == null)
            {
                Console.LogError("Could not find auto dev task for current work item");
                return;
            }

            if (item is SoftwareAlpha)
            {
                SoftwareAlpha alpha = item as SoftwareAlpha;
                if (alpha.InBeta)
                {
                    autoDevItem.AlreadyDev = autoDevItem.MonthsToSpend;
                }

                if (!alpha.InDelay)
                {
                    item.PromoteAction();
                    Console.Log("Manually moving out of alpha");
                    //if (!alpha.InDelay)
                    {
                        Console.Log("PrintingCopies target = " + autoDev.PrintingCopies);
                        if (autoDev.PrintingCopies > 0U && !autoDevItem.hasPrinted)
                        {
                            uint num = autoDev.PrintingCopies;
                            if (autoDev.PrintingCopyRel)
                            {
                                num = (uint)(item.Followers *
                                             (autoDev.PrintingCopies / 100.0));
                            }
                            Console.Log("PrintingCopies num = " + num);
                            autoDevItem.hasPrinted = true;
                            PrintJob printJob = new PrintJob(alpha.ForceID(), 1f)
                            {
                                Limit = num
                            };
                            GameSettings.Instance.PrintOrders[printJob.ID] = printJob;
                            HUD.Instance.distributionWindow.RefreshOrders();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Auto promotes the on going contracts
        /// </summary>
        /// <param name="workItems"></param>
        private void AutoPromote(IEnumerable <WorkItem> workItems)
        {
            try
            {
                var designDocuments = workItems.OfType <DesignDocument>()
                                      .Where(designDocument => designDocument.Iteration >= 1 && !designDocument.Done && designDocument.contract != null).ToList();

                foreach (var designDocument in designDocuments)
                {
                    designDocument.PromoteAction();
                }
            }
            catch (Exception e)
            {
                Console.LogError($"Error while running AutoPromote Exception: {e}");
                disabled = true;
            }
        }
        private void Update()
        {
            long hash = 0;

            if (!shown)
            {
                return;
            }
            hash += GameSettings.Instance.MyCompany.WorkItems.Where(wi => wi.AutoDev)
                    .Sum(item => (long)((float)item.GetHashCode() * 0.0001f));

            if (hash == _lastHash)
            {
                return;
            }
            Console.Log(string.Format("Refreshing list {0}/{1}", hash, _lastHash));
            _lastHash = hash;
            AssignDevItems();
            AssignSupportItems();
            AssignMarketingItems();
        }
Beispiel #4
0
        /// <summary>
        /// It handles the beta and developing cycle of the contract
        /// </summary>
        /// <param name="workItems"></param>
        private void AutoBeta(IEnumerable <WorkItem> workItems)
        {
            try
            {
                var alphaPhase = workItems.OfType <SoftwareAlpha>().Where(alpha => alpha.contract != null).ToList();

                foreach (var alpha in alphaPhase)
                {
                    if (alpha.InBeta)
                    {
                        //If it is Art related contract there is no bugs
                        if (alpha.Bugs < 0.1f)
                        {
                            alpha.PromoteAction();
                        }
                        else
                        {
                            if (alpha.FixedBugs >= Math.Min(5, alpha.Bugs / 2f))
                            {
                                alpha.PromoteAction();
                            }
                        }
                    }
                    else
                    {
                        if (alpha.GetProgress() >= Math.Min(100f, alpha.contract.MinProg * 1.2f))
                        {
                            alpha.PromoteAction();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.LogError($"Error while running AutoBeta Exception: {e}");
                disabled = true;
            }
        }
        private void HandleMarketing(SoftwareWorkItem item)
        {
            AutoDevWorkItem autoDev = GetAutoDevWorkItem(item);

            AutoDevWorkItem.AutoDevItem autoDevItem = null;
            if (autoDev != null)
            {
                autoDevItem = autoDev.Items.FirstOrDefault(adi => adi.Alpha == item);
            }

            if (autoDev == null || autoDevItem == null)
            {
                Console.LogError("Could not find auto dev task for current work item");
                return;
            }

            bool doneSomething = false;

            /// Do press release
            if (!autoDevItem.InHouse && (!autoDevItem.PressRelease && autoDev.MarketingTeams.Count > 0))
            {
                MarketingWindow marketingWindow = HUD.Instance.marketingWindow;
                float           cost            = marketingWindow.PressOptionCost.Sum();
                float           potential       =
                    marketingWindow.PressOptionEffect.Sum();
                autoDevItem.PressRelease = true;
                MarketingPlan marketingPlan = new MarketingPlan(autoDevItem.Alpha,
                                                                MarketingPlan.TaskType.PressRelease, cost,
                                                                potential,
                                                                !(autoDevItem.Alpha.guiItem ==
                                                                  null)
                                                                    ? autoDevItem.Alpha.guiItem.transform
                                                                .GetSiblingIndex() + 1
                                                                    : -1);
                marketingPlan.AutoDev = true;
                marketingPlan.Hidden  = false;
                autoDev.AssignTeams(marketingPlan, autoDev.MarketingTeams);
                GameSettings.Instance.MyCompany.WorkItems.Add(marketingPlan);

                doneSomething = true;
            }

            /// Do Press builds
            if (!autoDevItem.InHouse && autoDev.MarketingTeams.Count > 0)
            {
                SoftwareAlpha alpha = item as SoftwareAlpha;
                GameSettings.Instance.PressBuildQueue.Add(autoDevItem.Alpha);
                HUD.Instance.AddPopupMessage("PressBuildConfirmation".LocColor((object)item), "Info",
                                             PopupManager.PopUpAction.None, 0U, PopupManager.NotificationSound.Neutral,
                                             0.0f, PopupManager.PopupIDs.None, 6);
                autoDevItem.PressBuild = true;

                doneSomething = true;
            }

            if (!doneSomething)
            {
                HUD.Instance.AddPopupMessage("Can't market product at this time.", "Exclamation",
                                             PopupManager.PopUpAction.None, 0, PopupManager.NotificationSound.Warning,
                                             0f);
            }
        }
Beispiel #6
0
 public override void OnDeactivate()
 {
     Console.LogInfo("LazyContracts Deactivated!");
 }
        public bool TransferBestAvailableStaff(Team team, Team[] sourceTeams, out string error)
        {
            IEnumerable <SoftwareWorkItem> software =
                team.WorkItems.Where(wi => wi is SoftwareWorkItem).Cast <SoftwareWorkItem>();

            if (!software.Any())
            {
                error = "Team has no projects";
                return(false);
            }

            // Setup HR so that the correct number of employees are hired, should anyone leave
            if (AdjustDepartment != 0)
            {
                int MaxArt    = 0;
                int MaxCode   = 0;
                int MaxDesign = 0;
                foreach (SoftwareWorkItem workItem in software)
                {
                    Console.Log("Category 2: " + workItem.SWCategory);
                    SoftwareProduct softwareProduct = workItem.SequelTo;
                    SoftwareProduct sequelTo        = softwareProduct == null || !softwareProduct.Traded
                        ? softwareProduct
                        : (SoftwareProduct)null;

                    float devTime = workItem.Type.DevTime(workItem.GetFeatures(), workItem.SWCategory, null, null, null, null,
                                                          false, sequelTo);
                    if (workItem.Type.OSSpecific)
                    {
                        devTime += Mathf.Max(workItem.OSs.Length - 1, 0);
                    }

                    int[] employeeRatio = SoftwareType.GetOptimalEmployeeCount(devTime);

                    if ((AdjustDepartment & AdjustHRFlags.Art) != 0)
                    {
                        MaxArt = Mathf.Max(MaxArt, Mathf.CeilToInt(employeeRatio[1] * (1f - workItem.CodeArtRatio)));
                    }
                    if ((AdjustDepartment & AdjustHRFlags.Code) != 0)
                    {
                        MaxCode = Mathf.Max(MaxCode, Mathf.CeilToInt(employeeRatio[1] * workItem.CodeArtRatio));
                    }
                    if ((AdjustDepartment & AdjustHRFlags.Design) != 0)
                    {
                        MaxDesign = Mathf.Max(MaxDesign, employeeRatio[0]);
                    }
                }

                if (AdjustHR)
                {
                    if ((AdjustDepartment & AdjustHRFlags.Art) != 0)
                    {
                        team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Artist)] = MaxArt;
                    }
                    if ((AdjustDepartment & AdjustHRFlags.Code) != 0)
                    {
                        team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Programmer)] = MaxCode;
                    }
                    if ((AdjustDepartment & AdjustHRFlags.Design) != 0)
                    {
                        team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Designer)] = MaxDesign;
                    }
                }

                Console.Log(string.Format("Total staff required: C: {0} D: {1} A: {2}",
                                          team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Programmer)],
                                          team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Designer)],
                                          team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Artist)]));
            }

            // Switch team members around so that the team has the correct number of staff with the correct skills
            Dictionary <string, float> specializationMonths = null;

            foreach (SoftwareWorkItem workItem in software)
            {
                SoftwareProduct softwareProduct = workItem.SequelTo;
                SoftwareProduct sequelTo        = softwareProduct == null || !softwareProduct.Traded
                    ? softwareProduct
                    : (SoftwareProduct)null;


                var months = workItem.Type.GetSpecializationMonths(workItem.GetFeatures(), workItem.SWCategory,
                                                                   workItem.OSs, sequelTo);
                if (specializationMonths == null)
                {
                    specializationMonths = months;
                }
                else
                {
                    // Merge dictionaries
                    foreach (KeyValuePair <string, float> valuePair in months)
                    {
                        if (specializationMonths.ContainsKey(valuePair.Key))
                        {
                            specializationMonths[valuePair.Key] =
                                Mathf.Max(specializationMonths[valuePair.Key], valuePair.Value);
                        }
                        else
                        {
                            specializationMonths.Add(valuePair.Key, valuePair.Value);
                        }
                    }
                }
            }

            float totalMonths = specializationMonths.Sum(s => s.Value);

            List <Actor>        chosenEmployees = new List <Actor>();
            IEnumerable <Actor> actors          =
                GameSettings.Instance.sActorManager.Actors.Where(a => (!IdleOnly || a.IsIdle) &&
                                                                 (sourceTeams.Any(t => t == a.GetTeam()) ||
                                                                  a.GetTeam() == team || a.GetTeam() == null));

            Console.Log("Available employees : " + actors.Count());
            foreach (KeyValuePair <string, float> specialization in specializationMonths)
            {
                int numCodersRequired =
                    Mathf.CeilToInt((specialization.Value / totalMonths) *
                                    team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Programmer)]);
                int numDesignersRequired =
                    Mathf.CeilToInt((specialization.Value / totalMonths) *
                                    team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Designer)]);
                int numArtistsRequired =
                    Mathf.CeilToInt((specialization.Value / totalMonths) *
                                    team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Artist)]);

                Console.Log(
                    string.Format("Num {0} staff required: C: {1} D: {2} A: {3}", specialization.Key,
                                  numCodersRequired, numDesignersRequired, numArtistsRequired));

                // Coders
                if ((AdjustDepartment & AdjustHRFlags.Code) != 0)
                {
                    chosenEmployees.AddRange(actors
                                             .OrderByDescending(a =>
                                                                a.employee != null
                                ? a.employee
                                                                .GetSpecialization(Employee.EmployeeRole.Programmer,
                                                                                   specialization.Key, a)
                                : (float?)null)
                                             .Take(numCodersRequired));
                }

                // Designers
                if ((AdjustDepartment & AdjustHRFlags.Design) != 0)
                {
                    chosenEmployees.AddRange(actors
                                             .OrderByDescending(a =>
                                                                a.employee != null
                                ? a.employee
                                                                .GetSpecialization(Employee.EmployeeRole.Designer,
                                                                                   specialization.Key, a)
                                : (float?)null)
                                             .Take(numDesignersRequired));
                }

                // Artists
                if ((AdjustDepartment & AdjustHRFlags.Art) != 0)
                {
                    chosenEmployees.AddRange(actors
                                             .OrderByDescending(a =>
                                                                a.employee != null
                                ? a.employee
                                                                .GetSpecialization(Employee.EmployeeRole.Artist,
                                                                                   specialization.Key, a)
                                : (float?)null)
                                             .Take(numArtistsRequired));
                }
            }

            chosenEmployees = chosenEmployees.Distinct().ToList();

            // Remove old team members
            foreach (Actor actor in GameSettings.Instance.sActorManager.Actors.Where(a => a.GetTeam() == team))
            {
                // Don't kick out the lead
                if (actor.employee.IsRole(Employee.RoleBit.Lead))
                {
                    continue;
                }

                if ((AdjustDepartment & AdjustHRFlags.Art) == 0 && actor.employee.IsRole(Employee.RoleBit.Artist))
                {
                    continue;
                }

                if ((AdjustDepartment & AdjustHRFlags.Code) == 0 && actor.employee.IsRole(Employee.RoleBit.Programmer))
                {
                    continue;
                }

                if ((AdjustDepartment & AdjustHRFlags.Design) == 0 && actor.employee.IsRole(Employee.RoleBit.Designer))
                {
                    continue;
                }

                actor.Team = null;
            }

            // Make sure team has enough staff
            var unattachedStaff = GameSettings
                                  .Instance.sActorManager.Actors.Where(a => a.GetTeam() == null);

            if (chosenEmployees.Count(a => a.employee.IsRole(Employee.EmployeeRole.Programmer)) <
                team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Programmer)])
            {
                chosenEmployees.AddRange(unattachedStaff.OrderByDescending(a => a.employee != null
                        ? a.employee.GetSkill(Employee
                                              .EmployeeRole
                                              .Programmer)
                        : (float?)null)
                                         .Take(team.HR.MaxEmployees
                                               [EmployeeIndex(Employee.EmployeeRole.Programmer)]));
            }

            if (chosenEmployees.Count(a => a.employee.IsRole(Employee.EmployeeRole.Designer)) <
                team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Designer)])
            {
                chosenEmployees.AddRange(unattachedStaff.OrderByDescending(a =>
                                                                           a.employee != null
                            ? a.employee.GetSkill(Employee
                                                  .EmployeeRole
                                                  .Designer)
                            : (float?)null)
                                         .Take(team.HR.MaxEmployees
                                               [EmployeeIndex(Employee.EmployeeRole.Designer)]));
            }

            if (chosenEmployees.Count(a => a.employee.IsRole(Employee.EmployeeRole.Artist)) <
                team.HR.MaxEmployees[EmployeeIndex(Employee.EmployeeRole.Artist)])
            {
                chosenEmployees.AddRange(unattachedStaff.OrderByDescending(a => a.employee != null
                        ? a.employee.GetSkill(Employee
                                              .EmployeeRole
                                              .Artist)
                        : (float?)null)
                                         .Take(team.HR.MaxEmployees
                                               [EmployeeIndex(Employee.EmployeeRole.Artist)]));
            }

            chosenEmployees = chosenEmployees.Distinct().ToList();

            // Find how many staff we have stolen from each team
            IEnumerable <Actor> newActors = chosenEmployees.Where(e => e.GetTeam() != team && e.GetTeam() != null);

            Console.Log("newActors = " + newActors.Count());


            try
            {
                List <GroupCounts> teamCounts = newActors.GroupBy(e => e.Team)
                                                .Select(group => new GroupCounts()
                {
                    Key   = group.Key,
                    Count = group.Count()
                }).ToList();

                Console.Log("teamCounts = " + teamCounts.Count);
                // Add new team members
                foreach (Actor employee in chosenEmployees)
                {
                    employee.Team = team.Name;
                }

                // Which staff are still unattached
                foreach (var teamCount in teamCounts)
                {
                    unattachedStaff = unattachedStaff.Where(e => e.GetTeam() == null);
                    Console.Log(string.Format("After reassignment, {0} staff are unassigned.",
                                              unattachedStaff.Count()));

                    Console.Log(string.Format("Team {0} missing {1} staff.", teamCount.Key, teamCount.Count));
                    IEnumerable <Actor> takenStaff =
                        unattachedStaff.Take(Mathf.Min(unattachedStaff.Count(), teamCount.Count));
                    foreach (Actor employee in takenStaff)
                    {
                        employee.Team = teamCount.Key;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                throw;
            }

            unattachedStaff = unattachedStaff.Where(e => e.GetTeam() == null);
            Console.Log(string.Format("After final reassignment, {0} staff are unassigned.", unattachedStaff.Count()));
            if (unattachedStaff.Any())
            {
                HUD.Instance.AddPopupMessage(
                    unattachedStaff.Count() + " staff are without a team following reassignemnt", "Cogs",
                    PopupManager.PopUpAction.None,
                    0, PopupManager.NotificationSound.Issue, 0f, PopupManager.PopupIDs.None, 0);
            }

            error = null;
            return(true);
        }