Example #1
0
    /**
     * Since the planet belongs to another galaxy, we move the ships to the launcher for the current galaxy
     * We then do a universe bfs search for the fastest route to the galaxy we want to go towards from our current galaxy
     * Then we do another galaxy bfs from that launcher to the target planet
     */
    private GameObject[] multiGalaxyMoveFleet(GameObject planetToMoveTo)
    {
        Galaxy currentGalaxy = galaxy.GetComponent <Galaxy>();
        // TODO - make the launchers a dynamic option (bfs each, and see whichever list is shorter)
        GameObject closestCurrentLauncher = currentGalaxy.getLaunchers()[0];

        // Move the fleet to the launcher - initialized to empty in the case where the launcher and starting planet are the same (returns null)
        GameObject[] currentGalaxyMovementList = new GameObject[0];
        if (this.gameObject.GetInstanceID() != closestCurrentLauncher.GetInstanceID())
        {
            currentGalaxyMovementList = currentGalaxy.bfsGalaxy(this.gameObject, currentGalaxy.getLaunchers()[0]);
        }

        // Get the list of movements between the target galaxy launcher and destination planet
        Galaxy targetGalaxy = planetToMoveTo.GetComponent <Planet>().getGalaxy().GetComponent <Galaxy>();

        GameObject closestTargetLauncher = targetGalaxy.getLaunchers()[0];

        GameObject[] targetGalaxyMovementList = new GameObject[0];
        if (closestTargetLauncher.GetInstanceID() != planetToMoveTo.GetInstanceID())
        {
            targetGalaxyMovementList = targetGalaxy.bfsGalaxy(closestTargetLauncher, planetToMoveTo);
        }

        // Combine the values
        // Because the implementation of the bfs assumes that the ship is on the starting node,
        // we need to add the target galaxy launcher planet to our list of movements
        GameObject[] targetLauncher = new GameObject[] { closestTargetLauncher };
        GameObject[] fullMovement   = currentGalaxyMovementList.Concat(targetLauncher).Concat(targetGalaxyMovementList).ToArray();
        foreach (GameObject go in fullMovement)
        {
            Debug.Log("Planet visit " + go.GetComponent <Planet>().getName());
        }
        return(fullMovement);
    }
 public void Toggle()
 {
     if (_canToggle)
     {
         target.Concat(additionalTargets).ForEach(t => t.SetActive(!t.activeSelf));
     }
 }
Example #3
0
    private GameObject[] GetNearestTargets(float radius)
    {
        GameObject[] gos = new GameObject[] { };
        foreach (string tag in AllowedTargetTags)
        {
            gos.Concat(GameObject.FindGameObjectsWithTag(tag));
        }
        GameObject closest  = null;
        float      distance = radius;
        Vector3    position = transform.position;

        foreach (GameObject go in gos)
        {
            Vector3 diff        = go.transform.position - position;
            float   curDistance = diff.sqrMagnitude;
            if (curDistance < distance)
            {
                closest  = go;
                distance = curDistance;
            }
        }
        gos    = new GameObject[1];
        gos[0] = closest;
        return(gos);
    }
Example #4
0
    public Vector3 FindNearestTargetInRadius(float radius)
    {
        GameObject[] gos = new GameObject[] { };
        foreach (string tag in AllowedTargetTags)
        {
            gos.Concat(GameObject.FindGameObjectsWithTag(tag));
        }
        GameObject closest  = null;
        float      distance = radius;
        Vector3    position = transform.position;

        foreach (GameObject go in gos)
        {
            Vector3 diff        = go.transform.position - position;
            float   curDistance = diff.sqrMagnitude;
            if (curDistance < distance)
            {
                closest  = go;
                distance = curDistance;
            }
        }
        if (closest != null)
        {
            var target = (closest.transform.position - transform.position);
            target.y = 0;
            return(target.normalized);
        }
        return(transform.forward);
    }
Example #5
0
 public static GameObject[] GetUIAtPosition(Vector2 position, GraphicRaycaster[] graphicRaycasters)
 {
     GameObject[] gameObjects = new GameObject[0];
     foreach (GraphicRaycaster raycaster in graphicRaycasters)
     {
         List <RaycastResult> result = new List <RaycastResult>();
         PointerEventData     data   = new PointerEventData(EventSystem.current);
         data.position = position;
         raycaster.Raycast(data, result);
         gameObjects = gameObjects.Concat(Array.ConvertAll(result.ToArray(), x => x.gameObject)).ToArray();
     }
     return(gameObjects);
 }
