comparison mkloc.c @ 1775:db7fdbc8f81b

Modernification cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 28 Oct 2017 04:07:28 +0300
parents 72adabd8e746
children 77d6e13fb95e
comparison
equal deleted inserted replaced
1774:c7ee1c1e5bdf 1775:db7fdbc8f81b
272 272
273 /* Adjust location label coordinates for the ASCII-CTRL map 273 /* Adjust location label coordinates for the ASCII-CTRL map
274 */ 274 */
275 void adjustLocInfoCoords(MapBlock *map, MapLocations *l) 275 void adjustLocInfoCoords(MapBlock *map, MapLocations *l)
276 { 276 {
277 int i; 277 for (int i = 0; i < l->n; i++)
278
279 for (i = 0; i < l->n; i++)
280 { 278 {
281 int y, x0, x1, len; 279 int y, x0, x1, len;
282 LocMarker *tmp = l->locations[i]; 280 LocMarker *tmp = l->locations[i];
283 281
284 len = strlen(tmp->names[0].name); 282 len = strlen(tmp->names[0].name);
351 /* Scan given map and update location list with new locations, 349 /* Scan given map and update location list with new locations,
352 * if any are found. 350 * if any are found.
353 */ 351 */
354 void updateLocations(MapBlock *worldMap, MapLocations *worldLoc) 352 void updateLocations(MapBlock *worldMap, MapLocations *worldLoc)
355 { 353 {
356 int x, y, n, numNewLoc = 0, numInvLoc = 0, numNoMarker = 0; 354 int n, numNewLoc = 0, numInvLoc = 0, numNoMarker = 0;
357 unsigned char *dp;
358 LocMarker *tmpl; 355 LocMarker *tmpl;
359 356
360 THMSG(2, "Updating location information ..\n"); 357 THMSG(2, "Updating location information ..\n");
361 358
362 // Find new, unknown locations 359 // Find new, unknown locations
363 for (y = 0; y < worldMap->height; y++) 360 for (int y = 0; y < worldMap->height; y++)
364 { 361 {
365 dp = worldMap->data + (worldMap->scansize * y); 362 unsigned char *dp = worldMap->data + (worldMap->scansize * y);
366 363
367 for (x = 0; x < worldMap->width; x++) 364 for (int x = 0; x < worldMap->width; x++)
368 { 365 {
369 if (strchr(optLocMarkers, dp[x])) 366 if (strchr(optLocMarkers, dp[x]))
370 { 367 {
371 LocName tmpNames[LOC_MAX_NAMES]; 368 LocName tmpNames[LOC_MAX_NAMES];
372 char tmpDesc[512]; 369 char tmpDesc[512];
456 453
457 /* Sort locations by name 454 /* Sort locations by name
458 */ 455 */
459 void maplocSort(MapLocations *l) 456 void maplocSort(MapLocations *l)
460 { 457 {
461 int i; 458 for (int i = 0; i < l->n; i++)
462
463 for (i = 0; i < l->n; i++)
464 { 459 {
465 LocMarker *loc = l->locations[i]; 460 LocMarker *loc = l->locations[i];
466 loc->val = 2; 461 loc->val = 2;
467 462
468 switch (loc->flags & LOCF_M_MASK) 463 switch (loc->flags & LOCF_M_MASK)
469 { 464 {
470 case LOCF_M_CITY: loc->val = 1; break; 465 case LOCF_M_CITY: loc->val = 1; break;
471 case LOCF_M_PCITY: loc->val = 10; break; 466 case LOCF_M_PCITY: loc->val = 10; break;
472 default: 467 default:
473 switch (loc->flags & LOCF_T_MASK) 468 switch (loc->flags & LOCF_T_MASK)
474 { 469 {
475 case LOCF_T_GUILD: loc->val = 3; break; 470 case LOCF_T_GUILD: loc->val = 3; break;
476 case LOCF_T_TRAINER: loc->val = 4; break; 471 case LOCF_T_TRAINER: loc->val = 4; break;
477 case LOCF_T_SHRINE: loc->val = 5; break; 472 case LOCF_T_SHRINE: loc->val = 5; break;
478 case LOCF_T_SS: loc->val = 6; break; 473 case LOCF_T_SS: loc->val = 6; break;
479 case LOCF_T_MONSTER: loc->val = 7; break; 474 case LOCF_T_MONSTER: loc->val = 7; break;
480 case LOCF_T_FORT: loc->val = 100; break; 475 case LOCF_T_FORT: loc->val = 100; break;
481 } 476 }
482 } 477 }
483 } 478 }
484 479
485 qsort(l->locations, l->n, sizeof(LocMarker *), maplocCompare); 480 qsort(l->locations, l->n, sizeof(LocMarker *), maplocCompare);
486 } 481 }
489 /* Output the map with labels and location markers, etc. in 484 /* Output the map with labels and location markers, etc. in
490 * special ASCII-CTRL format understood by colormap utility. 485 * special ASCII-CTRL format understood by colormap utility.
491 */ 486 */
492 void outputMapCTRL(FILE *outFile, MapBlock *map, MapLocations *l) 487 void outputMapCTRL(FILE *outFile, MapBlock *map, MapLocations *l)
493 { 488 {
494 unsigned char *dp; 489 for (int y = 0; y < map->height; y++)
495 int x, y, n; 490 {
496 491 unsigned char *dp = map->data + (map->scansize * y);
497 for (y = 0; y < map->height; y++) 492
498 { 493 for (int x = 0; x < map->width; x++)
499 dp = map->data + (map->scansize * y); 494 {
500 495 int n;
501 for (x = 0; x < map->width; x++)
502 {
503 if ((n = locFindByCoords(l, x, y, TRUE)) >= 0) 496 if ((n = locFindByCoords(l, x, y, TRUE)) >= 0)
504 { 497 {
505 LocMarker *tmp = l->locations[n]; 498 LocMarker *tmp = l->locations[n];
506 char chm = dp[x]; 499 char chm = dp[x];
507 500
573 else 566 else
574 fputc(dp[x], outFile); 567 fputc(dp[x], outFile);
575 } 568 }
576 else 569 else
577 fputc(dp[x], outFile); 570 fputc(dp[x], outFile);
578 } else 571 }
572 else
579 fputc(dp[x], outFile); 573 fputc(dp[x], outFile);
580 } 574 }
581 575
582 fprintf(outFile, "\n"); 576 fprintf(outFile, "\n");
583 } 577 }
586 580
587 /* Print out location list as HTML option list. 581 /* Print out location list as HTML option list.
588 */ 582 */
589 void outputMapLocHTML(FILE *outFile, MapLocations *l) 583 void outputMapLocHTML(FILE *outFile, MapLocations *l)
590 { 584 {
591 int i;
592 assert(l != NULL); 585 assert(l != NULL);
593 586
594 fprintf(outFile, "<option value=\"\">-</option>\n"); 587 fprintf(outFile, "<option value=\"\">-</option>\n");
595 588
596 for (i = 0; i < l->n; i++) 589 for (int i = 0; i < l->n; i++)
597 { 590 {
598 LocMarker *tmp = l->locations[i]; 591 LocMarker *tmp = l->locations[i];
599 592
600 if (tmp->flags & LOCF_INVIS) 593 if (tmp->flags & LOCF_INVIS)
601 continue; 594 continue;
624 } 617 }
625 618
626 619
627 void outputLocationFile(FILE *outFile, MapLocations *l) 620 void outputLocationFile(FILE *outFile, MapLocations *l)
628 { 621 {
629 int i, n;
630
631 // Output header 622 // Output header
632 fprintf(outFile, 623 fprintf(outFile,
633 "# " LOC_MAGIC " (version %d.%d)\n", 624 "# " LOC_MAGIC " (version %d.%d)\n",
634 LOC_VERSION_MAJOR, LOC_VERSION_MINOR 625 LOC_VERSION_MAJOR, LOC_VERSION_MINOR
635 ); 626 );
638 "# Refer to README.loc for more information.\n" 629 "# Refer to README.loc for more information.\n"
639 "#\n" 630 "#\n"
640 ); 631 );
641 632
642 // Output each location entry 633 // Output each location entry
643 for (i = 0; i < l->n; i++) 634 for (int i = 0; i < l->n; i++)
644 { 635 {
645 LocMarker *tmp = l->locations[i]; 636 LocMarker *tmp = l->locations[i];
646 637
647 // Add comment in few cases 638 // Add comment in few cases
648 if (tmp->flags & LOCF_Q_MASK) 639 if (tmp->flags & LOCF_Q_MASK)
691 if (tmp->flags & LOCF_INVIS) 682 if (tmp->flags & LOCF_INVIS)
692 fputc('-', outFile); 683 fputc('-', outFile);
693 684
694 fprintf(outFile, "\t;"); 685 fprintf(outFile, "\t;");
695 printLocNameEsc(outFile, &tmp->names[0]); 686 printLocNameEsc(outFile, &tmp->names[0]);
696 for (n = 1; n < tmp->nnames; n++) 687 for (int n = 1; n < tmp->nnames; n++)
697 { 688 {
698 fprintf(outFile, "|"); 689 fprintf(outFile, "|");
699 printLocNameEsc(outFile, &tmp->names[n]); 690 printLocNameEsc(outFile, &tmp->names[n]);
700 } 691 }
701 fprintf(outFile, ";"); 692 fprintf(outFile, ";");
702 693
703 if (tmp->ncoders > 0) 694 if (tmp->ncoders > 0)
704 { 695 {
705 printLocNameEsc(outFile, &tmp->coders[0]); 696 printLocNameEsc(outFile, &tmp->coders[0]);
706 for (n = 1; n < tmp->ncoders; n++) 697 for (int n = 1; n < tmp->ncoders; n++)
707 { 698 {
708 fprintf(outFile, ","); 699 fprintf(outFile, ",");
709 printLocNameEsc(outFile, &tmp->coders[n]); 700 printLocNameEsc(outFile, &tmp->coders[n]);
710 } 701 }
711 } 702 }
736 /* Generate a shell-script for running ImageMagick to add 727 /* Generate a shell-script for running ImageMagick to add
737 * location and label information to an map image. 728 * location and label information to an map image.
738 */ 729 */
739 void outputMagickScript(FILE *outFile, MapLocations *l) 730 void outputMagickScript(FILE *outFile, MapLocations *l)
740 { 731 {
741 int i, numCity, numLoc, numTotal; 732 int numCity, numLoc, numTotal;
742 733
743 // Output script start 734 // Output script start
744 fprintf(outFile, 735 fprintf(outFile,
745 "#!/bin/sh\n" 736 "#!/bin/sh\n"
746 "convert \"$1\" @OPTS_START@ \\\n"); 737 "convert \"$1\" @OPTS_START@ \\\n");
747 738
748 numCity = numLoc = numTotal = 0; 739 numCity = numLoc = numTotal = 0;
749 740
750 // Output instructions for each visible location 741 // Output instructions for each visible location
751 for (i = 0; i < l->n; i++) 742 for (int i = 0; i < l->n; i++)
752 { 743 {
753 LocMarker *tmp = l->locations[i]; 744 LocMarker *tmp = l->locations[i];
754 int x, y, leftMove; 745 int x, y, leftMove;
755 char *cs; 746 char *cs;
756 747
853 * is not performed, caller must take care of it via iconv or similar. 844 * is not performed, caller must take care of it via iconv or similar.
854 */ 845 */
855 static char *getQuestLink(const char *name, const char *desc) 846 static char *getQuestLink(const char *name, const char *desc)
856 { 847 {
857 char *str, *tmp = th_strdup(name); 848 char *str, *tmp = th_strdup(name);
858 size_t i; 849
859 for (i = 0; i < strlen(tmp); i++) 850 for (size_t i = 0; i < strlen(tmp); i++)
860 tmp[i] = th_isspace(tmp[i]) ? '+' : th_tolower(tmp[i]); 851 tmp[i] = th_isspace(tmp[i]) ? '+' : th_tolower(tmp[i]);
861 852
862 str = th_strdup_printf("<a target=\"_blank\" href=\"http://www.bat.org/help/quests?str=%s\">%s</a>", tmp, desc); 853 str = th_strdup_printf("<a target=\"_blank\" href=\"http://www.bat.org/help/quests?str=%s\">%s</a>", tmp, desc);
863 th_free(tmp); 854 th_free(tmp);
864 return str; 855 return str;
883 } 874 }
884 875
885 void outputGMapsHTML(FILE *outFile, LocMarker *tmp, 876 void outputGMapsHTML(FILE *outFile, LocMarker *tmp,
886 int (*fpr)(FILE *, const char *fmt, ...), int (*fps)(const char *, FILE *)) 877 int (*fpr)(FILE *, const char *fmt, ...), int (*fps)(const char *, FILE *))
887 { 878 {
888 int n;
889
890 if (tmp->uri != NULL) 879 if (tmp->uri != NULL)
891 { 880 {
892 fpr(outFile, "<b><a target=\"_blank\" href=\"%s\">", tmp->uri); 881 fpr(outFile, "<b><a target=\"_blank\" href=\"%s\">", tmp->uri);
893 locPrintType(outFile, tmp, FALSE, fps, TRUE); 882 locPrintType(outFile, tmp, FALSE, fps, TRUE);
894 fpr(outFile, "</a></b><br>"); 883 fpr(outFile, "</a></b><br>");
902 891
903 // Alternative names, if any 892 // Alternative names, if any
904 if (tmp->nnames > 1) 893 if (tmp->nnames > 1)
905 { 894 {
906 fpr(outFile, "Also known as <i>"); 895 fpr(outFile, "Also known as <i>");
907 for (n = 1; n < tmp->nnames; n++) 896 for (int n = 1; n < tmp->nnames; n++)
908 { 897 {
909 fps(tmp->names[n].name, outFile); 898 fps(tmp->names[n].name, outFile);
910 if (tmp->names[n].flags & NAME_ORIG) 899 if (tmp->names[n].flags & NAME_ORIG)
911 fprintf(outFile, " (*)"); 900 fprintf(outFile, " (*)");
912 if (n < tmp->nnames - 1) 901 if (n < tmp->nnames - 1)
926 if (tmp->ncoders > 0) 915 if (tmp->ncoders > 0)
927 { 916 {
928 if (tmp->flags & LOCF_M_PCITY) 917 if (tmp->flags & LOCF_M_PCITY)
929 { 918 {
930 fprintf(outFile, "Societies: "); 919 fprintf(outFile, "Societies: ");
931 for (n = 0; n < tmp->ncoders; n++) 920 for (int n = 0; n < tmp->ncoders; n++)
932 { 921 {
933 fps(tmp->coders[n].name, outFile); 922 fps(tmp->coders[n].name, outFile);
934 if (n < tmp->ncoders - 1) 923 if (n < tmp->ncoders - 1)
935 fprintf(outFile, ", "); 924 fprintf(outFile, ", ");
936 } 925 }
937 } 926 }
938 else 927 else
939 { 928 {
940 fprintf(outFile, "Coders: "); 929 fprintf(outFile, "Coders: ");
941 for (n = 0; n < tmp->ncoders; n++) 930 for (int n = 0; n < tmp->ncoders; n++)
942 { 931 {
943 char *info = "", *sinfo = ""; 932 char *info = "", *sinfo = "";
944 switch (tmp->coders[n].flags) 933 switch (tmp->coders[n].flags)
945 { 934 {
946 case NAME_ORIG: info = " (O)"; sinfo = "Original coder"; break; 935 case NAME_ORIG: info = " (O)"; sinfo = "Original coder"; break;
993 } 982 }
994 983
995 984
996 void outputGMapsXML(FILE *outFile, MapLocations *l) 985 void outputGMapsXML(FILE *outFile, MapLocations *l)
997 { 986 {
998 int i;
999
1000 fprintf(outFile, 987 fprintf(outFile,
1001 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 988 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1002 "<markers>\n"); 989 "<markers>\n");
1003 990
1004 // Output each location entry 991 // Output each location entry
1005 for (i = 0; i < l->n; i++) 992 for (int i = 0; i < l->n; i++)
1006 { 993 {
1007 LocMarker *tmp = l->locations[i]; 994 LocMarker *tmp = l->locations[i];
1008 995
1009 // Skip disabled / invisible locations 996 // Skip disabled / invisible locations
1010 if (tmp->flags & (LOCF_INVIS | LOCF_INVALID)) continue; 997 if (tmp->flags & (LOCF_INVIS | LOCF_INVALID)) continue;
1040 } 1027 }
1041 1028
1042 1029
1043 void outputGMapsJSON(FILE *outFile, MapLocations *l) 1030 void outputGMapsJSON(FILE *outFile, MapLocations *l)
1044 { 1031 {
1045 int i;
1046
1047 fprintf(outFile, "[\n"); 1032 fprintf(outFile, "[\n");
1048 1033
1049 // Output each location entry 1034 // Output each location entry
1050 for (i = 0; i < l->n; i++) 1035 for (int i = 0; i < l->n; i++)
1051 { 1036 {
1052 LocMarker *tmp = l->locations[i]; 1037 LocMarker *tmp = l->locations[i];
1053 1038
1054 // Skip disabled / invisible locations 1039 // Skip disabled / invisible locations
1055 if (tmp->flags & (LOCF_INVIS | LOCF_INVALID)) continue; 1040 if (tmp->flags & (LOCF_INVIS | LOCF_INVALID)) continue;