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

Comparing deliantra/server/common/map.C (file contents):
Revision 1.85 by root, Wed Feb 7 23:50:01 2007 UTC vs.
Revision 1.88 by root, Fri Feb 16 19:43:40 2007 UTC

397} 397}
398 398
399/* 399/*
400 * Loads (ands parses) the objects into a given map from the specified 400 * Loads (ands parses) the objects into a given map from the specified
401 * file pointer. 401 * file pointer.
402 * mapflags is the same as we get with load_original_map
403 */ 402 */
404bool 403bool
405maptile::_load_objects (object_thawer &thawer) 404maptile::_load_objects (object_thawer &f)
406{ 405{
407 int unique; 406 for (;;)
408 object *op, *prev = NULL, *last_more = NULL, *otmp;
409
410 op = object::create ();
411 op->map = this; /* To handle buttons correctly */
412
413 while (int i = load_object (thawer, op, 0))
414 { 407 {
415 /* if the archetype for the object is null, means that we 408 coroapi::cede_every (1000); // cede once in a while
416 * got an invalid object. Don't do anything with it - the game 409
417 * or editor will not be able to do anything with it either. 410 switch (f.kw)
418 */
419 if (op->arch == NULL)
420 { 411 {
421 LOG (llevDebug, "Discarding object without arch: %s\n", op->name ? (const char *) op->name : "(null)"); 412 case KW_arch:
422 continue; 413 if (object *op = object::read (f))
423 }
424
425 switch (i)
426 { 414 {
427 case LL_NORMAL: 415 if (op->inv)
416 sum_weight (op);
417
428 insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 418 insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
419 }
429 420
430 if (op->inv) 421 continue;
431 sum_weight (op);
432 422
433 prev = op, last_more = op;
434 break;
435
436 case LL_MORE: 423 case KW_EOF:
437 insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 424 return true;
438 op->head = prev, last_more->more = op, last_more = op; 425
426 default:
427 if (!f.parse_error ("map file"))
428 return false;
439 break; 429 break;
440 } 430 }
441 431
442 op = object::create (); 432 f.next ();
443 op->map = this;
444 }
445
446 op->destroy ();
447
448#if 0
449 for (i = 0; i < width; i++)
450 for (j = 0; j < height; j++)
451 {
452 unique = 0;
453 /* check for unique items, or unique squares */
454 for (otmp = GET_MAP_OB (m, i, j); otmp; otmp = otmp->above)
455 {
456 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
457 unique = 1;
458
459 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
460 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
461 }
462 } 433 }
463#endif
464 434
465 return true; 435 return true;
466} 436}
467 437
468void 438void
486 for (object *op = ms->bot; op; op = op->above) 456 for (object *op = ms->bot; op; op = op->above)
487 op->deactivate_recursive (); 457 op->deactivate_recursive ();
488} 458}
489 459
490bool 460bool
491maptile::_save_objects (object_freezer &freezer, int flags) 461maptile::_save_objects (object_freezer &f, int flags)
492{ 462{
493 static int cede_count = 0; 463 static int cede_count = 0;
494 464
495 if (flags & IO_HEADER) 465 if (flags & IO_HEADER)
496 _save_header (freezer); 466 _save_header (f);
497 467
498 if (!spaces) 468 if (!spaces)
499 return false; 469 return false;
500 470
501 for (int i = 0; i < size (); ++i) 471 for (int i = 0; i < size (); ++i)
521 continue; 491 continue;
522 492
523 if (unique || op->flag [FLAG_UNIQUE]) 493 if (unique || op->flag [FLAG_UNIQUE])
524 { 494 {
525 if (flags & IO_UNIQUES) 495 if (flags & IO_UNIQUES)
526 save_object (freezer, op, 1); 496 op->write (f);
527 } 497 }
528 else if (flags & IO_OBJECTS) 498 else if (flags & IO_OBJECTS)
529 save_object (freezer, op, 1); 499 op->write (f);
530 } 500 }
531 } 501 }
532 502
533 return true; 503 return true;
534} 504}
535 505
536bool 506bool
537maptile::_load_objects (const char *path, bool skip_header) 507maptile::_load_objects (const char *path, bool skip_header)
538{ 508{
539 object_thawer thawer (path); 509 object_thawer f (path);
540 510
541 if (!thawer) 511 if (!f)
542 return false; 512 return false;
513
514 f.next ();
543 515
544 if (skip_header) 516 if (skip_header)
545 for (;;) 517 for (;;)
546 { 518 {
547 keyword kw = thawer.get_kv (); 519 keyword kw = f.kw;
548 520 f.skip ();
549 if (kw == KW_end) 521 if (kw == KW_end)
550 break; 522 break;
551
552 thawer.skip_kv (kw);
553 } 523 }
554 524
555 return _load_objects (thawer); 525 return _load_objects (f);
556} 526}
557 527
558bool 528bool
559maptile::_save_objects (const char *path, int flags) 529maptile::_save_objects (const char *path, int flags)
560{ 530{
803 773
804 case KW_end: 774 case KW_end:
805 return true; 775 return true;
806 776
807 default: 777 default:
808 if (!thawer.parse_error (kw, "map", 0)) 778 if (!thawer.parse_error ("map", 0))
809 return false; 779 return false;
810 break; 780 break;
811 } 781 }
812 } 782 }
813 783
1581get_rangevector (object *op1, object *op2, rv_vector * retval, int flags) 1551get_rangevector (object *op1, object *op2, rv_vector * retval, int flags)
1582{ 1552{
1583 if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y)) 1553 if (!adjacent_map (op1->map, op2->map, &retval->distance_x, &retval->distance_y))
1584 { 1554 {
1585 /* be conservative and fill in _some_ data */ 1555 /* be conservative and fill in _some_ data */
1586 retval->distance = 100000; 1556 retval->distance = 10000;
1587 retval->distance_x = 32767; 1557 retval->distance_x = 10000;
1588 retval->distance_y = 32767; 1558 retval->distance_y = 10000;
1589 retval->direction = 0; 1559 retval->direction = 0;
1590 retval->part = 0; 1560 retval->part = 0;
1591 } 1561 }
1592 else 1562 else
1593 { 1563 {
1598 1568
1599 best = op1; 1569 best = op1;
1600 /* If this is multipart, find the closest part now */ 1570 /* If this is multipart, find the closest part now */
1601 if (!(flags & 0x1) && op1->more) 1571 if (!(flags & 0x1) && op1->more)
1602 { 1572 {
1603 object *tmp;
1604 int best_distance = retval->distance_x * retval->distance_x + retval->distance_y * retval->distance_y, tmpi; 1573 int best_distance = retval->distance_x * retval->distance_x + retval->distance_y * retval->distance_y, tmpi;
1605 1574
1606 /* we just take the offset of the piece to head to figure 1575 /* we just take the offset of the piece to head to figure
1607 * distance instead of doing all that work above again 1576 * distance instead of doing all that work above again
1608 * since the distance fields we set above are positive in the 1577 * since the distance fields we set above are positive in the
1609 * same axis as is used for multipart objects, the simply arithmetic 1578 * same axis as is used for multipart objects, the simply arithmetic
1610 * below works. 1579 * below works.
1611 */ 1580 */
1612 for (tmp = op1->more; tmp != NULL; tmp = tmp->more) 1581 for (object *tmp = op1->more; tmp; tmp = tmp->more)
1613 { 1582 {
1614 tmpi = (op1->x - tmp->x + retval->distance_x) * (op1->x - tmp->x + retval->distance_x) + 1583 tmpi = (op1->x - tmp->x + retval->distance_x) * (op1->x - tmp->x + retval->distance_x) +
1615 (op1->y - tmp->y + retval->distance_y) * (op1->y - tmp->y + retval->distance_y); 1584 (op1->y - tmp->y + retval->distance_y) * (op1->y - tmp->y + retval->distance_y);
1616 if (tmpi < best_distance) 1585 if (tmpi < best_distance)
1617 { 1586 {
1626 retval->distance_y += op1->y - best->y; 1595 retval->distance_y += op1->y - best->y;
1627 } 1596 }
1628 } 1597 }
1629 1598
1630 retval->part = best; 1599 retval->part = best;
1631 retval->distance = idistance (retval->distance_x, retval->distance_y); 1600 retval->distance = upos_max (abs (retval->distance_x), abs (retval->distance_y));
1632 retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y); 1601 retval->direction = find_dir_2 (-retval->distance_x, -retval->distance_y);
1633 } 1602 }
1634} 1603}
1635 1604
1636/* this is basically the same as get_rangevector above, but instead of 1605/* this is basically the same as get_rangevector above, but instead of

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines