|
4 | 4 | #include <TFE_DarkForces/mission.h>
|
5 | 5 | #include <TFE_DarkForces/pickup.h>
|
6 | 6 | #include <TFE_DarkForces/weapon.h>
|
| 7 | +#include <TFE_Jedi/Collision/collision.h> |
| 8 | +#include <TFE_FrontEndUI/frontEndUi.h> |
7 | 9 | #include <TFE_System/system.h>
|
8 | 10 | #include <angelscript.h>
|
9 | 11 |
|
@@ -33,6 +35,91 @@ namespace TFE_DarkForces
|
33 | 35 | s_reviveTick = s_curTick + 436;
|
34 | 36 | }
|
35 | 37 |
|
| 38 | + vec3_float getPlayerPosition() |
| 39 | + { |
| 40 | + return |
| 41 | + { |
| 42 | + fixed16ToFloat(s_playerObject->posWS.x), |
| 43 | + -fixed16ToFloat(s_playerObject->posWS.y), |
| 44 | + fixed16ToFloat(s_playerObject->posWS.z), |
| 45 | + }; |
| 46 | + } |
| 47 | + |
| 48 | + void setPlayerPosition(vec3_float position) |
| 49 | + { |
| 50 | + fixed16_16 newX = floatToFixed16(position.x); |
| 51 | + fixed16_16 newY = -floatToFixed16(position.y); |
| 52 | + fixed16_16 newZ = floatToFixed16(position.z); |
| 53 | + |
| 54 | + // Check if player object has moved out of its current sector |
| 55 | + // Start with a bounds check |
| 56 | + bool outOfHorzBounds = newX < s_playerObject->sector->boundsMin.x || newX > s_playerObject->sector->boundsMax.x || |
| 57 | + newZ < s_playerObject->sector->boundsMin.z || newZ > s_playerObject->sector->boundsMax.z; |
| 58 | + bool outOfVertBounds = newY < s_playerObject->sector->ceilingHeight || newY > s_playerObject->sector->floorHeight; |
| 59 | + |
| 60 | + // If within bounds, check if it has passed through a wall |
| 61 | + RWall* collisionWall = nullptr; |
| 62 | + if (!outOfHorzBounds && !outOfVertBounds) |
| 63 | + { |
| 64 | + collisionWall = collision_wallCollisionFromPath(s_playerObject->sector, s_playerObject->posWS.x, s_playerObject->posWS.z, newX, newZ); |
| 65 | + } |
| 66 | + |
| 67 | + if (collisionWall || outOfHorzBounds || outOfVertBounds) |
| 68 | + { |
| 69 | + // Try to find a new sector for the player object; if there is none, don't move it |
| 70 | + RSector* sector = sector_which3D(newX, newY, newZ); |
| 71 | + if (sector) |
| 72 | + { |
| 73 | + if (sector != s_playerObject->sector) |
| 74 | + { |
| 75 | + sector_addObject(sector, s_playerObject); |
| 76 | + } |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + TFE_FrontEndUI::logToConsole("Cannot find a sector to move player to."); |
| 81 | + return; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + s_playerObject->posWS.x = newX; |
| 86 | + s_playerObject->posWS.y = newY; |
| 87 | + s_playerObject->posWS.z = newZ; |
| 88 | + s_playerYPos = newY; |
| 89 | + } |
| 90 | + |
| 91 | + float getPlayerYaw() |
| 92 | + { |
| 93 | + return angleToFloat(s_playerObject->yaw); |
| 94 | + } |
| 95 | + |
| 96 | + void setPlayerYaw(float value) |
| 97 | + { |
| 98 | + float yaw = floatToAngle(value); |
| 99 | + s_playerObject->yaw = yaw; |
| 100 | + s_playerYaw = yaw; |
| 101 | + } |
| 102 | + |
| 103 | + vec3_float getPlayerVelocity() |
| 104 | + { |
| 105 | + vec3_fixed velFixed; |
| 106 | + TFE_DarkForces::player_getVelocity(&velFixed); |
| 107 | + |
| 108 | + return { |
| 109 | + fixed16ToFloat(velFixed.x), |
| 110 | + -fixed16ToFloat(velFixed.y), |
| 111 | + fixed16ToFloat(velFixed.z), |
| 112 | + }; |
| 113 | + } |
| 114 | + |
| 115 | + void setPlayerVelocity(vec3_float vel) |
| 116 | + { |
| 117 | + s_playerVelX = floatToFixed16(vel.x); |
| 118 | + s_playerUpVel = -floatToFixed16(vel.y); |
| 119 | + s_playerUpVel2 = -floatToFixed16(vel.y); |
| 120 | + s_playerVelZ = floatToFixed16(vel.z); |
| 121 | + } |
| 122 | + |
36 | 123 | s32 getBatteryPercent()
|
37 | 124 | {
|
38 | 125 | return (s32)(100.0 * s_batteryPower / FIXED(2) );
|
@@ -492,6 +579,14 @@ namespace TFE_DarkForces
|
492 | 579 |
|
493 | 580 | ScriptObjFunc("void kill()", killPlayer);
|
494 | 581 |
|
| 582 | + // Position and velocity |
| 583 | + ScriptPropertyGetFunc("float3 get_position()", getPlayerPosition); |
| 584 | + ScriptPropertySetFunc("void set_position(float3)", setPlayerPosition); |
| 585 | + ScriptPropertyGetFunc("float get_yaw()", getPlayerYaw); |
| 586 | + ScriptPropertySetFunc("void set_yaw(float)", setPlayerYaw); |
| 587 | + ScriptPropertyGetFunc("float3 get_velocity()", getPlayerVelocity); |
| 588 | + ScriptPropertySetFunc("void set_velocity(float3)", setPlayerVelocity); |
| 589 | + |
495 | 590 | // Health / ammo getters
|
496 | 591 | ScriptLambdaPropertyGet("int get_health()", s32, { return s_playerInfo.health; });
|
497 | 592 | ScriptLambdaPropertyGet("int get_shields()", s32, { return s_playerInfo.shields; });
|
|
0 commit comments