Jump to content
Sims firehouse

Manipulating networks with a Hex editor

22 posts in this topic Last Reply

Highlighted Posts

Posted:
Last Online:  
 

Welcome to my personal thread. I post here from time to time to share some experience and knowledge.

Index:


  Edited by Sims firehouse  
  • Like 7

Share this post


Link to post
Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    #1: 8-way intersection, on which the latest based.

    074br3Y.jpg

    Why create this piece:

    (1) Intersection in the center has the notorious traffic lights.

    (2) Small segments that the slip ramps connect are bugged. Their shape deformed at the moment of saving the asset. It has worsened when I loaded the file and saved it again.

     

    QtquSoB.png

     

    The way to get around (2) was to make the divided part longer, so the curves would become more stable. Because the pillar could only sit on the freeway median, the divided part then extended all the way to the center, above the median, leading to a 8-way intersection.

     

    Note: since it's a game restriction that two networks cannot intersect at an angle less than 45 degrees, 8-way is the limit of multi-way configurations. 

     

    Making an 8-way intersection is easy, but the orthogonal one doesn't do the job. The design has required it be rotated by 22.5 degrees, so I needed to create an 8-way puzzle piece and to make sure it could be rotated by exactly 22.5 degrees.

     

    This is how I created the piece. First, the basic part; for convenience, I took a radius of 10:

    IOTmnaS.gif

    Note in the 5th frame that you need to drag out a 45-degree stub first to let others snap to this angle, so as to run exactly 10 cells on the diagonals.

     

    Bisecting the angle into 22.5 degrees:

    jsvNfUM.gif

    Trigonometry plays a role here: We want to know the minimal radius where the side of the octagon is long enough to create a pillar at the midpoint. It turned out that the minimal radius is 17, since 17 * 2 sin(22.5deg) = 13. Also note only the highway ramp tool is suitable for this job. Other tools like the road will create the pillar off-center.

     

    And finally, how the device for alignment works:

    9fla0Dp.gif

    #2: perfect pentagon with straight and arc tools (Link to the Steam page that gave me inspiration)

    I did a search with keyword "construct pentagon" and decided to try the following two constructions:

    X4vATAP.jpg

     

    ================================

    Section 1: first attempt, left image

     

    Plan: First I will take an arbitrary radius of 20 cells, lay down segments OB and OP1, take midpoint D on segment OB, then connect D and P1. The angle ODP1 then needs to be bisected. The angle bisection plan follows:

    cMe77Pt.jpg

    Draw a segment DE of 10 cells from D along the ray DP1, then draw a perpendicular ray from point E. Also draw a perpendicular ray from point O to intersect it at point N2.

     

    Once the point N2 is determined, draw an arc from P1 to B, using quadratic Bezier tool to approximate the circular arc P1B.

    Finally, draw a vertical from point N2 to reach point P2 on the arc P1B; this shall give us the side of the pentagon P1P2.

     

    Trial: This animated GIF should explain what I'm doing.

    0Yj6oPL.gif

    Error: Then I realized that the distance between the two open ends is not exactly 10 cells; therefore, however hard I tried, I couldn't stitch one sub-piece to another.

    Of4GhxT.jpg

    Reason: The arc tool that game provides is a quadratic Bezier tool. A quadratic function looks like this: y = x2, while a circular function is written in this form: x+ y= r2; the variables are in different degrees, so these two types of functions cannot match perfectly.

    Conclusion: With the arc tool the game provides, we cannot construct a perfect pentagon like we construct them using a compass and straightedge. We have to seek another method to build a perfect pentagon. In section 2 I will avoid using the Bezier tool for theoretical circular arcs.

     

    ===================================

    Section 2: second attempt, right image

     

    Second construction should avoid using circular arc to construct the length of a side of the pentagon.

     

    CiqcOVI.jpg

    Plan and practice: Take the same arbitrary radius of 20 cells, lay down the radial segments OA and OB, then take the midpoint of segment OB as point C. Connect A and C. Now take length of segment AC and make a point P on ray CO so that the distance of CP equals that of AC. Then the distance AP will construct one side of the pentagon. In practice, I rotated the triangle CAP about point C, to triangle CP'A; this way, I can save my time by saving one potential prefab: the segment AC.

     

    Then the complex thing comes: How can I build a pentagon with only one side of it but no angle?

     

    The answer: I must build an angle, from the lengths that are constructible. I must find an angle with one side being a constructible number.

     

    Then I drew this diagram, like when I was taught in high school:

    5RezGT5.png

     

    To plan out in detail, I need to ensure that the midpoint of the side can be located. I have taken a radius of 20, and thus the side is 20 * 2 sin(36deg) = 23.5 cells long. This will ensure me two segments if I connect the two vertices. Then the Highway Ramp tool is the sole tool to do the job because other tools such as road will always try to divide a length into at least one whole-number segment, and therefore miss the midpoint.

     

    Once the midpoint is determined, I marked it and proceeded to construct the normal to the side, which I saved as a prefab later. After the normal is constructed, I returned to the file containing the side of the pentagon and merge these two pieces into another prefab, which I finally used to construct the whole pentagon.

    5vVKh5d.gif

     

    Conclusion: The perfect pentagon is possible through a combination of constructible numbers, if the only tool available are the straight line and the function to save a piece as a prefabricated one. The prefab can be rotated prior to placement, so it is effectively a compass as used in the "compass-and-straightedge" method. The highway ramp tool is necessary for almost every midpoint we want to create on a segment. And last but not least, do not misunderstood the Bezier tool; it cannot be used to create the true circle!

     

    Note: I may have misused the term "normal" here. Please feel free to correct me.


      Edited by Sims firehouse  
    • Like 4

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    This is awesome Sims, thank you so much for sharing your insights and knowledge, I'm learning a ton from you mate.

     

    I did something similar to trisect the angle for my circular town.

     

    Eager to see what else you post. Cheers.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    I love this combined geometrical and trigonometrical approach for creating intersections, angled roads and road polygons.


    Dear sir/madam/whoever will read this!

    This profile is now defunct.

    Computer problems and issues with accessing my Imageshack account meant My SC4 CJ Scrapbook was lost and utterly irretrievable. This setback put me off SC4 for many months.

    Apologies for the inconvenience and for the lost pictures.

    But that SC4 itch did not go away and it had to be scratched! I have started afresh with a new account here- The British Sausage

    The URS is a spiritual successor to the SC4 CJ Scrapbook.

    With this update this will be the last time I visit my original Simtropolis account- admin/mods feel free to remove it or do whatever you need to do. I have no further use for the Ln X (BLANKBLANK) account.

     

    With regards, Miles Saunders-Priem aka. Ln X aka. The British Sausage

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Very cool! I guess with base 5 geometry you could create girih tiles in the asset editor?

    tumblr_lsf9f8NZ8l1qj75sao1_500.jpg

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    #3: Girih-patterned road layout would be a special tourist attraction, if not the worst city plan of all. :D

     

    Those are interesting to make, and doable - yes, the intersecting angles of segments within the girih pattern are 72, 108, and 144 degrees.

     

    I can make girih tiles without the borders, starting with the decagon and make it the largest size possible - that's 31 cells in radius - and add the other four elements: the hexagon, the bow tie, the rhombus, and the pentagon. Then these five elements can be placed in any combination to create a unique girih pattern!

     

    Update: I'm ready to test these girih tiles!

    It is downloadable from here: 

     

    Q0CF0LD.jpg


      Edited by Sims firehouse  
    • Like 2

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Scratch that, I found them on the steam workshop! Amazing work!!

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Just an update to say that traffic is really surprisingly manageable with a mixture of higher and lower density buildings. The picture above is just made from tiling the hexagon type, and the road network is not so different from a standard grid layout topologically speaking. There are no 3 way intersections, only 4 way intersections and the more randomised nature of the roads means the quickest routes are more various and unique to each journey than a standard grid layout. Moreover the less efficient zoning % means less traffic in general, and when main thoroughfares emerge they can be upgraded to wider roads or overpasses. My next project will be to map out a complete road structure to a custom base-10 region with decagonal and pentagonal islands as a cool sandbox. Thanks again, you've done a super job on these!

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    I don't even know what to say. . . This is interesting though.

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Hey Sims, I was wondering if you could give a few pointers on creating underpasses like the ramp in your 3-level semi-directional T crossing? http://steamcommunity.com/sharedfiles/filedetails/?id=422058740

    I can make the trench just fine, but when it comes to building the highway bridge across it, I either get a graphical glitch where the cliff faces disappear or I have to raise the highway and make a bridge that way. I can't get the highway to stay level and flat over the trench. Any pointers would be very much appreciated! :)

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    I can make the trench just fine, but when it comes to building the highway bridge across it, I either get a graphical glitch where the cliff faces disappear or I have to raise the highway and make a bridge that way. I can't get the highway to stay level and flat over the trench. Any pointers would be very much appreciated! :)

     

    First, the trench has to be at least 9 meters deep (since 6 meters won't work.) And wide enough to negate this problem (edges of the plateau are uneven). I'd suggest the trench bottom be at least 2 cells wide.

     

    Second, control the bridge length within 12 cells. If you have to build a longer overpass than this, you can break it up by extending the bridge <= 12 cells at a time, having some pillars in the middle.

     

    bVMEcKI.jpg

    • Like 4

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Is there a way to see the cell grid in the normal game mode? 

    So, if I have it correct, if my trench is at least 2 cells wide, and 9m deep, I should be able to drag the highway straight across it as long as it's less than 12 cells long?

     

    Does it make any difference if the trench is not fully perpendicular to the highway? I wanted to have a train track running under my highway in a trench at about a 30 degree angle from the direction of the highway.

    I'm sure I was within those parameters, but I'll give it another try and keep it all in mind. Thanks!

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Just had a go, both in the asset editor and in the normal game, and I can't get it to work. How do you be sure you have a 9m trench? I can't see any way to specify a trench depth, but my trench looked visually deeper than in your example. I keep winding up with something resembling your 14+ cell glitch, but the sides of the trench under the highway disappear as well.  :(

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    Just had a go, both in the asset editor and in the normal game, and I can't get it to work. How do you be sure you have a 9m trench? I can't see any way to specify a trench depth, but my trench looked visually deeper than in your example. 

     

    My mod will not load outside of the editor. I have intended it.

    In-game terraforming tool is provided by Rollo; his version of ditch tool lowers the ground by 12 meters, so your trench is indeed deeper.

     

    I keep winding up with something resembling your 14+ cell glitch, but the sides of the trench under the highway disappear as well.   :(

     

    Make sure the trench bottom itself is as wide as or wider than a road. demolish the road in the trench to check that. If your trench isn't wide enough, you can't build a bridge (showing elevated-road model) across it.

    • Like 1

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

     

     

    Make sure the trench bottom itself is as wide as or wider than a road. demolish the road in the trench to check that. If your trench isn't wide enough, you can't build a bridge (showing elevated-road model) across it.

     

     

    ... Thinking right now, that might actually be my problem. I usually use the levelling tool at ground height to make the trench neat and tidy around the road. As the road is already in place, it keeps the ground looking where it is, but if I demolish the road it might display the ground all level again. That's probably where I'm going wrong. Thanks for the tip! :D

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    Just wanted to pop back in and say that it was indeed my problem - I was building a channel, building a road in it, then using the level tool to tidy it all up. The ground inside the channel was therefore not flattened down, and the bridge failed. Thanks for the tip! 

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    #4: Manipulating networks with a Hex editor
     
    In this tutorial, I will describe:
     
    (1) Structure of the serialized data stored in the field m_paths, and
    (2) Coordinate system used in the game.
    If you don't have a hex editor, get the HxD from this website: http://mh-nexus.de/en/hxd/

     

    Caution: Changing the file size will break your asset. This means you cannot add paths to or remove them from the path stack. What is available is to replace a path with another one having the same name length.



     
    1. Structure of serialized path information
     
    1.1 Path stack
     
    Under the section where m_paths is defined, a stack of paths is found. Immediately after the key word, there is a 32-bit integer describing the size of the stack; that is, how many paths are stored. Be sure to check this number; the file won't load if this number is wrong.
     
    Note: Integers and floats, which we will see later, are stored with the least significant byte first. For example, a 32-bit unsigned integer 2 is expressed as 00 00 00 02 but stored as 02 00 00 00.
     
    Remark: Since the network stack size is represented by a 32-bit integer, the theoretical maximal number of network objects within a save game is 2^32, or 4,294,967,296. You may think four billion is big enough, but a network segment is very short; the maximal length of a segment is between 12 and 13 cells, so there tend to be a lot more objects in the stack than you'd think. This is why many players are hitting this object limit.
     
    OqhkPEJ.jpg
     
    1.2 Path structure
     
    Each path begins with its type name. Before the name string, there is an integer describing how many characters, or how many bytes, the name uses. It's also important to check the character count, or it will cause the file to fail to load up in the game.
     
    After the name is the section describing the position of the path in a 3D space. There are three key points controlling the length and direction of the path, and whether it is straight or curved. Similarly, before these points there are also integers that reflect the number of the stack, but these integers are constant. First two points are the start and end positions. The third point defines the control node of the curve or does nothing if it lies on the straight line between two nodes.
     
    The three coordinates of each point are stored as 32-bit floating-point numbers, with the least significant byte first. Their values are difficult to calculate manually; you might want to use a converter instead, but be careful – these bytes should be written in the reverse order to successfully convert them.
     
    The next variable is a boolean which determines if the direction of the path goes reverse. This is the basis of the tool for switching directions. It also offers great convenience if we want to do this manually.

     

    The last four bytes, not captioned in the image below, are another float called m_maxSnapDistance. Its default for virtually all networks is 0.1, which means they will snap to existing network if within a 0.1 meters' distance. It can also be edited.
     
    pAB5Iv1.png



     
    2. Map coordinate system
     
    In the default view, the three axes are laid out as: X pointing to the left, Y toward the top, and Z forward.
     
    The unit length in this system is 1 meter, which equals 1/8 a cell length. The origin is at the center of the map.
     
    From the origin, the map extends 1080 cells, or 8640 meters along X and Z directions. The asset editor provides an editable area that extends as far as 32 cells, or 256 meters in one direction. From the default height, one can go down at most 60 meters, or go up at most (1024 - 60 = 964) meters. 
     
    xhzMWfo.jpg
      Edited by Sims firehouse  
    • Like 1

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    Reference 1: List of float representations of common numbers

     

    From 0 to 32 meters (4 cells):


    Meters | Cells | Float in Little Endian (least significant byte first)
    0      | 0     | 00 00 00 00
    1, -1  | 1/8   | 00 00 80 3F, 00 00 80 BF
    2, -2  | 1/4   |       00 40,       00 C0
    3, -3  | 3/8   |       40 40,       40 C0
    4, -4  | 1/2   |       80 40,       80 C0
    6, -6  | 3/4   |       C0 40,       C0 C0
    8, -8  | 1, -1 |       00 41,       00 C1
    12, -12| 1 1/2 |       40 41,       40 C1
    16, -16| 2, -2 |       80 41,       80 C1
    24, -24| 3, -3 |       C0 41,       C0 C1
    32, -32| 4, -4 |       00 42,       00 C2
    


     

    From 4 cells upwards until 16:


    Cells | Float in Little Endian (least significant byte first)
    4, -4 | 00 00 00 42, 00 00 00 C2
    5, -5 |       20 42,       20 C2
    6, -6 |       40 42,       40 C2
    7, -7 |       60 42,       60 C2
    8, -8 |       80 42,       80 C2
    9, -9 |       90 42,       90 C2
    10    |       A0 42,       A0 C2
    11    |       B0 42,       B0 C2
    12    |       C0 42,       C0 C2
    13    |       D0 42,       D0 C2
    14    |       E0 42,       E0 C2
    15    |       F0 42,       F0 C2
    16    |       00 43,       00 C3
    


     

    Use the converter for the rest of the numbers: http://www.h-schmidt.net/FloatConverter/IEEE754.html

    But be careful: In the converter you need to write the most significant byte first, which is the reverse from those listed here.

    A common mistake is to break up a byte into two hexes. Don't just write the hexes in reverse.


     

    Reference 2: Types of paths

    Notice that most of them have spaces in their names, while HighwayRamp and HighwayRampElevated are the exceptions.


    [Common Types]                 | Length | Hex representation of length
    Gravel Road                    | 11     | 0B
    Basic Road                     | 10     | 0A
    Basic Road Decoration Grass    | 27     | 1B
    Basic Road Decoration Trees    | 27     | 1B
    Basic Road Elevated            | 19     | 13
    Oneway Road                    | 11     | 0B
    Oneway Road Decoration Grass   | 28     | 1C
    Oneway Road Decoration Trees   | 28     | 1C
    Oneway Road Elevated           | 20     | 14
    Medium Road                    | 11     | 0B
    Medium Road Decoration Grass   | 28     | 1C
    Medium Road Decoration Trees   | 28     | 1C
    Medium Road Elevated           | 20     | 14
    Large Road                     | 10     | 0A
    Large Road Decoration Grass    | 27     | 11
    Large Road Decoration Trees    | 27     | 11
    Large Road Elevated            | 19     | 13
    Large Oneway                   | 12     | 0C
    Large Oneway Decoration Grass  | 29     | 1D
    Large Oneway Decoration Trees  | 29     | 1D
    Large Oneway Elevated          | 21     | 15
    Highway                        | 7      | 07
    Highway Elevated               | 16     | 10
    Highway Barrier                | 15     | 0F
    HighwayRamp                    | 11     | 0B
    HighwayRampElevated            | 19     | 13
    Train Track                    | 11     | 0B
    Train Track Elevated           | 20     | 14
    Pedestrian Pavement            | 19     | 13
    Pedestrian Gravel              | 17     | 11
    Pedestrian Elevated            | 19     | 13
    
    [For Stations, Airport, Harbor] (not buildable nor bulldozable)
    Pedestrian Connection          | 21     | 15
    Pedestrian Connection Inside   | 28     | 1C
    Train Station Track            | 19     | 13
    Train Cargo Track              | 17     | 11
    Airplane Stop                  | 13     | 0D
    Airplane Runway                | 15     | 0F
    Airplane Taxiway               | 16     | 10
    Ship Dock                      | 9      | 09
    Ship Dockway                   | 12     | 0C
    
    [For Metro Stations exclusively] (not buildable nor bulldozable)
    Metro Station Track               | 19  | 13
    Pedestrian Connection Surface     | 29  | 1D
    Pedestrian Connection Underground | 33  | 21

      Edited by Sims firehouse  
    • Like 2

    Share this post


    Link to post
    Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    I've updated the information on the structure of the m_path field. The good news is, we can manually add or remove paths in a file, but we need to pay attention to two numbers:

     

    The first number is the size of the stack in m_paths, namely the number of paths stored under this field. It is a 32-bit integer immediately following the string m_paths. The second number is the character or byte count of the name of individual paths. It is an 8-bit integer that comes before the name field.

     

    If these two numbers do not correctly reflect the size of stack or length of name that comes after them, the save file will fail to load.

     

    On an additional note, since the network stack size is represented by a 32-bit integer, the theoretical maximal number of network objects within a save game is 2^32, or 4,294,967,296. You may think four billion is big enough, but a network segment is very short; the maximal length of a segment is between 12 and 13 cells, so there tend to be a lot more objects in the stack than you'd think.

    Share this post


    Link to post
    Share on other sites

    Sign In or register to comment...

    To comment in reply, you must be a community member

    Sign In  

    Already have an account? Sign in here.

    Sign In Now

    Create an Account  

    Sign up to join our friendly community. It's easy!  

    Register a New Account


    • Recently Browsing   0 members

      No registered users viewing this page.

    ×

    Thank You for the Continued Support!

    Simtropolis depends on donations to fund site maintenance costs.
    Without your support, we just would not be in our 24th year online!  You really help make this a great community. *:thumb:

    But we still need your support to stay online. If you're able to, please consider a donation to help us stay up and running. This helps sustain a platform where we can share our community creations for years to come.

    Make a Donation, Get a Gift!

    Expand your city with the best from the Simtropolis Exchange.
    Make a Donation and get one or all three discs today!

    STEX Collections

    By way of a "Thank You" gift, we'd like to send you our STEX Collector's DVD. It's some of the best buildings, lots, maps and mods collected for you over the years. Check out the STEX Collections for more info.

    Each donation helps keep Simtropolis online, open and free!

    Thank you for reading and enjoy the site!

    More About STEX Collections