Skip to content

Instantly share code, notes, and snippets.

@CryZe
Created April 16, 2020 22:12
Show Gist options
  • Select an option

  • Save CryZe/005eb72492bf46209db7adca4baff9fe to your computer and use it in GitHub Desktop.

Select an option

Save CryZe/005eb72492bf46209db7adca4baff9fe to your computer and use it in GitHub Desktop.
undefined4 dSeaFightGame_info_c_init(int this,int param_2,int param_3)
{
int y;
undefined *puVar1;
int x;
int iVar2;
x = 0;
y = 0;
do {
puVar1 = (undefined *)(this + y);
iVar2 = 8;
do {
*puVar1 = 0;
puVar1 = puVar1 + 1;
iVar2 = iVar2 + -1;
} while (iVar2 != 0);
x = x + 1;
y = y + 8;
} while (x < 8);
*(undefined *)(this + 0x7d) = (char)param_2;
*(undefined *)(this + 0x7e) = 0;
if (param_3 == 2) {
*(undefined *)(this + 0x7c) = 2;
dSeaFightGame_info_c_put_ship(this,0,2);
dSeaFightGame_info_c_put_ship(this,1,3);
}
else {
if (param_3 < 2) {
if (0 < param_3) {
*(undefined *)(this + 0x7c) = 1;
dSeaFightGame_info_c_put_ship(this,0,2);
}
}
else {
if (param_3 < 4) {
*(undefined *)(this + 0x7c) = 3;
dSeaFightGame_info_c_put_ship(this,0,2);
dSeaFightGame_info_c_put_ship(this,1,3);
dSeaFightGame_info_c_put_ship(this,2,4);
}
}
}
*(undefined4 *)(this + 0x80) = 0;
return 1;
}
void dSeaFightGame_info_c_put_ship(undefined4 this,undefined4 y,uint x)
{
uint should_search_vertically;
uint rand_y;
uint rand_x_ok;
Board *board_ptr;
uint uVar1;
char *cell_ptr;
undefined1 *puVar2;
Board *local_r3_388;
uint uVar3;
int iVar4;
int iVar5;
int iVar6;
char cVar7;
undefined uVar8;
char cVar9;
undefined uVar10;
uint search_count_byte;
double rand_y_double;
double rand_x_double;
undefined8 uVar11;
uVar11 = FUN_80326934();
board_ptr = (Board *)((ulonglong)uVar11 >> 0x20);
uVar3 = (uint)uVar11;
search_count_byte = x & 0xff;
do {
rand_y_double = (double)cM_rndF(f32)((double)@4056);
iVar4 = (int)(short)(int)rand_y_double >> 0x1f;
should_search_vertically = ((int)(short)(int)rand_y_double & 1U ^ -iVar4) + iVar4 & 0xff;
rand_y_double = (double)cM_rndF(f32)((double)@4057);
rand_y = (int)rand_y_double & 0xff;
rand_x_double = (double)cM_rndF(f32)((double)@4057);
rand_x_ok = (int)rand_x_double & 0xff;
uVar1 = dSeaFightGame_info_c_checkPutShip(
(board_ptr,rand_y,rand_x_ok,search_count_byte,should_search_vertically);
} while ((uVar1 & 0xff) == 0);
uVar10 = (undefined)rand_y;
uVar8 = (undefined)x;
cVar9 = (char)rand_x_ok;
if (should_search_vertically == 0) {
cVar7 = '\0';
iVar4 = 0;
iVar5 = (uVar3 & 0xff) * 0xf;
cell_ptr = &board_ptr->cells + ((int)rand_y_double & 0xffU) * 8 + rand_x_ok;
while (search_count_byte != 0) {
(&board_ptr->cells + iVar4 + iVar5)[0x40] = uVar10;
(&board_ptr->cells + iVar4 + iVar5)[0x41] = cVar9 + cVar7;
*cell_ptr = (char)(uVar3 & 0xff) + 'f';
cVar7 = cVar7 + '\x01';
cell_ptr = cell_ptr + 1;
iVar4 = iVar4 + 2;
search_count_byte = search_count_byte - 1;
}
puVar2 = &board_ptr->cells + iVar5;
puVar2[0x4b] = uVar10;
puVar2[0x4c] = cVar9;
puVar2[0x4d] = 0;
puVar2[0x4e] = uVar8;
}
else {
iVar4 = 0;
iVar5 = 0;
iVar6 = (uVar3 & 0xff) * 0xf;
while (search_count_byte != 0) {
(&board_ptr->cells + iVar5 + iVar6)[0x40] = (char)(rand_y + iVar4);
(&board_ptr->cells + iVar5 + iVar6)[0x41] = cVar9;
(&board_ptr->cells)[(rand_y + iVar4) * 8 + rand_x_ok] = (char)(uVar3 & 0xff) + 'f';
iVar4 = iVar4 + 1;
iVar5 = iVar5 + 2;
search_count_byte = search_count_byte - 1;
}
puVar2 = &board_ptr->cells + iVar6;
puVar2[0x4b] = uVar10;
puVar2[0x4c] = cVar9;
puVar2[0x4d] = uVar8;
puVar2[0x4e] = 0;
}
local_r3_388 = (Board *)(&board_ptr->cells + (uVar3 & 0xff) * 0xf);
*(undefined *)&local_r3_388->field_0x48 = uVar8;
*(undefined *)&local_r3_388->field_0x49 = uVar8;
FUN_80326980(1);
return;
}
int dSeaFightGame_info_c_checkPutShip(
(Board *this,int y,int x,int search_count,int should_search_vertically)
{
byte *cell_ptr;
int index;
if (should_search_vertically == 0) {
cell_ptr = &this->cells + x + y * 8;
if (0 < search_count) {
do {
if (((7 < y) || (7 < x)) || (100 < *cell_ptr)) {
return 0;
}
x = x + 1;
cell_ptr = cell_ptr + 1;
search_count = search_count + -1;
} while (search_count != 0);
}
}
else {
index = y << 3;
if (0 < search_count) {
do {
if (((7 < y) || (7 < x)) || (100 < (byte)(&this->cells)[index + x])) {
return 0;
}
y = y + 1;
index = index + 8;
search_count = search_count + -1;
} while (search_count != 0);
}
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment