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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.140 by root, Tue Apr 24 12:32:14 2007 UTC vs.
Revision 1.155 by root, Thu May 17 21:32:08 2007 UTC

29#include <stdio.h> 29#include <stdio.h>
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/uio.h> 31#include <sys/uio.h>
32#include <object.h> 32#include <object.h>
33#include <funcpoint.h> 33#include <funcpoint.h>
34#include <sproto.h>
34#include <loader.h> 35#include <loader.h>
35 36
36#include <bitset> 37#include <bitset>
37 38
38int nrofallocobjects = 0; 39int nrofallocobjects = 0;
324sum_weight (object *op) 325sum_weight (object *op)
325{ 326{
326 long sum; 327 long sum;
327 object *inv; 328 object *inv;
328 329
329 for (sum = 0, inv = op->inv; inv != NULL; inv = inv->below) 330 for (sum = 0, inv = op->inv; inv; inv = inv->below)
330 { 331 {
331 if (inv->inv) 332 if (inv->inv)
332 sum_weight (inv); 333 sum_weight (inv);
334
333 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); 335 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1);
334 } 336 }
335 337
336 if (op->type == CONTAINER && op->stats.Str) 338 if (op->type == CONTAINER && op->stats.Str)
337 sum = (sum * (100 - op->stats.Str)) / 100; 339 sum = (sum * (100 - op->stats.Str)) / 100;
446 */ 448 */
447 while (owner->owner) 449 while (owner->owner)
448 owner = owner->owner; 450 owner = owner->owner;
449 451
450 this->owner = owner; 452 this->owner = owner;
453}
454
455int
456object::slottype () const
457{
458 if (type == SKILL)
459 {
460 if (IS_COMBAT_SKILL (subtype)) return slot_combat;
461 if (IS_RANGED_SKILL (subtype)) return slot_ranged;
462 }
463 else
464 {
465 if (slot [body_combat].info) return slot_combat;
466 if (slot [body_range ].info) return slot_ranged;
467 }
468
469 return slot_none;
470}
471
472bool
473object::change_weapon (object *ob)
474{
475 if (current_weapon == ob)
476 return true;
477
478 if (chosen_skill)
479 chosen_skill->flag [FLAG_APPLIED] = false;
480
481 current_weapon = ob;
482 chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill);
483
484 if (chosen_skill)
485 chosen_skill->flag [FLAG_APPLIED] = true;
486
487 update_stats ();
488
489 if (ob)
490 {
491 // now check wether any body locations became invalid, in which case
492 // we cannot apply the weapon at the moment.
493 for (int i = 0; i < NUM_BODY_LOCATIONS; ++i)
494 if (slot[i].used < 0)
495 {
496 current_weapon = chosen_skill = 0;
497 update_stats ();
498
499 new_draw_info_format (NDI_UNIQUE, 0, this,
500 "You try to balance your applied items all at once, but the %s is too much. "
501 "You need to unapply some items first.", &ob->name);
502 return false;
503 }
504
505 //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name);
506 }
507 else
508 ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons.");
509
510 if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL)
511 {
512 LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s",
513 &name, ob->debug_desc ());
514 return false;
515 }
516
517 return true;
451} 518}
452 519
453/* Zero the key_values on op, decrementing the shared-string 520/* Zero the key_values on op, decrementing the shared-string
454 * refcounts and freeing the links. 521 * refcounts and freeing the links.
455 */ 522 */
537 * need for monsters, but doesn't hurt to do it for everything. 604 * need for monsters, but doesn't hurt to do it for everything.
538 * by doing so, when a monster is created, it has good starting 605 * by doing so, when a monster is created, it has good starting
539 * values for the body_used info, so when items are created 606 * values for the body_used info, so when items are created
540 * for it, they can be properly equipped. 607 * for it, they can be properly equipped.
541 */ 608 */
542 memcpy (body_used, body_info, sizeof (body_used)); 609 for (int i = NUM_BODY_LOCATIONS; i--; )
610 slot[i].used = slot[i].info;
543 611
544 attachable::instantiate (); 612 attachable::instantiate ();
545} 613}
546 614
547object * 615object *
1168object * 1236object *
1169insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1237insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1170{ 1238{
1171 assert (!op->flag [FLAG_FREED]); 1239 assert (!op->flag [FLAG_FREED]);
1172 1240
1173 object *tmp, *top, *floor = NULL; 1241 object *top, *floor = NULL;
1174 1242
1175 op->remove (); 1243 op->remove ();
1176 1244
1177#if 0 1245#if 0
1178 if (!m->active != !op->active) 1246 if (!m->active != !op->active)
1194#endif 1262#endif
1195 return op; 1263 return op;
1196 } 1264 }
1197 1265
1198 if (object *more = op->more) 1266 if (object *more = op->more)
1199 {
1200 if (!insert_ob_in_map (more, m, originator, flag)) 1267 if (!insert_ob_in_map (more, m, originator, flag))
1201 {
1202 if (!op->head)
1203 LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n");
1204
1205 return 0; 1268 return 0;
1206 }
1207 }
1208 1269
1209 CLEAR_FLAG (op, FLAG_REMOVED); 1270 CLEAR_FLAG (op, FLAG_REMOVED);
1210 1271
1211 /* Ideally, the caller figures this out. However, it complicates a lot 1272 /* Ideally, the caller figures this out. However, it complicates a lot
1212 * of areas of callers (eg, anything that uses find_free_spot would now 1273 * of areas of callers (eg, anything that uses find_free_spot would now
1219 mapspace &ms = op->ms (); 1280 mapspace &ms = op->ms ();
1220 1281
1221 /* this has to be done after we translate the coordinates. 1282 /* this has to be done after we translate the coordinates.
1222 */ 1283 */
1223 if (op->nrof && !(flag & INS_NO_MERGE)) 1284 if (op->nrof && !(flag & INS_NO_MERGE))
1224 for (tmp = ms.bot; tmp; tmp = tmp->above) 1285 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1225 if (object::can_merge (op, tmp)) 1286 if (object::can_merge (op, tmp))
1226 { 1287 {
1227 op->nrof += tmp->nrof; 1288 op->nrof += tmp->nrof;
1228 tmp->destroy (); 1289 tmp->destroy ();
1229 } 1290 }
1398 * blocked() and wall() work properly), and these flags are updated by 1459 * blocked() and wall() work properly), and these flags are updated by
1399 * update_object(). 1460 * update_object().
1400 */ 1461 */
1401 1462
1402 /* if this is not the head or flag has been passed, don't check walk on status */ 1463 /* if this is not the head or flag has been passed, don't check walk on status */
1403 if (!(flag & INS_NO_WALK_ON) && !op->head) 1464 if (!(flag & INS_NO_WALK_ON) && op->head_ () == op)
1404 { 1465 {
1405 if (check_move_on (op, originator)) 1466 if (check_move_on (op, originator))
1406 return 0; 1467 return 0;
1407 1468
1408 /* If we are a multi part object, lets work our way through the check 1469 /* If we are a multi part object, lets work our way through the check
1409 * walk on's. 1470 * walk on's.
1410 */ 1471 */
1411 for (tmp = op->more; tmp != NULL; tmp = tmp->more) 1472 for (object *tmp = op->more; tmp; tmp = tmp->more)
1412 if (check_move_on (tmp, originator)) 1473 if (check_move_on (tmp, originator))
1413 return 0; 1474 return 0;
1414 } 1475 }
1415 1476
1416 return op; 1477 return op;
1597 LOG (llevError, "Trying to put object in NULL.\n%s\n", dump); 1658 LOG (llevError, "Trying to put object in NULL.\n%s\n", dump);
1598 free (dump); 1659 free (dump);
1599 return op; 1660 return op;
1600 } 1661 }
1601 1662
1602 if (where->head) 1663 if (where->head_ () != where)
1603 { 1664 {
1604 LOG (llevDebug, "Warning: Tried to insert object into wrong part of multipart object.\n"); 1665 LOG (llevError | logBacktrace, "Warning: Tried to insert object into wrong part of multipart object.\n");
1605 where = where->head; 1666 where = where->head;
1606 } 1667 }
1607 1668
1608 return where->insert (op); 1669 return where->insert (op);
1609} 1670}
1937 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) 1998 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below)
1938 { 1999 {
1939 CLEAR_FLAG (tmp, flag); 2000 CLEAR_FLAG (tmp, flag);
1940 unflag_inv (tmp, flag); 2001 unflag_inv (tmp, flag);
1941 } 2002 }
1942}
1943
1944/*
1945 * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in
1946 * all it's inventory (recursively).
1947 * If checksums are used, a player will get set_cheat called for
1948 * him/her-self and all object carried by a call to this function.
1949 */
1950void
1951set_cheat (object *op)
1952{
1953 SET_FLAG (op, FLAG_WAS_WIZ);
1954 flag_inv (op, FLAG_WAS_WIZ);
1955} 2003}
1956 2004
1957/* 2005/*
1958 * find_free_spot(object, map, x, y, start, stop) will search for 2006 * find_free_spot(object, map, x, y, start, stop) will search for
1959 * a spot at the given map and coordinates which will be able to contain 2007 * a spot at the given map and coordinates which will be able to contain
2077 object *tmp; 2125 object *tmp;
2078 maptile *mp; 2126 maptile *mp;
2079 2127
2080 MoveType blocked, move_type; 2128 MoveType blocked, move_type;
2081 2129
2082 if (exclude && exclude->head) 2130 if (exclude && exclude->head_ () != exclude)
2083 { 2131 {
2084 exclude = exclude->head; 2132 exclude = exclude->head;
2085 move_type = exclude->move_type; 2133 move_type = exclude->move_type;
2086 } 2134 }
2087 else 2135 else
2110 max = maxfree[i]; 2158 max = maxfree[i];
2111 else if (mflags & P_IS_ALIVE) 2159 else if (mflags & P_IS_ALIVE)
2112 { 2160 {
2113 for (tmp = ms.bot; tmp; tmp = tmp->above) 2161 for (tmp = ms.bot; tmp; tmp = tmp->above)
2114 if ((tmp->flag [FLAG_MONSTER] || tmp->type == PLAYER) 2162 if ((tmp->flag [FLAG_MONSTER] || tmp->type == PLAYER)
2115 && (tmp != exclude || (tmp->head && tmp->head != exclude))) 2163 && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude)))
2116 break; 2164 break;
2117 2165
2118 if (tmp) 2166 if (tmp)
2119 return freedir[i]; 2167 return freedir[i];
2120 } 2168 }
2315 * create clone from object to another 2363 * create clone from object to another
2316 */ 2364 */
2317object * 2365object *
2318object_create_clone (object *asrc) 2366object_create_clone (object *asrc)
2319{ 2367{
2320 object *dst = 0, *tmp, *src, *part, *prev, *item; 2368 object *dst = 0, *tmp, *src, *prev, *item;
2321 2369
2322 if (!asrc) 2370 if (!asrc)
2323 return 0; 2371 return 0;
2324 2372
2325 src = asrc;
2326 if (src->head)
2327 src = src->head; 2373 src = asrc->head_ ();
2328 2374
2329 prev = 0; 2375 prev = 0;
2330 for (part = src; part; part = part->more) 2376 for (object *part = src; part; part = part->more)
2331 { 2377 {
2332 tmp = part->clone (); 2378 tmp = part->clone ();
2333 tmp->x -= src->x; 2379 tmp->x -= src->x;
2334 tmp->y -= src->y; 2380 tmp->y -= src->y;
2335 2381
2583} 2629}
2584 2630
2585const char * 2631const char *
2586object::debug_desc () const 2632object::debug_desc () const
2587{ 2633{
2588 static char info[256 * 4]; 2634 static char info[3][256 * 4];
2635 static int info_idx;
2636
2589 return debug_desc (info); 2637 return debug_desc (info [++info_idx % 3]);
2590}
2591
2592const char *
2593object::debug_desc2 () const
2594{
2595 static char info[256 * 4];
2596 return debug_desc (info);
2597} 2638}
2598 2639
2599struct region * 2640struct region *
2600object::region () const 2641object::region () const
2601{ 2642{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines