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.13 by pippijn, Sat Jan 6 14:42:29 2007 UTC vs.
Revision 1.14 by root, Sun Jan 7 02:39:13 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines