[Gcblue-commits] gcb_wx/src/sim tcFlightPort.cpp, 1.27, 1.28 tcPlatformObject.cpp, 1.63, 1.64
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-09-28 02:01:57
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv32752/src/sim Modified Files: tcFlightPort.cpp tcPlatformObject.cpp Log Message: Initial airbase automation work Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** tcPlatformObject.cpp 5 Sep 2006 01:04:25 -0000 1.63 --- tcPlatformObject.cpp 28 Sep 2006 02:01:53 -0000 1.64 *************** *** 30,33 **** --- 30,34 ---- #include "tcLauncherDBObject.h" #include "tcStoresDBObject.h" + #include "tcWeaponDBObject.h" #include "tcString.h" #include "tcRadar.h" *************** *** 545,548 **** --- 546,726 ---- } + /** + * @return true if either currently equipped for target type or + * parent magazines have compatible weapons in stock for target type + */ + bool tcPlatformObject::IsCapableVsTargetType(int targetFlag) + { + if (IsEquippedForTargetType(targetFlag)) return true; + + tcPlatformObject* parentPlatform = dynamic_cast<tcPlatformObject*>(parent); + if (parentPlatform == 0) return false; // not landed or docked, or parent is not tcPlatformObject + + size_t nMagazines = parentPlatform->GetMagazineCount(); + for (size_t n=0; n<nMagazines; n++) + { + tcStores* mag = parentPlatform->GetMagazine(n); + int magFlags = mag->GetAvailableTargetFlags(this); + if ((magFlags & targetFlag) != 0) return true; + } + + return false; + } + + + /** + * @return true if all launchers empty and not loading + */ + bool tcPlatformObject::AllLaunchersEmpty() + { + size_t nLaunchers = GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = GetLauncher(n); + if ((launcher->IsLoading()) || (launcher->mnCurrent > 0)) return false; + } + + return true; + } + + /** + * @return true if fully equipped, done loading, and at least one + * launcher is effective vs. target type + */ + bool tcPlatformObject::IsEquippedForTargetType(int targetFlag) + { + if (targetFlag == 0) return false; // don't call this to check empty + + bool anyEffective = false; + + size_t nLaunchers = GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = GetLauncher(n); + if (launcher->IsLoading()) return false; + if ((launcher->mnCurrent == 0) || (launcher->capacity > launcher->mnCurrent)) return false; + anyEffective = anyEffective || ((launcher->mnTargetFlags & targetFlag) != 0); + } + + return anyEffective; + } + + void tcPlatformObject::UnloadAllLaunchers() + { + tcPlatformObject* parentPlatform = dynamic_cast<tcPlatformObject*>(parent); + if (parentPlatform == 0) + { + fprintf(stderr, "tcPlatformObject::UnloadAllLaunchers - no host platform (%s)\n", + GetName()); + wxASSERT(false); + return; // not landed or docked, or parent is not tcPlatformObject + } + + size_t nMagazines = parentPlatform->GetMagazineCount(); + for (size_t n=0; n<nMagazines; n++) + { + tcStores* mag = parentPlatform->GetMagazine(n); + if (mag->HasStoresForThisObject(this)) // stores empty can cause problem with this + { + mag->AddAutomationOp("Empty", this); + return; + } + } + + fprintf(stderr, "tcPlatformObject::EquipForTargetType('empty') - no mags available (%s)\n", + GetName()); + wxASSERT(false); + } + + /** + * @param targetType "Empty" "AAW" "ASuW" "ASW" "Strike" + */ + void tcPlatformObject::EquipForTargetType(const std::string& targetType) + { + if (targetType == "Empty") + { + UnloadAllLaunchers(); + return; + } + + tcPlatformObject* parentPlatform = dynamic_cast<tcPlatformObject*>(parent); + if (parentPlatform == 0) + { + fprintf(stderr, "tcPlatformObject::EquipForTargetType - no host platform (%s)\n", + GetName()); + wxASSERT(false); + return; // not landed or docked, or parent is not tcPlatformObject + } + + int targetFlag = 0; + if (targetType == "AAW") targetFlag = AIR_TARGET; + else if (targetType == "ASuW") targetFlag = SURFACE_TARGET; + else if (targetType == "ASW") targetFlag = SUBSURFACE_TARGET; + else if (targetType == "Strike") targetFlag = LAND_TARGET; + else + { + fprintf(stderr, "tcPlatformObject::EquipForTargetType - targetType not found (%s)\n", + GetName()); + wxASSERT(false); + return; + } + + size_t nMagazines = parentPlatform->GetMagazineCount(); + for (size_t n=0; n<nMagazines; n++) + { + tcStores* mag = parentPlatform->GetMagazine(n); + int magFlags = mag->GetAvailableTargetFlags(this); + if ((magFlags & targetFlag) != 0) + { + mag->AddAutomationOp(targetType, this); + return; + } + } + + fprintf(stdout, "tcPlatformObject::EquipForTargetType - no compatible equipment found (%s)\n", + GetName()); + } + + /** + * Schedule automatic loadout op for target type. Platform must be + * landed and have access to appropriate stores + */ + void tcPlatformObject::EquipForTargetType(int targetFlag) + { + if ((targetFlag != 0) && (IsEquippedForTargetType(targetFlag))) return; // already equipped + + std::string loadoutType; + if (targetFlag == 0) + { + loadoutType = "Empty"; + } + else if ((targetFlag & AIR_TARGET) != 0) + { + loadoutType = "AAW"; + } + else if ((targetFlag & SURFACE_TARGET) != 0) + { + loadoutType = "ASuW"; + } + else if ((targetFlag & SUBSURFACE_TARGET) != 0) + { + loadoutType = "ASW"; + } + else if ((targetFlag & LAND_TARGET) != 0) + { + loadoutType = "Strike"; + } + else + { + fprintf(stderr, "tcPlatformObject::EquipForTargetType - bad target flag (%s)\n", + GetName()); + wxASSERT(false); // bad targetFlag + return; + } + + EquipForTargetType(loadoutType); + } + + bool tcPlatformObject::IsRefueling() const { Index: tcFlightPort.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcFlightPort.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** tcFlightPort.cpp 18 Jun 2006 00:45:02 -0000 1.27 --- tcFlightPort.cpp 28 Sep 2006 02:01:53 -0000 1.28 *************** *** 38,41 **** --- 38,42 ---- #include "tcPlatformObject.h" #include "tcLauncher.h" + #include "ai/tcMissionManager.h" #ifdef _DEBUG *************** *** 57,61 **** case READY: return "Deck"; case LAUNCH: return "Runwy"; ! case TRANSIT: return "Trans"; default: return "Error"; } --- 58,62 ---- case READY: return "Deck"; case LAUNCH: return "Runwy"; ! case TAKEOFF: return "Tkoff"; default: return "Error"; } *************** *** 438,441 **** --- 439,443 ---- airstate->goal_location = loc; airstate->goal_spot = airstate->current_spot; + airstate->inTransit = false; units.push_back(airstate); // add to fport units vector *************** *** 546,549 **** --- 548,557 ---- last_update_time = 0; + + if (missionManager == 0) + { + delete missionManager; + missionManager = 0; + } } *************** *** 585,589 **** loc_vector = GetLocVector(loc); if (loc == HANGAR) return (inHangarCount >= hangarCapacity) ? -1 : 0; ! if ((loc == TRANSIT)||(loc == NOWHERE)) return -1; // error return FindEmptySpot(loc_vector); --- 593,597 ---- loc_vector = GetLocVector(loc); if (loc == HANGAR) return (inHangarCount >= hangarCapacity) ? -1 : 0; ! if ((loc == TAKEOFF)||(loc == NOWHERE)) return -1; // error return FindEmptySpot(loc_vector); *************** *** 612,615 **** --- 620,628 ---- } + const tcAirState* tcFlightPort::GetAirState(unsigned n) const + { + return units[n]; + } + int tcFlightPort::GetAirStateIdx(long id) { *************** *** 638,641 **** --- 651,674 ---- } + /** + * @return game object for unit with matching id + */ + tcGameObject* tcFlightPort::GetObjectById(long id) + { + int idx = GetAirStateIdx(id); + if (idx < 0) return 0; + return GetObject(unsigned(idx)); + } + + tcMissionManager* tcFlightPort::GetMissionManager() + { + if (missionManager == 0) + { + missionManager = new tcMissionManager(this); + } + + return missionManager; + } + int tcFlightPort::Launch(int runway) { *************** *** 688,692 **** (spot->obj_info->obj->mnID == id)) { ! bool isReady = (spot->obj_info->ready_time >= last_update_time); if (isReady) { --- 721,725 ---- (spot->obj_info->obj->mnID == id)) { ! bool isReady = (spot->obj_info->ready_time <= last_update_time); if (isReady) { *************** *** 700,704 **** } } ! return 0; // not found on runway } --- 733,755 ---- } } ! ! // if not on runway, then queue for takeoff by moving to TAKEOFF destination ! ! int idx = GetAirStateIdx(id); ! if (idx >= 0) ! { ! tcAirState* airState = GetAirState(idx); ! if (airState != 0) ! { ! SetObjectDestination(airState, TAKEOFF, 0); ! return 1; ! } ! } ! ! ! fprintf(stderr, "tcFlightPort::LaunchID - Bad air state\n"); ! wxASSERT(false); ! return 0; ! } *************** *** 706,719 **** * Move object to new location if valid. Remove object from old location. */ ! void tcFlightPort::MoveObjectToGoal(tcAirState *airstate) { ! if (airstate->goal_spot == -1) return; // no valid goal spot yet ! if (airstate->current_location == airstate->goal_location) return; // no need to move (may need spot move in future) ! if (airstate->current_location == TRANSIT) return; // already moving, error ! if (airstate->goal_location == HANGAR) inHangarCount++; std::vector<tsSpotInfo>* current_loc_vect = GetLocVector(airstate->current_location); ! std::vector<tsSpotInfo>* goal_loc_vect = GetLocVector(airstate->goal_location); if (current_loc_vect) --- 757,771 ---- * Move object to new location if valid. Remove object from old location. */ ! void tcFlightPort::MoveObjectToDestination(tcAirState *airstate, teLocation destination, int spot) { ! if (spot == -1) return; // no valid goal spot yet ! if (airstate->current_location == destination) return; // no need to move (may need spot move in future) ! if (airstate->inTransit) return; // already moving, error ! wxASSERT(destination != TAKEOFF); ! if (destination == HANGAR) inHangarCount++; std::vector<tsSpotInfo>* current_loc_vect = GetLocVector(airstate->current_location); ! std::vector<tsSpotInfo>* dest_loc_vect = GetLocVector(destination); if (current_loc_vect) *************** *** 722,733 **** current_spot.obj_info = NULL; // remove from current spot } ! if (goal_loc_vect) { ! tsSpotInfo& goal_spot = goal_loc_vect->at(airstate->goal_spot); ! goal_spot.obj_info = airstate; // add to goal spot } ! airstate->current_location = TRANSIT; ! airstate->current_spot = -1; airstate->op = OP_TRANSIT; } --- 774,788 ---- current_spot.obj_info = NULL; // remove from current spot } ! if (dest_loc_vect) { ! tsSpotInfo& dest_spot = dest_loc_vect->at(spot); ! dest_spot.obj_info = airstate; // add to dest spot } ! airstate->current_location = destination; ! airstate->current_spot = spot; ! ! airstate->inTransit = true; ! airstate->op = OP_TRANSIT; } *************** *** 881,885 **** std::vector<tsSpotInfo>* loc_vector = GetLocVector(loc); ! if ((loc == TRANSIT)||(loc == NOWHERE)) { wxASSERT(false); --- 936,940 ---- std::vector<tsSpotInfo>* loc_vector = GetLocVector(loc); ! if ((loc == TAKEOFF)||(loc == NOWHERE)) { wxASSERT(false); *************** *** 937,943 **** --- 992,1011 ---- tcAirState* airstate = units.at(n); + SetObjectDestination(airstate, loc, position); + } + + /** + * + */ + void tcFlightPort::SetObjectDestination(tcAirState* airstate, teLocation loc, unsigned int position) + { + wxASSERT(airstate != 0); + teLocation currentLoc = airstate->current_location; bool validMove = false; + validMove = (currentLoc != loc); + + /* if (loc == HANGAR) { *************** *** 954,957 **** --- 1022,1026 ---- } + */ if (!validMove) return; *************** *** 970,977 **** } void tcFlightPort::UpdateRelPos(tcAirState *airstate, double time) { // tcGameObject *pGameObj = airstate->obj; ! if (airstate->current_location == TRANSIT) { if (time >= airstate->ready_time) --- 1039,1047 ---- } + void tcFlightPort::UpdateRelPos(tcAirState *airstate, double time) { // tcGameObject *pGameObj = airstate->obj; ! if (airstate->inTransit) { if (time >= airstate->ready_time) *************** *** 979,985 **** if (airstate->current_location == HANGAR) inHangarCount--; if (airstate->goal_location == HANGAR) inHangarCount++; ! airstate->current_location = airstate->goal_location; ! airstate->current_spot = airstate->goal_spot; airstate->op = OP_NONE; wxASSERT(inHangarCount <= hangarCapacity); --- 1049,1056 ---- if (airstate->current_location == HANGAR) inHangarCount--; if (airstate->goal_location == HANGAR) inHangarCount++; ! airstate->op = OP_NONE; + airstate->inTransit = false; + wxASSERT(inHangarCount <= hangarCapacity); *************** *** 1050,1059 **** /** * */ ! void tcFlightPort::Update(double afStatusTime) { ! if ((afStatusTime - last_update_time < 0.1f) && !tcGameObject::IsEditMode()) return; // restrict to slower update ! last_update_time = afStatusTime; // in mp client mode, update relative pos for display purposes, omit other updates --- 1121,1160 ---- /** + * @return next location if jumping more than one stage + * e.g. HANGAR to LAUNCH would stop at READY first + */ + teLocation tcFlightPort::GetNextStop(teLocation current, teLocation destination) + { + if (destination == HANGAR) return HANGAR; + else if (destination == READY) return READY; + else if (destination == LAUNCH) + { + return (current == HANGAR) ? READY : LAUNCH; + } + else if (destination == TAKEOFF) + { + switch (current) + { + case HANGAR: return READY; break; + case READY: return LAUNCH; break; + case LAUNCH: return TAKEOFF; break; + default: wxASSERT(false); return current; break; + } + } + else + { + wxASSERT(false); + return current; + } + + } + + /** * */ ! void tcFlightPort::Update(double t) { ! if ((t - last_update_time < 0.1f) && !tcGameObject::IsEditMode()) return; // restrict to slower update ! last_update_time = t; // in mp client mode, update relative pos for display purposes, omit other updates *************** *** 1063,1067 **** for(size_t n=0;n<obj_count;n++) { ! UpdateRelPos(units[n], afStatusTime); } return; --- 1164,1168 ---- for(size_t n=0;n<obj_count;n++) { ! UpdateRelPos(units[n], t); } return; *************** *** 1070,1073 **** --- 1171,1176 ---- UpdateLanded(); + std::vector<long> idsToLaunch; // queue to launch when done updating all airstates + size_t obj_count = units.size(); for(size_t n=0;n<obj_count;n++) *************** *** 1078,1095 **** ** check for a free spot in goal location. If there is a free spot in ** goal location, then take spot and set current location to TRANSIT */ ! bool inTransit = airstate->current_location == TRANSIT; if ((!inTransit)&&(airstate->current_location != airstate->goal_location)) { ! if (!IsSpotEmpty(airstate->goal_location, airstate->goal_spot)) { ! std::vector<tsSpotInfo> *loc_vector = 0; ! int spot_idx = FindEmptySpot(airstate->goal_location, loc_vector); ! airstate->goal_spot = spot_idx; } - airstate->ready_time = tcGameObject::IsEditMode() ? afStatusTime : afStatusTime + 30.0f; // short times for test - MoveObjectToGoal(airstate); } ! UpdateRelPos(airstate, afStatusTime); } } --- 1181,1217 ---- ** check for a free spot in goal location. If there is a free spot in ** goal location, then take spot and set current location to TRANSIT */ ! bool inTransit = airstate->inTransit; if ((!inTransit)&&(airstate->current_location != airstate->goal_location)) { ! if ((airstate->goal_location == TAKEOFF) && (airstate->current_location == LAUNCH)) { ! idsToLaunch.push_back(airstate->obj->mnID); ! } ! else ! { ! teLocation nextLoc = GetNextStop(airstate->current_location, airstate->goal_location); ! int nextSpot = airstate->goal_spot; // guess goal_spot ! ! // goal_spot has spot for next destination if more than one move is required ! if (!IsSpotEmpty(nextLoc, nextSpot)) ! { ! std::vector<tsSpotInfo> *loc_vector = 0; ! int spot_idx = FindEmptySpot(nextLoc, loc_vector); ! nextSpot = spot_idx; ! } ! airstate->ready_time = tcGameObject::IsEditMode() ? t : t + 30.0f; // short times for test ! ! MoveObjectToDestination(airstate, nextLoc, nextSpot); } } ! UpdateRelPos(airstate, t); } + + for (size_t n=0; n<idsToLaunch.size(); n++) + { + LaunchID(idsToLaunch[n]); + } + + if (missionManager != 0) missionManager->Update(t); } *************** *** 1118,1122 **** : localId(10), parent(0), ! mpDBObject(0) { --- 1240,1245 ---- : localId(10), parent(0), ! mpDBObject(0), ! missionManager(0) { |