diff --git a/finders.c b/finders.c index 0364ab6..a78468e 100644 --- a/finders.c +++ b/finders.c @@ -13,37 +13,6 @@ Biome biomes[256]; -// only the very best constellations -const int64_t lowerBaseBitsIdeal[] = -{ - 0x43f18,0xc751a,0xf520a, -}; - -// for the classic quad-structure constellations -const int64_t lowerBaseBitsClassic[] = -{ - 0x43f18,0x79a0a,0xc751a,0xf520a, -}; - -// for any valid quad-structure constellation with a structure size: -// (7+1,7+43+1,9+1) which corresponds to a fall-damage based quad-witch-farm, -// but may require a perfect player position -const int64_t lowerBaseBitsHutNormal[] = -{ - 0x43f18,0x65118,0x75618,0x79a0a, 0x89718,0x9371a,0xa5a08,0xb5e18, - 0xc751a,0xf520a, -}; - -// for any valid quad-structure constellation with a structure size: -// (7+1,7+1,9+1) which corresponds to quad-witch-farms without drop chute -const int64_t lowerBaseBitsHutBarely[] = -{ - 0x1272d,0x17908,0x367b9,0x43f18, 0x487c9,0x487ce,0x50aa7,0x647b5, - 0x65118,0x75618,0x79a0a,0x89718, 0x9371a,0x967ec,0xa3d0a,0xa5918, - 0xa591d,0xa5a08,0xb5e18,0xc6749, 0xc6d9a,0xc751a,0xd7108,0xd717a, - 0xe2739,0xe9918,0xee1c4,0xf520a, -}; - //============================================================================== // Saving & Loading Seeds //============================================================================== @@ -92,6 +61,14 @@ int64_t *loadSavedSeeds(const char *fnam, int64_t *scnt) //============================================================================== +static int testOutpostPos(int64_t s, int cx, int cz) +{ + s ^= (cx >> 4) ^ ( (cz >> 4) << 4 ); + setSeed(&s); + next(&s, 32); + return nextInt(&s, 5) == 0; +} + Pos getStructurePos(StructureConfig config, int64_t seed, int regX, int regZ, int *valid) { Pos pos; @@ -104,14 +81,7 @@ Pos getStructurePos(StructureConfig config, int64_t seed, int regX, int regZ, in { if (config.structType == Outpost) { - int64_t rnds = seed; - rnds ^= ((pos.x >> 8) ^ (pos.z >> 4)) << 4; - setSeed(&rnds); - next(&rnds, 32); - if (nextInt(&rnds, 5) == 0) - *valid = 1; - else - *valid = 0; + *valid = testOutpostPos(seed, pos.x >> 4, pos.z >> 4); // Outposts also require that there are no villages nearby. // However, before 1.16 this would include a biome check, so it // should be tested for in the position viability check. @@ -166,10 +136,10 @@ int isTreasureChunk(int64_t seed, int chunkX, int chunkZ) * * Returned is the number of spawning spaces within reach. */ -int countBlocksInSpawnRange(Pos p[4], const int ax, const int ay, const int az) +int countBlocksInSpawnRange(Pos p[4], int ax, int ay, int az, Pos *afk) { int minX = 3e7, minZ = 3e7, maxX = -3e7, maxZ = -3e7; - int best, i, x, z, px, pz; + int bestr, bestn, i, x, z, px, pz; // Find corners @@ -185,9 +155,10 @@ int countBlocksInSpawnRange(Pos p[4], const int ax, const int ay, const int az) // assume that the search area is bound by the inner corners maxX += ax; maxZ += az; - best = 0; + bestr = 0; + bestn = 0; - double thsq = 128.0*128.0 - az*az/4.0; + double thsq = 128.0*128.0 - ay*ay/4.0; for (x = minX; x < maxX; x++) { @@ -211,14 +182,35 @@ int countBlocksInSpawnRange(Pos p[4], const int ax, const int ay, const int az) } } - if (inrange > best) + if (inrange > bestr) { - best = inrange; + if (afk) + { + afk->x = x; + afk->z = z; + bestn = 1; + } + bestr = inrange; + } + else if (inrange == bestr) + { + if (afk) + { + afk->x += x; + afk->z += z; + bestn++; + } } } } - return best; + if (afk && bestn) + { + afk->x /= bestn; + afk->z /= bestn; + } + + return bestr; } @@ -1156,11 +1148,7 @@ int isViableStructurePos(int structureType, int mcversion, LayerStack *g, case Outpost: { - int64_t rnds = seed; - rnds ^= ((chunkX >> 4) ^ (chunkZ >> 4)) << 4; - setSeed(&rnds); - next(&rnds, 32); - if (nextInt(&rnds, 5) != 0) + if (!testOutpostPos(seed, chunkX, chunkZ)) goto L_NOT_VIABLE; if (mcversion < MC_1_16) { @@ -1640,7 +1628,7 @@ static int mapFilterMushroom(const Layer * l, int * out, int x, int z, int w, in int i, j; int err; - if (w*h < 100 && bf->majorToFind & (1ULL << mushroom_fields)) + if (w*h < 100 && (bf->majorToFind & (1ULL << mushroom_fields))) { int64_t ss = l->startSeed; int64_t cs; diff --git a/finders.h b/finders.h index 6c5653a..d61538c 100644 --- a/finders.h +++ b/finders.h @@ -54,6 +54,39 @@ enum // village house types prior to 1.14 Blacksmith, HouseLarge, HOUSE_NUM }; + +// only the very best constellations +static const int64_t lowerBaseBitsIdeal[] = +{ + 0x43f18,0xc751a,0xf520a, +}; + +// for the classic quad-structure constellations +static const int64_t lowerBaseBitsClassic[] = +{ + 0x43f18,0x79a0a,0xc751a,0xf520a, +}; + +// for any valid quad-structure constellation with a structure size: +// (7+1,7+43+1,9+1) which corresponds to a fall-damage based quad-witch-farm, +// but may require a perfect player position +static const int64_t lowerBaseBitsHutNormal[] = +{ + 0x43f18,0x65118,0x75618,0x79a0a, 0x89718,0x9371a,0xa5a08,0xb5e18, + 0xc751a,0xf520a, +}; + +// for any valid quad-structure constellation with a structure size: +// (7+1,7+1,9+1) which corresponds to quad-witch-farms without drop chute +static const int64_t lowerBaseBitsHutBarely[] = +{ + 0x1272d,0x17908,0x367b9,0x43f18, 0x487c9,0x487ce,0x50aa7,0x647b5, + 0x65118,0x75618,0x79a0a,0x89718, 0x9371a,0x967ec,0xa3d0a,0xa5918, + 0xa591d,0xa5a08,0xb5e18,0xc6749, 0xc6d9a,0xc751a,0xd7108,0xd717a, + 0xe2739,0xe9918,0xee1c4,0xf520a, +}; + + STRUCT(StructureConfig) { int salt; @@ -65,6 +98,10 @@ STRUCT(StructureConfig) /* for desert pyramids, jungle temples, witch huts and igloos prior to 1.13 */ static const StructureConfig FEATURE_CONFIG = { 14357617, 32, 24, Feature, 0}; +static const StructureConfig DESERT_CONFIG_17 = { 14357617, 32, 24, Desert_Pyramid, 0}; +static const StructureConfig IGLOO_CONFIG_17 = { 14357617, 32, 24, Igloo, 0}; +static const StructureConfig JUNGLE_CONFIG_17 = { 14357617, 32, 24, Jungle_Pyramid, 0}; +static const StructureConfig SWAMP_HUT_CONFIG_17 = { 14357617, 32, 24, Swamp_Hut, 0}; /* ocean features before 1.16 */ static const StructureConfig OCEAN_RUIN_CONFIG_113 = { 14357621, 16, 8, Ocean_Ruin, 0}; @@ -320,10 +357,10 @@ float isQuadBaseLarge (const StructureConfig sconf, int64_t seed, enum LowBitSet { LBIT_ALL, // all bit configurations - LBIT_IDEAL, // only the very best constellations that exist - LBIT_CLASSIC, // only classic constellations - LBIT_HUT_NORMAL, // sufficiently close for standard farm designs LBIT_HUT_BARELY, // any constellation for huts within 128 blocks + LBIT_HUT_NORMAL, // sufficiently close for standard farm designs + LBIT_CLASSIC, // only classic constellations + LBIT_IDEAL, // only the very best constellations that exist }; /* Starts a multi-threaded search for quad-bases, given a maximum block radius @@ -333,6 +370,7 @@ void search4QuadBases(const char *fnam, int threads, const StructureConfig structureConfig, int radius, int lbitset); +int countBlocksInSpawnRange(Pos p[4], int ax, int ay, int az, Pos *afk); //============================================================================== // Checking Biomes & Biome Helper Functions @@ -716,9 +754,9 @@ static inline float isQuadBase(const StructureConfig sconf, int64_t seed, int ra { case Swamp_Hut: if (radius == 128) - return isQuadBaseFeature24(sconf, seed, 7+1, 7+43+1, 9+1); + return isQuadBaseFeature24(sconf, seed, 7+1, 7+1, 9+1);//7+1, 7+43+1, 9+1); else - return isQuadBaseFeature(sconf, seed, 7+1, 7+43+1, 9+1, radius); + return isQuadBaseFeature(sconf, seed, 7+1, 7+1, 9+1, radius); case Desert_Pyramid: case Jungle_Pyramid: case Igloo: diff --git a/makefile b/makefile index b8d0792..e74e58a 100644 --- a/makefile +++ b/makefile @@ -14,7 +14,7 @@ endif .PHONY : all release debug libcubiomes clean -all: release +all: debug debug: CFLAGS += -DDEBUG -O0 -ggdb3 debug: libcubiomes find_quadhuts find_compactbiomes @@ -38,9 +38,6 @@ find_quadhuts.o: find_quadhuts.c $(CC) -c $(CFLAGS) $< -xmapview.o: xmapview.c xmapview.h - $(CC) -c $(CFLAGS) $< - finders.o: finders.c finders.h $(CC) -c $(CFLAGS) $< diff --git a/xmapview.c b/xmapview.c deleted file mode 100644 index 29154a4..0000000 --- a/xmapview.c +++ /dev/null @@ -1,129 +0,0 @@ -#include "xmapview.h" -#include "util.h" - -#include -#include - - -xwin_t init_x(uint sx, uint sy, const char *titel) -{ - xwin_t w; - - w.dis = XOpenDisplay(NULL); - w.screen = DefaultScreen(w.dis); - - w.win = XCreateSimpleWindow(w.dis, DefaultRootWindow(w.dis), 0, 0, sx, sy, - 5, 0x000000, 0xffffff); - - w.gc = XCreateGC(w.dis, w.win, 0,0); - - w.sx = sx; - w.sy = sy; - - XSetStandardProperties(w.dis, w.win, titel, "Cubiomes", None, NULL, 0, NULL); - - Atom WM_DELETE_WINDOW = XInternAtom(w.dis, "WM_DELETE_WINDOW", False); - XSetWMProtocols(w.dis, w.win, &WM_DELETE_WINDOW, 1); - - XSelectInput(w.dis, w.win, ExposureMask|ButtonPressMask|KeyPressMask); - - XSetBackground(w.dis, w.gc, 0x000000); - XSetForeground(w.dis, w.gc, 0xffffff); - - XClearWindow(w.dis, w.win); - XMapRaised(w.dis, w.win); - - return w; -} - -void close_x(xwin_t w) -{ - XFreeGC(w.dis, w.gc); - XDestroyWindow(w.dis, w.win); - XCloseDisplay(w.dis); -} - - -void viewmap(Layer *layer, unsigned char biomeColour[256][3], int areaX, int areaZ, uint areaWidth, uint areaHeight, uint pixscale) -{ - int *ints = allocCache(layer, areaWidth, areaHeight); - - // generate the biome ints - genArea(layer, ints, areaX, areaZ, areaWidth, areaHeight); - - // Calculate a hash for the area (useful to verify the accuracy of the map) - uint i, hash = 0; - for (i = 0; i < areaWidth*areaHeight; i++) hash = hash ^ (i*(ints[i]+1)); - printf("Hash:%3X\n", hash&0xfff); - - // construct the X11 window - xwin_t w = init_x(areaWidth*pixscale, areaHeight*pixscale, "XMapViewer"); - - XEvent event; - KeySym key; - char text[255]; - - - // convert the biome ints to a colour image - uint *colbuf = (uint *) malloc(sizeof(uint) * - areaWidth*areaHeight*pixscale*pixscale); - - biomesToImage(colbuf, biomeColour, ints, areaWidth, areaHeight, pixscale, 0); - - XImage *ximg = XCreateImage(w.dis, DefaultVisual(w.dis,0), 24, ZPixmap, 0, - (char*)colbuf, areaWidth*pixscale, areaHeight*pixscale, 24, 0); - - XSetForeground(w.dis, w.gc, 0xf00020); - - // enter the event loop - while (1) - { - XNextEvent(w.dis, &event); - - if (event.type == ClientMessage) - { - break; - } - - if (event.type==Expose && event.xexpose.count==0) - { - XMapWindow(w.dis, w.win); - - XPutImage(w.dis, w.win, w.gc, ximg, 0, 0, 0, 0, - areaWidth*pixscale, areaHeight*pixscale); - XSetForeground(w.dis, w.gc, 0xf00020); - } - if (event.type==KeyPress) - { - XLookupString(&event.xkey,text,255,&key,0); - if (key == XK_Escape) - { - break; - } - else - { - } - } - if (event.type==ButtonPress) - { - } - - //XResizeWindow(dis, win, sx, sy); - } - - close_x(w); - XFree(ximg); - - free(ints); - free(colbuf); -} - - - - - - - - - - diff --git a/xmapview.h b/xmapview.h deleted file mode 100644 index afe015f..0000000 --- a/xmapview.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef XMAPVIEW_H_ -#define XMAPVIEW_H_ - -#include "generator.h" - -#include -#include -#include -#include - -typedef struct xwin_t -{ - Display *dis; - int screen; - Window win; - GC gc; - - uint *colbuf; - uint sx, sy; - -} xwin_t; - -xwin_t init_x(uint sx, uint sy, const char *titel); -void close_x(xwin_t w); - -void viewmap(Layer *layer, unsigned char biomeColour[256][3], - int areaX, int areaZ, uint areaWidth, uint areaHeight, uint pixscale); - - - -#endif