[Gcblue-commits] gcb_wx/src/sim tcLauncher.cpp, 1.37, 1.38 tcMapData.cpp, 1.29, 1.30 tcPlatformObje
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-09-05 01:04:28
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv24958/src/sim Modified Files: tcLauncher.cpp tcMapData.cpp tcPlatformObject.cpp tcRadar.cpp tcStores.cpp Log Message: Index: tcLauncher.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcLauncher.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** tcLauncher.cpp 18 Jun 2006 00:45:03 -0000 1.37 --- tcLauncher.cpp 5 Sep 2006 01:04:25 -0000 1.38 *************** *** 620,623 **** --- 620,639 ---- /** + * @return true if child does not require platform guidance after launch + */ + bool tcLauncher::IsChildFireAndForget() + { + if (tcMissileDBObject* missileData = dynamic_cast<tcMissileDBObject*>(mpChildDBObj)) + { + return missileData->IsFireAndForget(); + } + else + { + return true; + } + } + + + /** * Sets child quantity, up to capacity */ Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** tcPlatformObject.cpp 18 Jun 2006 00:45:03 -0000 1.62 --- tcPlatformObject.cpp 5 Sep 2006 01:04:25 -0000 1.63 *************** *** 396,399 **** --- 396,408 ---- + const std::string& tcPlatformObject::GetLoadoutTag() const + { + return loadoutTag; + } + + void tcPlatformObject::SetLoadoutTag(const std::string& s) + { + loadoutTag = s; + } /** *************** *** 1005,1009 **** */ tcPlatformObject::tcPlatformObject() ! : mpDBObject(0) { wxASSERT(false); --- 1014,1019 ---- */ tcPlatformObject::tcPlatformObject() ! : mpDBObject(0), ! loadoutTag("") { wxASSERT(false); *************** *** 1018,1022 **** tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) : tcGameObject(obj), tcSensorPlatform(), ! isRefueling(false) { using namespace database; --- 1028,1033 ---- tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) : tcGameObject(obj), tcSensorPlatform(), ! isRefueling(false), ! loadoutTag("") { using namespace database; *************** *** 1100,1104 **** tcSensorPlatform(o), commandObj(o.commandObj), ! isRefueling(o.isRefueling) { brain = new Brain(this); // need copy constructor for this --- 1111,1116 ---- tcSensorPlatform(o), commandObj(o.commandObj), ! isRefueling(o.isRefueling), ! loadoutTag(o.loadoutTag) { brain = new Brain(this); // need copy constructor for this Index: tcMapData.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcMapData.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** tcMapData.cpp 27 Aug 2006 21:28:54 -0000 1.29 --- tcMapData.cpp 5 Sep 2006 01:04:25 -0000 1.30 *************** *** 1777,1787 **** fMain.Close(); ! tcString s; ! s.Format("tcMapData - LoadTile (lon %.1f,lat %.1f) (m %d n %d) idx:%d - success", ! fStartLon_deg,fStartLat_deg,mtile,ntile,nNewIndex); ! WTL(s.GetBuffer()); ! if ((pTileData->maMapData[0][0] == 0)&&(pTileData->maMapData[10][10]==0)) { ! WTLC("bad tile data"); } --- 1777,1788 ---- fMain.Close(); ! //tcString s; ! //s.Format("tcMapData - LoadTile (lon %.1f,lat %.1f) (m %d n %d) idx:%d - success", ! // fStartLon_deg,fStartLat_deg,mtile,ntile,nNewIndex); ! //WTL(s.GetBuffer()); ! if ((pTileData->maMapData[0][0] == 0)&&(pTileData->maMapData[10][10]==0)) ! { ! WTLC("Error: bad tile data"); } *************** *** 1895,1906 **** demTile.Close(); ! tcString s; ! s.Format("tcMapData - LoadTile (lon %.1f,lat %.1f) (m %d n %d) idx:%d - success", ! fStartLon_deg, fStartLat_deg, mtile, ntile, nNewIndex); ! WTL(s.GetBuffer()); if ((pTileData->maMapData[0][0] == 0)&&(pTileData->maMapData[10][10]==0)) { ! WTLC("bad tile data"); } --- 1896,1907 ---- demTile.Close(); ! //tcString s; ! //s.Format("tcMapData - LoadTile (lon %.1f,lat %.1f) (m %d n %d) idx:%d - success", ! // fStartLon_deg, fStartLat_deg, mtile, ntile, nNewIndex); ! //WTL(s.GetBuffer()); if ((pTileData->maMapData[0][0] == 0)&&(pTileData->maMapData[10][10]==0)) { ! WTLC("Error: bad tile data"); } Index: tcStores.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcStores.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tcStores.cpp 17 Aug 2006 01:28:05 -0000 1.11 --- tcStores.cpp 5 Sep 2006 01:04:25 -0000 1.12 *************** *** 33,36 **** --- 33,40 ---- #include "tcDatabase.h" #include "tcGenericDBObject.h" + #include "tcWeaponDBObject.h" + #include "tcMissileDBObject.h" + #include "tcTorpedoDBObject.h" + #include "tcBallisticDBObject.h" #include "tcFlightOpsObject.h" #include "tcFlightPort.h" *************** *** 278,281 **** --- 282,318 ---- /** + * Adds new automation operation used to set platform to one of several generic + * configurations. + * @param type "Empty" empty all launchers, "AAW" anti-air warfare, "ASuW" antisurface warfare, "ASW" antisubmarine warfare, "Strike" ground strike + */ + void tcStores::AddAutomationOp(const std::string& type, tcGameObject* child) + { + if (type == "Error") + { + wxASSERT(false); + return; + } + + // first search for any existing ops with this child and remove + std::vector<AutomationOperation> temp; + for (size_t n=0; n<automationOps.size(); n++) + { + if (automationOps[n].obj != child) + { + temp.push_back(automationOps[n]); + } + } + automationOps = temp; + + + AutomationOperation op; + op.type = type; + op.obj = child; + op.stage = 0; + + automationOps.push_back(op); + } + + /** * */ *************** *** 989,992 **** --- 1026,1031 ---- if (dt < 1.0) return; + UpdateAutomation(); + lastUpdate = t; *************** *** 1004,1007 **** --- 1043,1386 ---- } + void tcStores::UpdateAutomation() + { + for (size_t n=0; n<automationOps.size(); n++) + { + AutomationOperation& op = automationOps[n]; + if (op.stage == 0) + { + // all ops start with completely unloading the platform + if (UnloadPlatform(op.obj)) + { + op.stage = 1; + } + else + { + op.stage = 86; + } + } + else if (op.stage == 1) + { + if (AllLaunchersEmpty(op.obj)) + { + if (op.type == "Empty") + { + op.stage = 86; + } + else + { + if (LoadPlatform(op.obj, op.type)) + { + op.stage = 2; + } + else + { + op.stage = 86; + } + } + } + } + else if (op.stage == 2) + { + if (AllLaunchersReady(op.obj)) + { + op.stage = 86; + } + } + else + { + op.stage = 86; + } + } + + // remove all automation ops at delete stage (op.stage == 86) + std::vector<AutomationOperation> temp; + + for (size_t n=0; n<automationOps.size(); n++) + { + if (automationOps[n].stage != 86) + { + temp.push_back(automationOps[n]); + } + else + { + if (parent->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Completed loadout automation (%s)\n", + parent->mzUnit.c_str(), parent->mzClass.c_str(), automationOps[n].type.c_str()); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + } + } + automationOps = temp; + + + } + + + bool tcStores::LoadPlatform(tcGameObject* child, const std::string& type) + { + tcPlatformObject* obj = dynamic_cast<tcPlatformObject*>(GetChildOrParent(child)); + + // check that magazine is accessible (child hasn't taken off yet) + if (obj == 0) + { + if (parent->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Automation failed: Cannot load platform, no access to magazine\n", + parent->mzUnit.c_str(), parent->mzClass.c_str()); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; + } + + // verify all launchers are empty + if (!AllLaunchersEmpty(child)) + { + if (parent->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Automation failed: Cannot load platform, launchers not empty\n", + parent->mzUnit.c_str(), parent->mzClass.c_str()); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; + } + + // verify launchers are all valid + size_t nLaunchers = obj->GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = obj->GetLauncher(n); + wxASSERT(launcher); + + if (launcher == 0) + { + if (parent->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Automation failed: Cannot load platform, corrupt launcher\n", + parent->mzUnit.c_str(), parent->mzClass.c_str()); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; + } + } + + + + + // for each launcher find the best loadout based on mission type, weapon range, weapon availability + int targetMask = 0; + + if (type == "AAW") targetMask = AIR_TARGET; + else if (type == "ASuW") targetMask = SURFACE_TARGET; + else if (type == "ASW") targetMask = SUBSURFACE_TARGET; + else if (type == "Strike") targetMask = LAND_TARGET; + else wxASSERT(false); + + + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = obj->GetLauncher(n); + size_t nTypes = launcher->GetCompatibleCount(); + wxASSERT(nTypes > 0); + + std::string bestType = launcher->GetCompatibleName(0); + size_t bestQuantity = CurrentItemQuantity(bestType); + float bestRange_km; + int bestTargetFlags; + + GetWeaponInfo(bestType, bestRange_km, bestTargetFlags); + + // cycle through other types and compare + for (size_t k=1; k<nTypes; k++) + { + std::string candidateType = launcher->GetCompatibleName(k); + size_t candidateQuantity = CurrentItemQuantity(candidateType); + float candidateRange_km; + int candidateTargetFlags; + GetWeaponInfo(candidateType, candidateRange_km, candidateTargetFlags); + + bool betterMissionFit = ((bestTargetFlags & targetMask) == 0) && + ((candidateTargetFlags & targetMask) != 0); + bool worseMissionFit = ((bestTargetFlags & targetMask) != 0) && + ((candidateTargetFlags & targetMask) == 0); + bool fitsMission = ((candidateTargetFlags & targetMask) != 0); + bool betterRange = candidateRange_km > bestRange_km; + bool isAvailable = (candidateQuantity > 0); + + bool better = isAvailable && + (betterMissionFit || (!worseMissionFit && betterRange)); + + if (better) + { + bestType = candidateType; + bestQuantity = candidateQuantity; + bestRange_km = candidateRange_km; + bestTargetFlags = candidateTargetFlags; + } + } + + // load launcher with best results + LoadLauncher(n, bestType, child); + } + + return true; + } + + + void tcStores::GetWeaponInfo(const std::string& name, float& range_km, int& targetFlags) const + { + range_km = 0; + targetFlags = 0; + + tcDatabaseObject* databaseObj = tcDatabase::Get()->GetObject(name); + if (databaseObj == 0) return; + + if (tcWeaponDBObject* weaponObj = dynamic_cast<tcWeaponDBObject*>(databaseObj)) + { + targetFlags = weaponObj->targetFlags; + if (tcMissileDBObject* missileObj = dynamic_cast<tcMissileDBObject*>(weaponObj)) + { + range_km = missileObj->mfRange_km; + } + else if (tcTorpedoDBObject* torpedoObj = dynamic_cast<tcTorpedoDBObject*>(weaponObj)) + { + range_km = torpedoObj->mfRange_km; + } + else if (tcBallisticDBObject* ballObj = dynamic_cast<tcBallisticDBObject*>(weaponObj)) + { + range_km = ballObj->maxRange_km; + } + } + + + } + + + bool tcStores::UnloadPlatform(tcGameObject* child) + { + tcPlatformObject* obj = dynamic_cast<tcPlatformObject*>(GetChildOrParent(child)); + + if (obj == 0) + { + if (parent->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Automation failed: Cannot unload platform, no access to magazine\n", + parent->mzUnit.c_str(), parent->mzClass.c_str()); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; + } + + size_t nLaunchers = obj->GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = obj->GetLauncher(n); + wxASSERT(launcher); + + if ((launcher != 0) && (launcher->mnCurrent > 0)) + { + UnloadLauncher(n, child); + } + } + + return true; + } + + /** + * @return true if any ops for child are active + */ + bool tcStores::HasActiveOp(tcGameObject* child) const + { + std::vector<AutomationOperation>::const_iterator opIter; + for (opIter = automationOps.begin(); opIter != automationOps.end(); ++opIter) + { + if (opIter->obj == child) + { + return true; + } + } + + return false; + } + + /** + * @return true if all launchers of child are empty + */ + bool tcStores::AllLaunchersEmpty(tcGameObject* child) + { + tcPlatformObject* obj = dynamic_cast<tcPlatformObject*>(GetChildOrParent(child)); + + size_t nLaunchers = obj->GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = obj->GetLauncher(n); + wxASSERT(launcher); + + if ((launcher != 0) && (launcher->mnCurrent > 0)) + { + return false; + } + } + + return true; + } + + /** + * @return true if all launchers of child are full and ready + */ + bool tcStores::AllLaunchersReady(tcGameObject* child) + { + tcPlatformObject* obj = dynamic_cast<tcPlatformObject*>(GetChildOrParent(child)); + + size_t nLaunchers = obj->GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = obj->GetLauncher(n); + wxASSERT(launcher); + + if ((launcher != 0) && ((launcher->mnCurrent == 0) || (launcher->IsLoading()))) + { + return false; + } + } + + return true; + } + + + /** + * Used for good guess as to which magazine should manage automation operation + * for obj. + * @return true if stores has any items that are compatible with obj + */ + bool tcStores::HasStoresForThisObject(tcGameObject* obj) + { + tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(GetChildOrParent(obj)); + if (platform == 0) + { + wxASSERT(false); + return false; + } + + size_t nLaunchers = platform->GetLauncherCount(); + for (size_t n=0; n<nLaunchers; n++) + { + tcLauncher* launcher = platform->GetLauncher(n); + wxASSERT(launcher); + + size_t nCompatible = launcher->GetCompatibleCount(); + for (size_t k=0; k<nCompatible; k++) + { + if (CurrentItemQuantity(launcher->GetCompatibleName(k)) > 0) + { + return true; + } + } + } + + return false; + } + /** * For multiplayer, for obj's that are flightport objects, only objects in Index: tcRadar.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcRadar.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** tcRadar.cpp 17 Aug 2006 01:28:05 -0000 1.39 --- tcRadar.cpp 5 Sep 2006 01:04:25 -0000 1.40 *************** *** 410,414 **** void tcRadar::SetFireControlSensor(long id, unsigned char idx) { ! wxASSERT(isSemiactive || isCommandReceiver); tcSensorState::SetFireControlSensor(id, idx); --- 410,414 ---- void tcRadar::SetFireControlSensor(long id, unsigned char idx) { ! wxASSERT((id == -1) || isSemiactive || isCommandReceiver); tcSensorState::SetFireControlSensor(id, idx); |