Skip to content

Commit 6cc175f

Browse files
authored
Merge pull request #727 from Lihis/161-gates-do-not-open
Fix #161 gates do not open
2 parents 556cdfb + b409a8c commit 6cc175f

File tree

1 file changed

+53
-19
lines changed

1 file changed

+53
-19
lines changed

rwengine/src/script/modules/GTA3ModuleImpl.inl

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7192,18 +7192,32 @@ bool opcode_02b2(const ScriptArguments& args, const ScriptPlayer player, const S
71927192
@arg arg9
71937193
*/
71947194
bool opcode_02b3(const ScriptArguments& args, const ScriptPlayer player, const ScriptFloat arg2, const ScriptFloat arg3, const ScriptFloat arg4, const ScriptFloat arg5, const ScriptFloat arg6, const ScriptFloat arg7, const ScriptFloat arg8, const ScriptInt arg9) {
7195-
RW_UNIMPLEMENTED_OPCODE(0x02b3);
7196-
RW_UNUSED(player);
7197-
RW_UNUSED(arg2);
7198-
RW_UNUSED(arg3);
7199-
RW_UNUSED(arg4);
7200-
RW_UNUSED(arg5);
7201-
RW_UNUSED(arg6);
7202-
RW_UNUSED(arg7);
7203-
RW_UNUSED(arg8);
7204-
RW_UNUSED(arg9);
72057195
RW_UNUSED(args);
7206-
return false;
7196+
bool inArea;
7197+
7198+
if (arg9) {
7199+
RW_UNIMPLEMENTED("02B3: in_cube sphere");
7200+
inArea = false;
7201+
} else {
7202+
const glm::vec3& p = player.get()->getCharacter()->getPosition();
7203+
7204+
float angle = std::atan2(arg3 - arg6, arg5 - arg2);
7205+
float x = arg8 * std::cos(angle);
7206+
float y = arg8 * std::sin(angle);
7207+
7208+
glm::vec2 AB = glm::vec2(arg2 - (arg2 - x), arg3 - (arg3 - y));
7209+
glm::vec2 AM = glm::vec2(arg2 - p.x, arg3 - p.y);
7210+
glm::vec2 BC = glm::vec2((arg2 - x) - (arg5 - x), (arg3 - y) - (arg6 - y));
7211+
glm::vec2 BM = glm::vec2(arg2 - p.x, arg3 - p.y);
7212+
float dotABAM = glm::dot(AB, AM);
7213+
float dotBCBM = glm::dot(BC, BM);
7214+
7215+
inArea = (p.z >= arg4 && p.z <= arg7 &&
7216+
0 < dotABAM && dotABAM < glm::dot(AB, AB) &&
7217+
0 < dotBCBM && dotBCBM < glm::dot(BC, BC));
7218+
}
7219+
7220+
return inArea;
72077221
}
72087222

72097223
/**
@@ -9317,15 +9331,35 @@ bool opcode_034d(const ScriptArguments& args, const ScriptObject object, const S
93179331
@arg arg8 Boolean true/false
93189332
*/
93199333
bool opcode_034e(const ScriptArguments& args, const ScriptObject object, ScriptVec3 coord, const ScriptFloat arg5, const ScriptFloat arg6, const ScriptFloat arg7, const ScriptBoolean arg8) {
9320-
RW_UNIMPLEMENTED_OPCODE(0x034e);
9321-
RW_UNUSED(object);
9322-
RW_UNUSED(coord);
9323-
RW_UNUSED(arg5);
9324-
RW_UNUSED(arg6);
9325-
RW_UNUSED(arg7);
9326-
RW_UNUSED(arg8);
93279334
RW_UNUSED(args);
9328-
return true;
9335+
const glm::vec3& curPos = object.m_object->getPosition();
9336+
glm::vec3 newPos;
9337+
9338+
if (curPos == coord) {
9339+
return true;
9340+
}
9341+
9342+
newPos.x = (curPos.x < coord.x ? curPos.x + arg5 : curPos.x - arg5);
9343+
newPos.y = (curPos.y < coord.y ? curPos.y + arg6 : curPos.y - arg6);
9344+
newPos.z = (curPos.z < coord.z ? curPos.z + arg7 : curPos.z - arg7);
9345+
9346+
if (arg8) {
9347+
for (const auto& obj : args.getWorld()->pedestrianPool.objects) {
9348+
if (glm::distance(newPos, obj.second->getPosition()) <= 2.1f) {
9349+
return true;
9350+
}
9351+
}
9352+
9353+
for (const auto& obj : args.getWorld()->vehiclePool.objects) {
9354+
if (glm::distance(newPos, obj.second->getPosition()) <= 3.61f) {
9355+
return true;
9356+
}
9357+
}
9358+
}
9359+
9360+
object.m_object->setPosition(newPos);
9361+
9362+
return (newPos == coord);
93299363
}
93309364

93319365
/**

0 commit comments

Comments
 (0)