scroll

obj
CONCEPT
	Scroll, Scrolls 

LAST UPDATE
	Softbyte 19.08.1995

USAGE
	inherit "obj/scroll";

	#include <magic.h>
	#include <combat.h>


DESCRIPTION
	This is a generic scroll for all magic spells. It can
	be used for casting a spell as well as for adding a spell
	to the spellbooks of the magic guilds.
 	It provides all kind of functions to easily generate magic spells.
	Functions marked with a '*' are most needed to code a spell. The
	functions are ordered into three classes. For simply coding a spell
	you need only 'Main functions'.


 ------------------------ Main Functions ---------------------------------

* AddSpell(string shortname, string||int spelltype, int||closure SP_cost,
          closure Castfunction,string||void longname,int||closure failchance)
			Basic function to set up a new scroll. Most 
			paramters will be given here. shortname is the 
			name used for casting and idendifying the spell.
			spelltype is used from magic.h, i.e ST_FIRE, etc.
			SP_cost are the cost in SP for casting the spell.
			It can also be a function which calculates the cost
			dynamically. CastFunction ist the function which
			does the magic action.
			longname is the longname of the spell, i.e. the
			not abbreviated castname. failchance is the 
			difficulty of the spell in percent.
			For details see also 'caster(O)' or a example scroll.
* SetSpellDesc()
			Set the long description if the spell. Refer to
			caster(O) for details.

* SetSpellUsage()
			Set the usage string for the spell, e.g.
			"cast fire <target>". For details refer to 
			caster(O)

* SetUser(string||string * guild)
  AddUser(string||string * guild)
			Determines which guild(s) can memorize the spell.
			The argument can either be a string or an array
			of strings. It is the short name of the guild, i.e.
			sorcerer,conjurer,archmage,necromancer. Using
			'all' means all of them and using 'both' means
			sorcerer and conjurer. 'None' or 0 means that no
			guild can memorize that spell.
			AddUser adds a user to to the guildlist. SetUser
			sets the guildlist to the argument given.

* SetMemoLevel(int) 
  QueryMemoLevel()     
			Level from which on someone can memorize the spell.


* SetFailFn(closure failfunction)
  closure QueryFailFn()
			This function will be called if the caster failed 
                        to cast the spell. Here you can harm the
                        caster or write a message.	
                        If you want to harm the player you should do a:
                        if (Repulse(this_player(),this_player()))
                             return CAST_REPULSE;
                        to check for resistance against this spell.     


  NoSell()	   
			Scroll can't be sold.

* NoMemorize()    
  SetMemorize(int) 
  QueryMemorize()  
			Determines whether the scroll is memorizable
			when found or scribed. If not one has to go
			to the travveling magedaemons and let them make
			the scroll memorizable. If a scroll should be
			not memorizable by any guild set SetUser("none")
			NoMemorize() is equal to SetMemorize(0);

* NoDestruct()       
  SetDestruct(int i)
  int QueryDesctruct()
			If NoDestruct() is set the scroll is not
			automatically removed after casting. This is 
			usefull for spell which have a duration. It is
			recommended to make the scroll invisible then.
			NoDesctruct() is equal to SetDestruct(0);


  QueryValue()          Never overwrite this function. A SetValue(0) must
                        always work!


* GetEnemy(object||void caster)
			Draw a random enemy of the caster or this_player().
			This is handy if a spell that needs as an argument
			an enemy will be casted without target. Then the
			spell can select a random target easily.

* LogCast(object caster,object target)
			Use this function if an attack spell is used
			against a player. Then the caster will be recorded
			in the log file AGGRESSORS.

* Message(MESSAGE)
			An easy way of output is provided by this 
			function. It details are described in caster(O).

* int ModifyMagic(int dam)
			All magic effects which describe a quantity or quality
			of the spell should be processed by this
			function, i.e. damge=ModifyMagic(damage).
			This allows to reduce or increase the effect of
			Magic automatically. 
			For details refer to caster(O).
 ------------------- Auxiliary Functions ---------------------------------

  string *QueryUser()	       
			Returns an array holding the shortnames of the
			guilds which can memorize the spell.

