Ejemplo n.º 1
0
        private void SetMiniTurret(Unit player)
        {
            if (player == null)
                return;

            Vec3 location = new Vec3(1.5f, 1.5f, .5f); //set default above to start of player ball

            if (activeturrets == 1)
            {
                //Get Current position
                //Spawner spawner = new Spawner();

                //GameEntities.TurretAI turretAi = new GameEntities.TurretAI();
                //turretAi.unitWeapons
                turret = (Turret)Entities.Instance.Create("TurretScaled", Map.Instance);
                turret.Position = this.Position + location;
                turret.ViewRadius = turret.Type.ViewRadius;
                turret.Health = turret.Type.HealthMax;

                //if(player != null)
                //	turret.UserData = (Object)player;

                //turret.Armor = turret.Type.ArmorMax;
                turret.SubscribeToDeletionEvent((Entity)turret);
                //turret.InitialAI = turret.Type.InitialAI;
                //turret.InitialFaction = player.InitialFaction; //(FactionType)EntityTypes.Instance.GetByName("BadFaction");
                turret.PostCreate();

                //PhysicsModel.PopFromWorld();

                //////bool foundspot = true; //trick to make it reloop for next for loop

                //////for (int i = 1; i < 5; i++) //Change this for more alias MapObjectAttachedHelper points
                //////{
                //////    MapObjectAttachedObject helperpoint = GetAliasPoint(player, i);

                //////    if (helperpoint == null)
                //////        return;

                //////    location = Position + helperpoint.PositionOffset;

                //////    foreach (Body body in turret.PhysicsModel.Bodies)
                //////    {
                //////        if (foundspot == false) //flagging back to true to break foreach loop
                //////        {
                //////            //this should goto for loop
                //////            foundspot = true;
                //////            break;
                //////        }

                //////        //look down for a clear spot if none found break from for each
                //////        RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(new Ray( location, new Vec3(0, 0, -100)),
                //////        (int)body.Shapes[0].ContactGroup);

                //////        //find anything?
                //////        if (piercingResult.Length == 0)
                //////            continue;

                //////        foreach (RayCastResult result in piercingResult)
                //////        {
                //////            if (result.Shape.Body == body) //if self physics body
                //////                continue;

                //////            //check if throwing inside a mapobjects walls I am trying to do?
                //////            Bounds bounds = result.Shape.GetGlobalBounds().Intersect(body.Shapes[0].GetGlobalBounds());
                //////            if (bounds!= null &&
                //////                //body.GetGlobalBounds().IsContainsPoint(result.Shape.GetGlobalBounds().GetSize()))
                //////                //!result.Shape.GetGlobalBounds().IsContainsPoint(body.GetGlobalBounds().GetSize()))
                //////            {
                //////                if (result.Shape.ShapeType == Shape.Type.HeightField)
                //////                {
                //////                    turret.Position = new Vec3(location.X, location.Y, result.Position.Z + 1f); //1f is offset from floor
                //////                    //positioned = true;
                //////                    return;
                //////                }
                //////                else if (result.Shape.ShapeType == Shape.Type.Mesh || result.Shape.Body.Static)
                //////                {
                //////                    turret.Position = new Vec3(location.X, location.Y, result.Position.Z + 1f); //1f is offset from floor
                //////                    //positioned = true;
                //////                    return;
                //////                }
                //////                else
                //////                {
                //////                    foundspot = false;
                //////                    break;
                //////                }
                //////            }
                //////            else
                //////            {
                //////                //bad position
                //////                foundspot = false;
                //////                break;
                //////            }

                //////            //if (result.Shape.ShapeType == Shape.Type.HeightField)
                //////            //    turret.Position = new Vec3(location.X, location.Y, result.Position.Z + 1f); //1f is offset from floor
                //////            // {
                //////            //   //positioned = true;
                //////            //    return;
                //////            //}

                //////        }
                //////    }
                //////}

                foreach (Body body in turret.PhysicsModel.Bodies)
                {
                    RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing(new Ray(this.Position + location, new Vec3(0, 0, -100)),
                     (int)body.Shapes[0].ContactGroup); //use only "base"

                    if (piercingResult.Length == 0)
                        continue;

                    foreach (RayCastResult result in piercingResult)
                    {
                        if (result.Shape.Body == body) //if self physics body
                            continue;

                        Bounds bounds = result.Shape.GetGlobalBounds().Intersect(body.Shapes[0].GetGlobalBounds());

                        if (bounds != null && result.Shape.Name.Contains("Map"))//.ShapeType != Shape.Type.HeightField)
                        {
                            turret.Position = this.Position + location;
                            return;
                        }
                        else if (result.Shape.ShapeType == Shape.Type.HeightField && result.Shape.Position != Vec3.Zero)
                        {
                            turret.Position = this.Position + location;//new Vec3(turret.Position.X, turret.Position.Y, result.Position.Z + 1f) + location; //1f is offset from floor
                            return;
                        }
                        else if (result.Distance <= 2f)
                        {
                            turret.Position = this.Position + location;
                            return;
                        }
                        else
                        {
                            // turret.Position = new Vec3(turret.Position.X, turret.Position.Y, turret.Position.Z) + location;
                        }
                    }
                }

                //PhysicsModel.PushToWorld();
            }
            else
            {
                return;
            }
        }