[Gcblue-commits] gcb_wx/src/sim tcLauncherState.cpp,1.3,1.4 tcPlatformObject.cpp,1.11,1.12 tcRadarSe
Status: Alpha
Brought to you by:
ddcforge
From: <ddc...@pr...> - 2004-01-31 04:23:38
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4640/src/sim Modified Files: tcLauncherState.cpp tcPlatformObject.cpp tcRadarSensorState.cpp tcSimState.cpp Log Message: Index: tcLauncherState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcLauncherState.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tcLauncherState.cpp 29 Jan 2004 00:05:40 -0000 1.3 --- tcLauncherState.cpp 30 Jan 2004 01:02:35 -0000 1.4 *************** *** 24,30 **** #include "tcMissileDBObject.h" #include "tcRadarSensorState.h" ! tcDatabase* tcLauncherState::mpDatabase; ! /** * --- 24,32 ---- #include "tcMissileDBObject.h" #include "tcRadarSensorState.h" + #include "tcSimState.h" + #include <iostream> ! tcDatabase* tcLauncherState::mpDatabase = NULL; ! tcSimState* tcLauncherState::simState = NULL; /** * *************** *** 74,78 **** new_launcher.msDatum.mfLon_rad=0; new_launcher.msDatum.mfLat_rad=0; ! new_launcher.mnTargetID=NULL_INDEX; new_launcher.meLaunchMode = AUTO; new_launcher.mnPending = 0; --- 76,80 ---- new_launcher.msDatum.mfLon_rad=0; new_launcher.msDatum.mfLat_rad=0; ! new_launcher.mnTargetID = NULL_INDEX; new_launcher.meLaunchMode = AUTO; new_launcher.mnPending = 0; *************** *** 112,115 **** --- 114,212 ---- } + void tcLauncherState::SetFireControlSensor(unsigned nLauncher, tcRadar* radar) + { + if (nLauncher > launchers.size()) {return;} + launchers[nLauncher].fireControlSensor = radar; + } + + /** + * @return true if success + */ + bool tcLauncherState::SetLauncherDatum(unsigned nLauncher, double lon_rad, double lat_rad) + { + if (nLauncher > launchers.size()) + { + std::cerr << "Bad launcher index" << std::endl; + return false; + } + launchers[nLauncher].msDatum.Set(lon_rad, lat_rad); + return true; + } + + /** + * @return true if success + */ + bool tcLauncherState::SetLauncherTarget(unsigned nLauncher, long targetID) + { + + if (nLauncher > launchers.size()) + { + std::cerr << "Bad launcher index" << std::endl; + return false; + } + launchers[nLauncher].mnTargetID = targetID; + return true; + } + + /** + * @return true if launcher is ready to launch. Launch readiness + * conditions depend on meLaunchMode for the launcher + * @see teWeaponLaunchMode + */ + bool tcLauncherState::ReadyToLaunch(unsigned nLauncher) + { + using namespace Database; + if (nLauncher > launchers.size()) + { + std::cerr << "Bad launcher index" << std::endl; + return false; + } + tsLData& ldata = launchers[nLauncher]; + + if (ldata.mnCurrent <= 0) {return false;} // launcher empty + if (ldata.mfTimeToReady > 0) {return false;} // launcher not ready + + switch (ldata.meLaunchMode) + { + case DATUM_ONLY: // needs a datum programmed to launch + { + return (ldata.msDatum.mfLat_rad != 0) || (ldata.msDatum.mfLon_rad != 0); + } + case SA_TRACK: // needs a track (launching platform) to launch, semi-active or command guidance + case SEEKER_TRACK: // needs a track to launch, seeker sensor checked before associating + { + wxASSERT(simState); + + if (ldata.mnTargetID == NULL_INDEX) return false; // needs a target + tcMissileDBObject *pMissileDBObj = dynamic_cast<tcMissileDBObject*>(ldata.mpChildDBObj); + if (pMissileDBObj==NULL) + { + std::cerr << "ReadyToLaunch -- Error: SA_TRACK guidance with non-missile" << std::endl; + return false; + } + + tnPoolIndex nSensorKey = pMissileDBObj->GetPrimarySeekerKey(); + tcGameObject *targetObj = simState->GetObject(ldata.mnTargetID); + + float seekerAz = parent->mcKin.mfHeading_rad + ldata.pointingAngle; + tsGeoPoint seekerLoc; + seekerLoc.Set((float)parent->mcKin.mfLon_rad,(float)parent->mcKin.mfLat_rad); + bool canDetect = simState->RadarCanDetect(nSensorKey,targetObj,seekerLoc,seekerAz); + return canDetect; + } + + case AUTO: // will launch and either proceed unguided or autonomously search out target + { + bool hasDatum = (ldata.msDatum.mfLat_rad != 0) || (ldata.msDatum.mfLon_rad != 0); + bool hasTarget = (ldata.mnTargetID == NULL_INDEX); + return hasDatum || hasTarget; + } + default: + std::cerr << "Bad meLaunchMode" << std::endl; + return false; + } + return false; + } + /** * *************** *** 170,173 **** --- 267,271 ---- } + /** * *************** *** 177,180 **** --- 275,286 ---- mnCount = 0; launchers.clear(); + parent = NULL; + } + + tcLauncherState::tcLauncherState(tcGameObject *parentObj) + : parent(parentObj) + { + mnCount = 0; + launchers.clear(); } *************** *** 189,192 **** --- 295,299 ---- } mnCount = (int)launchers.size(); + parent = NULL; } Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tcPlatformObject.cpp 29 Jan 2004 00:05:45 -0000 1.11 --- tcPlatformObject.cpp 30 Jan 2004 01:02:35 -0000 1.12 *************** *** 48,59 **** void tcPlatformObject::DesignateLauncherDatum(tcPoint p, unsigned int anLauncher) { ! if (anLauncher >= (unsigned)mcLauncherState.mnCount) {return;} ! mcLauncherState.launchers[anLauncher].msDatum.Set(p.x, p.y); } ! void tcPlatformObject::DesignateLauncherTarget(tnPoolIndex anID, unsigned anLauncher) { ! if (anLauncher >= (unsigned)mcLauncherState.mnCount) {return;} ! mcLauncherState.launchers[anLauncher].mnTargetID = anID; } --- 48,61 ---- void tcPlatformObject::DesignateLauncherDatum(tcPoint p, unsigned int anLauncher) { ! mcLauncherState.SetLauncherDatum(anLauncher, p.x, p.y); } ! /** ! * @return false if target cannot be designated, out of seeker coverage or no fire ! * @return false control support available. ! */ ! bool tcPlatformObject::DesignateLauncherTarget(tnPoolIndex anID, unsigned anLauncher) { ! return mcLauncherState.SetLauncherTarget(anLauncher, anID); } *************** *** 421,424 **** --- 423,461 ---- } + + /** + * Set fire control sensors for launchers. If launcher + * has a non-null fire control sensor, then find and set + * it. + */ + void tcPlatformObject::SetFireControlSensors() + { + // + for(int nLauncher=0;nLauncher<mpDBObject->mnNumLaunchers;nLauncher++) + { + std::string fcSensor = + mcLauncherState.launchers[nLauncher].mpLauncherDBObj->fireControlSensorClass; + // search for sensor and add if match + bool bSearching = fcSensor.length() > 1; + for(size_t n=0; (n<mapSensorState.size()) && bSearching; n++) + { + tcRadar* radar = dynamic_cast<tcRadar*>(mapSensorState[n]); + if (radar) + { + if (fcSensor == radar->mpDBObj->mzClass.mz) + { + mcLauncherState.SetFireControlSensor(nLauncher, radar); + bSearching = false; + } + } + } + if (bSearching) + { + fprintf(stderr, "%s: Failed to find fc sensor, %s, for launcher %d\n", + mpDBObject->mzClass.mz, fcSensor.c_str(), nLauncher); + } + } + } + tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) : tcGameObject(obj) *************** *** 436,449 **** fuel_kg = mpDBObject->mfFuelCapacity_kg; // start with max fuel - // add launchers - mcLauncherState.mnCount = 0; - - for(int nLauncher=0;nLauncher<mpDBObject->mnNumLaunchers;nLauncher++) - { - tnPoolIndex nLauncherKey = database->GetKey(mpDBObject->maLauncherClass[nLauncher]); - float launcherAz_deg = mpDBObject->launcherAz[nLauncher]; - mcLauncherState.AddFullLauncher(database, nLauncherKey, C_PIOVER180*launcherAz_deg); - } - // add sensors if (mpDBObject->mnNumSensors > tcGenericDBObject::MAXSENSORS) --- 473,476 ---- *************** *** 483,486 **** --- 510,527 ---- } } + // add launchers + mcLauncherState.SetParent(this); + mcLauncherState.mnCount = 0; + + for(int nLauncher=0;nLauncher<mpDBObject->mnNumLaunchers;nLauncher++) + { + tnPoolIndex nLauncherKey = database->GetKey(mpDBObject->maLauncherClass[nLauncher]); + float launcherAz_deg = mpDBObject->launcherAz[nLauncher]; + mcLauncherState.AddFullLauncher(database, nLauncherKey, C_PIOVER180*launcherAz_deg); + } + + SetFireControlSensors(); + + model->SetupAnimation(this); *************** *** 494,497 **** --- 535,539 ---- mcGS = o.mcGS; mcLauncherState = o.mcLauncherState; + mcLauncherState.SetParent(this); mcLaunchRequest = o.mcLaunchRequest; mpDBObject = o.mpDBObject; Index: tcRadarSensorState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcRadarSensorState.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tcRadarSensorState.cpp 29 Jan 2004 00:05:45 -0000 1.3 --- tcRadarSensorState.cpp 30 Jan 2004 01:02:50 -0000 1.4 *************** *** 45,48 **** --- 45,49 ---- mnMode = mpDBObj->mbDetectsAir ? SSMODE_FCSURVEILLANCE : SSMODE_SURVEILLANCE; mfSensorHeight_m = 10.0f; + isSemiactive = mpDBObj->isSemiactive; return true; } *************** *** 133,136 **** --- 134,148 ---- /** + * Sets illuminator info for semi-active radars. + */ + void tcRadar::SetIlluminator(long illum_id, unsigned sensor_idx) + { + wxASSERT(isSemiactive); + + illuminatorID = illum_id; + illuminatorSensorIdx = sensor_idx; + } + + /** * */ *************** *** 185,188 **** --- 197,205 ---- mpDBObj = NULL; mnDBKey = NULL_INDEX; + + fireControlTrackCount = 0; + illuminatorID = -1; + illuminatorSensorIdx = 0; + isSemiactive = false; } Index: tcSimState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSimState.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** tcSimState.cpp 29 Jan 2004 00:05:45 -0000 1.25 --- tcSimState.cpp 30 Jan 2004 01:02:50 -0000 1.26 *************** *** 166,170 **** } /********************************************************************/ ! bool tcSimState::DesignateLauncherTarget(tnPoolIndex anKey, tnPoolIndex anTargetKey, unsigned anLauncher) { int bFound; tcGameObject *po; --- 166,171 ---- } /********************************************************************/ ! bool tcSimState::DesignateLauncherTarget(tnPoolIndex anKey, tnPoolIndex anTargetKey, unsigned anLauncher) ! { int bFound; tcGameObject *po; *************** *** 180,183 **** --- 181,198 ---- tcLauncherState *pLauncherState; po->GetLauncherState(pLauncherState); + if (pLauncherState->ReadyToLaunch(anLauncher)) + { + pPlatformObj->DesignateLauncherTarget(anTargetKey, anLauncher); + if (mpUserInfo->IsOwnAlliance(pPlatformObj->mnAlliance)) { + mpSound->PlayEffect(SEFFECT_NOISYBEEP); + } + return true; + } + else + { + return false; + } + /* + if (pLauncherState==NULL) {return false;} if (anLauncher>=(unsigned)pLauncherState->mnCount) {return false;} // invalid anLauncher *************** *** 215,218 **** --- 230,234 ---- return false; // don't designate for other launch modes for now } + */ } *************** *** 1723,1726 **** --- 1739,1743 ---- goalTracker = new tcGoalTracker(); tcGoal::AttachSimState(this); + tcLauncherState::AttachSimState(this); mcSensorMap.CreateMapForAlliance(1); |