private void Cancel(string From, int SeqNr)
        {
            Job    Job;
            string s = From + " " + SeqNr.ToString();

            lock (this.inProgress)
            {
                if (this.inProgress.TryGetValue(s, out Job))
                {
                    this.inProgress.Remove(s);
                }
                else
                {
                    Job = null;
                }
            }

            if (Job != null)
            {
                try
                {
                    Job.Abort();
                } catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            }
        }
示例#2
0
 private async Task Abort()
 {
     try
     {
         Logger.LogInfo(Job.Id, Loc["HardStopMessage"]);
         await Job.Abort();
     }
     catch (Exception ex)
     {
         await js.AlertException(ex);
     }
 }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        currentTime = Time.time;

        // Check if game has ended already
        if (gameOver == true)
        {
            restartTime = Time.time + 3.0f;
            gameOver    = false;
        }
        if (currentTime > restartTime)
        {
            Application.LoadLevel(Application.loadedLevel);
        }


        // Monitor team distribution

        redplayers  = myJob.numberofredplayers;
        blueplayers = myJob.numberofblueplayers;
        Debug.Log(myJob.numberofredplayers + " " + myJob.numberofblueplayers);
        //Debug.Log(myJob.rawData);
        //Debug.Log(myJob.name +" "+myJob.command);


        // Run democracy
        // Democracy startup sequence
        if (Input.GetKeyUp("p") && myJob.democracy == false)
        {
            // Stop executing command
            StopCoroutine("Execute");

            // Start democracy
            myJob.democracy = true;
            democracyStart  = Time.time;
            Debug.Log("Democracy Started");
            democracyEnd = democracyStart + democracyDuration;

            // Reset democracy option count
            for (int i = 0; i < 4; i++)
            {
                myJob.optionHistogram[i] = 0;
            }
        }

        // Democracy in progress - ONLY FOR DEBUGGING
        if (myJob.democracy == true)
        {
            Debug.Log("DEMOCRACY IN PROGRESS");
        }

        // Democracy quit sequence
        if (Time.time > democracyEnd && myJob.democracy == true)
        {
            Debug.Log("Democracy Ended");
            myJob.democracy = false;

            // Get results from democracy
            int result = calculateDemocracy(myJob.optionHistogram);
            Debug.Log("Winner is Option " + result);

            // Start executing commands again
            StartCoroutine("Execute");
        }

        // IN CLIENT TCP DISCONNECT
        if (Input.GetKeyUp("o"))
        {
            myJob.Abort();
            myJob.Start();
            myJob.Abort();
            StopAllCoroutines();
            Debug.Log("DISCONNECTED");
        }

        // P1 KEYBOARD DEBUG ONLY
        if (Input.GetKeyUp("w"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player1").GetComponent <Movement>().moveUp();
        }
        if (Input.GetKeyUp("s"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player1").GetComponent <Movement>().moveDown();
        }
        if (Input.GetKeyUp("a"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player1").GetComponent <Movement>().moveLeft();
        }
        if (Input.GetKeyUp("d"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player1").GetComponent <Movement>().moveRight();
        }
        if (Input.GetKeyUp("space"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player1").GetComponent <characterBehaviour>().triggerBomb();
        }
        //P2 KEYBOARD CONTROLS DEBUG ONLY
        if (Input.GetKeyUp("i"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player2").GetComponent <Movement>().moveUp();
        }
        if (Input.GetKeyUp("k"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player2").GetComponent <Movement>().moveDown();
        }
        if (Input.GetKeyUp("j"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player2").GetComponent <Movement>().moveLeft();
        }
        if (Input.GetKeyUp("l"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player2").GetComponent <Movement>().moveRight();
        }
        if (Input.GetKeyUp("m"))
        {
            //Debug.Log("Moving Up");
            GameObject.FindWithTag("Player2").GetComponent <characterBehaviour>().triggerBomb();
        }

        // MANUAL LEVEL RESTART DEBUG ONLY
        if (Input.GetKeyUp("x"))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
    }
示例#4
0
    //Ao clicar no botão "Iniciar Simulação"
    public void onStartClick()
    {
        if (!bIsGameRunning)
        {
            //Desabilita edição de parâmetros
            togglePrefs(false);

            //Muda o texto do botão
            btnStart.GetComponentInChildren <Text> ().text = "Parar Simulação";

            //Prepara o início do jogo
            bIsGameRunning = true;

            //Reseta o vetor de turnos
            turnOrder = new playerClass[4];

            //Primeiro a jogar pode ser qualquer um
            int randomInt = Random.Range(0, 4);
            turnOrder [0] = players [randomInt];

            //Define a ordem dos outros jogadores
            for (int i = 1; i < turnOrder.Length; i++)
            {
                bool bInserted = true;
                while (bInserted)
                {
                    //Sorteia um jogador
                    randomInt = Random.Range(0, 4);

                    //Verifica se este jogador já foi inserido
                    for (int j = 0; j < turnOrder.Length; j++)
                    {
                        if (turnOrder [j] == players [randomInt])
                        {
                            //Se já achou algum player igual, pode sair do loop
                            bInserted = true;
                            break;
                        }

                        //Se chegou até o final o player ainda não foi inserido
                        bInserted = false;
                    }
                }

                //Insere o jogador na ordem do turno
                turnOrder [i] = players [randomInt];
            }

            //Exibe a ordem dos players
            Text memo = memoPlayerOrder.GetComponent <Text> ();
            memo.text = "Ordem da primeira partida do jogo: \n";
            for (int i = 0; i < turnOrder.Length; i++)
            {
                memo.text += "Jogador " + i + ": Player " + turnOrder [i].getPlayerBehaviour() + '\n';
            }

            //Prepara a thread do jogo
            gameJobThread                  = new Job();
            gameJobThread.players          = turnOrder;
            gameJobThread.props            = props;
            gameJobThread.numberOfTurns    = numberRounds;
            gameJobThread.maxNumberOfTurns = maxNumberOfTurns;
            gameJobThread.numberOfRounds   = numberRounds;

            //Inicia a thread do jogo
            gameJobThread.Start();
        }
        else
        {
            //Destrói a thread se ela for parada antes de terminar
            if (gameJobThread != null)
            {
                gameJobThread.Abort();
                gameJobThread = null;
            }

            //Para o jogo
            bIsGameRunning = false;

            //Muda o texto do botão
            btnStart.GetComponentInChildren <Text> ().text = "Iniciar Simulação";

            //Apaga a ordem dos players
            memoPlayerOrder.GetComponent <Text> ().text = "";

            //Habilita edição de parâmetros
            togglePrefs(true);
        }
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if (pause_game_control.paused)
        {
            return;
        }

        CleanUpActionLine();

        if (unit_action_counter < unit_action_speed)
        {
            unit_action_counter += 1;
            return;
        }
        else
        {
            unit_action_counter = 0;
        }



        // If we have a job do something about it
        if (job != null)
        {
            // If we don't have a path we are either at the job
            // or we need to compute an new path
            if (!IsPathing())
            {
                if (IsByJob())
                {
                    // we are at the target, do work!
                    path = null;
                    WorkOnJob();
                }
                else
                {
                    // We arent't near the target, path there
                    var pos = GetPos();
                    var tgt = job.GetTarget();

                    bool[,] d_grid_mask = dispatcher.GetGridMask();
                    bool[,] grid_mask   = new bool[d_grid_mask.GetLength(0), d_grid_mask.GetLength(1)];

                    for (int i = 0; i < d_grid_mask.GetLength(0); i++)
                    {
                        for (int j = 0; j < d_grid_mask.GetLength(1); j++)
                        {
                            grid_mask[i, j] = d_grid_mask[i, j];
                        }
                    }

                    grid_mask[tgt.x, tgt.y] = true;

                    if (pathfinding_grid == null)
                    {
                        pathfinding_grid = new PathFind.Grid(grid_mask);
                    }
                    else
                    {
                        pathfinding_grid.UpdateGrid(grid_mask);
                    }

                    var _from = new PathFind.Point((int)pos.x, (int)pos.y);
                    var _to   = new PathFind.Point(tgt.x, tgt.y);
                    path = PathFind.Pathfinding.FindPath(pathfinding_grid, _from, _to);

                    if (path.Count == 0)
                    {
                        // we were not able to path to location or. Abort useful tasks, cancel idle tasks;

                        if (job is IdleJob)
                        {
                            job.Cancel();
                        }
                        else
                        {
                            job.Abort("Could not find path to job.");
                        }
                    }
                    else if (path.Count > 1)
                    {
                        // pop off the last action so we don't move onto the tile.
                        path.RemoveAt(path.Count - 1);
                    }
                }
            }

            // explicitly separate if so that we can move this turn
            // if we needed to compute a new path
            if (IsPathing())
            {
                // get the next point on the path and move there.
                var move_to = path[0];
                path.RemoveAt(0);

                var new_vec = new Vector3((float)move_to.x, (float)move_to.y, transform.position.z);
                transform.position = new_vec;

                var pos = GetPos();
                dispatcher.AcknowledgeUnitMove(pos, new_vec);
            }
        }
        else
        {
            // if we have no job, we can clear our pathing
            path = null;
        }
    }