public void SetMoveAI(MoveAI moveAI)
    {
        if (moveAI)
        {

            Agent agent = moveAI.GetAgent();

            lineRenderer.SetVertexCount(Agent.numOfComponets);

            Vector3 pos = moveAI.startPos;
            Vector3 dir = moveAI.starDir;

            for (int i = 0; i < Agent.numOfComponets; i++)
            {
                lineRenderer.SetPosition(i, pos);

                float time = 1 / MoveAI.updateRate;
                time *= moveAI.speed;
                dir = Quaternion.AngleAxis(agent.GetComponet(i).ID , Vector3.up) * dir;
                pos += dir * time;

            }

            lineRenderer.enabled = true;
        }
        else
        {
            lineRenderer.enabled = false;
        }
    }
Esempio n. 2
0
    public AttackRequest(float priority, AttackAI ai, GameObject targetObject) : base(priority)
    {
        attackAI       = ai;
        objectToAttack = targetObject;

        // check if we are in range
        float  attackRange = MovingObjectStats.GetAttackRangeForObject(ai.gameObject);
        MoveAI moveAI      = ai.GetComponent <MoveAI> ();

        fgoRequest = new FollowGameObjectRequest(0.5f, moveAI, attackRange);
        fgoRequest.targetObject = objectToAttack;
    }
    bool GetNeighboursTime(Vector2 v2, int time, int waits)
    {
        GameObject[] AI = GameObject.FindGameObjectsWithTag("AI");
        foreach (GameObject go in AI)
        {
            int            counter = 0;
            MoveAI         mai     = go.GetComponent <MoveAI> ();
            List <Vector2> path    = mai.currentPath;
            foreach (Vector2 tile in path)
            {
                int thisSleeps = selectedUnit.GetComponent <MoveAI> ().sleeps.Count;
                Debug.Log(thisSleeps);
                int maiSleeps = mai.sleeps.Count;
                Debug.Log(maiSleeps);
                counter++;
                if (tile.x == v2.x && tile.y == v2.y && counter + maiSleeps == time + 1 + thisSleeps + waits)
                {
                    return(false);
                }

                /*
                 * // if  nobody waited
                 * if (thisSleeps == 0 && maiSleeps == 0) {
                 *
                 * }
                 *
                 * // else if prev have waited
                 * else if (thisSleeps == 0 && maiSleeps > 0) {
                 *
                 * }
                 * // else if this have waited
                 * else if (thisSleeps > 0 && maiSleeps == 0) {
                 *      if (tile.x == v2.x && tile.y == v2.y && counter == time + 1 + thisSleeps)
                 *      {
                 *              return false;
                 *      }
                 * }
                 * // else  both have waited
                 * else {
                 *
                 * }
                 */
                //	Debug.Log ( "counter: " + counter +  "    time: " + (time + 1));
                //	Debug.Log ( "tile.x: " + tile.x +  "    v2.x: " + v2.x);
                //	Debug.Log ( "tile.y: " + tile.y +  "    v2.y: " + v2.y);
            }
        }
        return(true);
    }
Esempio n. 4
0
 public override void NDFixedUpdate(float deltaTime)
 {
     if (isAppear)
     {
         if (CurrentAction.IsDone())
         {
             isAppear      = false;
             CurrentAction = null;
             MoveAI.SetBornPos(m_bornpos, 0);
         }
         else
         {
             CurrentAction.Update();
         }
     }
 }
