# **************************************************************************** # CUI # # The Advanced Framework for Simulation, Integration, and Modeling (AFSIM) # # The use, dissemination or disclosure of data in this file is subject to # limitation or restriction. See accompanying README and LICENSE for details. # **************************************************************************** behavior go_home script_debug_writes off script_variables bool mDrawRoute = false; // draw the home route WsfDraw mDraw = WsfDraw(); bool mCheckFuel = true; // check fuel levels bool mCheckMyWeapons = true; // check the remaining quanitity of munitions on this platform bool mCheckAllWeapons = false; // check the remaining quantity of munitions on all platforms in the peer group, including my own bool mCheckUplinks = false; // check if uplinks are still existent bool mWaitOnActiveWeapons = false; // don't go home as long as active weapons are being controlled string mMainWeapon = ""; // main weapon of concern, not necessarily this platform's main weapon bool mCheckEscorts = false; // check if escort platforms are still existent and on course Array mEscortNames = Array(); // the names of platforms this platform is responsible for escorting double cBINGO_SPEED = 516 * MATH.MPS_PER_NMPH(); // ~M0.8 or 248 m/s @ 25 kft#removed 1.5 * that was added to help 6dof movers 14Oct11 WsfGeoPoint mFirstKnownPoint = WsfGeoPoint(); string mRouteName = ""; int mRouteHomeIndex = 0; // the index of the waypoint on the default route the platform should return to string mLastComment = ""; end_script_variables script bool HasEscorts() WsfPlatform escortPlatform; foreach ( string sEscortName in mEscortNames ) { escortPlatform = WsfSimulation.FindPlatform(sEscortName); if (escortPlatform.IsValid() ) { return true; } } return false; end_script script double NumWeaponsRemaining(WsfPlatform aPlatform) double total = 0.0; for (int i=0; i 0) { msg = ""; result = false; } } else if (NumWeaponsRemaining(sub) > 0.0) { msg = ""; result = false; } } } // go home if my weapons are out of ammo else if (mCheckMyWeapons == true) { if (mMainWeapon != "") { WsfWeapon temp = PLATFORM.Weapon(mMainWeapon); if (temp.IsValid() && temp.QuantityRemaining() <= 0) { msg = "GO HOME: main weapon out of ammo"; result = true; } } else if (NumWeaponsRemaining(PLATFORM) <= 0.0) { msg = "GO HOME: out of weapons"; result = true; } } // debug - why is this platform going home? if (result) { writeln_d(" T=", TIME_NOW, " ", PLATFORM.Name(), " ", msg); if (msg != mLastComment) { PLATFORM.Comment(msg); mLastComment = msg; } return true; } return false; end_precondition execute writeln_d(PLATFORM.Name(), " executing go_home, T=", TIME_NOW); //PLATFORM.Comment("go_home"); string msg = ""; WsfRIPRProcessor commander = ((WsfRIPRProcessor)PROCESSOR).CommanderProcessor(); if (commander.IsValid()) { for (int i = 0; i < ((WsfRIPRProcessor)PROCESSOR).NumJobChannels(); i = i + 1) { commander.ClearBidsFor(((WsfRIPRProcessor)PROCESSOR), i); } } // make sure we are at the right speed so we don't burn the fuel we have left too fast PLATFORM.GoToSpeed(cBINGO_SPEED); writeln_d(" GoToSpeed( ", cBINGO_SPEED," )"); bool onHomeRoute = false; // if an egress route is defined, and that is the current route, // find the closest waypoint and fly the route from there. // this is mainly used to correct some bugs in the 6dof mover if (mRouteName != "") { WsfRoute myRoute = PLATFORM.Route(); if(myRoute.Name() == "home_route") { int routeIndex = PLATFORM.RoutePointIndex(); if (routeIndex < 0 || routeIndex >= myRoute.Size()) { routeIndex = 0; } double distThreshold = 4.0*185.2; ## 4/10th nm if (myRoute.Waypoint(routeIndex).Location().GroundRangeTo(PLATFORM.Location()) < distThreshold) { routeIndex = routeIndex + 1; if (routeIndex >= myRoute.Size()) { routeIndex = 1; } } onHomeRoute = PLATFORM.FollowRoute(myRoute, routeIndex); #string msg = write_str("FollowRoute(home_route, ", routeIndex, ")"); #PLATFORM.Comment(msg); } // if there is an egress route defined, follow it if (!onHomeRoute) { msg = write_str("attempting to construct and fly route: ", mRouteName); //PLATFORM.Comment(msg); writeln_d(" T=", TIME_NOW, " ", PLATFORM.Name(), " ", msg); WsfRoute original = PLATFORM.Route(); WsfRoute homeRoute = WsfRoute.Create("home_route"); WsfRoute capRoute = WsfRoute.CopyGlobal(mRouteName); double goHomeSpeed = cBINGO_SPEED; #if (capRoute.Front().IsValid() && capRoute.Front().Speed() > 0) #{ # goHomeSpeed = capRoute.Front().Speed(); #} extern double cDEFAULT_ALTITUDE; WsfGeoPoint startPoint = WsfGeoPoint.Construct(mFirstKnownPoint.Latitude(), mFirstKnownPoint.Longitude(), cDEFAULT_ALTITUDE); homeRoute.Append(startPoint, goHomeSpeed); capRoute.Transform(startPoint.Latitude(), startPoint.Longitude(), 0); homeRoute.Append(capRoute); onHomeRoute = PLATFORM.FollowRoute(homeRoute); #PLATFORM.Comment("go_home FollowRoute(homeRoute)"); } } // if the platform is still not on an egress route, then there is not one // defined or there was a problem with it, so one needs to be created. if (!onHomeRoute) { if (PLATFORM.FollowRoute("DEFAULT_ROUTE", mRouteHomeIndex)) { msg = write_str("should be flying default route"); //PLATFORM.Comment(msg); writeln_d(" T=", TIME_NOW, " ", PLATFORM.Name(), " ", msg); //PLATFORM.Comment("FollowRoute(DEFAULT_ROUTE, 1)"); } else // what if no default route is provided? (fly to first known point) { #extern double cDEFAULT_ALTITUDE; WsfGeoPoint tempPt = WsfGeoPoint.Construct(mFirstKnownPoint.Latitude(), mFirstKnownPoint.Longitude(), cDEFAULT_ALTITUDE); PLATFORM.GoToLocation(tempPt); msg = write_str("should be flying to point: ", mFirstKnownPoint.ToString()); //PLATFORM.Comment(msg); writeln_d(" T=", TIME_NOW, " ", PLATFORM.Name(), " ", msg); //PLATFORM.Comment("GoToLocation(tempPt)"); } } // debug if (mDrawRoute) { DrawRoute(); } end_execute end_behavior