Jump to content




City Generating Script


24 replies to this topic

#1 elopus001

  • Members
  • 15 posts

Posted 01 November 2015 - 09:28 PM

This program for command computers generates a bunch of skyscrapers in a rectangular grid pattern.

Posted Image

Here is an example. I had to run the script once as a 1x1 and once as a 2x2 to get this shape.
All the blocks used are fully configurable and should support mod blocks.

The goal of this project is a re-write/completion of this http://www.computerc...dural-building/


The current version is 3.2

To add this to your computer, use the following command:

pastebin get DZ78widc citygen

Old versions:
Spoiler

You can then use the following command to generate a city:

citygen <corner x=""> <height of="" base="" level=""> <corner z=""> <chunks in="" x="" direction=""> <chunks in="" y="" direction="">

To Do:
  • Add roads (will likely require a re-write)

  • Add doors

  • Add multi-plot buildings (will likely require a re-write so I will try to tack it on with roads)

  • Add more buildings

  • Make the pattern have less grids (and multiple height levels)

  • Log building (and block) placement

  • Add to the skyscrapers (ladders (with random orientation), fire escapes)

  • Street lights

  • Fill air blocks option
Known Issues:
  • Occasionally misses blocks.

  • Fill roof block next to ladder with outside material

  • Runs out of storage space due to logging (commented out log)
Screenshots:
Spoiler

Video:
Spoiler

Edited by elopus001, 07 November 2015 - 09:21 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 02 November 2015 - 06:36 AM

If I might add to your to-do list: I feel that having different height levels to the ground would lead to a much more "natural" looking city.

#3 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 02 November 2015 - 08:48 AM

Maybe add roads and streets.

About what BB said, you can get the probability a construction is a skyscraper, and according to that generate a skyscraper or a house. You can also toy around with the sizes: The base size would be 6X6, there is a 30% a skyscraper might be 12x6. So play with math.random and look at the probabilities.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 02 November 2015 - 09:26 AM

Well, more I was referring to the ground on which the houses were built. Say you specified building across a 5x5 chunk area. You might have the ground of the center 3x3 section raised somewhat, and the ground of the center chunk raised a little higher still - creating a hill.

Building houses on these chunks would be easy enough, the only (somewhat) tricky bit would be getting the roads and footpaths to tilt according to the slope and connect to the building entranceways.

#5 Baaleos

  • Members
  • 11 posts

Posted 02 November 2015 - 12:51 PM

This program looks good.
I was wondering if it would be possible to configure the delay between setting each block?
Eg: Avoid TPS issues by having the structure/operation completed over X seconds/minutes etc
Instead of having it freeze the server and then the structure appearing instantly.

Would be nice for a time-lapse video etc

#6 elopus001

  • Members
  • 15 posts

Posted 02 November 2015 - 01:35 PM

View PostBomb Bloke, on 02 November 2015 - 06:36 AM, said:

If I might add to your to-do list: I feel that having different height levels to the ground would lead to a much more "natural" looking city.

Good idea. I've added this to my to-do list. I'm hoping to get a road generator working next weekend. Then I will add multi-plot buildings. From their I will start creating new buildings and foot paths.

View PostCreator, on 02 November 2015 - 08:48 AM, said:

Maybe add roads and streets.

About what BB said, you can get the probability a construction is a skyscraper, and according to that generate a skyscraper or a house. You can also toy around with the sizes: The base size would be 6X6, there is a 30% a skyscraper might be 12x6. So play with math.random and look at the probabilities.

In my development version I currently have a garden that occurs 1/5 times and the buildings do change slightly in width/length if you look. They just still remain in the same chunk currently. After I get roads working I will work on buildings that are spread across chunks.

View PostBomb Bloke, on 02 November 2015 - 09:26 AM, said:

Well, more I was referring to the ground on which the houses were built. Say you specified building across a 5x5 chunk area. You might have the ground of the center 3x3 section raised somewhat, and the ground of the center chunk raised a little higher still - creating a hill.

Building houses on these chunks would be easy enough, the only (somewhat) tricky bit would be getting the roads and footpaths to tilt according to the slope and connect to the building entranceways.

Assuming that the block difference is only a height of one, this shouldn't be too tricky. The footpaths might be a little weird. Maybe I can add stairs and have the sides touching higher levels be raised? Roads would be more difficult though because I don't know of any vanilla black blocks that are stairs or ramps.

#7 elopus001

  • Members
  • 15 posts

Posted 02 November 2015 - 01:44 PM

Here is a sneak preview at what gardens may look like when they are released! Any suggestions are welcome! I'm thinking about adding paths, benches, and trees.

Posted Image

Even better, here is a road sneak peak! The cross walks will be overlaid after the roads are built.
Posted Image

Edited by elopus001, 02 November 2015 - 02:24 PM.


#8 elopus001

  • Members
  • 15 posts

Posted 03 November 2015 - 02:59 PM

View PostBaaleos, on 02 November 2015 - 12:51 PM, said:

This program looks good.
I was wondering if it would be possible to configure the delay between setting each block?
Eg: Avoid TPS issues by having the structure/operation completed over X seconds/minutes etc
Instead of having it freeze the server and then the structure appearing instantly.

Would be nice for a time-lapse video etc

Currently it just runs each command using commands.exec
For me this generates no noticeable lag. It does take a while though as it waits for each block to finish before making the next one. I could add a configurable sleep though. The default will just be 0.

#9 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 03 November 2015 - 03:27 PM

On the road pic, what are the two thing on the right?

