This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [Question] about AllOcean3.0  (Read 1362 times)

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
[Question] about AllOcean3.0
« on: June 15, 2014, 11:41:15 pm »
I love this tool cause of what it does

"Fills the ADT with ocean 3.* style where no terrain is above 0."

What I am asking is what numbers do I have to change to make that height different in the code to fill to 125 instead of 0, this would REALLY make my life a lot easier lol. Would I have to recompile it also or does the .exe read from the .cpp

Here is the code:

Code: [Select]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define DESCRIPTION "Fills the ADT with ocean 3.* style where no terrain is above 0."
#define ARGUMENTS "<map filename> [<depthfactor>]"

#define USAGE( minimumArguments, argc, argv )
if( argc < minimumArguments + 1 )
{
printf( "  %sn", argv[0] );
printf( "    " DESCRIPTION "nn" );
printf( "    Usage: "%s " ARGUMENTS ""n", argv[0] );
printf( "    Built at: " __DATE__ "n" );
return -1;
}

struct MCIN
{
unsigned int Offset;
unsigned int Size;
unsigned int Temp1;
unsigned int Temp2;
};

struct MCVT
{
float row0[9];
float null0[8];
float row1[9];
float null1[8];
float row2[9];
float null2[8];
float row3[9];
float null3[8];
float row4[9];
float null4[8];
float row5[9];
float null5[8];
float row6[9];
float null6[8];
float row7[9];
float null7[8];
float row8[9];
};

MCIN *Positions;
MCVT * HeightMap;
float * basez;

FILE *Input;
char *File;

float fabs ( float a )
{
float temp = a * a;
temp = sqrt( a );
return temp;      
}

float getHeightValue2(int i)
{
if (i<8) return *basez + HeightMap->null0[i%8];
else if(i<16) return *basez + HeightMap->null1[i%8];
else if(i<24) return *basez + HeightMap->null2[i%8];
else if(i<32) return *basez + HeightMap->null3[i%8];
else if(i<40) return *basez + HeightMap->null4[i%8];
else if(i<48) return *basez + HeightMap->null5[i%8];
else if(i<56) return *basez + HeightMap->null6[i%8];
else if(i<64) return *basez + HeightMap->null7[i%8];

return *basez;
}

float getHeightValue(int i)
{
if (i<9) return *basez + HeightMap->row0[i%9];
else if(i<18) return *basez + HeightMap->row1[i%9];
else if(i<27) return *basez + HeightMap->row2[i%9];
else if(i<36) return *basez + HeightMap->row3[i%9];
else if(i<45) return *basez + HeightMap->row4[i%9];
else if(i<54) return *basez + HeightMap->row5[i%9];
else if(i<63) return *basez + HeightMap->row6[i%9];
else if(i<72) return *basez + HeightMap->row7[i%9];
else if(i<81) return *basez + HeightMap->row8[i%9];

return *basez;
}

float valueormax(float value, float max)
{
if(value < max) return value;
else return max;
}


unsigned int FileSize;

