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

Add script expression parsing support for primitive functions with parameter lists #377

Merged
merged 8 commits into from May 6, 2021

Conversation

Hypexion
Copy link
Contributor

@Hypexion Hypexion commented Mar 6, 2021

It's #354, but for mainline DROD. Adds functions that be used when setting variables. I consider the functions to exist in three categories.

Mathematical

For the manipulation of numbers or calculation of values.

_abs(x) - Returns the absolute value of x
min(x,y) and max(x,y) - Returns the lesser and greater value, respectively.
_dist0(x1,y1,x2,y2) - Distance between two points using L-infinity metric
_dist1(x1,y1,x2,y2) - Distance between two points using L1 metric
_dist2(x1,y1,x2,y2) - Distance between two points using L2 metric

DROD Maths

Number crunching, in specific DROD contexts

_ox(o) and _oy(o) - Returns x and y components of the given orientation. Invalid orientations return themselves
_orient(x,y) - Returns the orientation based on the given x and y component
_facing(dx,dy) - Returns the orientation closest to the direction of the given vector.
_rotateCW(o) and _rotateCCW(o) - Returns next clockwise or counterclockwise direction
_rotationDist(o1, o2) - How many rotations between the two orientations. If either value is invalid, returns zero.

Room Information

Finds information about the room.

_ArrowDir(x,y) - Direction of arrow at (x,y). Arrowless tiles return 4, for NO_ORIENTATION
_MonsterType(x,y) - The type of monster at (x,y). Monsterless tile returns -1, because Roaches are monster zero.
_RoomTile(x,y,z) - The tile id of the tile at (x,y). z parameter chooses the layer to inspect.

@Hypexion
Copy link
Contributor Author

Hypexion commented Mar 6, 2021

This PR is currently in draft form while I sort out tests and possible additional functions that would be useful in mainline DROD. Suggestions welcome.

@Hypexion Hypexion marked this pull request as ready for review March 18, 2021 18:03
Copy link
Member

@mrimer mrimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was happy to see this PR. :)

I really appreciate you porting this functionality to DROD and adding your own useful primitives.

Excellent work, and thank you also for the test cases.

I made a couple remarks, but I consider this ready to merge as soon as you think it's ready.

DRODLib/Character.cpp Outdated Show resolved Hide resolved
@@ -836,7 +851,7 @@ bool CCharacter::IsValidExpression(
//Parse another term.
if (pwStr[index] == W_t('+') || pwStr[index] == W_t('-'))
++index;
else if (bExpectCloseParen && pwStr[index] == W_t(')')) //closing nested expression
else if (closingChar && pwStr[index] == closingChar) //closing nested expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking:
In the original/source RPG code, I had pwStr[index] == W_t(closingChar).
Will leaving out the W_t cast always compile correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. This macro doesn't do anything for a Windows build, but it looks like it's used for other platforms.

{
CMonster* pMonster = this->pRoom->GetMonsterAtSquare(params[0], params[1]);
if (pMonster) {
return pMonster->wType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new operators are wonderful!

I can envision future additional operators querying various states of a character monster as well.

@mrimer mrimer merged commit a60bb96 into CaravelGames:tss-5.2-dev May 6, 2021
@Hypexion Hypexion deleted the script-primitve-functions branch May 6, 2021 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants