// // Generated by dtk // Translation Unit: d_seafightgame.cpp // #include "d/dolzel.h" // IWYU pragma: keep #include "d/d_seafightgame.h" #include "SSystem/SComponent/c_math.h" /* 800C1F90-800C20B0 .text init__20dSeaFightGame_info_cFii */ int dSeaFightGame_info_c::init(int i_bulletNum, int i_scenario) { for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { mGrid[x][y] = 0; } } mBulletNum = i_bulletNum; mScore = 0; switch (i_scenario) { case 1: mAliveShipNum = 1; put_ship(0, 2); break; case 2: mAliveShipNum = 2; put_ship(0, 2); put_ship(1, 3); break; case 3: mAliveShipNum = 3; put_ship(0, 2); put_ship(1, 3); put_ship(2, 4); break; } mDeadShipNum = 0; return 1; } /* 800C20B0-800C225C .text put_ship__20dSeaFightGame_info_cFUcUc */ int dSeaFightGame_info_c::put_ship(u8 i_shipNo, u8 i_shipSize) { u8 x; u8 y; u8 direction; do { direction = (s16)cM_rndF(1000.0f) % 2; x = (int)cM_rndF(8.0f); y = (int)cM_rndF(8.0f); } while (!checkPutShip(x, y, i_shipSize, direction)); if (direction == 0) { for (int i = 0; i < i_shipSize; i++) { mShips[i_shipNo].m_pos[i][0] = x; mShips[i_shipNo].m_pos[i][1] = y + i; mGrid[x][y + i] = i_shipNo + 102; } mShips[i_shipNo].field_0xb = x; mShips[i_shipNo].field_0xc = y; mShips[i_shipNo].field_0xd = 0; mShips[i_shipNo].field_0xe = i_shipSize; } else { for (int i = 0; i < i_shipSize; i++) { mShips[i_shipNo].m_pos[i][0] = x + i; mShips[i_shipNo].m_pos[i][1] = y; mGrid[x + i][y] = i_shipNo + 102; } mShips[i_shipNo].field_0xb = x; mShips[i_shipNo].field_0xc = y; mShips[i_shipNo].field_0xd = i_shipSize; mShips[i_shipNo].field_0xe = 0; } mShips[i_shipNo].field_0x8 = i_shipSize; mShips[i_shipNo].field_0x9 = i_shipSize; return 1; } /* 800C225C-800C22FC .text checkPutShip__20dSeaFightGame_info_cFiiii */ bool dSeaFightGame_info_c::checkPutShip(int i_x, int i_y, int i_shipSize, int i_direction) { if (i_direction == 0) { for (int i = 0; i < i_shipSize; i++) { if (i_x > 7 || i_y > 7 || mGrid[i_x][i_y] > 100) { return false; } i_y++; } } else { for (int i = 0; i < i_shipSize; i++) { if (i_x > 7 || i_y > 7 || mGrid[i_x][i_y] > 100) { return false; } i_x++; } } return true; } /* 800C22FC-800C239C .text attack__20dSeaFightGame_info_cFUcUc */ int dSeaFightGame_info_c::attack(u8 i_x, u8 i_y) { int rt = -1; u8 uvar1 = mGrid[i_x][i_y]; if (uvar1 == 0) { mGrid[i_x][i_y] = 1; } else if (uvar1 > 100) { rt = uvar1 - 102; mShips[rt].field_0x9--; if (mShips[rt].field_0x9 == 0) { mAliveShipNum--; mDeadShipNum++; } mGrid[i_x][i_y] = 3; } else { return -2; } mBulletNum--; mScore++; return rt; } struct offset_s { int x; int y; }; static const offset_s m_offset_1[] = { {-1, 1}, {0, 1}, {1, 1}, {-1, 0}, {1, 0}, {-1, -1}, {0, -1}, {1, -1}, {0, 0}, }; static const offset_s m_offset_2[] = { {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {-2, 1}, {2, 1}, {-2, 0}, {2, 0}, {-2, -1}, {2, -1}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {0, 0}, }; static const offset_s m_offset_3[] = { {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, {-3, 2}, {3, 2}, {-3, 1}, {3, 1}, {-3, 0}, {3, 0}, {-3, -1}, {3, -1}, {-3, -2}, {3, -2}, {-3, -3}, {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, {0, 0}, }; static const offset_s m_offset_4[] = { {-4, 4}, {-3, 4}, {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {-4, 3}, {4, 3}, {-4, 2}, {4, 2}, {-4, 1}, {4, 1}, {-4, 0}, {4, 0}, {-4, -1}, {4, -1}, {-4, -2}, {4, -2}, {-4, -3}, {4, -3}, {-4, -4}, {-3, -4}, {-2, -4}, {-1, -4}, {0, -4}, {1, -4}, {2, -4}, {3, -4}, {4, -4}, {0, 0}, }; static const offset_s m_offset_5[] = { {-5, 5}, {-4, 5}, {-3, 5}, {-2, 5}, {-1, 5}, {0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {5, 5}, {-5, 4}, {5, 4}, {-5, 3}, {5, 3}, {-5, 2}, {5, 2}, {-5, 1}, {5, 1}, {-5, 0}, {5, 0}, {-5, -1}, {5, -1}, {-5, -2}, {5, -2}, {-5, -3}, {5, -3}, {-5, -4}, {-5, -4}, // @bug: {-5, -4} appears twice. This second one should be {5, -4} instead. {-5, -5}, {-4, -5}, {-3, -5}, {-2, -5}, {-1, -5}, {0, -5}, {1, -5}, {2, -5}, {3, -5}, {4, -5}, {5, -5}, {0, 0}, }; static const offset_s m_offset_6[] = { {-6, 6}, {-5, 6}, {-4, 6}, {-3, 6}, {-2, 6}, {-1, 6}, {0, 6}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}, {6, 6}, {-6, 5}, {6, 5}, {-6, 4}, {6, 4}, {-6, 3}, {6, 3}, {-6, 2}, {6, 2}, {-6, 1}, {6, 1}, {-6, 0}, {6, 0}, {-6, -1}, {6, -1}, {-6, -2}, {6, -2}, {-6, -3}, {6, -3}, {-6, -4}, {6, -4}, {-6, -5}, {6, -5}, {-6, -6}, {-5, -6}, {-4, -6}, {-3, -6}, {-2, -6}, {-1, -6}, {0, -6}, {1, -6}, {2, -6}, {3, -6}, {4, -6}, {5, -6}, {6, -6}, {0, 0}, }; static const offset_s m_offset_7[] = { {-7, 7}, {-6, 7}, {-5, 7}, {-4, 7}, {-3, 7}, {-2, 7}, {-1, 7}, {0, 7}, {1, 7}, {2, 7}, {3, 7}, {4, 7}, {5, 7}, {6, 7}, {7, 7}, {-7, 6}, {7, 6}, {-7, 5}, {7, 5}, {-7, 4}, {7, 4}, {-7, 3}, {7, 3}, {-7, 2}, {7, 2}, {-7, 1}, {7, 1}, {-7, 0}, {7, 0}, {-7, -1}, {7, -1}, {-7, -2}, {7, -2}, {-7, -3}, {7, -3}, {-7, -4}, {7, -4}, {-7, -5}, {7, -5}, {-7, -6}, {7, -6}, {-7, -7}, {-6, -7}, {-5, -7}, {-4, -7}, {-3, -7}, {-2, -7}, {-1, -7}, {0, -7}, {1, -7}, {2, -7}, {3, -7}, {4, -7}, {5, -7}, {6, -7}, {7, -7}, {0, 0}, }; static const offset_s* offset_tbl_p[] = { m_offset_1, m_offset_2, m_offset_3, m_offset_4, m_offset_5, m_offset_6, m_offset_7, }; int dSeaFightGame_info_c::getNearEnemy(int i_x, int i_y) { int x; int y; for (int i = 0; i < ARRAY_SIZE(offset_tbl_p); i++) { const offset_s* offset = offset_tbl_p[i]; for (; offset->x != 0 || offset->y != 0; offset++) { x = i_x + offset->x; y = i_y + offset->y; if (x < 0) { continue; } if (y < 0) { continue; } if (x >= 8) { continue; } if (y >= 8) { continue; } if (mGrid[x][y] > 100) { return i + 1; } } } return 0; }