#10 elopus001

  • Members
  • 15 posts

Posted 03 November 2015 - 05:18 PM

View PostCreator, on 03 November 2015 - 03:27 PM, said:

On the road pic, what are the two thing on the right?

They are intersections. The crosswalks stick out because they will be overlaid on top of other roads next to them.

#11 elopus001

  • Members
  • 15 posts

Posted 03 November 2015 - 08:37 PM

Update: V3 is available! This entire recode adds doors, ladders, and has a few tiny bug fixes. The block lists have been changed slightly.

pastebin get gaAjBHvG citygen

Edited by elopus001, 03 November 2015 - 08:53 PM.


#12 Baaleos

  • Members
  • 11 posts

Posted 05 November 2015 - 02:00 AM

Would it be possible to make it configurable so it clears the area of nuisence blocks.
Eg: SetBlock to air - if it is meant to be empty?
That way the city could be generated on terrain where mountains intersect the area.

#13 elopus001

  • Members
  • 15 posts

Posted 06 November 2015 - 03:02 AM

View PostBaaleos, on 05 November 2015 - 02:00 AM, said:

Would it be possible to make it configurable so it clears the area of nuisence blocks.
Eg: SetBlock to air - if it is meant to be empty?
That way the city could be generated on terrain where mountains intersect the area.

That wouldn't be too complicated and would be easy. It just would slow it down significantly. I will add that in the next version.

Edited by elopus001, 06 November 2015 - 11:39 PM.


#14 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 06 November 2015 - 05:39 AM

Add it as an option. Maybe some people don't want it.

#15 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 06 November 2015 - 06:00 AM

Just don't forget to clear in order from the higher layers down to the lower layers. ;)

#16 Baaleos

  • Members
  • 11 posts

Posted 06 November 2015 - 11:19 AM

I tried running this for a 10 chunk by 10 chunk city.
Mostly it worked fine - but I found that on some of the buildings it left parts of the lower walls unfinished and one block was missing from the roofs of a few buildings.
The script also seems to have left the city unfinished - it stopped abruptly at around 75%
You can see the finished state here ( Coordinates : 6729 x 4755 )
http://minecraft.asmodei.net:8123/#

I left the program running while I was offline, but the chunk the computer was running from was kept alive with an admin Anchor from FTB Infinity
I scattered a few of them around to ensure the 10x10 area was chunk loaded.

#17 elopus001

  • Members
  • 15 posts

Posted 06 November 2015 - 11:45 PM

The logs probably caused it to run out of space on the computer. I will add an option to disable these for servers with extremely small computer disk spaces and those who don't want to create huge files. Sorry about the problem. :unsure:

View PostBomb Bloke, on 06 November 2015 - 06:00 AM, said:

Just don't forget to clear in order from the higher layers down to the lower layers. ;)

Why would I need to do this? So long as I don't clear blocks as I build them it could work either way, correct?

#18 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 November 2015 - 12:24 AM

Did the script think it'd finished, or did it crash / hang?

If code execution continued normally, then odds are the missing buildings were in chunks the anchor missed. The Minecraft setblock command requires loaded chunks, and will simply do nothing if pointed at unloaded ones.

(commands.getBlockInfo() loads unloaded chunks you point it at, but I'm not sure how long they stay loaded... may be worth looking into some day.)

If the entire script froze, then odds are it's this ComputerCraft bug; commands.exec() may not ever return. It's rare, but scripts like this pull lots of block placements, so it's bound to happen sooner or later.

You can somewhat work around this with commands.execAsync() (which also happens to be a heck of a lot faster). WorldPorter and the Pyramid Run offer examples, and there's some other useful details in these threads.

If it crashed (attempt to index nil, caused by an invalid file handle?), then it may indeed be the log thing.

View Postelopus001, on 06 November 2015 - 11:45 PM, said:

View PostBomb Bloke, on 06 November 2015 - 06:00 AM, said:

Just don't forget to clear in order from the higher layers down to the lower layers. ;)

Why would I need to do this? So long as I don't clear blocks as I build them it could work either way, correct?

Clearing from bottom to top will cause sand / gravel to fall from the upper layers into the ones you've cleared already (and lava would make a royal mess of any wooden materials you're placing as you go). Clearing downwards ensures that everything is removed correctly.

Of course, you have to build from bottom to top for much the same reasons: If you ever want to use gravel as a material, it's got to have something solid placed under it first.

In WorldPorter, I build from bottom to top, placing all air blocks as I go. This covers any circumstance where there's no sand / gravel / fluids already in the area. There's a tick box which does a pre-build sweep of air from top to bottom. If enabled, it'll correctly handle any pre-existing terrain, and it also means that it doesn't need to place air while it's later doing the building (though the overall process still ends up being a little bit slower).

Edited by Bomb Bloke, 07 November 2015 - 12:29 AM.


#19 elopus001

  • Members
  • 15 posts

Posted 07 November 2015 - 02:15 AM

I made a small bug-fix update for paths from doors not generating properly and the roof block issue. http://pastebin.com/DGkWYEKu

And Bomb Bloke Thanks for the advice. I forgot about gravel.

Edit: That pastebin was an accidental development version post. Here is the current version. http://pastebin.com/DZ78widc

Edited by elopus001, 07 November 2015 - 02:22 AM.


#20 elopus001

  • Members
  • 15 posts

Posted 07 November 2015 - 02:39 AM

Sneak peak at...fire escapes! P.S. sneak peak features have been designed but not coded.

Posted Image





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users