411{
413
415 return false;
416
418 if (!cells)
419 {
420 printf("Can't find cells in '%s'\n", inputPath.c_str());
421 return false;
422 }
423
427
429
430
435
436
440
441
442
443
444 bool fullAreaData = false;
447 {
449 {
450 if (area_id[x] != areaId)
451 {
452 fullAreaData = true;
453 break;
454 }
455 }
456 }
457
460
463 areaHeader.
flags = 0;
464 if (fullAreaData)
465 {
468 }
469 else
470 {
473 }
474
475
476
477
479 {
481 {
483 if (!cell)
484 continue;
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
503 {
506 {
509 }
510 }
512 {
515 {
518 }
519 }
520
522 if (!v)
523 continue;
524
526 {
529 {
532 }
533 }
534
536 {
539 {
542 }
543 }
544 }
545 }
546
547
548
549 float maxHeight = -20000;
550 float minHeight = 20000;
552 {
554 {
555 float h = y[x];
556 if (maxHeight < h) maxHeight = h;
557 if (minHeight > h) minHeight = h;
558 }
559 }
561 {
563 {
565 if (maxHeight < h) maxHeight = h;
566 if (minHeight > h) minHeight = h;
567 }
568 }
569
570
572 {
585 }
586
587 bool hasFlightBox = false;
589 {
592 hasFlightBox = true;
593 }
594
597
600 heightHeader.
flags = 0;
603
604 if (maxHeight == minHeight)
606
607
610
611 if (hasFlightBox)
612 {
615 }
616
617
619 {
620 float step = 0;
621
623 {
624 float diff = maxHeight - minHeight;
626 {
629 }
631 {
634 }
635 }
636
637
639 {
647 }
649 {
657 }
658 else
660 }
661
662
664 {
666 {
668 if (!cell)
669 continue;
670
672 int count = 0;
674 continue;
675
677 {
680 {
682 if (liquid->
flags[y][x] != 0x0F)
683 {
685 if (liquid->
flags[y][x] & (1 << 7))
687 ++count;
688 }
689 }
690 }
691
693 if (c_flag & (1 << 2))
694 {
697 }
698 if (c_flag & (1 << 3))
699 {
702 }
703 if (c_flag & (1 << 4))
704 {
707 }
708
710 fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
711
713 {
716 {
719 }
720 }
721 }
722 }
723
724
726 if (h2o)
727 {
729 {
731 {
733 if (!h)
734 continue;
735
737
741 {
744 {
746 if (existsMask & 1)
747 {
749 ++count;
750 }
751 existsMask >>= 1;
752 }
753 }
754
757 {
762 default:
763 printf(
"\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->
LiquidType, inputPath.c_str(), i, j);
764 break;
765 }
766
768 printf("Wrong liquid detect in MH2O chunk");
769
772 {
775 {
778
779 pos++;
780 }
781 }
782 }
783 }
784 }
785
786
787
790 bool fullType = false;
792 {
794 {
796 {
797 fullType = true;
799 break;
800 }
801 }
802 }
803
805
806
807 if (firstLiquidFlag == 0 && !fullType)
808 {
809
812 }
813 else
814 {
815 int minX = 255, minY = 255;
816 int maxX = 0, maxY = 0;
817 maxHeight = -20000;
818 minHeight = 20000;
820 {
822 {
824 {
825 if (minX > x) minX = x;
826 if (maxX < x) maxX = x;
827 if (minY > y) minY = y;
828 if (maxY < y) maxY = y;
830 if (maxHeight < h) maxHeight = h;
831 if (minHeight > h) minHeight = h;
832 }
833 else
834 {
836
838 {
840 }
841 }
842 }
843 }
847 liquidHeader.
flags = 0;
851 liquidHeader.
width = maxX - minX + 1 + 1;
852 liquidHeader.
height = maxY - minY + 1 + 1;
854
855 if (maxHeight == minHeight)
857
858
861
862 if (!fullType)
864
866 {
869 }
870 else
872
875 }
876
877 bool hasHoles = false;
878
880 {
882 {
884 if (!cell)
885 continue;
887 if (!hasHoles && cell->
holes != 0)
888 hasHoles = true;
889 }
890 }
891
892 if (hasHoles)
893 {
896 else
898
900 }
901 else
902 {
905 }
906
907
908 FILE* output = fopen(outputPath.c_str(), "wb");
909 if (!output)
910 {
911 printf("Can't create the output file '%s'\n", outputPath.c_str());
912 return false;
913 }
914 fwrite(&map, sizeof(map), 1, output);
915
916 fwrite(&areaHeader, sizeof(areaHeader), 1, output);
919
920
921 fwrite(&heightHeader, sizeof(heightHeader), 1, output);
923 {
925 {
928 }
930 {
933 }
934 else
935 {
936 fwrite(
V9,
sizeof(
V9), 1, output);
937 fwrite(
V8,
sizeof(
V8), 1, output);
938 }
939 }
940
942 {
945 }
946
947
949 {
950 fwrite(&liquidHeader, sizeof(liquidHeader), 1, output);
952 {
955 }
957 {
958 for (
int y = 0; y < liquidHeader.
height; y++)
960 }
961 }
962
963
964 if (hasHoles)
966
967 fclose(output);
968
969 return true;
970}
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
#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
float selectUInt8StepStore(float maxDiff)
Definition: System.cpp:382
float CONF_float_to_int8_limit
Definition: System.cpp:96
uint16 uint16_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:396
uint16 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:405
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS
Definition: System.cpp:348
bool CONF_allow_height_limit
Definition: System.cpp:91
#define MAP_LIQUID_TYPE_MAGMA
Definition: System.cpp:361
#define MAP_HEIGHT_AS_INT8
Definition: System.cpp:347
#define MAP_AREA_NO_AREA
Definition: System.cpp:336
bool CONF_allow_float_to_int
Definition: System.cpp:95
static char const * MAP_AREA_MAGIC
Definition: System.cpp:317
#define MAP_LIQUID_NO_TYPE
Definition: System.cpp:366
std::unordered_map< uint32, LiquidTypeEntry > LiquidTypes
Definition: System.cpp:73
#define MAP_LIQUID_NO_HEIGHT
Definition: System.cpp:367
uint16 uint16_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:397
#define MAP_LIQUID_TYPE_WATER
Definition: System.cpp:359
static char const * MAP_MAGIC
Definition: System.cpp:315
#define MAP_LIQUID_TYPE_DARK_WATER
Definition: System.cpp:364
float CONF_flat_liquid_delta_limit
Definition: System.cpp:99
#define MAP_LIQUID_TYPE_OCEAN
Definition: System.cpp:360
float CONF_use_minHeight
Definition: System.cpp:92
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:401
static uint32 const MAP_VERSION_MAGIC
Definition: System.cpp:316
int16 flight_box_min[3][3]
Definition: System.cpp:408
float selectUInt16StepStore(float maxDiff)
Definition: System.cpp:387
uint16 area_ids[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:392
static char const * MAP_LIQUID_MAGIC
Definition: System.cpp:319
int16 flight_box_max[3][3]
Definition: System.cpp:407
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:404
#define MAP_LIQUID_TYPE_SLIME
Definition: System.cpp:362
#define MAP_HEIGHT_NO_HEIGHT
Definition: System.cpp:345
uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]
Definition: System.cpp:402
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:394
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:399
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]
Definition: System.cpp:395
static char const * MAP_HEIGHT_MAGIC
Definition: System.cpp:318
float CONF_float_to_int16_limit
Definition: System.cpp:97
#define MAP_HEIGHT_AS_INT16
Definition: System.cpp:346
uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:398
bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE]
Definition: System.cpp:403
float CONF_flat_height_delta_limit
Definition: System.cpp:98
uint32 mapMagic
Definition: Map.h:89
uint32 holesSize
Definition: Map.h:99
uint32 liquidMapSize
Definition: Map.h:97
uint32 areaMapOffset
Definition: Map.h:92
uint32 heightMapSize
Definition: Map.h:95
uint32 heightMapOffset
Definition: Map.h:94
uint32 buildMagic
Definition: Map.h:91
uint32 holesOffset
Definition: Map.h:98
uint32 versionMagic
Definition: Map.h:90
uint32 liquidMapOffset
Definition: Map.h:96
uint32 areaMapSize
Definition: Map.h:93
uint32 fourcc
Definition: Map.h:106
uint16 gridArea
Definition: Map.h:108
uint16 flags
Definition: Map.h:107
float gridMaxHeight
Definition: Map.h:121
uint32 flags
Definition: Map.h:119
float gridHeight
Definition: Map.h:120
uint32 fourcc
Definition: Map.h:118
uint8 offsetX
Definition: Map.h:133
uint32 fourcc
Definition: Map.h:129
uint8 liquidFlags
Definition: Map.h:131
uint8 width
Definition: Map.h:135
uint8 height
Definition: Map.h:136
uint8 flags
Definition: Map.h:130
uint16 liquidType
Definition: Map.h:132
uint8 offsetY
Definition: Map.h:134
float liquidLevel
Definition: Map.h:137
float height_map[(ADT_CELL_SIZE+1) *(ADT_CELL_SIZE+1)+ADT_CELL_SIZE *ADT_CELL_SIZE]
Definition: adt.h:54
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
float height
Definition: adt.h:76
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
adt_MCNK * getMCNK(int x, int y)
Definition: adt.h:172
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
uint64 Deep
Definition: adt.h:209
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
adt_MHDR * a_grid
Definition: adt.h:403
bool loadFile(std::string const &filename, bool log=true)
Definition: loadlib.cpp:40