![]() |
|
|
Keys. They provide Wolfenstein's "puzzle factor". But you say silver and gold just aren't enough? Why not add another key or two to heighten the challenge? It's not that hard. You do, however, have to come up with some new key graphics (unless you actually want to try to convince the player that the secret new key is a basket or something). Apparently, a 3rd and 4th key were already set up for operation in the source code. There are even locked door tiles for them already in there! (You'll need to add them to Mapedit's MAPDATA file, and edit the OBJDATA file accordingly -- I show you how.) Luckily for you -- most of the hard work is done for you. In fact, all of the hard work is done for you. Making this the perfect tutorial for the novice source code hacker, on his way to bigger and better things. All right, now I want youze all to synchronize your brains to Wolfenstein. Ready? Begin!
DECLARING THE NEW KEY OBJECTS
Step
1.
Open up your favorite text editor.
(I actually use DOS Edit.)
Step 2.
Open the file WL_ACT1.C from your Wolfy
source code directory.
Step 3.
Scroll down a bit until you start seeing
a list of stuff that looks like {SPR_STAT_0,water1}, and a bunch of stuff like
that. This is where all of Wolfenstein's static objects and bonus items (all
the sprites between the wall tiles and the actors) are set up. You'll notice
the solid objects have the word "block" inside their braces, after
the SPR_STAT_# declaration. This word makes them blocking sprites. It's that
easy. Okay, you there? Good, let's move on.
Step 4.
Now since we can't add new objects to
Wolfenstein (damn it), we need to change an existing one (or two) to be keys.
The way we do this is, find a static object you don't think you'll need (like
one of the piles of bones, or the stupid "Aardwolf" sign) and modify
it. For this example, I'm going to change that ridiculous and infamous "Aardwolf"
sign into Key #3.
Here's what the file will look like before you've changed it:
All the game cares about is what's inside the braces {}, and the comma after them. Remember, "//" denotes a comment, and anything after them is culled out by the compiler. That stuff off to the right there is just programming notes. It can help you identify what each sprite is, however.
Step
5.
Okay, we're going to make the Aardwolf
sign (dubbed "Call Apogee" in the comment) a new key. Since a key
can't be a blocking sprite if we can pick it up, let's get rid of "block".
Go in there and erase that word.
Step 6.
Now, between the "SPR_STAT_40," and the "},"
add this: "bo_key3". (No quotes, remember.) You can also add "bo_key4"
if you want this to be key #4. Yes, it's important to decide on one and use
it. Just as the silver key can only open a silver door, Key #3 (let's call it
the Bronze Key for sake of argument) can only open bronze doors. So remember
whether you used bo_key3 or bo_key4. I recommend putting them both in; you can
never have too many cool secret keys and stuff. PLEASE don't forget to go into
the VSWAP and change the graphics! Make sure you remember which graphics to
change, too...that always helps!
Here's what your code should look like now.

