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

Comparing deliantra/server/server/player.C (file contents):
Revision 1.142 by root, Fri May 18 19:46:22 2007 UTC vs.
Revision 1.152 by root, Sun Jul 1 05:00:20 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT 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 3 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, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The author can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <sproto.h> 25#include <sproto.h>
27#include <sounds.h> 26#include <sounds.h>
157 op->x = -1; 156 op->x = -1;
158 op->y = -1; 157 op->y = -1;
159} 158}
160 159
161void 160void
162player::enter_map ()
163{
164 object *tmp = object::create ();
165
166 EXIT_PATH (tmp) = maplevel;
167 EXIT_X (tmp) = ob->x;
168 EXIT_Y (tmp) = ob->y;
169 ob->enter_exit (tmp);
170
171 tmp->destroy ();
172}
173
174void
175player::activate () 161player::activate ()
176{ 162{
177 if (active) 163 if (active)
178 return; 164 return;
179 165
181 ob->remove (); 167 ob->remove ();
182 ob->map = 0; 168 ob->map = 0;
183 ob->activate_recursive (); 169 ob->activate_recursive ();
184 CLEAR_FLAG (ob, FLAG_FRIENDLY); 170 CLEAR_FLAG (ob, FLAG_FRIENDLY);
185 add_friendly_object (ob); 171 add_friendly_object (ob);
186 enter_map ();
187} 172}
188 173
189void 174void
190player::deactivate () 175player::deactivate ()
191{ 176{
221 ob->close_container (); //TODO: client-specific 206 ob->close_container (); //TODO: client-specific
222 207
223 ns->update_look = 0; 208 ns->update_look = 0;
224 ns->look_position = 0; 209 ns->look_position = 0;
225 210
226 clear_los (ob); 211 clear_los (this);
227 212
228 ns->reset_stats (); 213 ns->reset_stats ();
229 214
230 /* make sure he's a player -- needed because of class change. */ 215 /* make sure he's a player -- needed because of class change. */
231 ob->type = PLAYER; // we are paranoid 216 ob->type = PLAYER; // we are paranoid
232 ob->race = ob->arch->clone.race; 217 ob->race = ob->arch->race;
233 218
234 ob->carrying = sum_weight (ob); 219 ob->carrying = sum_weight (ob);
235 link_player_skills (ob); 220 link_player_skills (ob);
236 221
237 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 222 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
238 223
239 assign (title, ob->arch->clone.name); 224 assign (title, ob->arch->object::name);
240 225
241 /* if it's a dragon player, set the correct title here */ 226 /* if it's a dragon player, set the correct title here */
242 if (is_dragon_pl (ob)) 227 if (is_dragon_pl (ob))
243 { 228 {
244 object *tmp, *abil = 0, *skin = 0; 229 object *tmp, *abil = 0, *skin = 0;
246 shstr_cmp dragon_ability_force ("dragon_ability_force"); 231 shstr_cmp dragon_ability_force ("dragon_ability_force");
247 shstr_cmp dragon_skin_force ("dragon_skin_force"); 232 shstr_cmp dragon_skin_force ("dragon_skin_force");
248 233
249 for (tmp = ob->inv; tmp; tmp = tmp->below) 234 for (tmp = ob->inv; tmp; tmp = tmp->below)
250 if (tmp->type == FORCE) 235 if (tmp->type == FORCE)
251 if (tmp->arch->name == dragon_ability_force) 236 if (tmp->arch->archname == dragon_ability_force)
252 abil = tmp; 237 abil = tmp;
253 else if (tmp->arch->name == dragon_skin_force) 238 else if (tmp->arch->archname == dragon_skin_force)
254 skin = tmp; 239 skin = tmp;
255 240
256 set_dragon_name (ob, abil, skin); 241 set_dragon_name (ob, abil, skin);
257 } 242 }
258 243
317 } 302 }
318 303
319 if (ob) 304 if (ob)
320 ob->close_container (); //TODO: client-specific 305 ob->close_container (); //TODO: client-specific
321 306
307 observe = ob;
308
322 deactivate (); 309 deactivate ();
323} 310}
324 311
325// the need for this function can be explained 312// the need for this function can be explained
326// by load_object not returning the object 313// by load_object not returning the object
327void 314void
328player::set_object (object *op) 315player::set_object (object *op)
329{ 316{
330 ob = op; 317 ob = observe = op;
331 ob->contr = this; /* this aren't yet in archetype */ 318 ob->contr = this; /* this aren't yet in archetype */
332 319
333 ob->speed = 1.0f; 320 ob->speed = 1.0f;
334 ob->speed_left = 0.5f; 321 ob->speed_left = 0.5f;
335 322
336 ob->direction = 5; /* So player faces south */ 323 ob->direction = 5; /* So player faces south */
324}
325
326void
327player::set_observe (object *op)
328{
329 observe = op ? op : ob;
330 do_los = 1;
337} 331}
338 332
339player::player () 333player::player ()
340{ 334{
341 /* There are some elements we want initialised to non zero value - 335 /* There are some elements we want initialised to non zero value -
369 if (ob) 363 if (ob)
370 { 364 {
371 ob->destroy_inv (false); 365 ob->destroy_inv (false);
372 ob->destroy (); 366 ob->destroy ();
373 } 367 }
368
369 ob = observe = 0;
374} 370}
375 371
376player::~player () 372player::~player ()
377{ 373{
378 /* Clear item stack */ 374 /* Clear item stack */
405 * Note: there MUST be at least one player archetype! 401 * Note: there MUST be at least one player archetype!
406 */ 402 */
407archetype * 403archetype *
408get_player_archetype (archetype *at) 404get_player_archetype (archetype *at)
409{ 405{
410 archetype *start = at; 406 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin ();
411 407
412 for (;;) 408 for (;;)
413 { 409 {
414 if (at == NULL || at->next == NULL) 410 if (++i == archetypes.end ())
415 at = first_archetype; 411 i = archetypes.begin ();
416 else 412 else if (*i == at)
417 at = at->next; 413 cleanup ("not a single player archetype found");
418 414
419 if (at->clone.type == PLAYER) 415 if ((*i)->type == PLAYER)
420 return at; 416 return *i;
421
422 if (at == start)
423 {
424 LOG (llevError, "No Player archetypes\n");
425 exit (-1);
426 }
427 } 417 }
428} 418}
429 419
430object * 420object *
431get_nearest_player (object *mon) 421get_nearest_player (object *mon)
921 if (*first_map_ext_path) 911 if (*first_map_ext_path)
922 { 912 {
923 object *tmp; 913 object *tmp;
924 char mapname[MAX_BUF]; 914 char mapname[MAX_BUF];
925 915
926 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->name); 916 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
927 tmp = object::create (); 917 tmp = object::create ();
928 EXIT_PATH (tmp) = mapname; 918 EXIT_PATH (tmp) = mapname;
929 EXIT_X (tmp) = ob->x; 919 EXIT_X (tmp) = ob->x;
930 EXIT_Y (tmp) = ob->y; 920 EXIT_Y (tmp) = ob->y;
931 ob->enter_exit (tmp); /* we don't really care if it succeeded; 921 ob->enter_exit (tmp); /* we don't really care if it succeeded;
950 int x = ob->x, y = ob->y; 940 int x = ob->x, y = ob->y;
951 941
952 ob->remove_statbonus (); 942 ob->remove_statbonus ();
953 ob->remove (); 943 ob->remove ();
954 ob->arch = get_player_archetype (ob->arch); 944 ob->arch = get_player_archetype (ob->arch);
955 ob->arch->clone.copy_to (ob); 945 ob->arch->copy_to (ob);
956 ob->instantiate (); 946 ob->instantiate ();
957 ob->stats = ob->contr->orig_stats; 947 ob->stats = ob->contr->orig_stats;
958 ob->name = ob->name_pl = name; 948 ob->name = ob->name_pl = name;
959 ob->x = x; 949 ob->x = x;
960 ob->y = y; 950 ob->y = y;
961 SET_ANIMATION (ob, 2); /* So player faces south */ 951 SET_ANIMATION (ob, 2); /* So player faces south */
962 insert_ob_in_map (ob, ob->map, ob, 0); 952 insert_ob_in_map (ob, ob->map, ob, 0);
963 assign (ob->contr->title, ob->arch->clone.name); 953 assign (ob->contr->title, ob->arch->object::name);
964 ob->add_statbonus (); 954 ob->add_statbonus ();
965 } 955 }
966 while (!allowed_class (ob)); 956 while (!allowed_class (ob));
967 957
968 update_object (ob, UP_OBJ_FACE); 958 update_object (ob, UP_OBJ_FACE);
1113 if (tmp->name != NULL) 1103 if (tmp->name != NULL)
1114 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1104 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1115 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1105 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1116 else 1106 else
1117 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1107 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1118 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1108 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1119 1109
1120 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1110 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1121 } 1111 }
1122 1112
1123 /* philosophy: 1113 /* philosophy:
1316 /* careful: chairs and tables are weapons! */ 1306 /* careful: chairs and tables are weapons! */
1317 if (op->contr->mode & PU_ALLWEAPON) 1307 if (op->contr->mode & PU_ALLWEAPON)
1318 { 1308 {
1319 if (tmp->type == WEAPON && tmp->name != NULL) 1309 if (tmp->type == WEAPON && tmp->name != NULL)
1320 { 1310 {
1321 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1311 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1322 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1312 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1323 { 1313 {
1324 pick_up (op, tmp); 1314 pick_up (op, tmp);
1325 continue; 1315 continue;
1326 } 1316 }
1327 } 1317 }
1328 1318
1329 if (tmp->type == WEAPON && tmp->name == NULL) 1319 if (tmp->type == WEAPON && tmp->name == NULL)
1330 { 1320 {
1331 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1321 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1332 { 1322 {
1333 pick_up (op, tmp); 1323 pick_up (op, tmp);
1334 continue; 1324 continue;
1335 } 1325 }
1336 } 1326 }
1361 if (tmp->name != NULL) 1351 if (tmp->name != NULL)
1362 { 1352 {
1363 fprintf (stderr, "%s", tmp->name); 1353 fprintf (stderr, "%s", tmp->name);
1364 } 1354 }
1365 else 1355 else
1366 fprintf (stderr, "%s", tmp->arch->name); 1356 fprintf (stderr, "%s", tmp->arch->archname);
1367 fprintf (stderr, ",%d] = ", tmp->type); 1357 fprintf (stderr, ",%d] = ", tmp->type);
1368 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1358 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1369#endif 1359#endif
1370 continue; 1360 continue;
1371 } 1361 }
1441 else 1431 else
1442 { 1432 {
1443 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) 1433 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++)
1444 { 1434 {
1445 attacktype = 1 << attacknum; 1435 attacktype = 1 << attacknum;
1446 if ((arrow->attacktype & attacktype) && (target->arch->clone.resist[attacknum]) < 0) 1436 if ((arrow->attacktype & attacktype) && (target->arch->resist[attacknum]) < 0)
1447 if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100) > betterby) 1437 if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100) > betterby)
1448 { 1438 {
1449 tmp = arrow; 1439 tmp = arrow;
1450 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100; 1440 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1451 } 1441 }
1452 } 1442 }
1453 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1443 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1454 { 1444 {
1455 tmp = arrow; 1445 tmp = arrow;
1814 object *tmp; 1804 object *tmp;
1815 1805
1816 if (item->arch) 1806 if (item->arch)
1817 { 1807 {
1818 CLEAR_FLAG (item, FLAG_ANIMATE); 1808 CLEAR_FLAG (item, FLAG_ANIMATE);
1819 item->face = item->arch->clone.face; 1809 item->face = item->arch->face;
1820 item->set_speed (0); 1810 item->set_speed (0);
1821 } 1811 }
1822 1812
1823 if ((tmp = item->in_player ())) 1813 if ((tmp = item->in_player ()))
1824 esrv_update_item (UPD_ANIM, tmp, item); 1814 esrv_update_item (UPD_ANIM, tmp, item);
2180 * that party_number -1 is no party, so attacks can still happen. 2170 * that party_number -1 is no party, so attacks can still happen.
2181 */ 2171 */
2182 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2172 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2183 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2173 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2184 { 2174 {
2185 if (op->contr->weapon_sp_left > 0.f) 2175 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
2186 { 2176 {
2187 --op->contr->weapon_sp_left; 2177 --op->contr->weapon_sp_left;
2188 2178
2189 skill_attack (mon, op, 0, 0, 0); 2179 skill_attack (mon, op, 0, 0, 0);
2190 2180
3047} 3037}
3048 3038
3049int 3039int
3050is_true_undead (object *op) 3040is_true_undead (object *op)
3051{ 3041{
3052 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3042 if (QUERY_FLAG (op->arch, FLAG_UNDEAD))
3053 return 1; 3043 return 1;
3054 3044
3055 return 0; 3045 return 0;
3056} 3046}
3057 3047
3227 * a blocked los square. 3217 * a blocked los square.
3228 * we use the archetype to figure out offsets. 3218 * we use the archetype to figure out offsets.
3229 */ 3219 */
3230 while (op) 3220 while (op)
3231 { 3221 {
3232 dx = rv.distance_x + op->arch->clone.x; 3222 dx = rv.distance_x + op->arch->x;
3233 dy = rv.distance_y + op->arch->clone.y; 3223 dy = rv.distance_y + op->arch->y;
3234 3224
3235 /* only the viewable area the player sees is updated by LOS 3225 /* only the viewable area the player sees is updated by LOS
3236 * code, so we need to restrict ourselves to that range of values 3226 * code, so we need to restrict ourselves to that range of values
3237 * for any meaningful values. 3227 * for any meaningful values.
3238 */ 3228 */
3363 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ 3353 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
3364 return; 3354 return;
3365 } 3355 }
3366 3356
3367 /* everything seems okay - now bring on the gift: */ 3357 /* everything seems okay - now bring on the gift: */
3368 item = &(tr->item->clone); 3358 item = tr->item;
3369 3359
3370 if (item->type == SPELL) 3360 if (item->type == SPELL)
3371 { 3361 {
3372 if (check_spell_known (who, item->name)) 3362 if (check_spell_known (who, item->name))
3373 return; 3363 return;
3433 /* forces in the treasurelist can alter the player's stats */ 3423 /* forces in the treasurelist can alter the player's stats */
3434 object *skin; 3424 object *skin;
3435 3425
3436 /* first get the dragon skin force */ 3426 /* first get the dragon skin force */
3437 shstr_cmp dragon_skin_force ("dragon_skin_force"); 3427 shstr_cmp dragon_skin_force ("dragon_skin_force");
3438 for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below) 3428 for (skin = who->inv; skin && !(skin->arch->archname == dragon_skin_force); skin = skin->below)
3439 ; 3429 ;
3440 3430
3441 if (!skin) 3431 if (!skin)
3442 return; 3432 return;
3443 3433

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines