ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/player.C
(Generate patch)

Comparing deliantra/server/common/player.C (file contents):
Revision 1.12 by root, Fri Dec 22 16:34:00 2006 UTC vs.
Revision 1.36 by root, Mon Apr 21 23:35:24 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <funcpoint.h>
26 25
27/* Determine if the attacktype represented by the 26/* Determine if the attacktype represented by the
28 * specified attack-number is enabled for dragon players. 27 * specified attack-number is enabled for dragon players.
29 * A dragon player (quetzal) can gain resistances for 28 * A dragon player (quetzal) can gain resistances for
30 * all enabled attacktypes. 29 * all enabled attacktypes.
44 * of the dragon race. 43 * of the dragon race.
45 */ 44 */
46int 45int
47is_dragon_pl (const object *op) 46is_dragon_pl (const object *op)
48{ 47{
49 if (op != NULL && op->type == PLAYER && op->arch != NULL && op->arch->clone.race != NULL && strcmp (op->arch->clone.race, "dragon") == 0) 48 if (op
49 && op->type == PLAYER
50 && op->arch
51 && op->arch->race
52 && !strcmp (op->arch->race, "dragon"))
50 return 1; 53 return 1;
54
51 return 0; 55 return 0;
52} 56}
57
58/*
59 * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory
60 */
61bool
62player::save_pl (object_freezer &freezer)
63{
64 INVOKE_PLAYER (SAVE, ob->contr);
65
66 int wiz = ob->flag [FLAG_WIZ];
67
68 /* Eneq(@csd.uu.se): If we have an open container hide it. */
69 object *container = ob->container;
70 ob->container = 0;
71
72 if (ob->map)
73 maplevel = ob->map->path;
74
75#define PL_OUT(k) freezer.put (KW_ ## k, k)
76#define PL_OUT2(k,v) freezer.put (KW_ ## k, v)
77
78 PL_OUT (password);
79 PL_OUT2 (title, own_title);
80 PL_OUT (gender);
81 PL_OUT (gen_hp);
82 PL_OUT (gen_sp);
83 PL_OUT (gen_grace);
84 PL_OUT (listening);
85 PL_OUT (bowtype);
86 PL_OUT (petmode);
87 PL_OUT (peaceful);
88 PL_OUT (digestion);
89 PL_OUT2 (pickup, mode);
90 PL_OUT (outputs_sync);
91 PL_OUT (outputs_count);
92
93 freezer.put (KW_usekeys, usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers"));
94 freezer.put (KW_unapply, unapply == unapply_nochoice ? "unapply_nochoice" : (unapply == unapply_never ? "unapply_never" : "unapply_always"));
95
96 PL_OUT2 (map, maplevel);
97 PL_OUT (savebed_map);
98 PL_OUT (bed_x);
99 PL_OUT (bed_y);
100 PL_OUT (weapon_sp);
101 PL_OUT (weapon_sp_left);
102 PL_OUT2 (Str, orig_stats.Str);
103 PL_OUT2 (Dex, orig_stats.Dex);
104 PL_OUT2 (Con, orig_stats.Con);
105 PL_OUT2 (Int, orig_stats.Int);
106 PL_OUT2 (Pow, orig_stats.Pow);
107 PL_OUT2 (Wis, orig_stats.Wis);
108 PL_OUT2 (Cha, orig_stats.Cha);
109
110 PL_OUT2 (lev_array, 10);
111
112 for (int i = 1; i <= 10; i++)
113 {
114 freezer.add (levhp [i]); freezer.add ('\n');
115 freezer.add (levsp [i]); freezer.add ('\n');
116 freezer.add (levgrace[i]); freezer.add ('\n');
117 }
118
119 freezer.put (ob->contr);
120 freezer.put (KW_endplst);
121
122 SET_FLAG (ob, FLAG_NO_FIX_PLAYER);
123 CLEAR_FLAG (ob, FLAG_WIZ);
124 ob->write (freezer);
125
126 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
127
128 /* Eneq(@csd.uu.se): Reveal the container if we have one. */
129 ob->container = container;
130
131 ob->flag [FLAG_WIZ] = wiz;
132
133 INVOKE_PLAYER (SAVE_DONE, ob->contr);
134
135 return true;
136}
137
138bool
139player::save_pl (const char *path)
140{
141 object_freezer freezer;
142
143 if (!save_pl (freezer))
144 return false;
145
146 return freezer.save (path);
147}
148
149player *
150player::load_pl (object_thawer &f)
151{
152 int maxerrs = 20;
153
154 player *pl = new player;
155
156 pl->savebed_map = first_map_path;
157
158 /* Loop through the file, loading the rest of the values */
159 for (;;)
160 {
161 switch (f.kw)
162 {
163 case KW_EOF:
164 LOG (llevError, "%s: unexpected EOF while reading player header\n", f.name);
165 goto failure;
166
167 default:
168 LOG (llevError, "%s: skipping unknown key in player header: %s\n", f.name, f.kw_str);
169 if (!--maxerrs) goto failure;
170 break;
171
172 case KW_ERROR:
173 LOG (llevError, "%s: parse error while reading player header, skipping (%s,%s).\n", f.name, f.kw_str, f.value);
174 if (!--maxerrs) goto failure;
175 break;
176
177 case KW_endplst:
178 f.next ();
179
180 if (object *op = pl->ob->read (f))
181 pl->set_object (op);
182 else
183 goto failure;
184
185 INVOKE_PLAYER (LOAD, pl);
186
187 return pl;
188
189 case KW_oid: f.get (pl, f.get_sint32 ()); break;
190 case KW_password: assign (pl->password , f.get_str ()); break;
191 case KW_title: assign (pl->own_title, f.get_str ()); break;
192 case KW_bowtype: pl->bowtype = (bowtype_t) f.get_sint32 (); break;
193 case KW_petmode: pl->petmode = (petmode_t) f.get_sint32 (); break;
194 case KW_gender: f.get (pl->gender); break;
195 case KW_listening: f.get (pl->listening); break;
196 case KW_peaceful: f.get (pl->peaceful); break;
197 case KW_digestion: f.get (pl->digestion); break;
198 case KW_pickup: f.get (pl->mode); break;
199 case KW_outputs_sync: f.get (pl->outputs_sync); break;
200 case KW_outputs_count: f.get (pl->outputs_count); break;
201 case KW_map: f.get (pl->maplevel); break;
202 case KW_savebed_map: f.get (pl->savebed_map); break;
203 case KW_bed_x: f.get (pl->bed_x); break;
204 case KW_bed_y: f.get (pl->bed_y); break;
205 case KW_weapon_sp: f.get (pl->weapon_sp); break;
206 case KW_weapon_sp_left:f.get (pl->weapon_sp_left); break;
207 case KW_Str: f.get (pl->orig_stats.Str); break;
208 case KW_Dex: f.get (pl->orig_stats.Dex); break;
209 case KW_Con: f.get (pl->orig_stats.Con); break;
210 case KW_Int: f.get (pl->orig_stats.Int); break;
211 case KW_Pow: f.get (pl->orig_stats.Pow); break;
212 case KW_Wis: f.get (pl->orig_stats.Wis); break;
213 case KW_Cha: f.get (pl->orig_stats.Cha); break;
214 case KW_gen_hp: f.get (pl->gen_hp); break;
215 case KW_gen_sp: f.get (pl->gen_sp); break;
216 case KW_gen_grace: f.get (pl->gen_grace); break;
217
218 case KW_usekeys:
219 if (!strcmp (f.get_str (), "key_inventory"))
220 pl->usekeys = key_inventory;
221 else if (!strcmp (f.get_str (), "keyrings"))
222 pl->usekeys = keyrings;
223 else if (!strcmp (f.get_str (), "containers"))
224 pl->usekeys = containers;
225 else
226 LOG (llevDebug, "load_player: got unknown usekeys type: %s\n", f.get_str ());
227 break;
228
229 case KW_unapply:
230 if (!strcmp (f.get_str (), "unapply_nochoice"))
231 pl->unapply = unapply_nochoice;
232 else if (!strcmp (f.get_str (), "unapply_never"))
233 pl->unapply = unapply_never;
234 else if (!strcmp (f.get_str (), "unapply_always"))
235 pl->unapply = unapply_always;
236 else
237 LOG (llevDebug, "load_player: got unknown unapply type: %s\n", f.get_str ());
238 break;
239
240 case KW_lev_array:
241 {
242 int count = f.get_sint32 ();
243
244 for (int i = 1; i <= count; i++)
245 {
246 char line [32];
247
248 fgets (line, 32, f); pl->levhp [i] = atoi (line);
249 fgets (line, 32, f); pl->levsp [i] = atoi (line);
250 fgets (line, 32, f); pl->levgrace[i] = atoi (line);
251 }
252 }
253 break;
254 }
255
256 f.next ();
257 }
258
259failure:
260 LOG (llevError, "%s: too many or too grave errors, aborting player load.\n", f.name);
261
262 if (pl->ob)
263 pl->ob->destroy ();
264
265 pl->destroy ();
266
267 return 0;
268}
269

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines