This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
elopus001's profile picture

City Generating Script

Started by elopus001, 01 November 2015 - 08:28 PM
elopus001 #1
Posted 01 November 2015 - 09:28 PM
This program for command computers generates a bunch of skyscrapers in a rectangular grid pattern.



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:
SpoilerVersion 3

pastebin get gaAjBHvG citygen
First Public Release (V2)

pastebin get N0CFJLHb citygen
Old Beta Version (V1)

pastebin get itUkpB7P citygen

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:
  1. Add roads (will likely require a re-write)
  2. Add doors
  3. Add multi-plot buildings (will likely require a re-write so I will try to tack it on with roads)
  4. Add more buildings
  5. Make the pattern have less grids (and multiple height levels)
  6. Log building (and block) placement
  7. Add to the skyscrapers (ladders (with random orientation), fire escapes)
  8. Street lights
  9. Fill air blocks option
Known Issues:
  1. Occasionally misses blocks.
  2. Fill roof block next to ladder with outside material
  3. Runs out of storage space due to logging (commented out log)
Screenshots:
Spoiler

Video:
Spoiler<iframe width="560" height="315" src="https://www.youtube.com/embed/ojYA2D6MNEc" frameborder="0" allowfullscreen></iframe>
https://youtu.be/ojYA2D6MNEc
Edited on 07 November 2015 - 08:21 PM
Bomb Bloke #2
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.
Creator #3
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.
Bomb Bloke #4
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.
Baaleos #5
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
elopus001 #6
Posted 02 November 2015 - 01:35 PM
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.

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.

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.
elopus001 #7
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.



Even better, here is a road sneak peak! The cross walks will be overlaid after the roads are built.
Edited on 02 November 2015 - 01:24 PM
elopus001 #8
Posted 03 November 2015 - 02:59 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

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.
Creator #9
Posted 03 November 2015 - 03:27 PM
On the road pic, what are the two thing on the right?
elopus001 #10
Posted 03 November 2015 - 05:18 PM
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.
elopus001 #11
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 on 03 November 2015 - 07:53 PM
Baaleos #12
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.
elopus001 #13
Posted 06 November 2015 - 03:02 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.

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 on 06 November 2015 - 10:39 PM
Creator #14
Posted 06 November 2015 - 05:39 AM
Add it as an option. Maybe some people don't want it.
Bomb Bloke #15
Posted 06 November 2015 - 06:00 AM
Just don't forget to clear in order from the higher layers down to the lower layers. ;)/>
Baaleos #16
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.
elopus001 #17
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:/>

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?
Bomb Bloke #18
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.

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 on 06 November 2015 - 11:29 PM
elopus001 #19
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 on 07 November 2015 - 01:22 AM
elopus001 #20
Posted 07 November 2015 - 02:39 AM
Sneak peak at…fire escapes! P.S. sneak peak features have been designed but not coded.

caza1112 #21
Posted 26 January 2016 - 12:32 AM
I'm going to be a bit of a pain here sorry, i have it installed but i tried multiple things to get the program to execute however i'm not having any look, would you mine writing a command i could copy so i can give this a try please.
Bomb Bloke #22
Posted 26 January 2016 - 04:05 AM
Say you're at x100/y64/z100, you might do:

citygen 110 64 110 4 4
caza1112 #23
Posted 30 January 2016 - 12:45 AM
Thanks Bomb Bloke :)/>
Communeguy #24
Posted 31 March 2016 - 03:28 AM
I like the idea of this very much. I was originally planning on putting in the "filler" buildings of my city using a buildcraft architect or similar. Now, I might do this, just to save the tedium of moving it around for each building manually and self-randomizing the blueprints.
elopus001 #25
Posted 27 April 2016 - 02:04 AM
Just wanted to give everyone an update, I have found Computercraft too slow for my tastes and have moved over to an MCedit filter.

http://pastebin.com/dP8YYU2d

And thanks Communeguy. Glad everyone likes it.