[Gcblue-commits] gcb_wx/src/sim tcSonobuoy.cpp,NONE,1.1 tcSensorMap.cpp,1.15,1.16 tcSimState.cpp,1.6
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-03-05 22:38:14
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21843/src/sim Modified Files: tcSensorMap.cpp tcSimState.cpp tcSonar.cpp Added Files: tcSonobuoy.cpp Log Message: Added sonobuoy model. 2525 view now uses small symbol for ballistic and sonobuoy instead of unknown symbol Index: tcSimState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSimState.cpp,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** tcSimState.cpp 2 Mar 2005 22:28:45 -0000 1.68 --- tcSimState.cpp 5 Mar 2005 22:38:03 -0000 1.69 *************** *** 43,46 **** --- 43,48 ---- #include "tcBallisticDBObject.h" #include "tcGroundObject.h" + #include "tcSonobuoy.h" + #include "tcSonobuoyDBObject.h" #include "tcTorpedoObject.h" #include "tcTorpedoDBObject.h" *************** *** 1524,1527 **** --- 1526,1533 ---- } } + else if (tcSonobuoy* sonobuoy = dynamic_cast<tcSonobuoy*>(launched)) + { + sonobuoy->LaunchFrom(launchingPlatform, nLauncher); + } else { *************** *** 1599,1602 **** --- 1605,1612 ---- return new tcBallisticWeapon(ballisticData); } + else if (tcSonobuoyDBObject* sonobuoyData = dynamic_cast<tcSonobuoyDBObject*>(apDBObject)) + { + return new tcSonobuoy(sonobuoyData); + } else { Index: tcSensorMap.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSensorMap.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tcSensorMap.cpp 2 Mar 2005 22:28:45 -0000 1.15 --- tcSensorMap.cpp 5 Mar 2005 22:38:03 -0000 1.16 *************** *** 150,153 **** --- 150,180 ---- } + /** + * @return number of contributors to this track + */ + unsigned tcSensorMapTrack::GetContributorCount() const + { + return (unsigned)mnContributors; + } + + /** + * @return name of contributing platform <idx> or pointer to "" if bad idx + */ + const char* tcSensorMapTrack::GetContributorName(unsigned idx) const + { + static const std::string emptyString(""); + + if (idx >= (unsigned)mnContributors) return emptyString.c_str(); + + long contributorId = maSensorReport[idx].mnSensorPlatformID; + if (tcGameObject* obj = simState->GetObject(contributorId)) + { + return obj->mzUnit.mz; + } + else + { + return emptyString.c_str(); + } + } --- NEW FILE: tcSonobuoy.cpp --- /** ** @file tcSonobuoy.cpp */ /* Copyright (C) 2005 Dewitt Colclough (de...@tw...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" // precompiled header file #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "tcSonobuoy.h" #include "tc3DPoint.h" #include "math_constants.h" #include "tcGameObject.h" #include "tcGenericDBObject.h" #include "tcLauncher.h" #include "tcPlatformObject.h" #include "tcSimState.h" #include "tcSonobuoyDBObject.h" #ifdef _DEBUG #define new DEBUG_NEW #endif void tcSonobuoy::Clear() { tcGameObject::Clear(); } void tcSonobuoy::PrintToFile(tcFile& file) { tcGameObject::PrintToFile(file); tcSensorPlatform::PrintToFile(file); } void tcSonobuoy::SaveToFile(tcFile& file) { tcGameObject::SaveToFile(file); tcSensorPlatform::SaveToFile(file); } void tcSonobuoy::LoadFromFile(tcFile& file) { tcGameObject::LoadFromFile(file); tcSensorPlatform::LoadFromFile(file); } void tcSonobuoy::Serialize(tcFile& file, bool mbLoad) { if (mbLoad) { LoadFromFile(file); } else { SaveToFile(file); } } /** * Initializes sonobuoy for launch from game object. * Adds self to simulation * * @param obj launching game object * @param launcher index of launcher */ void tcSonobuoy::LaunchFrom(tcGameObject* obj, unsigned nLauncher) { if (tcPlatformObject* platObj = dynamic_cast<tcPlatformObject*>(obj)) { tc3DPoint launcherPos = platObj->mpDBObject->GetLauncherPosition(nLauncher); GeoPoint pos = obj->RelPosToLatLonAlt(launcherPos.x, launcherPos.y, launcherPos.z); mcKin.mfLon_rad = pos.mfLon_rad; mcKin.mfLat_rad = pos.mfLat_rad; mcKin.mfAlt_m = pos.mfAlt_m; } else { wxASSERT(false); mcKin.mfLon_rad = obj->mcKin.mfLon_rad; mcKin.mfLat_rad = obj->mcKin.mfLat_rad; mcKin.mfAlt_m = obj->mcKin.mfAlt_m; } mcKin.mfSpeed_kts = obj->mcKin.mfSpeed_kts; parentId = obj->mnID; const tcLauncher* pLauncher = obj->GetLauncher(nLauncher); mcKin.mfHeading_rad = obj->mcKin.mfHeading_rad + pLauncher->pointingAngle; mcKin.mfPitch_rad = obj->mcKin.mfPitch_rad + pLauncher->pointingElevation; mcKin.mfClimbAngle_rad = mcKin.mfPitch_rad; mfStatusTime = obj->mfStatusTime; wxString s = wxString::Format("Sonobuoy %d-%d", obj->mnID, rand() % 1000); mzUnit = s.c_str(); mnAlliance = obj->mnAlliance; simState->AddPlatform(static_cast<tcGameObject*>(this)); } /** * */ void tcSonobuoy::Update(double afStatusTime) { const float min_update_s = 0.0f; float dt_s = (float)(afStatusTime - mfStatusTime); if (dt_s <= min_update_s) {return;} // added for pause case // air launched buoys drop into water first bool outOfWater = (mcKin.mfAlt_m > 0.0f); if (outOfWater) { UpdateDrop(dt_s); mfStatusTime = afStatusTime; return; } // cheesy wave bob effect mcKin.mfAlt_m = 0.45f * cos(0.7f * afStatusTime) - 0.5f; // TODO: Check that parent platform is in range before updating sensors tcSensorPlatform::Update(afStatusTime); batteryTimeRemaining_s -= dt_s; if (batteryTimeRemaining_s <= 0) { tcGameObject::mfDamageLevel += 1.0; // destroy buoy } mfStatusTime = afStatusTime; } /** * */ void tcSonobuoy::UpdateDrop(float dt_s) { float heading_rad = mcKin.mfHeading_rad; float fGroundSpeed_kts = cosf(mcKin.mfClimbAngle_rad) * mcKin.mfSpeed_kts; float vz_mps = C_KTSTOMPS * sinf(mcKin.mfClimbAngle_rad) * mcKin.mfSpeed_kts; float vxy_mps = C_KTSTOMPS * fGroundSpeed_kts; float z = mcKin.mfAlt_m; float dvz = C_G * dt_s; if (vz_mps < -50.0f) { dvz = 0; } else if (vz_mps < -40.0f) { dvz = 0.1f * (vz_mps + 50.0f) * dvz; // gradually limit acceleration } vz_mps = vz_mps - dvz; if (vxy_mps > 0) { vxy_mps = vxy_mps - dt_s * 0.02f * vxy_mps * vxy_mps; // air drag } if (vxy_mps < 0) { vxy_mps = 0; } double fDistance_rad = fGroundSpeed_kts*dt_s*(float)C_KTSTORADPS; mcKin.mfLon_rad += fDistance_rad*(double)(sinf(heading_rad)/cosf((float)mcKin.mfLat_rad)); mcKin.mfLat_rad += (double)cosf(heading_rad)*fDistance_rad; mcKin.mfAlt_m += vz_mps*dt_s; mcKin.mfClimbAngle_rad = atan2(vz_mps, vxy_mps); mcKin.mfPitch_rad = 0; mcKin.mfSpeed_kts = C_MPSTOKTS * sqrtf(vz_mps*vz_mps + vxy_mps*vxy_mps); // stop and activate all sensors after hitting water if (mcKin.mfAlt_m <= 0) { mcKin.mfAlt_m = 0; mcKin.mfSpeed_kts = 0; unsigned nSensors = tcSensorPlatform::GetSensorCount(); for (unsigned n=0; n<nSensors; n++) { tcSensorPlatform::SetSensorState(n, true); } } } /** * */ tcSonobuoy::tcSonobuoy() : mpDBObject(0) { wxASSERT(false); Clear(); mnModelType = MTYPE_SONOBUOY; } /** * Constructor that initializes using info from database entry. */ tcSonobuoy::tcSonobuoy(tcSonobuoyDBObject *obj) : tcGameObject(obj), tcSensorPlatform(), mpDBObject(obj), batteryTimeRemaining_s(obj->batteryLife_s), parentId(-1) { tcSensorPlatform::Init(obj, this); mcKin.mfSpeed_kts = 0; mnModelType = MTYPE_SONOBUOY; } tcSonobuoy::~tcSonobuoy() { } Index: tcSonar.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSonar.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tcSonar.cpp 27 Jan 2005 01:02:06 -0000 1.6 --- tcSonar.cpp 5 Mar 2005 22:38:03 -0000 1.7 *************** *** 611,614 **** --- 611,615 ---- mnMode = SSMODE_SURVEILLANCE; mfSensorHeight_m = 0.0f; + mbActive = isPassive; // passive sonar default to "on" state } |