Esempio n. 1
0
    private bool TryPlace(Server srv)
    {
        Phantom p = null, bestP = null;
        int     waste = 2147483647, w;

        for (int i = 0; i < sc.phantoms.Count; i++)
        {
            p = (Phantom)sc.phantoms.GetByIndex(i);
            if (p.CanAccomodate(srv))
            {
                w = p.GetWaste(srv);
                if (w < waste)
                {
                    waste = w;
                    bestP = p;
                }
            }
        }

        if (bestP != null)
        {
            bestP.Stack(srv);
            return(true);
        }

        return(false);
    }
Esempio n. 2
0
    /// <summary>
    /// Handle the Map command.
    /// </summary>
    /// <param name="l">Map</param>
    private void CmdMap(string l)
    {
        if (calculate)
        {
            Verbose.Out("Calculation mode - skipping Map");
            return;
        }

        int i;

        if ((i = l.IndexOf(']')) == -1)
        {
            Errors.Error("Usage: " + UsMap + " (" + lineNo + ")");
        }
        else
        {
            string p = l.Substring(0, i);

            if (phantoms.ContainsKey(p))
            {
                char[]   delim = new char[] { ' ' };
                Phantom  ph    = (Phantom)phantoms[p];
                string[] a;

                l = l.Substring(i + 1);
                a = l.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                for (i = 0; i < a.Length; i++)
                {
                    if (iServers.ContainsKey(a[i]))
                    {
                        if (ph.srvs.ContainsKey(a[i]) == true)
                        {
                            Errors.Warning("Server '" + a[i] + "' is already bound to this phantom - skipping (" + lineNo + ")");
                        }
                        else
                        {
                            Verbose.Out("Binding '" + a[i] + "' to phantom '" + ph.name + "' (" + lineNo + ")");
                            ph.Stack((Server)iServers[a[i]]);
                        }

                        iServers.Remove(a[i]);
                    }
                    else
                    {
                        Errors.Error("No such server: '" + a[i] + "' (" + lineNo + ")");
                    }
                }
            }
            else
            {
                Errors.Error("No such phantom server: '" + p + "' (" + lineNo + ")");
            }
        }
    }