Example #1
0
    private static void MoveMenuWithCam()
    {
        // move any build menus along with the cam
        BuildManager buildManager = BuildManager.instance;

        if (buildManager.IsFinishedWithSS())
        {
            LymphNode selLN = buildManager.GetSelectedLymphNode();
            if (selLN != null)
            {
                GameObject buildingMenu = selLN.GetBuildingMenu();
                if (buildingMenu != null)
                {   // there's a building menu shown; move the menu
                    RectTransform buildingMenuRT       = buildingMenu.GetComponent <RectTransform>();
                    RectTransform canvasRT             = staticCanvas.GetComponent <RectTransform>();
                    Vector2       viewportPosition     = Camera.main.WorldToViewportPoint(selLN.transform.position);
                    Vector2       uiOffset             = new Vector2((float)canvasRT.sizeDelta.x / 2f, (float)canvasRT.sizeDelta.y / 2f);                   // screen offset for the canvas
                    Vector2       proportionalPosition = new Vector2(viewportPosition.x * canvasRT.sizeDelta.x, viewportPosition.y * canvasRT.sizeDelta.y); // position on the canvas

                    // set the position and remove the screen offset
                    buildingMenuRT.localPosition = proportionalPosition - uiOffset;
                }
            }
        }
    }
Example #2
0
 internal void BuildBaseLevel(LymphNode _lymphNode)
 {
     lymphNode = _lymphNode;
     if (towerLevels.Length > 0)
     {
         if (towerLevels[0] != null)
         {
             currentTowerLevelIndex = 0;
             GetComponent <SpriteRenderer>().sprite = towerLevels[currentTowerLevelIndex].sprite;
         }
     }
 }
