public void ProcessState() { if (processCtr % msgRate == 0) { //Send scoreboard updates IEnumerator byStat = playerStatsById.GetEnumerator(); byStat.Reset(); while (byStat.MoveNext()) { KeyValuePair <StatBoardEnum, Dictionary <int, int> > curKV = (KeyValuePair <StatBoardEnum, Dictionary <int, int> >)byStat.Current; StatBoardEvent statBoard = new StatBoardEvent(curKV.Key, curKV.Value); eventMgr.SendEvent(statBoard); } } //calculate ship stats //TO-DO foreach (Ship shipOne in shipMgr.ShipTable.Values) { foreach (Ship shipTwo in shipMgr.ShipTable.Values) { Vector3 distance = shipOne.ShipState.Orientation.Inverse() * (shipOne.Position - shipTwo.Position); if (distance.z < 0 && distance.x * distance.x + distance.y * distance.y < distance.z * distance.z && distance.Length < FOLLOW_DISTANCE) { playerStatsById[StatBoardEnum.PositiveTime][shipTwo.ID]++; playerStatsById[StatBoardEnum.NegativeTime][shipOne.ID]++; } } } processCtr++; }
public ServerShipManager(World serverWorld, EventManager eventManager, YmfasServer _server) { serverShipLog = Mogre.LogManager.Singleton.CreateLog("server-ship.log"); serverShipLog.LogMessage("creating ssm"); world = serverWorld; eventMgr = eventManager; server = _server; //init ships ShipTypeData curShipType = new ShipTypeData(); curShipType.Class = ShipClass.Interceptor; curShipType.Model = ShipModel.MogreFighter; //player ships foreach (int id in server.PlayerIds ) { Vector3 curPosition = Vector3.ZERO;//new Vector3(Mogre.Math.RangeRandom(-TestEngine.WorldSizeParam / 1.5f, TestEngine.WorldSizeParam / 1.5f), Mogre.Math.RangeRandom(-TestEngine.WorldSizeParam / 1.5f, TestEngine.WorldSizeParam / 1.5f), Mogre.Math.RangeRandom(-TestEngine.WorldSizeParam / 1.5f, TestEngine.WorldSizeParam / 1.5f)); Quaternion curOrientation = Quaternion.IDENTITY; ShipInit curShipInit = new ShipInit(id, curShipType, curPosition, curOrientation, server.GetPlayerName(id)); eventMgr.SendEvent(curShipInit); Util.Log("sent init for ship " + id); //put them in world Ship s = new Ship(world, id, curPosition, curOrientation); shipTable.Add(id, s); } //init listeners ShipControlStatus.FiringEvent += new GameEventFiringHandler(handleShipControlStatus); }
public void sendShipStateStatus() { List <ShipState> l = new List <ShipState>(); foreach (Ship s in shipTable.Values) { l.Add(s.ShipState); } eventMgr.SendEvent(new ShipStateStatus(l)); }
public void PollInputs() { int pitch = 0; int roll = 0; int yaw = 0; int thrust = 0; input.Update(); if (input.IsDown(Key.E)) { pitch += POSITIVE; } if (input.IsDown(Key.D)) { pitch += NEGATIVE; } if (input.IsDown(Key.F)) { yaw += NEGATIVE; } if (input.IsDown(Key.S)) { yaw += POSITIVE; } if (input.IsDown(Key.R)) { roll += POSITIVE; } if (input.IsDown(Key.W)) { roll += NEGATIVE; } if (input.IsDown(Key.Space)) { thrust = FULL; } if (input.IsDown(Key.A)) { pitch = AUTOCORRECT; roll = AUTOCORRECT; yaw = AUTOCORRECT; } m.SendEvent(new ShipControlStatus(thrust, pitch, roll, yaw, playerID)); }
public ServerShipManager(World serverWorld, EventManager eventManager, YmfasServer _server) { serverShipLog = Mogre.LogManager.Singleton.CreateLog("server-ship.log"); serverShipLog.LogMessage("creating ssm"); world = serverWorld; eventMgr = eventManager; server = _server; //init ships ShipTypeData curShipType = new ShipTypeData(); curShipType.Class = ShipClass.Interceptor; curShipType.Model = ShipModel.MogreFighter; //player ships foreach (int id in server.PlayerIds) { Vector3 curPosition = Vector3.ZERO; //new Vector3(Mogre.Math.RangeRandom(-TestEngine.WorldSizeParam / 1.5f, TestEngine.WorldSizeParam / 1.5f), Mogre.Math.RangeRandom(-TestEngine.WorldSizeParam / 1.5f, TestEngine.WorldSizeParam / 1.5f), Mogre.Math.RangeRandom(-TestEngine.WorldSizeParam / 1.5f, TestEngine.WorldSizeParam / 1.5f)); Quaternion curOrientation = Quaternion.IDENTITY; ShipInit curShipInit = new ShipInit(id, curShipType, curPosition, curOrientation, server.GetPlayerName(id)); eventMgr.SendEvent(curShipInit); Util.Log("sent init for ship " + id); //put them in world Ship s = new Ship(world, id, curPosition, curOrientation); shipTable.Add(id, s); } //init listeners ShipControlStatus.FiringEvent += new GameEventFiringHandler(handleShipControlStatus); }