[ScryMUD] SVN Commit Info r784 - trunk/mud/grrmud/server

scrymud at wanfear.com scrymud at wanfear.com
Sun Dec 19 00:49:31 PST 2004


Author: eroper
Date: 2004-12-19 00:49:31 -0800 (Sun, 19 Dec 2004)
New Revision: 784

Modified:
   trunk/mud/grrmud/server/const.h
   trunk/mud/grrmud/server/critter.cc
   trunk/mud/grrmud/server/critter.h
   trunk/mud/grrmud/server/misc2.cc
Log:
Skills/Spells are no longer stored in pc_data:: but rather in critter::.

This allows us to teach mobs things (although the interface for doing so isn't
done yet.) Other uses include only letting teachers teach skills/spells they
know, and only to the %lrnd that they themselves possess.

I didn't bother bumping file versions for this change (although it does
rearrange critter_* and Pfiles/*, etc. I haven't started using any of the new
formats yet. If for whatever reason you are using the trunk code (after
implementation of file versions) I broke it for you. If you haven't yet, but
you're planning on it... wait a few more days until I roll this code out into
production ;) I promise I won't break it after that.

Old files are read fine. (If you haven't already converted).

I'm sure this will consume a bit more memory as well. 

As a side effect of this pc_data:: version information is now written to and
read from any files that store pc_data::


Modified: trunk/mud/grrmud/server/const.h
===================================================================
--- trunk/mud/grrmud/server/const.h	2004-12-19 05:28:06 UTC (rev 783)
+++ trunk/mud/grrmud/server/const.h	2004-12-19 08:49:31 UTC (rev 784)
@@ -1419,7 +1419,7 @@
 #define FOLLOWER_OF         follower_of
 #define MASTER                 master
 #define EQ                 eq
-#define SKILLS_KNOWN         pc->skills_spells_known
+#define SKILLS_KNOWN      skills_spells_known
 #define FOLLOWERS         followers
 #define FLAG1                 mob->proc_data->flag1
 #define INT1                 mob->proc_data->int1

Modified: trunk/mud/grrmud/server/critter.cc
===================================================================
--- trunk/mud/grrmud/server/critter.cc	2004-12-19 05:28:06 UTC (rev 783)
+++ trunk/mud/grrmud/server/critter.cc	2004-12-19 08:49:31 UTC (rev 784)
@@ -1395,7 +1395,6 @@
    }
 
    pc_data_flags.Clear();
-   skills_spells_known.Clear();
    prompt.Clear();
    poofout.Clear();
    poofin.Clear();
@@ -1470,7 +1469,6 @@
    died_count = source.died_count;
    quest_points = source.quest_points;
    idle_ticks = source.idle_ticks;
-   skills_spells_known = source.skills_spells_known; //overload operator
    prompt = source.prompt;
    w_eye_obj = source.w_eye_obj;
    last_login_time = source.last_login_time;
@@ -1502,6 +1500,8 @@
 
 void pc_data::Write(ofstream& ofile) {
    int i, ii;
+
+   ofile << "%" << PC_DATA_FORMAT_VERSION << "\tpc_data format version" << endl;
    
    ofile << password << "\tpasswd\n";
    
@@ -1520,25 +1520,6 @@
          << " " << pk_count << " " << died_count << " " << quest_points
          << " age hgr thr drg pk died qp\n";
    
-   int key;
-   i = 1;
-   int retval = 0;
-   if (skills_spells_known.Min(key)) {//if it isn't empty
-      ofile << key << " ";
-      skills_spells_known.Find(key, retval);
-      ofile << retval << " ";
-      while (skills_spells_known.Next(key)) {
-         ofile << key << " ";
-         skills_spells_known.Find(key, retval);
-         ofile << retval << " ";
-         if (++i > 9) {
-            ofile << endl;
-            i = 0;
-         }//if
-      }//while
-   }//if
-   ofile << -1 << "\tss_known\n";         
-   
    ofile << prompt << endl;
 
    if (pc_data_flags.get(21)) {
@@ -1592,9 +1573,10 @@
 }//Write()       
 
 
-void pc_data::Read(ifstream& ofile, int format_version) {
+void pc_data::Read(critter* parent, ifstream& ofile) {
    int i;
    char tmp[81];
+   int format_version;
    
    Clear();
 
@@ -1604,6 +1586,20 @@
       }
       return;
    }
+
+   // look for a file-version identifier
+   {
+      char tst_char;
+      ofile.get(tst_char);
+      if ( tst_char != '%' ) {
+         // no file version 
+         ofile.putback(tst_char);
+         format_version = 0;
+      } else {
+         ofile >> format_version;
+         ofile.getline(tmp, 80);
+      }
+   }
    
    ofile >> password;
    ofile.getline(tmp, 80);
@@ -1624,21 +1620,23 @@
          >> quest_points;
    ofile.getline(tmp, 80);
    
-   /* skills spells known */
-   ofile >> i;
-   int tmp_int;
-   while (i != -1) {
-      if (!ofile) {
-         if (mudlog.ofLevel(ERROR)) {
-            mudlog << "ERROR:  da_file FALSE in pc_data read." << endl;
+   if ( format_version == 0 ) {
+      /* skills spells known */
+      ofile >> i;
+      int tmp_int;
+      while (i != -1) {
+         if (!ofile) {
+            if (mudlog.ofLevel(ERROR)) {
+               mudlog << "ERROR:  da_file FALSE in pc_data read." << endl;
+            }
+            return;
          }
-         return;
-      }
-      ofile >> tmp_int;
-      skills_spells_known.Insert(i, tmp_int);
-      ofile >> i;
-   }//while
-   ofile.getline(tmp, 80);
+         ofile >> tmp_int;
+         parent->skills_spells_known.Insert(i, tmp_int);
+         ofile >> i;
+      }//while
+      ofile.getline(tmp, 80);
+   }//if format_version == 0
    
    ofile.getline(tmp, 80); //grabs prompt
    prompt = tmp;
@@ -1837,6 +1835,7 @@
    short_desc = source.short_desc;
    in_room_desc = source.in_room_desc;
    long_desc = source.long_desc;
+   skills_spells_known = source.skills_spells_known; //overload operator
 
    if (source.pc) {
       pc = new pc_data(*(source.pc));
@@ -2044,6 +2043,7 @@
    short_desc.Clear();
    in_room_desc.Clear();
    long_desc.Clear();
+   skills_spells_known.Clear();
 
    crit_flags.Clear();
    spam_cnt = 0;
@@ -2520,6 +2520,26 @@
    }//while
    ofile << -1 << "\taffected_by\n";
 
+   //Skills&Spells
+   int key;
+   i = 1;
+   int retval = 0;
+   if (skills_spells_known.Min(key)) {//if it isn't empty
+      ofile << key << " ";
+      skills_spells_known.Find(key, retval);
+      ofile << retval << " ";
+      while (skills_spells_known.Next(key)) {
+         ofile << key << " ";
+         skills_spells_known.Find(key, retval);
+         ofile << retval << " ";
+         if (++i > 9) {
+            ofile << endl;
+            i = 0;
+         }//if
+      }//while
+   }//if
+   ofile << -1 << "\tss_known\n";         
+
                 /*  Inventory */
    
    num_written = 0;
@@ -3575,6 +3595,24 @@
    }//while
    ofile.getline(tmp, 80);
 
