void CellularAutomata::Init(int sizeX, int sizeY, int birthLimit, int deathLimit, int generations, int changeToStayAlive, int numOfCavesToGenerate, unsigned int seed) { // Do we have a specified seed or will we randomize? if (seed != 0) std::srand(seed); else // Randomize if we don't have a seed std::srand((unsigned int)time(NULL)); // Set values for various things. SetSizeX(sizeX); SetSizeY(sizeY); SetBirthLimit(birthLimit); SetDeathLimit(deathLimit); SetGenerations(generations); SetChanceToStayAlive(changeToStayAlive); SetCavesToGenerate(numOfCavesToGenerate); SetCavesGenerated(0); SetFloorTiles(0); // Allocate memory for the map. ////////////// cave = new char*[GetSizeY()]; cave2 = new char*[GetSizeY()]; for (int y = 0; y < GetSizeY(); y++) { cave[y] = new char[GetSizeX()]; cave2[y] = new char[GetSizeX()]; } ///////////////////////////////////////////// }
bool Dialog::CreateFromXML(const char* idd){ ScopedPointer<File> fh = gUiRender->OpenFile(idd); if(!fh) return false; char* xml = (char*)fh->ReadWholeFile(); int tmpInt; bool result = true; try { ticpp::Document doc; doc.Parse(xml); ticpp::Element* root = doc.FirstChildElement("Root_Element"); if(root->GetAttribute("ID", &tmpInt)) SetID(tmpInt); if(root->GetAttribute("X", &tmpInt)) SetPositionX(tmpInt); if(root->GetAttribute("Y", &tmpInt)) SetPositionY(tmpInt); if(root->GetAttribute("WIDTH", &tmpInt)) SetSizeX(tmpInt); if(root->GetAttribute("HEIGHT", &tmpInt)) SetSizeY(tmpInt); if(root->GetAttribute("MODAL", &tmpInt)) SetModal(tmpInt); if(root->GetAttribute("SHOWSID", &tmpInt)) SetShowSoundID(tmpInt); if(root->GetAttribute("HIDESID", &tmpInt)) SetHideSoundID(tmpInt); if(root->GetAttribute("EXTENT", &tmpInt)) SetExtent(tmpInt); if(root->GetAttribute("DEFAULT_X", &tmpInt)) SetDefaultPositionX(tmpInt); if(root->GetAttribute("DEFAULT_Y", &tmpInt)) SetDefaultPositionY(tmpInt); if(root->GetAttribute("ADJUST_X", &tmpInt)) SetDefaultAdjustPositionX(tmpInt); if(root->GetAttribute("ADJUST_Y", &tmpInt)) SetDefaultAdjustPositionY(tmpInt); if(root->GetAttribute("DEFAULT_VISIBLE", &tmpInt)) SetDefaultVisible(tmpInt); SetName(root->GetAttribute("NAME").c_str()); for(ticpp::Element* child = root->FirstChildElement(false); child; child = child->NextSiblingElement(false)){ if(child->Value() == "CAPTION"){ mCaption = (Caption*)CreateControlFromXML(child, this); }else if(child->Value() == "RADIOBUTTON"){ RadioButton* btn = (RadioButton*)CreateControlFromXML(child, this); if(int id = btn->RadioBoxID()){ RadioBox* box = (RadioBox*)GetControlByID(id); if(box && box->ControlType() == CT_RADIOBOX) box->AddButton(btn); } AddChild(btn); }else{ AddChild(CreateControlFromXML(child, this)); } } }catch(ticpp::Exception& ex){ LOG("TinyXML Exception %s", ex.what()); result = false; } OnCreated(); delete [] xml; return result; }