From 7e3eb744f859f4c5b03ea89b779c482f432ac5cc Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 00:15:16 +0200 Subject: [PATCH 1/7] Fix wrong name in RW_UNIMPLEMENTED for game_has_death_or_arrest_finished --- rwengine/src/script/modules/GameModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rwengine/src/script/modules/GameModule.cpp b/rwengine/src/script/modules/GameModule.cpp index 87aae99d..53112925 100644 --- a/rwengine/src/script/modules/GameModule.cpp +++ b/rwengine/src/script/modules/GameModule.cpp @@ -99,7 +99,7 @@ void game_set_dead_or_arrested(const ScriptArguments& args) bool game_has_death_or_arrest_finished(const ScriptArguments& args) { RW_UNUSED(args); - RW_UNIMPLEMENTED("game_is_button_pressed()"); + RW_UNIMPLEMENTED("game_has_death_or_arrest_finished()"); return false; } From 0d089c9f5df9aa026c77112a8b25991c4b890b33 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 13:15:30 +0200 Subject: [PATCH 2/7] Script: 0176 (Get Object Heading) --- rwengine/include/objects/GameObject.hpp | 1 + rwengine/src/objects/GameObject.cpp | 7 +++++++ rwengine/src/script/modules/ObjectModule.cpp | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/rwengine/include/objects/GameObject.hpp b/rwengine/include/objects/GameObject.hpp index 8da40b1c..41d7960d 100644 --- a/rwengine/include/objects/GameObject.hpp +++ b/rwengine/include/objects/GameObject.hpp @@ -104,6 +104,7 @@ public: virtual glm::quat getRotation() const; virtual void setRotation(const glm::quat &orientation); + float getHeading() const; /** * @brief setHeading Rotates the object to face heading, in degrees. */ diff --git a/rwengine/src/objects/GameObject.cpp b/rwengine/src/objects/GameObject.cpp index 0318c208..529238cd 100644 --- a/rwengine/src/objects/GameObject.cpp +++ b/rwengine/src/objects/GameObject.cpp @@ -3,6 +3,7 @@ #include #include #include +#include GameObject::~GameObject() { @@ -32,6 +33,12 @@ void GameObject::setRotation(const glm::quat& orientation) rotation = orientation; } +float GameObject::getHeading() const +{ + auto hdg = glm::roll(getRotation()); + return hdg / glm::pi() * 180.f; +} + void GameObject::setHeading(float heading) { auto hdg = (heading / 180.f) * glm::pi(); diff --git a/rwengine/src/script/modules/ObjectModule.cpp b/rwengine/src/script/modules/ObjectModule.cpp index d7c02fab..6032370e 100644 --- a/rwengine/src/script/modules/ObjectModule.cpp +++ b/rwengine/src/script/modules/ObjectModule.cpp @@ -512,6 +512,13 @@ void game_set_player_heading(const ScriptArguments& args) object->setHeading(args[1].real); } +template +void game_get_object_heading(const ScriptArguments& args) +{ + auto object = args.getObject(0); + *args[1].globalReal = object->getHeading(); +} + template void game_set_object_heading(const ScriptArguments& args) { @@ -1172,6 +1179,7 @@ ObjectModule::ObjectModule() bindUnimplemented(0x0174, game_get_character_heading, 2, "Get Vehicle Heading" ); bindFunction(0x0175, game_set_object_heading, 2, "Set Vehicle heading" ); + bindFunction(0x0176, game_get_object_heading, 2, "Get Object heading" ); bindFunction(0x0177, game_set_object_heading, 2, "Set Object heading" ); bindUnimplemented( 0x0192, game_character_stand_still, 1, "Make character stand still" ); From 68f7291c3cba3a20d2bd94972080b8430c4b05f9 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 13:17:11 +0200 Subject: [PATCH 3/7] Script: 034F (Destroy Character with Fade) --- rwengine/src/script/modules/ObjectModule.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rwengine/src/script/modules/ObjectModule.cpp b/rwengine/src/script/modules/ObjectModule.cpp index 6032370e..9f9cb3ef 100644 --- a/rwengine/src/script/modules/ObjectModule.cpp +++ b/rwengine/src/script/modules/ObjectModule.cpp @@ -1098,6 +1098,13 @@ bool game_rotate_object(const ScriptArguments& args) return true; } +template +void game_destroy_object_with_fade(const ScriptArguments& args) +{ + /// @todo Fade not handled yet! + game_destroy_object(args); +} + void game_get_vehicle_colours(const ScriptArguments& args) { auto vehicle = static_cast(args.getObject(0)); @@ -1243,6 +1250,7 @@ ObjectModule::ObjectModule() bindFunction( 0x034D, game_rotate_object, 4, "Rotate Object" ); bindUnimplemented( 0x034E, game_slide_object, 8, "Slide Object" ); + bindFunction(0x034F, game_destroy_object_with_fade, 1, "Destroy Character with Fade" ); bindUnimplemented( 0x035D, game_set_object_targetable, 1, "Set Object Targetable" ); From adeb39c59b68b7966c70f260f814fbe5db7d66f2 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 13:18:00 +0200 Subject: [PATCH 4/7] Script: 0443 (Is Player In Any Vehicle) --- rwengine/src/script/modules/ObjectModule.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/rwengine/src/script/modules/ObjectModule.cpp b/rwengine/src/script/modules/ObjectModule.cpp index 9f9cb3ef..2bc765e5 100644 --- a/rwengine/src/script/modules/ObjectModule.cpp +++ b/rwengine/src/script/modules/ObjectModule.cpp @@ -1269,5 +1269,6 @@ ObjectModule::ObjectModule() bindUnimplemented( 0x042B, game_clear_volume_pedestrians, 6, "Clear volume pedestrians" ); bindFunction(0x0442, game_character_in_vehicle, 2, "Is Player in This Vehicle" ); + bindFunction(0x0443, game_player_in_any_vehicle, 1, "Is Player In Any Vehicle" ); /// Duplicate of 00E0?! bindFunction(0x0448, game_character_in_vehicle, 2, "Is Character in This Vehicle" ); } From ce50e47ab62e54b2c97aee41156ffebed0658b6a Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 13:18:21 +0200 Subject: [PATCH 5/7] Script: 0042 (Global Float Equal to Foat) --- rwengine/src/script/modules/VMModule.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index 1d967def..80b45da7 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -87,6 +87,11 @@ void vm_global_int_eq_int(const ScriptArguments& args) args.getThread()->conditionResult = *args[0].globalInteger == args[1].integer; } +void vm_global_float_eq_float(const ScriptArguments& args) +{ + args.getThread()->conditionResult = *args[0].globalReal == args[1].real; +} + void vm_new_thread(const ScriptArguments& args) { args.getVM()->startThread(args[0].integer); @@ -219,6 +224,8 @@ VMModule::VMModule() bindFunction(0x038, vm_global_int_eq_int, 2, "Global Int Equal to Int"); bindFunction(0x039, vm_global_int_eq_int, 2, "Local Int Equal to Int"); + bindFunction(0x042, vm_global_float_eq_float, 2, "Global Float Equal to Float"); + bindFunction(0x04F, vm_new_thread, -1, "Start New Thread"); bindFunction(0x04D, vm_jump_if_false, 1, "Jump if false"); From 574891e57ec6999e32c6bf4c0f5b0c7501035d64 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 13:23:44 +0200 Subject: [PATCH 6/7] Script: 00E6, 00E8 and 00EF (Locate .. stopped .. 2D) --- rwengine/src/script/modules/ObjectModule.cpp | 61 ++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/rwengine/src/script/modules/ObjectModule.cpp b/rwengine/src/script/modules/ObjectModule.cpp index 2bc765e5..7f42a27f 100644 --- a/rwengine/src/script/modules/ObjectModule.cpp +++ b/rwengine/src/script/modules/ObjectModule.cpp @@ -360,6 +360,62 @@ bool game_character_near_point_in_vehicle(const ScriptArguments& args) return false; } +template +bool game_locate_character_stopped_2d(const ScriptArguments& args) +{ + auto character = static_cast(args.getObject(0)); + glm::vec2 position(args[1].real, args[2].real); + glm::vec2 radius(args[3].real, args[4].real); + + bool drawCylinder = args[5].integer; + + auto cp = character->getPosition(); + glm::vec2 distance = glm::abs(position - glm::vec2(cp)); + + if(distance.x <= radius.x && distance.y <= radius.y && character->isStopped()) + { + return true; + } + + if( drawCylinder ) + { + auto ground = args.getWorld()->getGroundAtPosition(glm::vec3(position, 100.f)); + args.getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, ground, glm::vec3(radius, 5.f)); + } + + return false; +} + +bool game_locate_player_stopped_in_vehicle_2d(const ScriptArguments& args) +{ + auto character = static_cast(args.getPlayerCharacter(0)); + glm::vec2 position(args[1].real, args[2].real); + glm::vec2 radius(args[3].real, args[4].real); + + bool drawCylinder = args[5].integer; + + if( character->getCurrentVehicle() == nullptr ) + { + return false; + } + + auto vp = character->getCurrentVehicle()->getPosition(); + glm::vec2 distance = glm::abs(position - glm::vec2(vp)); + + if(distance.x <= radius.x && distance.y <= radius.y && character->isStopped()) + { + return true; + } + + if( drawCylinder ) + { + auto ground = args.getWorld()->getGroundAtPosition(glm::vec3(position, 100.f)); + args.getWorld()->drawAreaIndicator(AreaIndicatorInfo::Cylinder, ground, glm::vec3(radius, 5.f)); + } + + return false; +} + bool game_character_near_character_2D(const ScriptArguments& args) { auto character = static_cast(args.getObject(0)); @@ -1151,13 +1207,18 @@ ObjectModule::ObjectModule() bindFunction(0x00E5, game_player_in_area_2d_in_vehicle, 6, "Is Player in 2D Area in Vehicle" ); bindUnimplemented( 0x00E4, game_locate_character_on_foot_2d, 6, "Locate Player on foot 2D" ); + + bindFunction(0x00E6, game_locate_character_stopped_2d, 6, "Locate Player Stopped 2D" ); + bindFunction(0x00E8, game_locate_player_stopped_in_vehicle_2d, 6, "Locate Player Stopped in Vehicle 2D" ); bindFunction(0x00E9, game_character_near_character_2D, 5, "Locate Character near Character 2D"); bindFunction(0x00EB, game_character_near_character_in_vehicle_2D, 5, "Is player near character in vehicle" ); bindFunction(0x00ED, game_character_near_point_on_foot_2D, 6, "Is Character near point on foot" ); + bindFunction(0x00EF, game_locate_character_stopped_2d, 6, "Locate Character Stopped 2D" ); + bindUnimplemented( 0x00F5, game_locate_character_in_sphere, 8, "Locate Player In Sphere" ); bindFunction(0x00F6, game_player_near_point_on_foot_3D, 8, "Is Player near point on foot" ); bindFunction(0x00F7, game_player_near_point_in_vehicle_3D, 8, "Is Player near point in car" ); From 67fe32b3a17b778e4fc547605c36a053453c33ff Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 27 May 2016 13:24:35 +0200 Subject: [PATCH 7/7] Script: 0122 (Is Player Pressing Horn) and 0126 (Character Objective Passed) --- rwengine/src/script/modules/ObjectModule.cpp | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rwengine/src/script/modules/ObjectModule.cpp b/rwengine/src/script/modules/ObjectModule.cpp index 7f42a27f..992dcb8c 100644 --- a/rwengine/src/script/modules/ObjectModule.cpp +++ b/rwengine/src/script/modules/ObjectModule.cpp @@ -530,6 +530,29 @@ bool game_player_in_zone(const ScriptArguments& args) return false; } +bool game_player_pressing_horn(const ScriptArguments& args) +{ + auto character = static_cast(args.getPlayerCharacter(0)); + if ( character->getCurrentVehicle() != nullptr ) + { + /// @todo Respect actual horn key. + return true; + } + + return false; +} + +bool game_character_objective_passed(const ScriptArguments& args) +{ + auto character = static_cast(args.getObject(0)); + if( character && character->controller->getCurrentActivity() == nullptr ) + { + return true; + } + + return false; +} + void game_create_character_in_vehicle(const ScriptArguments& args) { auto vehicle = static_cast(args.getObject(0)); @@ -1234,6 +1257,9 @@ ObjectModule::ObjectModule() bindUnimplemented(0x011C, game_character_clear_objective, 1, "Clear Character Objective" ); bindFunction(0x0121, game_player_in_zone, 2, "Is Player In Zone" ); + bindFunction(0x0122, game_player_pressing_horn, 1, "Is Player Pressing Horn" ); + + bindFunction(0x0126, game_character_objective_passed, 1, "Character Objective Passed" ); bindFunction(0x0129, game_create_character_in_vehicle, 4, "Create Character In Car" );