Esempio n. 5
0
    void SpawnEnemiesAtStart()
    {
        ListOfEnemies = new List <Transform>();
        // Loop through enemy list
        for (int i = 0; i < enemySpawnDetails_list.Count; ++i)
        {
            // No. of enemy to spawn
            int enemySpawnCount = enemySpawnDetails_list[i].ai_spawn_count;

            // Spawn Enemy
            for (int z = 0; z < enemySpawnCount; ++z)
            {
                // Variables
                GameObject enemyGo = null;

                // Spawn Enemy
                if (enemySpawnDetails_list[i].ai_character_type == CharacterType.PEOPLE)
                {
                    enemyGo = ObjectPoolingManager.Instance.Spawn_A_Specific_CharacterPrefab(CharacterType.PEOPLE, Vector3.zero);
                }
                else if (enemySpawnDetails_list[i].ai_character_type == CharacterType.POLICE)
                {
                    enemyGo = ObjectPoolingManager.Instance.Spawn_A_Specific_CharacterPrefab(CharacterType.POLICE, Vector3.zero);
                }

                if (enemyGo)
                {
                    // Assign enemy_cs T_CheckPoints
                    MoveAI ai_cs = enemyGo.GetComponent <MoveAI>();
                    if (ai_cs)
                    {
                        ai_cs.Init(enemySpawnDetails_list[i].ai_movement_type, enemySpawnDetails_list[i].T_CheckPoints, enemySpawnDetails_list[i].ai_speed);
                    }

                    // Add to list
                    ListOfEnemies.Add(enemyGo.transform);

                    // Parent it under a gameobject
                    enemyGo.transform.SetParent(T_Parent_EnemyList);
                }
            }
        }
    }
Esempio n. 6
0
    public void Update(Identity identity, AiComponent aicompont, InputComponent input)
    {
        if (aicompont == null || aicompont.enable == false)
        {
            return;
        }

        if (identity.isAIControl == true)
        {
            if (identity.tag == "tank")
            {
                MoveAI.moveAI(aicompont, input);
            }
            else if (identity.tag == "gun")
            {
                ShootAI.shootAI(aicompont, input);
            }
        }
    }
    void OnMouseUp()
    {
//		Debug.Log (tileX + " " + tileY);
        switch (buttons.ChangeSelection)
        {
        case "target":
            go = (GameObject)Instantiate(tilemap.targetAI, new Vector2(tileX, tileY), Quaternion.identity);
            tilemap.mai.target.x = tileX;
            tilemap.mai.target.y = tileY;

            buttons.ChangeSelection = "empty";
            break;

        case "wall":
            isWalkable = false;
            this.gameObject.GetComponent <SpriteRenderer> ().sprite = tilemap.wallSprite;
//			go = (GameObject)Instantiate (tilemap.wall, new Vector2(tileX*2,tileY*2),Quaternion.identity);
            break;

        case "floor":
            isWalkable = true;
            this.gameObject.GetComponent <SpriteRenderer> ().sprite = tilemap.floorSprite;

//			go = (GameObject)Instantiate (tilemap.floor, new Vector2(tileX*2,tileY*2),Quaternion.identity);
            break;

        case "AI":
            go     = (GameObject)Instantiate(tilemap.AI, new Vector2(tileX, tileY), Quaternion.identity);
            go.tag = "AI";
            MoveAI mai = go.AddComponent <MoveAI> ();

            mai.start.x             = tileX;
            mai.start.y             = tileY;
            tilemap.mai             = mai;
            buttons.ChangeSelection = "target";
            break;

        default:
            break;
        }
    }
Esempio n. 8
0
 public void SetBornPos(Int2 BornPos, int deep)
 {
     if (m_Attr.AttrType == 3000)
     {
         isAppear      = true;
         CurrentAction = new GridActionCmd3000Appear(MapGrid.GetMG(BornPos).WorldPos);
         CurrentAction.SetTarget(this);
     }
     else if (m_Attr.AttrType == 200003)
     {
         isAppear        = true;
         m_CurrentAction = new GridActionCmd200003FindTarget();
         m_CurrentAction.SetTarget(this);
     }
     else
     {
         isAppear      = false;
         CurrentAction = null;
         MoveAI.SetBornPos(m_bornpos, 0);
     }
     m_bornpos = BornPos;
 }
