Esempio n. 1
0
void SquadronClass::UpdateSquadronStores (short weapon[HARDPOINT_MAX], uchar weapons[HARDPOINT_MAX], int lbsfuel, int planes)
	{
	int			i,j,n,done=0;
	long		f;
	int			weaparray[HARDPOINT_MAX] = {0};
	int			weapsarray[HARDPOINT_MAX] = {0};

	// Consolidate the weapons (we need to do this to minimize rounding errors)
	for (i=0; i<HARDPOINT_MAX; i++)
		{
		if (!(WeaponDataTable[weapon[i]].Flags & WEAP_INFINITE_MASK))
			{
			for (j=0,done=0; j<HARDPOINT_MAX && !done; j++)
				{
				if (weapon[i] == weaparray[j] || !weaparray[j])
					{
					weaparray[j] = weapon[i];
					weapsarray[j] += weapons[i] * planes;
					done = 1;
					}
				}
			}
		}

	// Record the stuff
	for (i=0; i<HARDPOINT_MAX && weaparray[i]; i++)
		{	
		// One 'supply point' is worth four weapons (or 1, if we're loading less than 4)	
		if (weapsarray[i] > 0)
			n = GetUnitStores(weaparray[i]) - ((weapsarray[i]+3)/4);
		else
			n = GetUnitStores(weaparray[i]) - ((weapsarray[i]-3)/4);
		if (n < 0)
			n = 0;
		if (n > 255)
			n = 255;
		SetUnitStores(weaparray[i], n);
		}
	f = GetSquadronFuel() - ((lbsfuel * planes) / 100);
	if (f < 0)
		f = 0;
	SetSquadronFuel(f);

	if (!IsLocal())
		{
		// Send a message to host notifying him of the changes to the squadron's weapon loads
		VuSessionEntity				*target = (VuSessionEntity*) vuDatabase->Find(OwnerId());
		FalconFlightPlanMessage		*msg = new FalconFlightPlanMessage(Id(), target);
		uchar						*buffer;

		msg->dataBlock.type = FalconFlightPlanMessage::squadronStores;
		msg->dataBlock.size = HARDPOINT_MAX + HARDPOINT_MAX * sizeof(short) + sizeof(long)*2;
		msg->dataBlock.data = buffer = new uchar[msg->dataBlock.size];
		memcpy(buffer,weapon,HARDPOINT_MAX * sizeof(short));		buffer += HARDPOINT_MAX * sizeof(short);
		memcpy(buffer,weapons,HARDPOINT_MAX);		buffer += HARDPOINT_MAX;
		memcpy(buffer,&lbsfuel,sizeof(long));		buffer += sizeof(long);
		memcpy(buffer,&planes,sizeof(long));		buffer += sizeof(long);
		FalconSendMessage(msg, TRUE);		
		}
	}
Esempio n. 2
0
void EjectedPilotClass::InitJettisonCanopy(){
	AircraftClass	*aircraft = (AircraftClass*) vuDatabase->Find(_aircraftId);

	_stageTimer = 0.0f;

	if (aircraft)
	{
		FalconSessionEntity *session = (FalconSessionEntity*) vuDatabase->Find(OwnerId());

		// Turn off the canopy.
		aircraft->SetSwitch(SIMP_CANOPY, FALSE);

		// Find and set the position of the seat in the cockpit.
		CalculateAndSetPositionAndOrientationInCockpit();

		// Create the drawable bsp here.
		// SCR 5/27/98  At this point a drawable was already created based on class table data in 
		// the OTWDriver::CreateVisualObject() function.  It might be okay to just use that if it
		// is always correcct, but for now I'll go ahead and let the existing draw pointer get 
		// deleted and a new one created in its place in the SetModel() call...
		SetModel(MD_PILOT_AND_SEAT);

		if(IsPlayerPilot() && session == FalconLocalSession)
		{
			// The sim driver now needs to know that the ejected pilot is the player entity.
			// KCK: We unfortunately need to do this outside of our exec loop, since it will
			// destroy our driver. So send a message which we'll handle later in the sim cycle.
			GameManager.AnnounceTransfer(aircraft,this);
		}
	}
}
EXPORT_C void CMemSpyEngineChunkEntry::AppendOwnerName( TDes& aDes ) const
    {
    RProcess owner;
    const TInt error = owner.Open( (TProcessId) OwnerId() );
    if  ( error == KErrNone )
        {
        aDes.Append( owner.FullName() );
        owner.Close();
        }
    }