* int QueryIsUser(string guild)
			Returns 1 if guild is a guild that can memorize
			the scroll. guild can either be the short or
			the long name of the guild.

  QueryCastName()
			What to type to cast this spell. Usually a short 
			form of the scrollname, e.g. "rcold". 
                        This name is also used for the "Resistance" Property.
                        QuercCastName() is equivalent to this_spell() and
                        for compatibility only.
 
 ------------------- Internal Used Functions -----------------------------

  string *QueryGuildNames(string) 
  			 Returns an array of the names of the mage guilds.
  			 If string=="short" the short abbreviations as used
  			 by AddUser are returned. if string=="long" the
  			 real names as obtained by QueryGuild() are returned.

  string ConvertGuildName(string,void||string)
   			Converts the guild string either to the long form
   			as obtained by QueryGuild() (second arg=="long")
   			or to the short form as used by AddUser() (second
   			arg=="short"). If the second argument is omitted
   			the guild string is exchanged. If the first 
   			agrument is no valid guild name it is returned
   			unchanged.
                                    
  mixed ScrollFailCheck(string spname)
  			Is one of the Failcheck functions of the scroll.
  			It checks for Blindness and how often the
  			spell had been casted.


  void CastOver(int flag, string spname)
  			Will be called after the actual cast had been
  			performed. Clean up and remove the scroll if
  			appropriate.

  int Backfire(string spname)
  			The backfire chance of the spell when repulsed.
  			It is wisdom dependent and can be changed by
  			overwriting this function.

  string QueryShort()  
  			Short description of the scroll.

  strinc QueryReadMsg()
  			Will be written when 'read'ing the scroll.
  			Text is the description and usage of the scroll.

  MESSAGE NotifySpellFail()
  			Change the default fail handling as given by
  			obj/caster a little.

  SetCasted(int i)
  int QueryCasted()
  			Sets and Queries how often a scroll had been casted.
  			In the current concept casting a scroll is possible
  			only once.

  SetMaxCasted(int i)
  int QueryMaxCasted()	
  			Sets and Queries the maximal number a spell can
  			be casted before it will be useless. In the 
  			current concept this is fixed to 1.

 -------------------------------------------------------------------------

When casting the spell it will automatically be checked whether
it is allowed to cast it or not. 
If the spell is casted the spellpoints are reduced according to
QueryCost() and the function set as Castfunction ist called. Its argument
is the string the player gave to "cast <castname> <string>". The
castobject also allows for casting of "cast spell at/on target".
This function either has to perform the action and return CAST_SUCCESS or
if the syntax is wrong has to return CAST_FAIL_NOMSG or CAST_FAIL_MSG,
where the latter prints out that the spell has failed whereas in the former
case you have already written something appropriate. The spellpoints are
restored to the caster in this case.
In case of failure the function set bySetFailFn will be called to allow to
perfom some harmful action on the caster.
If the spell got repulse the castfunction is called with the name of
the caster as argument and ModifyMagic set to 50%. For a properly coded
spell this will automatically work. If not you have to check wether 
the argument is equal to the name of the caster.

All spells must be added to the MAGIC_SCROLL_DIR directory defined in
<magic.h>. FUN spells go in the subdirectory MAGIC_SCROLL_DIR + "FUN/".
They must be described in the spell lists as well in the spell lists for
the guilds. 

Return values of the cast and failfunctions are:
	CAST_FAIL_MSG:  Spell failed. SP will be restored and "You failed..."
			will be written.
        CAST_FAIL_NOMSG: Same as above but you have to write the fail 
        		message
	CAST_SUCCES:	Everything went fine.
	CAST_REPULSE:	Spell got repulsed.


EXAMPLE
	- all scrolls in MAGIC_SCROLL_DIR especially arcfire.c

	/* Setting up a scroll in create */
	 AddSpell("fire",ST_FIRE,35,#'MyCast,"arcanic fire",25);
	 SetSpellDesc(
	 "This spell will produce an fiery burst of fire doing a damage of up\n\
	 to 3*level HP fire damage.\n\
	 The cost of this spell is 35 SP.\n");
	 SetSpellUsage("cast fire <target>\n");
	 SetUser("sorcerer");
	 SetMemoLevel(1);
	 SetFailFn(#'MyFail);



KNOWN BUGS



INHERITANCE TREE
obj/scroll
  |-STD_TELEPORT
  `-obj/caster


SEE ALSO
	caster, magic, spells, combat, [magic] resistance