Esempio n. 9
0
    private FleeAI fleeAI; //a variable used to check if the AI is in fleeing state
    #endregion

    private void Start()
    {
        //set all the variables to thier respective component values
        moveAI      = GetComponent <MoveAI>();
        patrolAI    = GetComponent <PatrolAI>();
        attackAI    = GetComponent <AttackAI>();
        fleeAI      = GetComponent <FleeAI>();
        enemyScript = GetComponent <Enemy>();
        isSeeking   = GetComponent <MoveAI>().isSeeking;

        //Debugging to check if objects are attached correctly
        if (moveAI == null)
        {
            Debug.LogError("moveAI not attached to StateMachine");
        }
        if (patrolAI == null)
        {
            Debug.LogError("patrolAI not attached to StateMachine");
        }

        //start the program in the patrol state
        ChangeStateTo("Patrol");
    }
Esempio n. 10
0
    static void Main(string[] args)
    {
        string[] inputs;

        // game loop
        while (true)
        {
            int turnType = int.Parse(Console.ReadLine());

            Grid grid = new Grid();
            //XmasRush.Debug("Grid grid = new Grid();");
            for (int y = 0; y < 7; y++)
            {
                inputs = Console.ReadLine().Split(' ');
                for (int x = 0; x < 7; x++)
                {
                    string tile = inputs[x];
                    grid.AddTile(x, y, new Tile(tile));

                    //XmasRush.Debug($@"grid.AddTile({x}, {y}, new Tile(""{tile}""));");
                }
            }

            Player[] players = new Player[2];

            for (int i = 0; i < 2; i++)
            {
                string line = Console.ReadLine();

                inputs = line.Split(' ');
                int    numPlayerCards = int.Parse(inputs[0]); // the total number of quests for a player (hidden and revealed)
                int    playerX        = int.Parse(inputs[1]);
                int    playerY        = int.Parse(inputs[2]);
                string playerTile     = inputs[3];

                players[i] = new Player(i, playerX, playerY, new Tile(playerTile));
            }

            int    numItems = int.Parse(Console.ReadLine()); // the total number of items available on board and on player tiles
            Item[] items    = new Item[numItems];

            for (int i = 0; i < numItems; i++)
            {
                string line = Console.ReadLine();

                inputs = line.Split(' ');
                string itemName     = inputs[0];
                int    itemX        = int.Parse(inputs[1]);
                int    itemY        = int.Parse(inputs[2]);
                int    itemPlayerId = int.Parse(inputs[3]);

                items[i] = new Item(itemX, itemY, itemName, itemPlayerId);
            }

            int numQuests = int.Parse(Console.ReadLine()); // the total number of revealed quests for both players
            for (int i = 0; i < numQuests; i++)
            {
                string line = Console.ReadLine();

                inputs = line.Split(' ');
                string questItemName = inputs[0];
                int    questPlayerId = int.Parse(inputs[1]);

                items.Single(it => it.itemName == questItemName && it.playerId == questPlayerId).IsInQuest = true;
            }

            Stopwatch watch = Stopwatch.StartNew();

            GameState gameState = new GameState(grid, players[0], players[1], items);

            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine("Debug messages...");
            if (turnType == 0)
            {
                //Push turn
                PushAI pushAi = new PushAI(gameState);
                Console.WriteLine(pushAi.ComputeCommand()); // PUSH <id> <direction> | MOVE <direction> | PASS
                //XmasRush.Debug($"PushAI {watch.ElapsedMilliseconds.ToString()} ms");
            }
            else
            {
                //Move turn
                MoveAI moveAI = new MoveAI(gameState);
                Console.WriteLine(moveAI.ComputeCommand());
                //XmasRush.Debug($"MoveAI {watch.ElapsedMilliseconds.ToString()} ms");
            }
        }
    }
Esempio n. 11
0
 public MoveRequest(float priority, MoveAI ai) : base(priority)
 {
     moveAI = ai;
 }
 public FollowGameObjectRequest(float priority, MoveAI ai, float distance) : base(priority, ai)
 {
     minDistance = distance;
 }
Esempio n. 13
0
 public void SetMoveAI(MoveAI ai)
 {
     moveAI = ai;
     AttemptStartup();
 }
Esempio n. 14
0
 private void Start()
 {
     moveAI = GetComponentInParent <MoveAI>();
 }