415{
417
419 return false;
420
422 if (!cells)
423 {
424 printf("Can't find cells in '%s'\n", inputPath.c_str());
425 return false;
426 }
427
431
433
434
439
440
444
445
446
447
448 bool fullAreaData = false;
451 {
453 {
454 if (area_id[x] != areaId)
455 {
456 fullAreaData = true;
457 break;
458 }
459 }
460 }
461
464
467 areaHeader.
flags = 0;
468 if (fullAreaData)
469 {
472 }
473 else
474 {
477 }
478
479
480
481
483 {
485 {
487 if (!cell)
488 continue;
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
507 {
510 {
513 }
514 }
516 {
519 {
522 }
523 }
524
526 if (!v)
527 continue;
528
530 {
533 {
536 }
537 }
538
540 {
543 {
546 }
547 }
548 }
549 }
550
551
552
553 float maxHeight = -20000;
554 float minHeight = 20000;
556 {
558 {
559 float h = y[x];
560 if (maxHeight < h) maxHeight = h;
561 if (minHeight > h) minHeight = h;
562 }
563 }
565 {
567 {
569 if (maxHeight < h) maxHeight = h;
570 if (minHeight > h) minHeight = h;
571 }
572 }
573
574
576 {
589 }
590
591 bool hasFlightBox = false;
593 {
596 hasFlightBox = true;
597 }
598
601
604 heightHeader.
flags = 0;
607
608 if (maxHeight == minHeight)
610
611
614
615 if (hasFlightBox)
616 {
619 }
620
621
623 {
624 float step = 0;
625
627 {
628 float diff = maxHeight - minHeight;
630 {
633 }
635 {
638 }
639 }
640
641
643 {
651 }
653 {
661 }
662 else
664 }
665
666
668 {
670 {
672 if (!cell)
673 continue;
674
676 int count = 0;
678 continue;
679
681 {
684 {
686 if (liquid->
flags[y][x] != 0x0F)
687 {
689 if (liquid->
flags[y][x] & (1 << 7))
691 ++count;
692 }
693 }
694 }
695
697 if (c_flag & (1 << 2))
698 {
701 }
702 if (c_flag & (1 << 3))
703 {
706 }
707 if (c_flag & (1 << 4))
708 {
711 }
712
714 fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
715
717 {
720 {
723 }
724 }
725 }
726 }
727
728
730 if (h2o)
731 {
733 {
735 {
737 if (!h)
738 continue;
739
741
745 {
748 {
750 if (existsMask & 1)
751 {
753 ++count;
754 }
755 existsMask >>= 1;
756 }
757 }
758
761 {
766 default:
767 printf(
"\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->
LiquidType, inputPath.c_str(), i, j);
768 break;
769 }
770
772 printf("Wrong liquid detect in MH2O chunk");
773
776 {
779 {
782
783 pos++;
784 }
785 }
786 }
787 }
788 }
789
790
791
794 bool fullType = false;
796 {
798 {
800 {
801 fullType = true;
803 break;
804 }
805 }
806 }
807
809
810
811 if (firstLiquidFlag == 0 && !fullType)
812 {
813
816 }
817 else
818 {
819 int minX = 255, minY = 255;
820 int maxX = 0, maxY = 0;
821 maxHeight = -20000;
822 minHeight = 20000;
824 {
826 {
828 {
829 if (minX > x) minX = x;
830 if (maxX < x) maxX = x;
831 if (minY > y) minY = y;
832 if (maxY < y) maxY = y;
834 if (maxHeight < h) maxHeight = h;
835 if (minHeight > h) minHeight = h;
836 }
837 else
838 {
840
842 {
844 }
845 }
846 }
847 }
851 liquidHeader.
flags = 0;
855 liquidHeader.
width = maxX - minX + 1 + 1;
856 liquidHeader.
height = maxY - minY + 1 + 1;
858
859 if (maxHeight == minHeight)
861
862
865
866 if (!fullType)
868
870 {
873 }
874 else
876
879 }
880
881 bool hasHoles = false;
882
884 {
886 {
888 if (!cell)
889 continue;
891 if (!hasHoles && cell->
holes != 0)
892 hasHoles = true;
893 }
894 }
895
896 if (hasHoles)
897 {
900 else
902
904 }
905 else
906 {
909 }
910
911
912 FILE* output = fopen(outputPath.c_str(), "wb");
913 if (!output)
914 {
915 printf("Can't create the output file '%s'\n", outputPath.c_str());
916 return false;
917 }
918 fwrite(&map, sizeof(map), 1, output);
919
920 fwrite(&areaHeader, sizeof(areaHeader), 1, output);
923
924
925 fwrite(&heightHeader, sizeof(heightHeader), 1, output);
927 {
929 {
932 }
934 {
937 }
938 else
939 {
940 fwrite(
V9,
sizeof(
V9), 1, output);
941 fwrite(
V8,
sizeof(
V8), 1, output);
942 }
943 }
944
946 {
949 }
950
951
953 {
954 fwrite(&liquidHeader, sizeof(liquidHeader), 1, output);
956 {
959 }
961 {
962 for (
int y = 0; y < liquidHeader.
height; y++)
964 }
965 }
966
967
968 if (hasHoles)
970
971 fclose(output);
972
973 return true;
974}
std::int32_t int32
Definition Define.h:103
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
std::uint64_t uint64
Definition Define.h:106
std::uint16_t uint16
Definition Define.h:108
float selectUInt8StepStore(float maxDiff)
Definition System.cpp:386
float CONF_float_to_int8_limit
Definition System.cpp:97
uint16 uint16_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition System.cpp:400
uint16 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition System.cpp:409
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition System.cpp:352
bool CONF_allow_height_limit
Definition System.cpp:92
#define MAP_LIQUID_TYPE_MAGMA
Definition System.cpp:365
#define MAP_HEIGHT_AS_INT8
Definition System.cpp:351
#define MAP_AREA_NO_AREA
Definition System.cpp:340
bool CONF_allow_float_to_int
Definition System.cpp:96
static char const * MAP_AREA_MAGIC
Definition System.cpp:321
#define MAP_LIQUID_NO_TYPE
Definition System.cpp:370
std::unordered_map< uint32, LiquidTypeEntry > LiquidTypes
Definition System.cpp:74
#define MAP_LIQUID_NO_HEIGHT
Definition System.cpp:371
uint16 uint16_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition System.cpp:401
#define MAP_LIQUID_TYPE_WATER
Definition System.cpp:363
static char const * MAP_MAGIC
Definition System.cpp:319
#define MAP_LIQUID_TYPE_DARK_WATER
Definition System.cpp:368
float CONF_flat_liquid_delta_limit
Definition System.cpp:100
#define MAP_LIQUID_TYPE_OCEAN
Definition System.cpp:364
float CONF_use_minHeight
Definition System.cpp:93
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition System.cpp:405
static uint32 const MAP_VERSION_MAGIC
Definition System.cpp:320
int16 flight_box_min[3][3]
Definition System.cpp:412
float selectUInt16StepStore(float maxDiff)
Definition System.cpp:391
uint16 area_ids[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition System.cpp:396
static char const * MAP_LIQUID_MAGIC
Definition System.cpp:323
int16 flight_box_max[3][3]
Definition System.cpp:411
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition System.cpp:408
#define MAP_LIQUID_TYPE_SLIME
Definition System.cpp:366
#define MAP_HEIGHT_NO_HEIGHT
Definition System.cpp:349
uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition System.cpp:406
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition System.cpp:398
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition System.cpp:403
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition System.cpp:399
static char const * MAP_HEIGHT_MAGIC
Definition System.cpp:322
float CONF_float_to_int16_limit
Definition System.cpp:98
#define MAP_HEIGHT_AS_INT16
Definition System.cpp:350
uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition System.cpp:402
bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition System.cpp:407
float CONF_flat_height_delta_limit
Definition System.cpp:99
#define ADT_CELL_SIZE
Definition adt.h:39
@ LIQUID_TYPE_WATER
Definition adt.h:29
@ LIQUID_TYPE_SLIME
Definition adt.h:32
@ LIQUID_TYPE_MAGMA
Definition adt.h:31
@ LIQUID_TYPE_OCEAN
Definition adt.h:30
#define ADT_GRID_SIZE
Definition adt.h:40
#define ADT_CELLS_PER_GRID
Definition adt.h:38
adt_MHDR * a_grid
Definition adt.h:403
bool loadFile(std::string const &filename, bool log=true)
Definition loadlib.cpp:40
adt_MCNK * getMCNK(int x, int y)
Definition adt.h:172
struct adt_MCLQ::liquid_data liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1]
uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE]
Definition adt.h:85
uint32 sizeMCLQ
Definition adt.h:127
adt_MCVT * getMCVT()
Definition adt.h:136
uint32 holes
Definition adt.h:117
adt_MCLQ * getMCLQ()
Definition adt.h:142
uint32 flags
Definition adt.h:102
uint32 areaid
Definition adt.h:115
float ypos
Definition adt.h:130
float height_map[(ADT_CELL_SIZE+1) *(ADT_CELL_SIZE+1)+ADT_CELL_SIZE *ADT_CELL_SIZE]
Definition adt.h:54
adt_liquid_attributes GetLiquidAttributes(int32 x, int32 y) const
Definition adt.h:241
adt_liquid_instance const * GetLiquidInstance(int32 x, int32 y) const
Definition adt.h:234
float GetLiquidHeight(adt_liquid_instance const *h, int32 pos) const
Definition adt.h:260
uint64 GetLiquidExistsBitmap(adt_liquid_instance const *h) const
Definition adt.h:316
adt_MFBO * getMFBO()
Definition adt.h:387
adt_MCIN * getMCIN()
Definition adt.h:377
adt_MH2O * getMH2O()
Definition adt.h:381
float height
Definition adt.h:76
uint64 Deep
Definition adt.h:209
uint8 GetWidth() const
Definition adt.h:202
uint8 GetOffsetX() const
Definition adt.h:200
uint16 LiquidType
Definition adt.h:189
uint8 GetHeight() const
Definition adt.h:203
uint8 GetOffsetY() const
Definition adt.h:201