Example #6
0
    public GameObject searchTag(GameObject nowObj, string[] tagNameArray) //後にIEnumerableに変えたほうがいいかも。qiita記事参照。
    {
        float tmpDis  = 0;                                                //距離用一時変数
        float nearDis = 0;                                                //最も近いオブジェクトの距離
        //string nearObjName = "";    //オブジェクト名称
        GameObject targetEnemy = null;                                    //オブジェクト

        GameObject[] enemyObs = new GameObject[] { };                     //空のゲームオブジェクト、複数ある。
        foreach (string tagName in tagNameArray)
        {
            GameObject[] obs = GameObject.FindGameObjectsWithTag(tagName);
            enemyObs = enemyObs.Concat(obs).ToArray();//IEnumerableの場合はToArrayを全て変える。
        }
        //タグ指定されたオブジェクトを配列で取得する
        foreach (GameObject obs in enemyObs)
        {
            //自身と取得したオブジェクトの距離を取得
            tmpDis = Vector2.Distance(obs.transform.position, nowObj.transform.position);

            enemyHPScript = obs.GetComponent <EnemyHP>();
            enemyHP       = enemyHPScript.HP;

            //オブジェクトの距離が近いか、距離0であればオブジェクト名を取得
            //一時変数に距離を格納
            if (enemyHP >= 1)//下のifとまとめてもいいかも
            {
                //obsのレンジが武器の射程に入ったときにランク分けしてtargetenemyに入れる
                //if(soldierrange > obsの距離){ランクの高い敵をtargetenemyに入れる }
                if (nearDis == 0 || nearDis > tmpDis)
                {
                    nearDis = tmpDis;
                    //nearObjName = obs.name;
                    targetEnemy = obs;
                }
            }
        }

        //最も近かったオブジェクトを返す
        //return GameObject.Find(nearObjName);
        return(targetEnemy);
    }
    private void findBestTarget()
    {
        GameObject[] possibleTargets = new GameObject[0];

        // if this character has a preferredTarget then find one
        if (!string.IsNullOrEmpty(preferredTarget))
        {
            possibleTargets = GameObject.FindGameObjectsWithTag(preferredTarget);
        }
        else
        {
            foreach (string buildingTag in buildingTags)
            {
                GameObject[] extraObjs = GameObject.FindGameObjectsWithTag(buildingTag);
                possibleTargets = possibleTargets.Concat(extraObjs).ToArray();
            }
        }

        if (possibleTargets.Length == 0)
        {
            return;
        }

        // get closest
        currentTarget = pickBestTarget(possibleTargets);

        Collider targetCollider = currentTarget.GetComponent <Collider>();

        targetPosition = targetCollider.ClosestPoint(this.transform.position);

        agent.SetDestination(targetPosition);

        // FIXME: This should be more intelligent,
        // like checking that the path isn't insane,
        // checking for walls to destroy to make it easier,
        // checking for alternate targets
    }
