|
| 1 | +/* |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 3 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 4 | + * obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | + * |
| 6 | + * The original code is copyright (c) 2024, open.mp team and contributors. |
| 7 | + */ |
| 8 | + |
| 9 | +#include "../ComponentManager.hpp" |
| 10 | + |
| 11 | +OMP_CAPI(Actor_Create, objectPtr(int model, float x, float y, float z, float rot, int* id)) |
| 12 | +{ |
| 13 | + IActorsComponent* component = ComponentManager::Get()->actors; |
| 14 | + if (component) |
| 15 | + { |
| 16 | + IActor* actor = component->create(model, { x, y, z }, rot); |
| 17 | + if (actor) |
| 18 | + { |
| 19 | + *id = actor->getID(); |
| 20 | + return actor; |
| 21 | + } |
| 22 | + } |
| 23 | + return nullptr; |
| 24 | +} |
| 25 | + |
| 26 | +OMP_CAPI(Actor_Destroy, bool(objectPtr actor)) |
| 27 | +{ |
| 28 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 29 | + actors->release(actor_->getID()); |
| 30 | + return true; |
| 31 | +} |
| 32 | + |
| 33 | +OMP_CAPI(Actor_FromID, objectPtr(int actorid)) |
| 34 | +{ |
| 35 | + IActorsComponent* component = ComponentManager::Get()->actors; |
| 36 | + if (component) |
| 37 | + { |
| 38 | + return component->get(actorid); |
| 39 | + } |
| 40 | + return nullptr; |
| 41 | +} |
| 42 | + |
| 43 | +OMP_CAPI(Actor_GetID, int(objectPtr actor)) |
| 44 | +{ |
| 45 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, INVALID_ACTOR_ID); |
| 46 | + return actor_->getID(); |
| 47 | +} |
| 48 | + |
| 49 | +OMP_CAPI(Actor_IsStreamedInFor, bool(objectPtr actor, objectPtr player)) |
| 50 | +{ |
| 51 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 52 | + POOL_ENTITY_RET(players, IPlayer, player, player_, false); |
| 53 | + return actor_->isStreamedInForPlayer(*player_); |
| 54 | +} |
| 55 | + |
| 56 | +OMP_CAPI(Actor_SetVirtualWorld, bool(objectPtr actor, int vw)) |
| 57 | +{ |
| 58 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 59 | + actor_->setVirtualWorld(vw); |
| 60 | + return true; |
| 61 | +} |
| 62 | + |
| 63 | +OMP_CAPI(Actor_GetVirtualWorld, int(objectPtr actor)) |
| 64 | +{ |
| 65 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, 0); |
| 66 | + return actor_->getVirtualWorld(); |
| 67 | +} |
| 68 | + |
| 69 | +OMP_CAPI(Actor_ApplyAnimation, bool(objectPtr actor, StringCharPtr name, StringCharPtr library, float delta, bool loop, bool lockX, bool lockY, bool freeze, int time)) |
| 70 | +{ |
| 71 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 72 | + const AnimationData animationData(delta, loop, lockX, lockY, freeze, uint32_t(time), library, name); |
| 73 | + actor_->applyAnimation(animationData); |
| 74 | + return true; |
| 75 | +} |
| 76 | + |
| 77 | +OMP_CAPI(Actor_ClearAnimations, bool(objectPtr actor)) |
| 78 | +{ |
| 79 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 80 | + actor_->clearAnimations(); |
| 81 | + return true; |
| 82 | +} |
| 83 | + |
| 84 | +OMP_CAPI(Actor_SetPos, bool(objectPtr actor, float x, float y, float z)) |
| 85 | +{ |
| 86 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 87 | + actor_->setPosition({ x, y, z }); |
| 88 | + return true; |
| 89 | +} |
| 90 | + |
| 91 | +OMP_CAPI(Actor_GetPos, bool(objectPtr actor, float* x, float* y, float* z)) |
| 92 | +{ |
| 93 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 94 | + const Vector3& pos = actor_->getPosition(); |
| 95 | + |
| 96 | + *x = pos.x; |
| 97 | + *y = pos.y; |
| 98 | + *z = pos.z; |
| 99 | + return true; |
| 100 | +} |
| 101 | + |
| 102 | +OMP_CAPI(Actor_SetFacingAngle, bool(objectPtr actor, float angle)) |
| 103 | +{ |
| 104 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 105 | + actor_->setRotation(Vector3(0.0f, 0.0f, angle)); |
| 106 | + return true; |
| 107 | +} |
| 108 | + |
| 109 | +OMP_CAPI(Actor_GetFacingAngle, float(objectPtr actor)) |
| 110 | +{ |
| 111 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, 0.0f); |
| 112 | + return actor_->getRotation().ToEuler().z; |
| 113 | +} |
| 114 | + |
| 115 | +OMP_CAPI(Actor_SetHealth, bool(objectPtr actor, float hp)) |
| 116 | +{ |
| 117 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 118 | + actor_->setHealth(hp); |
| 119 | + return true; |
| 120 | +} |
| 121 | + |
| 122 | +OMP_CAPI(Actor_GetHealth, float(objectPtr actor)) |
| 123 | +{ |
| 124 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, 0.0f); |
| 125 | + return actor_->getHealth(); |
| 126 | +} |
| 127 | + |
| 128 | +OMP_CAPI(Actor_SetInvulnerable, bool(objectPtr actor, bool toggle)) |
| 129 | +{ |
| 130 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 131 | + actor_->setInvulnerable(toggle); |
| 132 | + return true; |
| 133 | +} |
| 134 | + |
| 135 | +OMP_CAPI(Actor_IsInvulnerable, bool(objectPtr actor)) |
| 136 | +{ |
| 137 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 138 | + return actor_->isInvulnerable(); |
| 139 | +} |
| 140 | + |
| 141 | +OMP_CAPI(Actor_IsValid, bool(objectPtr actor)) |
| 142 | +{ |
| 143 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 144 | + if (!actors->get(actor_->getID())) |
| 145 | + return false; |
| 146 | + return true; |
| 147 | +} |
| 148 | + |
| 149 | +OMP_CAPI(Actor_SetSkin, bool(objectPtr actor, int skin)) |
| 150 | +{ |
| 151 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 152 | + actor_->setSkin(skin); |
| 153 | + return true; |
| 154 | +} |
| 155 | + |
| 156 | +OMP_CAPI(Actor_GetSkin, int(objectPtr actor)) |
| 157 | +{ |
| 158 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, 0); |
| 159 | + return actor_->getSkin(); |
| 160 | +} |
| 161 | + |
| 162 | +OMP_CAPI(Actor_GetAnimation, bool(objectPtr actor, OutputStringViewPtr library, OutputStringViewPtr name, float* delta, bool* loop, bool* lockX, bool* lockY, bool* freeze, int* time)) |
| 163 | +{ |
| 164 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 165 | + const AnimationData& anim = actor_->getAnimation(); |
| 166 | + |
| 167 | + SET_CAPI_STRING_VIEW(library, anim.lib); |
| 168 | + SET_CAPI_STRING_VIEW(name, anim.name); |
| 169 | + *delta = anim.delta; |
| 170 | + *loop = anim.loop; |
| 171 | + *lockX = anim.lockX; |
| 172 | + *lockY = anim.lockY; |
| 173 | + *freeze = anim.freeze; |
| 174 | + *time = int(anim.time); |
| 175 | + return true; |
| 176 | +} |
| 177 | + |
| 178 | +OMP_CAPI(Actor_GetSpawnInfo, bool(objectPtr actor, float* x, float* y, float* z, float* angle, int* skin)) |
| 179 | +{ |
| 180 | + POOL_ENTITY_RET(actors, IActor, actor, actor_, false); |
| 181 | + const ActorSpawnData& spawnData = actor_->getSpawnData(); |
| 182 | + |
| 183 | + *x = spawnData.position.x; |
| 184 | + *y = spawnData.position.y; |
| 185 | + *z = spawnData.position.z; |
| 186 | + *angle = spawnData.facingAngle; |
| 187 | + *skin = spawnData.skin; |
| 188 | + return true; |
| 189 | +} |
0 commit comments