Instances and random spawns
Quote from KyloX on July 4, 2015, 6:36 amI am working on something interesting, making a map which every time it spawns, the layout is different.
I have room instances and hallway instances which connect the rooms. My goal, as I said, every time the map is restarted, the rooms and hallways are in different places. The map consists of 24 rooms [5x5] (middle point is empty) and 26 hallways.Any suggestions on how to achieve this?
So far the best tools I have found are logic_case (for random) and point_teleport (to teleport instances), but would be nice to hear some feedback on this, as the more I think on how to achieve this, the more it gets complicated with how many connections and entities it might need.
I am working on something interesting, making a map which every time it spawns, the layout is different.
I have room instances and hallway instances which connect the rooms. My goal, as I said, every time the map is restarted, the rooms and hallways are in different places. The map consists of 24 rooms [5x5] (middle point is empty) and 26 hallways.
Any suggestions on how to achieve this?
So far the best tools I have found are logic_case (for random) and point_teleport (to teleport instances), but would be nice to hear some feedback on this, as the more I think on how to achieve this, the more it gets complicated with how many connections and entities it might need.
http://steamcommunity.com/profiles/7656 ... shopfiles/
Quote from HMW on July 5, 2015, 9:44 amThis sounds like an interesting concept. Although I imagine that it's going to be hard to use this for anything other than a maze. And it's really hard to make a maze that is not boring.
With that Oscar the Grouch thing out of the way, my first thought would be to use world portals. Wait no. My first thought would be to scale it way down to, say, four rooms with four hallways connecting them. See if you can get that working and go up from there.
Anyway my second thought would be to use world portals. The advantage is that you don't need to make the rooms movable, which is more work than it sounds like, especially when you want a room to have portal surfaces. (Each portal suface must be a separate func_brush, and moving a room while it has portals in it requires some trickery.)
World portals only display correctly when viewed through at most one other portal. To prevent display problems, you should design each hallway such that there is no line of sight between the two ends. (Corners, doors that only open when you're close, etcetera.)
Another solution might be to build a matrix of empty rooms with hallways connecting them, and build the interior of each room out of func_brushes, so they can be moved around. The advantage of this approach is that you don't have the GPU overhead of rendering all those portals, and because the hallways are static, they can be optimised in the traditional way, with areaportals and triangular hint planes in the corners.
As for the underlying logic, I would personally reach for vscript. As you said yourself, doing this with just logic entities is going to be very complex, and it will get exponentially more complex as you increase the number of rooms.
I'll try to come up with a vscript solution if / when I have the time.
This sounds like an interesting concept. Although I imagine that it's going to be hard to use this for anything other than a maze. And it's really hard to make a maze that is not boring.
With that Oscar the Grouch thing out of the way, my first thought would be to use world portals. Wait no. My first thought would be to scale it way down to, say, four rooms with four hallways connecting them. See if you can get that working and go up from there.
Anyway my second thought would be to use world portals. The advantage is that you don't need to make the rooms movable, which is more work than it sounds like, especially when you want a room to have portal surfaces. (Each portal suface must be a separate func_brush, and moving a room while it has portals in it requires some trickery.)
World portals only display correctly when viewed through at most one other portal. To prevent display problems, you should design each hallway such that there is no line of sight between the two ends. (Corners, doors that only open when you're close, etcetera.)
Another solution might be to build a matrix of empty rooms with hallways connecting them, and build the interior of each room out of func_brushes, so they can be moved around. The advantage of this approach is that you don't have the GPU overhead of rendering all those portals, and because the hallways are static, they can be optimised in the traditional way, with areaportals and triangular hint planes in the corners.
As for the underlying logic, I would personally reach for vscript. As you said yourself, doing this with just logic entities is going to be very complex, and it will get exponentially more complex as you increase the number of rooms.
I'll try to come up with a vscript solution if / when I have the time.
Other Portal 2 maps: Medusa Glare
Portal 1 maps: Try Anything Twice | Manic Mechanic
Quote from KyloX on July 6, 2015, 9:06 amThe concept is a maze style, without a portal gun, as the rooms would be trap/puzzle rooms and hallways do contain a door to pass through so that the player wouldn't be able to see each room.
Point_teleport was one of those ideas which I though it might work, the first one was point_template (which would be placed in the spots where the rooms/hallways are), but finding out how to make it random looked even more difficult.
When I though on testing on how to implement this mechanic, I did start with 4 rooms and 4 hallways, but the more I looked at the entities that hammer gives, the more complicated it got ( I know it is possible to do with the given entities, but it would require a lot of entities and it would be complicated).
The main point of the map is not to confuse players in a maze (nobodies like to be a lab rat), but to make players take countion in every room they step as it is probably booby trapped. If they die, the map restarts with a new generated layout of rooms. So in the end, players can memorize the traps, but they still have to find an exit in of those rooms.
I never used vscript for hammer yet, probably a good time to learn it if I want this to happen.
Map concept: R - room, H - hallway, S - start
The concept is a maze style, without a portal gun, as the rooms would be trap/puzzle rooms and hallways do contain a door to pass through so that the player wouldn't be able to see each room.
Point_teleport was one of those ideas which I though it might work, the first one was point_template (which would be placed in the spots where the rooms/hallways are), but finding out how to make it random looked even more difficult.
When I though on testing on how to implement this mechanic, I did start with 4 rooms and 4 hallways, but the more I looked at the entities that hammer gives, the more complicated it got ( I know it is possible to do with the given entities, but it would require a lot of entities and it would be complicated).
The main point of the map is not to confuse players in a maze (nobodies like to be a lab rat), but to make players take countion in every room they step as it is probably booby trapped. If they die, the map restarts with a new generated layout of rooms. So in the end, players can memorize the traps, but they still have to find an exit in of those rooms.
I never used vscript for hammer yet, probably a good time to learn it if I want this to happen.
Map concept: R - room, H - hallway, S - start
http://steamcommunity.com/profiles/7656 ... shopfiles/
Quote from HMW on July 6, 2015, 2:43 pmOh, so it's like those Cube movies. That sounds cool
I would definitely recommend vscript for this. Managing so many moving parts with just Hammer entities is going to be incredibly cumbersome.
I learned vscript mostly by looking at the existing scripts that come with the game (in $gamedir/scripts/vscripts) and occasionally looking at the list of script functions built into Portal 2 and the Squirrel language website. (Squirrel is the language used for vscript.)
However, I already have a lot of programming experience. The information on the Valve wiki is not targeted at beginners and there don't seem to be other beginner-friendly tutorials out there, unfortunately.
There are some threads here on TWP that try to explain the basics, such as this one.
Oh, so it's like those Cube movies. That sounds cool
I would definitely recommend vscript for this. Managing so many moving parts with just Hammer entities is going to be incredibly cumbersome.
I learned vscript mostly by looking at the existing scripts that come with the game (in $gamedir/scripts/vscripts) and occasionally looking at the list of script functions built into Portal 2 and the Squirrel language website. (Squirrel is the language used for vscript.)
However, I already have a lot of programming experience. The information on the Valve wiki is not targeted at beginners and there don't seem to be other beginner-friendly tutorials out there, unfortunately.
There are some threads here on TWP that try to explain the basics, such as this one.
Other Portal 2 maps: Medusa Glare
Portal 1 maps: Try Anything Twice | Manic Mechanic
Quote from KyloX on July 7, 2015, 3:12 amEven though I know the basics of programming, but looking up the scripts from valve, it is a hard start figuring out what does what.
A friend suggested to use env_entity_maker and point_template, and it seems to be the best way to accomplish this idea. But figuring out the script for it will take some time. I guess my programming skills got a little bit rusty.The biggest issue I still can't think out is how to make it randomize in order so that the rooms don't repeat themselves. I need something similar to random_shuffle.
Even though I know the basics of programming, but looking up the scripts from valve, it is a hard start figuring out what does what.
A friend suggested to use env_entity_maker and point_template, and it seems to be the best way to accomplish this idea. But figuring out the script for it will take some time. I guess my programming skills got a little bit rusty.
The biggest issue I still can't think out is how to make it randomize in order so that the rooms don't repeat themselves. I need something similar to random_shuffle.
http://steamcommunity.com/profiles/7656 ... shopfiles/
Quote from HMW on July 7, 2015, 3:11 pmThere is a random function in Squirrel's standard library:
- Code: Select all
rand();
returns a pseudorandom integer in the range 0 to RAND_MAX
So to get a random number between 0 and 9 (inclusive), you could do something like this:
- Code: Select all
rand() % 10
rand() first gets a random number between 0 and some arbitrary large value we don't care about. The % divides it by the range we want and returns the remainder, thus resulting in a random integer in that range.
This is a pseudo-random number generator. This means that it works by keeping track of an internal state and running some formula on that, resulting in a "random" number and a new internal state, which is used to compute the next "random" number and so on. (Computers suck at true randomness.)
I don't know where the first internal state of this random generator comes from, but it's very plausible that it will always be the same (say, 0) when your map starts. There is another function, "srand", that you have to call once, to make the random numbers different between runs of the same map:
- Code: Select all
srand(time())
This uses the current system time to initialise the random state; this should give you different results each time the map is restarted.
You will need to program the "shuffle" part youself. I think it's possible to randomly pick elements from an array, add them to a result array and then remove them from the original array so they don't get picked again.
There is a random function in Squirrel's standard library:
- Code: Select all
rand();
returns a pseudorandom integer in the range 0 to RAND_MAX
So to get a random number between 0 and 9 (inclusive), you could do something like this:
- Code: Select all
rand() % 10
rand() first gets a random number between 0 and some arbitrary large value we don't care about. The % divides it by the range we want and returns the remainder, thus resulting in a random integer in that range.
This is a pseudo-random number generator. This means that it works by keeping track of an internal state and running some formula on that, resulting in a "random" number and a new internal state, which is used to compute the next "random" number and so on. (Computers suck at true randomness.)
I don't know where the first internal state of this random generator comes from, but it's very plausible that it will always be the same (say, 0) when your map starts. There is another function, "srand", that you have to call once, to make the random numbers different between runs of the same map:
- Code: Select all
srand(time())
This uses the current system time to initialise the random state; this should give you different results each time the map is restarted.
You will need to program the "shuffle" part youself. I think it's possible to randomly pick elements from an array, add them to a result array and then remove them from the original array so they don't get picked again.
Other Portal 2 maps: Medusa Glare
Portal 1 maps: Try Anything Twice | Manic Mechanic
Quote from DaMaGepy on July 9, 2015, 12:48 pmjust make the rooms and map in fixed locations and a looot of linked portal door in the hallways that randomly connect/pair to another (SetPartner), but while keeping this 5x5 structure and orientations.
First randomizing the rooms then changing the portal doors in the hallways.
For example if room8 was randomized topleft andd rooom12 is on its right then room8right_door's partner is room12left_door etc but I guess it till needs some scripting, plus must close all other portal other than for example the 4 exit to not overhelm or bug Portal2.
At least this is what I would do
just make the rooms and map in fixed locations and a looot of linked portal door in the hallways that randomly connect/pair to another (SetPartner), but while keeping this 5x5 structure and orientations.
First randomizing the rooms then changing the portal doors in the hallways.
For example if room8 was randomized topleft andd rooom12 is on its right then room8right_door's partner is room12left_door etc but I guess it till needs some scripting, plus must close all other portal other than for example the 4 exit to not overhelm or bug Portal2.
At least this is what I would do
Quote from HMW on July 13, 2015, 3:40 pmHere's an example of a script that randomises the positions of a group of entities, plus a demonstration map. You can use this for the non-world-portal version of the concept.
It turns out that Portal 2 has a RandomInt() function that is much easier to use than the standard rand(). It accepts a custom input range and it does not need to be initialised with a seed. So that's what I used in the script.
I added plenty of comments to try to explain what everything does. Please let me know if you have any questions!
Here's an example of a script that randomises the positions of a group of entities, plus a demonstration map. You can use this for the non-world-portal version of the concept.
It turns out that Portal 2 has a RandomInt() function that is much easier to use than the standard rand(). It accepts a custom input range and it does not need to be initialised with a seed. So that's what I used in the script.
I added plenty of comments to try to explain what everything does. Please let me know if you have any questions!
Other Portal 2 maps: Medusa Glare
Portal 1 maps: Try Anything Twice | Manic Mechanic
Quote from KyloX on July 14, 2015, 1:55 pmOh wow, did not expected that.
Looking up the valve scripts and the one you just gaved, some are simple, some are just unknown as the language for this scripting I haven't encountered, so it is quite hard to understand what does what, but i guess that is how it begins with learning...Now about the shuffle script, It is a great leaning material as well a great tool for my kind of map, I won't let it go to waste, the map will be finished or must be finished...
I thank you for your given time to make this script.
Oh wow, did not expected that.
Looking up the valve scripts and the one you just gaved, some are simple, some are just unknown as the language for this scripting I haven't encountered, so it is quite hard to understand what does what, but i guess that is how it begins with learning...
Now about the shuffle script, It is a great leaning material as well a great tool for my kind of map, I won't let it go to waste, the map will be finished or must be finished...
I thank you for your given time to make this script.
http://steamcommunity.com/profiles/7656 ... shopfiles/
Quote from HMW on July 15, 2015, 1:00 pmYou're welcome! Good luck with the map; I hope it works out well.
You're welcome! Good luck with the map; I hope it works out well.
Other Portal 2 maps: Medusa Glare
Portal 1 maps: Try Anything Twice | Manic Mechanic