Add SQUARE macro to improve readibility for distances

This commit is contained in:
LagoLunatic
2025-08-08 21:51:30 -04:00
parent b24d8574cd
commit 5802571a56
37 changed files with 107 additions and 106 deletions
+2
View File
@@ -23,6 +23,8 @@
#define offsetof(type, member) ((size_t) & (((type*)0)->member))
#endif
#define SQUARE(x) ((x) * (x))
#ifdef __MWERKS__
#define GLUE(a, b) a##b
#define GLUE2(a, b) GLUE(a, b)
+2 -2
View File
@@ -1660,7 +1660,7 @@ BOOL daAgbsw0_c::HitCheck(fopAc_ac_c* param_1) {
f32 x_diff = std::abs(param_1->current.pos.x - current.pos.x);
if(x_diff < scale.x) {
f32 z_diff = fabs(param_1->current.pos.z - current.pos.z);
if(z_diff < scale.x && x_diff * x_diff + z_diff * z_diff < scale.x * scale.x) {
if(z_diff < scale.x && SQUARE(x_diff) + SQUARE(z_diff) < SQUARE(scale.x)) {
return true;
}
}
@@ -1685,7 +1685,7 @@ BOOL daAgbsw0_c::HitCheck(cXyz param_1, f32 param_2) {
f32 x_diff = fabs(param_1.x - current.pos.x);
if(x_diff < scale.x) {
f32 z_diff = fabs(param_1.z - current.pos.z);
if(z_diff < scale.x && x_diff * x_diff + z_diff * z_diff < scale.x * scale.x) {
if(z_diff < scale.x && SQUARE(x_diff) + SQUARE(z_diff) < SQUARE(scale.x)) {
return true;
}
}
+1 -1
View File
@@ -746,7 +746,7 @@ static void action_modoru_move(am_class* i_this) {
i_this->mTargetAngleY = cM_atan2s(xDistToSpawn, zDistToSpawn);
}
f32 xzDist = std::sqrtf(xDistToSpawn*xDistToSpawn + zDistToSpawn*zDistToSpawn);
f32 xzDist = std::sqrtf(SQUARE(xDistToSpawn) + SQUARE(zDistToSpawn));
if (xzDist < 20.0f) {
i_this->mTargetAngleY = i_this->mSpawnRotY;
actor->speedF = 0.0f;
+1 -1
View File
@@ -2218,7 +2218,7 @@ static BOOL daBb_Execute(bb_class* i_this) {
f32 yDiff = (player->current.pos.y + 100.0f) - i_this->actor.current.pos.y;
f32 zDiff = player->current.pos.z - i_this->actor.current.pos.z;
i_this->unk_33C = std::sqrtf(xDiff * xDiff + zDiff * zDiff);
i_this->unk_33C = std::sqrtf(SQUARE(xDiff) + SQUARE(zDiff));
i_this->unk_336 = cM_atan2s(xDiff, zDiff);
i_this->unk_338 = -cM_atan2s(yDiff, i_this->unk_33C);
+1 -1
View File
@@ -646,7 +646,7 @@ namespace daBomb2 {
f32 f30 = attr().field_0x40;
cXyz sp48 = *mSph.GetTgRVecP();
f32 f31 = sp48.abs2();
if (f31 > f30*f30) {
if (f31 > SQUARE(f30)) {
sp48 *= f30 / std::sqrtf(f31);
}
cCcD_ShapeAttr* hitShapeAttr = hitObj->GetShapeAttr();
+1 -1
View File
@@ -1119,7 +1119,7 @@ void daBomb_c::set_wind_vec() {
return;
cXyz sp48 = *mSph.GetTgRVecP();
f32 f31 = sp48.abs2();
if (f31 > 180.0f*180.0f) {
if (f31 > SQUARE(180.0f)) {
sp48 *= 180.0f / std::sqrtf(f31);
}
cCcD_ShapeAttr* hitShapeAttr = hitObj->GetShapeAttr();
+2 -2
View File
@@ -1147,8 +1147,8 @@ static void damage_check(bst_class* i_this) {
cXyz player_vec = i_this->current.pos - player->current.pos;
i_this->mHurtRecoilAngle1 = cM_atan2s(player_vec.x, player_vec.z);
f32 xz = player_vec.x * player_vec.x + player_vec.z * player_vec.z;
i_this->mHurtRecoilAngle2 = -cM_atan2s(player_vec.y, std::sqrtf(xz));
f32 xz2 = SQUARE(player_vec.x) + SQUARE(player_vec.z);
i_this->mHurtRecoilAngle2 = -cM_atan2s(player_vec.y, std::sqrtf(xz2));
i_this->speedF = 0.0f;
+3 -3
View File
@@ -253,9 +253,9 @@ const char* daDoor10_c::getDzbName() {
f32 daDoor10_c::getSize2X() {
switch (getType()) {
case 3:
return 15.0f * 15.0f;
return SQUARE(15.0f);
}
return 110.0f * 110.0f;
return SQUARE(110.0f);
}
const char daDoor10_c::M_arcname[] = "door10";
@@ -382,7 +382,7 @@ void daDoor10_c::setEventPrm() {
}
}
if (checkArea(getSize2X(), 110.0f * 110.0f, 250.0f * 250.0f)) {
if (checkArea(getSize2X(), SQUARE(110.0f), SQUARE(250.0f))) {
eventInfo.setEventId(mEventIdx[m2C6]);
eventInfo.setToolId(mToolId[m2C6]);
eventInfo.onCondition(dEvtCnd_CANDOOR_e);
+1 -1
View File
@@ -288,7 +288,7 @@ void daFire_c::ctrlEffect() {
field_0x8E0 = *field_0x2CC[0].GetTgRVecP();
f32 f2 = 1000.0f;
f32 dist_sq = (field_0x8E0.x * field_0x8E0.x + field_0x8E0.z * field_0x8E0.z) / f2;
f32 dist_sq = (SQUARE(field_0x8E0.x) + SQUARE(field_0x8E0.z)) / f2;
field_0x8E0.y = sqrt(dist_sq);
if (!field_0x8E0.normalizeRS()) {
field_0x8E0.set(0.0f, 1.0f, 0.0f);
+1 -1
View File
@@ -145,7 +145,7 @@ void daKnob00_c::setEventPrm() {
m2C6 = 9;
}
if (!checkArea(80.0f * 80.0f, 110.0 * 110.0f, 250.0f * 250.0f)) {
if (!checkArea(SQUARE(80.0f), SQUARE(110.0f), SQUARE(250.0f))) {
offFlag(4);
} else {
eventInfo.setEventId(mEventIdx[m2C6]);
+4 -4
View File
@@ -36,7 +36,7 @@ void draw_SUB(ks_class* i_this) {
cXyz local_24 = dComIfGp_getCamera(0)->mLookat.mEye - i_this->current.pos;
int iVar3 = cM_atan2s(local_24.x, local_24.z);
int iVar4 = (s16)-cM_atan2s(local_24.y, std::sqrtf(local_24.x * local_24.x + local_24.z * local_24.z));
int iVar4 = (s16)-cM_atan2s(local_24.y, std::sqrtf(SQUARE(local_24.x) + SQUARE(local_24.z)));
f32 fVar1 = 0.0f;
if (i_this->m2D0) {
@@ -233,10 +233,10 @@ BOOL shock_damage_check(ks_class* i_this) {
mSwordTopPos.y -= i_this->current.pos.y;
mSwordTopPos.z -= i_this->current.pos.z;
float distXZ = std::sqrtf(mSwordTopPos.x * mSwordTopPos.x + mSwordTopPos.z * mSwordTopPos.z);
float distXZ = std::sqrtf(SQUARE(mSwordTopPos.x) + SQUARE(mSwordTopPos.z));
if (distXZ < 200.0f) {
if (std::sqrtf(mSwordTopPos.y * mSwordTopPos.y) < 40.0f) {
if (std::sqrtf(SQUARE(mSwordTopPos.y)) < 40.0f) {
i_this->mAction = 3;
i_this->mMode = 32;
@@ -883,7 +883,7 @@ void action_omoi(ks_class* i_this) {
local_1c.z = REG12_F(16) + 10.0f;
}
if (std::sqrtf(mpCurPlayerActor->speed.x * mpCurPlayerActor->speed.x + mpCurPlayerActor->speed.y * mpCurPlayerActor->speed.y + mpCurPlayerActor->speed.z * mpCurPlayerActor->speed.z) < REG12_F(17) + 8.0f) {
if (std::sqrtf(SQUARE(mpCurPlayerActor->speed.x) + SQUARE(mpCurPlayerActor->speed.y) + SQUARE(mpCurPlayerActor->speed.z)) < REG12_F(17) + 8.0f) {
local_1c.setall(REG12_F(18) + 8.0f);
f32 x = a_this->current.pos.x - local_10.x;
+2 -2
View File
@@ -321,7 +321,7 @@ BOOL daNh_c::checkEscapeEnd() {
setAction(&daNh_c::waitAction, NULL);
return TRUE;
}
if (homeDelta.abs2XZ() > l_HIO.prm.mMaxHomeDist*l_HIO.prm.mMaxHomeDist) {
if (homeDelta.abs2XZ() > SQUARE(l_HIO.prm.mMaxHomeDist)) {
setAction(&daNh_c::returnAction, NULL);
return TRUE;
}
@@ -366,7 +366,7 @@ BOOL daNh_c::returnAction(void*) {
} else {
s16 targetAngle = cLib_targetAngleY(&current.pos, &home.pos);
cXyz homeDelta = home.pos - current.pos;
if (homeDelta.abs2XZ() < l_HIO.prm.mMaxHomeDist*l_HIO.prm.mMaxHomeDist) {
if (homeDelta.abs2XZ() < SQUARE(l_HIO.prm.mMaxHomeDist)) {
s16 angle = targetAngle - fopAcM_searchPlayerAngleY(this);
if (abs(angle) < 0x1000) {
if (angle < 0) {
+13 -13
View File
@@ -701,7 +701,7 @@ BOOL daNpc_Cb1_c::flyAction(BOOL param_1, f32 param_2, s16 param_3, BOOL param_4
s16 angle = cM_atan2s(temp.x, temp.z);
f32 temp6 = std::sqrtf(temp.x * temp.x + temp.z * temp.z);
f32 temp6 = std::sqrtf(SQUARE(temp.x) + SQUARE(temp.z));
if (temp6 > temp5) {
temp6 = temp5;
}
@@ -732,7 +732,7 @@ BOOL daNpc_Cb1_c::flyAction(BOOL param_1, f32 param_2, s16 param_3, BOOL param_4
current.angle.y = cM_atan2s(speed.x, speed.z);
speedF = std::sqrtf(speed.x * speed.x + speed.z * speed.z);
speedF = std::sqrtf(SQUARE(speed.x) + SQUARE(speed.z));
if(speed.y > ySpeedLimit) {
speed.y = ySpeedLimit;
}
@@ -1663,17 +1663,17 @@ BOOL daNpc_Cb1_c::waitNpcAction(void* param_1) {
cLib_offBit<u32>(attention_info.flags, fopAc_Attn_ACTION_SPEAK_e | fopAc_Attn_LOCKON_TALK_e);
}
f32 dist = fopAcM_searchActorDistance2(this, dComIfGp_getPlayer(0));
f32 dist_sq = fopAcM_searchActorDistance2(this, dComIfGp_getPlayer(0));
if(!checkNpcCallCommand()) {
if(dComIfGs_isEventBit(0x1610) && dist < l_HIO.field_0xC0 * l_HIO.field_0xC0) {
if(dComIfGs_isEventBit(0x1610) && dist_sq < SQUARE(l_HIO.field_0xC0)) {
daPy_getPlayerLinkActorClass()->onNpcCall();
temp = TRUE;
}
}
else {
if(dist >= l_HIO.mPlayerChaseDistance * l_HIO.mPlayerChaseDistance) {
if(dist_sq >= SQUARE(l_HIO.mPlayerChaseDistance)) {
setNpcAction(&daNpc_Cb1_c::searchNpcAction, NULL);
}
@@ -1935,7 +1935,7 @@ BOOL daNpc_Cb1_c::routeCheck(f32 param_1, s16* param_2) {
return TRUE;
}
if(param_1 > (600.0f * 600.0f)) {
if(param_1 > SQUARE(600.0f)) {
return FALSE;
}
@@ -1985,19 +1985,19 @@ BOOL daNpc_Cb1_c::searchNpcAction(void*) {
fopAc_ac_c* pPlayer = dComIfGp_getPlayer(0);
BOOL door = pPlayer->eventInfo.checkCommandDoor();
f32 dist1 = fopAcM_searchPlayerDistance2(this);
f32 dist2 = fopAcM_searchPlayerDistanceXZ2(this);
f32 dist_sq = fopAcM_searchPlayerDistance2(this);
f32 dist_xz_sq = fopAcM_searchPlayerDistanceXZ2(this);
if(!door && dist1 < l_HIO.mPlayerChaseDistance * l_HIO.mPlayerChaseDistance) {
if(!door && dist_sq < SQUARE(l_HIO.mPlayerChaseDistance)) {
temp2 = 0.0f;
}
else {
temp2 = l_HIO.mChaseDistScale * std::sqrtf(dist2);
temp2 = l_HIO.mChaseDistScale * std::sqrtf(dist_xz_sq);
temp2 = cLib_maxLimit(temp2, l_HIO.mMaxWalkSpeed);
}
temp = fopAcM_searchPlayerAngleY(this);
if(door || !routeCheck(dist2, &temp) || dComIfGp_checkPlayerStatus0(0, daPyStts0_UNK2000000_e | daPyStts0_UNK100_e | daPyStts0_UNK1_e) || ((daPy_py_c*)pPlayer)->checkAttentionLock()) {
if(door || !routeCheck(dist_xz_sq, &temp) || dComIfGp_checkPlayerStatus0(0, daPyStts0_UNK2000000_e | daPyStts0_UNK100_e | daPyStts0_UNK1_e) || ((daPy_py_c*)pPlayer)->checkAttentionLock()) {
temp2 = 0.0f;
if(speedF == 0.0f) {
@@ -2012,7 +2012,7 @@ BOOL daNpc_Cb1_c::searchNpcAction(void*) {
temp = current.angle.y;
}
if(dist2 < (400.0f * 400.0f) && cLib_distanceAngleS(shape_angle.y, temp) < 0x2000 && std::fabsf(fopAcM_searchPlayerDistanceY(this)) < 100.0f) {
if(dist_xz_sq < SQUARE(400.0f) && cLib_distanceAngleS(shape_angle.y, temp) < 0x2000 && std::fabsf(fopAcM_searchPlayerDistanceY(this)) < 100.0f) {
onPlayerFind();
}
@@ -2537,7 +2537,7 @@ BOOL daNpc_Cb1_c::chkAttention(f32 param_1, s32 param_2) {
temp.x = dComIfGp_getPlayer(0)->current.pos.x - current.pos.x;
temp.z = dComIfGp_getPlayer(0)->current.pos.z - current.pos.z;
f32 diff = std::sqrtf(temp.x * temp.x + temp.z * temp.z);
f32 diff = std::sqrtf(SQUARE(temp.x) + SQUARE(temp.z));
s16 angle = cM_atan2s(temp.x, temp.z);
if(mHasAttention) {
+1 -1
View File
@@ -1046,7 +1046,7 @@ BOOL daNpc_kam_c::actionDescendEvent(int evtStaffId) {
}
cXyz delta = linkHeadTopPos - current.pos;
if (delta.abs2XZ() < 100.0f*100.0f) {
if (delta.abs2XZ() < SQUARE(100.0f)) {
return TRUE;
}
+4 -4
View File
@@ -1197,15 +1197,15 @@ void daNpc_Md_c::NpcCall(int* r31) {
if (!dComIfGs_isEventBit(0x1620)) {
return;
}
f32 dist2 = fopAcM_searchPlayerDistance2(this);
f32 dist_sq = fopAcM_searchPlayerDistance2(this);
if (!checkNpcCallCommand()) {
if (dist2 < l_HIO.m0C8*l_HIO.m0C8) {
if (dist_sq < SQUARE(l_HIO.m0C8)) {
daPy_getPlayerLinkActorClass()->onNpcCallCommand();
*r31 = 1;
}
} else {
f32 temp = 2.0f*l_HIO.m0C4;
if (dist2 >= temp*temp) {
if (dist_sq >= temp*temp) {
setNpcAction(&daNpc_Md_c::searchNpcAction);
}
*r31 = 1;
@@ -1362,7 +1362,7 @@ BOOL daNpc_Md_c::waitNpcAction(void*) {
f32 playerDistY = link->current.pos.y - current.pos.y;
f32 f3 = l_HIO.m0BC;
f32 f4 = l_HIO.m0C0;
if (playerDistXZ2 < l_HIO.m0CC * l_HIO.m0CC && playerDistY < f3 && playerDistY > f4) {
if (playerDistXZ2 < SQUARE(l_HIO.m0CC) && playerDistY < f3 && playerDistY > f4) {
mCurEventMode = 0xB;
}
} else {
+6 -6
View File
@@ -713,15 +713,15 @@ BOOL daNpc_Os_c::waitNpcAction(void*) {
cLib_offBit<u32>(attention_info.flags, (fopAc_Attn_LOCKON_TALK_e | fopAc_Attn_ACTION_SPEAK_e));
f32 dist = fopAcM_searchPlayerDistance2(this);
f32 dist_sq = fopAcM_searchPlayerDistance2(this);
if(!checkNpcCallCommand()) {
if(dist < l_HIO.field_0x64 * l_HIO.field_0x64) {
if(dist_sq < SQUARE(l_HIO.field_0x64)) {
daPy_getPlayerLinkActorClass()->onNpcCallCommand();
}
}
else {
if(wakeupCheck()) {
if(dist >= l_HIO.field_0x60 * l_HIO.field_0x60) {
if(dist_sq >= SQUARE(l_HIO.field_0x60)) {
setNpcAction(&daNpc_Os_c::searchNpcAction, 0);
}
}
@@ -1064,16 +1064,16 @@ BOOL daNpc_Os_c::searchNpcAction(void*) {
daPy_py_c* player = daPy_getPlayerActorClass();
BOOL door = player->eventInfo.checkCommandDoor();
f32 dist = fopAcM_searchPlayerDistanceXZ2(this);
f32 dist_sq = fopAcM_searchPlayerDistanceXZ2(this);
f32 temp;
if (dist < l_HIO.field_0x60 * l_HIO.field_0x60) {
if (dist_sq < SQUARE(l_HIO.field_0x60)) {
temp = 0.0f;
} else {
temp = l_HIO.field_0xA8;
}
s16 angle, adjustedAngle;
angle = adjustedAngle = fopAcM_searchPlayerAngleY(this);
BOOL temp3 = routeCheck(dist, &adjustedAngle) && cLib_distanceAngleS(angle, adjustedAngle) <= 0x2000;
BOOL temp3 = routeCheck(dist_sq, &adjustedAngle) && cLib_distanceAngleS(angle, adjustedAngle) <= 0x2000;
if(door || !temp3 || (dComIfGp_checkPlayerStatus0(0, daPyStts0_UNK2000000_e | daPyStts0_UNK100_e | daPyStts0_UNK1_e) || player->checkAttentionLock())) {
temp = 0.0f;
offNpcCallCommand();
+8 -8
View File
@@ -332,7 +332,7 @@ void daObjBarrel2::Act_c::co_hitCB(fopAc_ac_c* a_this, dCcD_GObjInf*, fopAc_ac_c
cXyz sp14(ship->current.pos.x - i_this->current.pos.x, 0.0f, ship->current.pos.z - i_this->current.pos.z);
cXyz sp08(ship->speed.x, 0.0f, ship->speed.z);
f32 sq = i_this->attr()->m3C * i_this->attr()->m3C;
f32 sq = SQUARE(i_this->attr()->m3C);
if (sp14.inprod(sp08) < sq) {
i_this->m470 = 1;
@@ -892,7 +892,7 @@ void daObjBarrel2::Act_c::afl_sway() {
#if VERSION == VERSION_DEMO
f32 x3;
f32 z3;
f32 sq2 = attr()->m5C * attr()->m5C;
f32 sq2 = SQUARE(attr()->m5C);
f32 x = m420.x * attr()->m68;
f32 z = m420.z * attr()->m68;
f32 sq = x * x + z * z;
@@ -923,7 +923,7 @@ void daObjBarrel2::Act_c::afl_sway() {
f32 z3;
f32 x = m420.x * attr()->m68;
f32 z = m420.z * attr()->m68;
f32 sq2 = attr()->m5C * attr()->m5C;
f32 sq2 = SQUARE(attr()->m5C);
f32 sq = x * x + z * z;
if (sq > sq2) {
@@ -952,7 +952,7 @@ void daObjBarrel2::Act_c::afl_sway() {
bool daObjBarrel2::Act_c::mine_chk_range_flash() {
daShip_c* ship = dComIfGp_getShipActor();
f32 fVar1 = attr()->m40 * attr()->m40;
f32 fVar1 = SQUARE(attr()->m40);
bool uVar2 = false;
if (ship && fopAcM_searchActorDistanceXZ2(this, ship) < fVar1) {
uVar2 = true;
@@ -964,7 +964,7 @@ bool daObjBarrel2::Act_c::mine_chk_range_flash() {
bool daObjBarrel2::Act_c::mine_chk_range_explode() {
daShip_c* ship = dComIfGp_getShipActor();
f32 fVar1 = attr()->m44 * attr()->m44;
f32 fVar1 = SQUARE(attr()->m44);
bool uVar2 = false;
if (ship && fopAcM_searchActorDistanceXZ2(this, ship) < fVar1) {
uVar2 = true;
@@ -975,7 +975,7 @@ bool daObjBarrel2::Act_c::mine_chk_range_explode() {
/* 00002A00-00002B34 .text mine_chk_range_damage__Q212daObjBarrel25Act_cFv */
bool daObjBarrel2::Act_c::mine_chk_range_damage() {
daShip_c* ship = dComIfGp_getShipActor();
f32 sq = attr()->m48 * attr()->m48;
f32 sq = SQUARE(attr()->m48);
if (ship != NULL && fopAcM_searchActorDistanceXZ2(this, ship) < sq) {
if (ship->current.pos.y < current.pos.y + attr()->m4C) {
@@ -983,7 +983,7 @@ bool daObjBarrel2::Act_c::mine_chk_range_damage() {
cXyz sp14(ship->current.pos.x - current.pos.x, 0.0f, ship->current.pos.z - current.pos.z);
cXyz sp08(ship->speed.x, 0.0f, ship->speed.z);
sq = attr()->m3C * attr()->m3C;
sq = SQUARE(attr()->m3C);
if (sp14.inprod(sp08) < sq) {
ship->onCrashFlg();
return true;
@@ -1024,7 +1024,7 @@ void daObjBarrel2::Act_c::execute_sub() {
m46D--;
}
if (m45C < attr()->m34 * attr()->m34) {
if (m45C < SQUARE(attr()->m34)) {
item_give();
}
+3 -3
View File
@@ -104,10 +104,10 @@ void* daObjCorrect::Act_c::chk_try_actor2(daObjTry::Act_c* actor, daObjTry::Type
JUT_ASSERT(346, i_sw_r_sq <= i_depression_r_sq);
if (type == actor->prm_get_type()) {
f32 dist = actor->current.pos.abs2(current.pos);
if (dist < i_depression_r_sq) {
f32 dist_sq = actor->current.pos.abs2(current.pos);
if (dist_sq < i_depression_r_sq) {
bool should_return;
if (dist < i_sw_r_sq) {
if (dist_sq < i_sw_r_sq) {
should_return = prm_get_swSave() == actor->prm_get_swSave();
} else {
should_return = false;
+1 -1
View File
@@ -184,7 +184,7 @@ void daObjIce_c::tg_hitCallback(fopAc_ac_c* a_this, dCcD_GObjInf* arg1, fopAc_ac
f32 fVar6 = i_this->m44C * (i_this->scale.x * l_co_radius_table[i]);
f32 fVar7 = i_this->m450 * (i_this->scale.y * l_co_height_table[i]);
f32 fVar5 = i_this->m44C * (i_this->scale.z * l_co_radius_table[i]);
if (y < fVar7 && ((x2 * x2) / (fVar6 * fVar6) + (z2 * z2) / (fVar5 * fVar5) < 1.0f)) {
if (y < fVar7 && (SQUARE(x2) / SQUARE(fVar6) + SQUARE(z2) / SQUARE(fVar5) < 1.0f)) {
switch (pcVar8->GetAtType()) {
case AT_TYPE_UNK20000:
case AT_TYPE_FIRE:
+7 -7
View File
@@ -189,9 +189,9 @@ namespace daObjMovebox {
M_wall_work[i].SetActorPid(movebox->base.mBsPcId);
if (dComIfG_Bgsp()->LineCross(&M_wall_work[i])) {
mWallPos[i] = M_wall_work[i].GetCross();
f32 dist = startPos.abs2(mWallPos[i]);
if (dist < mNearestWallDist) {
mNearestWallDist = dist;
f32 dist_sq = startPos.abs2(mWallPos[i]);
if (dist_sq < mNearestWallDist) {
mNearestWallDist = dist_sq;
mWallIdx = i;
}
} else {
@@ -1089,18 +1089,18 @@ namespace daObjMovebox {
}
if (mType == TYPE_METAL_BOX_WITH_SPRING) {
daObjJump::Act_c* jump = (daObjJump::Act_c*)childActor;
if (jump->current.pos.abs2(current.pos) > 0.0001f) {
if (jump->current.pos.abs2(current.pos) > SQUARE(0.01f)) {
jump->setup(&current.pos);
}
} else if (mType == TYPE_MIRROR) {
daObjMmrr::Act_c* mmrr = (daObjMmrr::Act_c*)childActor;
if (mmrr->current.pos.abs2(current.pos) > 0.0001f) {
if (mmrr->current.pos.abs2(current.pos) > SQUARE(0.01f)) {
mmrr->setup(&current.pos);
}
} else if (mType == TYPE_BLACK_BOX_WITH_MKIE) {
daObjMkie::Act_c* mkie = (daObjMkie::Act_c*)childActor;
cXyz targetPos(current.pos.x, current.pos.y + 150.0f, current.pos.z);
if (mkie->current.pos.abs2(targetPos) > 0.0001f) {
if (mkie->current.pos.abs2(targetPos) > SQUARE(0.01f)) {
mkie->setup(&targetPos);
}
} else {
@@ -1182,7 +1182,7 @@ namespace daObjMovebox {
s32 pntIdx;
for (pntIdx = 0; pntIdx < numPnts; pntIdx++) {
cXyz pntPos = dPath_GetPnt(mpPath, pntIdx)->m_position;
if (current.pos.abs2(pntPos) < 9.0f) {
if (current.pos.abs2(pntPos) < SQUARE(3.0f)) {
break;
}
}
+1 -1
View File
@@ -122,7 +122,7 @@ void daObjNest::Act_c::init_mtx() {
void daObjNest::Act_c::rideCB(dBgW* bgw, fopAc_ac_c* i_ac, fopAc_ac_c* i_pt) {
daObjNest::Act_c * i_this = (daObjNest::Act_c *)i_ac;
f32 actorDistXZ2 = fopAcM_searchActorDistanceXZ2(i_this,i_pt);
if (actorDistXZ2 > attr().field_0x04 * attr().field_0x04) {
if (actorDistXZ2 > SQUARE(attr().field_0x04)) {
f32 fVar = i_pt->speedF * (1.0f / attr().field_0x00);
i_this->vib_set(cLib_maxLimit(fVar, 1.0f));
}
+9 -9
View File
@@ -2983,7 +2983,7 @@ void daPy_lk_c::setBlendMoveAnime(f32 param_1) {
r27 = ANM_WALKBARREL;
r26 = ANM_WALKBARREL;
} else if (checkHeavyStateOn()) {
if ((m373C.abs2XZ() > 25.0f &&
if ((m373C.abs2XZ() > SQUARE(5.0f) &&
(cLib_distanceAngleS(cM_atan2s(m373C.x, m373C.z), shape_angle.y) >= 0x4000)) ||
((checkNoResetFlg1(daPyFlg1_UNK10000000) && m3644 > 5.0f) &&
cLib_distanceAngleS(m3640, shape_angle.y) >= 0x4000))
@@ -3011,7 +3011,7 @@ void daPy_lk_c::setBlendMoveAnime(f32 param_1) {
}
} else {
r27 = ANM_WALK;
if ((m3730.abs2XZ() > 25.0f &&
if ((m3730.abs2XZ() > SQUARE(5.0f) &&
(cLib_distanceAngleS(cM_atan2s(m3730.x, m3730.z), shape_angle.y) >= 0x4000)) ||
((checkNoResetFlg1(daPyFlg1_UNK10000000) && m3644 > 5.0f) &&
cLib_distanceAngleS(m3640, shape_angle.y) >= 0x4000))
@@ -3248,7 +3248,7 @@ void daPy_lk_c::setBlendAtnBackMoveAnime(f32 param_1) {
onResetFlg0(daPyRFlg0_LEFT_FOOT_ON_GROUND);
}
} else {
if (m36A0.abs2XZ() >= 49.0f) {
if (m36A0.abs2XZ() >= SQUARE(7.0f)) {
fVar1 = 1.9f * daPy_HIO_atnMoveB_c0::m.field_0x28;
onResetFlg0(daPyRFlg0_UNK40000);
} else {
@@ -3376,7 +3376,7 @@ void daPy_lk_c::setBlendAtnMoveAnime(f32 f30) {
dVar9 = ANM_ATNDRS;
}
f32 f2;
if (m36A0.abs2XZ() >= 49.0f) {
if (m36A0.abs2XZ() >= SQUARE(7.0f)) {
f2 = 1.9f * daPy_HIO_atnMove_c0::m.field_0x2C;
onResetFlg0(daPyRFlg0_UNK40000);
} else {
@@ -6070,7 +6070,7 @@ BOOL daPy_lk_c::procWait_init() {
/* 80113044-801133FC .text procWait__9daPy_lk_cFv */
BOOL daPy_lk_c::procWait() {
if (m36A0.abs2XZ() <= (1.0f / 999999.9f) && m36AC.abs2XZ() >= 25.0f) {
if (m36A0.abs2XZ() <= SQUARE(1.0f / 1000.0f) && m36AC.abs2XZ() >= SQUARE(5.0f)) {
return procIceSlipAlmostFall_init();
}
if (!dComIfGp_event_runCheck() && mDemo.getDemoType() == 0 && spLTrigger() && mAcch.ChkWallHit()) {
@@ -8739,7 +8739,7 @@ void daPy_lk_c::footBgCheck() {
cXyz sp50;
sp74 = (r25_r26->field_0x018 + r25_r26->field_0x00C) * 0.5f;
sp50 = sp74 - r25_r26->field_0x024;
if (sp50.abs2XZ() < 100.0f && r29 != 0) {
if (sp50.abs2XZ() < SQUARE(10.0f) && r29 != 0) {
if (r25_r26->field_0x001 != 0) {
r25_r26->field_0x001--;
} else {
@@ -9005,9 +9005,9 @@ void daPy_lk_c::setNeckAngle() {
r28 = true;
}
} else if (m_tex_anm_heap.mIdx == LKANM_BTP_TDASHKAZE) {
if (checkHeavyStateOn() && m373C.abs2XZ() > 25.0f) {
if (checkHeavyStateOn() && m373C.abs2XZ() > SQUARE(5.0f)) {
spA0.set(current.pos.x - 100.0f * m373C.x, 120.0f + current.pos.y, current.pos.z - 100.0f * m373C.z);
} else if (!checkHeavyStateOn() && m3730.abs2XZ() > 25.0f) {
} else if (!checkHeavyStateOn() && m3730.abs2XZ() > SQUARE(5.0f)) {
spA0.set(current.pos.x - 100.0f * m3730.x, 120.0f + current.pos.y, current.pos.z - 100.0f * m3730.z);
} else {
spA0.set(
@@ -10434,7 +10434,7 @@ void daPy_lk_c::setDemoData() {
if (mDemo.getTimer() != 0) {
mDemo.decTimer();
cXyz sp5C = current.pos - home.pos;
if (sp5C.abs2XZ() > 90000.0f) {
if (sp5C.abs2XZ() > SQUARE(300.0f)) {
mDemo.setTimer(0);
dComIfGp_evmng_cutEnd(mStaffIdx);
}
+1 -1
View File
@@ -42,7 +42,7 @@ BOOL daPy_lk_c::checkJumpRideShip() {
cXyz sp20;
mDoMtx_multVec(ship->getBodyMtx(), &l_ship_offset, &sp20);
sp20 = old.pos - sp20;
if (sp20.y > 5.0f && sp20.abs2XZ() < 10000.0f) {
if (sp20.y > 5.0f && sp20.abs2XZ() < SQUARE(100.0f)) {
return procShipJumpRide_init();
}
}
+8 -8
View File
@@ -579,9 +579,9 @@ static void sail_pos_move(sail_class* i_this) {
// these explicit casts are necessary
u32 r22 = (i_this->mSailPacket.m1C50 * (s32)f23) + (i_this->mSailPacket.m1C52 * (s32)f12);
f20 = (1750.0f + REG_SAIL_F(13)) * ((f0 * f0) + 0.05f) * cM_ssin(-i_this->mSailPacket.m1C40 + r22) * f31;
f22 = (550.0f + REG_SAIL_F(12)) * ((f0 * f0) + 0.1f) * cM_scos(i_this->mSailPacket.m1C40 + r22) * f31;
f21 = std::sqrtf((f22 * f22) + (f20 * f20)) * 0.1f;
f20 = (1750.0f + REG_SAIL_F(13)) * (SQUARE(f0) + 0.05f) * cM_ssin(-i_this->mSailPacket.m1C40 + r22) * f31;
f22 = (550.0f + REG_SAIL_F(12)) * (SQUARE(f0) + 0.1f) * cM_scos(i_this->mSailPacket.m1C40 + r22) * f31;
f21 = std::sqrtf(SQUARE(f22) + SQUARE(f20)) * 0.1f;
f24 = (f25 * ((10.0f * f17) + (-f17 * f23 * f23)));
f24 += ((sp10.z * (18.0f - f23 * f23)) / 18.0f);
@@ -602,7 +602,7 @@ static void sail_pos_move(sail_class* i_this) {
}
}
f32 f14 = 100.0f - std::sqrtf((125.0f * 125.0f) - (f16 * f16));
f32 f14 = 100.0f - std::sqrtf(SQUARE(125.0f) - SQUARE(f16));
sp6C[j] += f14 > -10.0f ? f14 : -10.0f;
sp10.x = 0.0f;
@@ -618,21 +618,21 @@ static void sail_pos_move(sail_class* i_this) {
}
vtxPos->x = sp10.x + f22;
vtxPos->y = ((sp6C[j] + sp10.y + f21) - (i * 1.25f * (f23 * f23)));
vtxPos->y = ((sp6C[j] + sp10.y + f21) - (i * 1.25f * SQUARE(f23)));
vtxPos->z = f24 + f20;
vtxPos->x += l_pos[i * 7 + j].x;
vtxPos->y += l_pos[i * 7 + j].y;
vtxPos->z += l_pos[i * 7 + j].z;
vtxPos->y *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f));
vtxPos->y *= (1.0f - ((i_this->mSailPacket.m1C44 * SQUARE(f13)) / 30.25f));
vtxPos->y *= ((11.0f - (i_this->mSailPacket.m1C44 * i)) / 11.0f);
vtxPos->z *= (1.0f - ((i_this->mSailPacket.m1C44 * (f13 * f13)) / 30.25f));
vtxPos->z *= (1.0f - ((i_this->mSailPacket.m1C44 * SQUARE(f13)) / 30.25f));
vtxPos->z *= ((11.0f - (i_this->mSailPacket.m1C44 * i)) / 11.0f);
if (i_this->mSailPacket.m1C44 > 0.0f && i < 6) {
f32 f15_2 = i - 3;
f32 f20 = (9.0f - (f15_2 * f15_2)) / 9.0f;
f32 f20 = (9.0f - SQUARE(f15_2)) / 9.0f;
vtxPos->z += ((REG_SAIL_F(26) * 10.0f + 3.5f) * 200.0f * f20 * i_this->mSailPacket.m1C44);
vtxPos->y -= ((REG_SAIL_F(29) * 10.0f + 1.5f) * 100.0f * f20 * i_this->mSailPacket.m1C44);
}
+3 -3
View File
@@ -3203,7 +3203,7 @@ void daShip_c::setRopePos() {
mDoMtx_multVecZero(mpSalvageArmModel->getAnmMtx(1), &spE0);
spE0 -= *r4;
if (spE0.abs2XZ() < 2500.0f) {
if (spE0.abs2XZ() < SQUARE(50.0f)) {
currentRopeSegment = mRopeLineSegments;
f32 f2 = cM_scos(shape_angle.x) * 16.0f;
@@ -4120,7 +4120,7 @@ BOOL daShip_c::execute() {
#if VERSION == VERSION_DEMO
attention_info.flags = fopAc_Attn_LOCKON_TALK_e | fopAc_Attn_ACTION_SPEAK_e;
#endif
if (fopAcM_searchPlayerDistanceXZ2(this) < 250000.0f) {
if (fopAcM_searchPlayerDistanceXZ2(this) < SQUARE(500.0f)) {
spC0 = link->eyePos - eyePos;
r23_2 = TRUE;
#if VERSION > VERSION_DEMO
@@ -4190,7 +4190,7 @@ BOOL daShip_c::execute() {
(!dComIfGp_event_runCheck() && dComIfGp_checkPlayerStatus0(0, daPyStts0_SHIP_RIDE_e)) ||
(
std::fabsf(current.pos.y - link->current.pos.y) < 50.0f &&
spB4.abs2XZ() < 62500.0f &&
spB4.abs2XZ() < SQUARE(250.0f) &&
fopAcM_seenPlayerAngleY(this) < 0x6000 &&
mNextMessageNo != 0xD65
)
+1 -1
View File
@@ -67,7 +67,7 @@ static cPhs_State daSwc00_Create(fopAc_ac_c* i_this) {
i_this->scale.x *= 100.0f;
i_this->scale.x += 30.0f;
i_this->scale.x *= i_this->scale.x;
i_this->scale.x = SQUARE(i_this->scale.x);
i_this->scale.y *= 100.0f;
return cPhs_COMPLEATE_e;
+3 -3
View File
@@ -252,7 +252,7 @@ BOOL daTag_Event_c::actionHunt() {
if (swbit != 0xFF && dComIfGs_isSwitch(swbit, fopAcM_GetRoomNo(this))) {
setActio(ACTION_WAIT);
} else if (sp20.abs2XZ() < (scale.x*scale.x) * (100.0f*100.0f) && sp20.y <= scale.y * 100.0f) {
} else if (sp20.abs2XZ() < SQUARE(scale.x) * SQUARE(100.0f) && sp20.y <= scale.y * 100.0f) {
setActio(ACTION_READY);
fopAcM_orderOtherEventId(this, mEventIdx, getEventNo());
if (cancelShutter()) {
@@ -348,7 +348,7 @@ BOOL daTag_Event_c::actionSpeHunt() {
if (sp20.y < 0.0f) {
sp20.y = -sp20.y;
}
if (sp20.abs2XZ() < (scale.x*scale.x) * (100.0f*100.0f) && sp20.y <= scale.y * 100.0f) {
if (sp20.abs2XZ() < SQUARE(scale.x) * SQUARE(100.0f) && sp20.y <= scale.y * 100.0f) {
setActio(ACTION_SPE_READY);
fopAcM_orderOtherEventId(this, mEventIdx);
}
@@ -419,7 +419,7 @@ BOOL daTag_Event_c::actionMjHunt() {
if (swbit != 0xFF && dComIfGs_isSwitch(swbit, fopAcM_GetRoomNo(this))) {
setActio(ACTION_WAIT);
} else if (sp20.abs2XZ() < (scale.x*scale.x) * (100.0f*100.0f) && sp20.y <= scale.y * 100.0f) {
} else if (sp20.abs2XZ() < SQUARE(scale.x) * SQUARE(100.0f) && sp20.y <= scale.y * 100.0f) {
if (dComIfGp_checkPlayerStatus0(0, daPyStts0_SHIP_RIDE_e)) {
mEventIdx = dComIfGp_evmng_getEventIdx(NULL, getEventNo());
} else {
+1 -1
View File
@@ -90,7 +90,7 @@ BOOL daTag_Msg_c::rangeCheck() {
if (diff.y < 0.0f) {
diff.y = -diff.y;
}
if (diff.abs2XZ() < scale.x * scale.x * 10000.0f) {
if (diff.abs2XZ() < SQUARE(scale.x) * SQUARE(100.0f)) {
if(diff.y <= scale.y * 100.0f) {
return TRUE;
}
+1 -1
View File
@@ -569,7 +569,7 @@ s32 daTbox_c::boxCheck() {
fopAc_ac_c* player = dComIfGp_getPlayer(0);
cXyz playerChestDiff = player->current.pos - home.pos;
if (playerChestDiff.abs2XZ() < 10000.0f) {
if (playerChestDiff.abs2XZ() < SQUARE(100.0f)) {
if (fopAcM_seenActorAngleY(this, dComIfGp_getPlayer(0)) < 0x2000 && fopAcM_seenActorAngleY(player, this) < 0x2000) {
return TRUE;
}
+2 -2
View File
@@ -156,7 +156,7 @@ BOOL daTornado_c::execute() {
if (dComIfGp_checkPlayerStatus0(0, daPyStts0_SHIP_RIDE_e) && dComIfGp_getShipActor() != NULL) {
daShip_c* ship = dComIfGp_getShipActor();
cXyz diff = ship->current.pos - current.pos;
if (diff.abs2XZ() < 10000.0f*10000.0f) {
if (diff.abs2XZ() < SQUARE(10000.0f)) {
ship->onTornadoFlg(fopAcM_GetID(this));
speedF = 0.0f;
}
@@ -166,7 +166,7 @@ BOOL daTornado_c::execute() {
fopAcM_posMoveF(this, NULL);
cXyz diff = current.pos - home.pos;
diff.y = 0;
if (diff.abs2XZ() > 7500.0f*7500.0f) {
if (diff.abs2XZ() > SQUARE(7500.0f)) {
diff.normalize();
current.pos = home.pos + diff * 7500.0f;
}
+2 -2
View File
@@ -555,9 +555,9 @@ void dBgS_CrrPos::CrrPos(dBgS& i_bgs) {
CHECK_PVEC3_RANGE(2280, pm_pos);
if (!(mFlag & 4)) {
f32 dist2 = GetOldPos()->abs2(*pm_pos);
f32 dist_sq = GetOldPos()->abs2(*pm_pos);
bool inWall = false;
if (dist2 > (0.65f*0.65f * GetWallR()*GetWallR())) {
if (dist_sq > (SQUARE(0.65f) * GetWallR()*GetWallR())) {
inWall = true;
cBgS_LinChk linChk;
+1 -2
View File
@@ -50,8 +50,7 @@ bool dBgW::RwgWallCorrect(dBgS_Acch* pwi, u16 i_poly_idx) {
if (!ChkPolyThrough(i_poly_idx, pwi->GetPolyPassChk())) {
cBgW_TriElm* tri = &pm_tri[i_poly_idx];
f32 sp68 = std::sqrtf(tri->m_plane.GetNP()->x * tri->m_plane.GetNP()->x +
tri->m_plane.GetNP()->z * tri->m_plane.GetNP()->z);
f32 sp68 = std::sqrtf(SQUARE(tri->m_plane.GetNP()->x) + SQUARE(tri->m_plane.GetNP()->z));
if (cM3d_IsZero(sp68)) {
if (rwg_elm->next != 0xFFFF) {
i_poly_idx = rwg_elm->next;
+1 -1
View File
@@ -95,7 +95,7 @@ void dDetect_c::set_quake(const cXyz* pos) {
/* 8009C254-8009C32C .text chk_quake_area__9dDetect_cCFPC4cXyz */
bool dDetect_c::chk_quake_area(const cXyz* pos) const {
daPy_py_c* player = daPy_getPlayerActorClass();
f32 maxDist2XZ = attr().maxDistXZ * attr().maxDistXZ;
f32 maxDist2XZ = SQUARE(attr().maxDistXZ);
f32 dist2XZ = player->current.pos.abs2XZ(*pos);
f32 diffY = pos->y - player->current.pos.y;
return dist2XZ <= maxDist2XZ && diffY <= attr().maxY && diffY >= attr().minY;
+2 -2
View File
@@ -89,9 +89,9 @@ void dMagma_ball_c::draw() {
BOOL dMagma_ball_c::rangeCheck(cXyz& pos, f32* dst) {
f32 distSq = mPos.abs2XZ(pos);
f32 rad1 = mScale * 243.6414f;
if (distSq < rad1*rad1) {
if (distSq < SQUARE(rad1)) {
f32 rad2 = mScale * 800.0f;
f32 dist = std::sqrtf(rad2 * rad2 - distSq);
f32 dist = std::sqrtf(SQUARE(rad2) - distSq);
f32 temp = (mPos.y - (rad2 - 47.999146f));
temp += dist;
*dst = temp;
+3 -3
View File
@@ -104,7 +104,7 @@ void dNpc_JntCtrl_c::lookAtTarget(s16* outY, cXyz* pDstPos, cXyz srcPos, s16 def
delta.x = pDstPos->x - srcPos.x;
delta.y = pDstPos->y - srcPos.y;
delta.z = pDstPos->z - srcPos.z;
f32 distXZ = std::sqrtf(delta.x * delta.x + delta.z * delta.z);
f32 distXZ = std::sqrtf(SQUARE(delta.x) + SQUARE(delta.z));
targetY = cM_atan2s(delta.x, delta.z);
r23 = cM_atan2s(delta.y, distXZ);
} else {
@@ -422,7 +422,7 @@ bool dNpc_PathRun_c::setNearPathIndx(cXyz* param_1, f32 param_2) {
cXyz diff = (*param_1 - point);
f32 xz_mag = diff.abs2XZ();
f32 y_mag = param_2 * (diff.y * diff.y);
f32 y_mag = param_2 * SQUARE(diff.y);
f32 dist = std::sqrtf(y_mag + xz_mag);
if(max_dist > dist) {
@@ -629,7 +629,7 @@ void dNpc_calc_DisXZ_AngY(cXyz param_1, cXyz param_2, float* param_3, s16* param
diff.z = param_2.z - param_1.z;
if(param_3 != 0) {
f32 dist = std::sqrtf(diff.x * diff.x + diff.z * diff.z);
f32 dist = std::sqrtf(SQUARE(diff.x) + SQUARE(diff.z));
*param_3 = dist;
}
+3 -3
View File
@@ -1817,12 +1817,12 @@ int dSnap_packet::Regist(const dSnap_Obj& obj) {
if (!r6) {
return 0;
}
f32 dist2 = player->current.pos.abs2(obj.mCenter);
if (obj.GetPhoto() >= 0x48 && dist2 > f30) {
f32 dist_sq = player->current.pos.abs2(obj.mCenter);
if (obj.GetPhoto() >= 0x48 && dist_sq > f30) {
return 0;
}
m_tbl[r29].Regist(obj);
m_tbl[r29].field_0x34 = dist2;
m_tbl[r29].field_0x34 = dist_sq;
return 0;
} else {
m_tbl[field_0x14].Regist(obj);
+1 -1
View File
@@ -527,7 +527,7 @@ s32 fopAcM_rollPlayerCrash(fopAc_ac_c* i_this, f32 distAdjust, u32 flag) {
f32 maxDist = distAdjust + 40.0f;
f32 xzDist2 = fopAcM_searchPlayerDistanceXZ2(i_this);
f32 yDist = fopAcM_searchPlayerDistanceY(i_this);
if (xzDist2 < maxDist*maxDist && yDist > -100.0f && yDist < 200.0f) {
if (xzDist2 < SQUARE(maxDist) && yDist > -100.0f && yDist < 200.0f) {
daPy_py_c* player = (daPy_py_c*)dComIfGp_getPlayer(0);
s16 angle = fopAcM_searchPlayerAngleY(i_this);
if (cM_scos(player->current.angle.y - angle) < -0.9f) {