Example #8
0
        public GameObject GetGameObject(out GameObject[] boneGaos, GeometricObject morphObject = null, float morphProgress = 0f)
        {
            GameObject parentGao = new GameObject(Offset.ToString());

            // Bones
            boneGaos = null;
            if (bones != null && bones.Length > 0)
            {
                GameObject rootBone = new GameObject("Root bone");
                boneGaos = new GameObject[] { rootBone };
                boneGaos[0].transform.SetParent(parentGao.transform);
                boneGaos[0].transform.localPosition = Vector3.zero;
                boneGaos[0].transform.localRotation = Quaternion.identity;
                boneGaos[0].transform.localScale    = Vector3.one;
                boneGaos = boneGaos.Concat(bones.Select(b => b.GetGameObject(parentGao))).ToArray();
            }

            // Morph
            Vector3[] mainVertices = vertices.Select(s => new Vector3(
                                                         s.x / 256f,
                                                         s.z / 256f,
                                                         s.y / 256f)).ToArray();
            Color[] mainColors = vertices.Select(s => new Color(
                                                     s.r / (float)0x80,
                                                     s.g / (float)0x80,
                                                     s.b / (float)0x80,
                                                     1f)).ToArray();
            if (morphProgress > 0f && morphObject != null && morphObject.vertices.Length == vertices.Length)
            {
                Vector3[] morphVertices = morphObject.vertices.Select(s => new Vector3(
                                                                          s.x / 256f,
                                                                          s.z / 256f,
                                                                          s.y / 256f)).ToArray();
                Color[] morphColors = morphObject.vertices.Select(s => new Color(
                                                                      s.r / (float)0x80,
                                                                      s.g / (float)0x80,
                                                                      s.b / (float)0x80,
                                                                      1f)).ToArray();
                for (int i = 0; i < vertices.Length; i++)
                {
                    mainVertices[i] = Vector3.Lerp(mainVertices[i], morphVertices[i], morphProgress);
                    mainColors[i]   = Color.Lerp(mainColors[i], morphColors[i], morphProgress);
                }
            }

            // First pass

            Dictionary <VisualMaterial, List <IPS1Polygon> > textured = new Dictionary <VisualMaterial, List <IPS1Polygon> >();
            List <IPS1Polygon> untextured = new List <IPS1Polygon>();

            for (int i = 0; i < triangleLists.Length; i++)
            {
                PolygonList polys = triangleLists[i];
                if (polys.polygons != null)
                {
                    foreach (IPS1Polygon p in polys.polygons)
                    {
                        if (p is QuadLOD && (p as QuadLOD).quads?.Length > 0)
                        {
                            Quad[] quads = (p as QuadLOD).quads;
                            foreach (Quad q in quads)
                            {
                                VisualMaterial b = q.Material;
                                if (b == null)
                                {
                                    untextured.Add(q);
                                }
                                else
                                {
                                    if (!textured.ContainsKey(b))
                                    {
                                        textured[b] = new List <IPS1Polygon>();
                                    }
                                    textured[b].Add(q);
                                }
                            }
                        }
                        else
                        {
                            VisualMaterial b = p.Material;
                            if (b == null)
                            {
                                untextured.Add(p);
                            }
                            else
                            {
                                if (!textured.ContainsKey(b))
                                {
                                    textured[b] = new List <IPS1Polygon>();
                                }
                                textured[b].Add(p);
                            }
                        }
                    }
                }
            }

            // Second pass
            VisualMaterial[] textures = textured.Keys.ToArray();
            for (int i = 0; i < textures.Length; i++)
            {
                VisualMaterial vm = textures[i];
                TextureBounds  b  = vm.texture;

                float alpha = 1f;
                //if (!vm.IsLight) {

                /*switch (vm.BlendMode) {
                 *      case VisualMaterial.SemiTransparentMode.Point25:
                 *              alpha = 0.25f * 4f;
                 *              break;
                 *      case VisualMaterial.SemiTransparentMode.Point5:
                 *              alpha = 0.5f * 4f;
                 *              break;
                 * }*/
                //}

                IPS1Polygon pf  = textured[vm].FirstOrDefault();
                GameObject  gao = new GameObject(Offset.ToString()
                                                 + " - " + i
                                                 + " - " + pf?.Offset
                                                 + " - " + pf?.GetType()
                                                 + " - " + string.Format("{0:X2}", vm.materialFlags)
                                                 + "|" + string.Format("{0:X2}", vm.scroll)
                                                 + " - " + vm.BlendMode);
                gao.transform.SetParent(parentGao.transform);
                gao.layer = LayerMask.NameToLayer("Visual");
                gao.transform.localPosition = Vector3.zero;

                List <int>     vertIndices = new List <int>();
                List <int>     triIndices  = new List <int>();
                List <Vector2> uvs         = new List <Vector2>();
                foreach (IPS1Polygon p in textured[vm])
                {
                    int currentCount = vertIndices.Count;
                    switch (p)
                    {
                    case Triangle t:
                        vertIndices.Add(t.v0);
                        vertIndices.Add(t.v1);
                        vertIndices.Add(t.v2);

                        uvs.Add(b.CalculateUV(t.x0, t.y0));
                        uvs.Add(b.CalculateUV(t.x1, t.y1));
                        uvs.Add(b.CalculateUV(t.x2, t.y2));

                        /*Vector2 uv0 = b.CalculateUV(t.x0, t.y0);
                         * Vector2 uv1 = b.CalculateUV(t.x1, t.y1);
                         * Vector2 uv2 = b.CalculateUV(t.x2, t.y2);
                         * uvs.Add(uv0);
                         * uvs.Add(uv1);
                         * uvs.Add(uv2);*/

                        triIndices.Add(currentCount);
                        triIndices.Add(currentCount + 1);
                        triIndices.Add(currentCount + 2);
                        break;

                    case Quad q:
                        vertIndices.Add(q.v0);
                        vertIndices.Add(q.v1);
                        vertIndices.Add(q.v2);
                        vertIndices.Add(q.v3);

                        uvs.Add(b.CalculateUV(q.x0, q.y0));
                        uvs.Add(b.CalculateUV(q.x1, q.y1));
                        uvs.Add(b.CalculateUV(q.x2, q.y2));
                        uvs.Add(b.CalculateUV(q.x3, q.y3));

                        triIndices.Add(currentCount);
                        triIndices.Add(currentCount + 1);
                        triIndices.Add(currentCount + 2);

                        triIndices.Add(currentCount + 2);
                        triIndices.Add(currentCount + 1);
                        triIndices.Add(currentCount + 3);
                        break;

                    case Sprite s:

                        GameObject spr_gao = new GameObject("Sprite");
                        spr_gao.transform.SetParent(gao.transform);
                        spr_gao.transform.localPosition = mainVertices[s.v0];
                        BillboardBehaviour billboard = spr_gao.AddComponent <BillboardBehaviour>();
                        billboard.mode = BillboardBehaviour.LookAtMode.ViewRotation;
                        MeshFilter   sprites_mf = spr_gao.AddComponent <MeshFilter>();
                        MeshRenderer sprites_mr = spr_gao.AddComponent <MeshRenderer>();

                        spr_gao.layer = LayerMask.NameToLayer("Visual");

                        //Material unityMat = sprites[i].visualMaterial.MaterialBillboard;

                        sprites_mr.receiveShadows = false;
                        sprites_mr.material       = vm.CreateMaterial();

                        var       meshUnity = new Mesh();
                        Vector3[] vertices  = new Vector3[4];

                        float scale_x = 1.0f;
                        float scale_y = 1.0f;

                        scale_x = ((float)s.height / 256f) / 2.0f;
                        scale_y = ((float)s.width / 256f) / 2.0f;

                        BoxCollider bc = spr_gao.AddComponent <BoxCollider>();
                        bc.size = new Vector3(0, scale_y * 2, scale_x * 2);

                        vertices[0] = new Vector3(0, -scale_y, -scale_x);
                        vertices[1] = new Vector3(0, -scale_y, scale_x);
                        vertices[2] = new Vector3(0, scale_y, -scale_x);
                        vertices[3] = new Vector3(0, scale_y, scale_x);
                        Vector3[] normals = new Vector3[4];
                        normals[0] = Vector3.forward;
                        normals[1] = Vector3.forward;
                        normals[2] = Vector3.forward;
                        normals[3] = Vector3.forward;
                        Vector3[] sprite_uvs = new Vector3[4];

                        bool mirrorX = false;
                        bool mirrorY = false;

                        sprite_uvs[0] = new Vector3(0, 0 - (mirrorY ? 1 : 0), alpha);
                        sprite_uvs[1] = new Vector3(1 + (mirrorX ? 1 : 0), 0 - (mirrorY ? 1 : 0), alpha);
                        sprite_uvs[2] = new Vector3(0, 1, alpha);
                        sprite_uvs[3] = new Vector3(1 + (mirrorX ? 1 : 0), 1, alpha);
                        int[] triangles = new int[] { 0, 2, 1, 1, 2, 3 };

                        meshUnity.vertices  = vertices;
                        meshUnity.normals   = normals;
                        meshUnity.triangles = triangles;
                        meshUnity.SetUVs(0, sprite_uvs.ToList());
                        sprites_mf.sharedMesh = meshUnity;

                        break;
                    }
                }
                //Vertex[] v = vertIndices.Select(vi => vertices[vi]).ToArray();
                BoneWeight[] w = null;
                if (bones != null && bones.Length > 0 && boneWeights != null)
                {
                    w = new BoneWeight[vertIndices.Count];
                    for (int vi = 0; vi < w.Length; vi++)
                    {
                        DeformVertexWeights dvw = boneWeights.FirstOrDefault(bw => bw.ind_vertex == vertIndices[vi]);
                        if (dvw != null)
                        {
                            w[vi] = dvw.UnityWeight;
                        }
                        else
                        {
                            w[vi] = new BoneWeight()
                            {
                                boneIndex0 = 0, weight0 = 1f
                            };
                        }
                    }
                }
                if (vertIndices.Any())
                {
                    MeshFilter mf = gao.AddComponent <MeshFilter>();
                    gao.AddComponent <ExportableModel>();
                    MeshRenderer        mr        = null;
                    SkinnedMeshRenderer smr       = null;
                    Matrix4x4[]         bindPoses = null;
                    if (bones == null || bones.Length <= 0)
                    {
                        mr = gao.AddComponent <MeshRenderer>();
                    }
                    else
                    {
                        smr = gao.AddComponent <SkinnedMeshRenderer>();
                        //smr = (SkinnedMeshRenderer)mr;
                        smr.bones = boneGaos.Select(bo => bo.transform).ToArray();
                        bindPoses = new Matrix4x4[smr.bones.Length];
                        for (int bi = 0; bi < smr.bones.Length; bi++)
                        {
                            bindPoses[bi] = smr.bones[bi].worldToLocalMatrix * parentGao.transform.localToWorldMatrix;
                        }
                        smr.rootBone = smr.bones[0];
                    }

                    Mesh m = new Mesh();
                    m.vertices = vertIndices.Select(vi => mainVertices[vi]).ToArray();
                    m.colors   = vertIndices.Select(vi => mainColors[vi]).ToArray();
                    m.SetUVs(0, uvs.Select(s => new Vector4(s.x, s.y, alpha, 0f)).ToList());
                    m.triangles = triIndices.ToArray();
                    m.RecalculateNormals();
                    if (w != null)
                    {
                        m.boneWeights = w;
                        m.bindposes   = bindPoses;
                    }
                    mf.mesh = m;

                    if (mr != null)
                    {
                        mr.material = vm.CreateMaterial();
                    }
                    else if (smr != null)
                    {
                        smr.material   = vm.CreateMaterial();
                        smr.sharedMesh = m;
                    }
                    try {
                        MeshCollider mc = gao.AddComponent <MeshCollider>();
                        mc.isTrigger = false;
                        //mc.cookingOptions = MeshColliderCookingOptions.None;
                        //mc.sharedMesh = mesh;
                    } catch (Exception) { }
                }
            }
            // Untextured (some skyboxes, etc)
            if (untextured.Count > 0)
            {
                GameObject gao = new GameObject(Offset.ToString() + " - Untextured");
                gao.transform.SetParent(parentGao.transform);
                gao.layer = LayerMask.NameToLayer("Visual");
                gao.transform.localPosition = Vector3.zero;
                MeshFilter mf = gao.AddComponent <MeshFilter>();
                gao.AddComponent <ExportableModel>();
                MeshRenderer mr          = gao.AddComponent <MeshRenderer>();
                List <int>   vertIndices = new List <int>();
                List <int>   triIndices  = new List <int>();

                foreach (IPS1Polygon p in untextured)
                {
                    int currentCount = vertIndices.Count;
                    switch (p)
                    {
                    case TriangleNoTexture t:
                        vertIndices.Add(t.v0);
                        vertIndices.Add(t.v1);
                        vertIndices.Add(t.v2);

                        triIndices.Add(currentCount);
                        triIndices.Add(currentCount + 1);
                        triIndices.Add(currentCount + 2);
                        break;

                    case QuadNoTexture q:
                        vertIndices.Add(q.v0);
                        vertIndices.Add(q.v1);
                        vertIndices.Add(q.v2);
                        vertIndices.Add(q.v3);

                        triIndices.Add(currentCount);
                        triIndices.Add(currentCount + 1);
                        triIndices.Add(currentCount + 2);

                        triIndices.Add(currentCount + 2);
                        triIndices.Add(currentCount + 1);
                        triIndices.Add(currentCount + 3);
                        break;

                    default:
                        Debug.LogWarning(p.GetType()); break;
                    }
                }
                //Vertex[] v = vertIndices.Select(vi => vertices[vi]).ToArray();
                Mesh m = new Mesh();
                m.vertices = vertIndices.Select(vi => mainVertices[vi]).ToArray();
                m.colors   = vertIndices.Select(vi => mainColors[vi]).ToArray();
                m.SetUVs(0, vertIndices.Select(s => new Vector4(0.5f, 0.5f, 1f, 1f)).ToList());
                m.triangles = triIndices.ToArray();
                m.RecalculateNormals();
                mf.mesh = m;

                Material baseMaterial;

                /*if (m.colors.Any(c => c.a != 1f)) {
                 *      baseMaterial = Load.baseTransparentMaterial;
                 * } else {*/
                baseMaterial = Load.baseMaterial;
                //}
                Material mat = new Material(baseMaterial);
                mat.SetInt("_NumTextures", 1);
                string    textureName = "_Tex0";
                Texture2D tex         = Util.GrayTexture();
                mat.SetTexture(textureName, tex);
                mat.SetVector("_AmbientCoef", Vector4.one);
                mat.SetFloat("_Prelit", 1f);
                mr.material = mat;

                try {
                    MeshCollider mc = gao.AddComponent <MeshCollider>();
                    mc.isTrigger = false;
                    //mc.cookingOptions = MeshColliderCookingOptions.None;
                    //mc.sharedMesh = mesh;
                } catch (Exception) { }
            }

            return(parentGao);
        }
