1 /* 2 Copyright (C) 2000/2001 Kai Sterker <kai.sterker@gmail.com> 3 Part of the Adonthell Project <http://adonthell.nongnu.org> 4 5 Adonthell 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 Adonthell 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 Adonthell. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 20 /** 21 * @file character_base.cc 22 * @author Kai Sterker <kai.sterker@gmail.com> 23 * 24 * @brief Defines the character_base class. 25 * 26 * 27 */ 28 29 30 #include "character_base.h" 31 #include <iostream> 32 33 using namespace std; 34 35 character_base()36character_base::character_base () 37 { 38 color = 1; 39 name = ""; 40 dialogue = ""; 41 42 // characters are NPC's by default 43 set_val ("type", NPC); 44 } 45 ~character_base()46character_base::~character_base () 47 { 48 } 49 set_name(string newname)50void character_base::set_name (string newname) 51 { 52 name = newname; 53 } 54 set_dialogue(string newdlg)55void character_base::set_dialogue (string newdlg) 56 { 57 dialogue = newdlg; 58 } 59 put_state(ogzstream & out)60void character_base::put_state(ogzstream& out) 61 { 62 storage::iterator i; 63 64 u_int32 j; 65 66 // Save name 67 name >> out; 68 69 // save color 70 color >> out; 71 72 // Save all attributes and flags 73 j = size (); 74 j >> out; 75 76 for (i = begin (); i != end (); i++) 77 { 78 string s = (*i).first; 79 s >> out; 80 (*i).second >> out; 81 } 82 83 dialogue >> out; 84 portrait >> out; 85 } 86 get_state(igzstream & in)87void character_base::get_state (igzstream& in) 88 { 89 u_int32 i, size; 90 s_int32 value; 91 92 // load name 93 name << in; 94 95 // load color 96 color << in; 97 98 // load all attributes and flags 99 size << in; 100 for (i = 0; i < size; i++) 101 { 102 string key; 103 key << in; 104 105 /// @bug : We should be able to pass a string to objects 106 /// instead of a char *, which memory isn't freed at exit. 107 value << in; 108 set_val (key.c_str (), value); 109 } 110 111 dialogue << in; 112 portrait << in; 113 } 114