Object* ObjectsPool::addObjectbyName(const string& obj, Sint16 x, Sint16 y, const ParameterMap& objparam, bool outside) { ParameterMap parameters; if (hasParam(objparam,"file")) { parameters=getFileParameters(objparam.find("file")->second); ParameterMap::const_iterator it=objparam.begin(); while (it!=objparam.end()) { if (it->first!="file") parameters[it->first]=it->second; ++it; } } else { parameters=objparam; } //Set names... if (!hasParam(parameters,"name")) parameters["name"]=getNextObjectName(obj); if (obj=="Wall") return (addObject(new Wall(x,y,parameters), outside)); else if (obj=="Exit") return (addObject(new Exit(x,y,parameters), outside)); else if (obj=="Water") return (addObject(new Water(x,y,parameters), outside)); else if (obj=="Teleporter") return (addObject(new Teleporter(x,y,parameters), outside)); else if (obj=="Wind") return (addObject(new Wind(x,y,parameters), outside)); else if (obj=="Geyser") return (addObject(new Geyser(x,y,parameters), outside)); else if (obj=="Trigger") return (addObject(new Trigger(x,y,parameters), outside)); else if (obj=="Door") return (addObject(new Door(x,y,parameters), outside)); else if (obj=="Spike") return (addObject(new Spike(x,y,parameters), outside)); else if (obj=="Heart") return (addObject(new Heart(x,y,parameters), outside)); else if (obj=="Key") return (addObject(new Key(x,y,parameters), outside)); else if (obj=="Bomb") return (addObject(new Bomb(x,y,parameters), outside)); else if (obj=="TriggeredBomb") return (addObject(new TriggeredBomb(x,y,parameters), outside)); else if (obj=="DeadPlayer") return (addObject(new DeadPlayer(x,y,parameters), outside)); else if (obj=="Erik") return (addObject(new Erik(x,y,parameters), outside)); else if (obj=="Olaf") return (addObject(new Olaf(x,y,parameters), outside)); else if (obj=="Baleog") return (addObject(new Baleog(x,y,parameters), outside)); else if (obj=="Fang") return (addObject(new Fang(x,y,parameters), outside)); else if (obj=="Scorch") return (addObject(new Scorch(x,y,parameters), outside)); else if (obj=="Plant") return (addObject(new Plant(x,y,parameters), outside)); else if (obj=="Zombie") return (addObject(new Zombie(x,y,parameters), outside)); else { cout << "Object " << obj << " unknown, skipping...\n"; return NULL; } }
// int totalDistance(RST* root); // Must check for errors in instance, if so output error to console. // If option output is given, output file to a text // If option output is not given output to screen int main(int argc, char** argv){ char* filename = NULL; char** lines; Plane plane; char* options = NULL; bool correctFile = true; int** MST = NULL; int* degrees; //initiallize rand() with current time srand(time(NULL)); // Cheching for arguments, if they are greater than or equal to two, assume // their are options and a filename being passed in trying to be passed in. if(argc >= 2){ filename = getFilename(argv, argc); options = getOption(argv, argc); } // Grab Data if (filename == NULL){ plane = getParameters(); plane.instance_size = plane.NUM_PT; } else { lines = readFile(filename); // Check to see if a file was succesffully parsed if(lines == NULL){ printf("File not found\n"); printf("Exiting...\n"); return -1; } plane.generation = getGeneration(filename); plane = getFileParameters(lines); correctFile = checkFile(plane); free(lines); } // Ensure instances is of the correct size; if(!correctFile){ printf("File is corrupt, the instance file does not match specification\n"); return -2; } if(filename != NULL){ // If we opened up a file, the Plane instance is all ready generated for us. printPlane(plane, filename, options); if(plane.instance_size > 1){ MST = prims(plane); printMST(MST,plane.instance_size, filename, options); degrees = nodeDegree(MST, plane.instance_size-1); } else { printf("Can not generate MST, insufficient nodes \n"); } } else { while(plane.generation < plane.total_gen){ // If not we need to generate instances for the number of planes required plane.instance = genInstance(plane.NUM_PT, plane.MAX_X, plane.MAX_Y); printPlane(plane, NULL, options); filename = genFilename(plane.NUM_PT, plane.generation); if(plane.instance_size > 1){ MST = prims(plane); printMST(MST,plane.instance_size, filename, options); degrees = nodeDegree(MST, plane.instance_size-1); } else { printf("Can not generate MST, insufficient nodes \n"); } plane.generation++; } } RST* root; int rootIndex = findRoot(MST, plane.instance_size-1); printf("Root index %i\n", rootIndex); root = buildNode(NULL, rootIndex, NULL, 0, 0 ); buildTree(root, plane.instance, MST, plane.instance_size-1); // Need to create code to free plane.instance and and sub arrays of instance printList(root,0); //printf("Overlap is %i\n", maxOverlap(root)); //printf("Distance is %i\n", totalDistance(root)); freeMST(MST, plane.instance_size-1); freePlane(&plane); freeRST(root); // need to free MST return 0; }