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: Need a c++ Coders Help =D  (Read 1980 times)

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
Need a c++ Coders Help =D
« on: December 13, 2014, 03:49:01 pm »
I love AllOcean3.0, I just have one problem with it.... It does what it is suppose to do, just it leaves some cracks up against the land where its empty space and water missing. To fix this I want AllOcean3.0 to fill in from a height of zero where there is land plus 1 chunk into the land.

Basically how do I make it fill 1 chunk in further then what it does. Here is the code below

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 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;
}


I am not a coder just to say right off which is why I am asking on the forum, I can compile this just fine and it works fine, just want to make that tiny edit to it.

Any help would be greatly appreciated =D

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

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: Need a c++ Coders Help =D
« Reply #1 on: December 13, 2014, 11:38:44 pm »
The error is in here:
Quote
Code: [Select]
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  )
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
Re: Need a c++ Coders Help =D
« Reply #2 on: January 16, 2015, 08:24:06 pm »
Quote from: "schlumpf"
The error is in here:
Quote
Code: [Select]
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  )


I still can't seem to figure out what the error is (math is really not my strong suit, which for a coder seems to be a must .../hits head on metal beam). So I give lol, could you be a little more precise on what the error is :P?

Been tinkering with that section of code ever since you answered and still a no go :(
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

phantomx

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 615
    • View Profile
Re: Need a c++ Coders Help =D
« Reply #3 on: January 16, 2015, 10:30:38 pm »
Quote from: "Kranimal"
Quote from: "schlumpf"
The error is in here:
Quote
Code: [Select]
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  )


I still can't seem to figure out what the error is (math is really not my strong suit, which for a coder seems to be a must .../hits head on metal beam). So I give lol, could you be a little more precise on what the error is :P?

Been tinkering with that section of code ever since you answered and still a no go :(

Look closer, it's staring you in the face.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »
[wimg]http://i.imgur.com/6fxUQL1.gif[/wimg]

Kranimal

  • Registred Member
  • Loreweaver
  • *****
  • Posts: 84
    • View Profile
Re: Need a c++ Coders Help =D
« Reply #4 on: January 16, 2015, 11:22:31 pm »
Quote from: "phantomx"
Quote from: "Kranimal"
Quote from: "schlumpf"
The error is in here:
Quote
Code: [Select]
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  )


I still can't seem to figure out what the error is (math is really not my strong suit, which for a coder seems to be a must .../hits head on metal beam). So I give lol, could you be a little more precise on what the error is :P?

Been tinkering with that section of code ever since you answered and still a no go :(

Look closer, it's staring you in the face.

I have tried so many different variations of this section of code for over a month no that I couldn't even tell you which ones I have and have not tried. (except for the correct one of course lol).

The one I do remember is that

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  )

is suppose to be

if((baselevel - getHeightValue2(j*8+k)) >= baselevel
                 || (baselevel - getHeightValue(j*8+k)) >= baselevel
                 || (baselevel - getHeightValue(j*8+1+k)) >= baselevel
                 || (baselevel - getHeightValue((j+1)*8+k)) >= baselevel
                 || (baselevel - getHeightValue((j+1)*8+1+k)) >= baselevel  )

I think anyway lol. So if I want to change what it does do I change

if((baselevel - getHeightValue2(j*8+k)) >= baselevel

to one of the 4 options below it?

example if((baselevel - getHeightValue((j+1)*8+1+k)) >= baselevel

or am I WWAAAYYYYYYYYY of base here lol?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

phantomx

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 615
    • View Profile
Re: Need a c++ Coders Help =D
« Reply #5 on: January 16, 2015, 11:25:06 pm »
Quote from: "Kranimal"
Quote from: "phantomx"
Quote from: "Kranimal"
Quote from: "schlumpf"

I think anyway lol. So if I want to change what it does do I change

if((baselevel - getHeightValue2(j*8+k)) >= baselevel

to one of the 4 options below it?

example if((baselevel - getHeightValue((j+1)*8+1+k)) >= baselevel

or am I WWAAAYYYYYYYYY of base here lol?

Way off, you're not looking close enough.

Try this look at the rest of the code and then go back and compare and see if you can notice anything missing.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »
[wimg]http://i.imgur.com/6fxUQL1.gif[/wimg]

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: Need a c++ Coders Help =D
« Reply #6 on: January 17, 2015, 01:18:14 am »
Quote from: "phantomx"
Quote from: "Kranimal"
Quote from: "phantomx"
Quote from: "Kranimal"
Quote from: "schlumpf"

I think anyway lol. So if I want to change what it does do I change

if((baselevel - getHeightValue2(j*8+k)) >= baselevel

to one of the 4 options below it?

example if((baselevel - getHeightValue((j+1)*8+1+k)) >= baselevel

or am I WWAAAYYYYYYYYY of base here lol?

Way off, you're not looking close enough.

Try this look at the rest of the code and then go back and compare and see if you can notice anything missing.

Tell people what's wrong or shut up, thanks. Tbh, I don't even know what is wrong myself, else I had fixed it years ago.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »