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.133 by root, Fri Feb 16 19:43:40 2007 UTC vs.
Revision 1.137 by root, Mon Apr 16 06:23:40 2007 UTC

454 * refcounts and freeing the links. 454 * refcounts and freeing the links.
455 */ 455 */
456static void 456static void
457free_key_values (object *op) 457free_key_values (object *op)
458{ 458{
459 for (key_value *i = op->key_values; i != 0;) 459 for (key_value *i = op->key_values; i; )
460 { 460 {
461 key_value *next = i->next; 461 key_value *next = i->next;
462 delete i; 462 delete i;
463 463
464 i = next; 464 i = next;
465 } 465 }
466 466
467 op->key_values = 0; 467 op->key_values = 0;
468} 468}
469 469
470/* 470object &
471 * copy_to first frees everything allocated by the dst object, 471object::operator =(const object &src)
472 * and then copies the contents of itself into the second
473 * object, allocating what needs to be allocated. Basically, any
474 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
475 * if the first object is freed, the pointers in the new object
476 * will point at garbage.
477 */
478void
479object::copy_to (object *dst)
480{ 472{
481 bool is_freed = QUERY_FLAG (dst, FLAG_FREED); 473 bool is_freed = flag [FLAG_FREED];
482 bool is_removed = QUERY_FLAG (dst, FLAG_REMOVED); 474 bool is_removed = flag [FLAG_REMOVED];
483 475
484 *(object_copy *)dst = *this; 476 *(object_copy *)this = src;
485 477
486 if (is_freed) 478 flag [FLAG_FREED] = is_freed;
487 SET_FLAG (dst, FLAG_FREED); 479 flag [FLAG_REMOVED] = is_removed;
488
489 if (is_removed)
490 SET_FLAG (dst, FLAG_REMOVED);
491
492 if (speed < 0)
493 dst->speed_left = speed_left - rndm ();
494 480
495 /* Copy over key_values, if any. */ 481 /* Copy over key_values, if any. */
496 if (key_values) 482 if (src.key_values)
497 { 483 {
498 key_value *tail = 0; 484 key_value *tail = 0;
499 key_value *i;
500
501 dst->key_values = 0; 485 key_values = 0;
502 486
503 for (i = key_values; i; i = i->next) 487 for (key_value *i = src.key_values; i; i = i->next)
504 { 488 {
505 key_value *new_link = new key_value; 489 key_value *new_link = new key_value;
506 490
507 new_link->next = 0; 491 new_link->next = 0;
508 new_link->key = i->key; 492 new_link->key = i->key;
509 new_link->value = i->value; 493 new_link->value = i->value;
510 494
511 /* Try and be clever here, too. */ 495 /* Try and be clever here, too. */
512 if (!dst->key_values) 496 if (!key_values)
513 { 497 {
514 dst->key_values = new_link; 498 key_values = new_link;
515 tail = new_link; 499 tail = new_link;
516 } 500 }
517 else 501 else
518 { 502 {
519 tail->next = new_link; 503 tail->next = new_link;
520 tail = new_link; 504 tail = new_link;
521 } 505 }
522 } 506 }
523 } 507 }
508}
509
510/*
511 * copy_to first frees everything allocated by the dst object,
512 * and then copies the contents of itself into the second
513 * object, allocating what needs to be allocated. Basically, any
514 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
515 * if the first object is freed, the pointers in the new object
516 * will point at garbage.
517 */
518void
519object::copy_to (object *dst)
520{
521 *dst = *this;
522
523 if (speed < 0)
524 dst->speed_left = speed_left - rndm ();
524 525
525 dst->set_speed (dst->speed); 526 dst->set_speed (dst->speed);
526} 527}
527 528
528void 529void
606 * UP_OBJ_FACE: only the objects face has changed. 607 * UP_OBJ_FACE: only the objects face has changed.
607 */ 608 */
608void 609void
609update_object (object *op, int action) 610update_object (object *op, int action)
610{ 611{
611 MoveType move_on, move_off, move_block, move_slow;
612
613 if (op == NULL) 612 if (op == NULL)
614 { 613 {
615 /* this should never happen */ 614 /* this should never happen */
616 LOG (llevDebug, "update_object() called for NULL object.\n"); 615 LOG (llevDebug, "update_object() called for NULL object.\n");
617 return; 616 return;
1291 * looks like instead of lots of conditions here. 1290 * looks like instead of lots of conditions here.
1292 * makes things faster, and effectively the same result. 1291 * makes things faster, and effectively the same result.
1293 */ 1292 */
1294 1293
1295 /* Have object 'fall below' other objects that block view. 1294 /* Have object 'fall below' other objects that block view.
1296 * Unless those objects are exits, type 66 1295 * Unless those objects are exits.
1297 * If INS_ON_TOP is used, don't do this processing 1296 * If INS_ON_TOP is used, don't do this processing
1298 * Need to find the object that in fact blocks view, otherwise 1297 * Need to find the object that in fact blocks view, otherwise
1299 * stacking is a bit odd. 1298 * stacking is a bit odd.
1300 */ 1299 */
1301 if (!(flag & INS_ON_TOP) 1300 if (!(flag & INS_ON_TOP)
1302 && ms.flags () & P_BLOCKSVIEW 1301 && ms.flags () & P_BLOCKSVIEW
1303 && (op->face && !op->face->visibility)) 1302 && (op->face && !faces [op->face].visibility))
1304 { 1303 {
1305 for (last = top; last != floor; last = last->below) 1304 for (last = top; last != floor; last = last->below)
1306 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1305 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1307 break; 1306 break;
1308 1307
1431 tmp1->x = op->x; 1430 tmp1->x = op->x;
1432 tmp1->y = op->y; 1431 tmp1->y = op->y;
1433 insert_ob_in_map (tmp1, op->map, op, 0); 1432 insert_ob_in_map (tmp1, op->map, op, 0);
1434} 1433}
1435 1434
1435// XXX: function not returning object*
1436object * 1436object *
1437object::insert_at (object *where, object *originator, int flags) 1437object::insert_at (object *where, object *originator, int flags)
1438{ 1438{
1439 where->map->insert (this, where->x, where->y, originator, flags); 1439 where->map->insert (this, where->x, where->y, originator, flags);
1440} 1440}
2414 return link->value; 2414 return link->value;
2415 2415
2416 return 0; 2416 return 0;
2417} 2417}
2418 2418
2419
2420/* 2419/*
2421 * Updates the canonical_key in op to value. 2420 * Updates the canonical_key in op to value.
2422 * 2421 *
2423 * canonical_key is a shared string (value doesn't have to be). 2422 * canonical_key is a shared string (value doesn't have to be).
2424 * 2423 *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines