public override bool Equals(object obj) { Projector obj2 = (Projector)obj; return(this.id == obj2.id); }
/// <summary> /// Gets the relative position for a target. /// </summary> /// <param name="target">The object whose position needs to be obtained</param> /// <returns>A RelativePosition structure</returns> protected RelativePosition getPosition(Projector target) { return(Degrees.getPosition(x, y, z, direction, target.x, target.y, target.z, target.direction, target.isObject)); }
protected virtual void activate() { try { running = true; while (true) { modifiedProjectorList = false; startMarker = Environment.TickCount; count = 0; hault(); //will block here if asked to do so, //and then move on when released. lock (lockObject) { foreach (Object o in projectors) { Projector p = (Projector)o; if (!p.isTerminated) { p.move(); } else { p.freeResources(); remove(p); } if (modifiedProjectorList) //IE: if object requested another object to be added to this holder { break; } } //foreach } //lock long executionTime = Environment.TickCount - startMarker; if (executionTime < Common.intervalMS) { Thread.Sleep((int)(Common.intervalMS - executionTime)); } /* BUG FIX: * We need to have the added check below since * in an online game, holder[1] will have 0 projectors until a player connects to the FFA. * This would cause the holder to terminate, so when the player connected and * moved, the move would not register. * */ if (projectors.Count == 0 && (added || Interaction.isFFAFinished() || Options.abortGame || Options.serverEndedGame || Options.requestedShutdown)) { running = false; done = true; System.Diagnostics.Trace.WriteLine("Holder ended: " + (this is WeaponsHolder)); return; } } //while } catch (Exception e) { Common.handleError(e); } //catch }
public override void lockOn(Projector target) { origTarget = target; }
public static bool inRange(Projector weapon, Projector target, Range r) { return((Degrees.getDistanceBetween(weapon.x, weapon.y, target.x, target.y) <= r.horizontalDistance) && (Math.Abs(weapon.z - target.z) <= r.verticalDistance)); }
/// <summary> /// Creates a new projectile. /// </summary> /// <param name="type">The type (Guns, Missile, LTS, etc) of the weapon</param> /// <param name="target">The projector at which this projectile is being fired</param> /// <param name="reachRange">The range of how wide this projectile will consider itself a hit</param> /// <returns>The projectile as type Explosive. It will also have been given an ID.</returns> private WeaponBase createNewWeapon(WeaponTypes type, Projector target, Range reachRange) { //if isLoading is true, ammo count could be 0 but we still have to load weapon //since ammo is decreased when weapon is created. WeaponBase w = null; if (ammunitionFor(type) != 0 || Options.isLoading) { switch (type) { case WeaponTypes.guns: validWeapons.Add(w = new Guns(this)); break; case WeaponTypes.missile: validWeapons.Add(w = new Missile(this)); break; case WeaponTypes.laserCannonSystem: if ((lCSTarget == null && LTSCount < 1) || Options.isLoading) { //ltsCount will not increment if loaded in from file LTSCount++; //so increment it if we're loading it from a file as well validWeapons.Add(w = new LaserCannonSystem(this)); } break; case WeaponTypes.cruiseMissile: validWeapons.Add(w = new CruiseMissile(this)); break; case WeaponTypes.missileInterceptor: Projector iLock = getInterceptorLock(); if (iLock == null) { break; } target = iLock; validWeapons.Add(w = new MissileInterceptor(this)); break; case WeaponTypes.samMissile: validWeapons.Add(w = new SAMMissile(this)); break; case WeaponTypes.explosiveMissile: validWeapons.Add(w = new ExplosiveMissile(this)); break; case WeaponTypes.tankMissile: validWeapons.Add(w = new TankMissile(this)); break; case WeaponTypes.battleShipGuns: validWeapons.Add(w = new BattleShipGuns(this)); break; } } //if ammo remaining if (w != null) { // Only the client that fired the actual projectile will send info about its fired projectiles. // Other clients will just duplicate this projectile, and wait for instructions from this client. String id = creator.id + "_" + next + "_" + (nextPos++); if (nextID != null) //received weapon duplicate command from server { w.setID(nextID); // command includes assigned ID. /*When firing with guns, only one creation ID will be sent to the server, * signaling the ID of the first shot. We parse this ID to get the IDs of the remaining shots since nextID will be null after this. * See use() to see how gunshots are fired together. * */ if (weaponIndex == WeaponTypes.guns) { String[] idParts = nextID.Split(new char[] { '_' }); next = Convert.ToInt32(idParts[1]); nextPos = Convert.ToInt32(idParts[2]) + 1; } //if guns nextID = null; } else //If nextID == null IE: not server weapon { if (!Options.isLoading) //weapon's load method will add to object table { w.setID(id, !(w is Guns)); //don't add bullets to object table } } w.readyToDispose += freeWeapon; //Notify this class when the weapon has completed its execution w.eventHit += eventHit; if (target != null) { w.lockOn(target); } w.initRange(reachRange); System.Diagnostics.Trace.WriteLineIf(w != null, "WCreated weapon " + w.id); if (w.id != null) { System.Diagnostics.Trace.WriteLine("WCreated id " + w.id); } return(w); } return(null); }
public void clearLock() { lockIndex = "-"; m_target = null; }
public override void serverSideHit(Projector target, int remainingDamage) { throw new NotImplementedException(); }
public static MemoryStream completeBuild(Projector source, bool includeCommonAttributes) { MemoryStream mem = new MemoryStream(); BinaryWriter writer = new BinaryWriter(mem); ClientRecord cr = senders[source.id]; Aircraft a = null; if (source is Aircraft) { a = (Aircraft)source; } System.Diagnostics.Trace.WriteLine("Called complete build"); if (a != null) { System.Diagnostics.Trace.WriteLine("with " + a.name); } if (includeCommonAttributes && source.role == OnlineRole.bot) { writer.Write((sbyte)3); } else { writer.Write((sbyte)2); } writer.Flush(); long pos = mem.Position; writer.Write((uint)0); writer.Write(source.id); writer.Flush(); long numArgs = mem.Position; writer.Write((ushort)0); ushort size = 2; writer.Write((byte)Fields.damage); writer.Write(source.damage); writer.Write((byte)Fields.direction); writer.Write(source.direction); if (includeCommonAttributes) { writer.Write((byte)Fields.x); writer.Write(source.x); writer.Write((byte)Fields.y); writer.Write(source.y); writer.Write((byte)Fields.z); writer.Write(source.z); writer.Write((byte)Fields.speed); writer.Write(source.speed); size += 4; if (a != null) { //If this is object update for aircraft, need to send //throttle and afterburner status also writer.Write((byte)Fields.throttlePosition); writer.Write(a.getThrottle()); writer.Write((byte)Fields.isOnRunway); writer.Write(a.getRunwayStatus()); writer.Write((byte)Fields.afterburnersActive); writer.Write(a.getAfterburnerStatus()); writer.Write((byte)Fields.cloakStatus); writer.Write(a.getCloakStatus()); size += 4; } //if sending update for aircraft } if (includeCommonAttributes) { cr.dataCount += cr.deferredCount; } writer.Write((short)cr.dataCount); if (cr.dataCount > 0) { writer.Flush(); cr.data.WriteTo(mem); cr.data.SetLength(0); cr.dataCount = 0; } if (includeCommonAttributes && cr.deferredCount > 0) { writer.Flush(); cr.deferred.WriteTo(mem); cr.deferred.SetLength(0); cr.deferredCount = 0; } mem.Position = numArgs; writer.Write(size); mem.Position = pos; writer.Write((uint)mem.Length); writer.Flush(); mem.Position = 0; return(mem); }
private static void processRCV() { try { while (live) { if (!CSCommon.isLiveConnection(client)) { live = false; SapiSpeech.speak("Erreur: Le serveur a planté.", SapiSpeech.SpeakFlag.noInterrupt); Common.exitMenus = true; Common.repop(); return; } MemoryStream stream = null; //Bytes have to be explicitly copied into new stream since cmds is closed to save memory later on, so we'll lose rcvPauseData. stream = CSCommon.getData(client); BinaryReader cmds = null; if (stream != null) { cmds = new BinaryReader(stream); } if (cmds != null) { sbyte t; long start = 0; //start position of current packet while (cmds.BaseStream.Length > cmds.BaseStream.Position) { start = cmds.BaseStream.Position; System.Diagnostics.Trace.WriteLine(String.Format("S: {0}, L: {1}", start, cmds.BaseStream.Length)); t = cmds.ReadSByte(); if (t == 1) { byte command = cmds.ReadByte(); System.Diagnostics.Trace.WriteLine("co " + command); switch (command) { case CSCommon.cmd_addMember: addMember(cmds.ReadString(), cmds.ReadString()); break; case CSCommon.cmd_removeMember: removeMember(cmds.ReadString()); break; case CSCommon.cmd_resp: int respLength = cmds.ReadInt32(); responseStream = new byte[respLength]; cmds.BaseStream.Read(responseStream, 0, respLength); waitingForResponse.Set(); break; case CSCommon.cmd_notifyDemo: DSound.PlaySound(DSound.LoadSound(DSound.NSoundPath + "\\cd3.wav"), true, false); break; case CSCommon.cmd_newval: SelfVoice.purge(true); int amount = cmds.ReadInt32(); SelfVoice.NLS("#" + amount + "&points.wav", true, true); addChatMessage(String.Format("You earned {0} point{1}", amount, (amount == 1) ? "" : "s")); break; case CSCommon.cmd_position: next = cmds.ReadInt64(); addOns = processAddOns(cmds); break; case CSCommon.cmd_chat: MessageType type = (MessageType)cmds.ReadByte(); if (type == MessageType.normal) { DSound.PlaySound(chatSound, true, false); } else if (type == MessageType.enterRoom) { DSound.PlaySound(chatEnterSound, true, false); } else if (type == MessageType.leaveRoom) { DSound.PlaySound(chatLeaveSound, true, false); } else if (type == MessageType.privateMessage) { DSound.PlaySound(privateMessageSound, true, false); } else { DSound.PlaySound(serverMessageSound, true, false); } String incomingChatMessage = cmds.ReadString(); SapiSpeech.speak(incomingChatMessage, SapiSpeech.SpeakFlag.interruptable); addChatMessage(incomingChatMessage); Common.mainGUI.addToHistory(incomingChatMessage); break; case CSCommon.cmd_serverMessage: String incomingServerMessage = cmds.ReadString(); SapiSpeech.speak(incomingServerMessage, SapiSpeech.SpeakFlag.interruptable); addChatMessage(incomingServerMessage); break; case CSCommon.cmd_forceDisconnect: //Player was disconnected from the server //By the server itself and not through an in-game event, //so if we receive this command, we are being told to wipe our copy of the player in question. //Still, the server will send forceDisconnect even if object has already been disconnected //due to in-game event. This is ok since if the object is already gone, //this command will do nothing. It is just a redundancy check, more or less. String idToTerminate = cmds.ReadString(); Projector pToTerm = Interaction.objectAt(idToTerminate); if (pToTerm != null) { pToTerm.requestingTerminate(); } Interaction.clearLocks(idToTerminate); break; case CSCommon.cmd_requestCreate: //Response from server for requestCreate command sent by client. Interaction.createPlayer(cmds.ReadString(), cmds.ReadInt32()); addSender(Mission.player.id); if (addOns != null) { Mission.player.setAddOns(addOns); } addOns = null; if (Options.mode == Options.Modes.teamDeath) { Mission.player.team = Options.team; } Interaction.startMultiplayerGame(); break; case CSCommon.cmd_distributeServerTag: Projector o = Interaction.createObjectFromServer(cmds.ReadString(), cmds.ReadString(), OnlineRole.receiver, (ObjectType)cmds.ReadByte()); System.Diagnostics.Trace.WriteLine("Received request to create opponent " + o.name); if (Options.mode == Options.Modes.teamDeath) { o.team = (Projector.TeamColors)cmds.ReadInt32(); } AddOnArgs[] distAdd = processAddOns(cmds); if (distAdd != null) { o.setAddOns(distAdd); } break; case CSCommon.cmd_createBot: String createBotId = cmds.ReadString(); String createBotName = cmds.ReadString(); Projector bot = Interaction.createObjectFromServer(createBotId, createBotName, OnlineRole.bot, (ObjectType)cmds.ReadByte()); //will create bot or update current receiver to bot status. addSender(bot.id); break; case CSCommon.cmd_startGame: hostStartedGame = true; System.Diagnostics.Trace.WriteLine("Host started game"); break; case CSCommon.cmd_gameEnded: Options.serverEndedGame = true; break; } //switch System.Diagnostics.Trace.WriteLine("Command: " + t); continue; } //if command System.Diagnostics.Trace.Write(String.Format("Stream position: {0}, start: {1}, Char: {2} ", (int)cmds.BaseStream.Position, start, t)); int size = cmds.ReadInt32(); //total update size System.Diagnostics.Trace.WriteLine("Size: " + size); int temSize = size; String tag = cmds.ReadString(); System.Diagnostics.Trace.WriteLine(tag + " queuing data..."); Projector p = null; size = size - (int)(cmds.BaseStream.Position - start); byte[] buffer = null; try { buffer = new byte[size]; } catch (OverflowException) { throw new OverflowException(String.Format("Size: {0}, Stream position: {1}, start: {2}, original size: {3} Char: {4}", size, (int)cmds.BaseStream.Position, start, temSize, t)); } cmds.BaseStream.Read(buffer, 0, size); //Object could have been deleted by the time this command is reached if ((p = Interaction.objectAt(tag)) != null) { System.Diagnostics.Trace.WriteLine("Object found. sending queue"); p.queueData(t, buffer); } //if object exists else { System.Diagnostics.Trace.WriteLine("Object not found."); } } //while more data to read cmds.Close(); } //if got data Thread.Sleep(50); } //while live connection } catch (Exception e) { Common.handleError(e); } //catch finally { releaseConnection(); } }
public override void serverSideHit(Projector target, int remainingDamage) { throw new NotImplementedException("This weapon is not available online."); }