Example #9
0
 /// <summary>
 /// Validates attachment of the <see cref="Component"/> to the specified <see cref="GameObject"/>.
 /// </summary>
 /// <param name="gameObjectToAttachTo">
 /// The <see cref="GameObject"/> the <see cref="Component"/> is about to be attached to.
 /// </param>
 /// <param name="componentsToAttach">
 /// Other <see cref="Component"/>s (except the current one being attached!) that are supposed to be attached in
 /// the same transaction as the current object. Used to provide support for attaching multiple interdependent
 /// <see cref="Component"/>s.
 /// </param>
 /// <returns><c>true</c> if the attachment can be done, otherwise <c>false</c>.</returns>
 public override bool Validate(GameObject gameObjectToAttachTo, IEnumerable<Component> componentsToAttach)
 {
     return !gameObjectToAttachTo.Concat(componentsToAttach)
                                 .Distinct()
                                 .Any(component => this.ComponentType.IsAssignableFrom(component.GetType()));
 }
Example #10
0
        /// <summary>
        /// Validates the attachment process checking whether the dependencies are met.
        /// </summary>
        /// <param name="gameObjectToAttachTo">
        /// The <see cref="GameObject"/> the <see cref="Component"/> is about to be attached to.
        /// </param>
        /// <param name="componentsToAttach">
        /// Other <see cref="Component"/>s (except the current one being attached!) that are supposed to be attached in
        /// the same transaction as the current object. Used to provide support for attaching multiple interdependent
        /// <see cref="Component"/>s.
        /// </param>
        /// <returns><c>true</c> if the attachment can be done, otherwise <c>false</c>.</returns>
        public override bool Validate(GameObject gameObjectToAttachTo, IEnumerable<Component> componentsToAttach)
        {
            IEnumerable<Component> totalComponents = gameObjectToAttachTo.Concat(componentsToAttach).Distinct();

            return this.Dependencies.All(requiredComponent => totalComponents.Any(component => requiredComponent.IsAssignableFrom(component.GetType())));
        }
