[Gcblue-commits] gcb_wx/src/sim tcLauncher.cpp,1.22,1.23 tcPlatformObject.cpp,1.47,1.48 tcStores.cpp
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-06-12 20:47:10
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv840/src/sim Modified Files: tcLauncher.cpp tcPlatformObject.cpp tcStores.cpp Log Message: Drag and drop icon gui updates Index: tcLauncher.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcLauncher.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tcLauncher.cpp 11 Jun 2005 21:01:45 -0000 1.22 --- tcLauncher.cpp 12 Jun 2005 20:46:59 -0000 1.23 *************** *** 252,260 **** * @see tcLauncher::GetCompatibleCount */ ! std::string tcLauncher::GetCompatibleName(unsigned int idx) const { wxASSERT(mpLauncherDBObj); ! if (idx >= mpLauncherDBObj->mnConfigurations) return std::string(""); ! return std::string(mpLauncherDBObj->maChildClass[idx].mz); } --- 252,288 ---- * @see tcLauncher::GetCompatibleCount */ ! const std::string& tcLauncher::GetCompatibleName(unsigned int idx) const { + static std::string s; + wxASSERT(mpLauncherDBObj); ! if (idx >= mpLauncherDBObj->mnConfigurations) ! { ! s = ""; ! } ! else ! { ! s = mpLauncherDBObj->maChildClass[idx].mz; ! } ! ! return s; ! } ! ! /** ! * The names of this method and the GetCompatibleCount method are confusing, ! * should be renamed. ! * @see tcLauncher::GetCompatibleCount ! * @return quantity of configuration <idx> that can be loaded into launcher ! */ ! unsigned int tcLauncher::GetCompatibleQuantity(unsigned int idx) const ! { ! if (idx >= mpLauncherDBObj->mnConfigurations) ! { ! return 0; ! } ! else ! { ! return mpLauncherDBObj->maCapacity[idx]; ! } } Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** tcPlatformObject.cpp 1 Jun 2005 00:13:33 -0000 1.47 --- tcPlatformObject.cpp 12 Jun 2005 20:47:00 -0000 1.48 *************** *** 504,507 **** --- 504,511 ---- } + bool tcPlatformObject::IsRefueling() const + { + return isRefueling; + } /** *************** *** 531,534 **** --- 535,542 ---- } + void tcPlatformObject::SetRefueling(bool state) + { + isRefueling = state; + } /** *************** *** 885,889 **** tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) ! : tcGameObject(obj), tcSensorPlatform() { using namespace database; --- 893,898 ---- tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) ! : tcGameObject(obj), tcSensorPlatform(), ! isRefueling(false) { using namespace database; *************** *** 958,962 **** tcGameObject(o), tcSensorPlatform(o), ! commandObj(o.commandObj) { brain = new Brain(this); // need copy constructor for this --- 967,972 ---- tcGameObject(o), tcSensorPlatform(o), ! commandObj(o.commandObj), ! isRefueling(o.isRefueling) { brain = new Brain(this); // need copy constructor for this Index: tcStores.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcStores.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcStores.cpp 11 Jun 2005 21:01:45 -0000 1.4 --- tcStores.cpp 12 Jun 2005 20:47:00 -0000 1.5 *************** *** 32,35 **** --- 32,36 ---- #include "common/tcObjStream.h" #include "tcDatabase.h" + #include "tcGenericDBObject.h" #ifdef _DEBUG *************** *** 70,74 **** } ! tcStores::StoreItem::StoreItem(const std::string& name, unsigned int qty) : className(name), quantity(qty) --- 71,75 ---- } ! tcStores::StoreItem::StoreItem(const std::string& name, unsigned long qty) : className(name), quantity(qty) *************** *** 178,185 **** * */ ! bool tcStores::AddItems(const std::string& item, unsigned int quantity) { wxASSERT(storesDBObj); ! int freeCapacity = storesDBObj->capacity - CurrentQuantity(); if ((freeCapacity > 0) && IsCompatible(item)) { --- 179,186 ---- * */ ! bool tcStores::AddItems(const std::string& item, unsigned long quantity) { wxASSERT(storesDBObj); ! long freeCapacity = storesDBObj->capacity - CurrentQuantity(); if ((freeCapacity > 0) && IsCompatible(item)) { *************** *** 204,208 **** * Complete load or unload operation, updating stores and launcher */ ! void tcStores::CompleteOperation(StoreOperation& op) { tcGameObject* obj = GetChildOrParent(op.obj); --- 205,209 ---- * Complete load or unload operation, updating stores and launcher */ ! void tcStores::CompleteOperation(tcStores::StoreOperation& op) { tcGameObject* obj = GetChildOrParent(op.obj); *************** *** 219,223 **** launcher->SetChildQuantity(op.quantity); // assumes empty launcher } ! else { wxASSERT(launcher->mnCurrent == op.quantity); // no partial unloading --- 220,237 ---- launcher->SetChildQuantity(op.quantity); // assumes empty launcher } ! else if (op.transferType == StoreOperation::REFUEL) ! { ! if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj)) ! { ! platform->fuel_kg += float(op.quantity); ! float fuelCapacity_kg = platform->mpDBObject->mfFuelCapacity_kg; ! if (platform->fuel_kg > fuelCapacity_kg) ! { ! platform->fuel_kg = fuelCapacity_kg; ! } ! platform->SetRefueling(false); ! } ! } ! else // UNLOAD { wxASSERT(launcher->mnCurrent == op.quantity); // no partial unloading *************** *** 230,234 **** * @return current quantity of item available in magazine */ ! unsigned int tcStores::CurrentItemQuantity(const std::string& item) const { for (size_t n=0; n<stores.size(); n++) --- 244,248 ---- * @return current quantity of item available in magazine */ ! unsigned long tcStores::CurrentItemQuantity(const std::string& item) const { for (size_t n=0; n<stores.size(); n++) *************** *** 247,253 **** * @see tcStores::IncomingQuantity */ ! unsigned int tcStores::CurrentQuantity() const { ! unsigned currentCount = 0; for (size_t n=0; n<stores.size(); n++) { --- 261,267 ---- * @see tcStores::IncomingQuantity */ ! unsigned long tcStores::CurrentQuantity() const { ! unsigned long currentCount = 0; for (size_t n=0; n<stores.size(); n++) { *************** *** 305,308 **** --- 319,329 ---- } + const std::string& tcStores::GetDisplayName() const + { + wxASSERT(storesDBObj != 0); + + return storesDBObj->displayName; + } + const std::string& tcStores::GetItemName(unsigned int idx) const { *************** *** 336,342 **** * @see tcStores::CurrentQuantity */ ! unsigned int tcStores::IncomingQuantity() const { ! unsigned currentCount = 0; for (size_t k=0; k<ops.size(); k++) --- 357,363 ---- * @see tcStores::CurrentQuantity */ ! unsigned long tcStores::IncomingQuantity() const { ! unsigned long currentCount = 0; for (size_t k=0; k<ops.size(); k++) *************** *** 376,381 **** bool tcStores::IsFull() const { ! unsigned currentQuantity = CurrentQuantity(); ! unsigned incomingQuantity = IncomingQuantity(); return ((currentQuantity + incomingQuantity) >= storesDBObj->capacity); --- 397,402 ---- bool tcStores::IsFull() const { ! unsigned long currentQuantity = CurrentQuantity(); ! unsigned long incomingQuantity = IncomingQuantity(); return ((currentQuantity + incomingQuantity) >= storesDBObj->capacity); *************** *** 390,395 **** tcGameObject* obj = GetChildOrParent(child); ! wxASSERT(obj); ! if (obj == 0) return false; tcLauncher* launcher = obj->GetLauncher(idx); --- 411,425 ---- tcGameObject* obj = GetChildOrParent(child); ! if (obj == 0) ! { ! if (parent->IsOwnAlliance()) ! { ! wxString s = wxString::Format("%s (%s) - Cannot load launcher, no access to magazine\n", ! parent->mzUnit.mz, parent->mzClass.mz); ! tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); ! } ! return false; ! } ! tcLauncher* launcher = obj->GetLauncher(idx); *************** *** 424,428 **** bool found = false; int nStores = (int)stores.size(); ! unsigned int loadQuantity = 0; for (int k=nStores-1; (k>=0) && !found; k--) { --- 454,458 ---- bool found = false; int nStores = (int)stores.size(); ! unsigned long loadQuantity = 0; for (int k=nStores-1; (k>=0) && !found; k--) { *************** *** 521,524 **** --- 551,694 ---- /** + * Used to load a non-launcher item (e.g. fuel) from stores to platform + */ + bool tcStores::LoadOther(const std::string& item, tcGameObject* child) + { + tcGameObject* obj = GetChildOrParent(child); + + if (obj == 0) + { + if (parent->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Cannot load item, no access to stores\n", + parent->mzUnit.mz, parent->mzClass.mz); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; + } + + tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(obj); + if (platform == 0) + { + if (obj->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Cannot load item, not platform object\n", + parent->mzUnit.mz, parent->mzClass.mz); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; + } + + // only support refueling right now + if (item != "Fuel") + { + wxASSERT(false); + return false; + } + + long fuelNeeded_kg = long(platform->mpDBObject->mfFuelCapacity_kg - platform->fuel_kg); + + if (fuelNeeded_kg <= 0) + { + if (obj->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - platform already refueled\n", + obj->mzUnit.mz, obj->mzClass.mz); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; // item not compatible with launcher + } + + std::vector<StoreItem>::iterator iter; + bool found = false; + int nStores = (int)stores.size(); + unsigned long loadQuantity = 0; + for (int k=nStores-1; (k>=0) && !found; k--) + { + if (stores[k].className == item) + { + found = true; + wxASSERT(stores[k].quantity); + if (stores[k].quantity >= (unsigned long)fuelNeeded_kg) + { + loadQuantity = fuelNeeded_kg; + } + else + { + loadQuantity = stores[k].quantity; + } + stores[k].quantity -= loadQuantity; + if (stores[k].quantity == 0) + { + stores.erase(stores.begin()+k); + } + } + } + + if (!found) + { + if (obj->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - No %s in %s\n", + obj->mzUnit.mz, obj->mzClass.mz, + item.c_str(), storesDBObj->displayName.c_str()); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + return false; // stores not available + } + + // search for existing op with launcher + found = false; + std::vector<StoreOperation>::iterator opIter; + std::vector<StoreOperation>::iterator matchIter; + for (opIter = ops.begin(); (opIter != ops.end()) && (!found); ++opIter) + { + if ((opIter->transferType == StoreOperation::REFUEL) && (opIter->obj == child)) + { + matchIter = opIter; + found = true; + } + } + + if (found) // modify existing op + { + wxASSERT(matchIter->transferType == StoreOperation::REFUEL); + if (matchIter->item == item) + { + if (obj->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Already refueling\n", + obj->mzUnit.mz, obj->mzClass.mz); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + } + return false; + } + else // add new op + { + StoreOperation op; + op.item = item; + op.launcherIdx = 0; + op.quantity = loadQuantity; + op.timeToComplete = storesDBObj->moveTime; + op.transferType = StoreOperation::REFUEL; + op.obj = child; + + ops.push_back(op); + + platform->SetRefueling(true); + } + + if (obj->IsOwnAlliance()) + { + wxString s = wxString::Format("%s (%s) - Refueling\n", + obj->mzUnit.mz, obj->mzClass.mz); + tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); + } + + return true; + } + + /** * */ *************** *** 535,540 **** tcGameObject* obj = GetChildOrParent(child); ! wxASSERT(obj); ! if (obj == 0) return false; tcLauncher* launcher = obj->GetLauncher(idx); --- 705,718 ---- tcGameObject* obj = GetChildOrParent(child); ! if (obj == 0) ! { ! if (parent->IsOwnAlliance()) ! { ! wxString s = wxString::Format("%s (%s) - Cannot unload launcher, no access to magazine\n", ! parent->mzUnit.mz, parent->mzClass.mz); ! tcMessageInterface::Get()->ChannelMessage("Info", s.c_str()); ! } ! return false; ! } tcLauncher* launcher = obj->GetLauncher(idx); |