[Gcblue-commits] gcb_wx/src/sim tcPositionRegistry.cpp,NONE,1.1 tcSensorPlatform.cpp,NONE,1.1 tcPlat
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-03-04 00:46:29
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11821/src/sim Modified Files: tcPlatformObject.cpp tcSubObject.cpp Added Files: tcPositionRegistry.cpp tcSensorPlatform.cpp Log Message: Better sensor ageout behavior, more ai work, misc cleanup --- NEW FILE: tcPositionRegistry.cpp --- /** ** @file tcPositionRegistry.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" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "tcPositionRegistry.h" #include <math.h> #ifdef _DEBUG #define new DEBUG_NEW #endif /** * Adds contents of bin <bin> to back of vector <v>. If the bin is empty * nothing is added */ void tcPositionRegistry::AppendBinContents(std::vector<long>& v, long bin) { std::map<long, std::map<long, bool> >::const_iterator iter = positionMap.find(bin); if (iter == positionMap.end()) return; std::map<long, bool>::const_iterator binIter = iter->second.begin(); while (binIter != iter->second.end()) { v.push_back(binIter->first); ++binIter; } } void tcPositionRegistry::ConformLonLat(double& lon_west, double& lon_east, double& lat_south, double& lat_north) { // put lon into [-pi, pi) and saturate lat to [-pi/2, pi/2] wxASSERT((lat_south >= -piovertwo) && (lat_south <= piovertwo)); wxASSERT((lat_north >= -piovertwo) && (lat_north <= piovertwo)); wxASSERT((lon_west >= -twopi) && (lon_west <= twopi)); wxASSERT((lon_east >= -twopi) && (lon_east <= twopi)); if (lon_west < -pi) lon_west += twopi; else if (lon_west >= pi) lon_west -= twopi; if (lon_east < -pi) lon_east += twopi; else if (lon_east >= pi) lon_east -= twopi; if (lat_south < -piovertwo) lat_south = -piovertwo; else if (lat_south > piovertwo) lat_south = piovertwo; if (lat_north < -piovertwo) lat_north = -piovertwo; else if (lat_north > piovertwo) lat_north = piovertwo; } std::vector<long>& tcPositionRegistry::GetAllWithinRegion(double lon_west, double lon_east, double lat_south, double lat_north) { static std::vector<long> idVect; idVect.clear(); wxASSERT(lat_north >= lat_south); ConformLonLat(lon_west, lon_east, lat_south, lat_north); long lat_south_idx = LatToIndex(lat_south); long lat_north_idx = LatToIndex(lat_north); long lon_west_idx = LonToIndex(lon_west); long lon_east_idx = LonToIndex(lon_east); for (long lat_idx = lat_south_idx; lat_idx <= lat_north_idx; lat_idx++) { long lat_offset = nLatBins * lat_idx; for (long lon_idx = lon_west_idx; lon_idx <= lon_east_idx; lon_idx++) { long bin = lat_offset + lon_idx; AppendBinContents(idVect, bin); } } return idVect; } void tcPositionRegistry::AddIdToBin(long id, long bin) { positionMap[bin][id] = true; } void tcPositionRegistry::RemoveAll() { //fprintf(stdout, "removing all (%d)\n", entryLookup.size()); positionMap.clear(); entryLookup.clear(); } void tcPositionRegistry::RemoveIdFromBin(long id, long bin) { std::map<long, std::map<long, bool> >::iterator posIter = positionMap.find(bin); if (posIter == positionMap.end()) { fprintf(stderr, "tcPositionRegistry::RemoveIdFromBin - " "bin not found in positionMap (%d)\n", bin); return; } std::map<long, bool>::iterator binIter = posIter->second.find(id); if (binIter == posIter->second.end()) { fprintf(stderr, "tcPositionRegistry::RemoveIdFromBin - " "id not found in bin map (%d, %d)\n", bin, id); return; } // remove id from bin map posIter->second.erase(binIter); // if bin map is now empty, remove this bin from positionMap if (posIter->second.size() == 0) { positionMap.erase(posIter); } } void tcPositionRegistry::RemoveId(long id) { // check if id exists in entryLookup std::map<long, long>::iterator entryIter = entryLookup.find(id); if (entryIter == entryLookup.end()) { fprintf(stderr, "tcPositionRegistry::RemoveId - " "id not found in entryLoookup (%d)\n", id); return; } long bin = entryIter->second; entryLookup.erase(entryIter); //fprintf(stdout, "removing id %d from bin %d\n", id, bin); RemoveIdFromBin(bin, id); } void tcPositionRegistry::UpdatePosition(long id, double lon, double lat) { wxASSERT(id != -1); wxASSERT((lon >= -pi) && (lon < pi)); wxASSERT((lat >= -piovertwo) && (lat < piovertwo)); long bin = LonLatToBinLocation(lon, lat); // check if id exists in entryLookup std::map<long, long>::iterator entryIter = entryLookup.find(id); if (entryIter == entryLookup.end()) { entryLookup[id] = bin; // add for first time AddIdToBin(id, bin); //fprintf(stdout, "new add, id %d to bin %d\n", id, bin); return; } long previousBin = entryIter->second; if (previousBin == bin) return; // no change, return RemoveIdFromBin(id, previousBin); AddIdToBin(id, bin); //fprintf(stdout, "transfering id %d from bin %d to %d\n", id, previousBin, bin); entryLookup[id] = bin; // update bin for id } long tcPositionRegistry::LatToIndex(double lat) { double idx = floor((lat + piovertwo) * invBinWidth); return long(idx); } long tcPositionRegistry::LonToIndex(double lon) { double idx = floor((lon + pi) * invBinWidth); return long(idx); } long tcPositionRegistry::LonLatToBinLocation(double lon, double lat) { double bin = (nLatBins * LatToIndex(lat)) + LonToIndex(lon); long nBin = long(bin); return nBin; } /** * */ tcPositionRegistry::tcPositionRegistry() : pi(3.141592653589793), twopi(6.283185307179586), piovertwo(1.570796326794897), binWidth(0.25 * 0.017453293) // 0.25 degrees lon/lat { invBinWidth = 1.0 / binWidth; nLatBins = ceil(pi * invBinWidth); } /** * */ tcPositionRegistry::~tcPositionRegistry() { } --- NEW FILE: tcSensorPlatform.cpp --- /** ** @file tcSensorPlatform.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" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "tcSensorPlatform.h" #include "tcSensorPlatformDBObject.h" #include "tcRadar.h" #include "tcESMSensor.h" #include "common/tcStream.h" #include "common/tcObjStream.h" #include "common/tcString.h" #ifdef _DEBUG #define new DEBUG_NEW #endif /** * @return number of sensors on platform */ unsigned tcSensorPlatform::GetSensorCount() const { return (unsigned)sensorState.size(); } /** * @return description of sensors for display */ wxString tcSensorPlatform::GetSensorDescription() { wxString description; unsigned nSensors = GetSensorCount(); for (unsigned n=0; n < nSensors; n++) { const tcSensorState* sensor = GetSensor(n); description += wxString::Format("%s\n", sensor->mpDBObj->mzClass.mz); } if (nSensors == 0) { description = "No sensors\n"; } return description; } /** * consider all active (mbActive) sensors */ bool tcSensorPlatform::HasActivatedSensor() { int nSensors = (int)sensorState.size(); for (int k=0;k<nSensors;k++) { tcSensorState *pSensorState = sensorState[k]; if (pSensorState->GetActive()) {return true;} } return false; } /** * consider only active radars */ bool tcSensorPlatform::IsRadiating() { int nSensors = (int)sensorState.size(); for (int k=0;k<nSensors;k++) { tcSensorState *pSensorState = sensorState[k]; if (dynamic_cast<tcRadar*>(pSensorState)) { if (pSensorState->GetActive()) {return true;} } } return false; } const tcSensorState* tcSensorPlatform::GetSensor(unsigned int idx) { if (idx >= sensorState.size()) return 0; else return sensorState[idx]; } /** * This version is used for non-const access to the sensor */ tcSensorState* tcSensorPlatform::GetSensorMutable(unsigned idx) { if (idx >= sensorState.size()) return 0; else return sensorState[idx]; } /** * @returns mutable pointer to first sensor matching sensorClass or 0 if not found */ tcSensorState* tcSensorPlatform::GetSensorMutable(const std::string& sensorClass) { for(size_t n=0; n<sensorState.size(); n++) { if (sensorClass == sensorState[n]->mpDBObj->mzClass.mz) { return sensorState[n]; } } return 0; } /** * Used to active/deactive sensor on platform */ void tcSensorPlatform::SetSensorState(unsigned idx, bool state) { if (idx >= sensorState.size()) return; // error sensorState[idx]->SetActive(state); sensorCommandObj.SetNewCommand(0x01 << idx); } void tcSensorPlatform::PrintToFile(tcFile& file) { tcString s; int nSensors = (int)sensorState.size(); for(int i=0;i<nSensors;i++) { tcSensorState*& pSS = sensorState[i]; if (pSS != NULL) { s.Format(" SENSOR%d: %s\n",i,pSS->mpDBObj->mzClass.mz); } else { s = " BAD SENSOR\n"; } file.WriteString(s.GetBuffer()); } } void tcSensorPlatform::SaveToFile(tcFile& file) { size_t nSensors = sensorState.size(); for(size_t i=0;i<nSensors;i++) { tcSensorState*& pss = sensorState[i]; pss->Serialize(file, false); } } /** * */ void tcSensorPlatform::LoadFromFile(tcFile& file) { // assumes that sensors already created by higher level serialize method size_t nSensors = sensorState.size(); for(size_t i=0;i<nSensors;i++) { tcSensorState*& pss = sensorState[i]; pss->Serialize(file,true); } } /** * */ void tcSensorPlatform::Serialize(tcFile& file, bool mbLoad) { if (mbLoad) { LoadFromFile(file); } else { SaveToFile(file); } } /** * Loads state from command stream */ tcCommandStream& tcSensorPlatform::operator<<(tcCommandStream& stream) { size_t nSensors = sensorState.size(); for(size_t n=0; n < nSensors; n++) { sensorCommandObj.LoadCommandParam(stream, sensorState[n]->mbActive, (0x01) << n); } return stream; } /** * Saves state to command stream */ tcCommandStream& tcSensorPlatform::operator>>(tcCommandStream& stream) { size_t nSensors = sensorState.size(); for(size_t n=0; n < nSensors; n++) { stream << sensorState[n]->mbActive; } return stream; } /** * Loads state from create stream */ tcCreateStream& tcSensorPlatform::operator<<(tcCreateStream& stream) { return stream; } /** * Saves state to create stream */ tcCreateStream& tcSensorPlatform::operator>>(tcCreateStream& stream) { return stream; } /** * Loads state from update stream */ tcUpdateStream& tcSensorPlatform::operator<<(tcUpdateStream& stream) { return stream; } /** * Saves state to update stream */ tcUpdateStream& tcSensorPlatform::operator>>(tcUpdateStream& stream) { return stream; } void tcSensorPlatform::ClearNewCommand() { sensorCommandObj.ClearNewCommand(); } bool tcSensorPlatform::HasNewCommand() const { return sensorCommandObj.HasNewCommand(); } bool tcSensorPlatform::HasUnacknowledgedCommand() const { return sensorCommandObj.HasUnacknowledgedCommand(); } /** * If the default constructor is used, this should be used to initialize * this object. */ void tcSensorPlatform::Init(tcSensorPlatformDBObject* obj, tcGameObject* parent) { using namespace Database; // add sensors if (obj->sensorClass.size() > tcSensorPlatformDBObject::MAXSENSORS) { fprintf(stderr, "tcSensorPlatform::Init - Warning - " "DB sensor count exceeded limit\n"); } sensorState.clear(); tcDatabase* database = tcDatabase::Get(); for(size_t i=0; i<obj->sensorClass.size(); i++) { tcDatabaseObject *pDBObj = database->GetObject(obj->sensorClass[i]); if (tcSensorDBObject *pSensorDBObj = dynamic_cast<tcSensorDBObject*>(pDBObj)) { tcSensorState* sensor = pSensorDBObj->CreateSensor(parent); // factory method wxASSERT(sensor); float lookAz_rad = C_PIOVER180 * obj->sensorAz[i]; sensor->SetMountAz(lookAz_rad); sensorState.push_back(sensor); } else { fprintf(stderr, "Error - tcSensorPlatform::Init" "(tcSensorPlatformDBObject* obj *obj) - Sensor not found\n"); } } } /** * */ tcSensorPlatform::tcSensorPlatform() { } tcSensorPlatform::tcSensorPlatform(tcSensorPlatformDBObject* obj, tcGameObject* parent) { Init(obj, parent); // This way avoids using this pointer in base class initializer } /** * */ void tcSensorPlatform::Update(double t) { size_t nSensors = sensorState.size(); for(size_t n=0; n<nSensors; n++) { tcSensorState *sensor = sensorState[n]; wxASSERT(sensor); sensor->Update(t); } } /** * */ tcSensorPlatform::tcSensorPlatform(tcSensorPlatform& o) : sensorCommandObj(o.sensorCommandObj) { // copy sensor state array sensorState.clear(); size_t nSensors = o.sensorState.size(); for (size_t n=0;n<nSensors;n++) { tcSensorState*& pSensorState = o.sensorState[n]; tcSensorState* pNewSensorState = pSensorState->Clone(); sensorState.push_back(pNewSensorState); } } /** * */ tcSensorPlatform::~tcSensorPlatform() { size_t nSensors = sensorState.size(); for (size_t n=0; n<nSensors; n++) { delete sensorState[n]; } } Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** tcPlatformObject.cpp 24 Feb 2005 22:19:16 -0000 1.38 --- tcPlatformObject.cpp 4 Mar 2005 00:46:18 -0000 1.39 *************** *** 272,282 **** { if (clientMode) return; // no sensor update for client ! unsigned nSensors = mapSensorState.size(); ! for(unsigned n=0;n<nSensors;n++) ! { ! tcSensorState *sensor = mapSensorState[n]; ! wxASSERT(sensor); ! sensor->Update(t); ! } } --- 272,277 ---- { if (clientMode) return; // no sensor update for client ! ! tcSensorPlatform::Update(t); } *************** *** 363,410 **** } - /** - * @return number of sensors on platform - */ - unsigned tcPlatformObject::GetSensorCount() const - { - return (unsigned)mapSensorState.size(); - } - - /** - * @return description of sensors for display - */ - wxString tcPlatformObject::GetSensorDescription() - { - wxString description; - unsigned nSensors = GetSensorCount(); - for (unsigned n=0; n < nSensors; n++) - { - const tcSensorState* sensor = GetSensor(n); - description += wxString::Format("%s\n", - sensor->mpDBObj->mzClass.mz); - } - - if (nSensors == 0) - { - description = "No sensors\n"; - } - - return description; - } - - /** - * consider all active (mbActive) sensors - */ - bool tcPlatformObject::HasActivatedSensor() - { - int nSensors = (int)mapSensorState.size(); - for (int k=0;k<nSensors;k++) - { - tcSensorState *pSensorState = mapSensorState[k]; - if (pSensorState->GetActive()) {return true;} - } - return false; - } /** --- 358,362 ---- *************** *** 418,437 **** } ! /** ! * consider only active radars ! */ ! bool tcPlatformObject::IsRadiating() ! { ! int nSensors = (int)mapSensorState.size(); ! for (int k=0;k<nSensors;k++) ! { ! tcSensorState *pSensorState = mapSensorState[k]; ! if (dynamic_cast<tcRadar*>(pSensorState)) ! { ! if (pSensorState->GetActive()) {return true;} ! } ! } ! return false; ! } void tcPlatformObject::Clear() --- 370,374 ---- } ! void tcPlatformObject::Clear() *************** *** 482,500 **** - const tcSensorState* tcPlatformObject::GetSensor(unsigned int idx) - { - if (idx >= mapSensorState.size()) return 0; - else return mapSensorState[idx]; - } - - /** - * This version is used for non-const access to the sensor - */ - tcSensorState* tcPlatformObject::GetSensorMutable(unsigned idx) - { - if (idx >= mapSensorState.size()) return 0; - else return mapSensorState[idx]; - } - /** * @return key of object to launch, otherwise NULL_INDEX --- 419,422 ---- *************** *** 523,535 **** } - /** - * Used to active/deactive sensor on platform - */ - void tcPlatformObject::SetSensorState(unsigned idx, bool state) - { - if (idx >= mapSensorState.size()) return; // error - mapSensorState[idx]->SetActive(state); - sensorCommandObj.SetNewCommand(0x01 << idx); - } /** --- 445,448 ---- *************** *** 602,616 **** file.WriteString(s.GetBuffer()); } ! int nSensors = (int)mapSensorState.size(); ! for(i=0;i<nSensors;i++) { ! tcSensorState*& pSS = mapSensorState[i]; ! if (pSS != NULL) { ! s.Format(" SENSOR%d: %s\n",i,pSS->mpDBObj->mzClass.mz); ! } ! else { ! s = " BAD SENSOR\n"; ! } ! file.WriteString(s.GetBuffer()); ! } } --- 515,521 ---- file.WriteString(s.GetBuffer()); } ! ! tcSensorPlatform::PrintToFile(file); ! } *************** *** 620,630 **** file.Write(&fuel_kg,sizeof(fuel_kg)); ! // sensor array ! int nSensors = (int)mapSensorState.size(); ! for(int i=0;i<nSensors;i++) ! { ! tcSensorState*& pss = mapSensorState[i]; ! pss->Serialize(file,false); ! } // other data mcLauncherState.Serialize(file, false); --- 525,531 ---- file.Write(&fuel_kg,sizeof(fuel_kg)); ! ! tcSensorPlatform::SaveToFile(file); ! // other data mcLauncherState.Serialize(file, false); *************** *** 632,636 **** file.Write(&msFormationParameters,sizeof(msFormationParameters)); } ! /******************************************************************************/ void tcPlatformObject::LoadFromFile(tcFile& file) { --- 533,540 ---- file.Write(&msFormationParameters,sizeof(msFormationParameters)); } ! ! /** ! * ! */ void tcPlatformObject::LoadFromFile(tcFile& file) { *************** *** 638,649 **** file.Read(&fuel_kg,sizeof(fuel_kg)); ! // sensor array ! // assumes that sensors already created by higher level serialize method ! int nSensors = (int)mapSensorState.size(); ! for(int i=0;i<nSensors;i++) ! { ! tcSensorState*& pss = mapSensorState[i]; ! pss->Serialize(file,true); ! } // other data --- 542,547 ---- file.Read(&fuel_kg,sizeof(fuel_kg)); ! ! tcSensorPlatform::LoadFromFile(file); // other data *************** *** 652,657 **** file.Read(&msFormationParameters,sizeof(msFormationParameters)); } ! /******************************************************************************/ ! void tcPlatformObject::Serialize(tcFile& file, bool mbLoad) { if (mbLoad) { --- 550,559 ---- file.Read(&msFormationParameters,sizeof(msFormationParameters)); } ! ! /** ! * ! */ ! void tcPlatformObject::Serialize(tcFile& file, bool mbLoad) ! { if (mbLoad) { *************** *** 696,704 **** if (updateMask & UPDATE_SENSORS) { ! size_t nSensors = mapSensorState.size(); ! for(size_t n=0; n < nSensors; n++) ! { ! sensorCommandObj.LoadCommandParam(stream, mapSensorState[n]->mbActive, (0x01) << n); ! } } --- 598,602 ---- if (updateMask & UPDATE_SENSORS) { ! tcSensorPlatform::operator<<(stream); } *************** *** 720,724 **** updateMask |= UPDATE_LAUNCHERS; } ! if (stream.isAck || sensorCommandObj.HasUnacknowledgedCommand()) { updateMask |= UPDATE_SENSORS; --- 618,622 ---- updateMask |= UPDATE_LAUNCHERS; } ! if (stream.isAck || tcSensorPlatform::HasUnacknowledgedCommand()) { updateMask |= UPDATE_SENSORS; *************** *** 748,756 **** if (updateMask & UPDATE_SENSORS) { ! size_t nSensors = mapSensorState.size(); ! for(size_t n=0; n < nSensors; n++) ! { ! stream << mapSensorState[n]->mbActive; ! } } --- 646,650 ---- if (updateMask & UPDATE_SENSORS) { ! tcSensorPlatform::operator>>(stream); } *************** *** 766,769 **** --- 660,665 ---- tcGameObject::operator<<(stream); + tcSensorPlatform::operator<<(stream); + return stream; } *************** *** 775,778 **** --- 671,676 ---- { tcGameObject::operator>>(stream); + + tcSensorPlatform::operator>>(stream); return stream; *************** *** 789,792 **** --- 687,692 ---- mcLauncherState.operator<<(stream); + tcSensorPlatform::operator<<(stream); + return stream; } *************** *** 801,804 **** --- 701,706 ---- mcLauncherState.operator>>(stream); + tcSensorPlatform::operator>>(stream); + return stream; } *************** *** 808,812 **** commandObj.ClearNewCommand(); mcLauncherState.ClearNewCommand(); ! sensorCommandObj.ClearNewCommand(); } --- 710,714 ---- commandObj.ClearNewCommand(); mcLauncherState.ClearNewCommand(); ! tcSensorPlatform::ClearNewCommand(); } *************** *** 814,818 **** { return commandObj.HasNewCommand() || mcLauncherState.HasNewCommand() || ! sensorCommandObj.HasNewCommand(); } --- 716,720 ---- { return commandObj.HasNewCommand() || mcLauncherState.HasNewCommand() || ! tcSensorPlatform::HasNewCommand(); } *************** *** 820,837 **** { return commandObj.HasUnacknowledgedCommand() || mcLauncherState.HasNewCommand() || ! sensorCommandObj.HasUnacknowledgedCommand(); } ! /******************************************************************************/ ! tcPlatformObject::tcPlatformObject() ! { ! Clear(); ! brain = new Brain(this); ! mpDBObject = NULL; ! mcLauncherState.mnCount = 0; ! mapSensorState.clear(); ! mnModelType = MTYPE_PLATFORM; ! } --- 722,730 ---- { return commandObj.HasUnacknowledgedCommand() || mcLauncherState.HasNewCommand() || ! tcSensorPlatform::HasUnacknowledgedCommand(); } ! *************** *** 843,856 **** void tcPlatformObject::SetFireControlSensors() { // ! for(int nLauncher=0;nLauncher<mpDBObject->mnNumLaunchers;nLauncher++) { std::string fcSensor = mcLauncherState.GetFireControlSensorClass(nLauncher); // 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) { --- 736,752 ---- void tcPlatformObject::SetFireControlSensors() { + size_t nSensors = tcSensorPlatform::GetSensorCount(); + // ! for(int nLauncher=0; nLauncher<mpDBObject->mnNumLaunchers; nLauncher++) { std::string fcSensor = mcLauncherState.GetFireControlSensorClass(nLauncher); + // search for sensor and add if match bool bSearching = fcSensor.length() > 1; ! for(size_t n=0; (n<nSensors) && bSearching; n++) { ! tcRadar* radar = dynamic_cast<tcRadar*>(tcSensorPlatform::GetSensorMutable(n)); if (radar) { *************** *** 862,865 **** --- 758,762 ---- } } + if (bSearching) { *************** *** 870,880 **** } tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) ! : tcGameObject(obj) { using namespace Database; brain = new Brain(this); - //brain->AddTask("TestTask", 1.0); mpDBObject = obj; --- 767,794 ---- } + + /** + * + */ + tcPlatformObject::tcPlatformObject() + : mpDBObject(0) + { + wxASSERT(false); + + Clear(); + brain = new Brain(this); + mcLauncherState.mnCount = 0; + mnModelType = MTYPE_PLATFORM; + } + + tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) ! : tcGameObject(obj), tcSensorPlatform() { using namespace Database; + tcSensorPlatform::Init(obj, this); + brain = new Brain(this); mpDBObject = obj; *************** *** 888,918 **** fuel_kg = mpDBObject->mfFuelCapacity_kg; // start with max fuel - // add sensors - if (mpDBObject->mnNumSensors > tcGenericDBObject::MAXSENSORS) - { - mpDBObject->mnNumSensors = tcGenericDBObject::MAXSENSORS; // limit number of sensors - fprintf(stderr, "tcPlatformObject::tcPlatformObject - Warning - " - "DB sensor count exceeded limit\n"); - } - mapSensorState.clear(); - for(int i=0;i<mpDBObject->mnNumSensors;i++) - { - tnPoolIndex nSensorKey = database->GetKey(mpDBObject->maSensorClass[i]); - tcDatabaseObject *pDBObj = database->GetObject(nSensorKey); - - if (tcSensorDBObject *pSensorDBObj = dynamic_cast<tcSensorDBObject*>(pDBObj)) - { - tcSensorState* sensorState = pSensorDBObj->CreateSensor(this); // factory method - float lookAz_rad = C_PIOVER180 * mpDBObject->sensorAz[i]; - sensorState->SetMountAz(lookAz_rad); - mapSensorState.push_back(sensorState); - } - else - { - fprintf(stderr, "Error - tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj)" - " - Sensor not found\n"); - } - - } // add magazines --- 802,805 ---- *************** *** 962,968 **** lastHeadingDelta = 0; } ! /******************************************************************************/ tcPlatformObject::tcPlatformObject(tcPlatformObject& o) : tcGameObject(o), commandObj(o.commandObj) { --- 849,860 ---- lastHeadingDelta = 0; } ! ! ! /** ! * ! */ tcPlatformObject::tcPlatformObject(tcPlatformObject& o) : tcGameObject(o), + tcSensorPlatform(o), commandObj(o.commandObj) { *************** *** 986,1000 **** } - // copy sensor state array - mapSensorState.clear(); - int nSensors = (int)o.mapSensorState.size(); - for (int n=0;n<nSensors;n++) - { - tcSensorState*& pSensorState = o.mapSensorState[n]; - tcSensorState* pNewSensorState = pSensorState->Clone(); - mapSensorState.push_back(pNewSensorState); - } } ! /******************************************************************************/ tcPlatformObject::~tcPlatformObject() { --- 878,885 ---- } } ! /** ! * ! */ tcPlatformObject::~tcPlatformObject() { *************** *** 1006,1017 **** } - int nSensors = (int)mapSensorState.size(); - for (int n=0;n<nSensors;n++) - { - tcSensorState*& pSensorState = mapSensorState[n]; - delete pSensorState; - pSensorState = NULL; - } - mapSensorState.clear(); } --- 891,894 ---- Index: tcSubObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSubObject.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** tcSubObject.cpp 2 Dec 2004 04:17:27 -0000 1.3 --- tcSubObject.cpp 4 Mar 2005 00:46:18 -0000 1.4 *************** *** 408,415 **** { if (clientMode) return; // no sensor update for client ! unsigned nSensors = mapSensorState.size(); for(unsigned n=0; n<nSensors; n++) { ! tcSensorState* sensor = mapSensorState[n]; wxASSERT(sensor); if (sensor->IsSonar()) --- 408,416 ---- { if (clientMode) return; // no sensor update for client ! ! unsigned nSensors = GetSensorCount(); for(unsigned n=0; n<nSensors; n++) { ! tcSensorState* sensor = GetSensorMutable(n); wxASSERT(sensor); if (sensor->IsSonar()) |