1
\$\begingroup\$

I'm trying to build a mod that places zones on a keypress. How would I accomplish this?

So far I've detected the keypress. But when I modify m_blocks in ZoneManager by calling block.setZone(x,y,zone) The block appears to have changed, but only for the moment. When I run the keycommand again, the data appears to have been reset. I never see the zone change in game, only when I print it to the console.

string outtext = "";
            uint blockCount = Singleton<ZoneManager>.instance.m_blocks.m_size;
            outtext += "start{\n";
            for (int index = 0; index < blockCount; index++) {
                var block = Singleton<ZoneManager>.instance.m_blocks.m_buffer[index];
                if (block.m_valid != 0) {
                    block.SetZone(1, 1, ItemClass.Zone.Industrial);
                    block.RefreshZoning(0);
                    outtext += " valid:" + block.m_valid + " position:" + block.m_position.ToString() + " zone:" + block.GetZone(1, 1) + " \n ";
                }
            }
            outtext += "}";
            Debug.Log("OUTTEXT " + outtext);

I've tried calling block.refreshZoning() as well, but I'm not sure how to calculate the blockid :(.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Feels like this a question for a more specialized forum for cities Skylines modding \$\endgroup\$
    – Natalo77
    Jul 23 '20 at 8:47
1
\$\begingroup\$

The problem was that the equals operator does a deepcopy. I was able to fix this by forcing it to use a reference. This took forever to find out!

string outtext = "";
            uint blockCount = Singleton<ZoneManager>.instance.m_blocks.m_size;
            outtext += "start{\n";
            for (int index = 0; index < blockCount; index++) {
                ref var block = ref Singleton<ZoneManager>.instance.m_blocks.m_buffer[index];
                if (block.m_valid != 0) {
                    block.SetZone(1, 1, ItemClass.Zone.Industrial);
                    block.RefreshZoning(0);
                    outtext += " valid:" + block.m_valid + " position:" + block.m_position.ToString() + " zone:" + block.GetZone(1, 1) + " \n ";
                }
            }
            outtext += "}";
            Debug.Log("OUTTEXT " + outtext);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.