ID:152625
 
In my current project, surviving the environment is going to be a major, and difficult to achieve goal for players. One necessary element to survival will be the construction of shelters - something I'd like to do dynamically. As such, flagging a turf as indoors or outdoors will be necessary.


I'd like to be able to determine if, for every 'indoor' turf, there is shelter from wind (based on walls) and shelter from precipitation (based on roofs). A roof wouldn't be difficult to track; is either there, or it isn't. Walls, on the other hand, provide a certain challenge - how do you know if they actually enclose an area?

At one point I was actually thinking of walls to check to see if circuits are completed, and a similar methodology might work here. If something can follow the 'road' back to the starting point, then there's a complete circuit... and everything iside is marked as 'indoors'.

Actually, a glance at ancient history shows that I'm not the only person who has thought about making a circuit type system; Clicky .

The reason for posting, though, is to see if anyone has anyt thoughts on this topic. How would you go about declaring if something is indoors, or outdoors dynamically?
Gathin wrote:
In my current project, surviving the environment is going to be a major, and difficult to achieve goal for players. One necessary element to survival will be the construction of shelters - something I'd like to do dynamically. As such, flagging a turf as indoors or outdoors will be necessary.


I'd like to be able to determine if, for every 'indoor' turf, there is shelter from wind (based on walls) and shelter from precipitation (based on roofs). A roof wouldn't be difficult to track; is either there, or it isn't. Walls, on the other hand, provide a certain challenge - how do you know if they actually enclose an area?

At one point I was actually thinking of walls to check to see if circuits are completed, and a similar methodology might work here. If something can follow the 'road' back to the starting point, then there's a complete circuit... and everything iside is marked as 'indoors'.

That seems feasible. The big challenge would be responding to updates in status, making changes dynamically.

Actually, a glance at ancient history shows that I'm not the only person who has thought about making a circuit type system; Clicky .

The reason for posting, though, is to see if anyone has anyt thoughts on this topic. How would you go about declaring if something is indoors, or outdoors dynamically?

Well tracing a circuit is actually the easiest part. Start with any wall or door turf, and follow it around in one direction. If a turning presents itself, choose the outer. This will give you the entire building's outline.

However for dynamic systems, you're probably better off using individual rooms and using areas to trace them. Here would be my approach:

  • Trace the entire outline by starting at a wall and choosing a direction where there is another wall. (Consider cardinal directions NSEW only.) Turn left if possible, or otherwise go straight, otherwise right; keep track of all left and right turns, and every place where you turn. If you reach a dead end, go back to the last intersection or T encountered, or the original turf if none was found, and try a different direction. If you ultimately fail, there is no enclosed area. If you make it back to a turf you have visited before, it marks the beginning of your circuit. Now, if you made 4 right turns net (i.e., right turns - left turns == 4), you've marked off the entire structure. Otherwise, you've only found one room, and you'll need to repeat this process later for neighboring walls.
  • For any region you've found, add its walls and interior turfs to a new area. Do this by taking any two corners in a row where you turned right; add the corners and the turfs between them to the area. Then, progress inward and mark the "straight" walls where you didn't turn as right turns, and the left turns as straight. Repeat this for every consecutive pair of right turns. What we're basically doing here is identifying convex parts that we can remove, which in turn will eventually remove any concavities.
  • For the new area, find any walls that don't belong to the perimeter and repeat step 1.

    There are probably simpler ways to do this.

    Lummox JR