Mooses2k / SecretHistories

First-person stealth/combat roguelite
Other
14 stars 11 forks source link

world objects spawning rules #21

Open Mooses2k opened 3 years ago

Mooses2k commented 3 years ago

spawn items and furniture in the world

relates to and is kinda a giant mega-issue combining #38 as well

this comment is largely done.

SO CATEGORIES WILL BE: tiny items:

always equippable:

equippable, takes one of ten slots:

non-equippable, but draggable:

statics

Mooses2k commented 2 years ago

Already at least partially in the code:

NOTES AND PASTES OF USEFUL STUFF

standard 60% 'empty' rooms, tending to be the smaller rooms

https://github.com/HungryProton/scatter

filling dungeon rooms https://www.archmagerises.com/news/2021/6/12/how-to-procedurally-generate-and-decorate-3d-dungeon-rooms-in-unity-c https://www.archmagerises.com/news/2020/3/6/update-110-procedurally-decorate-a-dungeon-room-with-unity-amp-c

also allow some stuff to be toppled, damaged; no cupboards and bookcases in middle either unless there's been damage, fight, trash kind of thing

define 'surfaces' by dimensions, and even allow stuff to be placed on stairs? - tends towards candles and rubble

there should be natural walkways from the entrances to the highlights of the room and to other entrances

different library layouts, orthogonal to wall

"What I plan on doing for rooms in buildings (and would make sense for dungeon rooms too):

Divide the perimeter of the room up into blocks. The corners get 2x2 blocks and the sides get a random selection of 1x1, 2x1, 2x2, 3x2 blocks, etc... whatever fits. If all your furniture is 1x1, it's even easier. If the room is big enough to put a block in the middle with a 1-cell border, add one; otherwise leave the middle blank. Remove the blocks in front of the doors.

Then, each type of room should have an algorithm for placing furniture in each block, oriented against the wall. A bedroom would find the biggest block(s) to place beds, then dressers, nightstands, etc. Perhaps blocks next to doors should be given special preference for light fixtures or something like it. Rooms with a central block could have a big feature there like a dining table, or else leave it empty.

A dungeon generator should have room types too: treasure rooms, throne rooms, torture rooms, lots of storage rooms, monster camps, etc. Some of these could have large set-pieces that would only fit in bigger blocks."

Have room templates, and then use minimum space differences to move things apart.

Optional features (pedestals, statues, pillars) equi-distant from each other (mirrored on each side of the stairs) - chance for placement symmetrically/centered to wall or bilateral symmetry to center of room or across room, facing, like statues

"I wrote a custom procedural generator for my 3DWorld project. I haven't explained how this works in detail in my blog, but you can see the results in some of the latest posts: http://3dworldgen.blogspot.com/

I start by generating a building as a series of connected/adjacent cubes. The cubes are divided vertically into floors. Each cube is then assigned a high level floorplan type that may include one or more central hallways, where the same floorplan is shared by the floors within the cube. The remaining space is recursively sliced in X and Y to create rooms until all of the regions become small enough. Then rooms are connected to hallways or each other with doors. The different building cubes are connected with doors, and floors are connected above and below with stairs and elevators.

Next I assign room types based on things like room size, whether or not it has windows, if it has an exterior door/stairs/elevators, how many other rooms it's connected to, what floor it's on, etc. For example, living rooms, dining rooms, and kitchens are on the first floor. Bedrooms almost always have windows. Bathrooms have only one door and aren't connected to other bathrooms. Living rooms are larger than bathrooms. There are similar rules for office buildings. Once enough rules are added it tends to generate a realistic looking layout.

For each room, I randomly choose a room type assignment. I then evaluate the rules and discard it if a rule is broken. If it gets into a situation where a required room type can't be assigned, it throws out the room assignment and starts again, possibly relaxing some of the rules so it's more likely to succeed. If it fails after a few iterations I regenerate the walls/floorplan and try again. The vast majority of room assignments are successful, so it's pretty fast in practice.

Next I place objects in the room based on room type. This includes things like furniture, appliances, rugs, pictures, etc. Higher priority items are placed first, then lower priority items are placed around them so that they don't conflict. Items have clearance areas in various directions to make sure the player has space to move, doors can open, etc.

It's all very complex and took a long time to put together, but I think you can get most of the way there with a fraction of the effort. You can find all of the code here if you're interested, but it's long and not very readable."

https://github.com/fegennari/3DWorld/blob/master/src/building_floorplan.cpp

https://github.com/fegennari/3DWorld/blob/master/src/building_rooms.cpp

ensure no collision by checking radius of asset (Houdini does this)

"You can't just generate rooms, you have to design them. Like in a real life, you slice your floor plan to decide for the size of rooms, then assign the function, use that to add walls, doors, windows based on position on the floor plan and then populate each room by function with prebuilt furniture, using some simple algorithm which takes the size of the asset and some limited options of placement.. So, what you need is a good tutorial on how to manipulate geometry and assign attributes like Opara's lake house, and then search for some procedural asset modeling tutorials for the furniture assets. You can also avoid modeling of the assets if you use models from some market place, in that case you are just creating room slicing & furniture assembly tool."

wall fountains as well as centerpiece (need a Tomb of Horrors wall mouth too) hanging chains lights typically near doors could have chair next to bed with candle on it bureau in bedroom 3x3m bedroom typically has bed in line with door and either chair or nightstand hot items like braziers and cauldrons should have larger radiuses for safety

kitchen: cupboard, pantry, shelves, wall shelves barrel with a candle holder on it wall shelf above a kitchen counter chest against well with shelf over it bowl or plate or cutting board and knife in front of kitchen chair, jug or drink anchored to one or far corners of that, silverware off that centerpiecing and placing two long tables together when barrels around, sometimes a smaller one on the floor in front

