Ejemplo n.º 1
0
        private void ApplyTerrainMinimum()
        {
            float terrainHeight = EnvironmentPhysics.FindHeightAt(
                camIndependentLocation.position.x,
                camIndependentLocation.position.z
                );
            float heightAboveTerrain = camIndependentLocation.position.y
                                       - terrainHeight;
            float tempVerticalAngle = verticalAngle;

            while (heightAboveTerrain < minimumHeightFromTerrain &&
                   tempVerticalAngle < 89)
            {
                camIndependentLocation.RotateAround(
                    focus.position,
                    new Vector3(camIndependentLocation.right.x,
                                0,
                                camIndependentLocation.right.z
                                ),
                    1
                    );
                tempVerticalAngle++;
                heightAboveTerrain = camIndependentLocation.position.y
                                     - terrainHeight;
            }
        }
Ejemplo n.º 2
0
    private static List <TerrainDisparity> CalculateAllCoverDisparities(
        HumanoidVantage strategizer,
        List <HumanoidVantage> enemyVantages,
        Vector3 location
        )
    {
        List <TerrainDisparity> totalDisparity = new List <TerrainDisparity>();

        Projectile stratWeaponThreat = strategizer.GetWeaponThreat();
        Vector3    standingAtEnd     = location.AddY(strategizer.GetStandingHeight());
        Vector3    kneelingAtEnd     = location.AddY(strategizer.GetKneelingHeight());
        Vector3    layingAtEnd       = location.AddY(strategizer.GetLayingHeight());

        foreach (HumanoidVantage enemyVantage in enemyVantages)
        {
            Projectile enemyWeaponThreat = enemyVantage.GetWeaponThreat();
            Vector3    enemyStanding     = enemyVantage.GetStandingVantage();
            Vector3    enemyKneeling     = enemyVantage.GetKneelingVantage();
            Vector3    enemyLaying       = enemyVantage.GetLayingVantage();

            TerrainDisparity topToTopDisp =
                EnvironmentPhysics.CalculateTerrainDisparityBetween(
                    stratWeaponThreat,
                    enemyWeaponThreat,
                    standingAtEnd,
                    enemyStanding
                    );

            totalDisparity.Add(topToTopDisp);
        }

        return(totalDisparity);
    }
Ejemplo n.º 3
0
    private static void AddNode(Point location)
    {
        MapNode newNode =
            EnvironmentPhysics.CreateMapNodeAt(
                instance.NodeTo2DWorldCoord(location)
                );

        instance.nodes[location] = newNode;
        instance.pointsInUse.Add(location);
        //if(instance.nodes.Count > MAX_NODE_CACHE_SIZE){
        //    RemoveNode();
        //}
    }
Ejemplo n.º 4
0
    public void DrawWithGizmos()
    {
        Gizmos.color = Color.black;
        foreach (Vector3 p in lookPoints)
        {
            Gizmos.DrawCube(new Vector3(p.x, EnvironmentPhysics.FindHeightAt(p.x, p.z) + 1, p.z), Vector3.one);
        }

        //Gizmos.color = Color.white;

        /*foreach (Line l in turnBoundaries) {
         *      l.DrawWithGizmos (10);
         * }*/
    }
Ejemplo n.º 5
0
 void Awake()
 {
     instance         = this;
     bottomLeftCorner = mapbounds.GetBottomLeftCorner();
     maxDimensions    = mapbounds.GetDimensions();
     projectileCanPassThroughCache =
         new LinkedDictionary <Tuple <Projectile, Vector3, Vector3>, bool>(
             new ProjectileCanPassThroughCacheComparer()
             );
     calculateTerrainDisparityBetweenCache =
         new LinkedDictionary <Tuple <Projectile, Projectile, Vector3, Vector3>, TerrainDisparity>(
             new CalculateTerrainDisparityBetweenComparer()
             );
     calculateVisiblePortionCache =
         new LinkedDictionary <Tuple <Projectile, Vector3, Vector3>, VisiblePortionResult>();
 }
Ejemplo n.º 6
0
    private void CreateLocationInDirection(Vector2 direction)
    {
        Vector2 center = enemyMarker.GetLocation().To2D();

        Vector2 secondaryLocation;
        float   heightAtSecondaryLocation;
        Vector2 previousSecondaryLocation         = center;
        float   heightAtPreviousSecondaryLocation =
            EnvironmentPhysics.FindHeightAt(
                previousSecondaryLocation.x,
                previousSecondaryLocation.y
                );

        direction = direction.normalized;
        Vector2 dx = direction * STEPLENGTH;

        int numberOfSteps = (int)(radius / STEPLENGTH);

        for (int i = 0; i < numberOfSteps; i++)
        {
            secondaryLocation         = center + (dx * i);
            heightAtSecondaryLocation =
                EnvironmentPhysics.FindHeightAt(
                    secondaryLocation.x,
                    secondaryLocation.y
                    );

            if (Mathf.Abs(
                    heightAtSecondaryLocation - heightAtPreviousSecondaryLocation
                    ) > ACCEPTABLEHEIGHTDIFFERENCEBETWEENSTEPS ||
                !EnvironmentPhysics.WalkableAt(secondaryLocation.x, secondaryLocation.y, ConversionHub.GetSoldierRadius()))
            {
                break;
            }

            heightAtPreviousSecondaryLocation = heightAtSecondaryLocation;
            previousSecondaryLocation         = secondaryLocation;
        }
        Vector3 secondaryLocation3 = new Vector3(
            previousSecondaryLocation.x,
            heightAtPreviousSecondaryLocation,
            previousSecondaryLocation.y
            );

        secondaryLocations.Enqueue(secondaryLocation3);
    }
