ekudmada / Reforger-Shop-System

Other
7 stars 1 forks source link

No free space check for vehicles #1

Open nomisum opened 11 months ago

nomisum commented 11 months ago

Currently it seems there is no meaningful space check for spawning vehicles from merchant. Code here: https://github.com/ekudmada/Reforger-Shop-System/blob/0dc0dbe2168187d6aacbce88b21b11b3f38386dd/Scripts/Game/ShopSystem/MerchandiseTypes/ADM_MerchandiseVehicle.c#L73

It seems params does not respect the free space check inside CanDeliver / CanRespawn but simply takes a hardcoded position.

In our setup we dynamically move the shop around and multiple issues came up:

ekudmada commented 11 months ago

@nomisum Interesting use case. I will take a look soon and see if I can reproduce. Is it possible to share your script that teleports the shop around so I can test quickly?

nomisum commented 11 months ago

we use it in here: https://github.com/gruppe-adler/GRAD-On-The-Fly

its also in workshop if you want to quick start it

to spawn you need to start the game with a little custom button on top as gamemaster (inits phase opfor), then set a marker called 'opfor' as opfor commander (slot is important) to select spawn position

shop is attached to barrel that indicates capture position and sits on opfor spawn

nomisum commented 11 months ago

Ah sorry, Currently the shop only has vehicles for Blufor (Commander Role as well, marker called blufor). Its a bit cumbersome to test alone I suppose.

nomisum commented 11 months ago

did a local fix:

[BaseContainerProps()]
modded class ADM_MerchandiseVehicle: ADM_MerchandiseType
{   
    override EntitySpawnParams GetVehicleSpawnTransform(ADM_ShopBaseComponent shop)
    {
        EntitySpawnParams params = EntitySpawnParams();
        params.TransformMode = ETransformMode.WORLD;

        if (m_SpawnPosition && !shop.IsInherited(ADM_PhysicalShopComponent)) {
            m_SpawnPosition.GetWorldTransform(params.Transform);
            params.Transform[3] = shop.GetOwner().CoordToParent(params.Transform[3]);
        } else {
            shop.GetOwner().GetTransform(params.Transform);
        }       

        bool foundPositionEmpty = false;
        int spawnRadiusMin = 5;
        int spawnRadiusMax = 75;

        while (!foundPositionEmpty) {
            params.Transform[3][0] = params.Transform[3][0] + Math.RandomFloat(-spawnRadiusMin, spawnRadiusMin);
            params.Transform[3][2] = params.Transform[3][2] + Math.RandomFloat(-spawnRadiusMin, spawnRadiusMin);
            params.Transform[3][1] = GetGame().GetWorld().GetSurfaceY(params.Transform[3][0], params.Transform[3][2]);
            foundPositionEmpty = ADM_Utils.IsSpawnPositionClean(m_sPrefab, params, {});

            if (spawnRadiusMin < spawnRadiusMax) {
                spawnRadiusMin += 0.25;
                Print(string.Format("OTF - Cant find free position, radius '%1'", spawnRadiusMin), LogLevel.NORMAL);
            }
        }

        Print(string.Format("OTF - Found free position at radius  '%1'", spawnRadiusMin), LogLevel.NORMAL);

        return params;
    }
}