void Planet::UpdatePrices() { // First things first, we really don't care about a resorce if we aren't // going to use it. Therefore, those that aren't deemed critical should be // set to 0 // At the moment, the only ores that are needed are those that are those to make the ships in the factory std::vector<Ore> NecessaryOres = m_Factory.GetRecipe().GetOreList(); // Set all the ores that are not in the list to 0; for (uint i = 0; i < m_Prices.GetOreList().size(); ++i) { if (!IsInVector(m_Prices.GetOreList()[i], NecessaryOres)) { uint needed = m_Factory.GetRecipe().GetOreAmount(m_Prices.GetOreList()[i]); //The more it is needed, the more we should be willing to pay; uint price = needed; //Planets with more money should pay more because they have more. price = (double)price * (double)m_Money * .7; // That decimal number *may* need to be adjusted // However, if a planet has a fuckton of the stuff already... Then just nuke the price price = price / (m_RawStockpile.GetOreAmount(m_Prices.GetOreList()[i]) / 3); // Three here is another number that *may* need to be adjusted } else { m_Prices.SetOreAmount(m_Prices.GetOreList()[i], 0); } } }
void Refinery::ReceiveRawOre(Ore type, uint amount) { if(IsInVector(type, m_RawStockpile.GetOreList())) m_RawStockpile.AddOreAmount(type, amount); else m_RawStockpile.AddOre(type, amount); }
/*=========================================================================+ Parse_Block: Parse the specified block from the XML input. The block is expected to be an XML string of the following form: < {sBlockName} > <name1> {value1_1} </name1> <name2> {value2_1} </name2> ... < {sBlockName} > This method is to be used when the Exit XML has been extended, and the Parse_ETA_Input_XML() method might decode the wrong "object" block. This method return -1 if it failed to find the named block or zero on success. The data parsed can be retrieved using the Get_Block_Attribute_Name() and Get_Block_Attribute_Value(). +=========================================================================*/ int ExitXMLBlock::Parse_Block( string sBlockName ) { int iRc = -1; // failure DOMNodeList* pTopNodeList = NULL; DOMNode* pTopNode = NULL; DOMNodeList* pNodeList = NULL; const XMLCh* pxcValue = NULL; string sTagName; string sTagValue; short iTagType; int iTagCount; // Clear previous data, if any m_vsBlockAttributeList.clear(); m_vsBlockAttributes.clear(); m_vsBlockValues.clear(); // Find the XML block. pTopNodeList = Find_Node(m_pXmlDocument, sBlockName); if (!pTopNodeList) { goto exit; } pTopNode = pTopNodeList->item(0); // Should only be one! if (!pTopNode) { goto exit; } // Find all the child nodes. pNodeList = pTopNode->getChildNodes(); /* || Get the number of tags found under the top level node. || If the pNodeList is empty, initialize the tag count to 0. */ iTagCount = pNodeList->getLength(); // Get the tag and value under the top level node and parse each tag. for (int iIndex = 0; iIndex < iTagCount; iIndex++) { DOMNode* pNode = pNodeList->item(iIndex); if (!pNode) { // Error! continue; } iTagType = pNode->getNodeType(); if (iTagType != 1 /* DOMNode::NodeType::ELEMENT_NODE */) { continue; } /* || Get the tag name. If failed to get the tag name, || skip the current tag. */ pxcValue = pNode->getNodeName(); if (pxcValue) { sTagName = UTF16toUTF8(pxcValue); } /* pxcValue = pNode->getNodeValue(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } */ pxcValue = pNode->getTextContent(); if (pxcValue) { sTagValue = UTF16toUTF8(pxcValue); } #if 0 cout << "BLK Node Name: '" << sTagName << "'" << endl; cout << "BLK Node Type: " << iTagType << endl; cout << "BLK Node Value: '" << (sTagValue.empty() ? "<empty>" : sTagValue) << "'" << endl; cout << endl; #endif /* || Insert the attribute name and value into the end of the || respective attribute and value arrays. || Attribute with multiple values will have multiple elements || in both arrays. */ if (!IsInVector(sTagName, m_vsBlockAttributeList)) { m_vsBlockAttributeList.insert(m_vsBlockAttributeList.end(), sTagName); } m_vsBlockAttributes.insert(m_vsBlockAttributes.end(), sTagName); m_vsBlockValues.insert(m_vsBlockValues.end(), sTagValue); } iRc = 0; exit: return iRc; }