int main(int argc, char **argv)
{
USAGE( 1, argc, argv );

int depth = 1;

unsigned int *TInt;
unsigned char *TChar;
unsigned short *TShort;

if( argc == 3 )
depth = atoi(argv[2]);

Input = fopen( argv[1], "rb+" );
fseek( Input, 0, SEEK_END );
FileSize = ftell( Input );
File = new char[ FileSize + 0xC00 + 0x81 * 256 + 0x8 ];           // And new chunk.
fseek( Input, 0, SEEK_SET );
fread( File, 1, FileSize, Input );
fclose( Input );

Positions = (MCIN *)( File + 0x5C );

// header content is at 0x14, water is at header+0x28
TInt = (unsigned int *)( File + 0x14 + 0x28 );
*TInt = FileSize - 0x14;

// write chunk:
TChar = (unsigned char *)( File + FileSize ); // magix
*TChar = 'O'; TChar++; *TChar = '2'; TChar++;
*TChar = 'H'; TChar++; *TChar = 'M';

TInt = (unsigned int *)( File + FileSize + 0x4 ); // size
*TInt = 0xC00 + 0x81 * 256;


for( int i = 0; i < 256; i++ )
{
// delete MCLQ
TInt = (unsigned int *)( File + Positions[i].Offset + 0x08 );
*TInt = *TInt & ~(28); // b11100 = x1C = 28
        TInt = (unsigned int *)( File + Positions[i].Offset + 0x68 );
*TInt = 0;
TInt = (unsigned int *)( File + Positions[i].Offset + 0x6C );
*TInt = 0;

int address = 0xC00 + i * 0x81;

// the info - array

TInt = (unsigned int *)( File + FileSize + 0x8 + i*0xC );
/* 0x000 */ *TInt = address; TInt++;
/* 0x004 */ *TInt = 1; TInt++;
/* 0x008 */ *TInt = address + 0x18;

// the data

TShort = (unsigned short *)( File + FileSize + 0x8 + address );
/* 0xC00 */ *TShort = 2; TShort++;
/* 0xC02 */ *TShort = 2;
TInt = (unsigned int *)( File + FileSize + 0x8 + address + 0x4 );
/* 0xC04 */ *TInt = 0; TInt++;
/* 0xC08 */ *TInt = 0; TInt++;
TChar = (unsigned char *)( File + FileSize + 0x8 + address + 0xC );
/* 0xC0C */ *TChar = 0; TChar++; *TChar = 0; TChar++;
/* 0xC0E */ *TChar = 8; TChar++; *TChar = 8;
TInt = (unsigned int *)( File + FileSize + 0x8 + address + 0x10 );
/* 0xC10 */ *TInt = address + 0x28; TInt++;
/* 0xC14 */ *TInt = address + 0x30; TInt++;
/* 0xC18 */ *TInt = 0; TInt++;
/* 0xC1C */ *TInt = 0; TInt++;
/* 0xC20 */ *TInt = 0; TInt++;
/* 0xC24 */ *TInt = 0; TInt++;
/* 0xC28 */ *TInt = 0; TInt++;
/* 0xC2C */ *TInt = 0;

// and the information we gain from seeing the heightmap.

HeightMap = (MCVT *)( File + Positions[i].Offset + 0x8 + 128 + 0x8 );
basez = (float*)( File + Positions[i].Offset + 0x78 );

TChar = (unsigned char *)( File + FileSize + 0x8 + address + 0x30 );
unsigned char * mask_byte = (unsigned char*)( File + FileSize + 0x8 + address + 0x18 );
unsigned char * mask_byte2 = (unsigned char*)( File + FileSize + 0x8 + address + 0x28 );

for( int j = 0; j < 9*9; j++)
{
int baselevel = 0;
float trans = baselevel - getHeightValue(j);

if( trans < 0 ) trans = 0;
else if(trans > 255) trans = 255;

/* 0xC30 + j */ *TChar = (unsigned char)trans;
TChar++;    
}

for( int j = 0; j < 8; j++)
{
for( int k = 0; k < 8; k++)
{
int baselevel = 0;
float trans = baselevel - getHeightValue2(j*8+k);

// *   *   // j*8 + k, j*8 + 1 + k
   //    +     // j*8 + k
// *   *   // (j+1)*8 + k, (j+1)*8 + 1 + k
               

if((baselevel - getHeightValue2(j*8+k)) >= baselevel
                 || (baselevel - getHeightValue(j*8+k)) >= baselevel
                 || (baselevel - getHeightValue(j*8+k+1)) >= baselevel
                 || (baselevel - getHeightValue((j+1)*8+k)) >= baselevel
                 || (baselevel - getHeightValue((j+1)*8+k+1)) >= baselevel  )
{
*mask_byte = *mask_byte | ( 1 << (k % 8) );
*mask_byte2 = *mask_byte2 | ( 1 << (k % 8) );
}
}
mask_byte++;
mask_byte2++;
}
}


Input = fopen( argv[1], "wb" );
fwrite( File, 1, FileSize + 0xC00 + 0x81 * 256 + 0x8, Input );
fclose( Input );

delete File;
}


Any help here would be GREATLY appreciated lol
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [Question] about AllOcean3.0
« Reply #1 on: June 16, 2014, 12:09:12 am »
You will have to recompile.
Edit all occurrences of
Code: [Select]
baselevel = 0 to
Code: [Select]
baselevel = whatever_you_want_to_have_as_limit, i.e.
Code: [Select]
baselevel = 125
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
Re: [Question] about AllOcean3.0
« Reply #2 on: June 16, 2014, 02:16:24 am »
Thank you for that info but that leads to another question (I know nothing about reading writing code) I just understand what some stuff is/does.

When I try to compile this for win32 console in VS 2013 after adding the .h headers listed in the .cpp, when I try to build the .exe it says

float fabs ( float a )
{
   float temp = a * a;
   temp = sqrt( a );
   return temp;      
}

That the code above already has a body and it fails to build it.

Do you use a different compiler to make this or am I just a little to noobish to this stuff to do it completely on my own lol (considering I can't read or write a single line of code :P)
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
Re: [Question] about AllOcean3.0
« Reply #3 on: June 16, 2014, 04:05:19 am »
Quote from: "Kranimal"
Thank you for that info but that leads to another question (I know nothing about reading writing code) I just understand what some stuff is/does.

When I try to compile this for win32 console in VS 2013 after adding the .h headers listed in the .cpp, when I try to build the .exe it says

float fabs ( float a )
{
   float temp = a * a;
   temp = sqrt( a );
   return temp;      
}

That the code above already has a body and it fails to build it.

Do you use a different compiler to make this or am I just a little to noobish to this stuff to do it completely on my own lol (considering I can't read or write a single line of code :P)

Anybody :)? narrowed it down to having something to do with the math.h header

EDIT: Nvrm, don't know what the blip I am talking about lol.... still can't get it to compile though, still getting the same error at that spot.

Anybody know how to fix this? I have 1,681 adt files so this would REALLY make my life easier lol.

If anything I could remake the one adt file in taliis and use this on it then use the .adt adder to make the whole continent covered in water at the height I want. That way when ever I do an edit with Noggit and save, I can just drop the edited .adt files onto this and walla, got my ocean back without having to load up everything one by one in allwater.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [Question] about AllOcean3.0
« Reply #4 on: June 16, 2014, 09:32:30 am »
Try to just remove the function.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
Re: [Solved] about AllOcean3.0
« Reply #5 on: June 17, 2014, 01:33:55 am »
Quote from: "schlumpf"
Try to just remove the function.

hhmmm tried this and didn't work :(... well just strted from scratch again anyway =D... at 0 height lol so will just use it the way it is, thank for the help that was offered though =D

Much appreciated
« Last Edit: January 01, 1970, 01:00:00 am by Admin »