From cc2a9634ad4331ef9e6ac94fbe995f72df43dcc4 Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Wed, 12 Apr 2023 17:40:17 -0700 Subject: [PATCH 1/3] Expand js function capabilities --- doc/js-functions.md | 7 ++++--- src/component.cpp | 2 +- src/wzapi.cpp | 13 ++++++++----- src/wzapi.h | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/doc/js-functions.md b/doc/js-functions.md index 2cdcf9380da..017fcfb2276 100644 --- a/doc/js-functions.md +++ b/doc/js-functions.md @@ -268,8 +268,9 @@ looks, or to add variety to the looks of droids in campaign missions. (3.2+ only ## changePlayerColour(player, colour) -Change a player's colour slot. The current player colour can be read from the ```playerData``` array. There are as many -colour slots as the maximum number of players. (3.2.3+ only) +Change a player's colour slot. The current player colour can be read from the ```playerData``` array. Available colours +are green, orange, gray, black, red, blue, pink, cyan, yellow, purple, white, bright blue, neon green, infrared, +ultraviolet, and brown, represented by the integers 0 - 15 respectively. ## setHealth(object, health) @@ -769,7 +770,7 @@ Limit the scrollable area of the map to the given rectangle. (3.2+ only) Get the limits of the scrollable area of the map as an area object. (3.2+ only) -## addStructure(structureName, player, x, y) +## addStructure(structureName, player, x, y[, direction]) Create a structure on the given position. Returns the structure on success, null otherwise. Position uses world coordinates, if you want use position based on Map Tiles, then diff --git a/src/component.cpp b/src/component.cpp index b7dfbf175aa..637c9623afe 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -63,7 +63,7 @@ bool setPlayerColour(UDWORD player, UDWORD col) NetPlay.players[player].colour = MAX_PLAYERS; return true; } - ASSERT_OR_RETURN(false, col < MAX_PLAYERS, "Bad colour setting"); + ASSERT_OR_RETURN(false, col < 16, "Bad colour setting"); NetPlay.players[player].colour = col; return true; } diff --git a/src/wzapi.cpp b/src/wzapi.cpp index d2f754e3bf2..34421952dca 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -567,8 +567,9 @@ bool wzapi::replaceTexture(WZAPI_PARAMS(std::string oldFilename, std::string new //-- ## changePlayerColour(player, colour) //-- -//-- Change a player's colour slot. The current player colour can be read from the ```playerData``` array. There are as many -//-- colour slots as the maximum number of players. (3.2.3+ only) +//-- Change a player's colour slot. The current player colour can be read from the ```playerData``` array. Available colours +//-- are green, orange, gray, black, red, blue, pink, cyan, yellow, purple, white, bright blue, neon green, infrared, +//-- ultraviolet, and brown, represented by the integers 0 - 15 respectively. //-- bool wzapi::changePlayerColour(WZAPI_PARAMS(int player, int colour)) { @@ -2975,20 +2976,22 @@ scr_area wzapi::getScrollLimits(WZAPI_NO_PARAMS) return limits; } -//-- ## addStructure(structureName, player, x, y) +//-- ## addStructure(structureName, player, x, y[, direction]) //-- //-- Create a structure on the given position. Returns the structure on success, null otherwise. //-- Position uses world coordinates, if you want use position based on Map Tiles, then //-- use as addStructure(structureName, players, x*128, y*128) //-- -wzapi::returned_nullable_ptr wzapi::addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y)) +wzapi::returned_nullable_ptr wzapi::addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional _direction)) { int structureIndex = getStructStatFromName(WzString::fromUtf8(structureName.c_str())); SCRIPT_ASSERT(nullptr, context, structureIndex >= 0 && structureIndex < numStructureStats, "Structure %s not found", structureName.c_str()); SCRIPT_ASSERT_PLAYER(nullptr, context, player); + uint16_t direction = static_cast(DEG(_direction.value_or(0))); + STRUCTURE_STATS *psStat = &asStructureStats[structureIndex]; - STRUCTURE *psStruct = buildStructure(psStat, x, y, player, false); + STRUCTURE *psStruct = buildStructureDir(psStat, x, y, direction, player, false); if (psStruct) { psStruct->status = SS_BUILT; diff --git a/src/wzapi.h b/src/wzapi.h index 8b4b3ff7991..51f6144c534 100644 --- a/src/wzapi.h +++ b/src/wzapi.h @@ -1084,7 +1084,7 @@ namespace wzapi bool removeObject(WZAPI_PARAMS(BASE_OBJECT *psObj, optional _sfx)); no_return_value setScrollLimits(WZAPI_PARAMS(int x1, int y1, int x2, int y2)); scr_area getScrollLimits(WZAPI_NO_PARAMS); - returned_nullable_ptr addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y)); + returned_nullable_ptr addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional _direction)); unsigned int getStructureLimit(WZAPI_PARAMS(std::string structureName, optional _player)); int countStruct(WZAPI_PARAMS(std::string structureName, optional _playerFilter)); int countDroid(WZAPI_PARAMS(optional _droidType, optional _playerFilter)); From 989c2947903b84bf52b0fb5e7fdec5f068983844 Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:17:08 -0700 Subject: [PATCH 2/3] Add comment over magic number --- src/component.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/component.cpp b/src/component.cpp index 637c9623afe..37467524ae3 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -63,6 +63,7 @@ bool setPlayerColour(UDWORD player, UDWORD col) NetPlay.players[player].colour = MAX_PLAYERS; return true; } + // Allow color values from 0 to 15 ASSERT_OR_RETURN(false, col < 16, "Bad colour setting"); NetPlay.players[player].colour = col; return true; From 5d2f9cf108a37b63db805293703f3a870253fa30 Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Sat, 5 Aug 2023 13:02:40 -0700 Subject: [PATCH 3/3] A few small changes addStructure() now takes the direction argument as an int instead of a float. Added lines in functions.md and wzapi.cpp to clarify that the direction argument is optional. --- doc/js-functions.md | 1 + src/wzapi.cpp | 3 ++- src/wzapi.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/js-functions.md b/doc/js-functions.md index 017fcfb2276..d87ea33c250 100644 --- a/doc/js-functions.md +++ b/doc/js-functions.md @@ -775,6 +775,7 @@ Get the limits of the scrollable area of the map as an area object. (3.2+ only) Create a structure on the given position. Returns the structure on success, null otherwise. Position uses world coordinates, if you want use position based on Map Tiles, then use as addStructure(structureName, players, x*128, y*128) +Direction is optional, and is specified in degrees. ## getStructureLimit(structureName[, player]) diff --git a/src/wzapi.cpp b/src/wzapi.cpp index 34421952dca..e5a1bff02d5 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -2981,8 +2981,9 @@ scr_area wzapi::getScrollLimits(WZAPI_NO_PARAMS) //-- Create a structure on the given position. Returns the structure on success, null otherwise. //-- Position uses world coordinates, if you want use position based on Map Tiles, then //-- use as addStructure(structureName, players, x*128, y*128) +//-- Direction is optional, and is specified in degrees. //-- -wzapi::returned_nullable_ptr wzapi::addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional _direction)) +wzapi::returned_nullable_ptr wzapi::addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional _direction)) { int structureIndex = getStructStatFromName(WzString::fromUtf8(structureName.c_str())); SCRIPT_ASSERT(nullptr, context, structureIndex >= 0 && structureIndex < numStructureStats, "Structure %s not found", structureName.c_str()); diff --git a/src/wzapi.h b/src/wzapi.h index 51f6144c534..0e9c6051ad3 100644 --- a/src/wzapi.h +++ b/src/wzapi.h @@ -1084,7 +1084,7 @@ namespace wzapi bool removeObject(WZAPI_PARAMS(BASE_OBJECT *psObj, optional _sfx)); no_return_value setScrollLimits(WZAPI_PARAMS(int x1, int y1, int x2, int y2)); scr_area getScrollLimits(WZAPI_NO_PARAMS); - returned_nullable_ptr addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional _direction)); + returned_nullable_ptr addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional _direction)); unsigned int getStructureLimit(WZAPI_PARAMS(std::string structureName, optional _player)); int countStruct(WZAPI_PARAMS(std::string structureName, optional _playerFilter)); int countDroid(WZAPI_PARAMS(optional _droidType, optional _playerFilter));