Mercurial > hg > batmud > maputils
comparison mkspecial.c @ 1770:cc59f80b0e78
Various cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 27 Oct 2017 04:35:51 +0300 |
parents | f5d432ccc9d6 |
children | 72adabd8e746 |
comparison
equal
deleted
inserted
replaced
1769:57276229a8c8 | 1770:cc59f80b0e78 |
---|---|
206 | 206 |
207 c1 = match->data[(y * match->scansize) + x]; | 207 c1 = match->data[(y * match->scansize) + x]; |
208 | 208 |
209 if (c1 == 0 || c2 == 0) | 209 if (c1 == 0 || c2 == 0) |
210 { | 210 { |
211 /* Both empty ... */ | 211 // Both empty ... |
212 } else | 212 } else |
213 if (c1 != 0 && c1 == c2) | 213 if (c1 != 0 && c1 == c2) |
214 { | 214 { |
215 /* Exact match, increase % */ | 215 // Exact match, increase % |
216 n++; | 216 n++; |
217 } else | 217 } else |
218 if (hardDrop) | 218 if (hardDrop) |
219 { | 219 { |
220 /* Mismatch, return failure */ | 220 // Mismatch, return failure |
221 return -1; | 221 return -1; |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 if (k > 0) | 225 if (k > 0) |
301 { | 301 { |
302 THERR("Could not get location coordinates:\n'%s'\n", s); | 302 THERR("Could not get location coordinates:\n'%s'\n", s); |
303 return NULL; | 303 return NULL; |
304 } | 304 } |
305 | 305 |
306 /* Check for discardable lines */ | 306 // Check for discardable lines |
307 if (!getLineData(inFile, s, sizeof(s))) | 307 if (!getLineData(inFile, s, sizeof(s))) |
308 return NULL; | 308 return NULL; |
309 | 309 |
310 if (!th_strcasecmp(s, "You glance around.")) | 310 if (!th_strcasecmp(s, "You glance around.")) |
311 { | 311 { |
312 if (!getLineData(inFile, s, sizeof(s))) | 312 if (!getLineData(inFile, s, sizeof(s))) |
313 return NULL; | 313 return NULL; |
314 } | 314 } |
315 | 315 |
316 /* New 'map' output in city maps has an empty line before the data, ignore it */ | 316 // New 'map' output in city maps has an empty line before the data, ignore it |
317 if ((tmpW = getLineWidth(s, sizeof(s))) <= 9) | 317 if ((tmpW = getLineWidth(s, sizeof(s))) <= 9) |
318 { | 318 { |
319 if (!getLineData(inFile, s, sizeof(s))) | 319 if (!getLineData(inFile, s, sizeof(s))) |
320 return NULL; | 320 return NULL; |
321 tmpW = getLineWidth(s, sizeof(s)); | 321 tmpW = getLineWidth(s, sizeof(s)); |
399 MapBlock **mapBlocks = NULL; | 399 MapBlock **mapBlocks = NULL; |
400 | 400 |
401 th_init("mkspecial", "Yet Another ASCII Map Auto-Stitcher", "0.5", NULL, NULL); | 401 th_init("mkspecial", "Yet Another ASCII Map Auto-Stitcher", "0.5", NULL, NULL); |
402 th_verbosityLevel = 1; | 402 th_verbosityLevel = 1; |
403 | 403 |
404 /* Parse arguments */ | 404 // Parse arguments |
405 if (!th_args_process(argc, argv, optList, optListN, | 405 if (!th_args_process(argc, argv, optList, optListN, |
406 argHandleOpt, argHandleFile, OPTH_BAILOUT)) | 406 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
407 exit(1); | 407 exit(1); |
408 | 408 |
409 if (nsrcFiles < 1) | 409 if (nsrcFiles < 1) |
410 { | 410 { |
411 THERR("Nothing to do. (try --help)\n"); | 411 THERR("Nothing to do. (try --help)\n"); |
412 exit(0); | 412 exit(0); |
413 } | 413 } |
414 | 414 |
415 /* Read initial map */ | 415 // Read initial map |
416 if (optInitialMap) | 416 if (optInitialMap) |
417 { | 417 { |
418 THMSG(1, "Reading initial map '%s'\n", optInitialMap); | 418 THMSG(1, "Reading initial map '%s'\n", optInitialMap); |
419 initialMap = mapBlockParseFile(optInitialMap, FALSE); | 419 initialMap = mapBlockParseFile(optInitialMap, FALSE); |
420 if (initialMap) | 420 if (initialMap) |
519 if (all blocks placed) break | 519 if (all blocks placed) break |
520 } | 520 } |
521 */ | 521 */ |
522 | 522 |
523 | 523 |
524 /* If initial map is available, find a match and determine coords */ | 524 // If initial map is available, find a match and determine coords |
525 if (initialMap) | 525 if (initialMap) |
526 { | 526 { |
527 initialMap->x = optInitialX; | 527 initialMap->x = optInitialX; |
528 initialMap->y = optInitialY; | 528 initialMap->y = optInitialY; |
529 } | 529 } |
530 | 530 |
531 /* Clear marks */ | 531 // Clear marks |
532 for (i = 0; i < nmapBlocks; i++) | 532 for (i = 0; i < nmapBlocks; i++) |
533 mapBlocks[i]->mark = FALSE; | 533 mapBlocks[i]->mark = FALSE; |
534 | 534 |
535 | 535 |
536 /* Get world dimensions */ | 536 // Get world dimensions |
537 worldX0 = worldY0 = worldX1 = worldY1 = 0; | 537 worldX0 = worldY0 = worldX1 = worldY1 = 0; |
538 for (i = 0; i < nmapBlocks; i++) | 538 for (i = 0; i < nmapBlocks; i++) |
539 findWorldSize(mapBlocks[i], &worldX0, &worldY0, &worldX1, &worldY1); | 539 findWorldSize(mapBlocks[i], &worldX0, &worldY0, &worldX1, &worldY1); |
540 | 540 |
541 if (initialMap) | 541 if (initialMap) |
542 findWorldSize(initialMap, &worldX0, &worldY0, &worldX1, &worldY1); | 542 findWorldSize(initialMap, &worldX0, &worldY0, &worldX1, &worldY1); |
543 | 543 |
544 /* Compute offsets, allocate world map */ | 544 // Compute offsets, allocate world map |
545 /* FIXME: check dimensions */ | 545 // FIXME: check dimensions |
546 offsetX = -worldX0; | 546 offsetX = -worldX0; |
547 offsetY = -worldY0; | 547 offsetY = -worldY0; |
548 | 548 |
549 if ((worldMap = mapBlockAlloc((worldX1 - worldX0 + 1), (worldY1 - worldY0 + 1))) == NULL) | 549 if ((worldMap = mapBlockAlloc((worldX1 - worldX0 + 1), (worldY1 - worldY0 + 1))) == NULL) |
550 { | 550 { |
551 THERR("Error allocating world map!\n"); | 551 THERR("Error allocating world map!\n"); |
552 exit(4); | 552 exit(4); |
553 } | 553 } |
554 | 554 |
555 /* Place optional initial map */ | 555 // Place optional initial map |
556 if (initialMap) | 556 if (initialMap) |
557 { | 557 { |
558 if (mapBlockPut(&worldMap, initialMap, offsetX+initialMap->x, offsetY+initialMap->y) < 0) | 558 if (mapBlockPut(&worldMap, initialMap, offsetX+initialMap->x, offsetY+initialMap->y) < 0) |
559 { | 559 { |
560 THERR("Initial map mapBlockPut() failed!\n"); | 560 THERR("Initial map mapBlockPut() failed!\n"); |
567 if (mapBlockPut(&worldMap, mapBlocks[i], offsetX+mapBlocks[i]->x, offsetY+mapBlocks[i]->y) < 0) | 567 if (mapBlockPut(&worldMap, mapBlocks[i], offsetX+mapBlocks[i]->x, offsetY+mapBlocks[i]->y) < 0) |
568 { | 568 { |
569 THERR("Initial map mapBlockPut() failed!\n"); | 569 THERR("Initial map mapBlockPut() failed!\n"); |
570 exit(9); | 570 exit(9); |
571 } | 571 } |
572 mapBlocks[i]->mark = TRUE; | |
572 } | 573 } |
573 | 574 |
574 THMSG(1, "Initialized world map of (%d x %d), offset (%d, %d)\n", | 575 THMSG(1, "Initialized world map of (%d x %d), offset (%d, %d)\n", |
575 worldMap->width, worldMap->height, offsetX, offsetY); | 576 worldMap->width, worldMap->height, offsetX, offsetY); |
576 | 577 |
577 | 578 |
578 /* Start placing blocks */ | 579 // Start placing blocks |
579 currRounds = 0; | 580 currRounds = 0; |
580 isOK = FALSE; | 581 isOK = FALSE; |
581 while ((currRounds++ < optRounds) && !isOK) | 582 while (currRounds++ < optRounds && !isOK) |
582 { | 583 { |
583 int usedBlocks; | 584 int usedBlocks; |
584 | 585 |
585 /* Get number of used blocks */ | 586 // Get number of used blocks |
586 for (usedBlocks = i = 0; i < nmapBlocks; i++) | 587 for (usedBlocks = i = 0; i < nmapBlocks; i++) |
587 if (mapBlocks[i]->mark) usedBlocks++; | 588 if (mapBlocks[i]->mark) usedBlocks++; |
588 | 589 |
589 /* Print out status information */ | 590 // Print out status information |
590 THPRINT(2, "#%d [%d/%d]: ", | 591 THPRINT(2, "#%d [%d/%d]: ", |
591 currRounds, usedBlocks, nmapBlocks); | 592 currRounds, usedBlocks, nmapBlocks); |
592 | 593 |
593 /* Place and match blocks */ | 594 // Place and match blocks |
594 isOK = TRUE; | 595 isOK = TRUE; |
595 currBlocks = 0; | 596 currBlocks = 0; |
596 for (i = 0; i < nmapBlocks && currBlocks < optReset; i++) | 597 for (i = 0; i < nmapBlocks && currBlocks < optReset; i++) |
597 { | 598 { |
598 MapBlock *tmp = mapBlocks[i]; | 599 MapBlock *tmp = mapBlocks[i]; |
599 | 600 |
600 if (!tmp->mark) | 601 if (!tmp->mark) |
601 { | 602 { |
602 int qx = offsetX + tmp->x, | 603 int qx = offsetX + tmp->x, |
603 qy = offsetY + tmp->y; | 604 qy = offsetY + tmp->y; |
604 | 605 |
605 isOK = FALSE; | 606 isOK = FALSE; |
606 | 607 |
607 if (matchBlock(worldMap, tmp, qx, qy, optHardDrop) >= optMatch) | 608 if (matchBlock(worldMap, tmp, qx, qy, optHardDrop) >= optMatch) |
610 { | 611 { |
611 THERR("mapBlockPut(%d, %d, %d) failed!\n", | 612 THERR("mapBlockPut(%d, %d, %d) failed!\n", |
612 offsetX, offsetY, i); | 613 offsetX, offsetY, i); |
613 exit(9); | 614 exit(9); |
614 } | 615 } |
616 tmp->mark = TRUE; | |
615 | 617 |
616 currBlocks++; | 618 currBlocks++; |
617 THPRINT(2, "X"); | 619 THPRINT(2, "X"); |
618 } | 620 } |
619 else | 621 else |
620 { | 622 { |
621 THPRINT(2, "."); | 623 THPRINT(2, "."); |
622 | 624 |
623 #if 0 | 625 #if 0 |
624 /* Debug unmatching blocks */ | 626 // Debug unmatching blocks |
625 char mysti[512]; | 627 char mysti[512]; |
626 snprintf(mysti, sizeof(mysti), | 628 snprintf(mysti, sizeof(mysti), |
627 "[%d]: %d,%d (%d,%d)", | 629 "[%d]: %d,%d (%d,%d)", |
628 i, qx, qy, tmp->x, tmp->y); | 630 i, qx, qy, tmp->x, tmp->y); |
629 fprintf(stderr, "\n--- %.30s ---\n", mysti); | 631 fprintf(stderr, "\n--- %.30s ---\n", mysti); |
659 | 661 |
660 mapBlockPrint(tmpFile, worldMap); | 662 mapBlockPrint(tmpFile, worldMap); |
661 | 663 |
662 fclose(tmpFile); | 664 fclose(tmpFile); |
663 | 665 |
664 /* Compute number of unused blocks */ | 666 // Compute number of unused blocks |
665 for (unusedBlocks = i = 0; i < nmapBlocks; i++) | 667 for (unusedBlocks = i = 0; i < nmapBlocks; i++) |
666 if (!mapBlocks[i]->mark) | 668 if (!mapBlocks[i]->mark) |
669 { | |
670 if (optDumpRejected) | |
667 { | 671 { |
668 if (optDumpRejected) | 672 fprintf(stderr, "\n#%d: %d,%d (%d,%d)\n", |
669 { | 673 i, mapBlocks[i]->x, mapBlocks[i]->y, |
670 fprintf(stderr, "\n#%d: %d,%d (%d,%d)\n", | 674 mapBlocks[i]->x + offsetX, |
671 i, mapBlocks[i]->x, mapBlocks[i]->y, | 675 mapBlocks[i]->y + offsetY); |
672 mapBlocks[i]->x + offsetX, mapBlocks[i]->y + offsetY); | 676 |
673 | 677 mapBlockPrint(stderr, mapBlocks[i]); |
674 mapBlockPrint(stderr, mapBlocks[i]); | |
675 } | |
676 unusedBlocks++; | |
677 } | 678 } |
679 unusedBlocks++; | |
680 } | |
678 | 681 |
679 THMSG(1, "%d mapblocks unused/discarded\n", unusedBlocks); | 682 THMSG(1, "%d mapblocks unused/discarded\n", unusedBlocks); |
680 } | 683 } |
681 else | 684 else |
682 { | 685 { |