void
NetGameClient::DoWepRelease(NetMsg* msg)
{
	if (!msg) return;

	NetWepRelease release;
	release.Unpack(msg->Data());

	NetPlayer* player = FindPlayerByObjID(release.GetObjID());
	if (player) {
		player->DoWepRelease(&release);
	}

	else {
		Ship* shooter = FindShipByObjID(release.GetObjID());
		if (shooter) {
			int   index = release.GetIndex();
			DWORD tgtid = release.GetTgtID();
			DWORD wepid = release.GetWepID();
			int   subid = release.GetSubtarget();
			bool  decoy = release.GetDecoy();
			bool  probe = release.GetProbe();

			Weapon* w = 0;

			if (decoy)        w = shooter->GetDecoy();
			else if (probe)   w = shooter->GetProbeLauncher();
			else              w = shooter->GetWeaponByIndex(index);

			if (w && !w->IsPrimary()) {
				SimObject*  target = FindShipByObjID(tgtid);
				System*     subtgt = 0;

				if (target) {
					if (subid >= 0) {
						Ship* tgt_ship = (Ship*) target;
						subtgt = tgt_ship->Systems().at(subid);
					}
				}
				else {
					target = FindShotByObjID(tgtid);
				}

				Shot* shot = w->NetFireSecondary(target, subtgt, wepid);

				if (shot && shot->IsDrone()) {
					if (probe)
					shooter->SetProbe((Drone*) shot);

					else if (decoy)
					shooter->AddActiveDecoy((Drone*) shot);
				}
			}
		}
	}
}
Ejemplo n.º 2
0
bool
NetPlayer::DoWepRelease(NetWepRelease* release)
{
	if (ship && release) {
		int   index = release->GetIndex();
		DWORD tgtid = release->GetTgtID();
		DWORD wepid = release->GetWepID();
		int   subid = release->GetSubtarget();
		bool  decoy = release->GetDecoy();
		bool  probe = release->GetProbe();

		Weapon* w = 0;

		if (decoy)        w = ship->GetDecoy();
		else if (probe)   w = ship->GetProbeLauncher();
		else              w = ship->GetWeaponByIndex(index);

		if (w && !w->IsPrimary()) {
			SimObject*  target = 0;
			System*     subtgt = 0;

			NetGame* net_game = NetGame::GetInstance();
			if (net_game) {
				target = net_game->FindShipByObjID(tgtid);

				if (target) {
					if (subid >= 0) {
						Ship* tgt_ship = (Ship*) target;
						subtgt = tgt_ship->Systems().at(subid);
					}
				}
				else {
					target = net_game->FindShotByObjID(tgtid);
				}
			}

			Shot* shot = w->NetFireSecondary(target, subtgt, wepid);

			if (shot && shot->IsDrone()) {
				if (probe)
				ship->SetProbe((Drone*) shot);

				else if (decoy)
				ship->AddActiveDecoy((Drone*) shot);
			}

			return true;
		}
	}

	return false;
}
Ejemplo n.º 3
0
bool
NetPlayer::DoWepTrigger(NetWepTrigger* trigger)
{
	if (ship && trigger) {
		int   index = trigger->GetIndex();
		int   count = trigger->GetCount();
		DWORD tgtid = trigger->GetTgtID();
		int   subid = trigger->GetSubtarget();
		bool  decoy = trigger->GetDecoy();
		bool  probe = trigger->GetProbe();

		Weapon* w = 0;

		if (decoy)        w = ship->GetDecoy();
		else if (probe)   w = ship->GetProbeLauncher();
		else              w = ship->GetWeaponByIndex(index);

		if (w) {
			SimObject*  target = 0;
			System*     subtgt = 0;

			NetGame* net_game = NetGame::GetInstance();
			if (net_game) {
				target = net_game->FindShipByObjID(tgtid);

				if (target) {
					if (subid >= 0) {
						Ship* tgt_ship = (Ship*) target;
						subtgt = tgt_ship->Systems().at(subid);
					}
				}
				else {
					target = net_game->FindShotByObjID(tgtid);
				}

				// re-broadcast:
				if (net_game->IsServer()) {
					if (w->IsPrimary()) {
						w->NetFirePrimary(target, subtgt, count);
						net_game->SendData(trigger);
					}
					else {
						DWORD wepid = NetGame::GetNextObjID(NetGame::SHOT);
						Shot* shot  = w->NetFireSecondary(target, subtgt, wepid);

						if (shot && shot->IsDrone()) {
							if (probe)
							ship->SetProbe((Drone*) shot);

							else if (decoy)
							ship->AddActiveDecoy((Drone*) shot);
						}

						NetWepRelease release;
						release.SetObjID(objid);
						release.SetTgtID(tgtid);
						release.SetSubtarget(subid);
						release.SetWepID(wepid);
						release.SetIndex(index);
						release.SetDecoy(decoy);
						release.SetProbe(probe);

						net_game->SendData(&release);
					}
				}

				else {
					if (w->IsPrimary()) {
						w->NetFirePrimary(target, subtgt, count);
					}
				}

				return true;
			}
		}

	}
	return false;
}