From 36b78967ed0d793fc01e4f20cc876f521631afd9 Mon Sep 17 00:00:00 2001 From: Bam4d Date: Mon, 6 Sep 2021 17:43:09 +0100 Subject: [PATCH 1/3] allow rewards to be pointers to game variables --- src/Griddly/Core/GDY/Objects/Object.cpp | 5 +++-- tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Griddly/Core/GDY/Objects/Object.cpp b/src/Griddly/Core/GDY/Objects/Object.cpp index 9053ed051..5f9644be9 100644 --- a/src/Griddly/Core/GDY/Objects/Object.cpp +++ b/src/Griddly/Core/GDY/Objects/Object.cpp @@ -210,7 +210,8 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou // reward the player that owns this particular object, otherwise warn if (commandName == "reward") { - auto value = commandArguments["0"].as(0); + auto variablePointers = resolveVariables(commandArguments); + auto value = variablePointers["0"]; return [this, value](std::shared_ptr action) -> BehaviourResult { // if the object has a player Id, the reward will be given to that object's player, // otherwise the reward will be given to the player which has performed the action @@ -222,7 +223,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou } // Find the player id of this object and give rewards to this player. - return {false, {{rewardPlayer, value}}}; + return {false, {{rewardPlayer, value->resolve(action)}}}; }; } diff --git a/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp b/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp index 954869a66..6c77379ce 100644 --- a/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp +++ b/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp @@ -432,6 +432,21 @@ TEST(ObjectTest, command_reward) { verifyMocks(mockActionPtr); } +TEST(ObjectTest, command_reward_variable) { + auto srcObjectPtr = setupObject(1, "srcObject", {{"ten", _V(10)}}); + auto dstObjectPtr = setupObject(3, "dstObject", {{"minusten", _V(-10)}}); + auto mockActionPtr = setupAction("action", srcObjectPtr, dstObjectPtr); + + auto srcResult = addCommandsAndExecute(ActionBehaviourType::SOURCE, mockActionPtr, "reward", {{"0", _Y("ten")}}, srcObjectPtr, dstObjectPtr); + auto dstResult = addCommandsAndExecute(ActionBehaviourType::DESTINATION, mockActionPtr, "reward", {{"0", _Y("minusten")}}, srcObjectPtr, dstObjectPtr); + + verifyCommandResult(srcResult, false, {{1, 10}}); + verifyCommandResult(dstResult, false, {{3, -10}}); + + verifyMocks(mockActionPtr); +} + + TEST(ObjectTest, command_reward_default_to_action_player_id) { auto srcObjectPtr = setupObject(0, "srcObject", {}); auto dstObjectPtr = setupObject(0, "dstObject", {}); From e9ab6ebaf44467fdf5d8616362550ec909f85fed Mon Sep 17 00:00:00 2001 From: Bam4d Date: Mon, 6 Sep 2021 20:27:35 +0100 Subject: [PATCH 2/3] bumping version numbers --- python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index 4a25354db..41d1acc13 100644 --- a/python/setup.py +++ b/python/setup.py @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'): setup( name='griddly', - version="1.2.7", + version="1.2.8", author_email="chrisbam4d@gmail.com", description="Griddly Python Libraries", long_description=long_description, From f21b66eebd9be0b9da995a9661f627d7f871e7eb Mon Sep 17 00:00:00 2001 From: Bam4d Date: Mon, 6 Sep 2021 21:00:12 +0100 Subject: [PATCH 3/3] missed some version number bumps --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- CMakeLists.txt | 2 +- bindings/python.cpp | 2 +- docs/conf.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 15b39fba4..cd2e77c95 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,7 +24,7 @@ If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: [e.g. mac/linux/windows] - - Version [e.g. 1.2.7] + - Version [e.g. 1.2.8] **Additional context** Add any other context about the problem here. diff --git a/CMakeLists.txt b/CMakeLists.txt index 47f407b45..cd978825e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10.0) -project(Griddly VERSION 1.2.7) +project(Griddly VERSION 1.2.8) set(BINARY ${CMAKE_PROJECT_NAME}) diff --git a/bindings/python.cpp b/bindings/python.cpp index e4c731fc6..8d3509ac1 100644 --- a/bindings/python.cpp +++ b/bindings/python.cpp @@ -12,7 +12,7 @@ namespace griddly { PYBIND11_MODULE(python_griddly, m) { m.doc() = "Griddly python bindings"; - m.attr("version") = "1.2.7"; + m.attr("version") = "1.2.8"; #ifndef NDEBUG spdlog::set_level(spdlog::level::debug); diff --git a/docs/conf.py b/docs/conf.py index 577cedbb4..acc16b1d9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Chris Bamford' # The full version, including alpha/beta/rc tags -release = '1.2.7' +release = '1.2.8' # -- General configuration ---------------------------------------------------