Example #3
0
        private void bStart_Click(object sender, EventArgs e)
        {
            bStart.Enabled = false;
            bStop.Enabled  = true;
            bStart.Refresh();
            bStop.Refresh();
            logWriter = new StreamWriter("simulais_log.txt");
            logWriter.WriteLine(DateTime.Now);

            wsnSimulator = new WsnSimulatorApp();
            wsnSimulator.Initializing       += new EventHandler <ProgressEventArgs>(simulator_OnProgress);
            wsnSimulator.LogEvent           += new EventHandler <LogEventArgs>(simulator_LogEvent);
            wsnSimulator.SimulationFinished += new EventHandler <EventArgs>(simulator_SimulationFinished);
            Scheduler.Dispatching           += new Handler(Scheduler_Dispatching);

            progressFrm = new ProgressFrm();
            progressFrm.Show();
            var blockLen = 3;

            try
            {
                wsnSimulator.InitFromTrace(
                    "../../../NSTraces/Traces-2009-12-23/ntr_ex5.tr",
                    "../../../NSTraces/nm/ex6_nm4.tr",
                    blockLen,
                    1, 1, 1, int.Parse(tbNumOfAPCs.Text), int.Parse(tbNumOfTCells.Text), true);

                // initialize the simulator

                /*wsnSimulator.Init(
                 *      "../../../NSTraces/Traces-2009-12-23/ntr_ex5R.tr",		// self trace path
                 *      "../../../NSTraces/Traces-2009-12-23/ntr_ex6R.tr",		// test trace path
                 *      blockLen,												// block duration
                 *      1, 1, 1, int.Parse(tbNumOfAPCs.Text), int.Parse(tbNumOfTCells.Text), true); */
            }
            catch (Exception ex)
            {
                MessageBox.Show("Simulator initialization failed:\n\n" + ex.Message + "\n\n" + ex.StackTrace,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                progressFrm.Close();
                bStart.Enabled = true;
                bStop.Enabled  = false;
                return;
            }

            lymphNode   = wsnSimulator.LymphNodes[0];
            localTissue = wsnSimulator.LocalTissues[0];
            progressFrm.Close();
            Refresh();

            // start the simulation
            wsnSimulator.Run();
        }
Example #4
0
    internal void StartRallyPointSelector()
    {
        if (selectedLymphNode == null || selectedLymphNode.IsVacant())
        {
            throw new Exception("Error! There's no selected lymph node or no tower on it.");
        }

        selectedLymphNodeForRallyPoint = selectedLymphNode;

        if ((selectedLymphNode.GetTowerComponent() as MeleeTower) != null)
        {
            ((MeleeTower)selectedLymphNode.GetTowerComponent()).StartRallyPointSelector();
        }
    }
Example #5
0
    /// <summary> Deselects any currently selected lymph node,
    /// and calls <see cref="LymphNode.Deselect"/> on the selected lymph node.
    /// Also resets the <see cref="selectedAction"/>. </summary>
    internal void DeselectLymphNode()
    {
        SelectAction(SelectedAction.Nothing);
        if (Shop.infoPanel != null)
        {
            Destroy(Shop.infoPanel);
        }

        if (selectedLymphNode != null)
        {
            selectedLymphNode.HideTowerRange();

            selectedLymphNode.Deselect();
            selectedLymphNode = null;
        }
    }
Example #6
0
    /// <summary> Sets <paramref name="lymphNode"/> as the currently selected lymph node.
    /// If this method is not called from LymphNode, LymphNode.Select() has to be called! </summary>
    /// <param name="lymphNode">The selected LymphNode.</param>
    internal void SelectLymphNode(LymphNode lymphNode)
    {
        // if there's another lymph node already selected, first deselect that one
        if (selectedLymphNode != null)
        {
            DeselectLymphNode();
            //selectedLymphNode.Deselect();
        }

        // if this method is not called from LymphNode, LymphNode.Select() has to be called!
        //selectedLymphNode.Select(); // redundant, called from LymphNode too

        selectedLymphNode = lymphNode;

        selectedLymphNode.ShowTowerRange();
    }
Example #7
0
    private void Awake()
    {
        // initialize an instance of this singleton for use in other classes
        if (instance != null)
        {
            Debug.Log("More than one BuildManager in scene!");
            return;
        }
        instance = this;

        // initialize the list of SS objects that the player has to pick before starting the game
        selectedSSPoints = new SSPoint[numberOfLymphNodes];
        for (int i = 0; i < selectedSSPoints.Length; i++)
        {
            selectedSSPoints[i] = null;
        }

        selectedLymphNodeForRallyPoint = null;
    }
Example #8
0
    internal GameObject ShowInfoPanel(Transform menu, SelectedAction sa, Tower newTower)
    {
        GameObject infoPanel = Instantiate(menuSelectionInfoPrefab, new Vector3(0f, 0f, -1.2f), activeGameUIPanel.rotation);

        // set the menu as this panel's parent (so that it scrolls together with it)
        infoPanel.transform.SetParent(menu, false);

        ///////////////////////////

        // gather the data for the info panel
        string name        = "";
        string description = "";
        int    cost        = 0;
        int    level       = -1;
        int    maxLevel    = -1;
        //int health = -1;
        float damage  = -1;
        int   defense = -1;

        LymphNode selectedLymphNode = null;
        Tower     currentTower      = null;

        switch (sa)
        {
        case SelectedAction.BuildTower1:
        case SelectedAction.BuildTower2:
        case SelectedAction.BuildTower3:
        case SelectedAction.BuildTower4:
        {
            if (newTower != null)
            {
                name        = newTower.towerName;
                description = newTower.description;
                level       = 1;   // todo: does this even make sense? towers should always start at level 1
                cost        = newTower.GetBaseLevelCost();
                maxLevel    = newTower.GetNumberOfLevels();
                //health = newTower.GetBaseLevelHealth();
                damage = newTower.GetBaseLevelDamage();
                //defense = newTower.getDefen
            }
        }
        break;

        case SelectedAction.SellTower:
        {
            selectedLymphNode = BuildManager.instance.GetSelectedLymphNode();
            if (selectedLymphNode != null)
            {
                currentTower = selectedLymphNode.GetTowerComponent();
            }
            if (currentTower != null)
            {
                name        = "Sell tower";
                cost        = -currentTower.GetCurrentSellValue();
                description = "Sell this tower. You will receive " + (-cost) + " ATP, and you'll be able to build another tower on the same spot.";
            }
        }
        break;

        case SelectedAction.UpgradeTower:
        {
            selectedLymphNode = BuildManager.instance.GetSelectedLymphNode();

            if (selectedLymphNode != null)
            {
                currentTower = selectedLymphNode.GetTowerComponent();
            }
            if (currentTower != null)
            {
                name        = currentTower.GetNextLevelName();
                description = currentTower.GetNextLevelDescription();
                cost        = currentTower.GetNextLevelCost();
                level       = currentTower.GetCurrentLevel() + 1;
                maxLevel    = currentTower.GetNumberOfLevels();
                //health = currentTower.GetNextLevelHealth();
                damage = currentTower.GetNextLevelDamage();
                //defense = tower1.GetNextLevelDe();
            }
        }
        break;
        }

        //infoPanel.GetComponent<InfoPanel>().SetAll(name, description, level, maxLevel, cost, health, damage, defense);
        infoPanel.GetComponent <InfoPanel>().SetAll(name, description, level, maxLevel, cost, damage, defense);

        ///////////////////////////

        // no conversion is done now, because param menu is already a UI element
        RectTransform panelRT = infoPanel.GetComponent <RectTransform>();
        RectTransform menuRT  = menu.GetComponent <RectTransform>();

        // calculate the panel's x position so that it appears to the right of the menu
        float panelHalfWidth = panelRT.sizeDelta.x / 2;
        float menuHalfWidth  = menuRT.sizeDelta.x / 2;
        float xPos           = menuHalfWidth + panelHalfWidth;

        // if there's not enough space on the right, show it on the left
        // i.e. if the panel's width is longer than the space between xPos and right screen boundary
        Canvas canvas = activeGameUIPanel.parent.GetComponent <Canvas>(); // this assumes that this panel is the child of the top-level UI panel
        // calculate the right end of the panel as menuPosX + panelPosX + panelWidth
        // however, the UI elements are scalable according to screen size, so their size needs to be multiplied by the scaleFactor
        float panelRight = menuRT.localPosition.x + (canvas.scaleFactor * xPos) + (canvas.scaleFactor * panelRT.sizeDelta.x);

        if (panelRight > Screen.width / 2f)
        {
            xPos = 0 - menuHalfWidth - panelHalfWidth;
        }

        panelRT.localPosition = new Vector3(xPos, panelRT.localPosition.y, menu.position.z);

        return(infoPanel);
    }
Example #9
0
        private void Init(List <MolecularPattern> selfPatterns,
                          List <SimulatorInitEvent> initEvents, SimulatorInitArgs args, bool registerLogger)
        {
            // create and start local agents
            // number of local tissue must be equal to the number of NS nodes
            LocalTissues = new List <LocalTissue>(new LocalTissue[args.NumLocals]);
            for (int i = 0; i < args.NumLocals; i++)
            {
                var lt = new LocalTissue();
                LocalTissues[i] = lt;
                lt.Start();
            }

            // create, train and start thymus agents
            Thymuses = new List <Thymus>(new Thymus[args.NumThymuses]);
            for (int i = 0; i < args.NumThymuses; i++)
            {
                var thymus = new Thymus(args.NumTCells, args.PeptideLen);
                thymus.Train(selfPatterns);                             // train the thymus by self patterns
                Thymuses[i] = thymus;
                thymus.Start();
            }

            // create and start bone marrow agents
            BoneMarrows = new List <BoneMarrow <T> >(new BoneMarrow <T> [args.NumBoneMarrows]);
            for (int i = 0; i < args.NumBoneMarrows; i++)
            {
                var bm = new BoneMarrow <T>(args.NumAPCs, OnProcessSpamp, OnProcessSdamp, OnProcessAntigen);
                BoneMarrows[i] = bm;
                bm.Start();
            }

            // create and start lymph node agents
            LymphNodes = new List <LymphNode>(new LymphNode[args.NumLymphNodes]);
            for (int i = 0; i < args.NumLymphNodes; i++)
            {
                var ln = new LymphNode();
                LymphNodes[i] = ln;
                ln.Start();
            }

            if (registerLogger)
            {
                // register logger event
                foreach (var tissue in Tissues)
                {
                    tissue.LogEvent += new EventHandler <LogEventArgs>(OnLog);
                }
            }

            // schedule all initial events
            foreach (var pair in initEvents.Where(e => e.LocalNodeId < LocalTissues.Count))
            {
                if (pair.Signal == null)
                {
                    throw new Exception("Event signal cannot be null.");
                }
                if (pair.LocalNodeId > args.NumLocals)
                {
                    throw new Exception("Event refers to an invalid local node ID. Check number of local nodes and localNodeId of event.");
                }
                Scheduler.Schedule(LocalTissues[pair.LocalNodeId].HandleSignal, pair.Time, pair.Signal);
            }
            Initialized = true;
        }
Example #10
0
 internal void StopSelectingRallyPoint()
 {
     selectedLymphNodeForRallyPoint = null;
 }