Skip to content

Commit

Permalink
fix gangzone and pickups, added GetGazoneId andd GetGanzoneFromID fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
Sreyas-Sreelal committed Jun 7, 2024
1 parent 570a740 commit 05af030
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
43 changes: 41 additions & 2 deletions functions/gangzones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ OMPRS_API(void*, GangZoneCreate(GangZonePos pos))
IGangZonesComponent* component = OMPRSComponent::Get()->GetGangZones();
if (component)
{
return component->create(pos);
int id = component->reserveLegacyID();
if (id == INVALID_GANG_ZONE_ID)
{
return nullptr;
}

IGangZone* gz = component->create(pos);
if (gz)
{
component->setLegacyID(id, gz->getID());
return gz;
}
else
{
component->releaseLegacyID(id);
}
}
return nullptr;
}
Expand All @@ -21,6 +36,7 @@ OMPRS_API(void,GangZoneDestroy(void* gangzone))
if (id)
{
pool->release(id);
pool->releaseLegacyID(pool->toLegacyID(id));
}
}
}
Expand Down Expand Up @@ -86,7 +102,7 @@ OMPRS_API(bool,IsValidGangZoneID(int gangzoneid))
IGangZonesComponent* component = OMPRSComponent::Get()->GetGangZones();
if (component)
{
return component->get(gangzoneid) != nullptr;
return !!component->fromLegacyID(gangzoneid);
}
return false;
}
Expand Down Expand Up @@ -142,3 +158,26 @@ OMPRS_API(void,UseGangZoneCheck(void* gangzone, bool enable))
}
}

OMPRS_API(int, GetGangZoneID(void* gangzone))
{
IGangZonesComponent* component = OMPRSComponent::Get()->GetGangZones();
if (component)
{
return component->toLegacyID(static_cast<IGangZone*>(gangzone)->getID());
}
return INVALID_GANG_ZONE_ID;
}

OMPRS_API(void*, GetGangZoneFromID(int gangzoneid))
{
IGangZonesComponent* component = OMPRSComponent::Get()->GetGangZones();
if (component)
{
int realid = component->fromLegacyID(gangzoneid);
if (realid)
{
return component->get(realid);
}
}
return nullptr;
}
40 changes: 37 additions & 3 deletions functions/pickups.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ OMPRS_API(void*,CreatePickup(int model, int type, Vector3 position, int virtualW
IPickupsComponent* component = OMPRSComponent::Get()->GetPickups();
if (component)
{
return component->create(model, type, position, virtualWorld, false);
int id = component->reserveLegacyID();
if (id == INVALID_PICKUP_ID)
{
return nullptr;
}
IPickup * pickup = component->create(model, type, position, virtualWorld, false);
if (pickup)
{
component->setLegacyID(id, pickup->getID());
return pickup;
}
else
{
component->releaseLegacyID(id);
}
}
return nullptr;
}
Expand All @@ -17,7 +31,21 @@ OMPRS_API(void*,AddStaticPickup(int model, int type, Vector3 position, int virtu
IPickupsComponent* component = OMPRSComponent::Get()->GetPickups();
if (component)
{
return component->create(model, type, position, virtualWorld, true);
int id = component->reserveLegacyID();
if (id == INVALID_PICKUP_ID)
{
return nullptr;
}
IPickup* pickup = component->create(model, type, position, virtualWorld, true);
if (pickup)
{
component->setLegacyID(id, pickup->getID());
return pickup;
}
else
{
component->releaseLegacyID(id);
}
}
return nullptr;
}
Expand All @@ -31,6 +59,7 @@ OMPRS_API(void,DestroyPickup(void* pickup))
if (id)
{
component->release(id);
component->releaseLegacyID(component->toLegacyID(id));
}
}
}
Expand Down Expand Up @@ -112,7 +141,12 @@ OMPRS_API(void*, GetPickupFromID(int pickupid))
IPickupsComponent* component = OMPRSComponent::Get()->GetPickups();
if (component)
{
component->get(pickupid);
int realid = component->fromLegacyID(pickupid);
if (realid)
{
return component->get(pickupid);
}

}
return nullptr;
}

0 comments on commit 05af030

Please sign in to comment.