Adonthell  0.4
character_base.cc
Go to the documentation of this file.
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 
37 {
38  color = 1;
39  name = "";
40  dialogue = "";
41 
42  // characters are NPC's by default
43  set_val ("type", NPC);
44 }
45 
47 {
48 }
49 
50 void character_base::set_name (string newname)
51 {
52  name = newname;
53 }
54 
55 void character_base::set_dialogue (string newdlg)
56 {
57  dialogue = newdlg;
58 }
59 
61 {
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 
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 }
character_base::set_name
void set_name(string newname)
Sets the name of the character.
Definition: character_base.cc:50
storage::iterator
hash_map< string, s_int32 >::iterator iterator
Storage iterator, similar to STL iterator.
Definition: storage.h:118
character_base::~character_base
~character_base()
Destructor.
Definition: character_base.cc:46
igzstream
Class to read data from a Gzip compressed file.
Definition: fileops.h:135
u_int32
#define u_int32
32 bits long unsigned integer
Definition: types.h:41
s_int32
#define s_int32
32 bits long signed integer
Definition: types.h:50
ogzstream
Class to write data from a Gzip compressed file.
Definition: fileops.h:227
character_base::set_dialogue
void set_dialogue(string dialogue)
Sets the dialogue of the character.
Definition: character_base.cc:55
character_base.h
Declares the character_base class.
character_base::put_state
void put_state(ogzstream &out)
Saves the state (ttributes) of the character into an opened file.
Definition: character_base.cc:60
character_base::character_base
character_base()
Default constructor.
Definition: character_base.cc:36
character_base::get_state
void get_state(igzstream &in)
Loads the state (attributes) of the character from an opened file.
Definition: character_base.cc:87