From cf33ef8ca6b26145f15b83c7bd7602c15c826a00 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 13:27:57 +0200 Subject: [PATCH 01/12] Hardwire sub-mission button in `is_button_pressed` to `player->isRunning()` --- rwengine/src/script/modules/GameModule.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rwengine/src/script/modules/GameModule.cpp b/rwengine/src/script/modules/GameModule.cpp index 35139694..4d21ca9c 100644 --- a/rwengine/src/script/modules/GameModule.cpp +++ b/rwengine/src/script/modules/GameModule.cpp @@ -85,9 +85,18 @@ void game_set_time(const ScriptArguments& args) bool game_is_button_pressed(const ScriptArguments& args) { - /// @todo implement - RW_UNUSED(args); + int player = args[0].integerValue(); + int index = args[1].integerValue(); RW_UNIMPLEMENTED("game_is_button_pressed()"); + // NOTE: This is a hack. Hence we'll keep the unimplemented message for now. + if (player == 0) { + if (index == 19) { // look behind / sub-mission + /// @todo Return the keystate instead + auto object = args.getWorld()->pedestrianPool.find(args.getState()->playerObject); + auto player = static_cast(object); + return player->isRunning(); + } + } return false; } From ae7b70bed90505a0618549f72d97412eeaf38c16 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Thu, 23 Jun 2016 06:23:00 +0200 Subject: [PATCH 02/12] Introduce realValue() to load script real from var or immediate automaticly --- rwengine/include/script/ScriptTypes.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rwengine/include/script/ScriptTypes.hpp b/rwengine/include/script/ScriptTypes.hpp index 091e608a..59ce4976 100644 --- a/rwengine/include/script/ScriptTypes.hpp +++ b/rwengine/include/script/ScriptTypes.hpp @@ -82,6 +82,22 @@ struct SCMOpcodeParameter { return 0; } } + + float realValue() const + { + switch (type) + { + case TGlobal: + case TLocal: + return *globalReal; + case TFloat16: + return real; + default: + RW_ERROR("Unhandled type"); + return 0; + } + } + }; typedef std::vector SCMParams; From 3789a8454dd4b519543aa8ae65626d00b5f71742 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Thu, 23 Jun 2016 06:23:33 +0200 Subject: [PATCH 03/12] Fix `game_add_location_blip` by using realValue() --- rwengine/src/script/modules/GameModule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rwengine/src/script/modules/GameModule.cpp b/rwengine/src/script/modules/GameModule.cpp index 4d21ca9c..45e26093 100644 --- a/rwengine/src/script/modules/GameModule.cpp +++ b/rwengine/src/script/modules/GameModule.cpp @@ -320,7 +320,8 @@ void game_add_location_blip(const ScriptArguments& args) { BlipData data; data.target = 0; - data.coord = glm::vec3(args[0].real, args[1].real, args[2].real); + /// @todo this might use ground coords if z is -100.0 + data.coord = glm::vec3(args[0].realValue(), args[1].realValue(), args[2].realValue()); data.texture = ""; *args[3].globalInteger = args.getWorld()->state->addRadarBlip(data); } From 709cbc56865e3598331a19d227e011349ee49e0b Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 23:58:45 +0200 Subject: [PATCH 04/12] Fix vm_int_ge_global_int and vm_global_int_eq_int --- rwengine/src/script/modules/VMModule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index 80b45da7..a3a4cf00 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -79,12 +79,12 @@ void vm_global_int_ge_int(const ScriptArguments& args) void vm_int_ge_global_int(const ScriptArguments& args) { - args.getThread()->conditionResult = args[0].integer >= *args[1].globalInteger; + args.getThread()->conditionResult = args[0].integerValue() >= *args[1].globalInteger; } void vm_global_int_eq_int(const ScriptArguments& args) { - args.getThread()->conditionResult = *args[0].globalInteger == args[1].integer; + args.getThread()->conditionResult = *args[0].globalInteger == args[1].integerValue(); } void vm_global_float_eq_float(const ScriptArguments& args) From 6f49cc579aa7f903ef72169cb38a8d643e7a0e71 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 23:53:15 +0200 Subject: [PATCH 05/12] Script: 0010 (Multiply Global Int by Int) and 0014 (Divide Global by Integer) --- rwengine/src/script/modules/VMModule.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index a3a4cf00..1b4af85c 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -52,6 +52,15 @@ void vm_dec_global_float(const ScriptArguments& args) *args[0].globalReal -= args[1].real; } +void vm_mul_global_int(const ScriptArguments& args) +{ + *args[0].globalInteger *= args[1].integer; +} + +void vm_div_global_int(const ScriptArguments& args) +{ + *args[0].globalInteger /= args[1].integer; +} void vm_div_global_float(const ScriptArguments& args) { *args[0].globalReal /= args[1].real; @@ -205,7 +214,10 @@ VMModule::VMModule() bindFunction(0x009, vm_inc_global_float, 2, "Increment Global Float"); bindFunction(0x00C, vm_dec_global_int, 2, "Decrement Global Int"); bindFunction(0x00D, vm_dec_global_float, 2, "Decrement Global Float"); - + + bindFunction(0x010, vm_mul_global_int, 2, "Multiply Global Int by Int"); + + bindFunction(0x014, vm_div_global_int, 2, "Divide Global by Integer"); bindFunction(0x015, vm_div_global_float, 2, "Divide Global by Float"); bindFunction(0x018, vm_global_int_gt_int, 2, "Global Int Greater than Int"); From 004f42504afe230bdc20451de825fbb83fc78282 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 13:36:09 +0200 Subject: [PATCH 06/12] Script: 001F (Local Int Greater than Global Int) --- rwengine/src/script/modules/VMModule.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index 1b4af85c..cad74fd7 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -76,6 +76,11 @@ void vm_int_gt_global_int(const ScriptArguments& args) args.getThread()->conditionResult = args[0].integer > *args[1].globalInteger; } +bool vm_global_int_gt_global_int(const ScriptArguments& args) +{ + return *args[0].globalInteger > *args[1].globalInteger; +} + void vm_global_float_gt_float(const ScriptArguments& args) { args.getThread()->conditionResult = *args[0].globalReal > args[1].real; @@ -226,6 +231,7 @@ VMModule::VMModule() bindFunction(0x01A, vm_int_gt_global_int, 2, "Int Greater Than Global Int"); bindFunction(0x01B, vm_int_gt_global_int, 2, "Int Greater Than Var Int"); + bindFunction(0x01F, vm_global_int_gt_global_int, 2, "Local Int Greater than Global Int"); bindFunction(0x020, vm_global_float_gt_float, 2, "Global Float Greather than Float"); bindFunction(0x028, vm_global_int_ge_int, 2, "Global Int >= Int"); From 9042e235a83491e4800427a89eac072b71392ccd Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 13:23:50 +0200 Subject: [PATCH 07/12] Script: 003A (Global Int Equal to Global Int) --- rwengine/src/script/modules/VMModule.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index cad74fd7..48396c9a 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -106,6 +106,11 @@ void vm_global_float_eq_float(const ScriptArguments& args) args.getThread()->conditionResult = *args[0].globalReal == args[1].real; } +bool vm_global_int_eq_global_int(const ScriptArguments& args) +{ + return *args[0].globalInteger == *args[1].globalInteger; +} + void vm_new_thread(const ScriptArguments& args) { args.getVM()->startThread(args[0].integer); @@ -241,6 +246,7 @@ 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(0x03A, vm_global_int_eq_global_int, 2, "Global Int Equal to Global Int"); bindFunction(0x042, vm_global_float_eq_float, 2, "Global Float Equal to Float"); From 3869cd608aa17d2c1a76b127eb3ce0e14deba44e Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 23:55:15 +0200 Subject: [PATCH 08/12] Script: 0058 (Increment Global Integer by Global Integer) and 0059 (Increment Global Float by Global Float) --- rwengine/src/script/modules/VMModule.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index 48396c9a..c7cc1b5e 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -141,6 +141,15 @@ void vm_return(const ScriptArguments& args) args.getThread()->programCounter = args.getThread()->calls[--args.getThread()->stackDepth]; } +void vm_inc_global_int_by_global(const ScriptArguments& args) +{ + *args[0].globalInteger += *args[1].globalInteger; +} +void vm_inc_global_float_by_global(const ScriptArguments& args) +{ + *args[0].globalReal += *args[1].globalReal; +} + void vm_dec_global_int_by_global(const ScriptArguments& args) { *args[0].globalInteger -= *args[1].globalInteger; @@ -260,6 +269,9 @@ VMModule::VMModule() bindFunction(0x051, vm_return, 0, "Return"); + bindFunction(0x058, vm_inc_global_int_by_global, 2, "Increment Global Integer by Global Integer"); + bindFunction(0x059, vm_inc_global_float_by_global, 2, "Increment Global Float by Global Float"); + bindFunction(0x060, vm_dec_global_int_by_global, 2, "Decrement Global Integer by Global Integer"); bindFunction(0x061, vm_dec_global_float_by_global, 2, "Decrement Global Float by Global Float"); From 089d0efe5b509f53c7d9c8b506e5b27522c57414 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 23:55:43 +0200 Subject: [PATCH 09/12] Script: 0069 (Multiply Global Float by Global Float) --- 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 c7cc1b5e..5811273a 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -160,6 +160,11 @@ void vm_dec_global_float_by_global(const ScriptArguments& args) *args[0].globalReal -= *args[1].globalReal; } +void vm_mul_global_float_by_global(const ScriptArguments& args) +{ + *args[0].globalReal *= *args[1].globalReal; +} + void vm_global_int_to_global(const ScriptArguments& args) { *args[0].globalInteger = *args[1].globalInteger; @@ -275,6 +280,8 @@ VMModule::VMModule() bindFunction(0x060, vm_dec_global_int_by_global, 2, "Decrement Global Integer by Global Integer"); bindFunction(0x061, vm_dec_global_float_by_global, 2, "Decrement Global Float by Global Float"); + bindFunction(0x069, vm_mul_global_float_by_global, 2, "Multiply Global Float by Global Float"); + bindFunction(0x084, vm_global_int_to_global, 2, "Set Global Int To Global"); bindFunction(0x086, vm_global_float_to_global, 2, "Set Global Float To Global"); From 37e0ba943efa10742d7e3827d21e9161863f6468 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 23:56:41 +0200 Subject: [PATCH 10/12] Script: 008C (Floor Float To Int) --- rwengine/src/script/modules/VMModule.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rwengine/src/script/modules/VMModule.cpp b/rwengine/src/script/modules/VMModule.cpp index 5811273a..3c756f68 100644 --- a/rwengine/src/script/modules/VMModule.cpp +++ b/rwengine/src/script/modules/VMModule.cpp @@ -175,6 +175,12 @@ void vm_global_float_to_global(const ScriptArguments& args) *args[0].globalReal = *args[1].globalReal; } +void vm_floor_float_to_int(const ScriptArguments& args) +{ + /// @todo Not sure if this might round to zero + *args[0].globalInteger = floorf(*args[1].globalReal); +} + void vm_if(const ScriptArguments& args) { auto n = args[0].integer; @@ -286,6 +292,8 @@ VMModule::VMModule() bindFunction(0x086, vm_global_float_to_global, 2, "Set Global Float To Global"); + bindFunction(0x08C, vm_floor_float_to_int, 2, "Floor Float To Int"); + bindFunction(0x0D6, vm_if, 1, "If"); bindFunction(0x0D7, vm_new_mission_thread, 1, "Start Mission Thread"); From 86d31328c30606420cee114af12dd0be066b6d7c Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 13:27:05 +0200 Subject: [PATCH 11/12] Script: 00BD (Print Message Soon) --- rwengine/src/script/modules/GameModule.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rwengine/src/script/modules/GameModule.cpp b/rwengine/src/script/modules/GameModule.cpp index 45e26093..6a0148b7 100644 --- a/rwengine/src/script/modules/GameModule.cpp +++ b/rwengine/src/script/modules/GameModule.cpp @@ -66,6 +66,20 @@ void game_print_now(const ScriptArguments& args) )); } +void game_print_soon(const ScriptArguments& args) +{ + const auto& world = args.getWorld(); + + std::string id(args[0].string); + int time = args[1].integerValue(); + unsigned short style = args[2].integerValue(); + + auto str = world->data->texts.text(id); + + auto textEntry = ScreenTextEntry::makeBig(id, str, style, time); + world->state->text.addText(textEntry); +} + void game_clear_prints(const ScriptArguments& args) { args.getWorld()->state->text.clear(); @@ -1162,6 +1176,7 @@ GameModule::GameModule() bindFunction(0x00BA, game_print_big, 3, "Print big" ); bindFunction(0x00BC, game_print_now, 3, "Print Message Now" ); + bindFunction(0x00BD, game_print_soon, 3, "Print Message Soon" ); bindFunction(0x00BE, game_clear_prints, 0, "Clear Message Prints" ); bindFunction(0x00BF, game_get_time, 2, "Get Time of Day" ); From c5083701ea7e51d8aa038edbf6e66f61d0be5f28 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Sat, 11 Jun 2016 13:23:23 +0200 Subject: [PATCH 12/12] Script: 036D (Print Big With 2 Numbers) --- rwengine/src/script/modules/GameModule.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rwengine/src/script/modules/GameModule.cpp b/rwengine/src/script/modules/GameModule.cpp index 6a0148b7..ac997cc6 100644 --- a/rwengine/src/script/modules/GameModule.cpp +++ b/rwengine/src/script/modules/GameModule.cpp @@ -927,6 +927,22 @@ void game_start_chase_scene(const ScriptArguments& args) args.getWorld()->chase.start(); } +void game_print_big_with_2_numbers(const ScriptArguments& args) +{ + const auto& world = args.getWorld(); + + auto id(args[0].string); + int time = args[3].integerValue(); + unsigned short style = args[4].integerValue(); + + std::string str = ScreenText::format(world->data->texts.text(id), + formatValue(args[1]), + formatValue(args[2])); + + auto textEntry = ScreenTextEntry::makeBig(id, str, style, time); + world->state->text.addText(textEntry); +} + void game_stop_chase_scene(const ScriptArguments& args) { // Clean up remaining vehicles @@ -1362,6 +1378,8 @@ GameModule::GameModule() bindFunction( 0x0354, game_start_chase_scene, 1, "Start Chase Scene" ); bindFunction( 0x0355, game_stop_chase_scene, 0, "Stop Chase Scene" ); + bindFunction(0x036D, game_print_big_with_2_numbers, 5, "Print Big With 2 Numbers"); + bindUnimplemented( 0x0373, game_camera_behind_player, 0, "Set Camera Behind Player" ); bindUnimplemented( 0x0374, game_set_motion_blur, 1, "Set Motion Blur" );