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.4 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.15 by root, Mon Jan 8 18:18:35 2007 UTC

1
2/* 1/*
3 * static char *rcsid_player_c =
4 * "$Id: player.C,v 1.4 2006/09/10 16:00:23 root Exp $";
5 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
9 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
12 7 *
13 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
14 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
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 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,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 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
24 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21 *
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 23 */
29 24
30#include <global.h> 25#include <global.h>
31#include <funcpoint.h> 26#include <funcpoint.h>
32
33void
34free_player (player *pl)
35{
36
37 if (first_player != pl)
38 {
39 player *prev = first_player;
40
41 while (prev != NULL && prev->next != NULL && prev->next != pl)
42 prev = prev->next;
43 if (prev->next != pl)
44 {
45 LOG (llevError, "Free_player: Can't find previous player.\n");
46 exit (1);
47 }
48 prev->next = pl->next;
49 }
50 else
51 first_player = pl->next;
52
53 if (pl->ob != NULL)
54 {
55 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
56 remove_ob (pl->ob);
57 free_object (pl->ob);
58 }
59 /* Clear item stack */
60 if (pl->stack_items)
61 free (pl->stack_items);
62
63 free (pl->socket.faces_sent);
64
65 delete pl;
66}
67
68 27
69/* Determine if the attacktype represented by the 28/* Determine if the attacktype represented by the
70 * specified attack-number is enabled for dragon players. 29 * specified attack-number is enabled for dragon players.
71 * A dragon player (quetzal) can gain resistances for 30 * A dragon player (quetzal) can gain resistances for
72 * all enabled attacktypes. 31 * all enabled attacktypes.
75atnr_is_dragon_enabled (int attacknr) 34atnr_is_dragon_enabled (int attacknr)
76{ 35{
77 if (attacknr == ATNR_MAGIC || attacknr == ATNR_FIRE || 36 if (attacknr == ATNR_MAGIC || attacknr == ATNR_FIRE ||
78 attacknr == ATNR_ELECTRICITY || attacknr == ATNR_COLD || attacknr == ATNR_ACID || attacknr == ATNR_POISON) 37 attacknr == ATNR_ELECTRICITY || attacknr == ATNR_COLD || attacknr == ATNR_ACID || attacknr == ATNR_POISON)
79 return 1; 38 return 1;
39
80 return 0; 40 return 0;
81} 41}
82 42
83/* 43/*
84 * returns true if the adressed object 'ob' is a player 44 * returns true if the adressed object 'ob' is a player
89{ 49{
90 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)
91 return 1; 51 return 1;
92 return 0; 52 return 0;
93} 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, 10);
105
106 for (int i = 1; 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->savebed_map = first_map_path;
149
150 /* Loop through the file, loading the rest of the values */
151 for (;;)
152 {
153 keyword kw = thawer.get_kv ();
154
155 switch (kw)
156 {
157 case KW_EOF:
158 LOG (llevError, "%s: unexpected EOF while reading player header\n", thawer.name);
159 delete pl;
160 return 0;
161
162 case KW_ERROR:
163 LOG (llevError, "%s: error while reading player header, skipping (%s,%s)\n", thawer.name, thawer.last_keyword, thawer.last_value);
164 break;
165
166 case KW_endplst:
167 goto done;
168
169 case KW_oid: thawer.get (pl, thawer.get_sint32 ()); break;
170 case KW_password: assign (pl->password , thawer.get_str ()); break;
171 case KW_title: assign (pl->own_title, thawer.get_str ()); break;
172 case KW_shoottype: pl->shoottype = (rangetype) thawer.get_sint32 (); break;
173 case KW_bowtype: pl->bowtype = (bowtype_t) thawer.get_sint32 (); break;
174 case KW_petmode: pl->petmode = (petmode_t) thawer.get_sint32 (); break;
175 case KW_listening: thawer.get (pl->listening); break;
176 case KW_peaceful: thawer.get (pl->peaceful); break;
177 case KW_digestion: thawer.get (pl->digestion); break;
178 case KW_pickup: thawer.get (pl->mode); break;
179 case KW_outputs_sync: thawer.get (pl->outputs_sync); break;
180 case KW_outputs_count: thawer.get (pl->outputs_count); break;
181 case KW_map: thawer.get (pl->maplevel); break;
182 case KW_savebed_map: thawer.get (pl->savebed_map); break;
183 case KW_bed_x: thawer.get (pl->bed_x); break;
184 case KW_bed_y: thawer.get (pl->bed_y); break;
185 case KW_weapon_sp: thawer.get (pl->weapon_sp); break;
186 case KW_Str: thawer.get (pl->orig_stats.Str); break;
187 case KW_Dex: thawer.get (pl->orig_stats.Dex); break;
188 case KW_Con: thawer.get (pl->orig_stats.Con); break;
189 case KW_Int: thawer.get (pl->orig_stats.Int); break;
190 case KW_Pow: thawer.get (pl->orig_stats.Pow); break;
191 case KW_Wis: thawer.get (pl->orig_stats.Wis); break;
192 case KW_Cha: thawer.get (pl->orig_stats.Cha); break;
193 case KW_gen_hp: thawer.get (pl->gen_hp); break;
194 case KW_gen_sp: thawer.get (pl->gen_sp); break;
195 case KW_gen_grace: thawer.get (pl->gen_grace); break;
196
197 case KW_usekeys:
198 if (!strcmp (thawer.get_str (), "key_inventory"))
199 pl->usekeys = key_inventory;
200 else if (!strcmp (thawer.get_str (), "keyrings"))
201 pl->usekeys = keyrings;
202 else if (!strcmp (thawer.get_str (), "containers"))
203 pl->usekeys = containers;
204 else
205 LOG (llevDebug, "load_player: got unknown usekeys type: %s\n", thawer.get_str ());
206 break;
207
208 case KW_unapply:
209 if (!strcmp (thawer.get_str (), "unapply_nochoice"))
210 pl->unapply = unapply_nochoice;
211 else if (!strcmp (thawer.get_str (), "unapply_never"))
212 pl->unapply = unapply_never;
213 else if (!strcmp (thawer.get_str (), "unapply_always"))
214 pl->unapply = unapply_always;
215 else
216 LOG (llevDebug, "load_player: got unknown unapply type: %s\n", thawer.get_str ());
217 break;
218
219 case KW_lev_array:
220 {
221 int count = thawer.get_sint32 ();
222
223 for (int i = 1; i <= count; i++)
224 {
225 char line[128];
226
227 fgets (line, 128, thawer); pl->levhp [i] = atoi (line);
228 fgets (line, 128, thawer); pl->levsp [i] = atoi (line);
229 fgets (line, 128, thawer); pl->levgrace[i] = atoi (line);
230 }
231 }
232 break;
233
234 default:
235 LOG (llevError, "%s: skipping unknown key in player header: %s\n", thawer.name, keyword_str [kw]);
236 break;
237 }
238 }
239
240done:
241 /* this loads the standard objects values. */
242 pl->set_object (object::create ());
243
244 if (!load_object (thawer, pl->ob, 0))
245 {
246 pl->ob->destroy ();
247 delete pl;
248 return 0;
249 }
250
251 INVOKE_PLAYER (LOAD, pl);
252
253 return pl;
254}
255
256player *
257player::load_pl (const char *path)
258{
259 object_thawer thawer (path);
260
261 if (!thawer)
262 return 0;
263
264 return load_pl (thawer);
265}
266

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines