Magic is a very difficult concept to define. A lot has to left to the
good judgement of the domainlords. The best is naturally to check with
an archwizard if the intended magic falls beyond the listed categories
before implementing something of dubious quality. Note that the supplied
method of implementation of personal magic isn't a recommendation, it is
a requirement.


Object magic (potions, scrolls, talismans etc)
============

With this is meant magic that is found on as objects that you activate
with an action or a word of some kind. This kind of magic doesn't
normally require spell-points from the caster to work, but should be
treated as incidental magic with the object being consumed after
completion. This kind of magic should ordinarily work independant of
the user's magic skill or related stats.

Object magic should typically be found as rewards in quests and not
just lying around or being carried by guarding monster. It might be
sold as potions or scrolls in specialized guilds but definately not in
ordinary shops. Remember though, that anything found in a shop should
be of lesser quality than what can be found by adventuring.


Personal magic ("spells")
==============

This is what is normally thought of as "spells". It's some kind of
repetitive magic that can be called upon by the player simply by
speaking a special word or performing a special action. The success of
this magic should be dependant of the player's magic skill and perhaps
also of the related stats (intelligence, wisdom and disciplin). To
perform this magic the player should have to pay with mana and also
with some sort of material components. These components should have a
value and have to obtained as objects somewhere. Magic that only
require spellpoints should be rare and comparatively powerless. The
more powerful the magic, the more rare and expensive material
components.

Personal magic should only be available to people who has devoted
themselves to studies in the field. This means that no ordinary player
will have access to this type of magic. He would typically have to be
a member of a guild that supplies this type of magic. He would have
to learn the skills at a cost there and then gain access to better and
better spells as he advances his rank within that guild.


Implementation, game support
============================

The implementation of object magic can be very straight-forward. Just
implement the gadget as you would any other object. Use add_action to
define the activating action or word.

Personal magic on the other hand should be taken care of in a
different way. In order for this type of magic to be taken care of
properly by the player you MUST do as follows:

The spell object, the object that holds the spells, must inherit the
file /std/spells.c in order to work. In that object you can find a
description telling you which functions to call and for what reason.

You must also make a directory called "SPELLS" in your domain open 
directory. In that directory you must put a file with the name of the
spell-verb of your spell where you put information about the spell
according to the file /doc/man/general/spell_form.

For example, if you have three spells "lightning", "darkness" and
"shield", you must have the files "lightning", "darkness" and "shield"
in the directory "~<yourdomain>/open/SPELLS".

Just make a copy of the document "/doc/man/general/spell_form", put it
in ~<yourdomain>/open/SPELLS with the name of your spell and put in the
relevant information instead of the instructions you find there now.

