amessier Posted January 12, 2006 Report Share Posted January 12, 2006 (edited) I have been working on displaying facility construction time aka days left until built. I have the functions working for 1 square and im wondering what is the best way to approach multiple squares is . void BaseviewRenderer::displayDaysRemainingforConstruction(bool windowStatus){ bool freeFacilitySquare; Core::Player* player = Core::Player::getInstancePtr(); Core::HumanBase::SharedPtr base=getCurrentBase(); Core::HumanFacility::SharedPtr pickedFacility; // Get number of facilites and loop that many times (Special case for landing docks due to there size 2x2) freeFacilitySquare=base->isPlaceFree(0,5); if(!freeFacilitySquare) { pickedFacility = base->getFacility(0,5); CEGUI::WindowManager::getSingleton().getWindow("Baseview/FacilityDisplayWindow0x5")->setProperty("Text",pickedFacility->getDaysToComplete()); } else { CEGUI::WindowManager::getSingleton().getWindow("Baseview/FacilityDisplayWindow0x5")->setProperty("Text",""); }} I really dont want to repeat this "freeFacilitySquare=base->isPlaceFree(0,5); if(!freeFacilitySquare) { pickedFacility = base->getFacility(0,5); CEGUI::WindowManager::getSingleton().getWindow("Baseview/FacilityDisplayWindow0x5")->setProperty("Text",pickedFacility->getDaysToComplete()); } else { CEGUI::WindowManager::getSingleton().getWindow("Baseview/FacilityDisplayWindow0x5")->setProperty("Text",""); }}"for every single square on the grid... I know if this was IBM REXX i could have variables in my getWindow() Baseview/FacilityDisplayWindowAxB declare A and B . However in C++ to the best of my knowledge you are not able to use variables in this situation. Edited January 12, 2006 by amessier Link to comment Share on other sites More sharing options...
UnFleshed One Posted January 12, 2006 Report Share Posted January 12, 2006 (edited) You mean you want to generate strings like that:"Baseview/FacilityDisplayWindow0x0""Baseview/FacilityDisplayWindow0x1"..."Baseview/FacilityDisplayWindow5x5"... TryString windowName = boost::str( boost::format("Baseview/FacilityDisplayWindow%1%x%2%") % a % b);(I'm not sure about syntaxis here, in worst case you probably can use sprintf ) And then use windowName instead. (Put everything in a function or something) BTW, why do you iterate through squares, and not through facilities themselves? Edited January 12, 2006 by UnFleshed One Link to comment Share on other sites More sharing options...
amessier Posted January 12, 2006 Author Report Share Posted January 12, 2006 (edited) Thats exactlly what I wanted to know.. So boost supports it... Umm good point with the iterating thru facilities and not squares.... Thx!!! You mean you want to generate strings like that:"Baseview/FacilityDisplayWindow0x0""Baseview/FacilityDisplayWindow0x1"..."Baseview/FacilityDisplayWindow5x5"... TryString windowName = boost::str( boost::format("Baseview/FacilityDisplayWindow%1%x%2%") % a % b);(I'm not sure about syntaxis here, in worst case you probably can use sprintf ) And then use windowName instead. (Put everything in a function or something) BTW, why do you iterate through squares, and not through facilities themselves?<{POST_SNAPBACK}> Edited January 12, 2006 by amessier Link to comment Share on other sites More sharing options...
Garo Posted January 12, 2006 Report Share Posted January 12, 2006 Thats exactlly what I wanted to know.. So boost supports it... Yep, and it's typesafe. All hail and praise the typesafe printf - Garo Link to comment Share on other sites More sharing options...
rincewind Posted January 12, 2006 Report Share Posted January 12, 2006 Typesafe is probably word of the year for xenocide. Link to comment Share on other sites More sharing options...
Recommended Posts