Esempio n. 1
0
        private void SetProjectileVerticesOnHash(DynamicPosition2 projectileState)
        {
            Debug.Assert(mVertexHash.Count == 0);
            const float projectileScale   = 1f / 30f;
            const float forwardProportion = 0.12f;
            const float lateralScale      = 0.125f;
            Vector2     position          = projectileState.Position;
            Vector2     direction         = projectileScale * projectileState.Velocity;
            Vector2     lateral           = lateralScale * (new Vector2(-direction.Y, direction.X));

            mVertexHash.Add(position + forwardProportion * direction);
            mVertexHash.Add(position + lateral);
            mVertexHash.Add(position + (forwardProportion - 1f) * direction);
            mVertexHash.Add(position - lateral);
        }
Esempio n. 2
0
        private SimulationState GetPrimedState(Option option)
        {
            SimulationState simState = new SimulationState(2);

            //Add the state resulting from this option, and a mock shot to track hits
            simState.AddVehicle(mControlledID, option.ResultingState);
            simState.SetProjectileCount(mControlledID, 1);
            DynamicPosition2 mockProjectile = SimulationProcessor.CreateProjectileState(option.ResultingState.DynamicTransform, mSimData.GetVehiclePrototype(mControlledID).Guns, 0, mDeltaTime);

            simState.GetProjectiles(mControlledID).Add(mockProjectile);
            //Add the existing enemy projectiles, if they have any hope to hit
            simState.SetProjectileCount(mTargetID, mEnemyProjectiles.Count);
            simState.GetProjectiles(mTargetID).AddRange(mEnemyProjectiles);
            VehicleState targetRandomState = GetRandomNextState(mTargetRootState, mSimData.GetVehiclePrototype(mTargetID), mRandom, mDeltaTime);

            simState.AddVehicle(mTargetID, targetRandomState);
            return(simState);
        }
Esempio n. 3
0
        public void ResetAndSetup(SimulationState currentSimState)
        {
            mTargetRootState = currentSimState.GetVehicle(mTargetID);
            mEnemyProjectiles.Clear();

            VehiclePrototype controlledPrototype = mSimData.GetVehiclePrototype(mControlledID);
            VehicleState     controlledState     = currentSimState.GetVehicle(mControlledID);

            var projectiles = currentSimState.GetProjectiles(mTargetID);

            //Cache the projectile states for next frame, but onyl those with a chance of hiting
            foreach (var projectile in projectiles)
            {
                Vector2 relativePosition = controlledState.DynamicTransform.Position - projectile.Position;
                Vector2 relativeVelocity = controlledState.DynamicTransform.Velocity - projectile.Velocity;
                if (Vector2.Dot(relativePosition, relativeVelocity) < 0f)
                {
                    if (!SimulationProcessor.ProjectileHitsVehicle(controlledState.DynamicTransform, controlledPrototype, projectile, mDeltaTime))
                    {
                        DynamicPosition2 updatedProjectile = new DynamicPosition2(projectile.Position + mDeltaTime * projectile.Velocity, projectile.Velocity);
                        mEnemyProjectiles.Add(projectile);
                    }
                }
            }


            mOptions.Clear();
            controlledPrototype.ControlConfig.GetPossibleControlChanges(controlledState.ControlState, mDeltaTime, mControlOptionCache);
            foreach (var driveControlOption in mControlOptionCache)
            {
                VehicleControls   controlOption         = new VehicleControls(driveControlOption);
                DynamicTransform2 resultingDynamicState = controlledPrototype.VehicleDrive(controlledState.DynamicTransform, driveControlOption, mDeltaTime);
                VehicleState      resultingVehicleState = new VehicleState(resultingDynamicState, driveControlOption); //We should not care for the gun state... I thnk...

                Option option = new Option(controlOption, resultingVehicleState);
                mOptions.Add(option);
            }
            mControlOptionCache.Clear();
            mIterations = 0;
        }