+   if ( format_version > 0 ) {
+      /* skills spells known */
+      ofile >> i;
+      int tmp_int;
+      while (i != -1) {
+         if (!ofile) {
+            if (mudlog.ofLevel(ERROR)) {
+               mudlog << "ERROR:  da_file FALSE in pc_data read." << endl;
+            }
+            return;
+         }
+         ofile >> tmp_int;
+         skills_spells_known.Insert(i, tmp_int);
+         ofile >> i;
+      }//while
+      ofile.getline(tmp, 80);
+   }//format_version > 0
+
                 /*  Inventory */
    ofile >> i;
    while (i != -1) {
@@ -3620,7 +3658,7 @@
       if (!(pc)) {
          pc = new pc_data;
       }//if
-      pc->Read(ofile, format_version);  
+      pc->Read(this, ofile);  
       pc->file_format_version = format_version;
    }//if
    else { //its a mob

Modified: trunk/mud/grrmud/server/critter.h
===================================================================
--- trunk/mud/grrmud/server/critter.h	2004-12-19 05:28:06 UTC (rev 783)
+++ trunk/mud/grrmud/server/critter.h	2004-12-19 08:49:31 UTC (rev 784)
@@ -29,6 +29,7 @@
 #define GRRMUD_CRITTER_INCLUDE_H
 
 #define CRITTER_FORMAT_VERSION 1
+#define PC_DATA_FORMAT_VERSION 1
 
 #include <bitfield.h>
 #include <string2.h>
@@ -602,7 +603,6 @@
    int last_login_time; //in seconds, since 1970 etc...
    int total_time_online; //in seconds
 
-   Tree<int, int> skills_spells_known; 
    object* w_eye_obj; //wizard's eye object
 
    // Ansi color codes.
@@ -638,7 +638,7 @@
 
    void Clear();
    void Write(ofstream& ofile);
-   void Read(ifstream& ofile, int format_version);
+   void Read(critter* parent, ifstream& ofile);
    static int getInstanceCount() { return _cnt; }
 
    int client;
@@ -714,6 +714,7 @@
    PtrList<stat_spell_cell> mini_affected_by; //decreased every battle
    //round
    PtrList<object> inv; // array of items in inventory
+   Tree<int, int> skills_spells_known; 
    
    pc_data* pc; //NULL if not a pc
    mob_data* mob; //null if not a mob

Modified: trunk/mud/grrmud/server/misc2.cc
===================================================================
--- trunk/mud/grrmud/server/misc2.cc	2004-12-19 05:28:06 UTC (rev 783)
+++ trunk/mud/grrmud/server/misc2.cc	2004-12-19 08:49:31 UTC (rev 784)
@@ -1684,7 +1684,7 @@
    }//if not a pc
    
    int retval;
-   if (pc.SKILLS_KNOWN.Find(skill_num, retval)) {
+   if (static_cast< Tree<int,int> >(pc.SKILLS_KNOWN).Find(skill_num, retval)) {
       return retval;
    }//if
    




More information about the ScryMUD mailing list