[Code] Controlling Secret Levels
Select messages from
# through # FAQ
[/[Print]\]

DieHard Wolfers -> Code Tutorials

#1: [Code] Controlling Secret Levels Author: BrotherTankLocation: Ontario PostPosted: Wed Sep 01, 2004 10:16 am
    —
Controlling Secret Levels by BrotherTank

In Wolf3d, the game uses a simple array to hold what they call the "BackTo" levels, that are hard coded into the code. Sure, one can edit the code and set the array to the values you want the secret floor elevator to be on (once you've made your maps). But wouldn't it be easier to just have the game use the values that it already uses to define the "Secret Elevator Floor" to also control which level it goes back to??

Here is a very minor, but simple change, that will allow you to define on which level you are sent to the secret level (by defining the Secret Elevator with the Secret Elevator Floor), and then you don't have to keep changing your code to suit your latest mapset?

Ok... Get ready for this... It's as simple as adding one line of code as follows (Find the lines in Red and add the lines in Blue:

Open WL_GAME.C and go down to the "void PlayLoop (void)" function at the bottom...

::: CODE :::

         //
         // GOING TO SECRET LEVEL
         //
         if (playstate == ex_secretlevel)


            {
               ElevatorBackTo[gamestate.episode] = gamestate.mapon + 1;

               gamestate.mapon = 9;

            }



Pretty Simple Stuff... Now you never have to change the code if you decide that your Secret level will be called on say level 5 instead of level 1... You just set the Secret Elevator Floor code as you would in the original game.

Side Note: This method allows you to call a secret Level in more than 1 place/level and will not send you back to the wrong point in the game. Ie... Using the original game and original code:

The secret level is accessed on level 1. And it returns you to the start of Level 2 when you are done playing the secret level.. But lets say you changed your maps and put the secret level elevator on level 5. The original code would send you to the secret level, and then return you back to the start of Level 2. While this alone creates some interesting concepts in the game, this one line code fix above, will allow you to return to the level the next level in sequence from where you left off...

Hope that helps...

Greg
BrotherTank

#2: Re: [Code] Controlling Secret Levels Author: jamezLocation: Yorkshire, UK PostPosted: Wed Sep 01, 2004 3:41 pm
    —
So, whats the

gamestate.mapon = 9;

for? Or should it be cancelled out?

#3: Re: [Code] Controlling Secret Levels Author: BrotherTankLocation: Ontario PostPosted: Wed Sep 01, 2004 8:47 pm
    —
jamez wrote:
So, whats the

gamestate.mapon = 9;

for? Or should it be cancelled out?


James... Look at the original code... It's a nested If condition...

IF the playstate flag is set to "Completed" or "Secret Level" then it ends the level you were playing and then does the intermission. It then looks at these 2 nested if statements.

If you are on Gamestate.mapon 9 then it sends you back to the Level stored in the ElevatorBackTo[gamestate.episode] array. If you are not on level 9, then it checks the nested if to see if you should be going "TO" the secret level.

ie: If the playstate == ex_secretlevel then it will send you to gamestate.mapon = 9. What my additional line tells it to do is save the current level + 1 into the "ElevatorBackTo" array before you go to the secret level... This sets where you should be returned once you have completed the secret level...

Thus, it gives control to the map maker on which level the secret levels can be called from, rather than using fixed values in the ElevatorBackTo array, as it was originally programmed. If you take an episode... again using episode 1.. and don't change the hardcoded values in the array, and change the maps... lets say you decide that the secret elevator will now be in level 3... when you finish the secret level, it would return you back to the beginning of level 2... Which you have already played... not to level 4... where you should be going. Because of this hard-coded return, map makers have always been forced to use the values in the "ElevatorBackTo" array, and/or compile a new exe when they want the new secret level elevator located on a different floor.

This 1 line of code alleviates the problem... Add it and when making maps, it doesn't matter what level you put the secret level elevator on...

Greg
BrotherTank

Want to be really creative... make sure to save the elevatorbackto array as part of your saved/loaded games... Smile Big hint... Use the gamestate structure to store it and save a few bytes by removing the "ElevatorBackTo" array...

#4: Re: [Code] Controlling Secret Levels Author: ChrisLocation: Canada PostPosted: Thu Sep 02, 2004 3:06 am
    —
Funny, I also thought about this idea awhile ago. Like you said, you don't even need to have hardcoded numbers for the "return from secret" floor, you just need to keep track of the number when it actually goes to the secret elevator with a char/byte variable that can be called back later (thus getting rid of the 6 of them in the original ElevatorBackto). I was thinking of posting something about how easy this was to do, and how much easier this would make mapsets in general (since people can than put the secret levels wherever they want automatically without editing the exe), but no one gave me the impression that they needed this, so I didn't find it neccessary to post at the time; although I always found it intrieging.

It's cool to hear that someone else has considered this though, figuring out how to make elevators automatically go back to the next level after they reach the secret level, and realizing how completely irrelevant having hardcoded numbers for that sort of stuff really is. I didn't have much faith that someone else would have had the desire to try this, but you proved me wrong Greg. Smile

#5: Re: [Code] Controlling Secret Levels Author: WSJ PostPosted: Thu Sep 02, 2004 5:24 am
    —
Interesting... I wonder why John Carmack hadn't thought of something like this... or if he did, why he didn't use it. It would've made the games more flexible, without being hard-coded so that in this Episode you can only access the secret level from Level Such-and-Such. I remember this being a problem in the Doom games as well... In Doom, if you put the secret elevator on a level other than the level it was on originally, you'll still reappear on the same level as before... and in Doom II, you'll simply restart the level you just finished!

#6: Re: [Code] Controlling Secret Levels Author: BrotherTankLocation: Ontario PostPosted: Thu Sep 02, 2004 9:47 am
    —
@WSJ:

I'm not sure why they didn't think of this. It was something that I first did back when SR was being coded by MCS.

@Chris:

Yeah, I like to tinker with most of the code in the game (the wl_??? files that is). I've brought the all of the Spawn Boss routines into 1, and a few other modifications like that. It's nothing major, but most people don't even think about changing it. Seeing as I've made things user friendly in Wolfenstein Plus and this was part of it, this one was simple, and something that I thought should be released to the community.

@all:

When you understand the ElevatorBackTo array and the lines of code that Wolfenstein uses to control where to go and return, it's actually easy to take the secret levels one step further.. especially if you are using the Sequential Levels or Seamless level tutorials. With a little thought and a few lines of code, you can do Nested Secret Levels... Smile

Greg
BrotherTank

#7: Re: [Code] Controlling Secret Levels Author: jamezLocation: Yorkshire, UK PostPosted: Thu Sep 02, 2004 10:13 am
    —
I was thinking too ahead, as I'd normally use seemless level prog..

That's why i was confused there...

#8: Re: [Code] Controlling Secret Levels Author: Adam BiserLocation: USA PostPosted: Thu Sep 02, 2004 11:49 am
    —
I haven't tried the code, but I have a quick question.
If I save a game while in the secret level, quit, then restart the game and load the level, is the stored return level still correct?

#9: Re: [Code] Controlling Secret Levels Author: BrotherTankLocation: Ontario PostPosted: Thu Sep 02, 2004 2:49 pm
    —
Adam Biser wrote:
I haven't tried the code, but I have a quick question.
If I save a game while in the secret level, quit, then restart the game and load the level, is the stored return level still correct?


If you don't quit.. then everything is ok... otherwise No... That's why I said:
BrotherTank wrote:
Want to be really creative... make sure to save the elevatorbackto array as part of your saved/loaded games... Big hint... Use the gamestate structure to store it and save a few bytes by removing the "ElevatorBackTo" array...


To achieve things that way... In the wl_def.h file add

int backto;

in the gamestate type define... and then change the:

ElevatorBackTo[gamestate.episode] = gamestate.mapon + 1;

to:

gamestate.backto = gamestate.mapon + 1;

and then change the:

gamestate.mapon = ElevatorBackTo[gamestate.episode]; // back from secret

to:

gamestate.mapon = gamestate.backto;

in your wl_game.c file... Then you can remove the ElevatorBackTo array completely, saving yourself a few more bytes in the data group. And for James... Yes, seamless levels change this code considerably... at least they do in my Wolfenstein Plus code...

Greg
BrotherTank

#10: Re: [Code] Controlling Secret Levels Author: jamezLocation: Yorkshire, UK PostPosted: Thu Sep 02, 2004 4:37 pm
    —
Quote:
And for James... Yes, seamless levels change this code considerably... at least they do in my Wolfenstein Plus code...


Yeah. I should think quicker before posting Razz

#11: Re: [Code] Controlling Secret Levels Author: Adam BiserLocation: USA PostPosted: Thu Sep 02, 2004 4:57 pm
    —
BrotherTank wrote:
That's why I said: <snip>

And I should read all of the posts a bit closer before posting... Embarassed

#12: Re: [Code] Controlling Secret Levels Author: Guest PostPosted: Wed Sep 22, 2004 2:07 pm
    —
Shocked where in this world they comes from? Shocked

Quote:
Code removed.... by BT


I did tries to put elevator object (floor code) in level 1, test to see if it work, but it don't work..

@BrotherTank: is it your source code from SR????? which I uses this, so I replace this code to new code that you posted here and test again to see if it same thing, and it works.

That's what I did, see below.....

Quote:
Code removed... by BT


THANKS TO BROTHERTANK FOR HIS TIPS, Without his tips, my game will struck in hole and will not able to do this.... Exclamation Too Cool

#13: Re: [Code] Controlling Secret Levels Author: BrotherTankLocation: Ontario PostPosted: Wed Sep 22, 2004 3:11 pm
    —
@Howling_Wolf:

The code is for the "Wolf" side of the code, not the Spear. Spear is something completely different. With Spear, you must set hard limits. With wolf, you always know that level 9 is the secret level, so my code changes it so that you can call the secret level from any floor rather than the hardcoded ones.

What you posted (and I deleted) will only serve to confuse people. Sorry. If you follow the original tutorial or the one where I removed the elevatorbackto array properly, you won't have any problem. If you do or did have a problem, then you didn't enter the changes properly.

Greg
BrotherTank

#14: Re: [Code] Controlling Secret Levels Author: Guest PostPosted: Wed Sep 22, 2004 3:35 pm
    —
BrotherTank wrote:
@Howling_Wolf:

The code is for the "Wolf" side of the code, not the Spear. Spear is something completely different. With Spear, you must set hard limits. With wolf, you always know that level 9 is the secret level, so my code changes it so that you can call the secret level from any floor rather than the hardcoded ones.

What you posted (and I deleted) will only serve to confuse people. Sorry. If you follow the original tutorial or the one where I removed the elevatorbackto array properly, you won't have any problem. If you do or did have a problem, then you didn't enter the changes properly.

Greg
BrotherTank



Clear to understand, I just show you what I using, but I tried to figure it out what you did to elevatorbackto array, I look all to closer to end of file, I found it out that array was different then my code.. Until I find something miss, so I decide to post here for you look at them, but I don't know that code will cause them confused..... Now it is work properly... Forgiven me for post the code here Embarassed Feel free to delete my post above.... thanks........ Cheesy Grin

#15: Re: [Code] Controlling Secret Levels Author: CraneLocation: United Kingdom PostPosted: Tue Sep 02, 2008 6:44 am
    —
I'm posting on old topics again, but there is one thing I should mention.

If you use "tedlevel" or level warping to get to the secret level, the elevator back map will be undefined and nearly impossible to correctly determine, even if you use the gamestate structure as described above. Something to keep in mind.

#16: Re: [Code] Controlling Secret Levels Author: BrotherTankLocation: Ontario PostPosted: Tue Sep 02, 2008 9:56 am
    —
While using "tedlevel" or the debug code and warping to the secret level will leave the variable set to 0, the player will return to the first level of the game because you must remember the "-1" as it said in the original code. "0" is actually level "1". Hence someone using the cheats to bypass the proper playing of the game with levels in succession would be punished and sent back to the start of the game.

What this code does do though is free the map maker to set which level the secret levels are called from in the game. With things no longer hard-coded, the secret floor value in the elevator is all that is required to send the player to the secret level from whichever map the maker so chooses.

Just something to keep in mind....

Greg
BrotherTank

#17: Re: [Code] Controlling Secret Levels Author: CraneLocation: United Kingdom PostPosted: Tue Sep 02, 2008 10:32 am
    —
Ah, so Borland C initialises variables... due to my own experiences with Delphi, I assume that variables start uninitialised - still, initially setting it to zero is the most sensible option.

#18: Re: [Code] Controlling Secret Levels Author: TricobLocation: Neo-traditions, Inc. PostPosted: Tue Sep 02, 2008 6:49 pm
    —
Crane wrote:
still, initially setting it to zero is the most sensible option.
Easy for me to agree with you there, since I've been programming in BASIC for a *long* time. Smile



DieHard Wolfers -> Code Tutorials


output generated using printer-friendly topic mod. All times are GMT

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group