Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand addStructure() and changePlayerColour() functions #3202

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/js-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -769,11 +770,12 @@ 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
use as addStructure(structureName, players, x*128, y*128)
Direction is optional, and is specified in degrees.

## getStructureLimit(structureName[, player])

Expand Down
3 changes: 2 additions & 1 deletion src/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ bool setPlayerColour(UDWORD player, UDWORD col)
NetPlay.players[player].colour = MAX_PLAYERS;
return true;
}
ASSERT_OR_RETURN(false, col < MAX_PLAYERS, "Bad colour setting");
// Allow color values from 0 to 15
ASSERT_OR_RETURN(false, col < 16, "Bad colour setting");
NetPlay.players[player].colour = col;
return true;
}
Expand Down
14 changes: 9 additions & 5 deletions src/wzapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -2975,20 +2976,23 @@ 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)
//-- Direction is optional, and is specified in degrees.
//--
past-due marked this conversation as resolved.
Show resolved Hide resolved
wzapi::returned_nullable_ptr<const STRUCTURE> wzapi::addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y))
wzapi::returned_nullable_ptr<const STRUCTURE> wzapi::addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional<int> _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<uint16_t>(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;
Expand Down
2 changes: 1 addition & 1 deletion src/wzapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ namespace wzapi
bool removeObject(WZAPI_PARAMS(BASE_OBJECT *psObj, optional<bool> _sfx));
no_return_value setScrollLimits(WZAPI_PARAMS(int x1, int y1, int x2, int y2));
scr_area getScrollLimits(WZAPI_NO_PARAMS);
returned_nullable_ptr<const STRUCTURE> addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y));
returned_nullable_ptr<const STRUCTURE> addStructure(WZAPI_PARAMS(std::string structureName, int player, int x, int y, optional<int> _direction));
unsigned int getStructureLimit(WZAPI_PARAMS(std::string structureName, optional<int> _player));
int countStruct(WZAPI_PARAMS(std::string structureName, optional<int> _playerFilter));
int countDroid(WZAPI_PARAMS(optional<int> _droidType, optional<int> _playerFilter));
Expand Down
Loading