Ejemplo n.º 7
0
    protected bool InfoCanSee(Vector3 location)
    {
        Vector3 thisVantagePoint  = GetVantagePoint();
        Vector3 otherVantagePoint = location + new Vector3(0, 0.1f, 0);
        float   distance          = Vector3.Distance(thisVantagePoint, otherVantagePoint);

        if (distance > sightDistance)
        {
            return(false);
        }
        return(direction.WithinRangeOfVision(otherVantagePoint, visionWideness) &&
               EnvironmentPhysics.LineOfSightToVantagePointExists(
                   visionSharpness,
                   thisVantagePoint,
                   otherVantagePoint
                   ));
    }
Ejemplo n.º 8
0
    public bool InfoCanSee(HumanoidModel other)
    {
        Vector3 thisVantagePoint  = GetVantagePoint();
        Vector3 otherVantagePoint = other.GetVantagePoint();
        float   distance          = Vector3.Distance(thisVantagePoint, otherVantagePoint);

        if (distance > sightDistance)
        {
            return(false);
        }
        return(direction.WithinRangeOfVision(otherVantagePoint, visionWideness) &&
               EnvironmentPhysics.LineOfSightToVantagePointExists(
                   visionSharpness,
                   thisVantagePoint,
                   otherVantagePoint
                   ));
    }
Ejemplo n.º 9
0
    public virtual void EffectOnSeeEnemy(HumanoidModel enemy)
    {
        Vector3    thisVantagePoint = GetVantagePoint();
        Projectile thisWeapon       = currentWeapon.GetProjectile();

        Vector3    enemyVantagePoint = enemy.GetVantagePoint();
        Projectile enemyWeapon       = enemy.currentWeapon.GetProjectile();

        TerrainDisparity terrainDisparity = EnvironmentPhysics.CalculateTerrainDisparityBetween(
            thisWeapon, enemyWeapon, thisVantagePoint, enemyVantagePoint
            );

        float coverDisparity = terrainDisparity.visibleToTarget - terrainDisparity.visibleToObserver;

        // the following line prevents advantageous cover from decreasing stress
        coverDisparity = coverDisparity < 0 ? 0 : coverDisparity;
        baseStressManager.PendSightStress(coverDisparity, enemy);
    }
Ejemplo n.º 10
0
    private void MoveWithTerrain(float angle)
    {
        angle = angle * Mathf.Deg2Rad;
        Vector3 currentPosition = centerBottom.position;

        float   newX        = (Mathf.Cos(angle) * calculateSpeed()) + currentPosition.x;
        float   newZ        = (Mathf.Sin(angle) * calculateSpeed()) + currentPosition.z;
        float   newY        = EnvironmentPhysics.FindHeightAt(newX, newZ);
        Vector3 newPosition = new Vector3(newX, newY, newZ);

        direction.Face(newPosition);

        if (EnvironmentPhysics.WalkableAt(newPosition.x, newPosition.z, 1))
        {
            float twoDDistance = FastMath.Hyp(currentPosition.x
                                              , currentPosition.z
                                              , newPosition.x
                                              , newPosition.z);
            Vector3 hypotenuse     = newPosition - currentPosition;
            Vector3 unitHypotenuse = hypotenuse.normalized;
            unitHypotenuse.Scale(FastMath.CreateVectorCube(twoDDistance));


            Vector3 finalPosition = unitHypotenuse + currentPosition;

            centerBottom.position = new Vector3(finalPosition.x
                                                , EnvironmentPhysics.FindWalkableHeightAt(finalPosition.x
                                                                                          , finalPosition.z)
                                                , finalPosition.z
                                                );
        }

        /*
         * centerBottom is implied to be the child of
         * the gameobject movementcontroller is attached to
         */
        Transform centerBottomParent = centerBottom.parent;

        centerBottom.parent = null;
        body.position       = centerBottom.position + displacementFromCenterBottom;
        centerBottom.parent = centerBottomParent;
    }
Ejemplo n.º 11
0
    private static void BatchAddNodes(List <Point> locations)
    {
        List <Vector2> worldLocations = Pools.ListVector2s;

        for (int i = 0; i < locations.Count; i++)
        {
            worldLocations.Add(instance.NodeTo2DWorldCoord(locations[i]));
        }
        List <MapNode> newNodes =
            EnvironmentPhysics.CreateMapNodesAt(
                worldLocations
                );

        for (int i = 0; i < newNodes.Count; i++)
        {
            MapNode current      = newNodes[i];
            Point   currentPoint =
                instance.WorldCoordToNode(current.GetLocation());
            instance.nodes[currentPoint] = current;
            instance.pointsInUse.Add(currentPoint);
        }
        Pools.ListMapNodes = newNodes;
        Pools.ListVector2s = worldLocations;
    }
Ejemplo n.º 12
0
    public override void Attack(Vector3 start, Vector3 target)
    {
        Projectile projectile = new Projectile(power, suppressiveRadius);

        EnvironmentPhysics.SendProjectile(projectile, start, target);
    }
Ejemplo n.º 13
0
 public void ScreenTarget(GameplayCamera cam, Vector3 screenLocation)
 {
     environmentTarget = EnvironmentPhysics.ScreenToEnvironmentPoint(cam, screenLocation);
 }