Ejemplo n.º 1
0
void DogfightClass::ApplySettingsToFlight (Flight flight)
{
	float				x,y,z;
	WayPoint			w;
	int					p,i,cid=0;
	CampaignTime		ttc = FloatToInt32(startRange / 1500.0F) * CampaignSeconds;	// find time to convergence in campaign time
	
	x = startX + DFOffsetX[flight->GetTeam()]*startRange*0.5F;
	y = startY + DFOffsetY[flight->GetTeam()]*startRange*0.5F;
	
	while (calltable[flight->GetTeam()][cid] != flight->callsign_id)
	{
		cid++;
	}

	z = startAltitude - 500.0F * cid - 2500.0F * (flight->callsign_num-1);
	flight->SimSetLocation(x,y,z);
	
	if (FalconLocalGame && FalconLocalGame->IsLocal())
	{
		CampEnterCriticalSection();
		flight->DisposeWayPoints();
		
		// Start waypoint
		w = flight->AddUnitWP (0, 0, 0, 0, startTime, 0, WP_CA);
		w->SetLocation(x,y,startAltitude);
		flight->SetCurrentUnitWP(w);
		
		// Center waypoint
		w = flight->AddUnitWP (0, 0, 0, 0, startTime + ttc, 0, WP_CA);
		w->SetLocation(startX,startY,startAltitude);
		
		// Repeat waypoint
		w = flight->AddUnitWP (0, 0, 0, 0, startTime + ttc, 3*CampaignHours, WP_CA);
		w->SetLocation(x,y,startAltitude);
		w->SetWPFlags(WPF_REPEAT);
		
		// Load weapons
		flight->RemoveLoadout();
		flight->UseFuel(1);
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, numRadarMissiles, WEAP_FORCE_ON_ONE, WEAP_RADAR); 
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, numAllAspectMissiles, WEAP_FORCE_ON_ONE, WEAP_HEATSEEKER); 
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, numRearAspectMissiles, WEAP_FORCE_ON_ONE, WEAP_HEATSEEKER | WEAP_REAR_ASPECT); 

		if (flags & DF_ECM_AVAIL)
		{
			flight->LoadWeapons(NULL, DefaultDamageMods, Air, 1, WEAP_ECM, 0); 
		}

		// Load the gun (for guns only case)
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, 2, WEAP_GUN, 0); 
		CampLeaveCriticalSection();
	}

	flight->SetUnitLastMove (startTime);
	flight->SetFalcFlag(FEC_REGENERATING);
	
	// Check if there are any players in this flight
	for (i=0,p=0; i<PILOTS_PER_FLIGHT; i++){
		if (flight->player_slots[i] != NO_PILOT){
			p++;
		}
	}
	
	// Set our player flag appropriately
	if (p){
		flight->SetFalcFlag(FEC_PLAYERONLY);
		flight->SetFinal(0);
	}
	else {
		flight->UnSetFalcFlag(FEC_PLAYERONLY);
		flight->SetFinal(1);
	}
	
	flight->SetMoving(1);
	flight->SetNoAbort (1);
	flight->SetCurrentWaypoint (2);
	flight->SetUnitMission(AMIS_SWEEP);
	
	MonoPrint ("Apply Settings To Flight %08x %f %f %f\n", flight, x, y, z);
}
Ejemplo n.º 2
0
int TaskForceClass::MoveUnit (CampaignTime time)
{
    GridIndex x = 0, y = 0;
    GridIndex nx = 0, ny = 0;
    GridIndex ox = 0, oy = 0;
    WayPoint w = NULL, ow = NULL;
    Objective o = NULL;
    int	moving = 1;
    CampaignHeading	h = 0;

    // RV - Biker
    // Naval units now have three modes:
    // (a) Sit still in harbor
    // (b) Do a 20 km track (repeating waypoints)
    // (c) Followy WPs

    GetLocation(&x,&y);

    w = ResetCurrentWP(this);

    FindNearestUnit(x, y, NULL);

    // Check for mode a
    o = FindNearestObjective(x, y, NULL, 1);

    // RV - Biker - If we are in port and have no WPs do nothing
    if (o && o->GetType() == TYPE_PORT && !w) {
        return TRUE;
    }

    // If not in port and no WPs... create a repeating path 20 km north and back
    if (!w)	{
        DisposeWayPoints();

        w = AddUnitWP(x, y, 0, 60,	TheCampaign.CurrentTime + (rand()%15), 0, 0);
        w->SetWPFlags(WPF_REPEAT);

        // This should prevent naval units to run into ground
        if (GetCover(x, y+20) == Water) {
            w = AddUnitWP(x, y+20, 0, 60, TheCampaign.CurrentTime + (15+(rand()%15))*CampaignMinutes, 0, 0);
        }
        else {
            w = AddUnitWP(x, y, 0, 60, TheCampaign.CurrentTime + 15*CampaignMinutes, 0, 0);
        }
        w->SetWPFlags(WPF_REPEAT);

        w = AddUnitWP(x, y, 0, 60, TheCampaign.CurrentTime + (30+(rand()%15))*CampaignMinutes, 0xffffffff, 0);
        w->SetWPFlags(WPF_REPEAT);

        SetCurrentWaypoint (1);
        w = GetCurrentUnitWP();
    }

    w->GetWPLocation(&nx, &ny);

    // RV - Biker - Wait for departure
    if (Camp_GetCurrentTime() < w->GetWPDepartureTime()) {
        SetUnitLastMove(Camp_GetCurrentTime());
        return 0;
    }

    // Move, if we're not at destination
    if (x!=nx || y!=ny)
    {
        if (w)
            ow = w->GetPrevWP();
        if (ow)
            ow->GetWPLocation(&ox, &oy);
        else
            GetLocation(&ox, &oy);

        while (moving) {
            h = DirectionTo(ox, oy, nx, ny, x, y);
            if (h > 7) {
                moving = 0;
                h = Here;
            }
            // This is kinda hacky - basically, limit change in direction to 45 deg per move
            if (h > last_direction) {
                if (h - last_direction < 5)
                    h = (last_direction+1) & 0x07;
                else
                    h = (last_direction+7) & 0x07;
            }

            else if (h < last_direction) {
                if (last_direction - h < 5)
                    h = (last_direction+7) & 0x07;
                else
                    h = (last_direction+1) & 0x07;
            }

            //this moves the unit
            if (ChangeUnitLocation(h) > 0) {
                last_direction = h;
            }
            else {
                moving = 0;
            }

            // Now do combat
            if (GetCombatTime() > CombatTime()) {
                DoCombat();
            }
        }
    }
    return 0;
}