[Gcblue-commits] gcb_wx/src/database tcTorpedoDBObject.cpp,NONE,1.1
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-12-05 02:58:35
|
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22179/src/database Added Files: tcTorpedoDBObject.cpp Log Message: Sonar work, passive sonar, torpedoes --- NEW FILE: tcTorpedoDBObject.cpp --- /* ** @file tcTorpedoDBObject.cpp */ /* Copyright (C) 2004 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" #if _MSC_VER > 1000 #pragma warning(disable:4786) // suppress warning for STL bug in VC6, see Q167355 in the MSDN Library. #endif // _MSC_VER > 1000 #include "tcTorpedoDBObject.h" #include "math_constants.h" #include "randfn.h" #include "tcDatabase.h" #include "common/tinyxml.h" #include "database/tcSqlReader.h" #include <sstream> #ifdef _DEBUG #define new DEBUG_NEW #endif namespace Database { /** * Calculate parameters based on database values. */ void tcTorpedoDBObject::CalculateParams() { maxTurnRate_radps = C_PIOVER180 * maxTurnRate_degps; fuelRate_kgpktps = fuelRate_kgps / maxSpeed_kts; } /** * workaround for write serialization issue * @return true if db obj is a leaf obj */ bool tcTorpedoDBObject::IsLeaf() const { return mnClassID == DTYPE_TORPEDO; } void tcTorpedoDBObject::PrintToFile(tcFile& file) { tcString s; tcWeaponDBObject::PrintToFile(file); s.Format(" No torpedo info avail."); file.WriteString(s.GetBuffer()); } int tcTorpedoDBObject::Serialize(tcFile& file, bool mbLoad, UINT32 anVersion) { tcWeaponDBObject::Serialize(file, mbLoad, anVersion); if (mbLoad) { wxASSERT(false); } else { wxASSERT(false); } return true; } /** * Loads/saves XML data for database object * @param load true to load, false to save */ void tcTorpedoDBObject::SerializeXml(TiXmlElement* node, bool load) { if (load) return; // write only for now wxASSERT(node); TiXmlElement* localNode = node->InsertEndChild(TiXmlElement("torpedo"))->ToElement(); localNode->SetAttribute("mass_kg", mass_kg); localNode->SetAttribute("dragArea_sm", dragArea_sm); localNode->SetAttribute("maxTurnRate_degps", maxTurnRate_degps); localNode->SetAttribute("maxDepth_m", maxDepth_m); localNode->SetAttribute("maxThrust_N", maxThrust_N); localNode->SetAttribute("fuel_kg", fuel_kg); localNode->SetAttribute("fuelRate_kgps", fuelRate_kgps); localNode->SetAttribute("maxSpeed_kts", maxSpeed_kts); localNode->SetAttribute("acceleration_ktsps", acceleration_ktsps); localNode->SetAttribute("mfRange_km", mfRange_km); localNode->SetAttribute("sonarClass", sonarClass.c_str()); for(size_t i=0; (i<defaultProfile.size())&&(i<MAX_TORPEDO_SEGMENTS); i++) { TiXmlElement* childNode = node->InsertEndChild(TiXmlElement("segment"))->ToElement(); childNode->SetAttribute("range_km", defaultProfile[i].range_km); childNode->SetAttribute("depth_m", defaultProfile[i].depth_m); childNode->SetAttribute("thrust", defaultProfile[i].thrust); childNode->SetAttribute("guidanceMode", (int)defaultProfile[i].meGuidanceMode); } tcWeaponDBObject::SerializeXml(node, load); } /** * Adds sql column definitions to columnString. This is used for * SQL create table command */ void tcTorpedoDBObject::AddSqlColumns(std::string& columnString) { tcWeaponDBObject::AddSqlColumns(columnString); columnString += ","; columnString += "mass_kg number(8),"; columnString += "dragArea_sm number(8),"; columnString += "maxTurnRate_degps number(8),"; columnString += "maxDepth_m number(8),"; columnString += "maxThrust_N number(8),"; columnString += "fuel_kg number(8),"; columnString += "fuelRate_kgps number(8),"; columnString += "maxSpeed_kts number(8),"; columnString += "acceleration_ktsps number(8),"; columnString += "mfRange_km number(8),"; columnString += "sonarClass varchar(30),"; for(unsigned i=0; i<MAX_TORPEDO_SEGMENTS; i++) { tcString s; s.Format("Range%d_km number(5),",i+1); columnString += s.GetBuffer(); s.Format("Depth%d_m number(4),",i+1); columnString += s.GetBuffer(); s.Format("Thrust%d number(5),",i+1); columnString += s.GetBuffer(); s.Format("GuidMode%d number(2)",i+1); columnString += s.GetBuffer(); if (i < MAX_TORPEDO_SEGMENTS - 1) { columnString += ","; } } } void tcTorpedoDBObject::ReadSql(tcSqlReader& entry) { tcWeaponDBObject::ReadSql(entry); mass_kg = entry.GetDouble("mass_kg"); dragArea_sm = entry.GetDouble("dragArea_sm"); maxTurnRate_degps = entry.GetDouble("maxTurnRate_degps"); maxDepth_m = entry.GetDouble("maxDepth_m"); maxThrust_N = entry.GetDouble("maxThrust_N"); fuel_kg = entry.GetDouble("fuel_kg"); fuelRate_kgps = entry.GetDouble("fuelRate_kgps"); maxSpeed_kts = entry.GetDouble("maxSpeed_kts"); acceleration_ktsps = entry.GetDouble("acceleration_ktsps"); mfRange_km = entry.GetDouble("mfRange_km"); sonarClass = entry.GetString("sonarClass"); defaultProfile.clear(); for (unsigned i=0; i<MAX_TORPEDO_SEGMENTS; i++) { float range, depth, thrust; int guidanceMode; range = entry.GetDouble("Range%d_km", i+1); depth = entry.GetDouble("Depth%d_m", i+1); thrust = entry.GetDouble("Thrust%d", i+1); guidanceMode = entry.GetInt("GuidMode%d", i+1); if ((range > 0)||(depth > 0)||(thrust > 0)) { tsTorpedoSegment seg; seg.range_km = range; seg.depth_m = depth; seg.thrust = thrust; seg.meGuidanceMode = (TorpedoGuidanceMode)guidanceMode; ///< guidance mode defaultProfile.push_back(seg); } } } void tcTorpedoDBObject::WriteSql(std::string& valueString) { tcWeaponDBObject::WriteSql(valueString); std::stringstream s; s << ","; s << mass_kg << ","; s << dragArea_sm << ","; s << maxTurnRate_degps << ","; s << maxDepth_m << ","; s << maxThrust_N << ","; s << fuel_kg << ","; s << fuelRate_kgps << ","; s << maxSpeed_kts << ","; s << acceleration_ktsps << ","; s << mfRange_km << ","; s << "'" << sonarClass.c_str() << "'" << ","; for (unsigned i=0; i<MAX_TORPEDO_SEGMENTS; i++) { if (i < defaultProfile.size()) { s << defaultProfile[i].range_km << ","; s << defaultProfile[i].depth_m << ","; s << defaultProfile[i].thrust << ","; s << (long)defaultProfile[i].meGuidanceMode; } else { s << "0,"; s << "0,"; s << "0,"; s << "0"; } if (i < MAX_TORPEDO_SEGMENTS - 1) { s << ","; } } valueString += s.str(); } tcTorpedoDBObject::tcTorpedoDBObject(tcTorpedoDBObject& obj) : tcWeaponDBObject(obj), mass_kg(obj.mass_kg), dragArea_sm(obj.dragArea_sm), maxTurnRate_degps(obj.maxTurnRate_degps), maxDepth_m(obj.maxDepth_m), maxThrust_N(obj.maxThrust_N), fuel_kg(obj.fuel_kg), fuelRate_kgps(obj.fuelRate_kgps), maxSpeed_kts(obj.maxSpeed_kts), acceleration_ktsps(obj.acceleration_ktsps), mfRange_km(obj.mfRange_km), sonarClass(obj.sonarClass) { mnClassID = DTYPE_TORPEDO; mnModelType = MTYPE_TORPEDO; mnType = PTYPE_TORPEDO; CalculateParams(); } tcTorpedoDBObject::tcTorpedoDBObject() : tcWeaponDBObject() , mass_kg(100), dragArea_sm(1), maxTurnRate_degps(5), maxDepth_m(500), maxThrust_N(100), fuel_kg(100), fuelRate_kgps(1), maxSpeed_kts(40), acceleration_ktsps(3), mfRange_km(10), sonarClass("") { mnClassID = DTYPE_TORPEDO; mnModelType = MTYPE_TORPEDO; mnType = PTYPE_TORPEDO; CalculateParams(); } tcTorpedoDBObject::~tcTorpedoDBObject() { } } // namespace Database |