示例#1
0
    //Get the best houses for each category, and updates the dictionary "topHabitation"
    public void GetBestHouses()
    {
        SystemManager systemManager = GameManager.instance.systemManager;

        foreach (Population pop in GameManager.instance.populationManager.populationTypeList)
        {
            //Creates a dictionary assigning each house to it's attraction note
            Dictionary <House, PopulationManager.MoodEvolution> habitationNote = new Dictionary <House, PopulationManager.MoodEvolution>(); // Attribute a note to every habitation
            foreach (House house in systemManager.AllHouses)
            {
                PopulationManager.MoodEvolution houseAttraction = GetHouseNotation(house, pop);
                if (houseAttraction.Get(MoodAffect.noHouse) == 0f)
                {
                    // House is inhabitable
                    habitationNote[house] = houseAttraction;
                }
            }

            //Convert the dictionary to a sorted list
            List <KeyValuePair <House, PopulationManager.MoodEvolution> > sortedHabitations = new List <KeyValuePair <House, PopulationManager.MoodEvolution> >();
            foreach (KeyValuePair <House, PopulationManager.MoodEvolution> notedHabitation in habitationNote)
            {
                sortedHabitations.Add(new KeyValuePair <House, PopulationManager.MoodEvolution>(notedHabitation.Key, notedHabitation.Value));
            }
            // Sorting
            sortedHabitations   = sortedHabitations.OrderBy(x => - x.Value.ToFloat()).ToList();
            topHabitations[pop] = sortedHabitations;
        }
    }
示例#2
0
    //Return an int, the bigger it is, the more attractive is the house
    public PopulationManager.MoodEvolution GetHouseNotation(House house, Population populationType)
    {
        house.UpdateHouseInformations();
        PopulationManager.MoodEvolution notation = new PopulationManager.MoodEvolution();

        //If house isn't connected to spatioport, it sucks
        if (!house.block.isLinkedToSpatioport)
        {
            notation.Add(MoodAffect.noHouse, GameManager.instance.populationManager.moodModifierIfNoHabitation);
            return(notation);
        }

        //If house is already full, it also sucks
        if (house.affectedCitizen.Count >= house.slotAmount)
        {
            notation.Add(MoodAffect.noHouse, GameManager.instance.populationManager.moodModifierIfNoHabitation);
            return(notation);
        }


        bool profileFound = false;
        bool powered      = false;
        bool foodLeft     = false;
        bool jobLeft      = false;
        bool damaged      = false;

        foreach (Population profile in house.acceptedPop)
        {
            if (profile == populationType)
            {
                profileFound = true;
                break;
            }
        }

        if (house.powered)
        {
            powered = true;
        }

        float foodStock = 0;

        Logger.Debug("For house " + house.GetInstanceID() + " there are " + house.foodProvidersInRange.Count + " food providers in range");
        foreach (FoodProvider distributor in house.foodProvidersInRange)
        {
            foodStock += distributor.foodLeft;
        }
        if (foodStock > 0 && foodStock >= GameManager.instance.populationManager.GetFoodConsumption(populationType))
        {
            foodLeft = true;
        }
        else
        {
            foodLeft = false;
        }


        foreach (Occupator occupator in house.occupatorsInRange)
        {
            foreach (Population pop in occupator.acceptedPopulation)
            {
                if (pop == populationType)
                {
                    jobLeft = true;
                    break;
                }
            }
        }

        foreach (KeyValuePair <State, StateBehavior> state in house.block.states)
        {
            if (state.Key == State.Damaged)
            {
                damaged = true;
                break;
            }
        }

        if (!profileFound)
        {
            notation.Add(MoodAffect.wrongPopulationType, moodValues.values[MoodAffect.wrongPopulationType]);
        }
        if (!powered)
        {
            notation.Add(MoodAffect.noPower, moodValues.values[MoodAffect.noPower]);
        }
        if (!foodLeft)
        {
            notation.Add(MoodAffect.noFood, moodValues.values[MoodAffect.noFood]);
        }
        if (!jobLeft)
        {
            notation.Add(MoodAffect.noOccupations, moodValues.values[MoodAffect.noOccupations]);
        }
        if (damaged)
        {
            notation.Add(MoodAffect.damaged, moodValues.values[MoodAffect.damaged]);
        }

        if (notation.ToFloat() >= 0)
        {
            notation.Add(MoodAffect.everythingFine, moodValues.values[MoodAffect.everythingFine]);
        }

        notation.Add(MoodAffect.nuisance, -house.nuisanceImpact);
        foreach (NotationModifier notationModifier in house.notationModifiers)
        {
            notation.Add(MoodAffect.habitationBuff, notationModifier.amount);
        }
        return(notation);
    }