Esempio n. 4
0
// Sends a message to the GTM
void GroundTaskingManagerClass::SendGTMMessage (VU_ID from, short message, short data1, short data2, VU_ID data3)
{
	VuTargetEntity	*target = (VuTargetEntity*) vuDatabase->Find(OwnerId());
	FalconGndTaskingMessage*	togtm = new FalconGndTaskingMessage(Id(), target);

	if (this)
	{
		togtm->dataBlock.from = from;
		togtm->dataBlock.team = owner;
		togtm->dataBlock.messageType = message;
		togtm->dataBlock.data1 = data1;
		togtm->dataBlock.data2 = data2;
		togtm->dataBlock.enemy = data3;
		FalconSendMessage(togtm,TRUE);
	}
}
Esempio n. 5
0
// KCK: This is the function which determines what we do with all
// of a session's entities when it's gone off-line
VU_ERRCODE FalconGameEntity::Distribute(VuSessionEntity *sess)
{
	FalconSessionEntity	*new_host;

	MonoPrint("Calling Distribute() for %s",gameName_);
	if (sess)
		MonoPrint("- player: %s.\n",((FalconSessionEntity*)sess)->GetPlayerCallsign());
	else
		MonoPrint("- distribute all.\n");

	// KCK: Try using association to let VU do the distribution for us!
	VuGameEntity::Distribute(sess);

	new_host = (FalconSessionEntity*)vuDatabase->Find(OwnerId());
	if (new_host)
		MonoPrint("New Host: %s\n",((FalconSessionEntity*)new_host)->GetPlayerCallsign());
	else
		MonoPrint("No new host - shutting game down\n");

/*	if (!sess || Id() == sess->GameId()) 
		{
		// All Features get transfered to nearest session.
		// All Non-player transferable vehicles (i.e. non-dogfight) get transfered to nearest session.
		// Everything else gets removed
		VuDatabaseIterator	dbiter;
		VuEntity			*ent;
		uchar				ent_class;
		FalconSessionEntity	*new_host = (FalconSessionEntity*)vuDatabase->Find(OwnerId());

		// Step 1) A new game owner is picked, if necessary - basically, the session with the lowest creator id.
		if (new_host == sess)
			{
			VuSessionsIterator	siter(this);
			FalconSessionEntity	*cs;
			ulong				best = ~0;
		
			new_host = NULL;
			cs = (FalconSessionEntity*) siter.GetFirst();
			while (cs) 
				{
				if ((!sess || sess->Id() != cs->Id()) && cs->GameId() == Id() && (ulong)cs->Id().creator_ < best) 
					{
					best = cs->Id().creator_;
					new_host = cs;
					}
				cs = (FalconSessionEntity*) siter.GetNext();
				}
			}

		// We must be loaded in order to take over this game
		if (new_host == FalconLocalSession && !TheCampaign.IsLoaded())
			CampaignJoinFail(TRUE);

		if (new_host)
			MonoPrint("New Host: %s\n",((FalconSessionEntity*)new_host)->GetPlayerCallsign());
		else
			MonoPrint("No new host - shutting game down\n");

		// Step 2: Redistribute all the entities
		// The Game and any Groups get transfered to game owner.
		// All Objectives get transfered to game owner.
		// All Units get transfered to game owner.
		// All Managers get transfered to game owner.
		// All Transferable Features and Vehicles are temporarily transfered to the game owner 
		// - but should get transfered or reaggregated when the new owner handles the reaggregate message for the parent.
		// All other entities are removed.
		VuEnterCriticalSection();
		ent = dbiter.GetFirst();
		while (ent) 
			{
			if ((!sess || ent->OwnerId() == sess->Id()) && ent != sess)
				{
				ent_class = ent->EntityType()->classInfo_[VU_CLASS];
				if (!new_host || (sess && !ent->IsTransferrable()))
					{
					vuDatabase->Remove(ent);
					}
				else if (ent_class == CLASS_OBJECTIVE || ent_class == CLASS_UNIT || ent_class == CLASS_MANAGER || ent_class == CLASS_GAME || ent_class == CLASS_GROUP)
					{
					((FalconEntity*)ent)->SetOwner(new_host);
					((CampEntity)ent)->SendMessage(sess->Id(), FalconCampMessage.campReaggregate, 0, 0, 0, 0);
					}
				else if (ent_class == CLASS_FEATURE || ent_class == CLASS_VEHICLE)
					{
					// KCK: If there's a valid deaggregate owner, set owner to that..
					if ((int)((SimBaseClass*)ent)->campaignObject > MAX_IA_CAMP_UNIT && ((CampBaseClass*)((SimBaseClass*)ent)->campaignObject)->deag_owner != sess->Id())
						((SimBaseClass*)ent)->ChangeOwner(((CampBaseClass*)((SimBaseClass*)ent)->campaignObject)->GetDeaggregateOwner());
					// Otherwise, change ownership to the host (let campaign entity know too!)
					else
						{
						((SimBaseClass*)ent)->ChangeOwner(new_host);
						((CampBaseClass*)((SimBaseClass*)ent)->campaignObject)->deag_owner = new_host->Id();
						}
					}
				else
					{
					vuDatabase->Remove(ent);
					}
				}
			ent = dbiter.GetNext();
			}
		VuExitCriticalSection();
		}
*/
	if( FalconLocalGame && FalconLocalSession && \
			FalconLocalSession->GetFlyState() == FLYSTATE_IN_UI && \
			FalconLocalGame->OwnerId() == FalconLocalSession->Id() && \
			gMainHandler)
		{
			INFOSetupRulesControls();
		}

	return VU_SUCCESS;
	}