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

Comparing cf.schmorp.de/server/common/map.C (file contents):
Revision 1.49 by root, Mon Dec 25 14:54:44 2006 UTC vs.
Revision 1.51 by root, Mon Dec 25 17:11:16 2006 UTC

601 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 601 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
602 * and we only save the head of multi part objects - this is needed 602 * and we only save the head of multi part objects - this is needed
603 * in order to do map tiling properly. 603 * in order to do map tiling properly.
604 */ 604 */
605void 605void
606save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) 606save_objects (maptile *m, object_freezer &fp, object_freezer &fp2, int flag)
607{ 607{
608 int i, j = 0, unique = 0; 608 int i, j = 0, unique = 0;
609 object *op; 609 object *op;
610 610
611 /* first pass - save one-part objects */ 611 /* first pass - save one-part objects */
612 for (i = 0; i < m->width; i++) 612 for (i = 0; i < m->width; i++)
613 for (j = 0; j < m->height; j++) 613 for (j = 0; j < m->height; j++)
614 { 614 {
615 unique = 0; 615 unique = 0;
616
616 for (op = m->at (i, j).bot; op; op = op->above) 617 for (op = m->at (i, j).bot; op; op = op->above)
617 { 618 {
618 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE]) 619 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
619 unique = 1; 620 unique = 1;
620 621
621 if (op->type == PLAYER) 622 if (op->type == PLAYER)
622 continue; 623 continue;
623 624
624 if (op->head || op->owner) 625 if (op->head || op->owner)
625 continue; 626 continue;
626 627
627 if (unique || op->flag [FLAG_UNIQUE]) 628 if (unique || op->flag [FLAG_UNIQUE])
628 save_object (fp2, op, 3); 629 save_object (fp2, op, 1);
629 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) 630 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID])))
630 save_object (fp, op, 3); 631 save_object (fp, op, 1);
631 } 632 }
632 } 633 }
633} 634}
634 635
635maptile::maptile () 636maptile::maptile ()
1289 return; 1290 return;
1290 1291
1291 m->in_memory = MAP_LOADING; 1292 m->in_memory = MAP_LOADING;
1292 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1293 if (m->tmpname == NULL) /* if we have loaded unique items from */
1293 delete_unique_items (m); /* original map before, don't duplicate them */ 1294 delete_unique_items (m); /* original map before, don't duplicate them */
1295
1294 load_objects (m, thawer, 0); 1296 load_objects (m, thawer, 0);
1295 1297
1296 m->in_memory = MAP_IN_MEMORY; 1298 m->in_memory = MAP_IN_MEMORY;
1297} 1299}
1298
1299 1300
1300/* 1301/*
1301 * Saves a map to file. If flag is set, it is saved into the same 1302 * Saves a map to file. If flag is set, it is saved into the same
1302 * file it was (originally) loaded from. Otherwise a temporary 1303 * file it was (originally) loaded from. Otherwise a temporary
1303 * filename will be genarated, and the file will be stored there. 1304 * filename will be genarated, and the file will be stored there.
1304 * The temporary filename will be stored in the maptileure. 1305 * The temporary filename will be stored in the maptileure.
1305 * If the map is unique, we also save to the filename in the map 1306 * If the map is unique, we also save to the filename in the map
1306 * (this should have been updated when first loaded) 1307 * (this should have been updated when first loaded)
1307 */ 1308 */
1308
1309int 1309int
1310new_save_map (maptile *m, int flag) 1310new_save_map (maptile *m, int flag)
1311{ 1311{
1312 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; 1312 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1313 int i; 1313 int i;
1477 * don't free tmpname - our caller is left to do that 1477 * don't free tmpname - our caller is left to do that
1478 */ 1478 */
1479void 1479void
1480free_map (maptile *m, int flag) 1480free_map (maptile *m, int flag)
1481{ 1481{
1482 if (m->in_memory != MAP_IN_MEMORY) 1482 if (!m->in_memory) //TODO: makes no sense to me?
1483 return; 1483 return;
1484 1484
1485 m->in_memory = MAP_SAVING; 1485 m->in_memory = MAP_SAVING;
1486 1486
1487 // TODO: use new/delete 1487 // TODO: use new/delete
1488#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1489 1488
1490 if (flag && m->spaces) 1489 if (flag && m->spaces)
1491 free_all_objects (m); 1490 free_all_objects (m);
1492 if (m->name)
1493 FREE_AND_CLEAR (m->name);
1494 if (m->spaces)
1495 FREE_AND_CLEAR (m->spaces);
1496 if (m->msg)
1497 FREE_AND_CLEAR (m->msg);
1498 if (m->maplore)
1499 FREE_AND_CLEAR (m->maplore);
1500 1491
1501 delete [] m->shopitems; 1492 free (m->name), m->name = 0;
1502 m->shopitems = 0; 1493 free (m->spaces), m->spaces = 0;
1503 1494 free (m->msg), m->msg = 0;
1504 if (m->shoprace) 1495 free (m->maplore), m->maplore = 0;
1505 FREE_AND_CLEAR (m->shoprace); 1496 free (m->shoprace), m->shoprace = 0;
1497 delete [] m->shopitems, m->shopitems = 0;
1506 1498
1507 if (m->buttons) 1499 if (m->buttons)
1508 free_objectlinkpt (m->buttons); 1500 free_objectlinkpt (m->buttons), m->buttons = 0;
1509
1510 m->buttons = NULL;
1511 1501
1512 for (int i = 0; i < 4; i++) 1502 for (int i = 0; i < 4; i++)
1513 { 1503 {
1514 if (m->tile_path[i]) 1504 if (m->tile_path[i])
1515 FREE_AND_CLEAR (m->tile_path[i]); 1505 free (m->tile_path[i]), m->tile_path[i] = 0;
1516 1506
1517 m->tile_map[i] = 0; 1507 m->tile_map[i] = 0;
1518 } 1508 }
1519 1509
1520 m->in_memory = MAP_SWAPPED; 1510 m->in_memory = MAP_SWAPPED;
1521
1522#undef FREE_AND_CLEAR
1523} 1511}
1524 1512
1525maptile::~maptile () 1513maptile::~maptile ()
1526{ 1514{
1527 free_map (this, 1); 1515 free_map (this, 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines