Giter Site home page Giter Site logo

Comments (5)

boformer avatar boformer commented on July 17, 2024

I only know that the policies are hidden deep in the source code (was going after it when I created the GUI).

It would definitely be possible to ban more buildings if the building height can be obtained (by filtering the list).

from buildingthemes.

boformer avatar boformer commented on July 17, 2024

I inspected the source code of the game to see how we can override the policy.

public override void ResidentialBuildingAI.SimulationStep:

// seems like this code demolishes level5 buildings in highriseban districts
if (this.m_info.m_class.m_subService == ItemClass.SubService.ResidentialHigh && (cityPlanningPolicies & DistrictPolicies.CityPlanning.HighriseBan) != DistrictPolicies.CityPlanning.None && this.m_info.m_class.m_level == ItemClass.Level.Level5)
{
    SimulationManager instance2 = Singleton<SimulationManager>.instance;
    if (instance2.m_randomizer.Int32(10u) == 0 && Singleton<ZoneManager>.instance.m_lastBuildIndex == instance2.m_currentBuildIndex)
    {
        District[] expr_179_cp_0 = instance.m_districts.m_buffer;
        byte expr_179_cp_1 = district;
        expr_179_cp_0[(int)expr_179_cp_1].m_cityPlanningPoliciesEffect = (expr_179_cp_0[(int)expr_179_cp_1].m_cityPlanningPoliciesEffect | DistrictPolicies.CityPlanning.HighriseBan);
        buildingData.m_flags |= Building.Flags.Demolishing; 
        instance2.m_currentBuildIndex += 1u;
    }
}

private void ResidentialBuildingAI.CheckBuildingLevel:

// "level3" is the calculated level that the building should upgrade to
if (level3 > this.m_info.m_class.m_level)
{
    num3 = 0;
    num5 = 0;

    // this piece of code checks if the policy is enabled
    if (this.m_info.m_class.m_subService == ItemClass.SubService.ResidentialHigh && (cityPlanningPolicies & DistrictPolicies.CityPlanning.HighriseBan) != DistrictPolicies.CityPlanning.None && level3 == ItemClass.Level.Level5)
    {
        District[] expr_414_cp_0 = instance.m_districts.m_buffer;
        byte expr_414_cp_1 = district;
        expr_414_cp_0[(int)expr_414_cp_1].m_cityPlanningPoliciesEffect = (expr_414_cp_0[(int)expr_414_cp_1].m_cityPlanningPoliciesEffect | DistrictPolicies.CityPlanning.HighriseBan);
        // here the level is reduced to 4 if the policy is enabled
        level3 = ItemClass.Level.Level4; 
        num3 = 1;
    }
    // if the upgrade level is still higher than the current level, start upgrading
    if (buildingData.m_problems == Notification.Problem.None && level3 > this.m_info.m_class.m_level && this.GetUpgradeInfo(buildingID, ref buildingData) != null)
    {
        frameData.m_constructState = 0;
        base.StartUpgrading(buildingID, ref buildingData);
    }
}

Similar code can be found in the commercial and office AIs. We could detour the sealed methods and extend the AIs to override the virtual methods to change the behavior of the policy.

from buildingthemes.

bloodypenguin avatar bloodypenguin commented on July 17, 2024

Each mesh has bounds.size property:

  • bounds.size.y is proportional to assets height
  • bounds.size.x is proportional to assets width
  • bounds.size.z is proportional to assets length

from buildingthemes.

boformer avatar boformer commented on July 17, 2024

👍

from buildingthemes.

bloodypenguin avatar bloodypenguin commented on July 17, 2024

Nohealforu's Building Simulation Overhaul overrides No High Rises policy in the suggested way. But it completely replaces buildings AI, which renders it incompatible with our mod. We may use its height calculation algorithm though :)
We definitely need to find a way to detour virtual functions.

from buildingthemes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.