Ejemplo n.º 1
0
 public GameServer(GameRule rule, Map map, int botcount)
 {
     NextMap = map;
     NextBotCount = botcount;
     NextRule = rule;
 }
Ejemplo n.º 2
0
        public override void Tick(float dtime)
        {
            if (Local)
                Server.Tick(dtime);

            base.Tick(dtime);

            Log.Tick(dtime);

            if (MusicChannel != null && Music!=null)
            {
                if (!Root.Instance.UserInterface.Audio.IsPlaying(MusicChannel))
                {
                    MusicChannel = MainCamera.PlaySound(Music, true);
                }
            }

            if (Rule == null)
            {
                Rule = Root.Instance.Scene.FindEntityByType<GameRule>();
                if (Rule != null)
                {
                    //Rule.AnnounceEvent += ControlMenu.Comm.WriteLine;
                }
            }
            if (NeedInit)
            {
                if (Root.Instance.Scene.FindEntityByType<Map>() != null)
                {
                    Init();
                    NeedInit = false;
                }
                else return;
            }

            if (!Spectate)
            {
                Control.Tick(dtime);
                if (playership.Kill)
                {
                    TimeToSpawn -= dtime;
                    if (TimeToSpawn <= 0)
                    {
                        SpawnShip();
                    }
                }
            }
            MainCamera.Tick(dtime);

            if(Root.Instance.UserInterface!=null)
                UpdateCursorPosition(GetMouseVector());

            if (playership != null && Rule is Race)
            {
                CheckPoint cp = ((Race)Rule).GetNextCheckPoint((RacePlayer)Player);
                if (cp != null)
                {
                    Vector3 dir = cp.AbsolutePosition - playership.AbsolutePosition;
                    dir.Normalize();
                    dir *= 200;
                    Arrow.Position = playership.AbsolutePosition + dir;
                    Arrow.LookAt(cp.AbsolutePosition);
                    Arrow.Visible = true;
                }
                else
                    Arrow.Visible = false;
            }
            else
                Arrow.Visible = false;

            if (Spectate)
            {

            }
            else
            {
                if (playership != null && !playership.Kill && playership.Computer.Target != null)
                {
                    //valid target
                    TargetMarker.Visible = true;
                    TargetMarker.Attach = playership.Computer.Target;
                }
                else
                {
                    //no target
                    TargetMarker.Visible = false;
                }
            }
        }
Ejemplo n.º 3
0
        public override void Start()
        {
            base.Start();
            Config c = Root.Instance.ResourceManager.LoadConfig("config/global.config");

            Root.Instance.Scene.Clear();

            if (NextMap == null || NextRule == null)
                SetDefault();

            Root.Instance.Scene.Spawn(NextMap);
            NextMap = null;

            if (NextRule == null || NextRule is Mission)
                NextRule = Root.Instance.Scene.FindEntityByType<GameRule>();
            else
                Root.Instance.Scene.Spawn(NextRule);
            Rule = NextRule;
            NextRule = null;

            Rule.AnnounceEvent += Cheetah.Console.WriteLine;

            if (Root.Instance.UserInterface==null && c.GetBool("server.queryport.enable"))
            {
                int queryport = c.GetInteger("server.queryport");
                if (queryport > 0 && qs == null)
                    Root.Instance.LocalObjects.Add(qs = new QueryServer(queryport, new IQuery[] { new OldGameSpyQuery() }));
            }

            if (Root.Instance.UserInterface==null && c.GetBool("irc.enable") && reporter == null)
            {
                reporter = new IrcReporter(c.GetString("irc.host"), c.GetInteger("irc.port"), c.GetString("irc.nick"), c.GetString("irc.realname"), c.GetString("irc.channels").Split(','));
                Root.Instance.LocalObjects.Add(reporter);
                Rule.AnnounceEvent += reporter.Announce;
            }

            int botcount = NextBotCount;
            Bots = new SpaceShipBotControl[botcount];
            BotPlayers = new Player[botcount];
            for (int i = 0; i < botcount; ++i)
            {
                int team = (Rule is TeamDeathMatch) ? c.GetInteger("server.bot" + i + ".team") : -1;
                string name = c.GetString("server.bot" + i + ".name");
                SpawnBot(i, team, name);
            }
            //SpawnBot(1);
        }
Ejemplo n.º 4
0
        public Game(GameRule rule, Map map, int botcount,bool spectate)
        {
            Host = null;
            Demo = null;
            Spectate = spectate;

            Server = new GameServer(rule, map, botcount);

            PreCache();
        }
Ejemplo n.º 5
0
        public void SetDefault()
        {
            Cheetah.Console.WriteLine("loading defaults from config.");
            Config c = Root.Instance.ResourceManager.LoadConfig("config/global.config");

            NextMap = (Map)Activator.CreateInstance(Root.Instance.Factory.GetType(c.GetString("gameserver.map")));

            if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.DeathMatch).FullName)
                NextRule = CreateDeathMatch();
            else if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.TeamDeathMatch).FullName)
                NextRule = CreateTeamDeathMatch();
            else if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.KingOfTheHill).FullName)
                NextRule = CreateKingOfTheHill();
            else if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.Domination).FullName)
                NextRule = CreateDomination();
            else if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.Race).FullName)
                NextRule = CreateRace();
            else if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.CaptureTheFlag).FullName)
                NextRule = CreateCaptureTheFlag();
            else if (c.GetString("gameserver.rule") == typeof(SpaceWar2006.Rules.Mission).FullName)
                NextRule = NextMap.Mission;
            else throw new Exception("unknown rule.");

            NextBotCount = c.GetInteger("server.bots");
        }