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
Add script expression parsing support for primitive functions with parameter lists #377
Conversation
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. |
There was a problem hiding this 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
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
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 xmin(x,y)
andmax(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 metricDROD 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.