Adonthell  0.4
character_base.cc
Go to the documentation of this file.
00001 /*
00002    $Id: character_base.cc,v 1.11 2002/08/25 14:16:18 gnurou Exp $
00003    
00004    Copyright (C) 2000/2001 Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 
00016 /**
00017  * @file   character_base.cc
00018  * @author Kai Sterker <kaisterker@linuxgames.com>
00019  * 
00020  * @brief  Defines the character_base class.
00021  * 
00022  * 
00023  */
00024 
00025 
00026 #include "character_base.h"
00027 #include <iostream>
00028 
00029 using namespace std; 
00030 
00031 
00032 character_base::character_base ()
00033 {
00034     color = 1;
00035     name = "";
00036     dialogue = "";
00037 
00038     // characters are NPC's by default
00039     set_val ("type", NPC);
00040 }
00041 
00042 character_base::~character_base ()
00043 {
00044 }
00045 
00046 void character_base::set_name (string newname)
00047 {
00048     name = newname;
00049 }
00050 
00051 void character_base::set_dialogue (string newdlg)
00052 {
00053     dialogue = newdlg; 
00054 }
00055 
00056 void character_base::put_state(ogzstream& out)
00057 {
00058     storage::iterator i;
00059     
00060     u_int32 j;
00061     
00062     // Save name
00063     name >> out; 
00064     
00065     // save color
00066     color >> out; 
00067     
00068     // Save all attributes and flags
00069     j = size ();
00070     j >> out; 
00071     
00072     for (i = begin (); i != end (); i++)
00073     {
00074         string s = (*i).first;
00075         s >> out; 
00076         (*i).second >> out; 
00077     }
00078     
00079     dialogue >> out;
00080     portrait >> out; 
00081 }
00082 
00083 void character_base::get_state (igzstream& in)
00084 {
00085     u_int32 i, size;
00086     s_int32 value;
00087     
00088     // load name
00089     name << in; 
00090 
00091     // load color
00092     color << in; 
00093     
00094     // load all attributes and flags
00095     size << in; 
00096     for (i = 0; i < size; i++)
00097     {
00098         string key;
00099         key << in;
00100         
00101         /// @bug : We should be able to pass a string to objects
00102         /// instead of a char *, which memory isn't freed at exit.
00103         value << in;
00104         set_val (key.c_str (), value);
00105     }
00106 
00107     dialogue << in;
00108     portrait << in; 
00109 }