Ejemplo n.º 1
0
    public void Start()
    {
        GrabSettings();

        rb       = GetComponent <Rigidbody>();
        simCtrl  = GetComponent <SimInstantiator>();
        worldMap = FindObjectOfType <SimulationMap>();
        InvokeRepeating("CalcNeighbors", neighborCalcFreq, neighborCalcFreq);
        InvokeRepeating("Drift", villageNumber / 100f, driftFreq);

        Vector3 scale = gameObject.transform.localScale;

        for (int i = 0; i < population; i++)
        {
            // Make a new agent.
            GameObject clone     = Instantiate(agentPrefab);
            AgentCtrl  cloneCtrl = clone.GetComponent <AgentCtrl>();
            agents.Add(cloneCtrl);
            cloneCtrl.SetHome(this);

            // Set the agent moving along a random direction.
            Rigidbody cloneRB = clone.GetComponent <Rigidbody>();
            cloneRB.velocity = new Vector3(Random.Range(0f, 100f), 0f, Random.Range(0f, 100f));

            // Put the agent somewhere in the village.
            float rndX = Random.Range(-scale.x / 2f, +scale.x / 2f);
            float rndZ = Random.Range(-scale.z / 2f, +scale.z / 2f);
            rndX += gameObject.transform.position.x;
            rndZ += gameObject.transform.position.z;
            clone.transform.position = new Vector3(rndX, 1f, rndZ);    // 1 so agents aren't spawned inside the ground
        }
    }
Ejemplo n.º 2
0
 public void CalcNeighbors()
 {
     neighbors.Clear();  // in case we want to recalculate this after some changes
     if (worldMap == null)
     {
         worldMap = FindObjectOfType <SimulationMap>();
     }
     neighbors.AddRange(worldMap.GetNeighbors(GetPosition(), neighborsPerVillage));
 }
Ejemplo n.º 3
0
        static public void OnClose(GameSocket gameSocket)
        {
            using (Database DataContext = new Database(Program.Configuration["database:connection-string"]))
            {
                Character c = DataContext.Characters.Find(gameSocket.SelectedCharacter.CharacterId);
                //DataContext.Entry(oldMap).CurrentValues.SetValues(m);
                c.CoordX = gameSocket.SelectedCharacter.BoundingBox.X;
                c.CoordY = gameSocket.SelectedCharacter.BoundingBox.Y;
                DataContext.SaveChanges();
            }

            SimulationMap sm = Program.SimulatedMaps.FirstOrDefault(smm => smm.Map.MapId == gameSocket.SelectedCharacter.CurrentMapId);

            sm.RemoveCharacter(gameSocket.SelectedCharacter);

            Network.GamingConnections.Remove(gameSocket);
        }
Ejemplo n.º 4
0
 static public void SetupMapsSimulations()
 {
     SimulatedMaps = new List <SimulationMap>();
     using (Database DataContext = new Database(Configuration["database:connection-string"]))
     {
         List <Map> maps = DataContext.Maps.ToList();
         foreach (Map m in maps)
         {
             SimulationMap sm = new SimulationMap(m);
             SimulatedMaps.Add(sm);
         }
         foreach (SimulationMap sm in SimulatedMaps)
         {
             sm.Start();
         }
     }
 }
Ejemplo n.º 5
0
    void Start()
    {
        GrabAndSetSettings();

        Time.timeScale = 1f;
        Random.InitState((int)seed);
        worldMap = FindObjectOfType <SimulationMap>();  // MakeVillage() needs this to work,
        Debug.Log(worldMap);

        for (int i = 0; i < numVillages; i++)
        {
            MakeVillage();
        }

        CalcNeighbors();
        GetComponent <DataSummarizer>().villages = worldMap.villageList;
        PhysicallyPlaceVillages();
        PlaceCamera();
    }
Ejemplo n.º 6
0
    static void Main(string[] args)
    {
        char[][]   map     = new char[12][];
        List <int> lastSim = new List <int>();

        while (true)
        {
            var colors = new List <Color>();
            for (int i = 0; i < 8; i++)
            {
                string[] inputs = Console.ReadLine().Split(' ');
                colors.Add(new Color(char.Parse(inputs[0]), char.Parse(inputs[1])));
            }
            for (int i = 0; i < 12; i++)
            {
                map[i] = Console.ReadLine().ToCharArray();
            }
            for (int i = 0; i < 12; i++)
            {
                string ennemy = Console.ReadLine(); // One line of the map ('.' = empty, '0' = skull block, '1' to '5' = colored block)
            }
            //colors.ForEach(color => Console.Error.WriteLine("ColorA {0}, ColorB : {1}", color.ColorA, color.ColorB));

            SimulationMap sm = new SimulationMap(colors, map, lastSim);
            lastSim = sm.lastSim;
            if (sm.baseMax[sm.bestCol] < 0 ||
                sm.baseMax[sm.bestCol + 1] < 0 ||
                sm.baseMax[sm.bestCol] > 11 ||
                sm.baseMax[sm.bestCol + 1] > 11)
            {
                Console.Error.WriteLine("ERROR");
                sm.TryMin();
            }

            /*Console.Error.Write("MAIN : ");
             * foreach(int l in lastSim)
             *  Console.Error.Write("{0} ", l);
             * Console.Error.WriteLine();*/

            Console.WriteLine("{0} {1}", sm.bestCol, 0);
        }
    }
