home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / spl / src / splbook.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  4.7 KB  |  171 lines

  1. /* splbook.hpp: spell and spellbook classes
  2.  
  3.     Copyright (C) 1993, 1994 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 <stdio.h>
  21. #include "general.hpp"
  22.  
  23. // file containing names of spellbooks to create master list:
  24. #define ALLSPELLS "splbook.all"
  25.  
  26. // any spell or psionic effect
  27. class spell {
  28.     
  29. public:
  30.     char *name;
  31.     
  32.     char *source;     // what book it came from
  33.  
  34.     char *source_file;  // file on disk that it came from
  35.     fpos_t desc_pos;    // fgetpos of first description line
  36.     boolean desc_loaded;
  37.     
  38.     int level;
  39.     char type;    // the type of spell; i.e. M, C, P
  40.     char *range;
  41.     char *area;
  42.     char *description[256];
  43.     int lines; // # of lines in the description
  44.     
  45.     spell();
  46.     ~spell();
  47.     
  48.     void add_desc(char *x);
  49.     virtual void print_stats()=0;
  50.     
  51.     // print to a file
  52.     virtual void f_print(FILE *outfile)=0;
  53.  
  54.     // print to a buffer
  55.     virtual void s_print(char *buffer)=0;
  56.     
  57.     // print a one line header to a file.
  58.     virtual void f_print_header(FILE *outfile)=0;
  59.     
  60.     // read from file
  61.     virtual void f_read(FILE *infile)=0;
  62.  
  63.     // quickly save/load in error-intolerant format
  64.     virtual void quicksave(FILE *outfile)=0;
  65.     virtual void quickload(FILE *infile)=0;
  66.     
  67.     // find and read in description
  68.     void get_desc();
  69.     void kill_desc();
  70.  
  71.     // search for a string in the description
  72.     // if ignore_case,, have string in upper case to save time!
  73.     boolean desc_search(char *str,boolean ignore_case);
  74. };
  75.  
  76. // a mage spell
  77. class magespell: public spell {
  78. public:
  79.     char *school;
  80.     char *components;
  81.     char *duration;
  82.     char *casttime;
  83.     char *save;
  84.     boolean reversible;
  85.     
  86.     magespell();
  87.     ~magespell();
  88.  
  89.     void print_stats();
  90.     void f_print(FILE *outfile);
  91.     void s_print(char *buffer);
  92.     void f_print_header(FILE *outfile);
  93.     void f_read(FILE *infile);
  94.     void quicksave(FILE *outfile);
  95.     void quickload(FILE *infile);
  96. };
  97.  
  98. // a priest spell
  99. class priestspell: public magespell {
  100. public:
  101.     char *sphere;
  102.  
  103.     priestspell();
  104.     ~priestspell();
  105.  
  106.     void print_stats();
  107.     void f_print(FILE *outfile);
  108.     void s_print(char *buffer);
  109.     void f_print_header(FILE *outfile);
  110.     void f_read(FILE *infile);
  111.     void quicksave(FILE *outfile);
  112.     void quickload(FILE *infile);
  113. };
  114.  
  115. class spelllist {
  116. public:
  117.     spell *s;
  118.     spelllist *next;
  119.     spelllist *prev;
  120.     
  121.     spelllist() {s=NULL; next=NULL; prev=NULL;};
  122.     spelllist(spell *x) {s=x; next=NULL; prev=NULL;};
  123. };
  124.  
  125. // a list of spells
  126. class spellbook {
  127. public:
  128.     spelllist *first;
  129.     spelllist *last;
  130.  
  131.     char *name;
  132.  
  133.     spellbook();
  134.     spellbook(spellbook &s);
  135.     ~spellbook();
  136.  
  137.     // for adding spells to books
  138.     spelllist* add_spell(spell &x, spelllist *where=NULL);  // null= at beginning.
  139.     spellbook& operator +=(spell &x);  // at end.
  140.     spellbook& operator +=(spellbook &s);  // at end.
  141.  
  142.     // for deleting spells from books
  143.     void del_spell(spelllist *sl);  // dangerous!  may affect other books!
  144.     void del_spell(spell &x);  // find and delete 1st copy of spell from book
  145.     spellbook& operator -=(spell &x);  // find and delete 1st copy of spell.
  146.     spellbook& operator -=(spellbook &s); // find and delete 1 copy of each
  147.                                           // spell in s.
  148.  
  149.     // look up a spell by title
  150.     spell *lookup(char *);
  151.  
  152.     // for saving books
  153.     int print_book(char *);
  154.     boolean print_abbrev(char *);
  155.     int print_titles(char *);
  156.     // quick, error-intolerant saving
  157.     boolean quicksave(char *);
  158.  
  159.     // for loading books
  160.     int read_book(char *);
  161.     // given filename and master spell list:
  162.     int read_titles(char *, spellbook *);
  163.     // or, do a best guess on the above 2 options
  164.     int read(char *, spellbook *);
  165.     // quick, error-intolerant loading
  166.     boolean quickload(char *);
  167. };
  168.  
  169. // return master spellbok using ALLSPELLS, or given name
  170. spellbook *get_master_list(char *filename=ALLSPELLS);
  171.