If the spell exists but the documentation doesn`t, or is inaccurate,
your lord will probably be demoted a level or two.

The player will at all times be able to type "spells" and get a list
of the spells he has active, providing that you have followed the
instructions above. 

Resistance properties
=====================

There are a number of resistance properties that deal exclusively with
magic. These properties all work in the same way, by defining a
resistance in the living object by using an external object that
defines the actual resistance. This can be items like rings, cloaks,
braces or even potions and spells. It works like this: The property
that is stored in the living object contains a count of the number of
objects in the inventory that defines a resistance. When the
resistance object is removed it should decrement the count in the
living object it protects. A spell should simply add an object with no
short or long that defines this property in the player with a call_out
of suitable length before it self-destructs.  The object resistance
property should be an array with two values defined: ({ resistance,
additivity }). The resistance is simply a percentage, if it was
defined to 25 and 8 hp was inflicted, only 6 hp would actually be
taken. The second value is 1 or 0 depending on wether the resistance
is additive or not. If it is additive, it will be added to other
additive resistances in objects the player is carried, if not it will
be counted separately. So, if the player wears one object with a
non-additive resistance of 30% and four other that are additive and
come up to 24%, he still will have a 30% protection. The maximum of
the two would be used in any occation.

The algorithm for obtaining the sum of the resistances in a living
object is a bit complicated. It's not just a simple addition since
that would make for too radical protection changes by just adding a
few objects. The algorithm works like this:

If you have n objects that provide protection:
Protection = (1 - MUL(1 -> n)[1 - objres(n)]) * 100 %                     

For example, if you have a 30%, a 20% and a 45% additive resistance
object on you, the result would be (1 - (1-0.3)*(1-0.2)*(1-0.45)) *
100 = 69% in total protection. Not 95% as would have been the case
with simple addition.

There are custom routines in the living object for returning the
total resistance of that object for a given property. Just call the 
function query_magic_res(RES_PROP); to get the total resistance of
the specified property.

The maximum resistance in an addtivie resistance object is 40%. The
maximum resistance in a non-additive resistance object is 75%. You may
not make any object better than this. Also, objects with so high
resistance should be very hard to obtain.


Distinctions of power
=====================

An important question is naturally how to order personal magic in
"cost". Which magic should be available to whom and so on. A very
natural rule-of-thumb is that players who are members in magic-related
guilds have access to magic that others never will see. You must also
distinguish carefully between which magic is available to which guild.
For obvious reasons a figher guild should only have very minor access
to healing magic. It's simply not their business to heal people, they
use offensive magic, but again not very powerful magic. A figher guild
fights with weapons, not magic. A priest guild might have access to
powerful healing spells, but not very powerful offensive spells. A
wizard guild has offensive & defensive magic, but no healing magic and
so on. Use common sense when setting up the spellists and you will
have no trouble. Ignore common sense and rules, and you'll find
yourself outside the game as soon as it is discovered.

The text following here is a very temporary thing. It will probably 
have to be replaced by something more detailed later, but you can use
it as a guideline when you design your spells. 

Let's measure the proficiency of a player in the game or in a guild
in 10 levels. A level 10 player in the game is just about to become
wizard, a level 1 player has just started.

The player is a member of a non-magical guild, or no guild at all:

Lvl 1 -  3:	No magic. He simply won't get access to it other than
	        as object magic, never as spells.
    4 -  6:	Very minor spells.
    7 - 10:	Minor spells.

The player is a member of a magic-related "other" guild. In other words
magic is not his major subject, he's just studying it on the side:

Lvl 1 -  3:	Very minor spells.
    4 -  6:	Minor spells.
    7 - 10:	Intermediary spells.

The player is a member of an "occupational" guild specializing in magic.

Lvl 1 -  3:	Minor spells.
    3 -  6:	Intermediary spells.
    7 - 10:	Advanced spells.


Very minor spells:	Typically spells that harms no one, only gives
			limited information and help. Examples of this
			kind of magic is temporary light and darkness
			spells, limited information detection spells.

Minor spells:		Very minor healing/damage, easy detection spells,
			minor defensive, dispelling spells.

Intermediary spells:	Ordinary healing/damage, detection, defense,
			dispelling etc.

Advanced spells:	Advanced detection spells (see stuff in other rooms,
			know other people's inventories etc). Powerful
			attack/healing spells. Advanced dispelling, maybe
			even stat-affecting spells. Limited conjuring power
			for very advanced players.


Timing of combat spells
=======================

Spells used to inflict damage on enemies should do so as an integral part
of the combatsystem. It should NOT inflict damage instantly upon a given 
command. This is so that wizards can code their NPC's to avoid all forms
of attacks, if that is somehow logical.

There is a property called: LIVE_O_SPELL_ATTACK

If you set this property with an object as value. The function:
spell_attack(attacker, enemy) will be called from within the combatsystem
instead of running the normal attacks. The property will then be removed.

Notice that you have to write appropriate texts and inflict damage
yourself in your 'spell_attack' routine. It is only the timing of the
attack that is controlled by the combat system.


Typical example:
	{
	    ..... in your spell code ....
 	
	    /* The spellcaster is to activate a prepared combatspell 
	     */
	    spellcaster->attack_object(enemy);
	    spellcaster->add_prop(LIVE_O_SPELL_ATTACK, this_object())
 
	    ........
	}

	void spell_attack(object caster, object target)
	{
		..... Inflict damage on target, write text etc ....
	}
/*
	Note that the target of the attack is the spellcasters current enemy
	at the time of attack. This might not be the same as when the attack
	were initialized. If you want a specific target and not the current
	enemy, you must use a property of your own in the spellcaster to
	denote target.
*/