Ejemplo n.º 7
0
        static public void OnMessage(GameSocket gameSocket, string msg)
        {
            //Log.Information("GameSocket > " + msg + " from host " + gameSocket.Socket.ConnectionInfo.ClientIpAddress);
            if (msg.StartsWith("client.char.move"))
            {
                string[]    arguments = msg.Split("|");
                int         dirValue  = Convert.ToInt32(arguments[1]);
                AABB.Movdir dir       = AABB.Movdir.TOP;
                switch (dirValue)
                {
                case 0:
                    gameSocket.SelectedCharacter.movementDirection = MovingDirection.Top;
                    dir = AABB.Movdir.TOP;
                    break;

                case 2:
                    gameSocket.SelectedCharacter.movementDirection = MovingDirection.Right;
                    dir = AABB.Movdir.RIGHT;
                    break;

                case 4:
                    gameSocket.SelectedCharacter.movementDirection = MovingDirection.Down;
                    dir = AABB.Movdir.DOWN;
                    break;

                case 6:
                    gameSocket.SelectedCharacter.movementDirection = MovingDirection.Left;
                    dir = AABB.Movdir.LEFT;
                    break;

                default:
                    break;
                }
                gameSocket.SelectedCharacter.BoundingBox.SetMovement(dir);
            }
            else if (msg.StartsWith("client.char.stop"))
            {
                gameSocket.SelectedCharacter.movementDirection = MovingDirection.Stop;
                gameSocket.SelectedCharacter.BoundingBox.StopMovement();
            }
            else if (msg.StartsWith("client.chat.message"))
            {
                string[] arguments = msg.Split("|");
                string   m         = arguments[1];
                string   message   = gameSocket.SelectedCharacter.Name + ": " + m;
                foreach (GameSocket gs in Network.GamingConnections)
                {
                    gs.Socket.Send("server.chat.message|" + message);
                }
            }
            else if (msg.StartsWith("client.map.chonmap"))
            {
                SimulationMap sm = Program.SimulatedMaps.FirstOrDefault(smm => smm.Map.MapId == gameSocket.SelectedCharacter.CurrentMapId);
                if (sm != null)
                {
                    sm.GetOtherCharsOnMap(gameSocket.SelectedCharacter);
                }
            }
            else if (msg.StartsWith("client.cast.spell1"))
            {
                SimulationMap sm = Program.SimulatedMaps.FirstOrDefault(smm => smm.Map.MapId == gameSocket.SelectedCharacter.CurrentMapId);
                if (sm != null)
                {
                    gameSocket.SelectedCharacter.CurrentResource -= 5;
                    string[] arguments = msg.Split("|");
                    sm.AddProjectile(gameSocket.SelectedCharacter, Convert.ToInt32(arguments[1]), Convert.ToInt32(arguments[2]), 4, 10, 23, 10, false);
                }
            }
            else if (msg.StartsWith("client.cast.spell2"))
            {
                SimulationMap sm = Program.SimulatedMaps.FirstOrDefault(smm => smm.Map.MapId == gameSocket.SelectedCharacter.CurrentMapId);

                if (sm != null && gameSocket.SelectedCharacter.CurrentResource > 20)
                {
                    gameSocket.SelectedCharacter.CurrentResource -= 20;
                    gameSocket.SelectedCharacter.isShielded       = true;
                    sm.NotifyAllInMap("csh|" + gameSocket.SelectedCharacter.CharacterId);
                    new Thread(new ThreadStart(() => {
                        Thread.Sleep(3000);
                        try
                        {
                            gameSocket.SelectedCharacter.isShielded = false;
                            sm.NotifyAllInMap("cnsh|" + gameSocket.SelectedCharacter.CharacterId);
                        }
                        catch (Exception e) {
                            Console.WriteLine("Couldn't find entity to stop spell2");
                        }
                    })).Start();
                }
            }
            else if (msg.StartsWith("client.cast.spell3"))
            {
                SimulationMap sm = Program.SimulatedMaps.FirstOrDefault(smm => smm.Map.MapId == gameSocket.SelectedCharacter.CurrentMapId);
                if (sm != null)
                {
                    gameSocket.SelectedCharacter.CurrentResource -= 50;
                    string[] arguments = msg.Split("|");
                    sm.AddProjectile(gameSocket.SelectedCharacter, Convert.ToInt32(arguments[1]), Convert.ToInt32(arguments[2]), 1, 20, 60, 5, true);
                }
            }
            else
            {
                Log.Error("Un-handled command from client " + msg);
            }
        }