home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / games / spl / src / splbook.hpp < prev    next >
C/C++ Source or Header  |  1993-08-10  |  4KB  |  152 lines

  1. /* spellbk.hpp: spell and spellbook classes
  2.  
  3.     Copyright (C) 1993 John-Marc Chandonia
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "general.hpp"
  21.  
  22. // file containing names of spellbooks to create master list:
  23. #define ALLSPELLS "splbook.all"
  24.  
  25. // any spell or psionic effect
  26. class spell {
  27.     
  28. public:
  29.     char *name;
  30.     
  31.     char *source;     // what book it came from
  32.     
  33.     int level;
  34.     char type;    // the type of spell; i.e. M, C, P
  35.     char *range;
  36.     char *area;
  37.     char *description[256];
  38.     int lines; // # of lines in the description
  39.     
  40.     spell();
  41.     ~spell();
  42.     
  43.     void add_desc(char *x);
  44.     virtual void print_stats()=0;
  45.     
  46.     // print to a file
  47.     virtual void f_print(FILE *outfile)=0;
  48.  
  49.     // print to a buffer
  50.     virtual void s_print(char *buffer)=0;
  51.     
  52.     // print a one line header to a file.
  53.     virtual void f_print_header(FILE *outfile)=0;
  54.     
  55.     // read from file
  56.     virtual void f_read(FILE *infile)=0;
  57.     
  58.     // find and read in description
  59.     void get_desc();
  60.     void kill_desc();
  61.  
  62.     // search for a string in the description
  63.     // if ignore_case,, have string in upper case to save time!
  64.     boolean desc_search(char *str,boolean ignore_case);
  65. };
  66.  
  67. // a mage spell
  68. class magespell: public spell {
  69. public:
  70.     char *school;
  71.     char *components;
  72.     char *duration;
  73.     char *casttime;
  74.     char *save;
  75.     boolean reversible;
  76.  
  77.     magespell();
  78.     ~magespell();
  79.  
  80.     void print_stats();
  81.     void f_print(FILE *outfile);
  82.     void s_print(char *buffer);
  83.     void f_print_header(FILE *outfile);
  84.     void f_read(FILE *infile);
  85. };
  86.  
  87. // a priest spell
  88. class priestspell: public magespell {
  89. public:
  90.     char *sphere;
  91.  
  92.     priestspell();
  93.     ~priestspell();
  94.  
  95.     void print_stats();
  96.     void f_print(FILE *outfile);
  97.     void s_print(char *buffer);
  98.     void f_print_header(FILE *outfile);
  99.     void f_read(FILE *infile);
  100. };
  101.  
  102. class spelllist {
  103. public:
  104.     spell *s;
  105.     spelllist *next;
  106.     spelllist *prev;
  107.  
  108.     spelllist() {s=NULL; next=NULL; prev=NULL;};
  109.     spelllist(spell *x) {s=x; next=NULL; prev=NULL;};
  110. };
  111.  
  112. // a list of spells
  113. class spellbook {
  114. public:
  115.     spelllist *first;
  116.     spelllist *last;
  117.  
  118.     char *name;
  119.  
  120.     spellbook() {first=last=NULL; name = NULL;};
  121.     spellbook(spellbook &s);
  122.     ~spellbook();
  123.  
  124.     // for adding spells to books
  125.     spelllist* add_spell(spell &x, spelllist *where=NULL);  // null= at beginning.
  126.     spellbook& operator +=(spell &x);  // at end.
  127.     spellbook& operator +=(spellbook &s);  // at end.
  128.  
  129.     // for deleting spells from books
  130.     void del_spell(spelllist *sl);  // dangerous!  may affect other books!
  131.     void del_spell(spell &x);  // find and delete 1st copy of spell from book
  132.     spellbook& operator -=(spell &x);  // find and delete 1st copy of spell.
  133.     spellbook& operator -=(spellbook &s); // find and delete 1 copy of each
  134.                                           // spell in s.
  135.  
  136.     // look up a spell by title
  137.     spell *lookup(char *);
  138.  
  139.     // for saving books
  140.     void print_book(char *);
  141.     void print_abbrev(char *);
  142.     void print_titles(char *);
  143.  
  144.     // for loading books
  145.     boolean read_book(char *);
  146.     // given filename and master spell list:
  147.     boolean read_titles(char *, spellbook *);
  148. };
  149.  
  150. // return master spellbok using ALLSPELLS
  151. spellbook *get_master_list();
  152.