Beispiel #1
0
            private static bool CreatePotentialContract(
                StarSystem system,
                SimGameState.ContractDifficultyRange diffRange,
                ContractOverride contractOvr,
                Dictionary <string, WeightedList <SimGameState.ContractParticipants> > validTargets,
                MapAndEncounters level,
                int encounterContractTypeID,
                out SimGameState.PotentialContract returnContract)
            {
                returnContract = new SimGameState.PotentialContract();
                if (Globals.Sim.GetValidFaction(system, validTargets, contractOvr.requirementList, out var chosenContractParticipants))
                {
                    system.SetCurrentContractFactions(chosenContractParticipants.Employer, chosenContractParticipants.Target);
                    if (Globals.Sim.DoesContractMeetRequirements(system, level, contractOvr))
                    {
                        returnContract = new SimGameState.PotentialContract
                        {
                            contractOverride = contractOvr,
                            difficulty       = actualDifficulty,
                            employer         = chosenContractParticipants.Employer,
                            target           = chosenContractParticipants.Target,
                            employerAlly     = chosenContractParticipants.EmployersAlly,
                            targetAlly       = chosenContractParticipants.TargetsAlly,
                            NeutralToAll     = chosenContractParticipants.NeutralToAll,
                            HostileToAll     = chosenContractParticipants.HostileToAll
                        };
                        return(true);
                    }
                }

                return(false);
            }
Beispiel #2
0
        internal static Contract GenerateContract(StarSystem system, int minDiff, int maxDiff, string employer = null,
                                                  List <string> opFor = null, bool usingBreadcrumbs = false, bool includeOwnershipCheck = false)
        {
            min = minDiff;
            max = maxDiff;
            actualDifficulty = Globals.Rng.Next(min, max + 1);
            var difficultyRange    = new SimGameState.ContractDifficultyRange(actualDifficulty, actualDifficulty, ContractDifficulty.Easy, ContractDifficulty.Easy);
            var potentialContracts = GetSinglePlayerProceduralContractOverrides(difficultyRange).ToDictionary(k => k.Key, v => v.Value);
            var playableMaps       = GetSinglePlayerProceduralPlayableMaps(system, includeOwnershipCheck);
            var validParticipants  = GetValidParticipants(system, employer, opFor);
            var source             = playableMaps.Select(map => map.Map.Weight);
            var activeMaps         = new WeightedList <MapAndEncounters>(WeightedListType.SimpleRandom, playableMaps.ToList(), source.ToList());
            var next = activeMaps.GetNext();

            LogDebug($"{system.Name} {difficultyRange.MinDifficulty}/{difficultyRange.MaxDifficulty} {potentialContracts.Count} {validParticipants.Count} {next._encounters.Count}");
            var mapEncounterContractData = Globals.Sim.FillMapEncounterContractData(system, difficultyRange, potentialContracts, validParticipants, next);

            system.SetCurrentContractFactions();
            var gameContext = new GameContext(Globals.Sim.Context);

            gameContext.SetObject(GameContextObjectTagEnum.TargetStarSystem, system);
            if (mapEncounterContractData.FlatContracts.rootList == null ||
                mapEncounterContractData.FlatContracts.rootList.Count < 1)
            {
                loops++;
                LogDebug("Recursion...");
                if (loops > 10)
                {
                    loops = 0;
                    return(null);
                }

                return(GenerateContract(system, minDiff, maxDiff, employer, opFor, usingBreadcrumbs, includeOwnershipCheck));
            }

            return(CreateProceduralContract(system, usingBreadcrumbs, next, mapEncounterContractData, gameContext));
        }
Beispiel #3
0
 private static Dictionary <int, List <ContractOverride> > GetSinglePlayerProceduralContractOverrides(SimGameState.ContractDifficultyRange diffRange)
 {
     return(MetadataDatabase.Instance.GetContractsByDifficultyRangeAndScopeAndOwnership(
                (int)diffRange.MinDifficultyClamped,
                (int)diffRange.MaxDifficultyClamped,
                Globals.Sim.ContractScope, true)
            .Where(c => c.ContractTypeRow.IsSinglePlayerProcedural)
            .GroupBy(c =>
                     (int)c.ContractTypeRow.ContractTypeID, c => c.ContractID)
            .ToDictionary(c => c.Key, c => c.Select(ci => Globals.Sim.DataManager.ContractOverrides.Get(ci))
                          .ToList()));
 }