Step
7.
Add a 4th key if desired, so you have both "bo_key3"
and "bo_key4" used.
Step 8.
Scroll down a bit until you get to a portion of the file where
you see a bunch of lines starting with "case" and then some object
name. Find "case bo_key1:" and "case bo_key2:". You need
to add a new line like that for each of your new keys. Just hit Enter to create
a new line and type in "case bo_key3:" (no quotes as always), then
add a second line that says "case bo_key4:" (assuming you added a
4th key back there). It looks a lot nicer to match up the spacing of the other
definitions around them, by the way. Other programmers would approve. :)
Step
9.
That's it for in here! Save the file and close it.
TELLING THE GAME HOW TO PICK UP YOUR NEW KEYS
Okay, now that we have the 3rd and 4th keys defined, we need to tell the game what to do when the player picks them up. Right now it's not going to do anything. For that, we'll need to modify some code in another file.
Step
10.
Open up WL_AGENT.C.
Step 11.
Do a search for "bo_key1" or scroll on down to around
line 693 -- you'll be in the "GetBonus" routine.
Step 12.
This is where the game is told what to do if the player picks
up the objects defined as bo_key1 and bo_key2. In other words, the gold and
silver key. Since you probably want your new keys to act the same way as the
original two (make the same noise, flash the screen yellow, and actually give
you a key), you can add two simple lines in here. Under "case bo_key1:"
and "case bo_key2:", add two more lines just like you did at the end
of the last file: "case bo_key3:" and "case bo_key4:". There!
Now you're all set to go!
Step 13.
Save the file. If you want to add new key icons on the status
bar, don't close it yet.
ADDING TWO MORE KEY ICONS TO THE STATUS BAR
It would be polite if you gave the player some kind of notion as to when they had these new keys in their possession, don't you think? It's not hard to add two new key icons to the status bar, so let's go ahead and do that. The best place, I have found, is the far right side of the status bar, to the right of the selected weapon picture, with key3 on top, and key4 on the bottom. That's how this example will be set up. You can change it to suit your own liking of course.
Step
14.
With WL_AGENT.C still open, do a search for "DrawKeys".
It's probably around line 564 at this point.
Now
you'll see two "if/else" statements. Basically what the first one
is saying is, "If the player has the gold key, draw the gold key icon.
Else, if not, draw the blank icon." Then the second one is the same thing
for the silver key. You're going to add two more statements just like that,
after the one for the silver key. Use your editor's copy and paste functions.
CAREFUL -- don't paste it outside of the end brace } there, or things will become
a mess.
Here's a screen shot of the code in its default condition.
![]()
Step
15.
Copy the two "if/else" statements to the clipboard.
Paste them directly after the 2nd one, before the end brace }. Now there should
be four if/else statements.
Step 16.
Set up the icon for Key #3. In the 3rd if/else statement,
change "(gamestate.keys & 1)" to "(gamestate.keys & 4)".
Where it says "30,4" after "StatusDrawPic", change it to
"38,4" to move the icon over to the far
right side of the status bar.
Step 17.
Set up the icon for Key #4. In the 4th if/else statement,
change "(gamestate.keys & 2)" to "(gamestate.keys & 8)".
Where it says "30,20" after "StatusDrawPic", change it to
"38,20" to move the icon over to the
far right side of the status bar.
Your code should now look like this:
![]()
(By the way, the "bo_key3" and "bo_key4" over there on the left margin are for your benefit. DON'T type that in the code.)
Step
18.
Save and close WL_AGENT.C.
Step 19.
Compile WL_ACT1.C and WL_AGENT.C. Link everything up.
Step 20.
Go make sure the new EXE will run without any noticeable problems.
If it doesn't, well...you gotta problem!
SETTING UP MAPEDIT TO USE YOUR NEW KEYS AND LOCKED DOORS
Fortunately for you (and for me, since this tutorial is getting rather long), the locked doors for keys 3 and 4 are already in there. Isn't that loverly? In fact, newer versions of Mapedit may actually have the key 3 doors in the legend, in which case they're called something to the effect of "Stuck Door E/W holo" or something like that. Anyway, here's how to set up Mapedit properly so you can use your new keys, and put in doors for them to unlock.
Step
1.
Open up OBJDATA.WL6 or whatever your preferred object definition
file is for Mapedit.
Step 2.
Find the two objects you replaced with keys, and change them
accordingly. Tips: Make their colors high-intensity (colors 9-f), so they show
up better. Put them under the gold and silver keys in the list for easier access.
I also recommend making the icon for them a "k" like the other keys
are, so there's some kind of standardization. It will help you design levels
quicker. And if you need help setting up this stuff, read the Mapedit documention.
Warren Buss is an excellent writer.
Step 3.
Save and close OBJDATA.WL6, and open MAPDATA.WL6.
Step 4.
Okay, you're probably going to need to add at least two of
the locked doors to your legend. The doors for key 3 might be in there already.
Key 4 doors are almost certainly not. Here's the object hex values for the doors
(the first 4 numbers to the left of the entry in MAPDATA.WL6):
0060 -- Key3 door, vertical
0061 -- Key3 door, horizontal
0062 -- Key4 door, vertical
0063 -- Key4 door, horizontal
For your convenience, here are the 4 lines from my MAPDATA file that define these doors. You can use them if you like.
0060 c070 Locked door (Key 3)
0061 c060 Locked door (Key 3)
0062 f070 Locked door (Key 4)
0063 f060 Locked door (Key 4)
EXTRA CREDIT: ALTERING THE CHEAT CODES TO GIVE YOU ALL THE KEYS
Now that you've got 4 keys instead of 2, wouldn't you like to have the "M-L-I" cheat give you all 4? No, not so you can cheat to the extreme -- so you can test your levels without having to go find the blasted keys every time. Here's how to fix M-L-I up real good.
Step
1.
Open up WL_PLAY.C in your text editor.
Step 2.
Do a text search for "MLI", or jump down to line
665.
Step 3.
Okay, kiddies, this is the code that controls what the M-L-I
cheat does. Remember this for future reference, lest you wish to eliminate the
chance of people cheating so easily in your new add-on! Anyway, we're concerned
with the line that says "gamestate.keys = 3". See it? Change that
"3" to a "15". Now, you will get all 4 keys when you hit
M-L-I. If you understand that gamestate.keys is a 4-bit binary variable, you'll
see why it works this way. Key1 = 1, Key2 = 2, Key3 = 4, and Key4=8. Add all
that up and what do you get? Yep -- 15. That's how binary addition works. I
don't wanna explain it because I had a whole lecture on that when I started
college and I don't wanna drag it out of my notes again. You can create any
combination of keys this way. Say you only wanted to give the player Key1 (gold)
and your new Key4? Make "gamestate.keys" equal to 9 (1 + 8). See how
this works? You'll get it! Just play around with it. Don't feel bad if you don't
understand yet. It took me a while too. I had to write a frickin' debug code
that would tell me what the value of gamestate.keys was whenever I pressed Tab+Z,
just so I could figure this stuff out.
Step 4.
Save WL_PLAY.C, go compile it and link, and you're done.
FOR THE ULTIMATE TEST (RECOMMENDED FOR PEACE OF MIND):
Step 5.
Build a quick level in Mapedit that uses all 4 keys and all
4 locked doors.
Step
6.
Run your new EXE, load the test level you just made, and hit
"M-L-I". If you get all your keys and all your icons come on, you've
done it! Reload the level and try going around and picking up each key individually,
to make sure it works and that the icons come on properly (I had a hell of a
time with that at first, but the code I gave you all should work). Make sure
the right keys open the right doors and all that stuff.
TAB+K: ALL KEYS CHEAT
I went so far as to add a "Get all keys" cheat to the debug mode, complete with key pickup sound effects upon activation. If you want to do the same, you can go figure out how...or if you're lazy, you can copy and paste this code into your WL_DEBUG.C file, where all the rest of the key combos are defined. (You'll see where I mean once you take a look.)
else if (Keyboard[sc_K]) // K = get keys
{
CenterWindow (18,3);
US_PrintCentered ("All keys acquired!");
VW_UpdateScreen();
SD_PlaySound (GETKEYSND);
gamestate.keys = 15;
DrawKeys();
IN_Ack ();
DrawAllPlayBorderSides ();
IN_ClearKeysDown();
return 1;
}
WRAPPING IT UP
Well, I hope you have enjoyed this little (little?!) lesson in the art of key creation. By now, hopefully you should be learning a few things from experience about where things are stored in the source code files, and the basics of C code organization. Of course, there is no substitute for going in there are just playing around, which is what I recommend you do. But for those who needed a quick fix for their latest add-on, I hope you enjoyed yourselves, and that everything worked as it should. Now, if you're one of those folks who desperately wants to make one big episode with seamless level progression, I've recently added just the tutorial for you. See it next!
On to the next tutorial: Seamless Level Progression w/Ratio Reporting
[
Welcome ] [ News ] [ About
the Bunker ] [ Add-ons ] [ Design
Tips ]
[ Source Code ] [ My Project
] [ Links ]