Example #11
0
    void Update()
    {
        isAirborne = false;

        if (!Physics.Raycast (rb.position, down, .6f)) {  //casts ray directly underneath to check for ground.
            isAirborne = true;
        }

        Vector3 adjustPosition = new Vector3(rb.position.x, rb.position.y + .85f, rb.position.z);

        if (x < 1) {   //build initial loadout, overwrites inspector
            Arsenal.SetValue (1000, IRON);
            Arsenal.SetValue (500, STEEL);
            Arsenal.SetValue (50, TIN);
            Arsenal.SetValue (500, PEWTER);
            Arsenal.SetValue (50, ZINC);
            Arsenal.SetValue (50, BRASS);
            Arsenal.SetValue (50, COPPER);
            Arsenal.SetValue (50, BRONZE);
            Arsenal.SetValue (0, CHROMIUM);
            Arsenal.SetValue (25, DURALUMIN);
            Arsenal.SetValue (1, ATIUM);  //somehow not bugged to shit

            BurnRate.SetValue(.8, IRON);
            BurnRate.SetValue(.8, STEEL);
            BurnRate.SetValue(1, TIN);
            BurnRate.SetValue(.8, PEWTER);
            BurnRate.SetValue(1, ZINC);
            BurnRate.SetValue(1, BRASS);
            BurnRate.SetValue(1, COPPER);
            BurnRate.SetValue(1, BRONZE);
            BurnRate.SetValue(1, CHROMIUM);
            BurnRate.SetValue(1, DURALUMIN);
            BurnRate.SetValue(.75, ATIUM); //bugged to shit //NOT ANYMORE NIGGAAAAAA
        //WHAT WE LEARNED FROM THE ABOVE BEING BUGGED TO SHIT:
            // CHECK ARRAY SIZES IN INSPECTOR, SCRIPT DOESNT ALWAYS OVERRIDE PROPERLY
            //IF BUGGED JUST MAKE SURE ARRAY SIZE IS RIGHT IN INSPECTOR, IF NOT, INCREASE THERE
            //NO NEED TO F**K AROUND HERE
            AllomanticStrength.SetValue(1.5, IRON);
            AllomanticStrength.SetValue(1.5, STEEL);
            AllomanticStrength.SetValue(1.2, TIN);
            AllomanticStrength.SetValue(1.2, PEWTER);
            AllomanticStrength.SetValue(0.8, ZINC);
            AllomanticStrength.SetValue(0.8, BRASS);
            AllomanticStrength.SetValue(0.8, COPPER);
            AllomanticStrength.SetValue(1.0, BRONZE);
            AllomanticStrength.SetValue(0.5, CHROMIUM);
            AllomanticStrength.SetValue(0.5, DURALUMIN);
            AllomanticStrength.SetValue(1.5, ATIUM);  //also bugged to shit

            coins = 25; //TODO create wallet object that holds coins, not player
            x=2;
        }

        //PEWTER EFFECTS

        if (Input.GetKeyDown("t")) { //only triggers once when key pressed and wont reset till released

            if(pewterActive){
                turnOffPewter = true;
            }
            if(!turnOffPewter)
            {
                pewterActive = true;
            }
        }

        if (Input.GetKeyDown("r")) { //WORKS
            if(!isFlaring  && uFlareCD == 0)
            {
                isFlaring = true;
            }
            else if(isFlaring){
                isFlaring = false;
            }

        }

        if (Input.GetKeyDown ("e")) {
            if(sightActive == false && !feStDepleted())
            {
                sightActive = true;
            }
            else{
                sightActive = false;
            }
        }

            if (feStDepleted())
            {
                sightActive = false;
            }

        //Following logic governs ironsight, push and pull and is mildly complicated
        //dont mess with it.
             //TODO swap to lists for dynamic sizing.
            GameObject[] objs2 = new GameObject[500];
            GameObject[] objs = new GameObject[500];
            //add objects to arrays by tags
            objs = GameObject.FindGameObjectsWithTag("Metallic");
            objs2 = GameObject.FindGameObjectsWithTag("Pick Up[IRON]");
            //combine arrays using linq
            GameObject[] finalObjs = new GameObject[(objs.Length + objs2.Length)]; //array is sized to hold exactly how many elements constitute the others.  Artificially dynamic
            finalObjs = objs.Concat(objs2).ToArray();
            //Debug.Log("finalObjs length: " + finalObjs.Length);
            objs = null;
            objs2 = null;
            //iterate through array drawing line to each
            //if obj is destroyed or set inactive the line will disappear next frame
        if (sightActive) {
            foreach (GameObject obj in finalObjs){
                Color lineColor;
                lineColor = Color.cyan; /* //no rigidbody, just testing, all should be blue in real

                if (obj.GetComponent<Rigidbody>())
                {
                    Rigidbody objRB = obj.GetComponent<Rigidbody>();
                    if(objRB.mass > rb.mass){
                        lineColor = Color.blue;  //heavier
                    }
                    if(objRB.mass < rb.mass){
                        lineColor = Color.cyan; //lighter
                    }
                    if(objRB.mass == rb.mass){
                        lineColor = Color.magenta;  //equal
                    }
                }*/
                Debug.DrawLine(adjustPosition, obj.transform.position, lineColor);

        }

                               }
            List<float> distances = new List<float>();
            GameObject targetObject;
            foreach (GameObject obj in finalObjs)
            {
                //get distance
                distances.Add(Vector3.Distance(obj.transform.position, rb.position));              //
            }

        float dist = distances.Min();
        //	Debug.Log ("Shortest distance: " + dist);

        int closestIndex  =  distances.IndexOf(dist); //check for position in index

        targetObject = finalObjs[closestIndex]; //~salamander wiggle~

        if (sightActive) {
            Debug.DrawLine(adjustPosition, targetObject.transform.position, Color.green);

        }
        if (lockedObj != null && lockedObj.activeSelf == false ) {
            lockedObj = null;
        }
        if (lockedObj != null) {
            targetObject = lockedObj;    //OVERRIDE PROXIMITY TARGET WITH LOCKED
        }

        Vector3 direction = (rb.position - targetObject.transform.position).normalized; //calculate direction
        //Debug.Log (direction);

        if(Input.GetKeyDown("n"))
        {
            if(!shift()){
                if(lockedObj = null)
                {
                    lockedObj = targetObject;

                }
                else{
                    lockedObj = finalObjs[closestIndex];
                }
                Debug.Log("Locking to target object... " + lockedObj.name);
            }
            if(shift()){
                if (Bookmarks.Contains(targetObject)){
                    Bookmarks.Remove(targetObject);
                }
                else{
                    Bookmarks.Add(targetObject);
                    Debug.Log("Added to bookmarks..." + targetObject.name);

                }

            }

        }

        /*
        if (Input.GetKeyDown (KeyCode.Tab) && Bookmarks.Count > 0) {
            bookmarksCounter

        }
        */

        if (sightActive) {
            foreach (GameObject obj in Bookmarks)
            {
                if(obj.activeSelf)
                {
                Debug.DrawLine(adjustPosition, obj.transform.position, Color.magenta);
                }
                else
                {
                    Bookmarks.Remove(obj);
                }
            }
        }

        if (Input.GetKeyDown ("m")) {
            lockedObj = null;
            Debug.Log("Unlocked from target object...");
        }

        if (sightActive) {
            if(lockedObj != null){
            //	Debug.Log ("trying to drawline to locked obj...");
                Debug.DrawLine(adjustPosition, lockedObj.transform.position, Color.red);
            }
        }

            if(Input.GetKey("v") && Arsenal[IRON] > 0){
                //determine closest obj
                    Arsenal.SetValue(Arsenal[IRON] - .1*(BurnRate[IRON]*uBurnRate[IRON]), IRON);

            if (targetObject.GetComponent<Rigidbody>()) {                                        //counter force
                Rigidbody targetObjRB = targetObject.GetComponent<Rigidbody>();
                targetObjRB.AddForce((float)feStFlareMulti*(direction*10.5f*(float)AllomanticStrength[IRON]/(dist/15)));
            }
            rb.AddForce((float)feStFlareMulti*(-direction*10.5f*(float)AllomanticStrength[IRON]/(dist/15)));
            //Debug.Log((float)feStFlareMulti*(-direction*10.5f*(float)AllomanticStrength[IRON]/(dist/10)).magnitude);
                }

            if(Arsenal[IRON] < 0)
            {
                Arsenal.SetValue(0,IRON);
                ironActive = false;
            }

            if (steelActive){// burn iron if thats whats active, slower drain than if using fully

                Arsenal.SetValue(Arsenal[STEEL] - .003*(BurnRate[STEEL]*uBurnRate[STEEL]), STEEL);
            }
                if(Input.GetKey("c") && Arsenal[STEEL]> 0 && pushTimer == 0){

                //FUNCTION WAS MOVED TO RUN REGARDLESS OF ACTIVATION OF IRON/STEEL.  REENABLE THIS ONLY IF YOU DISABLE THE ABOVE BECAUSE OF PERFORMANCE ISSUES, AND BE SURE TO COPY TO IRON METHOD AS WELL
            /*		//determine closest obj
                    List<float> distances = new List<float>();
                    GameObject targetObject;
                    foreach (GameObject obj in finalObjs)
                    {
                        //get distance
                        distances.Add(Vector3.Distance(obj.transform.position, rb.position));              //             new Vector3(Mathf.Abs(obj.transform.position.x - rb.position.x), Mathf.Abs(obj.transform.position.y - rb.position.y), Mathf.Abs (obj.transform.position.z - rb.position.z)));
                    }
                    float dist = distances.Min();
                    int closestIndex  =  distances.IndexOf(dist); //System.Array.IndexOf(distances, dist) ; // .IndexOf(distances, dist);  //check for position in index
                    targetObject = finalObjs[closestIndex];
                    Vector3 direction = (rb.position - targetObject.transform.position).normalized; //calculate direction */

            pushTimer = pushCD;
            if (targetObject.GetComponent<Rigidbody>()) {                                        //counter force
                Rigidbody targetObjRB = targetObject.GetComponent<Rigidbody>();
                //targetObjRB.AddForce((float)feStFlareMulti*(-direction*10.5f*(float)AllomanticStrength[IRON]/(dist)));

                if(dist > distanceFalloff)
                {//INSTRUCTIONS FOR DIST MODIFIER: For each interval amount over distanceFalloff, reduce the total acceleration generated by reductionPercent.
                    //the function will return 0 at reduction%*100*interval + distanceFalloff

                    distModifier = 1f - ((dist/interval)/(reductionPercent*100f));
                    if (distModifier < 0)
                    {
                        distModifier = 0;
                    }
                }

                //Debug.Log(distModifier);
                float A; //total acceleration
                A = (float)distModifier*(((float)AllomanticStrength[STEEL]*1000*rb.mass) / (((rb.mass)*(rb.mass))));//TODO
                //A = (float)(((float)AllomanticStrength[STEEL]*10000*rb.mass) / ((dist*dist)*((rb.mass+targetObjRB.mass)*(rb.mass+targetObjRB.mass))));//TODO
                //Debug.Log(A);
                if ( A > 1000 && A < 100000)
                {
                    A = A*(1-2*(A/1000));
                //	Debug.Log ( " Adjusting acceleration");
                }
                // total acceleration = (strength*mass)/ (Distance^2(mass+targetMass)^2))
                float totalMass = rb.mass + targetObjRB.mass;
                float PercTarg = rb.mass/totalMass;
                float PercRB = targetObjRB.mass/totalMass;
                Arsenal.SetValue(Arsenal[STEEL] - .1*(BurnRate[STEEL]*uBurnRate[STEEL]) , STEEL);

                if(Arsenal[STEEL] < 0)
                {
                    Arsenal[STEEL] = 0;
                }

                if(braced(targetObjRB, -direction ))
                {
                    PercRB = 1f;
                    PercTarg = 0f;
                }
                if(braced(rb, direction ))
                {
                    PercRB = .05f;
                    PercTarg = 1.1f;
                    Debug.Log("You are braced!");
                    if(braced(targetObjRB, -direction ))
                    {
                        PercRB = .5f;
                        PercTarg = .5f;
                    }
                }
                if(pewterActive)

                {
                    PercRB = PercRB*.75f;
                }
                Debug.Log ("Self: " + PercRB + " Target: " + PercTarg);
                float Arb = A*PercRB;
                float AObjRB = A*PercTarg;
                //Debug.Log (" Accelerations: " + Arb + " Targ " + AObjRB);
                float FmagRb = rb.mass*Arb;
                float FmagTargRB = targetObjRB.mass*AObjRB;
            //	Debug.Log (" Force magnitudes: " + FmagRb + "  Targ:" + FmagTargRB);
                rb.AddForce(direction*Math.Abs(FmagRb));
                //Debug.Log("RB Force: " + direction*FmagRb) ;
                targetObjRB.AddForce(-direction*Math.Abs(FmagTargRB));
                //	Debug.Log("Target RB Force: " + direction*FmagTargRB + "RB Force: " + direction*FmagRb) ;

            }

        //	rb.AddForce((float)feStFlareMulti*(direction*10.5f*(float)AllomanticStrength[STEEL]/(dist)));

                }

        Vector3 jForce = new Vector3 (0, (float)jHeight, 0);

        if (Input.GetKey ("space") ) { //jump n***a
            RaycastHit hit;
            if( metalUnder() && Arsenal[STEEL] > 0 && jumpTimer == 0){
                //Debug.Log("jumpTimer is " + jumpTimer + " and has been set to: " + jumpCD );
                    rb.AddForce(new Vector3 ( 0, 750*(float)AllomanticStrength[STEEL],0  ));
                jumpTimer = jumpCD;

            }
            else {
                if(checkGrounded()){
                //	anime.Play("JUMP");
                    rb.AddForce(jForce);
                    jumpTimer = 5;
                    jumping = true;
                }

            }
        }

        if (jumpTimer > 0) {
            jumpTimer--;
            //	Debug.Log(jumpTimer);
        } else {
            jumping = false;
        }

        if (pushTimer > 0) {
            pushTimer--;
            //Debug.Log (pushTimer);
        }

        if (pewterActive) {   //WORKS
            if(isFlaring){
                Arsenal.SetValue(Arsenal[PEWTER] - .01*AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER]*(BurnRate[PEWTER]*uBurnRate[PEWTER]), PEWTER);

                if(Arsenal[PEWTER] < 0)
                {
                    Arsenal.SetValue(0,PEWTER);
                    turnOffPewter = true;
                }

                //distorary physical enhancements
                jHeight = oJHeight * 3.9 * AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER];
                mSpeed = oMSpeed * 1.2 * AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER];
                weaponSkill = oWeaponSkill * 1.25 * AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER]* AllomanticStrength[PEWTER];
            }
            else{ //pewter on but not flared
            Arsenal.SetValue(Arsenal[PEWTER] - .005*(BurnRate[PEWTER]*uBurnRate[PEWTER]), PEWTER);

            if(Arsenal[PEWTER] < 0)
            {
                Arsenal.SetValue(0,PEWTER);
                turnOffPewter = true;
            }

            //distorary physical enhancements
            jHeight = oJHeight * 1.9 * AllomanticStrength[PEWTER];
            mSpeed = oMSpeed * 1.9 * AllomanticStrength[PEWTER];
            weaponSkill = oWeaponSkill * 1.15 * AllomanticStrength[PEWTER];
            } //end else

            if (turnOffPewter){  //disable pewter and reset all physical buffs
                turnOffPewter = false;
                jHeight = oJHeight;
                mSpeed = oMSpeed;
                pewterActive=false;

            }
        }

                //UI AND TIMERS ____________________________________

        if (metalUnder ()) {

            Debug.DrawRay(rb.position, new Vector3(0, 5, 0), Color.yellow);
        }

        //	Debug.Log (rb.velocity);

        //flare timers
        if (isFlaring) {
            uFlareCD +=1.5;
            feStFlareMulti = 1.5;
        }

        if (uFlareCD > 500) {
            isFlaring = false;
        }
        if (!isFlaring) {
            feStFlareMulti = 1;
            if (uFlareCD < 0)
            {
                uFlareCD = 0;
            }
            if(uFlareCD > 0)
            {
                uFlareCD --;
            }
        }

        anime.SetBool ("Jumping", jumping);
        //Debug.Log (jumping);
        if (!anime.IsInTransition(0)) {
            jumping = false;
        }

        if(Mathf.Abs(rb.velocity.x) < .1f && Mathf.Abs(rb.velocity.y) < .1f && Mathf.Abs(rb.velocity.z) < .1f)

        {
            rb.velocity = (emptyVec);
        }

        //build string
        currentArsenalText = "Press e to use vision and enable Iron/Steel" + "\n(V)Iron: " + Arsenal.GetValue(IRON) + "\n(C)Steel: " + Arsenal.GetValue(STEEL) + "\nTin: " + Arsenal.GetValue(TIN)+ "\n(T) Pewter: " + Arsenal.GetValue(PEWTER)+ "\nZinc: " + Arsenal.GetValue(ZINC)+ "\nBrass: " + Arsenal.GetValue(BRASS)+ "\nCopper: " + Arsenal.GetValue(COPPER)+ "\nBronze: " + Arsenal.GetValue(BRONZE)+ "\nChromium: " + Arsenal.GetValue(CHROMIUM)+ "\nDuralumin: " + Arsenal.GetValue(DURALUMIN)+ "\nAtium: " + Arsenal.GetValue(ATIUM) + "\nCoins: " + coins + "\nPewter: " + pewterActive + "\nMspeed: " + mSpeed + "\nBurnRate: " + BurnRate[PEWTER] +"\n(R)Flaring: " + isFlaring + "\nFlare CD: " + uFlareCD + "\n (F)Jump";
        arsenalText.text = currentArsenalText ; //display remaining metals
    }