void MissionUpdateTime(Flight element,C_Mission *mission) { _TCHAR buffer[80]; mission->Refresh(); WayPoint wp = element->GetFirstUnitWP(); if (wp) { // JPO CTD fix GetTimeString(wp->GetWPDepartureTime(),buffer); mission->SetTakeOff(buffer); mission->SetTakeOffTime(wp->GetWPDepartureTime()); } else mission->SetTakeOff(_T("Unknown")); mission->Refresh(); }
long GetFlightTime(Flight element) { WayPoint wp; if(!element) return(0); wp=element->GetCurrentUnitWP(); if(wp) return(wp->GetWPDepartureTime()); return(0); }
WayPoint ResetCurrentWP (TaskForce tf) { WayPoint w; GridIndex x,y,ux,uy; w = tf->GetCurrentUnitWP(); while (w && w->GetWPDepartureTime() < Camp_GetCurrentTime()) { if (w->GetWPFlags()) // Make sure we actually get here, it's important { w->GetWPLocation(&x,&y); tf->GetLocation(&ux,&uy); if (DistSqu(x,y,ux,uy) > 2.0F) return w; if (DoWPAction(tf,w)) return tf->GetCurrentUnitWP(); } w = w->GetNextWP(); tf->SetCurrentUnitWP(w); } return w; }
// Unit within operation area, needs to take it's Waypoint's action // This currently is only called if this waypoint has a flag set WayPoint DoWPAction (TaskForce tf, WayPoint w) { WayPoint cw; if (!w || !tf) return NULL; // Check Actions /* int action = w->GetWPAction(); switch (action) { case WP_NOTHING: default: break; } */ // Check Flags if (w->GetWPFlags() & WPF_REPEAT) { // Check if we've been here long enough if (Camp_GetCurrentTime() > w->GetWPDepartureTime()) { // If so, go on to the next wp (adjust their times from now) tf->AdjustWayPoints(); } else { // If not, restore previous WP and readjust times cw = w->GetPrevWP(); tf->SetCurrentUnitWP(cw); tf->AdjustWayPoints(); return cw; } } return NULL; }
C_Mission *MakeMissionItem(C_TreeList *tree,Flight element) { C_Mission *mission; C_Window *win; _TCHAR buffer[200]; TREELIST *item; int ent_mission; Package package; WayPoint wp; if(!element->Final()) return(NULL); if(TheCampaign.Flags & CAMP_TACTICAL) { if (element->GetOwner () != FalconLocalSession->GetTeam ()) { return NULL; } } else { if(element->GetUnitSquadronID() != FalconLocalSession->GetPlayerSquadronID()) return(NULL); } if(!tree || !element || !element->GetUnitParent()) return(NULL); // Create new record mission=new C_Mission; if(!mission) return(NULL); win=tree->GetParent(); if(!win) return(NULL); mission->Setup(element->GetCampID(),0); // ID=element->CampID; mission->SetFont(win->Font_); mission->SetClient(tree->GetClient()); mission->SetW(win->ClientArea_[tree->GetClient()].right - win->ClientArea_[tree->GetClient()].left); mission->SetH(gFontList->GetHeight(tree->GetFont())); // Set takeoff time string wp = element->GetFirstUnitWP(); if (wp) { // JPO CTD fix GetTimeString(wp->GetWPDepartureTime(),buffer); mission->SetTakeOff(static_cast<short>(tree->GetUserNumber(C_STATE_0)),0,buffer); mission->SetTakeOffTime(wp->GetWPDepartureTime()); } // Set Mission Type ent_mission = element->GetUnitMission(); if (ent_mission == AMIS_ALERT) ent_mission = AMIS_INTERCEPT; mission->SetMission(static_cast<short>(tree->GetUserNumber(C_STATE_1)),0,MissStr[ent_mission]); mission->SetMissionID(static_cast<short>(element->GetUnitMission())); // Set Package (campID of package) _stprintf(buffer,"%1d",element->GetUnitParent()->GetCampID()); mission->SetPackage(static_cast<short>(tree->GetUserNumber(C_STATE_2)),0,buffer); mission->SetPackageID(element->GetUnitParent()->GetCampID()); // Set Mission Status String mission->SetStatusID(GetFlightStatusID(element)); mission->SetStatus(static_cast<short>(tree->GetUserNumber(C_STATE_3)),0,gStringMgr->GetString(FlightStatusID[mission->GetStatusID()])); // Set Mission Priority String package = element->GetUnitPackage(); buffer[1]=0; // KCK: It seemed more logical to get the priority from the flight, not the package's request // PJW: Why Kevin you are sooo f*****g wrong... and ASK when making changes butt f**k // buffer[0]=(255 - element->GetUnitPriority()) / 51 + _T('A'); buffer[0]=static_cast<char>((255 - package->GetMissionRequest()->priority) / 51 + _T('A')); mission->SetPriority(static_cast<short>(tree->GetUserNumber(C_STATE_4)),0,buffer); mission->SetPriorityID(static_cast<short>(255 - package->GetMissionRequest()->priority)); // Set a callback incase someone actually wants to see this mission // if (TheCampaign.Flags & CAMP_TACTICAL) // { // mission->SetCallback (TacMissionSelectCB); // } // else // { mission->SetCallback(MissionSelectCB); // } // Tack on the VU_ID mission->SetVUID(element->Id()); mission->SetUserNumber(C_STATE_0,element->GetTeam()); mission->SetUserNumber(C_STATE_1,wp ? wp->GetWPDepartureTime() : 0); mission->SetUserNumber(C_STATE_2,1000 - element->GetUnitPriority()); // Priority mission->SetUserNumber(C_STATE_3,element->GetUnitMission()); if (!element->Final() || element->GetUnitMission() == AMIS_ALERT) { mission->SetFlagBitOn(C_BIT_INVISIBLE); } // Add to tree item=tree->CreateItem(element->GetCampID(),C_TYPE_ITEM,mission); mission->SetOwner(item); if(tree->AddItem(tree->GetRoot(),item)) return(mission); mission->Cleanup(); delete mission; delete item; return(NULL); }
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; }