Covers the cObject, a generic object class that's a superclass of all other MIF objects.
cObject - Generic objects
The cObject class is at the heart of all the interactive
fiction objects, such as lanterns, monsters, player characters,
doors, and rooms. Every other interactive fiction object
is based directly or indirectly from cObject.
This tutorial will give an overview about how to use cObject.
You should read this before learning how to use cRoom for rooms,
cCharacter or cMonster for monsters, NPCs, and player characters, cDoor
for making doors, cContainer for containers, etc. since they're
all based on cObject.
To make a new object for your world, such as a lantern:
-
Create a new object using the "Objects" menu, and
selecting "Add a new object".
-
Type in the name for the object; if it's an object in
the world (such as a specific lantern) then prefix the
name with a "o" so it's easy to identify it as such.
If it's a class, such as a "light emitting class" then
prefix it with "c".
-
Under the object's "Superclass" tab, press
the "Add class" button.
-
In the "Add class(es)" page, check the "cObject" class.
This tells MIFL that your lantern object is based off
the generic object.
-
Press "Back" to return to the classes page;
you'll see the "cObject" class listed.
-
Check the "Automatically create an an object" button;
this is what makes it an object and not a class.
-
Below that, select the room that the lantern will
appear in. If it starts out held or contained by another
object then select that object.
-
Don't bother changing the object's GUID since
a unique one has automatically been generated.
-
Switch to the properties tab.
When you selected the cObject class, some properties were
automatically added. These include pNLPParseName, pNLPNounName,
and pVisual.
-
Type in pNLPParseName and pNLPNounName.
These are the names used to identify the object when its name
is typed in a command, and how to diplay the name to the
user. For more information on these,
see the How command parsing works and Noun
cases and noun-verb agreement tutorials.
Some commands, particularly in conversations, allow the use of
possessives, like as "Bill Smith's". Circumreality already contains code
to create possessives in NLPMakePossessive(), but if this
ends up making a mistake then you may need
to provide your own pNLPParseNamePossessive.
-
For pVisual you'll need a resource that
is to be used to "draw" a picture of the object. It
can either be an Image, ThreeDScene, ThreeDObject, Title,
or Text resource. If you don't have one now, leave this
blank and a default visual will be provided.
-
You should set pWeightSelf to the weight of
the object, in kilograms. pVolumeSelf is
the area that the object takes up, in liters. If the object
is roughly as dense as water, use the same values for both.
However, if the object is light but large, like a pillow,
you'll need a high volume.
-
Since you want your lantern to provide light,
add the pProvidesLight property and set
it to TRUE. Of course, this means that
your lantern is always on, but it's good enough
for the purpose of this tutorial.
-
If you want your lantern to be described the first
time a player sees it, set pDescribed.
Assuming you had a room to place the latern in, you should
be able to compile the project and visit the room with
your character. The lantern will be there and providing light.
The default cObject supports numerous properties and methods.
A typical object will only need to override some of the
properties and methods. For example: The lantern object
needs to change pProvidesLight and the methods
dealing with turning the object on or off.
For more details on the supported properties and methods,
look around the help files.
04 cRoom – Room objects
How to make rooms and connect them.
In MIFL, rooms are just objects (based on cObject) that players
can walk around in. If you want, you could even design backpacks
that players could walk around in; it's all the same. A room
is basically a container that's large enough to hold player
characters. (Although the room class is not based
on the cContainer class.)
Creating a room is easy:
-
Just as described in the "cObject" tutorial, create
a new object, but instead of deriving
your room off cObject, derive it from cRoom.
(cRoom is a subclass of cObject, so by deriving from cRoom
you are also deriving from cObject.)
If you want to make a grid of rooms, such as 16 x 16 rooms
for a section of wilderness, then name your rooms like,
"oRoomWildernessXXxYY". Replace XX with the X (east/west) location in the
16 x 16 grid, and YY with the Y (north/south) location.
However, offset your numbers so that the room in the center of the
3D model (.m3d file) is at 50 x 50. Thus, the center room would
be oRoomWilderness50x50. The room to the west of it would be
oRoomWilderness49x50.
If all of the rooms in the grid are basically
the same, you can save yourself time by creating the room in the
north-west corner first, oRoomWilderness42x42, and then copying the
same object. Everytime you copy a room, the last number, Y, will be
automatically incremented by one, to "oRoomWilderness42x43", then
"oRoomWilderness42x44". One you've created 16 rooms at 42xYY, you'll
need to manually enter a 43 for the X location.
-
Make sure the Automatically create as an object button
is checked.
-
Rooms do not need to start off contained in
other objects, although it's possible.
-
In the object's properties tab, you'll find a
number of properties that were automatically added when
you selected the "cRoom" class. You'll need to fill these in.
-
pNLPParseName and pNLPNounName will
need to be filled in. See How command parsing
works and Noun cases and noun-verb agreement.
-
pAutoMapMap should be filled in the the
map that the room is in. For now, use oMapDefault for
the value. I'll discuss maps, regions, and zones later.
-
pLocation controls
where the center of the room is in the map. This is a list
of [EW, NS, UD], where EW is the location in meters east (positive)
or west (negative). NS is north (positive) or south (negative).
UD is up (positive) or down (negative).
You don't have to set pLocation if your room is
part of a grid of rooms. The X and Y locations will automatically
be converted into a pLocation, using pAutoMapMap.pMapRoomSeparation
to determine the room spacing. The default spacing is 10 meters.
-
pDimensions specifies the size of the room.
It is a list with [EW, NS, UD], where EW is the east/west
size in meters, NS is north/south, and UD is the
height. You might
also want to change some of the other automap settings (see
the help) to control the room's shape or orientation.
You don't have to set pDimensions. If you don't,
the dimensions will be guessed based on the sizes of the
surrounding rooms.
-
pVisual and pVisualDark provide
the image that the user sees when he/she enters the room.
You should probably use a ThreeDScene resource with a 360
degree view for a room. If you haven't produced a 3D model
yet, leave pVisual and pVisualDark blank. (pVisualDark is
optional; it is used to draw the room when there's no light,
but will be automatically simulated by the lighting models.)
Alternatively, you can leave the room's pVisual blank and
create a pVisual for the room's pAutoMapMap. In
this case, the room's visual will automatically be based on
the map, and the camera location will be set to the
room's pLocation. An empty pVisual is particularly
useful for a grid of rooms.
You'll ususally use a ThreeDScene resource with
a 360-degree camera. Unless you
change pRoomAutoCameraHeight, the camera height
that you set in the ThreeDScene resource will be ignored,
and it
will automatically be adjusted based on the terrain or building (block)
that the character is in. This is desirable most of the time,
but may cause some confusion once in awhile when the camera
height suddenly changes.
-
If you want your room to be described the first
time a player enters it, set pDescribed.
Once you have built your room you need to add some exits (and
hence entrances.)
-
In the "Properties" tab, add a pExitXXX property,
like pExitNorth,
where XXX is "North", "South", "East", etc. There are twelve
different directions to choose from.
If your room is part of a grid of rooms then exits
to other rooms in the grid will be automatically generated.
You will still have to set up exits to non-grid rooms. And, if
you don't want an automatic exit in a grid room then
set pExitXXX to NULL.
Room exits will automatically be created as hotspots in the
360-degree room image unless you
change pRoomAutoHotSpots. The size and location
of the hotspots are automatically calculated, although you
can override this by changing pExitNorthHotSpot (or
pExitXXXHotSpot), or writing
your own RoomExitHotSpot() method.
-
In the property's value, type in the name of the room you
wish to connect it to, such as oRoomCircular.
-
You will also need to modify oRoomCircular and provide an
exit that connects to your new room.
That's all. Easy, eh? If you wish to add doors,
read the cDoor - Door objects tutorials.
This is a bit of an advanced topic, but I'll cover it now since
I'm covering rooms.
Online virtual worlds (and some single player games) requires
that monsters and items "spawn" from time to time. This means
that new copies of monsters and items are automatically created
a few minutes after the old ones are killed or taken. This
is necessary for muliplayer games to ensure that there are
still monsters and loot around even after previous players have been through.
To have a room spawn monsters (or items):
-
Set the pSpawnClass property to a string with
the spawned monster's class, such as "cOrc". Or, to spawn
magic mushrooms, use "cMushroomMagic". You can also use
a list, to ensure that several orcs appear in the
room, like ["cOrc", "cOrc", "cOrc"].
-
Set the pSpawnTime to the average number
of minutes between spawns. If you want
an exact time, or want to control how the time varies,
then use a list with [min time, max time].
If you don't set the value, the default pSpawnTime for
rooms is 10 minutes.
See also pSpawnTimeRange to limit the times.
-
If you wish the objects to spawn in an area (as opposed
to always appearing in this room), or you wish them
to appear in a container (such as a letter appearing in
a mailbox), then change pSpawnLocation. Look
at its documentation for details.
Other properties and methods
Rooms support many other properties and methods, such as properties
for controlling ambient sounds. To find out more, look
in the documentation.
-
If you want to play a special cutscene when a player enters the room,
then set pRoomEnterDisplay or write
your own RoomEnterDisplay() method. This is particularly
useful when a player enters a room and you wan't to narrate a special
entrance, and have the NPC provide a special greeting.
A large virtual world can contain tens of thousands of rooms.
Because this many rooms is too conceptually difficult to fit
onto one map, the rooms in a virtual world are grouped together.
First, a collection of rooms is grouped into a "map", such as
a map of a house, a map of a city, or a map of a dungeon.
A collection of nearby maps is a "region". Regions might
include counties, with multiple cities and towns.
A collection of
nearby regions is a "zone". Zones could include entire
countries, containing multiple counties.
Thus, every map is in a region, and
every region in a zone.
The IF library includes a default map, region, and zone
object: oMapDefault, oRegionDefault, oZoneDefault. You can
use these objects if you only want one map, one region, or
one zone in your world. However, if you want more you'll
need to create new objects.
To make a map object:
-
Create a new object,
-
Set its super-class to cMap.
-
Make sure the Automatically create as an object button
is checked.
-
In the object's properties page, fill
in pNLPNounName and pNLPParseName with
the map's name, such as "New York City".
-
Fill in pAutoMapRegion with the region where
the map is, such as oRegionDefault, or whatever regions you
create.
-
Fill in pLocation with [EW, NS, UD].
These are offsets for
the center of the map, compared to the center of the region.
The same properties in a room control the room's location in the
map. Likewise, in a map object, they control the map's location
within the region. You must fill these in properly
or the artificial intelligence routines will have difficulty
walking from rooms on one map to another.
-
If your map has waterfalls, or other objects that can be
heard several rooms away, you might wish
to set pMapAmbient.
To create a region object, follow basically the
same actions as a map object, but base the object off
the cRegion class, and fill in pAutoMapZone instead
of pAutoMapRegion.
A zone object can be created in the same way,
but is based off cZone and doesn't need a
pAutoMapZone or pAutoMapRegion.
Share with your friends: |