[Gcblue-commits] gcb_wx/src/sim tcCarrierObject.cpp, 1.16, 1.17 tcFlightOpsObject.cpp, 1.16, 1.17 t
Status: Alpha
Brought to you by:
ddcforge
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv3929/src/sim Modified Files: tcCarrierObject.cpp tcFlightOpsObject.cpp tcFlightPort.cpp tcHeloObject.cpp tcObjectControl.cpp tcSonar.cpp tcSubObject.cpp Log Message: Index: tcHeloObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcHeloObject.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tcHeloObject.cpp 20 Nov 2006 00:17:44 -0000 1.10 --- tcHeloObject.cpp 27 Nov 2006 00:46:40 -0000 1.11 *************** *** 28,31 **** --- 28,33 ---- #include "tcHeloObject.h" #include "tcAirDBObject.h" + #include "tcSonarDBObject.h" + #include "tcSonar.h" #ifdef _DEBUG *************** *** 41,44 **** --- 43,89 ---- } + + /** + * @returns altitude of dipping sonar if dipping sonar active, 999.9 m otherwise + */ + float tcHeloObject::GetDippingSonarAlt() const + { + const float NOT_APPLICABLE = 999.9f; + if (!IsEnsonifying()) return NOT_APPLICABLE; + + const tcSonar* sonar = GetStrongestActiveSonar(); + + if (sonar != 0) + { + return mcKin.mfAlt_m - sonar->GetScope(); + } + else + { + return NOT_APPLICABLE; + } + } + + + /** + * @returns max active sonar source level (dipping sonar) + */ + float tcHeloObject::GetSonarSourceLevel() const + { + const float NOT_APPLICABLE = -999.9f; + + if (!IsEnsonifying()) return NOT_APPLICABLE; + + const tcSonar* sonar = GetStrongestActiveSonar(); + if (sonar != 0) + { + return sonar->mpDBObj->SL; + } + else + { + return NOT_APPLICABLE; + } + } + + void tcHeloObject::RandInitNear(float afLon_deg, float afLat_deg) { Index: tcFlightPort.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcFlightPort.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** tcFlightPort.cpp 20 Nov 2006 00:17:44 -0000 1.30 --- tcFlightPort.cpp 27 Nov 2006 00:46:40 -0000 1.31 *************** *** 40,43 **** --- 40,44 ---- #include "tcLauncher.h" #include "ai/tcMissionManager.h" + #include "tcTime.h" #ifdef _DEBUG *************** *** 113,141 **** ready_time = x; ! // if this obj is in a ready spot, then update launcher and fuel state ! if (current_location == READY) ! { ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->operator<<(stream); ! unsigned char isLoading; ! stream >> isLoading; ! launcher->SetLoadState(isLoading != 0); ! } ! float fuel; ! stream >> fuel; ! platform->fuel_kg = fuel; ! char isRefueling; ! stream >> isRefueling; ! platform->SetRefueling(isRefueling != 0); ! } } ! return stream; --- 114,143 ---- ready_time = x; ! // if this obj is in a ready or launch spot, then update launcher and fuel state ! if (current_location != HANGAR) ! { ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->operator<<(stream); ! unsigned char isLoading; ! stream >> isLoading; ! launcher->SetLoadState(isLoading != 0); ! } ! float fuel; ! stream >> fuel; ! platform->fuel_kg = fuel; ! char isRefueling; ! stream >> isRefueling; ! platform->SetRefueling(isRefueling != 0); ! } } ! ! return stream; *************** *** 167,193 **** stream << x; ! // if this obj is in a ready spot, then update launcher and fuel state ! if (current_location == READY) ! { ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->operator>>(stream); ! // additional info that we don't want part of the normal launcher update (could use detail level instead) ! unsigned char isLoading = launcher->IsLoading() ? 1 : 0; ! stream << isLoading; ! } ! float fuel = platform->fuel_kg; ! stream << fuel; - char isRefueling = platform->IsRefueling() ? 1 : 0; - stream << isRefueling; - platform->SetRefueling(isRefueling != 0); - } - } return stream; --- 169,195 ---- stream << x; ! if (current_location != HANGAR) ! { ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->operator>>(stream); ! // additional info that we don't want part of the normal launcher update (could use detail level instead) ! unsigned char isLoading = launcher->IsLoading() ? 1 : 0; ! stream << isLoading; ! } ! float fuel = platform->fuel_kg; ! stream << fuel; ! ! char isRefueling = platform->IsRefueling() ? 1 : 0; ! stream << isRefueling; ! platform->SetRefueling(isRefueling != 0); ! } ! } return stream; *************** *** 204,219 **** static tcAirState tempAirState; ! stream >> inHangarCount; unsigned short nChildren = GetCount(); ! unsigned short nUpdate; stream >> nUpdate; - if (nUpdate == 0) - { - if (nChildren > 0) Clear(); - return stream; - } unsigned short updateIdx = 0; --- 206,216 ---- static tcAirState tempAirState; ! unsigned int updateTimestamp = tcTime::Get()->GetUpdated30HzCount(); unsigned short nChildren = GetCount(); ! unsigned char nUpdate; stream >> nUpdate; unsigned short updateIdx = 0; *************** *** 238,253 **** { *airState << stream; foundMatch = true; nUpdated++; } - else // assume this child has been deleted - { - //parent->RemoveChild(airState->obj); - //delete airState->obj; - //airState->obj = 0; - } childIdx++; } updateIdx++; } --- 235,251 ---- { *airState << stream; + airState->lastMultiplayerUpdate = updateTimestamp; + foundMatch = true; nUpdated++; } childIdx++; } + if (!foundMatch) + { + parent->SetRecreate(true); // request re-create + } + updateIdx++; } *************** *** 266,273 **** ** and delete children vs. re-creating all of the children. */ ! if ((nUpdated < nUpdate) || (nUpdated < nChildren)) ! { ! parent->SetRecreate(true); ! } /* --- 264,271 ---- ** and delete children vs. re-creating all of the children. */ ! //if ((nUpdated < nUpdate) || (nUpdated < nChildren)) ! //{ ! // parent->SetRecreate(true); ! //} /* *************** *** 291,314 **** /** * Saves state to update stream */ tcUpdateStream& tcFlightPort::operator>>(tcUpdateStream& stream) { ! stream << inHangarCount; ! ! unsigned short nChildren = GetCount(); ! ! stream << nChildren; ! for (unsigned short k=0; k<nChildren; k++) { ! tcAirState* airState = GetAirState(k); tcGameObject* obj = airState->obj; wxASSERT(obj); short int localId = (short int)obj->mnID; ! stream << localId; - *airState >> stream; - } return stream; --- 289,352 ---- /** * Saves state to update stream + * Do partial update if stream size limit is reached */ tcUpdateStream& tcFlightPort::operator>>(tcUpdateStream& stream) { ! long freeSpace = stream.GetMaxSize() - stream.size() - 1; // 1 byte for update count header ! // if freeSpace < 0, the message should be rejected anyway so don't worry about special case ! // for this ! ! tcUpdateStream tempStream1; ! tcUpdateStream tempStream2; ! ! unsigned short nChildren = GetCount(); ! if (nextUpdateIdx >= nChildren) nextUpdateIdx = 0; ! ! unsigned char nUpdates = 0; ! ! //stream << nChildren; ! ! while ((nextUpdateIdx < nChildren) && (freeSpace > 0)) { ! tempStream1.clear(); ! ! tcAirState* airState = GetAirState(nextUpdateIdx); tcGameObject* obj = airState->obj; wxASSERT(obj); short int localId = (short int)obj->mnID; ! tempStream1 << localId; ! ! *airState >> tempStream1; ! ! if ((long)tempStream1.size() <= freeSpace) ! { ! tempStream2 << tempStream1; ! freeSpace -= tempStream1.size(); ! nextUpdateIdx++; ! nUpdates++; ! } ! else ! { ! freeSpace = 0; ! } ! ! } ! ! stream << nUpdates; ! stream << tempStream2; ! ! if (nextUpdateIdx >= nChildren) ! { ! nextUpdateIdx = 0; ! stream.SetDoneFlag(true); ! } ! else ! { ! stream.SetDoneFlag(false); ! } ! return stream; *************** *** 441,444 **** --- 479,483 ---- airstate->goal_spot = airstate->current_spot; airstate->inTransit = false; + airstate->lastMultiplayerUpdate = tcTime::Get()->GetUpdated30HzCount(); units.push_back(airstate); // add to fport units vector *************** *** 555,558 **** --- 594,599 ---- missionManager = 0; } + + nextUpdateIdx = 0; } *************** *** 770,775 **** ! fprintf(stderr, "tcFlightPort::LaunchID - Bad air state\n"); ! wxASSERT(false); return 0; --- 811,816 ---- ! fprintf(stderr, "tcFlightPort::LaunchID - Bad air state (id:%d)\n", id); ! //wxASSERT(false); return 0; *************** *** 829,832 **** --- 870,917 ---- /** + * For multiplayer client + */ + void tcFlightPort::RemoveStaleUnits() + { + unsigned int t = tcTime::Get()->GetUpdated30HzCount(); + + + int minTimeLag = 999; + int maxTimeLag = 0; + + size_t nUnits = units.size(); + for (size_t n=0; n<nUnits; n++) + { + int lag = t - units[n]->lastMultiplayerUpdate; + if (lag < minTimeLag) minTimeLag = lag; + else if (lag > maxTimeLag) maxTimeLag = lag; + } + + // remove units with lastMultiplayerUpdate more than 3 seconds + // older than latest update + int lagThresh = minTimeLag + 90; + std::vector<tcAirState*> temp; + + for (size_t n=0; n<nUnits; n++) + { + int lag = t - units[n]->lastMultiplayerUpdate; + if (lag <= lagThresh) + { + temp.push_back(units[n]); + } + else + { + parent->RemoveChild(units[n]->obj); + delete(units[n]->obj); + delete units[n]; + } + } + + units = temp; + + ResyncSpots(); + } + + /** * @return pointer to tsSpotInfo for current location and spot. */ *************** *** 1007,1014 **** } for (size_t n=0; n<units.size(); n++) { tcAirState* airstate = units[n]; ! if (airstate->current_location == READY) { if ((airstate->current_spot >= 0) && ((unsigned)airstate->current_spot < ready_spots.size())) --- 1092,1105 ---- } + inHangarCount = 0; + for (size_t n=0; n<units.size(); n++) { tcAirState* airstate = units[n]; ! if (airstate->current_location == HANGAR) ! { ! inHangarCount++; ! } ! else if (airstate->current_location == READY) { if ((airstate->current_spot >= 0) && ((unsigned)airstate->current_spot < ready_spots.size())) *************** *** 1204,1211 **** --- 1295,1305 ---- if (parent->IsClientMode()) { + RemoveStaleUnits(); + size_t obj_count = units.size(); for(size_t n=0;n<obj_count;n++) { UpdateRelPos(units[n], t); + units[n]->inTransit = (units[n]->goal_location != units[n]->current_location); } return; *************** *** 1284,1288 **** parent(0), mpDBObject(0), ! missionManager(0) { --- 1378,1383 ---- parent(0), mpDBObject(0), ! missionManager(0), ! nextUpdateIdx(0) { Index: tcObjectControl.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcObjectControl.cpp,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** tcObjectControl.cpp 23 Nov 2006 00:07:33 -0000 1.54 --- tcObjectControl.cpp 27 Nov 2006 00:46:40 -0000 1.55 *************** *** 2,6 **** ** @file tcObjectControl.cpp */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@gc...) ** All rights reserved. --- 2,6 ---- ** @file tcObjectControl.cpp */ ! /* Copyright (C) 2003-2006 Dewitt Colclough (de...@gc...) ** All rights reserved. *************** *** 31,34 **** --- 31,35 ---- #include "ai/Brain.h" + #include "ai/Nav.h" #include "tcAeroAirObject.h" #include "ai/tcAIData.h" *************** *** 862,866 **** if (sub->IsSnorkeling()) { ! fuelText = fuelText.Format("FUEL: %.1f%% BATT: %.1f%% (Snorkeling)", fuelFraction * 100.0f, batteryFraction * 100.0f); } --- 863,867 ---- if (sub->IsSnorkeling()) { ! fuelText = fuelText.Format("FUEL: %.1f%% BATT: %.1f%% (Diesels active)", fuelFraction * 100.0f, batteryFraction * 100.0f); } *************** *** 1523,1526 **** --- 1524,1534 ---- plat->SetHeading(msHOI.mfMouseHeading_rad); msHOI.mbMouseOver = false; + ai::Brain* brain = plat->GetBrain(); + ai::Nav* nav = (brain != 0) ? brain->GetNavTask() : 0; + if (nav != 0) + { + nav->ClearWaypoints(); + nav->EndTask(); + } } } Index: tcSubObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSubObject.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** tcSubObject.cpp 20 Nov 2006 00:17:45 -0000 1.19 --- tcSubObject.cpp 27 Nov 2006 00:46:40 -0000 1.20 *************** *** 274,278 **** bool tcSubObject::IsSurfaced() const { ! return mcKin.mfAlt_m == 0; } --- 274,278 ---- bool tcSubObject::IsSurfaced() const { ! return mcKin.mfAlt_m >= 0; } *************** *** 356,360 **** else if (mcKin.mfAlt_m <= 0) // restrict speed near surface { ! float maxSpeed = (0.5f - 0.5f*invPeriscopeDepth*mcKin.mfAlt_m) * mpDBObject->mfMaxSpeed_kts; if (mcKin.mfSpeed_kts > maxSpeed) --- 356,360 ---- else if (mcKin.mfAlt_m <= 0) // restrict speed near surface { ! float maxSpeed = (0.75f - 0.25f*invPeriscopeDepth*mcKin.mfAlt_m) * mpDBObject->mfMaxSpeed_kts; if (mcKin.mfSpeed_kts > maxSpeed) *************** *** 366,369 **** --- 366,370 ---- { mcKin.mfAlt_m = 0; // subs can't fly + mcKin.mfClimbAngle_rad = 0; } } *************** *** 400,404 **** mcKin.mfPitch_rad = 0; mcKin.mfAlt_m += dalt_m; ! return; } --- 401,409 ---- mcKin.mfPitch_rad = 0; mcKin.mfAlt_m += dalt_m; ! ! if (dalt_m == 0) ! { ! return; ! } } *************** *** 442,445 **** --- 447,461 ---- mcKin.mfAlt_m += dz; } + + // automatically raise/lower radar mast and scope + bool isScopeDepth = IsAtPeriscopeDepth(); + SetRadarMastState(isScopeDepth); + SetPeriscopeState(isScopeDepth); + + if (IsSurfaced()) + { + SetSnorkelState(true); + } + } Index: tcFlightOpsObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcFlightOpsObject.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tcFlightOpsObject.cpp 20 Nov 2006 00:17:44 -0000 1.16 --- tcFlightOpsObject.cpp 27 Nov 2006 00:46:40 -0000 1.17 *************** *** 70,78 **** tcCreateStream& tcFlightOpsObject::operator<<(tcCreateStream& stream) { ! unsigned short nChildren; stream >> nChildren; - flight_deck.Clear(); - for (unsigned short k=0; k < nChildren; k++) { --- 70,76 ---- tcCreateStream& tcFlightOpsObject::operator<<(tcCreateStream& stream) { ! unsigned char nChildren; stream >> nChildren; for (unsigned short k=0; k < nChildren; k++) { *************** *** 94,110 **** stream >> pos; ! tcGameObject* child = AddChildToFlightDeck(databaseObj, unitName, teLocation(loc), pos); ! child->mnID = long(localId); // override default localId assigned by flightport // load launcher create from stream ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(child)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->operator<<(stream); ! } ! } } --- 92,124 ---- stream >> pos; ! int idx = flight_deck.GetAirStateIdx(localId); ! if (idx == -1) ! { ! tcGameObject* child = AddChildToFlightDeck(databaseObj, unitName, teLocation(loc), pos); ! child->mnID = long(localId); // override default localId assigned by flightport ! ! // initialize launchers to empty, since this info isn't updated for hangar aircraft ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(child)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->SetChildClass(""); ! } ! } ! ! } // load launcher create from stream ! //if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(child)) ! //{ ! // size_t nLaunchers = platform->GetLauncherCount(); ! // for (size_t n=0; n<nLaunchers; n++) ! // { ! // tcLauncher* launcher = platform->GetLauncher(n); ! // launcher->operator<<(stream); ! // } ! //} } *************** *** 114,157 **** /** * Saves state to create stream */ tcCreateStream& tcFlightOpsObject::operator>>(tcCreateStream& stream) { ! unsigned short nChildren = flight_deck.GetCount(); ! ! stream << nChildren; ! for (unsigned short k=0; k < nChildren; k++) { ! tcAirState* airState = flight_deck.GetAirState(k); tcGameObject* obj = airState->obj; wxASSERT(obj); ! ! stream << obj->mnDBKey; short int localId = short(obj->mnID); ! stream << localId; std::string unitName = obj->mzUnit.c_str(); ! stream << unitName; unsigned char loc = unsigned char(airState->current_location); ! stream << loc; unsigned char pos = unsigned char(airState->current_spot); // doesn't matter for HANGAR loc ! stream << pos; ! // add launcher create to stream ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! { ! size_t nLaunchers = platform->GetLauncherCount(); ! for (size_t n=0; n<nLaunchers; n++) ! { ! tcLauncher* launcher = platform->GetLauncher(n); ! launcher->operator>>(stream); ! } ! } } return stream; --- 128,207 ---- /** * Saves state to create stream + * Do partial save if stream size limit is reached */ tcCreateStream& tcFlightOpsObject::operator>>(tcCreateStream& stream) { ! long freeSpace = stream.GetMaxSize() - stream.size() - 1; // 1 byte for update count header ! wxASSERT(freeSpace > 0); ! tcCreateStream tempStream1; ! tcCreateStream tempStream2; ! ! wxASSERT(flight_deck.GetCount() < 256); ! unsigned char nChildren = flight_deck.GetCount(); ! if (nextUpdateIdx >= nChildren) nextUpdateIdx = 0; ! size_t nUpdates = 0; ! ! while ((nextUpdateIdx < nChildren) && (freeSpace > 0)) { ! tempStream1.clear(); ! ! tcAirState* airState = flight_deck.GetAirState(nextUpdateIdx); tcGameObject* obj = airState->obj; wxASSERT(obj); ! tempStream1 << obj->mnDBKey; short int localId = short(obj->mnID); ! tempStream1 << localId; std::string unitName = obj->mzUnit.c_str(); ! tempStream1 << unitName; unsigned char loc = unsigned char(airState->current_location); ! tempStream1 << loc; unsigned char pos = unsigned char(airState->current_spot); // doesn't matter for HANGAR loc ! tempStream1 << pos; ! if ((long)tempStream1.size() <= freeSpace) ! { ! tempStream2 << tempStream1; ! freeSpace -= tempStream1.size(); ! nextUpdateIdx++; ! nUpdates++; ! } ! else ! { ! freeSpace = 0; ! } ! ! // add launcher create to tempStream1 ! //if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! //{ ! // size_t nLaunchers = platform->GetLauncherCount(); ! // for (size_t n=0; n<nLaunchers; n++) ! // { ! // tcLauncher* launcher = platform->GetLauncher(n); ! // launcher->operator>>(tempStream1); ! // } ! //} } + unsigned char nUpdatesChar = (unsigned char)nUpdates; + stream << nUpdatesChar; + + stream << tempStream2; + + if (nextUpdateIdx >= nChildren) + { + nextUpdateIdx = 0; + stream.SetDoneFlag(true); + } + else + { + stream.SetDoneFlag(false); + } + return stream; *************** *** 184,187 **** --- 234,242 ---- } + size_t tcFlightOpsObject::CurrentAirComplementSize() const + { + return flight_deck.GetCount(); + } + bool tcFlightOpsObject::HasNewCommand() const { *************** *** 475,479 **** */ tcFlightOpsObject::tcFlightOpsObject(tcFlightportDBObject* dbObject, tcGameObject* gameObject) ! : gameObj(gameObject) { wxASSERT(gameObj); --- 530,535 ---- */ tcFlightOpsObject::tcFlightOpsObject(tcFlightportDBObject* dbObject, tcGameObject* gameObject) ! : gameObj(gameObject), ! nextUpdateIdx(0) { wxASSERT(gameObj); Index: tcSonar.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSonar.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** tcSonar.cpp 20 Nov 2006 00:17:45 -0000 1.18 --- tcSonar.cpp 27 Nov 2006 00:46:40 -0000 1.19 *************** *** 24,27 **** --- 24,28 ---- #include "tcSonar.h" #include "tcGameObject.h" + #include "tcHeloObject.h" #include "tcSurfaceObject.h" #include "tcSubObject.h" *************** *** 71,74 **** --- 72,78 ---- float fCoverageAz1, fCoverageAz2; bool isInSearchVolume = false; + last_snr_excess = -99.9f; + range_km = 0; + emitterId = -1; wxASSERT(mpDBObj); *************** *** 132,136 **** if (!isInSearchVolume) { - range_km = 0; return false; } --- 136,139 ---- *************** *** 142,148 **** mpDBObj->alpha * range_km; // one-way transmission loss referenced to 1 m // crude thermocline ! bool parentAbove = par_kin->mfAlt_m >= -80.0; ! bool targetAbove = tgt_kin->mfAlt_m >= -80.0; if (parentAbove != targetAbove) TL += 10.0f; // add 10 dB loss --- 145,180 ---- mpDBObj->alpha * range_km; // one-way transmission loss referenced to 1 m + + float sonarAlt_m = par_kin->mfAlt_m; + float targetAlt_m = tgt_kin->mfAlt_m; + + // if parent or target airborne, assume helo dipping sonar and subtract scope_m from alt + if (sonarAlt_m > 0) + { + sonarAlt_m -= scope_m; + if (sonarAlt_m > 0) return false; // sonar out of water + } + + if (targetAlt_m > 0) + { + const tcHeloObject* helo = dynamic_cast<const tcHeloObject*>(target); + if (helo != 0) + { + targetAlt_m = helo->GetDippingSonarAlt(); + if (targetAlt_m > 0) return false; // sonar out of water + + const tcSonar* sonar = helo->GetStrongestActiveSonar(); + emitterId = sonar->mpDBObj->mnKey; + } + else + { + wxASSERT(false); // non-helo dipping sonar? + return false; + } + } + // crude thermocline ! bool parentAbove = sonarAlt_m >= -80.0; ! bool targetAbove = targetAlt_m >= -80.0; if (parentAbove != targetAbove) TL += 10.0f; // add 10 dB loss *************** *** 255,258 **** --- 287,295 ---- } + float tcSonar::GetScope() const + { + return scope_m; + } + /** * @return true if torpedo is running in passive mode *************** *** 519,522 **** --- 556,572 ---- + // update emitter info if applicable + if (emitterId != -1) + { + tsEmitterInfo *pEmitterInfo; + if (pSMTrack->UpdateEmitter(pEmitterInfo, emitterId)) + { + pEmitterInfo->mfTimestamp = t; + pEmitterInfo->mnMode = 0; // ?? probably unimplemented param + } + } + + + if (bNewDetection) { *************** *** 548,551 **** --- 598,607 ---- { bool isEligible = (target->mpDBObject->mnType & (PTYPE_SUBSURFACE | PTYPE_SURFACE)) != 0; + + // if this sonar is passive, allow detection of helo dipping sonar + bool possibleDippingSonar = isPassive && (target->mpDBObject->mnType == PTYPE_HELO) && + (target->mcKin.mfAlt_m < 500.0f); + isEligible = isEligible || possibleDippingSonar; + float range_km = 0; bool bDetected = *************** *** 660,664 **** /** ! * If this is a towed array, update the array scope based on state and platform speed */ void tcSonar::UpdateScope(double t) --- 716,720 ---- /** ! * If this is a towed array or dipping sonar, update the array scope based on state and platform speed */ void tcSonar::UpdateScope(double t) *************** *** 710,714 **** isPassive(false), last_az_rad(0), ! depth_m(0) { mnMode = SSMODE_SURVEILLANCE; --- 766,772 ---- isPassive(false), last_az_rad(0), ! depth_m(0), ! scope_m(0), ! emitterId(-1) { mnMode = SSMODE_SURVEILLANCE; *************** *** 721,725 **** isPassive(dbObj->isPassive), last_az_rad(0), ! depth_m(0) { wxASSERT(dbObj); --- 779,785 ---- isPassive(dbObj->isPassive), last_az_rad(0), ! depth_m(0), ! scope_m(0), ! emitterId(-1) { wxASSERT(dbObj); Index: tcCarrierObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcCarrierObject.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tcCarrierObject.cpp 20 Nov 2006 00:17:44 -0000 1.16 --- tcCarrierObject.cpp 27 Nov 2006 00:46:40 -0000 1.17 *************** *** 254,257 **** --- 254,260 ---- { mpDBObject = obj; + mnModelType = MTYPE_CARRIER; + + brain->AddTask("RefuelAllAircraft", 3.0, ai::Task::PERMANENT | ai::Task::HIDDEN); } |