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

feat(gamestate/server): ped AI node getter #3061

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ struct CPedMovementGroupNodeData
bool isRagdolling;
};

struct CPedAINodeData
{
int relationShip;
int decisionMaker;
};

enum ePopType
{
POPTYPE_UNKNOWN = 0,
Expand Down Expand Up @@ -851,6 +857,8 @@ struct SyncTreeBase

virtual CPedMovementGroupNodeData* GetPedMovementGroup() = 0;

virtual CPedAINodeData* GetPedAI() = 0;

virtual void CalculatePosition() = 0;

virtual bool GetPopulationType(ePopType* popType) = 0;
Expand Down
22 changes: 20 additions & 2 deletions code/components/citizen-server-impl/include/state/SyncTrees_Five.h
Original file line number Diff line number Diff line change
Expand Up @@ -2466,9 +2466,20 @@ struct CPedMovementGroupDataNode

return true;
}
};
};

struct CPedAIDataNode : GenericSerializeDataNode<CPedAIDataNode>
{
CPedAINodeData data;

struct CPedAIDataNode { };
template<typename Serializer>
bool Serialize(Serializer& s)
{
s.Serialize(32, data.relationShip);
s.Serialize(32, data.decisionMaker);
return true;
}
};

struct CPedAppearanceDataNode
{
Expand Down Expand Up @@ -4068,6 +4079,13 @@ struct SyncTree : public SyncTreeBaseImpl<TNode, false>
{
auto [hasNode, node] = this->template GetData<CPedMovementGroupDataNode>();

return hasNode ? &node->data : nullptr;
}

virtual CPedAINodeData* GetPedAI() override
{
auto [hasNode, node] = this->template GetData<CPedAIDataNode>();

return hasNode ? &node->data : nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,11 @@ struct SyncTree : public SyncTreeBaseImpl<TNode, true>
return nullptr;
}

virtual CPedAINodeData* GetPedAI() override
{
return nullptr;
}

virtual void CalculatePosition() override
{
// TODO: cache it?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,12 @@ static void Init()
return 0;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_PED_RELATIONSHIP_GROUP_HASH", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
auto ped = entity->syncTree->GetPedAI();
return ped ? ped->relationShip : 0;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_ENTITY_SPEED", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
auto v = entity->syncTree->GetVelocity();
Expand Down
17 changes: 17 additions & 0 deletions ext/native-decls/GetPedRelationshipGroupHash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
ns: CFX
apiset: server
---
## GET_PED_RELATIONSHIP_GROUP_HASH

```c
Hash GET_PED_RELATIONSHIP_GROUP_HASH(Ped ped);
```

Gets the current relationship group hash of a ped.

## Parameters
* **ped**: The target ped

## Return value
The relationship group hash.
Loading