Merentha
Come code with us
Come code with us
The adventure begins

Merentha Website
Overview
About LPC Coding
Header Files
The Problem Sets

Rooms
Normal Rooms
Monster Rooms
Search Rooms
Exit Rooms
Door Rooms

Monsters
Normal Monster
Random/Emote Monster
Patrol/Talking Monster
Skills/Interactive Monster

Armour
A Vest
A Ring
Cursed Armour

Weapons
Normal Staff
Two Handed Sword
Special Attack Weapon
Cursed Weapon
Talkin Weapon

Lights
A Match
A Torch
A Lantern

Bags
A Normal Bag
A Backpack (wearable)
An Expanding Bag

Misc Objects
A Leaf
A Sea Shell
A Key
A Snowball

What is a header file?

This is a commonly asked question and at first most people don't value the usefulness of them. Now first I will assume you looded at some of the code examples. Lets look at the first room we coded....
It contains the lines....

    set_exits(([
        "south" : "/realms/petrarch/forest/f_room3.c",
        "north" : "/realms/petrarch/forest/f_room1.c",
    ]));

I think this is simple to understand. In this room there are 2 exits, one south and one north and after each direction name is the file name of the room you will go to when you move in that direction. Now in this case my Immortal's name is Petrarch and I am coding in my home directory (most likely the only directoy you will have access too) and I don't have access to the /domains/ directory where all areas "in the game" are stored.

So in short I code in my own directory, but when my area is completed and moved to the /domains/ those file names are no longer valid becasue instead of

        "south" : "/realms/petrarch/forest/f_room3.c",
        "north" : "/realms/petrarch/forest/f_room1.c",

I want

        "south" : "/domains/Atheria/forest/f_room3.c",
        "north" : "/domains/Atheria/forest/f_room1.c",

Which means I will need to edit every room for the new exits. If I have 50 rooms, with an average of 3 exits each, thats 150 lines of code to change. Plus, look at our examples for rooms with monsters. We load a monster by file name as well, which means that line needs to be changed. Then look at the code for monsters. Monsters load equipment by file name, and so all those lines need to be changed as well.

Now wether you followed that or not I am sure you see that there is a lot involved in changing file names around. So the question is how do we do it easier, and the answer is to use headerfiles. Now beleive it or not, if you based your code on what the examples here are like the you have already used headerfiles.

#include 
inherit ROOM;

Here you have included a header file called std.h and on the very next line you use it. To understand more, lets first look at the header file std.h

#ifndef __STD_H__
#define __STD_H__

#define ROOM 	"/std/room.c"
#define MONSTER "/std/monster.c"
#define OBJECT	"/std/object.c"
#define ARMOUR	"/std/armour.c"
#define WEAPON	"/std/weapon.c"
#define LIGHT	"/std/light.c"
#define STORAGE	"/std/storage.c"

#endif

Now what does this all mean?

Well the first 2 and the last lines are very important. They insure that you do not #include more then once. If you have it in your file more then once, bad things happen, but those lines protect you so that if you do have it more then once nothing bad happens. As a convention the __STD_H__ is based on the filename of the header, so a headerfile named petrarch.h would use __PETRARCH_H__ instead of __STD_H__.

Now if you are totally lost, a header file can be made for you by someone else so don't worry about not knowing how to create one.

Well now how to use it? Well you know that line

inherit ROOM;

Well the header file defines ROOM to be "/std/room.c" so what the MUD sees is...

inherit "/std/room.c";

Where it places the definition in for you. Now this is how a header file is used for you. Lets recode the first room using a header file.

Step 1. Create a Header File (or edit it)

So here is our file.

#ifndef __PETRARCH_H__
#define __PETRARCH_H__

#define FOREST	"/realms/petrarch/forest/"

#endif

Now here is the new code for the room. Changed lines and new lines are in red.

// by Petrarch
// Forest room, file=f_room2.c    
#include <std.h>#include <petrarch.h> inherit ROOM; void create() { ::create(); set_short("lost in a forest"); set_day_long("This section of the forest is overgrown with tall " "trees that stretch to the sky. They block out almost " "all sunlight from above making it rather dark as well " "as drop the occassional leaf to the ground."); set_night_long("The forest is nearly completely dark. Any light " "from the moons or stars is completely blocked out from " "the tall overhanging trees."); set_items(([ "forest" : "The forest is thich with trees.", "sky" : "The sky can barely be seen though the tall trees.", "ground" : "The ground is littered with leaves and twigs from " "the tree braches above.", ({"leaves", "leaf", "twig", "twigs", "brach", "bracnches"}): "Leaves and twigs litter the ground.", ({"tree", "trees"}) : "The trees stretch high into the sky.", ])); set_properties(([ "light" : 1, "night light" : 0, ])); set_exits(([
        "south" : FOREST "f_room3.c",
        "north" : FOREST "f_room1.c",
])); }
Ok, very simple. First we tell the MUD to include our header file, then in the exits we use them. Now when the MUD sees.....

"south" : FOREST "f_room3.c",

It knows to change that to

"south" : "/realms/petrarch/forest/" "f_room3.c",

Which is the file name we want. So when we code anything that points to another file, we will first define the path of that file in our own headerfile and then use the definition instead.

And how does this help us? Well now when we move files from your realm to the domains all that needs to be changed is the header file. Maybe 6 or 7 lines instead of 100s of lines in 100s of files like before.

Use header files anytime you need to reference another file. So when you include objects or monsters in rooms be sure to use a headerfile to point to that file, don't include the whole path name.


There is more documention on the MUDs to help you with headerfiles as well.



Merentha
It's your creation
Merentha Entertainment
© Copyright 1998-2002
Merentha Entertainment
All rights reserved.