public static List <GameEntity> GetSortedCompetitors(GameEntity company, GameContext gameContext, ref int index, bool directCompetitors) { // first - Strong // last - Weak var competitors = (directCompetitors ? GetDirectCompetitors(company, gameContext, true) : GetCompetitorsOf(company, gameContext, true)) .OrderByDescending(c => Economy.CostOf(c, gameContext)) .ToList(); index = competitors.FindIndex(c => c.company.Id == company.company.Id); return(competitors); }
public static bool IsShareholderWillAcceptCorporationOffer(int companyId, int shareholderId, GameContext gameContext) { var cost = Economy.GetCompanyCost(gameContext, companyId); var baseDesireToSellCompany = GetBaseDesireToSellShares(gameContext, companyId, shareholderId); var wantsToSellShares = true || baseDesireToSellCompany == 1; var corporationCost = Economy.GetCompanyCost(gameContext, companyId); var isSmallComparedToCorporation = cost * 100 < 15 * corporationCost; return(wantsToSellShares && isSmallComparedToCorporation); }
public static List <InvestmentGoal> GetCommonGoals(GameEntity company, GameContext Q) { var goals = new List <InvestmentGoal>(); #region data bool releasedProduct = company.hasProduct && company.isRelease; bool isGroup = !company.hasProduct; var income = Economy.GetIncome(Q, company); bool profitable = Economy.IsProfitable(Q, company); bool solidCompany = (releasedProduct || isGroup) && income > 100_000; // weaker GameEntity weakerCompany = Companies.GetWeakerCompetitor(company, Q, true); // null; // stronger GameEntity strongerCompany = Companies.GetStrongerCompetitor(company, Q, true); // null; #endregion if (solidCompany) { goals.Add(new InvestmentGoalGrowCost(Economy.CostOf(company, Q) * 3 / 2)); goals.Add(new InvestmentGoalGrowProfit(Economy.GetIncome(Q, company) * 3 / 2)); //goals.Add(InvestorGoalType.GrowCompanyCost); //goals.Add(InvestorGoalType.GrowIncome); if (!profitable) { goals.Add(new InvestmentGoalBecomeProfitable(Economy.GetIncome(Q, company))); //goals.Add(InvestorGoalType.BecomeProfitable); } if (strongerCompany != null) { goals.Add(new InvestmentGoalOutcompeteByIncome(strongerCompany.company.Id, strongerCompany.company.Name)); //goals.Add(new InvestmentGoalOutcompeteByCost(strongerCompany.company.Id, strongerCompany.company.Name)); //goals.Add(InvestorGoalType.OutcompeteCompanyByIncome); //goals.Add(InvestorGoalType.OutcompeteCompanyByCost); ////goals.Add(InvestorGoalType.OutcompeteCompanyByUsers); } } return(goals); }
public static IEnumerable <ChannelInfo> GetMaintainableMarketingChannels(GameEntity product, GameContext gameContext) { var payer = product.isFlagship ? Companies.GetPlayerCompany(gameContext) : product; int periods = product.isFlagship ? 10 * 4 : 1; var profit = Economy.GetProfit(gameContext, payer); var spareBudget = profit; var channels = new List <ChannelInfo>(); var allChannels = GetAllMarketingChannels(product).OrderBy(c => Marketing.GetChannelCost(product, c.ID)).ToList(); var spareBudget2 = Economy.BalanceOf(payer); // spareBudget + if (profit < 0) { spareBudget2 += profit; } for (var i = 0; i < allChannels.Count(); i++) { var c = allChannels[i]; var adCost = Marketing.GetChannelCost(product, c.ID); if (Marketing.IsActiveInChannel(product, c.ID) || adCost == 0) { channels.Add(c); continue; } // 5, cause some channels take too much time to recover if (adCost > spareBudget2) { if (product.isFlagship) { //Debug.Log("not enough money for " + c.ID + " " + Format.Money(adCost * 3) + " spare=" + Format.Money(spareBudget2)); } break; } channels.Add(c); spareBudget2 -= adCost; } return(channels); return(allChannels .Where(IsCanMaintainChannel(product, spareBudget)) ); }
public static long GetBiggestMaintenanceOnMarket(GameContext context, GameEntity niche) { var players = GetProductsOnMarket(context, niche.niche.NicheType); var productCompany = players .OrderByDescending(p => Economy.GetProductCompanyMaintenance(p, context)) .FirstOrDefault(); if (productCompany == null) { return(0); } return(Economy.GetProductCompanyMaintenance(productCompany, context)); }
public static long GetLowestIncomeOnMarket(GameContext context, GameEntity niche) { var players = GetProductsOnMarket(context, niche.niche.NicheType); var productCompany = players .OrderBy(p => Economy.GetProductCompanyIncome(p, context)) .FirstOrDefault(); if (productCompany == null) { return(0); } return(Economy.GetProductCompanyIncome(productCompany, context)); }
public static void SetJobOffer(HumanFF human, GameEntity company, JobOffer offer, int teamId, GameContext gameContext) { var o = new ExpiringJobOffer { Accepted = true, JobOffer = offer, CompanyId = company.company.Id, HumanId = human.HumanComponent.Id, DecisionDate = -1 }; AddOrReplaceOffer(company, human, o); Economy.UpdateSalaries(company, gameContext); }
public static long GetMarketSize(GameContext gameContext, NicheType nicheType) { var products = GetProductsOnMarket(gameContext, nicheType); try { return(products .Sum(p => Economy.CostOf(p, gameContext))); } catch { Debug.LogWarning("Get market size of " + Enums.GetFormattedNicheName(nicheType)); } return(0); //return products.Select(p => CompanyEconomyUtils.GetProductCompanyBaseCost(gameContext, p.company.Id)).Sum(); }
public static void SpawnProposals(GameContext context, GameEntity company) { long cost = Economy.CostOf(company, context); var date = ScheduleUtils.GetCurrentDate(context); var potentialInvestors = GetPotentialInvestors(context, company); foreach (var potentialInvestor in potentialInvestors) { var modifier = 50 + UnityEngine.Random.Range(0, 100); long valuation = cost * modifier / 100; var max = GetMaxInvestingAmountForInvestorType(potentialInvestor); var ShareholderId = potentialInvestor.shareholder.Id; var Duration = 10; // UnityEngine.Random.Range(5, 10); // TODO increase offer on early stages // or increase company valuation instead! var offer = Math.Min(valuation / 20, max); //var goal = new InvestmentGoalUnknown(InvestorGoalType.GrowCompanyCost); var goal = company.companyGoal.Goals[0]; var p = new InvestmentProposal { Investment = new Investment(offer, Duration, goal, date), AdditionalShares = (int)GetNewSharesSize(context, company, offer), ShareholderId = ShareholderId, WasAccepted = false }; // you cannot invest in yourself! if (company.hasShareholder && company.shareholder.Id == ShareholderId) { continue; } AddInvestmentProposal(company, p); } }
public static void SpawnProposals(GameContext context, int companyId) { long cost = Economy.GetCompanyCost(context, companyId); var c = Get(context, companyId); var potentialInvestors = GetPotentialInvestors(context, companyId); var investorsCount = potentialInvestors.Length; foreach (var potentialInvestor in potentialInvestors) { var modifier = (50 + UnityEngine.Random.Range(0, 100)); long valuation = cost * modifier / 100; var ShareholderId = potentialInvestor.shareholder.Id; long offer = valuation / 10; var max = GetMaxInvestingAmountForInvestorType(potentialInvestor); if (offer > max) { offer = max; } var p = new InvestmentProposal { Valuation = valuation, Offer = valuation / 10, ShareholderId = ShareholderId, InvestorBonus = InvestorBonus.None, WasAccepted = false }; // you cannot invest in yourself! if (c.hasShareholder && c.shareholder.Id == ShareholderId) { continue; } AddInvestmentProposal(context, companyId, p); } }
internal static void AcceptInvestmentProposal(GameContext gameContext, int companyId, int investorId) { var p = GetInvestmentProposal(gameContext, companyId, investorId); //if (p == null) // return; long cost = Economy.GetCompanyCost(gameContext, companyId); var allShares = (long)GetTotalShares(gameContext, companyId); long shares = allShares * p.Offer / cost; AddShareholder(gameContext, companyId, investorId, (int)shares); Economy.IncreaseCompanyBalance(gameContext, companyId, p.Offer); Economy.DecreaseInvestmentFunds(gameContext, investorId, p.Offer); MarkProposalAsAccepted(gameContext, companyId, investorId); }
public static void JoinCorporation(GameContext gameContext, int companyId, int buyerInvestorId) { var target = Get(gameContext, companyId); var corporation = Investments.GetCompanyByInvestorId(gameContext, buyerInvestorId); var shareholders = GetShareholders(target); int[] array = new int[shareholders.Keys.Count]; var corporationCost = Economy.GetCompanyCost(gameContext, corporation); var targetCost = Economy.GetCompanyCost(gameContext, target); var corporationShares = Companies.GetTotalShares(gameContext, companyId); var emitedShares = corporationShares * targetCost / corporationCost; // give shares in corporation to shareholders of integratable company foreach (var shareholderId in array) { var percentOfSharesInPreviousCompany = GetShareSize(gameContext, companyId, shareholderId); var newShare = emitedShares * percentOfSharesInPreviousCompany / 100; AddShares(gameContext, corporation, shareholderId, (int)newShare); Debug.Log($"investor {GetInvestorName(gameContext, shareholderId)} will get {(int)newShare} shares of corporation {corporation.company.Name}"); } foreach (var shareholderId in array) { RemoveShareholder(target, shareholderId); } AddShareholder(gameContext, companyId, buyerInvestorId, 100); target.isIndependentCompany = false; NotifyAboutCorporateAcquisition(gameContext, buyerInvestorId, companyId); }
public static long GetInvestorCapitalCost(GameContext gameContext, GameEntity human) { var holdings = Companies.GetPersonalHoldings(gameContext, human.shareholder.Id, false); return(Economy.GetHoldingCost(gameContext, holdings)); }
public static long GetInvestorCapitalCost(GameContext gameContext, GameEntity human) { var holdings = Investments.GetHoldings(human, gameContext, false); return(Economy.GetHoldingsCost(gameContext, holdings)); }
public static bool IsMeetsIPOCompanyCostRequirement(GameContext gameContext, int companyId) { return(Economy.GetCompanyCost(gameContext, companyId) > Balance.IPO_REQUIREMENTS_COMPANY_COST); }
public static bool IsMeetsIPOProfitRequirement(GameContext gameContext, int companyId) { return(Economy.GetProfit(gameContext, companyId) > Balance.IPO_REQUIREMENTS_COMPANY_PROFIT); }
public static bool IsAllReleasedCompaniesAreProfitable(GameEntity niche, GameContext gameContext) { var releasedProducts = GetProductsOnMarket(niche, gameContext).Where(p => p.isRelease); return(releasedProducts.All(p => Economy.IsProfitable(gameContext, p.company.Id))); }
public static List <InvestmentGoal> GetGroupOnlyGoals(GameEntity company, GameContext Q) { var goals = new List <InvestmentGoal>(); var groupGoals = new List <InvestorGoalType> { InvestorGoalType.AcquireCompany, InvestorGoalType.DominateSegment, // 50%+ users InvestorGoalType.DominateMarket, // OWN ALL COMPANIES InvestorGoalType.BuyBack, InvestorGoalType.IPO, }; #region data var income = Economy.GetIncome(Q, company); bool solidCompany = income > 50_000; GameEntity weakerCompany; // null; #endregion var daughters = Companies.GetDaughterProducts(Q, company); if (solidCompany) { if (daughters.Any()) { var flagship = daughters.First(); var flagshipCompetitors = Companies.GetDirectCompetitors(flagship, Q, false); if (flagshipCompetitors.Any()) { weakerCompany = flagshipCompetitors.OrderByDescending(c => Economy.CostOf(c, Q)).Last(); } else { weakerCompany = Companies.GetWeakerCompetitor(company, Q, true); } // if there are weaker companies if (weakerCompany != null) { var acquisitionGoal = new InvestmentGoalAcquireCompany(weakerCompany.company.Id, weakerCompany.company.Name); if (!CanCompleteGoal(company, Q, acquisitionGoal)) { goals.Add(acquisitionGoal); } } } } #region DominateSegment //if (solidCompany && company.companyFocus.Niches.Count == 1) //{ // var first = daughters.First(); // var positioning = Marketing.GetPositioning(first); // if (Companies.GetMarketShareOfCompanyMultipliedByHundred(company, Q) < 2) // goals.Add(InvestorGoalType.DominateSegment); //} #endregion if (solidCompany && daughters.Length > 2) { AddOnce(goals, company, new InvestmentGoalDominateMarket(company.companyFocus.Niches.First())); } if (Completed(company, InvestorGoalType.DominateMarket)) { return(OnlyGoal(new InvestmentGoalBuyBack())); } return(goals); }
static void ReplaceTeam(GameEntity company, GameContext gameContext, TeamComponent t) { company.ReplaceTeam(t.Morale, t.Organisation, t.Managers, t.Workers, t.Teams, t.Salaries); Economy.UpdateSalaries(company, gameContext); }