// Calculates climate value from 4 cached values // Use relative positions here public int GetLerpedOreValueAt(double posX, double posZ, int[] oreCache, int sizeX, float contrastMul, float sub) { int posXInt = (int)(posX); int posZInt = (int)(posZ); byte val = GameMath.BiSerpByte( (float)(posX - posXInt), (float)(posZ - posZInt), 0, oreCache[posZInt * sizeX + posXInt], oreCache[posZInt * sizeX + posXInt + 1], oreCache[(posZInt + 1) * sizeX + posXInt], oreCache[(posZInt + 1) * sizeX + posXInt + 1] ); val = (byte)GameMath.Clamp((val - 128f) * contrastMul + 128 - sub, 0, 255); int richness = Math.Max( oreCache[(posZInt + 1) * sizeX + posXInt + 1] & 0xff0000, Math.Max(oreCache[(posZInt + 1) * sizeX + posXInt] & 0xff0000, Math.Max(oreCache[posZInt * sizeX + posXInt] & 0xff0000, oreCache[posZInt * sizeX + posXInt + 1] & 0xff0000)) ); int hypercommon = Math.Max( oreCache[(posZInt + 1) * sizeX + posXInt + 1] & 0x00ff00, Math.Max(oreCache[(posZInt + 1) * sizeX + posXInt] & 0x00ff00, Math.Max(oreCache[posZInt * sizeX + posXInt] & 0x00ff00, oreCache[posZInt * sizeX + posXInt + 1] & 0x00ff00)) ); return(val == 0 ? 0 : val | richness | hypercommon); }
// Calculates climate value from 4 cached values // Use relative positions here public int GetLerpedClimateAt(double posX, double posZ, int[] oreCache, int sizeX) { int posXInt = (int)(posX); int posZInt = (int)(posZ); byte val = GameMath.BiSerpByte( (float)(posX - posXInt), (float)(posZ - posZInt), 0, oreCache[posZInt * sizeX + posXInt], oreCache[posZInt * sizeX + posXInt + 1], oreCache[(posZInt + 1) * sizeX + posXInt], oreCache[(posZInt + 1) * sizeX + posXInt + 1] ); int richness = Math.Max(oreCache[(posZInt + 1) * sizeX + posXInt + 1] & 0xff0000, Math.Max(oreCache[(posZInt + 1) * sizeX + posXInt] & 0xff0000, Math.Max(oreCache[posZInt * sizeX + posXInt] & 0xff0000, oreCache[posZInt * sizeX + posXInt + 1] & 0xff0000))); int hypercommon = Math.Max(oreCache[(posZInt + 1) * sizeX + posXInt + 1] & 0x00ff00, Math.Max(oreCache[(posZInt + 1) * sizeX + posXInt] & 0x00ff00, Math.Max(oreCache[posZInt * sizeX + posXInt] & 0x00ff00, oreCache[posZInt * sizeX + posXInt + 1] & 0x00ff00))); return(val == 0 ? 0 : val | richness | hypercommon); }