Skip to content

Commit 233b231

Browse files
committed
Get and set Velocity
1 parent c154f92 commit 233b231

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

TheForceEngine/TFE_DarkForces/Scripting/gs_player.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "gs_player.h"
22
#include "assert.h"
3-
#include <TFE_DarkForces/player.h>
43
#include <TFE_DarkForces/mission.h>
54
#include <TFE_DarkForces/pickup.h>
65
#include <TFE_DarkForces/weapon.h>

TheForceEngine/TFE_DarkForces/Scripting/gs_player.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include <TFE_System/system.h>
33
#include <TFE_System/types.h>
4+
#include <TFE_DarkForces/player.h>
45
#include <TFE_ForceScript/scriptInterface.h>
56
#include <string>
67

@@ -11,4 +12,7 @@ namespace TFE_DarkForces
1112
public:
1213
bool scriptRegister(ScriptAPI api) override;
1314
};
15+
16+
vec3_float getPlayerVelocity();
17+
void setPlayerVelocity(vec3_float vel);
1418
}

TheForceEngine/TFE_DarkForces/Scripting/scriptObject.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "gs_level.h"
2+
#include "gs_player.h"
23
#include "scriptObject.h"
34
#include "scriptSector.h"
45
#include <angelscript.h>
@@ -451,6 +452,123 @@ namespace TFE_DarkForces
451452
}
452453
}
453454
}
455+
456+
vec3_float getVelocity(ScriptObject* sObject)
457+
{
458+
if (!doesObjectExist(sObject)) { return { 0, 0, 0,}; }
459+
SecObject* obj = TFE_Jedi::s_objectRefList[sObject->m_id].object;
460+
461+
// Is it the player?
462+
if (obj->entityFlags & ETFLAG_PLAYER)
463+
{
464+
return getPlayerVelocity();
465+
}
466+
467+
// First try to find a dispatch logic
468+
ActorDispatch* dispatch = getDispatch(obj);
469+
if (dispatch)
470+
{
471+
return
472+
{
473+
fixed16ToFloat(dispatch->vel.x),
474+
-fixed16ToFloat(dispatch->vel.y),
475+
fixed16ToFloat(dispatch->vel.z)
476+
};
477+
}
478+
479+
// Then try other logics
480+
Logic** logicPtr = (Logic**)allocator_getHead((Allocator*)obj->logic);
481+
while (logicPtr)
482+
{
483+
Logic* logic = *logicPtr;
484+
PhysicsActor* actor = nullptr;
485+
486+
switch (logic->type)
487+
{
488+
case LOGIC_BOBA_FETT:
489+
case LOGIC_DRAGON:
490+
case LOGIC_PHASE_ONE:
491+
case LOGIC_PHASE_TWO:
492+
case LOGIC_PHASE_THREE:
493+
case LOGIC_TURRET:
494+
case LOGIC_WELDER:
495+
case LOGIC_MOUSEBOT:
496+
SpecialActor* data = (SpecialActor*)logic;
497+
actor = &data->actor;
498+
break;
499+
}
500+
501+
if (actor)
502+
{
503+
return
504+
{
505+
fixed16ToFloat(actor->vel.x),
506+
-fixed16ToFloat(actor->vel.y),
507+
fixed16ToFloat(actor->vel.z)
508+
};
509+
}
510+
511+
logicPtr = (Logic**)allocator_getNext((Allocator*)obj->logic);
512+
}
513+
514+
return { 0, 0, 0 };
515+
}
516+
517+
void setVelocity(vec3_float vel, ScriptObject* sObject)
518+
{
519+
if (!doesObjectExist(sObject)) { return; }
520+
SecObject* obj = TFE_Jedi::s_objectRefList[sObject->m_id].object;
521+
522+
// Is it the player?
523+
if (obj->entityFlags & ETFLAG_PLAYER)
524+
{
525+
setPlayerVelocity(vel);
526+
return;
527+
}
528+
529+
// First try to find a dispatch logic
530+
ActorDispatch* dispatch = getDispatch(obj);
531+
if (dispatch)
532+
{
533+
dispatch->vel.x = floatToFixed16(vel.x);
534+
dispatch->vel.y = -floatToFixed16(vel.y);
535+
dispatch->vel.z = floatToFixed16(vel.z);
536+
return;
537+
}
538+
539+
// Then try other logics
540+
Logic** logicPtr = (Logic**)allocator_getHead((Allocator*)obj->logic);
541+
while (logicPtr)
542+
{
543+
Logic* logic = *logicPtr;
544+
PhysicsActor* actor = nullptr;
545+
546+
switch (logic->type)
547+
{
548+
case LOGIC_BOBA_FETT:
549+
case LOGIC_DRAGON:
550+
case LOGIC_PHASE_ONE:
551+
case LOGIC_PHASE_TWO:
552+
case LOGIC_PHASE_THREE:
553+
case LOGIC_TURRET:
554+
case LOGIC_WELDER:
555+
case LOGIC_MOUSEBOT:
556+
SpecialActor* data = (SpecialActor*)logic;
557+
actor = &data->actor;
558+
break;
559+
}
560+
561+
if (actor)
562+
{
563+
actor->vel.x = floatToFixed16(vel.x);
564+
actor->vel.y = -floatToFixed16(vel.y);
565+
actor->vel.z = floatToFixed16(vel.z);
566+
return;
567+
}
568+
569+
logicPtr = (Logic**)allocator_getNext((Allocator*)obj->logic);
570+
}
571+
}
454572

455573
void ScriptObject::registerType()
456574
{
@@ -516,5 +634,7 @@ namespace TFE_DarkForces
516634
ScriptPropertyGetFunc("int get_hitPoints()", getHitPoints);
517635
ScriptPropertySetFunc("void set_hitPoints(int)", setHitPoints);
518636
ScriptPropertySetFunc("void set_projectile(int)", setProjectile);
637+
ScriptPropertyGetFunc("float3 get_velocity()", getVelocity);
638+
ScriptPropertySetFunc("void set_velocity(float3)", setVelocity);
519639
}
520640
}

0 commit comments

Comments
 (0)