https://www.youtube.com/watch?v=AYDJ1Qy_nfg good examples waterworks for fountains? Did the monks get down to the UR? screw pump stacks like DF?

decide if Mostly standing or sitting room (kitchen & training standing, study & dining room sitting, etc) - Tables can be in center or along wall; tend to use higher tables in standing rooms and little or no seating

as a room test step, test pathing to side or front of every chair that's upright and not listed as rubble (like a corner full of broken or pushed aside chairs)

rarely something may start on fire or have the effects of an explosion go off in the room during gen

Bookcase etc is not so much back to wall, but back to something else back (like another bookcase), whereas a fireplace is definitely wall only

Chair doesn't directly face a wall usually unless it's a corner and that's all that's in the room or maybe in bedrooms or exercise/training rooms

Tables in study can be more likely against wall

Coat rack typically to either side of door

Beds nearly head always against wall Sometimes in patterns on five in center of room, head to center

Closet has purpose, cleaning, clothes, body storage

Tables on tables, cultists being weird, artistic Keep rules flexible for this

furniture typically doesn't block doors or walkways

lightsource's chance of being lit at start is based on type of lightsource and type of room (braziers in ritual rooms always lit, candles in study almost always lit, campfire in kitchen lit if cultist present, etc)

some models should be labeled 'unique to floor/branch/run' and only one of them should spawn

https://github.com/Mooses2k/SecretHistories/issues/131 stuff found in sarcophagi

small rooms:

Detect symmetry Detect if goes straight through to another door Careful with centerpieces in rooms with room pillars Path to end, know how many loops, be careful with difficulty before reaching first loop.traps tend to be in long hallways and around corners away from entrance find halfway points from a door to a corner and place something there for symmetry

If a large and very rare piece of furniture spawns in a room, like a statue, focus layout on that, even raise on dais sometimes. Statues sometimes facing corner and sometimes rubble or bodies nearby

Small plinths next to sarcophagi sometimes, some decayed offerings, maybe a vase, maybe something more sinister

Lighting something from side especially in statue rooms, or below, like statues with candles at base

single chair under a light in the center of a too large room

sometimes stuff on ground in patterns of five, like skulls, bones, chairs, etc

often floor and wall candelabra will only have a few lit, not all candles

If room has campfire or 2+ braziers, good chance there's a ceiling vent in this room

"""if it's common to all anchors, and small stuff, it could be just boolean exports for example, a boolean "allow_recursive" to say that the object placed on that anchor should or not fill it's own anchors or a float probability to say how often an anchor should be filled If a tag can be reasonably used to describe an object, it probably should be a tag if it only makes sense on the context of the anchors, it probably shouldn't for example, when describing a book, you can say it's a "book", "goes on a surface, or table, or shelf"(generic and specific)", "it's small", "it's knowledge/intellectual related", "it's flammable" you could separate those into different types of tags, if you want to is, goes on, attributes then, an anchor on a bookshelf would require all the tags "is a book", "goes on a surface", "goes on a shelf" and maybe forbid an item that is ruined/destroyed, for example or, on a ruined boolkshelf, forbid anything that is "new" or "in good state"""""

And at some point we'll move the tags out to somewhere else so we can have them on the objects as well, I think I made a consts or enum script you can put them in Moses2k — Yesterday at 7:11 PM It's more like 'must place' or regen room crazyStewie — Yesterday at 7:11 PM Yeah, but that's inside an object Moses2k — Yesterday at 7:11 PM yeah, i get that, wrong place for this crazyStewie — Yesterday at 7:12 PM You could make some templates/kind of templates required for certain rooms at some point Maybe with a similar tag system, but for more generic stuff

Basically, give each template some tags that represent what they do, and require a room to instantiate templates that cover a set of tags Like, a table that spawns chair around it is some sort of table/dinner setup, and every dining room should have at least one of those And each room should have at least one light source And if we have a table with a lantern on top, it fulfills both requirements One thing that might be good for the anchors is some sort of priority To decide the order they should be filled in bench with some probability, before chairs, so chairs won't fit if bench there

GROUPS seems like a really easy system for newcomers

crates and barrels

barrels and crates and firewood look better against the wall

barrels and crates should be able to stack, if stacking item, high chance that next to it is another stacking barrel/crate; once you have a base one on the floor, they can only go up (3 max probably); maybe have prefab stacked layouts as well, with two crates then another not squarely on top etc

Would be nice not to have any crates, barrels, or sewers in game http://www.oldmanmurray.com/features/39.html

Some few pieces of furniture are static, as in, built into the ground, so have a flag for that: Sarcos pedestals Some statues maybe Wells and fountains

Have per branch roomtypes and weights

Randomize rotation of corpse and drop it to place in places like bathtub Villagers and villager bodies and skeletons

Piles of books on floor, candles can be on top, or food plates

Skull chance of spawning jawbone (system for this kind of thing) and similar things - thing sub-spawning related thing sometimes

Mooses2k commented 1 year ago

FOR DEMO:

I think we should really pare down the world objects/room decoration for the demo. Start with basically two or three things. 1) Floor candelabras in n percent of rooms. 2) One or more sarcos in the middle of the room, based on room size and if it has pillars, 3) maybe a fountain instead of a sarco rarely in few rooms.

Then just a flat loot table (#406) on things that can randomly spawn on or in those and I'll set placement anchors.

Oh, and spawn the cultists (#405).

Nothing advanced like nesting or placement rules beyond check roomsize and pillars.

This seem a much simpler task?

Mooses2k commented 1 year ago

only the floor candelabras and sarcos or fountains left, eh_jogos on it for early next week

Mooses2k commented 1 year ago

Floor candelabras done. Sarcos early this week