Esempio n. 1
0
    bool FollowClosestFriend(int length)
    {
        // Find closest ally (removed if closest ally is self).
        Transform  nearestAllyPos;
        TeamTarget target = gameObject.GetComponent <TargetMarker>().AlliedTargets;

        GameObject nearestAlly = target.FindNearestTarget(this.transform.position);

        if (nearestAlly != null)
        {
            nearestAllyPos = nearestAlly.transform;
        }
        else
        {
            return(false);
        }

        // Make sure ally is not self.
        if (nearestAllyPos == transform)
        {
            nearestAllyPos = null;
        }

        // Let the decision tree know if we found friend or not.
        if (nearestAllyPos)
        {
            SetMoveTarget(nearestAllyPos, false);
            LockAi(length);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 2
0
    private void makeTeam(Team team, bool makePlayer)
    {
        CombatTeam combatTeam = new CombatTeam();

        TeamTarget allies  = TeamTarget.TargetJust(combatTeam);
        TeamTarget enemies = TeamTarget.TargetAllExcept(combatTeam);

        for (int i = 0; i < team.ShipCount; i++)
        {
            makeShip(team.Prefab, combatTeam, allies, enemies, new Vector3(team.Pos.x + Random.Range(-Dist, Dist), 0, team.Pos.z + Random.Range(-Dist, Dist)));
        }

        if (makePlayer)
        {
            // Make cursor
            MonoBehaviour.Instantiate(cursor, new Vector3(0, 0, 0), Quaternion.identity);

            // Reset player for start of combat.
            GameObject player = GameObject.FindGameObjectWithTag("ShipBlueprint");
            player.transform.position = new Vector3(team.Pos.x + +Random.Range(-Dist, Dist), 0, team.Pos.z + Random.Range(-Dist, Dist));
            player.transform.rotation = new Quaternion(0, 0, 0, 0);
            player.GetComponent <TeamMarker>().Team            = combatTeam;
            player.GetComponent <TargetMarker>().AlliedTargets = allies;
            player.GetComponent <TargetMarker>().EnemyTargets  = enemies;

            PlayerActivation activater = player.GetComponent <PlayerActivation>();
            activater.Recreate();
            activater.SetBehavioursEnabled(true);
            activater.Show();
        }
    }
Esempio n. 3
0
    private void makeShip(GameObject prefab, CombatTeam team, TeamTarget allies, TeamTarget enemies, Vector3 pos)
    {
        Quaternion rot  = new Quaternion(0, 0, 0, 0);
        GameObject ship = MonoBehaviour.Instantiate(prefab, pos, rot) as GameObject;

        ship.GetComponent <TeamMarker>().Team            = team;
        ship.GetComponent <TargetMarker>().AlliedTargets = allies;
        ship.GetComponent <TargetMarker>().EnemyTargets  = enemies;
    }
Esempio n. 4
0
    private void makeShip(GameObject prefab, CombatTeam team, TeamTarget allies, TeamTarget enemies, Vector3 pos)
    {
        Quaternion rot = new Quaternion(0, 0, 0, 0);
        GameObject ship = MonoBehaviour.Instantiate(prefab, pos, rot) as GameObject;

        ship.GetComponent<TeamMarker>().Team = team;
        ship.GetComponent<TargetMarker>().AlliedTargets = allies;
        ship.GetComponent<TargetMarker>().EnemyTargets = enemies;
    }
Esempio n. 5
0
        protected override void OnProcessOutputSchema(MutableObject newSchema)
        {
            //var info = new MutableObject {
            //    {"Team", 0}
            //};

            TeamTarget.SetValue(0, newSchema);

            base.OnProcessOutputSchema(newSchema);
        }
Esempio n. 6
0
 public void Start() {
   // Replace the prefabs in Weapons with real instances.
   int length = weapons.Count;
   TeamTarget enemies = GetComponent<TargetMarker>().EnemyTargets;
   for (int i = 0; i < length; i++) {
     GameObject weapon = Instantiate(weapons[i], transform.position, transform.rotation) as GameObject;
     weapon.transform.parent = this.transform;
     weapon.GetComponent<Weapon>().targeting = enemies;
     weapons[i] = weapon;
   }
 }
Esempio n. 7
0
    public void Recreate()
    {
        weapons.Clear();

        TeamTarget enemies = GetComponent <TargetMarker>().EnemyTargets;

        // Run over factory and get relevant modules, and add to the weapons.
        foreach (ModuleFactory module in GetComponents <ModuleFactory>())
        {
            if (module.FactoryType == "Weapon")
            {
                foreach (GameObject weapon in module.Modules)
                {
                    weapon.GetComponent <Weapon>().targeting = enemies;
                    weapons.Add(weapon);
                    weapon.transform.parent = transform;
                }
            }
        }
    }
Esempio n. 8
0
    protected override void instantEffects()
    {
        Vector3    pos = this.position;
        Quaternion rot = new Quaternion(0, 0, 0, 0);

        GameObject[] flares  = new GameObject[NumFlares];
        GameObject   ship    = this.GetComponent <Ability>().Ship;
        TeamTarget   allies  = ship.GetComponent <TargetMarker>().AlliedTargets;
        TeamTarget   enemies = ship.GetComponent <TargetMarker>().EnemyTargets;
        CombatTeam   team    = ship.GetComponent <TeamMarker>().Team;

        for (int i = 0; i < NumFlares; i++)
        {
            flares[i] = Instantiate(FlarePrefab, pos, rot) as GameObject;
            flares[i].transform.Rotate(0, Random.Range(0.0f, 360.0f), 0);
            flares[i].transform.Translate(Random.Range(1.0f, 20.0f), -5, 0);
            flares[i].GetComponent <TeamMarker>().Team            = team;
            flares[i].GetComponent <TargetMarker>().AlliedTargets = allies;
            flares[i].GetComponent <TargetMarker>().EnemyTargets  = enemies;
            Destroy(flares[i], 10);
        }
    }
Esempio n. 9
0
    bool FollowClosestEnemy(int length, float maxDist, bool mustBeInFront, bool attack)
    {
        // Find closest enemy (removed if closest enemy is self).
        Transform  nearestEnemyPos;
        TeamTarget target = gameObject.GetComponent <TargetMarker>().EnemyTargets;

        // Try and find any enemy in the game.
        GameObject nearestEnemy = target.FindNearestTarget(this.transform.position);

        if (nearestEnemy != null)
        {
            nearestEnemyPos = nearestEnemy.transform;
        }
        else
        {
            return(false);
        }

        // Make sure ally is not self.
        if (nearestEnemyPos == transform)
        {
            nearestEnemyPos = null;
        }

        // Drop enemy if further away than the maximum distance.
        if (maxDist > 0 && nearestEnemyPos)
        {
            if (Vector3.Distance(nearestEnemyPos.position, transform.position) > maxDist)
            {
                return(false);
            }
        }

        if (mustBeInFront && nearestEnemyPos)
        {
            Vector3 targetDir    = nearestEnemyPos.position - transform.position;
            float   angleBetween = Vector3.Angle(transform.forward, targetDir);
            float   offset       = 0;
            if (angleBetween > 0 - inFrontAngle * 0.5 + offset && angleBetween < inFrontAngle * 0.5 + offset)
            {
            }
            else
            {
                return(false);
            }
        }

        // Let the decision tree know if we found enemy or not.
        if (nearestEnemyPos)
        {
            SetMoveTarget(nearestEnemyPos.transform, attack);
            LockAi(length);
            if (debugActions)
            {
                Debug.Log("I am following " + nearestEnemyPos.name + " at: " + nearestEnemyPos.position);
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 10
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            if (!SpoofData.GetFirstValue(payload.Data))
            {
                var requestNature = RequestNatureField.GetFirstValue(payload.Data);
                var requestId     = RequestIdField.GetFirstValue(payload.Data);

                var command = new GetPovInfoCommand(requestId);
                var team    = 0;

                if (requestNature == RequestNature.Pov && requestId > 0)
                {
                    var commandIterator = CommandProcessor.Execute(command);
                    while (commandIterator.MoveNext())
                    {
                        yield return(null);
                    }

                    team = command.TeamId;
                }

                //var info = new MutableObject();
                //
                //if ( requestNature == RequestNature.Pov )
                //{
                //    var commandIterator = CommandProcessor.Execute( command );
                //    while ( commandIterator.MoveNext() )
                //        yield return null;

                //    info[ "Team" ] = command.Team;
                //    info[ "CsId" ] = command.CsId;
                //    info[ "File" ] = command.File;
                //    info[ "Submissions" ] = new List< MutableObject > {
                //        new MutableObject {
                //            { "Id", command.Submissions[0].Id },
                //            { "Round", command.Submissions[0].Round },
                //            { "Target", command.Submissions[0].Target },
                //            { "ThrowCount", command.Submissions[0].ThrowCount },
                //        }
                //    };
                //}
                //else
                //{
                //    // These are so incorrect, I have simplified this entire class to just return the requesting team id.
                //
                //    info["Team"] = 8;
                //    info["CsId"] = 0;
                //    info["File"] = "";
                //    info["Submissions"] = new List<MutableObject> {
                //        new MutableObject {
                //            { "Id", 0 },
                //            { "Round", 0 },
                //            { "Target", 0 },
                //            { "ThrowCount", 0 },
                //        }
                //    };
                //}

                //var info = new MutableObject {
                //    {"Team", team}
                //};

                TeamTarget.SetValue(team, payload.Data);
            }
            else
            {
                TeamTarget.SetValue(3, payload.Data);
            }

            var routerIterator = Router.TransmitAll(payload);

            while (routerIterator.MoveNext())
            {
                yield return(null);
            }
        }